@rybosome/tspice 0.0.7 → 0.0.8
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 +140 -78
- package/backend-contract/dist/.tsbuildinfo +1 -1
- package/backend-contract/dist/domains/cells-windows.d.ts +94 -0
- package/backend-contract/dist/domains/cells-windows.js +10 -0
- package/backend-contract/dist/domains/coords-vectors.d.ts +50 -0
- package/backend-contract/dist/domains/dsk.d.ts +49 -0
- package/backend-contract/dist/domains/dsk.js +2 -0
- package/backend-contract/dist/domains/ek.d.ts +186 -0
- package/backend-contract/dist/domains/ek.js +8 -0
- package/backend-contract/dist/domains/ephemeris.d.ts +141 -3
- package/backend-contract/dist/domains/error.d.ts +42 -0
- package/backend-contract/dist/domains/error.js +33 -0
- package/backend-contract/dist/domains/file-io.d.ts +114 -0
- package/backend-contract/dist/domains/file-io.js +8 -0
- package/backend-contract/dist/domains/frames.d.ts +40 -0
- package/backend-contract/dist/domains/geometry-gf.d.ts +44 -0
- package/backend-contract/dist/domains/geometry-gf.js +14 -0
- package/backend-contract/dist/domains/geometry.d.ts +21 -1
- package/backend-contract/dist/domains/ids-names-normalize.d.ts +3 -0
- package/backend-contract/dist/domains/ids-names-normalize.js +74 -0
- package/backend-contract/dist/domains/ids-names.d.ts +37 -0
- package/backend-contract/dist/domains/kernel-pool.d.ts +134 -0
- package/backend-contract/dist/domains/kernel-pool.js +2 -0
- package/backend-contract/dist/domains/kernels-utils.d.ts +44 -0
- package/backend-contract/dist/domains/kernels-utils.js +265 -0
- package/backend-contract/dist/domains/kernels.d.ts +39 -3
- package/backend-contract/dist/domains/time.d.ts +102 -0
- package/backend-contract/dist/index.d.ts +31 -3
- package/backend-contract/dist/index.js +15 -1
- package/backend-contract/dist/shared/errors.d.ts +6 -0
- package/backend-contract/dist/shared/errors.js +8 -0
- package/backend-contract/dist/shared/mat3.d.ts +26 -14
- package/backend-contract/dist/shared/mat3.js +46 -17
- package/backend-contract/dist/shared/mat6.d.ts +34 -0
- package/backend-contract/dist/shared/mat6.js +116 -0
- package/backend-contract/dist/shared/spice-handles.d.ts +20 -0
- package/backend-contract/dist/shared/spice-handles.js +82 -0
- package/backend-contract/dist/shared/spice-int.d.ts +32 -0
- package/backend-contract/dist/shared/spice-int.js +41 -0
- package/backend-contract/dist/shared/types.d.ts +106 -1
- package/backend-contract/dist/shared/vec.d.ts +54 -0
- package/backend-contract/dist/shared/vec.js +162 -0
- package/backend-fake/dist/.tsbuildinfo +1 -1
- package/backend-fake/dist/index.d.ts +19 -1
- package/backend-fake/dist/index.js +1103 -18
- package/backend-node/dist/.tsbuildinfo +1 -1
- package/backend-node/dist/codec/arrays.d.ts +9 -0
- package/backend-node/dist/codec/arrays.js +36 -0
- package/backend-node/dist/codec/errors.d.ts +6 -6
- package/backend-node/dist/codec/errors.js +6 -6
- package/backend-node/dist/domains/cells-windows.d.ts +5 -0
- package/backend-node/dist/domains/cells-windows.js +112 -0
- package/backend-node/dist/domains/coords-vectors.d.ts +1 -0
- package/backend-node/dist/domains/coords-vectors.js +64 -1
- package/backend-node/dist/domains/dsk.d.ts +6 -0
- package/backend-node/dist/domains/dsk.js +108 -0
- package/backend-node/dist/domains/ek.d.ts +10 -0
- package/backend-node/dist/domains/ek.js +100 -0
- package/backend-node/dist/domains/ephemeris.d.ts +5 -1
- package/backend-node/dist/domains/ephemeris.js +150 -1
- package/backend-node/dist/domains/error.d.ts +5 -0
- package/backend-node/dist/domains/error.js +34 -0
- package/backend-node/dist/domains/file-io.d.ts +7 -0
- package/backend-node/dist/domains/file-io.js +105 -0
- package/backend-node/dist/domains/frames.d.ts +1 -0
- package/backend-node/dist/domains/frames.js +52 -0
- package/backend-node/dist/domains/geometry-gf.d.ts +5 -0
- package/backend-node/dist/domains/geometry-gf.js +74 -0
- package/backend-node/dist/domains/geometry.d.ts +1 -0
- package/backend-node/dist/domains/geometry.js +62 -0
- package/backend-node/dist/domains/ids-names.d.ts +2 -1
- package/backend-node/dist/domains/ids-names.js +30 -0
- package/backend-node/dist/domains/kernel-pool.d.ts +5 -0
- package/backend-node/dist/domains/kernel-pool.js +74 -0
- package/backend-node/dist/domains/kernels.d.ts +1 -0
- package/backend-node/dist/domains/kernels.js +100 -13
- package/backend-node/dist/domains/time.d.ts +1 -0
- package/backend-node/dist/domains/time.js +75 -1
- package/backend-node/dist/index.d.ts +2 -0
- package/backend-node/dist/index.js +62 -1
- package/backend-node/dist/lowlevel/binding.d.ts +3 -0
- package/backend-node/dist/lowlevel/binding.js +115 -0
- package/backend-node/dist/runtime/addon.d.ts +271 -0
- package/backend-node/dist/runtime/addon.js +3 -0
- package/backend-node/dist/runtime/kernel-staging.d.ts +17 -0
- package/backend-node/dist/runtime/kernel-staging.js +80 -7
- package/backend-node/dist/runtime/spice-handles.d.ts +3 -0
- package/backend-node/dist/runtime/spice-handles.js +2 -0
- package/backend-node/dist/runtime/virtual-output-staging.d.ts +16 -0
- package/backend-node/dist/runtime/virtual-output-staging.js +148 -0
- package/backend-wasm/dist/.tsbuildinfo +1 -1
- package/backend-wasm/dist/codec/alloc.d.ts +19 -0
- package/backend-wasm/dist/codec/alloc.js +64 -0
- package/backend-wasm/dist/codec/calls.d.ts +2 -0
- package/backend-wasm/dist/codec/calls.js +13 -24
- package/backend-wasm/dist/codec/errors.d.ts +6 -0
- package/backend-wasm/dist/codec/errors.js +34 -2
- package/backend-wasm/dist/codec/found.d.ts +2 -0
- package/backend-wasm/dist/codec/found.js +20 -43
- package/backend-wasm/dist/codec/strings.d.ts +31 -1
- package/backend-wasm/dist/codec/strings.js +93 -6
- package/backend-wasm/dist/domains/cells-windows.d.ts +9 -0
- package/backend-wasm/dist/domains/cells-windows.js +392 -0
- package/backend-wasm/dist/domains/coords-vectors.d.ts +1 -0
- package/backend-wasm/dist/domains/coords-vectors.js +377 -187
- package/backend-wasm/dist/domains/dsk.d.ts +6 -0
- package/backend-wasm/dist/domains/dsk.js +179 -0
- package/backend-wasm/dist/domains/ek.d.ts +6 -0
- package/backend-wasm/dist/domains/ek.js +543 -0
- package/backend-wasm/dist/domains/ephemeris.d.ts +4 -1
- package/backend-wasm/dist/domains/ephemeris.js +405 -46
- package/backend-wasm/dist/domains/error.d.ts +5 -0
- package/backend-wasm/dist/domains/error.js +109 -0
- package/backend-wasm/dist/domains/file-io.d.ts +7 -0
- package/backend-wasm/dist/domains/file-io.js +462 -0
- package/backend-wasm/dist/domains/frames.d.ts +1 -0
- package/backend-wasm/dist/domains/frames.js +136 -4
- package/backend-wasm/dist/domains/geometry-gf.d.ts +5 -0
- package/backend-wasm/dist/domains/geometry-gf.js +178 -0
- package/backend-wasm/dist/domains/geometry.d.ts +1 -0
- package/backend-wasm/dist/domains/geometry.js +210 -0
- package/backend-wasm/dist/domains/ids-names.d.ts +2 -1
- package/backend-wasm/dist/domains/ids-names.js +89 -0
- package/backend-wasm/dist/domains/kernel-pool.d.ts +5 -0
- package/backend-wasm/dist/domains/kernel-pool.js +357 -0
- package/backend-wasm/dist/domains/kernels.d.ts +1 -0
- package/backend-wasm/dist/domains/kernels.js +91 -2
- package/backend-wasm/dist/domains/time.d.ts +2 -0
- package/backend-wasm/dist/domains/time.js +235 -133
- package/backend-wasm/dist/lowlevel/exports.d.ts +215 -1
- package/backend-wasm/dist/lowlevel/exports.js +217 -38
- package/backend-wasm/dist/runtime/create-backend-options.d.ts +21 -0
- package/backend-wasm/dist/runtime/create-backend.node.d.ts +7 -0
- package/backend-wasm/dist/runtime/create-backend.node.js +283 -12
- package/backend-wasm/dist/runtime/create-backend.web.d.ts +1 -0
- package/backend-wasm/dist/runtime/create-backend.web.js +40 -4
- package/backend-wasm/dist/runtime/fs.d.ts +5 -0
- package/backend-wasm/dist/runtime/fs.js +5 -0
- package/backend-wasm/dist/runtime/spice-handles.d.ts +3 -0
- package/backend-wasm/dist/runtime/spice-handles.js +2 -0
- package/backend-wasm/dist/runtime/virtual-outputs.d.ts +16 -0
- package/backend-wasm/dist/runtime/virtual-outputs.js +35 -0
- package/backend-wasm/dist/tspice_backend_wasm.node.js +3 -3
- package/backend-wasm/dist/tspice_backend_wasm.wasm +0 -0
- package/backend-wasm/dist/tspice_backend_wasm.web.js +1 -1
- package/core/dist/.tsbuildinfo +1 -1
- package/core/dist/index.d.ts +19 -8
- package/core/dist/index.js +19 -8
- package/dist/.tsbuildinfo +1 -1
- package/dist/backend.d.ts +5 -0
- package/dist/clients/createSpiceAsyncFromTransport.d.ts +5 -0
- package/dist/clients/createSpiceAsyncFromTransport.js +90 -0
- package/dist/clients/createSpiceSyncFromTransport.d.ts +5 -0
- package/dist/clients/createSpiceSyncFromTransport.js +88 -0
- package/dist/clients/spiceClients.d.ts +59 -0
- package/dist/clients/spiceClients.js +292 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +4 -0
- package/dist/index.d.ts +10 -7
- package/dist/index.js +4 -3
- package/dist/kernels/defaultKernelPathFromUrl.d.ts +8 -0
- package/dist/kernels/defaultKernelPathFromUrl.js +32 -0
- package/dist/kernels/kernelPack.d.ts +88 -0
- package/dist/kernels/kernelPack.js +122 -0
- package/dist/kernels/kernels.d.ts +98 -0
- package/dist/kernels/kernels.js +217 -0
- package/dist/kernels/naifKernelId.d.ts +2 -0
- package/dist/kernels/naifKernelId.js +2 -0
- package/dist/kit/math/mat3.d.ts +9 -1
- package/dist/kit/math/mat3.js +9 -1
- package/dist/kit/spice/create-kit.d.ts +1 -0
- package/dist/kit/spice/create-kit.js +1 -0
- package/dist/kit/spice/frames.d.ts +1 -0
- package/dist/kit/spice/frames.js +1 -0
- package/dist/kit/spice/kernels.d.ts +1 -0
- package/dist/kit/spice/kernels.js +1 -0
- package/dist/kit/spice/state.d.ts +2 -1
- package/dist/kit/spice/state.js +8 -4
- package/dist/kit/spice/time.d.ts +1 -0
- package/dist/kit/spice/time.js +1 -0
- package/dist/kit/types/spice-types.d.ts +18 -1
- package/dist/spice.d.ts +10 -1
- package/dist/spice.js +41 -0
- package/dist/transport/caching/policy.d.ts +16 -0
- package/dist/transport/caching/policy.js +77 -0
- package/dist/transport/caching/withCaching.d.ts +125 -0
- package/dist/transport/caching/withCaching.js +335 -0
- package/dist/transport/caching/withCachingSync.d.ts +24 -0
- package/dist/transport/caching/withCachingSync.js +161 -0
- package/dist/transport/rpc/protocol.d.ts +35 -0
- package/dist/transport/rpc/protocol.js +56 -0
- package/dist/transport/rpc/taskScheduling.d.ts +20 -0
- package/dist/transport/rpc/taskScheduling.js +98 -0
- package/dist/transport/rpc/valueCodec.d.ts +5 -0
- package/dist/transport/rpc/valueCodec.js +106 -0
- package/dist/transport/types.d.ts +7 -0
- package/dist/transport/types.js +2 -0
- package/dist/types.d.ts +8 -5
- package/dist/types.js +2 -1
- package/dist/worker/browser/createSpiceWorker.d.ts +22 -0
- package/dist/worker/browser/createSpiceWorker.js +41 -0
- package/dist/worker/browser/createSpiceWorkerClient.d.ts +40 -0
- package/dist/worker/browser/createSpiceWorkerClient.js +99 -0
- package/dist/worker/browser/spiceWorkerEntry.d.ts +2 -0
- package/dist/worker/browser/spiceWorkerEntry.js +129 -0
- package/dist/worker/browser/spiceWorkerInlineSource.d.ts +2 -0
- package/dist/worker/browser/spiceWorkerInlineSource.js +4 -0
- package/dist/worker/index.d.ts +10 -0
- package/dist/worker/index.js +7 -0
- package/dist/worker/transport/createWorkerTransport.d.ts +69 -0
- package/dist/worker/transport/createWorkerTransport.js +398 -0
- package/dist/worker/transport/exposeTransportToWorker.d.ts +51 -0
- package/dist/worker/transport/exposeTransportToWorker.js +196 -0
- package/package.json +4 -4
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createSpiceAsyncFromTransport } from "../../clients/createSpiceAsyncFromTransport.js";
|
|
2
|
+
import { createWorkerTransport, } from "../transport/createWorkerTransport.js";
|
|
3
|
+
import { createSpiceWorker } from "./createSpiceWorker.js";
|
|
4
|
+
function getDisposeFn(value) {
|
|
5
|
+
if (value === null)
|
|
6
|
+
return undefined;
|
|
7
|
+
const t = typeof value;
|
|
8
|
+
if (t !== "object" && t !== "function")
|
|
9
|
+
return undefined;
|
|
10
|
+
const dispose = value.dispose;
|
|
11
|
+
return typeof dispose === "function" ? dispose : undefined;
|
|
12
|
+
}
|
|
13
|
+
function isPromiseLike(value) {
|
|
14
|
+
if (value === null)
|
|
15
|
+
return false;
|
|
16
|
+
const t = typeof value;
|
|
17
|
+
if (t !== "object" && t !== "function")
|
|
18
|
+
return false;
|
|
19
|
+
return typeof value.then === "function";
|
|
20
|
+
}
|
|
21
|
+
/** Create a {@link SpiceWorkerClient} that communicates with a tspice Web Worker via RPC. */
|
|
22
|
+
export function createSpiceWorkerClient(opts) {
|
|
23
|
+
const workerInput = opts?.worker ?? (() => createSpiceWorker());
|
|
24
|
+
const worker = typeof workerInput === "function" ? workerInput() : workerInput;
|
|
25
|
+
const terminateOnDispose = opts?.terminateOnDispose ??
|
|
26
|
+
(typeof workerInput === "function" ? true : false);
|
|
27
|
+
const baseTransport = createWorkerTransport({
|
|
28
|
+
worker,
|
|
29
|
+
...(opts?.timeoutMs === undefined ? {} : { timeoutMs: opts.timeoutMs }),
|
|
30
|
+
terminateOnDispose,
|
|
31
|
+
...(opts?.signalDispose === undefined
|
|
32
|
+
? {}
|
|
33
|
+
: { signalDispose: opts.signalDispose }),
|
|
34
|
+
});
|
|
35
|
+
const transport = opts?.wrapTransport
|
|
36
|
+
? opts.wrapTransport(baseTransport)
|
|
37
|
+
: baseTransport;
|
|
38
|
+
const spice = createSpiceAsyncFromTransport(transport);
|
|
39
|
+
let disposePromise;
|
|
40
|
+
const disposeAsync = () => {
|
|
41
|
+
if (disposePromise)
|
|
42
|
+
return disposePromise;
|
|
43
|
+
disposePromise = (async () => {
|
|
44
|
+
try {
|
|
45
|
+
// If a wrapper transport supports cleanup, run it before disposing the
|
|
46
|
+
// underlying worker transport.
|
|
47
|
+
if (transport !== baseTransport) {
|
|
48
|
+
const wrapperDispose = getDisposeFn(transport);
|
|
49
|
+
if (wrapperDispose) {
|
|
50
|
+
const result = wrapperDispose.call(transport);
|
|
51
|
+
if (isPromiseLike(result))
|
|
52
|
+
await result;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
baseTransport.dispose();
|
|
58
|
+
}
|
|
59
|
+
})();
|
|
60
|
+
return disposePromise;
|
|
61
|
+
};
|
|
62
|
+
const dispose = () => {
|
|
63
|
+
// Fire-and-forget. Ensure we don't surface unhandled rejections if wrapper
|
|
64
|
+
// cleanup fails.
|
|
65
|
+
void disposeAsync().catch((err) => {
|
|
66
|
+
try {
|
|
67
|
+
opts?.onDisposeError?.(err);
|
|
68
|
+
}
|
|
69
|
+
catch (callbackErr) {
|
|
70
|
+
if (typeof console !== "undefined" &&
|
|
71
|
+
typeof console.error === "function") {
|
|
72
|
+
// Log both: the original disposal failure and the error thrown by the
|
|
73
|
+
// error callback.
|
|
74
|
+
try {
|
|
75
|
+
console.error("createSpiceWorkerClient.dispose(): disposeAsync() failed", err);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// ignore
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
console.error("createSpiceWorkerClient.dispose(): onDisposeError threw", callbackErr);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// ignore
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
worker,
|
|
92
|
+
baseTransport,
|
|
93
|
+
transport,
|
|
94
|
+
spice,
|
|
95
|
+
dispose,
|
|
96
|
+
disposeAsync,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=createSpiceWorkerClient.js.map
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { createSpiceAsync } from "../../spice.js";
|
|
2
|
+
import { exposeTransportToWorker } from "../transport/exposeTransportToWorker.js";
|
|
3
|
+
const getWorkerConfig = () => {
|
|
4
|
+
const cfg = globalThis
|
|
5
|
+
.__TSPICE_WORKER_CONFIG__;
|
|
6
|
+
if (!cfg || typeof cfg !== "object")
|
|
7
|
+
return undefined;
|
|
8
|
+
return cfg;
|
|
9
|
+
};
|
|
10
|
+
const blockedStringKeys = new Set([
|
|
11
|
+
// Promise / thenable
|
|
12
|
+
"then",
|
|
13
|
+
// Prototype / constructor escapes
|
|
14
|
+
"__proto__",
|
|
15
|
+
"prototype",
|
|
16
|
+
"constructor",
|
|
17
|
+
// Common stringification / inspection hooks
|
|
18
|
+
"toJSON",
|
|
19
|
+
"inspect",
|
|
20
|
+
// Object.prototype keys (avoid accidental RPC calls during introspection)
|
|
21
|
+
"toString",
|
|
22
|
+
"valueOf",
|
|
23
|
+
"toLocaleString",
|
|
24
|
+
"hasOwnProperty",
|
|
25
|
+
"isPrototypeOf",
|
|
26
|
+
"propertyIsEnumerable",
|
|
27
|
+
"__defineGetter__",
|
|
28
|
+
"__defineSetter__",
|
|
29
|
+
"__lookupGetter__",
|
|
30
|
+
"__lookupSetter__",
|
|
31
|
+
]);
|
|
32
|
+
const isSafeRpcKey = (key) => /^[A-Za-z_$][\w$]*$/.test(key);
|
|
33
|
+
const allowedKitMethodList = [
|
|
34
|
+
"loadKernel",
|
|
35
|
+
"unloadKernel",
|
|
36
|
+
"kclear",
|
|
37
|
+
"toolkitVersion",
|
|
38
|
+
"utcToEt",
|
|
39
|
+
"etToUtc",
|
|
40
|
+
"frameTransform",
|
|
41
|
+
"getState",
|
|
42
|
+
];
|
|
43
|
+
const defaultAllowlist = {
|
|
44
|
+
// NOTE: `kit` is deliberately allowlisted because it's a small, curated API.
|
|
45
|
+
// `raw` is intentionally not allowlisted here (see module comment below).
|
|
46
|
+
kit: new Set(allowedKitMethodList),
|
|
47
|
+
};
|
|
48
|
+
function createSpiceTransportFromSpiceAsync(spice, opts) {
|
|
49
|
+
const allowlist = opts?.allowlist ?? defaultAllowlist;
|
|
50
|
+
return {
|
|
51
|
+
request: async (op, args) => {
|
|
52
|
+
const dot = op.indexOf(".");
|
|
53
|
+
if (dot <= 0 || dot === op.length - 1) {
|
|
54
|
+
throw new Error(`Invalid op: ${op}`);
|
|
55
|
+
}
|
|
56
|
+
const namespace = op.slice(0, dot);
|
|
57
|
+
const method = op.slice(dot + 1);
|
|
58
|
+
if (namespace !== "raw" && namespace !== "kit") {
|
|
59
|
+
throw new Error(`Unknown namespace: ${namespace}`);
|
|
60
|
+
}
|
|
61
|
+
if (!isSafeRpcKey(method) || blockedStringKeys.has(method)) {
|
|
62
|
+
throw new Error(`Invalid method name: ${method}`);
|
|
63
|
+
}
|
|
64
|
+
const ns = namespace;
|
|
65
|
+
const nsAllowlist = allowlist[ns];
|
|
66
|
+
if (nsAllowlist && !nsAllowlist.has(method)) {
|
|
67
|
+
throw new Error(`Disallowed op: ${op}`);
|
|
68
|
+
}
|
|
69
|
+
const target = spice[ns];
|
|
70
|
+
const fn = target[method];
|
|
71
|
+
if (typeof fn !== "function") {
|
|
72
|
+
throw new Error(`Unknown op: ${op}`);
|
|
73
|
+
}
|
|
74
|
+
// `spice.raw` and `spice.kit` are proxies that return bound/wrapped
|
|
75
|
+
// functions, but use Reflect.apply to be defensive about `this`.
|
|
76
|
+
return await Reflect.apply(fn, target, args);
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// NOTE: This file is meant to be loaded as a Web Worker module.
|
|
81
|
+
// It intentionally has no exports and runs as a side-effect.
|
|
82
|
+
//
|
|
83
|
+
// Security/design note:
|
|
84
|
+
// - This worker entry is intended for internal workspace use.
|
|
85
|
+
// - By default, it exposes:
|
|
86
|
+
// - `kit.*` as a small, curated allowlist (see `allowedKitMethodList`), and
|
|
87
|
+
// - `raw.*` without an allowlist (subject to the blocked key checks above).
|
|
88
|
+
// - If you need a tighter RPC capability set (especially for `raw.*`), create
|
|
89
|
+
// a custom worker entry and provide an explicit allowlist.
|
|
90
|
+
//
|
|
91
|
+
// IMPORTANT: `exposeTransportToWorker()` must run synchronously so the worker's
|
|
92
|
+
// `message` handler is installed immediately. Otherwise, early RPC messages from
|
|
93
|
+
// the main thread can be dropped while the WASM backend is still initializing.
|
|
94
|
+
let spicePromise;
|
|
95
|
+
let transportPromise;
|
|
96
|
+
const getSpicePromise = () => {
|
|
97
|
+
if (spicePromise)
|
|
98
|
+
return spicePromise;
|
|
99
|
+
const config = getWorkerConfig();
|
|
100
|
+
const wasmUrl = config?.wasmUrl;
|
|
101
|
+
spicePromise = createSpiceAsync({
|
|
102
|
+
backend: "wasm",
|
|
103
|
+
...(wasmUrl === undefined ? {} : { wasmUrl }),
|
|
104
|
+
});
|
|
105
|
+
return spicePromise;
|
|
106
|
+
};
|
|
107
|
+
const getTransportPromise = () => (transportPromise ??= getSpicePromise().then((spice) => createSpiceTransportFromSpiceAsync(spice)));
|
|
108
|
+
exposeTransportToWorker({
|
|
109
|
+
transport: {
|
|
110
|
+
request: async (op, args) => (await getTransportPromise()).request(op, args),
|
|
111
|
+
},
|
|
112
|
+
onDispose: async () => {
|
|
113
|
+
// Best-effort cleanup. Worker termination also releases resources, but this
|
|
114
|
+
// helps callers who keep the worker alive.
|
|
115
|
+
if (!spicePromise) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
const spice = await getSpicePromise();
|
|
120
|
+
await spice.raw.kclear();
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// ignore
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
// Kick off init after the `message` handler has been installed.
|
|
128
|
+
void getTransportPromise();
|
|
129
|
+
//# sourceMappingURL=spiceWorkerEntry.js.map
|