openworkflow 0.6.0 → 0.6.2

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 (97) hide show
  1. package/README.md +2 -0
  2. package/dist/bin/openworkflow.js +0 -0
  3. package/dist/internal.d.ts +0 -1
  4. package/dist/internal.d.ts.map +1 -1
  5. package/dist/internal.js +0 -1
  6. package/package.json +6 -6
  7. package/dist/backend-test/backend.testsuite.d.ts +0 -20
  8. package/dist/backend-test/backend.testsuite.d.ts.map +0 -1
  9. package/dist/backend-test/backend.testsuite.js +0 -1090
  10. package/dist/backend-test/index.d.ts +0 -2
  11. package/dist/backend-test/index.d.ts.map +0 -1
  12. package/dist/backend-test/index.js +0 -1
  13. package/dist/backend.testsuite.d.ts +0 -20
  14. package/dist/backend.testsuite.d.ts.map +0 -1
  15. package/dist/backend.testsuite.js +0 -1090
  16. package/dist/chaos.test.d.ts +0 -2
  17. package/dist/chaos.test.d.ts.map +0 -1
  18. package/dist/chaos.test.js +0 -88
  19. package/dist/client.test.d.ts +0 -2
  20. package/dist/client.test.d.ts.map +0 -1
  21. package/dist/client.test.js +0 -311
  22. package/dist/core/duration.test.d.ts +0 -2
  23. package/dist/core/duration.test.d.ts.map +0 -1
  24. package/dist/core/duration.test.js +0 -263
  25. package/dist/core/error.test.d.ts +0 -2
  26. package/dist/core/error.test.d.ts.map +0 -1
  27. package/dist/core/error.test.js +0 -60
  28. package/dist/core/result.test.d.ts +0 -2
  29. package/dist/core/result.test.d.ts.map +0 -1
  30. package/dist/core/result.test.js +0 -11
  31. package/dist/core/step.test.d.ts +0 -2
  32. package/dist/core/step.test.d.ts.map +0 -1
  33. package/dist/core/step.test.js +0 -266
  34. package/dist/core/workflow.test.d.ts +0 -2
  35. package/dist/core/workflow.test.d.ts.map +0 -1
  36. package/dist/core/workflow.test.js +0 -113
  37. package/dist/driver.d.ts +0 -116
  38. package/dist/driver.d.ts.map +0 -1
  39. package/dist/driver.js +0 -1
  40. package/dist/execution.test.d.ts +0 -2
  41. package/dist/execution.test.d.ts.map +0 -1
  42. package/dist/execution.test.js +0 -381
  43. package/dist/factory.d.ts +0 -74
  44. package/dist/factory.d.ts.map +0 -1
  45. package/dist/factory.js +0 -72
  46. package/dist/node-sqlite/backend.d.ts +0 -52
  47. package/dist/node-sqlite/backend.d.ts.map +0 -1
  48. package/dist/node-sqlite/backend.js +0 -673
  49. package/dist/node-sqlite/index.d.ts +0 -11
  50. package/dist/node-sqlite/index.d.ts.map +0 -1
  51. package/dist/node-sqlite/index.js +0 -7
  52. package/dist/node-sqlite/sqlite.d.ts +0 -60
  53. package/dist/node-sqlite/sqlite.d.ts.map +0 -1
  54. package/dist/node-sqlite/sqlite.js +0 -246
  55. package/dist/postgres/backend.test.d.ts +0 -2
  56. package/dist/postgres/backend.test.d.ts.map +0 -1
  57. package/dist/postgres/backend.test.js +0 -19
  58. package/dist/postgres/driver.d.ts +0 -81
  59. package/dist/postgres/driver.d.ts.map +0 -1
  60. package/dist/postgres/driver.js +0 -63
  61. package/dist/postgres/index.d.ts +0 -11
  62. package/dist/postgres/index.d.ts.map +0 -1
  63. package/dist/postgres/index.js +0 -7
  64. package/dist/postgres/internal.d.ts +0 -2
  65. package/dist/postgres/internal.d.ts.map +0 -1
  66. package/dist/postgres/internal.js +0 -1
  67. package/dist/postgres/postgres.test.d.ts +0 -2
  68. package/dist/postgres/postgres.test.d.ts.map +0 -1
  69. package/dist/postgres/postgres.test.js +0 -45
  70. package/dist/postgres/vitest.global-setup.d.ts +0 -3
  71. package/dist/postgres/vitest.global-setup.d.ts.map +0 -1
  72. package/dist/postgres/vitest.global-setup.js +0 -7
  73. package/dist/registry.test.d.ts +0 -2
  74. package/dist/registry.test.d.ts.map +0 -1
  75. package/dist/registry.test.js +0 -109
  76. package/dist/sqlite/backend.test.d.ts +0 -2
  77. package/dist/sqlite/backend.test.d.ts.map +0 -1
  78. package/dist/sqlite/backend.test.js +0 -50
  79. package/dist/sqlite/driver.d.ts +0 -79
  80. package/dist/sqlite/driver.d.ts.map +0 -1
  81. package/dist/sqlite/driver.js +0 -62
  82. package/dist/sqlite/index.d.ts +0 -13
  83. package/dist/sqlite/index.d.ts.map +0 -1
  84. package/dist/sqlite/index.js +0 -11
  85. package/dist/sqlite/internal.d.ts +0 -2
  86. package/dist/sqlite/internal.d.ts.map +0 -1
  87. package/dist/sqlite/internal.js +0 -1
  88. package/dist/sqlite/sqlite.test.d.ts +0 -2
  89. package/dist/sqlite/sqlite.test.d.ts.map +0 -1
  90. package/dist/sqlite/sqlite.test.js +0 -171
  91. package/dist/tsconfig.tsbuildinfo +0 -1
  92. package/dist/worker.test.d.ts +0 -2
  93. package/dist/worker.test.d.ts.map +0 -1
  94. package/dist/worker.test.js +0 -900
  95. package/dist/workflow.test.d.ts +0 -2
  96. package/dist/workflow.test.d.ts.map +0 -1
  97. package/dist/workflow.test.js +0 -84
