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.
- package/README.md +2 -0
- package/dist/bin/openworkflow.js +0 -0
- package/dist/internal.d.ts +0 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +0 -1
- package/package.json +6 -6
- package/dist/backend-test/backend.testsuite.d.ts +0 -20
- package/dist/backend-test/backend.testsuite.d.ts.map +0 -1
- package/dist/backend-test/backend.testsuite.js +0 -1090
- package/dist/backend-test/index.d.ts +0 -2
- package/dist/backend-test/index.d.ts.map +0 -1
- package/dist/backend-test/index.js +0 -1
- package/dist/backend.testsuite.d.ts +0 -20
- package/dist/backend.testsuite.d.ts.map +0 -1
- package/dist/backend.testsuite.js +0 -1090
- package/dist/chaos.test.d.ts +0 -2
- package/dist/chaos.test.d.ts.map +0 -1
- package/dist/chaos.test.js +0 -88
- package/dist/client.test.d.ts +0 -2
- package/dist/client.test.d.ts.map +0 -1
- package/dist/client.test.js +0 -311
- package/dist/core/duration.test.d.ts +0 -2
- package/dist/core/duration.test.d.ts.map +0 -1
- package/dist/core/duration.test.js +0 -263
- package/dist/core/error.test.d.ts +0 -2
- package/dist/core/error.test.d.ts.map +0 -1
- package/dist/core/error.test.js +0 -60
- package/dist/core/result.test.d.ts +0 -2
- package/dist/core/result.test.d.ts.map +0 -1
- package/dist/core/result.test.js +0 -11
- package/dist/core/step.test.d.ts +0 -2
- package/dist/core/step.test.d.ts.map +0 -1
- package/dist/core/step.test.js +0 -266
- package/dist/core/workflow.test.d.ts +0 -2
- package/dist/core/workflow.test.d.ts.map +0 -1
- package/dist/core/workflow.test.js +0 -113
- package/dist/driver.d.ts +0 -116
- package/dist/driver.d.ts.map +0 -1
- package/dist/driver.js +0 -1
- package/dist/execution.test.d.ts +0 -2
- package/dist/execution.test.d.ts.map +0 -1
- package/dist/execution.test.js +0 -381
- package/dist/factory.d.ts +0 -74
- package/dist/factory.d.ts.map +0 -1
- package/dist/factory.js +0 -72
- package/dist/node-sqlite/backend.d.ts +0 -52
- package/dist/node-sqlite/backend.d.ts.map +0 -1
- package/dist/node-sqlite/backend.js +0 -673
- package/dist/node-sqlite/index.d.ts +0 -11
- package/dist/node-sqlite/index.d.ts.map +0 -1
- package/dist/node-sqlite/index.js +0 -7
- package/dist/node-sqlite/sqlite.d.ts +0 -60
- package/dist/node-sqlite/sqlite.d.ts.map +0 -1
- package/dist/node-sqlite/sqlite.js +0 -246
- package/dist/postgres/backend.test.d.ts +0 -2
- package/dist/postgres/backend.test.d.ts.map +0 -1
- package/dist/postgres/backend.test.js +0 -19
- package/dist/postgres/driver.d.ts +0 -81
- package/dist/postgres/driver.d.ts.map +0 -1
- package/dist/postgres/driver.js +0 -63
- package/dist/postgres/index.d.ts +0 -11
- package/dist/postgres/index.d.ts.map +0 -1
- package/dist/postgres/index.js +0 -7
- package/dist/postgres/internal.d.ts +0 -2
- package/dist/postgres/internal.d.ts.map +0 -1
- package/dist/postgres/internal.js +0 -1
- package/dist/postgres/postgres.test.d.ts +0 -2
- package/dist/postgres/postgres.test.d.ts.map +0 -1
- package/dist/postgres/postgres.test.js +0 -45
- package/dist/postgres/vitest.global-setup.d.ts +0 -3
- package/dist/postgres/vitest.global-setup.d.ts.map +0 -1
- package/dist/postgres/vitest.global-setup.js +0 -7
- package/dist/registry.test.d.ts +0 -2
- package/dist/registry.test.d.ts.map +0 -1
- package/dist/registry.test.js +0 -109
- package/dist/sqlite/backend.test.d.ts +0 -2
- package/dist/sqlite/backend.test.d.ts.map +0 -1
- package/dist/sqlite/backend.test.js +0 -50
- package/dist/sqlite/driver.d.ts +0 -79
- package/dist/sqlite/driver.d.ts.map +0 -1
- package/dist/sqlite/driver.js +0 -62
- package/dist/sqlite/index.d.ts +0 -13
- package/dist/sqlite/index.d.ts.map +0 -1
- package/dist/sqlite/index.js +0 -11
- package/dist/sqlite/internal.d.ts +0 -2
- package/dist/sqlite/internal.d.ts.map +0 -1
- package/dist/sqlite/internal.js +0 -1
- package/dist/sqlite/sqlite.test.d.ts +0 -2
- package/dist/sqlite/sqlite.test.d.ts.map +0 -1
- package/dist/sqlite/sqlite.test.js +0 -171
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/worker.test.d.ts +0 -2
- package/dist/worker.test.d.ts.map +0 -1
- package/dist/worker.test.js +0 -900
- package/dist/workflow.test.d.ts +0 -2
- package/dist/workflow.test.d.ts.map +0 -1
- package/dist/workflow.test.js +0 -84
package/dist/registry.test.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { WorkflowRegistry } from "./registry.js";
|
|
2
|
-
import { defineWorkflow } from "./workflow.js";
|
|
3
|
-
import { describe, expect, test } from "vitest";
|
|
4
|
-
describe("WorkflowRegistry", () => {
|
|
5
|
-
describe("register", () => {
|
|
6
|
-
test("registers a workflow without version", () => {
|
|
7
|
-
const registry = new WorkflowRegistry();
|
|
8
|
-
const workflow = createMockWorkflow("my-workflow");
|
|
9
|
-
registry.register(workflow);
|
|
10
|
-
expect(registry.get("my-workflow", null)).toBe(workflow);
|
|
11
|
-
});
|
|
12
|
-
test("registers a workflow with version", () => {
|
|
13
|
-
const registry = new WorkflowRegistry();
|
|
14
|
-
const workflow = createMockWorkflow("my-workflow", "v1");
|
|
15
|
-
registry.register(workflow);
|
|
16
|
-
expect(registry.get("my-workflow", "v1")).toBe(workflow);
|
|
17
|
-
});
|
|
18
|
-
test("registers multiple versions of the same workflow", () => {
|
|
19
|
-
const registry = new WorkflowRegistry();
|
|
20
|
-
const v1 = createMockWorkflow("my-workflow", "v1");
|
|
21
|
-
const v2 = createMockWorkflow("my-workflow", "v2");
|
|
22
|
-
registry.register(v1);
|
|
23
|
-
registry.register(v2);
|
|
24
|
-
expect(registry.get("my-workflow", "v1")).toBe(v1);
|
|
25
|
-
expect(registry.get("my-workflow", "v2")).toBe(v2);
|
|
26
|
-
});
|
|
27
|
-
test("registers different workflows with same version", () => {
|
|
28
|
-
const registry = new WorkflowRegistry();
|
|
29
|
-
const workflow1 = createMockWorkflow("workflow-a", "v1");
|
|
30
|
-
const workflow2 = createMockWorkflow("workflow-b", "v1");
|
|
31
|
-
registry.register(workflow1);
|
|
32
|
-
registry.register(workflow2);
|
|
33
|
-
expect(registry.get("workflow-a", "v1")).toBe(workflow1);
|
|
34
|
-
expect(registry.get("workflow-b", "v1")).toBe(workflow2);
|
|
35
|
-
});
|
|
36
|
-
test("throws when registering duplicate unversioned workflow", () => {
|
|
37
|
-
const registry = new WorkflowRegistry();
|
|
38
|
-
registry.register(createMockWorkflow("my-workflow"));
|
|
39
|
-
expect(() => {
|
|
40
|
-
registry.register(createMockWorkflow("my-workflow"));
|
|
41
|
-
}).toThrow('Workflow "my-workflow" is already registered');
|
|
42
|
-
});
|
|
43
|
-
test("throws when registering duplicate versioned workflow", () => {
|
|
44
|
-
const registry = new WorkflowRegistry();
|
|
45
|
-
registry.register(createMockWorkflow("my-workflow", "v1"));
|
|
46
|
-
expect(() => {
|
|
47
|
-
registry.register(createMockWorkflow("my-workflow", "v1"));
|
|
48
|
-
}).toThrow('Workflow "my-workflow" (version: v1) is already registered');
|
|
49
|
-
});
|
|
50
|
-
test("allows same name with different versions", () => {
|
|
51
|
-
const registry = new WorkflowRegistry();
|
|
52
|
-
const versioned = createMockWorkflow("my-workflow", "v1");
|
|
53
|
-
const unversioned = createMockWorkflow("my-workflow");
|
|
54
|
-
registry.register(versioned);
|
|
55
|
-
registry.register(unversioned);
|
|
56
|
-
expect(registry.get("my-workflow", "v1")).toBe(versioned);
|
|
57
|
-
expect(registry.get("my-workflow", null)).toBe(unversioned);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
describe("get", () => {
|
|
61
|
-
test("returns undefined for non-existent workflow", () => {
|
|
62
|
-
const registry = new WorkflowRegistry();
|
|
63
|
-
expect(registry.get("non-existent", null)).toBeUndefined();
|
|
64
|
-
});
|
|
65
|
-
test("returns undefined for wrong version", () => {
|
|
66
|
-
const registry = new WorkflowRegistry();
|
|
67
|
-
registry.register(createMockWorkflow("my-workflow", "v1"));
|
|
68
|
-
expect(registry.get("my-workflow", "v2")).toBeUndefined();
|
|
69
|
-
expect(registry.get("my-workflow", null)).toBeUndefined();
|
|
70
|
-
});
|
|
71
|
-
test("returns undefined for versioned lookup on unversioned workflow", () => {
|
|
72
|
-
const registry = new WorkflowRegistry();
|
|
73
|
-
registry.register(createMockWorkflow("my-workflow"));
|
|
74
|
-
expect(registry.get("my-workflow", "v1")).toBeUndefined();
|
|
75
|
-
});
|
|
76
|
-
test("returns the registered workflow", () => {
|
|
77
|
-
const registry = new WorkflowRegistry();
|
|
78
|
-
const workflow = createMockWorkflow("my-workflow");
|
|
79
|
-
registry.register(workflow);
|
|
80
|
-
expect(registry.get("my-workflow", null)).toBe(workflow);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
describe("getAll", () => {
|
|
84
|
-
test("returns all registered workflows", () => {
|
|
85
|
-
const registry = new WorkflowRegistry();
|
|
86
|
-
const a = createMockWorkflow("workflow-a");
|
|
87
|
-
const b = createMockWorkflow("workflow-b", "v1");
|
|
88
|
-
const c = createMockWorkflow("workflow-a", "v2");
|
|
89
|
-
registry.register(a);
|
|
90
|
-
registry.register(b);
|
|
91
|
-
registry.register(c);
|
|
92
|
-
const all = registry.getAll();
|
|
93
|
-
expect(all).toHaveLength(3);
|
|
94
|
-
expect(all).toEqual(expect.arrayContaining([a, b, c]));
|
|
95
|
-
});
|
|
96
|
-
test("returns empty array when none registered", () => {
|
|
97
|
-
const registry = new WorkflowRegistry();
|
|
98
|
-
expect(registry.getAll()).toEqual([]);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
function createMockWorkflow(name, version) {
|
|
103
|
-
return defineWorkflow({
|
|
104
|
-
name,
|
|
105
|
-
...(version && { version }),
|
|
106
|
-
}, async () => {
|
|
107
|
-
// no-op
|
|
108
|
-
});
|
|
109
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"backend.test.d.ts","sourceRoot":"","sources":["../../sqlite/backend.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { testBackend } from "../internal.js";
|
|
2
|
-
import { BackendSqlite } from "./backend.js";
|
|
3
|
-
import assert from "node:assert";
|
|
4
|
-
import { randomUUID } from "node:crypto";
|
|
5
|
-
import { unlinkSync, existsSync } from "node:fs";
|
|
6
|
-
import { tmpdir } from "node:os";
|
|
7
|
-
import path from "node:path";
|
|
8
|
-
import { test, describe, afterAll } from "vitest";
|
|
9
|
-
test("it is a test file (workaround for sonarjs/no-empty-test-file linter)", () => {
|
|
10
|
-
assert.ok(true);
|
|
11
|
-
});
|
|
12
|
-
describe("BackendSqlite (in-memory)", () => {
|
|
13
|
-
testBackend({
|
|
14
|
-
setup: () => {
|
|
15
|
-
return Promise.resolve(BackendSqlite.connect(":memory:", {
|
|
16
|
-
namespaceId: randomUUID(),
|
|
17
|
-
}));
|
|
18
|
-
},
|
|
19
|
-
teardown: async (backend) => {
|
|
20
|
-
await backend.stop();
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
describe("BackendSqlite (file-based)", () => {
|
|
25
|
-
const testDbPath = path.join(tmpdir(), `openworkflow-test-${randomUUID()}.db`);
|
|
26
|
-
afterAll(() => {
|
|
27
|
-
const walPath = `${testDbPath}-wal`;
|
|
28
|
-
const shmPath = `${testDbPath}-shm`;
|
|
29
|
-
// clean up the test database, WAL, and SHM files if they exist
|
|
30
|
-
if (existsSync(testDbPath)) {
|
|
31
|
-
unlinkSync(testDbPath);
|
|
32
|
-
}
|
|
33
|
-
if (existsSync(walPath)) {
|
|
34
|
-
unlinkSync(walPath);
|
|
35
|
-
}
|
|
36
|
-
if (existsSync(shmPath)) {
|
|
37
|
-
unlinkSync(shmPath);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
testBackend({
|
|
41
|
-
setup: () => {
|
|
42
|
-
return Promise.resolve(BackendSqlite.connect(testDbPath, {
|
|
43
|
-
namespaceId: randomUUID(),
|
|
44
|
-
}));
|
|
45
|
-
},
|
|
46
|
-
teardown: async (backend) => {
|
|
47
|
-
await backend.stop();
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
});
|
package/dist/sqlite/driver.d.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SQLite driver for OpenWorkflow using the Drizzle-style API.
|
|
3
|
-
*
|
|
4
|
-
* This module provides a `sqlite()` function that creates a driver
|
|
5
|
-
* for connecting to SQLite databases.
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* import { openworkflow } from 'openworkflow';
|
|
9
|
-
* import { sqlite } from 'openworkflow/sqlite';
|
|
10
|
-
*
|
|
11
|
-
* // In-memory database (great for testing)
|
|
12
|
-
* const ow = await openworkflow(sqlite(':memory:'));
|
|
13
|
-
*
|
|
14
|
-
* // File-based database
|
|
15
|
-
* const ow = await openworkflow(sqlite('./data/workflow.db'));
|
|
16
|
-
*
|
|
17
|
-
* // With configuration options
|
|
18
|
-
* const ow = await openworkflow(sqlite({
|
|
19
|
-
* path: './data/workflow.db',
|
|
20
|
-
* namespace: 'my-app',
|
|
21
|
-
* runMigrations: true,
|
|
22
|
-
* }));
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
import type { Backend, Driver, DriverConfig } from "openworkflow/internal";
|
|
26
|
-
/**
|
|
27
|
-
* SQLite-specific driver configuration.
|
|
28
|
-
*/
|
|
29
|
-
export interface SqliteDriverConfig extends DriverConfig {
|
|
30
|
-
/**
|
|
31
|
-
* Path to the SQLite database file.
|
|
32
|
-
* Use ':memory:' for an in-memory database.
|
|
33
|
-
*/
|
|
34
|
-
path?: string;
|
|
35
|
-
/**
|
|
36
|
-
* Existing SQLite database instance.
|
|
37
|
-
* If provided, the driver will use this database instead of creating a new one.
|
|
38
|
-
*/
|
|
39
|
-
database?: SqliteDatabase;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Interface for SQLite database instance.
|
|
43
|
-
* This matches the node:sqlite DatabaseSync interface.
|
|
44
|
-
*/
|
|
45
|
-
export interface SqliteDatabase {
|
|
46
|
-
close(): void;
|
|
47
|
-
exec(sql: string): void;
|
|
48
|
-
prepare(sql: string): any;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* SQLite driver instance.
|
|
52
|
-
*/
|
|
53
|
-
export interface SqliteDriver extends Driver {
|
|
54
|
-
readonly dialect: "sqlite";
|
|
55
|
-
readonly $client: SqliteDatabase | undefined;
|
|
56
|
-
createBackend(): Backend;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Creates a SQLite driver for OpenWorkflow.
|
|
60
|
-
*
|
|
61
|
-
* This function follows the Drizzle ORM pattern and supports multiple
|
|
62
|
-
* calling conventions:
|
|
63
|
-
* @param config - Database path or configuration object
|
|
64
|
-
* @returns A SqliteDriver instance
|
|
65
|
-
* @example
|
|
66
|
-
* ```ts
|
|
67
|
-
* // With database path
|
|
68
|
-
* sqlite('./data/workflow.db')
|
|
69
|
-
* sqlite(':memory:')
|
|
70
|
-
*
|
|
71
|
-
* // With config object
|
|
72
|
-
* sqlite({
|
|
73
|
-
* path: './data/workflow.db',
|
|
74
|
-
* namespace: 'my-app',
|
|
75
|
-
* })
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
export declare function sqlite(config: string | SqliteDriverConfig): SqliteDriver;
|
|
79
|
-
//# sourceMappingURL=driver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../../sqlite/driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACtD;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,IAAI,IAAI,CAAC;IACd,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAExB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,MAAM;IAC1C,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS,CAAC;IAC7C,aAAa,IAAI,OAAO,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,GAAG,YAAY,CAqExE"}
|
package/dist/sqlite/driver.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a SQLite driver for OpenWorkflow.
|
|
3
|
-
*
|
|
4
|
-
* This function follows the Drizzle ORM pattern and supports multiple
|
|
5
|
-
* calling conventions:
|
|
6
|
-
* @param config - Database path or configuration object
|
|
7
|
-
* @returns A SqliteDriver instance
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* // With database path
|
|
11
|
-
* sqlite('./data/workflow.db')
|
|
12
|
-
* sqlite(':memory:')
|
|
13
|
-
*
|
|
14
|
-
* // With config object
|
|
15
|
-
* sqlite({
|
|
16
|
-
* path: './data/workflow.db',
|
|
17
|
-
* namespace: 'my-app',
|
|
18
|
-
* })
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export function sqlite(config) {
|
|
22
|
-
// Normalize config
|
|
23
|
-
const normalizedConfig = typeof config === "string" ? { path: config } : config;
|
|
24
|
-
// Store the database reference (will be set on createBackend)
|
|
25
|
-
let databaseRef = normalizedConfig.database;
|
|
26
|
-
return {
|
|
27
|
-
dialect: "sqlite",
|
|
28
|
-
get $client() {
|
|
29
|
-
return databaseRef;
|
|
30
|
-
},
|
|
31
|
-
createBackend() {
|
|
32
|
-
// Dynamically import BackendSqlite to avoid requiring the sqlite
|
|
33
|
-
// package as a direct dependency of the openworkflow package
|
|
34
|
-
// Note: We use require here because sqlite is synchronous
|
|
35
|
-
// Determine the database path
|
|
36
|
-
const databasePath = normalizedConfig.path;
|
|
37
|
-
if (!databasePath && !normalizedConfig.database) {
|
|
38
|
-
throw new Error("SQLite driver requires either a database path or an existing database. " +
|
|
39
|
-
"Provide `path` or `database` in the config.");
|
|
40
|
-
}
|
|
41
|
-
// If we have an existing database, we need to handle it differently
|
|
42
|
-
if (!databasePath) {
|
|
43
|
-
throw new Error("Using an existing SQLite database is not yet supported. " +
|
|
44
|
-
"Please provide a database path via the `path` option.");
|
|
45
|
-
}
|
|
46
|
-
// Import and create the backend synchronously
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
48
|
-
const { BackendSqlite } = require("@openworkflow/backend-sqlite");
|
|
49
|
-
const options = {
|
|
50
|
-
runMigrations: normalizedConfig.runMigrations ?? true,
|
|
51
|
-
};
|
|
52
|
-
if (normalizedConfig.namespace) {
|
|
53
|
-
options.namespaceId = normalizedConfig.namespace;
|
|
54
|
-
}
|
|
55
|
-
const backend = BackendSqlite.connect(databasePath, options);
|
|
56
|
-
// Store database reference for $client getter
|
|
57
|
-
// Note: BackendSqlite doesn't expose the database, so this remains undefined
|
|
58
|
-
databaseRef = undefined;
|
|
59
|
-
return backend;
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
}
|
package/dist/sqlite/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SQLite driver for OpenWorkflow.
|
|
3
|
-
* @example
|
|
4
|
-
* ```ts
|
|
5
|
-
* import { openworkflow } from 'openworkflow';
|
|
6
|
-
* import { sqlite } from 'openworkflow/sqlite';
|
|
7
|
-
*
|
|
8
|
-
* const ow = await openworkflow(sqlite(':memory:'));
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
export { sqlite } from "./driver.js";
|
|
12
|
-
export type { SqliteDriver, SqliteDriverConfig, SqliteDatabase, } from "./driver.js";
|
|
13
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../sqlite/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,YAAY,EACV,YAAY,EACZ,kBAAkB,EAClB,cAAc,GACf,MAAM,aAAa,CAAC"}
|
package/dist/sqlite/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SQLite driver for OpenWorkflow.
|
|
3
|
-
* @example
|
|
4
|
-
* ```ts
|
|
5
|
-
* import { openworkflow } from 'openworkflow';
|
|
6
|
-
* import { sqlite } from 'openworkflow/sqlite';
|
|
7
|
-
*
|
|
8
|
-
* const ow = await openworkflow(sqlite(':memory:'));
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
export { sqlite } from "./driver.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../sqlite/internal.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
package/dist/sqlite/internal.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./sqlite.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.test.d.ts","sourceRoot":"","sources":["../../sqlite/sqlite.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { migrate, migrations, newDatabase } from "./sqlite.js";
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { existsSync, unlinkSync } from "node:fs";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
7
|
-
// Helper to get the current migration version (exported for testing)
|
|
8
|
-
// Note: This function exists in sqlite.ts but isn't exported, so we'll
|
|
9
|
-
// test it indirectly through migrate() and by checking the migrations table
|
|
10
|
-
function getMigrationVersion(db) {
|
|
11
|
-
const existsStmt = db.prepare(`
|
|
12
|
-
SELECT COUNT(*) as count
|
|
13
|
-
FROM sqlite_master
|
|
14
|
-
WHERE type = 'table' AND name = 'openworkflow_migrations'
|
|
15
|
-
`);
|
|
16
|
-
const existsResult = existsStmt.get();
|
|
17
|
-
if (!existsResult || existsResult.count === 0)
|
|
18
|
-
return -1;
|
|
19
|
-
const versionStmt = db.prepare(`SELECT MAX("version") AS "version" FROM "openworkflow_migrations";`);
|
|
20
|
-
const versionResult = versionStmt.get();
|
|
21
|
-
return versionResult?.version ?? -1;
|
|
22
|
-
}
|
|
23
|
-
describe("sqlite", () => {
|
|
24
|
-
let db;
|
|
25
|
-
let dbPath;
|
|
26
|
-
beforeEach(() => {
|
|
27
|
-
// Use a unique file path for each test to ensure isolation
|
|
28
|
-
dbPath = path.join(tmpdir(), `test_${randomUUID()}.db`);
|
|
29
|
-
db = newDatabase(dbPath);
|
|
30
|
-
});
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
db.close();
|
|
33
|
-
const walPath = `${dbPath}-wal`;
|
|
34
|
-
const shmPath = `${dbPath}-shm`;
|
|
35
|
-
// clean up the test database, WAL, and SHM files if they exist
|
|
36
|
-
if (existsSync(dbPath)) {
|
|
37
|
-
unlinkSync(dbPath);
|
|
38
|
-
}
|
|
39
|
-
if (existsSync(walPath)) {
|
|
40
|
-
unlinkSync(walPath);
|
|
41
|
-
}
|
|
42
|
-
if (existsSync(shmPath)) {
|
|
43
|
-
unlinkSync(shmPath);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
describe("migrations()", () => {
|
|
47
|
-
test("returns migration SQL statements with correct table names", () => {
|
|
48
|
-
const migs = migrations();
|
|
49
|
-
expect(migs.length).toBeGreaterThan(0);
|
|
50
|
-
// Check that migrations reference the openworkflow_migrations table
|
|
51
|
-
for (const mig of migs) {
|
|
52
|
-
expect(mig).toContain("openworkflow_migrations");
|
|
53
|
-
}
|
|
54
|
-
// Verify first migration creates the migrations table
|
|
55
|
-
expect(migs[0]).toContain('CREATE TABLE IF NOT EXISTS "openworkflow_migrations"');
|
|
56
|
-
expect(migs[0]).toContain('"version"');
|
|
57
|
-
});
|
|
58
|
-
test("migrations create workflow_runs and step_attempts tables", () => {
|
|
59
|
-
const migs = migrations();
|
|
60
|
-
// Migration 1 should create workflow_runs and step_attempts
|
|
61
|
-
const migration1 = migs[1];
|
|
62
|
-
expect(migration1).toContain('CREATE TABLE IF NOT EXISTS "workflow_runs"');
|
|
63
|
-
expect(migration1).toContain('CREATE TABLE IF NOT EXISTS "step_attempts"');
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
describe("migrate()", () => {
|
|
67
|
-
test("runs database migrations idempotently", () => {
|
|
68
|
-
// First migration
|
|
69
|
-
migrate(db);
|
|
70
|
-
const version1 = getMigrationVersion(db);
|
|
71
|
-
expect(version1).toBeGreaterThanOrEqual(0);
|
|
72
|
-
// Second migration - should not cause errors
|
|
73
|
-
migrate(db);
|
|
74
|
-
const version2 = getMigrationVersion(db);
|
|
75
|
-
expect(version2).toBe(version1); // Version should not change
|
|
76
|
-
// Third migration - should still work
|
|
77
|
-
migrate(db);
|
|
78
|
-
const version3 = getMigrationVersion(db);
|
|
79
|
-
expect(version3).toBe(version1);
|
|
80
|
-
});
|
|
81
|
-
test("tracks migration versions correctly", () => {
|
|
82
|
-
// Before migration, version should be -1 (table doesn't exist)
|
|
83
|
-
let version = getMigrationVersion(db);
|
|
84
|
-
expect(version).toBe(-1);
|
|
85
|
-
// After migration, version should be the latest migration version
|
|
86
|
-
migrate(db);
|
|
87
|
-
version = getMigrationVersion(db);
|
|
88
|
-
const allMigrations = migrations();
|
|
89
|
-
const expectedLatestVersion = allMigrations.length - 1;
|
|
90
|
-
expect(version).toBe(expectedLatestVersion);
|
|
91
|
-
});
|
|
92
|
-
test("applies migrations incrementally", () => {
|
|
93
|
-
// Create the migrations table manually with version 0
|
|
94
|
-
db.exec(`
|
|
95
|
-
CREATE TABLE IF NOT EXISTS "openworkflow_migrations" (
|
|
96
|
-
"version" INTEGER NOT NULL PRIMARY KEY
|
|
97
|
-
);
|
|
98
|
-
INSERT OR IGNORE INTO "openworkflow_migrations" ("version")
|
|
99
|
-
VALUES (0);
|
|
100
|
-
`);
|
|
101
|
-
let version = getMigrationVersion(db);
|
|
102
|
-
expect(version).toBe(0);
|
|
103
|
-
// Run migrate - should apply remaining migrations
|
|
104
|
-
migrate(db);
|
|
105
|
-
version = getMigrationVersion(db);
|
|
106
|
-
const allMigrations = migrations();
|
|
107
|
-
const expectedLatestVersion = allMigrations.length - 1;
|
|
108
|
-
expect(version).toBe(expectedLatestVersion);
|
|
109
|
-
});
|
|
110
|
-
test("creates all required tables after migration", () => {
|
|
111
|
-
migrate(db);
|
|
112
|
-
// Check that migrations table exists
|
|
113
|
-
const migrationsCheck = db
|
|
114
|
-
.prepare(`
|
|
115
|
-
SELECT COUNT(*) as count
|
|
116
|
-
FROM sqlite_master
|
|
117
|
-
WHERE type = 'table' AND name = 'openworkflow_migrations'
|
|
118
|
-
`)
|
|
119
|
-
.get();
|
|
120
|
-
expect(migrationsCheck.count).toBe(1);
|
|
121
|
-
// Check that workflow_runs table exists
|
|
122
|
-
const workflowRunsCheck = db
|
|
123
|
-
.prepare(`
|
|
124
|
-
SELECT COUNT(*) as count
|
|
125
|
-
FROM sqlite_master
|
|
126
|
-
WHERE type = 'table' AND name = 'workflow_runs'
|
|
127
|
-
`)
|
|
128
|
-
.get();
|
|
129
|
-
expect(workflowRunsCheck.count).toBe(1);
|
|
130
|
-
// Check that step_attempts table exists
|
|
131
|
-
const stepAttemptsCheck = db
|
|
132
|
-
.prepare(`
|
|
133
|
-
SELECT COUNT(*) as count
|
|
134
|
-
FROM sqlite_master
|
|
135
|
-
WHERE type = 'table' AND name = 'step_attempts'
|
|
136
|
-
`)
|
|
137
|
-
.get();
|
|
138
|
-
expect(stepAttemptsCheck.count).toBe(1);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
describe("migration version tracking", () => {
|
|
142
|
-
test("migrations table stores version numbers correctly", () => {
|
|
143
|
-
migrate(db);
|
|
144
|
-
const versionStmt = db.prepare(`SELECT "version" FROM "openworkflow_migrations" ORDER BY "version";`);
|
|
145
|
-
const versions = versionStmt.all();
|
|
146
|
-
// Should have all migration versions from 0 to latest
|
|
147
|
-
const allMigrations = migrations();
|
|
148
|
-
const expectedLatestVersion = allMigrations.length - 1;
|
|
149
|
-
expect(versions.length).toBe(expectedLatestVersion + 1);
|
|
150
|
-
for (let i = 0; i <= expectedLatestVersion; i++) {
|
|
151
|
-
const version = versions[i];
|
|
152
|
-
expect(version).toBeDefined();
|
|
153
|
-
expect(version?.version).toBe(i);
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
test("migrations can be run multiple times safely with INSERT OR IGNORE", () => {
|
|
157
|
-
migrate(db);
|
|
158
|
-
const versionAfterFirst = getMigrationVersion(db);
|
|
159
|
-
// Run migrations again
|
|
160
|
-
migrate(db);
|
|
161
|
-
const versionAfterSecond = getMigrationVersion(db);
|
|
162
|
-
expect(versionAfterSecond).toBe(versionAfterFirst);
|
|
163
|
-
// Check that version entries aren't duplicated
|
|
164
|
-
const versionStmt = db.prepare(`SELECT COUNT(*) as count FROM "openworkflow_migrations";`);
|
|
165
|
-
const countResult = versionStmt.get();
|
|
166
|
-
const allMigrations = migrations();
|
|
167
|
-
const expectedCount = allMigrations.length;
|
|
168
|
-
expect(countResult.count).toBe(expectedCount);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
});
|