@aresdefencelabs/wasm-http-runtime 0.1.2 → 0.1.3

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 CHANGED
@@ -9,7 +9,7 @@ export declare function createAresAbiImports<Env>(state: RuntimeState<Env>): {
9
9
  free_mem(ptr: number, size: number): void;
10
10
  abi_log(messagePtr: number): void;
11
11
  abi_http_get_user_agent_name(): number;
12
- abi_http_fetch_blocking_async: (requestJsonCstrPtr: number) => Promise<number>;
12
+ abi_http_fetch_blocking_async(requestJsonCstrPtr: number): number;
13
13
  abi_http_response_get_status(responseId: number): number;
14
14
  abi_http_response_get_body_len(responseId: number): number;
15
15
  abi_http_response_copy_body(responseId: number, outPtr: number, maxLen: number): number;
package/dist/abi.js CHANGED
@@ -101,46 +101,52 @@ export function createAresAbiImports(state) {
101
101
  const alloc = getAllocOrThrow(instance);
102
102
  return writeCString(memory, alloc, userAgent);
103
103
  },
104
- abi_http_fetch_blocking_async: async (requestJsonCstrPtr) => {
105
- const instance = getInstanceOrThrow(state);
106
- const memory = getMemoryOrThrow(instance);
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);
104
+ abi_http_fetch_blocking_async(requestJsonCstrPtr) {
105
+ const Asyncify = globalThis.Asyncify;
106
+ if (!Asyncify?.handleAsync) {
107
+ throw new Error("Asyncify.handleAsync is not available in this runtime");
108
+ }
109
+ return Asyncify.handleAsync(async () => {
110
+ const instance = getInstanceOrThrow(state);
111
+ const memory = getMemoryOrThrow(instance);
112
+ try {
113
+ const requestJson = readCString(memory, requestJsonCstrPtr);
114
+ const outbound = JSON.parse(requestJson);
115
+ if (state.options.debug) {
116
+ console.log("[AresWasm] abi_http_fetch_blocking outbound =", outbound);
117
+ }
118
+ const response = await fetch(outbound.url, {
119
+ method: outbound.method ?? "GET",
120
+ headers: outbound.headers,
121
+ body: outbound.body ?? undefined
122
+ });
123
+ console.log("[AresWasm] abi_http_fetch_blocking fetch completed, status =", response.status);
124
+ const bodyText = await response.text();
125
+ const bodyBytes = utf8ByteLength(bodyText);
126
+ if (bodyBytes > state.options.maxResponseBodyBytes) {
127
+ throw new Error(`HTTP response body too large: ${bodyBytes} bytes exceeds maxResponseBodyBytes=${state.options.maxResponseBodyBytes}`);
128
+ }
129
+ const headers = normalizeHeaders(response.headers);
130
+ const estimatedBytes = estimateResponseBytes({
131
+ bodyText,
132
+ headers
133
+ });
134
+ assertBridgeCapacity(state, estimatedBytes);
135
+ const responseId = state.nextHttpResponseId++;
136
+ state.httpResponses.set(responseId, {
137
+ status: response.status,
138
+ bodyText,
139
+ headers,
140
+ createdAtMs: Date.now(),
141
+ estimatedBytes
142
+ });
143
+ return responseId >>> 0;
112
144
  }
113
- const response = await fetch(outbound.url, {
114
- method: outbound.method ?? "GET",
115
- headers: outbound.headers,
116
- body: outbound.body ?? undefined
117
- });
118
- console.log("[AresWasm] abi_http_fetch_blocking fetch completed, status =", response.status);
119
- const bodyText = await response.text();
120
- const bodyBytes = utf8ByteLength(bodyText);
121
- if (bodyBytes > state.options.maxResponseBodyBytes) {
122
- throw new Error(`HTTP response body too large: ${bodyBytes} bytes exceeds maxResponseBodyBytes=${state.options.maxResponseBodyBytes}`);
145
+ catch (error) {
146
+ console.error("[AresWasm] abi_http_fetch_blocking failed:", error);
147
+ return 0;
123
148
  }
124
- const headers = normalizeHeaders(response.headers);
125
- const estimatedBytes = estimateResponseBytes({
126
- bodyText,
127
- headers
128
- });
129
- assertBridgeCapacity(state, estimatedBytes);
130
- const responseId = state.nextHttpResponseId++;
131
- state.httpResponses.set(responseId, {
132
- status: response.status,
133
- bodyText,
134
- headers,
135
- createdAtMs: Date.now(),
136
- estimatedBytes
137
- });
138
- return responseId >>> 0;
139
- }
140
- catch (error) {
141
- console.error("[AresWasm] abi_http_fetch_blocking failed:", error);
142
- return 0;
143
- }
149
+ });
144
150
  },
145
151
  abi_http_response_get_status(responseId) {
146
152
  return getResponseByIdOrEmpty(state, responseId).status >>> 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aresdefencelabs/wasm-http-runtime",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Runtime adapter that connects C++ WebAssembly workers to the Cloudflare Workers runtime via an ABI bridge.",
5
5
  "type": "module",
6
6
  "private": false,