@@ -1,60 +0,0 @@
1
- import { DatabaseSync } from "node:sqlite";
2
- /**
3
- * newDatabase creates a new SQLite database connection.
4
- * @param path - Database file path (or ":memory:") for testing
5
- * @returns SQLite database connection
6
- */
7
- export declare function newDatabase(path: string): DatabaseSync;
8
- /**
9
- * migrations returns the list of migration SQL statements.
10
- * @returns Migration SQL statements
11
- */
12
- export declare function migrations(): string[];
13
- /**
14
- * migrate applies pending migrations to the database. Does nothing if the
15
- * database is already up to date.
16
- * @param db - SQLite database
17
- */
18
- export declare function migrate(db: DatabaseSync): void;
19
- /**
20
- * Helper to generate UUIDs (SQLite doesn't have built-in UUID generation)
21
- * @returns A UUID string
22
- */
23
- export declare function generateUUID(): string;
24
- /**
25
- * Helper to get current timestamp in ISO8601 format
26
- * @returns ISO8601 timestamp string
27
- */
28
- export declare function now(): string;
29
- /**
30
- * Helper to add milliseconds to a date and return ISO8601 string
31
- * @param date - ISO8601 date string
32
- * @param ms - Milliseconds to add
33
- * @returns Updated ISO8601 date string
34
- */
35
- export declare function addMilliseconds(date: string, ms: number): string;
36
- /**
37
- * Helper to serialize JSON for SQLite storage
38
- * @param value - Value to serialize
39
- * @returns JSON string or null
40
- */
41
- export declare function toJSON(value: unknown): string | null;
42
- /**
43
- * Helper to deserialize JSON from SQLite storage
44
- * @param value - JSON string or null
45
- * @returns Parsed value
46
- */
47
- export declare function fromJSON(value: string | null): unknown;
48
- /**
49
- * Helper to convert Date to ISO8601 string for SQLite
50
- * @param date - Date or null
51
- * @returns ISO8601 date string or null
52
- */
53
- export declare function toISO(date: Date | null): string | null;
54
- /**
55
- * Helper to convert ISO8601 string from SQLite to Date
56
- * @param dateStr - ISO8601 date string or null
57
- * @returns Date or null
58
- */
59
- export declare function fromISO(dateStr: string | null): Date | null;
60
- //# sourceMappingURL=sqlite.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../node-sqlite/sqlite.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAQtD;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,MAAM,EAAE,CA2IrC;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAQ9C;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"}
@@ -1,246 +0,0 @@
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
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=backend.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"backend.test.d.ts","sourceRoot":"","sources":["../../postgres/backend.test.ts"],"names":[],"mappings":""}
@@ -1,19 +0,0 @@
1
- import { testBackend } from "../internal.js";
2
- import { BackendPostgres } from "./backend.js";
3
- import { DEFAULT_POSTGRES_URL } from "./postgres.js";
4
- import assert from "node:assert";
5
- import { randomUUID } from "node:crypto";
6
- import { test } from "vitest";
7
- test("it is a test file (workaround for sonarjs/no-empty-test-file linter)", () => {
8
- assert.ok(true);
9
- });
10
- testBackend({
11
- setup: async () => {
12
- return await BackendPostgres.connect(DEFAULT_POSTGRES_URL, {
13
- namespaceId: randomUUID(),
14
- });
15
- },
16
- teardown: async (backend) => {
17
- await backend.stop();
18
- },
19
- });
@@ -1,81 +0,0 @@
1
- /**
2
- * PostgreSQL driver for OpenWorkflow using the Drizzle-style API.
3
- *
4
- * This module provides a `postgres()` function that creates a driver
5
- * for connecting to PostgreSQL databases.
6
- * @example
7
- * ```ts
8
- * import { openworkflow } from 'openworkflow';
9
- * import { postgres } from 'openworkflow/postgres';
10
- *
11
- * // Simple usage with connection string
12
- * const ow = await openworkflow(postgres(process.env.DATABASE_URL));
13
- *
14
- * // With configuration options
15
- * const ow = await openworkflow(postgres({
16
- * connection: process.env.DATABASE_URL,
17
- * namespace: 'my-app',
18
- * runMigrations: true,
19
- * }));
20
- *
21
- * // With existing postgres.js client
22
- * import postgresJs from 'postgres';
23
- * const client = postgresJs(process.env.DATABASE_URL);
24
- * const ow = await openworkflow(postgres({ client }));
25
- * ```
26
- */
27
- import type { Backend, Driver, DriverConfig } from "openworkflow/internal";
28
- /**
29
- * PostgreSQL-specific driver configuration.
30
- */
31
- export interface PostgresDriverConfig extends DriverConfig {
32
- /**
33
- * PostgreSQL connection string URL.
34
- */
35
- connection?: string;
36
- /**
37
- * Existing postgres.js client instance.
38
- * If provided, the driver will use this client instead of creating a new one.
39
- */
40
- client?: PostgresClient;
41
- }
42
- /**
43
- * Type for postgres.js client.
44
- * This is a simplified interface that matches the postgres.js interface.
45
- */
46
- export interface PostgresClient {
47
- end(): Promise<void>;
48
- [key: string]: any;
49
- }
50
- /**
51
- * PostgreSQL driver instance.
52
- */
53
- export interface PostgresDriver extends Driver {
54
- readonly dialect: "postgres";
55
- readonly $client: PostgresClient | undefined;
56
- createBackend(): Promise<Backend>;
57
- }
58
- /**
59
- * Creates a PostgreSQL driver for OpenWorkflow.
60
- *
61
- * This function follows the Drizzle ORM pattern and supports multiple
62
- * calling conventions:
63
- * @param config - Connection string or configuration object
64
- * @returns A PostgresDriver instance
65
- * @example
66
- * ```ts
67
- * // With connection string
68
- * postgres(process.env.DATABASE_URL)
69
- *
70
- * // With config object
71
- * postgres({
72
- * connection: process.env.DATABASE_URL,
73
- * namespace: 'my-app',
74
- * })
75
- *
76
- * // With existing client
77
- * postgres({ client: existingPostgresClient })
78
- * ```
79
- */
80
- export declare function postgres(config: string | PostgresDriverConfig): PostgresDriver;
81
- //# sourceMappingURL=driver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../../postgres/driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACxD;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAErB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,MAAM;IAC5C,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS,CAAC;IAC7C,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,MAAM,GAAG,oBAAoB,GACpC,cAAc,CA6DhB"}
@@ -1,63 +0,0 @@
1
- /**
2
- * Creates a PostgreSQL driver for OpenWorkflow.
3
- *
4
- * This function follows the Drizzle ORM pattern and supports multiple
5
- * calling conventions:
6
- * @param config - Connection string or configuration object
7
- * @returns A PostgresDriver instance
8
- * @example
9
- * ```ts
10
- * // With connection string
11
- * postgres(process.env.DATABASE_URL)
12
- *
13
- * // With config object
14
- * postgres({
15
- * connection: process.env.DATABASE_URL,
16
- * namespace: 'my-app',
17
- * })
18
- *
19
- * // With existing client
20
- * postgres({ client: existingPostgresClient })
21
- * ```
22
- */
23
- export function postgres(config) {
24
- // Normalize config
25
- const normalizedConfig = typeof config === "string" ? { connection: config } : config;
26
- // Store the client reference (will be set on createBackend)
27
- let clientRef = normalizedConfig.client;
28
- return {
29
- dialect: "postgres",
30
- get $client() {
31
- return clientRef;
32
- },
33
- async createBackend() {
34
- // Dynamically import BackendPostgres to avoid requiring the postgres
35
- // package as a direct dependency of the openworkflow package
36
- const { BackendPostgres } = await import("@openworkflow/backend-postgres");
37
- // Determine the connection URL
38
- const connectionUrl = normalizedConfig.connection;
39
- if (!connectionUrl && !normalizedConfig.client) {
40
- throw new Error("PostgreSQL driver requires either a connection string or an existing client. " +
41
- "Provide `connection` URL or `client` in the config.");
42
- }
43
- // If we have an existing client, we need to handle it differently
44
- // For now, we use the BackendPostgres.connect which creates its own client
45
- if (!connectionUrl) {
46
- throw new Error("Using an existing postgres.js client is not yet supported. " +
47
- "Please provide a connection string via the `connection` option.");
48
- }
49
- const options = {
50
- runMigrations: normalizedConfig.runMigrations ?? true,
51
- };
52
- if (normalizedConfig.namespace) {
53
- options.namespaceId = normalizedConfig.namespace;
54
- }
55
- const backend = await BackendPostgres.connect(connectionUrl, options);
56
- // Store client reference for $client getter
57
- // Note: BackendPostgres doesn't expose the client, so this remains undefined
58
- // In the future, we could extend BackendPostgres to expose the client
59
- clientRef = undefined;
60
- return backend;
61
- },
62
- };
63
- }
@@ -1,11 +0,0 @@
1
- import { BackendPostgres } from "./backend.js";
2
- import type { Postgres } from "./postgres.js";
3
- /**
4
- * Create a Postgres-backed OpenWorkflow backend using postgres.js.
5
- * @param client - postgres.js client or connection URL
6
- * @param options - Backend options
7
- * @returns A connected backend instance
8
- */
9
- export declare function openworkflow(client: Postgres, options?: Parameters<typeof BackendPostgres.fromClient>[1]): Promise<BackendPostgres>;
10
- export declare function openworkflow(url: string, options?: Parameters<typeof BackendPostgres.connect>[1]): Promise<BackendPostgres>;
11
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../postgres/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,QAAQ,EAChB,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,eAAe,CAAC,CAAC;AAC5B,wBAAsB,YAAY,CAChC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GACtD,OAAO,CAAC,eAAe,CAAC,CAAC"}
@@ -1,7 +0,0 @@
1
- import { BackendPostgres } from "./backend.js";
2
- export async function openworkflow(clientOrUrl, options) {
3
- if (typeof clientOrUrl === "string") {
4
- return BackendPostgres.connect(clientOrUrl, options);
5
- }
6
- return BackendPostgres.fromClient(clientOrUrl, options);
7
- }
@@ -1,2 +0,0 @@
1
- export * from "./postgres.js";
2
- //# sourceMappingURL=internal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../postgres/internal.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
@@ -1 +0,0 @@
1
- export * from "./postgres.js";
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=postgres.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"postgres.test.d.ts","sourceRoot":"","sources":["../../postgres/postgres.test.ts"],"names":[],"mappings":""}
@@ -1,45 +0,0 @@
1
- import { DEFAULT_POSTGRES_URL, DEFAULT_SCHEMA, newPostgresMaxOne, migrations, migrate, dropSchema, } from "./postgres.js";
2
- import { afterAll, beforeAll, describe, expect, test } from "vitest";
3
- describe("postgres", () => {
4
- let pg;
5
- beforeAll(() => {
6
- // maxOne since we use SQL-based transactions instead of the postgres
7
- // driver's built-in transactions
8
- pg = newPostgresMaxOne(DEFAULT_POSTGRES_URL);
9
- });
10
- afterAll(async () => {
11
- await pg.end();
12
- });
13
- describe("migrations()", () => {
14
- test("returns migrations in 'openworkflow' schema when no schema is specified", () => {
15
- const migs = migrations(DEFAULT_SCHEMA);
16
- for (const mig of migs) {
17
- expect(mig).toContain(`"openworkflow"`);
18
- }
19
- });
20
- test("returns migration in the specified schema when one is specified", () => {
21
- const schema = "test_custom_schema";
22
- const migs = migrations(schema);
23
- for (const mig of migs) {
24
- expect(mig).toContain(`"${schema}"`);
25
- expect(mig).not.toContain(`"openworkflow"`);
26
- }
27
- });
28
- });
29
- describe("migrate()", () => {
30
- test("runs database migrations idempotently", async () => {
31
- const schema = "test_migrate_idempotent";
32
- await dropSchema(pg, schema);
33
- await migrate(pg, schema);
34
- await migrate(pg, schema);
35
- });
36
- });
37
- describe("dropSchema()", () => {
38
- test("drops the schema idempotently", async () => {
39
- const testSchema = "test_drop_schema_idempotent";
40
- await migrate(pg, testSchema);
41
- await dropSchema(pg, testSchema);
42
- await dropSchema(pg, testSchema);
43
- });
44
- });
45
- });
@@ -1,3 +0,0 @@
1
- /** Run database migrations once before Postgres backend tests. */
2
- export declare function setup(): Promise<void>;
3
- //# sourceMappingURL=vitest.global-setup.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vitest.global-setup.d.ts","sourceRoot":"","sources":["../../postgres/vitest.global-setup.ts"],"names":[],"mappings":"AAOA,kEAAkE;AAClE,wBAAsB,KAAK,kBAI1B"}
@@ -1,7 +0,0 @@
1
- import { migrate, newPostgresMaxOne, DEFAULT_SCHEMA, DEFAULT_POSTGRES_URL, } from "./postgres.js";
2
- /** Run database migrations once before Postgres backend tests. */
3
- export async function setup() {
4
- const pg = newPostgresMaxOne(DEFAULT_POSTGRES_URL);
5
- await migrate(pg, DEFAULT_SCHEMA);
6
- await pg.end();
7
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=registry.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"registry.test.d.ts","sourceRoot":"","sources":["../registry.test.ts"],"names":[],"mappings":""}