openworkflow 0.4.0 → 0.5.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 (143) hide show
  1. package/README.md +57 -46
  2. package/dist/backend-postgres/index.d.ts +44 -0
  3. package/dist/backend-postgres/index.d.ts.map +1 -0
  4. package/dist/backend-postgres/index.js +535 -0
  5. package/dist/backend-postgres/index.js.map +1 -0
  6. package/dist/backend-postgres/postgres.d.ts +42 -0
  7. package/dist/backend-postgres/postgres.d.ts.map +1 -0
  8. package/dist/backend-postgres/postgres.js +234 -0
  9. package/dist/backend-postgres/postgres.js.map +1 -0
  10. package/dist/backend-sqlite/index.d.ts +42 -0
  11. package/dist/backend-sqlite/index.d.ts.map +1 -0
  12. package/dist/backend-sqlite/index.js +655 -0
  13. package/dist/backend-sqlite/index.js.map +1 -0
  14. package/dist/backend-sqlite/sqlite.d.ts +61 -0
  15. package/dist/backend-sqlite/sqlite.d.ts.map +1 -0
  16. package/dist/backend-sqlite/sqlite.js +247 -0
  17. package/dist/backend-sqlite/sqlite.js.map +1 -0
  18. package/dist/backend.d.ts +21 -89
  19. package/dist/backend.d.ts.map +1 -1
  20. package/dist/backend.js +0 -21
  21. package/dist/backend.js.map +1 -1
  22. package/dist/bin/openworkflow.d.ts +3 -0
  23. package/dist/bin/openworkflow.d.ts.map +1 -0
  24. package/dist/bin/openworkflow.js +44 -0
  25. package/dist/bin/openworkflow.js.map +1 -0
  26. package/dist/client.d.ts +68 -80
  27. package/dist/client.d.ts.map +1 -1
  28. package/dist/client.js +83 -53
  29. package/dist/client.js.map +1 -1
  30. package/dist/config.d.ts +34 -0
  31. package/dist/config.d.ts.map +1 -0
  32. package/dist/config.js +49 -0
  33. package/dist/config.js.map +1 -0
  34. package/dist/{duration.d.ts → core/duration.d.ts} +5 -2
  35. package/dist/core/duration.d.ts.map +1 -0
  36. package/dist/{duration.js → core/duration.js} +9 -6
  37. package/dist/core/duration.js.map +1 -0
  38. package/dist/core/error.d.ts +14 -0
  39. package/dist/core/error.d.ts.map +1 -0
  40. package/dist/core/error.js +18 -0
  41. package/dist/core/error.js.map +1 -0
  42. package/dist/core/json.d.ts +5 -0
  43. package/dist/core/json.d.ts.map +1 -0
  44. package/dist/core/json.js +2 -0
  45. package/dist/core/json.js.map +1 -0
  46. package/dist/core/result.d.ts +22 -0
  47. package/dist/core/result.d.ts.map +1 -0
  48. package/dist/core/result.js +17 -0
  49. package/dist/core/result.js.map +1 -0
  50. package/dist/core/retry.d.ts +7 -0
  51. package/dist/core/retry.d.ts.map +1 -0
  52. package/dist/core/retry.js +7 -0
  53. package/dist/core/retry.js.map +1 -0
  54. package/dist/core/schema.d.ts.map +1 -0
  55. package/dist/core/schema.js.map +1 -0
  56. package/dist/core/step.d.ts +89 -0
  57. package/dist/core/step.d.ts.map +1 -0
  58. package/dist/core/step.js +66 -0
  59. package/dist/core/step.js.map +1 -0
  60. package/dist/core/workflow.d.ts +63 -0
  61. package/dist/core/workflow.d.ts.map +1 -0
  62. package/dist/core/workflow.js +35 -0
  63. package/dist/core/workflow.js.map +1 -0
  64. package/dist/execution.d.ts +69 -0
  65. package/dist/execution.d.ts.map +1 -0
  66. package/dist/execution.js +188 -0
  67. package/dist/execution.js.map +1 -0
  68. package/dist/index.d.ts +2 -1
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +2 -1
  71. package/dist/index.js.map +1 -1
  72. package/dist/internal.d.ts +8 -0
  73. package/dist/internal.d.ts.map +1 -0
  74. package/dist/internal.js +5 -0
  75. package/dist/internal.js.map +1 -0
  76. package/dist/pg/backend.d.ts +42 -0
  77. package/dist/pg/backend.d.ts.map +1 -0
  78. package/dist/pg/backend.js +534 -0
  79. package/dist/pg/backend.js.map +1 -0
  80. package/dist/pg/index.d.ts +3 -0
  81. package/dist/pg/index.d.ts.map +1 -0
  82. package/dist/pg/index.js +3 -0
  83. package/dist/pg/index.js.map +1 -0
  84. package/dist/pg/postgres.d.ts +42 -0
  85. package/dist/pg/postgres.d.ts.map +1 -0
  86. package/dist/pg/postgres.js +234 -0
  87. package/dist/pg/postgres.js.map +1 -0
  88. package/dist/pg/scripts/db-migrate.d.ts +2 -0
  89. package/dist/pg/scripts/db-migrate.d.ts.map +1 -0
  90. package/dist/pg/scripts/db-migrate.js +5 -0
  91. package/dist/pg/scripts/db-migrate.js.map +1 -0
  92. package/dist/pg/scripts/db-reset.d.ts +2 -0
  93. package/dist/pg/scripts/db-reset.d.ts.map +1 -0
  94. package/dist/pg/scripts/db-reset.js +6 -0
  95. package/dist/pg/scripts/db-reset.js.map +1 -0
  96. package/dist/pg/scripts/squawk.d.ts +2 -0
  97. package/dist/pg/scripts/squawk.d.ts.map +1 -0
  98. package/dist/pg/scripts/squawk.js +17 -0
  99. package/dist/pg/scripts/squawk.js.map +1 -0
  100. package/dist/pg/vitest.global-setup.d.ts +3 -0
  101. package/dist/pg/vitest.global-setup.d.ts.map +1 -0
  102. package/dist/pg/vitest.global-setup.js +8 -0
  103. package/dist/pg/vitest.global-setup.js.map +1 -0
  104. package/dist/registry.d.ts +27 -0
  105. package/dist/registry.d.ts.map +1 -0
  106. package/dist/registry.js +49 -0
  107. package/dist/registry.js.map +1 -0
  108. package/dist/sqlite/backend.d.ts +40 -0
  109. package/dist/sqlite/backend.d.ts.map +1 -0
  110. package/dist/sqlite/backend.js +654 -0
  111. package/dist/sqlite/backend.js.map +1 -0
  112. package/dist/sqlite/index.d.ts +3 -0
  113. package/dist/sqlite/index.d.ts.map +1 -0
  114. package/dist/sqlite/index.js +3 -0
  115. package/dist/sqlite/index.js.map +1 -0
  116. package/dist/sqlite/sqlite.d.ts +61 -0
  117. package/dist/sqlite/sqlite.d.ts.map +1 -0
  118. package/dist/sqlite/sqlite.js +247 -0
  119. package/dist/sqlite/sqlite.js.map +1 -0
  120. package/dist/testing/backend.testsuite.d.ts +20 -0
  121. package/dist/testing/backend.testsuite.d.ts.map +1 -0
  122. package/dist/testing/backend.testsuite.js +1091 -0
  123. package/dist/testing/backend.testsuite.js.map +1 -0
  124. package/dist/testing/index.d.ts +2 -0
  125. package/dist/testing/index.d.ts.map +1 -0
  126. package/dist/testing/index.js +2 -0
  127. package/dist/testing/index.js.map +1 -0
  128. package/dist/tsconfig.tsbuildinfo +1 -1
  129. package/dist/worker.d.ts +10 -3
  130. package/dist/worker.d.ts.map +1 -1
  131. package/dist/worker.js +29 -195
  132. package/dist/worker.js.map +1 -1
  133. package/dist/workflow.d.ts +60 -0
  134. package/dist/workflow.d.ts.map +1 -0
  135. package/dist/workflow.js +49 -0
  136. package/dist/workflow.js.map +1 -0
  137. package/package.json +16 -6
  138. package/dist/duration.d.ts.map +0 -1
  139. package/dist/duration.js.map +0 -1
  140. package/dist/schema.d.ts.map +0 -1
  141. package/dist/schema.js.map +0 -1
  142. /package/dist/{schema.d.ts → core/schema.d.ts} +0 -0
  143. /package/dist/{schema.js → core/schema.js} +0 -0
