This repository has been archived by the owner on Feb 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathraw.ts
173 lines (149 loc) · 4.17 KB
/
raw.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* This file was automatically generated by witx-codegen - Do not edit manually.
*/
export type WasiHandle = i32;
export type Char8 = u8;
export type Char32 = u32;
export type WasiPtr<T> = usize;
export type WasiMutPtr<T> = usize;
export type WasiStringBytesPtr = WasiPtr<Char8>;
@unmanaged
export class WasiString {
ptr: WasiStringBytesPtr;
length: usize;
constructor(str: string) {
let wasiString = String.UTF8.encode(str, false);
// @ts-ignore: cast
this.ptr = changetype<WasiStringBytesPtr>(wasiString);
this.length = wasiString.byteLength;
}
toString(): string {
let tmp = new ArrayBuffer(this.length as u32);
memory.copy(changetype<usize>(tmp), this.ptr, this.length);
return String.UTF8.decode(tmp);
}
}
@unmanaged
export class WasiSlice<T> {
ptr: WasiPtr<T>;
length: usize;
constructor(array: ArrayBufferView) {
// @ts-ignore: cast
this.ptr = array.dataStart;
this.length = array.byteLength;
}
}
@unmanaged
export class WasiMutSlice<T> {
ptr: WasiMutPtr<T>;
length: usize;
constructor(array: ArrayBufferView) {
// @ts-ignore: cast
this.ptr = array.dataStart;
this.length = array.byteLength;
}
}
/**
* ---------------------- Module: [wasi_experimental_http] ----------------------
*/
export type HttpError = u32;
export namespace HttpError {
export const SUCCESS: HttpError = 0;
export const INVALID_HANDLE: HttpError = 1;
export const MEMORY_NOT_FOUND: HttpError = 2;
export const MEMORY_ACCESS_ERROR: HttpError = 3;
export const BUFFER_TOO_SMALL: HttpError = 4;
export const HEADER_NOT_FOUND: HttpError = 5;
export const UTF_8_ERROR: HttpError = 6;
export const DESTINATION_NOT_ALLOWED: HttpError = 7;
export const INVALID_METHOD: HttpError = 8;
export const INVALID_ENCODING: HttpError = 9;
export const INVALID_URL: HttpError = 10;
export const REQUEST_ERROR: HttpError = 11;
export const RUNTIME_ERROR: HttpError = 12;
export const TOO_MANY_SESSIONS: HttpError = 13;
}
/**
* HTTP status code
*/
export type StatusCode = u16;
/**
* An HTTP body being sent
*/
export type OutgoingBody = WasiSlice<u8>;
/**
* Buffer for an HTTP body being received
*/
export type IncomingBody = WasiMutSlice<u8>;
/**
* A response handle
*/
export type ResponseHandle = WasiHandle;
/**
* Buffer to store a header value
*/
export type HeaderValueBuf = WasiMutSlice<u8>;
/**
* Number of bytes having been written
*/
export type WrittenBytes = usize;
/**
* Send a request
*/
// @ts-ignore: decorator
@external("wasi_experimental_http", "req")
export declare function req(
url_ptr: WasiPtr<Char8>,
url_len: usize,
method_ptr: WasiPtr<Char8>,
method_len: usize,
headers_ptr: WasiPtr<Char8>,
headers_len: usize,
body_ptr: WasiPtr<u8>,
body_len: usize,
result_0_ptr: WasiMutPtr<StatusCode>,
result_1_ptr: WasiMutPtr<ResponseHandle>
): HttpError;
/**
* Close a request handle
*/
// @ts-ignore: decorator
@external("wasi_experimental_http", "close")
export declare function close(
response_handle: ResponseHandle
): HttpError;
/**
* Get the value associated with a header
*/
// @ts-ignore: decorator
@external("wasi_experimental_http", "header_get")
export declare function headerGet(
response_handle: ResponseHandle,
header_name_ptr: WasiPtr<Char8>,
header_name_len: usize,
header_value_buf_ptr: WasiMutPtr<u8>,
header_value_buf_len: usize,
result_ptr: WasiMutPtr<WrittenBytes>
): HttpError;
/**
* Get the entire response header map
*/
// @ts-ignore: decorator
@external("wasi_experimental_http", "headers_get_all")
export declare function headersGetAll(
response_handle: ResponseHandle,
header_value_buf_ptr: WasiMutPtr<u8>,
header_value_buf_len: usize,
result_ptr: WasiMutPtr<WrittenBytes>
): HttpError;
/**
* Fill a buffer with the streamed content of a response body
*/
// @ts-ignore: decorator
@external("wasi_experimental_http", "body_read")
export declare function bodyRead(
response_handle: ResponseHandle,
body_buf_ptr: WasiMutPtr<u8>,
body_buf_len: usize,
result_ptr: WasiMutPtr<WrittenBytes>
): HttpError;