openworkflow 0.5.0 → 0.6.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.
- package/README.md +40 -347
- package/dist/{testing → backend-test}/backend.testsuite.d.ts +1 -1
- package/dist/backend-test/backend.testsuite.d.ts.map +1 -0
- package/dist/{testing → backend-test}/backend.testsuite.js +8 -9
- package/dist/backend-test/index.d.ts +2 -0
- package/dist/backend-test/index.d.ts.map +1 -0
- package/dist/{testing → backend-test}/index.js +0 -1
- package/dist/backend.js +0 -1
- package/dist/backend.testsuite.d.ts +20 -0
- package/dist/backend.testsuite.d.ts.map +1 -0
- package/dist/backend.testsuite.js +1090 -0
- package/dist/bin/openworkflow.js +0 -1
- package/dist/chaos.test.d.ts +2 -0
- package/dist/chaos.test.d.ts.map +1 -0
- package/dist/chaos.test.js +88 -0
- package/dist/client.js +0 -1
- package/dist/client.test.d.ts +2 -0
- package/dist/client.test.d.ts.map +1 -0
- package/dist/client.test.js +311 -0
- package/dist/core/duration.js +0 -1
- package/dist/core/duration.test.d.ts +2 -0
- package/dist/core/duration.test.d.ts.map +1 -0
- package/dist/core/duration.test.js +263 -0
- package/dist/core/error.js +0 -1
- package/dist/core/error.test.d.ts +2 -0
- package/dist/core/error.test.d.ts.map +1 -0
- package/dist/core/error.test.js +60 -0
- package/dist/core/json.js +0 -1
- package/dist/core/result.js +0 -1
- package/dist/core/result.test.d.ts +2 -0
- package/dist/core/result.test.d.ts.map +1 -0
- package/dist/core/result.test.js +11 -0
- package/dist/core/retry.js +0 -1
- package/dist/core/schema.js +0 -1
- package/dist/core/step.js +0 -1
- package/dist/core/step.test.d.ts +2 -0
- package/dist/core/step.test.d.ts.map +1 -0
- package/dist/core/step.test.js +266 -0
- package/dist/core/workflow.js +0 -1
- package/dist/core/workflow.test.d.ts +2 -0
- package/dist/core/workflow.test.d.ts.map +1 -0
- package/dist/core/workflow.test.js +113 -0
- package/dist/driver.d.ts +116 -0
- package/dist/driver.d.ts.map +1 -0
- package/dist/driver.js +1 -0
- package/dist/execution.js +0 -1
- package/dist/execution.test.d.ts +2 -0
- package/dist/execution.test.d.ts.map +1 -0
- package/dist/execution.test.js +381 -0
- package/dist/factory.d.ts +74 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +72 -0
- package/dist/index.js +0 -1
- package/dist/internal.d.ts +4 -5
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -4
- package/dist/{backend-sqlite/index.d.ts → node-sqlite/backend.d.ts} +14 -4
- package/dist/node-sqlite/backend.d.ts.map +1 -0
- package/dist/{backend-sqlite/index.js → node-sqlite/backend.js} +23 -5
- package/dist/node-sqlite/index.d.ts +11 -0
- package/dist/node-sqlite/index.d.ts.map +1 -0
- package/dist/node-sqlite/index.js +7 -0
- package/dist/{backend-sqlite → node-sqlite}/sqlite.d.ts +2 -3
- package/dist/node-sqlite/sqlite.d.ts.map +1 -0
- package/dist/{backend-sqlite → node-sqlite}/sqlite.js +0 -1
- package/dist/{pg → postgres}/backend.d.ts +3 -1
- package/dist/postgres/backend.d.ts.map +1 -0
- package/dist/{pg → postgres}/backend.js +5 -5
- package/dist/postgres/backend.test.d.ts +2 -0
- package/dist/postgres/backend.test.d.ts.map +1 -0
- package/dist/postgres/backend.test.js +19 -0
- package/dist/postgres/driver.d.ts +81 -0
- package/dist/postgres/driver.d.ts.map +1 -0
- package/dist/postgres/driver.js +63 -0
- package/dist/postgres/index.d.ts +11 -0
- package/dist/postgres/index.d.ts.map +1 -0
- package/dist/postgres/index.js +7 -0
- package/dist/postgres/internal.d.ts +2 -0
- package/dist/postgres/internal.d.ts.map +1 -0
- package/dist/postgres/internal.js +1 -0
- package/dist/postgres/postgres.d.ts.map +1 -0
- package/dist/{backend-postgres → postgres}/postgres.js +0 -1
- package/dist/postgres/postgres.test.d.ts +2 -0
- package/dist/postgres/postgres.test.d.ts.map +1 -0
- package/dist/postgres/postgres.test.js +45 -0
- package/dist/postgres/scripts/db-migrate.d.ts.map +1 -0
- package/dist/{pg → postgres}/scripts/db-migrate.js +0 -1
- package/dist/postgres/scripts/db-reset.d.ts.map +1 -0
- package/dist/{pg → postgres}/scripts/db-reset.js +0 -1
- package/dist/{pg → postgres}/scripts/squawk.d.ts.map +1 -1
- package/dist/{pg → postgres}/scripts/squawk.js +0 -1
- package/dist/postgres/vitest.global-setup.d.ts.map +1 -0
- package/dist/{pg → postgres}/vitest.global-setup.js +0 -1
- package/dist/postgres.d.ts +2 -0
- package/dist/postgres.d.ts.map +1 -0
- package/dist/postgres.js +1 -0
- package/dist/registry.js +0 -1
- package/dist/registry.test.d.ts +2 -0
- package/dist/registry.test.d.ts.map +1 -0
- package/dist/registry.test.js +109 -0
- package/dist/sqlite/backend.d.ts +3 -1
- package/dist/sqlite/backend.d.ts.map +1 -1
- package/dist/sqlite/backend.js +5 -5
- package/dist/sqlite/backend.test.d.ts +2 -0
- package/dist/sqlite/backend.test.d.ts.map +1 -0
- package/dist/sqlite/backend.test.js +50 -0
- package/dist/sqlite/driver.d.ts +79 -0
- package/dist/sqlite/driver.d.ts.map +1 -0
- package/dist/sqlite/driver.js +62 -0
- package/dist/sqlite/index.d.ts +12 -2
- package/dist/sqlite/index.d.ts.map +1 -1
- package/dist/sqlite/index.js +11 -3
- package/dist/sqlite/internal.d.ts +2 -0
- package/dist/sqlite/internal.d.ts.map +1 -0
- package/dist/sqlite/internal.js +1 -0
- package/dist/sqlite/sqlite.js +0 -1
- package/dist/sqlite/sqlite.test.d.ts +2 -0
- package/dist/sqlite/sqlite.test.d.ts.map +1 -0
- package/dist/sqlite/sqlite.test.js +171 -0
- package/dist/sqlite.d.ts +2 -0
- package/dist/sqlite.d.ts.map +1 -0
- package/dist/sqlite.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/worker.js +0 -1
- package/dist/worker.test.d.ts +2 -0
- package/dist/worker.test.d.ts.map +1 -0
- package/dist/worker.test.js +900 -0
- package/dist/workflow.js +0 -1
- package/dist/workflow.test.d.ts +2 -0
- package/dist/workflow.test.d.ts.map +1 -0
- package/dist/workflow.test.js +84 -0
- package/package.json +19 -5
- package/dist/backend-postgres/index.d.ts +0 -44
- package/dist/backend-postgres/index.d.ts.map +0 -1
- package/dist/backend-postgres/index.js +0 -535
- package/dist/backend-postgres/index.js.map +0 -1
- package/dist/backend-postgres/postgres.d.ts.map +0 -1
- package/dist/backend-postgres/postgres.js.map +0 -1
- package/dist/backend-sqlite/index.d.ts.map +0 -1
- package/dist/backend-sqlite/index.js.map +0 -1
- package/dist/backend-sqlite/sqlite.d.ts.map +0 -1
- package/dist/backend-sqlite/sqlite.js.map +0 -1
- package/dist/backend.js.map +0 -1
- package/dist/bin/openworkflow.js.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/config.d.ts +0 -34
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -49
- package/dist/config.js.map +0 -1
- package/dist/core/duration.js.map +0 -1
- package/dist/core/error.js.map +0 -1
- package/dist/core/json.js.map +0 -1
- package/dist/core/result.js.map +0 -1
- package/dist/core/retry.js.map +0 -1
- package/dist/core/schema.js.map +0 -1
- package/dist/core/step.js.map +0 -1
- package/dist/core/workflow.js.map +0 -1
- package/dist/execution.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/internal.js.map +0 -1
- package/dist/pg/backend.d.ts.map +0 -1
- package/dist/pg/backend.js.map +0 -1
- package/dist/pg/index.d.ts +0 -3
- package/dist/pg/index.d.ts.map +0 -1
- package/dist/pg/index.js +0 -3
- package/dist/pg/index.js.map +0 -1
- package/dist/pg/postgres.d.ts +0 -42
- package/dist/pg/postgres.d.ts.map +0 -1
- package/dist/pg/postgres.js +0 -234
- package/dist/pg/postgres.js.map +0 -1
- package/dist/pg/scripts/db-migrate.d.ts.map +0 -1
- package/dist/pg/scripts/db-migrate.js.map +0 -1
- package/dist/pg/scripts/db-reset.d.ts.map +0 -1
- package/dist/pg/scripts/db-reset.js.map +0 -1
- package/dist/pg/scripts/squawk.js.map +0 -1
- package/dist/pg/vitest.global-setup.d.ts.map +0 -1
- package/dist/pg/vitest.global-setup.js.map +0 -1
- package/dist/registry.js.map +0 -1
- package/dist/sqlite/backend.js.map +0 -1
- package/dist/sqlite/index.js.map +0 -1
- package/dist/sqlite/sqlite.js.map +0 -1
- package/dist/testing/backend.testsuite.d.ts.map +0 -1
- package/dist/testing/backend.testsuite.js.map +0 -1
- package/dist/testing/index.d.ts +0 -2
- package/dist/testing/index.d.ts.map +0 -1
- package/dist/testing/index.js.map +0 -1
- package/dist/worker.js.map +0 -1
- package/dist/workflow.js.map +0 -1
- /package/dist/{backend-postgres → postgres}/postgres.d.ts +0 -0
- /package/dist/{pg → postgres}/scripts/db-migrate.d.ts +0 -0
- /package/dist/{pg → postgres}/scripts/db-reset.d.ts +0 -0
- /package/dist/{pg → postgres}/scripts/squawk.d.ts +0 -0
- /package/dist/{pg → postgres}/vitest.global-setup.d.ts +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drizzle-style factory function for creating OpenWorkflow instances.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a factory function that follows the Drizzle ORM pattern
|
|
5
|
+
* for creating database instances. It supports multiple calling conventions:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* // With a pre-configured driver
|
|
9
|
+
* const ow = openworkflow(postgres(url));
|
|
10
|
+
*
|
|
11
|
+
* // With inline configuration
|
|
12
|
+
* const ow = openworkflow(postgres({ connection: url, namespace: 'app' }));
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
import type { Backend } from "./backend.js";
|
|
16
|
+
import { OpenWorkflow } from "./client.js";
|
|
17
|
+
import type { Driver } from "./driver.js";
|
|
18
|
+
/**
|
|
19
|
+
* Extended OpenWorkflow instance with driver metadata.
|
|
20
|
+
*/
|
|
21
|
+
export interface OpenWorkflowWithDriver extends OpenWorkflow {
|
|
22
|
+
/**
|
|
23
|
+
* The underlying driver used to create this instance.
|
|
24
|
+
*/
|
|
25
|
+
readonly $driver: Driver;
|
|
26
|
+
/**
|
|
27
|
+
* The underlying backend instance.
|
|
28
|
+
*/
|
|
29
|
+
readonly $backend: Backend;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new OpenWorkflow instance from a driver.
|
|
33
|
+
*
|
|
34
|
+
* This is the Drizzle-style factory function that provides a clean API for
|
|
35
|
+
* creating OpenWorkflow instances with different database backends.
|
|
36
|
+
* @param driver - A configured driver (e.g., from `postgres()` or `sqlite()`)
|
|
37
|
+
* @returns A promise that resolves to an OpenWorkflow instance
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { openworkflow } from 'openworkflow';
|
|
41
|
+
* import { postgres } from 'openworkflow/postgres';
|
|
42
|
+
*
|
|
43
|
+
* // Simple usage
|
|
44
|
+
* const ow = await openworkflow(postgres(process.env.DATABASE_URL));
|
|
45
|
+
*
|
|
46
|
+
* // With SQLite
|
|
47
|
+
* import { sqlite } from 'openworkflow/sqlite';
|
|
48
|
+
* const ow = await openworkflow(sqlite(':memory:'));
|
|
49
|
+
*
|
|
50
|
+
* // Define and run workflows
|
|
51
|
+
* const myWorkflow = ow.defineWorkflow(
|
|
52
|
+
* { name: 'my-workflow' },
|
|
53
|
+
* async ({ input, step }) => {
|
|
54
|
+
* const result = await step.run({ name: 'do-work' }, async () => {
|
|
55
|
+
* return 'done';
|
|
56
|
+
* });
|
|
57
|
+
* return result;
|
|
58
|
+
* }
|
|
59
|
+
* );
|
|
60
|
+
*
|
|
61
|
+
* const handle = await myWorkflow.run({ data: 'test' });
|
|
62
|
+
* const result = await handle.result();
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function openworkflow(driver: Driver): Promise<OpenWorkflowWithDriver>;
|
|
66
|
+
/**
|
|
67
|
+
* Synchronous version of openworkflow for drivers that support sync creation.
|
|
68
|
+
* Note: Most drivers require async creation due to migrations.
|
|
69
|
+
* @param driver - A configured driver
|
|
70
|
+
* @returns An OpenWorkflow instance
|
|
71
|
+
* @throws {TypeError} If driver requires async setup
|
|
72
|
+
*/
|
|
73
|
+
export declare function openworkflowSync(driver: Driver): OpenWorkflowWithDriver;
|
|
74
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,YAAY,EAA4B,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,YAAY;IAC1D;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,sBAAsB,CAAC,CAgBjC;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,sBAAsB,CAsBvE"}
|
package/dist/factory.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { OpenWorkflow } from "./client.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new OpenWorkflow instance from a driver.
|
|
4
|
+
*
|
|
5
|
+
* This is the Drizzle-style factory function that provides a clean API for
|
|
6
|
+
* creating OpenWorkflow instances with different database backends.
|
|
7
|
+
* @param driver - A configured driver (e.g., from `postgres()` or `sqlite()`)
|
|
8
|
+
* @returns A promise that resolves to an OpenWorkflow instance
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { openworkflow } from 'openworkflow';
|
|
12
|
+
* import { postgres } from 'openworkflow/postgres';
|
|
13
|
+
*
|
|
14
|
+
* // Simple usage
|
|
15
|
+
* const ow = await openworkflow(postgres(process.env.DATABASE_URL));
|
|
16
|
+
*
|
|
17
|
+
* // With SQLite
|
|
18
|
+
* import { sqlite } from 'openworkflow/sqlite';
|
|
19
|
+
* const ow = await openworkflow(sqlite(':memory:'));
|
|
20
|
+
*
|
|
21
|
+
* // Define and run workflows
|
|
22
|
+
* const myWorkflow = ow.defineWorkflow(
|
|
23
|
+
* { name: 'my-workflow' },
|
|
24
|
+
* async ({ input, step }) => {
|
|
25
|
+
* const result = await step.run({ name: 'do-work' }, async () => {
|
|
26
|
+
* return 'done';
|
|
27
|
+
* });
|
|
28
|
+
* return result;
|
|
29
|
+
* }
|
|
30
|
+
* );
|
|
31
|
+
*
|
|
32
|
+
* const handle = await myWorkflow.run({ data: 'test' });
|
|
33
|
+
* const result = await handle.result();
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export async function openworkflow(driver) {
|
|
37
|
+
// Create the backend from the driver
|
|
38
|
+
const backend = await driver.createBackend();
|
|
39
|
+
// Create the OpenWorkflow instance
|
|
40
|
+
const options = {
|
|
41
|
+
backend,
|
|
42
|
+
};
|
|
43
|
+
const ow = new OpenWorkflow(options);
|
|
44
|
+
// Return an extended instance with driver metadata
|
|
45
|
+
return Object.assign(ow, {
|
|
46
|
+
$driver: driver,
|
|
47
|
+
$backend: backend,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Synchronous version of openworkflow for drivers that support sync creation.
|
|
52
|
+
* Note: Most drivers require async creation due to migrations.
|
|
53
|
+
* @param driver - A configured driver
|
|
54
|
+
* @returns An OpenWorkflow instance
|
|
55
|
+
* @throws {TypeError} If driver requires async setup
|
|
56
|
+
*/
|
|
57
|
+
export function openworkflowSync(driver) {
|
|
58
|
+
// Try to create the backend synchronously
|
|
59
|
+
const backendOrPromise = driver.createBackend();
|
|
60
|
+
if (backendOrPromise instanceof Promise) {
|
|
61
|
+
throw new TypeError(`Driver '${driver.dialect}' requires async setup. Use 'await openworkflow()' instead of 'openworkflowSync()'.`);
|
|
62
|
+
}
|
|
63
|
+
const backend = backendOrPromise;
|
|
64
|
+
const options = {
|
|
65
|
+
backend,
|
|
66
|
+
};
|
|
67
|
+
const ow = new OpenWorkflow(options);
|
|
68
|
+
return Object.assign(ow, {
|
|
69
|
+
$driver: driver,
|
|
70
|
+
$backend: backend,
|
|
71
|
+
});
|
|
72
|
+
}
|
package/dist/index.js
CHANGED
package/dist/internal.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export type { Workflow } from "./workflow.js";
|
|
2
2
|
export { isWorkflow } from "./workflow.js";
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export type { WorkflowRun } from "./core/workflow.js";
|
|
6
|
-
export type { StepAttempt } from "./core/step.js";
|
|
7
|
-
export { DEFAULT_RETRY_POLICY } from "./core/retry.js";
|
|
3
|
+
export type { Backend, PaginationOptions, PaginatedResponse, } from "./backend.js";
|
|
4
|
+
export { testBackend } from "./backend.testsuite.js";
|
|
5
|
+
export type { WorkflowRun, WorkflowRunStatus } from "./core/workflow.js";
|
|
6
|
+
export type { StepAttempt, StepAttemptStatus, StepKind } from "./core/step.js";
|
|
8
7
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../internal.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../internal.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,YAAY,EACV,OAAO,EACP,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACzE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/internal.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { Backend, CancelWorkflowRunParams, ClaimWorkflowRunParams, CompleteStepAttemptParams, CompleteWorkflowRunParams, CreateStepAttemptParams, CreateWorkflowRunParams, ExtendWorkflowRunLeaseParams, FailStepAttemptParams, FailWorkflowRunParams, GetStepAttemptParams, GetWorkflowRunParams, ListStepAttemptsParams, ListWorkflowRunsParams, PaginatedResponse, SleepWorkflowRunParams } from "../backend.js";
|
|
2
|
+
import { StepAttempt } from "../core/step.js";
|
|
3
|
+
import { WorkflowRun } from "../core/workflow.js";
|
|
4
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
4
5
|
interface BackendSqliteOptions {
|
|
5
6
|
namespaceId?: string;
|
|
6
7
|
runMigrations?: boolean;
|
|
@@ -21,6 +22,15 @@ export declare class BackendSqlite implements Backend {
|
|
|
21
22
|
* @returns A connected backend instance
|
|
22
23
|
*/
|
|
23
24
|
static connect(path: string, options?: BackendSqliteOptions): BackendSqlite;
|
|
25
|
+
/**
|
|
26
|
+
* Create and initialize a new BackendSqlite instance from an existing
|
|
27
|
+
* SQLite database connection. This will automatically run migrations on
|
|
28
|
+
* startup unless `runMigrations` is set to false.
|
|
29
|
+
* @param db - SQLite database connection
|
|
30
|
+
* @param options - Backend options
|
|
31
|
+
* @returns A connected backend instance
|
|
32
|
+
*/
|
|
33
|
+
static fromClient(db: DatabaseSync, options?: BackendSqliteOptions): BackendSqlite;
|
|
24
34
|
stop(): Promise<void>;
|
|
25
35
|
createWorkflowRun(params: CreateWorkflowRunParams): Promise<WorkflowRun>;
|
|
26
36
|
getWorkflowRun(params: GetWorkflowRunParams): Promise<WorkflowRun | null>;
|
|
@@ -39,4 +49,4 @@ export declare class BackendSqlite implements Backend {
|
|
|
39
49
|
failStepAttempt(params: FailStepAttemptParams): Promise<StepAttempt>;
|
|
40
50
|
}
|
|
41
51
|
export {};
|
|
42
|
-
//# sourceMappingURL=
|
|
52
|
+
//# sourceMappingURL=backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../node-sqlite/backend.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,EACP,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EACzB,yBAAyB,EACzB,uBAAuB,EACvB,uBAAuB,EACvB,4BAA4B,EAC5B,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAYlD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD,UAAU,oBAAoB;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC3C,OAAO,CAAC,EAAE,CAAe;IACzB,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO;IAKP;;;;;;;OAOG;IACH,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,aAAa;IAgB3E;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CACf,EAAE,EAAE,YAAY,EAChB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,aAAa;IAeV,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,iBAAiB,CACrB,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,WAAW,CAAC;IAgDvB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAenE,gBAAgB,CACpB,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IA0FxB,sBAAsB,CAC1B,MAAM,EAAE,4BAA4B,GACnC,OAAO,CAAC,WAAW,CAAC;IAmCjB,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,WAAW,CAAC;IAoCtE,mBAAmB,CACvB,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,WAAW,CAAC;IAyCjB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,WAAW,CAAC;IA+DpE,iBAAiB,CACrB,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,WAAW,CAAC;IAuDvB,gBAAgB,CACd,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAgE1C,gBAAgB,CACd,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAmE1C,OAAO,CAAC,wBAAwB;IAyC1B,iBAAiB,CACrB,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,WAAW,CAAC;IAwCvB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAenE,mBAAmB,CACvB,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,WAAW,CAAC;IA0DjB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,WAAW,CAAC;CAyD3E"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_NAMESPACE_ID } from "../backend.js";
|
|
1
|
+
import { DEFAULT_NAMESPACE_ID, } from "../backend.js";
|
|
2
2
|
import { DEFAULT_RETRY_POLICY } from "../core/retry.js";
|
|
3
3
|
import { newDatabase, migrate, generateUUID, now, addMilliseconds, toJSON, fromJSON, toISO, fromISO, } from "./sqlite.js";
|
|
4
4
|
const DEFAULT_PAGINATION_PAGE_SIZE = 100;
|
|
@@ -32,6 +32,25 @@ export class BackendSqlite {
|
|
|
32
32
|
}
|
|
33
33
|
return new BackendSqlite(db, namespaceId);
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Create and initialize a new BackendSqlite instance from an existing
|
|
37
|
+
* SQLite database connection. This will automatically run migrations on
|
|
38
|
+
* startup unless `runMigrations` is set to false.
|
|
39
|
+
* @param db - SQLite database connection
|
|
40
|
+
* @param options - Backend options
|
|
41
|
+
* @returns A connected backend instance
|
|
42
|
+
*/
|
|
43
|
+
static fromClient(db, options) {
|
|
44
|
+
const { namespaceId, runMigrations } = {
|
|
45
|
+
namespaceId: DEFAULT_NAMESPACE_ID,
|
|
46
|
+
runMigrations: true,
|
|
47
|
+
...options,
|
|
48
|
+
};
|
|
49
|
+
if (runMigrations) {
|
|
50
|
+
migrate(db);
|
|
51
|
+
}
|
|
52
|
+
return new BackendSqlite(db, namespaceId);
|
|
53
|
+
}
|
|
35
54
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
36
55
|
async stop() {
|
|
37
56
|
this.db.close();
|
|
@@ -310,12 +329,12 @@ export class BackendSqlite {
|
|
|
310
329
|
cursor = decodeCursor(before);
|
|
311
330
|
}
|
|
312
331
|
const order = before
|
|
313
|
-
? `ORDER BY "created_at"
|
|
314
|
-
: `ORDER BY "created_at"
|
|
332
|
+
? `ORDER BY "created_at" ASC, "id" ASC`
|
|
333
|
+
: `ORDER BY "created_at" DESC, "id" DESC`;
|
|
315
334
|
let query;
|
|
316
335
|
let queryParams;
|
|
317
336
|
if (cursor) {
|
|
318
|
-
const op = after ? "
|
|
337
|
+
const op = after ? "<" : ">";
|
|
319
338
|
query = `
|
|
320
339
|
SELECT *
|
|
321
340
|
FROM "workflow_runs"
|
|
@@ -652,4 +671,3 @@ function decodeCursor(cursor) {
|
|
|
652
671
|
id: parsed.id,
|
|
653
672
|
};
|
|
654
673
|
}
|
|
655
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BackendSqlite } from "./backend.js";
|
|
2
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
3
|
+
/**
|
|
4
|
+
* Create a SQLite-backed OpenWorkflow backend using node:sqlite.
|
|
5
|
+
* @param client - SQLite client or database path
|
|
6
|
+
* @param options - Backend options
|
|
7
|
+
* @returns A connected backend instance
|
|
8
|
+
*/
|
|
9
|
+
export declare function openworkflow(client: DatabaseSync, options?: Parameters<typeof BackendSqlite.fromClient>[1]): BackendSqlite;
|
|
10
|
+
export declare function openworkflow(path: string, options?: Parameters<typeof BackendSqlite.connect>[1]): BackendSqlite;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../node-sqlite/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,YAAY,EACpB,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GACvD,aAAa,CAAC;AACjB,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GACpD,aAAa,CAAC"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { DatabaseSync } from "node:sqlite";
|
|
2
|
-
export type Database = DatabaseSync;
|
|
3
2
|
/**
|
|
4
3
|
* newDatabase creates a new SQLite database connection.
|
|
5
4
|
* @param path - Database file path (or ":memory:") for testing
|
|
6
5
|
* @returns SQLite database connection
|
|
7
6
|
*/
|
|
8
|
-
export declare function newDatabase(path: string):
|
|
7
|
+
export declare function newDatabase(path: string): DatabaseSync;
|
|
9
8
|
/**
|
|
10
9
|
* migrations returns the list of migration SQL statements.
|
|
11
10
|
* @returns Migration SQL statements
|
|
@@ -16,7 +15,7 @@ export declare function migrations(): string[];
|
|
|
16
15
|
* database is already up to date.
|
|
17
16
|
* @param db - SQLite database
|
|
18
17
|
*/
|
|
19
|
-
export declare function migrate(db:
|
|
18
|
+
export declare function migrate(db: DatabaseSync): void;
|
|
20
19
|
/**
|
|
21
20
|
* Helper to generate UUIDs (SQLite doesn't have built-in UUID generation)
|
|
22
21
|
* @returns A UUID string
|
|
@@ -0,0 +1 @@
|
|
|
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,4 +1,6 @@
|
|
|
1
|
-
import { Backend, CancelWorkflowRunParams, ClaimWorkflowRunParams, CreateStepAttemptParams, CreateWorkflowRunParams, GetStepAttemptParams, GetWorkflowRunParams, ExtendWorkflowRunLeaseParams, ListStepAttemptsParams, ListWorkflowRunsParams, PaginatedResponse, FailStepAttemptParams, CompleteStepAttemptParams, FailWorkflowRunParams, CompleteWorkflowRunParams, SleepWorkflowRunParams
|
|
1
|
+
import { Backend, CancelWorkflowRunParams, ClaimWorkflowRunParams, CreateStepAttemptParams, CreateWorkflowRunParams, GetStepAttemptParams, GetWorkflowRunParams, ExtendWorkflowRunLeaseParams, ListStepAttemptsParams, ListWorkflowRunsParams, PaginatedResponse, FailStepAttemptParams, CompleteStepAttemptParams, FailWorkflowRunParams, CompleteWorkflowRunParams, SleepWorkflowRunParams } from "../backend.js";
|
|
2
|
+
import { StepAttempt } from "../core/step.js";
|
|
3
|
+
import { WorkflowRun } from "../core/workflow.js";
|
|
2
4
|
interface BackendPostgresOptions {
|
|
3
5
|
namespaceId?: string;
|
|
4
6
|
runMigrations?: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../postgres/backend.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,EACP,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,oBAAoB,EACpB,oBAAoB,EACpB,4BAA4B,EAC5B,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,EACrB,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACvB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAWlD,UAAU,sBAAsB;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,qBAAa,eAAgB,YAAW,OAAO;IAC7C,OAAO,CAAC,EAAE,CAAW;IACrB,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO;IAKP;;;;;;;OAOG;WACU,OAAO,CAClB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,eAAe,CAAC;IAiBrB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,iBAAiB,CACrB,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,WAAW,CAAC;IA0CjB,cAAc,CAClB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAYxB,gBAAgB,CACpB,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IA2B1C,OAAO,CAAC,0BAA0B;IA0B5B,gBAAgB,CACpB,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAmDxB,sBAAsB,CAC1B,MAAM,EAAE,4BAA4B,GACnC,OAAO,CAAC,WAAW,CAAC;IAkBjB,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,WAAW,CAAC;IAwBtE,mBAAmB,CACvB,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,WAAW,CAAC;IAuBjB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,WAAW,CAAC;IAgEpE,iBAAiB,CACrB,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,WAAW,CAAC;IA2CjB,iBAAiB,CACrB,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,WAAW,CAAC;IAoCjB,cAAc,CAClB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAWxB,gBAAgB,CACpB,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IA2B1C,OAAO,CAAC,0BAA0B;IA6BlC,OAAO,CAAC,wBAAwB;IAyC1B,mBAAmB,CACvB,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,WAAW,CAAC;IA0BjB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,WAAW,CAAC;CAyB3E"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { DEFAULT_NAMESPACE_ID, } from "../backend.js";
|
|
2
|
+
import { DEFAULT_RETRY_POLICY } from "../core/retry.js";
|
|
1
3
|
import { newPostgres, newPostgresMaxOne, migrate, DEFAULT_SCHEMA, } from "./postgres.js";
|
|
2
|
-
import { DEFAULT_NAMESPACE_ID, DEFAULT_RETRY_POLICY, } from "openworkflow/internal";
|
|
3
4
|
const DEFAULT_PAGINATION_PAGE_SIZE = 100;
|
|
4
5
|
/**
|
|
5
6
|
* Manages a connection to a Postgres database for workflow operations.
|
|
@@ -98,8 +99,8 @@ export class BackendPostgres {
|
|
|
98
99
|
}
|
|
99
100
|
const whereClause = this.buildListWorkflowRunsWhere(params, cursor);
|
|
100
101
|
const order = before
|
|
101
|
-
? this.pg `ORDER BY "created_at"
|
|
102
|
-
: this.pg `ORDER BY "created_at"
|
|
102
|
+
? this.pg `ORDER BY "created_at" ASC, "id" ASC`
|
|
103
|
+
: this.pg `ORDER BY "created_at" DESC, "id" DESC`;
|
|
103
104
|
const rows = await this.pg `
|
|
104
105
|
SELECT *
|
|
105
106
|
FROM "openworkflow"."workflow_runs"
|
|
@@ -113,7 +114,7 @@ export class BackendPostgres {
|
|
|
113
114
|
const { after } = params;
|
|
114
115
|
const conditions = [this.pg `"namespace_id" = ${this.namespaceId}`];
|
|
115
116
|
if (cursor) {
|
|
116
|
-
const op = after ? this.pg
|
|
117
|
+
const op = after ? this.pg `<` : this.pg `>`;
|
|
117
118
|
conditions.push(this.pg `("created_at", "id") ${op} (${cursor.createdAt}, ${cursor.id})`);
|
|
118
119
|
}
|
|
119
120
|
let whereClause = conditions[0];
|
|
@@ -531,4 +532,3 @@ function decodeCursor(cursor) {
|
|
|
531
532
|
id: parsed.id,
|
|
532
533
|
};
|
|
533
534
|
}
|
|
534
|
-
//# sourceMappingURL=backend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.test.d.ts","sourceRoot":"","sources":["../../postgres/backend.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../postgres/internal.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./postgres.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../postgres/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,eAAO,MAAM,oBAAoB,2DACyB,CAAC;AAO3D,eAAO,MAAM,cAAc,iBAAiB,CAAC;AAE7C,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC;AACnD,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7D;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,oBAEjE;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,oBAEvE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CA+JnD;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iBAQzD;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iBAE5D"}
|
|
@@ -231,4 +231,3 @@ async function getCurrentMigrationVersion(pg, schema) {
|
|
|
231
231
|
const currentVersionRes = await pg.unsafe(`SELECT MAX("version") AS "version" FROM "${schema}"."openworkflow_migrations";`);
|
|
232
232
|
return currentVersionRes[0]?.version ?? -1;
|
|
233
233
|
}
|
|
234
|
-
//# sourceMappingURL=postgres.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres.test.d.ts","sourceRoot":"","sources":["../../postgres/postgres.test.ts"],"names":[],"mappings":""}
|