@superdurable/dex 0.1.0 → 0.1.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.
package/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  This package targets Node.js 22 and 24. It provides strongly typed workflow
4
4
  contracts and a Promise-based gRPC Client. The Client and Worker runtime use
5
- `@grpc/grpc-js`. The native BlobCache binding remains a separate runtime phase.
5
+ `@grpc/grpc-js`. Blob caching uses the shared Rust DXBC implementation through
6
+ a Node-API addon.
6
7
 
7
8
  Application values use `Codec<T>`. Flow, Step, RPC, Attribute, and Channel
8
9
  definitions retain their input and output types. Client methods return Promise
@@ -81,12 +82,13 @@ continue importing only from `@superdurable/dex`.
81
82
  - `worker.ts`: Worker gRPC service and lifecycle
82
83
  - `worker-dispatcher.ts`: typed callback dispatch and response mapping
83
84
  - `invocation-context.ts`: invocation-scoped persistence and condition state
84
- - `blob-cache.ts`: injectable cache contract and future N-API binding
85
+ - `blob-cache.ts`: DXBC BlobCache contract and Node-API binding loader
85
86
  - `gen/`: checked-in protobuf and grpc-js bindings
86
87
 
87
- Run `npm test` for runtime contracts and `npm run typecheck` for strict static
88
- contracts. Run `./run-integration-tests.sh` for all 58 IWF compatibility
89
- scenarios against an isolated `dexcli dev` environment. Run
88
+ Run `npm run build:native` once to stage the DXBC Node addon for the current
89
+ platform, then `npm test` for runtime contracts and `npm run typecheck` for
90
+ strict static contracts. Run `./run-integration-tests.sh` for all 58 IWF
91
+ compatibility scenarios against an isolated `dexcli dev` environment. Run
90
92
  `npm run generate:proto` after changing `protos/dex.proto`; `protoc` and its
91
93
  standard protobuf includes must be installed.
92
94
 
@@ -118,11 +120,12 @@ suite's workflow behavior and its 58 assertions run against a real Dex server.
118
120
  ## Releases
119
121
 
