@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/src/values.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Errors } from "./errors.ts";
|
|
2
|
+
|
|
3
|
+
import { refuse } from "./error.ts";
|
|
4
|
+
|
|
5
|
+
/** Owned bridge slots. Local values never pass through the metadata kernel or a codec. */
|
|
6
|
+
export class Values {
|
|
7
|
+
#next = 1;
|
|
8
|
+
#values = new Map<number, unknown>();
|
|
9
|
+
|
|
10
|
+
/** Use the shared kernel allocator when values cross language adapters. */
|
|
11
|
+
constructor(readonly allocate?: () => number) {}
|
|
12
|
+
|
|
13
|
+
/** Retain a value under a fresh bridge identity. */
|
|
14
|
+
put(value: unknown): number {
|
|
15
|
+
if (this.#next > 0xffff_ffff) refuse(Errors.Invalid.ValuesExhausted);
|
|
16
|
+
const id = this.allocate ? this.allocate() : this.#next++;
|
|
17
|
+
this.#values.set(id, value);
|
|
18
|
+
return id;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Resolve a retained value or reject an expired identity. */
|
|
22
|
+
get<T = unknown>(id: number): T {
|
|
23
|
+
if (!this.#values.has(id)) refuse(Errors.Invalid.ValueGone);
|
|
24
|
+
return this.#values.get(id) as T;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Release the value held by one bridge identity. */
|
|
28
|
+
drop(id: number): void {
|
|
29
|
+
this.#values.delete(id);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Check whether this adapter already retains the value. */
|
|
33
|
+
has(id: number): boolean {
|
|
34
|
+
return this.#values.has(id);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Cache a value under an identity issued by another adapter. */
|
|
38
|
+
set(id: number, value: unknown): void {
|
|
39
|
+
this.#values.set(id, value);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Release all retained values at host shutdown. */
|
|
43
|
+
clear(): void {
|
|
44
|
+
this.#values.clear();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Count the value slots retained by this adapter. */
|
|
48
|
+
get size(): number {
|
|
49
|
+
return this.#values.size;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const protectedValues = new WeakSet<object>();
|
|
54
|
+
|
|
55
|
+
/** Freezes new plain-data branches once. An externally shallow-frozen value is still traversed. */
|
|
56
|
+
export function protect<T>(value: T): Readonly<T> {
|
|
57
|
+
const visiting = new WeakSet<object>();
|
|
58
|
+
/** Protect each new plain-data branch and reject cycles or accessors. */
|
|
59
|
+
function visit(value: unknown): void {
|
|
60
|
+
if (value === null || typeof value !== "object") {
|
|
61
|
+
if (["function", "symbol"].includes(typeof value))
|
|
62
|
+
refuse(Errors.Invalid.StateValue, "State must contain plain data");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (protectedValues.has(value)) return;
|
|
66
|
+
if (visiting.has(value)) refuse(Errors.Invalid.StateCycle, "State cannot contain cycles");
|
|
67
|
+
const proto = Object.getPrototypeOf(value);
|
|
68
|
+
if (!Array.isArray(value) && proto !== Object.prototype && proto !== null)
|
|
69
|
+
refuse(Errors.Invalid.StateValue, "State requires plain objects and arrays");
|
|
70
|
+
visiting.add(value);
|
|
71
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
72
|
+
if (typeof key !== "string")
|
|
73
|
+
refuse(Errors.Invalid.StateValue, "State cannot contain symbol properties");
|
|
74
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key)!;
|
|
75
|
+
if (!Object.hasOwn(descriptor, "value"))
|
|
76
|
+
refuse(Errors.Invalid.StateValue, "State cannot contain accessors");
|
|
77
|
+
visit(descriptor.value);
|
|
78
|
+
}
|
|
79
|
+
visiting.delete(value);
|
|
80
|
+
Object.freeze(value);
|
|
81
|
+
protectedValues.add(value);
|
|
82
|
+
}
|
|
83
|
+
visit(value);
|
|
84
|
+
return value;
|
|
85
|
+
}
|