@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
package/dist/create.js ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * `rift.embedded()` wiring (issue #10): resolves the `librift_ffi` cdylib, loads the `NativeEngine`,
3
+ * runs the version/feature preflight, and returns the same `RiftEngine` facade `rift.connect`/
4
+ * `rift.spawn` produce — backed by `EmbeddedAdmin` (./admin.ts) instead of an HTTP client.
5
+ *
6
+ * `loadNativeEngine` is injectable specifically so this whole pipeline — preflight, registry, stub
7
+ * routing, and the lazy admin-plane bridge — is unit-testable against a FAKE `NativeEngineLike` with
8
+ * no real cdylib/koffi involved (see test/unit/embedded-admin.test.ts). The default wiring (real
9
+ * `resolveCdylib` + `NativeEngine.load`) is only exercised by the real-cdylib integration suite,
10
+ * which self-skips without `RIFT_FFI_LIB`.
11
+ */
12
+ import { Engine, versionIssue, MIN_ENGINE_VERSION } from '@rift-vs/rift/internal';
13
+ import { EngineVersionError, NativeLibraryError } from '@rift-vs/rift';
14
+ import { resolveCdylib } from '@rift-vs/rift';
15
+ import { EmbeddedInterceptBackend } from './intercept-backend.js';
16
+ import { NativeEngine } from './native.js';
17
+ import { EmbeddedAdmin } from './admin.js';
18
+ /**
19
+ * `native.buildInfo` is the FFI's build-info payload, JSON-encoded (`{version, commit?, builtAt?,
20
+ * features[]}`) — distinct from the free-text handshake string `NativeEngine`'s own init log uses
21
+ * internally (issue #8); this is the richer payload the version/feature preflight below needs.
22
+ */
23
+ function parseBuildInfo(raw) {
24
+ let parsed;
25
+ try {
26
+ parsed = JSON.parse(raw);
27
+ }
28
+ catch (cause) {
29
+ throw new NativeLibraryError(`embedded engine reported non-JSON build info: ${raw}`, { cause });
30
+ }
31
+ if (parsed === null || typeof parsed !== 'object') {
32
+ throw new NativeLibraryError(`embedded engine reported malformed build info: ${raw}`);
33
+ }
34
+ const obj = parsed;
35
+ if (typeof obj['version'] !== 'string') {
36
+ throw new NativeLibraryError(`embedded engine build info is missing "version": ${raw}`);
37
+ }
38
+ const features = obj['features'];
39
+ return {
40
+ version: obj['version'],
41
+ commit: typeof obj['commit'] === 'string' ? obj['commit'] : undefined,
42
+ builtAt: typeof obj['builtAt'] === 'string' ? obj['builtAt'] : undefined,
43
+ features: Array.isArray(features) ? features.filter((f) => typeof f === 'string') : [],
44
+ };
45
+ }
46
+ function runVersionPreflight(buildInfo, versionCheck) {
47
+ if (versionCheck === 'off')
48
+ return;
49
+ const issue = versionIssue(buildInfo.version);
50
+ if (issue === undefined)
51
+ return;
52
+ if (versionCheck === 'fail') {
53
+ throw new EngineVersionError(buildInfo.version, MIN_ENGINE_VERSION, issue);
54
+ }
55
+ console.warn(`rift: ${issue}; skipping compatibility gate`);
56
+ }
57
+ function runFeaturePreflight(buildInfo, requireFeatures) {
58
+ if (requireFeatures === undefined)
59
+ return;
60
+ const missing = requireFeatures.find((f) => !buildInfo.features.includes(f));
61
+ if (missing === undefined)
62
+ return;
63
+ throw new EngineVersionError(buildInfo.version, MIN_ENGINE_VERSION, `this cdylib was built without '${missing}' — requireFeatures needs it. This is a build-variant ` +
64
+ `property (rebuild or download a cdylib variant with '${missing}' enabled), not a version mismatch.`);
65
+ }
66
+ export async function createEmbeddedEngine(options = {}, deps = {}) {
67
+ const loadNativeEngine = deps.loadNativeEngine ??
68
+ ((p) => NativeEngine.load(p, { keepAlive: options.keepAlive }));
69
+ const libPath = deps.loadNativeEngine !== undefined
70
+ ? (options.libPath ?? 'injected://native-engine')
71
+ : await resolveCdylib({
72
+ libPath: options.libPath,
73
+ version: options.version,
74
+ download: options.download,
75
+ env: options.cacheDir !== undefined ? { ...process.env, RIFT_CACHE_DIR: options.cacheDir } : undefined,
76
+ });
77
+ const native = await loadNativeEngine(libPath);
78
+ const buildInfo = parseBuildInfo(native.buildInfo);
79
+ runVersionPreflight(buildInfo, options.versionCheck ?? 'fail');
80
+ runFeaturePreflight(buildInfo, options.requireFeatures);
81
+ const admin = new EmbeddedAdmin({ native, buildInfo, startAdminPlane: deps.startAdminPlane });
82
+ // No `onClose` hook: `Engine.close()` already awaits `adminClient.close()` (== `admin.close()`)
83
+ // unconditionally — there's no separate spawned process to tear down for the embedded transport.
84
+ return new Engine(admin, 'embedded', {
85
+ buildInfo: async () => admin.buildInfo,
86
+ adminUrl: () => admin.adminUrl(),
87
+ interceptBackend: new EmbeddedInterceptBackend(native),
88
+ });
89
+ }
90
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,kBAAkB,EAAkB,MAAM,wBAAwB,CAAC;AAClG,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAA+C,MAAM,YAAY,CAAC;AAoBxF;;;;GAIG;AACH,SAAS,cAAc,CAAC,GAAW;IACjC,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,kBAAkB,CAAC,iDAAiD,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAClG,CAAC;IACD,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAClD,MAAM,IAAI,kBAAkB,CAAC,kDAAkD,GAAG,EAAE,CAAC,CAA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D,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,YAAY,IAAI,MAAM,CAAC,CAAC;IAC/D,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAExD,MAAM,KAAK,GAAG,IAAI,aAAa,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC;IAE9F,gGAAgG;IAChG,iGAAiG;IACjG,OAAO,IAAI,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE;QACnC,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,SAAS;QACtC,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE;QAChC,gBAAgB,EAAE,IAAI,wBAAwB,CAAC,MAAM,CAAC;KACvD,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function traceFfi(label: string): void;
2
+ //# sourceMappingURL=debug-trace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-trace.d.ts","sourceRoot":"","sources":["../src/debug-trace.ts"],"names":[],"mappings":"AAgBA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAQ5C"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Diagnostic-only tracing for the embedded FFI segfault (#53). When `RIFT_FFI_DEBUG_TRACE` is set,
3
+ * {@link traceFfi} records a label at each native step so that, if the next step segfaults, the last
4
+ * label names where it died (which koffi bind, or which call). Writes go two ways, both synchronous
5
+ * so a crash can't lose the last line:
6
+ * - `writeSync(2, …)` to stderr — appears inline in the CI job log, independent of any file path
7
+ * or the jest worker/env plumbing (the prior file-only approach came up empty);
8
+ * - `appendFileSync(RIFT_FFI_DEBUG_TRACE, …)` when that env var names a file, for the artifact.
9
+ * Inert unless `RIFT_FFI_DEBUG_TRACE` is set; only the embedded debug CI lane sets it, so production
10
+ * behaviour is unchanged.
11
+ */
12
+ import { appendFileSync, writeSync } from 'fs';
13
+ const TRACE_FILE = process.env.RIFT_FFI_DEBUG_TRACE;
14
+ const ENABLED = TRACE_FILE !== undefined && TRACE_FILE !== '';
15
+ export function traceFfi(label) {
16
+ if (!ENABLED)
17
+ return;
18
+ try {
19
+ writeSync(2, `[ffi-trace] ${label}\n`);
20
+ }
21
+ catch {
22
+ // stderr may be unavailable in some worker configs — the file append below is the fallback.
23
+ }
24
+ if (TRACE_FILE)
25
+ appendFileSync(TRACE_FILE, `${label}\n`);
26
+ }
27
+ //# sourceMappingURL=debug-trace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-trace.js","sourceRoot":"","sources":["../src/debug-trace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAE/C,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;AACpD,MAAM,OAAO,GAAG,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,EAAE,CAAC;AAE9D,MAAM,UAAU,QAAQ,CAAC,KAAa;IACpC,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,IAAI,CAAC;QACH,SAAS,CAAC,CAAC,EAAE,eAAe,KAAK,IAAI,CAAC,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,4FAA4F;IAC9F,CAAC;IACD,IAAI,UAAU;QAAE,cAAc,CAAC,UAAU,EAAE,GAAG,KAAK,IAAI,CAAC,CAAC;AAC3D,CAAC"}
package/dist/ffi.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Real koffi-backed `NativeBinding` for `librift_ffi` (issue #8).
3
+ *
4
+ * `koffi` is dynamically `import()`ed ONLY from inside {@link loadNativeBinding}, which itself is
5
+ * only ever called by `worker.ts` at init (i.e. when a caller actually opts into the embedded
6
+ * transport). The SDK core — and every other module in this package — stays zero-dependency;
7
+ * koffi's absence, or the cdylib's absence/incompatibility, surfaces as a rejected Promise at that
8
+ * opt-in moment, never as a failure to `import` this module or any module that (transitively)
9
+ * imports it.
10
+ *
11
+ * Declares all 26 `librift_ffi` C-ABI v2 symbols. Every `char*`-typed result is declared as a raw
12
+ * pointer (`'void *'`), never koffi's auto-decoding `'string'` result type — `native-call.ts`'s
13
+ * `handleCall` is the only thing that decides when to decode and free.
14
+ *
15
+ * Reading the string back is done with `koffi.decode(ptr, 'char', -1)`, NOT `koffi.decode(ptr,
16
+ * 'string')` (#53). Given a raw `char*`, koffi's `'string'`/`'str'`/`'char *'` decode types treat
17
+ * the argument as a pointer-TO-a-string (`char**`) and dereference once too many — they read the
18
+ * first sizeof(ptr) bytes of the JSON, take those bytes as an address, and `strlen` them, which
19
+ * SIGSEGVs. `('char', -1)` reads a NUL-terminated char array AT the pointer, which is what the ABI
20
+ * actually returns, while keeping the raw `'void *'` so `rift_free` still owns the buffer.
21
+ */
22
+ import type { NativeBinding } from './native-binding.js';
23
+ import type { Decode } from './native-call.js';
24
+ /** Message for a v1 (pre-FFI) engine build: `rift_build_info` is the v2-probe symbol — its
25
+ * absence means the loaded cdylib predates the C-ABI v2 surface this SDK requires. */
26
+ export declare function v1AbiMessage(libPath: string, minEngineVersion: string): string;
27
+ /** Message for a missing file / non-library path — wraps koffi's `load()` failure with the path
28
+ * and the precise underlying cause, so a copy-pasted error names the exact broken input. */
29
+ export declare function loadFailureMessage(libPath: string, cause: unknown): string;
30
+ export interface LoadedNative {
31
+ binding: NativeBinding;
32
+ decode: Decode;
33
+ }
34
+ /**
35
+ * Loads `librift_ffi` from `libPath` and wires up every C-ABI v2 symbol as a `NativeBinding`.
36
+ * Never throws synchronously — always rejects — with a precise, user-actionable message for each
37
+ * of the three failure modes: koffi itself unresolvable (not installed), the path isn't a loadable
38
+ * library (missing file / wrong format), or the library is missing `rift_build_info` (ABI v1).
39
+ */
40
+ export declare function loadNativeBinding(libPath: string): Promise<LoadedNative>;
41
+ //# sourceMappingURL=ffi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ffi.d.ts","sourceRoot":"","sources":["../src/ffi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAOH,OAAO,KAAK,EAAE,aAAa,EAAa,MAAM,qBAAqB,CAAC;AACpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAoB/C;sFACsF;AACtF,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAE9E;AAED;4FAC4F;AAC5F,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAE1E;AAOD,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,aAAa,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAyH9E"}
package/dist/ffi.js ADDED
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Real koffi-backed `NativeBinding` for `librift_ffi` (issue #8).
3
+ *
4
+ * `koffi` is dynamically `import()`ed ONLY from inside {@link loadNativeBinding}, which itself is
5
+ * only ever called by `worker.ts` at init (i.e. when a caller actually opts into the embedded
6
+ * transport). The SDK core — and every other module in this package — stays zero-dependency;
7
+ * koffi's absence, or the cdylib's absence/incompatibility, surfaces as a rejected Promise at that
8
+ * opt-in moment, never as a failure to `import` this module or any module that (transitively)
9
+ * imports it.
10
+ *
11
+ * Declares all 26 `librift_ffi` C-ABI v2 symbols. Every `char*`-typed result is declared as a raw
12
+ * pointer (`'void *'`), never koffi's auto-decoding `'string'` result type — `native-call.ts`'s
13
+ * `handleCall` is the only thing that decides when to decode and free.
14
+ *
15
+ * Reading the string back is done with `koffi.decode(ptr, 'char', -1)`, NOT `koffi.decode(ptr,
16
+ * 'string')` (#53). Given a raw `char*`, koffi's `'string'`/`'str'`/`'char *'` decode types treat
17
+ * the argument as a pointer-TO-a-string (`char**`) and dereference once too many — they read the
18
+ * first sizeof(ptr) bytes of the JSON, take those bytes as an address, and `strlen` them, which
19
+ * SIGSEGVs. `('char', -1)` reads a NUL-terminated char array AT the pointer, which is what the ABI
20
+ * actually returns, while keeping the raw `'void *'` so `rift_free` still owns the buffer.
21
+ */
22
+ import { readFileSync } from 'fs';
23
+ import { fileURLToPath } from 'url';
24
+ import { dirname, join } from 'path';
25
+ import { NativeLibraryError } from '@rift-vs/rift';
26
+ import { traceFfi } from './debug-trace.js';
27
+ const here = dirname(fileURLToPath(import.meta.url));
28
+ const packageJson = JSON.parse(readFileSync(join(here, '..', 'package.json'), 'utf8'));
29
+ const MIN_ENGINE_VERSION = packageJson.minEngineVersion ?? '0.0.0';
30
+ const PTR = 'void *';
31
+ const STR = 'str';
32
+ function causeMessage(err) {
33
+ return err instanceof Error ? err.message : String(err);
34
+ }
35
+ /** Message for a v1 (pre-FFI) engine build: `rift_build_info` is the v2-probe symbol — its
36
+ * absence means the loaded cdylib predates the C-ABI v2 surface this SDK requires. */
37
+ export function v1AbiMessage(libPath, minEngineVersion) {
38
+ return `ABI v1 library at ${libPath} — rift-node requires C-ABI v2 (rift >= ${minEngineVersion})`;
39
+ }
40
+ /** Message for a missing file / non-library path — wraps koffi's `load()` failure with the path
41
+ * and the precise underlying cause, so a copy-pasted error names the exact broken input. */
42
+ export function loadFailureMessage(libPath, cause) {
43
+ return `Failed to load native library at ${libPath}: ${causeMessage(cause)}`;
44
+ }
45
+ async function importKoffi() {
46
+ const mod = await import('koffi');
47
+ return mod.default;
48
+ }
49
+ /**
50
+ * Loads `librift_ffi` from `libPath` and wires up every C-ABI v2 symbol as a `NativeBinding`.
51
+ * Never throws synchronously — always rejects — with a precise, user-actionable message for each
52
+ * of the three failure modes: koffi itself unresolvable (not installed), the path isn't a loadable
53
+ * library (missing file / wrong format), or the library is missing `rift_build_info` (ABI v1).
54
+ */
55
+ export async function loadNativeBinding(libPath) {
56
+ let koffi;
57
+ try {
58
+ koffi = await importKoffi();
59
+ }
60
+ catch (err) {
61
+ throw new NativeLibraryError(`The embedded transport requires the optional "koffi" dependency, which is not installed: ${causeMessage(err)}`, { path: libPath, cause: err });
62
+ }
63
+ let lib;
64
+ try {
65
+ traceFfi(`koffi.load(${libPath})`);
66
+ lib = koffi.load(libPath);
67
+ traceFfi('koffi.load:ok');
68
+ }
69
+ catch (err) {
70
+ throw new NativeLibraryError(loadFailureMessage(libPath, err), { path: libPath, cause: err });
71
+ }
72
+ traceFfi('koffi.opaque(RiftHandle)');
73
+ const handlePtr = koffi.pointer(koffi.opaque('RiftHandle'));
74
+ const bindProbe = (name, result, args) => {
75
+ try {
76
+ traceFfi(`bind:${name}`);
77
+ return lib.func(name, result, args);
78
+ }
79
+ catch (err) {
80
+ throw new NativeLibraryError(v1AbiMessage(libPath, MIN_ENGINE_VERSION), { path: libPath, cause: err });
81
+ }
82
+ };
83
+ const bindRequired = (name, result, args) => {
84
+ try {
85
+ traceFfi(`bind:${name}`);
86
+ return lib.func(name, result, args);
87
+ }
88
+ catch (err) {
89
+ throw new NativeLibraryError(`librift_ffi at ${libPath} is missing the "${name}" symbol — this build may be corrupt or incomplete.`, { path: libPath, cause: err });
90
+ }
91
+ };
92
+ // rift_build_info is resolved FIRST, and specially: its absence is the v2-probe failure. Every
93
+ // symbol resolved after it is presumed to be on a genuine v2 library, so a missing symbol past
94
+ // this point means a corrupt/incomplete build, not an old ABI.
95
+ const buildInfoFn = bindProbe('rift_build_info', PTR, []);
96
+ const fn = {
97
+ rift_start: bindRequired('rift_start', handlePtr, []),
98
+ rift_stop: bindRequired('rift_stop', 'void', [handlePtr]),
99
+ rift_create_imposter: bindRequired('rift_create_imposter', 'uint16', [handlePtr, STR]),
100
+ rift_replace_stubs: bindRequired('rift_replace_stubs', 'int32', [handlePtr, 'uint16', STR]),
101
+ rift_delete_imposter: bindRequired('rift_delete_imposter', 'int32', [handlePtr, 'uint16']),
102
+ rift_delete_all: bindRequired('rift_delete_all', 'int32', [handlePtr]),
103
+ rift_apply_config: bindRequired('rift_apply_config', PTR, [handlePtr, STR]),
104
+ rift_recorded: bindRequired('rift_recorded', PTR, [handlePtr, 'uint16']),
105
+ rift_stub_warnings: bindRequired('rift_stub_warnings', PTR, [handlePtr, 'uint16']),
106
+ rift_flow_state_get: bindRequired('rift_flow_state_get', PTR, [handlePtr, 'uint16', STR, STR]),
107
+ rift_flow_state_put: bindRequired('rift_flow_state_put', 'int32', [handlePtr, 'uint16', STR, STR, STR]),
108
+ rift_flow_state_delete: bindRequired('rift_flow_state_delete', 'int32', [handlePtr, 'uint16', STR, STR]),
109
+ rift_space_add_stub: bindRequired('rift_space_add_stub', 'int32', [handlePtr, 'uint16', STR, STR]),
110
+ rift_space_list_stubs: bindRequired('rift_space_list_stubs', PTR, [handlePtr, 'uint16', STR]),
111
+ rift_space_delete: bindRequired('rift_space_delete', 'int32', [handlePtr, 'uint16', STR]),
112
+ rift_space_recorded: bindRequired('rift_space_recorded', PTR, [handlePtr, 'uint16', STR]),
113
+ rift_start_intercept: bindRequired('rift_start_intercept', PTR, [handlePtr, STR]),
114
+ rift_intercept_add_rules: bindRequired('rift_intercept_add_rules', 'int32', [handlePtr, STR]),
115
+ rift_intercept_clear_rules: bindRequired('rift_intercept_clear_rules', 'int32', [handlePtr]),
116
+ rift_intercept_list_rules: bindRequired('rift_intercept_list_rules', PTR, [handlePtr]),
117
+ rift_intercept_ca_pem: bindRequired('rift_intercept_ca_pem', PTR, [handlePtr]),
118
+ rift_intercept_export_truststore: bindRequired('rift_intercept_export_truststore', 'int32', [
119
+ handlePtr,
120
+ STR,
121
+ STR,
122
+ STR,
123
+ ]),
124
+ rift_serve_admin: bindRequired('rift_serve_admin', PTR, [handlePtr, STR]),
125
+ rift_build_info: buildInfoFn,
126
+ rift_last_error: bindRequired('rift_last_error', PTR, []),
127
+ rift_free: bindRequired('rift_free', 'void', [PTR]),
128
+ };
129
+ traceFfi('all-26-bound');
130
+ const binding = {
131
+ rift_start: () => fn.rift_start(),
132
+ rift_stop: (h) => {
133
+ fn.rift_stop(h);
134
+ },
135
+ rift_create_imposter: (h, json) => fn.rift_create_imposter(h, json),
136
+ rift_replace_stubs: (h, port, json) => fn.rift_replace_stubs(h, port, json),
137
+ rift_delete_imposter: (h, port) => fn.rift_delete_imposter(h, port),
138
+ rift_delete_all: (h) => fn.rift_delete_all(h),
139
+ rift_apply_config: (h, json) => fn.rift_apply_config(h, json),
140
+ rift_recorded: (h, port) => fn.rift_recorded(h, port),
141
+ rift_stub_warnings: (h, port) => fn.rift_stub_warnings(h, port),
142
+ rift_flow_state_get: (h, port, flowId, key) => fn.rift_flow_state_get(h, port, flowId, key),
143
+ rift_flow_state_put: (h, port, flowId, key, valueJson) => fn.rift_flow_state_put(h, port, flowId, key, valueJson),
144
+ rift_flow_state_delete: (h, port, flowId, key) => fn.rift_flow_state_delete(h, port, flowId, key),
145
+ rift_space_add_stub: (h, port, flowId, json) => fn.rift_space_add_stub(h, port, flowId, json),
146
+ rift_space_list_stubs: (h, port, flowId) => fn.rift_space_list_stubs(h, port, flowId),
147
+ rift_space_delete: (h, port, flowId) => fn.rift_space_delete(h, port, flowId),
148
+ rift_space_recorded: (h, port, flowId) => fn.rift_space_recorded(h, port, flowId),
149
+ rift_start_intercept: (h, optionsJson) => fn.rift_start_intercept(h, optionsJson),
150
+ rift_intercept_add_rules: (h, json) => fn.rift_intercept_add_rules(h, json),
151
+ rift_intercept_clear_rules: (h) => fn.rift_intercept_clear_rules(h),
152
+ rift_intercept_list_rules: (h) => fn.rift_intercept_list_rules(h),
153
+ rift_intercept_ca_pem: (h) => fn.rift_intercept_ca_pem(h),
154
+ rift_intercept_export_truststore: (h, format, password, outPath) => fn.rift_intercept_export_truststore(h, format, password, outPath),
155
+ rift_serve_admin: (h, optionsJson) => fn.rift_serve_admin(h, optionsJson),
156
+ rift_build_info: () => fn.rift_build_info(),
157
+ rift_last_error: () => fn.rift_last_error(),
158
+ rift_free: (p) => {
159
+ fn.rift_free(p);
160
+ },
161
+ };
162
+ const decode = (p) => koffi.decode(p, 'char', -1);
163
+ return { binding, decode };
164
+ }
165
+ //# sourceMappingURL=ffi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ffi.js","sourceRoot":"","sources":["../src/ffi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAErC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAM5C,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACrD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAEpF,CAAC;AACF,MAAM,kBAAkB,GAAG,WAAW,CAAC,gBAAgB,IAAI,OAAO,CAAC;AAEnE,MAAM,GAAG,GAAG,QAAQ,CAAC;AACrB,MAAM,GAAG,GAAG,KAAK,CAAC;AAElB,SAAS,YAAY,CAAC,GAAY;IAChC,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC;AAED;sFACsF;AACtF,MAAM,UAAU,YAAY,CAAC,OAAe,EAAE,gBAAwB;IACpE,OAAO,qBAAqB,OAAO,2CAA2C,gBAAgB,GAAG,CAAC;AACpG,CAAC;AAED;4FAC4F;AAC5F,MAAM,UAA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CAAC,EAAE,WAAW,EAAE,EAAE,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,EAAE,WAAW,CAAc;QACtF,eAAe,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,eAAe,EAAe;QACxD,eAAe,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,eAAe,EAAe;QACxD,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE;YACf,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;KACF,CAAC;IAEF,MAAM,MAAM,GAAW,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;IAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Embedded transport: koffi FFI binding + worker_threads wrapper for `librift_ffi` (issue #8),
3
+ * cdylib resolution reuse (issue #9), and the `rift.embedded()` wiring — `createEmbeddedEngine` +
4
+ * `EmbeddedAdmin` — that ties them into the same `RiftEngine` facade `connect`/`spawn` produce
5
+ * (issue #10).
6
+ *
7
+ * A separate package (`@rift-vs/rift-embedded`, #39) — deliberately not part of core, since
8
+ * importing it pulls in `worker_threads` and the `koffi` dependency (a REAL dependency here,
9
+ * unlike core which has none). Core's `rift.embedded()` reaches this package via a dynamic
10
+ * `import('@rift-vs/rift-embedded')`, not a static one, so `rift.connect`/`rift.spawn` alone
11
+ * never load it — and projects that never call `rift.embedded()` never need to install it.
12
+ */
13
+ export { NativeEngine } from './native.js';
14
+ export type { NativeEngineLoadOptions, WorkerLike } from './native.js';
15
+ export { handleCall, readBuildInfo, readLastErrorMessage } from './native-call.js';
16
+ export type { Decode, NativeCallError, NativeCallErr, NativeCallOk, NativeCallRequest, NativeCallResponse } from './native-call.js';
17
+ export { RETURN_KIND } from './native-binding.js';
18
+ export type { NativeBinding, NativeCallableFn, NativePtr, ReturnKind } from './native-binding.js';
19
+ export { loadNativeBinding, v1AbiMessage, loadFailureMessage } from './ffi.js';
20
+ export type { LoadedNative } from './ffi.js';
21
+ export type { FromWorkerMessage, ToWorkerMessage } from './protocol.js';
22
+ export { createEmbeddedEngine } from './create.js';
23
+ export type { EmbeddedDeps, EmbeddedOptions } from './create.js';
24
+ export { EmbeddedAdmin } from './admin.js';
25
+ export type { EmbeddedAdminOptions, NativeEngineLike, StartAdminPlane } from './admin.js';
26
+ export { AdminBridge } from './bridge.js';
27
+ export type { BridgeOptions } from './bridge.js';
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACnF,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEpI,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAElG,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC/E,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,YAAY,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE1F,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Embedded transport: koffi FFI binding + worker_threads wrapper for `librift_ffi` (issue #8),
3
+ * cdylib resolution reuse (issue #9), and the `rift.embedded()` wiring — `createEmbeddedEngine` +
4
+ * `EmbeddedAdmin` — that ties them into the same `RiftEngine` facade `connect`/`spawn` produce
5
+ * (issue #10).
6
+ *
7
+ * A separate package (`@rift-vs/rift-embedded`, #39) — deliberately not part of core, since
8
+ * importing it pulls in `worker_threads` and the `koffi` dependency (a REAL dependency here,
9
+ * unlike core which has none). Core's `rift.embedded()` reaches this package via a dynamic
10
+ * `import('@rift-vs/rift-embedded')`, not a static one, so `rift.connect`/`rift.spawn` alone
11
+ * never load it — and projects that never call `rift.embedded()` never need to install it.
12
+ */
13
+ export { NativeEngine } from './native.js';
14
+ export { handleCall, readBuildInfo, readLastErrorMessage } from './native-call.js';
15
+ export { RETURN_KIND } from './native-binding.js';
16
+ export { loadNativeBinding, v1AbiMessage, loadFailureMessage } from './ffi.js';
17
+ // `rift.embedded()` wiring (issue #10).
18
+ export { createEmbeddedEngine } from './create.js';
19
+ export { EmbeddedAdmin } from './admin.js';
20
+ export { AdminBridge } from './bridge.js';
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGnF,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAK/E,wCAAwC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGnD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Embedded `InterceptBackend` adapter (issue #11) — a thin JSON-boundary wrapper over the
3
+ * FFI-backed `NativeEngine` intercept calls (issue #8, `rift_start_intercept`/`rift_intercept_*`).
4
+ * Parses/stringifies JSON at this boundary so `InterceptHandle` never touches it directly.
5
+ */
6
+ import type { InterceptBackend } from '@rift-vs/rift/internal';
7
+ /** The subset of `NativeEngine`'s facade this backend depends on — small enough that tests inject a
8
+ * fake, and the real `NativeEngine` (and `EmbeddedAdmin`'s `NativeEngineLike`) satisfy it structurally
9
+ * as-is (see `embedded/create.ts`). */
10
+ export interface NativeInterceptEngine {
11
+ startIntercept(optionsJson: string): Promise<Record<string, unknown>>;
12
+ interceptAddRules(json: string): Promise<number>;
13
+ interceptClearRules(): Promise<number>;
14
+ interceptListRules(): Promise<string>;
15
+ interceptCaPem(): Promise<string>;
16
+ interceptExportTruststore(format: string, password: string, outPath: string): Promise<number>;
17
+ }
18
+ export declare class EmbeddedInterceptBackend implements InterceptBackend {
19
+ private readonly native;
20
+ constructor(native: NativeInterceptEngine);
21
+ startIntercept(optionsJson: string): Promise<{
22
+ interceptPort: number;
23
+ interceptUrl: string;
24
+ }>;
25
+ addRules(rulesJson: string): Promise<void>;
26
+ listRules(): Promise<string>;
27
+ clearRules(): Promise<void>;
28
+ caPem(): Promise<string>;
29
+ exportTruststore(format: string, password: string, outPath: string): Promise<void>;
30
+ }
31
+ //# sourceMappingURL=intercept-backend.d.ts.map
@@ -0,0 +1 @@
1
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2
+ * Embedded `InterceptBackend` adapter (issue #11) — a thin JSON-boundary wrapper over the
3
+ * FFI-backed `NativeEngine` intercept calls (issue #8, `rift_start_intercept`/`rift_intercept_*`).
4
+ * Parses/stringifies JSON at this boundary so `InterceptHandle` never touches it directly.
5
+ */
6
+ import { RiftError } from '@rift-vs/rift';
7
+ export class EmbeddedInterceptBackend {
8
+ native;
9
+ constructor(native) {
10
+ this.native = native;
11
+ }
12
+ async startIntercept(optionsJson) {
13
+ const result = await this.native.startIntercept(optionsJson);
14
+ const interceptPort = result['interceptPort'];
15
+ const interceptUrl = result['interceptUrl'];
16
+ if (typeof interceptPort !== 'number' || typeof interceptUrl !== 'string') {
17
+ throw new RiftError(`rift_start_intercept returned an unexpected shape (expected {interceptPort, interceptUrl}): ${JSON.stringify(result)}`);
18
+ }
19
+ return { interceptPort, interceptUrl };
20
+ }
21
+ async addRules(rulesJson) {
22
+ await this.native.interceptAddRules(rulesJson);
23
+ }
24
+ async listRules() {
25
+ return this.native.interceptListRules();
26
+ }
27
+ async clearRules() {
28
+ await this.native.interceptClearRules();
29
+ }
30
+ async caPem() {
31
+ return this.native.interceptCaPem();
32
+ }
33
+ async exportTruststore(format, password, outPath) {
34
+ await this.native.interceptExportTruststore(format, password, outPath);
35
+ }
36
+ }
37
+ //# sourceMappingURL=intercept-backend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intercept-backend.js","sourceRoot":"","sources":["../src/intercept-backend.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAe1C,MAAM,OAAO,wBAAwB;IACN;IAA7B,YAA6B,MAA6B;QAA7B,WAAM,GAAN,MAAM,CAAuB;IAAG,CAAC;IAE9D,KAAK,CAAC,cAAc,CAAC,WAAmB;QACtC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;QAC7D,MAAM,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;QAC9C,MAAM,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;QAC5C,IAAI,OAAO,aAAa,KAAK,QAAQ,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;YAC1E,MAAM,IAAI,SAAS,CACjB,+FAA+F,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CACxH,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,SAAiB;QAC9B,MAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,SAAS;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,UAAU;QACd,MAAM,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,KAAK;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,MAAc,EAAE,QAAgB,EAAE,OAAe;QACtE,MAAM,IAAI,CAAC,MAAM,CAAC,yBAAyB,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IACzE,CAAC;CACF"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * `librift_ffi` C-ABI v2 surface (issue #8), shaped for koffi: every argument/return is a pointer
3
+ * or a primitive — no auto-decoded strings. `char*` returns come back as {@link NativePtr} (raw,
4
+ * possibly-null) so `native-call.ts`'s `handleCall` controls the decode-then-free ordering itself;
5
+ * input JSON strings are passed as plain `string` (koffi encodes those on the way in — there's no
6
+ * discipline needed for an argument the callee copies out of).
7
+ */
8
+ /** An opaque native pointer as koffi hands it back: a `RiftHandle*` or an unfreed `char*`. `null`
9
+ * is the universal "this pointer is absent" sentinel (a real `NULL`). */
10
+ export type NativePtr = unknown;
11
+ export interface NativeBinding {
12
+ rift_start(): NativePtr;
13
+ rift_stop(handle: NativePtr): void;
14
+ rift_create_imposter(handle: NativePtr, json: string): number;
15
+ rift_replace_stubs(handle: NativePtr, port: number, json: string): number;
16
+ rift_delete_imposter(handle: NativePtr, port: number): number;
17
+ rift_delete_all(handle: NativePtr): number;
18
+ rift_apply_config(handle: NativePtr, json: string): NativePtr;
19
+ rift_recorded(handle: NativePtr, port: number): NativePtr;
20
+ rift_stub_warnings(handle: NativePtr, port: number): NativePtr;
21
+ rift_flow_state_get(handle: NativePtr, port: number, flowId: string, key: string): NativePtr;
22
+ rift_flow_state_put(handle: NativePtr, port: number, flowId: string, key: string, valueJson: string): number;
23
+ rift_flow_state_delete(handle: NativePtr, port: number, flowId: string, key: string): number;
24
+ rift_space_add_stub(handle: NativePtr, port: number, flowId: string, json: string): number;
25
+ rift_space_list_stubs(handle: NativePtr, port: number, flowId: string): NativePtr;
26
+ rift_space_delete(handle: NativePtr, port: number, flowId: string): number;
27
+ rift_space_recorded(handle: NativePtr, port: number, flowId: string): NativePtr;
28
+ rift_start_intercept(handle: NativePtr, optionsJson: string): NativePtr;
29
+ rift_intercept_add_rules(handle: NativePtr, json: string): number;
30
+ rift_intercept_clear_rules(handle: NativePtr): number;
31
+ rift_intercept_list_rules(handle: NativePtr): NativePtr;
32
+ rift_intercept_ca_pem(handle: NativePtr): NativePtr;
33
+ rift_intercept_export_truststore(handle: NativePtr, format: string, password: string, outPath: string): number;
34
+ rift_serve_admin(handle: NativePtr, optionsJson: string): NativePtr;
35
+ /** Static string — always present, NEVER pass to `rift_free`. */
36
+ rift_build_info(): NativePtr;
37
+ /** Reads and clears the calling thread's last-error slot. */
38
+ rift_last_error(): NativePtr;
39
+ rift_free(ptr: NativePtr): void;
40
+ }
41
+ export type ReturnKind = 'void' | 'uint16' | 'int32' | 'string';
42
+ /** Every `NativeBinding` member EXCEPT the four handled specially outside `handleCall`'s dispatch
43
+ * table: `rift_start` (one-time init, its own NULL-handle failure path), `rift_last_error` and
44
+ * `rift_free` (the discipline's own internal machinery), and `rift_build_info` (read once at
45
+ * init, bypassing the sentinel path entirely — see `readBuildInfo`). */
46
+ type DispatchableFn = Exclude<keyof NativeBinding, 'rift_start' | 'rift_last_error' | 'rift_free' | 'rift_build_info'>;
47
+ /** Maps each dispatchable call to how `handleCall` classifies its return value: which sentinel
48
+ * (if any) signals failure, and whether a success value needs decode+free. Keyed off
49
+ * `DispatchableFn` so adding/removing a `NativeBinding` member forces this table to stay exhaustive. */
50
+ export declare const RETURN_KIND: Record<DispatchableFn, ReturnKind>;
51
+ export type NativeCallableFn = keyof typeof RETURN_KIND;
52
+ export {};
53
+ //# sourceMappingURL=native-binding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-binding.d.ts","sourceRoot":"","sources":["../src/native-binding.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;yEACyE;AACzE,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC;AAEhC,MAAM,WAAW,aAAa;IAC5B,UAAU,IAAI,SAAS,CAAC;IACxB,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACnC,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9D,kBAAkB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1E,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9D,eAAe,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC;IAC3C,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9D,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAA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AAC;IACxD,qBAAqB,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,CAAC;IACpD,gCAAgC,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/G,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IACpE,iEAAiE;IACjE,eAAe,IAAI,SAAS,CAAC;IAC7B,6DAA6D;IAC7D,eAAe,IAAI,SAAS,CAAC;IAC7B,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;CACjC;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEhE;;;wEAGwE;AACxE,KAAK,cAAc,GAAG,OAAO,CAC3B,MAAM,aAAa,EACnB,YAAY,GAAG,iBAAiB,GAAG,WAAW,GAAG,iBAAiB,CACnE,CAAC;AAEF;;wGAEwG;AACxG,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,cAAc,EAAE,UAAU,CAuB1D,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,WAAW,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * `librift_ffi` C-ABI v2 surface (issue #8), shaped for koffi: every argument/return is a pointer
3
+ * or a primitive — no auto-decoded strings. `char*` returns come back as {@link NativePtr} (raw,
4
+ * possibly-null) so `native-call.ts`'s `handleCall` controls the decode-then-free ordering itself;
5
+ * input JSON strings are passed as plain `string` (koffi encodes those on the way in — there's no
6
+ * discipline needed for an argument the callee copies out of).
7
+ */
8
+ /** Maps each dispatchable call to how `handleCall` classifies its return value: which sentinel
9
+ * (if any) signals failure, and whether a success value needs decode+free. Keyed off
10
+ * `DispatchableFn` so adding/removing a `NativeBinding` member forces this table to stay exhaustive. */
11
+ export const RETURN_KIND = {
12
+ rift_stop: 'void',
13
+ rift_create_imposter: 'uint16',
14
+ rift_replace_stubs: 'int32',
15
+ rift_delete_imposter: 'int32',
16
+ rift_delete_all: 'int32',
17
+ rift_apply_config: 'string',
18
+ rift_recorded: 'string',
19
+ rift_stub_warnings: 'string',
20
+ rift_flow_state_get: 'string',
21
+ rift_flow_state_put: 'int32',
22
+ rift_flow_state_delete: 'int32',
23
+ rift_space_add_stub: 'int32',
24
+ rift_space_list_stubs: 'string',
25
+ rift_space_delete: 'int32',
26
+ rift_space_recorded: 'string',
27
+ rift_start_intercept: 'string',
28
+ rift_intercept_add_rules: 'int32',
29
+ rift_intercept_clear_rules: 'int32',
30
+ rift_intercept_list_rules: 'string',
31
+ rift_intercept_ca_pem: 'string',
32
+ rift_intercept_export_truststore: 'int32',
33
+ rift_serve_admin: 'string',
34
+ };
35
+ //# sourceMappingURL=native-binding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-binding.js","sourceRoot":"","sources":["../src/native-binding.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgDH;;wGAEwG;AACxG,MAAM,CAAC,MAAM,WAAW,GAAuC;IAC7D,SAAS,EAAE,MAAM;IACjB,oBAAoB,EAAE,QAAQ;IAC9B,kBAAkB,EAAE,OAAO;IAC3B,oBAAoB,EAAE,OAAO;IAC7B,eAAe,EAAE,OAAO;IACxB,iBAAiB,EAAE,QAAQ;IAC3B,aAAa,EAAE,QAAQ;IACvB,kBAAkB,EAAE,QAAQ;IAC5B,mBAAmB,EAAE,QAAQ;IAC7B,mBAAmB,EAAE,OAAO;IAC5B,sBAAsB,EAAE,OAAO;IAC/B,mBAAmB,EAAE,OAAO;IAC5B,qBAAqB,EAAE,QAAQ;IAC/B,iBAAiB,EAAE,OAAO;IAC1B,mBAAmB,EAAE,QAAQ;IAC7B,oBAAoB,EAAE,QAAQ;IAC9B,wBAAwB,EAAE,OAAO;IACjC,0BAA0B,EAAE,OAAO;IACnC,yBAAyB,EAAE,QAAQ;IACnC,qBAAqB,EAAE,QAAQ;IAC/B,gCAAgC,EAAE,OAAO;IACzC,gBAAgB,EAAE,QAAQ;CAC3B,CAAC"}