@aresdefencelabs/wasm-http-runtime 0.2.1 → 0.2.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.
@@ -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');
@@ -1,3 +1,4 @@
1
+ let cloudflareEnv
1
2
  export function createWasmHttpRuntime(config) {
2
3
  const {
3
4
  wasmModule,
@@ -11,6 +12,7 @@ export function createWasmHttpRuntime(config) {
11
12
  onError = null,
12
13
  beforeOutboundFetch = null,
13
14
  afterOutboundFetch = null,
15
+ onInitialise = null,
14
16
  } = config ?? {};
15
17
 
16
18
  if (!wasmModule) {
@@ -39,6 +41,7 @@ export function createWasmHttpRuntime(config) {
39
41
  onError,
40
42
  beforeOutboundFetch,
41
43
  afterOutboundFetch,
44
+ onInitialise
42
45
  },
43
46
  };
44
47
 
@@ -389,6 +392,26 @@ export function createWasmHttpRuntime(config) {
389
392
  return instance.exports;
390
393
  },
391
394
 
395
+ __aresAbiGetValueFromKey(keyPtr) {
396
+ const key = readCStringFromModule(mod, keyPtr);
397
+
398
+ const ctx = state.requestContext;
399
+ const env = ctx?.env;
400
+
401
+ if (!env || typeof env !== "object") {
402
+ return 0;
403
+ }
404
+
405
+ const value = env[key];
406
+
407
+ if (value === undefined || value === null) {
408
+ return 0;
409
+ }
410
+
411
+ const written = writeCString(mod, String(value));
412
+ return written.ptr >>> 0;
413
+ },
414
+
392
415
  __aresAbiLog(messagePtr) {
393
416
  const message = readCStringFromModule(mod, messagePtr);
394
417
 
@@ -552,6 +575,13 @@ export function createWasmHttpRuntime(config) {
552
575
 
553
576
  const appInit = pickExport(mod, ["_app_init", "app_init"]);
554
577
  if (appInit) {
578
+ if (typeof state.options.onInitialise === "function") {
579
+ await state.options.onInitialise({
580
+ state,
581
+ getModule: () => mod,
582
+ });
583
+ }
584
+
555
585
  const rc = await Promise.resolve(appInit());
556
586
  if (rc !== 0) {
557
587
  throw new Error(`WASM app_init failed rc=${rc}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aresdefencelabs/wasm-http-runtime",
3
- "version": "0.2.1",
3
+ "version": "0.2.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,
@@ -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",