@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.
Files changed (215) hide show
  1. package/.oxlintrc.json +3 -0
  2. package/AGENTS.md +21 -0
  3. package/dist/backend.d.ts +126 -103
  4. package/dist/backend.d.ts.map +1 -1
  5. package/dist/backend.js +4 -1
  6. package/dist/backend.js.map +1 -1
  7. package/dist/client.d.ts +145 -132
  8. package/dist/client.d.ts.map +1 -1
  9. package/dist/client.js +220 -212
  10. package/dist/client.js.map +1 -1
  11. package/dist/config.d.ts +15 -8
  12. package/dist/config.d.ts.map +1 -1
  13. package/dist/config.js +22 -17
  14. package/dist/config.js.map +1 -1
  15. package/dist/core/duration.d.ts +5 -4
  16. package/dist/core/duration.d.ts.map +1 -1
  17. package/dist/core/duration.js +54 -59
  18. package/dist/core/duration.js.map +1 -1
  19. package/dist/core/error.d.ts +10 -7
  20. package/dist/core/error.d.ts.map +1 -1
  21. package/dist/core/error.js +21 -21
  22. package/dist/core/error.js.map +1 -1
  23. package/dist/core/json.d.ts +8 -3
  24. package/dist/core/json.d.ts.map +1 -1
  25. package/dist/core/result.d.ts +10 -14
  26. package/dist/core/result.d.ts.map +1 -1
  27. package/dist/core/result.js +21 -16
  28. package/dist/core/result.js.map +1 -1
  29. package/dist/core/retry.d.ts +42 -20
  30. package/dist/core/retry.d.ts.map +1 -1
  31. package/dist/core/retry.js +49 -20
  32. package/dist/core/retry.js.map +1 -1
  33. package/dist/core/schema.d.ts +57 -53
  34. package/dist/core/schema.d.ts.map +1 -1
  35. package/dist/core/step.d.ts +28 -78
  36. package/dist/core/step.d.ts.map +1 -1
  37. package/dist/core/step.js +53 -63
  38. package/dist/core/step.js.map +1 -1
  39. package/dist/core/workflow.d.ts +33 -61
  40. package/dist/core/workflow.d.ts.map +1 -1
  41. package/dist/core/workflow.js +31 -41
  42. package/dist/core/workflow.js.map +1 -1
  43. package/dist/database/backend.d.ts +53 -46
  44. package/dist/database/backend.d.ts.map +1 -1
  45. package/dist/database/backend.js +544 -545
  46. package/dist/database/backend.js.map +1 -1
  47. package/dist/database/base.js +48 -25
  48. package/dist/database/base.js.map +1 -1
  49. package/dist/database/migrations/20251212000000_0_init.d.ts +10 -0
  50. package/dist/database/migrations/20251212000000_0_init.d.ts.map +1 -0
  51. package/dist/database/migrations/20251212000000_0_init.js +8 -4
  52. package/dist/database/migrations/20251212000000_0_init.js.map +1 -1
  53. package/dist/database/migrations/20251212000000_1_tables.d.ts +10 -0
  54. package/dist/database/migrations/20251212000000_1_tables.d.ts.map +1 -0
  55. package/dist/database/migrations/20251212000000_1_tables.js +81 -83
  56. package/dist/database/migrations/20251212000000_1_tables.js.map +1 -1
  57. package/dist/database/migrations/20251212000000_2_fk.d.ts +10 -0
  58. package/dist/database/migrations/20251212000000_2_fk.d.ts.map +1 -0
  59. package/dist/database/migrations/20251212000000_2_fk.js +20 -43
  60. package/dist/database/migrations/20251212000000_2_fk.js.map +1 -1
  61. package/dist/database/migrations/20251212000000_3_indexes.d.ts +10 -0
  62. package/dist/database/migrations/20251212000000_3_indexes.d.ts.map +1 -0
  63. package/dist/database/migrations/20251212000000_3_indexes.js +88 -102
  64. package/dist/database/migrations/20251212000000_3_indexes.js.map +1 -1
  65. package/dist/database/pubsub.d.ts +7 -16
  66. package/dist/database/pubsub.d.ts.map +1 -1
  67. package/dist/database/pubsub.js +75 -73
  68. package/dist/database/pubsub.js.map +1 -1
  69. package/dist/execution.d.ts +20 -57
  70. package/dist/execution.d.ts.map +1 -1
  71. package/dist/execution.js +175 -174
  72. package/dist/execution.js.map +1 -1
  73. package/dist/index.d.ts +5 -8
  74. package/dist/index.js +5 -5
  75. package/dist/internal.d.ts +12 -12
  76. package/dist/internal.js +4 -4
  77. package/dist/registry.d.ts +33 -27
  78. package/dist/registry.d.ts.map +1 -1
  79. package/dist/registry.js +58 -49
  80. package/dist/registry.js.map +1 -1
  81. package/dist/worker.d.ts +57 -50
  82. package/dist/worker.d.ts.map +1 -1
  83. package/dist/worker.js +194 -198
  84. package/dist/worker.js.map +1 -1
  85. package/dist/workflow.d.ts +26 -27
  86. package/dist/workflow.d.ts.map +1 -1
  87. package/dist/workflow.js +20 -15
  88. package/dist/workflow.js.map +1 -1
  89. package/nodemon.json +1 -1
  90. package/package.json +18 -20
  91. package/src/backend.ts +28 -8
  92. package/src/chaos.test.ts +3 -1
  93. package/src/client.test.ts +2 -0
  94. package/src/client.ts +32 -8
  95. package/src/config.test.ts +1 -0
  96. package/src/config.ts +3 -2
  97. package/src/core/duration.test.ts +2 -1
  98. package/src/core/duration.ts +1 -1
  99. package/src/core/error.test.ts +1 -0
  100. package/src/core/error.ts +1 -1
  101. package/src/core/result.test.ts +1 -0
  102. package/src/core/retry.test.ts +181 -11
  103. package/src/core/retry.ts +95 -19
  104. package/src/core/schema.ts +2 -2
  105. package/src/core/step.test.ts +2 -1
  106. package/src/core/step.ts +4 -3
  107. package/src/core/workflow.test.ts +2 -1
  108. package/src/core/workflow.ts +4 -3
  109. package/src/database/backend.test.ts +1 -0
  110. package/src/database/backend.testsuite.ts +162 -39
  111. package/src/database/backend.ts +271 -35
  112. package/src/database/base.test.ts +41 -0
  113. package/src/database/base.ts +51 -2
  114. package/src/database/migrations/20251212000000_0_init.ts +2 -1
  115. package/src/database/migrations/20251212000000_1_tables.ts +2 -1
  116. package/src/database/migrations/20251212000000_2_fk.ts +2 -1
  117. package/src/database/migrations/20251212000000_3_indexes.ts +2 -1
  118. package/src/database/pubsub.test.ts +6 -3
  119. package/src/database/pubsub.ts +55 -33
  120. package/src/execution.test.ts +117 -0
  121. package/src/execution.ts +65 -10
  122. package/src/internal.ts +21 -1
  123. package/src/practices/01-remote-workflow.ts +1 -0
  124. package/src/registry.test.ts +1 -0
  125. package/src/registry.ts +1 -1
  126. package/src/testing/connection.ts +3 -1
  127. package/src/worker.test.ts +2 -0
  128. package/src/worker.ts +31 -9
  129. package/src/workflow.test.ts +1 -0
  130. package/src/workflow.ts +5 -2
  131. package/templates/openworkflow.config.ts +2 -1
  132. package/tsdown.config.ts +31 -0
  133. package/.swcrc +0 -17
  134. package/dist/chaos.test.d.ts +0 -2
  135. package/dist/chaos.test.d.ts.map +0 -1
  136. package/dist/chaos.test.js +0 -92
  137. package/dist/chaos.test.js.map +0 -1
  138. package/dist/client.test.d.ts +0 -2
  139. package/dist/client.test.d.ts.map +0 -1
  140. package/dist/client.test.js +0 -340
  141. package/dist/client.test.js.map +0 -1
  142. package/dist/config.test.d.ts +0 -2
  143. package/dist/config.test.d.ts.map +0 -1
  144. package/dist/config.test.js +0 -24
  145. package/dist/config.test.js.map +0 -1
  146. package/dist/core/duration.test.d.ts +0 -2
  147. package/dist/core/duration.test.d.ts.map +0 -1
  148. package/dist/core/duration.test.js +0 -265
  149. package/dist/core/duration.test.js.map +0 -1
  150. package/dist/core/error.test.d.ts +0 -2
  151. package/dist/core/error.test.d.ts.map +0 -1
  152. package/dist/core/error.test.js +0 -63
  153. package/dist/core/error.test.js.map +0 -1
  154. package/dist/core/json.js +0 -3
  155. package/dist/core/json.js.map +0 -1
  156. package/dist/core/result.test.d.ts +0 -2
  157. package/dist/core/result.test.d.ts.map +0 -1
  158. package/dist/core/result.test.js +0 -19
  159. package/dist/core/result.test.js.map +0 -1
  160. package/dist/core/retry.test.d.ts +0 -2
  161. package/dist/core/retry.test.d.ts.map +0 -1
  162. package/dist/core/retry.test.js +0 -37
  163. package/dist/core/retry.test.js.map +0 -1
  164. package/dist/core/schema.js +0 -4
  165. package/dist/core/schema.js.map +0 -1
  166. package/dist/core/step.test.d.ts +0 -2
  167. package/dist/core/step.test.d.ts.map +0 -1
  168. package/dist/core/step.test.js +0 -356
  169. package/dist/core/step.test.js.map +0 -1
  170. package/dist/core/workflow.test.d.ts +0 -2
  171. package/dist/core/workflow.test.d.ts.map +0 -1
  172. package/dist/core/workflow.test.js +0 -172
  173. package/dist/core/workflow.test.js.map +0 -1
  174. package/dist/database/backend.test.d.ts +0 -2
  175. package/dist/database/backend.test.d.ts.map +0 -1
  176. package/dist/database/backend.test.js +0 -19
  177. package/dist/database/backend.test.js.map +0 -1
  178. package/dist/database/backend.testsuite.d.ts +0 -20
  179. package/dist/database/backend.testsuite.d.ts.map +0 -1
  180. package/dist/database/backend.testsuite.js +0 -1174
  181. package/dist/database/backend.testsuite.js.map +0 -1
  182. package/dist/database/base.d.ts +0 -12
  183. package/dist/database/base.d.ts.map +0 -1
  184. package/dist/database/pubsub.test.d.ts +0 -2
  185. package/dist/database/pubsub.test.d.ts.map +0 -1
  186. package/dist/database/pubsub.test.js +0 -86
  187. package/dist/database/pubsub.test.js.map +0 -1
  188. package/dist/execution.test.d.ts +0 -2
  189. package/dist/execution.test.d.ts.map +0 -1
  190. package/dist/execution.test.js +0 -558
  191. package/dist/execution.test.js.map +0 -1
  192. package/dist/index.d.ts.map +0 -1
  193. package/dist/index.js.map +0 -1
  194. package/dist/internal.d.ts.map +0 -1
  195. package/dist/internal.js.map +0 -1
  196. package/dist/practices/01-remote-workflow.d.ts +0 -2
  197. package/dist/practices/01-remote-workflow.d.ts.map +0 -1
  198. package/dist/practices/01-remote-workflow.js +0 -70
  199. package/dist/practices/01-remote-workflow.js.map +0 -1
  200. package/dist/registry.test.d.ts +0 -2
  201. package/dist/registry.test.d.ts.map +0 -1
  202. package/dist/registry.test.js +0 -95
  203. package/dist/registry.test.js.map +0 -1
  204. package/dist/testing/connection.d.ts +0 -7
  205. package/dist/testing/connection.d.ts.map +0 -1
  206. package/dist/testing/connection.js +0 -39
  207. package/dist/testing/connection.js.map +0 -1
  208. package/dist/worker.test.d.ts +0 -2
  209. package/dist/worker.test.d.ts.map +0 -1
  210. package/dist/worker.test.js +0 -1164
  211. package/dist/worker.test.js.map +0 -1
  212. package/dist/workflow.test.d.ts +0 -2
  213. package/dist/workflow.test.d.ts.map +0 -1
  214. package/dist/workflow.test.js +0 -73
  215. package/dist/workflow.test.js.map +0 -1
