@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
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oatscenter/trellis",
|
|
3
|
+
"description": "Client-side Trellis runtime, models, and participant helpers for TypeScript applications.",
|
|
4
|
+
"exports": {
|
|
5
|
+
".": {
|
|
6
|
+
"types": "./index.d.ts",
|
|
7
|
+
"import": "./index.js"
|
|
8
|
+
},
|
|
9
|
+
"./generated": {
|
|
10
|
+
"types": "./generated.d.ts",
|
|
11
|
+
"import": "./generated.js"
|
|
12
|
+
},
|
|
13
|
+
"./auth": {
|
|
14
|
+
"types": "./auth.d.ts",
|
|
15
|
+
"import": "./auth.js"
|
|
16
|
+
},
|
|
17
|
+
"./auth/browser": {
|
|
18
|
+
"types": "./auth/browser.d.ts",
|
|
19
|
+
"import": "./auth/browser.js"
|
|
20
|
+
},
|
|
21
|
+
"./device": {
|
|
22
|
+
"types": "./device.d.ts",
|
|
23
|
+
"import": "./device.js"
|
|
24
|
+
},
|
|
25
|
+
"./errors": {
|
|
26
|
+
"types": "./errors/index.d.ts",
|
|
27
|
+
"import": "./errors/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./service": {
|
|
30
|
+
"types": "./service/mod.d.ts",
|
|
31
|
+
"import": "./service/mod.js"
|
|
32
|
+
},
|
|
33
|
+
"./telemetry": {
|
|
34
|
+
"types": "./telemetry.d.ts",
|
|
35
|
+
"import": "./telemetry.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@opentelemetry/api": "^1.9.1",
|
|
40
|
+
"@opentelemetry/exporter-metrics-otlp-proto": "^0.215.0",
|
|
41
|
+
"@opentelemetry/exporter-trace-otlp-proto": "^0.215.0",
|
|
42
|
+
"@opentelemetry/resources": "^2.7.0",
|
|
43
|
+
"@opentelemetry/sdk-metrics": "^2.7.0",
|
|
44
|
+
"@opentelemetry/sdk-trace-base": "^2.7.0",
|
|
45
|
+
"@opentelemetry/sdk-trace-node": "^2.7.0",
|
|
46
|
+
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
47
|
+
"@nats-io/jetstream": "^3.3.1",
|
|
48
|
+
"@nats-io/kv": "^3.3.1",
|
|
49
|
+
"@nats-io/obj": "^3.3.1",
|
|
50
|
+
"@nats-io/nats-core": "^3.3.1",
|
|
51
|
+
"@nats-io/nkeys": "^2.0.3",
|
|
52
|
+
"@nats-io/transport-node": "^3.3.1",
|
|
53
|
+
"@noble/curves": "^2.0.1",
|
|
54
|
+
"@noble/hashes": "1.8.0",
|
|
55
|
+
"@oatscenter/result": "0.100.0-rc.1",
|
|
56
|
+
"js-sha256": "^0.11.1",
|
|
57
|
+
"pino": "^10.3.1",
|
|
58
|
+
"tweetnacl": "^1.0.3",
|
|
59
|
+
"ts-deepmerge": "^7.0.3",
|
|
60
|
+
"typebox": "^1.1.33",
|
|
61
|
+
"ulid": "^3.0.2"
|
|
62
|
+
},
|
|
63
|
+
"version": "0.100.0-rc.1",
|
|
64
|
+
"type": "module",
|
|
65
|
+
"license": "Apache-2.0",
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
},
|
|
69
|
+
"repository": {
|
|
70
|
+
"type": "git",
|
|
71
|
+
"url": "git+https://github.com/OATS-Center/trellis.git"
|
|
72
|
+
}
|
|
73
|
+
}
|
package/pagination.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type AsyncResult, BaseError, type BaseErrorSchema, type Result } from "@oatscenter/result";
|
|
2
|
+
import type { RequestOpts } from "./session.ts";
|
|
3
|
+
type CursorPage<TItem> = Readonly<{
|
|
4
|
+
items: readonly TItem[];
|
|
5
|
+
page: Readonly<{
|
|
6
|
+
nextCursor?: string;
|
|
7
|
+
}>;
|
|
8
|
+
}>;
|
|
9
|
+
export type PaginationErrorData = BaseErrorSchema & {
|
|
10
|
+
type: "PaginationError";
|
|
11
|
+
cursor: string;
|
|
12
|
+
};
|
|
13
|
+
/** Failure caused by an invalid cursor sequence returned during pagination. */
|
|
14
|
+
export declare class PaginationError extends BaseError<PaginationErrorData> {
|
|
15
|
+
readonly cursor: string;
|
|
16
|
+
readonly name: "PaginationError";
|
|
17
|
+
constructor(cursor: string);
|
|
18
|
+
toSerializable(): PaginationErrorData;
|
|
19
|
+
}
|
|
20
|
+
type CursorCall = (input: unknown, options?: RequestOpts) => AsyncResult<unknown, BaseError>;
|
|
21
|
+
/** Lazily traverses complete pages from one cursor-paginated RPC. */
|
|
22
|
+
export declare function cursorPages<TPage extends CursorPage<unknown>>(call: CursorCall, input?: unknown, options?: RequestOpts): AsyncIterable<Result<TPage, BaseError>>;
|
|
23
|
+
/** Lazily traverses items from one cursor-paginated RPC. */
|
|
24
|
+
export declare function cursorItems<TItem, TPage extends CursorPage<TItem>>(call: CursorCall, input?: unknown, options?: RequestOpts): AsyncIterable<Result<TItem, BaseError>>;
|
|
25
|
+
export {};
|
package/pagination.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { BaseError, err, ok, } from "@oatscenter/result";
|
|
2
|
+
/** Failure caused by an invalid cursor sequence returned during pagination. */
|
|
3
|
+
export class PaginationError extends BaseError {
|
|
4
|
+
cursor;
|
|
5
|
+
name = "PaginationError";
|
|
6
|
+
constructor(cursor) {
|
|
7
|
+
super("The paginated RPC returned a cursor that was already visited.", {
|
|
8
|
+
context: { cursor },
|
|
9
|
+
});
|
|
10
|
+
this.cursor = cursor;
|
|
11
|
+
}
|
|
12
|
+
toSerializable() {
|
|
13
|
+
return { ...this.baseSerializable(), type: this.name, cursor: this.cursor };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function pageIterator(call, input, options) {
|
|
17
|
+
let cursor;
|
|
18
|
+
let stopped = false;
|
|
19
|
+
let inFlight;
|
|
20
|
+
let serial = Promise.resolve();
|
|
21
|
+
const initialCursor = typeof input === "object" && input !== null &&
|
|
22
|
+
"page" in input && typeof input.page === "object" &&
|
|
23
|
+
input.page !== null &&
|
|
24
|
+
"cursor" in input.page && typeof input.page.cursor === "string" &&
|
|
25
|
+
input.page.cursor.length > 0
|
|
26
|
+
? input.page.cursor
|
|
27
|
+
: undefined;
|
|
28
|
+
const seen = new Set(initialCursor === undefined ? [] : [initialCursor]);
|
|
29
|
+
const next = () => {
|
|
30
|
+
const result = serial.then(async () => {
|
|
31
|
+
if (stopped)
|
|
32
|
+
return { value: undefined, done: true };
|
|
33
|
+
const controller = new AbortController();
|
|
34
|
+
inFlight = controller;
|
|
35
|
+
const signal = options?.signal
|
|
36
|
+
? AbortSignal.any([options.signal, controller.signal])
|
|
37
|
+
: controller.signal;
|
|
38
|
+
const requestInput = cursor === undefined ? input ?? {} : {
|
|
39
|
+
...(typeof input === "object" && input !== null ? input : {}),
|
|
40
|
+
page: {
|
|
41
|
+
...(typeof input === "object" && input !== null &&
|
|
42
|
+
"page" in input && typeof input.page === "object" &&
|
|
43
|
+
input.page !== null
|
|
44
|
+
? input.page
|
|
45
|
+
: {}),
|
|
46
|
+
cursor,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
const result = await call(requestInput, { ...options, signal });
|
|
50
|
+
if (inFlight === controller)
|
|
51
|
+
inFlight = undefined;
|
|
52
|
+
if (stopped)
|
|
53
|
+
return { value: undefined, done: true };
|
|
54
|
+
if (result.isErr()) {
|
|
55
|
+
stopped = true;
|
|
56
|
+
return { value: result, done: false };
|
|
57
|
+
}
|
|
58
|
+
const page = result.take();
|
|
59
|
+
const nextCursor = page.page.nextCursor;
|
|
60
|
+
if (nextCursor === undefined) {
|
|
61
|
+
stopped = true;
|
|
62
|
+
}
|
|
63
|
+
else if (seen.has(nextCursor)) {
|
|
64
|
+
stopped = true;
|
|
65
|
+
return { value: err(new PaginationError(nextCursor)), done: false };
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
seen.add(nextCursor);
|
|
69
|
+
cursor = nextCursor;
|
|
70
|
+
}
|
|
71
|
+
return { value: ok(page), done: false };
|
|
72
|
+
});
|
|
73
|
+
serial = result.then(() => undefined, () => undefined);
|
|
74
|
+
return result;
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
next,
|
|
78
|
+
async return() {
|
|
79
|
+
stopped = true;
|
|
80
|
+
inFlight?.abort();
|
|
81
|
+
return { value: undefined, done: true };
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Lazily traverses complete pages from one cursor-paginated RPC. */
|
|
86
|
+
export function cursorPages(call, input, options) {
|
|
87
|
+
return { [Symbol.asyncIterator]: () => pageIterator(call, input, options) };
|
|
88
|
+
}
|
|
89
|
+
/** Lazily traverses items from one cursor-paginated RPC. */
|
|
90
|
+
export function cursorItems(call, input, options) {
|
|
91
|
+
return {
|
|
92
|
+
[Symbol.asyncIterator]() {
|
|
93
|
+
const pages = pageIterator(call, input, options);
|
|
94
|
+
let items = [][Symbol.iterator]();
|
|
95
|
+
return {
|
|
96
|
+
async next() {
|
|
97
|
+
while (true) {
|
|
98
|
+
const item = items.next();
|
|
99
|
+
if (!item.done) {
|
|
100
|
+
return { value: ok(item.value), done: false };
|
|
101
|
+
}
|
|
102
|
+
const page = await pages.next();
|
|
103
|
+
if (page.done)
|
|
104
|
+
return { value: undefined, done: true };
|
|
105
|
+
if (page.value.isErr())
|
|
106
|
+
return { value: page.value, done: false };
|
|
107
|
+
items = page.value.orThrow().items[Symbol.iterator]();
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
async return() {
|
|
111
|
+
await pages.return?.();
|
|
112
|
+
return { value: undefined, done: true };
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
package/participant.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./participant_runtime/api.ts";
|
|
2
|
+
export * from "./participant_runtime/json.ts";
|
|
3
|
+
export * from "./participant_runtime/metadata.ts";
|
|
4
|
+
export * from "./participant_runtime/participant.ts";
|
|
5
|
+
export * from "./participant_runtime/schemas.ts";
|
|
6
|
+
export * from "./participant_runtime/surface_names.ts";
|
package/participant.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./participant_runtime/api.js";
|
|
2
|
+
export * from "./participant_runtime/json.js";
|
|
3
|
+
export * from "./participant_runtime/metadata.js";
|
|
4
|
+
export * from "./participant_runtime/participant.js";
|
|
5
|
+
export * from "./participant_runtime/schemas.js";
|
|
6
|
+
export * from "./participant_runtime/surface_names.js";
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { StaticDecode, TSchema } from "typebox";
|
|
2
|
+
import type { BaseError } from "@oatscenter/result";
|
|
3
|
+
import type { Codec } from "../generated.ts";
|
|
4
|
+
type SubjectParam = `/${string}`;
|
|
5
|
+
/** Encodes one exact generated event descriptor identity for signed metadata. */
|
|
6
|
+
export declare function eventDescriptorIdentity(apiId: string, eventName: string, parameterCount: number): string;
|
|
7
|
+
/** Derives one deployment-bound API request subject. */
|
|
8
|
+
export declare function boundApiSubject(family: "rpc" | "operation" | "feed", apiId: string, providerDeploymentId: string, action: string): string;
|
|
9
|
+
/** Derives one API-qualified event subject template. */
|
|
10
|
+
export declare function eventSubject(apiId: string, action: string): string;
|
|
11
|
+
/** Derives an owner control subscription or an exact subject for one Feed instance. */
|
|
12
|
+
export declare function feedControlSubject(feedSubject: string, ownerInstanceId: string, feedId?: string): string;
|
|
13
|
+
/** Derives the stable queue shared by replicas subscribed to an exact route. */
|
|
14
|
+
export declare function routeQueueGroup(subject: string): string;
|
|
15
|
+
export type Schema<T> = {
|
|
16
|
+
schema: unknown;
|
|
17
|
+
readonly __trellisType?: T;
|
|
18
|
+
};
|
|
19
|
+
export type SchemaLike<T = unknown> = TSchema | Schema<T> | Codec<T>;
|
|
20
|
+
export type SerializableErrorData = {
|
|
21
|
+
id: string;
|
|
22
|
+
type: string;
|
|
23
|
+
message: string;
|
|
24
|
+
context?: Record<string, unknown>;
|
|
25
|
+
traceId?: string;
|
|
26
|
+
} & Record<string, unknown>;
|
|
27
|
+
export type RpcErrorClass<TData extends SerializableErrorData = SerializableErrorData, TError extends BaseError = BaseError> = {
|
|
28
|
+
fromSerializable(data: TData): TError;
|
|
29
|
+
};
|
|
30
|
+
export type RuntimeRpcErrorDesc<TType extends string = string, TSchema extends SchemaLike | undefined = SchemaLike | undefined, TError extends BaseError = BaseError> = {
|
|
31
|
+
type: TType;
|
|
32
|
+
schema?: TSchema;
|
|
33
|
+
fromSerializable(data: TSchema extends SchemaLike ? InferSchemaType<TSchema> : SerializableErrorData): TError;
|
|
34
|
+
};
|
|
35
|
+
export type InferRuntimeRpcError<T extends RuntimeRpcErrorDesc> = T extends RuntimeRpcErrorDesc<string, SchemaLike | undefined, infer TError> ? TError : never;
|
|
36
|
+
export type InferSchemaType<S> = S extends Schema<infer T> ? T : S extends {
|
|
37
|
+
decode(value: unknown): infer T;
|
|
38
|
+
} ? T : S extends TSchema ? StaticDecode<S> : unknown;
|
|
39
|
+
export declare function schema<T>(raw: unknown): Schema<T>;
|
|
40
|
+
export declare function unwrapSchema(raw: SchemaLike): unknown;
|
|
41
|
+
/** Exact permission metadata for one contract API surface action. */
|
|
42
|
+
export type PermissionAtom = Readonly<{
|
|
43
|
+
/** Source API semantic identity. */
|
|
44
|
+
apiId: string;
|
|
45
|
+
/** Version of the source API surface. */
|
|
46
|
+
apiVersion: `v${number}`;
|
|
47
|
+
/** API surface family. */
|
|
48
|
+
surfaceKind: "rpc" | "operation" | "event" | "feed" | "state";
|
|
49
|
+
/** Exact API-local surface name. */
|
|
50
|
+
surfaceName: string;
|
|
51
|
+
/** Exact action required for the surface. */
|
|
52
|
+
action: "call" | "invoke" | "observe" | "cancel" | "control" | "publish" | "subscribe" | "read" | "write" | "delete" | "submit" | "process" | "consume";
|
|
53
|
+
}>;
|
|
54
|
+
export type RPCDesc<I extends SchemaLike = SchemaLike, O extends SchemaLike = SchemaLike, E extends readonly string[] | undefined = readonly string[] | undefined, TRuntimeErrors extends readonly RuntimeRpcErrorDesc[] | undefined = readonly RuntimeRpcErrorDesc[] | undefined> = {
|
|
55
|
+
subject: string;
|
|
56
|
+
input: I;
|
|
57
|
+
output: O;
|
|
58
|
+
/** Exact permission required to call this RPC. */
|
|
59
|
+
permission: PermissionAtom;
|
|
60
|
+
callerCapabilities: readonly string[];
|
|
61
|
+
transfer?: {
|
|
62
|
+
direction: "receive";
|
|
63
|
+
};
|
|
64
|
+
authRequired?: boolean;
|
|
65
|
+
errors?: E;
|
|
66
|
+
runtimeErrors?: TRuntimeErrors;
|
|
67
|
+
declaredErrorTypes?: readonly string[];
|
|
68
|
+
};
|
|
69
|
+
export type EventDesc<S extends SchemaLike = SchemaLike> = {
|
|
70
|
+
subject: string;
|
|
71
|
+
/** Canonical API, event, and parameter-shape identity bound into proofs. */
|
|
72
|
+
descriptorIdentity: string;
|
|
73
|
+
params?: readonly SubjectParam[];
|
|
74
|
+
event: S;
|
|
75
|
+
/** Exact permission required to publish this event. */
|
|
76
|
+
publishPermission: PermissionAtom;
|
|
77
|
+
/** Exact permission required to subscribe to this event. */
|
|
78
|
+
subscribePermission: PermissionAtom;
|
|
79
|
+
publishCapabilities: readonly string[];
|
|
80
|
+
subscribeCapabilities: readonly string[];
|
|
81
|
+
};
|
|
82
|
+
export type FeedDesc<I extends SchemaLike = SchemaLike, E extends SchemaLike = SchemaLike> = {
|
|
83
|
+
subject: string;
|
|
84
|
+
input: I;
|
|
85
|
+
event: E;
|
|
86
|
+
/** Exact permission required to subscribe to this feed. */
|
|
87
|
+
permission: PermissionAtom;
|
|
88
|
+
subscribeCapabilities: readonly string[];
|
|
89
|
+
};
|
|
90
|
+
export type OperationDesc<I extends SchemaLike = SchemaLike, P extends SchemaLike | undefined = SchemaLike | undefined, O extends SchemaLike | undefined = SchemaLike | undefined, E extends readonly string[] | undefined = readonly string[] | undefined, TRuntimeErrors extends readonly RuntimeRpcErrorDesc[] | undefined = readonly RuntimeRpcErrorDesc[] | undefined, U extends SchemaLike | undefined = SchemaLike | undefined> = {
|
|
91
|
+
subject: string;
|
|
92
|
+
input: I;
|
|
93
|
+
progress?: P;
|
|
94
|
+
update?: U;
|
|
95
|
+
output?: O;
|
|
96
|
+
/** Exact permissions required by each operation action. */
|
|
97
|
+
permissions: Readonly<{
|
|
98
|
+
invoke: PermissionAtom;
|
|
99
|
+
observe: PermissionAtom;
|
|
100
|
+
cancel: PermissionAtom;
|
|
101
|
+
control: Readonly<Record<string, PermissionAtom>>;
|
|
102
|
+
}>;
|
|
103
|
+
errors?: E;
|
|
104
|
+
runtimeErrors?: TRuntimeErrors;
|
|
105
|
+
declaredErrorTypes?: readonly string[];
|
|
106
|
+
transfer?: {
|
|
107
|
+
direction: "send";
|
|
108
|
+
store?: string;
|
|
109
|
+
key?: `/${string}`;
|
|
110
|
+
contentType?: `/${string}`;
|
|
111
|
+
metadata?: `/${string}`;
|
|
112
|
+
expiresInMs?: number;
|
|
113
|
+
maxBytes?: number;
|
|
114
|
+
};
|
|
115
|
+
signals?: Record<string, {
|
|
116
|
+
input: SchemaLike;
|
|
117
|
+
}>;
|
|
118
|
+
callerCapabilities: readonly string[];
|
|
119
|
+
observeCapabilities: readonly string[];
|
|
120
|
+
cancelCapabilities: readonly string[];
|
|
121
|
+
controlCapabilities: readonly string[];
|
|
122
|
+
cancel?: boolean;
|
|
123
|
+
};
|
|
124
|
+
export type RuntimeApi = {
|
|
125
|
+
rpc: Record<string, RPCDesc>;
|
|
126
|
+
operations: Record<string, OperationDesc>;
|
|
127
|
+
events: Record<string, EventDesc>;
|
|
128
|
+
feeds?: Record<string, FeedDesc>;
|
|
129
|
+
subjects: Record<string, unknown>;
|
|
130
|
+
};
|
|
131
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { sha256Base64urlSync } from "./json.js";
|
|
2
|
+
function subjectToken(value) {
|
|
3
|
+
return btoa(String.fromCharCode(...new TextEncoder().encode(value)))
|
|
4
|
+
.replaceAll("+", "-")
|
|
5
|
+
.replaceAll("/", "_")
|
|
6
|
+
.replace(/=+$/u, "");
|
|
7
|
+
}
|
|
8
|
+
/** Encodes one exact generated event descriptor identity for signed metadata. */
|
|
9
|
+
export function eventDescriptorIdentity(apiId, eventName, parameterCount) {
|
|
10
|
+
if (!Number.isSafeInteger(parameterCount) || parameterCount < 0) {
|
|
11
|
+
throw new Error("event parameter count must be a non-negative safe integer");
|
|
12
|
+
}
|
|
13
|
+
return `v1.${subjectToken(apiId)}.${subjectToken(eventName)}.${parameterCount}`;
|
|
14
|
+
}
|
|
15
|
+
/** Derives one deployment-bound API request subject. */
|
|
16
|
+
export function boundApiSubject(family, apiId, providerDeploymentId, action) {
|
|
17
|
+
return `${family}.v1.${subjectToken(apiId)}.${subjectToken(providerDeploymentId)}.${action}`;
|
|
18
|
+
}
|
|
19
|
+
/** Derives one API-qualified event subject template. */
|
|
20
|
+
export function eventSubject(apiId, action) {
|
|
21
|
+
return `events.v1.${subjectToken(apiId)}.${action}`;
|
|
22
|
+
}
|
|
23
|
+
/** Derives an owner control subscription or an exact subject for one Feed instance. */
|
|
24
|
+
export function feedControlSubject(feedSubject, ownerInstanceId, feedId) {
|
|
25
|
+
const ownerSubject = `${feedSubject}.control.${subjectToken(ownerInstanceId)}`;
|
|
26
|
+
return feedId === undefined
|
|
27
|
+
? `${ownerSubject}.*`
|
|
28
|
+
: `${ownerSubject}.${subjectToken(feedId)}`;
|
|
29
|
+
}
|
|
30
|
+
/** Derives the stable queue shared by replicas subscribed to an exact route. */
|
|
31
|
+
export function routeQueueGroup(subject) {
|
|
32
|
+
return `trellis.${sha256Base64urlSync(subject)}`;
|
|
33
|
+
}
|
|
34
|
+
export function schema(raw) {
|
|
35
|
+
return { schema: raw };
|
|
36
|
+
}
|
|
37
|
+
export function unwrapSchema(raw) {
|
|
38
|
+
if (raw && typeof raw === "object" && "schema" in raw) {
|
|
39
|
+
return raw.schema;
|
|
40
|
+
}
|
|
41
|
+
return raw;
|
|
42
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
2
|
+
[k: string]: JsonValue;
|
|
3
|
+
};
|
|
4
|
+
export declare function isJsonValue(value: unknown): value is JsonValue;
|
|
5
|
+
export declare function canonicalizeJson(value: JsonValue): string;
|
|
6
|
+
export declare function base64url(bytes: Uint8Array): string;
|
|
7
|
+
export declare function sha256Bytes(data: Uint8Array): Uint8Array;
|
|
8
|
+
/** Computes a synchronous SHA-256 digest encoded as base64url. */
|
|
9
|
+
export declare function sha256Base64urlSync(text: string): string;
|
|
10
|
+
/** Computes a SHA-256 digest encoded as base64url. */
|
|
11
|
+
export declare function sha256Base64url(text: string): Promise<string>;
|
|
12
|
+
/** Canonicalizes JSON and computes its SHA-256 base64url digest. */
|
|
13
|
+
export declare function digestJson(value: JsonValue): Promise<{
|
|
14
|
+
canonical: string;
|
|
15
|
+
digest: string;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
export function isJsonValue(value) {
|
|
2
|
+
if (value === null ||
|
|
3
|
+
typeof value === "string" ||
|
|
4
|
+
typeof value === "boolean")
|
|
5
|
+
return true;
|
|
6
|
+
if (typeof value === "number") {
|
|
7
|
+
return Number.isFinite(value) && !Object.is(value, -0);
|
|
8
|
+
}
|
|
9
|
+
if (Array.isArray(value))
|
|
10
|
+
return value.every(isJsonValue);
|
|
11
|
+
if (typeof value === "object") {
|
|
12
|
+
return Object.values(value).every(isJsonValue);
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
export function canonicalizeJson(value) {
|
|
17
|
+
if (value === null)
|
|
18
|
+
return "null";
|
|
19
|
+
if (typeof value === "boolean")
|
|
20
|
+
return value ? "true" : "false";
|
|
21
|
+
if (typeof value === "string")
|
|
22
|
+
return JSON.stringify(value);
|
|
23
|
+
if (typeof value === "number") {
|
|
24
|
+
if (!Number.isFinite(value)) {
|
|
25
|
+
throw new Error(`Non-canonical number in manifest: ${value}`);
|
|
26
|
+
}
|
|
27
|
+
return JSON.stringify(value);
|
|
28
|
+
}
|
|
29
|
+
if (Array.isArray(value)) {
|
|
30
|
+
return `[${value.map(canonicalizeJson).join(",")}]`;
|
|
31
|
+
}
|
|
32
|
+
const keys = Object.keys(value).sort();
|
|
33
|
+
const entries = keys.map((k) => `${JSON.stringify(k)}:${canonicalizeJson(value[k])}`);
|
|
34
|
+
return `{${entries.join(",")}}`;
|
|
35
|
+
}
|
|
36
|
+
export function base64url(bytes) {
|
|
37
|
+
let bin = "";
|
|
38
|
+
for (const b of bytes)
|
|
39
|
+
bin += String.fromCharCode(b);
|
|
40
|
+
const b64 = btoa(bin);
|
|
41
|
+
return b64.replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/u, "");
|
|
42
|
+
}
|
|
43
|
+
function rotr(value, bits) {
|
|
44
|
+
return (value >>> bits) | (value << (32 - bits));
|
|
45
|
+
}
|
|
46
|
+
export function sha256Bytes(data) {
|
|
47
|
+
const K = new Uint32Array([
|
|
48
|
+
0x428a2f98,
|
|
49
|
+
0x71374491,
|
|
50
|
+
0xb5c0fbcf,
|
|
51
|
+
0xe9b5dba5,
|
|
52
|
+
0x3956c25b,
|
|
53
|
+
0x59f111f1,
|
|
54
|
+
0x923f82a4,
|
|
55
|
+
0xab1c5ed5,
|
|
56
|
+
0xd807aa98,
|
|
57
|
+
0x12835b01,
|
|
58
|
+
0x243185be,
|
|
59
|
+
0x550c7dc3,
|
|
60
|
+
0x72be5d74,
|
|
61
|
+
0x80deb1fe,
|
|
62
|
+
0x9bdc06a7,
|
|
63
|
+
0xc19bf174,
|
|
64
|
+
0xe49b69c1,
|
|
65
|
+
0xefbe4786,
|
|
66
|
+
0x0fc19dc6,
|
|
67
|
+
0x240ca1cc,
|
|
68
|
+
0x2de92c6f,
|
|
69
|
+
0x4a7484aa,
|
|
70
|
+
0x5cb0a9dc,
|
|
71
|
+
0x76f988da,
|
|
72
|
+
0x983e5152,
|
|
73
|
+
0xa831c66d,
|
|
74
|
+
0xb00327c8,
|
|
75
|
+
0xbf597fc7,
|
|
76
|
+
0xc6e00bf3,
|
|
77
|
+
0xd5a79147,
|
|
78
|
+
0x06ca6351,
|
|
79
|
+
0x14292967,
|
|
80
|
+
0x27b70a85,
|
|
81
|
+
0x2e1b2138,
|
|
82
|
+
0x4d2c6dfc,
|
|
83
|
+
0x53380d13,
|
|
84
|
+
0x650a7354,
|
|
85
|
+
0x766a0abb,
|
|
86
|
+
0x81c2c92e,
|
|
87
|
+
0x92722c85,
|
|
88
|
+
0xa2bfe8a1,
|
|
89
|
+
0xa81a664b,
|
|
90
|
+
0xc24b8b70,
|
|
91
|
+
0xc76c51a3,
|
|
92
|
+
0xd192e819,
|
|
93
|
+
0xd6990624,
|
|
94
|
+
0xf40e3585,
|
|
95
|
+
0x106aa070,
|
|
96
|
+
0x19a4c116,
|
|
97
|
+
0x1e376c08,
|
|
98
|
+
0x2748774c,
|
|
99
|
+
0x34b0bcb5,
|
|
100
|
+
0x391c0cb3,
|
|
101
|
+
0x4ed8aa4a,
|
|
102
|
+
0x5b9cca4f,
|
|
103
|
+
0x682e6ff3,
|
|
104
|
+
0x748f82ee,
|
|
105
|
+
0x78a5636f,
|
|
106
|
+
0x84c87814,
|
|
107
|
+
0x8cc70208,
|
|
108
|
+
0x90befffa,
|
|
109
|
+
0xa4506ceb,
|
|
110
|
+
0xbef9a3f7,
|
|
111
|
+
0xc67178f2,
|
|
112
|
+
]);
|
|
113
|
+
const H = new Uint32Array([
|
|
114
|
+
0x6a09e667,
|
|
115
|
+
0xbb67ae85,
|
|
116
|
+
0x3c6ef372,
|
|
117
|
+
0xa54ff53a,
|
|
118
|
+
0x510e527f,
|
|
119
|
+
0x9b05688c,
|
|
120
|
+
0x1f83d9ab,
|
|
121
|
+
0x5be0cd19,
|
|
122
|
+
]);
|
|
123
|
+
const bitLength = data.length * 8;
|
|
124
|
+
const paddedLength = Math.ceil((data.length + 9) / 64) * 64;
|
|
125
|
+
const padded = new Uint8Array(paddedLength);
|
|
126
|
+
padded.set(data);
|
|
127
|
+
padded[data.length] = 0x80;
|
|
128
|
+
const view = new DataView(padded.buffer);
|
|
129
|
+
view.setUint32(paddedLength - 4, bitLength >>> 0, false);
|
|
130
|
+
view.setUint32(paddedLength - 8, Math.floor(bitLength / 2 ** 32), false);
|
|
131
|
+
const w = new Uint32Array(64);
|
|
132
|
+
for (let offset = 0; offset < padded.length; offset += 64) {
|
|
133
|
+
for (let i = 0; i < 16; i++) {
|
|
134
|
+
w[i] = view.getUint32(offset + i * 4, false);
|
|
135
|
+
}
|
|
136
|
+
for (let i = 16; i < 64; i++) {
|
|
137
|
+
const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^
|
|
138
|
+
(w[i - 15] >>> 3);
|
|
139
|
+
const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >>> 10);
|
|
140
|
+
w[i] = (((w[i - 16] + s0) | 0) + w[i - 7] + s1) >>> 0;
|
|
141
|
+
}
|
|
142
|
+
let [a, b, c, d, e, f, g, h] = H;
|
|
143
|
+
for (let i = 0; i < 64; i++) {
|
|
144
|
+
const s1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
145
|
+
const ch = (e & f) ^ (~e & g);
|
|
146
|
+
const temp1 = (((((h + s1) | 0) + ch) | 0) + K[i] + w[i]) >>> 0;
|
|
147
|
+
const s0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
148
|
+
const maj = (a & b) ^ (a & c) ^ (b & c);
|
|
149
|
+
const temp2 = (s0 + maj) >>> 0;
|
|
150
|
+
h = g;
|
|
151
|
+
g = f;
|
|
152
|
+
f = e;
|
|
153
|
+
e = (d + temp1) >>> 0;
|
|
154
|
+
d = c;
|
|
155
|
+
c = b;
|
|
156
|
+
b = a;
|
|
157
|
+
a = (temp1 + temp2) >>> 0;
|
|
158
|
+
}
|
|
159
|
+
H[0] = (H[0] + a) >>> 0;
|
|
160
|
+
H[1] = (H[1] + b) >>> 0;
|
|
161
|
+
H[2] = (H[2] + c) >>> 0;
|
|
162
|
+
H[3] = (H[3] + d) >>> 0;
|
|
163
|
+
H[4] = (H[4] + e) >>> 0;
|
|
164
|
+
H[5] = (H[5] + f) >>> 0;
|
|
165
|
+
H[6] = (H[6] + g) >>> 0;
|
|
166
|
+
H[7] = (H[7] + h) >>> 0;
|
|
167
|
+
}
|
|
168
|
+
const out = new Uint8Array(32);
|
|
169
|
+
const outView = new DataView(out.buffer);
|
|
170
|
+
for (let i = 0; i < H.length; i++) {
|
|
171
|
+
outView.setUint32(i * 4, H[i], false);
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
/** Computes a synchronous SHA-256 digest encoded as base64url. */
|
|
176
|
+
export function sha256Base64urlSync(text) {
|
|
177
|
+
return base64url(sha256Bytes(new TextEncoder().encode(text)));
|
|
178
|
+
}
|
|
179
|
+
/** Computes a SHA-256 digest encoded as base64url. */
|
|
180
|
+
export async function sha256Base64url(text) {
|
|
181
|
+
if (typeof crypto !== "undefined" && crypto.subtle) {
|
|
182
|
+
const data = new TextEncoder().encode(text);
|
|
183
|
+
const digest = await crypto.subtle.digest("SHA-256", data);
|
|
184
|
+
return base64url(new Uint8Array(digest));
|
|
185
|
+
}
|
|
186
|
+
return sha256Base64urlSync(text);
|
|
187
|
+
}
|
|
188
|
+
/** Canonicalizes JSON and computes its SHA-256 base64url digest. */
|
|
189
|
+
export async function digestJson(value) {
|
|
190
|
+
const canonical = canonicalizeJson(value);
|
|
191
|
+
const digest = await sha256Base64url(canonical);
|
|
192
|
+
return { canonical, digest };
|
|
193
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { KvRepresentation } from "../kv.ts";
|
|
2
|
+
import type { SchemaLike } from "./api.ts";
|
|
3
|
+
export declare const PARTICIPANT_JOBS_METADATA: unique symbol;
|
|
4
|
+
export declare const PARTICIPANT_KV_METADATA: unique symbol;
|
|
5
|
+
export declare const PARTICIPANT_STORE_METADATA: unique symbol;
|
|
6
|
+
export declare const PARTICIPANT_EVENT_CONSUMERS_METADATA: unique symbol;
|
|
7
|
+
export type ParticipantJobsMetadata = Record<string, {
|
|
8
|
+
payload: unknown;
|
|
9
|
+
update?: unknown;
|
|
10
|
+
updateSchema?: SchemaLike;
|
|
11
|
+
result: unknown;
|
|
12
|
+
}>;
|
|
13
|
+
export type ParticipantKvMetadata = Record<string, {
|
|
14
|
+
required: boolean;
|
|
15
|
+
value: unknown;
|
|
16
|
+
schema: KvRepresentation<unknown>;
|
|
17
|
+
}>;
|
|
18
|
+
export type ParticipantStoreMetadata = Record<string, {
|
|
19
|
+
required: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
export type TrellisValidationIssueHint = {
|
|
22
|
+
code: string;
|
|
23
|
+
message: string;
|
|
24
|
+
note?: string;
|
|
25
|
+
label?: string;
|
|
26
|
+
i18nKey?: string;
|
|
27
|
+
severity?: "error" | "warning" | "info";
|
|
28
|
+
};
|
|
29
|
+
export type TrellisValidationExtension = {
|
|
30
|
+
label?: string;
|
|
31
|
+
note?: string;
|
|
32
|
+
uiPath?: string;
|
|
33
|
+
issues?: Record<string, TrellisValidationIssueHint>;
|
|
34
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export const PARTICIPANT_JOBS_METADATA = Symbol.for("@oatscenter/trellis/participant/jobs");
|
|
2
|
+
export const PARTICIPANT_KV_METADATA = Symbol.for("@oatscenter/trellis/participant/kv");
|
|
3
|
+
export const PARTICIPANT_STORE_METADATA = Symbol.for("@oatscenter/trellis/participant/store");
|
|
4
|
+
export const PARTICIPANT_EVENT_CONSUMERS_METADATA = Symbol.for("@oatscenter/trellis/participant/event-consumers");
|