@sonamu-kit/tasks 0.1.3 → 0.3.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/.oxlintrc.json +3 -0
- package/AGENTS.md +21 -0
- package/dist/backend.d.ts +126 -103
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +4 -1
- package/dist/backend.js.map +1 -1
- package/dist/client.d.ts +145 -132
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +220 -212
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +15 -8
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +22 -17
- package/dist/config.js.map +1 -1
- package/dist/core/duration.d.ts +5 -4
- package/dist/core/duration.d.ts.map +1 -1
- package/dist/core/duration.js +54 -59
- package/dist/core/duration.js.map +1 -1
- package/dist/core/error.d.ts +10 -7
- package/dist/core/error.d.ts.map +1 -1
- package/dist/core/error.js +21 -21
- package/dist/core/error.js.map +1 -1
- package/dist/core/json.d.ts +8 -3
- package/dist/core/json.d.ts.map +1 -1
- package/dist/core/result.d.ts +10 -14
- package/dist/core/result.d.ts.map +1 -1
- package/dist/core/result.js +21 -16
- package/dist/core/result.js.map +1 -1
- package/dist/core/retry.d.ts +42 -20
- package/dist/core/retry.d.ts.map +1 -1
- package/dist/core/retry.js +49 -20
- package/dist/core/retry.js.map +1 -1
- package/dist/core/schema.d.ts +57 -53
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/step.d.ts +28 -78
- package/dist/core/step.d.ts.map +1 -1
- package/dist/core/step.js +53 -63
- package/dist/core/step.js.map +1 -1
- package/dist/core/workflow.d.ts +33 -61
- package/dist/core/workflow.d.ts.map +1 -1
- package/dist/core/workflow.js +31 -41
- package/dist/core/workflow.js.map +1 -1
- package/dist/database/backend.d.ts +53 -46
- package/dist/database/backend.d.ts.map +1 -1
- package/dist/database/backend.js +544 -545
- package/dist/database/backend.js.map +1 -1
- package/dist/database/base.js +48 -25
- package/dist/database/base.js.map +1 -1
- package/dist/database/migrations/20251212000000_0_init.d.ts +10 -0
- package/dist/database/migrations/20251212000000_0_init.d.ts.map +1 -0
- package/dist/database/migrations/20251212000000_0_init.js +8 -4
- package/dist/database/migrations/20251212000000_0_init.js.map +1 -1
- package/dist/database/migrations/20251212000000_1_tables.d.ts +10 -0
- package/dist/database/migrations/20251212000000_1_tables.d.ts.map +1 -0
- package/dist/database/migrations/20251212000000_1_tables.js +81 -83
- package/dist/database/migrations/20251212000000_1_tables.js.map +1 -1
- package/dist/database/migrations/20251212000000_2_fk.d.ts +10 -0
- package/dist/database/migrations/20251212000000_2_fk.d.ts.map +1 -0
- package/dist/database/migrations/20251212000000_2_fk.js +20 -43
- package/dist/database/migrations/20251212000000_2_fk.js.map +1 -1
- package/dist/database/migrations/20251212000000_3_indexes.d.ts +10 -0
- package/dist/database/migrations/20251212000000_3_indexes.d.ts.map +1 -0
- package/dist/database/migrations/20251212000000_3_indexes.js +88 -102
- package/dist/database/migrations/20251212000000_3_indexes.js.map +1 -1
- package/dist/database/pubsub.d.ts +7 -16
- package/dist/database/pubsub.d.ts.map +1 -1
- package/dist/database/pubsub.js +75 -73
- package/dist/database/pubsub.js.map +1 -1
- package/dist/execution.d.ts +20 -57
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +175 -174
- package/dist/execution.js.map +1 -1
- package/dist/index.d.ts +5 -8
- package/dist/index.js +5 -5
- package/dist/internal.d.ts +12 -12
- package/dist/internal.js +4 -4
- package/dist/registry.d.ts +33 -27
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +58 -49
- package/dist/registry.js.map +1 -1
- package/dist/worker.d.ts +57 -50
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +194 -198
- package/dist/worker.js.map +1 -1
- package/dist/workflow.d.ts +26 -27
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +20 -15
- package/dist/workflow.js.map +1 -1
- package/nodemon.json +1 -1
- package/package.json +18 -20
- package/src/backend.ts +28 -8
- package/src/chaos.test.ts +3 -1
- package/src/client.test.ts +2 -0
- package/src/client.ts +32 -8
- package/src/config.test.ts +1 -0
- package/src/config.ts +3 -2
- package/src/core/duration.test.ts +2 -1
- package/src/core/duration.ts +1 -1
- package/src/core/error.test.ts +1 -0
- package/src/core/error.ts +1 -1
- package/src/core/result.test.ts +1 -0
- package/src/core/retry.test.ts +181 -11
- package/src/core/retry.ts +95 -19
- package/src/core/schema.ts +2 -2
- package/src/core/step.test.ts +2 -1
- package/src/core/step.ts +4 -3
- package/src/core/workflow.test.ts +2 -1
- package/src/core/workflow.ts +4 -3
- package/src/database/backend.test.ts +1 -0
- package/src/database/backend.testsuite.ts +162 -39
- package/src/database/backend.ts +271 -35
- package/src/database/base.test.ts +41 -0
- package/src/database/base.ts +51 -2
- package/src/database/migrations/20251212000000_0_init.ts +2 -1
- package/src/database/migrations/20251212000000_1_tables.ts +2 -1
- package/src/database/migrations/20251212000000_2_fk.ts +2 -1
- package/src/database/migrations/20251212000000_3_indexes.ts +2 -1
- package/src/database/pubsub.test.ts +6 -3
- package/src/database/pubsub.ts +55 -33
- package/src/execution.test.ts +117 -0
- package/src/execution.ts +65 -10
- package/src/internal.ts +21 -1
- package/src/practices/01-remote-workflow.ts +1 -0
- package/src/registry.test.ts +1 -0
- package/src/registry.ts +1 -1
- package/src/testing/connection.ts +3 -1
- package/src/worker.test.ts +2 -0
- package/src/worker.ts +31 -9
- package/src/workflow.test.ts +1 -0
- package/src/workflow.ts +5 -2
- package/templates/openworkflow.config.ts +2 -1
- package/tsdown.config.ts +31 -0
- package/.swcrc +0 -17
- package/dist/chaos.test.d.ts +0 -2
- package/dist/chaos.test.d.ts.map +0 -1
- package/dist/chaos.test.js +0 -92
- package/dist/chaos.test.js.map +0 -1
- package/dist/client.test.d.ts +0 -2
- package/dist/client.test.d.ts.map +0 -1
- package/dist/client.test.js +0 -340
- package/dist/client.test.js.map +0 -1
- package/dist/config.test.d.ts +0 -2
- package/dist/config.test.d.ts.map +0 -1
- package/dist/config.test.js +0 -24
- package/dist/config.test.js.map +0 -1
- package/dist/core/duration.test.d.ts +0 -2
- package/dist/core/duration.test.d.ts.map +0 -1
- package/dist/core/duration.test.js +0 -265
- package/dist/core/duration.test.js.map +0 -1
- package/dist/core/error.test.d.ts +0 -2
- package/dist/core/error.test.d.ts.map +0 -1
- package/dist/core/error.test.js +0 -63
- package/dist/core/error.test.js.map +0 -1
- package/dist/core/json.js +0 -3
- package/dist/core/json.js.map +0 -1
- package/dist/core/result.test.d.ts +0 -2
- package/dist/core/result.test.d.ts.map +0 -1
- package/dist/core/result.test.js +0 -19
- package/dist/core/result.test.js.map +0 -1
- package/dist/core/retry.test.d.ts +0 -2
- package/dist/core/retry.test.d.ts.map +0 -1
- package/dist/core/retry.test.js +0 -37
- package/dist/core/retry.test.js.map +0 -1
- package/dist/core/schema.js +0 -4
- package/dist/core/schema.js.map +0 -1
- package/dist/core/step.test.d.ts +0 -2
- package/dist/core/step.test.d.ts.map +0 -1
- package/dist/core/step.test.js +0 -356
- package/dist/core/step.test.js.map +0 -1
- package/dist/core/workflow.test.d.ts +0 -2
- package/dist/core/workflow.test.d.ts.map +0 -1
- package/dist/core/workflow.test.js +0 -172
- package/dist/core/workflow.test.js.map +0 -1
- package/dist/database/backend.test.d.ts +0 -2
- package/dist/database/backend.test.d.ts.map +0 -1
- package/dist/database/backend.test.js +0 -19
- package/dist/database/backend.test.js.map +0 -1
- package/dist/database/backend.testsuite.d.ts +0 -20
- package/dist/database/backend.testsuite.d.ts.map +0 -1
- package/dist/database/backend.testsuite.js +0 -1174
- package/dist/database/backend.testsuite.js.map +0 -1
- package/dist/database/base.d.ts +0 -12
- package/dist/database/base.d.ts.map +0 -1
- package/dist/database/pubsub.test.d.ts +0 -2
- package/dist/database/pubsub.test.d.ts.map +0 -1
- package/dist/database/pubsub.test.js +0 -86
- package/dist/database/pubsub.test.js.map +0 -1
- package/dist/execution.test.d.ts +0 -2
- package/dist/execution.test.d.ts.map +0 -1
- package/dist/execution.test.js +0 -558
- package/dist/execution.test.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/internal.d.ts.map +0 -1
- package/dist/internal.js.map +0 -1
- package/dist/practices/01-remote-workflow.d.ts +0 -2
- package/dist/practices/01-remote-workflow.d.ts.map +0 -1
- package/dist/practices/01-remote-workflow.js +0 -70
- package/dist/practices/01-remote-workflow.js.map +0 -1
- package/dist/registry.test.d.ts +0 -2
- package/dist/registry.test.d.ts.map +0 -1
- package/dist/registry.test.js +0 -95
- package/dist/registry.test.js.map +0 -1
- package/dist/testing/connection.d.ts +0 -7
- package/dist/testing/connection.d.ts.map +0 -1
- package/dist/testing/connection.js +0 -39
- package/dist/testing/connection.js.map +0 -1
- package/dist/worker.test.d.ts +0 -2
- package/dist/worker.test.d.ts.map +0 -1
- package/dist/worker.test.js +0 -1164
- package/dist/worker.test.js.map +0 -1
- package/dist/workflow.test.d.ts +0 -2
- package/dist/workflow.test.d.ts.map +0 -1
- package/dist/workflow.test.js +0 -73
- package/dist/workflow.test.js.map +0 -1
package/dist/core/schema.d.ts
CHANGED
|
@@ -1,57 +1,61 @@
|
|
|
1
|
+
//#region src/core/schema.d.ts
|
|
1
2
|
/** The Standard Schema interface. https://standardschema.dev */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
4
|
+
/** The Standard Schema properties. */
|
|
5
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
5
6
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
7
|
+
declare namespace StandardSchemaV1 {
|
|
8
|
+
/** The Standard Schema properties interface. */
|
|
9
|
+
export interface Props<Input = unknown, Output = Input> {
|
|
10
|
+
/** The version number of the standard. */
|
|
11
|
+
readonly version: 1;
|
|
12
|
+
/** The vendor name of the schema library. */
|
|
13
|
+
readonly vendor: string;
|
|
14
|
+
/** Validates unknown input values. */
|
|
15
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
16
|
+
/** Inferred types associated with the schema. */
|
|
17
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
18
|
+
}
|
|
19
|
+
/** The result interface of the validate function. */
|
|
20
|
+
export type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
21
|
+
/** The result interface if validation succeeds. */
|
|
22
|
+
export interface SuccessResult<Output> {
|
|
23
|
+
/** The typed output value. */
|
|
24
|
+
readonly value: Output;
|
|
25
|
+
/** The non-existent issues. */
|
|
26
|
+
readonly issues?: undefined;
|
|
27
|
+
}
|
|
28
|
+
/** The result interface if validation fails. */
|
|
29
|
+
export interface FailureResult {
|
|
30
|
+
/** The issues of failed validation. */
|
|
31
|
+
readonly issues: readonly Issue[];
|
|
32
|
+
}
|
|
33
|
+
/** The issue interface of the failure output. */
|
|
34
|
+
export interface Issue {
|
|
35
|
+
/** The error message of the issue. */
|
|
36
|
+
readonly message: string;
|
|
37
|
+
/** The path of the issue, if any. */
|
|
38
|
+
readonly path?: readonly (PropertyKey | PathSegment)[] | undefined;
|
|
39
|
+
}
|
|
40
|
+
/** The path segment interface of the issue. */
|
|
41
|
+
export interface PathSegment {
|
|
42
|
+
/** The key representing a path segment. */
|
|
43
|
+
readonly key: PropertyKey;
|
|
44
|
+
}
|
|
45
|
+
/** The Standard Schema types interface. */
|
|
46
|
+
export interface Types<Input = unknown, Output = Input> {
|
|
47
|
+
/** The input type of the schema. */
|
|
48
|
+
readonly input: Input;
|
|
49
|
+
/** The output type of the schema. */
|
|
50
|
+
readonly output: Output;
|
|
51
|
+
}
|
|
52
|
+
/** Infers the input type of a Standard Schema. */
|
|
53
|
+
export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
54
|
+
/** Infers the output type of a Standard Schema. */
|
|
55
|
+
export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
56
|
+
export {};
|
|
56
57
|
}
|
|
58
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
59
|
+
//#endregion
|
|
60
|
+
export { StandardSchemaV1 };
|
|
57
61
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","
|
|
1
|
+
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/core/schema.ts"],"sourcesContent":[],"mappings":";;AACiB,UAAA,gBAAgB,CAAA,QAAA,OAAA,EAAA,SAA2B,KAA3B,CAAA,CAAA;EAAA;WAA2B,WAAA,EAEpC,gBAAA,CAAiB,KAFmB,CAEb,KAFa,EAEN,MAFM,CAAA;;AAEN,kBAI7B,gBAAA,CAJ6B;;EAAR,OAAA,UAAA,KAAA,CAAA,QAAA,OAAA,EAAA,SAOK,KAPL,CAAA,CAAA;IAIrB;IAAgB,SAAA,OAAA,EAAA,CAAA;IAGU;IAMD,SAAA,MAAA,EAAA,MAAA;IAAP;IAAgC,SAAA,QAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAAhC,MAAgC,CAAzB,MAAyB,CAAA,GAAf,OAAe,CAAP,MAAO,CAAA,MAAA,CAAA,CAAA;IAAP;IAAR,SAAA,KAAA,CAAA,EAEvC,KAFuC,CAEjC,KAFiC,EAE1B,MAF0B,CAAA,GAAA,SAAA;;;SAEvC,KAAA,MAAA,CAAA,MAAA,CAAA,GAIU,aAJV,CAIwB,MAJxB,CAAA,GAIkC,aAJlC;;SAIU,UAAA,aAAA,CAAA,MAAA,CAAA,CAAA;IAAwB;IAKnC,SAAA,KAAA,EAAA,MAAA;IAQU;IAQA,SAAA,MAAA,CAAA,EAAA,SAAA;;;SAUqB,UAAA,aAAA,CAAA;IAE/B;IAEC,SAAA,MAAA,EAAA,SAtBS,KAsBT,EAAA;;;SAIuC,UAAA,KAAA,CAAA;IAKnB;IACrC,SAAA,OAAA,EAAA,MAAA;IADyD;IAAW,SAAA,IAAA,CAAA,EAAA,SAAA,CAvB1C,WAuB0C,GAvB5B,WAuB4B,CAAA,EAAA,GAAA,SAAA;;;;;kBAjBtD;;;mDAIiC;;oBAE/B;;qBAEC;;;wCAImB,oBAAoB,YACxD;;yCAIqC,oBAAoB,YACzD"}
|
package/dist/core/step.d.ts
CHANGED
|
@@ -1,96 +1,46 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { JsonValue } from "./json.js";
|
|
2
|
+
|
|
3
|
+
//#region src/core/step.d.ts
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* The kind of step in a workflow.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
type StepKind = "function" | "sleep";
|
|
8
9
|
/**
|
|
9
10
|
* Status of a step attempt through its lifecycle.
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
+
type StepAttemptStatus = "running" | "paused" | "succeeded" | "completed" | "failed";
|
|
12
13
|
/**
|
|
13
14
|
* Context for a step attempt (currently only used for sleep steps).
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
interface StepAttemptContext {
|
|
17
|
+
kind: "sleep";
|
|
18
|
+
resumeAt: string;
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
21
|
* StepAttempt represents a single attempt of a step within a workflow.
|
|
21
22
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
interface StepAttempt {
|
|
24
|
+
namespaceId: string;
|
|
25
|
+
id: string;
|
|
26
|
+
workflowRunId: string;
|
|
27
|
+
stepName: string;
|
|
28
|
+
kind: StepKind;
|
|
29
|
+
status: StepAttemptStatus;
|
|
30
|
+
config: JsonValue;
|
|
31
|
+
context: StepAttemptContext | null;
|
|
32
|
+
output: JsonValue | null;
|
|
33
|
+
error: JsonValue | null;
|
|
34
|
+
childWorkflowRunNamespaceId: string | null;
|
|
35
|
+
childWorkflowRunId: string | null;
|
|
36
|
+
startedAt: Date | null;
|
|
37
|
+
finishedAt: Date | null;
|
|
38
|
+
createdAt: Date;
|
|
39
|
+
updatedAt: Date;
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
41
42
|
* Immutable cache for step attempts, keyed by step name.
|
|
42
43
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
* Create a step attempt cache from an array of attempts. Only includes
|
|
46
|
-
* successful attempts (completed or succeeded status).
|
|
47
|
-
* @param attempts - Array of step attempts to cache
|
|
48
|
-
* @returns An immutable map of step name to successful attempt
|
|
49
|
-
*/
|
|
50
|
-
export declare function createStepAttemptCacheFromAttempts(attempts: readonly StepAttempt[]): StepAttemptCache;
|
|
51
|
-
/**
|
|
52
|
-
* Get a cached step attempt by name.
|
|
53
|
-
* @param cache - The step attempt cache
|
|
54
|
-
* @param stepName - The name of the step to look up
|
|
55
|
-
* @returns The cached attempt or undefined if not found
|
|
56
|
-
*/
|
|
57
|
-
export declare function getCachedStepAttempt(cache: StepAttemptCache, stepName: string): StepAttempt | undefined;
|
|
58
|
-
/**
|
|
59
|
-
* Check if a step attempt is cached (has completed successfully).
|
|
60
|
-
* @param cache - The step attempt cache
|
|
61
|
-
* @param stepName - The name of the step to check
|
|
62
|
-
* @returns True if the step has a cached successful result
|
|
63
|
-
*/
|
|
64
|
-
export declare function hasCompletedStep(cache: StepAttemptCache, stepName: string): boolean;
|
|
65
|
-
/**
|
|
66
|
-
* Add a step attempt to the cache (returns new cache, original unchanged). This
|
|
67
|
-
* is an immutable operation.
|
|
68
|
-
* @param cache - The existing step attempt cache
|
|
69
|
-
* @param attempt - The attempt to add
|
|
70
|
-
* @returns A new cache with the attempt added
|
|
71
|
-
*/
|
|
72
|
-
export declare function addToStepAttemptCache(cache: StepAttemptCache, attempt: Readonly<StepAttempt>): StepAttemptCache;
|
|
73
|
-
/**
|
|
74
|
-
* Convert a step function result to a JSON-compatible value. Undefined values
|
|
75
|
-
* are converted to null for JSON serialization.
|
|
76
|
-
* @param result - The result from a step function
|
|
77
|
-
* @returns A JSON-serializable value
|
|
78
|
-
*/
|
|
79
|
-
export declare function normalizeStepOutput(result: unknown): JsonValue;
|
|
80
|
-
/**
|
|
81
|
-
* Calculate the resume time for a sleep step.
|
|
82
|
-
* @param duration - The duration string to sleep for
|
|
83
|
-
* @param now - The current timestamp (defaults to Date.now())
|
|
84
|
-
* @returns A Result containing the resume Date or an Error
|
|
85
|
-
*/
|
|
86
|
-
export declare function calculateSleepResumeAt(duration: DurationString, now?: number): Result<Date>;
|
|
87
|
-
/**
|
|
88
|
-
* Create the context object for a sleep step attempt.
|
|
89
|
-
* @param resumeAt - The time when the sleep should resume
|
|
90
|
-
* @returns The context object for the sleep step
|
|
91
|
-
*/
|
|
92
|
-
export declare function createSleepContext(resumeAt: Readonly<Date>): {
|
|
93
|
-
kind: "sleep";
|
|
94
|
-
resumeAt: string;
|
|
95
|
-
};
|
|
44
|
+
//#endregion
|
|
45
|
+
export { StepAttempt, StepAttemptContext, StepKind };
|
|
96
46
|
//# sourceMappingURL=step.d.ts.map
|
package/dist/core/step.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step.d.ts","
|
|
1
|
+
{"version":3,"file":"step.d.ts","names":[],"sources":["../../src/core/step.ts"],"sourcesContent":[],"mappings":";;;;AASA;AAKA;AAUA;AAQiB,KAvBL,QAAA,GAuBgB,UAAA,GAAA,OAAA;;;;AAOlB,KAzBE,iBAAA,GAyBF,SAAA,GAAA,QAAA,GAAA,WAAA,GAAA,WAAA,GAAA,QAAA;;;;AAMG,UArBI,kBAAA,CAqBJ;MACC,EAAA,OAAA;UACD,EAAA,MAAA;;;;;UAfI,WAAA;;;;;QAKT;UACE;UACA;WACC;UACD;SACD;;;aAGI;cACC;aACD;aACA"}
|
package/dist/core/step.js
CHANGED
|
@@ -1,78 +1,68 @@
|
|
|
1
|
-
import { parseDuration } from "./duration.js";
|
|
2
1
|
import { err, ok } from "./result.js";
|
|
2
|
+
import { parseDuration } from "./duration.js";
|
|
3
|
+
|
|
4
|
+
//#region src/core/step.ts
|
|
3
5
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
attempt.stepName,
|
|
13
|
-
attempt
|
|
14
|
-
]));
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Get a cached step attempt by name.
|
|
18
|
-
* @param cache - The step attempt cache
|
|
19
|
-
* @param stepName - The name of the step to look up
|
|
20
|
-
* @returns The cached attempt or undefined if not found
|
|
21
|
-
*/ export function getCachedStepAttempt(cache, stepName) {
|
|
22
|
-
return cache.get(stepName);
|
|
6
|
+
* Create a step attempt cache from an array of attempts. Only includes
|
|
7
|
+
* successful attempts (completed or succeeded status).
|
|
8
|
+
* @param attempts - Array of step attempts to cache
|
|
9
|
+
* @returns An immutable map of step name to successful attempt
|
|
10
|
+
*/
|
|
11
|
+
function createStepAttemptCacheFromAttempts(attempts) {
|
|
12
|
+
const successfulAttempts = attempts.filter((attempt) => attempt.status === "succeeded" || attempt.status === "completed");
|
|
13
|
+
return new Map(successfulAttempts.map((attempt) => [attempt.stepName, attempt]));
|
|
23
14
|
}
|
|
24
15
|
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
16
|
+
* Get a cached step attempt by name.
|
|
17
|
+
* @param cache - The step attempt cache
|
|
18
|
+
* @param stepName - The name of the step to look up
|
|
19
|
+
* @returns The cached attempt or undefined if not found
|
|
20
|
+
*/
|
|
21
|
+
function getCachedStepAttempt(cache, stepName) {
|
|
22
|
+
return cache.get(stepName);
|
|
31
23
|
}
|
|
32
24
|
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
[
|
|
42
|
-
attempt.stepName,
|
|
43
|
-
attempt
|
|
44
|
-
]
|
|
45
|
-
]);
|
|
25
|
+
* Add a step attempt to the cache (returns new cache, original unchanged). This
|
|
26
|
+
* is an immutable operation.
|
|
27
|
+
* @param cache - The existing step attempt cache
|
|
28
|
+
* @param attempt - The attempt to add
|
|
29
|
+
* @returns A new cache with the attempt added
|
|
30
|
+
*/
|
|
31
|
+
function addToStepAttemptCache(cache, attempt) {
|
|
32
|
+
return new Map([...cache, [attempt.stepName, attempt]]);
|
|
46
33
|
}
|
|
47
34
|
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
35
|
+
* Convert a step function result to a JSON-compatible value. Undefined values
|
|
36
|
+
* are converted to null for JSON serialization.
|
|
37
|
+
* @param result - The result from a step function
|
|
38
|
+
* @returns A JSON-serializable value
|
|
39
|
+
*/
|
|
40
|
+
function normalizeStepOutput(result) {
|
|
41
|
+
return result ?? null;
|
|
54
42
|
}
|
|
55
43
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return ok(new Date(now + result.value));
|
|
44
|
+
* Calculate the resume time for a sleep step.
|
|
45
|
+
* @param duration - The duration string to sleep for
|
|
46
|
+
* @param now - The current timestamp (defaults to Date.now())
|
|
47
|
+
* @returns A Result containing the resume Date or an Error
|
|
48
|
+
*/
|
|
49
|
+
function calculateSleepResumeAt(duration, now = Date.now()) {
|
|
50
|
+
const result = parseDuration(duration);
|
|
51
|
+
if (!result.ok) return err(result.error);
|
|
52
|
+
return ok(new Date(now + result.value));
|
|
66
53
|
}
|
|
67
54
|
/**
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
55
|
+
* Create the context object for a sleep step attempt.
|
|
56
|
+
* @param resumeAt - The time when the sleep should resume
|
|
57
|
+
* @returns The context object for the sleep step
|
|
58
|
+
*/
|
|
59
|
+
function createSleepContext(resumeAt) {
|
|
60
|
+
return {
|
|
61
|
+
kind: "sleep",
|
|
62
|
+
resumeAt: resumeAt.toISOString()
|
|
63
|
+
};
|
|
76
64
|
}
|
|
77
65
|
|
|
66
|
+
//#endregion
|
|
67
|
+
export { addToStepAttemptCache, calculateSleepResumeAt, createSleepContext, createStepAttemptCacheFromAttempts, getCachedStepAttempt, normalizeStepOutput };
|
|
78
68
|
//# sourceMappingURL=step.js.map
|
package/dist/core/step.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/step.ts"],"sourcesContent":["import type
|
|
1
|
+
{"version":3,"file":"step.js","names":[],"sources":["../../src/core/step.ts"],"sourcesContent":["import { type DurationString } from \"./duration\";\nimport { parseDuration } from \"./duration\";\nimport { type JsonValue } from \"./json\";\nimport { type Result } from \"./result\";\nimport { err, ok } from \"./result\";\n\n/**\n * The kind of step in a workflow.\n */\nexport type StepKind = \"function\" | \"sleep\";\n\n/**\n * Status of a step attempt through its lifecycle.\n */\nexport type StepAttemptStatus =\n | \"running\"\n | \"paused\"\n | \"succeeded\" // deprecated in favor of 'completed'\n | \"completed\"\n | \"failed\";\n\n/**\n * Context for a step attempt (currently only used for sleep steps).\n */\nexport interface StepAttemptContext {\n kind: \"sleep\";\n resumeAt: string;\n}\n\n/**\n * StepAttempt represents a single attempt of a step within a workflow.\n */\nexport interface StepAttempt {\n namespaceId: string;\n id: string;\n workflowRunId: string;\n stepName: string;\n kind: StepKind;\n status: StepAttemptStatus;\n config: JsonValue; // user-defined config\n context: StepAttemptContext | null; // runtime execution metadata\n output: JsonValue | null;\n error: JsonValue | null;\n childWorkflowRunNamespaceId: string | null;\n childWorkflowRunId: string | null;\n startedAt: Date | null;\n finishedAt: Date | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\n/**\n * Immutable cache for step attempts, keyed by step name.\n */\nexport type StepAttemptCache = ReadonlyMap<string, StepAttempt>;\n\n/**\n * Create a step attempt cache from an array of attempts. Only includes\n * successful attempts (completed or succeeded status).\n * @param attempts - Array of step attempts to cache\n * @returns An immutable map of step name to successful attempt\n */\nexport function createStepAttemptCacheFromAttempts(\n attempts: readonly StepAttempt[],\n): StepAttemptCache {\n // 'succeeded' status is deprecated in favor of 'completed'\n const successfulAttempts = attempts.filter(\n (attempt) => attempt.status === \"succeeded\" || attempt.status === \"completed\",\n );\n\n return new Map(successfulAttempts.map((attempt) => [attempt.stepName, attempt]));\n}\n\n/**\n * Get a cached step attempt by name.\n * @param cache - The step attempt cache\n * @param stepName - The name of the step to look up\n * @returns The cached attempt or undefined if not found\n */\nexport function getCachedStepAttempt(\n cache: StepAttemptCache,\n stepName: string,\n): StepAttempt | undefined {\n return cache.get(stepName);\n}\n\n/**\n * Check if a step attempt is cached (has completed successfully).\n * @param cache - The step attempt cache\n * @param stepName - The name of the step to check\n * @returns True if the step has a cached successful result\n */\nexport function hasCompletedStep(cache: StepAttemptCache, stepName: string): boolean {\n return cache.has(stepName);\n}\n\n/**\n * Add a step attempt to the cache (returns new cache, original unchanged). This\n * is an immutable operation.\n * @param cache - The existing step attempt cache\n * @param attempt - The attempt to add\n * @returns A new cache with the attempt added\n */\nexport function addToStepAttemptCache(\n cache: StepAttemptCache,\n attempt: Readonly<StepAttempt>,\n): StepAttemptCache {\n return new Map([...cache, [attempt.stepName, attempt]]);\n}\n\n/**\n * Convert a step function result to a JSON-compatible value. Undefined values\n * are converted to null for JSON serialization.\n * @param result - The result from a step function\n * @returns A JSON-serializable value\n */\nexport function normalizeStepOutput(result: unknown): JsonValue {\n return (result ?? null) as JsonValue;\n}\n\n/**\n * Calculate the resume time for a sleep step.\n * @param duration - The duration string to sleep for\n * @param now - The current timestamp (defaults to Date.now())\n * @returns A Result containing the resume Date or an Error\n */\nexport function calculateSleepResumeAt(\n duration: DurationString,\n now: number = Date.now(),\n): Result<Date> {\n const result = parseDuration(duration);\n\n if (!result.ok) {\n return err(result.error);\n }\n\n return ok(new Date(now + result.value));\n}\n\n/**\n * Create the context object for a sleep step attempt.\n * @param resumeAt - The time when the sleep should resume\n * @returns The context object for the sleep step\n */\nexport function createSleepContext(resumeAt: Readonly<Date>): {\n kind: \"sleep\";\n resumeAt: string;\n} {\n return {\n kind: \"sleep\" as const,\n resumeAt: resumeAt.toISOString(),\n };\n}\n"],"mappings":";;;;;;;;;;AA8DA,SAAgB,mCACd,UACkB;CAElB,MAAM,qBAAqB,SAAS,QACjC,YAAY,QAAQ,WAAW,eAAe,QAAQ,WAAW,YACnE;AAED,QAAO,IAAI,IAAI,mBAAmB,KAAK,YAAY,CAAC,QAAQ,UAAU,QAAQ,CAAC,CAAC;;;;;;;;AASlF,SAAgB,qBACd,OACA,UACyB;AACzB,QAAO,MAAM,IAAI,SAAS;;;;;;;;;AAoB5B,SAAgB,sBACd,OACA,SACkB;AAClB,QAAO,IAAI,IAAI,CAAC,GAAG,OAAO,CAAC,QAAQ,UAAU,QAAQ,CAAC,CAAC;;;;;;;;AASzD,SAAgB,oBAAoB,QAA4B;AAC9D,QAAQ,UAAU;;;;;;;;AASpB,SAAgB,uBACd,UACA,MAAc,KAAK,KAAK,EACV;CACd,MAAM,SAAS,cAAc,SAAS;AAEtC,KAAI,CAAC,OAAO,GACV,QAAO,IAAI,OAAO,MAAM;AAG1B,QAAO,GAAG,IAAI,KAAK,MAAM,OAAO,MAAM,CAAC;;;;;;;AAQzC,SAAgB,mBAAmB,UAGjC;AACA,QAAO;EACL,MAAM;EACN,UAAU,SAAS,aAAa;EACjC"}
|
package/dist/core/workflow.d.ts
CHANGED
|
@@ -1,79 +1,51 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { JsonValue } from "./json.js";
|
|
2
|
+
import { SerializedError } from "./error.js";
|
|
3
|
+
import { StandardSchemaV1 } from "./schema.js";
|
|
4
|
+
|
|
5
|
+
//#region src/core/workflow.d.ts
|
|
6
|
+
|
|
4
7
|
/**
|
|
5
8
|
* Status of a workflow run through its lifecycle.
|
|
6
9
|
*/
|
|
7
|
-
|
|
10
|
+
type WorkflowRunStatus = "pending" | "running" | "sleeping" | "paused" | "succeeded" | "completed" | "failed" | "canceled";
|
|
8
11
|
/**
|
|
9
12
|
* WorkflowRun represents a single execution instance of a workflow.
|
|
10
13
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
14
|
+
interface WorkflowRun {
|
|
15
|
+
namespaceId: string;
|
|
16
|
+
id: string;
|
|
17
|
+
workflowName: string;
|
|
18
|
+
version: string | null;
|
|
19
|
+
status: WorkflowRunStatus;
|
|
20
|
+
idempotencyKey: string | null;
|
|
21
|
+
config: JsonValue;
|
|
22
|
+
context: JsonValue | null;
|
|
23
|
+
input: JsonValue | null;
|
|
24
|
+
output: JsonValue | null;
|
|
25
|
+
error: SerializedError | null;
|
|
26
|
+
attempts: number;
|
|
27
|
+
parentStepAttemptNamespaceId: string | null;
|
|
28
|
+
parentStepAttemptId: string | null;
|
|
29
|
+
workerId: string | null;
|
|
30
|
+
availableAt: Date | null;
|
|
31
|
+
deadlineAt: Date | null;
|
|
32
|
+
startedAt: Date | null;
|
|
33
|
+
finishedAt: Date | null;
|
|
34
|
+
createdAt: Date;
|
|
35
|
+
updatedAt: Date;
|
|
33
36
|
}
|
|
34
37
|
/**
|
|
35
38
|
* Infers the input type from a Standard Schema.
|
|
36
39
|
*/
|
|
37
|
-
|
|
40
|
+
type SchemaInput<TSchema, Fallback> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : Fallback;
|
|
38
41
|
/**
|
|
39
42
|
* Infers the output type from a Standard Schema.
|
|
40
43
|
*/
|
|
41
|
-
|
|
44
|
+
type SchemaOutput<TSchema, Fallback> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : Fallback;
|
|
42
45
|
/**
|
|
43
46
|
* Result of input validation - either success with a value or failure with an
|
|
44
47
|
* error message.
|
|
45
48
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
value: T;
|
|
49
|
-
} | {
|
|
50
|
-
success: false;
|
|
51
|
-
error: string;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Default configuration for result polling when awaiting workflow completion.
|
|
55
|
-
*/
|
|
56
|
-
export declare const DEFAULT_WORKFLOW_RESULT_CONFIG: {
|
|
57
|
-
/** Polling interval in milliseconds (1 second) */
|
|
58
|
-
readonly pollIntervalMs: 1000;
|
|
59
|
-
/** Timeout in milliseconds (5 minutes) */
|
|
60
|
-
readonly timeoutMs: number;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Validate input against a Standard Schema. Pure async function that validates
|
|
64
|
-
* input and returns a ValidationResult.
|
|
65
|
-
* @param schema - The Standard Schema to validate against (or null/undefined
|
|
66
|
-
* for no validation)
|
|
67
|
-
* @param input - The input value to validate
|
|
68
|
-
* @returns A ValidationResult containing either the validated value or an error
|
|
69
|
-
* message
|
|
70
|
-
*/
|
|
71
|
-
export declare function validateInput<RunInput, Input>(schema: StandardSchemaV1<RunInput, Input> | null | undefined, input: RunInput | undefined): Promise<ValidationResult<Input>>;
|
|
72
|
-
/**
|
|
73
|
-
* Check if a workflow run status represents a terminal state.
|
|
74
|
-
* @param status - The workflow run status
|
|
75
|
-
* @returns True if the status is terminal (succeeded, completed, failed, or canceled).
|
|
76
|
-
* Note: 'succeeded' is deprecated in favor of 'completed'.
|
|
77
|
-
*/
|
|
78
|
-
export declare function isTerminalStatus(status: string): status is "succeeded" | "completed" | "failed" | "canceled";
|
|
49
|
+
//#endregion
|
|
50
|
+
export { SchemaInput, SchemaOutput, WorkflowRun };
|
|
79
51
|
//# sourceMappingURL=workflow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.d.ts","
|
|
1
|
+
{"version":3,"file":"workflow.d.ts","names":[],"sources":["../../src/core/workflow.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAOA;AAaiB,KAbL,iBAAA,GAagB,SAAA,GAAA,SAAA,GAAA,UAAA,GAAA,QAAA,GAAA,WAAA,GAAA,WAAA,GAAA,QAAA,GAAA,UAAA;;;;AAQjB,UARM,WAAA,CAQN;aACF,EAAA,MAAA;MACC,MAAA;cACD,EAAA,MAAA;SAKM,EAAA,MAAA,GAAA,IAAA;QACD,EAZJ,iBAYI;gBACD,EAAA,MAAA,GAAA,IAAA;QACC,EAZJ,SAYI;SACD,EAZF,SAYE,GAAA,IAAA;OACA,EAZJ,SAYI,GAAA,IAAA;EAAI,MAAA,EAXP,SAWO,GAAA,IAAA;EAML,KAAA,EAhBH,eAgBc,GAAA,IAAA;EAAA,QAAA,EAAA,MAAA;8BAAsB,EAAA,MAAA,GAAA,IAAA;qBAAgB,EAAA,MAAA,GAAA,IAAA;UAC7B,EAAA,MAAA,GAAA,IAAA;aAA5B,EAZW,IAYX,GAAiB,IAAA;YACjB,EAZU,IAYV,GAAA,IAAA;EAAQ,SAAA,EAXC,IAWD,GAAA,IAAA;EAKA,UAAA,EAfE,IAeU,GAAA,IAAA;EAAA,SAAA,EAdX,IAcW;WAAsB,EAbjC,IAaiC;;;;;AAElC,KATA,WASA,CAAA,OAAA,EAAA,QAAA,CAAA,GATiC,OASjC,SATiD,gBASjD,GARR,gBAAA,CAAiB,UAQT,CARoB,OAQpB,CAAA,GAPR,QAOQ;;;;KAFA,kCAAkC,gBAAgB,mBAC1D,gBAAA,CAAiB,YAAY,WAC7B"}
|