@@ -0,0 +1,61 @@
1
+ import { DatabaseSync } from "node:sqlite";
2
+ export type Database = DatabaseSync;
3
+ /**
4
+ * newDatabase creates a new SQLite database connection.
5
+ * @param path - Database file path (or ":memory:") for testing
6
+ * @returns SQLite database connection
7
+ */
8
+ export declare function newDatabase(path: string): Database;
9
+ /**
10
+ * migrations returns the list of migration SQL statements.
11
+ * @returns Migration SQL statements
12
+ */
13
+ export declare function migrations(): string[];
14
+ /**
15
+ * migrate applies pending migrations to the database. Does nothing if the
16
+ * database is already up to date.
17
+ * @param db - SQLite database
18
+ */
19
+ export declare function migrate(db: Database): void;
20
+ /**
21
+ * Helper to generate UUIDs (SQLite doesn't have built-in UUID generation)
22
+ * @returns A UUID string
23
+ */
24
+ export declare function generateUUID(): string;
25
+ /**
26
+ * Helper to get current timestamp in ISO8601 format
27
+ * @returns ISO8601 timestamp string
28
+ */
29
+ export declare function now(): string;
30
+ /**
31
+ * Helper to add milliseconds to a date and return ISO8601 string
32
+ * @param date - ISO8601 date string
33
+ * @param ms - Milliseconds to add
34
+ * @returns Updated ISO8601 date string
35
+ */
36
+ export declare function addMilliseconds(date: string, ms: number): string;
37
+ /**
38
+ * Helper to serialize JSON for SQLite storage
39
+ * @param value - Value to serialize
40
+ * @returns JSON string or null
41
+ */
42
+ export declare function toJSON(value: unknown): string | null;
43
+ /**
44
+ * Helper to deserialize JSON from SQLite storage
45
+ * @param value - JSON string or null
46
+ * @returns Parsed value
47
+ */
48
+ export declare function fromJSON(value: string | null): unknown;
49
+ /**
50
+ * Helper to convert Date to ISO8601 string for SQLite
51
+ * @param date - Date or null
52
+ * @returns ISO8601 date string or null
53
+ */
54
+ export declare function toISO(date: Date | null): string | null;
55
+ /**
56
+ * Helper to convert ISO8601 string from SQLite to Date
57
+ * @param dateStr - ISO8601 date string or null
58
+ * @returns Date or null
59
+ */
60
+ export declare function fromISO(dateStr: string | null): Date | null;
61
+ //# sourceMappingURL=sqlite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/backend-sqlite/sqlite.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,MAAM,QAAQ,GAAG,YAAY,CAAC;AAEpC;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAQlD;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,MAAM,EAAE,CA2IrC;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAQ1C;AAyBD;;;GAGG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;;GAGG;AACH,wBAAgB,GAAG,IAAI,MAAM,CAE5B;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAIhE;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAE3D"}
@@ -0,0 +1,247 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { DatabaseSync } from "node:sqlite";
3
+ /**
4
+ * newDatabase creates a new SQLite database connection.
5
+ * @param path - Database file path (or ":memory:") for testing
6
+ * @returns SQLite database connection
7
+ */
8
+ export function newDatabase(path) {
9
+ const db = new DatabaseSync(path);
10
+ // Only enable WAL mode for file-based databases
11
+ if (path !== ":memory:") {
12
+ db.exec("PRAGMA journal_mode = WAL;");
13
+ }
14
+ db.exec("PRAGMA foreign_keys = ON;");
15
+ return db;
16
+ }
17
+ /**
18
+ * migrations returns the list of migration SQL statements.
19
+ * @returns Migration SQL statements
20
+ */
21
+ export function migrations() {
22
+ return [
23
+ // 0 - init
24
+ `BEGIN;
25
+
26
+ CREATE TABLE IF NOT EXISTS "openworkflow_migrations" (
27
+ "version" INTEGER NOT NULL PRIMARY KEY
28
+ );
29
+
30
+ INSERT OR IGNORE INTO "openworkflow_migrations" ("version")
31
+ VALUES (0);
32
+
33
+ COMMIT;`,
34
+ // 1 - add workflow_runs and step_attempts tables
35
+ `BEGIN;
36
+
37
+ PRAGMA defer_foreign_keys = ON;
38
+
39
+ CREATE TABLE IF NOT EXISTS "workflow_runs" (
40
+ "namespace_id" TEXT NOT NULL,
41
+ "id" TEXT NOT NULL,
42
+ --
43
+ "workflow_name" TEXT NOT NULL,
44
+ "version" TEXT,
45
+ "status" TEXT NOT NULL,
46
+ "idempotency_key" TEXT,
47
+ "config" TEXT NOT NULL,
48
+ "context" TEXT,
49
+ "input" TEXT,
50
+ "output" TEXT,
51
+ "error" TEXT,
52
+ "attempts" INTEGER NOT NULL,
53
+ "parent_step_attempt_namespace_id" TEXT,
54
+ "parent_step_attempt_id" TEXT,
55
+ "worker_id" TEXT,
56
+ "available_at" TEXT,
57
+ "deadline_at" TEXT,
58
+ "started_at" TEXT,
59
+ "finished_at" TEXT,
60
+ "created_at" TEXT NOT NULL,
61
+ "updated_at" TEXT NOT NULL,
62
+ PRIMARY KEY ("namespace_id", "id"),
63
+ FOREIGN KEY ("parent_step_attempt_namespace_id", "parent_step_attempt_id")
64
+ REFERENCES "step_attempts" ("namespace_id", "id")
65
+ ON DELETE SET NULL
66
+ );
67
+
68
+ CREATE TABLE IF NOT EXISTS "step_attempts" (
69
+ "namespace_id" TEXT NOT NULL,
70
+ "id" TEXT NOT NULL,
71
+ --
72
+ "workflow_run_id" TEXT NOT NULL,
73
+ "step_name" TEXT NOT NULL,
74
+ "kind" TEXT NOT NULL,
75
+ "status" TEXT NOT NULL,
76
+ "config" TEXT NOT NULL,
77
+ "context" TEXT,
78
+ "output" TEXT,
79
+ "error" TEXT,
80
+ "child_workflow_run_namespace_id" TEXT,
81
+ "child_workflow_run_id" TEXT,
82
+ "started_at" TEXT,
83
+ "finished_at" TEXT,
84
+ "created_at" TEXT NOT NULL,
85
+ "updated_at" TEXT NOT NULL,
86
+ PRIMARY KEY ("namespace_id", "id"),
87
+ FOREIGN KEY ("namespace_id", "workflow_run_id")
88
+ REFERENCES "workflow_runs" ("namespace_id", "id")
89
+ ON DELETE CASCADE,
90
+ FOREIGN KEY ("child_workflow_run_namespace_id", "child_workflow_run_id")
91
+ REFERENCES "workflow_runs" ("namespace_id", "id")
92
+ ON DELETE SET NULL
93
+ );
94
+
95
+ INSERT OR IGNORE INTO "openworkflow_migrations" ("version")
96
+ VALUES (1);
97
+
98
+ COMMIT;`,
99
+ // 2 - foreign keys
100
+ `BEGIN;
101
+
102
+ -- Foreign keys are defined in migration 1 since SQLite requires them during table creation
103
+ -- This migration exists for version parity with PostgreSQL backend
104
+
105
+ INSERT OR IGNORE INTO "openworkflow_migrations" ("version")
106
+ VALUES (2);
107
+
108
+ COMMIT;`,
109
+ // 3 - validate foreign keys
110
+ `BEGIN;
111
+
112
+ -- Foreign key validation happens automatically in SQLite when PRAGMA foreign_keys = ON
113
+ -- This migration exists for version parity with PostgreSQL backend
114
+
115
+ INSERT OR IGNORE INTO "openworkflow_migrations" ("version")
116
+ VALUES (3);
117
+
118
+ COMMIT;`,
119
+ // 4 - indexes
120
+ `BEGIN;
121
+
122
+ CREATE INDEX IF NOT EXISTS "workflow_runs_status_available_at_created_at_idx"
123
+ ON "workflow_runs" ("namespace_id", "status", "available_at", "created_at");
124
+
125
+ CREATE INDEX IF NOT EXISTS "workflow_runs_workflow_name_idempotency_key_created_at_idx"
126
+ ON "workflow_runs" ("namespace_id", "workflow_name", "idempotency_key", "created_at");
127
+
128
+ CREATE INDEX IF NOT EXISTS "workflow_runs_parent_step_idx"
129
+ ON "workflow_runs" ("parent_step_attempt_namespace_id", "parent_step_attempt_id")
130
+ WHERE parent_step_attempt_namespace_id IS NOT NULL AND parent_step_attempt_id IS NOT NULL;
131
+
132
+ CREATE INDEX IF NOT EXISTS "workflow_runs_created_at_desc_idx"
133
+ ON "workflow_runs" ("namespace_id", "created_at" DESC);
134
+
135
+ CREATE INDEX IF NOT EXISTS "workflow_runs_status_created_at_desc_idx"
136
+ ON "workflow_runs" ("namespace_id", "status", "created_at" DESC);
137
+
138
+ CREATE INDEX IF NOT EXISTS "workflow_runs_workflow_name_status_created_at_desc_idx"
139
+ ON "workflow_runs" ("namespace_id", "workflow_name", "status", "created_at" DESC);
140
+
141
+ CREATE INDEX IF NOT EXISTS "step_attempts_workflow_run_created_at_idx"
142
+ ON "step_attempts" ("namespace_id", "workflow_run_id", "created_at");
143
+
144
+ CREATE INDEX IF NOT EXISTS "step_attempts_workflow_run_step_name_created_at_idx"
145
+ ON "step_attempts" ("namespace_id", "workflow_run_id", "step_name", "created_at");
146
+
147
+ CREATE INDEX IF NOT EXISTS "step_attempts_child_workflow_run_idx"
148
+ ON "step_attempts" ("child_workflow_run_namespace_id", "child_workflow_run_id")
149
+ WHERE child_workflow_run_namespace_id IS NOT NULL AND child_workflow_run_id IS NOT NULL;
150
+
151
+ INSERT OR IGNORE INTO "openworkflow_migrations" ("version")
152
+ VALUES (4);
153
+
154
+ COMMIT;`,
155
+ ];
156
+ }
157
+ /**
158
+ * migrate applies pending migrations to the database. Does nothing if the
159
+ * database is already up to date.
160
+ * @param db - SQLite database
161
+ */
162
+ export function migrate(db) {
163
+ const currentMigrationVersion = getCurrentMigrationVersion(db);
164
+ for (const [i, migrationSql] of migrations().entries()) {
165
+ if (i <= currentMigrationVersion)
166
+ continue; // already applied
167
+ db.exec(migrationSql);
168
+ }
169
+ }
170
+ /**
171
+ * getCurrentMigrationVersion returns the current migration version of the database.
172
+ * @param db - SQLite database
173
+ * @returns Current migration version
174
+ */
175
+ function getCurrentMigrationVersion(db) {
176
+ // check if migrations table exists
177
+ const existsStmt = db.prepare(`
178
+ SELECT COUNT(*) as count
179
+ FROM sqlite_master
180
+ WHERE type = 'table' AND name = 'openworkflow_migrations'
181
+ `);
182
+ const existsResult = existsStmt.get();
183
+ if (!existsResult || existsResult.count === 0)
184
+ return -1;
185
+ // get current version
186
+ const versionStmt = db.prepare(`SELECT MAX("version") AS "version" FROM "openworkflow_migrations";`);
187
+ const versionResult = versionStmt.get();
188
+ return versionResult?.version ?? -1;
189
+ }
190
+ /**
191
+ * Helper to generate UUIDs (SQLite doesn't have built-in UUID generation)
192
+ * @returns A UUID string
193
+ */
194
+ export function generateUUID() {
195
+ return randomUUID();
196
+ }
197
+ /**
198
+ * Helper to get current timestamp in ISO8601 format
199
+ * @returns ISO8601 timestamp string
200
+ */
201
+ export function now() {
202
+ return new Date().toISOString();
203
+ }
204
+ /**
205
+ * Helper to add milliseconds to a date and return ISO8601 string
206
+ * @param date - ISO8601 date string
207
+ * @param ms - Milliseconds to add
208
+ * @returns Updated ISO8601 date string
209
+ */
210
+ export function addMilliseconds(date, ms) {
211
+ const d = new Date(date);
212
+ d.setMilliseconds(d.getMilliseconds() + ms);
213
+ return d.toISOString();
214
+ }
215
+ /**
216
+ * Helper to serialize JSON for SQLite storage
217
+ * @param value - Value to serialize
218
+ * @returns JSON string or null
219
+ */
220
+ export function toJSON(value) {
221
+ return value === null || value === undefined ? null : JSON.stringify(value);
222
+ }
223
+ /**
224
+ * Helper to deserialize JSON from SQLite storage
225
+ * @param value - JSON string or null
226
+ * @returns Parsed value
227
+ */
228
+ export function fromJSON(value) {
229
+ return value === null ? null : JSON.parse(value);
230
+ }
231
+ /**
232
+ * Helper to convert Date to ISO8601 string for SQLite
233
+ * @param date - Date or null
234
+ * @returns ISO8601 date string or null
235
+ */
236
+ export function toISO(date) {
237
+ return date ? date.toISOString() : null;
238
+ }
239
+ /**
240
+ * Helper to convert ISO8601 string from SQLite to Date
241
+ * @param dateStr - ISO8601 date string or null
242
+ * @returns Date or null
243
+ */
244
+ export function fromISO(dateStr) {
245
+ return dateStr ? new Date(dateStr) : null;
246
+ }
247
+ //# sourceMappingURL=sqlite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../src/backend-sqlite/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,EAAE,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;IAClC,gDAAgD;IAChD,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;QACxB,EAAE,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;IACxC,CAAC;IACD,EAAE,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;IACrC,OAAO,EAAE,CAA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AE,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,GAAG;IACjB,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,EAAU;IACtD,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;IAC5C,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,KAAc;IACnC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAoB;IAC3C,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACnD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,IAAiB;IACrC,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,OAAsB;IAC5C,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5C,CAAC"}
package/dist/backend.d.ts CHANGED
@@ -1,22 +1,27 @@
1
+ import type { SerializedError } from "./core/error.js";
2
+ import { JsonValue } from "./core/json.js";
3
+ import type { StepAttempt, StepAttemptContext, StepKind } from "./core/step.js";
4
+ import type { WorkflowRun } from "./core/workflow.js";
1
5
  export declare const DEFAULT_NAMESPACE_ID = "default";
