@syntropika/tembra-sdk 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +47 -2
- package/dist/authoring/declaration.d.ts +47 -0
- package/dist/authoring/hooks.d.ts +11 -0
- package/dist/authoring/orb.d.ts +3 -0
- package/dist/authoring/types.d.ts +166 -0
- package/dist/bridge/identifiers.d.ts +207 -0
- package/dist/bridge/kernel.d.ts +117 -0
- package/dist/bridge/protocol.d.ts +181 -0
- package/dist/browser.d.ts +21 -0
- package/dist/browser.js +3282 -0
- package/dist/codec.d.ts +1 -0
- package/dist/codecs/json.d.ts +13 -0
- package/dist/codecs/msgpack.d.ts +3 -0
- package/dist/context-key.d.ts +35 -0
- package/dist/coordinator.d.ts +1 -0
- package/dist/coordinator.js +543 -0
- package/dist/embedded.d.ts +1 -0
- package/dist/embedded.js +1 -0
- package/dist/error.d.ts +13 -0
- package/dist/errors.d.ts +122 -0
- package/dist/hooks.d.ts +1 -0
- package/dist/host.d.ts +96 -0
- package/dist/host.js +3225 -0
- package/dist/identifiers.d.ts +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +833 -0
- package/dist/infrastructure/coordinator.d.ts +13 -0
- package/dist/infrastructure/manager.d.ts +23 -0
- package/dist/infrastructure/rpc/channel.d.ts +52 -0
- package/dist/infrastructure/rpc/client.d.ts +20 -0
- package/dist/infrastructure/rpc/server.d.ts +10 -0
- package/dist/infrastructure/rpc/state.d.ts +16 -0
- package/dist/kernel.d.ts +1 -0
- package/dist/manager.d.ts +1 -0
- package/dist/manager.js +390 -0
- package/dist/msgpack.d.ts +1 -0
- package/dist/msgpack.js +635 -0
- package/dist/node.d.ts +14 -0
- package/dist/node.js +3283 -0
- package/dist/orb.d.ts +1 -0
- package/dist/protocol.d.ts +1 -0
- package/dist/rpc.d.ts +3 -0
- package/dist/rpc.js +1036 -0
- package/dist/runtime/activities.d.ts +30 -0
- package/dist/runtime/calls.d.ts +22 -0
- package/dist/runtime/context.d.ts +37 -0
- package/dist/runtime/declaration.d.ts +1 -0
- package/dist/runtime/lifecycle.d.ts +28 -0
- package/dist/runtime/orbs.d.ts +39 -0
- package/dist/runtime/programs.d.ts +31 -0
- package/dist/runtime/records.d.ts +107 -0
- package/dist/runtime/references.d.ts +38 -0
- package/dist/runtime/reload.d.ts +17 -0
- package/dist/runtime/resources.d.ts +24 -0
- package/dist/runtime/scopes.d.ts +35 -0
- package/dist/runtime/session.d.ts +69 -0
- package/dist/state/binding.d.ts +28 -0
- package/dist/state/selection.d.ts +21 -0
- package/dist/state/types.d.ts +35 -0
- package/dist/state.d.ts +2 -0
- package/dist/telemetry.d.ts +23 -0
- package/dist/telemetry.js +27 -0
- package/dist/tooling/build.d.ts +3 -0
- package/dist/tooling/index.d.ts +2 -0
- package/dist/tooling/index.js +181 -0
- package/dist/tooling/resolver.d.ts +5 -0
- package/dist/tooling/typecheck.d.ts +2 -0
- package/dist/tooling/types.d.ts +29 -0
- package/dist/types.d.ts +1 -0
- package/dist/values.d.ts +23 -0
- package/package.json +103 -4
- package/src/authoring/declaration.ts +220 -0
- package/src/authoring/hooks.ts +101 -0
- package/src/authoring/orb.ts +77 -0
- package/src/authoring/types.ts +212 -0
- package/src/bridge/identifiers.ts +212 -0
- package/src/bridge/kernel.ts +117 -0
- package/src/bridge/protocol.ts +193 -0
- package/src/browser.ts +59 -0
- package/src/codec.ts +1 -0
- package/src/codecs/json.ts +147 -0
- package/src/codecs/msgpack.ts +26 -0
- package/src/context-key.ts +94 -0
- package/src/coordinator.ts +1 -0
- package/src/embedded.ts +293 -0
- package/src/error.ts +50 -0
- package/src/errors.ts +237 -0
- package/src/hooks.ts +1 -0
- package/src/host.ts +142 -0
- package/src/identifiers.ts +1 -0
- package/src/index.ts +22 -0
- package/src/infrastructure/coordinator.ts +76 -0
- package/src/infrastructure/manager.ts +77 -0
- package/src/infrastructure/rpc/channel.ts +88 -0
- package/src/infrastructure/rpc/client.ts +161 -0
- package/src/infrastructure/rpc/server.ts +201 -0
- package/src/infrastructure/rpc/state.ts +70 -0
- package/src/kernel.ts +1 -0
- package/src/manager.ts +1 -0
- package/src/msgpack.ts +1 -0
- package/src/node.ts +53 -0
- package/src/orb.ts +1 -0
- package/src/protocol.ts +1 -0
- package/src/rpc.ts +3 -0
- package/src/runtime/activities.ts +197 -0
- package/src/runtime/calls.ts +165 -0
- package/src/runtime/context.ts +113 -0
- package/src/runtime/declaration.ts +1 -0
- package/src/runtime/lifecycle.ts +227 -0
- package/src/runtime/orbs.ts +292 -0
- package/src/runtime/programs.ts +274 -0
- package/src/runtime/records.ts +127 -0
- package/src/runtime/references.ts +398 -0
- package/src/runtime/reload.ts +161 -0
- package/src/runtime/resources.ts +157 -0
- package/src/runtime/scopes.ts +210 -0
- package/src/runtime/session.ts +181 -0
- package/src/state/binding.ts +157 -0
- package/src/state/selection.ts +122 -0
- package/src/state/types.ts +47 -0
- package/src/state.ts +2 -0
- package/src/telemetry.ts +45 -0
- package/src/tooling/build.ts +83 -0
- package/src/tooling/index.ts +8 -0
- package/src/tooling/resolver.ts +95 -0
- package/src/tooling/typecheck.ts +32 -0
- package/src/tooling/types.ts +32 -0
- package/src/types.ts +1 -0
- package/src/values.ts +85 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Errors } from "../errors.ts";
|
|
2
|
+
|
|
3
|
+
import { refuse } from "../error.ts";
|
|
4
|
+
import type { OrbDefinition, ServiceDefinition } from "./types.ts";
|
|
5
|
+
|
|
6
|
+
/** Captures executable declarations. No structural schemas or generated contracts are required. */
|
|
7
|
+
export function orb<const F extends OrbDefinition>(definition: F): Readonly<F> {
|
|
8
|
+
if (!definition.name || !Number.isInteger(definition.apiVersion) || definition.apiVersion <= 0)
|
|
9
|
+
refuse(Errors.Invalid.Orb, "An orb needs a name and positive API version");
|
|
10
|
+
const services = Object.fromEntries(
|
|
11
|
+
Object.entries(definition.services ?? {}).map(([name, service]) => {
|
|
12
|
+
if (!name || !service.methods || typeof service.methods !== "object")
|
|
13
|
+
refuse(Errors.Invalid.Service);
|
|
14
|
+
if (service.create && typeof service.create !== "function") refuse(Errors.Invalid.Factory);
|
|
15
|
+
for (const handler of Object.values(service.methods)) {
|
|
16
|
+
if (typeof handler !== "function")
|
|
17
|
+
refuse(Errors.Invalid.Method, "Methods must be functions");
|
|
18
|
+
}
|
|
19
|
+
const copy: ServiceDefinition = {
|
|
20
|
+
...service,
|
|
21
|
+
methods: Object.freeze({ ...service.methods }),
|
|
22
|
+
};
|
|
23
|
+
return [name, Object.freeze(copy)];
|
|
24
|
+
}),
|
|
25
|
+
);
|
|
26
|
+
const requires = Object.fromEntries(
|
|
27
|
+
Object.entries(definition.requires ?? {}).map(([name, requirement]) => [
|
|
28
|
+
name,
|
|
29
|
+
Object.freeze({
|
|
30
|
+
...requirement,
|
|
31
|
+
...(requirement.methods ? { methods: Object.freeze([...requirement.methods]) } : {}),
|
|
32
|
+
...(requirement.hooks ? { hooks: Object.freeze([...requirement.hooks]) } : {}),
|
|
33
|
+
...(requirement.services
|
|
34
|
+
? {
|
|
35
|
+
services: Object.freeze(
|
|
36
|
+
Object.fromEntries(
|
|
37
|
+
Object.entries(requirement.services).map(([name, methods]) => [
|
|
38
|
+
name,
|
|
39
|
+
Object.freeze([...methods]),
|
|
40
|
+
]),
|
|
41
|
+
),
|
|
42
|
+
),
|
|
43
|
+
}
|
|
44
|
+
: {}),
|
|
45
|
+
}),
|
|
46
|
+
]),
|
|
47
|
+
);
|
|
48
|
+
const hooks = Object.fromEntries(
|
|
49
|
+
Object.entries(definition.hooks ?? {}).map(([name, hook]) => {
|
|
50
|
+
if (typeof hook.run !== "function") refuse(Errors.Invalid.Hook, "Hooks need a run function");
|
|
51
|
+
return [
|
|
52
|
+
name,
|
|
53
|
+
Object.freeze({ ...hook, capabilities: Object.freeze([...(hook.capabilities ?? [])]) }),
|
|
54
|
+
];
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
const contributes = Object.fromEntries(
|
|
58
|
+
Object.entries(definition.contributes ?? {}).map(([alias, hooks]) => [
|
|
59
|
+
alias,
|
|
60
|
+
Object.freeze(
|
|
61
|
+
Object.fromEntries(
|
|
62
|
+
Object.entries(hooks).map(([name, contribution]) => [
|
|
63
|
+
name,
|
|
64
|
+
typeof contribution === "function" ? contribution : Object.freeze({ ...contribution }),
|
|
65
|
+
]),
|
|
66
|
+
),
|
|
67
|
+
),
|
|
68
|
+
]),
|
|
69
|
+
);
|
|
70
|
+
return Object.freeze({
|
|
71
|
+
...definition,
|
|
72
|
+
services: Object.freeze(services),
|
|
73
|
+
requires: Object.freeze(requires),
|
|
74
|
+
hooks: Object.freeze(hooks),
|
|
75
|
+
contributes: Object.freeze(contributes),
|
|
76
|
+
}) as Readonly<F>;
|
|
77
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { Lifetime, ReloadStatus, Status } from "../bridge/identifiers.ts";
|
|
2
|
+
import type { Invocation, KernelOrb, KernelPort } from "../bridge/kernel.ts";
|
|
3
|
+
import type { Codec } from "../codecs/json.ts";
|
|
4
|
+
import type { Context } from "../runtime/context.ts";
|
|
5
|
+
import type { Readable } from "../state.ts";
|
|
6
|
+
import type { Declaration } from "./declaration.ts";
|
|
7
|
+
|
|
8
|
+
export type Completion<T> = T | PromiseLike<T>;
|
|
9
|
+
|
|
10
|
+
// Executable definitions are heterogeneous. These dynamic positions carry caller-owned types;
|
|
11
|
+
// runtime authority and ownership are established by the kernel, not TypeScript casts.
|
|
12
|
+
export type Handler = (environment: any, context: Context, ...arguments_: any[]) => unknown;
|
|
13
|
+
export interface ServiceDefinition {
|
|
14
|
+
create?: (self: Declaration) => unknown;
|
|
15
|
+
methods: Record<string, Handler>;
|
|
16
|
+
lifetime?: Lifetime;
|
|
17
|
+
|
|
18
|
+
/** Idle milliseconds to retain an unreferenced object and its running tasks; defaults to zero. */
|
|
19
|
+
linger?: number;
|
|
20
|
+
access?: (principal: string) => { methods: readonly string[] };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface Requirement {
|
|
24
|
+
orb?: string;
|
|
25
|
+
apiVersion: number;
|
|
26
|
+
methods?: readonly string[];
|
|
27
|
+
services?: Readonly<Record<string, readonly string[]>>;
|
|
28
|
+
hooks?: readonly string[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface HookDefinition {
|
|
32
|
+
capabilities?: readonly string[];
|
|
33
|
+
|
|
34
|
+
/** Execute a hook with its admitted participants. */
|
|
35
|
+
run(context: Context, input: any, participants: readonly Participant[]): Completion<unknown>;
|
|
36
|
+
}
|
|
37
|
+
export type Participant = (
|
|
38
|
+
context: Context,
|
|
39
|
+
input: any,
|
|
40
|
+
next?: (input: any) => Promise<unknown>,
|
|
41
|
+
) => Promise<any>;
|
|
42
|
+
export type ContributionHandler = (
|
|
43
|
+
context: Context,
|
|
44
|
+
input: any,
|
|
45
|
+
next?: (input: any) => Promise<unknown>,
|
|
46
|
+
) => unknown;
|
|
47
|
+
export type Contribution = ContributionHandler | { handle: ContributionHandler; priority?: number };
|
|
48
|
+
|
|
49
|
+
export interface OrbDefinition {
|
|
50
|
+
name: string;
|
|
51
|
+
apiVersion: number;
|
|
52
|
+
requires?: Readonly<Record<string, Requirement>>;
|
|
53
|
+
create?: (self: Declaration) => unknown;
|
|
54
|
+
services?: Readonly<Record<string, ServiceDefinition>>;
|
|
55
|
+
hooks?: Readonly<Record<string, HookDefinition>>;
|
|
56
|
+
contributes?: Readonly<Record<string, Readonly<Record<string, Contribution>>>>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ResourceOptions<T> {
|
|
60
|
+
version?: number;
|
|
61
|
+
exclusive?: boolean;
|
|
62
|
+
opaque?: boolean;
|
|
63
|
+
deps?: readonly unknown[];
|
|
64
|
+
|
|
65
|
+
/** Create the resource value and observe cancellation when supported. */
|
|
66
|
+
open(signal: AbortSignal): Completion<T>;
|
|
67
|
+
|
|
68
|
+
/** Release the value after its physical users settle. */
|
|
69
|
+
close?(value: T, context: Context): Completion<unknown>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface Resource<T> {
|
|
73
|
+
readonly value: T;
|
|
74
|
+
readonly version: number;
|
|
75
|
+
}
|
|
76
|
+
export interface TaskScope {
|
|
77
|
+
readonly signal: AbortSignal;
|
|
78
|
+
|
|
79
|
+
/** Run one operation under this task's authority. */
|
|
80
|
+
root<T>(operation: (context: Context) => Completion<T>): Promise<T>;
|
|
81
|
+
}
|
|
82
|
+
export interface EventSource<T> {
|
|
83
|
+
/** Attach a listener and return its detach function. */
|
|
84
|
+
subscribe(listener: (value: T) => void): () => void;
|
|
85
|
+
}
|
|
86
|
+
export interface ListenerOptions {
|
|
87
|
+
maxPending?: number;
|
|
88
|
+
maxBytes?: number;
|
|
89
|
+
sizeOf?: (value: any) => number;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface ReferenceBase<T = unknown> {
|
|
93
|
+
readonly ready: Promise<void>;
|
|
94
|
+
readonly status: Status;
|
|
95
|
+
readonly state: Readable<T>;
|
|
96
|
+
|
|
97
|
+
/** Release this reference's ownership claim. */
|
|
98
|
+
release(): void;
|
|
99
|
+
|
|
100
|
+
/** Read an explicitly exposed local resource. */
|
|
101
|
+
opaque<R = unknown>(name: string): R;
|
|
102
|
+
}
|
|
103
|
+
export type DynamicReference = ReferenceBase<any> & Record<string, any>;
|
|
104
|
+
|
|
105
|
+
export interface AcquisitionOptions {
|
|
106
|
+
apiVersion?: number;
|
|
107
|
+
methods?: readonly string[];
|
|
108
|
+
principal?: string;
|
|
109
|
+
}
|
|
110
|
+
export interface ReloadOptions {
|
|
111
|
+
deadline?: number;
|
|
112
|
+
}
|
|
113
|
+
export interface ReloadReport {
|
|
114
|
+
codeVersion: number;
|
|
115
|
+
orbs: readonly string[];
|
|
116
|
+
}
|
|
117
|
+
export interface PreparedReload {
|
|
118
|
+
readonly report: ReloadReport;
|
|
119
|
+
readonly status: ReloadStatus;
|
|
120
|
+
|
|
121
|
+
/** Adopt the prepared replacement and start its scopes. */
|
|
122
|
+
commit(): Promise<ReloadReport>;
|
|
123
|
+
|
|
124
|
+
/** Discard the candidate and restore previous scopes. */
|
|
125
|
+
abort(): Promise<void>;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface NativeAdapter {
|
|
129
|
+
/** Recheck context authority and admit one call using the kernel command rules. */
|
|
130
|
+
admit?(
|
|
131
|
+
reference: number,
|
|
132
|
+
method: string,
|
|
133
|
+
context: Context,
|
|
134
|
+
): { call: Invocation; native: boolean };
|
|
135
|
+
/** Tick the supplied host clock, finish a call, then drain actions and read the deadline. */
|
|
136
|
+
finish?(
|
|
137
|
+
call: number,
|
|
138
|
+
now: number,
|
|
139
|
+
): { actions: import("../bridge/kernel.ts").Action[]; deadline: number | null };
|
|
140
|
+
/** Revoke native reference claims issued inside a JS-owned root. */
|
|
141
|
+
rootEnded?(root: number): void;
|
|
142
|
+
/** Return a native service's principal-specific method policy when configured. */
|
|
143
|
+
access?(orb: number, service: string, principal: string): readonly string[] | undefined;
|
|
144
|
+
/** Await native callbacks while this realm keeps dispatching their replies. */
|
|
145
|
+
settled?(): Promise<void>;
|
|
146
|
+
/** Mirror shared kernel notifications into native callback storage. */
|
|
147
|
+
notify?(action: import("../bridge/kernel.ts").Action): boolean;
|
|
148
|
+
|
|
149
|
+
/** Check whether Rust owns a managed hook participant. */
|
|
150
|
+
hasContribution?(operation: number): boolean;
|
|
151
|
+
|
|
152
|
+
/** Execute a native hook participant while retaining its physical lifetime. */
|
|
153
|
+
contribute?(operation: number, context: Context, input: unknown): Promise<unknown>;
|
|
154
|
+
|
|
155
|
+
/** Check whether Rust owns this orb implementation. */
|
|
156
|
+
hasOrb(id: number): boolean;
|
|
157
|
+
|
|
158
|
+
/** Declare the native object's scopes before activation. */
|
|
159
|
+
activate(
|
|
160
|
+
object: number,
|
|
161
|
+
orb: number,
|
|
162
|
+
service: string,
|
|
163
|
+
key: readonly string[],
|
|
164
|
+
principal: string,
|
|
165
|
+
): Promise<void>;
|
|
166
|
+
|
|
167
|
+
/** Execute an admitted call in Rust. */
|
|
168
|
+
invoke(
|
|
169
|
+
invocation: Invocation,
|
|
170
|
+
arguments_: readonly unknown[],
|
|
171
|
+
context: Context,
|
|
172
|
+
): Promise<unknown>;
|
|
173
|
+
|
|
174
|
+
/** Release native object storage after scope cleanup. */
|
|
175
|
+
dispose(object: number): Promise<void>;
|
|
176
|
+
|
|
177
|
+
/** Execute a language callback requested by the kernel. */
|
|
178
|
+
effect(effect: import("../bridge/kernel.ts").Effect): Promise<number | void>;
|
|
179
|
+
|
|
180
|
+
/** Signals cancellation without acknowledging physical effect completion. */
|
|
181
|
+
cancelEffect?(effect: import("../bridge/kernel.ts").Effect): Completion<void>;
|
|
182
|
+
|
|
183
|
+
/** Decode a native value for the JS adapter. */
|
|
184
|
+
value(id: number): unknown;
|
|
185
|
+
|
|
186
|
+
/** Release the native value's bridge slot. */
|
|
187
|
+
dropValue?(id: number): void;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface HostOptions {
|
|
191
|
+
/** Explicit monotonic origin for adapters sharing an already-running kernel. */
|
|
192
|
+
clockOrigin?: number;
|
|
193
|
+
name?: string;
|
|
194
|
+
principal?: string;
|
|
195
|
+
kernel: KernelPort;
|
|
196
|
+
serialization?: Codec;
|
|
197
|
+
load?: (location: string | URL) => Promise<OrbDefinition>;
|
|
198
|
+
|
|
199
|
+
/** Receives adapter and observer failures; throwing from this callback cannot interrupt dispatch. */
|
|
200
|
+
onError?: (error: Error) => void;
|
|
201
|
+
|
|
202
|
+
/** Monotonic milliseconds from any origin; each host measures time relative to its creation. */
|
|
203
|
+
now?: () => number;
|
|
204
|
+
native?: NativeAdapter;
|
|
205
|
+
resources?: Readonly<Record<string, ResourceOptions<unknown>>>;
|
|
206
|
+
telemetry?: { capacity?: number; sampleEvery?: number };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface OrbDescription extends KernelOrb {
|
|
210
|
+
/** Read metadata without activating orb services. */
|
|
211
|
+
describe(): Readonly<KernelOrb>;
|
|
212
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/** Named public options and built-in failures. Values remain stable on the wire. */
|
|
2
|
+
type ValueOf<T> = T[keyof T];
|
|
3
|
+
|
|
4
|
+
export const Code = Object.freeze({
|
|
5
|
+
Invalid: "invalid",
|
|
6
|
+
Unavailable: "unavailable",
|
|
7
|
+
Released: "released",
|
|
8
|
+
Gone: "gone",
|
|
9
|
+
Expired: "expired",
|
|
10
|
+
Cancelled: "cancelled",
|
|
11
|
+
Forbidden: "forbidden",
|
|
12
|
+
Conflict: "conflict",
|
|
13
|
+
Unsupported: "unsupported",
|
|
14
|
+
Closed: "closed",
|
|
15
|
+
Exhausted: "exhausted",
|
|
16
|
+
} as const);
|
|
17
|
+
export type Code = ValueOf<typeof Code>;
|
|
18
|
+
|
|
19
|
+
export const Reason = Object.freeze({
|
|
20
|
+
ActivationBusy: "activation_busy",
|
|
21
|
+
Address: "address",
|
|
22
|
+
AlreadyCommitted: "already_committed",
|
|
23
|
+
AmbiguousScope: "ambiguous_scope",
|
|
24
|
+
ApiVersion: "api_version",
|
|
25
|
+
Arguments: "arguments",
|
|
26
|
+
AsyncFactory: "async_factory",
|
|
27
|
+
AsyncState: "async_state",
|
|
28
|
+
Bigint: "bigint",
|
|
29
|
+
ByteResult: "byte_result",
|
|
30
|
+
Call: "call",
|
|
31
|
+
Callback: "callback",
|
|
32
|
+
CleanupBusy: "cleanup_busy",
|
|
33
|
+
Clock: "clock",
|
|
34
|
+
Codec: "codec",
|
|
35
|
+
Connection: "connection",
|
|
36
|
+
Context: "context",
|
|
37
|
+
Contribution: "contribution",
|
|
38
|
+
CoordinationLimits: "coordination_limits",
|
|
39
|
+
Deadline: "deadline",
|
|
40
|
+
Dependency: "dependency",
|
|
41
|
+
DependencyCycle: "dependency_cycle",
|
|
42
|
+
DependencyService: "dependency_service",
|
|
43
|
+
Disposing: "disposing",
|
|
44
|
+
Driver: "driver",
|
|
45
|
+
Duplicate: "duplicate",
|
|
46
|
+
DuplicateContribution: "duplicate_contribution",
|
|
47
|
+
DuplicateListener: "duplicate_listener",
|
|
48
|
+
DuplicateResource: "duplicate_resource",
|
|
49
|
+
DuplicateService: "duplicate_service",
|
|
50
|
+
EffectResults: "effect_results",
|
|
51
|
+
EffectsRunning: "effects_running",
|
|
52
|
+
EngineEffect: "engine_effect",
|
|
53
|
+
EventSource: "event_source",
|
|
54
|
+
ExclusiveDependent: "exclusive_dependent",
|
|
55
|
+
Executor: "executor",
|
|
56
|
+
Orb: "orb",
|
|
57
|
+
OrbGone: "orb_gone",
|
|
58
|
+
OrbInstalled: "orb_installed",
|
|
59
|
+
OrbScope: "orb_scope",
|
|
60
|
+
Factory: "factory",
|
|
61
|
+
FactoryExpired: "factory_expired",
|
|
62
|
+
FrameSize: "frame_size",
|
|
63
|
+
GateBusy: "gate_busy",
|
|
64
|
+
GateOrb: "gate_orb",
|
|
65
|
+
GateObject: "gate_object",
|
|
66
|
+
Hook: "hook",
|
|
67
|
+
HookDependency: "hook_dependency",
|
|
68
|
+
Hooks: "hooks",
|
|
69
|
+
HooksDisabled: "hooks_disabled",
|
|
70
|
+
Host: "host",
|
|
71
|
+
HostAddress: "host_address",
|
|
72
|
+
HostResource: "host_resource",
|
|
73
|
+
HostResourceReload: "host_resource_reload",
|
|
74
|
+
Identities: "identities",
|
|
75
|
+
Implementation: "implementation",
|
|
76
|
+
Invocation: "invocation",
|
|
77
|
+
Javascript: "javascript",
|
|
78
|
+
JsonAccessor: "json_accessor",
|
|
79
|
+
JsonCycle: "json_cycle",
|
|
80
|
+
JsonNumber: "json_number",
|
|
81
|
+
JsonSymbol: "json_symbol",
|
|
82
|
+
JsonTag: "json_tag",
|
|
83
|
+
JsonType: "json_type",
|
|
84
|
+
JsonValue: "json_value",
|
|
85
|
+
Lifetime: "lifetime",
|
|
86
|
+
Linger: "linger",
|
|
87
|
+
ListenerCallback: "listener_callback",
|
|
88
|
+
LiveConsumer: "live_consumer",
|
|
89
|
+
LiveReference: "live_reference",
|
|
90
|
+
LocalValue: "local_value",
|
|
91
|
+
Memory: "memory",
|
|
92
|
+
Metadata: "metadata",
|
|
93
|
+
MetadataSize: "metadata_size",
|
|
94
|
+
Method: "method",
|
|
95
|
+
MigrationGate: "migration_gate",
|
|
96
|
+
MigrationRequired: "migration_required",
|
|
97
|
+
MigrationValue: "migration_value",
|
|
98
|
+
MissingHook: "missing_hook",
|
|
99
|
+
MissingMethod: "missing_method",
|
|
100
|
+
NativeEffect: "native_effect",
|
|
101
|
+
NativeMethod: "native_method",
|
|
102
|
+
NativeObject: "native_object",
|
|
103
|
+
NativeService: "native_service",
|
|
104
|
+
Next: "next",
|
|
105
|
+
NextUsed: "next_used",
|
|
106
|
+
NotReady: "not_ready",
|
|
107
|
+
Object: "object",
|
|
108
|
+
ObjectState: "object_state",
|
|
109
|
+
ObservationSource: "observation_source",
|
|
110
|
+
ObservationAdmitted: "observation_admitted",
|
|
111
|
+
Opaque: "opaque",
|
|
112
|
+
Operation: "operation",
|
|
113
|
+
OperationOwner: "operation_owner",
|
|
114
|
+
Owner: "owner",
|
|
115
|
+
Payload: "payload",
|
|
116
|
+
PendingRequests: "pending_requests",
|
|
117
|
+
PrepareDeadline: "prepare_deadline",
|
|
118
|
+
Priority: "priority",
|
|
119
|
+
Program: "program",
|
|
120
|
+
ProgramPhase: "program_phase",
|
|
121
|
+
ProgramRunning: "program_running",
|
|
122
|
+
Reference: "reference",
|
|
123
|
+
ReloadAborted: "reload_aborted",
|
|
124
|
+
ReloadDeadline: "reload_deadline",
|
|
125
|
+
ReloadPreparing: "reload_preparing",
|
|
126
|
+
ReloadRunning: "reload_running",
|
|
127
|
+
ReloadTicket: "reload_ticket",
|
|
128
|
+
RemoteOpaque: "remote_opaque",
|
|
129
|
+
RemoteReferences: "remote_references",
|
|
130
|
+
Request: "request",
|
|
131
|
+
RequestIds: "request_ids",
|
|
132
|
+
Requires: "requires",
|
|
133
|
+
Resource: "resource",
|
|
134
|
+
ResourceDependencies: "resource_dependencies",
|
|
135
|
+
ResourceDependency: "resource_dependency",
|
|
136
|
+
ResourceHost: "resource_host",
|
|
137
|
+
ResourceInFactory: "resource_in_factory",
|
|
138
|
+
ResourceState: "resource_state",
|
|
139
|
+
ResourceVersion: "resource_version",
|
|
140
|
+
Result: "result",
|
|
141
|
+
RetainedVersions: "retained_versions",
|
|
142
|
+
RevisionExhausted: "revision_exhausted",
|
|
143
|
+
Root: "root",
|
|
144
|
+
Route: "route",
|
|
145
|
+
RpcFrame: "rpc_frame",
|
|
146
|
+
RpcOperation: "rpc_operation",
|
|
147
|
+
RpcRequest: "rpc_request",
|
|
148
|
+
RustType: "rust_type",
|
|
149
|
+
Scope: "scope",
|
|
150
|
+
ScopeClosed: "scope_closed",
|
|
151
|
+
ScopeOrb: "scope_orb",
|
|
152
|
+
ScopeOwner: "scope_owner",
|
|
153
|
+
ScopeResource: "scope_resource",
|
|
154
|
+
Serialization: "serialization",
|
|
155
|
+
Service: "service",
|
|
156
|
+
ServiceGone: "service_gone",
|
|
157
|
+
State: "state",
|
|
158
|
+
StateCycle: "state_cycle",
|
|
159
|
+
StateInitialized: "state_initialized",
|
|
160
|
+
StateOwner: "state_owner",
|
|
161
|
+
StateRevision: "state_revision",
|
|
162
|
+
StateValidation: "state_validation",
|
|
163
|
+
StateValue: "state_value",
|
|
164
|
+
StateVersion: "state_version",
|
|
165
|
+
Subscription: "subscription",
|
|
166
|
+
SubscriptionBusy: "subscription_busy",
|
|
167
|
+
SubscriptionIdle: "subscription_idle",
|
|
168
|
+
SubscriptionQueue: "subscription_queue",
|
|
169
|
+
SubscriptionSize: "subscription_size",
|
|
170
|
+
SubscriptionsDisabled: "subscriptions_disabled",
|
|
171
|
+
Superseded: "superseded",
|
|
172
|
+
Task: "task",
|
|
173
|
+
Telemetry: "telemetry",
|
|
174
|
+
UndeclaredDependency: "undeclared_dependency",
|
|
175
|
+
UndeclaredService: "undeclared_service",
|
|
176
|
+
UnknownService: "unknown_service",
|
|
177
|
+
UpgradeConflict: "upgrade_conflict",
|
|
178
|
+
Utf8: "utf8",
|
|
179
|
+
Value: "value",
|
|
180
|
+
ValueGone: "value_gone",
|
|
181
|
+
ValuesExhausted: "values_exhausted",
|
|
182
|
+
Views: "views",
|
|
183
|
+
} as const);
|
|
184
|
+
export type Reason = ValueOf<typeof Reason>;
|
|
185
|
+
|
|
186
|
+
export const Lifetime = Object.freeze({
|
|
187
|
+
Referenced: "referenced",
|
|
188
|
+
Host: "host",
|
|
189
|
+
} as const);
|
|
190
|
+
export type Lifetime = ValueOf<typeof Lifetime>;
|
|
191
|
+
|
|
192
|
+
export const Status = Object.freeze({
|
|
193
|
+
Loading: "loading",
|
|
194
|
+
Live: "live",
|
|
195
|
+
Released: "released",
|
|
196
|
+
Gone: "gone",
|
|
197
|
+
} as const);
|
|
198
|
+
export type Status = ValueOf<typeof Status>;
|
|
199
|
+
|
|
200
|
+
export const ReloadStatus = Object.freeze({
|
|
201
|
+
Prepared: "prepared",
|
|
202
|
+
Committed: "committed",
|
|
203
|
+
Aborted: "aborted",
|
|
204
|
+
} as const);
|
|
205
|
+
export type ReloadStatus = ValueOf<typeof ReloadStatus>;
|
|
206
|
+
|
|
207
|
+
export const HookCapability = Object.freeze({
|
|
208
|
+
Observe: "observe",
|
|
209
|
+
Transform: "transform",
|
|
210
|
+
Decide: "decide",
|
|
211
|
+
} as const);
|
|
212
|
+
export type HookCapability = ValueOf<typeof HookCapability>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { TembraError } from "../error.ts";
|
|
2
|
+
import { Code, Lifetime } from "./identifiers.ts";
|
|
3
|
+
import { ActionType, EffectType, KernelOp, OwnerKind } from "./protocol.ts";
|
|
4
|
+
|
|
5
|
+
/** Implemented by Node-API, browser WASM, and embedded V8's native binding. */
|
|
6
|
+
export interface KernelPort {
|
|
7
|
+
/** Exchange one JSON metadata request with the Rust kernel. */
|
|
8
|
+
request(metadata: string): string;
|
|
9
|
+
|
|
10
|
+
/** Release the platform binding after host shutdown. */
|
|
11
|
+
free?(): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface KernelFeatures {
|
|
15
|
+
hooks: boolean;
|
|
16
|
+
subscriptions: boolean;
|
|
17
|
+
views: boolean;
|
|
18
|
+
telemetry: boolean;
|
|
19
|
+
}
|
|
20
|
+
export type Owner =
|
|
21
|
+
| { kind: typeof OwnerKind.Host }
|
|
22
|
+
| { kind: typeof OwnerKind.Orb | typeof OwnerKind.Object; id: number };
|
|
23
|
+
export interface KernelOrb {
|
|
24
|
+
id: number;
|
|
25
|
+
owner: number;
|
|
26
|
+
codeVersion: number;
|
|
27
|
+
name: string;
|
|
28
|
+
apiVersion: number;
|
|
29
|
+
services: { name: string; methods: string[]; lifetime: Lifetime; linger: number }[];
|
|
30
|
+
hooks: string[];
|
|
31
|
+
requires: {
|
|
32
|
+
orb: string;
|
|
33
|
+
apiVersion: number;
|
|
34
|
+
services: Record<string, string[]>;
|
|
35
|
+
hooks: string[];
|
|
36
|
+
}[];
|
|
37
|
+
}
|
|
38
|
+
export interface Acquisition {
|
|
39
|
+
reference: number;
|
|
40
|
+
object: number;
|
|
41
|
+
orb: number;
|
|
42
|
+
codeVersion: number;
|
|
43
|
+
activate: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface Invocation {
|
|
46
|
+
id: number;
|
|
47
|
+
root: number;
|
|
48
|
+
object: number;
|
|
49
|
+
orb: number;
|
|
50
|
+
codeVersion: number;
|
|
51
|
+
method: string;
|
|
52
|
+
}
|
|
53
|
+
export interface HookObservation {
|
|
54
|
+
invocation: Invocation;
|
|
55
|
+
plan: number[];
|
|
56
|
+
}
|
|
57
|
+
export interface Snapshot {
|
|
58
|
+
value: number;
|
|
59
|
+
revision: string;
|
|
60
|
+
version: number;
|
|
61
|
+
}
|
|
62
|
+
export interface Reload {
|
|
63
|
+
id: number;
|
|
64
|
+
codeVersion: number;
|
|
65
|
+
orbs: KernelOrb[];
|
|
66
|
+
objects: number[];
|
|
67
|
+
providers: Record<string, number>;
|
|
68
|
+
}
|
|
69
|
+
export interface Effect {
|
|
70
|
+
type: EffectType;
|
|
71
|
+
scope?: number;
|
|
72
|
+
previous?: number | null;
|
|
73
|
+
resource?: number;
|
|
74
|
+
value?: number | null;
|
|
75
|
+
version?: number;
|
|
76
|
+
keepListeners?: boolean;
|
|
77
|
+
replacements?: { previous: number | null; next: number | null }[];
|
|
78
|
+
}
|
|
79
|
+
export interface Action {
|
|
80
|
+
type: ActionType;
|
|
81
|
+
id: number;
|
|
82
|
+
revision?: string;
|
|
83
|
+
effects?: Effect[];
|
|
84
|
+
payload?: number;
|
|
85
|
+
operation?: number;
|
|
86
|
+
error?: { code: Code; reason: string; message: string } | null;
|
|
87
|
+
}
|
|
88
|
+
export interface Diagnostics {
|
|
89
|
+
objects: number;
|
|
90
|
+
references: number;
|
|
91
|
+
roots: number;
|
|
92
|
+
calls: number;
|
|
93
|
+
resources: number;
|
|
94
|
+
tasks: number;
|
|
95
|
+
orbs: number;
|
|
96
|
+
closing: boolean;
|
|
97
|
+
codeVersion: number;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export class Kernel {
|
|
101
|
+
readonly features: KernelFeatures;
|
|
102
|
+
|
|
103
|
+
/** Read the capabilities of the supplied kernel binding. */
|
|
104
|
+
constructor(readonly port: KernelPort) {
|
|
105
|
+
this.features = this.command(KernelOp.Features);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Decode a kernel result or raise its structured error. */
|
|
109
|
+
command<T = null>(op: KernelOp, fields: Record<string, unknown> = {}): T {
|
|
110
|
+
const envelope = JSON.parse(this.port.request(JSON.stringify({ ...fields, op }))) as {
|
|
111
|
+
ok?: T;
|
|
112
|
+
error?: { code: Code; reason: string; message: string };
|
|
113
|
+
};
|
|
114
|
+
if (envelope.error) throw new TembraError(envelope.error);
|
|
115
|
+
return envelope.ok as T;
|
|
116
|
+
}
|
|
117
|
+
}
|