@aresdefencelabs/wasm-http-runtime 0.0.5 → 0.0.7
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/dist/abi.d.ts +4 -0
- package/dist/abi.js +41 -26
- package/package.json +1 -1
package/dist/abi.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { RuntimeState } from "./types";
|
|
2
2
|
export declare function createAresAbiImports<Env>(state: RuntimeState<Env>): {
|
|
3
3
|
env: {
|
|
4
|
+
emscripten_notify_memory_growth: () => void;
|
|
5
|
+
emscripten_date_now: () => number;
|
|
6
|
+
emscripten_get_now: () => number;
|
|
7
|
+
abort: (msg?: unknown, file?: unknown, line?: number, col?: number) => never;
|
|
4
8
|
alloc(size: number): number;
|
|
5
9
|
free_mem(ptr: number, size: number): void;
|
|
6
10
|
abi_log(messagePtr: number): void;
|
package/dist/abi.js
CHANGED
|
@@ -66,6 +66,12 @@ function getResponseByIdOrEmpty(state, responseId) {
|
|
|
66
66
|
export function createAresAbiImports(state) {
|
|
67
67
|
return {
|
|
68
68
|
env: {
|
|
69
|
+
emscripten_notify_memory_growth: () => { },
|
|
70
|
+
emscripten_date_now: () => Date.now(),
|
|
71
|
+
emscripten_get_now: () => performance.now(),
|
|
72
|
+
abort: (msg, file, line, col) => {
|
|
73
|
+
throw new Error(`abort: ${String(msg)} @ ${String(file)}:${String(line)}:${String(col)}`);
|
|
74
|
+
},
|
|
69
75
|
alloc(size) {
|
|
70
76
|
const instance = getInstanceOrThrow(state);
|
|
71
77
|
const alloc = getAllocOrThrow(instance);
|
|
@@ -98,33 +104,42 @@ export function createAresAbiImports(state) {
|
|
|
98
104
|
async abi_http_fetch_blocking(requestJsonCstrPtr) {
|
|
99
105
|
const instance = getInstanceOrThrow(state);
|
|
100
106
|
const memory = getMemoryOrThrow(instance);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
try {
|
|
108
|
+
const requestJson = readCString(memory, requestJsonCstrPtr);
|
|
109
|
+
const outbound = JSON.parse(requestJson);
|
|
110
|
+
if (state.options.debug) {
|
|
111
|
+
console.log("[AresWasm] abi_http_fetch_blocking outbound =", outbound);
|
|
112
|
+
}
|
|
113
|
+
const response = await fetch(outbound.url, {
|
|
114
|
+
method: outbound.method ?? "GET",
|
|
115
|
+
headers: outbound.headers,
|
|
116
|
+
body: outbound.body ?? undefined
|
|
117
|
+
});
|
|
118
|
+
const bodyText = await response.text();
|
|
119
|
+
const bodyBytes = utf8ByteLength(bodyText);
|
|
120
|
+
if (bodyBytes > state.options.maxResponseBodyBytes) {
|
|
121
|
+
throw new Error(`HTTP response body too large: ${bodyBytes} bytes exceeds maxResponseBodyBytes=${state.options.maxResponseBodyBytes}`);
|
|
122
|
+
}
|
|
123
|
+
const headers = normalizeHeaders(response.headers);
|
|
124
|
+
const estimatedBytes = estimateResponseBytes({
|
|
125
|
+
bodyText,
|
|
126
|
+
headers
|
|
127
|
+
});
|
|
128
|
+
assertBridgeCapacity(state, estimatedBytes);
|
|
129
|
+
const responseId = state.nextHttpResponseId++;
|
|
130
|
+
state.httpResponses.set(responseId, {
|
|
131
|
+
status: response.status,
|
|
132
|
+
bodyText,
|
|
133
|
+
headers,
|
|
134
|
+
createdAtMs: Date.now(),
|
|
135
|
+
estimatedBytes
|
|
136
|
+
});
|
|
137
|
+
return responseId >>> 0;
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
console.error("[AresWasm] abi_http_fetch_blocking failed:", error);
|
|
141
|
+
return 0;
|
|
112
142
|
}
|
|
113
|
-
const headers = normalizeHeaders(response.headers);
|
|
114
|
-
const estimatedBytes = estimateResponseBytes({
|
|
115
|
-
bodyText,
|
|
116
|
-
headers
|
|
117
|
-
});
|
|
118
|
-
assertBridgeCapacity(state, estimatedBytes);
|
|
119
|
-
const responseId = state.nextHttpResponseId++;
|
|
120
|
-
state.httpResponses.set(responseId, {
|
|
121
|
-
status: response.status,
|
|
122
|
-
bodyText,
|
|
123
|
-
headers,
|
|
124
|
-
createdAtMs: Date.now(),
|
|
125
|
-
estimatedBytes
|
|
126
|
-
});
|
|
127
|
-
return responseId >>> 0;
|
|
128
143
|
},
|
|
129
144
|
abi_http_response_get_status(responseId) {
|
|
130
145
|
return getResponseByIdOrEmpty(state, responseId).status >>> 0;
|
package/package.json
CHANGED