@rift-vs/rift-embedded 0.12.1-snapshot.104.g9a93306

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.
Files changed (49) hide show
  1. package/dist/admin.d.ts +134 -0
  2. package/dist/admin.d.ts.map +1 -0
  3. package/dist/admin.js +310 -0
  4. package/dist/admin.js.map +1 -0
  5. package/dist/bridge.d.ts +42 -0
  6. package/dist/bridge.d.ts.map +1 -0
  7. package/dist/bridge.js +53 -0
  8. package/dist/bridge.js.map +1 -0
  9. package/dist/create.d.ts +26 -0
  10. package/dist/create.d.ts.map +1 -0
  11. package/dist/create.js +90 -0
  12. package/dist/create.js.map +1 -0
  13. package/dist/debug-trace.d.ts +2 -0
  14. package/dist/debug-trace.d.ts.map +1 -0
  15. package/dist/debug-trace.js +27 -0
  16. package/dist/debug-trace.js.map +1 -0
  17. package/dist/ffi.d.ts +41 -0
  18. package/dist/ffi.d.ts.map +1 -0
  19. package/dist/ffi.js +165 -0
  20. package/dist/ffi.js.map +1 -0
  21. package/dist/index.d.ts +28 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +21 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/intercept-backend.d.ts +31 -0
  26. package/dist/intercept-backend.d.ts.map +1 -0
  27. package/dist/intercept-backend.js +37 -0
  28. package/dist/intercept-backend.js.map +1 -0
  29. package/dist/native-binding.d.ts +53 -0
  30. package/dist/native-binding.d.ts.map +1 -0
  31. package/dist/native-binding.js +35 -0
  32. package/dist/native-binding.js.map +1 -0
  33. package/dist/native-call.d.ts +77 -0
  34. package/dist/native-call.d.ts.map +1 -0
  35. package/dist/native-call.js +118 -0
  36. package/dist/native-call.js.map +1 -0
  37. package/dist/native.d.ts +76 -0
  38. package/dist/native.d.ts.map +1 -0
  39. package/dist/native.js +304 -0
  40. package/dist/native.js.map +1 -0
  41. package/dist/protocol.d.ts +30 -0
  42. package/dist/protocol.d.ts.map +1 -0
  43. package/dist/protocol.js +7 -0
  44. package/dist/protocol.js.map +1 -0
  45. package/dist/worker.d.ts +13 -0
  46. package/dist/worker.d.ts.map +1 -0
  47. package/dist/worker.js +86 -0
  48. package/dist/worker.js.map +1 -0
  49. package/package.json +49 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Embedded transport worker (issue #8) — a THIN worker_threads wrapper. All correctness logic
3
+ * (sentinel detection, decode-then-free, per-call last-error reads) lives in `native-call.ts`'s
4
+ * `handleCall`, unit-tested there against a fake binding; this file only owns:
5
+ *
6
+ * - building the real `NativeBinding` from koffi at init (via `ffi.ts`, which is where the
7
+ * dynamic `import('koffi')` actually happens),
8
+ * - holding the one piece of state `handleCall` doesn't manage itself — the `RiftHandle*` from
9
+ * `rift_start` — and prepending it to every dispatched call's args,
10
+ * - the message-loop plumbing and graceful/forced shutdown.
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
package/dist/worker.js ADDED
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Embedded transport worker (issue #8) — a THIN worker_threads wrapper. All correctness logic
3
+ * (sentinel detection, decode-then-free, per-call last-error reads) lives in `native-call.ts`'s
4
+ * `handleCall`, unit-tested there against a fake binding; this file only owns:
5
+ *
6
+ * - building the real `NativeBinding` from koffi at init (via `ffi.ts`, which is where the
7
+ * dynamic `import('koffi')` actually happens),
8
+ * - holding the one piece of state `handleCall` doesn't manage itself — the `RiftHandle*` from
9
+ * `rift_start` — and prepending it to every dispatched call's args,
10
+ * - the message-loop plumbing and graceful/forced shutdown.
11
+ */
12
+ import { parentPort } from 'worker_threads';
13
+ import { loadNativeBinding } from './ffi.js';
14
+ import { handleCallMessage, readBuildInfo, readLastErrorMessage } from './native-call.js';
15
+ import { traceFfi } from './debug-trace.js';
16
+ traceFfi('worker:module-load');
17
+ if (!parentPort) {
18
+ throw new Error('src/embedded/worker.js must be run inside a worker_threads Worker');
19
+ }
20
+ const port = parentPort;
21
+ function post(msg) {
22
+ port.postMessage(msg);
23
+ }
24
+ let native = null;
25
+ async function handleInit(libPath) {
26
+ try {
27
+ traceFfi('worker:handleInit');
28
+ const { binding, decode } = await loadNativeBinding(libPath);
29
+ traceFfi('rift_build_info');
30
+ const buildInfo = readBuildInfo(binding, decode);
31
+ traceFfi('rift_start');
32
+ const handle = binding.rift_start();
33
+ if (handle === null) {
34
+ const { message } = readLastErrorMessage(binding, decode, 'rift_start');
35
+ post({ type: 'init-error', message });
36
+ return;
37
+ }
38
+ // Diagnostic hook (#53): `RIFT_FFI_DEBUG_NO_DECODE` neuters the PER-CALL decode only — leaving
39
+ // init's build_info/last-error decode intact so init still succeeds — to isolate whether the
40
+ // strlen SIGSEGV is in koffi.decode(char*) of a call RESULT vs argument marshalling. If the crash
41
+ // disappears with this set, it is the result-decode path. Inert unless the env var is set.
42
+ const callDecode = process.env.RIFT_FFI_DEBUG_NO_DECODE ? () => '' : decode;
43
+ native = { binding, decode: callDecode, handle };
44
+ post({ type: 'ready', buildInfo });
45
+ }
46
+ catch (err) {
47
+ post({ type: 'init-error', message: err instanceof Error ? err.message : String(err) });
48
+ }
49
+ }
50
+ function handleShutdown() {
51
+ if (native) {
52
+ try {
53
+ native.binding.rift_stop(native.handle);
54
+ }
55
+ catch {
56
+ // Best-effort: the process is exiting either way, and a failing rift_stop must not block
57
+ // the worker from ever tearing down (that would defeat the facade's shutdown timeout).
58
+ }
59
+ }
60
+ post({ type: 'shutdown-ack' });
61
+ process.exit(0);
62
+ }
63
+ port.on('message', (raw) => {
64
+ const msg = raw;
65
+ switch (msg.type) {
66
+ case 'init':
67
+ void handleInit(msg.libPath);
68
+ return;
69
+ case 'call': {
70
+ // handleCallMessage rejects pre-init calls, prepends the worker-local handle, and converts any
71
+ // throw into an error result — so a bad call never escapes this handler and hangs the caller.
72
+ traceFfi(msg.fn);
73
+ const response = handleCallMessage(native, { id: msg.id, fn: msg.fn, args: msg.args });
74
+ post({ type: 'result', ...response });
75
+ return;
76
+ }
77
+ case 'shutdown':
78
+ handleShutdown();
79
+ return;
80
+ default: {
81
+ const exhaustive = msg;
82
+ throw new Error(`embedded worker: unhandled message ${JSON.stringify(exhaustive)}`);
83
+ }
84
+ }
85
+ });
86
+ //# sourceMappingURL=worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAG1F,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,QAAQ,CAAC,oBAAoB,CAAC,CAAC;AAE/B,IAAI,CAAC,UAAU,EAAE,CAAC;IAChB,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;AACvF,CAAC;AACD,MAAM,IAAI,GAAG,UAAU,CAAC;AAExB,SAAS,IAAI,CAAC,GAAsB;IAClC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC;AAED,IAAI,MAAM,GAA6B,IAAI,CAAC;AAE5C,KAAK,UAAU,UAAU,CAAC,OAAe;IACvC,IAAI,CAAC;QACH,QAAQ,CAAC,mBAAmB,CAAC,CAAC;QAC9B,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC7D,QAAQ,CAAC,iBAAiB,CAAC,CAAC;QAC5B,MAAM,SAAS,GAAG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,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,GAAY,EAAE,EAAE;IAClC,MAAM,GAAG,GAAG,GAAsB,CAAC;IACnC,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC;QACjB,KAAK,MAAM;YACT,KAAK,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC7B,OAAO;QACT,KAAK,MAAM,CAAC,CAAC,CAAC;YACZ,+FAA+F;YAC/F,8FAA8F;YAC9F,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACjB,MAAM,QAAQ,GAAG,iBAAiB,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;YACvF,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CAAC,CAAC;YACtC,OAAO;QACT,CAAC;QACD,KAAK,UAAU;YACb,cAAc,EAAE,CAAC;YACjB,OAAO;QACT,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,UAAU,GAAU,GAAG,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,sCAAsC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACtF,CAAC;IACH,CAAC;AACH,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@rift-vs/rift-embedded",
3
+ "version": "0.12.1-snapshot.104.g9a93306",
4
+ "description": "Embedded (in-process) engine transport for @rift-vs/rift — koffi FFI binding to librift_ffi. Installing this package is what opts a project into rift.embedded().",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "prepublishOnly": "npm run build",
20
+ "test": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js",
21
+ "lint": "eslint src test --ext .ts",
22
+ "typecheck": "tsc --noEmit"
23
+ },
24
+ "dependencies": {
25
+ "koffi": "^2.9.0"
26
+ },
27
+ "peerDependencies": {
28
+ "@rift-vs/rift": "*"
29
+ },
30
+ "devDependencies": {
31
+ "@rift-vs/rift": "*",
32
+ "typescript": "^5.3.0",
33
+ "jest": "^29.7.0",
34
+ "ts-jest": "^29.1.0",
35
+ "@types/jest": "^29.5.0",
36
+ "@types/node": "^20.10.0",
37
+ "eslint": "^8.56.0"
38
+ },
39
+ "engines": {
40
+ "node": ">=20.0.0"
41
+ },
42
+ "minEngineVersion": "0.12.0",
43
+ "license": "MIT",
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "git+https://github.com/EtaCassiopeia/rift-node.git",
47
+ "directory": "packages/rift-embedded"
48
+ }
49
+ }