openworkflow 0.3.0 → 0.4.1

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 (131) hide show
  1. package/README.md +54 -18
  2. package/dist/backend-sqlite/backend.d.ts +38 -0
  3. package/dist/backend-sqlite/backend.d.ts.map +1 -0
  4. package/dist/backend-sqlite/backend.js +628 -0
  5. package/dist/backend-sqlite/backend.js.map +1 -0
  6. package/dist/backend-sqlite/index.d.ts +2 -0
  7. package/dist/backend-sqlite/index.d.ts.map +1 -0
  8. package/dist/backend-sqlite/index.js +2 -0
  9. package/dist/backend-sqlite/index.js.map +1 -0
  10. package/dist/backend-sqlite/sqlite.d.ts +45 -0
  11. package/dist/backend-sqlite/sqlite.d.ts.map +1 -0
  12. package/dist/backend-sqlite/sqlite.js +229 -0
  13. package/dist/backend-sqlite/sqlite.js.map +1 -0
  14. package/dist/config/config.d.ts +102 -0
  15. package/dist/config/config.d.ts.map +1 -0
  16. package/dist/config/config.js +29 -0
  17. package/dist/config/config.js.map +1 -0
  18. package/dist/config/index.d.ts +3 -0
  19. package/dist/config/index.d.ts.map +1 -0
  20. package/dist/config/index.js +2 -0
  21. package/dist/config/index.js.map +1 -0
  22. package/dist/config.d.ts +28 -0
  23. package/dist/config.d.ts.map +1 -0
  24. package/dist/config.js +41 -0
  25. package/dist/config.js.map +1 -0
  26. package/dist/core/backend-test-suite.d.ts +22 -0
  27. package/dist/core/backend-test-suite.d.ts.map +1 -0
  28. package/dist/core/backend-test-suite.js +960 -0
  29. package/dist/core/backend-test-suite.js.map +1 -0
  30. package/dist/core/backend.d.ts +103 -0
  31. package/dist/core/backend.d.ts.map +1 -0
  32. package/dist/core/backend.js +2 -0
  33. package/dist/core/backend.js.map +1 -0
  34. package/dist/core/backend.testsuite.d.ts +21 -0
  35. package/dist/core/backend.testsuite.d.ts.map +1 -0
  36. package/dist/core/backend.testsuite.js +958 -0
  37. package/dist/core/backend.testsuite.js.map +1 -0
  38. package/dist/{duration.d.ts → core/duration.d.ts} +2 -1
  39. package/dist/core/duration.d.ts.map +1 -0
  40. package/dist/{duration.js → core/duration.js} +6 -5
  41. package/dist/core/duration.js.map +1 -0
  42. package/dist/core/duration.test.d.ts +2 -0
  43. package/dist/core/duration.test.d.ts.map +1 -0
  44. package/dist/core/duration.test.js +264 -0
  45. package/dist/core/duration.test.js.map +1 -0
  46. package/dist/core/json.d.ts +5 -0
  47. package/dist/core/json.d.ts.map +1 -0
  48. package/dist/core/json.js +2 -0
  49. package/dist/core/json.js.map +1 -0
  50. package/dist/core/result.d.ts +12 -0
  51. package/dist/core/result.d.ts.map +1 -0
  52. package/dist/core/result.js +7 -0
  53. package/dist/core/result.js.map +1 -0
  54. package/dist/core/result.test.d.ts +2 -0
  55. package/dist/core/result.test.d.ts.map +1 -0
  56. package/dist/core/result.test.js +11 -0
  57. package/dist/core/result.test.js.map +1 -0
  58. package/dist/core/retry.d.ts +16 -0
  59. package/dist/core/retry.d.ts.map +1 -0
  60. package/dist/{backend.js → core/retry.js} +1 -3
  61. package/dist/core/retry.js.map +1 -0
  62. package/dist/core/retry.test.d.ts +2 -0
  63. package/dist/core/retry.test.d.ts.map +1 -0
  64. package/dist/core/retry.test.js +36 -0
  65. package/dist/core/retry.test.js.map +1 -0
  66. package/dist/core/schema.d.ts +57 -0
  67. package/dist/core/schema.d.ts.map +1 -0
  68. package/dist/core/schema.js +2 -0
  69. package/dist/core/schema.js.map +1 -0
  70. package/dist/core/step.d.ts +120 -0
  71. package/dist/core/step.d.ts.map +1 -0
  72. package/dist/core/step.js +101 -0
  73. package/dist/core/step.js.map +1 -0
  74. package/dist/core/step.test.d.ts +2 -0
  75. package/dist/core/step.test.d.ts.map +1 -0
  76. package/dist/core/step.test.js +340 -0
  77. package/dist/core/step.test.js.map +1 -0
  78. package/dist/core/workflow.d.ts +108 -0
  79. package/dist/core/workflow.d.ts.map +1 -0
  80. package/dist/core/workflow.js +79 -0
  81. package/dist/core/workflow.js.map +1 -0
  82. package/dist/core/workflow.test.d.ts +2 -0
  83. package/dist/core/workflow.test.d.ts.map +1 -0
  84. package/dist/core/workflow.test.js +216 -0
  85. package/dist/core/workflow.test.js.map +1 -0
  86. package/dist/execution/execution.d.ts +91 -0
  87. package/dist/execution/execution.d.ts.map +1 -0
  88. package/dist/execution/execution.js +188 -0
  89. package/dist/execution/execution.js.map +1 -0
  90. package/dist/execution/execution.test.d.ts +2 -0
  91. package/dist/execution/execution.test.d.ts.map +1 -0
  92. package/dist/execution/execution.test.js +382 -0
  93. package/dist/execution/execution.test.js.map +1 -0
  94. package/dist/global.d.ts +62 -0
  95. package/dist/global.d.ts.map +1 -0
  96. package/dist/global.js +78 -0
  97. package/dist/global.js.map +1 -0
  98. package/dist/index.d.ts +9 -5
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +4 -3
  101. package/dist/index.js.map +1 -1
  102. package/dist/sdk/sdk.d.ts +182 -0
  103. package/dist/sdk/sdk.d.ts.map +1 -0
  104. package/dist/sdk/sdk.js +208 -0
  105. package/dist/sdk/sdk.js.map +1 -0
  106. package/dist/sdk/sdk.test.d.ts +2 -0
  107. package/dist/sdk/sdk.test.d.ts.map +1 -0
  108. package/dist/sdk/sdk.test.js +195 -0
  109. package/dist/sdk/sdk.test.js.map +1 -0
  110. package/dist/tsconfig.tsbuildinfo +1 -1
  111. package/dist/{worker.d.ts → worker/worker.d.ts} +4 -4
  112. package/dist/worker/worker.d.ts.map +1 -0
  113. package/dist/worker/worker.js +208 -0
  114. package/dist/worker/worker.js.map +1 -0
  115. package/dist/worker/worker.test.d.ts +2 -0
  116. package/dist/worker/worker.test.d.ts.map +1 -0
  117. package/dist/worker/worker.test.js +786 -0
  118. package/dist/worker/worker.test.js.map +1 -0
  119. package/package.json +9 -3
  120. package/dist/backend.d.ts +0 -159
  121. package/dist/backend.d.ts.map +0 -1
  122. package/dist/backend.js.map +0 -1
  123. package/dist/client.d.ts +0 -141
  124. package/dist/client.d.ts.map +0 -1
  125. package/dist/client.js +0 -135
  126. package/dist/client.js.map +0 -1
  127. package/dist/duration.d.ts.map +0 -1
  128. package/dist/duration.js.map +0 -1
  129. package/dist/worker.d.ts.map +0 -1
  130. package/dist/worker.js +0 -375
  131. package/dist/worker.js.map +0 -1