2
6
  /**
3
7
  * Backend is the interface for backend providers to implement.
4
8
  */
5
9
  export interface Backend {
6
- createWorkflowRun(params: CreateWorkflowRunParams): Promise<WorkflowRun>;
7
- getWorkflowRun(params: GetWorkflowRunParams): Promise<WorkflowRun | null>;
8
- listWorkflowRuns(params: ListWorkflowRunsParams): Promise<PaginatedResponse<WorkflowRun>>;
9
- claimWorkflowRun(params: ClaimWorkflowRunParams): Promise<WorkflowRun | null>;
10
- extendWorkflowRunLease(params: ExtendWorkflowRunLeaseParams): Promise<WorkflowRun>;
11
- sleepWorkflowRun(params: SleepWorkflowRunParams): Promise<WorkflowRun>;
12
- completeWorkflowRun(params: CompleteWorkflowRunParams): Promise<WorkflowRun>;
13
- failWorkflowRun(params: FailWorkflowRunParams): Promise<WorkflowRun>;
14
- cancelWorkflowRun(params: CancelWorkflowRunParams): Promise<WorkflowRun>;
15
- createStepAttempt(params: CreateStepAttemptParams): Promise<StepAttempt>;
16
- getStepAttempt(params: GetStepAttemptParams): Promise<StepAttempt | null>;
17
- listStepAttempts(params: ListStepAttemptsParams): Promise<PaginatedResponse<StepAttempt>>;
18
- completeStepAttempt(params: CompleteStepAttemptParams): Promise<StepAttempt>;
19
- failStepAttempt(params: FailStepAttemptParams): Promise<StepAttempt>;
10
+ createWorkflowRun(params: Readonly<CreateWorkflowRunParams>): Promise<WorkflowRun>;
11
+ getWorkflowRun(params: Readonly<GetWorkflowRunParams>): Promise<WorkflowRun | null>;
12
+ listWorkflowRuns(params: Readonly<ListWorkflowRunsParams>): Promise<PaginatedResponse<WorkflowRun>>;
13
+ claimWorkflowRun(params: Readonly<ClaimWorkflowRunParams>): Promise<WorkflowRun | null>;
14
+ extendWorkflowRunLease(params: Readonly<ExtendWorkflowRunLeaseParams>): Promise<WorkflowRun>;
15
+ sleepWorkflowRun(params: Readonly<SleepWorkflowRunParams>): Promise<WorkflowRun>;
16
+ completeWorkflowRun(params: Readonly<CompleteWorkflowRunParams>): Promise<WorkflowRun>;
17
+ failWorkflowRun(params: Readonly<FailWorkflowRunParams>): Promise<WorkflowRun>;
18
+ cancelWorkflowRun(params: Readonly<CancelWorkflowRunParams>): Promise<WorkflowRun>;
19
+ createStepAttempt(params: Readonly<CreateStepAttemptParams>): Promise<StepAttempt>;
20
+ getStepAttempt(params: Readonly<GetStepAttemptParams>): Promise<StepAttempt | null>;
21
+ listStepAttempts(params: Readonly<ListStepAttemptsParams>): Promise<PaginatedResponse<StepAttempt>>;
22
+ completeStepAttempt(params: Readonly<CompleteStepAttemptParams>): Promise<StepAttempt>;
23
+ failStepAttempt(params: Readonly<FailStepAttemptParams>): Promise<StepAttempt>;
24
+ stop(): Promise<void>;
20
25
  }
