@superdurable/dex 0.1.3 → 0.1.4
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 +55 -3
- package/dist/src/attribute-store-sync.d.ts +5 -0
- package/dist/src/attribute-store-sync.js +19 -0
- package/dist/src/attribute-store-sync.js.map +1 -0
- package/dist/src/blob-cache.d.ts +36 -0
- package/dist/src/blob-cache.js +13 -0
- package/dist/src/blob-cache.js.map +1 -1
- package/dist/src/client.d.ts +183 -4
- package/dist/src/client.js +152 -37
- package/dist/src/client.js.map +1 -1
- package/dist/src/codec.d.ts +73 -0
- package/dist/src/codec.js +23 -0
- package/dist/src/codec.js.map +1 -1
- package/dist/src/context.d.ts +80 -0
- package/dist/src/errors.d.ts +122 -6
- package/dist/src/errors.js +139 -9
- package/dist/src/errors.js.map +1 -1
- package/dist/src/flow.d.ts +36 -1
- package/dist/src/flow.js +96 -28
- package/dist/src/flow.js.map +1 -1
- package/dist/src/gen/dex.d.ts +58 -9
- package/dist/src/gen/dex.js +417 -55
- package/dist/src/gen/dex.js.map +1 -1
- package/dist/src/grpc-status.d.ts +5 -4
- package/dist/src/grpc-status.js +52 -6
- package/dist/src/grpc-status.js.map +1 -1
- package/dist/src/invocation-context.js +3 -0
- package/dist/src/invocation-context.js.map +1 -1
- package/dist/src/options.d.ts +150 -1
- package/dist/src/options.js +53 -0
- package/dist/src/options.js.map +1 -1
- package/dist/src/persistence.d.ts +103 -0
- package/dist/src/persistence.js +98 -0
- package/dist/src/persistence.js.map +1 -1
- package/dist/src/rpc.d.ts +53 -0
- package/dist/src/rpc.js +17 -0
- package/dist/src/rpc.js.map +1 -1
- package/dist/src/step.d.ts +162 -0
- package/dist/src/step.js +85 -0
- package/dist/src/step.js.map +1 -1
- package/dist/src/value-mapper.js +48 -18
- package/dist/src/value-mapper.js.map +1 -1
- package/dist/src/wait.d.ts +180 -0
- package/dist/src/wait.js +157 -0
- package/dist/src/wait.js.map +1 -1
- package/dist/src/worker-dispatcher.js +52 -26
- package/dist/src/worker-dispatcher.js.map +1 -1
- package/dist/src/worker.d.ts +30 -1
- package/dist/src/worker.js +48 -2
- package/dist/src/worker.js.map +1 -1
- package/native/linux-aarch64/dex_blob_cache_node.node +0 -0
- package/native/linux-x86_64/dex_blob_cache_node.node +0 -0
- package/native/macos-aarch64/dex_blob_cache_node.node +0 -0
- package/native/macos-x86_64/dex_blob_cache_node.node +0 -0
- package/native/windows-x86_64/dex_blob_cache_node.node +0 -0
- package/package.json +2 -1
package/dist/src/context.d.ts
CHANGED
|
@@ -1,23 +1,103 @@
|
|
|
1
1
|
import type { Attribute, AttributeMap } from "./persistence.js";
|
|
2
2
|
import type { Channel, ChannelMap } from "./wait.js";
|
|
3
3
|
import type { Codec } from "./codec.js";
|
|
4
|
+
/**
|
|
5
|
+
* Exposes execution metadata and decision-local persistence operations.
|
|
6
|
+
* Dex supplies a Context to each Step or RPC handler; do not retain it afterward.
|
|
7
|
+
*/
|
|
4
8
|
export interface Context {
|
|
9
|
+
/** Stable application Flow ID shared across runs. */
|
|
5
10
|
readonly flowId: string;
|
|
11
|
+
/** Current server-assigned run ID. */
|
|
6
12
|
readonly runId: string;
|
|
13
|
+
/** UTC timestamp at which the current Flow run started. */
|
|
7
14
|
readonly flowStartedAt: Date;
|
|
15
|
+
/** Current Step type and execution number encoded by Dex. */
|
|
8
16
|
readonly stepExecutionId: string;
|
|
17
|
+
/** Predecessor Step execution ID, or an empty string at Flow start. */
|
|
9
18
|
readonly fromStepExecutionId: string;
|
|
19
|
+
/** UTC timestamp of the first handler attempt. */
|
|
10
20
|
readonly firstAttemptAt: Date;
|
|
21
|
+
/** One-based handler retry attempt number. */
|
|
11
22
|
readonly attempt: number;
|
|
23
|
+
/**
|
|
24
|
+
* Reports whether a Timer made the current Wait ready.
|
|
25
|
+
* @param index - Optional zero-based Timer index; checks any Timer when omitted.
|
|
26
|
+
* @returns Whether the selected Timer fired.
|
|
27
|
+
*/
|
|
12
28
|
hasTimerFired(index?: number): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Reports whether `waitFor` failed before the current `execute` call.
|
|
31
|
+
* @returns Whether failure policy proceeded to execution.
|
|
32
|
+
*/
|
|
13
33
|
waitForMethodFailed(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Stores process-local data for this Step execution; it is not durable.
|
|
36
|
+
* @typeParam T - Local value type.
|
|
37
|
+
* @param key - Non-empty execution-scoped key.
|
|
38
|
+
* @param value - Value retained in worker memory.
|
|
39
|
+
* @param codec - Codec used to serialize the local value when required.
|
|
40
|
+
*/
|
|
14
41
|
setStepExecutionLocal<T>(key: string, value: T, codec: Codec<T>): void;
|
|
42
|
+
/**
|
|
43
|
+
* Reads process-local data for this Step execution.
|
|
44
|
+
* @typeParam T - Expected local value type.
|
|
45
|
+
* @param key - Key used when storing the value.
|
|
46
|
+
* @param codec - Codec used to decode the value.
|
|
47
|
+
* @returns The value, or `undefined` after absence or worker restart.
|
|
48
|
+
*/
|
|
15
49
|
getStepExecutionLocal<T>(key: string, codec: Codec<T>): T | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Stages an application event in the current handler result.
|
|
52
|
+
* @typeParam T - Event payload type.
|
|
53
|
+
* @param name - Non-empty diagnostic event name.
|
|
54
|
+
* @param value - Event payload.
|
|
55
|
+
* @param codec - Payload codec.
|
|
56
|
+
*/
|
|
16
57
|
recordEvent<T>(name: string, value: T, codec: Codec<T>): void;
|
|
58
|
+
/**
|
|
59
|
+
* Reads a typed Attribute from decision state.
|
|
60
|
+
* @typeParam T - Attribute value type.
|
|
61
|
+
* @param attribute - Registered singleton or map definition.
|
|
62
|
+
* @param instance - Required AttributeMap instance; omitted for a singleton.
|
|
63
|
+
* @returns The decoded current value.
|
|
64
|
+
*/
|
|
17
65
|
getAttribute<T>(attribute: Attribute<T> | AttributeMap<T>, instance?: string): T;
|
|
66
|
+
/**
|
|
67
|
+
* Stages an Attribute write in the current decision.
|
|
68
|
+
* @typeParam T - Attribute value type.
|
|
69
|
+
* @param attribute - Registered singleton or map definition.
|
|
70
|
+
* @param value - Typed value to persist.
|
|
71
|
+
* @param instance - Required AttributeMap instance; omitted for a singleton.
|
|
72
|
+
*/
|
|
18
73
|
setAttribute<T>(attribute: Attribute<T> | AttributeMap<T>, value: T, instance?: string): void;
|
|
74
|
+
/**
|
|
75
|
+
* Stages deletion of an Attribute value.
|
|
76
|
+
* @param attribute - Registered singleton or map definition.
|
|
77
|
+
* @param instance - Required AttributeMap instance; omitted for a singleton.
|
|
78
|
+
*/
|
|
19
79
|
deleteAttribute(attribute: Attribute<unknown> | AttributeMap<unknown>, instance?: string): void;
|
|
80
|
+
/**
|
|
81
|
+
* Stages one typed Channel publication.
|
|
82
|
+
* @typeParam T - Channel element type.
|
|
83
|
+
* @param channel - Registered singleton or map definition.
|
|
84
|
+
* @param value - Value to append.
|
|
85
|
+
* @param instance - Required ChannelMap instance; omitted for a singleton.
|
|
86
|
+
*/
|
|
20
87
|
publish<T>(channel: Channel<T> | ChannelMap<T>, value: T, instance?: string): void;
|
|
88
|
+
/**
|
|
89
|
+
* Returns a Channel's current queued value count.
|
|
90
|
+
* @param channel - Registered singleton or map definition.
|
|
91
|
+
* @param instance - Required ChannelMap instance; omitted for a singleton.
|
|
92
|
+
* @returns Non-negative queued value count.
|
|
93
|
+
*/
|
|
21
94
|
channelSize(channel: Channel<unknown> | ChannelMap<unknown>, instance?: string): number;
|
|
95
|
+
/**
|
|
96
|
+
* Returns values selected by the satisfied Channel condition.
|
|
97
|
+
* @typeParam T - Channel element type.
|
|
98
|
+
* @param channel - Registered singleton or map definition.
|
|
99
|
+
* @param instance - Required ChannelMap instance; omitted for a singleton.
|
|
100
|
+
* @returns Ordered values for this Step execution.
|
|
101
|
+
*/
|
|
22
102
|
channelResults<T>(channel: Channel<T> | ChannelMap<T>, instance?: string): readonly T[];
|
|
23
103
|
}
|
package/dist/src/errors.d.ts
CHANGED
|
@@ -2,43 +2,159 @@ import type { status } from "@grpc/grpc-js";
|
|
|
2
2
|
import type { Codec } from "./codec.js";
|
|
3
3
|
import type { Value } from "./gen/dex.js";
|
|
4
4
|
import type { FlowStatus } from "./options.js";
|
|
5
|
+
/** Indicates that an API is intentionally unavailable in the current SDK phase. */
|
|
5
6
|
export declare class PhaseNotImplementedError extends Error {
|
|
6
7
|
}
|
|
8
|
+
/** Provides stable Dex-specific classifications beyond gRPC status codes. */
|
|
7
9
|
export declare const ErrorSubStatus: Readonly<{
|
|
10
|
+
/** Dex returned no more specific classification. */
|
|
8
11
|
readonly UNCATEGORIZED: "uncategorized";
|
|
12
|
+
/** A start request conflicted with an existing Flow ID. */
|
|
9
13
|
readonly FLOW_ALREADY_STARTED: "flowAlreadyStarted";
|
|
14
|
+
/** No Flow exists for the requested ID. */
|
|
10
15
|
readonly FLOW_NOT_EXISTS: "flowNotExists";
|
|
16
|
+
/** A nested application Worker invocation failed. */
|
|
11
17
|
readonly WORKER_API_ERROR: "workerApiError";
|
|
18
|
+
/** A retryable long poll ended without observing its condition. */
|
|
12
19
|
readonly LONG_POLL_TIMEOUT: "longPollTimeout";
|
|
13
20
|
}>;
|
|
21
|
+
/** Represents a value from {@link ErrorSubStatus}. */
|
|
14
22
|
export type ErrorSubStatus = (typeof ErrorSubStatus)[keyof typeof ErrorSubStatus];
|
|
23
|
+
/** Provides terminal Flow failure categories returned by Dex. */
|
|
15
24
|
export declare const FlowErrorType: Readonly<{
|
|
25
|
+
/** A Step decision could not be applied. */
|
|
16
26
|
readonly STEP_DECISION_FAILED: "stepDecisionFailed";
|
|
27
|
+
/** A Client-originated operation failed the Flow. */
|
|
17
28
|
readonly CLIENT_API_FAILED: "clientApiFailed";
|
|
29
|
+
/** Worker dispatch or application handler execution failed. */
|
|
18
30
|
readonly WORKER_API_FAILED: "workerApiFailed";
|
|
31
|
+
/** Application Flow code returned an invalid definition or result. */
|
|
19
32
|
readonly INVALID_USER_FLOW_CODE: "invalidUserFlowCode";
|
|
33
|
+
/** Dex encountered an internal invariant or infrastructure failure. */
|
|
20
34
|
readonly INTERNAL: "internal";
|
|
21
35
|
}>;
|
|
36
|
+
/** Represents a value from {@link FlowErrorType}. */
|
|
22
37
|
export type FlowErrorType = (typeof FlowErrorType)[keyof typeof FlowErrorType];
|
|
23
|
-
|
|
38
|
+
/** Exposes structured metadata returned by a failed FlowService operation. */
|
|
39
|
+
export declare class DexServiceError extends Error {
|
|
24
40
|
readonly code: status;
|
|
25
|
-
readonly subStatus: ErrorSubStatus
|
|
41
|
+
readonly subStatus: ErrorSubStatus;
|
|
26
42
|
readonly detail: string;
|
|
43
|
+
readonly operation: string;
|
|
44
|
+
readonly flowId: string | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a structured service error.
|
|
47
|
+
* @param code - Outer gRPC status code.
|
|
48
|
+
* @param subStatus - Stable Dex-specific classification.
|
|
49
|
+
* @param detail - Human-readable service detail.
|
|
50
|
+
* @param operation - Client operation that failed.
|
|
51
|
+
* @param flowId - Target Flow ID, or `undefined` for service-wide calls.
|
|
52
|
+
* @param options - Standard Error construction options.
|
|
53
|
+
*/
|
|
54
|
+
constructor(code: status, subStatus: ErrorSubStatus, detail: string, operation: string, flowId: string | undefined, options?: ErrorOptions);
|
|
55
|
+
}
|
|
56
|
+
/** Indicates that `startFlow` conflicts with an existing Flow ID. */
|
|
57
|
+
export declare class FlowAlreadyStartedError extends DexServiceError {
|
|
58
|
+
}
|
|
59
|
+
/** Indicates that an operation targeted a Flow ID that does not exist. */
|
|
60
|
+
export declare class FlowNotFoundError extends DexServiceError {
|
|
61
|
+
}
|
|
62
|
+
/** Indicates that an operation requires an active but already closed Flow. */
|
|
63
|
+
export declare class FlowNotActiveError extends DexServiceError {
|
|
64
|
+
}
|
|
65
|
+
/** Exposes both outer FlowService and nested WorkerService failure details. */
|
|
66
|
+
export declare class WorkerInvocationError extends DexServiceError {
|
|
67
|
+
readonly workerCode: status | undefined;
|
|
27
68
|
readonly workerErrorType: string;
|
|
28
69
|
readonly workerErrorDetail: string;
|
|
29
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Creates an error from outer and nested Worker metadata.
|
|
72
|
+
* @param code - Outer FlowService gRPC status.
|
|
73
|
+
* @param subStatus - Dex-specific classification.
|
|
74
|
+
* @param detail - Outer human-readable detail.
|
|
75
|
+
* @param operation - Client operation that invoked the Worker.
|
|
76
|
+
* @param flowId - Target Flow ID, when available.
|
|
77
|
+
* @param workerCode - Nested Worker gRPC status, when available.
|
|
78
|
+
* @param workerErrorType - Worker-reported application error type.
|
|
79
|
+
* @param workerErrorDetail - Worker-reported human-readable detail.
|
|
80
|
+
* @param options - Standard Error construction options.
|
|
81
|
+
*/
|
|
82
|
+
constructor(code: status, subStatus: ErrorSubStatus, detail: string, operation: string, flowId: string | undefined, workerCode: status | undefined, workerErrorType: string, workerErrorDetail: string, options?: ErrorOptions);
|
|
83
|
+
}
|
|
84
|
+
/** Indicates that an RPC could not acquire all requested Attribute locks. */
|
|
85
|
+
export declare class RpcLockConflictError extends DexServiceError {
|
|
86
|
+
}
|
|
87
|
+
/** Indicates that a retryable long poll ended before its condition was observed. */
|
|
88
|
+
export declare class LongPollTimeoutError extends DexServiceError {
|
|
89
|
+
}
|
|
90
|
+
/** Indicates that Registry construction found an invalid Flow definition. */
|
|
91
|
+
export declare class FlowDefinitionError extends Error {
|
|
92
|
+
/**
|
|
93
|
+
* Creates a Flow definition error.
|
|
94
|
+
* @param message - Precise validation failure detail.
|
|
95
|
+
* @param options - Standard Error construction options.
|
|
96
|
+
*/
|
|
97
|
+
constructor(message: string, options?: ErrorOptions);
|
|
98
|
+
}
|
|
99
|
+
/** Identifies a Step or RPC result that violates the SDK contract. */
|
|
100
|
+
export declare class InvalidStepResultError extends FlowDefinitionError {
|
|
101
|
+
readonly flowType: string;
|
|
102
|
+
readonly stepType: string | undefined;
|
|
103
|
+
readonly method: "waitFor" | "execute" | "rpc";
|
|
104
|
+
/**
|
|
105
|
+
* Creates an invalid-handler-result error.
|
|
106
|
+
* @param flowType - Containing Flow type.
|
|
107
|
+
* @param stepType - Step type, or `undefined` for an RPC.
|
|
108
|
+
* @param method - Handler method that returned the invalid value.
|
|
109
|
+
* @param detail - Precise contract violation.
|
|
110
|
+
* @param options - Standard Error construction options.
|
|
111
|
+
*/
|
|
112
|
+
constructor(flowType: string, stepType: string | undefined, method: "waitFor" | "execute" | "rpc", detail: string, options?: ErrorOptions);
|
|
30
113
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
114
|
+
/** Reports an application value encoding, decoding, or hydration failure. */
|
|
115
|
+
export declare class ValueMappingError extends Error {
|
|
116
|
+
readonly operation: "encode" | "decode" | "hydrate";
|
|
117
|
+
/**
|
|
118
|
+
* Creates a value-mapping error.
|
|
119
|
+
* @param operation - Mapping phase that failed.
|
|
120
|
+
* @param detail - Incompatible type, wire kind, or malformed payload detail.
|
|
121
|
+
* @param options - Standard Error construction options.
|
|
122
|
+
*/
|
|
123
|
+
constructor(operation: "encode" | "decode" | "hydrate", detail: string, options?: ErrorOptions);
|
|
34
124
|
}
|
|
125
|
+
/** Reports that `waitForFlow` observed a non-successful terminal status. */
|
|
35
126
|
export declare class FlowUncompletedError extends Error {
|
|
36
127
|
readonly runId: string;
|
|
37
128
|
readonly status: FlowStatus;
|
|
38
129
|
readonly errorType: FlowErrorType | undefined;
|
|
39
130
|
private readonly results;
|
|
131
|
+
/**
|
|
132
|
+
* Creates an error that keeps completed Step outputs for typed decoding.
|
|
133
|
+
* @param runId - Terminal server-assigned run ID.
|
|
134
|
+
* @param status - Non-completed terminal status.
|
|
135
|
+
* @param errorType - Terminal failure category, when available.
|
|
136
|
+
* @param message - Human-readable terminal detail.
|
|
137
|
+
* @param results - Hydrated Step outputs in server order.
|
|
138
|
+
*/
|
|
40
139
|
constructor(runId: string, status: FlowStatus, errorType: FlowErrorType | undefined, message: string | undefined, results: readonly Value[]);
|
|
140
|
+
/**
|
|
141
|
+
* Returns the number of retained Step completion outputs.
|
|
142
|
+
* @returns A non-negative result count.
|
|
143
|
+
*/
|
|
41
144
|
get resultCount(): number;
|
|
145
|
+
/**
|
|
146
|
+
* Decodes one completed Step output.
|
|
147
|
+
* @typeParam T - Expected output type.
|
|
148
|
+
* @param index - Zero-based output position.
|
|
149
|
+
* @param codec - Codec for the expected output type.
|
|
150
|
+
* @returns The decoded Step output.
|
|
151
|
+
* @throws {@link RangeError} when the index is outside the retained outputs.
|
|
152
|
+
*/
|
|
42
153
|
getResult<T>(index: number, codec: Codec<T>): T;
|
|
43
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Creates a consistent error for an API planned in a later implementation phase.
|
|
157
|
+
* @param component - Human-readable unavailable component name.
|
|
158
|
+
* @returns A new PhaseNotImplementedError.
|
|
159
|
+
*/
|
|
44
160
|
export declare function laterPhase(component: string): PhaseNotImplementedError;
|
package/dist/src/errors.js
CHANGED
|
@@ -6,49 +6,162 @@
|
|
|
6
6
|
//
|
|
7
7
|
// SPDX-License-Identifier: LicenseRef-Super-Durable-1.0
|
|
8
8
|
import { decodeValue } from "./value-mapper.js";
|
|
9
|
+
/** Indicates that an API is intentionally unavailable in the current SDK phase. */
|
|
9
10
|
export class PhaseNotImplementedError extends Error {
|
|
10
11
|
}
|
|
12
|
+
/** Provides stable Dex-specific classifications beyond gRPC status codes. */
|
|
11
13
|
export const ErrorSubStatus = Object.freeze({
|
|
14
|
+
/** Dex returned no more specific classification. */
|
|
12
15
|
UNCATEGORIZED: "uncategorized",
|
|
16
|
+
/** A start request conflicted with an existing Flow ID. */
|
|
13
17
|
FLOW_ALREADY_STARTED: "flowAlreadyStarted",
|
|
18
|
+
/** No Flow exists for the requested ID. */
|
|
14
19
|
FLOW_NOT_EXISTS: "flowNotExists",
|
|
20
|
+
/** A nested application Worker invocation failed. */
|
|
15
21
|
WORKER_API_ERROR: "workerApiError",
|
|
22
|
+
/** A retryable long poll ended without observing its condition. */
|
|
16
23
|
LONG_POLL_TIMEOUT: "longPollTimeout",
|
|
17
24
|
});
|
|
25
|
+
/** Provides terminal Flow failure categories returned by Dex. */
|
|
18
26
|
export const FlowErrorType = Object.freeze({
|
|
27
|
+
/** A Step decision could not be applied. */
|
|
19
28
|
STEP_DECISION_FAILED: "stepDecisionFailed",
|
|
29
|
+
/** A Client-originated operation failed the Flow. */
|
|
20
30
|
CLIENT_API_FAILED: "clientApiFailed",
|
|
31
|
+
/** Worker dispatch or application handler execution failed. */
|
|
21
32
|
WORKER_API_FAILED: "workerApiFailed",
|
|
33
|
+
/** Application Flow code returned an invalid definition or result. */
|
|
22
34
|
INVALID_USER_FLOW_CODE: "invalidUserFlowCode",
|
|
35
|
+
/** Dex encountered an internal invariant or infrastructure failure. */
|
|
23
36
|
INTERNAL: "internal",
|
|
24
37
|
});
|
|
25
|
-
|
|
38
|
+
/** Exposes structured metadata returned by a failed FlowService operation. */
|
|
39
|
+
export class DexServiceError extends Error {
|
|
26
40
|
code;
|
|
27
41
|
subStatus;
|
|
28
42
|
detail;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
43
|
+
operation;
|
|
44
|
+
flowId;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a structured service error.
|
|
47
|
+
* @param code - Outer gRPC status code.
|
|
48
|
+
* @param subStatus - Stable Dex-specific classification.
|
|
49
|
+
* @param detail - Human-readable service detail.
|
|
50
|
+
* @param operation - Client operation that failed.
|
|
51
|
+
* @param flowId - Target Flow ID, or `undefined` for service-wide calls.
|
|
52
|
+
* @param options - Standard Error construction options.
|
|
53
|
+
*/
|
|
54
|
+
constructor(code, subStatus, detail, operation, flowId, options) {
|
|
32
55
|
super(detail, options);
|
|
33
56
|
this.code = code;
|
|
34
57
|
this.subStatus = subStatus;
|
|
35
58
|
this.detail = detail;
|
|
59
|
+
this.operation = operation;
|
|
60
|
+
this.flowId = flowId;
|
|
61
|
+
this.name = new.target.name;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** Indicates that `startFlow` conflicts with an existing Flow ID. */
|
|
65
|
+
export class FlowAlreadyStartedError extends DexServiceError {
|
|
66
|
+
}
|
|
67
|
+
/** Indicates that an operation targeted a Flow ID that does not exist. */
|
|
68
|
+
export class FlowNotFoundError extends DexServiceError {
|
|
69
|
+
}
|
|
70
|
+
/** Indicates that an operation requires an active but already closed Flow. */
|
|
71
|
+
export class FlowNotActiveError extends DexServiceError {
|
|
72
|
+
}
|
|
73
|
+
/** Exposes both outer FlowService and nested WorkerService failure details. */
|
|
74
|
+
export class WorkerInvocationError extends DexServiceError {
|
|
75
|
+
workerCode;
|
|
76
|
+
workerErrorType;
|
|
77
|
+
workerErrorDetail;
|
|
78
|
+
/**
|
|
79
|
+
* Creates an error from outer and nested Worker metadata.
|
|
80
|
+
* @param code - Outer FlowService gRPC status.
|
|
81
|
+
* @param subStatus - Dex-specific classification.
|
|
82
|
+
* @param detail - Outer human-readable detail.
|
|
83
|
+
* @param operation - Client operation that invoked the Worker.
|
|
84
|
+
* @param flowId - Target Flow ID, when available.
|
|
85
|
+
* @param workerCode - Nested Worker gRPC status, when available.
|
|
86
|
+
* @param workerErrorType - Worker-reported application error type.
|
|
87
|
+
* @param workerErrorDetail - Worker-reported human-readable detail.
|
|
88
|
+
* @param options - Standard Error construction options.
|
|
89
|
+
*/
|
|
90
|
+
constructor(code, subStatus, detail, operation, flowId, workerCode, workerErrorType, workerErrorDetail, options) {
|
|
91
|
+
super(code, subStatus, detail, operation, flowId, options);
|
|
92
|
+
this.workerCode = workerCode;
|
|
36
93
|
this.workerErrorType = workerErrorType;
|
|
37
94
|
this.workerErrorDetail = workerErrorDetail;
|
|
38
95
|
}
|
|
39
96
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
97
|
+
/** Indicates that an RPC could not acquire all requested Attribute locks. */
|
|
98
|
+
export class RpcLockConflictError extends DexServiceError {
|
|
99
|
+
}
|
|
100
|
+
/** Indicates that a retryable long poll ended before its condition was observed. */
|
|
101
|
+
export class LongPollTimeoutError extends DexServiceError {
|
|
102
|
+
}
|
|
103
|
+
/** Indicates that Registry construction found an invalid Flow definition. */
|
|
104
|
+
export class FlowDefinitionError extends Error {
|
|
105
|
+
/**
|
|
106
|
+
* Creates a Flow definition error.
|
|
107
|
+
* @param message - Precise validation failure detail.
|
|
108
|
+
* @param options - Standard Error construction options.
|
|
109
|
+
*/
|
|
110
|
+
constructor(message, options) {
|
|
111
|
+
super(message, options);
|
|
112
|
+
this.name = new.target.name;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** Identifies a Step or RPC result that violates the SDK contract. */
|
|
116
|
+
export class InvalidStepResultError extends FlowDefinitionError {
|
|
117
|
+
flowType;
|
|
118
|
+
stepType;
|
|
119
|
+
method;
|
|
120
|
+
/**
|
|
121
|
+
* Creates an invalid-handler-result error.
|
|
122
|
+
* @param flowType - Containing Flow type.
|
|
123
|
+
* @param stepType - Step type, or `undefined` for an RPC.
|
|
124
|
+
* @param method - Handler method that returned the invalid value.
|
|
125
|
+
* @param detail - Precise contract violation.
|
|
126
|
+
* @param options - Standard Error construction options.
|
|
127
|
+
*/
|
|
128
|
+
constructor(flowType, stepType, method, detail, options) {
|
|
129
|
+
const target = stepType === undefined ? `RPC in Flow ${flowType}` : `Flow ${flowType} Step ${stepType}`;
|
|
130
|
+
super(`${target} ${method} returned an invalid result: ${detail}`, options);
|
|
131
|
+
this.flowType = flowType;
|
|
132
|
+
this.stepType = stepType;
|
|
133
|
+
this.method = method;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/** Reports an application value encoding, decoding, or hydration failure. */
|
|
137
|
+
export class ValueMappingError extends Error {
|
|
138
|
+
operation;
|
|
139
|
+
/**
|
|
140
|
+
* Creates a value-mapping error.
|
|
141
|
+
* @param operation - Mapping phase that failed.
|
|
142
|
+
* @param detail - Incompatible type, wire kind, or malformed payload detail.
|
|
143
|
+
* @param options - Standard Error construction options.
|
|
144
|
+
*/
|
|
145
|
+
constructor(operation, detail, options) {
|
|
146
|
+
super(`Cannot ${operation} Dex Value: ${detail}`, options);
|
|
147
|
+
this.operation = operation;
|
|
148
|
+
this.name = new.target.name;
|
|
45
149
|
}
|
|
46
150
|
}
|
|
151
|
+
/** Reports that `waitForFlow` observed a non-successful terminal status. */
|
|
47
152
|
export class FlowUncompletedError extends Error {
|
|
48
153
|
runId;
|
|
49
154
|
status;
|
|
50
155
|
errorType;
|
|
51
156
|
results;
|
|
157
|
+
/**
|
|
158
|
+
* Creates an error that keeps completed Step outputs for typed decoding.
|
|
159
|
+
* @param runId - Terminal server-assigned run ID.
|
|
160
|
+
* @param status - Non-completed terminal status.
|
|
161
|
+
* @param errorType - Terminal failure category, when available.
|
|
162
|
+
* @param message - Human-readable terminal detail.
|
|
163
|
+
* @param results - Hydrated Step outputs in server order.
|
|
164
|
+
*/
|
|
52
165
|
constructor(runId, status, errorType, message, results) {
|
|
53
166
|
super(message);
|
|
54
167
|
this.runId = runId;
|
|
@@ -56,9 +169,21 @@ export class FlowUncompletedError extends Error {
|
|
|
56
169
|
this.errorType = errorType;
|
|
57
170
|
this.results = results;
|
|
58
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Returns the number of retained Step completion outputs.
|
|
174
|
+
* @returns A non-negative result count.
|
|
175
|
+
*/
|
|
59
176
|
get resultCount() {
|
|
60
177
|
return this.results.length;
|
|
61
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Decodes one completed Step output.
|
|
181
|
+
* @typeParam T - Expected output type.
|
|
182
|
+
* @param index - Zero-based output position.
|
|
183
|
+
* @param codec - Codec for the expected output type.
|
|
184
|
+
* @returns The decoded Step output.
|
|
185
|
+
* @throws {@link RangeError} when the index is outside the retained outputs.
|
|
186
|
+
*/
|
|
62
187
|
getResult(index, codec) {
|
|
63
188
|
const value = this.results[index];
|
|
64
189
|
if (value === undefined) {
|
|
@@ -67,6 +192,11 @@ export class FlowUncompletedError extends Error {
|
|
|
67
192
|
return decodeValue(codec, value);
|
|
68
193
|
}
|
|
69
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Creates a consistent error for an API planned in a later implementation phase.
|
|
197
|
+
* @param component - Human-readable unavailable component name.
|
|
198
|
+
* @returns A new PhaseNotImplementedError.
|
|
199
|
+
*/
|
|
70
200
|
export function laterPhase(component) {
|
|
71
201
|
return new PhaseNotImplementedError(`${component} belongs to a later phase`);
|
|
72
202
|
}
|
package/dist/src/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,uDAAuD;AACvD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,wDAAwD;AAOxD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,OAAO,wBAAyB,SAAQ,KAAK;CAAG;AAEtD,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1C,aAAa,EAAE,eAAe;IAC9B,oBAAoB,EAAE,oBAAoB;IAC1C,eAAe,EAAE,eAAe;IAChC,gBAAgB,EAAE,gBAAgB;IAClC,iBAAiB,EAAE,iBAAiB;CAC5B,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,uDAAuD;AACvD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,wDAAwD;AAOxD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,mFAAmF;AACnF,MAAM,OAAO,wBAAyB,SAAQ,KAAK;CAAG;AAEtD,6EAA6E;AAC7E,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1C,oDAAoD;IACpD,aAAa,EAAE,eAAe;IAC9B,2DAA2D;IAC3D,oBAAoB,EAAE,oBAAoB;IAC1C,2CAA2C;IAC3C,eAAe,EAAE,eAAe;IAChC,qD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,SAA0C,EAC1D,MAAc,EACd,OAAsB;QAEtB,KAAK,CAAC,UAAU,SAAS,eAAe,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;QAJ3C,cAAS,GAAT,SAAS,CAAiC;QAK1D,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAED,4EAA4E;AAC5E,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAU3B;IACA;IACA;IAEC;IAbnB;;;;;;;OAOG;IACH,YACkB,KAAa,EACb,MAAkB,EAClB,SAAoC,EACpD,OAA2B,EACV,OAAyB;QAE1C,KAAK,CAAC,OAAO,CAAC,CAAC;QANC,UAAK,GAAL,KAAK,CAAQ;QACb,WAAM,GAAN,MAAM,CAAY;QAClB,cAAS,GAAT,SAAS,CAA2B;QAEnC,YAAO,GAAP,OAAO,CAAkB;IAG5C,CAAC;IAED;;;OAGG;IACH,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED;;;;;;;OAOG;IACI,SAAS,CAAI,KAAa,EAAE,KAAe;QAChD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,IAAI,UAAU,CAAC,gBAAgB,KAAK,kBAAkB,CAAC,CAAC;QAChE,CAAC;QACD,OAAO,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,SAAiB;IAC1C,OAAO,IAAI,wBAAwB,CAAC,GAAG,SAAS,2BAA2B,CAAC,CAAC;AAC/E,CAAC"}
|
package/dist/src/flow.d.ts
CHANGED
|
@@ -1,14 +1,48 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AttributeMap, type Attribute, type PersistenceSchema } from "./persistence.js";
|
|
2
|
+
import { IndexType as ProtoIndexType } from "./gen/dex.js";
|
|
2
3
|
import { type RegisteredRPC } from "./rpc.js";
|
|
3
4
|
import { StepList, type Step } from "./step.js";
|
|
4
5
|
import type { Channel, ChannelMap } from "./wait.js";
|
|
6
|
+
/**
|
|
7
|
+
* Defines one durable application Flow and its registered API surface.
|
|
8
|
+
* @typeParam StartInput - Value accepted by the optional starting Step.
|
|
9
|
+
*/
|
|
5
10
|
export interface Flow<StartInput = void> {
|
|
11
|
+
/**
|
|
12
|
+
* Returns the protocol Flow type.
|
|
13
|
+
* @returns A non-empty Flow type unique within the Registry.
|
|
14
|
+
*/
|
|
6
15
|
getFlowType(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Returns this Flow's Step definitions.
|
|
18
|
+
* @returns Zero or one starting Step plus all other registered Steps.
|
|
19
|
+
*/
|
|
7
20
|
getSteps(): StepList<StartInput>;
|
|
21
|
+
/**
|
|
22
|
+
* Returns this Flow's persistence definitions.
|
|
23
|
+
* @returns Attributes and Channels owned by this Flow. Flows without this method have none.
|
|
24
|
+
*/
|
|
8
25
|
getPersistenceSchema?(): PersistenceSchema;
|
|
9
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Validates and stores Flow definitions shared by Client and Worker.
|
|
29
|
+
* Construction checks names, Step/RPC signatures, persistence definitions, locks,
|
|
30
|
+
* and Attribute indexes atomically.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const orders = new OrdersFlow();
|
|
35
|
+
* const registry = new Registry([orders]);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
10
38
|
export declare class Registry {
|
|
39
|
+
/** Registered Flow instances in input order. */
|
|
11
40
|
readonly flows: readonly Flow<any>[];
|
|
41
|
+
/**
|
|
42
|
+
* Creates a Registry.
|
|
43
|
+
* @param flows - Flow instances with unique Flow types.
|
|
44
|
+
* @throws {@link FlowDefinitionError} when any public definition is invalid.
|
|
45
|
+
*/
|
|
12
46
|
constructor(flows: readonly Flow<any>[]);
|
|
13
47
|
}
|
|
14
48
|
export interface RegisteredStep {
|
|
@@ -29,3 +63,4 @@ export declare function registeredRPC(registry: Registry, method: Function): Reg
|
|
|
29
63
|
export declare function registeredFlowByName(registry: Registry, name: string): RegisteredFlow;
|
|
30
64
|
export declare function registeredStep(flow: RegisteredFlow, name: string): RegisteredStep;
|
|
31
65
|
export declare function registeredRPCByName(flow: RegisteredFlow, name: string): RegisteredRPC;
|
|
66
|
+
export declare function registeredAttributeIndexes(registry: Registry): ReadonlyMap<string, ProtoIndexType>;
|