@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,65 @@
|
|
|
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 IndexType = Object.freeze({
|
|
10
|
+
KEYWORD: "keyword",
|
|
11
|
+
FULL_TEXT: "fullText",
|
|
12
|
+
KEYWORD_ARRAY: "keywordArray",
|
|
13
|
+
INT: "int",
|
|
14
|
+
DOUBLE: "double",
|
|
15
|
+
BOOL: "bool",
|
|
16
|
+
DATETIME: "datetime",
|
|
17
|
+
});
|
|
18
|
+
export class Attribute {
|
|
19
|
+
name;
|
|
20
|
+
codec;
|
|
21
|
+
index;
|
|
22
|
+
constructor(name, codec, index) {
|
|
23
|
+
this.name = name;
|
|
24
|
+
this.codec = codec;
|
|
25
|
+
this.index = index;
|
|
26
|
+
requireName(name);
|
|
27
|
+
}
|
|
28
|
+
get(context) {
|
|
29
|
+
return context.getAttribute(this);
|
|
30
|
+
}
|
|
31
|
+
set(context, value) {
|
|
32
|
+
context.setAttribute(this, value);
|
|
33
|
+
}
|
|
34
|
+
delete(context) {
|
|
35
|
+
context.deleteAttribute(this);
|
|
36
|
+
}
|
|
37
|
+
lock() {
|
|
38
|
+
return { attribute: this };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export class AttributeMap {
|
|
42
|
+
name;
|
|
43
|
+
codec;
|
|
44
|
+
index;
|
|
45
|
+
constructor(name, codec, index) {
|
|
46
|
+
this.name = name;
|
|
47
|
+
this.codec = codec;
|
|
48
|
+
this.index = index;
|
|
49
|
+
requireName(name);
|
|
50
|
+
}
|
|
51
|
+
get(context, instance) {
|
|
52
|
+
return context.getAttribute(this, instance);
|
|
53
|
+
}
|
|
54
|
+
set(context, instance, value) {
|
|
55
|
+
context.setAttribute(this, value, instance);
|
|
56
|
+
}
|
|
57
|
+
delete(context, instance) {
|
|
58
|
+
context.deleteAttribute(this, instance);
|
|
59
|
+
}
|
|
60
|
+
lock(instance) {
|
|
61
|
+
requireName(instance);
|
|
62
|
+
return { attribute: this, instance };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=persistence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistence.js","sourceRoot":"","sources":["../../src/persistence.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,uDAAuD;AACvD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,wDAAwD;AA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,CAAC;IAEM,GAAG,CAAC,OAAgB,EAAE,QAAgB,EAAE,KAAQ;QACrD,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC9C,CAAC;IAEM,MAAM,CAAC,OAAgB,EAAE,QAAgB;QAC9C,OAAO,CAAC,eAAe,CAAC,IAA6B,EAAE,QAAQ,CAAC,CAAC;IACnE,CAAC;IAEM,IAAI,CAAC,QAAgB;QAC1B,WAAW,CAAC,QAAQ,CAAC,CAAC;QACtB,OAAO,EAAE,SAAS,EAAE,IAA6B,EAAE,QAAQ,EAAE,CAAC;IAChE,CAAC;CACF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Codec } from "./codec.js";
|
|
2
|
+
import type { Context } from "./context.js";
|
|
3
|
+
import type { Flow } from "./flow.js";
|
|
4
|
+
import type { AttributeLock } from "./persistence.js";
|
|
5
|
+
import type { StepMovement } from "./step.js";
|
|
6
|
+
export interface RPCResult<Output> {
|
|
7
|
+
readonly output: Output;
|
|
8
|
+
readonly nextSteps?: readonly StepMovement<unknown>[];
|
|
9
|
+
}
|
|
10
|
+
export type RPC<Input, Output> = (context: Context, input: Input) => RPCResult<Output>;
|
|
11
|
+
export interface RPCOptions<Input = unknown, Output = unknown> {
|
|
12
|
+
readonly name?: string;
|
|
13
|
+
readonly inputCodec?: Codec<Input>;
|
|
14
|
+
readonly outputCodec?: Codec<Output>;
|
|
15
|
+
readonly timeoutMs?: number;
|
|
16
|
+
readonly lockAttributes?: readonly AttributeLock[];
|
|
17
|
+
}
|
|
18
|
+
export interface RegisteredRPC {
|
|
19
|
+
readonly method: Function;
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly options: RPCOptions<any, any>;
|
|
22
|
+
}
|
|
23
|
+
export declare function rpc<Input, Output>(options: RPCOptions<Input, Output> & {
|
|
24
|
+
readonly inputCodec: Codec<Input>;
|
|
25
|
+
readonly outputCodec: Codec<Output>;
|
|
26
|
+
}): <This>(method: (this: This, context: Context, input: Input) => RPCResult<Output>, context: ClassMethodDecoratorContext<This, (this: This, context: Context, input: Input) => RPCResult<Output>>) => void;
|
|
27
|
+
export declare function rpc<Output>(options: RPCOptions<never, Output> & {
|
|
28
|
+
readonly inputCodec?: never;
|
|
29
|
+
readonly outputCodec: Codec<Output>;
|
|
30
|
+
}): <This>(method: (this: This, context: Context) => RPCResult<Output>, context: ClassMethodDecoratorContext<This, (this: This, context: Context) => RPCResult<Output>>) => void;
|
|
31
|
+
export declare function rpc<Input>(options: RPCOptions<Input, never> & {
|
|
32
|
+
readonly inputCodec: Codec<Input>;
|
|
33
|
+
readonly outputCodec?: never;
|
|
34
|
+
}): <This>(method: (this: This, context: Context, input: Input) => void, context: ClassMethodDecoratorContext<This, (this: This, context: Context, input: Input) => void>) => void;
|
|
35
|
+
export declare function rpc(options?: RPCOptions<never, never> & {
|
|
36
|
+
readonly inputCodec?: never;
|
|
37
|
+
readonly outputCodec?: never;
|
|
38
|
+
}): <This>(method: (this: This, context: Context) => void, context: ClassMethodDecoratorContext<This, (this: This, context: Context) => void>) => void;
|
|
39
|
+
export declare function registeredRPCs(flow: Flow<unknown>): readonly RegisteredRPC[];
|
package/dist/src/rpc.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
const rpcOptions = new WeakMap();
|
|
10
|
+
export function rpc(options = {}) {
|
|
11
|
+
if (options.name !== undefined) {
|
|
12
|
+
requireName(options.name);
|
|
13
|
+
}
|
|
14
|
+
if (options.timeoutMs !== undefined && options.timeoutMs < 0) {
|
|
15
|
+
throw new RangeError("RPC timeout must be non-negative");
|
|
16
|
+
}
|
|
17
|
+
const immutableOptions = Object.freeze({ ...options });
|
|
18
|
+
return function (method, _context) {
|
|
19
|
+
rpcOptions.set(method, immutableOptions);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function registeredRPCs(flow) {
|
|
23
|
+
const registered = [];
|
|
24
|
+
const visitedNames = new Set();
|
|
25
|
+
let prototype = Object.getPrototypeOf(flow);
|
|
26
|
+
while (prototype !== null && prototype !== Object.prototype) {
|
|
27
|
+
for (const name of Object.getOwnPropertyNames(prototype)) {
|
|
28
|
+
if (name === "constructor" || visitedNames.has(name)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
visitedNames.add(name);
|
|
32
|
+
const method = Object.getOwnPropertyDescriptor(prototype, name)?.value;
|
|
33
|
+
if (typeof method !== "function") {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const options = rpcOptions.get(method);
|
|
37
|
+
if (options === undefined) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
registered.push({
|
|
41
|
+
method,
|
|
42
|
+
name: options.name ?? name,
|
|
43
|
+
options,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
47
|
+
}
|
|
48
|
+
return registered;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=rpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../src/rpc.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,iBAAiB,CAAC;AAuB9C,MAAM,UAAU,GAAG,IAAI,OAAO,EAAkC,CAAC;AAwCjE,MAAM,UAAU,GAAG,CAAC,UAAgC,EAAE;IACpD,IAAI,OAAO,CAAC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AAE,CAAC;gBAC1B,SAAS;YACX,CAAC;YACD,UAAU,CAAC,IAAI,CAAC;gBACd,MAAM;gBACN,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI;gBAC1B,OAAO;aACR,CAAC,CAAC;QACL,CAAC;QACD,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,SAAS,CAAkB,CAAC;IAChE,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Codec } from "./codec.js";
|
|
2
|
+
import type { Context } from "./context.js";
|
|
3
|
+
import type { AttributeLock } from "./persistence.js";
|
|
4
|
+
import type { Channel, ChannelMap, Wait } from "./wait.js";
|
|
5
|
+
export type StepDurability = "sync" | "async";
|
|
6
|
+
export type WaitForFailurePolicy = "failFlow" | "proceed";
|
|
7
|
+
export interface RetryPolicy {
|
|
8
|
+
readonly initialIntervalMs?: number;
|
|
9
|
+
readonly backoffCoefficient?: number;
|
|
10
|
+
readonly maximumIntervalMs?: number;
|
|
11
|
+
readonly maximumAttempts?: number;
|
|
12
|
+
readonly totalDurationMs?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ExecuteFailure {
|
|
15
|
+
readonly step: Step<unknown>;
|
|
16
|
+
readonly options?: StepOptions;
|
|
17
|
+
}
|
|
18
|
+
export declare const ExecuteFailure: Readonly<{
|
|
19
|
+
proceedTo<Input>(step: Step<Input>, options?: StepOptions): ExecuteFailure;
|
|
20
|
+
}>;
|
|
21
|
+
export interface StepOptions {
|
|
22
|
+
readonly waitForMethodTimeoutMs?: number;
|
|
23
|
+
readonly executeMethodTimeoutMs?: number;
|
|
24
|
+
readonly waitForRetry?: RetryPolicy;
|
|
25
|
+
readonly executeRetry?: RetryPolicy;
|
|
26
|
+
readonly waitForFailure?: WaitForFailurePolicy;
|
|
27
|
+
readonly waitForDurability?: StepDurability;
|
|
28
|
+
readonly executeDurability?: StepDurability;
|
|
29
|
+
readonly waitForLockAttributes?: readonly AttributeLock[];
|
|
30
|
+
readonly executeLockAttributes?: readonly AttributeLock[];
|
|
31
|
+
readonly executeFailure?: ExecuteFailure;
|
|
32
|
+
}
|
|
33
|
+
export interface Step<Input> {
|
|
34
|
+
readonly inputCodec: Codec<Input>;
|
|
35
|
+
getStepType(): string;
|
|
36
|
+
getStepOptions?(): StepOptions | undefined;
|
|
37
|
+
waitFor?(context: Context, input: Input): Wait;
|
|
38
|
+
execute(context: Context, input: Input): StepDecision;
|
|
39
|
+
}
|
|
40
|
+
interface StartStepDefinition<StartInput> {
|
|
41
|
+
readonly step: Step<StartInput>;
|
|
42
|
+
readonly isStartStep: true;
|
|
43
|
+
}
|
|
44
|
+
interface NonStartStepDefinition {
|
|
45
|
+
readonly step: Step<unknown>;
|
|
46
|
+
readonly isStartStep: false;
|
|
47
|
+
}
|
|
48
|
+
type StepDefinition = StartStepDefinition<unknown> | NonStartStepDefinition;
|
|
49
|
+
declare const startInputType: unique symbol;
|
|
50
|
+
export declare class StepList<StartInput> {
|
|
51
|
+
readonly [startInputType]: (input: StartInput) => StartInput;
|
|
52
|
+
private readonly definitions;
|
|
53
|
+
private constructor();
|
|
54
|
+
static empty<StartInput = void>(): StepList<StartInput>;
|
|
55
|
+
static startStep<StartInput>(step: Step<StartInput>): StepList<StartInput>;
|
|
56
|
+
static withoutStartStep<StartInput = never>(...steps: readonly Step<any>[]): StepList<StartInput>;
|
|
57
|
+
otherSteps(...steps: readonly Step<any>[]): StepList<StartInput>;
|
|
58
|
+
[Symbol.iterator](): Iterator<StepDefinition>;
|
|
59
|
+
}
|
|
60
|
+
export interface StepMovement<Input> {
|
|
61
|
+
readonly step: Step<Input>;
|
|
62
|
+
readonly input: Input;
|
|
63
|
+
readonly options?: StepOptions;
|
|
64
|
+
}
|
|
65
|
+
export declare const StepMovement: Readonly<{
|
|
66
|
+
of<Input>(step: Step<Input>, input: Input, options?: StepOptions): StepMovement<Input>;
|
|
67
|
+
}>;
|
|
68
|
+
export type StepDecision = Readonly<{
|
|
69
|
+
kind: "next";
|
|
70
|
+
movements: readonly StepMovement<unknown>[];
|
|
71
|
+
}> | Readonly<{
|
|
72
|
+
kind: "gracefulComplete" | "forceComplete";
|
|
73
|
+
output: unknown;
|
|
74
|
+
}> | Readonly<{
|
|
75
|
+
kind: "forceCompleteIfChannelsEmpty";
|
|
76
|
+
output: unknown;
|
|
77
|
+
fallback: StepMovement<unknown>;
|
|
78
|
+
channels: readonly (Channel<unknown> | ChannelMap<unknown>)[];
|
|
79
|
+
}> | Readonly<{
|
|
80
|
+
kind: "forceFail";
|
|
81
|
+
reason: string;
|
|
82
|
+
}> | Readonly<{
|
|
83
|
+
kind: "deadEnd";
|
|
84
|
+
}>;
|
|
85
|
+
export declare const goTo: <Input>(step: Step<Input>, input: Input) => StepDecision;
|
|
86
|
+
export declare const goToMulti: (...movements: readonly StepMovement<unknown>[]) => StepDecision;
|
|
87
|
+
export declare const gracefulComplete: (output?: unknown) => StepDecision;
|
|
88
|
+
export declare const forceComplete: (output?: unknown) => StepDecision;
|
|
89
|
+
export declare const forceCompleteWhenChannelsEmpty: (output: unknown, fallback: StepMovement<unknown>, ...channels: readonly (Channel<unknown> | ChannelMap<unknown>)[]) => StepDecision;
|
|
90
|
+
export declare const forceFail: (reason: string) => StepDecision;
|
|
91
|
+
export declare const deadEnd: () => StepDecision;
|
|
92
|
+
export {};
|
package/dist/src/step.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
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 const ExecuteFailure = Object.freeze({
|
|
9
|
+
proceedTo(step, options) {
|
|
10
|
+
return {
|
|
11
|
+
step: step,
|
|
12
|
+
...(options === undefined ? {} : { options }),
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
export class StepList {
|
|
17
|
+
definitions;
|
|
18
|
+
constructor(definitions) {
|
|
19
|
+
this.definitions = Object.freeze([...definitions]);
|
|
20
|
+
}
|
|
21
|
+
static empty() {
|
|
22
|
+
return new StepList([]);
|
|
23
|
+
}
|
|
24
|
+
static startStep(step) {
|
|
25
|
+
return new StepList([{ step: step, isStartStep: true }]);
|
|
26
|
+
}
|
|
27
|
+
static withoutStartStep(...steps) {
|
|
28
|
+
return new StepList(steps.map((step) => ({ step: step, isStartStep: false })));
|
|
29
|
+
}
|
|
30
|
+
otherSteps(...steps) {
|
|
31
|
+
return new StepList([
|
|
32
|
+
...this.definitions,
|
|
33
|
+
...steps.map((step) => ({ step: step, isStartStep: false })),
|
|
34
|
+
]);
|
|
35
|
+
}
|
|
36
|
+
[Symbol.iterator]() {
|
|
37
|
+
return this.definitions[Symbol.iterator]();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export const StepMovement = Object.freeze({
|
|
41
|
+
of(step, input, options) {
|
|
42
|
+
return {
|
|
43
|
+
step,
|
|
44
|
+
input,
|
|
45
|
+
...(options === undefined ? {} : { options }),
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
export const goTo = (step, input) => goToMulti(StepMovement.of(step, input));
|
|
50
|
+
export const goToMulti = (...movements) => ({
|
|
51
|
+
kind: "next",
|
|
52
|
+
movements,
|
|
53
|
+
});
|
|
54
|
+
export const gracefulComplete = (output) => ({
|
|
55
|
+
kind: "gracefulComplete",
|
|
56
|
+
output,
|
|
57
|
+
});
|
|
58
|
+
export const forceComplete = (output) => ({ kind: "forceComplete", output });
|
|
59
|
+
export const forceCompleteWhenChannelsEmpty = (output, fallback, ...channels) => ({ kind: "forceCompleteIfChannelsEmpty", output, fallback, channels });
|
|
60
|
+
export const forceFail = (reason) => ({ kind: "forceFail", reason });
|
|
61
|
+
export const deadEnd = ()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QAA+B,EAC/B,GAAG,QAA6D,EAClD,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,8BAA8B,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;AAE1F,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,MAAc,EAAgB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;AAE3F,MAAM,CAAC,MAAM,OAAO,GAAG,GAAiB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 function requireName(name) {
|
|
9
|
+
if (name.trim().length === 0) {
|
|
10
|
+
throw new TypeError("durable name is required");
|
|
11
|
+
}
|
|
12
|
+
return name;
|
|
13
|
+
}
|
|
14
|
+
export function requireConditionId(conditionId) {
|
|
15
|
+
if (conditionId !== undefined && conditionId.length === 0) {
|
|
16
|
+
throw new TypeError("condition ID must not be empty");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function validateChannelBounds(atLeast, atMost) {
|
|
20
|
+
if (atLeast === undefined && atMost === undefined) {
|
|
21
|
+
throw new RangeError("channel condition requires a bound");
|
|
22
|
+
}
|
|
23
|
+
if (atLeast !== undefined && atLeast < 0) {
|
|
24
|
+
throw new RangeError("atLeast must be non-negative");
|
|
25
|
+
}
|
|
26
|
+
if (atMost !== undefined && atMost < 0) {
|
|
27
|
+
throw new RangeError("atMost must be non-negative");
|
|
28
|
+
}
|
|
29
|
+
if (atLeast !== undefined && atMost !== undefined && atMost < atLeast) {
|
|
30
|
+
throw new RangeError("atMost must not be below atLeast");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,uDAAuD;AACvD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,wDAAwD;AAExD,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,SAAS,CAAC,0BAA0B,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,WAA+B;IAChE,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1D,MAAM,IAAI,SAAS,CAAC,gCAAgC,CAAC,CAAC;IACxD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,OAA2B,EAC3B,MAA0B;IAE1B,IAAI,OAAO,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAClD,MAAM,IAAI,UAAU,CAAC,oCAAoC,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,UAAU,CAAC,8BAA8B,CAAC,CAAC;IACvD,CAAC;IACD,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,UAAU,CAAC,6BAA6B,CAAC,CAAC;IACtD,CAAC;IACD,IAAI,OAAO,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,GAAG,OAAO,EAAE,CAAC;QACtE,MAAM,IAAI,UAAU,CAAC,kCAAkC,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BlobCache } from "./blob-cache.js";
|
|
2
|
+
import type { Codec } from "./codec.js";
|
|
3
|
+
import { Value as ProtoValue, type FlowServiceClient } from "./gen/dex.js";
|
|
4
|
+
export declare function encodeValue<T>(codec: Codec<T>, value: T): ProtoValue;
|
|
5
|
+
export declare function encodeUnknown(value: unknown): ProtoValue;
|
|
6
|
+
export declare function decodeValue<T>(codec: Codec<T>, value: ProtoValue): T;
|
|
7
|
+
export declare function deletionValue(): ProtoValue;
|
|
8
|
+
export declare class ValueHydrator {
|
|
9
|
+
private readonly service;
|
|
10
|
+
private readonly blobCache;
|
|
11
|
+
constructor(service: FlowServiceClient, blobCache: BlobCache);
|
|
12
|
+
hydrate(value: ProtoValue | undefined): Promise<ProtoValue>;
|
|
13
|
+
hydrateAll(values: readonly (ProtoValue | undefined)[]): Promise<ProtoValue[]>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
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 { NullValue } from "./gen/google/protobuf/struct.js";
|
|
9
|
+
import { Value as ProtoValue, } from "./gen/dex.js";
|
|
10
|
+
const textEncoder = new TextEncoder();
|
|
11
|
+
const textDecoder = new TextDecoder();
|
|
12
|
+
export function encodeValue(codec, value) {
|
|
13
|
+
if (value === undefined || value === null) {
|
|
14
|
+
return objectValue("json", textEncoder.encode("null"));
|
|
15
|
+
}
|
|
16
|
+
const encoded = codec.encode(value);
|
|
17
|
+
switch (encoded.kind) {
|
|
18
|
+
case "string":
|
|
19
|
+
return ProtoValue.create({ kind: { $case: "stringValue", value: encoded.data } });
|
|
20
|
+
case "bool":
|
|
21
|
+
return ProtoValue.create({ kind: { $case: "boolValue", value: encoded.data } });
|
|
22
|
+
case "int64":
|
|
23
|
+
return ProtoValue.create({ kind: { $case: "intValue", value: encoded.data } });
|
|
24
|
+
case "double":
|
|
25
|
+
return ProtoValue.create({ kind: { $case: "doubleValue", value: encoded.data } });
|
|
26
|
+
case "bytes":
|
|
27
|
+
return objectValue("rawbytes", encoded.data);
|
|
28
|
+
case "json":
|
|
29
|
+
return objectValue("json", textEncoder.encode(encoded.data));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function encodeUnknown(value) {
|
|
33
|
+
if (value === undefined || value === null) {
|
|
34
|
+
return objectValue("json", textEncoder.encode("null"));
|
|
35
|
+
}
|
|
36
|
+
if (typeof value === "string") {
|
|
37
|
+
return ProtoValue.create({ kind: { $case: "stringValue", value } });
|
|
38
|
+
}
|
|
39
|
+
if (typeof value === "boolean") {
|
|
40
|
+
return ProtoValue.create({ kind: { $case: "boolValue", value } });
|
|
41
|
+
}
|
|
42
|
+
if (typeof value === "bigint") {
|
|
43
|
+
return ProtoValue.create({ kind: { $case: "intValue", value } });
|
|
44
|
+
}
|
|
45
|
+
if (typeof value === "number") {
|
|
46
|
+
if (!Number.isFinite(value)) {
|
|
47
|
+
throw new RangeError("non-finite numbers are unsupported");
|
|
48
|
+
}
|
|
49
|
+
return ProtoValue.create({ kind: { $case: "doubleValue", value } });
|
|
50
|
+
}
|
|
51
|
+
if (value instanceof Uint8Array) {
|
|
52
|
+
return objectValue("rawbytes", value);
|
|
53
|
+
}
|
|
54
|
+
const json = JSON.stringify(value);
|
|
55
|
+
if (json === undefined) {
|
|
56
|
+
throw new TypeError("value cannot be encoded as JSON");
|
|
57
|
+
}
|
|
58
|
+
return objectValue("json", textEncoder.encode(json));
|
|
59
|
+
}
|
|
60
|
+
export function decodeValue(codec, value) {
|
|
61
|
+
if (value.kind?.$case === "objValue" &&
|
|
62
|
+
value.kind.value.encoding === "json" &&
|
|
63
|
+
textDecoder.decode(value.kind.value.payload) === "null") {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
return codec.decode(toCodecValue(value));
|
|
67
|
+
}
|
|
68
|
+
export function deletionValue() {
|
|
69
|
+
return ProtoValue.create({
|
|
70
|
+
kind: { $case: "nullValue", value: NullValue.NULL_VALUE },
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
export class ValueHydrator {
|
|
74
|
+
service;
|
|
75
|
+
blobCache;
|
|
76
|
+
constructor(service, blobCache) {
|
|
77
|
+
this.service = service;
|
|
78
|
+
this.blobCache = blobCache;
|
|
79
|
+
}
|
|
80
|
+
async hydrate(value) {
|
|
81
|
+
if (value?.kind === undefined) {
|
|
82
|
+
throw new TypeError("Value has no concrete kind");
|
|
83
|
+
}
|
|
84
|
+
const blobId = blobIdOf(value);
|
|
85
|
+
if (blobId === undefined) {
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
const cached = this.blobCache.get(blobId);
|
|
89
|
+
if (cached !== undefined) {
|
|
90
|
+
return ProtoValue.decode(cached);
|
|
91
|
+
}
|
|
92
|
+
const response = await unary((callback) => this.service.loadBlobs({ values: [value] }, callback));
|
|
93
|
+
const hydrated = response.values[blobId];
|
|
94
|
+
if (hydrated?.kind === undefined || blobIdOf(hydrated) !== undefined) {
|
|
95
|
+
throw new TypeError(`Dex did not hydrate blob ${blobId}`);
|
|
96
|
+
}
|
|
97
|
+
this.blobCache.put(blobId, ProtoValue.encode(hydrated).finish());
|
|
98
|
+
return hydrated;
|
|
99
|
+
}
|
|
100
|
+
async hydrateAll(values) {
|
|
101
|
+
const hydrated = new Array(values.length);
|
|
102
|
+
const missing = new Map();
|
|
103
|
+
for (let index = 0; index < values.length; index += 1) {
|
|
104
|
+
const value = values[index];
|
|
105
|
+
if (value?.kind === undefined) {
|
|
106
|
+
throw new TypeError("Value has no concrete kind");
|
|
107
|
+
}
|
|
108
|
+
const blobId = blobIdOf(value);
|
|
109
|
+
if (blobId === undefined) {
|
|
110
|
+
hydrated[index] = value;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const cached = this.blobCache.get(blobId);
|
|
114
|
+
if (cached !== undefined) {
|
|
115
|
+
hydrated[index] = ProtoValue.decode(cached);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const pending = missing.get(blobId);
|
|
119
|
+
if (pending === undefined) {
|
|
120
|
+
missing.set(blobId, { value, indexes: [index] });
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
pending.indexes.push(index);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (missing.size > 0) {
|
|
127
|
+
const response = await unary((callback) => this.service.loadBlobs({ values: [...missing.values()].map((pending) => pending.value) }, callback));
|
|
128
|
+
for (const [blobId, pending] of missing) {
|
|
129
|
+
const value = response.values[blobId];
|
|
130
|
+
if (value?.kind === undefined || blobIdOf(value) !== undefined) {
|
|
131
|
+
throw new TypeError(`Dex did not hydrate blob ${blobId}`);
|
|
132
|
+
}
|
|
133
|
+
this.blobCache.put(blobId, ProtoValue.encode(value).finish());
|
|
134
|
+
for (const index of pending.indexes) {
|
|
135
|
+
hydrated[index] = value;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return hydrated.map((value) => {
|
|
140
|
+
if (value === undefined) {
|
|
141
|
+
throw new TypeError("Value hydration left an unresolved entry");
|
|
142
|
+
}
|
|
143
|
+
return value;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function objectValue(encoding, payload) {
|
|
148
|
+
return ProtoValue.create({
|
|
149
|
+
kind: { $case: "objValue", value: { encoding, payload } },
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function toCodecValue(value) {
|
|
153
|
+
const kind = value.kind;
|
|
154
|
+
if (kind === undefined) {
|
|
155
|
+
throw new TypeError("Value has no concrete kind");
|
|
156
|
+
}
|
|
157
|
+
switch (kind.$case) {
|
|
158
|
+
case "stringValue":
|
|
159
|
+
return { kind: "string", data: kind.value };
|
|
160
|
+
case "boolValue":
|
|
161
|
+
return { kind: "bool", data: kind.value };
|
|
162
|
+
case "intValue":
|
|
163
|
+
return { kind: "int64", data: kind.value };
|
|
164
|
+
case "doubleValue":
|
|
165
|
+
return { kind: "double", data: kind.value };
|
|
166
|
+
case "objValue":
|
|
167
|
+
if (kind.value.encoding === "rawbytes") {
|
|
168
|
+
return { kind: "bytes", data: kind.value.payload };
|
|
169
|
+
}
|
|
170
|
+
if (kind.value.encoding === "json") {
|
|
171
|
+
return { kind: "json", data: textDecoder.decode(kind.value.payload) };
|
|
172
|
+
}
|
|
173
|
+
throw new TypeError(`unsupported object encoding ${kind.value.encoding}`);
|
|
174
|
+
case "internalBlobIdForStringValue":
|
|
175
|
+
case "internalBlobIdForObjValue":
|
|
176
|
+
throw new TypeError("blob-backed Value was not hydrated");
|
|
177
|
+
case "nullValue":
|
|
178
|
+
throw new TypeError("attribute deletion marker cannot be decoded");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function blobIdOf(value) {
|
|
182
|
+
if (value.kind?.$case === "internalBlobIdForStringValue" ||
|
|
183
|
+
value.kind?.$case === "internalBlobIdForObjValue") {
|
|
184
|
+
return value.kind.value;
|
|
185
|
+
}
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
function unary(invoke) {
|
|
189
|
+
return new Promise((resolve, reject) => {
|
|
190
|
+
invoke((error, response) => {
|
|
191
|
+
if (error !== null) {
|
|
192
|
+
reject(error);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
resolve(response);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=value-mapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-mapper.js","sourceRoot":"","sources":["../../src/value-mapper.ts"],"names":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2B,EACjD,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;IAC1B,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,KAAK,CACZ,MAAgF;IAEhF,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;YACzB,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACnB,MAAM,CAAC,KAAK,CAAC,CAAC;gBACd,OAAO;YACT,CAAC;YACD,OAAO,CAAC,QAAQ,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Codec } from "./codec.js";
|
|
2
|
+
import type { Context } from "./context.js";
|
|
3
|
+
export interface Condition {
|
|
4
|
+
readonly kind: "timer" | "channel";
|
|
5
|
+
readonly conditionId?: string;
|
|
6
|
+
readonly durationMs?: number;
|
|
7
|
+
readonly channelName?: string;
|
|
8
|
+
readonly instance?: string;
|
|
9
|
+
readonly atLeast?: number;
|
|
10
|
+
readonly atMost?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ConditionCombination {
|
|
13
|
+
readonly conditions: readonly Condition[];
|
|
14
|
+
}
|
|
15
|
+
export declare const ConditionCombination: Readonly<{
|
|
16
|
+
of(...conditions: readonly Condition[]): ConditionCombination;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const Timer: Readonly<{
|
|
19
|
+
byDuration(durationMs: number, conditionId?: string): Condition;
|
|
20
|
+
}>;
|
|
21
|
+
export declare class Channel<T> {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly codec: Codec<T>;
|
|
24
|
+
constructor(name: string, codec: Codec<T>);
|
|
25
|
+
publish(context: Context, value: T): void;
|
|
26
|
+
size(context: Context): number;
|
|
27
|
+
results(context: Context): readonly T[];
|
|
28
|
+
forOne(conditionId?: string): Condition;
|
|
29
|
+
forN(count: number, conditionId?: string): Condition;
|
|
30
|
+
atLeast(count: number, conditionId?: string): Condition;
|
|
31
|
+
atMost(count: number, conditionId?: string): Condition;
|
|
32
|
+
range(atLeast?: number, atMost?: number, conditionId?: string): Condition;
|
|
33
|
+
}
|
|
34
|
+
export declare class ChannelMap<T> {
|
|
35
|
+
readonly name: string;
|
|
36
|
+
readonly codec: Codec<T>;
|
|
37
|
+
constructor(name: string, codec: Codec<T>);
|
|
38
|
+
publish(context: Context, instance: string, value: T): void;
|
|
39
|
+
size(context: Context, instance: string): number;
|
|
40
|
+
results(context: Context, instance: string): readonly T[];
|
|
41
|
+
forOne(instance: string, conditionId?: string): Condition;
|
|
42
|
+
forN(instance: string, count: number, conditionId?: string): Condition;
|
|
43
|
+
atLeast(instance: string, count: number, conditionId?: string): Condition;
|
|
44
|
+
atMost(instance: string, count: number, conditionId?: string): Condition;
|
|
45
|
+
range(instance: string, atLeast?: number, atMost?: number, conditionId?: string): Condition;
|
|
46
|
+
}
|
|
47
|
+
export type Wait = Readonly<{
|
|
48
|
+
kind: "skipImmediately" | "allOf" | "anyOf" | "anyCombinationOf";
|
|
49
|
+
conditions: readonly Condition[];
|
|
50
|
+
combinations: readonly ConditionCombination[];
|
|
51
|
+
}>;
|
|
52
|
+
export declare const Wait: Readonly<{
|
|
53
|
+
skipImmediately(): Wait;
|
|
54
|
+
allOf(...conditions: readonly Condition[]): Wait;
|
|
55
|
+
anyOf(...conditions: readonly Condition[]): Wait;
|
|
56
|
+
anyCombinationOf(...combinations: readonly ConditionCombination[]): Wait;
|
|
57
|
+
}>;
|