21
26
  export interface CreateWorkflowRunParams {
22
27
  workflowName: string;
@@ -54,7 +59,7 @@ export interface CompleteWorkflowRunParams {
54
59
  export interface FailWorkflowRunParams {
55
60
  workflowRunId: string;
56
61
  workerId: string;
57
- error: JsonValue;
62
+ error: SerializedError;
58
63
  }
59
64
  export interface CancelWorkflowRunParams {
60
65
  workflowRunId: string;
@@ -83,7 +88,7 @@ export interface FailStepAttemptParams {
83
88
  workflowRunId: string;
84
89
  stepAttemptId: string;
85
90
  workerId: string;
86
- error: JsonValue;
91
+ error: SerializedError;
87
92
  }
88
93
  export interface PaginationOptions {
89
94
  limit?: number;
@@ -97,77 +102,4 @@ export interface PaginatedResponse<T> {
97
102
  prev: string | null;
98
103
  };
99
104
  }
100
- export type JsonPrimitive = string | number | boolean | null;
101
- export type JsonValue = JsonPrimitive | JsonValue[] | {
102
- [key: string]: JsonValue;
103
- };
104
- export type WorkflowRunStatus = "pending" | "running" | "sleeping" | "succeeded" | "completed" | "failed" | "canceled";
105
- /**
106
- * WorkflowRun represents a single execution instance of a workflow.
107
- */
108
- export interface WorkflowRun {
109
- namespaceId: string;
110
- id: string;
111
- workflowName: string;
112
- version: string | null;
113
- status: WorkflowRunStatus;
114
- idempotencyKey: string | null;
115
- config: JsonValue;
116
- context: JsonValue | null;
117
- input: JsonValue | null;
118
- output: JsonValue | null;
119
- error: JsonValue | null;
120
- attempts: number;
121
- parentStepAttemptNamespaceId: string | null;
122
- parentStepAttemptId: string | null;
123
- workerId: string | null;
124
- availableAt: Date | null;
125
- deadlineAt: Date | null;
126
- startedAt: Date | null;
127
- finishedAt: Date | null;
128
- createdAt: Date;
129
- updatedAt: Date;
130
- }
131
- export type StepKind = "function" | "sleep";
132
- export type StepAttemptStatus = "running" | "succeeded" | "completed" | "failed";
133
- export interface StepAttemptContext {
134
- kind: "sleep";
135
- resumeAt: string;
136
- }
137
- /**
138
- * StepAttempt represents a single attempt of a step within a workflow.
139
- */
140
- export interface StepAttempt {
141
- namespaceId: string;
142
- id: string;
143
- workflowRunId: string;
144
- stepName: string;
145
- kind: StepKind;
146
- status: StepAttemptStatus;
147
- config: JsonValue;
148
- context: StepAttemptContext | null;
149
- output: JsonValue | null;
150
- error: JsonValue | null;
151
- childWorkflowRunNamespaceId: string | null;
152
- childWorkflowRunId: string | null;
153
- startedAt: Date | null;
154
- finishedAt: Date | null;
155
- createdAt: Date;
156
- updatedAt: Date;
157
- }
158
- export declare const DEFAULT_RETRY_POLICY: {
159
- readonly initialIntervalMs: 1000;
160
- readonly backoffCoefficient: 2;
161
- readonly maximumIntervalMs: number;
162
- readonly maximumAttempts: number;
163
- };
164
- export type RetryPolicy = typeof DEFAULT_RETRY_POLICY;
165
- /**
166
- * Calculate the next retry delay using exponential backoff.
167
- */
168
- export declare function calculateRetryDelayMs(attemptNumber: number): number;
169
- /**
170
- * Check if an operation should be retried based on the retry policy.
171
- */
172
- export declare function shouldRetry(retryPolicy: RetryPolicy, attemptNumber: number): boolean;
173
105
  //# sourceMappingURL=backend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../backend.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,YAAY,CAAC;AAE9C;;GAE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B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACpC;AAED,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,sBAAuB,SAAQ,iBAAiB;IAC/D,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,yBAAyB;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,eAAe,CAAC;CACxB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,UAAU,EAAE;QACV,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;KACrB,CAAC;CACH"}
package/dist/backend.js CHANGED
@@ -1,23 +1,2 @@
1
1
  export const DEFAULT_NAMESPACE_ID = "default";
2
- // -----------------------------------------------------------------------------
3
- export const DEFAULT_RETRY_POLICY = {
4
- initialIntervalMs: 1000, // 1s
5
- backoffCoefficient: 2,
6
- maximumIntervalMs: 100 * 1000, // 100s
7
- maximumAttempts: Infinity, // unlimited
8
- };
9
- /**
10
- * Calculate the next retry delay using exponential backoff.
11
- */
12
- export function calculateRetryDelayMs(attemptNumber) {
13
- const { initialIntervalMs, backoffCoefficient, maximumIntervalMs } = DEFAULT_RETRY_POLICY;
14
- const backoffMs = initialIntervalMs * Math.pow(backoffCoefficient, attemptNumber - 1);
15
- return Math.min(backoffMs, maximumIntervalMs);
16
- }
17
- /**
18
- * Check if an operation should be retried based on the retry policy.
19
- */
20
- export function shouldRetry(retryPolicy, attemptNumber) {
21
- return attemptNumber < retryPolicy.maximumAttempts;
22
- }
23
2
  //# sourceMappingURL=backend.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"backend.js","sourceRoot":"","sources":["../backend.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,SAAS,CAAC;AA6M9C,gFAAgF;AAEhF,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,iBAAiB,EAAE,IAAI,EAAE,KAAK;IAC9B,kBAAkB,EAAE,CAAC;IACrB,iBAAiB,EAAE,GAAG,GAAG,IAAI,EAAE,OAAO;IACtC,eAAe,EAAE,QAAQ,EAAE,YAAY;CAC/B,CAAC;AAIX;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,aAAqB;IACzD,MAAM,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,GAChE,oBAAoB,CAAC;IAEvB,MAAM,SAAS,GACb,iBAAiB,GAAG,IAAI,CAAC,GAAG,CAAC,kBAAkB,EAAE,aAAa,GAAG,CAAC,CAAC,CAAC;IAEtE,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CACzB,WAAwB,EACxB,aAAqB;IAErB,OAAO,aAAa,GAAG,WAAW,CAAC,eAAe,CAAC;AACrD,CAAC"}
1
+ {"version":3,"file":"backend.js","sourceRoot":"","sources":["../backend.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,oBAAoB,GAAG,SAAS,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=openworkflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openworkflow.d.ts","sourceRoot":"","sources":["../../bin/openworkflow.ts"],"names":[],"mappings":""}
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * This script is a zero-dependency entrypoint for the OpenWorkflow CLI. It
4
+ * allows users to run `npx openworkflow <command>` without requiring the core
5
+ * 'openworkflow' package to have any production dependencies (like commander,
6
+ * consola, etc).
7
+ *
8
+ * Note: This file is transpiled to `./dist/bin/openworkflow.js`. Relative paths
9
+ * below are calculated based on that runtime location.
10
+ */
11
+ import { spawnSync } from "node:child_process";
12
+ import { existsSync, readFileSync } from "node:fs";
13
+ import path from "node:path";
14
+ import { fileURLToPath } from "node:url";
15
+ const __dirname = fileURLToPath(new URL(".", import.meta.url));
16
+ // get the version of the current package to ensure we call the matching CLI
17
+ const packageJsonPath = path.join(__dirname, "../../package.json");
18
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
19
+ const version = packageJson.version;
20
+ // capture all args passed to npx openworkflow (e.g., "init", "worker start")
21
+ const args = process.argv.slice(2);
22
+ // build the command, using tsx to run local TypeScript CLI if in dev and
23
+ // otherwise using npx to run the published CLI package
24
+ const cliScriptFilePath = path.resolve(__dirname, "../../../cli/cli.ts");
25
+ const isMonorepo = existsSync(cliScriptFilePath);
26
+ if (isMonorepo) {
27
+ console.log("⚠️ Running OpenWorkflow CLI from local source (monorepo development mode)\n");
28
+ }
29
+ const command = isMonorepo
30
+ ? // `npx tsx ../../../cli/cli.ts ...args`
31
+ ["tsx", cliScriptFilePath, ...args]
32
+ : // `npx -y @openworkflow/cli@<version> ...args`
33
+ // uses -y to skip the "Need to install @openworkflow/cli" prompt
34
+ ["-y", `@openworkflow/cli@${version}`, ...args];
35
+ // spawn the CLI the command to run the actual CLI package
36
+ const result = spawnSync(
37
+ // eslint-disable-next-line sonarjs/no-os-command-from-path
38
+ "npx", command, {
39
+ stdio: "inherit",
40
+ shell: true,
41
+ });
42
+ // exit with the same status code as the CLI
43
+ process.exit(result.status ?? 0);
44
+ //# sourceMappingURL=openworkflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openworkflow.js","sourceRoot":"","sources":["../../bin/openworkflow.ts"],"names":[],"mappings":";AACA;;;;;;;;GAQG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE/D,4EAA4E;AAC5E,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;AACnE,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAEnE,CAAC;AACF,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC;AAEpC,6EAA6E;AAC7E,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEnC,yEAAyE;AACzE,uDAAuD;AACvD,MAAM,iBAAiB,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;AACzE,MAAM,UAAU,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC;AAEjD,IAAI,UAAU,EAAE,CAAC;IACf,OAAO,CAAC,GAAG,CACT,6EAA6E,CAC9E,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,GAAG,UAAU;IACxB,CAAC,CAAC,wCAAwC;QACxC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