@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/session.d.ts
ADDED
|
@@ -0,0 +1,862 @@
|
|
|
1
|
+
import { type JetStreamClient } from "@nats-io/jetstream";
|
|
2
|
+
import { type Msg, type NatsConnection } from "@nats-io/nats-core";
|
|
3
|
+
import type { EventDesc, FeedDesc, InferSchemaType } from "./participant.ts";
|
|
4
|
+
import { type PermissionAtom as DescriptorPermissionAtom, type RuntimeApi } from "./participant_runtime/api.ts";
|
|
5
|
+
import type { Codec } from "./generated.ts";
|
|
6
|
+
import type { ParticipantKvMetadata } from "./participant_runtime/metadata.ts";
|
|
7
|
+
import { AuthorizationProviderCache } from "./auth/authorization_context.ts";
|
|
8
|
+
import { AsyncResult, BaseError, type MaybeAsync, Result } from "@oatscenter/result";
|
|
9
|
+
import { Type } from "typebox";
|
|
10
|
+
import { type JsonValue } from "./codec.ts";
|
|
11
|
+
import { AuthError, SchemaValidationError, type StoreError, TransferError, TransportError, type TrellisErrorInstance, type TrellisErrorMap, type TrellisErrorName, UnexpectedError, ValidationError } from "./errors/index.ts";
|
|
12
|
+
import { RemoteError } from "./errors/RemoteError.ts";
|
|
13
|
+
import { type LoggerLike } from "./globals.ts";
|
|
14
|
+
import { type KvRepresentation, type ResourceMigrations, TypedKV } from "./kv.ts";
|
|
15
|
+
import type { ActiveJob, JobRef, JobTypeMetadata, JobUpdatesOptions, JobUpdateSubscription } from "./jobs.ts";
|
|
16
|
+
import type { StoreWaitOptions, TypedStore, TypedStoreEntry } from "./store.ts";
|
|
17
|
+
import { OperationInvoker, type OperationRefData } from "./operations.ts";
|
|
18
|
+
import { type DeleteOutput as StateDeleteResponse, type GetOutput as StateGetResponse, type PutOutput as StateSetResponse } from "./internal_sdk/generated/apis/state/mod.js";
|
|
19
|
+
import { type FileInfo, type ReceiveTransferGrant, type ReceiveTransferHandle, type SendTransferGrant, type SendTransferHandle } from "./transfer.ts";
|
|
20
|
+
import { TrellisConnection } from "./connection.ts";
|
|
21
|
+
export type { NatsConnection } from "@nats-io/nats-core";
|
|
22
|
+
type InferRuntimeRpcError<T> = T extends {
|
|
23
|
+
fromSerializable(data: unknown): infer TError;
|
|
24
|
+
} ? TError : never;
|
|
25
|
+
/** Caller projection returned after a context-bound proof is verified locally. */
|
|
26
|
+
export type VerifiedCaller = {
|
|
27
|
+
type: "verified";
|
|
28
|
+
sessionKey: string;
|
|
29
|
+
principalId: string;
|
|
30
|
+
principalKind: "user" | "service" | "device";
|
|
31
|
+
participantId: string;
|
|
32
|
+
contextDigest: string;
|
|
33
|
+
connectionId: string;
|
|
34
|
+
loginSessionId: string | null;
|
|
35
|
+
identityKeyId: string | null;
|
|
36
|
+
deploymentId: string | null;
|
|
37
|
+
instanceId: string | null;
|
|
38
|
+
grantRevision: number;
|
|
39
|
+
platformPrivileges: ("trellis.auth::admin")[];
|
|
40
|
+
inboxPrefix: string;
|
|
41
|
+
};
|
|
42
|
+
/** Internal system caller used only by explicitly unauthenticated surfaces. */
|
|
43
|
+
export type InternalCaller = {
|
|
44
|
+
type: "internal";
|
|
45
|
+
capabilities: readonly [];
|
|
46
|
+
};
|
|
47
|
+
/** Caller data exposed to Trellis handlers. */
|
|
48
|
+
export type SessionCaller = VerifiedCaller | InternalCaller;
|
|
49
|
+
type LocalAuthorizationRequestMessage = Pick<Msg, "data" | "headers" | "reply" | "subject">;
|
|
50
|
+
type LocalAuthorizationEventMessage = Pick<Msg, "data" | "headers" | "subject">;
|
|
51
|
+
type LocalAuthorizationArgs = {
|
|
52
|
+
kind: "request";
|
|
53
|
+
cache: AuthorizationProviderCache | undefined;
|
|
54
|
+
message: LocalAuthorizationRequestMessage;
|
|
55
|
+
proofPayload?: Uint8Array;
|
|
56
|
+
permission: DescriptorPermissionAtom | undefined;
|
|
57
|
+
requiredCapabilities: readonly string[];
|
|
58
|
+
identityOnly?: boolean;
|
|
59
|
+
} | {
|
|
60
|
+
kind: "event";
|
|
61
|
+
cache: AuthorizationProviderCache | undefined;
|
|
62
|
+
message: LocalAuthorizationEventMessage;
|
|
63
|
+
permission: DescriptorPermissionAtom | undefined;
|
|
64
|
+
descriptorIdentity: string;
|
|
65
|
+
requiredCapabilities: readonly string[];
|
|
66
|
+
};
|
|
67
|
+
/** Verifies one received request or event through the provider-local WASM cache. */
|
|
68
|
+
export declare function verifyLocalAuthorization(args: LocalAuthorizationArgs): Promise<Result<VerifiedCaller, AuthError>>;
|
|
69
|
+
/**
|
|
70
|
+
* Safely extract JSON from a NATS message.
|
|
71
|
+
* The .json() method can throw if the message data is not valid JSON.
|
|
72
|
+
*/
|
|
73
|
+
export declare function safeJson(msg: Msg): Result<JsonValue, UnexpectedError>;
|
|
74
|
+
/** Creates the existing typed transport error for an unavailable optional action. */
|
|
75
|
+
export declare function createActionUnavailableError(action: string, capabilities: readonly string[]): TransportError;
|
|
76
|
+
export declare function base64urlEncode(data: Uint8Array): string;
|
|
77
|
+
export declare function base64urlDecode(s: string): Uint8Array;
|
|
78
|
+
export declare function toArrayBuffer(data: Uint8Array): ArrayBuffer;
|
|
79
|
+
export declare function sha256(data: Uint8Array): Promise<Uint8Array>;
|
|
80
|
+
export declare function buildProofInput(contextDigest: string, subject: string, reply: string, payloadHash: Uint8Array, iat: number, requestId: string): Uint8Array;
|
|
81
|
+
export type TrellisSigner = (data: Uint8Array) => Promise<Uint8Array> | Uint8Array;
|
|
82
|
+
export type TrellisAuth = {
|
|
83
|
+
sessionKey: string;
|
|
84
|
+
sign: TrellisSigner;
|
|
85
|
+
currentIat?: () => number;
|
|
86
|
+
/** Current authorization-context digest bound into v1 request and event proofs. */
|
|
87
|
+
contextDigest?: string | (() => string);
|
|
88
|
+
/** Provider-only local verifier for service request and event handling. */
|
|
89
|
+
authorizationProviderCache?: AuthorizationProviderCache;
|
|
90
|
+
};
|
|
91
|
+
export type TrellisMode = "client" | "service";
|
|
92
|
+
type OwnedApiFor<TContract> = TContract extends {
|
|
93
|
+
implements: readonly unknown[];
|
|
94
|
+
} ? RuntimeApi : never;
|
|
95
|
+
type ContractKvFor<TContract> = TContract extends {
|
|
96
|
+
resources: infer TResources extends Readonly<Record<string, unknown>>;
|
|
97
|
+
} ? {
|
|
98
|
+
[K in keyof TResources as TResources[K] extends {
|
|
99
|
+
kind: "kv";
|
|
100
|
+
} ? K : never]: TResources[K] extends {
|
|
101
|
+
codec: infer TCodec;
|
|
102
|
+
availability: infer TAvailability;
|
|
103
|
+
} ? {
|
|
104
|
+
value: TCodec extends Codec<infer TValue> ? TValue : unknown;
|
|
105
|
+
schema: TCodec;
|
|
106
|
+
required: TAvailability extends "required" ? true : false;
|
|
107
|
+
} : never;
|
|
108
|
+
} : {};
|
|
109
|
+
type ContractJobsFor<TContract> = TContract extends {
|
|
110
|
+
resources: infer TResources extends Readonly<Record<string, unknown>>;
|
|
111
|
+
} ? {
|
|
112
|
+
[K in keyof TResources as TResources[K] extends {
|
|
113
|
+
kind: "job";
|
|
114
|
+
} ? K : never]: TResources[K] extends {
|
|
115
|
+
payload: infer TPayload;
|
|
116
|
+
result: infer TResult;
|
|
117
|
+
update: infer TUpdate;
|
|
118
|
+
} ? {
|
|
119
|
+
payload: TPayload extends Codec<infer TValue> ? TValue : unknown;
|
|
120
|
+
result: TResult extends Codec<infer TValue> ? TValue : void;
|
|
121
|
+
update: TUpdate extends Codec<infer TValue> ? TValue : never;
|
|
122
|
+
} : never;
|
|
123
|
+
} : {};
|
|
124
|
+
export type RuntimeStateStoreShape = {
|
|
125
|
+
kind: "value";
|
|
126
|
+
value: unknown;
|
|
127
|
+
codec: Codec<unknown>;
|
|
128
|
+
version: number;
|
|
129
|
+
migrations: Readonly<Record<number, Codec<unknown>>>;
|
|
130
|
+
};
|
|
131
|
+
export type RuntimeStateStores = Record<string, RuntimeStateStoreShape>;
|
|
132
|
+
export type RuntimeStateStoresForContract<TContract> = TContract extends {
|
|
133
|
+
resources: infer TResources extends Readonly<Record<string, unknown>>;
|
|
134
|
+
} ? {
|
|
135
|
+
[K in keyof TResources as TResources[K] extends {
|
|
136
|
+
kind: "state";
|
|
137
|
+
} ? K : never]: TResources[K] extends {
|
|
138
|
+
codec: infer TCodec;
|
|
139
|
+
} ? {
|
|
140
|
+
kind: "value";
|
|
141
|
+
value: TCodec extends Codec<infer TValue> ? TValue : unknown;
|
|
142
|
+
codec: TCodec;
|
|
143
|
+
version: TResources[K] extends {
|
|
144
|
+
version: infer TVersion;
|
|
145
|
+
} ? TVersion : number;
|
|
146
|
+
migrations: TResources[K] extends {
|
|
147
|
+
migrations: infer TMigrations;
|
|
148
|
+
} ? TMigrations : {};
|
|
149
|
+
} : never;
|
|
150
|
+
} : {};
|
|
151
|
+
type TrellisApiFor<TContract> = OwnedApiFor<TContract>;
|
|
152
|
+
type RpcMethodsOf<TA extends RuntimeApi> = TA["rpc"];
|
|
153
|
+
export type MethodsOf<TA extends RuntimeApi> = keyof RpcMethodsOf<TA> & string;
|
|
154
|
+
export type RpcMethodNameOf<TA extends RuntimeApi> = MethodsOf<TA>;
|
|
155
|
+
export type OperationsOf<TA extends RuntimeApi> = keyof TA["operations"] & string;
|
|
156
|
+
type EventsOf<TA extends RuntimeApi> = keyof TA["events"] & string;
|
|
157
|
+
export type FeedsOf<TA extends RuntimeApi> = keyof NonNullable<TA["feeds"]> & string;
|
|
158
|
+
type RpcMethodOf<TA extends RuntimeApi, M extends keyof TA["rpc"] & string> = RpcMethodsOf<TA>[M];
|
|
159
|
+
type MethodInputOf<TA extends RuntimeApi, M extends keyof TA["rpc"] & string> = RpcMethodOf<TA, M> extends {
|
|
160
|
+
input: infer TInput;
|
|
161
|
+
} ? InferSchemaType<TInput> : never;
|
|
162
|
+
export type RpcInputOf<TA extends RuntimeApi, M extends RpcMethodNameOf<TA>> = MethodInputOf<TA, M>;
|
|
163
|
+
type MethodOutputOf<TA extends RuntimeApi, M extends keyof TA["rpc"] & string> = RpcMethodOf<TA, M> extends {
|
|
164
|
+
output: infer TOutput;
|
|
165
|
+
} ? InferSchemaType<TOutput> : never;
|
|
166
|
+
export type RpcOutputOf<TA extends RuntimeApi, M extends RpcMethodNameOf<TA>> = MethodOutputOf<TA, M>;
|
|
167
|
+
type RpcRequestShapes<TA extends RuntimeApi> = {
|
|
168
|
+
[M in keyof TA["rpc"] & string]: {
|
|
169
|
+
input: MethodInputOf<TA, M>;
|
|
170
|
+
output: MethodOutputOf<TA, M>;
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
type RequestMethodOf<TRequests> = keyof TRequests & string;
|
|
174
|
+
type RequestInputOf<TRequests, M extends RequestMethodOf<TRequests>> = TRequests[M] extends {
|
|
175
|
+
input: infer TInput;
|
|
176
|
+
} ? TInput : never;
|
|
177
|
+
type RequestOutputOf<TRequests, M extends RequestMethodOf<TRequests>> = TRequests[M] extends {
|
|
178
|
+
output: infer TOutput;
|
|
179
|
+
} ? TOutput : never;
|
|
180
|
+
type RpcDescriptorOf<TA extends RuntimeApi, M extends keyof TA["rpc"] & string> = RpcMethodOf<TA, M> extends {
|
|
181
|
+
input: infer TInput;
|
|
182
|
+
output: infer TOutput;
|
|
183
|
+
errors?: infer TErrors;
|
|
184
|
+
runtimeErrors?: infer TRuntimeErrors;
|
|
185
|
+
declaredErrorTypes?: infer TDeclaredErrorTypes;
|
|
186
|
+
} ? {
|
|
187
|
+
input: TInput;
|
|
188
|
+
output: TOutput;
|
|
189
|
+
errors?: TErrors;
|
|
190
|
+
runtimeErrors?: TRuntimeErrors;
|
|
191
|
+
declaredErrorTypes?: TDeclaredErrorTypes;
|
|
192
|
+
} & RpcMethodOf<TA, M> : never;
|
|
193
|
+
type DeclaredBuiltinErrorOf<TNames> = TNames extends readonly (infer TName)[] ? TName extends TrellisErrorName ? TrellisErrorMap[TName] : never : never;
|
|
194
|
+
type DeclaredRuntimeErrorOf<TRuntimeErrors> = TRuntimeErrors extends readonly (infer TRuntimeError)[] ? InferRuntimeRpcError<TRuntimeError> : never;
|
|
195
|
+
type MethodDeclaredErrorOf<TA extends RuntimeApi, M extends keyof TA["rpc"] & string> = RpcDescriptorOf<TA, M> extends {
|
|
196
|
+
errors?: infer TErrors;
|
|
197
|
+
runtimeErrors?: infer TRuntimeErrors;
|
|
198
|
+
} ? DeclaredBuiltinErrorOf<TErrors> | DeclaredRuntimeErrorOf<TRuntimeErrors> : never;
|
|
199
|
+
type RequestErrorOf<TA extends RuntimeApi, M extends MethodsOf<TA>> = MethodDeclaredErrorOf<TA, M> | RemoteError | TransportError | ValidationError | UnexpectedError;
|
|
200
|
+
type HandlerErrorOf<TA extends RuntimeApi, M extends MethodsOf<TA>> = MethodDeclaredErrorOf<TA, M> | TrellisErrorInstance;
|
|
201
|
+
type OperationDescriptorOf<TA extends RuntimeApi, O extends OperationsOf<TA>> = TA["operations"][O] extends {
|
|
202
|
+
input: infer TInput;
|
|
203
|
+
progress?: infer TProgress;
|
|
204
|
+
output?: infer TOutput;
|
|
205
|
+
errors?: infer TErrors;
|
|
206
|
+
runtimeErrors?: infer TRuntimeErrors;
|
|
207
|
+
declaredErrorTypes?: infer TDeclaredErrorTypes;
|
|
208
|
+
} ? {
|
|
209
|
+
input: TInput;
|
|
210
|
+
progress?: TProgress;
|
|
211
|
+
output?: TOutput;
|
|
212
|
+
errors?: TErrors;
|
|
213
|
+
runtimeErrors?: TRuntimeErrors;
|
|
214
|
+
declaredErrorTypes?: TDeclaredErrorTypes;
|
|
215
|
+
} & TA["operations"][O] : never;
|
|
216
|
+
type OperationDeclaredErrorOf<TA extends RuntimeApi, O extends OperationsOf<TA>> = OperationDescriptorOf<TA, O> extends {
|
|
217
|
+
errors?: infer TErrors;
|
|
218
|
+
runtimeErrors?: infer TRuntimeErrors;
|
|
219
|
+
} ? DeclaredBuiltinErrorOf<TErrors> | DeclaredRuntimeErrorOf<TRuntimeErrors> : never;
|
|
220
|
+
export type OperationHandlerErrorOf<TA extends RuntimeApi, O extends OperationsOf<TA>> = OperationDeclaredErrorOf<TA, O> | TrellisErrorInstance;
|
|
221
|
+
type EventMessageOf<TA extends RuntimeApi, E extends EventsOf<TA>> = TA["events"][E] extends EventDesc<infer TEvent> ? InferSchemaType<TEvent> : never;
|
|
222
|
+
type EventOf<TA extends RuntimeApi, E extends EventsOf<TA>> = EventMessageOf<TA, E>;
|
|
223
|
+
type EventPayloadOf<TA extends RuntimeApi, E extends EventsOf<TA>> = EventOf<TA, E> & Record<string, unknown>;
|
|
224
|
+
/** Runtime metadata assigned to every Trellis event message. */
|
|
225
|
+
export type TrellisEventHeader = Readonly<{
|
|
226
|
+
/** Stable event id used for event identity and JetStream de-duplication. */
|
|
227
|
+
id: string;
|
|
228
|
+
/** Event creation time in ISO-8601 format. */
|
|
229
|
+
time: string;
|
|
230
|
+
}>;
|
|
231
|
+
/** Event body plus Trellis runtime event metadata. */
|
|
232
|
+
export type TrellisEventMessage<TBody extends Record<string, unknown> = Record<string, unknown>> = Readonly<{
|
|
233
|
+
/** User-authored contract event body. */
|
|
234
|
+
body: Readonly<TBody>;
|
|
235
|
+
/** Runtime metadata assigned by Trellis. */
|
|
236
|
+
header: TrellisEventHeader;
|
|
237
|
+
}>;
|
|
238
|
+
/** A fully encoded event whose subject, payload, and headers are stable. */
|
|
239
|
+
export type PreparedTrellisEvent<TPayload extends Record<string, unknown> = Record<string, unknown>> = Readonly<{
|
|
240
|
+
event: string;
|
|
241
|
+
descriptorIdentity: string;
|
|
242
|
+
subject: string;
|
|
243
|
+
/** Runtime event metadata assigned when the event was prepared. */
|
|
244
|
+
header: TrellisEventHeader;
|
|
245
|
+
payload: Readonly<TPayload>;
|
|
246
|
+
encodedPayload: string;
|
|
247
|
+
headers: Readonly<Record<string, string>>;
|
|
248
|
+
}>;
|
|
249
|
+
export type FeedInputOf<TA extends RuntimeApi, F extends FeedsOf<TA>> = NonNullable<TA["feeds"]>[F] extends FeedDesc<infer TInput, infer _TEvent> ? InferSchemaType<TInput> : never;
|
|
250
|
+
export type FeedEventOf<TA extends RuntimeApi, F extends FeedsOf<TA>> = NonNullable<TA["feeds"]>[F] extends FeedDesc<infer _TInput, infer TEvent> ? InferSchemaType<TEvent> : never;
|
|
251
|
+
export type OperationInputOf<TA extends RuntimeApi, O extends OperationsOf<TA>> = TA["operations"][O] extends {
|
|
252
|
+
input: infer TInput;
|
|
253
|
+
} ? InferSchemaType<TInput> : never;
|
|
254
|
+
export type OperationProgressOf<TA extends RuntimeApi, O extends OperationsOf<TA>> = TA["operations"][O] extends {
|
|
255
|
+
progress?: infer TProgress;
|
|
256
|
+
} ? TProgress extends undefined ? unknown : InferSchemaType<NonNullable<TProgress>> : unknown;
|
|
257
|
+
/** Infers the transient update payload for an operation descriptor. */
|
|
258
|
+
export type OperationUpdateOf<TA extends RuntimeApi, O extends OperationsOf<TA>> = TA["operations"][O] extends {
|
|
259
|
+
update?: infer TUpdate;
|
|
260
|
+
} ? TUpdate extends undefined ? unknown : InferSchemaType<NonNullable<TUpdate>> : unknown;
|
|
261
|
+
export type OperationOutputOf<TA extends RuntimeApi, O extends OperationsOf<TA>> = TA["operations"][O] extends {
|
|
262
|
+
output?: infer TOutput;
|
|
263
|
+
} ? TOutput extends undefined ? unknown : InferSchemaType<NonNullable<TOutput>> : unknown;
|
|
264
|
+
export type OperationRuntimeHandle<TProgress, TOutput, TError extends BaseError, TUpdate = unknown> = {
|
|
265
|
+
id: string;
|
|
266
|
+
started(): AsyncResult<RuntimeOperationSnapshot, BaseError>;
|
|
267
|
+
progress(value: TProgress): AsyncResult<RuntimeOperationSnapshot, BaseError>;
|
|
268
|
+
/** Emits a transient update without changing the persisted snapshot. */
|
|
269
|
+
emitUpdate(value: TUpdate): AsyncResult<void, BaseError>;
|
|
270
|
+
complete(value: TOutput): AsyncResult<RuntimeOperationSnapshot, BaseError>;
|
|
271
|
+
fail(error: TError): AsyncResult<RuntimeOperationSnapshot, BaseError>;
|
|
272
|
+
cancel(): AsyncResult<RuntimeOperationSnapshot, BaseError>;
|
|
273
|
+
attach(job: {
|
|
274
|
+
wait(): AsyncResult<unknown, BaseError>;
|
|
275
|
+
}): AsyncResult<RuntimeOperationSnapshot, BaseError>;
|
|
276
|
+
signals(): AsyncIterable<RuntimeOperationSignal>;
|
|
277
|
+
nextSignal(name?: string): AsyncResult<RuntimeOperationSignal, BaseError>;
|
|
278
|
+
/** Durably acknowledges a signal after its side effects have been accepted. */
|
|
279
|
+
acknowledgeSignal(sequence: number): AsyncResult<void, BaseError>;
|
|
280
|
+
defer(): OperationDeferred;
|
|
281
|
+
};
|
|
282
|
+
export type OperationDeferred = {
|
|
283
|
+
kind: "deferred";
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* Returns true when a handler result explicitly leaves operation completion to
|
|
287
|
+
* an external control path.
|
|
288
|
+
*/
|
|
289
|
+
export declare function isOperationDeferred(value: unknown): value is OperationDeferred;
|
|
290
|
+
export type AcceptedOperation<TProgress, TOutput, TError extends BaseError, TUpdate = unknown> = OperationRuntimeHandle<TProgress, TOutput, TError, TUpdate> & {
|
|
291
|
+
ref: OperationRefData;
|
|
292
|
+
snapshot: RuntimeOperationSnapshot & {
|
|
293
|
+
progress?: TProgress;
|
|
294
|
+
output?: TOutput;
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
export type OperationTransferHandle = {
|
|
298
|
+
updates(): AsyncIterable<RuntimeOperationTransferProgress>;
|
|
299
|
+
completed(): AsyncResult<FileInfo, TransferError>;
|
|
300
|
+
};
|
|
301
|
+
/** Decoded current State value and its opaque storage revision. */
|
|
302
|
+
export type StateValue<T> = Readonly<{
|
|
303
|
+
value: T;
|
|
304
|
+
revision: string;
|
|
305
|
+
createdAt: string;
|
|
306
|
+
updatedAt: string;
|
|
307
|
+
}>;
|
|
308
|
+
/** State CAS failure with the authoritative current value, when present. */
|
|
309
|
+
export declare class StateConflictError<T> extends BaseError {
|
|
310
|
+
readonly name: "StateConflictError";
|
|
311
|
+
readonly current?: StateValue<T>;
|
|
312
|
+
constructor(current?: StateValue<T>);
|
|
313
|
+
toSerializable(): {
|
|
314
|
+
context?: Record<string, unknown> | undefined;
|
|
315
|
+
traceId?: string | undefined;
|
|
316
|
+
type: string;
|
|
317
|
+
message: string;
|
|
318
|
+
id: string;
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
/** Raised when an optional participant resource is not installed. */
|
|
322
|
+
export declare class ResourceUnavailableError extends BaseError {
|
|
323
|
+
readonly kind: string;
|
|
324
|
+
readonly resourceName: string;
|
|
325
|
+
readonly name: "ResourceUnavailableError";
|
|
326
|
+
/** Construct an unavailable-resource failure. */
|
|
327
|
+
constructor(kind: string, resourceName: string);
|
|
328
|
+
toSerializable(): {
|
|
329
|
+
context?: Record<string, unknown> | undefined;
|
|
330
|
+
traceId?: string | undefined;
|
|
331
|
+
type: string;
|
|
332
|
+
message: string;
|
|
333
|
+
id: string;
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
/** Typed single-value State handle. */
|
|
337
|
+
export type ValueStateStoreClient<TValue> = StateHandle<TValue>;
|
|
338
|
+
export type StateFacade<TState extends RuntimeStateStores> = {
|
|
339
|
+
[K in keyof TState]: ValueStateStoreClient<TState[K]["value"]>;
|
|
340
|
+
};
|
|
341
|
+
export type OperationHandlerContext<TInput, TProgress, TOutput, TTransfer, TError extends BaseError, TUpdate = unknown> = {
|
|
342
|
+
input: TInput;
|
|
343
|
+
op: OperationRuntimeHandle<TProgress, TOutput, TError, TUpdate>;
|
|
344
|
+
caller: SessionCaller;
|
|
345
|
+
/** Aborted when cancellation is committed or this executor loses ownership. */
|
|
346
|
+
signal: AbortSignal;
|
|
347
|
+
/** Whether this handler invocation reclaimed an expired executor lease. */
|
|
348
|
+
resuming: boolean;
|
|
349
|
+
/** Last durably persisted progress available to a resumed handler. */
|
|
350
|
+
progress?: TProgress;
|
|
351
|
+
} & (TTransfer extends undefined ? {} : {
|
|
352
|
+
transfer: TTransfer;
|
|
353
|
+
});
|
|
354
|
+
export type OperationRegistration<TInput, TProgress, TOutput, TTransfer, TError extends BaseError, TUpdate = unknown> = {
|
|
355
|
+
/**
|
|
356
|
+
* Loads an existing operation by id and returns a service-side control handle.
|
|
357
|
+
* The operation must belong to this service and registration name.
|
|
358
|
+
*/
|
|
359
|
+
control(operationId: string): AsyncResult<OperationRuntimeHandle<TProgress, TOutput, TError, TUpdate>, BaseError>;
|
|
360
|
+
handle(handler: (context: OperationHandlerContext<TInput, TProgress, TOutput, TTransfer, TError, TUpdate>) => unknown | Promise<unknown>): Promise<void>;
|
|
361
|
+
};
|
|
362
|
+
export type OperationTransferContextOf<TA extends RuntimeApi, O extends OperationsOf<TA>> = TA["operations"][O] extends {
|
|
363
|
+
transfer: infer TTransfer;
|
|
364
|
+
} ? TTransfer extends undefined ? undefined : OperationTransferHandle : undefined;
|
|
365
|
+
export type OperationSurface<TA extends RuntimeApi, TMode extends TrellisMode, O extends OperationsOf<TA>> = TMode extends "service" ? OperationRegistration<OperationInputOf<TA, O>, OperationProgressOf<TA, O>, OperationOutputOf<TA, O>, OperationTransferContextOf<TA, O>, OperationHandlerErrorOf<TA, O>, OperationUpdateOf<TA, O>> : OperationInvoker<TA["operations"][O] & RuntimeOperationDesc>;
|
|
366
|
+
export declare function isResultLike(value: unknown): value is Result<unknown, BaseError>;
|
|
367
|
+
type SerializableRuntimeError = {
|
|
368
|
+
id?: string;
|
|
369
|
+
type: string;
|
|
370
|
+
message: string;
|
|
371
|
+
context?: Record<string, unknown>;
|
|
372
|
+
traceId?: string;
|
|
373
|
+
} & Record<string, unknown>;
|
|
374
|
+
export type HandlerErrorAnnotationContext = {
|
|
375
|
+
method?: string;
|
|
376
|
+
event?: string;
|
|
377
|
+
feed?: string;
|
|
378
|
+
operation?: string;
|
|
379
|
+
jobType?: string;
|
|
380
|
+
requestId?: string;
|
|
381
|
+
service?: string;
|
|
382
|
+
contractId?: string;
|
|
383
|
+
contractDigest?: string;
|
|
384
|
+
traceId?: string;
|
|
385
|
+
};
|
|
386
|
+
export declare function annotateHandlerBoundaryError(cause: unknown, context: HandlerErrorAnnotationContext): BaseError;
|
|
387
|
+
export type RuntimeOperationDesc = {
|
|
388
|
+
subject: string;
|
|
389
|
+
input: unknown;
|
|
390
|
+
revision: number;
|
|
391
|
+
progress?: unknown;
|
|
392
|
+
update?: unknown;
|
|
393
|
+
output?: unknown;
|
|
394
|
+
signals?: Record<string, {
|
|
395
|
+
input: unknown;
|
|
396
|
+
}>;
|
|
397
|
+
cancelCapabilities?: readonly string[];
|
|
398
|
+
controlCapabilities?: readonly string[];
|
|
399
|
+
transfer?: {
|
|
400
|
+
store: string;
|
|
401
|
+
key: `/${string}`;
|
|
402
|
+
contentType?: `/${string}`;
|
|
403
|
+
metadata?: `/${string}`;
|
|
404
|
+
expiresInMs?: number;
|
|
405
|
+
maxBytes?: number;
|
|
406
|
+
};
|
|
407
|
+
cancel?: boolean;
|
|
408
|
+
};
|
|
409
|
+
export type RuntimeOperationSignal = {
|
|
410
|
+
operationId: string;
|
|
411
|
+
sequence: number;
|
|
412
|
+
requestId: string;
|
|
413
|
+
signal: string;
|
|
414
|
+
input?: JsonValue;
|
|
415
|
+
acceptedAt: string;
|
|
416
|
+
acknowledged: boolean;
|
|
417
|
+
};
|
|
418
|
+
export type RuntimeOperationSignalWaiter = (result: Result<RuntimeOperationSignal, BaseError>) => void;
|
|
419
|
+
export type RuntimeOperationTransferProgress = {
|
|
420
|
+
chunkIndex: number;
|
|
421
|
+
chunkBytes: number;
|
|
422
|
+
transferredBytes: number;
|
|
423
|
+
};
|
|
424
|
+
export type RuntimeOperationState = "pending" | "running" | "completed" | "failed" | "cancelled";
|
|
425
|
+
export type RuntimeOperationSnapshot = {
|
|
426
|
+
id: string;
|
|
427
|
+
service: string;
|
|
428
|
+
operation: string;
|
|
429
|
+
revision: number;
|
|
430
|
+
state: RuntimeOperationState;
|
|
431
|
+
createdAt: string;
|
|
432
|
+
updatedAt: string;
|
|
433
|
+
completedAt?: string;
|
|
434
|
+
progress?: unknown;
|
|
435
|
+
transfer?: RuntimeOperationTransferProgress;
|
|
436
|
+
output?: unknown;
|
|
437
|
+
error?: SerializableRuntimeError;
|
|
438
|
+
};
|
|
439
|
+
export type RuntimeOperationRecord = {
|
|
440
|
+
id: string;
|
|
441
|
+
service: string;
|
|
442
|
+
operation: string;
|
|
443
|
+
callerSessionKey: string;
|
|
444
|
+
invocationDigest: string;
|
|
445
|
+
caller: VerifiedCaller;
|
|
446
|
+
creatorPrincipalId: string;
|
|
447
|
+
creatorParticipantId: string;
|
|
448
|
+
apiId: string;
|
|
449
|
+
input: unknown;
|
|
450
|
+
revision: number;
|
|
451
|
+
ownerInstanceId: string;
|
|
452
|
+
ownerConnectionId: string;
|
|
453
|
+
ownerEpoch: number;
|
|
454
|
+
leaseExpiresAt: string;
|
|
455
|
+
cancelRequestedAt?: string;
|
|
456
|
+
transferGrant?: SendTransferGrant;
|
|
457
|
+
snapshot: RuntimeOperationSnapshot;
|
|
458
|
+
sequence: number;
|
|
459
|
+
signalSequence: number;
|
|
460
|
+
signals: RuntimeOperationSignal[];
|
|
461
|
+
terminal: boolean;
|
|
462
|
+
watchers: Map<string, {
|
|
463
|
+
includeUpdates: boolean;
|
|
464
|
+
}>;
|
|
465
|
+
frameQueue: Promise<void>;
|
|
466
|
+
signalWaiters: Set<RuntimeOperationSignalWaiter>;
|
|
467
|
+
cancellation: AbortController;
|
|
468
|
+
reclaimed?: boolean;
|
|
469
|
+
};
|
|
470
|
+
export type DurableOperationRecord = {
|
|
471
|
+
invocationId: string;
|
|
472
|
+
callerSessionKey: string;
|
|
473
|
+
invocationDigest: string;
|
|
474
|
+
caller: VerifiedCaller;
|
|
475
|
+
creatorPrincipalId: string;
|
|
476
|
+
creatorParticipantId: string;
|
|
477
|
+
apiId: string;
|
|
478
|
+
operation: string;
|
|
479
|
+
input: unknown;
|
|
480
|
+
revision: number;
|
|
481
|
+
ownerInstanceId: string;
|
|
482
|
+
ownerConnectionId: string;
|
|
483
|
+
ownerEpoch: number;
|
|
484
|
+
leaseExpiresAt: string;
|
|
485
|
+
cancelRequestedAt?: string;
|
|
486
|
+
transferGrant?: SendTransferGrant;
|
|
487
|
+
sequence: number;
|
|
488
|
+
signalSequence: number;
|
|
489
|
+
signals: RuntimeOperationSignal[];
|
|
490
|
+
snapshot: RuntimeOperationSnapshot;
|
|
491
|
+
};
|
|
492
|
+
export declare const DurableOperationRecordSchema: Type.TObject<{
|
|
493
|
+
invocationId: Type.TString;
|
|
494
|
+
callerSessionKey: Type.TString;
|
|
495
|
+
apiId: Type.TString;
|
|
496
|
+
operation: Type.TString;
|
|
497
|
+
input: Type.TAny;
|
|
498
|
+
ownerInstanceId: Type.TString;
|
|
499
|
+
ownerConnectionId: Type.TString;
|
|
500
|
+
ownerEpoch: Type.TNumber;
|
|
501
|
+
leaseExpiresAt: Type.TString;
|
|
502
|
+
cancelRequestedAt: Type.TOptional<Type.TString>;
|
|
503
|
+
transferGrant: Type.TOptional<Type.TAny>;
|
|
504
|
+
sequence: Type.TNumber;
|
|
505
|
+
signalSequence: Type.TNumber;
|
|
506
|
+
signals: Type.TArray<Type.TObject<{
|
|
507
|
+
operationId: Type.TString;
|
|
508
|
+
sequence: Type.TNumber;
|
|
509
|
+
requestId: Type.TString;
|
|
510
|
+
signal: Type.TString;
|
|
511
|
+
input: Type.TOptional<Type.TAny>;
|
|
512
|
+
acceptedAt: Type.TString;
|
|
513
|
+
acknowledged: Type.TBoolean;
|
|
514
|
+
}>>;
|
|
515
|
+
snapshot: Type.TObject<{
|
|
516
|
+
id: Type.TString;
|
|
517
|
+
service: Type.TString;
|
|
518
|
+
operation: Type.TString;
|
|
519
|
+
revision: Type.TNumber;
|
|
520
|
+
state: Type.TUnion<[Type.TLiteral<"pending">, Type.TLiteral<"running">, Type.TLiteral<"completed">, Type.TLiteral<"failed">, Type.TLiteral<"cancelled">]>;
|
|
521
|
+
createdAt: Type.TString;
|
|
522
|
+
updatedAt: Type.TString;
|
|
523
|
+
completedAt: Type.TOptional<Type.TString>;
|
|
524
|
+
progress: Type.TOptional<Type.TAny>;
|
|
525
|
+
transfer: Type.TOptional<Type.TObject<{
|
|
526
|
+
chunkIndex: Type.TNumber;
|
|
527
|
+
chunkBytes: Type.TNumber;
|
|
528
|
+
transferredBytes: Type.TNumber;
|
|
529
|
+
}>>;
|
|
530
|
+
output: Type.TOptional<Type.TAny>;
|
|
531
|
+
error: Type.TOptional<Type.TObject<{
|
|
532
|
+
id: Type.TOptional<Type.TString>;
|
|
533
|
+
type: Type.TString;
|
|
534
|
+
message: Type.TString;
|
|
535
|
+
context: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
|
|
536
|
+
traceId: Type.TOptional<Type.TString>;
|
|
537
|
+
}>>;
|
|
538
|
+
}>;
|
|
539
|
+
}>;
|
|
540
|
+
export type RuntimeOperationAcceptedEnvelope = {
|
|
541
|
+
kind: "accepted";
|
|
542
|
+
ref: OperationRefData;
|
|
543
|
+
snapshot: RuntimeOperationSnapshot;
|
|
544
|
+
transfer?: SendTransferGrant;
|
|
545
|
+
};
|
|
546
|
+
export type RuntimeOperationControlRequest = {
|
|
547
|
+
action: "get" | "cancel";
|
|
548
|
+
operationId: string;
|
|
549
|
+
} | {
|
|
550
|
+
action: "watch";
|
|
551
|
+
operationId: string;
|
|
552
|
+
includeUpdates?: boolean;
|
|
553
|
+
} | {
|
|
554
|
+
action: "signal";
|
|
555
|
+
operationId: string;
|
|
556
|
+
signal: string;
|
|
557
|
+
input?: JsonValue;
|
|
558
|
+
};
|
|
559
|
+
export type RuntimeOperationController = {
|
|
560
|
+
get(operationId: string): AsyncResult<RuntimeOperationSnapshot, BaseError>;
|
|
561
|
+
started(operationId: string): AsyncResult<RuntimeOperationSnapshot, BaseError>;
|
|
562
|
+
progress(operationId: string, progress: unknown): AsyncResult<RuntimeOperationSnapshot, BaseError>;
|
|
563
|
+
complete(operationId: string, output: unknown): AsyncResult<RuntimeOperationSnapshot, BaseError>;
|
|
564
|
+
fail(operationId: string, error: BaseError): AsyncResult<RuntimeOperationSnapshot, BaseError>;
|
|
565
|
+
cancel(operationId: string): AsyncResult<RuntimeOperationSnapshot, BaseError>;
|
|
566
|
+
signals(operationId: string): AsyncIterable<RuntimeOperationSignal>;
|
|
567
|
+
nextSignal(operationId: string, name?: string): AsyncResult<RuntimeOperationSignal, BaseError>;
|
|
568
|
+
};
|
|
569
|
+
export declare function buildRuntimeOperationSnapshot(runtime: Pick<RuntimeOperationRecord, "id" | "service" | "operation" | "snapshot">, state: RuntimeOperationState, patch?: Partial<RuntimeOperationSnapshot>): RuntimeOperationSnapshot;
|
|
570
|
+
export declare function isTerminalRuntimeOperationSnapshot(value: unknown): value is RuntimeOperationSnapshot;
|
|
571
|
+
type NoResponderRetryOpts = {
|
|
572
|
+
maxAttempts?: number;
|
|
573
|
+
baseDelayMs?: number;
|
|
574
|
+
};
|
|
575
|
+
export type TrellisOpts<TA extends RuntimeApi> = {
|
|
576
|
+
log?: LoggerLike;
|
|
577
|
+
timeout?: number;
|
|
578
|
+
stream?: string;
|
|
579
|
+
noResponderRetry?: NoResponderRetryOpts;
|
|
580
|
+
api?: TA;
|
|
581
|
+
state?: RuntimeStateStores;
|
|
582
|
+
stateMigrations?: Readonly<Record<string, ResourceMigrations<unknown> | undefined>>;
|
|
583
|
+
resourceGeneration?: () => number;
|
|
584
|
+
resourceAvailability?: (name: string) => boolean;
|
|
585
|
+
connection?: TrellisConnection;
|
|
586
|
+
onSessionNotFound?: () => MaybePromise<void>;
|
|
587
|
+
contractId?: string;
|
|
588
|
+
contractDigest?: string;
|
|
589
|
+
};
|
|
590
|
+
export type RequestOpts = {
|
|
591
|
+
timeout?: number;
|
|
592
|
+
signal?: AbortSignal;
|
|
593
|
+
};
|
|
594
|
+
export type EventOpts = {
|
|
595
|
+
mode?: "durable" | "ephemeral";
|
|
596
|
+
/**
|
|
597
|
+
* Contract event consumer group to use for durable service listeners when an
|
|
598
|
+
* event is declared in more than one group.
|
|
599
|
+
*/
|
|
600
|
+
group?: string;
|
|
601
|
+
signal?: AbortSignal;
|
|
602
|
+
};
|
|
603
|
+
/** Context provided to event listener callbacks. */
|
|
604
|
+
export type EventListenerContext = {
|
|
605
|
+
/** Stable event id from the Trellis event header. */
|
|
606
|
+
id: string;
|
|
607
|
+
/** Event creation time from the Trellis event header. */
|
|
608
|
+
time: Date;
|
|
609
|
+
/** NATS subject that delivered the event. */
|
|
610
|
+
subject: string;
|
|
611
|
+
/** Runtime listener mode that delivered the event. */
|
|
612
|
+
mode: "durable" | "ephemeral";
|
|
613
|
+
/** Durable event consumer group, when delivered through a group. */
|
|
614
|
+
group?: string;
|
|
615
|
+
/** JetStream sequence number, when available. */
|
|
616
|
+
sequence?: number;
|
|
617
|
+
};
|
|
618
|
+
export type FeedSubscribeOpts = {
|
|
619
|
+
signal?: AbortSignal;
|
|
620
|
+
};
|
|
621
|
+
export type FeedSubscription<TEvent> = AsyncIterable<TEvent>;
|
|
622
|
+
export type FeedInputBuilder<TInput, TEvent> = {
|
|
623
|
+
input(input: TInput): {
|
|
624
|
+
subscribe(opts?: FeedSubscribeOpts): AsyncResult<FeedSubscription<TEvent>, BaseError>;
|
|
625
|
+
};
|
|
626
|
+
};
|
|
627
|
+
export type FeedHandlerContext<TInput, TEvent> = {
|
|
628
|
+
input: TInput;
|
|
629
|
+
caller: SessionCaller;
|
|
630
|
+
signal: AbortSignal;
|
|
631
|
+
emit(event: TEvent): AsyncResult<void, SchemaValidationError | ValidationError | UnexpectedError>;
|
|
632
|
+
};
|
|
633
|
+
export type FeedRegistration<TInput, TEvent> = {
|
|
634
|
+
handle(handler: (context: FeedHandlerContext<TInput, TEvent>) => unknown | Promise<unknown>): Promise<void>;
|
|
635
|
+
};
|
|
636
|
+
type PascalSurfaceName<T extends string> = T extends `${infer Head}.${infer Tail}` ? `${Capitalize<Head>}${PascalSurfaceName<Tail>}` : Capitalize<T>;
|
|
637
|
+
type LowerCamelSurfaceName<T extends string> = Uncapitalize<PascalSurfaceName<T>>;
|
|
638
|
+
type SurfaceGroupName<T extends string> = T extends `${infer Head}.${string}` ? LowerCamelSurfaceName<Head> : LowerCamelSurfaceName<T>;
|
|
639
|
+
type SurfaceLeafName<T extends string> = T extends `${string}.${infer Tail}` ? LowerCamelSurfaceName<Tail> : LowerCamelSurfaceName<T>;
|
|
640
|
+
type SurfaceKeysForGroup<TKeys extends string, TGroup extends string> = TKeys extends string ? SurfaceGroupName<TKeys> extends TGroup ? TKeys : never : never;
|
|
641
|
+
export type ActiveRpcFacade<TA extends RuntimeApi = RuntimeApi> = {
|
|
642
|
+
readonly [TGroup in SurfaceGroupName<MethodsOf<TA>>]: {
|
|
643
|
+
readonly [M in SurfaceKeysForGroup<MethodsOf<TA>, TGroup> as SurfaceLeafName<M>]: (input: RpcInputOf<TA, M>, opts?: RequestOpts) => AsyncResult<RpcOutputOf<TA, M>, BaseError>;
|
|
644
|
+
};
|
|
645
|
+
};
|
|
646
|
+
export type ActiveEventFacade<TA extends RuntimeApi = RuntimeApi> = {
|
|
647
|
+
readonly [TGroup in SurfaceGroupName<EventsOf<TA>>]: {
|
|
648
|
+
readonly [E in SurfaceKeysForGroup<EventsOf<TA>, TGroup> as SurfaceLeafName<E>]: {
|
|
649
|
+
prepare(event: EventPayloadOf<TA, E>): Result<PreparedTrellisEvent<EventPayloadOf<TA, E>>, ValidationError | UnexpectedError>;
|
|
650
|
+
publish(event: EventPayloadOf<TA, E>): AsyncResult<void, ValidationError | UnexpectedError>;
|
|
651
|
+
listen(handler: EventCallback<EventOf<TA, E>>, subjectData?: Record<string, unknown>, opts?: EventOpts): AsyncResult<void, ValidationError | UnexpectedError>;
|
|
652
|
+
};
|
|
653
|
+
};
|
|
654
|
+
};
|
|
655
|
+
export type ActiveEventPublishFacade<TA extends RuntimeApi = RuntimeApi> = {
|
|
656
|
+
readonly [TGroup in SurfaceGroupName<EventsOf<TA>>]: {
|
|
657
|
+
readonly [E in SurfaceKeysForGroup<EventsOf<TA>, TGroup> as SurfaceLeafName<E>]: {
|
|
658
|
+
prepare(event: EventPayloadOf<TA, E>): Result<PreparedTrellisEvent<EventPayloadOf<TA, E>>, ValidationError | UnexpectedError>;
|
|
659
|
+
publish(event: EventPayloadOf<TA, E>): AsyncResult<void, ValidationError | UnexpectedError>;
|
|
660
|
+
};
|
|
661
|
+
};
|
|
662
|
+
};
|
|
663
|
+
export type ActiveFeedFacade<TA extends RuntimeApi = RuntimeApi> = {
|
|
664
|
+
readonly [TGroup in SurfaceGroupName<FeedsOf<TA>>]: {
|
|
665
|
+
readonly [F in SurfaceKeysForGroup<FeedsOf<TA>, TGroup> as SurfaceLeafName<F>]: (input: FeedInputOf<TA, F>, opts?: FeedSubscribeOpts) => AsyncResult<FeedSubscription<FeedEventOf<TA, F>>, BaseError>;
|
|
666
|
+
};
|
|
667
|
+
};
|
|
668
|
+
export type ActiveOperationFacade<TA extends RuntimeApi = RuntimeApi> = {
|
|
669
|
+
readonly [TGroup in SurfaceGroupName<OperationsOf<TA>>]: {
|
|
670
|
+
readonly [O in SurfaceKeysForGroup<OperationsOf<TA>, TGroup> as SurfaceLeafName<O>]: OperationInvoker<TA["operations"][O] & RuntimeOperationDesc>;
|
|
671
|
+
};
|
|
672
|
+
};
|
|
673
|
+
export type ActiveRpcHandleFacade<TA extends RuntimeApi = RuntimeApi, TRequests = RpcRequestShapes<TA>> = {
|
|
674
|
+
readonly [TGroup in SurfaceGroupName<MethodsOf<TA>>]: {
|
|
675
|
+
readonly [M in SurfaceKeysForGroup<MethodsOf<TA>, TGroup> as SurfaceLeafName<M>]: (handler: HandlerFn<TA, M, TA, HandlerTrellis<TA, TRequests>>) => Promise<void>;
|
|
676
|
+
};
|
|
677
|
+
};
|
|
678
|
+
export type FeedSurface<TA extends RuntimeApi, TMode extends TrellisMode, F extends FeedsOf<TA>> = TMode extends "service" ? FeedRegistration<FeedInputOf<TA, F>, FeedEventOf<TA, F>> : FeedInputBuilder<FeedInputOf<TA, F>, FeedEventOf<TA, F>>;
|
|
679
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
680
|
+
type EventCallback<TMessage> = {
|
|
681
|
+
bivarianceHack(message: TMessage, context: EventListenerContext): MaybeAsync<void, BaseError>;
|
|
682
|
+
}["bivarianceHack"];
|
|
683
|
+
export type RpcHandlerContext = {
|
|
684
|
+
caller: SessionCaller;
|
|
685
|
+
sessionKey: string;
|
|
686
|
+
inboxPrefix: string;
|
|
687
|
+
/** Exact permission verified for this request. */
|
|
688
|
+
permission: DescriptorPermissionAtom;
|
|
689
|
+
/** Capabilities required by this request surface. */
|
|
690
|
+
requiredCapabilities: readonly string[];
|
|
691
|
+
requestId?: string;
|
|
692
|
+
traceId?: string;
|
|
693
|
+
/** Schedules work after the successful RPC response has reached NATS. */
|
|
694
|
+
afterReply(task: () => MaybePromise<void>): void;
|
|
695
|
+
};
|
|
696
|
+
export type HandlerTrellis<TA extends RuntimeApi, TRequests = RpcRequestShapes<TA>> = {
|
|
697
|
+
readonly rpc: ActiveRpcFacade<TA>;
|
|
698
|
+
readonly event: ActiveEventPublishFacade<TA>;
|
|
699
|
+
readonly feed: ActiveFeedFacade<TA>;
|
|
700
|
+
readonly operation: ActiveOperationFacade<TA>;
|
|
701
|
+
request<const M extends RequestMethodOf<TRequests>>(method: M, input: RequestInputOf<TRequests, M>, opts?: RequestOpts): AsyncResult<RequestOutputOf<TRequests, M>, BaseError>;
|
|
702
|
+
publish(event: string, data: Record<string, unknown>): AsyncResult<void, ValidationError | UnexpectedError>;
|
|
703
|
+
prepare(event: string, data: Record<string, unknown>): Result<PreparedTrellisEvent, ValidationError | UnexpectedError>;
|
|
704
|
+
publishPrepared(event: PreparedTrellisEvent): AsyncResult<void, UnexpectedError>;
|
|
705
|
+
/** Stops durable event listener loops owned by this handler runtime. */
|
|
706
|
+
stopEventListeners(): void;
|
|
707
|
+
};
|
|
708
|
+
export type HandlerKvFacade<TKv extends ParticipantKvMetadata> = {
|
|
709
|
+
[K in keyof TKv]: TKv[K]["required"] extends false ? TypedKV<TKv[K]["value"]> | undefined : TypedKV<TKv[K]["value"]>;
|
|
710
|
+
};
|
|
711
|
+
export type HandlerStoreHandle = {
|
|
712
|
+
open(): AsyncResult<TypedStore, StoreError>;
|
|
713
|
+
waitFor(key: string, options?: StoreWaitOptions): AsyncResult<TypedStoreEntry, StoreError>;
|
|
714
|
+
};
|
|
715
|
+
export type HandlerJobQueue<TPayload, TResult, TTrellis, TUpdate = never> = {
|
|
716
|
+
create(payload: TPayload): AsyncResult<JobRef<TPayload, TResult, TUpdate>, BaseError>;
|
|
717
|
+
updates(jobId: string, options?: JobUpdatesOptions): AsyncResult<JobUpdateSubscription<TUpdate>, BaseError>;
|
|
718
|
+
handle(handler: (args: {
|
|
719
|
+
job: ActiveJob<TPayload, TResult, TUpdate>;
|
|
720
|
+
client: TTrellis;
|
|
721
|
+
}) => Promise<Result<TResult, BaseError>>): void;
|
|
722
|
+
};
|
|
723
|
+
export type HandlerJobsFacade<TJobs extends Record<string, JobTypeMetadata>, TTrellis> = {
|
|
724
|
+
[K in keyof TJobs]: HandlerJobQueue<TJobs[K]["payload"], TJobs[K]["result"], TTrellis, TJobs[K]["update"]>;
|
|
725
|
+
};
|
|
726
|
+
export type HandlerTrellisForContract<TContract> = HandlerTrellis<TrellisApiFor<TContract>> & {
|
|
727
|
+
kv: HandlerKvFacade<ContractKvFor<TContract>>;
|
|
728
|
+
store: Record<string, HandlerStoreHandle>;
|
|
729
|
+
jobs: HandlerJobsFacade<ContractJobsFor<TContract>, HandlerTrellisForContract<TContract>>;
|
|
730
|
+
};
|
|
731
|
+
export type HandlerFn<TMountApi extends RuntimeApi, M extends MethodsOf<TMountApi>, TOutboundApi extends RuntimeApi = TMountApi, TTrellis = HandlerTrellis<TOutboundApi>> = (args: {
|
|
732
|
+
input: MethodInputOf<TMountApi, M>;
|
|
733
|
+
context: RpcHandlerContext;
|
|
734
|
+
client: TTrellis;
|
|
735
|
+
}) => MaybePromise<Result<MethodOutputOf<TMountApi, M>, HandlerErrorOf<TMountApi, M>>>;
|
|
736
|
+
/** Transport calls consumed by a typed State handle. */
|
|
737
|
+
export type StateResourceCalls = Readonly<{
|
|
738
|
+
get(input: {
|
|
739
|
+
resourceName: string;
|
|
740
|
+
}): PromiseLike<Result<StateGetResponse, BaseError>>;
|
|
741
|
+
set(input: {
|
|
742
|
+
resourceName: string;
|
|
743
|
+
representationVersion: bigint;
|
|
744
|
+
value: Uint8Array;
|
|
745
|
+
mode: "create" | "set" | "replace";
|
|
746
|
+
revision?: string;
|
|
747
|
+
}): PromiseLike<Result<StateSetResponse, BaseError>>;
|
|
748
|
+
delete(input: {
|
|
749
|
+
resourceName: string;
|
|
750
|
+
revision?: string;
|
|
751
|
+
}): PromiseLike<Result<StateDeleteResponse, BaseError>>;
|
|
752
|
+
}>;
|
|
753
|
+
/** Typed handle for one generated single-value State resource. */
|
|
754
|
+
export declare class StateHandle<T> {
|
|
755
|
+
#private;
|
|
756
|
+
/** Construct a handle from generated metadata and settled State transport calls. */
|
|
757
|
+
constructor(args: {
|
|
758
|
+
resourceName: string;
|
|
759
|
+
definition: KvRepresentation<T>;
|
|
760
|
+
migrations?: ResourceMigrations<T>;
|
|
761
|
+
isCurrent?: () => boolean;
|
|
762
|
+
isAvailable?: () => boolean;
|
|
763
|
+
calls: StateResourceCalls;
|
|
764
|
+
});
|
|
765
|
+
/** Read the current value, migrating only in memory when required. */
|
|
766
|
+
get(): AsyncResult<StateValue<T> | undefined, BaseError>;
|
|
767
|
+
/** Create the value only when no live value exists. */
|
|
768
|
+
create(value: T): AsyncResult<StateValue<T>, BaseError>;
|
|
769
|
+
/** Unconditionally replace the current value. */
|
|
770
|
+
set(value: T): AsyncResult<StateValue<T>, BaseError>;
|
|
771
|
+
/** Replace the value only while `revision` remains current. */
|
|
772
|
+
replace(revision: string, value: T): AsyncResult<StateValue<T>, BaseError>;
|
|
773
|
+
/** Delete unconditionally or only while `revision` remains current. */
|
|
774
|
+
delete(revision?: string): AsyncResult<boolean, BaseError>;
|
|
775
|
+
}
|
|
776
|
+
export type RpcRequestErrorOf<TA extends RuntimeApi, M extends RpcMethodNameOf<TA>> = RequestErrorOf<TA, M>;
|
|
777
|
+
export type RpcHandlerErrorOf<TA extends RuntimeApi, M extends RpcMethodNameOf<TA>> = HandlerErrorOf<TA, M>;
|
|
778
|
+
export type EventName<TContract> = EventsOf<OwnedApiFor<TContract>>;
|
|
779
|
+
export type EventType<TContract, E extends EventName<TContract>> = EventOf<OwnedApiFor<TContract>, E>;
|
|
780
|
+
export type EventPayload<TContract, E extends EventName<TContract>> = EventPayloadOf<OwnedApiFor<TContract>, E>;
|
|
781
|
+
export declare class Trellis<TA extends RuntimeApi = RuntimeApi, TMode extends TrellisMode = "client", TState extends RuntimeStateStores = {}, TRequests = RpcRequestShapes<TA>> {
|
|
782
|
+
#private;
|
|
783
|
+
readonly name: string;
|
|
784
|
+
readonly timeout: number;
|
|
785
|
+
readonly stream: string;
|
|
786
|
+
readonly state: StateFacade<TState>;
|
|
787
|
+
readonly rpc: ActiveRpcFacade<TA>;
|
|
788
|
+
readonly event: ActiveEventFacade<TA>;
|
|
789
|
+
readonly feed: ActiveFeedFacade<TA>;
|
|
790
|
+
readonly operation: ActiveOperationFacade<TA>;
|
|
791
|
+
readonly handle: {
|
|
792
|
+
readonly rpc: ActiveRpcHandleFacade<TA, TRequests>;
|
|
793
|
+
};
|
|
794
|
+
/** Framework-neutral lifecycle handle for this Trellis runtime connection. */
|
|
795
|
+
readonly connection: TrellisConnection;
|
|
796
|
+
readonly contractId?: string;
|
|
797
|
+
readonly contractDigest?: string;
|
|
798
|
+
readonly api: TA;
|
|
799
|
+
constructor(name: string, // Must be unique for a service
|
|
800
|
+
nats: NatsConnection, auth: TrellisAuth, opts?: TrellisOpts<TA>, inboxPrefix?: string);
|
|
801
|
+
protected get nats(): NatsConnection;
|
|
802
|
+
protected get js(): JetStreamClient;
|
|
803
|
+
protected get auth(): TrellisAuth;
|
|
804
|
+
operationStoreHandle(): Promise<TypedKV<DurableOperationRecord>>;
|
|
805
|
+
protected setOperationDeploymentId(id: string): void;
|
|
806
|
+
protected setFeedOwnerId(id: string): void;
|
|
807
|
+
loadOperationRecord(operationId: string): Promise<DurableOperationRecord | null>;
|
|
808
|
+
protected listNonterminalOperationRecords(): Promise<DurableOperationRecord[]>;
|
|
809
|
+
saveOperationRecord(runtime: RuntimeOperationRecord): Promise<void>;
|
|
810
|
+
/**
|
|
811
|
+
* Makes an authenticated request to a Trellis RPC method.
|
|
812
|
+
*
|
|
813
|
+
* @template M The specific RPC method being called.
|
|
814
|
+
* @param method The name of the RPC method to call.
|
|
815
|
+
* @param input The input data for the method, conforming to its schema.
|
|
816
|
+
* @param opts Optional request-specific options.
|
|
817
|
+
* @returns An `AsyncResult` containing either the method's output or an error.
|
|
818
|
+
* @returns A `Result` object after awaiting:
|
|
819
|
+
* ok: A validated response for method M
|
|
820
|
+
* err: declared RPC errors | RemoteError | ValidationError | UnexpectedError
|
|
821
|
+
*/
|
|
822
|
+
request<const M extends RequestMethodOf<TRequests>>(method: M, input: RequestInputOf<TRequests, M>, opts?: RequestOpts): AsyncResult<RequestOutputOf<TRequests, M>, BaseError>;
|
|
823
|
+
feedHandle<F extends FeedsOf<TA>>(feed: F): FeedInputBuilder<FeedInputOf<TA, F>, FeedEventOf<TA, F>> & FeedRegistration<FeedInputOf<TA, F>, FeedEventOf<TA, F>>;
|
|
824
|
+
operationHandle<O extends OperationsOf<TA>>(operation: O, unavailable?: () => TransportError | undefined): OperationSurface<TA, TMode, O>;
|
|
825
|
+
/**
|
|
826
|
+
* Creates a helper for a short-lived Trellis transfer grant.
|
|
827
|
+
*/
|
|
828
|
+
transfer(grant: SendTransferGrant): SendTransferHandle;
|
|
829
|
+
transfer(grant: ReceiveTransferGrant): ReceiveTransferHandle;
|
|
830
|
+
mount(method: string, fn: (args: {
|
|
831
|
+
input: unknown;
|
|
832
|
+
context: RpcHandlerContext;
|
|
833
|
+
client: HandlerTrellis<TA, TRequests>;
|
|
834
|
+
}) => MaybePromise<Result<unknown, BaseError>>): Promise<void>;
|
|
835
|
+
respondWithError(msg: Msg, error: Error | BaseError): void;
|
|
836
|
+
/**
|
|
837
|
+
* Builds a stable event subject, encoded payload, and publish headers.
|
|
838
|
+
*
|
|
839
|
+
* The prepared event intentionally carries no contract id or digest so callers
|
|
840
|
+
* can persist it in a service-owned outbox without coupling storage to the
|
|
841
|
+
* publisher's current deployment metadata.
|
|
842
|
+
*/
|
|
843
|
+
prepare(event: string, data: Record<string, unknown>): Result<PreparedTrellisEvent, ValidationError | UnexpectedError>;
|
|
844
|
+
/**
|
|
845
|
+
* Publishes a previously prepared event without regenerating its id, time,
|
|
846
|
+
* subject, payload, or headers.
|
|
847
|
+
*/
|
|
848
|
+
publishPrepared(event: PreparedTrellisEvent): AsyncResult<void, UnexpectedError>;
|
|
849
|
+
publish(event: string, data: Record<string, unknown>): AsyncResult<void, ValidationError | UnexpectedError>;
|
|
850
|
+
listenEvent<E extends EventsOf<TA>>(event: E, subjectData: Record<string, unknown>, fn: EventCallback<EventOf<TA, E>>, opts?: EventOpts): AsyncResult<void, ValidationError | UnexpectedError>;
|
|
851
|
+
wait(): AsyncResult<void, BaseError>;
|
|
852
|
+
/** Stops durable event listener loops without closing the underlying transport. */
|
|
853
|
+
stopEventListeners(): void;
|
|
854
|
+
template(subject: string, data: unknown, allowWildcards?: boolean): Result<string, ValidationError>;
|
|
855
|
+
/** Creates a context-bound request proof for an exact subject, payload, and reply. */
|
|
856
|
+
protected createRequestProof(subject: string, payload: string, reply: string): Promise<{
|
|
857
|
+
proof: string;
|
|
858
|
+
iat: number;
|
|
859
|
+
requestId: string;
|
|
860
|
+
contextDigest: string;
|
|
861
|
+
}>;
|
|
862
|
+
}
|