@syntropika/tembra-sdk 0.2.2 → 0.3.0
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 +43 -17
- package/dist/authoring/types.d.ts +64 -3
- package/dist/authoring/wit.d.ts +6 -0
- package/dist/bridge/commands.d.ts +1190 -0
- package/dist/bridge/identifiers.d.ts +2 -0
- package/dist/bridge/kernel.d.ts +18 -107
- package/dist/bridge/protocol.d.ts +3 -138
- package/dist/browser.d.ts +14 -1
- package/dist/browser.js +141 -3332
- package/dist/chunks/browser-b8jamxw2.js +3399 -0
- package/dist/chunks/execution-nsqc6nrt.js +1419 -0
- package/dist/chunks/index-01zk0xqx.js +160 -0
- package/dist/chunks/index-3fjdfdfd.js +152 -0
- package/dist/chunks/index-aaymjn7v.js +787 -0
- package/dist/chunks/index-c1w7z9hx.js +356 -0
- package/dist/chunks/index-h8t0n42q.js +738 -0
- package/dist/chunks/index-hfds9mzp.js +308 -0
- package/dist/chunks/index-kr4x67wt.js +177 -0
- package/dist/chunks/index-kr6bnh34.js +117 -0
- package/dist/chunks/index-kyt9dj0a.js +1421 -0
- package/dist/chunks/index-n1wxzc9w.js +830 -0
- package/dist/chunks/index-pvac426d.js +74 -0
- package/dist/chunks/index-smyds5ce.js +3234 -0
- package/dist/chunks/index-sse8aapb.js +121 -0
- package/dist/chunks/index-v6heph77.js +643 -0
- package/dist/chunks/index-xrdvnv37.js +3448 -0
- package/dist/chunks/index-za4mg94e.js +26 -0
- package/dist/chunks/index-zkqmnjj8.js +167 -0
- package/dist/coordinator.js +9 -500
- package/dist/error.d.ts +2 -0
- package/dist/errors.d.ts +3 -0
- package/dist/guest.d.ts +173 -0
- package/dist/guest.js +26 -0
- package/dist/host.d.ts +36 -30
- package/dist/host.js +37 -3310
- package/dist/http/bytes.d.ts +8 -0
- package/dist/http/events.d.ts +7 -0
- package/dist/http.d.ts +45 -0
- package/dist/http.js +291 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +49 -862
- package/dist/infrastructure/rpc/client.d.ts +2 -1
- package/dist/infrastructure/rpc/resources.d.ts +28 -0
- package/dist/interpreter/abi.d.ts +54 -0
- package/dist/interpreter/acquire.d.ts +18 -0
- package/dist/interpreter/browser-network.d.ts +52 -0
- package/dist/interpreter/browser-port.d.ts +55 -0
- package/dist/interpreter/browser.d.ts +79 -0
- package/dist/interpreter/cli.d.ts +5 -0
- package/dist/interpreter/codec.d.ts +42 -0
- package/dist/interpreter/component/execution.d.ts +42 -0
- package/dist/interpreter/component/host.d.ts +69 -0
- package/dist/interpreter/component/instance.d.ts +40 -0
- package/dist/interpreter/component/kernel.d.ts +120 -0
- package/dist/interpreter/component/names.d.ts +5 -0
- package/dist/interpreter/component/port.d.ts +85 -0
- package/dist/interpreter/component/prepared.d.ts +97 -0
- package/dist/interpreter/component/resources.d.ts +45 -0
- package/dist/interpreter/component/revision.d.ts +87 -0
- package/dist/interpreter/component/scope.d.ts +116 -0
- package/dist/interpreter/component/streams.d.ts +28 -0
- package/dist/interpreter/component/values.d.ts +79 -0
- package/dist/interpreter/component/wasi-filesystem.d.ts +21 -0
- package/dist/interpreter/component/wasi-host.d.ts +64 -0
- package/dist/interpreter/component/wasi-http.d.ts +33 -0
- package/dist/interpreter/component/wasi-sockets.d.ts +183 -0
- package/dist/interpreter/component/wasi.d.ts +41 -0
- package/dist/interpreter/core.d.ts +64 -0
- package/dist/interpreter/fetch-http-provider.d.ts +17 -0
- package/dist/interpreter/filesystem/contract.d.ts +85 -0
- package/dist/interpreter/filesystem/memory.d.ts +3 -0
- package/dist/interpreter/filesystem/opfs.d.ts +3 -0
- package/dist/interpreter/filesystem/scope.d.ts +35 -0
- package/dist/interpreter/filesystem.d.ts +8 -0
- package/dist/interpreter/gate.d.ts +6 -0
- package/dist/interpreter/host-protocol.d.ts +100 -0
- package/dist/interpreter/http-ingress-fetch.d.ts +7 -0
- package/dist/interpreter/http-ingress.d.ts +96 -0
- package/dist/interpreter/http-provider.d.ts +85 -0
- package/dist/interpreter/io.d.ts +20 -0
- package/dist/interpreter/mobile.d.ts +149 -0
- package/dist/interpreter/native-ingress.d.ts +95 -0
- package/dist/interpreter/node-port.d.ts +25 -0
- package/dist/interpreter/node.d.ts +36 -0
- package/dist/interpreter/revision.d.ts +64 -0
- package/dist/interpreter/scope.d.ts +89 -0
- package/dist/interpreter/socket-addresses.d.ts +50 -0
- package/dist/interpreter/socket-provider.d.ts +110 -0
- package/dist/interpreter/standard-cli.d.ts +34 -0
- package/dist/interpreter/standard-codec.d.ts +96 -0
- package/dist/interpreter/standard-filesystem.d.ts +47 -0
- package/dist/interpreter/standard-host.d.ts +71 -0
- package/dist/interpreter/standard-http-values.d.ts +159 -0
- package/dist/interpreter/standard-http.d.ts +9 -0
- package/dist/interpreter/standard-ingress.d.ts +63 -0
- package/dist/interpreter/standard-sockets.d.ts +177 -0
- package/dist/interpreter/standard-streams.d.ts +218 -0
- package/dist/interpreter/standard-system.d.ts +35 -0
- package/dist/interpreter/standard-utf8.d.ts +4 -0
- package/dist/interpreter/standard.d.ts +18 -0
- package/dist/interpreter/types.d.ts +152 -0
- package/dist/interpreter/wit-shape.d.ts +92 -0
- package/dist/manager.js +5 -332
- package/dist/msgpack.js +9 -615
- package/dist/node.d.ts +8 -1
- package/dist/node.js +248 -3321
- package/dist/rpc.js +196 -699
- package/dist/runtime/adapters.d.ts +120 -0
- package/dist/runtime/adapters.js +38 -0
- package/dist/runtime/calls.d.ts +7 -6
- package/dist/runtime/lifecycle.d.ts +3 -1
- package/dist/runtime/orbs.d.ts +5 -4
- package/dist/runtime/references.d.ts +27 -1
- package/dist/runtime/reload.d.ts +5 -3
- package/dist/runtime/scopes.d.ts +1 -1
- package/dist/runtime/signals.d.ts +4 -0
- package/dist/runtime/wit-client.d.ts +38 -0
- package/dist/telemetry.js +4 -25
- package/dist/tooling/build.d.ts +2 -2
- package/dist/tooling/client-resources.d.ts +23 -0
- package/dist/tooling/client.d.ts +10 -0
- package/dist/tooling/component-glue.d.ts +17 -0
- package/dist/tooling/component.d.ts +11 -0
- package/dist/tooling/index.d.ts +3 -1
- package/dist/tooling/index.js +1155 -102
- package/dist/tooling/resolver.d.ts +4 -4
- package/dist/tooling/typecheck.d.ts +2 -1
- package/dist/tooling/types.d.ts +27 -12
- package/dist/tooling/wit.d.ts +9 -0
- package/dist/wasi/wasi-clocks-types.d.ts +2 -0
- package/dist/wasi/wasi-http-client.d.ts +5 -0
- package/dist/wasi/wasi-http-types.d.ts +285 -0
- package/dist/wasi/wasi-sockets-ip-name-lookup.d.ts +23 -0
- package/dist/wasi/wasi-sockets-types.d.ts +146 -0
- package/package.json +62 -35
- package/src/authoring/declaration.ts +1 -1
- package/src/authoring/types.ts +53 -3
- package/src/authoring/wit.ts +15 -0
- package/src/bridge/commands.ts +1105 -0
- package/src/bridge/identifiers.ts +2 -0
- package/src/bridge/kernel.ts +56 -98
- package/src/bridge/protocol.ts +3 -142
- package/src/browser.ts +90 -6
- package/src/context-key.ts +4 -7
- package/src/error.ts +1 -1
- package/src/errors.ts +7 -0
- package/src/guest.ts +327 -0
- package/src/host.ts +128 -23
- package/src/http/bytes.ts +87 -0
- package/src/http/events.ts +34 -0
- package/src/http.ts +272 -0
- package/src/index.ts +3 -0
- package/src/infrastructure/rpc/client.ts +136 -17
- package/src/infrastructure/rpc/resources.ts +123 -0
- package/src/interpreter/abi.ts +69 -0
- package/src/interpreter/acquire.ts +58 -0
- package/src/interpreter/browser-network.ts +170 -0
- package/src/interpreter/browser-port.ts +425 -0
- package/src/interpreter/browser.ts +340 -0
- package/src/interpreter/cli.ts +30 -0
- package/src/interpreter/codec.ts +298 -0
- package/src/interpreter/component/execution.ts +264 -0
- package/src/interpreter/component/host.ts +409 -0
- package/src/interpreter/component/instance.ts +138 -0
- package/src/interpreter/component/kernel.ts +611 -0
- package/src/interpreter/component/names.ts +13 -0
- package/src/interpreter/component/port.ts +598 -0
- package/src/interpreter/component/prepared.ts +194 -0
- package/src/interpreter/component/resources.ts +345 -0
- package/src/interpreter/component/revision.ts +702 -0
- package/src/interpreter/component/scope.ts +447 -0
- package/src/interpreter/component/streams.ts +180 -0
- package/src/interpreter/component/values.ts +254 -0
- package/src/interpreter/component/wasi-filesystem.ts +472 -0
- package/src/interpreter/component/wasi-host.ts +197 -0
- package/src/interpreter/component/wasi-http.ts +939 -0
- package/src/interpreter/component/wasi-sockets.ts +958 -0
- package/src/interpreter/component/wasi.ts +238 -0
- package/src/interpreter/core.ts +386 -0
- package/src/interpreter/fetch-http-provider.ts +98 -0
- package/src/interpreter/filesystem/contract.ts +138 -0
- package/src/interpreter/filesystem/memory.ts +180 -0
- package/src/interpreter/filesystem/opfs.ts +294 -0
- package/src/interpreter/filesystem/scope.ts +390 -0
- package/src/interpreter/filesystem.ts +20 -0
- package/src/interpreter/gate.ts +55 -0
- package/src/interpreter/host-protocol.ts +242 -0
- package/src/interpreter/http-ingress-fetch.ts +133 -0
- package/src/interpreter/http-ingress.ts +203 -0
- package/src/interpreter/http-provider.ts +105 -0
- package/src/interpreter/io.ts +66 -0
- package/src/interpreter/mobile.ts +385 -0
- package/src/interpreter/native-ingress.ts +550 -0
- package/src/interpreter/node-port.ts +218 -0
- package/src/interpreter/node.ts +114 -0
- package/src/interpreter/revision.ts +450 -0
- package/src/interpreter/scope.ts +453 -0
- package/src/interpreter/socket-addresses.ts +246 -0
- package/src/interpreter/socket-provider.ts +126 -0
- package/src/interpreter/standard-cli.ts +184 -0
- package/src/interpreter/standard-codec.ts +403 -0
- package/src/interpreter/standard-filesystem.ts +545 -0
- package/src/interpreter/standard-host.ts +840 -0
- package/src/interpreter/standard-http-values.ts +624 -0
- package/src/interpreter/standard-http.ts +622 -0
- package/src/interpreter/standard-ingress.ts +344 -0
- package/src/interpreter/standard-sockets.ts +847 -0
- package/src/interpreter/standard-streams.ts +710 -0
- package/src/interpreter/standard-system.ts +182 -0
- package/src/interpreter/standard-utf8.ts +72 -0
- package/src/interpreter/standard.ts +283 -0
- package/src/interpreter/types.ts +163 -0
- package/src/interpreter/wit-shape.ts +175 -0
- package/src/node.ts +43 -14
- package/src/runtime/activities.ts +6 -6
- package/src/runtime/adapters.ts +314 -0
- package/src/runtime/calls.ts +213 -90
- package/src/runtime/context.ts +7 -7
- package/src/runtime/lifecycle.ts +36 -17
- package/src/runtime/orbs.ts +81 -39
- package/src/runtime/programs.ts +16 -8
- package/src/runtime/references.ts +128 -11
- package/src/runtime/reload.ts +71 -30
- package/src/runtime/resources.ts +2 -2
- package/src/runtime/scopes.ts +17 -17
- package/src/runtime/session.ts +3 -1
- package/src/runtime/signals.ts +31 -0
- package/src/runtime/wit-client.ts +228 -0
- package/src/tooling/build.ts +152 -54
- package/src/tooling/client-resources.ts +74 -0
- package/src/tooling/client.ts +531 -0
- package/src/tooling/component-glue.ts +288 -0
- package/src/tooling/component.ts +225 -0
- package/src/tooling/index.ts +3 -7
- package/src/tooling/resolver.ts +42 -25
- package/src/tooling/typecheck.ts +59 -4
- package/src/tooling/types.ts +27 -12
- package/src/tooling/wit.ts +188 -0
- package/dist/embedded.d.ts +0 -1
- package/dist/embedded.js +0 -1
- package/src/embedded.ts +0 -301
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { CoreLimits, TaskObserver } from "./instance.ts";
|
|
2
|
+
import type { CallbackScope } from "./scope.ts";
|
|
3
|
+
import { type WasiHost } from "./wasi-host.ts";
|
|
4
|
+
/** The callback a host import acts for. */
|
|
5
|
+
export interface Callback {
|
|
6
|
+
readonly scope: CallbackScope;
|
|
7
|
+
/** The host-issued environment of this callback. */
|
|
8
|
+
readonly environment: bigint;
|
|
9
|
+
/** Physical host operations started by this callback. */
|
|
10
|
+
readonly pending: Set<Promise<unknown>>;
|
|
11
|
+
/** Aborts when the callback ends; its waiters stop while physical work stays tracked. */
|
|
12
|
+
readonly ended: AbortController;
|
|
13
|
+
/** The generated export task this callback entered, bound synchronously at entry. */
|
|
14
|
+
task: number | undefined;
|
|
15
|
+
/** Resolves at that task's real exit. */
|
|
16
|
+
readonly exit: Promise<void>;
|
|
17
|
+
readonly exited: () => void;
|
|
18
|
+
}
|
|
19
|
+
/** The text of a failure, a structured one as the native worker writes it: `code/reason: message`. */
|
|
20
|
+
export declare function failureText(error: unknown): string;
|
|
21
|
+
export declare class ComponentPort {
|
|
22
|
+
#private;
|
|
23
|
+
readonly timeout: number;
|
|
24
|
+
readonly dispose: () => Promise<void>;
|
|
25
|
+
/** Fuel shared by a physically overlapping callback group; continuations never refill it. */
|
|
26
|
+
readonly callFuel: bigint;
|
|
27
|
+
exports: Record<string, Record<string, (...args: unknown[]) => unknown>> | undefined;
|
|
28
|
+
/** Lifecycle notifications from the instrumented glue of this instance. */
|
|
29
|
+
readonly observer: TaskObserver;
|
|
30
|
+
/** Whether the instrumented glue attached its task accessor during instantiation. */
|
|
31
|
+
get attached(): boolean;
|
|
32
|
+
/** Services of the WASI adapters bound to this instance. */
|
|
33
|
+
readonly wasi: WasiHost;
|
|
34
|
+
/** Shared fuel and page budget of the instance, set at instantiation. */
|
|
35
|
+
limits: CoreLimits | undefined;
|
|
36
|
+
constructor(timeout: number, dispose: () => Promise<void>,
|
|
37
|
+
/** Fuel shared by a physically overlapping callback group; continuations never refill it. */
|
|
38
|
+
callFuel?: bigint);
|
|
39
|
+
/**
|
|
40
|
+
* The callback a host import serves: the admitted callback owning the guest's current root
|
|
41
|
+
* export task (read synchronously at import entry), or the active callback for host-side work
|
|
42
|
+
* outside guest code. There is none between callbacks.
|
|
43
|
+
*/
|
|
44
|
+
current(): Callback;
|
|
45
|
+
/** Queue revision-owned destruction; it must never wait on the callback holding its gate. */
|
|
46
|
+
cleanup(operation: () => Promise<void>): Promise<void>;
|
|
47
|
+
/** Run a guest destructor without borrowing the active callback's authority. */
|
|
48
|
+
destroy(call: () => void): Promise<void>;
|
|
49
|
+
/** Race a waiter against the quarantine signal. */
|
|
50
|
+
guard<T>(operation: Promise<T>): Promise<T>;
|
|
51
|
+
/** Account one physical host operation to its callback until it settles. */
|
|
52
|
+
physical<T>(callback: Callback, operation: Promise<T>): Promise<T>;
|
|
53
|
+
/** Whether the instance can still be entered. */
|
|
54
|
+
get usable(): boolean;
|
|
55
|
+
/** Mark the instance unusable after a trap observed outside `run`. */
|
|
56
|
+
poison(cause?: unknown): void;
|
|
57
|
+
/**
|
|
58
|
+
* Serve one callback through its bounded outcome, joining actual completion on success.
|
|
59
|
+
* Register physical retention before waiting: a failure can answer promptly while its task
|
|
60
|
+
* and providers are still physically owned by the invocation.
|
|
61
|
+
*/
|
|
62
|
+
run<T>(environment: bigint, scope: CallbackScope, call: () => T | Promise<T>, retain?: (physical: Promise<void>) => void): Promise<T>;
|
|
63
|
+
/**
|
|
64
|
+
* Enter one admitted callback. `result` settles with the export's value (an incoming HTTP
|
|
65
|
+
* response head can be used while its body still streams). `finished` is the bounded callback
|
|
66
|
+
* outcome; `physical` proves actual task exit and settlement of its host work, even if a
|
|
67
|
+
* timeout or trap already rejected `finished`. Retention uses `physical`, never the deadline.
|
|
68
|
+
* One deadline governs the whole lifetime: on expiry the instance is quarantined, the callback's
|
|
69
|
+
* authority and waits are revoked, and provider work still running stays owned by the revision
|
|
70
|
+
* until its disposal. `call` must turn recoverable WIT `result` errors into values; anything it
|
|
71
|
+
* throws is a trap. After a successful checked stream head, `park()` releases the exclusive
|
|
72
|
+
* entry slot while preserving this callback's physical lifetime and deadline. Overlapping
|
|
73
|
+
* callbacks and destructors share the group's original fuel until every callback has ended.
|
|
74
|
+
*/
|
|
75
|
+
start<T>(environment: bigint, scope: CallbackScope, call: () => T | Promise<T>): {
|
|
76
|
+
result: Promise<T>;
|
|
77
|
+
finished: Promise<void>;
|
|
78
|
+
physical: Promise<void>;
|
|
79
|
+
park(): void;
|
|
80
|
+
};
|
|
81
|
+
/** Join physical provider work and resource destruction without retiring the instance. */
|
|
82
|
+
settled(): Promise<void>;
|
|
83
|
+
/** Dispose providers only after the last callback physically returned. */
|
|
84
|
+
close(): Promise<void>;
|
|
85
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Application-owned prepared components: the only way a compiled Orb runs in a browser.
|
|
3
|
+
*
|
|
4
|
+
* Tembra's build tooling verifies a compiled artifact's real WIT types natively, generates its
|
|
5
|
+
* bindings once with JCO, instruments the glue and every core module, and emits an ES module that
|
|
6
|
+
* calls `preparedComponent`. That module is host-trusted application code: the application
|
|
7
|
+
* imports it explicitly and registers it with `createHost({ isolated: { components } })`.
|
|
8
|
+
* Nothing an Orb names (a URL, a sidecar, a claimed hash) is ever imported or trusted; an
|
|
9
|
+
* uploaded artifact selects an adapter only when the browser verifier hashed its actual bytes
|
|
10
|
+
* to the adapter's `artifact` digest.
|
|
11
|
+
*
|
|
12
|
+
* This module is small and loaded with the browser facade; execution code loads lazily.
|
|
13
|
+
*/
|
|
14
|
+
/** Format of the generated adapter modules this SDK accepts. */
|
|
15
|
+
export declare const PREPARED_FORMAT = 1;
|
|
16
|
+
/** The generator whose output the build-time glue instrumentation recognizes exactly. */
|
|
17
|
+
export declare const PREPARED_GENERATOR = "@bytecodealliance/jco-transpile@0.23.0";
|
|
18
|
+
/** Pages of a 32-bit memory: the build-time clamp; installations budget below it at runtime. */
|
|
19
|
+
export declare const PREPARED_MAXIMUM_PAGES = 65536;
|
|
20
|
+
/** Generated component core modules; all are instrumented with `tembra:limits`. */
|
|
21
|
+
export declare const COMPONENT_CORE: RegExp;
|
|
22
|
+
/** JCO's own JSPI trampolines: fixed helpers carrying no component code. */
|
|
23
|
+
export declare const TRAMPOLINE_CORE: RegExp;
|
|
24
|
+
/** The generated `instantiate` export of instrumented JCO glue. */
|
|
25
|
+
export type Instantiate = (getCoreModule: (name: string) => Promise<WebAssembly.Module>, imports: Record<string, unknown>, instantiateCore: (module: WebAssembly.Module, imports: WebAssembly.Imports) => Promise<WebAssembly.Instance>, options: {
|
|
26
|
+
tembraObserver: unknown;
|
|
27
|
+
}) => Promise<Record<string, unknown>>;
|
|
28
|
+
/** Core module bytes as a generated loader supplies them. */
|
|
29
|
+
export type CoreSource = Response | ArrayBuffer | ArrayBufferView | WebAssembly.Module;
|
|
30
|
+
/** One generated core module of a prepared component. */
|
|
31
|
+
export interface PreparedCoreSource {
|
|
32
|
+
/** The name the generated glue requests. */
|
|
33
|
+
readonly name: string;
|
|
34
|
+
/** Pages one instantiation allocates (instrumented component cores only). */
|
|
35
|
+
readonly pages?: number;
|
|
36
|
+
/** Load the module's bytes; called at most once per successful compilation. */
|
|
37
|
+
readonly load: () => CoreSource | Promise<CoreSource>;
|
|
38
|
+
}
|
|
39
|
+
/** What a generated adapter module passes to `preparedComponent`. */
|
|
40
|
+
export interface PreparedComponentSource {
|
|
41
|
+
readonly format: number;
|
|
42
|
+
readonly generator: string;
|
|
43
|
+
/** Identity of the prepared Orb, checked against the artifact's own metadata. */
|
|
44
|
+
readonly orb: {
|
|
45
|
+
readonly name: string;
|
|
46
|
+
readonly apiVersion: number;
|
|
47
|
+
};
|
|
48
|
+
/** Lowercase hexadecimal SHA-256 of the exact original artifact bytes. */
|
|
49
|
+
readonly artifact: string;
|
|
50
|
+
/** The page clamp the core modules were instrumented with. */
|
|
51
|
+
readonly maximumPages: number;
|
|
52
|
+
/** Exact versioned top-level import names of the verified component. */
|
|
53
|
+
readonly imports: readonly string[];
|
|
54
|
+
/** `import#function` names generated as suspending (JSPI) host imports. */
|
|
55
|
+
readonly suspending: readonly string[];
|
|
56
|
+
/** `export#function` names generated as promising (JSPI) exports. */
|
|
57
|
+
readonly promising: readonly string[];
|
|
58
|
+
readonly cores: readonly PreparedCoreSource[];
|
|
59
|
+
readonly instantiate: Instantiate;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* An application-owned compiled component adapter, created by a build-generated module. Pass it
|
|
63
|
+
* to `createHost({ isolated: { components: [...] } })`; its fields are informational.
|
|
64
|
+
*/
|
|
65
|
+
export interface PreparedComponent {
|
|
66
|
+
readonly orb: {
|
|
67
|
+
readonly name: string;
|
|
68
|
+
readonly apiVersion: number;
|
|
69
|
+
};
|
|
70
|
+
/** SHA-256 of the exact compiled artifact this adapter executes. */
|
|
71
|
+
readonly artifact: string;
|
|
72
|
+
}
|
|
73
|
+
/** The checked, immutable adapter record behind one `PreparedComponent`. */
|
|
74
|
+
export interface PreparedRecord {
|
|
75
|
+
readonly orb: PreparedComponent["orb"];
|
|
76
|
+
readonly artifact: string;
|
|
77
|
+
readonly maximumPages: number;
|
|
78
|
+
readonly imports: readonly string[];
|
|
79
|
+
readonly suspending: ReadonlySet<string>;
|
|
80
|
+
readonly promising: ReadonlySet<string>;
|
|
81
|
+
readonly cores: readonly PreparedCoreSource[];
|
|
82
|
+
readonly instantiate: Instantiate;
|
|
83
|
+
}
|
|
84
|
+
/** A browser platform requirement is missing; no other engine is tried. */
|
|
85
|
+
export declare class BrowserPlatformError extends Error {
|
|
86
|
+
readonly name = "BrowserPlatformError";
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Check a build-generated adapter description and capture it. Only generated modules call this;
|
|
90
|
+
* applications register the returned value.
|
|
91
|
+
*/
|
|
92
|
+
export declare function preparedComponent(source: PreparedComponentSource): PreparedComponent;
|
|
93
|
+
/**
|
|
94
|
+
* Index registered adapters by artifact digest. A value not created by `preparedComponent` (for
|
|
95
|
+
* example a copied object or a different SDK instance) is refused rather than trusted.
|
|
96
|
+
*/
|
|
97
|
+
export declare function preparedRegistry(components: readonly PreparedComponent[] | undefined): ReadonlyMap<string, PreparedRecord>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Provider-owned WIT resources of the bounded compiled capability profile. */
|
|
2
|
+
import type { ReferenceRecord } from "../../runtime/records.ts";
|
|
3
|
+
import type { Session } from "../../runtime/session.ts";
|
|
4
|
+
import type { ResourceCapability, ResourceLoan } from "#tembra-adapters";
|
|
5
|
+
import type { GraphFunction, TypeGraph } from "./values.ts";
|
|
6
|
+
export interface Nominal {
|
|
7
|
+
readonly interface: string;
|
|
8
|
+
readonly name: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ResourceRoles {
|
|
11
|
+
readonly arguments?: ((value: unknown, own: (nominal: Nominal, value: unknown) => unknown) => unknown) | undefined;
|
|
12
|
+
readonly receiver?: Nominal | undefined;
|
|
13
|
+
readonly owned?: readonly Nominal[] | undefined;
|
|
14
|
+
/** Map only own positions in the host-domain result; other values remain ordinary data. */
|
|
15
|
+
readonly result?: ((value: unknown, own: (nominal: Nominal, value: unknown) => unknown) => unknown) | undefined;
|
|
16
|
+
readonly stream?: boolean | undefined;
|
|
17
|
+
readonly resource?: Nominal | undefined;
|
|
18
|
+
readonly member?: string | undefined;
|
|
19
|
+
readonly construct?: boolean | undefined;
|
|
20
|
+
}
|
|
21
|
+
/** One live ownership generation; moving extracts all physical authority from stale aliases. */
|
|
22
|
+
export declare class ResourceOwner implements ResourceCapability {
|
|
23
|
+
#private;
|
|
24
|
+
readonly nominal: Nominal;
|
|
25
|
+
readonly kind = "resource";
|
|
26
|
+
constructor(nominal: Nominal, issuer: object, environment: number, value: object, destroy: () => void | Promise<void>);
|
|
27
|
+
/** Revision retirement follows the physical resource even after its original wrapper moves. */
|
|
28
|
+
retirement(): () => void;
|
|
29
|
+
whenRetired(operation: () => void): void;
|
|
30
|
+
anchor(session: Session, reference: ReferenceRecord): void;
|
|
31
|
+
get reference(): ReferenceRecord;
|
|
32
|
+
lend(): ResourceLoan;
|
|
33
|
+
redeem(issuer: object, environment: number, expected: Nominal): object;
|
|
34
|
+
issuedBy(issuer: object): boolean;
|
|
35
|
+
move(): ResourceOwner;
|
|
36
|
+
take(issuer: object, expected: Nominal): object;
|
|
37
|
+
whenClosed(operation: () => void): void;
|
|
38
|
+
close(): void;
|
|
39
|
+
}
|
|
40
|
+
/** Read roles already admitted by the Rust resource profile; handles remain outside data. */
|
|
41
|
+
export declare function resourceRoles(graph: TypeGraph, binding: string, fn: GraphFunction): ResourceRoles;
|
|
42
|
+
/** The signature of the checked data lane: self and whole capabilities travel separately. */
|
|
43
|
+
export declare function resourceDataFunction(fn: GraphFunction, roles: ResourceRoles): GraphFunction;
|
|
44
|
+
/** Resolve the JCO resource class/member rather than its flattened contract spelling. */
|
|
45
|
+
export declare function resourceExport(exports: Record<string, unknown>, spelling: string, roles: ResourceRoles, receiver: object | undefined, args: readonly unknown[], enter?: () => readonly unknown[]): unknown;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { OrbDefinition } from "../../authoring/types.ts";
|
|
2
|
+
import type { Lifetime } from "../../bridge/identifiers.ts";
|
|
3
|
+
import { type ResourceCapability } from "#tembra-adapters";
|
|
4
|
+
import { Gate } from "../gate.ts";
|
|
5
|
+
import { type ContractPort, type Description, type InstallationPlan, type ReferenceBinding } from "../types.ts";
|
|
6
|
+
import { type Signature, type WitFunction, type WitTypes } from "../wit-shape.ts";
|
|
7
|
+
import { ComponentKernel, type LogObserver } from "./kernel.ts";
|
|
8
|
+
import type { ComponentPort } from "./port.ts";
|
|
9
|
+
import { ComponentScope, type BoundMethod, type ScopeOwner } from "./scope.ts";
|
|
10
|
+
import { type TypeGraph } from "./values.ts";
|
|
11
|
+
import type { IngressBridge } from "./wasi-http.ts";
|
|
12
|
+
/** The contract's `describe` answer, as far as component execution reads it. */
|
|
13
|
+
export type Described = WitTypes & TypeGraph & {
|
|
14
|
+
imports: {
|
|
15
|
+
binding: string;
|
|
16
|
+
contract?: string;
|
|
17
|
+
type_only?: boolean;
|
|
18
|
+
functions?: Record<string, WitFunction>;
|
|
19
|
+
}[];
|
|
20
|
+
exports: {
|
|
21
|
+
binding: string;
|
|
22
|
+
contract?: string;
|
|
23
|
+
functions?: Record<string, WitFunction>;
|
|
24
|
+
}[];
|
|
25
|
+
/** Checked reference views; artifact metadata alone declares them. */
|
|
26
|
+
references: Readonly<Record<string, ReferenceBinding>>;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The roles a compiled artifact's metadata gives its exports, by interface identity: the hooks
|
|
30
|
+
* it contributes to with their priority, the hooks it declares with their composition, and the
|
|
31
|
+
* lifetime and linger of its services' objects.
|
|
32
|
+
*/
|
|
33
|
+
export interface CompiledRoles {
|
|
34
|
+
readonly contributions: Readonly<Record<string, number>>;
|
|
35
|
+
readonly hooks?: Readonly<Record<string, "series" | "waterfall" | "bail">>;
|
|
36
|
+
readonly services?: Readonly<Record<string, {
|
|
37
|
+
lifetime: Lifetime;
|
|
38
|
+
linger_ms: number;
|
|
39
|
+
}>>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A compiled component's description: one service per callable export interface, with the
|
|
43
|
+
* lifetime and linger its policy names, and its declared hooks under their export's alias, as
|
|
44
|
+
* the native executor describes it. Contribution callbacks and the kernel's own callbacks
|
|
45
|
+
* (`tembra:guest`) are answered to their callers, never offered as services.
|
|
46
|
+
*/
|
|
47
|
+
export declare function compiledDescription(graph: Described, identity: {
|
|
48
|
+
name: string;
|
|
49
|
+
apiVersion: number;
|
|
50
|
+
}, roles: CompiledRoles): Description;
|
|
51
|
+
export declare class ComponentRevision implements ScopeOwner {
|
|
52
|
+
#private;
|
|
53
|
+
readonly port: ComponentPort;
|
|
54
|
+
readonly contract: ContractPort;
|
|
55
|
+
readonly graph: Described;
|
|
56
|
+
readonly timeout: number;
|
|
57
|
+
readonly gate: Gate;
|
|
58
|
+
readonly imports: Map<string, string>;
|
|
59
|
+
readonly importSignatures: Map<string, string>;
|
|
60
|
+
readonly importMethods: Map<string, Map<string, BoundMethod>>;
|
|
61
|
+
readonly views: Map<string, Map<string, BoundMethod>>;
|
|
62
|
+
readonly signatures: Map<number, Signature>;
|
|
63
|
+
readonly scopes: Map<number, ComponentScope>;
|
|
64
|
+
readonly importedResources: Set<ResourceCapability>;
|
|
65
|
+
/** The instance's incoming-HTTP bridge from the HTTP adapter (`wasi.ts`). */
|
|
66
|
+
ingressBridge: IngressBridge | undefined;
|
|
67
|
+
/** The kernel's interfaces (`tembra:guest`) and the hooks this Orb declares. */
|
|
68
|
+
readonly kernel: ComponentKernel;
|
|
69
|
+
constructor(port: ComponentPort, contract: ContractPort, graph: Described, timeout: number,
|
|
70
|
+
/** The Orb's name and where its `tembra:guest/context` log records go. */
|
|
71
|
+
log?: {
|
|
72
|
+
readonly orb: string;
|
|
73
|
+
readonly observer?: LogObserver;
|
|
74
|
+
});
|
|
75
|
+
/** Call one typed export under an admitted callback and answer checked result bytes. */
|
|
76
|
+
private invoke;
|
|
77
|
+
/**
|
|
78
|
+
* The host-local incoming HTTP service of a `wasi:http/handler` export. It has no contract
|
|
79
|
+
* signature, so no WIT dependency can bind it, and its method accepts only an exchange issued by
|
|
80
|
+
* `Host.handleHttp`. One request is one admitted callback: the response head is published as
|
|
81
|
+
* soon as the handler returns it, while the callback stays admitted until the task's real exit
|
|
82
|
+
* and the end of the response delivery.
|
|
83
|
+
*/
|
|
84
|
+
private ingress;
|
|
85
|
+
/** Build callback definitions from the checked plan. */
|
|
86
|
+
definition(identity: Pick<OrbDefinition, "name" | "apiVersion">, installation: InstallationPlan, description: Description): OrbDefinition;
|
|
87
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host authority of one compiled component environment.
|
|
3
|
+
*
|
|
4
|
+
* A compiled component reaches the kernel only through the `tembra:guest` interfaces its world
|
|
5
|
+
* imports (kernel state, root resources, declared hooks, the call's context), served under the
|
|
6
|
+
* callback's own authority by the same `Scope` as a source Orb (`kernel.ts`); it declares no
|
|
7
|
+
* named host resources or references. Provider-owned WIT resources travel only through the
|
|
8
|
+
* private typed capability lane. Its only host authority beyond granted WASI and those kernel
|
|
9
|
+
* interfaces is calling its typed Orb dependency
|
|
10
|
+
* imports. A plain import targets the default `main` reference the root factory declared for its
|
|
11
|
+
* binding. A checked reference view (an artifact role) declares no default: the guest acquires
|
|
12
|
+
* root claims by key through the view's acquisition function and calls the provider through the
|
|
13
|
+
* returned host-local handle. Every call runs under the admitted invocation of the callback that
|
|
14
|
+
* issued it, with arguments and results checked by the import's own WIT signature.
|
|
15
|
+
*/
|
|
16
|
+
import type { CapturedArguments, ResourceCapability } from "#tembra-adapters";
|
|
17
|
+
import type { Declaration } from "../../authoring/declaration.ts";
|
|
18
|
+
import type { DynamicReference } from "../../authoring/types.ts";
|
|
19
|
+
import type { Context } from "../../runtime/context.ts";
|
|
20
|
+
import type { Authority } from "../scope.ts";
|
|
21
|
+
import type { ContractPort, ExecutionScope } from "../types.ts";
|
|
22
|
+
import type { KernelAccess, KernelTable } from "./kernel.ts";
|
|
23
|
+
import type { ResourceRoles } from "./resources.ts";
|
|
24
|
+
import { type Signature } from "../wit-shape.ts";
|
|
25
|
+
/** One prepared import function: the provider method it calls and its original WIT slot. */
|
|
26
|
+
export interface BoundMethod {
|
|
27
|
+
readonly name: string;
|
|
28
|
+
readonly slot: number;
|
|
29
|
+
readonly roles?: ResourceRoles;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* An opaque, unforgeable token naming one ready root claim of a reference view. Only the scope
|
|
33
|
+
* that issued it can resolve it, and only for a callback of the root owning the claim.
|
|
34
|
+
*/
|
|
35
|
+
export interface ReferenceClaim {
|
|
36
|
+
readonly binding: string;
|
|
37
|
+
}
|
|
38
|
+
/** The callback authority a component port serves host imports with. */
|
|
39
|
+
export interface CallbackScope {
|
|
40
|
+
readonly signal?: AbortSignal;
|
|
41
|
+
check(): void;
|
|
42
|
+
report(error: unknown): void;
|
|
43
|
+
/** Revoke the callback: later calls are refused and pending waits stop. */
|
|
44
|
+
cancel(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Call a plain Orb dependency import with host-domain arguments (WIT 64-bit positions as
|
|
47
|
+
* `bigint`) and answer its checked host-domain result.
|
|
48
|
+
*/
|
|
49
|
+
call(binding: string, method: string, args: readonly unknown[], arguments_?: CapturedArguments): Promise<unknown>;
|
|
50
|
+
releaseResource(owner: ResourceCapability): void;
|
|
51
|
+
resource?(owner: ResourceCapability, binding: string, method: string, args: readonly unknown[], arguments_?: CapturedArguments): Promise<unknown>;
|
|
52
|
+
/**
|
|
53
|
+
* Acquire a reference view's provider at `key` for this callback's admitted invocation and
|
|
54
|
+
* root. `abandoned` stops a pending readiness wait and releases the claim.
|
|
55
|
+
*/
|
|
56
|
+
acquire(binding: string, key: readonly string[], abandoned: AbortSignal): Promise<ReferenceClaim>;
|
|
57
|
+
/** Call view `method` (its original WIT name) on the claim of exactly `binding`. */
|
|
58
|
+
invoke(claim: ReferenceClaim, binding: string, method: string, args: readonly unknown[]): Promise<unknown>;
|
|
59
|
+
/**
|
|
60
|
+
* Release a claim of this callback's root. A claim of another root is left to its root, which
|
|
61
|
+
* releases it when it ends; a drop never acts for another root.
|
|
62
|
+
*/
|
|
63
|
+
release(claim: ReferenceClaim): void;
|
|
64
|
+
/**
|
|
65
|
+
* This callback's kernel requests (`tembra:guest`), served under its own authority by its
|
|
66
|
+
* environment's table; absent for an Orb that uses no kernel interface.
|
|
67
|
+
*/
|
|
68
|
+
readonly kernel?: KernelAccess;
|
|
69
|
+
}
|
|
70
|
+
/** The revision tables a component scope resolves import calls against. */
|
|
71
|
+
export interface ScopeOwner {
|
|
72
|
+
readonly contract: ContractPort;
|
|
73
|
+
readonly imports: ReadonlyMap<string, string>;
|
|
74
|
+
/** Plain import methods by JavaScript spelling. */
|
|
75
|
+
readonly importMethods: ReadonlyMap<string, ReadonlyMap<string, BoundMethod>>;
|
|
76
|
+
/** Reference-view methods by original WIT name (`[method]R.name`). */
|
|
77
|
+
readonly views: ReadonlyMap<string, ReadonlyMap<string, BoundMethod>>;
|
|
78
|
+
readonly importSignatures: ReadonlyMap<string, string>;
|
|
79
|
+
readonly signatures: ReadonlyMap<number, Signature>;
|
|
80
|
+
readonly scopes: ReadonlyMap<number, ComponentScope>;
|
|
81
|
+
readonly importedResources?: Set<ResourceCapability>;
|
|
82
|
+
}
|
|
83
|
+
/** One kernel environment (the Orb root or a service instance) of a compiled component. */
|
|
84
|
+
export declare class ComponentScope {
|
|
85
|
+
readonly owner: ScopeOwner;
|
|
86
|
+
readonly declaration: Declaration;
|
|
87
|
+
readonly id: number;
|
|
88
|
+
readonly parent: ComponentScope | undefined;
|
|
89
|
+
/** Default `main` reference per plain Orb import binding (root scope only). */
|
|
90
|
+
readonly defaults: Map<string, DynamicReference>;
|
|
91
|
+
/** The kernel handles this environment declared; absent for an Orb that uses none. */
|
|
92
|
+
kernel: KernelTable | undefined;
|
|
93
|
+
constructor(owner: ScopeOwner, declaration: Declaration, service: string | null);
|
|
94
|
+
/**
|
|
95
|
+
* Adapt one admitted invocation to the component port without exposing it to the guest.
|
|
96
|
+
* `execution` is the kernel's scope of a callback the kernel issued (a resource closer).
|
|
97
|
+
*/
|
|
98
|
+
exchange(context: Context, execution?: ExecutionScope): CallbackScope;
|
|
99
|
+
/**
|
|
100
|
+
* A callback the kernel itself runs on this environment: its declaration, a validation of the
|
|
101
|
+
* state a reload hands over, a resource opener. It serves only the kernel's interfaces, under
|
|
102
|
+
* `authority`; an Orb dependency call needs an admitted invocation and is refused, as it is for
|
|
103
|
+
* a source Orb. `execution` is the kernel's scope when the kernel issued the callback.
|
|
104
|
+
*/
|
|
105
|
+
callback(authority: Exclude<Authority, {
|
|
106
|
+
context: Context;
|
|
107
|
+
}>, execution?: ExecutionScope): CallbackScope;
|
|
108
|
+
/** The kernel access of a callback under `authority`, when this environment has a table. */
|
|
109
|
+
private access;
|
|
110
|
+
/** Resolve a token this revision issued for exactly `binding`. */
|
|
111
|
+
private claim;
|
|
112
|
+
/** Acquire a ready root claim and issue its opaque token. */
|
|
113
|
+
private acquire;
|
|
114
|
+
/** Arguments are checked under the import's own WIT slot before the provider sees them. */
|
|
115
|
+
private call;
|
|
116
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Private, single-owner transport for the canonical whole-result `stream<u8>` profile.
|
|
3
|
+
* A published stream is a capability, never JSON or a JCO representation shared between
|
|
4
|
+
* instances. The producer's physical completion remains independent of publication and drop.
|
|
5
|
+
*/
|
|
6
|
+
import type { Context } from "../../runtime/context.ts";
|
|
7
|
+
import type { ByteStreamCapability } from "../../runtime/adapters.ts";
|
|
8
|
+
/** The receiving call may retain this capability only for its original root. */
|
|
9
|
+
export declare class ByteStreamOwner implements ByteStreamCapability {
|
|
10
|
+
readonly finished: Promise<void>;
|
|
11
|
+
readonly kind: "bytes";
|
|
12
|
+
private constructor();
|
|
13
|
+
/** Issue only at the checked whole-result stream seam. */
|
|
14
|
+
static issue(stream: unknown, finished: Promise<void>, signal: AbortSignal): ByteStreamOwner;
|
|
15
|
+
/** Anchor publication to the admitted receiver; cancellation promptly drops the reader. */
|
|
16
|
+
bind(context: Context): void;
|
|
17
|
+
/** Request reader drop immediately. `finished` separately acknowledges physical completion. */
|
|
18
|
+
close(): void;
|
|
19
|
+
/** Publication and receipt share one host report even if the receiver never takes its head. */
|
|
20
|
+
reportFailure(error: unknown, report: (error: unknown) => void): void;
|
|
21
|
+
}
|
|
22
|
+
export declare const issueByteStream: typeof ByteStreamOwner.issue;
|
|
23
|
+
/**
|
|
24
|
+
* Redeem once as a symbol-free iterator accepted by the receiving JCO glue. Plain byte streams
|
|
25
|
+
* have no guest error lane: report the producer cause to the host and end the guest stream.
|
|
26
|
+
* Cleanup retains the physical producer after early drop without blocking drop acknowledgement.
|
|
27
|
+
*/
|
|
28
|
+
export declare function receiveByteStream(owner: ByteStreamCapability, ended: AbortSignal, cleanup: (operation: () => unknown) => void, failed: (error: unknown) => void): AsyncIterableIterator<Uint8Array>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed value conversion between Tembra's host domain form and trusted JCO bindings.
|
|
3
|
+
*
|
|
4
|
+
* The host domain form is the checked wire form with WIT 64-bit positions restored as `bigint`
|
|
5
|
+
* (see `wit-shape.ts`): options are `null` or the value, results and variants are `{ tag, val }`,
|
|
6
|
+
* lists are arrays. JCO bindings use `undefined` for an absent option, typed arrays for numeric
|
|
7
|
+
* lists and, for a function's own `result` return, return the ok value or throw `ComponentError`
|
|
8
|
+
* carrying the err payload. Only the shapes JCO and the contract disagree on are rewritten; the
|
|
9
|
+
* prepared Rust contract stays the single WIT validator of every value that reaches the host.
|
|
10
|
+
*/
|
|
11
|
+
type WitType = string | number | null | undefined;
|
|
12
|
+
interface WitKind {
|
|
13
|
+
type?: WitType;
|
|
14
|
+
list?: WitType;
|
|
15
|
+
option?: WitType;
|
|
16
|
+
record?: {
|
|
17
|
+
fields: {
|
|
18
|
+
name: string;
|
|
19
|
+
type: WitType;
|
|
20
|
+
}[];
|
|
21
|
+
};
|
|
22
|
+
tuple?: {
|
|
23
|
+
types: WitType[];
|
|
24
|
+
};
|
|
25
|
+
variant?: {
|
|
26
|
+
cases: {
|
|
27
|
+
name: string;
|
|
28
|
+
type?: WitType;
|
|
29
|
+
}[];
|
|
30
|
+
};
|
|
31
|
+
result?: {
|
|
32
|
+
ok?: WitType;
|
|
33
|
+
err?: WitType;
|
|
34
|
+
};
|
|
35
|
+
enum?: unknown;
|
|
36
|
+
flags?: unknown;
|
|
37
|
+
handle?: {
|
|
38
|
+
own?: number;
|
|
39
|
+
borrow?: number;
|
|
40
|
+
};
|
|
41
|
+
stream?: WitType;
|
|
42
|
+
[other: string]: unknown;
|
|
43
|
+
}
|
|
44
|
+
export interface TypeGraph {
|
|
45
|
+
readonly javascriptNames: Readonly<Record<string, string>>;
|
|
46
|
+
readonly types: readonly {
|
|
47
|
+
readonly id: number;
|
|
48
|
+
readonly definition: {
|
|
49
|
+
kind: WitKind | string;
|
|
50
|
+
owner?: string;
|
|
51
|
+
name?: string;
|
|
52
|
+
};
|
|
53
|
+
}[];
|
|
54
|
+
}
|
|
55
|
+
export interface GraphFunction {
|
|
56
|
+
readonly name?: string;
|
|
57
|
+
readonly kind?: string | Readonly<Record<string, number>>;
|
|
58
|
+
readonly params: readonly {
|
|
59
|
+
readonly name: string;
|
|
60
|
+
readonly type: WitType;
|
|
61
|
+
}[];
|
|
62
|
+
readonly result?: WitType;
|
|
63
|
+
}
|
|
64
|
+
/** Conversions of one function: arguments in both directions and its result. */
|
|
65
|
+
export interface FunctionValues {
|
|
66
|
+
/** Domain arguments to JCO arguments (host calling a guest export). */
|
|
67
|
+
readonly guestArguments: (args: readonly unknown[]) => unknown[];
|
|
68
|
+
/** JCO arguments to domain arguments (guest calling a host import). */
|
|
69
|
+
readonly hostArguments: (args: readonly unknown[]) => unknown[];
|
|
70
|
+
/** Await a JCO export call and answer the domain result (a `result` return is re-tagged). */
|
|
71
|
+
readonly fromGuest: (call: () => unknown) => Promise<unknown>;
|
|
72
|
+
/** Domain result to the value a JCO import implementation returns. */
|
|
73
|
+
readonly toGuest: (value: unknown) => unknown;
|
|
74
|
+
/** Whether the function's own return type is a WIT `result`. */
|
|
75
|
+
readonly tagged: boolean;
|
|
76
|
+
}
|
|
77
|
+
/** Compile conversions against one contract graph; compiled types are memoized. */
|
|
78
|
+
export declare function converters(graph: TypeGraph): (fn: GraphFunction) => FunctionValues;
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wasi:filesystem@0.3.0` for trusted JCO bindings over the granted provider mounts
|
|
3
|
+
* (`filesystem.ts`: MemoryFS, OPFS or embedder providers).
|
|
4
|
+
*
|
|
5
|
+
* Tembra checks descriptor kind, rights and lexical confinement before any provider call, then
|
|
6
|
+
* providers enforce their own scope as well. Error codes follow upstream Wasmtime: a wrong
|
|
7
|
+
* descriptor kind or a missing file right is `bad-descriptor` (`not-directory` for directory
|
|
8
|
+
* methods), and a directory mutation without `mutate-directory` is `not-permitted`. Browser
|
|
9
|
+
* providers have no settable timestamps, hard links or symbolic links: those methods report
|
|
10
|
+
* `unsupported` after their authority checks.
|
|
11
|
+
*/
|
|
12
|
+
import { type MountedFilesystem } from "../filesystem.ts";
|
|
13
|
+
import { type WasiHost, type WasiInterfaces } from "./wasi-host.ts";
|
|
14
|
+
/** A mount granted to this revision. */
|
|
15
|
+
export interface StandardMount {
|
|
16
|
+
readonly path: string;
|
|
17
|
+
readonly writable: boolean;
|
|
18
|
+
readonly filesystem: MountedFilesystem;
|
|
19
|
+
}
|
|
20
|
+
/** The `wasi:filesystem/types` and `preopens` import objects of one instance. */
|
|
21
|
+
export declare function filesystemImports(host: WasiHost, mounts: () => readonly StandardMount[]): WasiInterfaces<"types" | "preopens">;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared pieces of the WASI 0.3 adapters for trusted JCO bindings: physical accounting of
|
|
3
|
+
* provider work, revision retirement, and the two directions of `stream<u8>`.
|
|
4
|
+
*
|
|
5
|
+
* JCO hands an imported function a guest `stream<u8>` as an object with `read({ count })`
|
|
6
|
+
* (resolving `{ value, done }`) and `Symbol.dispose`; it accepts any async iterable from the host
|
|
7
|
+
* as a stream it produces, and any thenable as a future. A pending guest-stream read is never
|
|
8
|
+
* awaited without a bound: after a guest trap JCO never settles it, so every read races the
|
|
9
|
+
* revision's retirement signal, which aborts on quarantine and disposal.
|
|
10
|
+
*/
|
|
11
|
+
/** Host services an adapter uses; implemented by the component port. */
|
|
12
|
+
export interface WasiHost {
|
|
13
|
+
/**
|
|
14
|
+
* Run one provider operation under physical accounting: it belongs to the current callback
|
|
15
|
+
* (or the revision between callbacks) until it settles, even when the caller stops waiting.
|
|
16
|
+
* The returned promise rejects promptly when the current callback is cancelled.
|
|
17
|
+
*/
|
|
18
|
+
physical<T>(operation: () => Promise<T>): Promise<T>;
|
|
19
|
+
/** Retain cleanup/background work in its callback, or in the revision between callbacks. */
|
|
20
|
+
cleanup(operation: () => unknown): void;
|
|
21
|
+
/** Aborts when the revision quarantines or retires. */
|
|
22
|
+
readonly retired: AbortSignal;
|
|
23
|
+
/** Cancellation of the callback serving the current operation (its end, its context, retirement). */
|
|
24
|
+
signal(): AbortSignal;
|
|
25
|
+
}
|
|
26
|
+
/** Import objects of one package, keyed by interface; resource classes stay private. */
|
|
27
|
+
export type WasiInterfaces<K extends string> = Record<K, Record<string, unknown>>;
|
|
28
|
+
/** WASI `result` values in JCO form. */
|
|
29
|
+
export type WasiResult = {
|
|
30
|
+
tag: "ok";
|
|
31
|
+
val?: unknown;
|
|
32
|
+
} | {
|
|
33
|
+
tag: "err";
|
|
34
|
+
val: unknown;
|
|
35
|
+
};
|
|
36
|
+
export declare const ok: (val?: unknown) => WasiResult;
|
|
37
|
+
export declare const err: (code: unknown) => WasiResult;
|
|
38
|
+
export declare const cancelled: () => Error;
|
|
39
|
+
/** Reject when `signal` aborts; the operation's own settlement is unaffected. */
|
|
40
|
+
export declare function abortable<T>(operation: Promise<T>, signal: AbortSignal | undefined): Promise<T>;
|
|
41
|
+
/**
|
|
42
|
+
* Run a closing operation (a provider close, cancel or abort) as physical work. Started while a
|
|
43
|
+
* callback is attributed, it belongs to that callback, which then completes only after it settled
|
|
44
|
+
* (bounded by its deadline), so the next callback never overlaps it. Otherwise, and after
|
|
45
|
+
* retirement, the revision owns it until disposal.
|
|
46
|
+
*/
|
|
47
|
+
export declare function closing(host: WasiHost, operation: () => unknown): void;
|
|
48
|
+
/** Largest chunk requested from a guest stream at once. */
|
|
49
|
+
export declare const STREAM_CHUNK: number;
|
|
50
|
+
/**
|
|
51
|
+
* Consume a guest `stream<u8>` as chunks pulled on demand (backpressure). Every read is bounded
|
|
52
|
+
* by `retired`; `return()` (an early stop by the consumer) drops the guest stream.
|
|
53
|
+
*/
|
|
54
|
+
export declare function guestBytes(stream: unknown, retired: AbortSignal): AsyncIterableIterator<Uint8Array>;
|
|
55
|
+
/**
|
|
56
|
+
* A host-produced `stream<u8>` for JCO: chunks come from `next(limit)` (`undefined` or empty is
|
|
57
|
+
* the end). `close` runs exactly once with how the stream ended. A producer failure ends the
|
|
58
|
+
* stream and is reported only through `close` (whose owner settles the stream's companion
|
|
59
|
+
* future with the error, as WASI streams carry no error); it is never thrown to JCO, which would
|
|
60
|
+
* turn it into a guest trap.
|
|
61
|
+
*/
|
|
62
|
+
export declare function hostBytes(next: (limit: number) => Promise<Uint8Array | undefined>, close: (end: "eof" | "dropped" | "failed", failure?: unknown) => void, retired: AbortSignal): AsyncIterableIterator<Uint8Array>;
|
|
63
|
+
/** A host-produced typed `stream<T>` whose items come one at a time from `next()`; failures as `hostBytes`. */
|
|
64
|
+
export declare function hostItems(next: () => Promise<unknown>, close: (end: "eof" | "dropped" | "failed", failure?: unknown) => void, retired: AbortSignal): AsyncIterableIterator<unknown>;
|