120
122
  The npm package is published as [`@superdurable/dex`](https://www.npmjs.com/package/@superdurable/dex).
121
- Update `package.json` and `package-lock.json` to the same version, merge the
122
- change, then publish a GitHub Release tagged `sdk-typescript/vX.Y.Z`. The
123
- release workflow verifies that the tag matches `package.json`, runs type checks
124
- and tests, inspects the tarball, and publishes through npm Trusted Publishing.
125
- Prerelease versions use the `next` npm dist-tag; stable versions use `latest`.
123
+ After the initial bootstrap, publish a GitHub Release tagged
124
+ `sdk-typescript/vX.Y.Z`. The tag is the release version source of truth; CI
125
+ temporarily writes it to `package.json` and `package-lock.json` without
126
+ committing either file. The release workflow then runs type checks and tests,
127
+ inspects the tarball, and publishes through npm Trusted Publishing. Prerelease
128
+ versions use the `next` npm dist-tag; stable versions use `latest`.
126
129
 
127
130
  Trusted Publishing can only be configured after the package exists. Bootstrap
128
131
  the first version from a maintainer workstation with 2FA:
@@ -5,7 +5,11 @@
5
5
  // See the LICENSE file in the repository root.
6
6
  //
7
7
  // SPDX-License-Identifier: LicenseRef-Super-Durable-1.0
8
- import { laterPhase } from "./errors.js";
8
+ import { createRequire } from "node:module";
9
+ import { dirname, join } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+ const require = createRequire(import.meta.url);
12
+ let nativeModule;
9
13
  export function openBlobCache(config) {
10
14
  if (config.directory.length === 0) {
11
15
  throw new TypeError("blob cache directory is required");
@@ -17,6 +21,80 @@ export function openBlobCache(config) {
17
21
  (!Number.isSafeInteger(config.frequencyCounters) || config.frequencyCounters < 0)) {
18
22
  throw new RangeError("blob cache frequencyCounters must be a non-negative safe integer");
19
23
  }
20
- throw laterPhase("BlobCache bridge");
24
+ return new RustBlobCache(config, loadNativeModule());
25
+ }
26
+ class RustBlobCache {
27
+ config;
28
+ native;
29
+ constructor(config, binding) {
30
+ this.config = config;
31
+ this.native = new binding.NativeBlobCache(config.directory, config.maxBytes, config.frequencyCounters ?? 0);
32
+ }
33
+ get(blobId) {
34
+ const payload = this.native.get(blobId);
35
+ return payload === null ? undefined : new Uint8Array(payload);
36
+ }
37
+ put(blobId, payload) {
38
+ return this.native.put(blobId, Buffer.from(payload));
39
+ }
40
+ delete(blobId) {
41
+ this.native.delete(blobId);
42
+ }
43
+ deleteAll() {
44
+ this.native.deleteAll();
45
+ }
46
+ close() {
47
+ this.native.close();
48
+ }
49
+ }
50
+ function loadNativeModule() {
51
+ if (nativeModule !== undefined) {
52
+ return nativeModule;
53
+ }
54
+ const candidates = nativeCandidates();
55
+ const failures = [];
56
+ for (const candidate of candidates) {
57
+ try {
58
+ nativeModule = require(candidate);
59
+ return nativeModule;
60
+ }
61
+ catch (failure) {
62
+ failures.push(`${candidate}: ${failure instanceof Error ? failure.message : String(failure)}`);
63
+ }
64
+ }
65
+ throw new Error(`cannot load the Dex BlobCache native module for ${process.platform}/${process.arch}; ` +
66
+ `set DEX_BLOB_CACHE_NATIVE to an absolute .node path to override packaged natives. ` +
67
+ `Tried:\n${failures.join("\n")}`);
68
+ }
69
+ function nativeCandidates() {
70
+ const override = process.env.DEX_BLOB_CACHE_NATIVE;
71
+ if (override !== undefined && override.length > 0) {
72
+ return [override];
73
+ }
74
+ const packageRoot = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
75
+ const packaged = join(packageRoot, "native", `${operatingSystem()}-${architecture()}`, "dex_blob_cache_node.node");
76
+ return [packaged];
77
+ }
78
+ function operatingSystem() {
79
+ switch (process.platform) {
80
+ case "darwin":
81
+ return "macos";
82
+ case "linux":
83
+ return "linux";
84
+ case "win32":
85
+ return "windows";
86
+ default:
87
+ throw new Error(`unsupported operating system: ${process.platform}`);
88
+ }
89
+ }
90
+ function architecture() {
91
+ switch (process.arch) {
92
+ case "x64":
93
+ return "x86_64";
94
+ case "arm64":
95
+ return "aarch64";
96
+ default:
97
+ throw new Error(`unsupported architecture: ${process.arch}`);
98
+ }
21
99
  }
22
100
  //# sourceMappingURL=blob-cache.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"blob-cache.js","sourceRoot":"","sources":["../../src/blob-cache.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,uDAAuD;AACvD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,wDAAwD;A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C,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9E,MAAM,QAAQ,GAAG,IAAI,CACnB,WAAW,EACX,QAAQ,EACR,GAAG,eAAe,EAAE,IAAI,YAAY,EAAE,EAAE,EACxC,0BAA0B,CAC3B,CAAC;IACF,OAAO,CAAC,QAAQ,CAAC,CAAC;AACpB,CAAC;AAED,SAAS,eAAe;IACtB,QAAQ,OAAO,CAAC,QAAQ,EAAE,CAAC;QACzB,KAAK,QAAQ;YACX,OAAO,OAAO,CAAC;QACjB,KAAK,OAAO;YACV,OAAO,OAAO,CAAC;QACjB,KAAK,OAAO;YACV,OAAO,SAAS,CAAC;QACnB;YACE,MAAM,IAAI,KAAK,CAAC,iCAAiC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IACzE,CAAC;AACH,CAAC;AAED,SAAS,YAAY;IACnB,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;QACrB,KAAK,KAAK;YACR,OAAO,QAAQ,CAAC;QAClB,KAAK,OAAO;YACV,OAAO,SAAS,CAAC;QACnB;YACE,MAAM,IAAI,KAAK,CAAC,6BAA6B,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACjE,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdurable/dex",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "TypeScript SDK for the Dex durable workflow engine",
5
5
  "license": "LicenseRef-Super-Durable-1.0",
6
6
  "repository": {
@@ -18,6 +18,7 @@
18
18
  },
19
19
  "files": [
20
20
  "dist/src",
21
+ "native",
21
22
  "LICENSE"
22
23
  ],
23
24
  "exports": {
@@ -32,13 +33,14 @@
32
33
  },
33
34
  "scripts": {
34
35
  "build": "tsc -p tsconfig.json",
36
+ "build:native": "node scripts/build-native.mjs",
35
37
  "coverage:integration": "./run-integration-tests.sh --coverage",
36
38
  "generate:proto": "node scripts/generate-proto.mjs",
37
- "prepack": "npm run build",
38
- "test:integration": "npm run build && node --test --test-concurrency=1 dist/test/integ/*.integration.test.js",
39
- "test:integration:coverage": "npm run build && c8 node --test --test-concurrency=1 dist/test/integ/*.integration.test.js && node scripts/report-uncovered.mjs coverage/lcov.info",
39
+ "prepack": "npm run build:native && npm run build",
40
+ "test:integration": "npm run build:native && npm run build && node --test --test-concurrency=1 dist/test/integ/*.integration.test.js",
41
+ "test:integration:coverage": "npm run build:native && npm run build && c8 node --test --test-concurrency=1 dist/test/integ/*.integration.test.js && node scripts/report-uncovered.mjs coverage/lcov.info",
40
42
  "typecheck": "tsc -p tsconfig.json --noEmit",
41
- "test": "npm run build && node --test dist/test/*.test.js"
43
+ "test": "npm run build:native && npm run build && node --test dist/test/*.test.js"
42
44
  },
43
45
  "devDependencies": {
44
46
  "@types/node": "^24.0.0",