@oatscenter/trellis 0.100.0-rc.1
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 +59 -0
- package/auth/authorization/client_context.d.ts +61 -0
- package/auth/authorization/client_context.js +266 -0
- package/auth/authorization/nats_registry.d.ts +41 -0
- package/auth/authorization/nats_registry.js +283 -0
- package/auth/authorization/provider_cache.d.ts +90 -0
- package/auth/authorization/provider_cache.js +783 -0
- package/auth/authorization/refresh.d.ts +46 -0
- package/auth/authorization/refresh.js +246 -0
- package/auth/authorization/types.d.ts +207 -0
- package/auth/authorization/types.js +60 -0
- package/auth/authorization_context.d.ts +11 -0
- package/auth/authorization_context.js +10 -0
- package/auth/browser/flow_types.d.ts +84 -0
- package/auth/browser/flow_types.js +70 -0
- package/auth/browser/portal.d.ts +21 -0
- package/auth/browser/portal.js +307 -0
- package/auth/browser/storage.d.ts +26 -0
- package/auth/browser/storage.js +224 -0
- package/auth/browser.d.ts +11 -0
- package/auth/browser.js +10 -0
- package/auth/browser_recovery.d.ts +13 -0
- package/auth/browser_recovery.js +38 -0
- package/auth/device_activation.d.ts +134 -0
- package/auth/device_activation.js +376 -0
- package/auth/http_error.d.ts +12 -0
- package/auth/http_error.js +32 -0
- package/auth/keys.d.ts +5 -0
- package/auth/keys.js +63 -0
- package/auth/mod.d.ts +16 -0
- package/auth/mod.js +16 -0
- package/auth/proof.d.ts +31 -0
- package/auth/proof.js +95 -0
- package/auth/protocol_wasm/trellis_protocol_wasm.d.ts +138 -0
- package/auth/protocol_wasm/trellis_protocol_wasm.js +605 -0
- package/auth/protocol_wasm/trellis_protocol_wasm_bg.wasm +0 -0
- package/auth/protocol_wasm/trellis_protocol_wasm_bytes.d.ts +1 -0
- package/auth/protocol_wasm/trellis_protocol_wasm_bytes.js +2 -0
- package/auth/protocol_wasm.d.ts +179 -0
- package/auth/protocol_wasm.js +133 -0
- package/auth/session_auth.d.ts +30 -0
- package/auth/session_auth.js +77 -0
- package/auth/session_proof.d.ts +53 -0
- package/auth/session_proof.js +43 -0
- package/auth/time.d.ts +6 -0
- package/auth/time.js +7 -0
- package/auth/trellis_id.d.ts +1 -0
- package/auth/trellis_id.js +5 -0
- package/auth/utils.d.ts +10 -0
- package/auth/utils.js +69 -0
- package/auth.d.ts +1 -0
- package/auth.js +1 -0
- package/caller.d.ts +111 -0
- package/caller.js +85 -0
- package/client.d.ts +14 -0
- package/client.js +1 -0
- package/client_connect.d.ts +143 -0
- package/client_connect.js +1097 -0
- package/codec.d.ts +13 -0
- package/codec.js +192 -0
- package/connection.d.ts +107 -0
- package/connection.js +396 -0
- package/device/activation.d.ts +42 -0
- package/device/activation.js +319 -0
- package/device.d.ts +80 -0
- package/device.js +687 -0
- package/env.d.ts +2 -0
- package/env.js +10 -0
- package/errors/AuthError.d.ts +30 -0
- package/errors/AuthError.js +34 -0
- package/errors/KVError.d.ts +30 -0
- package/errors/KVError.js +36 -0
- package/errors/OperationLifecycleError.d.ts +110 -0
- package/errors/OperationLifecycleError.js +142 -0
- package/errors/RemoteError.d.ts +61 -0
- package/errors/RemoteError.js +72 -0
- package/errors/SchemaValidationError.d.ts +48 -0
- package/errors/SchemaValidationError.js +49 -0
- package/errors/StoreError.d.ts +21 -0
- package/errors/StoreError.js +31 -0
- package/errors/TransferError.d.ts +21 -0
- package/errors/TransferError.js +31 -0
- package/errors/TransportError.d.ts +29 -0
- package/errors/TransportError.js +33 -0
- package/errors/TrellisError.d.ts +15 -0
- package/errors/TrellisError.js +15 -0
- package/errors/ValidationError.d.ts +50 -0
- package/errors/ValidationError.js +59 -0
- package/errors/index.d.ts +254 -0
- package/errors/index.js +238 -0
- package/generated.d.ts +4 -0
- package/generated.js +3 -0
- package/generated_support.d.ts +120 -0
- package/generated_support.js +359 -0
- package/globals.d.ts +9 -0
- package/globals.js +16 -0
- package/health_transport.d.ts +18 -0
- package/health_transport.js +32 -0
- package/helpers.d.ts +11 -0
- package/helpers.js +53 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/internal_sdk/generated/apis/auth/mod.d.ts +805 -0
- package/internal_sdk/generated/apis/auth/mod.js +958 -0
- package/internal_sdk/generated/apis/core/mod.d.ts +79 -0
- package/internal_sdk/generated/apis/core/mod.js +93 -0
- package/internal_sdk/generated/apis/events/mod.d.ts +224 -0
- package/internal_sdk/generated/apis/events/mod.js +313 -0
- package/internal_sdk/generated/apis/health/mod.d.ts +106 -0
- package/internal_sdk/generated/apis/health/mod.js +132 -0
- package/internal_sdk/generated/apis/index.d.ts +7 -0
- package/internal_sdk/generated/apis/index.js +8 -0
- package/internal_sdk/generated/apis/jobs/mod.d.ts +176 -0
- package/internal_sdk/generated/apis/jobs/mod.js +209 -0
- package/internal_sdk/generated/apis/state/mod.d.ts +104 -0
- package/internal_sdk/generated/apis/state/mod.js +139 -0
- package/internal_sdk/generated/index.d.ts +4 -0
- package/internal_sdk/generated/index.js +5 -0
- package/internal_sdk/generated/package.json +18 -0
- package/internal_sdk/generated/participants/cli/mod.d.ts +402 -0
- package/internal_sdk/generated/participants/cli/mod.js +460 -0
- package/internal_sdk/generated/participants/cli/types.d.ts +2 -0
- package/internal_sdk/generated/participants/cli/types.js +3 -0
- package/internal_sdk/generated/participants/console/mod.d.ts +489 -0
- package/internal_sdk/generated/participants/console/mod.js +579 -0
- package/internal_sdk/generated/participants/console/types.d.ts +2 -0
- package/internal_sdk/generated/participants/console/types.js +3 -0
- package/internal_sdk/generated/participants/eventsRuntime/mod.d.ts +64 -0
- package/internal_sdk/generated/participants/eventsRuntime/mod.js +42 -0
- package/internal_sdk/generated/participants/eventsRuntime/types.d.ts +2 -0
- package/internal_sdk/generated/participants/eventsRuntime/types.js +3 -0
- package/internal_sdk/generated/participants/healthRuntime/mod.d.ts +58 -0
- package/internal_sdk/generated/participants/healthRuntime/mod.js +36 -0
- package/internal_sdk/generated/participants/healthRuntime/types.d.ts +2 -0
- package/internal_sdk/generated/participants/healthRuntime/types.js +3 -0
- package/internal_sdk/generated/participants/index.d.ts +8 -0
- package/internal_sdk/generated/participants/index.js +9 -0
- package/internal_sdk/generated/participants/jobsRuntime/mod.d.ts +64 -0
- package/internal_sdk/generated/participants/jobsRuntime/mod.js +42 -0
- package/internal_sdk/generated/participants/jobsRuntime/types.d.ts +2 -0
- package/internal_sdk/generated/participants/jobsRuntime/types.js +3 -0
- package/internal_sdk/generated/participants/platform/mod.d.ts +164 -0
- package/internal_sdk/generated/participants/platform/mod.js +149 -0
- package/internal_sdk/generated/participants/platform/types.d.ts +7 -0
- package/internal_sdk/generated/participants/platform/types.js +5 -0
- package/internal_sdk/generated/participants/portal/mod.d.ts +131 -0
- package/internal_sdk/generated/participants/portal/mod.js +109 -0
- package/internal_sdk/generated/participants/portal/types.d.ts +2 -0
- package/internal_sdk/generated/participants/portal/types.js +3 -0
- package/internal_sdk/generated/types/_internal/p0.d.ts +13511 -0
- package/internal_sdk/generated/types/_internal/p0.js +6105 -0
- package/internal_sdk/generated/types/index.d.ts +2951 -0
- package/internal_sdk/generated/types/index.js +1477 -0
- package/jobs.d.ts +309 -0
- package/jobs.js +389 -0
- package/kv.d.ts +85 -0
- package/kv.js +330 -0
- package/operations.d.ts +189 -0
- package/operations.js +847 -0
- package/package.json +73 -0
- package/pagination.d.ts +25 -0
- package/pagination.js +117 -0
- package/participant.d.ts +6 -0
- package/participant.js +6 -0
- package/participant_runtime/api.d.ts +131 -0
- package/participant_runtime/api.js +42 -0
- package/participant_runtime/json.d.ts +16 -0
- package/participant_runtime/json.js +193 -0
- package/participant_runtime/metadata.d.ts +34 -0
- package/participant_runtime/metadata.js +4 -0
- package/participant_runtime/participant.d.ts +200 -0
- package/participant_runtime/participant.js +330 -0
- package/participant_runtime/schemas.d.ts +347 -0
- package/participant_runtime/schemas.js +211 -0
- package/participant_runtime/surface_names.d.ts +16 -0
- package/participant_runtime/surface_names.js +34 -0
- package/portable.d.ts +30 -0
- package/portable.js +14 -0
- package/provider.d.ts +69 -0
- package/provider.js +68 -0
- package/runtime_transport.d.ts +25 -0
- package/runtime_transport.js +48 -0
- package/service/mod.d.ts +14 -0
- package/service/mod.js +13 -0
- package/service/outbox_inbox.d.ts +259 -0
- package/service/outbox_inbox.js +908 -0
- package/service/runtime/bootstrap.d.ts +56 -0
- package/service/runtime/bootstrap.js +226 -0
- package/service/runtime/core.d.ts +46 -0
- package/service/runtime/core.js +1747 -0
- package/service/runtime/health.d.ts +97 -0
- package/service/runtime/health.js +153 -0
- package/service/runtime/health_schemas.d.ts +23 -0
- package/service/runtime/health_schemas.js +20 -0
- package/service/runtime/internal_jobs/active-job.d.ts +40 -0
- package/service/runtime/internal_jobs/active-job.js +91 -0
- package/service/runtime/internal_jobs/bindings.d.ts +40 -0
- package/service/runtime/internal_jobs/bindings.js +1 -0
- package/service/runtime/internal_jobs/cancellation-registry.d.ts +13 -0
- package/service/runtime/internal_jobs/cancellation-registry.js +55 -0
- package/service/runtime/internal_jobs/heartbeat.d.ts +33 -0
- package/service/runtime/internal_jobs/heartbeat.js +65 -0
- package/service/runtime/internal_jobs/job-manager.d.ts +126 -0
- package/service/runtime/internal_jobs/job-manager.js +821 -0
- package/service/runtime/internal_jobs/key-coordinator.d.ts +280 -0
- package/service/runtime/internal_jobs/key-coordinator.js +747 -0
- package/service/runtime/internal_jobs/projection.d.ts +3 -0
- package/service/runtime/internal_jobs/projection.js +42 -0
- package/service/runtime/internal_jobs/runtime-worker.d.ts +126 -0
- package/service/runtime/internal_jobs/runtime-worker.js +454 -0
- package/service/runtime/internal_jobs/types.d.ts +246 -0
- package/service/runtime/internal_jobs/types.js +163 -0
- package/service/runtime/logger.d.ts +2 -0
- package/service/runtime/logger.js +7 -0
- package/service/runtime/runtime.d.ts +16 -0
- package/service/runtime/runtime.js +1 -0
- package/service/runtime/service.d.ts +372 -0
- package/service/runtime/service.js +1896 -0
- package/service/runtime/transfer/download.d.ts +27 -0
- package/service/runtime/transfer/download.js +1 -0
- package/service/runtime/transfer/protocol.d.ts +15 -0
- package/service/runtime/transfer/protocol.js +46 -0
- package/service/runtime/transfer/queue.d.ts +18 -0
- package/service/runtime/transfer/queue.js +136 -0
- package/service/runtime/transfer/upload.d.ts +40 -0
- package/service/runtime/transfer/upload.js +27 -0
- package/service/runtime/transfer.d.ts +62 -0
- package/service/runtime/transfer.js +763 -0
- package/session.d.ts +862 -0
- package/session.js +3407 -0
- package/store.d.ts +71 -0
- package/store.js +412 -0
- package/store_entry.d.ts +20 -0
- package/store_entry.js +75 -0
- package/tasks.d.ts +10 -0
- package/tasks.js +28 -0
- package/telemetry/carrier.d.ts +8 -0
- package/telemetry/carrier.js +20 -0
- package/telemetry/core.d.ts +7 -0
- package/telemetry/core.js +14 -0
- package/telemetry/env.d.ts +2 -0
- package/telemetry/env.js +10 -0
- package/telemetry/init.d.ts +2 -0
- package/telemetry/init.js +7 -0
- package/telemetry/metrics.d.ts +81 -0
- package/telemetry/metrics.js +267 -0
- package/telemetry/mod.d.ts +13 -0
- package/telemetry/mod.js +8 -0
- package/telemetry/nats.d.ts +6 -0
- package/telemetry/nats.js +6 -0
- package/telemetry/result.d.ts +1 -0
- package/telemetry/result.js +18 -0
- package/telemetry/runtime.d.ts +1 -0
- package/telemetry/runtime.js +141 -0
- package/telemetry/trace.d.ts +4 -0
- package/telemetry/trace.js +26 -0
- package/telemetry/trellis.d.ts +1 -0
- package/telemetry/trellis.js +1 -0
- package/telemetry.d.ts +1 -0
- package/telemetry.js +1 -0
- package/transfer.d.ts +112 -0
- package/transfer.js +525 -0
- package/transfer_protocol.d.ts +1 -0
- package/transfer_protocol.js +13 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import type { BaseError } from "@oatscenter/result";
|
|
2
|
+
import type { Codec } from "../generated.ts";
|
|
3
|
+
import type { EventDesc, FeedDesc, OperationDesc, RPCDesc, RuntimeApi, SchemaLike } from "./api.ts";
|
|
4
|
+
import type { TrellisAvailability } from "../connection.ts";
|
|
5
|
+
type GeneratedCodec = Readonly<{
|
|
6
|
+
decode(value: unknown): unknown;
|
|
7
|
+
encode(value: never): unknown;
|
|
8
|
+
}>;
|
|
9
|
+
export type GeneratedActionDescriptor = Readonly<{
|
|
10
|
+
kind: "rpc" | "operation" | "event" | "feed";
|
|
11
|
+
descriptorName: `${"rpc" | "operation" | "event" | "feed"}:${string}`;
|
|
12
|
+
input?: GeneratedCodec;
|
|
13
|
+
output?: GeneratedCodec;
|
|
14
|
+
payload?: GeneratedCodec;
|
|
15
|
+
event?: GeneratedCodec;
|
|
16
|
+
progress?: GeneratedCodec;
|
|
17
|
+
errors?: readonly RuntimeRpcErrorClass[];
|
|
18
|
+
signals?: Readonly<Record<string, GeneratedCodec>>;
|
|
19
|
+
parameters?: readonly (readonly string[])[];
|
|
20
|
+
upload?: boolean;
|
|
21
|
+
download?: boolean;
|
|
22
|
+
pagination?: "cursor";
|
|
23
|
+
}>;
|
|
24
|
+
export type GeneratedApiDescriptor = Readonly<{
|
|
25
|
+
identity: string;
|
|
26
|
+
actions: Readonly<Record<string, GeneratedActionDescriptor>>;
|
|
27
|
+
}>;
|
|
28
|
+
export type GeneratedActionSelection = Readonly<{
|
|
29
|
+
api: GeneratedApiDescriptor;
|
|
30
|
+
actions: readonly Readonly<{
|
|
31
|
+
descriptorName: string;
|
|
32
|
+
direction: "call" | "invoke" | "publish" | "subscribe";
|
|
33
|
+
}>[];
|
|
34
|
+
optionalCapabilities: readonly string[];
|
|
35
|
+
}>;
|
|
36
|
+
export type GeneratedResourceDescriptor = Readonly<Record<string, unknown>> & Readonly<{
|
|
37
|
+
availability: "required" | "optional";
|
|
38
|
+
}> & (Readonly<{
|
|
39
|
+
kind: "state" | "kv";
|
|
40
|
+
codec: GeneratedCodec;
|
|
41
|
+
version: number;
|
|
42
|
+
migrations: Readonly<Record<number, GeneratedCodec>>;
|
|
43
|
+
}> | Readonly<{
|
|
44
|
+
kind: "store" | "job" | "consumer";
|
|
45
|
+
}>);
|
|
46
|
+
/** Generated participant descriptor accepted by Trellis runtimes. */
|
|
47
|
+
export type GeneratedParticipant = Readonly<{
|
|
48
|
+
kind: "service" | "device" | "app" | "agent";
|
|
49
|
+
id: string;
|
|
50
|
+
identity: string;
|
|
51
|
+
path: string;
|
|
52
|
+
implements: readonly GeneratedApiDescriptor[];
|
|
53
|
+
uses: readonly GeneratedActionSelection[];
|
|
54
|
+
actionNames: Readonly<Record<string, string>>;
|
|
55
|
+
resources: Readonly<Record<string, GeneratedResourceDescriptor>>;
|
|
56
|
+
companion?: Readonly<{
|
|
57
|
+
participant: GeneratedParticipant;
|
|
58
|
+
availability: "required" | "optional";
|
|
59
|
+
}>;
|
|
60
|
+
packageEvidence: unknown;
|
|
61
|
+
}>;
|
|
62
|
+
type GeneratedSchema<T> = T extends {
|
|
63
|
+
decode(value: unknown): infer V;
|
|
64
|
+
} ? Codec<V> : Extract<T, SchemaLike>;
|
|
65
|
+
type GeneratedDescriptorRuntime<T> = T extends {
|
|
66
|
+
kind: "rpc";
|
|
67
|
+
input: infer I;
|
|
68
|
+
output: infer O;
|
|
69
|
+
} ? RPCDesc<GeneratedSchema<I>, GeneratedSchema<O>> : T extends {
|
|
70
|
+
kind: "operation";
|
|
71
|
+
input: infer I;
|
|
72
|
+
output?: infer O;
|
|
73
|
+
progress?: infer P;
|
|
74
|
+
} ? OperationDesc<GeneratedSchema<I>, GeneratedSchema<P>, GeneratedSchema<O>> & (T extends {
|
|
75
|
+
upload: true;
|
|
76
|
+
} ? {
|
|
77
|
+
transfer: {
|
|
78
|
+
direction: "send";
|
|
79
|
+
};
|
|
80
|
+
} : {}) : T extends {
|
|
81
|
+
kind: "event";
|
|
82
|
+
payload: infer E;
|
|
83
|
+
} ? EventDesc<GeneratedSchema<E>> : T extends {
|
|
84
|
+
kind: "feed";
|
|
85
|
+
input: infer I;
|
|
86
|
+
event: infer E;
|
|
87
|
+
} ? FeedDesc<GeneratedSchema<I>, GeneratedSchema<E>> : never;
|
|
88
|
+
type GeneratedRuntimeEntries<TApi, TNames extends Readonly<Record<string, string>>, TKind extends GeneratedActionDescriptor["kind"]> = TApi extends {
|
|
89
|
+
identity: string;
|
|
90
|
+
actions: Readonly<Record<string, unknown>>;
|
|
91
|
+
} ? {
|
|
92
|
+
[K in keyof TApi["actions"]]: TApi["actions"][K] extends infer TAction ? TAction extends {
|
|
93
|
+
kind: TKind;
|
|
94
|
+
descriptorName: infer TDescriptorName extends string;
|
|
95
|
+
} ? {
|
|
96
|
+
[N in TNames[`${TApi["identity"]}:${TDescriptorName}`] & string]: GeneratedDescriptorRuntime<TAction>;
|
|
97
|
+
} : never : never;
|
|
98
|
+
}[keyof TApi["actions"]] : never;
|
|
99
|
+
type UnionToIntersection<T> = (T extends unknown ? (value: T) => void : never) extends (value: infer I) => void ? I : never;
|
|
100
|
+
type GeneratedRuntimeFamily<TApi, TNames extends Readonly<Record<string, string>>, TKind extends GeneratedActionDescriptor["kind"]> = [GeneratedRuntimeEntries<TApi, TNames, TKind>] extends [never] ? {} : UnionToIntersection<GeneratedRuntimeEntries<TApi, TNames, TKind>>;
|
|
101
|
+
/** Exact runtime API type projected from canonical generated action descriptors. */
|
|
102
|
+
export type RuntimeApiFromGenerated<TApi, TNames extends Readonly<Record<string, string>>> = {
|
|
103
|
+
rpc: GeneratedRuntimeFamily<TApi, TNames, "rpc">;
|
|
104
|
+
operations: GeneratedRuntimeFamily<TApi, TNames, "operation">;
|
|
105
|
+
events: GeneratedRuntimeFamily<TApi, TNames, "event">;
|
|
106
|
+
feeds: GeneratedRuntimeFamily<TApi, TNames, "feed">;
|
|
107
|
+
subjects: Record<string, unknown>;
|
|
108
|
+
};
|
|
109
|
+
/** Exact job metadata projected from generated participant resources. */
|
|
110
|
+
export type ParticipantJobsFromResources<TResources extends GeneratedParticipant["resources"]> = {
|
|
111
|
+
[K in keyof TResources as TResources[K] extends {
|
|
112
|
+
kind: "job";
|
|
113
|
+
} ? K : never]: TResources[K] extends {
|
|
114
|
+
payload: Codec<infer P>;
|
|
115
|
+
result?: Codec<infer R>;
|
|
116
|
+
} ? {
|
|
117
|
+
payload: P;
|
|
118
|
+
result: R;
|
|
119
|
+
} : never;
|
|
120
|
+
};
|
|
121
|
+
/** Exact KV metadata projected from generated participant resources. */
|
|
122
|
+
export type ParticipantKvFromResources<TResources extends GeneratedParticipant["resources"]> = {
|
|
123
|
+
[K in keyof TResources as TResources[K] extends {
|
|
124
|
+
kind: "kv";
|
|
125
|
+
} ? K : never]: TResources[K] extends {
|
|
126
|
+
availability: infer A;
|
|
127
|
+
codec: {
|
|
128
|
+
decode(value: unknown): unknown;
|
|
129
|
+
};
|
|
130
|
+
version: infer Version;
|
|
131
|
+
migrations: infer Migrations;
|
|
132
|
+
} ? {
|
|
133
|
+
required: A extends "required" ? true : false;
|
|
134
|
+
value: ReturnType<TResources[K]["codec"]["decode"]>;
|
|
135
|
+
schema: {
|
|
136
|
+
codec: TResources[K]["codec"];
|
|
137
|
+
version: Version;
|
|
138
|
+
migrations: Migrations;
|
|
139
|
+
};
|
|
140
|
+
} : never;
|
|
141
|
+
};
|
|
142
|
+
type RuntimeRpcErrorClass = Readonly<{
|
|
143
|
+
type: string;
|
|
144
|
+
fromSerializable(data: unknown): BaseError;
|
|
145
|
+
}>;
|
|
146
|
+
export type RuntimeSelectedAction = Readonly<{
|
|
147
|
+
api: GeneratedApiDescriptor;
|
|
148
|
+
descriptor: GeneratedActionDescriptor;
|
|
149
|
+
direction: "call" | "invoke" | "publish" | "subscribe";
|
|
150
|
+
name: string;
|
|
151
|
+
connectedName: string;
|
|
152
|
+
optional: boolean;
|
|
153
|
+
optionalCapabilities: readonly string[];
|
|
154
|
+
}>;
|
|
155
|
+
type RuntimeStateDescriptor = Readonly<{
|
|
156
|
+
kind: "value";
|
|
157
|
+
value: unknown;
|
|
158
|
+
codec: Codec<unknown>;
|
|
159
|
+
version: number;
|
|
160
|
+
migrations: Readonly<Record<number, Codec<unknown>>>;
|
|
161
|
+
}>;
|
|
162
|
+
export type ParticipantRuntime = Readonly<{
|
|
163
|
+
ownedApi: RuntimeApi;
|
|
164
|
+
usedApi: RuntimeApi;
|
|
165
|
+
api: RuntimeApi;
|
|
166
|
+
actions: readonly RuntimeSelectedAction[];
|
|
167
|
+
state: Readonly<Record<string, RuntimeStateDescriptor>>;
|
|
168
|
+
kv: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
169
|
+
jobs: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
170
|
+
eventConsumers: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
171
|
+
}>;
|
|
172
|
+
/** Applies bootstrap-selected provider deployments to request route subjects. */
|
|
173
|
+
export declare function bindApiRoutes(api: RuntimeApi, apiBindings: Readonly<Record<string, unknown>>): RuntimeApi;
|
|
174
|
+
/** Replaces request subjects after an authorization binding refresh. */
|
|
175
|
+
export declare function refreshApiRoutes(api: RuntimeApi, apiBindings: Readonly<Record<string, unknown>>): void;
|
|
176
|
+
/** Projects generated descriptors into the participant runtime. */
|
|
177
|
+
export declare function getParticipantRuntime(participant: GeneratedParticipant): ParticipantRuntime;
|
|
178
|
+
/** Projects installed API and resource bindings into one immutable participant snapshot. */
|
|
179
|
+
export declare function participantAvailability(participant: GeneratedParticipant, apiBindings: Readonly<Record<string, unknown>>, resourceBindings: Readonly<{
|
|
180
|
+
kv?: Readonly<Record<string, unknown>>;
|
|
181
|
+
store?: Readonly<Record<string, unknown>>;
|
|
182
|
+
jobs?: Readonly<{
|
|
183
|
+
queues: Readonly<Record<string, unknown>>;
|
|
184
|
+
}>;
|
|
185
|
+
eventConsumers?: Readonly<Record<string, unknown>>;
|
|
186
|
+
}>, permissions?: readonly Readonly<{
|
|
187
|
+
target: Readonly<{
|
|
188
|
+
kind: string;
|
|
189
|
+
participant?: string;
|
|
190
|
+
resource?: string;
|
|
191
|
+
name?: string;
|
|
192
|
+
}>;
|
|
193
|
+
}>[]): TrellisAvailability;
|
|
194
|
+
/** Returns the proof-bound package evidence envelope without interpreting source. */
|
|
195
|
+
export declare function participantEvidence(participant: GeneratedParticipant): {
|
|
196
|
+
packageEvidence: unknown;
|
|
197
|
+
participantPath: string;
|
|
198
|
+
packageDigest: string;
|
|
199
|
+
};
|
|
200
|
+
export {};
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { boundApiSubject, eventDescriptorIdentity, eventSubject, } from "./api.js";
|
|
2
|
+
import { lowerCamelSurfaceName, pascalSurfaceName } from "./surface_names.js";
|
|
3
|
+
function actionName(descriptorName) {
|
|
4
|
+
return descriptorName.slice(descriptorName.indexOf(":") + 1);
|
|
5
|
+
}
|
|
6
|
+
function permission(apiId, descriptor, action) {
|
|
7
|
+
const match = /^(.+)@v([1-9][0-9]*)$/.exec(apiId);
|
|
8
|
+
if (!match)
|
|
9
|
+
throw new Error(`Invalid generated API identity '${apiId}'`);
|
|
10
|
+
return {
|
|
11
|
+
apiId: match[1],
|
|
12
|
+
apiVersion: `v${match[2]}`,
|
|
13
|
+
surfaceKind: descriptor.kind,
|
|
14
|
+
surfaceName: actionName(descriptor.descriptorName),
|
|
15
|
+
action,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function runtimeErrors(errors) {
|
|
19
|
+
return errors?.map((error) => ({
|
|
20
|
+
type: error.type,
|
|
21
|
+
fromSerializable: error.fromSerializable,
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
function subject(api, descriptor) {
|
|
25
|
+
const name = actionName(descriptor.descriptorName);
|
|
26
|
+
const prefix = descriptor.kind === "event"
|
|
27
|
+
? "events"
|
|
28
|
+
: descriptor.kind === "operation"
|
|
29
|
+
? "operations"
|
|
30
|
+
: descriptor.kind;
|
|
31
|
+
const parameters = descriptor.parameters?.map((path) => `.{/${path.join("/")}}`).join("") ??
|
|
32
|
+
"";
|
|
33
|
+
if (descriptor.kind === "event") {
|
|
34
|
+
return `${eventSubject(api.identity, name)}${parameters}`;
|
|
35
|
+
}
|
|
36
|
+
const apiName = api.identity.split(".").at(-1)?.split("@v")[0];
|
|
37
|
+
if (!apiName) {
|
|
38
|
+
throw new Error(`Invalid generated API identity '${api.identity}'`);
|
|
39
|
+
}
|
|
40
|
+
return `${prefix}.v1.${apiName}.${name}`;
|
|
41
|
+
}
|
|
42
|
+
function runtimeDescriptor(api, descriptor) {
|
|
43
|
+
const transportSubject = subject(api, descriptor);
|
|
44
|
+
const errors = descriptor.errors?.map((error) => error.type);
|
|
45
|
+
const declaredErrors = runtimeErrors(descriptor.errors);
|
|
46
|
+
switch (descriptor.kind) {
|
|
47
|
+
case "rpc":
|
|
48
|
+
return {
|
|
49
|
+
subject: transportSubject,
|
|
50
|
+
input: descriptor.input,
|
|
51
|
+
output: descriptor.output,
|
|
52
|
+
permission: permission(api.identity, descriptor, "call"),
|
|
53
|
+
callerCapabilities: [],
|
|
54
|
+
...(descriptor.download ? { transfer: { direction: "receive" } } : {}),
|
|
55
|
+
...(errors ? { errors, declaredErrorTypes: errors } : {}),
|
|
56
|
+
...(declaredErrors ? { runtimeErrors: declaredErrors } : {}),
|
|
57
|
+
};
|
|
58
|
+
case "operation":
|
|
59
|
+
return {
|
|
60
|
+
subject: transportSubject,
|
|
61
|
+
input: descriptor.input,
|
|
62
|
+
output: descriptor.output,
|
|
63
|
+
progress: descriptor.progress,
|
|
64
|
+
update: descriptor.progress,
|
|
65
|
+
permissions: {
|
|
66
|
+
invoke: permission(api.identity, descriptor, "invoke"),
|
|
67
|
+
observe: permission(api.identity, descriptor, "observe"),
|
|
68
|
+
cancel: permission(api.identity, descriptor, "cancel"),
|
|
69
|
+
control: Object.fromEntries(Object.keys(descriptor.signals ?? {}).map((name) => {
|
|
70
|
+
const control = permission(api.identity, descriptor, "control");
|
|
71
|
+
return [
|
|
72
|
+
name,
|
|
73
|
+
{
|
|
74
|
+
...control,
|
|
75
|
+
surfaceName: `${control.surfaceName}.${name}`,
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
})),
|
|
79
|
+
},
|
|
80
|
+
signals: Object.fromEntries(Object.entries(descriptor.signals ?? {}).map(([name, input]) => [
|
|
81
|
+
name,
|
|
82
|
+
{ input },
|
|
83
|
+
])),
|
|
84
|
+
callerCapabilities: [],
|
|
85
|
+
observeCapabilities: [],
|
|
86
|
+
cancelCapabilities: [],
|
|
87
|
+
controlCapabilities: [],
|
|
88
|
+
...(descriptor.upload ? { transfer: { direction: "send" } } : {}),
|
|
89
|
+
...(errors ? { errors, declaredErrorTypes: errors } : {}),
|
|
90
|
+
...(declaredErrors ? { runtimeErrors: declaredErrors } : {}),
|
|
91
|
+
};
|
|
92
|
+
case "event": {
|
|
93
|
+
const eventName = actionName(descriptor.descriptorName);
|
|
94
|
+
return {
|
|
95
|
+
subject: transportSubject,
|
|
96
|
+
descriptorIdentity: eventDescriptorIdentity(api.identity, eventName, descriptor.parameters?.length ?? 0),
|
|
97
|
+
params: descriptor.parameters?.map((path) => `/${path.join("/")}`),
|
|
98
|
+
event: descriptor.payload,
|
|
99
|
+
publishPermission: permission(api.identity, descriptor, "publish"),
|
|
100
|
+
subscribePermission: permission(api.identity, descriptor, "subscribe"),
|
|
101
|
+
publishCapabilities: [],
|
|
102
|
+
subscribeCapabilities: [],
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
case "feed":
|
|
106
|
+
return {
|
|
107
|
+
subject: transportSubject,
|
|
108
|
+
input: descriptor.input,
|
|
109
|
+
event: descriptor.event,
|
|
110
|
+
permission: permission(api.identity, descriptor, "subscribe"),
|
|
111
|
+
subscribeCapabilities: [],
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** Applies bootstrap-selected provider deployments to request route subjects. */
|
|
116
|
+
export function bindApiRoutes(api, apiBindings) {
|
|
117
|
+
const bind = (descriptor, family) => {
|
|
118
|
+
const permission = "permissions" in descriptor
|
|
119
|
+
? descriptor.permissions.invoke
|
|
120
|
+
: descriptor.permission;
|
|
121
|
+
const apiId = `${permission.apiId}@${permission.apiVersion}`;
|
|
122
|
+
const binding = apiBindings[apiId];
|
|
123
|
+
if (!binding || typeof binding !== "object" ||
|
|
124
|
+
typeof Reflect.get(binding, "providerDeploymentId") !== "string") {
|
|
125
|
+
throw new Error(`Bootstrap did not bind API '${apiId}' to a provider deployment`);
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
...descriptor,
|
|
129
|
+
subject: boundApiSubject(family, apiId, Reflect.get(binding, "providerDeploymentId"), permission.surfaceName),
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
return {
|
|
133
|
+
...api,
|
|
134
|
+
rpc: Object.fromEntries(Object.entries(api.rpc).map(([name, descriptor]) => [
|
|
135
|
+
name,
|
|
136
|
+
bind(descriptor, "rpc"),
|
|
137
|
+
])),
|
|
138
|
+
operations: Object.fromEntries(Object.entries(api.operations).map(([name, descriptor]) => [
|
|
139
|
+
name,
|
|
140
|
+
bind(descriptor, "operation"),
|
|
141
|
+
])),
|
|
142
|
+
feeds: Object.fromEntries(Object.entries(api.feeds ?? {}).map(([name, descriptor]) => [
|
|
143
|
+
name,
|
|
144
|
+
bind(descriptor, "feed"),
|
|
145
|
+
])),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/** Replaces request subjects after an authorization binding refresh. */
|
|
149
|
+
export function refreshApiRoutes(api, apiBindings) {
|
|
150
|
+
const next = bindApiRoutes(api, apiBindings);
|
|
151
|
+
for (const family of ["rpc", "operations", "feeds"]) {
|
|
152
|
+
for (const [name, descriptor] of Object.entries(next[family] ?? {})) {
|
|
153
|
+
const current = api[family]?.[name];
|
|
154
|
+
if (current)
|
|
155
|
+
current.subject = descriptor.subject;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function addAction(target, api, descriptor, name) {
|
|
160
|
+
const runtime = runtimeDescriptor(api, descriptor);
|
|
161
|
+
if (descriptor.kind === "rpc")
|
|
162
|
+
target.rpc[name] = runtime;
|
|
163
|
+
else if (descriptor.kind === "operation") {
|
|
164
|
+
target.operations[name] = runtime;
|
|
165
|
+
}
|
|
166
|
+
else if (descriptor.kind === "event") {
|
|
167
|
+
target.events[name] = runtime;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
const feeds = target.feeds ?? {};
|
|
171
|
+
feeds[name] = runtime;
|
|
172
|
+
target.feeds = feeds;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function generatedActionName(participant, api, descriptor) {
|
|
176
|
+
const name = participant.actionNames[`${api.identity}:${descriptor.descriptorName}`];
|
|
177
|
+
if (!name)
|
|
178
|
+
throw new Error("Generated participant action name is missing");
|
|
179
|
+
return name;
|
|
180
|
+
}
|
|
181
|
+
function emptyApi() {
|
|
182
|
+
return { rpc: {}, operations: {}, events: {}, feeds: {}, subjects: {} };
|
|
183
|
+
}
|
|
184
|
+
/** Projects generated descriptors into the participant runtime. */
|
|
185
|
+
export function getParticipantRuntime(participant) {
|
|
186
|
+
const ownedApi = emptyApi();
|
|
187
|
+
const usedApi = emptyApi();
|
|
188
|
+
const actions = [];
|
|
189
|
+
const state = {};
|
|
190
|
+
const kv = {};
|
|
191
|
+
const jobs = {};
|
|
192
|
+
const eventConsumers = {};
|
|
193
|
+
for (const api of participant.implements) {
|
|
194
|
+
for (const descriptor of Object.values(api.actions)) {
|
|
195
|
+
addAction(ownedApi, api, descriptor, generatedActionName(participant, api, descriptor));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
for (const selection of participant.uses) {
|
|
199
|
+
for (const selected of selection.actions) {
|
|
200
|
+
const descriptor = selection.api.actions[selected.descriptorName];
|
|
201
|
+
if (!descriptor) {
|
|
202
|
+
throw new Error(`Generated action '${selected.descriptorName}' is absent from '${selection.api.identity}'`);
|
|
203
|
+
}
|
|
204
|
+
const name = generatedActionName(participant, selection.api, descriptor);
|
|
205
|
+
addAction(usedApi, selection.api, descriptor, name);
|
|
206
|
+
actions.push({
|
|
207
|
+
api: selection.api,
|
|
208
|
+
descriptor,
|
|
209
|
+
direction: selected.direction,
|
|
210
|
+
name,
|
|
211
|
+
connectedName: descriptor.kind === "event"
|
|
212
|
+
? `${selected.direction === "publish" ? "publish" : "on"}${pascalSurfaceName(name)}`
|
|
213
|
+
: lowerCamelSurfaceName(name),
|
|
214
|
+
optional: selection.optionalCapabilities.length > 0,
|
|
215
|
+
optionalCapabilities: selection.optionalCapabilities,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
for (const [name, resource] of Object.entries(participant.resources)) {
|
|
220
|
+
if (resource.kind === "state") {
|
|
221
|
+
state[name] = {
|
|
222
|
+
kind: "value",
|
|
223
|
+
value: undefined,
|
|
224
|
+
codec: resource.codec,
|
|
225
|
+
version: resource.version,
|
|
226
|
+
migrations: resource.migrations,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
else if (resource.kind === "kv") {
|
|
230
|
+
kv[name] = {
|
|
231
|
+
required: resource.availability === "required",
|
|
232
|
+
schema: resource,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
else if (resource.kind === "job") {
|
|
236
|
+
jobs[name] = {
|
|
237
|
+
payload: resource.payload,
|
|
238
|
+
update: resource.update,
|
|
239
|
+
updateSchema: resource.update,
|
|
240
|
+
result: resource.result,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
else if (resource.kind === "consumer") {
|
|
244
|
+
const uses = {};
|
|
245
|
+
for (const [api, event] of resource.events) {
|
|
246
|
+
const events = uses[api] ?? [];
|
|
247
|
+
events.push(event);
|
|
248
|
+
uses[api] = events;
|
|
249
|
+
}
|
|
250
|
+
eventConsumers[name] = {
|
|
251
|
+
uses,
|
|
252
|
+
replay: resource.replay,
|
|
253
|
+
concurrency: resource.concurrency,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
ownedApi,
|
|
259
|
+
usedApi,
|
|
260
|
+
api: {
|
|
261
|
+
rpc: { ...ownedApi.rpc, ...usedApi.rpc },
|
|
262
|
+
operations: { ...ownedApi.operations, ...usedApi.operations },
|
|
263
|
+
events: { ...ownedApi.events, ...usedApi.events },
|
|
264
|
+
feeds: { ...ownedApi.feeds, ...usedApi.feeds },
|
|
265
|
+
subjects: {},
|
|
266
|
+
},
|
|
267
|
+
actions,
|
|
268
|
+
state,
|
|
269
|
+
kv,
|
|
270
|
+
jobs,
|
|
271
|
+
eventConsumers,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
/** Projects installed API and resource bindings into one immutable participant snapshot. */
|
|
275
|
+
export function participantAvailability(participant, apiBindings, resourceBindings, permissions) {
|
|
276
|
+
const capabilities = {};
|
|
277
|
+
for (const selection of participant.uses) {
|
|
278
|
+
const available = selection.api.identity in apiBindings;
|
|
279
|
+
for (const capability of selection.optionalCapabilities) {
|
|
280
|
+
capabilities[capability] = available;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
const resources = {};
|
|
284
|
+
const granted = (name, kind) => permissions?.some((permission) => permission.target.kind === "participantResource" &&
|
|
285
|
+
permission.target.participant === participant.identity &&
|
|
286
|
+
permission.target.resource === kind &&
|
|
287
|
+
permission.target.name === name) ?? true;
|
|
288
|
+
for (const [name, descriptor] of Object.entries(participant.resources)) {
|
|
289
|
+
if (descriptor.availability !== "optional")
|
|
290
|
+
continue;
|
|
291
|
+
switch (descriptor.kind) {
|
|
292
|
+
case "state":
|
|
293
|
+
resources[name] = granted(name, "state");
|
|
294
|
+
break;
|
|
295
|
+
case "kv":
|
|
296
|
+
resources[name] = resourceBindings.kv?.[name] !== undefined &&
|
|
297
|
+
granted(name, "kv");
|
|
298
|
+
break;
|
|
299
|
+
case "store":
|
|
300
|
+
resources[name] = resourceBindings.store?.[name] !== undefined &&
|
|
301
|
+
granted(name, "store");
|
|
302
|
+
break;
|
|
303
|
+
case "job":
|
|
304
|
+
resources[name] = resourceBindings.jobs?.queues[name] !== undefined;
|
|
305
|
+
break;
|
|
306
|
+
case "consumer":
|
|
307
|
+
resources[name] = resourceBindings.eventConsumers?.[name] !== undefined;
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return Object.freeze({
|
|
312
|
+
capabilities: Object.freeze(capabilities),
|
|
313
|
+
resources: Object.freeze(resources),
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
/** Returns the proof-bound package evidence envelope without interpreting source. */
|
|
317
|
+
export function participantEvidence(participant) {
|
|
318
|
+
const evidence = participant.packageEvidence;
|
|
319
|
+
const packageDigest = evidence && typeof evidence === "object"
|
|
320
|
+
? Reflect.get(evidence, "rootDigest")
|
|
321
|
+
: undefined;
|
|
322
|
+
if (typeof packageDigest !== "string" || packageDigest.length === 0) {
|
|
323
|
+
throw new Error("Generated participant has invalid package evidence");
|
|
324
|
+
}
|
|
325
|
+
return {
|
|
326
|
+
packageEvidence: evidence,
|
|
327
|
+
participantPath: participant.path,
|
|
328
|
+
packageDigest,
|
|
329
|
+
};
|
|
330
|
+
}
|