@superdurable/dex 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +145 -0
- package/dist/src/blob-cache.d.ts +14 -0
- package/dist/src/blob-cache.js +22 -0
- package/dist/src/blob-cache.js.map +1 -0
- package/dist/src/client.d.ts +36 -0
- package/dist/src/client.js +441 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/codec.d.ts +38 -0
- package/dist/src/codec.js +86 -0
- package/dist/src/codec.js.map +1 -0
- package/dist/src/context.d.ts +23 -0
- package/dist/src/context.js +9 -0
- package/dist/src/context.js.map +1 -0
- package/dist/src/errors.d.ts +44 -0
- package/dist/src/errors.js +73 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/flow.d.ts +31 -0
- package/dist/src/flow.js +155 -0
- package/dist/src/flow.js.map +1 -0
- package/dist/src/gen/dex.d.ts +1529 -0
- package/dist/src/gen/dex.js +10661 -0
- package/dist/src/gen/dex.js.map +1 -0
- package/dist/src/gen/google/protobuf/duration.d.ts +103 -0
- package/dist/src/gen/google/protobuf/duration.js +64 -0
- package/dist/src/gen/google/protobuf/duration.js.map +1 -0
- package/dist/src/gen/google/protobuf/empty.d.ts +37 -0
- package/dist/src/gen/google/protobuf/empty.js +39 -0
- package/dist/src/gen/google/protobuf/empty.js.map +1 -0
- package/dist/src/gen/google/protobuf/struct.d.ts +140 -0
- package/dist/src/gen/google/protobuf/struct.js +359 -0
- package/dist/src/gen/google/protobuf/struct.js.map +1 -0
- package/dist/src/gen/google/protobuf/timestamp.d.ts +133 -0
- package/dist/src/gen/google/protobuf/timestamp.js +64 -0
- package/dist/src/gen/google/protobuf/timestamp.js.map +1 -0
- package/dist/src/grpc-status.d.ts +4 -0
- package/dist/src/grpc-status.js +105 -0
- package/dist/src/grpc-status.js.map +1 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.js +20 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/invocation-context.d.ts +44 -0
- package/dist/src/invocation-context.js +203 -0
- package/dist/src/invocation-context.js.map +1 -0
- package/dist/src/options.d.ts +106 -0
- package/dist/src/options.js +55 -0
- package/dist/src/options.js.map +1 -0
- package/dist/src/persistence.d.ts +45 -0
- package/dist/src/persistence.js +65 -0
- package/dist/src/persistence.js.map +1 -0
- package/dist/src/rpc.d.ts +39 -0
- package/dist/src/rpc.js +50 -0
- package/dist/src/rpc.js.map +1 -0
- package/dist/src/step.d.ts +92 -0
- package/dist/src/step.js +62 -0
- package/dist/src/step.js.map +1 -0
- package/dist/src/validation.d.ts +3 -0
- package/dist/src/validation.js +33 -0
- package/dist/src/validation.js.map +1 -0
- package/dist/src/value-mapper.d.ts +14 -0
- package/dist/src/value-mapper.js +199 -0
- package/dist/src/value-mapper.js.map +1 -0
- package/dist/src/wait.d.ts +57 -0
- package/dist/src/wait.js +124 -0
- package/dist/src/wait.js.map +1 -0
- package/dist/src/worker-dispatcher.d.ts +14 -0
- package/dist/src/worker-dispatcher.js +374 -0
- package/dist/src/worker-dispatcher.js.map +1 -0
- package/dist/src/worker.d.ts +18 -0
- package/dist/src/worker.js +139 -0
- package/dist/src/worker.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Super Durable Source License 1.0.
|
|
4
|
+
// You may not use this file except in compliance with the License.
|
|
5
|
+
// See the LICENSE file in the repository root.
|
|
6
|
+
//
|
|
7
|
+
// SPDX-License-Identifier: LicenseRef-Super-Durable-1.0
|
|
8
|
+
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
|
9
|
+
import { Metadata, status } from "@grpc/grpc-js";
|
|
10
|
+
import { ErrorResponse, ErrorSubStatus as ProtoErrorSubStatus, WorkerErrorResponse, } from "./gen/dex.js";
|
|
11
|
+
import { DexError, ErrorSubStatus } from "./errors.js";
|
|
12
|
+
const statusDetailsKey = "grpc-status-details-bin";
|
|
13
|
+
export function workerServiceError(failure) {
|
|
14
|
+
const cause = failure instanceof Error ? failure : new Error(String(failure));
|
|
15
|
+
const detail = cause.message || cause.name;
|
|
16
|
+
const worker = WorkerErrorResponse.encode({ detail, errorType: cause.name }).finish();
|
|
17
|
+
const metadata = new Metadata();
|
|
18
|
+
metadata.set(statusDetailsKey, Buffer.from(encodeStatus(status.UNKNOWN, detail, [
|
|
19
|
+
{ typeUrl: "type.googleapis.com/dex.WorkerErrorResponse", value: worker },
|
|
20
|
+
])));
|
|
21
|
+
return Object.assign(new Error(detail), {
|
|
22
|
+
code: status.UNKNOWN,
|
|
23
|
+
details: detail,
|
|
24
|
+
metadata,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export function translateServiceError(error) {
|
|
28
|
+
const response = errorResponse(error);
|
|
29
|
+
const detail = response?.detail || error.details || error.message;
|
|
30
|
+
return new DexError(error.code, response === undefined ? undefined : mapSubStatus(response.subStatus), detail, response?.originalWorkerErrorType ?? "", response?.originalWorkerErrorDetail ?? "", { cause: error });
|
|
31
|
+
}
|
|
32
|
+
function errorResponse(error) {
|
|
33
|
+
const encoded = error.metadata.get(statusDetailsKey)[0];
|
|
34
|
+
if (!(encoded instanceof Buffer)) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
const decoded = decodeStatus(encoded);
|
|
38
|
+
const detail = decoded.details.find((candidate) => candidate.typeUrl.endsWith("/dex.ErrorResponse"));
|
|
39
|
+
return detail === undefined ? undefined : ErrorResponse.decode(detail.value);
|
|
40
|
+
}
|
|
41
|
+
function mapSubStatus(value) {
|
|
42
|
+
switch (value) {
|
|
43
|
+
case ProtoErrorSubStatus.ERROR_SUB_STATUS_UNCATEGORIZED:
|
|
44
|
+
return ErrorSubStatus.UNCATEGORIZED;
|
|
45
|
+
case ProtoErrorSubStatus.ERROR_SUB_STATUS_FLOW_ALREADY_STARTED:
|
|
46
|
+
return ErrorSubStatus.FLOW_ALREADY_STARTED;
|
|
47
|
+
case ProtoErrorSubStatus.ERROR_SUB_STATUS_FLOW_NOT_EXISTS:
|
|
48
|
+
return ErrorSubStatus.FLOW_NOT_EXISTS;
|
|
49
|
+
case ProtoErrorSubStatus.ERROR_SUB_STATUS_WORKER_API_ERROR:
|
|
50
|
+
return ErrorSubStatus.WORKER_API_ERROR;
|
|
51
|
+
case ProtoErrorSubStatus.ERROR_SUB_STATUS_LONG_POLL_TIME_OUT:
|
|
52
|
+
return ErrorSubStatus.LONG_POLL_TIMEOUT;
|
|
53
|
+
default:
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function encodeStatus(code, message, details) {
|
|
58
|
+
const writer = new BinaryWriter();
|
|
59
|
+
if (code !== 0) {
|
|
60
|
+
writer.uint32(8).int32(code);
|
|
61
|
+
}
|
|
62
|
+
if (message !== "") {
|
|
63
|
+
writer.uint32(18).string(message);
|
|
64
|
+
}
|
|
65
|
+
for (const detail of details) {
|
|
66
|
+
writer.uint32(26).fork();
|
|
67
|
+
writer.uint32(10).string(detail.typeUrl);
|
|
68
|
+
writer.uint32(18).bytes(detail.value);
|
|
69
|
+
writer.join();
|
|
70
|
+
}
|
|
71
|
+
return writer.finish();
|
|
72
|
+
}
|
|
73
|
+
function decodeStatus(input) {
|
|
74
|
+
const reader = new BinaryReader(input);
|
|
75
|
+
const details = [];
|
|
76
|
+
while (reader.pos < reader.len) {
|
|
77
|
+
const tag = reader.uint32();
|
|
78
|
+
if (tag >>> 3 === 3) {
|
|
79
|
+
details.push(decodeAny(reader, reader.uint32()));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
reader.skip(tag & 7);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return { details };
|
|
86
|
+
}
|
|
87
|
+
function decodeAny(reader, length) {
|
|
88
|
+
const end = reader.pos + length;
|
|
89
|
+
let typeUrl = "";
|
|
90
|
+
let value = new Uint8Array();
|
|
91
|
+
while (reader.pos < end) {
|
|
92
|
+
const tag = reader.uint32();
|
|
93
|
+
if (tag >>> 3 === 1) {
|
|
94
|
+
typeUrl = reader.string();
|
|
95
|
+
}
|
|
96
|
+
else if (tag >>> 3 === 2) {
|
|
97
|
+
value = reader.bytes();
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
reader.skip(tag & 7);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return { typeUrl, value };
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=grpc-status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grpc-status.js","sourceRoot":"","sources":["../../src/grpc-status.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,uDAAuD;AACvD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,wDAAwD;AAExD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAqB,MAAM,eAAe,CAAC;AAEpE,OAAO,EACL,aAAa,EACb,cAAc,IAAI,mBAAmB,EACrC,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,QAAQ,EAAE,cAAc,EAA8C,MAAM,aAAa,CAAC;AAEnG,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AAOnD,MAAM,UAAU,kBAAkB,CAAC,OAAgB;IACjD,MAAM,KAAK,GAAG,OAAO,YAAY,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9E,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC;IAC3C,MAAM,MAAM,GAAG,mBAAmB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MA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AE,CAAC;QAC5B,CAAC;aAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,KAAK,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./blob-cache.js";
|
|
2
|
+
export * from "./client.js";
|
|
3
|
+
export * from "./codec.js";
|
|
4
|
+
export * from "./context.js";
|
|
5
|
+
export * from "./errors.js";
|
|
6
|
+
export { Registry } from "./flow.js";
|
|
7
|
+
export type { Flow } from "./flow.js";
|
|
8
|
+
export * from "./options.js";
|
|
9
|
+
export * from "./persistence.js";
|
|
10
|
+
export { rpc } from "./rpc.js";
|
|
11
|
+
export type { RPC, RPCOptions, RPCResult } from "./rpc.js";
|
|
12
|
+
export * from "./step.js";
|
|
13
|
+
export * from "./wait.js";
|
|
14
|
+
export * from "./worker.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Super Durable Source License 1.0.
|
|
4
|
+
// You may not use this file except in compliance with the License.
|
|
5
|
+
// See the LICENSE file in the repository root.
|
|
6
|
+
//
|
|
7
|
+
// SPDX-License-Identifier: LicenseRef-Super-Durable-1.0
|
|
8
|
+
export * from "./blob-cache.js";
|
|
9
|
+
export * from "./client.js";
|
|
10
|
+
export * from "./codec.js";
|
|
11
|
+
export * from "./context.js";
|
|
12
|
+
export * from "./errors.js";
|
|
13
|
+
export { Registry } from "./flow.js";
|
|
14
|
+
export * from "./options.js";
|
|
15
|
+
export * from "./persistence.js";
|
|
16
|
+
export { rpc } from "./rpc.js";
|
|
17
|
+
export * from "./step.js";
|
|
18
|
+
export * from "./wait.js";
|
|
19
|
+
export * from "./worker.js";
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,uDAAuD;AACvD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,wDAAwD;AAExD,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Codec } from "./codec.js";
|
|
2
|
+
import type { Context } from "./context.js";
|
|
3
|
+
import { type AttributeWrite, type ChannelInfo, type ChannelMessage, type ConditionResults, type Context as ProtoContext, type KV } from "./gen/dex.js";
|
|
4
|
+
import type { RegisteredFlow } from "./flow.js";
|
|
5
|
+
import { AttributeMap, type Attribute } from "./persistence.js";
|
|
6
|
+
import { ChannelMap, type Channel } from "./wait.js";
|
|
7
|
+
export type InvocationMethod = "waitFor" | "execute" | "rpc";
|
|
8
|
+
export declare class InvocationContext implements Context {
|
|
9
|
+
private readonly method;
|
|
10
|
+
private readonly flow;
|
|
11
|
+
private readonly conditionResults?;
|
|
12
|
+
readonly flowId: string;
|
|
13
|
+
readonly runId: string;
|
|
14
|
+
readonly flowStartedAt: Date;
|
|
15
|
+
readonly stepExecutionId: string;
|
|
16
|
+
readonly fromStepExecutionId: string;
|
|
17
|
+
readonly firstAttemptAt: Date;
|
|
18
|
+
readonly attempt: number;
|
|
19
|
+
private readonly attributes;
|
|
20
|
+
private readonly locals;
|
|
21
|
+
private readonly channelInfos;
|
|
22
|
+
private readonly attributeWrites;
|
|
23
|
+
private readonly localWrites;
|
|
24
|
+
private readonly events;
|
|
25
|
+
private readonly eventNames;
|
|
26
|
+
private readonly publications;
|
|
27
|
+
constructor(method: InvocationMethod, flow: RegisteredFlow, metadata: ProtoContext | undefined, attributes: readonly KV[], locals?: readonly KV[], conditionResults?: ConditionResults | undefined, channelInfos?: Readonly<Record<string, ChannelInfo>>);
|
|
28
|
+
hasTimerFired(index?: number): boolean;
|
|
29
|
+
waitForMethodFailed(): boolean;
|
|
30
|
+
setStepExecutionLocal<T>(key: string, value: T, codec: Codec<T>): void;
|
|
31
|
+
getStepExecutionLocal<T>(key: string, codec: Codec<T>): T | undefined;
|
|
32
|
+
recordEvent<T>(name: string, value: T, codec: Codec<T>): void;
|
|
33
|
+
getAttribute<T>(attribute: Attribute<T> | AttributeMap<T>, instance?: string): T;
|
|
34
|
+
setAttribute<T>(attribute: Attribute<T> | AttributeMap<T>, value: T, instance?: string): void;
|
|
35
|
+
deleteAttribute(attribute: Attribute<unknown> | AttributeMap<unknown>, instance?: string): void;
|
|
36
|
+
publish<T>(channel: Channel<T> | ChannelMap<T>, value: T, instance?: string): void;
|
|
37
|
+
channelSize(channel: Channel<unknown> | ChannelMap<unknown>, instance?: string): number;
|
|
38
|
+
channelResults<T>(channel: Channel<T> | ChannelMap<T>, instance?: string): readonly T[];
|
|
39
|
+
getAttributeWrites(): readonly AttributeWrite[];
|
|
40
|
+
getLocalWrites(): readonly KV[];
|
|
41
|
+
getEvents(): readonly KV[];
|
|
42
|
+
getPublications(): readonly ChannelMessage[];
|
|
43
|
+
private requireRegistered;
|
|
44
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Super Durable Source License 1.0.
|
|
4
|
+
// You may not use this file except in compliance with the License.
|
|
5
|
+
// See the LICENSE file in the repository root.
|
|
6
|
+
//
|
|
7
|
+
// SPDX-License-Identifier: LicenseRef-Super-Durable-1.0
|
|
8
|
+
import { ConditionStatus, IndexType as ProtoIndexType, } from "./gen/dex.js";
|
|
9
|
+
import { AttributeMap, IndexType } from "./persistence.js";
|
|
10
|
+
import { decodeValue, deletionValue, encodeValue } from "./value-mapper.js";
|
|
11
|
+
import { requireName } from "./validation.js";
|
|
12
|
+
import { ChannelMap } from "./wait.js";
|
|
13
|
+
export class InvocationContext {
|
|
14
|
+
method;
|
|
15
|
+
flow;
|
|
16
|
+
conditionResults;
|
|
17
|
+
flowId;
|
|
18
|
+
runId;
|
|
19
|
+
flowStartedAt;
|
|
20
|
+
stepExecutionId;
|
|
21
|
+
fromStepExecutionId;
|
|
22
|
+
firstAttemptAt;
|
|
23
|
+
attempt;
|
|
24
|
+
attributes;
|
|
25
|
+
locals;
|
|
26
|
+
channelInfos;
|
|
27
|
+
attributeWrites = new Map();
|
|
28
|
+
localWrites = new Map();
|
|
29
|
+
events = [];
|
|
30
|
+
eventNames = new Set();
|
|
31
|
+
publications = [];
|
|
32
|
+
constructor(method, flow, metadata, attributes, locals = [], conditionResults, channelInfos = {}) {
|
|
33
|
+
this.method = method;
|
|
34
|
+
this.flow = flow;
|
|
35
|
+
this.conditionResults = conditionResults;
|
|
36
|
+
if (metadata === undefined) {
|
|
37
|
+
throw new TypeError("Worker request Context is required");
|
|
38
|
+
}
|
|
39
|
+
this.flowId = metadata.flowId;
|
|
40
|
+
this.runId = metadata.runId;
|
|
41
|
+
this.flowStartedAt = secondsDate(metadata.flowStartedTimestamp);
|
|
42
|
+
this.stepExecutionId = metadata.stepExecutionId;
|
|
43
|
+
this.fromStepExecutionId = metadata.fromStepExecutionId;
|
|
44
|
+
this.firstAttemptAt = secondsDate(metadata.firstAttemptTimestamp);
|
|
45
|
+
this.attempt = metadata.attempt;
|
|
46
|
+
this.attributes = mapValues("Attribute", attributes);
|
|
47
|
+
this.locals = mapValues("step-execution local", locals);
|
|
48
|
+
this.channelInfos = new Map(Object.entries(channelInfos));
|
|
49
|
+
}
|
|
50
|
+
hasTimerFired(index) {
|
|
51
|
+
const results = this.conditionResults?.timerResults ?? [];
|
|
52
|
+
if (index !== undefined) {
|
|
53
|
+
return results[index]?.conditionStatus === ConditionStatus.CONDITION_STATUS_COMPLETED;
|
|
54
|
+
}
|
|
55
|
+
return results.some((result) => result.conditionStatus === ConditionStatus.CONDITION_STATUS_COMPLETED);
|
|
56
|
+
}
|
|
57
|
+
waitForMethodFailed() {
|
|
58
|
+
return this.conditionResults?.waitForFailed ?? false;
|
|
59
|
+
}
|
|
60
|
+
setStepExecutionLocal(key, value, codec) {
|
|
61
|
+
requireName(key);
|
|
62
|
+
this.localWrites.set(key, { key, value: encodeValue(codec, value) });
|
|
63
|
+
}
|
|
64
|
+
getStepExecutionLocal(key, codec) {
|
|
65
|
+
requireName(key);
|
|
66
|
+
const value = this.localWrites.get(key)?.value ?? this.locals.get(key);
|
|
67
|
+
return value === undefined ? undefined : decodeValue(codec, value);
|
|
68
|
+
}
|
|
69
|
+
recordEvent(name, value, codec) {
|
|
70
|
+
requireName(name);
|
|
71
|
+
if (this.eventNames.has(name)) {
|
|
72
|
+
throw new TypeError(`event was already recorded: ${name}`);
|
|
73
|
+
}
|
|
74
|
+
this.eventNames.add(name);
|
|
75
|
+
this.events.push({ key: name, value: encodeValue(codec, value) });
|
|
76
|
+
}
|
|
77
|
+
getAttribute(attribute, instance) {
|
|
78
|
+
this.requireRegistered(attribute);
|
|
79
|
+
const key = definitionName(attribute, instance);
|
|
80
|
+
const write = this.attributeWrites.get(key)?.value;
|
|
81
|
+
if (write?.kind?.$case === "nullValue") {
|
|
82
|
+
return defaultValue(attribute.codec);
|
|
83
|
+
}
|
|
84
|
+
const value = write ?? this.attributes.get(key);
|
|
85
|
+
return value === undefined ? defaultValue(attribute.codec) : decodeValue(attribute.codec, value);
|
|
86
|
+
}
|
|
87
|
+
setAttribute(attribute, value, instance) {
|
|
88
|
+
this.requireRegistered(attribute);
|
|
89
|
+
const key = definitionName(attribute, instance);
|
|
90
|
+
this.attributeWrites.set(key, {
|
|
91
|
+
key,
|
|
92
|
+
value: encodeValue(attribute.codec, value),
|
|
93
|
+
indexConfig: mapIndex(attribute.index),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
deleteAttribute(attribute, instance) {
|
|
97
|
+
this.requireRegistered(attribute);
|
|
98
|
+
const key = definitionName(attribute, instance);
|
|
99
|
+
this.attributeWrites.set(key, {
|
|
100
|
+
key,
|
|
101
|
+
value: deletionValue(),
|
|
102
|
+
indexConfig: mapIndex(attribute.index),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
publish(channel, value, instance) {
|
|
106
|
+
this.requireRegistered(channel);
|
|
107
|
+
const name = definitionName(channel, instance);
|
|
108
|
+
this.publications.push({ channelName: name, value: encodeValue(channel.codec, value) });
|
|
109
|
+
if (this.method === "rpc") {
|
|
110
|
+
this.channelInfos.set(name, { size: (this.channelInfos.get(name)?.size ?? 0) + 1 });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
channelSize(channel, instance) {
|
|
114
|
+
this.requireRegistered(channel);
|
|
115
|
+
return this.channelInfos.get(definitionName(channel, instance))?.size ?? 0;
|
|
116
|
+
}
|
|
117
|
+
channelResults(channel, instance) {
|
|
118
|
+
this.requireRegistered(channel);
|
|
119
|
+
const name = definitionName(channel, instance);
|
|
120
|
+
return (this.conditionResults?.channelResults ?? [])
|
|
121
|
+
.filter((result) => result.channelName === name &&
|
|
122
|
+
result.conditionStatus === ConditionStatus.CONDITION_STATUS_COMPLETED)
|
|
123
|
+
.flatMap((result) => result.values.map((value) => decodeValue(channel.codec, value)));
|
|
124
|
+
}
|
|
125
|
+
getAttributeWrites() {
|
|
126
|
+
return [...this.attributeWrites.values()];
|
|
127
|
+
}
|
|
128
|
+
getLocalWrites() {
|
|
129
|
+
return [...this.localWrites.values()];
|
|
130
|
+
}
|
|
131
|
+
getEvents() {
|
|
132
|
+
return this.events;
|
|
133
|
+
}
|
|
134
|
+
getPublications() {
|
|
135
|
+
return this.publications;
|
|
136
|
+
}
|
|
137
|
+
requireRegistered(definition) {
|
|
138
|
+
if (this.flow.persistence.get(definition.name) !== definition) {
|
|
139
|
+
throw new TypeError(`persistence definition does not belong to Flow: ${definition.name}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function definitionName(definition, instance) {
|
|
144
|
+
if (definition instanceof AttributeMap || definition instanceof ChannelMap) {
|
|
145
|
+
if (instance === undefined) {
|
|
146
|
+
throw new TypeError(`map definition ${definition.name} requires an instance`);
|
|
147
|
+
}
|
|
148
|
+
requireName(instance);
|
|
149
|
+
return `${definition.name}/${encodeURIComponent(instance).replace(/[!'()*]/g, encodeCharacter)}`;
|
|
150
|
+
}
|
|
151
|
+
if (instance !== undefined) {
|
|
152
|
+
throw new TypeError(`static definition ${definition.name} cannot use an instance`);
|
|
153
|
+
}
|
|
154
|
+
return definition.name;
|
|
155
|
+
}
|
|
156
|
+
function encodeCharacter(character) {
|
|
157
|
+
return `%${character.charCodeAt(0).toString(16).toUpperCase()}`;
|
|
158
|
+
}
|
|
159
|
+
function mapValues(kind, entries) {
|
|
160
|
+
const values = new Map();
|
|
161
|
+
for (const entry of entries) {
|
|
162
|
+
if (entry.key === "" || entry.value === undefined || values.has(entry.key)) {
|
|
163
|
+
throw new TypeError(`invalid or duplicate ${kind}`);
|
|
164
|
+
}
|
|
165
|
+
values.set(entry.key, entry.value);
|
|
166
|
+
}
|
|
167
|
+
return values;
|
|
168
|
+
}
|
|
169
|
+
function defaultValue(codec) {
|
|
170
|
+
switch (codec.wireKind) {
|
|
171
|
+
case "bool":
|
|
172
|
+
return false;
|
|
173
|
+
case "double":
|
|
174
|
+
return 0;
|
|
175
|
+
case "int64":
|
|
176
|
+
return 0n;
|
|
177
|
+
default:
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function mapIndex(index) {
|
|
182
|
+
if (index === undefined) {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
const types = {
|
|
186
|
+
[IndexType.KEYWORD]: ProtoIndexType.INDEX_TYPE_KEYWORD,
|
|
187
|
+
[IndexType.FULL_TEXT]: ProtoIndexType.INDEX_TYPE_TEXT,
|
|
188
|
+
[IndexType.KEYWORD_ARRAY]: ProtoIndexType.INDEX_TYPE_KEYWORD_ARRAY,
|
|
189
|
+
[IndexType.INT]: ProtoIndexType.INDEX_TYPE_INT,
|
|
190
|
+
[IndexType.DOUBLE]: ProtoIndexType.INDEX_TYPE_DOUBLE,
|
|
191
|
+
[IndexType.BOOL]: ProtoIndexType.INDEX_TYPE_BOOL,
|
|
192
|
+
[IndexType.DATETIME]: ProtoIndexType.INDEX_TYPE_DATETIME,
|
|
193
|
+
};
|
|
194
|
+
return { enable: true, type: types[index.type], indexKey: index.indexKey ?? "" };
|
|
195
|
+
}
|
|
196
|
+
function secondsDate(seconds) {
|
|
197
|
+
const milliseconds = Number(seconds * 1000n);
|
|
198
|
+
if (!Number.isSafeInteger(milliseconds)) {
|
|
199
|
+
throw new RangeError("Context timestamp exceeds JavaScript's safe Date range");
|
|
200
|
+
}
|
|
201
|
+
return new Date(milliseconds);
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=invocation-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invocation-context.js","sourceRoot":"","sources":["../../src/invocation-context.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,uDAAuD;AACvD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,wDAAwD;AAIxD,OAAO,EACL,eAAe,EACf,SAAS,IAAI,cAAc,GAS5B,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,YAAY,EAAE,SAAS,EAAkB,MAAM,kBAAkB,CAAC;A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CAAC;AAED,SAAS,WAAW,CAAC,OAAe;IAClC,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,GAAG,KAAM,CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,UAAU,CAAC,wDAAwD,CAAC,CAAC;IACjF,CAAC;IACD,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Attribute, AttributeMap } from "./persistence.js";
|
|
2
|
+
import type { RetryPolicy, StepDurability } from "./step.js";
|
|
3
|
+
export interface ClientOptions {
|
|
4
|
+
readonly serverAddress?: string;
|
|
5
|
+
readonly workerTarget?: WorkerTarget;
|
|
6
|
+
}
|
|
7
|
+
export declare const ActiveStepSearchMode: Readonly<{
|
|
8
|
+
readonly DEFAULT: "default";
|
|
9
|
+
readonly ALL: "all";
|
|
10
|
+
}>;
|
|
11
|
+
export type ActiveStepSearchMode = (typeof ActiveStepSearchMode)[keyof typeof ActiveStepSearchMode];
|
|
12
|
+
export declare const IdReusePolicy: Readonly<{
|
|
13
|
+
readonly DEFAULT: "default";
|
|
14
|
+
readonly ALLOW_IF_PREVIOUS_FAILED: "allowIfPreviousFailed";
|
|
15
|
+
readonly ALLOW_IF_NOT_RUNNING: "allowIfNotRunning";
|
|
16
|
+
readonly ALLOW_TERMINATE_IF_RUNNING: "allowTerminateIfRunning";
|
|
17
|
+
readonly DISALLOW: "disallow";
|
|
18
|
+
}>;
|
|
19
|
+
export type IdReusePolicy = (typeof IdReusePolicy)[keyof typeof IdReusePolicy];
|
|
20
|
+
export interface FlowConfig {
|
|
21
|
+
readonly activeStepSearchMode?: ActiveStepSearchMode;
|
|
22
|
+
readonly continueAsNewThreshold?: number;
|
|
23
|
+
readonly continueAsNewPageSizeBytes?: number;
|
|
24
|
+
readonly stepDurability?: StepDurability;
|
|
25
|
+
readonly workerTarget?: WorkerTarget;
|
|
26
|
+
}
|
|
27
|
+
export interface InitialAttribute<T> {
|
|
28
|
+
readonly attribute: Attribute<T> | AttributeMap<T>;
|
|
29
|
+
readonly instance?: string;
|
|
30
|
+
readonly value: T;
|
|
31
|
+
}
|
|
32
|
+
export declare const InitialAttribute: Readonly<{
|
|
33
|
+
of<T>(attribute: Attribute<T>, value: T): InitialAttribute<T>;
|
|
34
|
+
mapValue<T>(attribute: AttributeMap<T>, instance: string, value: T): InitialAttribute<T>;
|
|
35
|
+
}>;
|
|
36
|
+
export interface StartFlowOptions {
|
|
37
|
+
readonly timeoutMs?: number;
|
|
38
|
+
readonly startDelayMs?: number;
|
|
39
|
+
readonly idReusePolicy?: IdReusePolicy;
|
|
40
|
+
readonly cronSchedule?: string;
|
|
41
|
+
readonly retryPolicy?: RetryPolicy;
|
|
42
|
+
readonly attributes?: readonly InitialAttribute<any>[];
|
|
43
|
+
readonly configOverride?: FlowConfig;
|
|
44
|
+
readonly ignoreAlreadyStarted?: boolean;
|
|
45
|
+
readonly requestId?: string;
|
|
46
|
+
}
|
|
47
|
+
export type FlowStatus = "running" | "completed" | "failed" | "cancelled" | "terminated" | "timedOut" | "continuedAsNew";
|
|
48
|
+
export interface FlowInfo {
|
|
49
|
+
readonly flowId: string;
|
|
50
|
+
readonly runId: string;
|
|
51
|
+
readonly flowType: string;
|
|
52
|
+
readonly status: FlowStatus;
|
|
53
|
+
readonly startedAt: Date;
|
|
54
|
+
}
|
|
55
|
+
export interface StepExecutionId {
|
|
56
|
+
readonly stepType: string;
|
|
57
|
+
readonly number?: number;
|
|
58
|
+
}
|
|
59
|
+
export declare const StepExecutionId: Readonly<{
|
|
60
|
+
of(stepType: string, number?: number): StepExecutionId;
|
|
61
|
+
}>;
|
|
62
|
+
export interface TimerId {
|
|
63
|
+
readonly conditionId?: string;
|
|
64
|
+
readonly conditionIndex?: number;
|
|
65
|
+
}
|
|
66
|
+
export declare const TimerId: Readonly<{
|
|
67
|
+
byConditionId(conditionId: string): TimerId;
|
|
68
|
+
byConditionIndex(conditionIndex: number): TimerId;
|
|
69
|
+
}>;
|
|
70
|
+
export declare const ResetType: Readonly<{
|
|
71
|
+
readonly BEGINNING: "beginning";
|
|
72
|
+
readonly HISTORY_EVENT_ID: "historyEventId";
|
|
73
|
+
readonly HISTORY_EVENT_TIME: "historyEventTime";
|
|
74
|
+
readonly STEP_TYPE: "stepType";
|
|
75
|
+
readonly STEP_EXECUTION_ID: "stepExecutionId";
|
|
76
|
+
}>;
|
|
77
|
+
export type ResetType = (typeof ResetType)[keyof typeof ResetType];
|
|
78
|
+
export interface ResetFlowOptions {
|
|
79
|
+
readonly type: ResetType;
|
|
80
|
+
readonly historyEventId?: bigint;
|
|
81
|
+
readonly historyEventTime?: Date;
|
|
82
|
+
readonly stepType?: string;
|
|
83
|
+
readonly stepExecutionId?: string;
|
|
84
|
+
readonly reason?: string;
|
|
85
|
+
readonly skipChannelMessagesReapply?: boolean;
|
|
86
|
+
readonly skipLockingRpcReapply?: boolean;
|
|
87
|
+
}
|
|
88
|
+
export declare const StopType: Readonly<{
|
|
89
|
+
readonly CANCEL: "cancel";
|
|
90
|
+
readonly TERMINATE: "terminate";
|
|
91
|
+
readonly FAIL: "fail";
|
|
92
|
+
}>;
|
|
93
|
+
export type StopType = (typeof StopType)[keyof typeof StopType];
|
|
94
|
+
export interface StopFlowOptions {
|
|
95
|
+
readonly type?: StopType;
|
|
96
|
+
readonly reason?: string;
|
|
97
|
+
}
|
|
98
|
+
export interface WorkerOptions {
|
|
99
|
+
readonly bindAddress?: string;
|
|
100
|
+
readonly workerTarget?: WorkerTarget;
|
|
101
|
+
readonly serverAddress?: string;
|
|
102
|
+
}
|
|
103
|
+
export interface WorkerTarget {
|
|
104
|
+
readonly address: string;
|
|
105
|
+
readonly headless?: boolean;
|
|
106
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Super Durable Source License 1.0.
|
|
4
|
+
// You may not use this file except in compliance with the License.
|
|
5
|
+
// See the LICENSE file in the repository root.
|
|
6
|
+
//
|
|
7
|
+
// SPDX-License-Identifier: LicenseRef-Super-Durable-1.0
|
|
8
|
+
import { requireName } from "./validation.js";
|
|
9
|
+
export const ActiveStepSearchMode = Object.freeze({
|
|
10
|
+
DEFAULT: "default",
|
|
11
|
+
ALL: "all",
|
|
12
|
+
});
|
|
13
|
+
export const IdReusePolicy = Object.freeze({
|
|
14
|
+
DEFAULT: "default",
|
|
15
|
+
ALLOW_IF_PREVIOUS_FAILED: "allowIfPreviousFailed",
|
|
16
|
+
ALLOW_IF_NOT_RUNNING: "allowIfNotRunning",
|
|
17
|
+
ALLOW_TERMINATE_IF_RUNNING: "allowTerminateIfRunning",
|
|
18
|
+
DISALLOW: "disallow",
|
|
19
|
+
});
|
|
20
|
+
export const InitialAttribute = Object.freeze({
|
|
21
|
+
of(attribute, value) {
|
|
22
|
+
return { attribute, value };
|
|
23
|
+
},
|
|
24
|
+
mapValue(attribute, instance, value) {
|
|
25
|
+
requireName(instance);
|
|
26
|
+
return { attribute, instance, value };
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
export const StepExecutionId = Object.freeze({
|
|
30
|
+
of(stepType, number) {
|
|
31
|
+
return { stepType, number: number ?? 1 };
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
export const TimerId = Object.freeze({
|
|
35
|
+
byConditionId(conditionId) {
|
|
36
|
+
requireName(conditionId);
|
|
37
|
+
return { conditionId };
|
|
38
|
+
},
|
|
39
|
+
byConditionIndex(conditionIndex) {
|
|
40
|
+
return { conditionIndex };
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
export const ResetType = Object.freeze({
|
|
44
|
+
BEGINNING: "beginning",
|
|
45
|
+
HISTORY_EVENT_ID: "historyEventId",
|
|
46
|
+
HISTORY_EVENT_TIME: "historyEventTime",
|
|
47
|
+
STEP_TYPE: "stepType",
|
|
48
|
+
STEP_EXECUTION_ID: "stepExecutionId",
|
|
49
|
+
});
|
|
50
|
+
export const StopType = Object.freeze({
|
|
51
|
+
CANCEL: "cancel",
|
|
52
|
+
TERMINATE: "terminate",
|
|
53
|
+
FAIL: "fail",
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/options.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,uDAAuD;AACvD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,wDAAwD;AAIxD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAO9C,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC;IAChD,OAAO,EAAE,SAAS;IAClB,GAAG,EAAE,KAAK;CACF,CAAC,CAAC;AAKZ,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IACzC,OAAO,EAAE,SAAS;IAClB,wBAAwB,EAAE,uBAAuB;IACjD,oBAAoB,EAAE,mBAAmB;IACzC,0BAA0B,EAAE,yBAAyB;IACrD,QAAQ,EAAE,UAAU;CACZ,CAAC,CAAC;AAkBZ,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5C,EAAE,CAAI,SAAuB,EAAE,KAAQ;QACrC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;IACD,QAAQ,CACN,SAA0B,EAC1B,QAAgB,EAChB,KAAQ;QAER,WAAW,CAAC,QAAQ,CAAC,CAAC;QACtB,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IACxC,CAAC;CACF,CAAC,CAAC;AAoCH,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3C,EAAE,CAAC,QAAgB,EAAE,MAAe;QAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC,EAAE,CAAC;IAC3C,CAAC;CACF,CAAC,CAAC;AAOH,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;IACnC,aAAa,CAAC,WAAmB;QAC/B,WAAW,CAAC,WAAW,CAAC,CAAC;QACzB,OAAO,EAAE,WAAW,EAAE,CAAC;IACzB,CAAC;IACD,gBAAgB,CAAC,cAAsB;QACrC,OAAO,EAAE,cAAc,EAAE,CAAC;IAC5B,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;IACrC,SAAS,EAAE,WAAW;IACtB,gBAAgB,EAAE,gBAAgB;IAClC,kBAAkB,EAAE,kBAAkB;IACtC,SAAS,EAAE,UAAU;IACrB,iBAAiB,EAAE,iBAAiB;CAC5B,CAAC,CAAC;AAeZ,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,MAAM,EAAE,QAAQ;IAChB,SAAS,EAAE,WAAW;IACtB,IAAI,EAAE,MAAM;CACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Channel, ChannelMap } from "./wait.js";
|
|
2
|
+
import type { Codec } from "./codec.js";
|
|
3
|
+
import type { Context } from "./context.js";
|
|
4
|
+
export declare const IndexType: Readonly<{
|
|
5
|
+
readonly KEYWORD: "keyword";
|
|
6
|
+
readonly FULL_TEXT: "fullText";
|
|
7
|
+
readonly KEYWORD_ARRAY: "keywordArray";
|
|
8
|
+
readonly INT: "int";
|
|
9
|
+
readonly DOUBLE: "double";
|
|
10
|
+
readonly BOOL: "bool";
|
|
11
|
+
readonly DATETIME: "datetime";
|
|
12
|
+
}>;
|
|
13
|
+
export type IndexType = (typeof IndexType)[keyof typeof IndexType];
|
|
14
|
+
export interface AttributeIndex {
|
|
15
|
+
readonly type: IndexType;
|
|
16
|
+
readonly indexKey?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface AttributeLock {
|
|
19
|
+
readonly attribute: Attribute<unknown> | AttributeMap<unknown>;
|
|
20
|
+
readonly instance?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare class Attribute<T> {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly codec: Codec<T>;
|
|
25
|
+
readonly index?: AttributeIndex | undefined;
|
|
26
|
+
constructor(name: string, codec: Codec<T>, index?: AttributeIndex | undefined);
|
|
27
|
+
get(context: Context): T;
|
|
28
|
+
set(context: Context, value: T): void;
|
|
29
|
+
delete(context: Context): void;
|
|
30
|
+
lock(): AttributeLock;
|
|
31
|
+
}
|
|
32
|
+
export declare class AttributeMap<T> {
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly codec: Codec<T>;
|
|
35
|
+
readonly index?: AttributeIndex | undefined;
|
|
36
|
+
constructor(name: string, codec: Codec<T>, index?: AttributeIndex | undefined);
|
|
37
|
+
get(context: Context, instance: string): T;
|
|
38
|
+
set(context: Context, instance: string, value: T): void;
|
|
39
|
+
delete(context: Context, instance: string): void;
|
|
40
|
+
lock(instance: string): AttributeLock;
|
|
41
|
+
}
|
|
42
|
+
export interface PersistenceSchema {
|
|
43
|
+
readonly attributes?: readonly (Attribute<unknown> | AttributeMap<unknown>)[];
|
|
44
|
+
readonly channels?: readonly (Channel<unknown> | ChannelMap<unknown>)[];
|
|
45
|
+
}
|