@aresdefencelabs/wasm-http-runtime 0.2.0 → 0.2.2

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.
@@ -7,6 +7,15 @@ addToLibrary({
7
7
  Module.__aresAbiLog(messagePtr);
8
8
  },
9
9
 
10
+ get_value_from_key__deps: ['$UTF8ToString'],
11
+ get_value_from_key: function (keyPtr) {
12
+ if (typeof Module.__aresAbiGetValueFromKey !== 'function') {
13
+ throw new Error('Module.__aresAbiGetValueFromKey is not set');
14
+ }
15
+
16
+ return Module.__aresAbiGetValueFromKey(keyPtr) >>> 0;
17
+ },
18
+
10
19
  abi_http_get_user_agent_name: function () {
11
20
  if (typeof Module.__aresAbiHttpGetUserAgentName !== 'function') {
12
21
  throw new Error('Module.__aresAbiHttpGetUserAgentName is not set');
@@ -56,4 +65,13 @@ addToLibrary({
56
65
  }
57
66
  return (await Module.__aresAbiHttpFetchBlockingAsync(requestJsonCstrPtr)) >>> 0;
58
67
  },
68
+
69
+ abi_http_fetch_non_blocking_async__async: true,
70
+ abi_http_fetch_non_blocking_async: function (requestJsonCstrPtr) {
71
+ if (typeof Module.__aresAbiHttpFetchNonBlockingAsync !== 'function') {
72
+ throw new Error('Module.__aresAbiHttpFetchNonBlockingAsync is not set');
73
+ }
74
+
75
+ Module.__aresAbiHttpFetchNonBlockingAsync(requestJsonCstrPtr);
76
+ },
59
77
  });
@@ -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;
@@ -386,6 +389,26 @@ export function createWasmHttpRuntime(config) {
386
389
  return instance.exports;
387
390
  },
388
391
 
392
+ __aresAbiGetValueFromKey(keyPtr) {
393
+ const key = readCStringFromModule(mod, keyPtr);
394
+
395
+ const ctx = state.requestContext;
396
+ const env = ctx?.env;
397
+
398
+ if (!env || typeof env !== "object") {
399
+ return 0;
400
+ }
401
+
402
+ const value = env[key];
403
+
404
+ if (value === undefined || value === null) {
405
+ return 0;
406
+ }
407
+
408
+ const written = writeCString(mod, String(value));
409
+ return written.ptr >>> 0;
410
+ },
411
+
389
412
  __aresAbiLog(messagePtr) {
390
413
  const message = readCStringFromModule(mod, messagePtr);
391
414
 
@@ -459,6 +482,56 @@ export function createWasmHttpRuntime(config) {
459
482
  }
460
483
  },
461
484
 
485
+ __aresAbiHttpFetchNonBlockingAsync(requestJsonCstrPtr) {
486
+ try {
487
+ const requestJson = readCStringFromModule(mod, requestJsonCstrPtr);
488
+ const outbound = JSON.parse(requestJson);
489
+
490
+ if (typeof state.options.beforeOutboundFetch === "function") {
491
+ state.options.beforeOutboundFetch(outbound);
492
+ }
493
+
494
+ Promise.resolve().then(async () => {
495
+ try {
496
+ const response = await fetch(outbound.url, {
497
+ method: outbound.method ?? "GET",
498
+ headers: outbound.headers ?? {},
499
+ body: outbound.body ?? undefined,
500
+ });
501
+
502
+ const bodyText = await response.text();
503
+
504
+ if (typeof state.options.afterOutboundFetch === "function") {
505
+ state.options.afterOutboundFetch(response, bodyText, outbound);
506
+ }
507
+
508
+ if (state.options.debug) {
509
+ console.log("[AresHost] fire-and-forget fetch completed", {
510
+ url: outbound.url,
511
+ status: response.status,
512
+ });
513
+ }
514
+ } catch (error) {
515
+ console.error("[AresHost] fire-and-forget fetch failed:", error);
516
+
517
+ if (typeof state.options.onError === "function") {
518
+ try {
519
+ state.options.onError(error);
520
+ } catch {}
521
+ }
522
+ }
523
+ });
524
+ } catch (error) {
525
+ console.error("[AresHost] fire-and-forget setup failed:", error);
526
+
527
+ if (typeof state.options.onError === "function") {
528
+ try {
529
+ state.options.onError(error);
530
+ } catch {}
531
+ }
532
+ }
533
+ },
534
+
462
535
  __aresAbiHttpResponseGetStatus(responseId) {
463
536
  return getResponseByIdOrEmpty(responseId).status >>> 0;
464
537
  },
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.2",
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,
@@ -32,7 +32,9 @@
32
32
  ],
33
33
 
34
34
  "scripts": {
35
- "build": "tsc -p tsconfig.json"
35
+ "build": "tsc -p tsconfig.json",
36
+ "dryrun": "npm pack --dry-run",
37
+ "deploy": "npm publish --access public"
36
38
  },
37
39
  "main": "./dist/index.js",
38
40
  "types": "./dist/index.d.ts",