@aresdefencelabs/wasm-http-runtime 0.2.0 → 0.2.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.
@@ -56,4 +56,13 @@ addToLibrary({
56
56
  }
57
57
  return (await Module.__aresAbiHttpFetchBlockingAsync(requestJsonCstrPtr)) >>> 0;
58
58
  },
59
+
60
+ abi_http_fetch_non_blocking_async__async: true,
61
+ abi_http_fetch_non_blocking_async: function (requestJsonCstrPtr) {
62
+ if (typeof Module.__aresAbiHttpFetchNonBlockingAsync !== 'function') {
63
+ throw new Error('Module.__aresAbiHttpFetchNonBlockingAsync is not set');
64
+ }
65
+
66
+ Module.__aresAbiHttpFetchNonBlockingAsync(requestJsonCstrPtr);
67
+ },
59
68
  });
@@ -356,6 +356,9 @@ export function createWasmHttpRuntime(config) {
356
356
  };
357
357
  }
358
358
 
359
+ const pendingRequests = new Map();
360
+ let nextRequestId = 1;
361
+
359
362
  async function bootWasm() {
360
363
  if (instancePromise) {
361
364
  return instancePromise;
@@ -459,6 +462,56 @@ export function createWasmHttpRuntime(config) {
459
462
  }
460
463
  },
461
464
 
465
+ __aresAbiHttpFetchNonBlockingAsync(requestJsonCstrPtr) {
466
+ try {
467
+ const requestJson = readCStringFromModule(mod, requestJsonCstrPtr);
468
+ const outbound = JSON.parse(requestJson);
469
+
470
+ if (typeof state.options.beforeOutboundFetch === "function") {
471
+ state.options.beforeOutboundFetch(outbound);
472
+ }
473
+
474
+ Promise.resolve().then(async () => {
475
+ try {
476
+ const response = await fetch(outbound.url, {
477
+ method: outbound.method ?? "GET",
478
+ headers: outbound.headers ?? {},
479
+ body: outbound.body ?? undefined,
480
+ });
481
+
482
+ const bodyText = await response.text();
483
+
484
+ if (typeof state.options.afterOutboundFetch === "function") {
485
+ state.options.afterOutboundFetch(response, bodyText, outbound);
486
+ }
487
+
488
+ if (state.options.debug) {
489
+ console.log("[AresHost] fire-and-forget fetch completed", {
490
+ url: outbound.url,
491
+ status: response.status,
492
+ });
493
+ }
494
+ } catch (error) {
495
+ console.error("[AresHost] fire-and-forget fetch failed:", error);
496
+
497
+ if (typeof state.options.onError === "function") {
498
+ try {
499
+ state.options.onError(error);
500
+ } catch {}
501
+ }
502
+ }
503
+ });
504
+ } catch (error) {
505
+ console.error("[AresHost] fire-and-forget setup failed:", error);
506
+
507
+ if (typeof state.options.onError === "function") {
508
+ try {
509
+ state.options.onError(error);
510
+ } catch {}
511
+ }
512
+ }
513
+ },
514
+
462
515
  __aresAbiHttpResponseGetStatus(responseId) {
463
516
  return getResponseByIdOrEmpty(responseId).status >>> 0;
464
517
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aresdefencelabs/wasm-http-runtime",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
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,