@@ -0,0 +1,45 @@
1
+ import { DatabaseSync } from "node:sqlite";
2
+ export type Database = DatabaseSync;
3
+ export declare const DEFAULT_DATABASE_PATH = ":memory:";
4
+ /**
5
+ * newDatabase creates a new SQLite database connection.
6
+ */
7
+ export declare function newDatabase(path?: string): Database;
8
+ /**
9
+ * migrations returns the list of migration SQL statements.
10
+ */
11
+ export declare function migrations(): string[];
12
+ /**
13
+ * migrate applies pending migrations to the database. Does nothing if the
14
+ * database is already up to date.
15
+ */
16
+ export declare function migrate(db: Database): void;
17
+ /**
18
+ * Helper to generate UUIDs (SQLite doesn't have built-in UUID generation)
19
+ */
20
+ export declare function generateUUID(): string;
21
+ /**
22
+ * Helper to get current timestamp in ISO8601 format
23
+ */
24
+ export declare function now(): string;
25
+ /**
26
+ * Helper to add milliseconds to a date and return ISO8601 string
27
+ */
28
+ export declare function addMilliseconds(date: string, ms: number): string;
29
+ /**
30
+ * Helper to serialize JSON for SQLite storage
31
+ */
32
+ export declare function toJSON(value: unknown): string | null;
33
+ /**
34
+ * Helper to deserialize JSON from SQLite storage
35
+ */
36
+ export declare function fromJSON(value: string | null): unknown;
37
+ /**
38
+ * Helper to convert Date to ISO8601 string for SQLite
39
+ */
40
+ export declare function toISO(date: Date | null): string | null;
41
+ /**
42
+ * Helper to convert ISO8601 string from SQLite to Date
43
+ */
44
+ export declare function fromISO(dateStr: string | null): Date | null;
45
+ //# sourceMappingURL=sqlite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../backend-sqlite/sqlite.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,MAAM,QAAQ,GAAG,YAAY,CAAC;AAEpC,eAAO,MAAM,qBAAqB,aAAa,CAAC;AAEhD;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,GAAE,MAA8B,GAAG,QAAQ,CAQ1E;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,MAAM,EAAE,CA2IrC;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAQ1C;AAuBD;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;GAEG;AACH,wBAAgB,GAAG,IAAI,MAAM,CAE5B;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAIhE;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAEpD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAEtD;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAEtD;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAE3D"}
@@ -0,0 +1,229 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { DatabaseSync } from "node:sqlite";
3
+ export const DEFAULT_DATABASE_PATH = ":memory:";
4
+ /**
5
+ * newDatabase creates a new SQLite database connection.
6
+ */
7
+ export function newDatabase(path = DEFAULT_DATABASE_PATH) {
8
+ const db = new DatabaseSync(path);
9
+ // Only enable WAL mode for file-based databases
10
+ if (path !== ":memory:") {
11
+ db.exec("PRAGMA journal_mode = WAL;");
12
+ }
13
+ db.exec("PRAGMA foreign_keys = ON;");
14
+ return db;
15
+ }
16
+ /**
17
+ * migrations returns the list of migration SQL statements.
18
+ */
19
+ export function migrations() {
20
+ return [
21
+ // 0 - init
22
+ `BEGIN;
23
+
24
+ CREATE TABLE IF NOT EXISTS "openworkflow_migrations" (
25
+ "version" INTEGER NOT NULL PRIMARY KEY
26
+ );
27
+
28
+ INSERT OR IGNORE INTO "openworkflow_migrations" ("version")
29
+ VALUES (0);
30
+
31
+ COMMIT;`,
32
+ // 1 - add workflow_runs and step_attempts tables
33
+ `BEGIN;
34
+
35
+ PRAGMA defer_foreign_keys = ON;
36
+
37
+ CREATE TABLE IF NOT EXISTS "workflow_runs" (
38
+ "namespace_id" TEXT NOT NULL,
39
+ "id" TEXT NOT NULL,
40
+ --
41
+ "workflow_name" TEXT NOT NULL,
42
+ "version" TEXT,
43
+ "status" TEXT NOT NULL,
44
+ "idempotency_key" TEXT,
45
+ "config" TEXT NOT NULL,
46
+ "context" TEXT,
47
+ "input" TEXT,
48
+ "output" TEXT,
49
+ "error" TEXT,
50
+ "attempts" INTEGER NOT NULL,
51
+ "parent_step_attempt_namespace_id" TEXT,
52
+ "parent_step_attempt_id" TEXT,
53
+ "worker_id" TEXT,
54
+ "available_at" TEXT,
55
+ "deadline_at" TEXT,
56
+ "started_at" TEXT,
57
+ "finished_at" TEXT,
58
+ "created_at" TEXT NOT NULL,
59
+ "updated_at" TEXT NOT NULL,
60
+ PRIMARY KEY ("namespace_id", "id"),
61
+ FOREIGN KEY ("parent_step_attempt_namespace_id", "parent_step_attempt_id")
62
+ REFERENCES "step_attempts" ("namespace_id", "id")
63
+ ON DELETE SET NULL
64
+ );
65
+
66
+ CREATE TABLE IF NOT EXISTS "step_attempts" (
67
+ "namespace_id" TEXT NOT NULL,
68
+ "id" TEXT NOT NULL,
69
+ --
70
+ "workflow_run_id" TEXT NOT NULL,
71
+ "step_name" TEXT NOT NULL,
72
+ "kind" TEXT NOT NULL,
73
+ "status" TEXT NOT NULL,
74
+ "config" TEXT NOT NULL,
75
+ "context" TEXT,
76
+ "output" TEXT,
77
+ "error" TEXT,
78
+ "child_workflow_run_namespace_id" TEXT,
79
+ "child_workflow_run_id" TEXT,
80
+ "started_at" TEXT,
81
+ "finished_at" TEXT,
82
+ "created_at" TEXT NOT NULL,
83
+ "updated_at" TEXT NOT NULL,
84
+ PRIMARY KEY ("namespace_id", "id"),
85
+ FOREIGN KEY ("namespace_id", "workflow_run_id")
86
+ REFERENCES "workflow_runs" ("namespace_id", "id")
87
+ ON DELETE CASCADE,
88
+ FOREIGN KEY ("child_workflow_run_namespace_id", "child_workflow_run_id")
89
+ REFERENCES "workflow_runs" ("namespace_id", "id")
90
+ ON DELETE SET NULL
91
+ );
92
+
93
+ INSERT OR IGNORE INTO "openworkflow_migrations" ("version")
94
+ VALUES (1);
95
+
96
+ COMMIT;`,
97
+ // 2 - foreign keys
98
+ `BEGIN;
99
+
100
+ -- Foreign keys are defined in migration 1 since SQLite requires them during table creation
101
+ -- This migration exists for version parity with PostgreSQL backend
102
+
103
+ INSERT OR IGNORE INTO "openworkflow_migrations" ("version")
104
+ VALUES (2);
105
+
106
+ COMMIT;`,
107
+ // 3 - validate foreign keys
108
+ `BEGIN;
109
+
110
+ -- Foreign key validation happens automatically in SQLite when PRAGMA foreign_keys = ON
111
+ -- This migration exists for version parity with PostgreSQL backend
112
+
113
+ INSERT OR IGNORE INTO "openworkflow_migrations" ("version")
114
+ VALUES (3);
115
+
116
+ COMMIT;`,
117
+ // 4 - indexes
118
+ `BEGIN;
119
+
120
+ CREATE INDEX IF NOT EXISTS "workflow_runs_status_available_at_created_at_idx"
121
+ ON "workflow_runs" ("namespace_id", "status", "available_at", "created_at");
122
+
123
+ CREATE INDEX IF NOT EXISTS "workflow_runs_workflow_name_idempotency_key_created_at_idx"
124
+ ON "workflow_runs" ("namespace_id", "workflow_name", "idempotency_key", "created_at");
125
+
126
+ CREATE INDEX IF NOT EXISTS "workflow_runs_parent_step_idx"
127
+ ON "workflow_runs" ("parent_step_attempt_namespace_id", "parent_step_attempt_id")
128
+ WHERE parent_step_attempt_namespace_id IS NOT NULL AND parent_step_attempt_id IS NOT NULL;
129
+
130
+ CREATE INDEX IF NOT EXISTS "workflow_runs_created_at_desc_idx"
131
+ ON "workflow_runs" ("namespace_id", "created_at" DESC);
132
+
133
+ CREATE INDEX IF NOT EXISTS "workflow_runs_status_created_at_desc_idx"
134
+ ON "workflow_runs" ("namespace_id", "status", "created_at" DESC);
135
+
136
+ CREATE INDEX IF NOT EXISTS "workflow_runs_workflow_name_status_created_at_desc_idx"
137
+ ON "workflow_runs" ("namespace_id", "workflow_name", "status", "created_at" DESC);
138
+
139
+ CREATE INDEX IF NOT EXISTS "step_attempts_workflow_run_created_at_idx"
140
+ ON "step_attempts" ("namespace_id", "workflow_run_id", "created_at");
141
+
142
+ CREATE INDEX IF NOT EXISTS "step_attempts_workflow_run_step_name_created_at_idx"
143
+ ON "step_attempts" ("namespace_id", "workflow_run_id", "step_name", "created_at");
144
+
145
+ CREATE INDEX IF NOT EXISTS "step_attempts_child_workflow_run_idx"
146
+ ON "step_attempts" ("child_workflow_run_namespace_id", "child_workflow_run_id")
147
+ WHERE child_workflow_run_namespace_id IS NOT NULL AND child_workflow_run_id IS NOT NULL;
148
+
149
+ INSERT OR IGNORE INTO "openworkflow_migrations" ("version")
150
+ VALUES (4);
151
+
152
+ COMMIT;`,
153
+ ];
154
+ }
155
+ /**
156
+ * migrate applies pending migrations to the database. Does nothing if the
157
+ * database is already up to date.
158
+ */
159
+ export function migrate(db) {
160
+ const currentMigrationVersion = getCurrentMigrationVersion(db);
161
+ for (const [i, migrationSql] of migrations().entries()) {
162
+ if (i <= currentMigrationVersion)
163
+ continue; // already applied
164
+ db.exec(migrationSql);
165
+ }
166
+ }
167
+ /**
168
+ * getCurrentMigrationVersion returns the current migration version of the database.
169
+ */
170
+ function getCurrentMigrationVersion(db) {
171
+ // check if migrations table exists
172
+ const existsStmt = db.prepare(`
173
+ SELECT COUNT(*) as count
174
+ FROM sqlite_master
175
+ WHERE type = 'table' AND name = 'openworkflow_migrations'
176
+ `);
177
+ const existsResult = existsStmt.get();
178
+ if (!existsResult || existsResult.count === 0)
179
+ return -1;
180
+ // get current version
181
+ const versionStmt = db.prepare(`SELECT MAX("version") AS "version" FROM "openworkflow_migrations";`);
182
+ const versionResult = versionStmt.get();
183
+ return versionResult?.version ?? -1;
184
+ }
185
+ /**
186
+ * Helper to generate UUIDs (SQLite doesn't have built-in UUID generation)
187
+ */
188
+ export function generateUUID() {
189
+ return randomUUID();
190
+ }
191
+ /**
192
+ * Helper to get current timestamp in ISO8601 format
193
+ */
194
+ export function now() {
195
+ return new Date().toISOString();
196
+ }
197
+ /**
198
+ * Helper to add milliseconds to a date and return ISO8601 string
199
+ */
200
+ export function addMilliseconds(date, ms) {
201
+ const d = new Date(date);
202
+ d.setMilliseconds(d.getMilliseconds() + ms);
203
+ return d.toISOString();
204
+ }
205
+ /**
206
+ * Helper to serialize JSON for SQLite storage
207
+ */
208
+ export function toJSON(value) {
209
+ return value === null || value === undefined ? null : JSON.stringify(value);
210
+ }
211
+ /**
212
+ * Helper to deserialize JSON from SQLite storage
213
+ */
214
+ export function fromJSON(value) {
215
+ return value === null ? null : JSON.parse(value);
216
+ }
217
+ /**
218
+ * Helper to convert Date to ISO8601 string for SQLite
219
+ */
220
+ export function toISO(date) {
221
+ return date ? date.toISOString() : null;
222
+ }
223
+ /**
224
+ * Helper to convert ISO8601 string from SQLite to Date
225
+ */
226
+ export function fromISO(dateStr) {
227
+ return dateStr ? new Date(dateStr) : null;
228
+ }
229
+ //# sourceMappingURL=sqlite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../backend-sqlite/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,MAAM,CAAC,MAAM,qBAAqB,GAAG,UAAU,CAAC;AAEhD;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe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AAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Backend type discriminator
3
+ */
4
+ export type BackendKind = "postgres" | "sqlite";
5
+ /**
6
+ * PostgreSQL backend configuration
7
+ */
8
+ export interface PostgresConfig {
9
+ /**
10
+ * PostgreSQL connection URL
11
+ * @example "postgresql://user:password@localhost:5432/database"
12
+ */
13
+ url: string;
14
+ /**
15
+ * Optional namespace ID to isolate workflows
16
+ */
17
+ namespaceId?: string;
18
+ }
19
+ /**
20
+ * SQLite backend configuration
21
+ */
22
+ export interface SqliteConfig {
23
+ /**
24
+ * SQLite database file path, or ":memory:" for in-memory database
25
+ * @example ":memory:"
26
+ * @example "./data/workflows.db"
27
+ */
28
+ file: string;
29
+ }
30
+ /**
31
+ * Backend configuration with discriminated union
32
+ */
33
+ export interface BackendConfig {
34
+ /**
35
+ * Backend type to use
36
+ */
37
+ kind: BackendKind;
38
+ /**
39
+ * PostgreSQL-specific configuration (required if kind is "postgres")
40
+ */
41
+ postgres?: PostgresConfig;
42
+ /**
43
+ * SQLite-specific configuration (required if kind is "sqlite")
44
+ */
45
+ sqlite?: SqliteConfig;
46
+ }
47
+ /**
48
+ * Worker configuration options
49
+ */
50
+ export interface WorkerConfig {
51
+ /**
52
+ * Maximum number of concurrent workflow executions
53
+ * @default 10
54
+ */
55
+ concurrency?: number;
56
+ }
57
+ /**
58
+ * OpenWorkflow configuration
59
+ */
60
+ export interface OpenWorkflowConfig {
61
+ /**
62
+ * Backend configuration
63
+ */
64
+ backend: BackendConfig;
65
+ /**
66
+ * Worker configuration
67
+ */
68
+ worker?: WorkerConfig;
69
+ /**
70
+ * Glob patterns to locate workflow definition files.
71
+ * @example ["./src/workflows/*.ts"]
72
+ * @example ["**\/workflows\/**\/*.ts"]
73
+ */
74
+ workflowDirs?: string[];
75
+ }
76
+ /**
77
+ * Define an OpenWorkflow configuration with type safety and autocomplete support.
78
+ *
79
+ * @param config - The configuration object
80
+ * @returns The same configuration object (identity function for type inference)
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * import { defineConfig } from "openworkflow/config";
85
+ *
86
+ * export default defineConfig({
87
+ * backend: {
88
+ * kind: "postgres",
89
+ * postgres: {
90
+ * url: process.env.DATABASE_URL!,
91
+ * namespaceId: "my-app"
92
+ * }
93
+ * },
94
+ * worker: {
95
+ * concurrency: 5
96
+ * },
97
+ * workflowDirs: ["./src/workflows/*.ts"]
98
+ * });
99
+ * ```
100
+ */
101
+ export declare function defineConfig(config: OpenWorkflowConfig): OpenWorkflowConfig;
102
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../config/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,QAAQ,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,IAAI,EAAE,WAAW,CAAC;IAClB;;OAEG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B;;OAEG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,EAAE,aAAa,CAAC;IACvB;;OAEG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,kBAAkB,CAE3E"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Define an OpenWorkflow configuration with type safety and autocomplete support.
3
+ *
4
+ * @param config - The configuration object
5
+ * @returns The same configuration object (identity function for type inference)
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { defineConfig } from "openworkflow/config";
10
+ *
11
+ * export default defineConfig({
12
+ * backend: {
13
+ * kind: "postgres",
14
+ * postgres: {
15
+ * url: process.env.DATABASE_URL!,
16
+ * namespaceId: "my-app"
17
+ * }
18
+ * },
19
+ * worker: {
20
+ * concurrency: 5
21
+ * },
22
+ * workflowDirs: ["./src/workflows/*.ts"]
23
+ * });
24
+ * ```
25
+ */
26
+ export function defineConfig(config) {
27
+ return config;
28
+ }
29
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../config/config.ts"],"names":[],"mappings":"AAiFA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,YAAY,CAAC,MAA0B;IACrD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type { BackendConfig, BackendKind, OpenWorkflowConfig, PostgresConfig, SqliteConfig, WorkerConfig, } from "./config.js";
2
+ export { defineConfig } from "./config.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../config/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { defineConfig } from "./config.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../config/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { OpenWorkflow } from "./sdk/sdk.js";
2
+ import type { WorkerOptions } from "./worker/worker.js";
3
+ export type WorkerConfig = Pick<WorkerOptions, "concurrency">;
4
+ /**
5
+ * Configuration object for OpenWorkflow.
6
+ * This is the expected shape of the default export from openworkflow.config.ts
7
+ */
8
+ export interface OpenWorkflowConfig {
9
+ ow: OpenWorkflow;
10
+ worker?: WorkerConfig;
11
+ }
12
+ /**
13
+ * Load OpenWorkflow configuration using c12.
14
+ * This function searches for openworkflow.config.{ts,js,mjs,cjs} files
15
+ * in the current working directory and returns the configuration.
16
+ *
17
+ * Note: This function requires Node.js and will only work in Node environments.
18
+ * For non-Node environments (browser, edge), create OpenWorkflow instances manually.
19
+ *
20
+ * @param options - Optional configuration options
21
+ * @param options.cwd - The directory to search for config files (defaults to process.cwd())
22
+ * @returns The loaded configuration
23
+ * @throws Error if config file is not found or invalid
24
+ */
25
+ export declare function loadConfig(options?: {
26
+ cwd?: string;
27
+ }): Promise<OpenWorkflowConfig>;
28
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;AAE9D;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,YAAY,CAAC;IACjB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,UAAU,CAAC,OAAO,CAAC,EAAE;IACzC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAoC9B"}
package/dist/config.js ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Load OpenWorkflow configuration using c12.
3
+ * This function searches for openworkflow.config.{ts,js,mjs,cjs} files
4
+ * in the current working directory and returns the configuration.
5
+ *
6
+ * Note: This function requires Node.js and will only work in Node environments.
7
+ * For non-Node environments (browser, edge), create OpenWorkflow instances manually.
8
+ *
9
+ * @param options - Optional configuration options
10
+ * @param options.cwd - The directory to search for config files (defaults to process.cwd())
11
+ * @returns The loaded configuration
12
+ * @throws Error if config file is not found or invalid
13
+ */
14
+ export async function loadConfig(options) {
15
+ // Dynamic import to avoid breaking non-Node environments
16
+ // This is lazy-loaded only when actually calling loadConfig()
17
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
18
+ const { loadConfig: c12LoadConfig } = await import("c12");
19
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
20
+ const result = await c12LoadConfig({
21
+ name: "openworkflow",
22
+ ...(options?.cwd ? { cwd: options.cwd } : {}),
23
+ });
24
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
25
+ const config = result.config;
26
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
27
+ const configFile = result.configFile;
28
+ // Check if a config file was actually found and loaded
29
+ // configFile will be a full path if found, or just the base name if not found
30
+ const hasConfigFile = configFile?.includes("/") ?? false;
31
+ // If no config file was found, throw a specific error
32
+ if (!hasConfigFile) {
33
+ throw new Error("OpenWorkflow config file not found. Expected: openworkflow.config.{ts,js,mjs,cjs}\nRun 'ow init' to create one.");
34
+ }
35
+ // If config file exists but doesn't have the required structure
36
+ if (!config || typeof config !== "object" || !("ow" in config)) {
37
+ throw new Error("Config missing 'ow' property. Add 'ow: new OpenWorkflow(...)' to your config export.");
38
+ }
39
+ return config;
40
+ }
41
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAEhC;IACC,yDAAyD;IACzD,8DAA8D;IAC9D,mEAAmE;IACnE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC;IAE1D,sGAAsG;IACtG,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC;QACjC,IAAI,EAAE,cAAc;QACpB,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9C,CAAC,CAAC;IAEH,sEAAsE;IACtE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAwC,CAAC;IAC/D,sEAAsE;IACtE,MAAM,UAAU,GAAuB,MAAM,CAAC,UAAU,CAAC;IAEzD,uDAAuD;IACvD,8EAA8E;IAC9E,MAAM,aAAa,GAAG,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC;IAEzD,sDAAsD;IACtD,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CACb,iHAAiH,CAClH,CAAC;IACJ,CAAC;IAED,gEAAgE;IAChE,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,IAAI,MAAM,CAAC,EAAE,CAAC;QAC/D,MAAM,IAAI,KAAK,CACb,sFAAsF,CACvF,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { Backend } from "./backend.js";
2
+ /**
3
+ * A factory function that creates a new Backend instance.
4
+ * Each call should return a fresh, isolated backend (e.g., with a unique namespace).
5
+ */
6
+ export type BackendFactory = () => Promise<Backend>;
7
+ /**
8
+ * A teardown function that cleans up a Backend instance.
9
+ */
10
+ export type BackendTeardown = (backend: Backend) => Promise<void>;
11
+ /**
12
+ * Runs the Backend compliance test suite.
13
+ *
14
+ * This function wraps all the tests that verify a Backend implementation
15
+ * conforms to the Backend interface contract. It uses the factory to create
16
+ * backend instances and the teardown function to clean them up.
17
+ *
18
+ * @param factory - Creates a new isolated Backend instance
19
+ * @param teardown - Cleans up a Backend instance
20
+ */
21
+ export declare function testBackend(factory: BackendFactory, teardown: BackendTeardown): void;
22
+ //# sourceMappingURL=backend-test-suite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend-test-suite.d.ts","sourceRoot":"","sources":["../../core/backend-test-suite.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAI5C;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAElE;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,cAAc,EACvB,QAAQ,EAAE,eAAe,GACxB,IAAI,CAulCN"}