@@ -1,57 +1,61 @@
1
+ //#region src/core/schema.d.ts
1
2
  /** The Standard Schema interface. https://standardschema.dev */
2
- export interface StandardSchemaV1<Input = unknown, Output = Input> {
3
- /** The Standard Schema properties. */
4
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
3
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
4
+ /** The Standard Schema properties. */
5
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
5
6
  }
6
- export declare namespace StandardSchemaV1 {
7
- /** The Standard Schema properties interface. */
8
- export interface Props<Input = unknown, Output = Input> {
9
- /** The version number of the standard. */
10
- readonly version: 1;
11
- /** The vendor name of the schema library. */
12
- readonly vendor: string;
13
- /** Validates unknown input values. */
14
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
15
- /** Inferred types associated with the schema. */
16
- readonly types?: Types<Input, Output> | undefined;
17
- }
18
- /** The result interface of the validate function. */
19
- export type Result<Output> = SuccessResult<Output> | FailureResult;
20
- /** The result interface if validation succeeds. */
21
- export interface SuccessResult<Output> {
22
- /** The typed output value. */
23
- readonly value: Output;
24
- /** The non-existent issues. */
25
- readonly issues?: undefined;
26
- }
27
- /** The result interface if validation fails. */
28
- export interface FailureResult {
29
- /** The issues of failed validation. */
30
- readonly issues: readonly Issue[];
31
- }
32
- /** The issue interface of the failure output. */
33
- export interface Issue {
34
- /** The error message of the issue. */
35
- readonly message: string;
36
- /** The path of the issue, if any. */
37
- readonly path?: readonly (PropertyKey | PathSegment)[] | undefined;
38
- }
39
- /** The path segment interface of the issue. */
40
- export interface PathSegment {
41
- /** The key representing a path segment. */
42
- readonly key: PropertyKey;
43
- }
44
- /** The Standard Schema types interface. */
45
- export interface Types<Input = unknown, Output = Input> {
46
- /** The input type of the schema. */
47
- readonly input: Input;
48
- /** The output type of the schema. */
49
- readonly output: Output;
50
- }
51
- /** Infers the input type of a Standard Schema. */
52
- export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
53
- /** Infers the output type of a Standard Schema. */
54
- export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
55
- export {};
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 {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AA,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"}
@@ -1,96 +1,46 @@
1
- import type { DurationString } from "./duration";
2
- import type { JsonValue } from "./json";
3
- import type { Result } from "./result";
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
- export type StepKind = "function" | "sleep";
8
+ type StepKind = "function" | "sleep";
8
9
  /**
9
10
  * Status of a step attempt through its lifecycle.
10
11
  */
11
- export type StepAttemptStatus = "running" | "succeeded" | "completed" | "failed";
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
- export interface StepAttemptContext {
16
- kind: "sleep";
17
- resumeAt: string;
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
- export interface StepAttempt {
23
- namespaceId: string;
24
- id: string;
25
- workflowRunId: string;
26
- stepName: string;
27
- kind: StepKind;
28
- status: StepAttemptStatus;
29
- config: JsonValue;
30
- context: StepAttemptContext | null;
31
- output: JsonValue | null;
32
- error: JsonValue | null;
33
- childWorkflowRunNamespaceId: string | null;
34
- childWorkflowRunId: string | null;
35
- startedAt: Date | null;
36
- finishedAt: Date | null;
37
- createdAt: Date;
38
- updatedAt: Date;
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
- export type StepAttemptCache = ReadonlyMap<string, StepAttempt>;
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
@@ -1 +1 @@
1
- {"version":3,"file":"step.d.ts","sourceRoot":"","sources":["../../src/core/step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGvC;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,SAA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AE,gBAAgB,EACvB,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,GAC7B,gBAAgB,CAElB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,cAAc,EACxB,GAAG,GAAE,MAAmB,GACvB,MAAM,CAAC,IAAI,CAAC,CAQd;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG;IAC5D,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB,CAKA"}
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
- * Create a step attempt cache from an array of attempts. Only includes
5
- * successful attempts (completed or succeeded status).
6
- * @param attempts - Array of step attempts to cache
7
- * @returns An immutable map of step name to successful attempt
8
- */ export function createStepAttemptCacheFromAttempts(attempts) {
9
- // 'succeeded' status is deprecated in favor of 'completed'
10
- const successfulAttempts = attempts.filter((attempt)=>attempt.status === "succeeded" || attempt.status === "completed");
11
- return new Map(successfulAttempts.map((attempt)=>[
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
- * Check if a step attempt is cached (has completed successfully).
26
- * @param cache - The step attempt cache
27
- * @param stepName - The name of the step to check
28
- * @returns True if the step has a cached successful result
29
- */ export function hasCompletedStep(cache, stepName) {
30
- return cache.has(stepName);
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
- * Add a step attempt to the cache (returns new cache, original unchanged). This
34
- * is an immutable operation.
35
- * @param cache - The existing step attempt cache
36
- * @param attempt - The attempt to add
37
- * @returns A new cache with the attempt added
38
- */ export function addToStepAttemptCache(cache, attempt) {
39
- return new Map([
40
- ...cache,
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
- * Convert a step function result to a JSON-compatible value. Undefined values
49
- * are converted to null for JSON serialization.
50
- * @param result - The result from a step function
51
- * @returns A JSON-serializable value
52
- */ export function normalizeStepOutput(result) {
53
- return result ?? null;
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
- * Calculate the resume time for a sleep step.
57
- * @param duration - The duration string to sleep for
58
- * @param now - The current timestamp (defaults to Date.now())
59
- * @returns A Result containing the resume Date or an Error
60
- */ export function calculateSleepResumeAt(duration, now = Date.now()) {
61
- const result = parseDuration(duration);
62
- if (!result.ok) {
63
- return err(result.error);
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
- * Create the context object for a sleep step attempt.
69
- * @param resumeAt - The time when the sleep should resume
70
- * @returns The context object for the sleep step
71
- */ export function createSleepContext(resumeAt) {
72
- return {
73
- kind: "sleep",
74
- resumeAt: resumeAt.toISOString()
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
@@ -1 +1 @@
1
- {"version":3,"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 | \"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"],"names":["parseDuration","err","ok","createStepAttemptCacheFromAttempts","attempts","successfulAttempts","filter","attempt","status","Map","map","stepName","getCachedStepAttempt","cache","get","hasCompletedStep","has","addToStepAttemptCache","normalizeStepOutput","result","calculateSleepResumeAt","duration","now","Date","error","value","createSleepContext","resumeAt","kind","toISOString"],"mappings":"AACA,SAASA,aAAa,QAAQ,gBAAa;AAG3C,SAASC,GAAG,EAAEC,EAAE,QAAQ,cAAW;AAmDnC;;;;;CAKC,GACD,OAAO,SAASC,mCACdC,QAAgC;IAEhC,2DAA2D;IAC3D,MAAMC,qBAAqBD,SAASE,MAAM,CACxC,CAACC,UAAYA,QAAQC,MAAM,KAAK,eAAeD,QAAQC,MAAM,KAAK;IAGpE,OAAO,IAAIC,IAAIJ,mBAAmBK,GAAG,CAAC,CAACH,UAAY;YAACA,QAAQI,QAAQ;YAAEJ;SAAQ;AAChF;AAEA;;;;;CAKC,GACD,OAAO,SAASK,qBACdC,KAAuB,EACvBF,QAAgB;IAEhB,OAAOE,MAAMC,GAAG,CAACH;AACnB;AAEA;;;;;CAKC,GACD,OAAO,SAASI,iBAAiBF,KAAuB,EAAEF,QAAgB;IACxE,OAAOE,MAAMG,GAAG,CAACL;AACnB;AAEA;;;;;;CAMC,GACD,OAAO,SAASM,sBACdJ,KAAuB,EACvBN,OAA8B;IAE9B,OAAO,IAAIE,IAAI;WAAII;QAAO;YAACN,QAAQI,QAAQ;YAAEJ;SAAQ;KAAC;AACxD;AAEA;;;;;CAKC,GACD,OAAO,SAASW,oBAAoBC,MAAe;IACjD,OAAQA,UAAU;AACpB;AAEA;;;;;CAKC,GACD,OAAO,SAASC,uBACdC,QAAwB,EACxBC,MAAcC,KAAKD,GAAG,EAAE;IAExB,MAAMH,SAASnB,cAAcqB;IAE7B,IAAI,CAACF,OAAOjB,EAAE,EAAE;QACd,OAAOD,IAAIkB,OAAOK,KAAK;IACzB;IAEA,OAAOtB,GAAG,IAAIqB,KAAKD,MAAMH,OAAOM,KAAK;AACvC;AAEA;;;;CAIC,GACD,OAAO,SAASC,mBAAmBC,QAAwB;IAIzD,OAAO;QACLC,MAAM;QACND,UAAUA,SAASE,WAAW;IAChC;AACF"}
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"}
@@ -1,79 +1,51 @@
1
- import type { SerializedError } from "./error";
2
- import type { JsonValue } from "./json";
3
- import type { StandardSchemaV1 } from "./schema";
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
- export type WorkflowRunStatus = "pending" | "running" | "sleeping" | "succeeded" | "completed" | "failed" | "canceled";
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
- export interface WorkflowRun {
12
- namespaceId: string;
13
- id: string;
14
- workflowName: string;
15
- version: string | null;
16
- status: WorkflowRunStatus;
17
- idempotencyKey: string | null;
18
- config: JsonValue;
19
- context: JsonValue | null;
20
- input: JsonValue | null;
21
- output: JsonValue | null;
22
- error: SerializedError | null;
23
- attempts: number;
24
- parentStepAttemptNamespaceId: string | null;
25
- parentStepAttemptId: string | null;
26
- workerId: string | null;
27
- availableAt: Date | null;
28
- deadlineAt: Date | null;
29
- startedAt: Date | null;
30
- finishedAt: Date | null;
31
- createdAt: Date;
32
- updatedAt: Date;
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
- export type SchemaInput<TSchema, Fallback> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : Fallback;
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
- export type SchemaOutput<TSchema, Fallback> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : Fallback;
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
- export type ValidationResult<T> = {
47
- success: true;
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","sourceRoot":"","sources":["../../src/core/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,SAAS,GACT,UAAU,GACV,WAAW,GACX,WAAW,GACX,QAAQ,GACR,UAAU,CAAC;AAEf;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,SAAS,GAAG,IAAI,CAAC;IAC1B,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC;IAC9B,QAAQ,EAAE,MA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