@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
package/dist/codec.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./codecs/json.ts";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Selected once by infrastructure. Local calls and local state reads do not use a codec. */
|
|
2
|
+
export interface Codec {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
/** Encode a portable value using the host's wire contract. */
|
|
5
|
+
serialize(value: unknown): Uint8Array;
|
|
6
|
+
/** Decode bytes using the same wire contract. */
|
|
7
|
+
deserialize(bytes: Uint8Array): unknown;
|
|
8
|
+
}
|
|
9
|
+
/** Also works in a minimal embedded runtime without Web APIs. */
|
|
10
|
+
export declare function utf8(text: string): Uint8Array;
|
|
11
|
+
/** Decode UTF-8 bytes into a string. */
|
|
12
|
+
export declare function text(bytes: Uint8Array): string;
|
|
13
|
+
export declare const jsonCodec: Codec;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Stable scalar keys shared across bundles and languages. */
|
|
2
|
+
import type { Context } from "./runtime/context.ts";
|
|
3
|
+
export declare const ContextKind: Readonly<{
|
|
4
|
+
readonly Text: "text";
|
|
5
|
+
readonly Integer: "integer";
|
|
6
|
+
readonly Boolean: "boolean";
|
|
7
|
+
readonly Opaque: "opaque";
|
|
8
|
+
}>;
|
|
9
|
+
export type ContextKind = (typeof ContextKind)[keyof typeof ContextKind];
|
|
10
|
+
/** An owner-issued reference. Its token does not retain the source frame. */
|
|
11
|
+
export interface OpaqueContextValue {
|
|
12
|
+
readonly opaque: true;
|
|
13
|
+
}
|
|
14
|
+
export declare class ContextKey<T> {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly version: number;
|
|
17
|
+
readonly kind: ContextKind;
|
|
18
|
+
private readonly type;
|
|
19
|
+
/** Retain a frozen key contract; Rust validates its use. */
|
|
20
|
+
private constructor();
|
|
21
|
+
/** Declare a text binding with stable identity. */
|
|
22
|
+
static text(name: string, version?: number): ContextKey<string>;
|
|
23
|
+
/** Declare an integer binding with stable identity. */
|
|
24
|
+
static integer(name: string, version?: number): ContextKey<number>;
|
|
25
|
+
/** Declare a boolean binding with stable identity. */
|
|
26
|
+
static boolean(name: string, version?: number): ContextKey<boolean>;
|
|
27
|
+
/** Declare an opaque binding with stable identity. */
|
|
28
|
+
static opaque(name: string, version?: number): ContextKey<OpaqueContextValue>;
|
|
29
|
+
/** Resolve a token issued by the owner in this host and root. */
|
|
30
|
+
source(value: T, ctx: Context): number | undefined;
|
|
31
|
+
}
|
|
32
|
+
/** Read metadata or wrap an owner-issued local reference. */
|
|
33
|
+
export declare function readContextValue<T>(ctx: Context, key: ContextKey<T>, frame: number): T | undefined;
|
|
34
|
+
/** Read an owner-issued reference from a live source frame. */
|
|
35
|
+
export declare function opaqueFrom(ctx: Context, key: ContextKey<OpaqueContextValue>, issuedFrame: number): OpaqueContextValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./infrastructure/coordinator.ts";
|
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
// src/bridge/protocol.ts
|
|
2
|
+
var KernelOp = Object.freeze({
|
|
3
|
+
ContextDerive: "context-derive",
|
|
4
|
+
ContextValue: "context-value",
|
|
5
|
+
ContextStats: "context-stats",
|
|
6
|
+
Allocate: "allocate",
|
|
7
|
+
ScopeRegister: "scope-register",
|
|
8
|
+
ScopeExists: "scope-exists",
|
|
9
|
+
ScopesForOwner: "scopes-for-owner",
|
|
10
|
+
ScopesForOrb: "scopes-for-orb",
|
|
11
|
+
ScopeAddResource: "scope-add-resource",
|
|
12
|
+
ScopeActivate: "scope-activate",
|
|
13
|
+
ScopesCleanup: "scopes-cleanup",
|
|
14
|
+
ScopesReloadRegistered: "scopes-reload-registered",
|
|
15
|
+
ScopesReload: "scopes-reload",
|
|
16
|
+
ProgramRun: "program-run",
|
|
17
|
+
ProgramNext: "program-next",
|
|
18
|
+
ProgramCompleteStep: "program-complete-step",
|
|
19
|
+
ProgramCommit: "program-commit",
|
|
20
|
+
ProgramAbort: "program-abort",
|
|
21
|
+
ProgramForget: "program-forget",
|
|
22
|
+
Features: "features",
|
|
23
|
+
Prepare: "prepare",
|
|
24
|
+
Gate: "gate",
|
|
25
|
+
GateOrbs: "gate-orbs",
|
|
26
|
+
Commit: "commit",
|
|
27
|
+
Abort: "abort",
|
|
28
|
+
Orbs: "orbs",
|
|
29
|
+
Orb: "orb",
|
|
30
|
+
OrbNamed: "orb-named",
|
|
31
|
+
NextDeadline: "next-deadline",
|
|
32
|
+
Address: "address",
|
|
33
|
+
Acquire: "acquire",
|
|
34
|
+
Ready: "ready",
|
|
35
|
+
Dependency: "dependency",
|
|
36
|
+
Undepend: "undepend",
|
|
37
|
+
Fail: "fail",
|
|
38
|
+
Status: "status",
|
|
39
|
+
Release: "release",
|
|
40
|
+
Forget: "forget",
|
|
41
|
+
Root: "root",
|
|
42
|
+
CleanupRoot: "cleanup-root",
|
|
43
|
+
RootPrincipal: "root-principal",
|
|
44
|
+
CheckContext: "check-context",
|
|
45
|
+
CheckRoot: "check-root",
|
|
46
|
+
EndRoot: "end-root",
|
|
47
|
+
CancelRoot: "cancel-root",
|
|
48
|
+
BeginCall: "begin-call",
|
|
49
|
+
BeginOperation: "begin-operation",
|
|
50
|
+
BeginHookObservation: "begin-hook-observation",
|
|
51
|
+
FinishCall: "finish-call",
|
|
52
|
+
Invocation: "invocation",
|
|
53
|
+
StateInit: "state-init",
|
|
54
|
+
Snapshot: "snapshot",
|
|
55
|
+
StateAdopt: "state-adopt",
|
|
56
|
+
Task: "task",
|
|
57
|
+
TaskRoot: "task-root",
|
|
58
|
+
StopTask: "stop-task",
|
|
59
|
+
FinishTask: "finish-task",
|
|
60
|
+
Resource: "resource",
|
|
61
|
+
ResourceOpened: "resource-opened",
|
|
62
|
+
ResourceValue: "resource-value",
|
|
63
|
+
CloseResource: "close-resource",
|
|
64
|
+
ResourceClosed: "resource-closed",
|
|
65
|
+
Disposed: "disposed",
|
|
66
|
+
Tick: "tick",
|
|
67
|
+
NextWake: "next-wake",
|
|
68
|
+
NextIdle: "next-idle",
|
|
69
|
+
Close: "close",
|
|
70
|
+
FinishClose: "finish-close",
|
|
71
|
+
Diagnostics: "diagnostics",
|
|
72
|
+
Drain: "drain",
|
|
73
|
+
Restrict: "restrict",
|
|
74
|
+
Contribute: "contribute",
|
|
75
|
+
ContributionOrdinal: "contribution-ordinal",
|
|
76
|
+
HookPlan: "hook-plan",
|
|
77
|
+
Listen: "listen",
|
|
78
|
+
Subscribe: "subscribe",
|
|
79
|
+
Enqueue: "enqueue",
|
|
80
|
+
NextDelivery: "next-delivery",
|
|
81
|
+
FinishDelivery: "finish-delivery",
|
|
82
|
+
Unsubscribe: "unsubscribe"
|
|
83
|
+
});
|
|
84
|
+
var ActionType = Object.freeze({
|
|
85
|
+
Execute: "execute",
|
|
86
|
+
CancelEffects: "cancel-effects",
|
|
87
|
+
ProgramPrepared: "program-prepared",
|
|
88
|
+
ProgramComplete: "program-complete",
|
|
89
|
+
Dispose: "dispose",
|
|
90
|
+
CloseResource: "close-resource",
|
|
91
|
+
DropValue: "drop-value",
|
|
92
|
+
CancelRoot: "cancel-root",
|
|
93
|
+
CancelTask: "cancel-task",
|
|
94
|
+
RetireOrb: "retire-orb",
|
|
95
|
+
State: "state",
|
|
96
|
+
SubscriptionFailed: "subscription-failed",
|
|
97
|
+
DetachSubscription: "detach-subscription",
|
|
98
|
+
Deliver: "deliver"
|
|
99
|
+
});
|
|
100
|
+
var EffectType = Object.freeze({
|
|
101
|
+
Stop: "stop",
|
|
102
|
+
Open: "open",
|
|
103
|
+
Close: "close",
|
|
104
|
+
Restore: "restore",
|
|
105
|
+
Prepare: "prepare",
|
|
106
|
+
Validate: "validate",
|
|
107
|
+
Initialize: "initialize",
|
|
108
|
+
Migrate: "migrate",
|
|
109
|
+
Adopt: "adopt",
|
|
110
|
+
Start: "start",
|
|
111
|
+
Drop: "drop"
|
|
112
|
+
});
|
|
113
|
+
var StepType = Object.freeze({
|
|
114
|
+
Execute: "execute",
|
|
115
|
+
Wait: "wait",
|
|
116
|
+
Prepared: "prepared",
|
|
117
|
+
Complete: "complete",
|
|
118
|
+
Failed: "failed"
|
|
119
|
+
});
|
|
120
|
+
var NativeOp = Object.freeze({
|
|
121
|
+
Activate: "activate",
|
|
122
|
+
Dispose: "dispose",
|
|
123
|
+
CancelEffect: "cancel-effect",
|
|
124
|
+
Effect: "effect",
|
|
125
|
+
Invoke: "invoke",
|
|
126
|
+
Contribute: "contribute"
|
|
127
|
+
});
|
|
128
|
+
var RpcOp = Object.freeze({
|
|
129
|
+
Describe: "describe",
|
|
130
|
+
Get: "get",
|
|
131
|
+
Release: "release",
|
|
132
|
+
Call: "call",
|
|
133
|
+
Cancel: "cancel"
|
|
134
|
+
});
|
|
135
|
+
var RpcEvent = Object.freeze({
|
|
136
|
+
State: "state"
|
|
137
|
+
});
|
|
138
|
+
var OwnerKind = Object.freeze({
|
|
139
|
+
Host: "host",
|
|
140
|
+
Orb: "orb",
|
|
141
|
+
Object: "object"
|
|
142
|
+
});
|
|
143
|
+
var EnvironmentPhase = Object.freeze({
|
|
144
|
+
Declaring: "declaring",
|
|
145
|
+
Prepared: "prepared",
|
|
146
|
+
Live: "live",
|
|
147
|
+
Closed: "closed"
|
|
148
|
+
});
|
|
149
|
+
var CoordinationDecision = Object.freeze({
|
|
150
|
+
Preparing: "preparing",
|
|
151
|
+
Commit: "commit",
|
|
152
|
+
Abort: "abort"
|
|
153
|
+
});
|
|
154
|
+
var Outcome = Object.freeze({
|
|
155
|
+
Ok: "ok",
|
|
156
|
+
Error: "error"
|
|
157
|
+
});
|
|
158
|
+
var CodecTag = Object.freeze({
|
|
159
|
+
Bigint: "bigint",
|
|
160
|
+
Bytes: "bytes",
|
|
161
|
+
Object: "object"
|
|
162
|
+
});
|
|
163
|
+
var CodecId = Object.freeze({
|
|
164
|
+
Json: "tembra-json/1",
|
|
165
|
+
MessagePack: "tembra-msgpack/1"
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// src/bridge/identifiers.ts
|
|
169
|
+
var Code = Object.freeze({
|
|
170
|
+
Invalid: "invalid",
|
|
171
|
+
Unavailable: "unavailable",
|
|
172
|
+
Released: "released",
|
|
173
|
+
Gone: "gone",
|
|
174
|
+
Expired: "expired",
|
|
175
|
+
Cancelled: "cancelled",
|
|
176
|
+
Forbidden: "forbidden",
|
|
177
|
+
Conflict: "conflict",
|
|
178
|
+
Unsupported: "unsupported",
|
|
179
|
+
Closed: "closed",
|
|
180
|
+
Exhausted: "exhausted"
|
|
181
|
+
});
|
|
182
|
+
var Reason = Object.freeze({
|
|
183
|
+
ActivationBusy: "activation_busy",
|
|
184
|
+
Address: "address",
|
|
185
|
+
AlreadyCommitted: "already_committed",
|
|
186
|
+
AmbiguousScope: "ambiguous_scope",
|
|
187
|
+
ApiVersion: "api_version",
|
|
188
|
+
Arguments: "arguments",
|
|
189
|
+
AsyncFactory: "async_factory",
|
|
190
|
+
AsyncState: "async_state",
|
|
191
|
+
Bigint: "bigint",
|
|
192
|
+
ByteResult: "byte_result",
|
|
193
|
+
Call: "call",
|
|
194
|
+
Callback: "callback",
|
|
195
|
+
CleanupBusy: "cleanup_busy",
|
|
196
|
+
Clock: "clock",
|
|
197
|
+
Codec: "codec",
|
|
198
|
+
Connection: "connection",
|
|
199
|
+
Context: "context",
|
|
200
|
+
Contribution: "contribution",
|
|
201
|
+
CoordinationLimits: "coordination_limits",
|
|
202
|
+
Deadline: "deadline",
|
|
203
|
+
Dependency: "dependency",
|
|
204
|
+
DependencyCycle: "dependency_cycle",
|
|
205
|
+
DependencyService: "dependency_service",
|
|
206
|
+
Disposing: "disposing",
|
|
207
|
+
Driver: "driver",
|
|
208
|
+
Duplicate: "duplicate",
|
|
209
|
+
DuplicateContribution: "duplicate_contribution",
|
|
210
|
+
DuplicateListener: "duplicate_listener",
|
|
211
|
+
DuplicateResource: "duplicate_resource",
|
|
212
|
+
DuplicateService: "duplicate_service",
|
|
213
|
+
EffectResults: "effect_results",
|
|
214
|
+
EffectsRunning: "effects_running",
|
|
215
|
+
EngineEffect: "engine_effect",
|
|
216
|
+
EventSource: "event_source",
|
|
217
|
+
ExclusiveDependent: "exclusive_dependent",
|
|
218
|
+
Executor: "executor",
|
|
219
|
+
Orb: "orb",
|
|
220
|
+
OrbGone: "orb_gone",
|
|
221
|
+
OrbInstalled: "orb_installed",
|
|
222
|
+
OrbScope: "orb_scope",
|
|
223
|
+
Factory: "factory",
|
|
224
|
+
FactoryExpired: "factory_expired",
|
|
225
|
+
FrameSize: "frame_size",
|
|
226
|
+
GateBusy: "gate_busy",
|
|
227
|
+
GateOrb: "gate_orb",
|
|
228
|
+
GateObject: "gate_object",
|
|
229
|
+
Hook: "hook",
|
|
230
|
+
HookDependency: "hook_dependency",
|
|
231
|
+
Hooks: "hooks",
|
|
232
|
+
HooksDisabled: "hooks_disabled",
|
|
233
|
+
Host: "host",
|
|
234
|
+
HostAddress: "host_address",
|
|
235
|
+
HostResource: "host_resource",
|
|
236
|
+
HostResourceReload: "host_resource_reload",
|
|
237
|
+
Identities: "identities",
|
|
238
|
+
Implementation: "implementation",
|
|
239
|
+
Invocation: "invocation",
|
|
240
|
+
Javascript: "javascript",
|
|
241
|
+
JsonAccessor: "json_accessor",
|
|
242
|
+
JsonCycle: "json_cycle",
|
|
243
|
+
JsonNumber: "json_number",
|
|
244
|
+
JsonSymbol: "json_symbol",
|
|
245
|
+
JsonTag: "json_tag",
|
|
246
|
+
JsonType: "json_type",
|
|
247
|
+
JsonValue: "json_value",
|
|
248
|
+
Lifetime: "lifetime",
|
|
249
|
+
Linger: "linger",
|
|
250
|
+
ListenerCallback: "listener_callback",
|
|
251
|
+
LiveConsumer: "live_consumer",
|
|
252
|
+
LiveReference: "live_reference",
|
|
253
|
+
LocalValue: "local_value",
|
|
254
|
+
Memory: "memory",
|
|
255
|
+
Metadata: "metadata",
|
|
256
|
+
MetadataSize: "metadata_size",
|
|
257
|
+
Method: "method",
|
|
258
|
+
MigrationGate: "migration_gate",
|
|
259
|
+
MigrationRequired: "migration_required",
|
|
260
|
+
MigrationValue: "migration_value",
|
|
261
|
+
MissingHook: "missing_hook",
|
|
262
|
+
MissingMethod: "missing_method",
|
|
263
|
+
NativeEffect: "native_effect",
|
|
264
|
+
NativeMethod: "native_method",
|
|
265
|
+
NativeObject: "native_object",
|
|
266
|
+
NativeService: "native_service",
|
|
267
|
+
Next: "next",
|
|
268
|
+
NextUsed: "next_used",
|
|
269
|
+
NotReady: "not_ready",
|
|
270
|
+
Object: "object",
|
|
271
|
+
ObjectState: "object_state",
|
|
272
|
+
ObservationSource: "observation_source",
|
|
273
|
+
ObservationAdmitted: "observation_admitted",
|
|
274
|
+
Opaque: "opaque",
|
|
275
|
+
Operation: "operation",
|
|
276
|
+
OperationOwner: "operation_owner",
|
|
277
|
+
Owner: "owner",
|
|
278
|
+
Payload: "payload",
|
|
279
|
+
PendingRequests: "pending_requests",
|
|
280
|
+
PrepareDeadline: "prepare_deadline",
|
|
281
|
+
Priority: "priority",
|
|
282
|
+
Program: "program",
|
|
283
|
+
ProgramPhase: "program_phase",
|
|
284
|
+
ProgramRunning: "program_running",
|
|
285
|
+
Reference: "reference",
|
|
286
|
+
ReloadAborted: "reload_aborted",
|
|
287
|
+
ReloadDeadline: "reload_deadline",
|
|
288
|
+
ReloadPreparing: "reload_preparing",
|
|
289
|
+
ReloadRunning: "reload_running",
|
|
290
|
+
ReloadTicket: "reload_ticket",
|
|
291
|
+
RemoteOpaque: "remote_opaque",
|
|
292
|
+
RemoteReferences: "remote_references",
|
|
293
|
+
Request: "request",
|
|
294
|
+
RequestIds: "request_ids",
|
|
295
|
+
Requires: "requires",
|
|
296
|
+
Resource: "resource",
|
|
297
|
+
ResourceDependencies: "resource_dependencies",
|
|
298
|
+
ResourceDependency: "resource_dependency",
|
|
299
|
+
ResourceHost: "resource_host",
|
|
300
|
+
ResourceInFactory: "resource_in_factory",
|
|
301
|
+
ResourceState: "resource_state",
|
|
302
|
+
ResourceVersion: "resource_version",
|
|
303
|
+
Result: "result",
|
|
304
|
+
RetainedVersions: "retained_versions",
|
|
305
|
+
RevisionExhausted: "revision_exhausted",
|
|
306
|
+
Root: "root",
|
|
307
|
+
Route: "route",
|
|
308
|
+
RpcFrame: "rpc_frame",
|
|
309
|
+
RpcOperation: "rpc_operation",
|
|
310
|
+
RpcRequest: "rpc_request",
|
|
311
|
+
RustType: "rust_type",
|
|
312
|
+
Scope: "scope",
|
|
313
|
+
ScopeClosed: "scope_closed",
|
|
314
|
+
ScopeOrb: "scope_orb",
|
|
315
|
+
ScopeOwner: "scope_owner",
|
|
316
|
+
ScopeResource: "scope_resource",
|
|
317
|
+
Serialization: "serialization",
|
|
318
|
+
Service: "service",
|
|
319
|
+
ServiceGone: "service_gone",
|
|
320
|
+
State: "state",
|
|
321
|
+
StateCycle: "state_cycle",
|
|
322
|
+
StateInitialized: "state_initialized",
|
|
323
|
+
StateOwner: "state_owner",
|
|
324
|
+
StateRevision: "state_revision",
|
|
325
|
+
StateValidation: "state_validation",
|
|
326
|
+
StateValue: "state_value",
|
|
327
|
+
StateVersion: "state_version",
|
|
328
|
+
Subscription: "subscription",
|
|
329
|
+
SubscriptionBusy: "subscription_busy",
|
|
330
|
+
SubscriptionIdle: "subscription_idle",
|
|
331
|
+
SubscriptionQueue: "subscription_queue",
|
|
332
|
+
SubscriptionSize: "subscription_size",
|
|
333
|
+
SubscriptionsDisabled: "subscriptions_disabled",
|
|
334
|
+
Superseded: "superseded",
|
|
335
|
+
Task: "task",
|
|
336
|
+
Telemetry: "telemetry",
|
|
337
|
+
UndeclaredDependency: "undeclared_dependency",
|
|
338
|
+
UndeclaredService: "undeclared_service",
|
|
339
|
+
UnknownService: "unknown_service",
|
|
340
|
+
UpgradeConflict: "upgrade_conflict",
|
|
341
|
+
Utf8: "utf8",
|
|
342
|
+
Value: "value",
|
|
343
|
+
ValueGone: "value_gone",
|
|
344
|
+
ValuesExhausted: "values_exhausted",
|
|
345
|
+
Views: "views"
|
|
346
|
+
});
|
|
347
|
+
var Lifetime = Object.freeze({
|
|
348
|
+
Referenced: "referenced",
|
|
349
|
+
Host: "host"
|
|
350
|
+
});
|
|
351
|
+
var Status = Object.freeze({
|
|
352
|
+
Loading: "loading",
|
|
353
|
+
Live: "live",
|
|
354
|
+
Released: "released",
|
|
355
|
+
Gone: "gone"
|
|
356
|
+
});
|
|
357
|
+
var ReloadStatus = Object.freeze({
|
|
358
|
+
Prepared: "prepared",
|
|
359
|
+
Committed: "committed",
|
|
360
|
+
Aborted: "aborted"
|
|
361
|
+
});
|
|
362
|
+
var HookCapability = Object.freeze({
|
|
363
|
+
Observe: "observe",
|
|
364
|
+
Transform: "transform",
|
|
365
|
+
Decide: "decide"
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
// src/errors.ts
|
|
369
|
+
function define(code, reason, message) {
|
|
370
|
+
return Object.freeze({ code, reason, message });
|
|
371
|
+
}
|
|
372
|
+
var Errors = Object.freeze({
|
|
373
|
+
Cancelled: Object.freeze({
|
|
374
|
+
EngineEffect: define(Code.Cancelled, Reason.EngineEffect, "The engine effect was cancelled"),
|
|
375
|
+
Request: define(Code.Cancelled, Reason.Request, "The request was cancelled"),
|
|
376
|
+
Resource: define(Code.Cancelled, Reason.Resource, "Resource opening was cancelled"),
|
|
377
|
+
Root: define(Code.Cancelled, Reason.Root, "The operation was cancelled"),
|
|
378
|
+
Task: define(Code.Cancelled, Reason.Task, "The task was cancelled")
|
|
379
|
+
}),
|
|
380
|
+
Closed: Object.freeze({
|
|
381
|
+
Host: define(Code.Closed, Reason.Host, "The host is closing")
|
|
382
|
+
}),
|
|
383
|
+
Conflict: Object.freeze({
|
|
384
|
+
AlreadyCommitted: define(Code.Conflict, Reason.AlreadyCommitted, "The replacement is already committed"),
|
|
385
|
+
Codec: define(Code.Conflict, Reason.Codec, "The Rust and JS host codecs must agree"),
|
|
386
|
+
PrepareDeadline: define(Code.Conflict, Reason.PrepareDeadline, "The preparation deadline expired"),
|
|
387
|
+
ReloadRunning: define(Code.Conflict, Reason.ReloadRunning, "A replacement is already running"),
|
|
388
|
+
ReloadTicket: define(Code.Conflict, Reason.ReloadTicket, "The replacement is no longer prepared")
|
|
389
|
+
}),
|
|
390
|
+
Exhausted: Object.freeze({
|
|
391
|
+
FrameSize: define(Code.Exhausted, Reason.FrameSize, "The frame exceeds the configured size limit"),
|
|
392
|
+
PendingRequests: define(Code.Exhausted, Reason.PendingRequests, "The pending request limit was reached"),
|
|
393
|
+
RemoteReferences: define(Code.Exhausted, Reason.RemoteReferences, "The remote reference limit was reached"),
|
|
394
|
+
RequestIds: define(Code.Exhausted, Reason.RequestIds, "Request identities are exhausted"),
|
|
395
|
+
SubscriptionQueue: define(Code.Exhausted, Reason.SubscriptionQueue, "The subscription queue is full")
|
|
396
|
+
}),
|
|
397
|
+
Expired: Object.freeze({
|
|
398
|
+
Next: define(Code.Expired, Reason.Next, "Continuation scope has ended")
|
|
399
|
+
}),
|
|
400
|
+
Forbidden: Object.freeze({
|
|
401
|
+
Context: define(Code.Forbidden, Reason.Context, "An issued context from this host is required"),
|
|
402
|
+
HostResource: define(Code.Forbidden, Reason.HostResource, "The host resource was not declared"),
|
|
403
|
+
Method: define(Code.Forbidden, Reason.Method, "The method is not allowed by this reference"),
|
|
404
|
+
ObservationSource: define(Code.Forbidden, Reason.ObservationSource, "Hook observation requires the original physical invocation"),
|
|
405
|
+
Opaque: define(Code.Forbidden, Reason.Opaque, "The resource is not available as an opaque local value"),
|
|
406
|
+
Service: define(Code.Forbidden, Reason.Service, "Access to this service is forbidden"),
|
|
407
|
+
StateOwner: define(Code.Forbidden, Reason.StateOwner, "Only the owning orb may change this state"),
|
|
408
|
+
UndeclaredDependency: define(Code.Forbidden, Reason.UndeclaredDependency, "The dependency was not declared"),
|
|
409
|
+
UndeclaredService: define(Code.Forbidden, Reason.UndeclaredService, "The service was not declared as a dependency")
|
|
410
|
+
}),
|
|
411
|
+
Gone: Object.freeze({
|
|
412
|
+
Connection: define(Code.Gone, Reason.Connection, "The connection is closed"),
|
|
413
|
+
Contribution: define(Code.Gone, Reason.Contribution, "The contribution is no longer available"),
|
|
414
|
+
Implementation: define(Code.Gone, Reason.Implementation, "The implementation is no longer available"),
|
|
415
|
+
ListenerCallback: define(Code.Gone, Reason.ListenerCallback, "The listener callback is no longer available"),
|
|
416
|
+
Reference: define(Code.Gone, Reason.Reference, "The reference is no longer available"),
|
|
417
|
+
Resource: define(Code.Gone, Reason.Resource, "The resource is no longer available"),
|
|
418
|
+
Scope: define(Code.Gone, Reason.Scope, "The declaration scope is no longer available"),
|
|
419
|
+
State: define(Code.Gone, Reason.State, "State owner is gone")
|
|
420
|
+
}),
|
|
421
|
+
Invalid: Object.freeze({
|
|
422
|
+
Address: define(Code.Invalid, Reason.Address, "Invalid address"),
|
|
423
|
+
AsyncFactory: define(Code.Invalid, Reason.AsyncFactory, "Factories must be synchronous"),
|
|
424
|
+
AsyncState: define(Code.Invalid, Reason.AsyncState, "State updates and migrations must be synchronous"),
|
|
425
|
+
CoordinationLimits: define(Code.Invalid, Reason.CoordinationLimits, "Invalid coordination limits"),
|
|
426
|
+
DependencyCycle: define(Code.Invalid, Reason.DependencyCycle, "Orb factories cannot acquire their own services"),
|
|
427
|
+
DependencyService: define(Code.Invalid, Reason.DependencyService, "Invalid dependency service"),
|
|
428
|
+
DuplicateListener: define(Code.Invalid, Reason.DuplicateListener, "Invalid duplicate listener"),
|
|
429
|
+
DuplicateResource: define(Code.Invalid, Reason.DuplicateResource, "Invalid duplicate resource"),
|
|
430
|
+
EventSource: define(Code.Invalid, Reason.EventSource, "Invalid event source"),
|
|
431
|
+
Orb: define(Code.Invalid, Reason.Orb, "An orb needs a name and positive API version"),
|
|
432
|
+
OrbGone: define(Code.Invalid, Reason.OrbGone, "Invalid orb gone"),
|
|
433
|
+
OrbInstalled: define(Code.Invalid, Reason.OrbInstalled, "Use reload to replace an installed orb"),
|
|
434
|
+
Factory: define(Code.Invalid, Reason.Factory, "Invalid factory"),
|
|
435
|
+
FactoryExpired: define(Code.Invalid, Reason.FactoryExpired, "Declarations must be synchronous"),
|
|
436
|
+
Hook: define(Code.Invalid, Reason.Hook, "Hooks need a run function"),
|
|
437
|
+
HookDependency: define(Code.Invalid, Reason.HookDependency, "Invalid hook dependency"),
|
|
438
|
+
HooksDisabled: define(Code.Invalid, Reason.HooksDisabled, "Invalid hooks disabled"),
|
|
439
|
+
JsonAccessor: define(Code.Invalid, Reason.JsonAccessor, "Invalid json accessor"),
|
|
440
|
+
JsonCycle: define(Code.Invalid, Reason.JsonCycle, "Invalid json cycle"),
|
|
441
|
+
JsonNumber: define(Code.Invalid, Reason.JsonNumber, "Use BigInt for integers outside the safe Number range"),
|
|
442
|
+
JsonSymbol: define(Code.Invalid, Reason.JsonSymbol, "Invalid json symbol"),
|
|
443
|
+
JsonTag: define(Code.Invalid, Reason.JsonTag, "Unknown or malformed portable type tag"),
|
|
444
|
+
JsonType: define(Code.Invalid, Reason.JsonType, "Supply a codec for custom object types"),
|
|
445
|
+
JsonValue: define(Code.Invalid, Reason.JsonValue, "This JSON codec requires explicit portable values"),
|
|
446
|
+
Method: define(Code.Invalid, Reason.Method, "Methods must be functions"),
|
|
447
|
+
NextUsed: define(Code.Invalid, Reason.NextUsed, "Invalid next used"),
|
|
448
|
+
Priority: define(Code.Invalid, Reason.Priority, "Invalid priority"),
|
|
449
|
+
Reference: define(Code.Invalid, Reason.Reference, "An issued local reference is required"),
|
|
450
|
+
Resource: define(Code.Invalid, Reason.Resource, "Invalid resource"),
|
|
451
|
+
ResourceHost: define(Code.Invalid, Reason.ResourceHost, "Resource dependencies must belong to the same host"),
|
|
452
|
+
ResourceInFactory: define(Code.Invalid, Reason.ResourceInFactory, "Resources open after declaration"),
|
|
453
|
+
RpcFrame: define(Code.Invalid, Reason.RpcFrame, "Invalid rpc frame"),
|
|
454
|
+
RpcOperation: define(Code.Invalid, Reason.RpcOperation, "Invalid rpc operation"),
|
|
455
|
+
RpcRequest: define(Code.Invalid, Reason.RpcRequest, "Invalid rpc request"),
|
|
456
|
+
Service: define(Code.Invalid, Reason.Service, "Invalid service"),
|
|
457
|
+
ServiceGone: define(Code.Invalid, Reason.ServiceGone, "Invalid service gone"),
|
|
458
|
+
State: define(Code.Invalid, Reason.State, "Service does not expose state"),
|
|
459
|
+
StateCycle: define(Code.Invalid, Reason.StateCycle, "State cannot contain cycles"),
|
|
460
|
+
StateValidation: define(Code.Invalid, Reason.StateValidation, "The orb rejected the state candidate"),
|
|
461
|
+
StateValue: define(Code.Invalid, Reason.StateValue, "State cannot contain accessors"),
|
|
462
|
+
StateVersion: define(Code.Invalid, Reason.StateVersion, "Invalid state version"),
|
|
463
|
+
SubscriptionsDisabled: define(Code.Invalid, Reason.SubscriptionsDisabled, "Invalid subscriptions disabled"),
|
|
464
|
+
SubscriptionSize: define(Code.Invalid, Reason.SubscriptionSize, "A local byte budget requires an explicit sizeOf function"),
|
|
465
|
+
Task: define(Code.Invalid, Reason.Task, "Invalid task"),
|
|
466
|
+
Utf8: define(Code.Invalid, Reason.Utf8, "Invalid utf8"),
|
|
467
|
+
ValueGone: define(Code.Invalid, Reason.ValueGone, "Invalid value gone"),
|
|
468
|
+
ValuesExhausted: define(Code.Invalid, Reason.ValuesExhausted, "Invalid values exhausted")
|
|
469
|
+
}),
|
|
470
|
+
Released: Object.freeze({
|
|
471
|
+
Reference: define(Code.Released, Reason.Reference, "The reference has been released")
|
|
472
|
+
}),
|
|
473
|
+
Unavailable: Object.freeze({
|
|
474
|
+
Callback: define(Code.Unavailable, Reason.Callback, "A callback failed"),
|
|
475
|
+
OrbScope: define(Code.Unavailable, Reason.OrbScope, "The orb scope is unavailable"),
|
|
476
|
+
NotReady: define(Code.Unavailable, Reason.NotReady, "The object is not ready"),
|
|
477
|
+
Route: define(Code.Unavailable, Reason.Route, "The route is unavailable")
|
|
478
|
+
}),
|
|
479
|
+
Unsupported: Object.freeze({
|
|
480
|
+
EngineEffect: define(Code.Unsupported, Reason.EngineEffect, "The engine effect is not supported by this adapter"),
|
|
481
|
+
RemoteOpaque: define(Code.Unsupported, Reason.RemoteOpaque, "Opaque resources are local to their language environment"),
|
|
482
|
+
Telemetry: define(Code.Unsupported, Reason.Telemetry, "Telemetry is disabled in this kernel"),
|
|
483
|
+
Views: define(Code.Unsupported, Reason.Views, "Reference views are disabled in this kernel")
|
|
484
|
+
})
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
// src/error.ts
|
|
488
|
+
var codes = new Set(Object.values(Code));
|
|
489
|
+
class TembraError extends Error {
|
|
490
|
+
code;
|
|
491
|
+
reason;
|
|
492
|
+
constructor(error, message = error.message, options) {
|
|
493
|
+
super(message, options);
|
|
494
|
+
this.name = "TembraError";
|
|
495
|
+
this.code = error.code;
|
|
496
|
+
this.reason = error.reason;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// src/infrastructure/coordinator.ts
|
|
501
|
+
async function coordinate(participants, options = {}) {
|
|
502
|
+
const deadline = options.deadline ?? 5000;
|
|
503
|
+
if (participants.length > (options.maxParticipants ?? 32) || !Number.isFinite(deadline) || deadline <= 0)
|
|
504
|
+
throw new TembraError(Errors.Invalid.CoordinationLimits);
|
|
505
|
+
const controller = new AbortController;
|
|
506
|
+
const prepared = new Map;
|
|
507
|
+
let decision = CoordinationDecision.Preparing;
|
|
508
|
+
let timer;
|
|
509
|
+
const preparation = Promise.all(participants.map(async (participant) => {
|
|
510
|
+
const ticket = await participant.prepare(controller.signal);
|
|
511
|
+
if (decision === CoordinationDecision.Abort)
|
|
512
|
+
await participant.abort(ticket);
|
|
513
|
+
else
|
|
514
|
+
prepared.set(participant, ticket);
|
|
515
|
+
}));
|
|
516
|
+
try {
|
|
517
|
+
await Promise.race([
|
|
518
|
+
preparation,
|
|
519
|
+
new Promise((_, reject) => {
|
|
520
|
+
timer = setTimeout(() => reject(new TembraError(Errors.Conflict.PrepareDeadline)), deadline);
|
|
521
|
+
})
|
|
522
|
+
]);
|
|
523
|
+
decision = CoordinationDecision.Commit;
|
|
524
|
+
} catch (error) {
|
|
525
|
+
decision = CoordinationDecision.Abort;
|
|
526
|
+
controller.abort(error);
|
|
527
|
+
const aborted = await Promise.allSettled([...prepared].map(([participant, ticket]) => participant.abort(ticket)));
|
|
528
|
+
preparation.catch(() => {});
|
|
529
|
+
const errors = aborted.filter((result) => result.status === "rejected").map((result) => result.reason);
|
|
530
|
+
if (errors.length)
|
|
531
|
+
throw new AggregateError([error, ...errors], "Preparation and cleanup failed");
|
|
532
|
+
throw error;
|
|
533
|
+
} finally {
|
|
534
|
+
clearTimeout(timer);
|
|
535
|
+
}
|
|
536
|
+
const committed = await Promise.allSettled([...prepared].map(([participant, ticket]) => participant.commit(ticket)));
|
|
537
|
+
const errors = committed.filter((result) => result.status === "rejected").map((result) => result.reason);
|
|
538
|
+
if (errors.length)
|
|
539
|
+
throw new AggregateError(errors, "Commit was decided but some participants did not acknowledge it");
|
|
540
|
+
}
|
|
541
|
+
export {
|
|
542
|
+
coordinate
|
|
543
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|