@velarscript/node 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +148 -0
- package/dist/compiler.d.ts +12 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +954 -0
- package/dist/compiler.js.map +1 -0
- package/dist/environment-runtime.d.ts +2 -0
- package/dist/environment-runtime.d.ts.map +1 -0
- package/dist/environment-runtime.js +53 -0
- package/dist/environment-runtime.js.map +1 -0
- package/dist/filesystem-runtime.d.ts +2 -0
- package/dist/filesystem-runtime.d.ts.map +1 -0
- package/dist/filesystem-runtime.js +329 -0
- package/dist/filesystem-runtime.js.map +1 -0
- package/dist/host-runtime.d.ts +2 -0
- package/dist/host-runtime.d.ts.map +1 -0
- package/dist/host-runtime.js +149 -0
- package/dist/host-runtime.js.map +1 -0
- package/dist/http-runtime.d.ts +2 -0
- package/dist/http-runtime.d.ts.map +1 -0
- package/dist/http-runtime.js +612 -0
- package/dist/http-runtime.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/node-host-runtime.d.ts +2 -0
- package/dist/node-host-runtime.d.ts.map +1 -0
- package/dist/node-host-runtime.js +314 -0
- package/dist/node-host-runtime.js.map +1 -0
- package/dist/node-host-worker-runtime.d.ts +2 -0
- package/dist/node-host-worker-runtime.d.ts.map +1 -0
- package/dist/node-host-worker-runtime.js +1144 -0
- package/dist/node-host-worker-runtime.js.map +1 -0
- package/dist/process-runtime.d.ts +2 -0
- package/dist/process-runtime.d.ts.map +1 -0
- package/dist/process-runtime.js +167 -0
- package/dist/process-runtime.js.map +1 -0
- package/dist/process-worker-runtime.d.ts +2 -0
- package/dist/process-worker-runtime.d.ts.map +1 -0
- package/dist/process-worker-runtime.js +473 -0
- package/dist/process-worker-runtime.js.map +1 -0
- package/dist/serve-runtime.d.ts +2 -0
- package/dist/serve-runtime.d.ts.map +1 -0
- package/dist/serve-runtime.js +463 -0
- package/dist/serve-runtime.js.map +1 -0
- package/dist/sqlite-runtime.d.ts +3 -0
- package/dist/sqlite-runtime.d.ts.map +1 -0
- package/dist/sqlite-runtime.js +92 -0
- package/dist/sqlite-runtime.js.map +1 -0
- package/dist/terminal-runtime.d.ts +2 -0
- package/dist/terminal-runtime.d.ts.map +1 -0
- package/dist/terminal-runtime.js +290 -0
- package/dist/terminal-runtime.js.map +1 -0
- package/dist/terminal-worker-runtime.d.ts +2 -0
- package/dist/terminal-worker-runtime.d.ts.map +1 -0
- package/dist/terminal-worker-runtime.js +311 -0
- package/dist/terminal-worker-runtime.js.map +1 -0
- package/dist/websocket-runtime.d.ts +2 -0
- package/dist/websocket-runtime.d.ts.map +1 -0
- package/dist/websocket-runtime.js +46 -0
- package/dist/websocket-runtime.js.map +1 -0
- package/dist/worker-runtime.d.ts +2 -0
- package/dist/worker-runtime.d.ts.map +1 -0
- package/dist/worker-runtime.js +160 -0
- package/dist/worker-runtime.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
import { VELAR_STRICT_JSON_RUNTIME, VELAR_TYPE_REGISTRY_RUNTIME, VELAR_UTF8_RUNTIME } from "@velarscript/compiler/extension";
|
|
2
|
+
export const VELAR_NODE_HTTP_RUNTIME = String.raw `
|
|
3
|
+
import { __velarNodeHostHttpTransportError, __velarNodeHostInvoke } from "velar/node-host-v1";
|
|
4
|
+
import { Bytes as __velarHttpBytes } from "velar/binary";
|
|
5
|
+
|
|
6
|
+
${VELAR_STRICT_JSON_RUNTIME}
|
|
7
|
+
${VELAR_TYPE_REGISTRY_RUNTIME}
|
|
8
|
+
${VELAR_UTF8_RUNTIME}
|
|
9
|
+
const maxBodyBytes = 16 * 1024 * 1024;
|
|
10
|
+
const maxResponseBytes = 64 * 1024 * 1024;
|
|
11
|
+
const maxResponseChunks = 1000000;
|
|
12
|
+
const NativeArray = globalThis.Array;
|
|
13
|
+
const NativeError = globalThis.Error;
|
|
14
|
+
const NativeNumber = globalThis.Number;
|
|
15
|
+
const NativeObject = globalThis.Object;
|
|
16
|
+
const NativePromise = globalThis.Promise;
|
|
17
|
+
const NativeRangeError = globalThis.RangeError;
|
|
18
|
+
const NativeRegExp = globalThis.RegExp;
|
|
19
|
+
const NativeString = globalThis.String;
|
|
20
|
+
const NativeTypeError = globalThis.TypeError;
|
|
21
|
+
const NativeWeakSet = globalThis.WeakSet;
|
|
22
|
+
const NativeUint8Array = globalThis.Uint8Array;
|
|
23
|
+
const NativeURL = typeof globalThis.URL === "function" ? globalThis.URL : null;
|
|
24
|
+
const NativeMap = typeof globalThis.Map === "function" ? globalThis.Map : null;
|
|
25
|
+
const NativeSet = typeof globalThis.Set === "function" ? globalThis.Set : null;
|
|
26
|
+
const nativeReflectApply = Object.getOwnPropertyDescriptor(Reflect, "apply")?.value;
|
|
27
|
+
const nativeReflectOwnKeys = Object.getOwnPropertyDescriptor(Reflect, "ownKeys")?.value;
|
|
28
|
+
const nativeArrayIsArray = Object.getOwnPropertyDescriptor(NativeArray, "isArray")?.value;
|
|
29
|
+
const nativeArrayJoin = Object.getOwnPropertyDescriptor(NativeArray.prototype, "join")?.value;
|
|
30
|
+
const nativeArrayPush = Object.getOwnPropertyDescriptor(NativeArray.prototype, "push")?.value;
|
|
31
|
+
const nativeTypedArrayPrototype = Object.getPrototypeOf(NativeUint8Array.prototype);
|
|
32
|
+
const nativeUint8ArraySet = Object.getOwnPropertyDescriptor(nativeTypedArrayPrototype, "set")?.value;
|
|
33
|
+
const nativePromiseThen = Object.getOwnPropertyDescriptor(NativePromise.prototype, "then")?.value;
|
|
34
|
+
const nativeNumberIsInteger = Object.getOwnPropertyDescriptor(NativeNumber, "isInteger")?.value;
|
|
35
|
+
const nativeNumberIsSafeInteger = Object.getOwnPropertyDescriptor(NativeNumber, "isSafeInteger")?.value;
|
|
36
|
+
const nativeObjectCreate = Object.getOwnPropertyDescriptor(NativeObject, "create")?.value;
|
|
37
|
+
const nativeObjectFreeze = Object.getOwnPropertyDescriptor(NativeObject, "freeze")?.value;
|
|
38
|
+
const nativeObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(NativeObject, "getOwnPropertyDescriptor")?.value;
|
|
39
|
+
const nativeObjectGetPrototypeOf = Object.getOwnPropertyDescriptor(NativeObject, "getPrototypeOf")?.value;
|
|
40
|
+
const nativeRegExpTest = Object.getOwnPropertyDescriptor(NativeRegExp.prototype, "test")?.value;
|
|
41
|
+
const nativeStringToLowerCase = Object.getOwnPropertyDescriptor(NativeString.prototype, "toLowerCase")?.value;
|
|
42
|
+
const nativeStringToUpperCase = Object.getOwnPropertyDescriptor(NativeString.prototype, "toUpperCase")?.value;
|
|
43
|
+
const nativeMapSize = Object.getOwnPropertyDescriptor(Map.prototype, "size")?.get;
|
|
44
|
+
const nativeMapGet = Object.getOwnPropertyDescriptor(Map.prototype, "get")?.value;
|
|
45
|
+
const nativeMapHas = Object.getOwnPropertyDescriptor(Map.prototype, "has")?.value;
|
|
46
|
+
const nativeMapSet = Object.getOwnPropertyDescriptor(Map.prototype, "set")?.value;
|
|
47
|
+
const nativeMapForEach = Object.getOwnPropertyDescriptor(Map.prototype, "forEach")?.value;
|
|
48
|
+
const nativeSetSize = Object.getOwnPropertyDescriptor(Set.prototype, "size")?.get;
|
|
49
|
+
const nativeSetHas = Object.getOwnPropertyDescriptor(Set.prototype, "has")?.value;
|
|
50
|
+
const nativeSetAdd = Object.getOwnPropertyDescriptor(Set.prototype, "add")?.value;
|
|
51
|
+
const nativeSetDelete = Object.getOwnPropertyDescriptor(Set.prototype, "delete")?.value;
|
|
52
|
+
const nativeWeakSetHas = Object.getOwnPropertyDescriptor(WeakSet.prototype, "has")?.value;
|
|
53
|
+
const nativeWeakSetAdd = Object.getOwnPropertyDescriptor(WeakSet.prototype, "add")?.value;
|
|
54
|
+
const nativeUrlHref = typeof NativeURL === "function" ? Object.getOwnPropertyDescriptor(NativeURL.prototype, "href")?.get : null;
|
|
55
|
+
const nativeUrlProtocol = typeof NativeURL === "function" ? Object.getOwnPropertyDescriptor(NativeURL.prototype, "protocol")?.get : null;
|
|
56
|
+
const nativeUrlUsername = typeof NativeURL === "function" ? Object.getOwnPropertyDescriptor(NativeURL.prototype, "username")?.get : null;
|
|
57
|
+
const nativeUrlPassword = typeof NativeURL === "function" ? Object.getOwnPropertyDescriptor(NativeURL.prototype, "password")?.get : null;
|
|
58
|
+
const nativeSetTimeout = typeof globalThis.setTimeout === "function" ? globalThis.setTimeout : null;
|
|
59
|
+
const nativeClearTimeout = typeof globalThis.clearTimeout === "function" ? globalThis.clearTimeout : null;
|
|
60
|
+
const nativeProcessEnvironment = typeof process === "object" && process !== null ? process.env : null;
|
|
61
|
+
const nativeMaxSafeInteger = NativeNumber.MAX_SAFE_INTEGER;
|
|
62
|
+
const methodPattern = /^[!#$%&'*+.^_\x60|~0-9A-Z-]+$/u;
|
|
63
|
+
const headerNamePattern = /^[!#$%&'*+.^_|~0-9A-Za-z-]+$/u;
|
|
64
|
+
const lineBreakPattern = /[\r\n]/u;
|
|
65
|
+
const secretEnvironmentPattern = /^[A-Z_][A-Z0-9_]{0,127}$/u;
|
|
66
|
+
|
|
67
|
+
function parseJsonText(text) {
|
|
68
|
+
return __velarJsonParse(text, "HTTP JSON text");
|
|
69
|
+
}
|
|
70
|
+
function runtimeHttpType(Type) { return __velarRequireRuntimeType(Type, "HTTP parsing"); }
|
|
71
|
+
|
|
72
|
+
function call(operation, receiver, argumentsValue) { return nativeReflectApply(operation, receiver, argumentsValue); }
|
|
73
|
+
function arrayJoin(value, separator) { return call(nativeArrayJoin, value, [separator]); }
|
|
74
|
+
function arrayPush(value, item) { return call(nativeArrayPush, value, [item]); }
|
|
75
|
+
function freeze(value) { return call(nativeObjectFreeze, NativeObject, [value]); }
|
|
76
|
+
function ownDescriptor(value, key) { return call(nativeObjectGetOwnPropertyDescriptor, NativeObject, [value, key]); }
|
|
77
|
+
function ownKeys(value) { return call(nativeReflectOwnKeys, Reflect, [value]); }
|
|
78
|
+
function stringLower(value) { return call(nativeStringToLowerCase, value, []); }
|
|
79
|
+
function stringUpper(value) { return call(nativeStringToUpperCase, value, []); }
|
|
80
|
+
function patternMatches(pattern, value) { return call(nativeRegExpTest, pattern, [value]); }
|
|
81
|
+
function setOf(values) {
|
|
82
|
+
const output = new NativeSet();
|
|
83
|
+
for (let index = 0; index < values.length; index += 1) call(nativeSetAdd, output, [values[index]]);
|
|
84
|
+
return output;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function requireHttpHost() {
|
|
88
|
+
if (typeof NativeArray !== "function" || typeof NativeError !== "function" || typeof NativeNumber !== "function"
|
|
89
|
+
|| typeof NativeObject !== "function" || typeof NativePromise !== "function" || typeof NativeRangeError !== "function" || typeof NativeRegExp !== "function"
|
|
90
|
+
|| typeof NativeString !== "function" || typeof NativeTypeError !== "function" || typeof NativeWeakSet !== "function"
|
|
91
|
+
|| typeof NativeURL !== "function" || typeof NativeMap !== "function" || typeof NativeSet !== "function"
|
|
92
|
+
|| typeof nativeReflectApply !== "function" || typeof nativeReflectOwnKeys !== "function"
|
|
93
|
+
|| typeof nativeArrayIsArray !== "function" || typeof nativeArrayJoin !== "function"
|
|
94
|
+
|| typeof nativeArrayPush !== "function" || typeof nativeUint8ArraySet !== "function" || typeof nativePromiseThen !== "function"
|
|
95
|
+
|| typeof nativeNumberIsInteger !== "function" || typeof nativeNumberIsSafeInteger !== "function"
|
|
96
|
+
|| typeof nativeObjectCreate !== "function" || typeof nativeObjectFreeze !== "function"
|
|
97
|
+
|| typeof nativeObjectGetOwnPropertyDescriptor !== "function" || typeof nativeObjectGetPrototypeOf !== "function"
|
|
98
|
+
|| typeof nativeRegExpTest !== "function" || typeof nativeStringToLowerCase !== "function" || typeof nativeStringToUpperCase !== "function"
|
|
99
|
+
|| typeof nativeMapSize !== "function" || typeof nativeMapGet !== "function" || typeof nativeMapHas !== "function" || typeof nativeMapSet !== "function"
|
|
100
|
+
|| typeof nativeMapForEach !== "function" || typeof nativeSetSize !== "function" || typeof nativeSetHas !== "function"
|
|
101
|
+
|| typeof nativeSetAdd !== "function" || typeof nativeSetDelete !== "function"
|
|
102
|
+
|| typeof nativeWeakSetHas !== "function" || typeof nativeWeakSetAdd !== "function" || typeof nativeUrlHref !== "function"
|
|
103
|
+
|| typeof nativeUrlProtocol !== "function" || typeof nativeUrlUsername !== "function" || typeof nativeUrlPassword !== "function"
|
|
104
|
+
|| typeof nativeSetTimeout !== "function" || typeof nativeClearTimeout !== "function" || nativeProcessEnvironment === null) {
|
|
105
|
+
throw new NativeTypeError("The Node HTTP host ABI is unavailable");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function urlHref(value) { return nativeReflectApply(nativeUrlHref, value, []); }
|
|
110
|
+
function urlProtocol(value) { return nativeReflectApply(nativeUrlProtocol, value, []); }
|
|
111
|
+
function urlUsername(value) { return nativeReflectApply(nativeUrlUsername, value, []); }
|
|
112
|
+
function urlPassword(value) { return nativeReflectApply(nativeUrlPassword, value, []); }
|
|
113
|
+
function plainRecord(value, name) {
|
|
114
|
+
if (value == null) return call(nativeObjectCreate, NativeObject, [null]);
|
|
115
|
+
if (typeof value !== "object" || call(nativeArrayIsArray, NativeArray, [value])) throw new NativeTypeError(name + " must be a record");
|
|
116
|
+
const prototype = call(nativeObjectGetPrototypeOf, NativeObject, [value]);
|
|
117
|
+
if (prototype !== NativeObject.prototype && prototype !== null) throw new NativeTypeError(name + " must be a plain record");
|
|
118
|
+
const output = call(nativeObjectCreate, NativeObject, [null]);
|
|
119
|
+
const keys = ownKeys(value);
|
|
120
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
121
|
+
const key = keys[index];
|
|
122
|
+
if (typeof key !== "string") throw new NativeTypeError(name + " fields must use string names");
|
|
123
|
+
const descriptor = ownDescriptor(value, key);
|
|
124
|
+
if (!descriptor?.enumerable || !("value" in descriptor)) throw new NativeTypeError(name + " fields must be enumerable data values");
|
|
125
|
+
output[key] = descriptor.value;
|
|
126
|
+
}
|
|
127
|
+
return output;
|
|
128
|
+
}
|
|
129
|
+
function methodOf(value) {
|
|
130
|
+
if (typeof value !== "string") throw new NativeTypeError("HTTP method must be text");
|
|
131
|
+
const method = stringUpper(value);
|
|
132
|
+
if (method.length === 0 || method.length > 32 || !patternMatches(methodPattern, method)
|
|
133
|
+
|| method === "CONNECT" || method === "TRACE" || method === "TRACK") {
|
|
134
|
+
throw new NativeTypeError("HTTP method is invalid or forbidden");
|
|
135
|
+
}
|
|
136
|
+
return method;
|
|
137
|
+
}
|
|
138
|
+
function urlOf(value) {
|
|
139
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 2 * 1024 * 1024) throw new NativeTypeError("HTTP URL must be bounded text");
|
|
140
|
+
requireHttpHost();
|
|
141
|
+
const url = new NativeURL(value);
|
|
142
|
+
const protocol = urlProtocol(url);
|
|
143
|
+
if (protocol !== "http:" && protocol !== "https:") throw new NativeTypeError("HTTP URL must use http or https");
|
|
144
|
+
if (urlUsername(url) || urlPassword(url)) throw new NativeTypeError("HTTP URL credentials are not allowed; use an Authorization header");
|
|
145
|
+
return urlHref(url);
|
|
146
|
+
}
|
|
147
|
+
function headersOf(value) {
|
|
148
|
+
if (value == null) { requireHttpHost(); return new NativeMap(); }
|
|
149
|
+
let size;
|
|
150
|
+
try { requireHttpHost(); size = nativeReflectApply(nativeMapSize, value, []); }
|
|
151
|
+
catch { throw new NativeTypeError("HTTP headers must be Map<string, string>"); }
|
|
152
|
+
if (size > 100) throw new NativeRangeError("HTTP headers cannot exceed 100 fields");
|
|
153
|
+
const output = new NativeMap();
|
|
154
|
+
let units = 0;
|
|
155
|
+
nativeReflectApply(nativeMapForEach, value, [(item, name) => {
|
|
156
|
+
if (typeof name !== "string" || typeof item !== "string" || !patternMatches(headerNamePattern, name) || patternMatches(lineBreakPattern, item)) {
|
|
157
|
+
throw new NativeTypeError("HTTP headers must use valid string names and single-line values");
|
|
158
|
+
}
|
|
159
|
+
units += name.length + item.length;
|
|
160
|
+
if (units > 65536) throw new NativeRangeError("HTTP headers cannot exceed 64 KiB");
|
|
161
|
+
nativeReflectApply(nativeMapSet, output, [name, item]);
|
|
162
|
+
}]);
|
|
163
|
+
return output;
|
|
164
|
+
}
|
|
165
|
+
const secretHeaderValues = new NativeWeakSet();
|
|
166
|
+
const forbiddenSecretHeaders = setOf(["connection", "content-length", "cookie", "cookie2", "host", "proxy-authorization", "te", "trailer", "transfer-encoding", "upgrade"]);
|
|
167
|
+
const allowedOptionFields = setOf(["headers", "secretHeaders", "body", "timeout", "maxBytes"]);
|
|
168
|
+
function secretHeaderName(value) {
|
|
169
|
+
if (typeof value !== "string" || !patternMatches(headerNamePattern, value)
|
|
170
|
+
|| call(nativeSetHas, forbiddenSecretHeaders, [stringLower(value)])) {
|
|
171
|
+
throw new NativeTypeError("HTTP secret header name is invalid or transport-controlled");
|
|
172
|
+
}
|
|
173
|
+
return value;
|
|
174
|
+
}
|
|
175
|
+
function secretEnvironment(value) {
|
|
176
|
+
if (typeof value !== "string" || !patternMatches(secretEnvironmentPattern, value)) {
|
|
177
|
+
throw new NativeTypeError("HTTP secret environment name must be uppercase ASCII text");
|
|
178
|
+
}
|
|
179
|
+
return value;
|
|
180
|
+
}
|
|
181
|
+
function secretPrefix(value) {
|
|
182
|
+
if (typeof value !== "string" || value.length > 256 || patternMatches(lineBreakPattern, value)) {
|
|
183
|
+
throw new NativeTypeError("HTTP secret header prefix must be single-line text of at most 256 characters");
|
|
184
|
+
}
|
|
185
|
+
return value;
|
|
186
|
+
}
|
|
187
|
+
export function secretHeader(name, environment, prefix = "") {
|
|
188
|
+
const value = freeze({
|
|
189
|
+
name: secretHeaderName(name),
|
|
190
|
+
environment: secretEnvironment(environment),
|
|
191
|
+
prefix: secretPrefix(prefix),
|
|
192
|
+
});
|
|
193
|
+
nativeReflectApply(nativeWeakSetAdd, secretHeaderValues, [value]);
|
|
194
|
+
return value;
|
|
195
|
+
}
|
|
196
|
+
function secretHeadersOf(value) {
|
|
197
|
+
if (value == null) return freeze([]);
|
|
198
|
+
if (!call(nativeArrayIsArray, NativeArray, [value]) || value.length > 16) throw new NativeTypeError("HTTP secretHeaders must be a List with at most 16 entries");
|
|
199
|
+
const output = [];
|
|
200
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
201
|
+
const descriptor = ownDescriptor(value, call(NativeString, undefined, [index]));
|
|
202
|
+
if (!descriptor?.enumerable || !("value" in descriptor) || !nativeReflectApply(nativeWeakSetHas, secretHeaderValues, [descriptor.value])) {
|
|
203
|
+
throw new NativeTypeError("HTTP secretHeaders entries must be created by secretHeader");
|
|
204
|
+
}
|
|
205
|
+
arrayPush(output, descriptor.value);
|
|
206
|
+
}
|
|
207
|
+
return freeze(output);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function resolvedSecretHeaders(value, headers) {
|
|
211
|
+
const names = new NativeSet();
|
|
212
|
+
const output = [];
|
|
213
|
+
let units = 0;
|
|
214
|
+
call(nativeMapForEach, headers, [(item, name) => { units += name.length + item.length; }]);
|
|
215
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
216
|
+
const item = value[index];
|
|
217
|
+
const lower = stringLower(item.name);
|
|
218
|
+
let conflict = false;
|
|
219
|
+
call(nativeMapForEach, headers, [(_item, name) => { if (stringLower(name) === lower) conflict = true; }]);
|
|
220
|
+
if (conflict || call(nativeSetHas, names, [lower])) throw new NativeTypeError("HTTP secret header conflicts with another header");
|
|
221
|
+
const secretDescriptor = ownDescriptor(nativeProcessEnvironment, item.environment);
|
|
222
|
+
if (!secretDescriptor || !("value" in secretDescriptor) || typeof secretDescriptor.value !== "string") {
|
|
223
|
+
throw new NativeError("HTTP secret environment variable '" + item.environment + "' is unavailable");
|
|
224
|
+
}
|
|
225
|
+
const headerValue = item.prefix + secretDescriptor.value;
|
|
226
|
+
if (patternMatches(lineBreakPattern, headerValue) || __velarUtf8ByteLength(headerValue) > 65536) {
|
|
227
|
+
throw new NativeRangeError("HTTP secret header value is outside the supported bounds");
|
|
228
|
+
}
|
|
229
|
+
units += item.name.length + headerValue.length;
|
|
230
|
+
if (units > 65536 || value.length + call(nativeMapSize, headers, []) > 100) throw new NativeRangeError("HTTP headers exceed their supported bounds");
|
|
231
|
+
call(nativeSetAdd, names, [lower]);
|
|
232
|
+
arrayPush(output, {name: item.name, value: headerValue});
|
|
233
|
+
}
|
|
234
|
+
return output;
|
|
235
|
+
}
|
|
236
|
+
function jsonBody(value) {
|
|
237
|
+
const text = __velarJsonStringify(value);
|
|
238
|
+
if (__velarUtf8ByteLength(text) > maxBodyBytes) throw new NativeRangeError("HTTP body cannot exceed 16 MiB");
|
|
239
|
+
return text;
|
|
240
|
+
}
|
|
241
|
+
function optionsOf(value) {
|
|
242
|
+
value = plainRecord(value, "HTTP options");
|
|
243
|
+
const keys = ownKeys(value);
|
|
244
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
245
|
+
const key = keys[index];
|
|
246
|
+
if (typeof key !== "string" || !call(nativeSetHas, allowedOptionFields, [key])) throw new NativeTypeError("HTTP options has unknown field '" + key + "'");
|
|
247
|
+
}
|
|
248
|
+
const timeout = value.timeout ?? 120000;
|
|
249
|
+
if (!call(nativeNumberIsSafeInteger, NativeNumber, [timeout]) || timeout < 0 || timeout > 600000) throw new NativeRangeError("HTTP timeout must be an integer from 0 through 600000 milliseconds");
|
|
250
|
+
const maxBytes = value.maxBytes ?? maxBodyBytes;
|
|
251
|
+
if (!call(nativeNumberIsSafeInteger, NativeNumber, [maxBytes]) || maxBytes < 1 || maxBytes > maxResponseBytes) throw new NativeRangeError("HTTP maxBytes must be an integer from 1 through 67108864");
|
|
252
|
+
let headers = headersOf(value.headers);
|
|
253
|
+
const secretHeaders = secretHeadersOf(value.secretHeaders);
|
|
254
|
+
let body = value.body ?? null;
|
|
255
|
+
if (body !== null && __velarHttpBytes.is(body)) {
|
|
256
|
+
body = __velarHttpBytes.parse(body);
|
|
257
|
+
} else if (body !== null && typeof body !== "string") {
|
|
258
|
+
body = jsonBody(body);
|
|
259
|
+
let hasContentType = false;
|
|
260
|
+
call(nativeMapForEach, headers, [(_item, name) => { if (stringLower(name) === "content-type") hasContentType = true; }]);
|
|
261
|
+
if (!hasContentType) call(nativeMapSet, headers, ["content-type", "application/json"]);
|
|
262
|
+
headers = headersOf(headers);
|
|
263
|
+
}
|
|
264
|
+
if (typeof body === "string" && __velarUtf8ByteLength(body) > maxBodyBytes || __velarHttpBytes.is(body) && body.byteLength > maxBodyBytes) throw new NativeRangeError("HTTP body cannot exceed 16 MiB");
|
|
265
|
+
return { headers, secretHeaders, body, timeout, maxBytes };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function headerPairs(value) {
|
|
269
|
+
const output = [];
|
|
270
|
+
call(nativeMapForEach, value, [(item, name) => { arrayPush(output, [name, item]); }]);
|
|
271
|
+
return output;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function hostFields(value, names, label) {
|
|
275
|
+
value = plainRecord(value, label);
|
|
276
|
+
const allowed = setOf(names);
|
|
277
|
+
const keys = ownKeys(value);
|
|
278
|
+
if (keys.length !== names.length) throw new NativeTypeError(label + " is invalid");
|
|
279
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
280
|
+
if (typeof keys[index] !== "string" || !call(nativeSetHas, allowed, [keys[index]])) throw new NativeTypeError(label + " is invalid");
|
|
281
|
+
}
|
|
282
|
+
for (let index = 0; index < names.length; index += 1) {
|
|
283
|
+
if (!ownDescriptor(value, names[index])) throw new NativeTypeError(label + " is invalid");
|
|
284
|
+
}
|
|
285
|
+
return value;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function responseHeaderMap(value) {
|
|
289
|
+
if (!call(nativeArrayIsArray, NativeArray, [value]) || value.length > 100) throw new NativeTypeError("Node host returned invalid HTTP response headers");
|
|
290
|
+
const output = new NativeMap();
|
|
291
|
+
let units = 0;
|
|
292
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
293
|
+
const pair = ownDescriptor(value, call(NativeString, undefined, [index]));
|
|
294
|
+
if (!pair?.enumerable || !("value" in pair) || !call(nativeArrayIsArray, NativeArray, [pair.value]) || pair.value.length !== 2) {
|
|
295
|
+
throw new NativeTypeError("Node host returned invalid HTTP response headers");
|
|
296
|
+
}
|
|
297
|
+
const name = ownDescriptor(pair.value, "0");
|
|
298
|
+
const item = ownDescriptor(pair.value, "1");
|
|
299
|
+
if (!name?.enumerable || !("value" in name) || !item?.enumerable || !("value" in item)
|
|
300
|
+
|| typeof name.value !== "string" || typeof item.value !== "string" || !patternMatches(headerNamePattern, name.value)) {
|
|
301
|
+
throw new NativeTypeError("Node host returned invalid HTTP response headers");
|
|
302
|
+
}
|
|
303
|
+
units += name.value.length + item.value.length;
|
|
304
|
+
if (units > 65536 || call(nativeMapHas, output, [name.value])) throw new NativeRangeError("HTTP response headers exceed their supported bounds");
|
|
305
|
+
call(nativeMapSet, output, [name.value, item.value]);
|
|
306
|
+
}
|
|
307
|
+
return output;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function hostResponse(value, expectedHandle) {
|
|
311
|
+
value = hostFields(value, ["handle", "ok", "status", "statusText", "url", "headers", "body"], "Node HTTP response");
|
|
312
|
+
if (!call(nativeNumberIsSafeInteger, NativeNumber, [value.handle]) || value.handle !== expectedHandle
|
|
313
|
+
|| typeof value.ok !== "boolean" || !call(nativeNumberIsInteger, NativeNumber, [value.status]) || value.status < 100 || value.status > 599
|
|
314
|
+
|| value.ok !== (value.status >= 200 && value.status <= 299) || typeof value.statusText !== "string" || value.statusText.length > 65536
|
|
315
|
+
|| typeof value.url !== "string" || value.url.length === 0 || value.url.length > 2 * 1024 * 1024 || typeof value.body !== "boolean") {
|
|
316
|
+
throw new NativeTypeError("Node host returned invalid HTTP response metadata");
|
|
317
|
+
}
|
|
318
|
+
return {
|
|
319
|
+
ok: value.ok,
|
|
320
|
+
status: value.status,
|
|
321
|
+
statusText: value.statusText,
|
|
322
|
+
url: value.url,
|
|
323
|
+
headers: responseHeaderMap(value.headers),
|
|
324
|
+
body: value.body,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function hostChunk(value) {
|
|
329
|
+
value = hostFields(value, ["done", "text"], "Node HTTP chunk");
|
|
330
|
+
if (typeof value.done !== "boolean" || typeof value.text !== "string") throw new NativeTypeError("Node host returned an invalid HTTP chunk");
|
|
331
|
+
return value;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const activeHttpHandles = new NativeSet();
|
|
335
|
+
let nextHttpHandle = 1;
|
|
336
|
+
|
|
337
|
+
function allocateHttpHandle() {
|
|
338
|
+
if (call(nativeSetSize, activeHttpHandles, []) >= 1024) throw new NativeRangeError("Node HTTP cannot have more than 1024 active requests");
|
|
339
|
+
for (let attempts = 0; attempts <= 1024; attempts += 1) {
|
|
340
|
+
const handle = nextHttpHandle;
|
|
341
|
+
nextHttpHandle = handle >= nativeMaxSafeInteger ? 1 : handle + 1;
|
|
342
|
+
if (!call(nativeSetHas, activeHttpHandles, [handle])) {
|
|
343
|
+
call(nativeSetAdd, activeHttpHandles, [handle]);
|
|
344
|
+
return handle;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
throw new NativeRangeError("Node HTTP request identity space is unavailable");
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function observe(promise, fulfilled, rejected) {
|
|
351
|
+
return call(nativePromiseThen, promise, [fulfilled, rejected]);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function releaseHttpHandle(handle, promise) {
|
|
355
|
+
observe(promise,
|
|
356
|
+
() => { call(nativeSetDelete, activeHttpHandles, [handle]); return null; },
|
|
357
|
+
() => { call(nativeSetDelete, activeHttpHandles, [handle]); return null; });
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export class HttpAbortError extends NativeError {
|
|
361
|
+
constructor(reason) {
|
|
362
|
+
if (reason !== "cancelled" && reason !== "timeout") throw new NativeTypeError("HTTP abort reason must be cancelled or timeout");
|
|
363
|
+
super(reason === "timeout" ? "HTTP request timed out" : "HTTP request cancelled");
|
|
364
|
+
this.name = "HttpAbortError";
|
|
365
|
+
this.reason = reason;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
// D60 rule 149: a module-provided enum carries the same runtime face a declared
|
|
369
|
+
// enum does -- charter section 6 reserves is, parse, and values on every enum,
|
|
370
|
+
// and this one published members only.
|
|
371
|
+
export const HttpTransportPhase = __velarRegisterRuntimeType(freeze({
|
|
372
|
+
request: "request",
|
|
373
|
+
response: "response",
|
|
374
|
+
is(value) { return value === "request" || value === "response"; },
|
|
375
|
+
parse(value) {
|
|
376
|
+
if (!HttpTransportPhase.is(value)) throw new NativeTypeError("Value does not match HttpTransportPhase");
|
|
377
|
+
return value;
|
|
378
|
+
},
|
|
379
|
+
values() { return ["request", "response"]; },
|
|
380
|
+
}));
|
|
381
|
+
export class HttpTransportError extends NativeError {
|
|
382
|
+
constructor(message, phase) {
|
|
383
|
+
if (typeof message !== "string") throw new NativeTypeError("HTTP transport error message must be text");
|
|
384
|
+
if (message.length === 0 || message.length > 65536) throw new NativeRangeError("HTTP transport error messages must contain at most 64 KiB");
|
|
385
|
+
if (phase !== HttpTransportPhase.request && phase !== HttpTransportPhase.response) {
|
|
386
|
+
throw new NativeTypeError("HTTP transport phase must be request or response");
|
|
387
|
+
}
|
|
388
|
+
super(message);
|
|
389
|
+
this.name = "HttpTransportError";
|
|
390
|
+
this.phase = phase;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
export class HttpError extends NativeError {
|
|
394
|
+
constructor(message, status, url, body = null) {
|
|
395
|
+
if (typeof message !== "string") throw new NativeTypeError("HTTP error message must be text");
|
|
396
|
+
if (message.length > 65536) throw new NativeRangeError("HTTP error messages cannot exceed 64 KiB");
|
|
397
|
+
if (!call(nativeNumberIsInteger, NativeNumber, [status]) || status < 100 || status > 599) throw new NativeRangeError("HTTP error status must be an integer from 100 through 599");
|
|
398
|
+
if (typeof url !== "string") throw new NativeTypeError("HTTP error URL must be text");
|
|
399
|
+
if (url.length > 2 * 1024 * 1024) throw new NativeRangeError("HTTP error URLs cannot exceed 2 MiB");
|
|
400
|
+
super(message);
|
|
401
|
+
this.name = "HttpError";
|
|
402
|
+
this.status = status;
|
|
403
|
+
this.url = url;
|
|
404
|
+
this.body = body;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
class HttpResponse {
|
|
409
|
+
constructor(response, request) {
|
|
410
|
+
this.request = request;
|
|
411
|
+
this.body = response.body;
|
|
412
|
+
this.ok = response.ok;
|
|
413
|
+
this.status = response.status;
|
|
414
|
+
this.statusText = response.statusText;
|
|
415
|
+
this.url = response.url;
|
|
416
|
+
this.headers = response.headers;
|
|
417
|
+
this.declaredLength = call(nativeMapGet, response.headers, ["content-length"]) ?? null;
|
|
418
|
+
this.cachedText = null;
|
|
419
|
+
this.cachedBytes = null;
|
|
420
|
+
this.textPending = null;
|
|
421
|
+
this.consuming = false;
|
|
422
|
+
if (!this.body) request.finish();
|
|
423
|
+
}
|
|
424
|
+
async consume(consumer) {
|
|
425
|
+
if (this.cachedText !== null) {
|
|
426
|
+
const result = await consumer(this.cachedText);
|
|
427
|
+
if (result !== null) throw new NativeTypeError("HTTP stream consumer must resolve to null");
|
|
428
|
+
return null;
|
|
429
|
+
}
|
|
430
|
+
if (this.consuming) throw new NativeError("HTTP response body is already being consumed");
|
|
431
|
+
const declared = __velarDeclaredLength(this.declaredLength);
|
|
432
|
+
if (this.body && declared !== null && declared > this.request.options.maxBytes) {
|
|
433
|
+
this.request.finish();
|
|
434
|
+
throw new NativeRangeError("HTTP response exceeds maxBytes");
|
|
435
|
+
}
|
|
436
|
+
this.consuming = true;
|
|
437
|
+
let chunks = 0;
|
|
438
|
+
try {
|
|
439
|
+
if (this.body) {
|
|
440
|
+
while (true) {
|
|
441
|
+
let wire;
|
|
442
|
+
try { wire = await __velarNodeHostInvoke("http.read", [this.request.handle]); }
|
|
443
|
+
catch (error) {
|
|
444
|
+
if (this.request.abortError) throw this.request.abortError;
|
|
445
|
+
if (error instanceof __velarNodeHostHttpTransportError && error.phase === "response") {
|
|
446
|
+
throw new HttpTransportError(error.message, HttpTransportPhase.response);
|
|
447
|
+
}
|
|
448
|
+
throw error;
|
|
449
|
+
}
|
|
450
|
+
const next = hostChunk(wire);
|
|
451
|
+
if (!next.done) {
|
|
452
|
+
chunks += 1;
|
|
453
|
+
if (chunks > maxResponseChunks) throw new NativeRangeError("HTTP responses cannot exceed 1000000 chunks");
|
|
454
|
+
}
|
|
455
|
+
if (next.text) {
|
|
456
|
+
const result = await consumer(next.text);
|
|
457
|
+
if (result !== null) throw new NativeTypeError("HTTP stream consumer must resolve to null");
|
|
458
|
+
}
|
|
459
|
+
if (next.done) break;
|
|
460
|
+
if (this.request.abortError) throw this.request.abortError;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (this.request.abortError) throw this.request.abortError;
|
|
464
|
+
return null;
|
|
465
|
+
} catch (error) {
|
|
466
|
+
if (this.request.abortError) throw this.request.abortError;
|
|
467
|
+
throw error;
|
|
468
|
+
} finally {
|
|
469
|
+
this.request.finish();
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
async streamText(consumer) {
|
|
473
|
+
if (typeof consumer !== "function") throw new NativeTypeError("HTTP streamText requires an async consumer");
|
|
474
|
+
return this.consume(consumer);
|
|
475
|
+
}
|
|
476
|
+
async text() {
|
|
477
|
+
if (this.cachedText !== null) return this.cachedText;
|
|
478
|
+
if (this.textPending !== null) return this.textPending;
|
|
479
|
+
const pending = (async () => {
|
|
480
|
+
const chunks = [];
|
|
481
|
+
await this.consume(async chunk => { arrayPush(chunks, chunk); return null; });
|
|
482
|
+
return arrayJoin(chunks, "");
|
|
483
|
+
})();
|
|
484
|
+
this.textPending = pending;
|
|
485
|
+
try {
|
|
486
|
+
this.cachedText = await pending;
|
|
487
|
+
return this.cachedText;
|
|
488
|
+
} finally {
|
|
489
|
+
if (this.textPending === pending) this.textPending = null;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
async bytes() {
|
|
493
|
+
if (this.cachedBytes !== null) return this.cachedBytes;
|
|
494
|
+
if (this.cachedText !== null) throw new NativeError("HTTP response body was already consumed as text");
|
|
495
|
+
if (this.consuming) throw new NativeError("HTTP response body is already being consumed");
|
|
496
|
+
const declared = __velarDeclaredLength(this.declaredLength);
|
|
497
|
+
if (this.body && declared !== null && declared > this.request.options.maxBytes) { this.request.finish(); throw new NativeRangeError("HTTP response exceeds maxBytes"); }
|
|
498
|
+
this.consuming = true;
|
|
499
|
+
const chunks = [];
|
|
500
|
+
let total = 0;
|
|
501
|
+
try {
|
|
502
|
+
if (this.body) {
|
|
503
|
+
while (true) {
|
|
504
|
+
let wire;
|
|
505
|
+
try { wire = await __velarNodeHostInvoke("http.readBytes", [this.request.handle]); }
|
|
506
|
+
catch (error) { if (this.request.abortError) throw this.request.abortError; if (error instanceof __velarNodeHostHttpTransportError && error.phase === "response") throw new HttpTransportError(error.message, HttpTransportPhase.response); throw error; }
|
|
507
|
+
if (!wire || typeof wire !== "object" || typeof wire.done !== "boolean" || !__velarHttpBytes.is(wire.bytes)) throw new NativeTypeError("Node host returned an invalid HTTP byte chunk");
|
|
508
|
+
if (wire.bytes.byteLength) { total += wire.bytes.byteLength; if (total > this.request.options.maxBytes || chunks.length >= maxResponseChunks) throw new NativeRangeError("HTTP response exceeds its byte or chunk bound"); arrayPush(chunks, wire.bytes); }
|
|
509
|
+
if (wire.done) break;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
const output = new NativeUint8Array(total); let offset = 0;
|
|
513
|
+
for (let index = 0; index < chunks.length; index += 1) { call(nativeUint8ArraySet, output, [chunks[index], offset]); offset += chunks[index].byteLength; }
|
|
514
|
+
this.cachedBytes = __velarHttpBytes.parse(output);
|
|
515
|
+
return this.cachedBytes;
|
|
516
|
+
} finally { this.request.finish(); }
|
|
517
|
+
}
|
|
518
|
+
async json() {
|
|
519
|
+
const text = await this.text();
|
|
520
|
+
return parseJsonText(text);
|
|
521
|
+
}
|
|
522
|
+
async parse(Type) { Type = runtimeHttpType(Type); return Type.parse(await this.json()); }
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
class Request {
|
|
526
|
+
constructor(method, url, options) {
|
|
527
|
+
this.method = methodOf(method);
|
|
528
|
+
this.url = urlOf(url);
|
|
529
|
+
this.options = optionsOf(options);
|
|
530
|
+
if ((this.method === "GET" || this.method === "HEAD") && this.options.body !== null) throw new NativeTypeError(this.method + " requests cannot have a body");
|
|
531
|
+
this.handle = null;
|
|
532
|
+
this.timer = null;
|
|
533
|
+
this.pending = null;
|
|
534
|
+
this.abortError = null;
|
|
535
|
+
this.finished = false;
|
|
536
|
+
}
|
|
537
|
+
finish() {
|
|
538
|
+
if (this.finished) return;
|
|
539
|
+
this.finished = true;
|
|
540
|
+
if (this.timer) { nativeReflectApply(nativeClearTimeout, globalThis, [this.timer]); this.timer = null; }
|
|
541
|
+
if (this.handle !== null) {
|
|
542
|
+
const handle = this.handle;
|
|
543
|
+
this.handle = null;
|
|
544
|
+
releaseHttpHandle(handle, __velarNodeHostInvoke("http.close", [handle]));
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
abort(reason) {
|
|
548
|
+
if (this.finished || this.abortError) return;
|
|
549
|
+
this.abortError = new HttpAbortError(reason);
|
|
550
|
+
if (this.timer) { nativeReflectApply(nativeClearTimeout, globalThis, [this.timer]); this.timer = null; }
|
|
551
|
+
if (this.handle !== null) observe(__velarNodeHostInvoke("http.cancel", [this.handle, reason]), () => null, () => null);
|
|
552
|
+
}
|
|
553
|
+
async response() {
|
|
554
|
+
if (this.pending) return this.pending;
|
|
555
|
+
if (this.abortError) throw this.abortError;
|
|
556
|
+
requireHttpHost();
|
|
557
|
+
this.handle = allocateHttpHandle();
|
|
558
|
+
if (this.options.timeout) this.timer = nativeReflectApply(nativeSetTimeout, globalThis, [() => this.abort("timeout"), this.options.timeout]);
|
|
559
|
+
this.pending = (async () => {
|
|
560
|
+
try {
|
|
561
|
+
let wire;
|
|
562
|
+
try {
|
|
563
|
+
wire = await __velarNodeHostInvoke("http.request", [
|
|
564
|
+
this.handle,
|
|
565
|
+
this.method,
|
|
566
|
+
this.url,
|
|
567
|
+
headerPairs(this.options.headers),
|
|
568
|
+
resolvedSecretHeaders(this.options.secretHeaders, this.options.headers),
|
|
569
|
+
this.options.body,
|
|
570
|
+
this.options.maxBytes,
|
|
571
|
+
]);
|
|
572
|
+
} catch (error) {
|
|
573
|
+
if (this.abortError) throw this.abortError;
|
|
574
|
+
if (error instanceof __velarNodeHostHttpTransportError && error.phase === "request") {
|
|
575
|
+
throw new HttpTransportError(error.message, HttpTransportPhase.request);
|
|
576
|
+
}
|
|
577
|
+
throw error;
|
|
578
|
+
}
|
|
579
|
+
const response = hostResponse(wire, this.handle);
|
|
580
|
+
if (this.abortError) throw this.abortError;
|
|
581
|
+
const wrapped = new HttpResponse(response, this);
|
|
582
|
+
if (!wrapped.ok) {
|
|
583
|
+
const text = await wrapped.text();
|
|
584
|
+
let body = text;
|
|
585
|
+
try { body = text ? parseJsonText(text) : null; } catch {}
|
|
586
|
+
const errorUrl = wrapped.url || this.url;
|
|
587
|
+
throw new HttpError("HTTP " + wrapped.status + " for " + errorUrl, wrapped.status, errorUrl, body);
|
|
588
|
+
}
|
|
589
|
+
return wrapped;
|
|
590
|
+
} catch (error) {
|
|
591
|
+
this.finish();
|
|
592
|
+
if (this.abortError) throw this.abortError;
|
|
593
|
+
throw error;
|
|
594
|
+
}
|
|
595
|
+
})();
|
|
596
|
+
return this.pending;
|
|
597
|
+
}
|
|
598
|
+
async text() { return (await this.response()).text(); }
|
|
599
|
+
async bytes() { return (await this.response()).bytes(); }
|
|
600
|
+
async json() { return (await this.response()).json(); }
|
|
601
|
+
async streamText(consumer) { return (await this.response()).streamText(consumer); }
|
|
602
|
+
async parse(Type) { Type = runtimeHttpType(Type); return Type.parse(await this.json()); }
|
|
603
|
+
cancel() { this.abort("cancelled"); return null; }
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
const createRequest = method => (url, options = {}) => new Request(method, url, options);
|
|
607
|
+
export const http = freeze({
|
|
608
|
+
request(method, url, options = {}) { return new Request(method, url, options); },
|
|
609
|
+
get: createRequest("GET"), post: createRequest("POST"), put: createRequest("PUT"), patch: createRequest("PATCH"), delete: createRequest("DELETE"), head: createRequest("HEAD"),
|
|
610
|
+
});
|
|
611
|
+
`.trimStart();
|
|
612
|
+
//# sourceMappingURL=http-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-runtime.js","sourceRoot":"","sources":["../src/http-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAE7H,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;EAI/C,yBAAyB;EACzB,2BAA2B;EAC3B,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2lBnB,CAAC,SAAS,EAAE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { VELAR_NODE_API_VERSION } from "./compiler.ts";
|
|
2
|
+
export declare const VELAR_NODE_MODULES: readonly ["velar/serve", "velar/fs", "velar/env", "velar/host", "velar/terminal", "velar/path", "velar/process", "velar/http"];
|
|
3
|
+
export interface VelarNodeRuntimeManifest {
|
|
4
|
+
readonly name: "@velarscript/node";
|
|
5
|
+
readonly apiVersion: string;
|
|
6
|
+
readonly modules: typeof VELAR_NODE_MODULES;
|
|
7
|
+
}
|
|
8
|
+
export declare const velarNodeRuntime: VelarNodeRuntimeManifest;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD,eAAO,MAAM,kBAAkB,gIASpB,CAAC;AAEZ,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,kBAAkB,CAAC;CAC7C;AAED,eAAO,MAAM,gBAAgB,EAAE,wBAI7B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { VELAR_NODE_API_VERSION } from "./compiler.js";
|
|
2
|
+
export { VELAR_NODE_API_VERSION } from "./compiler.js";
|
|
3
|
+
export const VELAR_NODE_MODULES = Object.freeze([
|
|
4
|
+
"velar/serve",
|
|
5
|
+
"velar/fs",
|
|
6
|
+
"velar/env",
|
|
7
|
+
"velar/host",
|
|
8
|
+
"velar/terminal",
|
|
9
|
+
"velar/path",
|
|
10
|
+
"velar/process",
|
|
11
|
+
"velar/http",
|
|
12
|
+
]);
|
|
13
|
+
export const velarNodeRuntime = Object.freeze({
|
|
14
|
+
name: "@velarscript/node",
|
|
15
|
+
apiVersion: VELAR_NODE_API_VERSION,
|
|
16
|
+
modules: VELAR_NODE_MODULES,
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9C,aAAa;IACb,UAAU;IACV,WAAW;IACX,YAAY;IACZ,gBAAgB;IAChB,YAAY;IACZ,eAAe;IACf,YAAY;CACJ,CAAC,CAAC;AAQZ,MAAM,CAAC,MAAM,gBAAgB,GAA6B,MAAM,CAAC,MAAM,CAAC;IACtE,IAAI,EAAE,mBAAmB;IACzB,UAAU,EAAE,sBAAsB;IAClC,OAAO,EAAE,kBAAkB;CAC5B,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-host-runtime.d.ts","sourceRoot":"","sources":["../src/node-host-runtime.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,uBAAuB,QAqTvB,CAAC"}
|