@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,47 +1,37 @@
1
+ //#region src/core/workflow.ts
1
2
  /**
2
- * Default configuration for result polling when awaiting workflow completion.
3
- */ export const DEFAULT_WORKFLOW_RESULT_CONFIG = {
4
- /** Polling interval in milliseconds (1 second) */ pollIntervalMs: 1000,
5
- /** Timeout in milliseconds (5 minutes) */ timeoutMs: 5 * 60 * 1000
3
+ * Default configuration for result polling when awaiting workflow completion.
4
+ */
5
+ const DEFAULT_WORKFLOW_RESULT_CONFIG = {
6
+ pollIntervalMs: 1e3,
7
+ timeoutMs: 300 * 1e3
6
8
  };
7
9
  /**
8
- * Validate input against a Standard Schema. Pure async function that validates
9
- * input and returns a ValidationResult.
10
- * @param schema - The Standard Schema to validate against (or null/undefined
11
- * for no validation)
12
- * @param input - The input value to validate
13
- * @returns A ValidationResult containing either the validated value or an error
14
- * message
15
- */ export async function validateInput(schema, input) {
16
- // No schema means no validation - pass through as-is
17
- if (!schema) {
18
- return {
19
- success: true,
20
- value: input
21
- };
22
- }
23
- // Validate using Standard Schema v1 protocol https://standardschema.dev
24
- const result = schema["~standard"].validate(input);
25
- const resolved = await Promise.resolve(result);
26
- if (resolved.issues) {
27
- const messages = resolved.issues.length > 0 ? resolved.issues.map((issue)=>issue.message).join("; ") : "Validation failed";
28
- return {
29
- success: false,
30
- error: messages
31
- };
32
- }
33
- return {
34
- success: true,
35
- value: resolved.value
36
- };
37
- }
38
- /**
39
- * Check if a workflow run status represents a terminal state.
40
- * @param status - The workflow run status
41
- * @returns True if the status is terminal (succeeded, completed, failed, or canceled).
42
- * Note: 'succeeded' is deprecated in favor of 'completed'.
43
- */ export function isTerminalStatus(status) {
44
- return status === "succeeded" || status === "completed" || status === "failed" || status === "canceled";
10
+ * Validate input against a Standard Schema. Pure async function that validates
11
+ * input and returns a ValidationResult.
12
+ * @param schema - The Standard Schema to validate against (or null/undefined
13
+ * for no validation)
14
+ * @param input - The input value to validate
15
+ * @returns A ValidationResult containing either the validated value or an error
16
+ * message
17
+ */
18
+ async function validateInput(schema, input) {
19
+ if (!schema) return {
20
+ success: true,
21
+ value: input
22
+ };
23
+ const result = schema["~standard"].validate(input);
24
+ const resolved = await Promise.resolve(result);
25
+ if (resolved.issues) return {
26
+ success: false,
27
+ error: resolved.issues.length > 0 ? resolved.issues.map((issue) => issue.message).join("; ") : "Validation failed"
28
+ };
29
+ return {
30
+ success: true,
31
+ value: resolved.value
32
+ };
45
33
  }
46
34
 
35
+ //#endregion
36
+ export { validateInput };
47
37
  //# sourceMappingURL=workflow.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/workflow.ts"],"sourcesContent":["import type { SerializedError } from \"./error\";\nimport type { JsonValue } from \"./json\";\nimport type { StandardSchemaV1 } from \"./schema\";\n\n/**\n * Status of a workflow run through its lifecycle.\n */\nexport type WorkflowRunStatus =\n | \"pending\"\n | \"running\"\n | \"sleeping\"\n | \"succeeded\" // deprecated in favor of 'completed'\n | \"completed\"\n | \"failed\"\n | \"canceled\";\n\n/**\n * WorkflowRun represents a single execution instance of a workflow.\n */\nexport interface WorkflowRun {\n namespaceId: string;\n id: string;\n workflowName: string;\n version: string | null;\n status: WorkflowRunStatus;\n idempotencyKey: string | null;\n config: JsonValue; // user-defined config\n context: JsonValue | null; // runtime execution metadata\n input: JsonValue | null;\n output: JsonValue | null;\n error: SerializedError | null;\n attempts: number;\n parentStepAttemptNamespaceId: string | null;\n parentStepAttemptId: string | null;\n workerId: string | null;\n availableAt: Date | null;\n deadlineAt: Date | null;\n startedAt: Date | null;\n finishedAt: Date | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\n/**\n * Infers the input type from a Standard Schema.\n */\nexport type SchemaInput<TSchema, Fallback> = TSchema extends StandardSchemaV1\n ? StandardSchemaV1.InferInput<TSchema>\n : Fallback;\n\n/**\n * Infers the output type from a Standard Schema.\n */\nexport type SchemaOutput<TSchema, Fallback> = TSchema extends StandardSchemaV1\n ? StandardSchemaV1.InferOutput<TSchema>\n : Fallback;\n\n/**\n * Result of input validation - either success with a value or failure with an\n * error message.\n */\nexport type ValidationResult<T> = { success: true; value: T } | { success: false; error: string };\n\n/**\n * Default configuration for result polling when awaiting workflow completion.\n */\nexport const DEFAULT_WORKFLOW_RESULT_CONFIG = {\n /** Polling interval in milliseconds (1 second) */\n pollIntervalMs: 1000,\n /** Timeout in milliseconds (5 minutes) */\n timeoutMs: 5 * 60 * 1000,\n} as const;\n\n/**\n * Validate input against a Standard Schema. Pure async function that validates\n * input and returns a ValidationResult.\n * @param schema - The Standard Schema to validate against (or null/undefined\n * for no validation)\n * @param input - The input value to validate\n * @returns A ValidationResult containing either the validated value or an error\n * message\n */\nexport async function validateInput<RunInput, Input>(\n schema: StandardSchemaV1<RunInput, Input> | null | undefined,\n input: RunInput | undefined,\n): Promise<ValidationResult<Input>> {\n // No schema means no validation - pass through as-is\n if (!schema) {\n return {\n success: true,\n value: input as unknown as Input,\n };\n }\n\n // Validate using Standard Schema v1 protocol https://standardschema.dev\n const result = schema[\"~standard\"].validate(input);\n const resolved = await Promise.resolve(result);\n\n if (resolved.issues) {\n const messages =\n resolved.issues.length > 0\n ? resolved.issues.map((issue) => issue.message).join(\"; \")\n : \"Validation failed\";\n return {\n success: false,\n error: messages,\n };\n }\n\n return {\n success: true,\n value: resolved.value,\n };\n}\n\n/**\n * Check if a workflow run status represents a terminal state.\n * @param status - The workflow run status\n * @returns True if the status is terminal (succeeded, completed, failed, or canceled).\n * Note: 'succeeded' is deprecated in favor of 'completed'.\n */\nexport function isTerminalStatus(\n status: string,\n): status is \"succeeded\" | \"completed\" | \"failed\" | \"canceled\" {\n return (\n status === \"succeeded\" || status === \"completed\" || status === \"failed\" || status === \"canceled\"\n );\n}\n"],"names":["DEFAULT_WORKFLOW_RESULT_CONFIG","pollIntervalMs","timeoutMs","validateInput","schema","input","success","value","result","validate","resolved","Promise","resolve","issues","messages","length","map","issue","message","join","error","isTerminalStatus","status"],"mappings":"AA+DA;;CAEC,GACD,OAAO,MAAMA,iCAAiC;IAC5C,gDAAgD,GAChDC,gBAAgB;IAChB,wCAAwC,GACxCC,WAAW,IAAI,KAAK;AACtB,EAAW;AAEX;;;;;;;;CAQC,GACD,OAAO,eAAeC,cACpBC,MAA4D,EAC5DC,KAA2B;IAE3B,qDAAqD;IACrD,IAAI,CAACD,QAAQ;QACX,OAAO;YACLE,SAAS;YACTC,OAAOF;QACT;IACF;IAEA,wEAAwE;IACxE,MAAMG,SAASJ,MAAM,CAAC,YAAY,CAACK,QAAQ,CAACJ;IAC5C,MAAMK,WAAW,MAAMC,QAAQC,OAAO,CAACJ;IAEvC,IAAIE,SAASG,MAAM,EAAE;QACnB,MAAMC,WACJJ,SAASG,MAAM,CAACE,MAAM,GAAG,IACrBL,SAASG,MAAM,CAACG,GAAG,CAAC,CAACC,QAAUA,MAAMC,OAAO,EAAEC,IAAI,CAAC,QACnD;QACN,OAAO;YACLb,SAAS;YACTc,OAAON;QACT;IACF;IAEA,OAAO;QACLR,SAAS;QACTC,OAAOG,SAASH,KAAK;IACvB;AACF;AAEA;;;;;CAKC,GACD,OAAO,SAASc,iBACdC,MAAc;IAEd,OACEA,WAAW,eAAeA,WAAW,eAAeA,WAAW,YAAYA,WAAW;AAE1F"}
1
+ {"version":3,"file":"workflow.js","names":[],"sources":["../../src/core/workflow.ts"],"sourcesContent":["import { type SerializedError } from \"./error\";\nimport { type JsonValue } from \"./json\";\nimport { type StandardSchemaV1 } from \"./schema\";\n\n/**\n * Status of a workflow run through its lifecycle.\n */\nexport type WorkflowRunStatus =\n | \"pending\"\n | \"running\"\n | \"sleeping\"\n | \"paused\"\n | \"succeeded\" // deprecated in favor of 'completed'\n | \"completed\"\n | \"failed\"\n | \"canceled\";\n\n/**\n * WorkflowRun represents a single execution instance of a workflow.\n */\nexport interface WorkflowRun {\n namespaceId: string;\n id: string;\n workflowName: string;\n version: string | null;\n status: WorkflowRunStatus;\n idempotencyKey: string | null;\n config: JsonValue; // user-defined config\n context: JsonValue | null; // runtime execution metadata\n input: JsonValue | null;\n output: JsonValue | null;\n error: SerializedError | null;\n attempts: number;\n parentStepAttemptNamespaceId: string | null;\n parentStepAttemptId: string | null;\n workerId: string | null;\n availableAt: Date | null;\n deadlineAt: Date | null;\n startedAt: Date | null;\n finishedAt: Date | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\n/**\n * Infers the input type from a Standard Schema.\n */\nexport type SchemaInput<TSchema, Fallback> = TSchema extends StandardSchemaV1\n ? StandardSchemaV1.InferInput<TSchema>\n : Fallback;\n\n/**\n * Infers the output type from a Standard Schema.\n */\nexport type SchemaOutput<TSchema, Fallback> = TSchema extends StandardSchemaV1\n ? StandardSchemaV1.InferOutput<TSchema>\n : Fallback;\n\n/**\n * Result of input validation - either success with a value or failure with an\n * error message.\n */\nexport type ValidationResult<T> = { success: true; value: T } | { success: false; error: string };\n\n/**\n * Default configuration for result polling when awaiting workflow completion.\n */\nexport const DEFAULT_WORKFLOW_RESULT_CONFIG = {\n /** Polling interval in milliseconds (1 second) */\n pollIntervalMs: 1000,\n /** Timeout in milliseconds (5 minutes) */\n timeoutMs: 5 * 60 * 1000,\n} as const;\n\n/**\n * Validate input against a Standard Schema. Pure async function that validates\n * input and returns a ValidationResult.\n * @param schema - The Standard Schema to validate against (or null/undefined\n * for no validation)\n * @param input - The input value to validate\n * @returns A ValidationResult containing either the validated value or an error\n * message\n */\nexport async function validateInput<RunInput, Input>(\n schema: StandardSchemaV1<RunInput, Input> | null | undefined,\n input: RunInput | undefined,\n): Promise<ValidationResult<Input>> {\n // No schema means no validation - pass through as-is\n if (!schema) {\n return {\n success: true,\n value: input as unknown as Input,\n };\n }\n\n // Validate using Standard Schema v1 protocol https://standardschema.dev\n const result = schema[\"~standard\"].validate(input);\n const resolved = await Promise.resolve(result);\n\n if (resolved.issues) {\n const messages =\n resolved.issues.length > 0\n ? resolved.issues.map((issue) => issue.message).join(\"; \")\n : \"Validation failed\";\n return {\n success: false,\n error: messages,\n };\n }\n\n return {\n success: true,\n value: resolved.value,\n };\n}\n\n/**\n * Check if a workflow run status represents a terminal state.\n * @param status - The workflow run status\n * @returns True if the status is terminal (succeeded, completed, failed, or canceled).\n * Note: 'succeeded' is deprecated in favor of 'completed'.\n */\nexport function isTerminalStatus(\n status: string,\n): status is \"succeeded\" | \"completed\" | \"failed\" | \"canceled\" {\n return (\n status === \"succeeded\" || status === \"completed\" || status === \"failed\" || status === \"canceled\"\n );\n}\n"],"mappings":";;;;AAmEA,MAAa,iCAAiC;CAE5C,gBAAgB;CAEhB,WAAW,MAAS;CACrB;;;;;;;;;;AAWD,eAAsB,cACpB,QACA,OACkC;AAElC,KAAI,CAAC,OACH,QAAO;EACL,SAAS;EACT,OAAO;EACR;CAIH,MAAM,SAAS,OAAO,aAAa,SAAS,MAAM;CAClD,MAAM,WAAW,MAAM,QAAQ,QAAQ,OAAO;AAE9C,KAAI,SAAS,OAKX,QAAO;EACL,SAAS;EACT,OALA,SAAS,OAAO,SAAS,IACrB,SAAS,OAAO,KAAK,UAAU,MAAM,QAAQ,CAAC,KAAK,KAAK,GACxD;EAIL;AAGH,QAAO;EACL,SAAS;EACT,OAAO,SAAS;EACjB"}
@@ -1,48 +1,58 @@
1
- import { type Knex } from "knex";
2
- import { type Backend, type CancelWorkflowRunParams, type ClaimWorkflowRunParams, type CompleteStepAttemptParams, type CompleteWorkflowRunParams, type CreateStepAttemptParams, type CreateWorkflowRunParams, type ExtendWorkflowRunLeaseParams, type FailStepAttemptParams, type FailWorkflowRunParams, type GetStepAttemptParams, type GetWorkflowRunParams, type ListStepAttemptsParams, type ListWorkflowRunsParams, type PaginatedResponse, type SleepWorkflowRunParams } from "../backend";
3
- import type { StepAttempt } from "../core/step";
4
- import type { WorkflowRun } from "../core/workflow";
5
- import { type OnSubscribed } from "./pubsub";
6
- export declare const DEFAULT_LISTEN_CHANNEL: "new_tasks";
1
+ import { StepAttempt } from "../core/step.js";
2
+ import { WorkflowRun } from "../core/workflow.js";
3
+ import { OnSubscribed } from "./pubsub.js";
4
+ import { Backend, CancelWorkflowRunParams, ClaimWorkflowRunParams, CompleteStepAttemptParams, CompleteWorkflowRunParams, CreateStepAttemptParams, CreateWorkflowRunParams, ExtendWorkflowRunLeaseParams, FailStepAttemptParams, FailWorkflowRunParams, GetStepAttemptParams, GetWorkflowRunParams, ListStepAttemptsParams, ListWorkflowRunsParams, PaginatedResponse, PauseWorkflowRunParams, ResumeWorkflowRunParams, SleepWorkflowRunParams } from "../backend.js";
5
+ import { Knex } from "knex";
6
+
7
+ //#region src/database/backend.d.ts
7
8
  interface BackendPostgresOptions {
8
- namespaceId?: string;
9
- runMigrations?: boolean;
10
- usePubSub?: boolean;
9
+ namespaceId?: string;
10
+ runMigrations?: boolean;
11
+ usePubSub?: boolean;
11
12
  }
12
13
  /**
13
14
  * Manages a connection to a Postgres database for workflow operations.
14
15
  */
15
- export declare class BackendPostgres implements Backend {
16
- private config;
17
- private namespaceId;
18
- private usePubSub;
19
- private pubsub;
20
- private initialized;
21
- private runMigrations;
22
- private _knex;
23
- private get knex();
24
- constructor(config: Knex.Config, options?: BackendPostgresOptions);
25
- initialize(): Promise<void>;
26
- subscribe(callback: OnSubscribed): Promise<void>;
27
- publish(payload?: string): Promise<void>;
28
- stop(): Promise<void>;
29
- createWorkflowRun(params: CreateWorkflowRunParams): Promise<WorkflowRun>;
30
- getWorkflowRun(params: GetWorkflowRunParams): Promise<WorkflowRun | null>;
31
- listWorkflowRuns(params: ListWorkflowRunsParams): Promise<PaginatedResponse<WorkflowRun>>;
32
- private buildListWorkflowRunsWhere;
33
- claimWorkflowRun(params: ClaimWorkflowRunParams): Promise<WorkflowRun | null>;
34
- extendWorkflowRunLease(params: ExtendWorkflowRunLeaseParams): Promise<WorkflowRun>;
35
- sleepWorkflowRun(params: SleepWorkflowRunParams): Promise<WorkflowRun>;
36
- completeWorkflowRun(params: CompleteWorkflowRunParams): Promise<WorkflowRun>;
37
- failWorkflowRun(params: FailWorkflowRunParams): Promise<WorkflowRun>;
38
- cancelWorkflowRun(params: CancelWorkflowRunParams): Promise<WorkflowRun>;
39
- createStepAttempt(params: CreateStepAttemptParams): Promise<StepAttempt>;
40
- getStepAttempt(params: GetStepAttemptParams): Promise<StepAttempt | null>;
41
- listStepAttempts(params: ListStepAttemptsParams): Promise<PaginatedResponse<StepAttempt>>;
42
- private buildListStepAttemptsWhere;
43
- private processPaginationResults;
44
- completeStepAttempt(params: CompleteStepAttemptParams): Promise<StepAttempt>;
45
- failStepAttempt(params: FailStepAttemptParams): Promise<StepAttempt>;
16
+ declare class BackendPostgres implements Backend {
17
+ private config;
18
+ private namespaceId;
19
+ private usePubSub;
20
+ private pubsub;
21
+ private initialized;
22
+ private runMigrations;
23
+ private _knex;
24
+ private get knex();
25
+ constructor(config: Knex.Config, options?: BackendPostgresOptions);
26
+ initialize(): Promise<void>;
27
+ subscribe(callback: OnSubscribed): Promise<void>;
28
+ publish(payload?: string): Promise<void>;
29
+ stop(): Promise<void>;
30
+ createWorkflowRun(params: CreateWorkflowRunParams): Promise<WorkflowRun>;
31
+ getWorkflowRun(params: GetWorkflowRunParams): Promise<WorkflowRun | null>;
32
+ listWorkflowRuns(params: ListWorkflowRunsParams): Promise<PaginatedResponse<WorkflowRun>>;
33
+ private buildListWorkflowRunsWhere;
34
+ claimWorkflowRun(params: ClaimWorkflowRunParams): Promise<WorkflowRun | null>;
35
+ extendWorkflowRunLease(params: ExtendWorkflowRunLeaseParams): Promise<WorkflowRun>;
36
+ sleepWorkflowRun(params: SleepWorkflowRunParams): Promise<WorkflowRun>;
37
+ completeWorkflowRun(params: CompleteWorkflowRunParams): Promise<WorkflowRun>;
38
+ failWorkflowRun(params: FailWorkflowRunParams): Promise<WorkflowRun>;
39
+ cancelWorkflowRun(params: CancelWorkflowRunParams): Promise<WorkflowRun>;
40
+ pauseWorkflowRun(params: PauseWorkflowRunParams): Promise<WorkflowRun>;
41
+ resumeWorkflowRun(params: ResumeWorkflowRunParams): Promise<WorkflowRun>;
42
+ createStepAttempt(params: CreateStepAttemptParams): Promise<StepAttempt>;
43
+ getStepAttempt(params: GetStepAttemptParams): Promise<StepAttempt | null>;
44
+ listStepAttempts(params: ListStepAttemptsParams): Promise<PaginatedResponse<StepAttempt>>;
45
+ private buildListStepAttemptsWhere;
46
+ private processPaginationResults;
47
+ completeStepAttempt(params: CompleteStepAttemptParams): Promise<StepAttempt | null>;
48
+ failStepAttempt(params: FailStepAttemptParams): Promise<StepAttempt | null>;
49
+ /**
50
+ * completeStepAttempt/failStepAttempt에서 UPDATE가 0건일 때,
51
+ * 외부 상태 변경(pause/cancel)에 의한 것인지 판단합니다.
52
+ * - 외부 상태 변경이면 해당 step의 상태도 워크플로우와 동일하게 맞추고 null을 반환합니다.
53
+ * - 그 외에는 예상하지 못한 상황이므로 에러를 throw합니다.
54
+ */
55
+ private handleStepAttemptUpdateMiss;
46
56
  }
47
57
  /**
48
58
  * Cursor used for pagination. Requires created_at and id fields. Because JS
@@ -50,10 +60,7 @@ export declare class BackendPostgres implements Backend {
50
60
  * be stored with millisecond precision in paginated tables to avoid issues with
51
61
  * cursor comparisons.
52
62
  */
53
- interface Cursor {
54
- createdAt: Date;
55
- id: string;
56
- }
57
- export declare function decodeCursor(cursor: string): Cursor;
58
- export {};
63
+
64
+ //#endregion
65
+ export { BackendPostgres };
59
66
  //# sourceMappingURL=backend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../src/database/backend.ts"],"names":[],"mappings":"AAEA,OAAa,EAAE,KAAK,IAAI,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,yBAAyB,EAC9B,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAE5B,KAAK,4BAA4B,EACjC,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,i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