@yieldstar/sqlite-runtime 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/dist/bun.js +15 -17
  2. package/dist/dao/effect-waiters-dao.d.ts +19 -0
  3. package/dist/dao/effect-waiters-dao.d.ts.map +1 -0
  4. package/dist/dao/effects-dao.d.ts +17 -0
  5. package/dist/dao/effects-dao.d.ts.map +1 -0
  6. package/dist/dao/executions-dao.d.ts +24 -0
  7. package/dist/dao/executions-dao.d.ts.map +1 -0
  8. package/dist/dao/start-requests-dao.d.ts +15 -0
  9. package/dist/dao/start-requests-dao.d.ts.map +1 -0
  10. package/dist/dao/step-response-dao.d.ts +1 -0
  11. package/dist/dao/step-response-dao.d.ts.map +1 -1
  12. package/dist/dao/store-waiters-dao.d.ts +26 -0
  13. package/dist/dao/store-waiters-dao.d.ts.map +1 -0
  14. package/dist/index-083bmj5k.js +800 -0
  15. package/dist/index-4kybaxga.js +798 -0
  16. package/dist/index-a8thbaee.js +718 -0
  17. package/dist/index-ag93sv33.js +664 -0
  18. package/dist/index-eabcgmaa.js +996 -0
  19. package/dist/index-ekggxe8v.js +987 -0
  20. package/dist/index-gjfs8rn6.js +997 -0
  21. package/dist/index-h3h7r4b6.js +981 -0
  22. package/dist/index-ma984fze.js +718 -0
  23. package/dist/index-ne28djfn.js +718 -0
  24. package/dist/index-t60e4kvz.js +988 -0
  25. package/dist/index-v6rn0pr6.js +664 -0
  26. package/dist/index-wx6vk994.js +669 -0
  27. package/dist/index.d.ts +3 -4
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +11 -13
  30. package/dist/node.js +15 -17
  31. package/dist/sqlite-effect.d.ts +30 -0
  32. package/dist/sqlite-effect.d.ts.map +1 -0
  33. package/dist/sqlite-execution.d.ts +55 -0
  34. package/dist/sqlite-execution.d.ts.map +1 -0
  35. package/dist/sqlite-heap.d.ts +12 -4
  36. package/dist/sqlite-heap.d.ts.map +1 -1
  37. package/dist/sqlite-runtime.d.ts +22 -0
  38. package/dist/sqlite-runtime.d.ts.map +1 -0
  39. package/dist/sqlite-store.d.ts +31 -25
  40. package/dist/sqlite-store.d.ts.map +1 -1
  41. package/dist/sqlite-transaction.d.ts +9 -0
  42. package/dist/sqlite-transaction.d.ts.map +1 -0
  43. package/package.json +2 -2
  44. package/src/dao/effect-waiters-dao.ts +63 -0
  45. package/src/dao/effects-dao.ts +123 -0
  46. package/src/dao/executions-dao.ts +199 -0
  47. package/src/dao/start-requests-dao.ts +72 -0
  48. package/src/dao/step-response-dao.ts +16 -1
  49. package/src/dao/store-waiters-dao.ts +92 -0
  50. package/src/index.ts +6 -4
  51. package/src/sqlite-effect.ts +99 -0
  52. package/src/sqlite-execution.ts +242 -0
  53. package/src/sqlite-heap.ts +64 -12
  54. package/src/sqlite-runtime.ts +36 -0
  55. package/src/sqlite-store.ts +184 -520
  56. package/src/sqlite-transaction.ts +19 -0
  57. package/dist/dao/task-queue-dao.d.ts +0 -21
  58. package/dist/dao/task-queue-dao.d.ts.map +0 -1
  59. package/dist/dao/timers-dao.d.ts +0 -22
  60. package/dist/dao/timers-dao.d.ts.map +0 -1
  61. package/dist/index-4vq70w0r.js +0 -796
  62. package/dist/index-s8wqgfwt.js +0 -19
  63. package/dist/index-x891hxwg.js +0 -796
  64. package/dist/node-driver.d.ts +0 -10
  65. package/dist/node-driver.d.ts.map +0 -1
  66. package/dist/sqlite-event-loop.d.ts +0 -18
  67. package/dist/sqlite-event-loop.d.ts.map +0 -1
  68. package/dist/sqlite-scheduler.d.ts +0 -13
  69. package/dist/sqlite-scheduler.d.ts.map +0 -1
  70. package/dist/sqlite-store.test.d.ts +0 -2
  71. package/dist/sqlite-store.test.d.ts.map +0 -1
  72. package/dist/sqlite-task-queue.d.ts +0 -26
  73. package/dist/sqlite-task-queue.d.ts.map +0 -1
  74. package/dist/sqlite-timers.d.ts +0 -18
  75. package/dist/sqlite-timers.d.ts.map +0 -1
  76. package/src/dao/task-queue-dao.ts +0 -79
  77. package/src/dao/timers-dao.ts +0 -81
  78. package/src/sqlite-event-loop.ts +0 -41
  79. package/src/sqlite-scheduler.ts +0 -24
  80. package/src/sqlite-task-queue.ts +0 -64
  81. package/src/sqlite-timers.ts +0 -40
  82. package/tsconfig.tsbuildinfo +0 -1
  83. /package/dist/{index-h7bm9xg4.js → index-dapqh99v.js} +0 -0
@@ -1,10 +0,0 @@
1
- import type { DatabaseSync } from "node:sqlite";
2
- import type { SqliteDriver, SqliteStatement } from "./sqlite-driver";
3
- export declare class NodeSqliteDriver implements SqliteDriver {
4
- private readonly database;
5
- constructor(database: DatabaseSync);
6
- run(sql: string): void;
7
- query<Row>(sql: string): SqliteStatement<Row>;
8
- close(): void;
9
- }
10
- //# sourceMappingURL=node-driver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node-driver.d.ts","sourceRoot":"","sources":["../src/node-driver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAiB,MAAM,aAAa,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAoB,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvF,qBAAa,gBAAiB,YAAW,YAAY;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,YAAY;IAEnD,GAAG,CAAC,GAAG,EAAE,MAAM;IAIf,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC;IAkB7C,KAAK;CAGN"}
@@ -1,18 +0,0 @@
1
- import { SqliteTaskQueue } from "./sqlite-task-queue";
2
- import { SqliteTimers } from "./sqlite-timers";
3
- import type { EventProcessor } from "@yieldstar/core";
4
- import type { Logger } from "pino";
5
- import type { SqliteDriver } from "./sqlite-driver";
6
- export declare class SqliteEventLoop {
7
- taskQueue: SqliteTaskQueue;
8
- timers: SqliteTimers;
9
- private isRunning;
10
- constructor(db: SqliteDriver);
11
- start(params: {
12
- onNewEvent: EventProcessor;
13
- logger: Logger;
14
- }): void;
15
- stop(): void;
16
- private loop;
17
- }
18
- //# sourceMappingURL=sqlite-event-loop.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sqlite-event-loop.d.ts","sourceRoot":"","sources":["../src/sqlite-event-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,qBAAa,eAAe;IAC1B,SAAS,EAAE,eAAe,CAAC;IAC3B,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,CAAC,SAAS,CAAkB;gBAEvB,EAAE,EAAE,YAAY;IAK5B,KAAK,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IAK5D,IAAI;YAIU,IAAI;CAenB"}
@@ -1,13 +0,0 @@
1
- import type { SchedulerClient, WorkflowEvent } from "@yieldstar/core";
2
- import { SqliteTaskQueueClient } from "./sqlite-task-queue";
3
- import { SqliteTimersClient } from "./sqlite-timers";
4
- export declare class SqliteSchedulerClient implements SchedulerClient {
5
- private taskQueue;
6
- private timersClient;
7
- constructor(params: {
8
- taskQueueClient: SqliteTaskQueueClient;
9
- timersClient: SqliteTimersClient;
10
- });
11
- requestWakeUp(event: WorkflowEvent, resumeIn?: number): Promise<void>;
12
- }
13
- //# sourceMappingURL=sqlite-scheduler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sqlite-scheduler.d.ts","sourceRoot":"","sources":["../src/sqlite-scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,qBAAa,qBAAsB,YAAW,eAAe;IAC3D,OAAO,CAAC,SAAS,CAAwB;IACzC,OAAO,CAAC,YAAY,CAAqB;gBAE7B,MAAM,EAAE;QAClB,eAAe,EAAE,qBAAqB,CAAC;QACvC,YAAY,EAAE,kBAAkB,CAAC;KAClC;IAKK,aAAa,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,MAAM;CAO5D"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=sqlite-store.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sqlite-store.test.d.ts","sourceRoot":"","sources":["../src/sqlite-store.test.ts"],"names":[],"mappings":""}
@@ -1,26 +0,0 @@
1
- import type { WorkflowEvent } from "@yieldstar/core";
2
- import type { SqliteDriver } from "./sqlite-driver";
3
- export declare class SqliteTaskQueue {
4
- private taskQueueDao;
5
- constructor(db: SqliteDriver);
6
- add(event: WorkflowEvent): void;
7
- process(): {
8
- taskId: number;
9
- visibilityTimeout: number;
10
- event: {
11
- workflowId: string;
12
- executionId: string;
13
- params: any;
14
- context: Map<any, any>;
15
- };
16
- } | undefined;
17
- remove(taskId: number): void;
18
- makeVisible(taskId: number): void;
19
- get isEmpty(): boolean;
20
- }
21
- export declare class SqliteTaskQueueClient {
22
- private taskQueueDao;
23
- constructor(db: SqliteDriver);
24
- add(event: WorkflowEvent): void;
25
- }
26
- //# sourceMappingURL=sqlite-task-queue.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sqlite-task-queue.d.ts","sourceRoot":"","sources":["../src/sqlite-task-queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAIpD,qBAAa,eAAe;IAC1B,OAAO,CAAC,YAAY,CAAe;gBAEvB,EAAE,EAAE,YAAY;IAK5B,GAAG,CAAC,KAAK,EAAE,aAAa;IAIxB,OAAO;;;;;;;;;;IAsBP,MAAM,CAAC,MAAM,EAAE,MAAM;IAIrB,WAAW,CAAC,MAAM,EAAE,MAAM;IAI1B,IAAI,OAAO,IAAI,OAAO,CAErB;CACF;AAED,qBAAa,qBAAqB;IAChC,OAAO,CAAC,YAAY,CAAe;gBAEvB,EAAE,EAAE,YAAY;IAI5B,GAAG,CAAC,KAAK,EAAE,aAAa;CAGzB"}
@@ -1,18 +0,0 @@
1
- import { SqliteTaskQueue } from "./sqlite-task-queue";
2
- import type { WorkflowEvent } from "@yieldstar/core";
3
- import type { SqliteDriver } from "./sqlite-driver";
4
- export declare class SqliteTimers {
5
- private timersDao;
6
- private taskQueue;
7
- constructor(params: {
8
- db: SqliteDriver;
9
- taskQueue: SqliteTaskQueue;
10
- });
11
- processTimers(): void;
12
- }
13
- export declare class SqliteTimersClient {
14
- private timersDao;
15
- constructor(db: SqliteDriver);
16
- createTimer(event: WorkflowEvent, delay: number): void;
17
- }
18
- //# sourceMappingURL=sqlite-timers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sqlite-timers.d.ts","sourceRoot":"","sources":["../src/sqlite-timers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,qBAAa,YAAY;IACvB,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,SAAS,CAAkB;gBAEvB,MAAM,EAAE;QAAE,EAAE,EAAE,YAAY,CAAC;QAAC,SAAS,EAAE,eAAe,CAAA;KAAE;IAKpE,aAAa;CAYd;AAED,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,SAAS,CAAY;gBAEjB,EAAE,EAAE,YAAY;IAI5B,WAAW,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM;CAGhD"}
@@ -1,79 +0,0 @@
1
- import type { WorkflowEvent } from "@yieldstar/core";
2
- import type { SqliteDriver } from "../sqlite-driver";
3
-
4
- class TaskRow {
5
- task_id!: number;
6
- workflow_id!: string;
7
- execution_id!: string;
8
- params?: string;
9
- context?: string;
10
- }
11
-
12
- class CountRow {
13
- count!: number;
14
- }
15
-
16
- export class TaskQueueDao {
17
- private db: SqliteDriver;
18
-
19
- constructor(db: SqliteDriver) {
20
- this.db = db;
21
- }
22
-
23
- setupDb() {
24
- this.db.run(`
25
- CREATE TABLE IF NOT EXISTS task_queue (
26
- task_id INTEGER PRIMARY KEY AUTOINCREMENT,
27
- workflow_id TEXT NOT NULL,
28
- execution_id TEXT NOT NULL,
29
- params TEXT,
30
- context TEXT,
31
- visible_from INTEGER DEFAULT (strftime('%s', 'now'))
32
- )
33
- `);
34
- }
35
-
36
- insertTask(event: WorkflowEvent) {
37
- const query = this.db.query(
38
- `INSERT INTO task_queue (workflow_id, execution_id, params, context)
39
- VALUES ($workflowId, $executionId, $params, $context)`
40
- );
41
-
42
- query.run({
43
- $workflowId: event.workflowId,
44
- $executionId: event.executionId,
45
- $params: event.params ? JSON.stringify(event.params) : null,
46
- $context: event.context
47
- ? JSON.stringify(Array.from(event.context.entries()))
48
- : null,
49
- });
50
- }
51
-
52
- getNextTask() {
53
- const query = this.db.query<TaskRow>(
54
- `SELECT * FROM task_queue WHERE visible_from < strftime('%s', 'now') ORDER BY task_id LIMIT 1`
55
- );
56
- return query.get();
57
- }
58
-
59
- updateTaskVisibility(taskId: number, visibleFrom: number) {
60
- const query = this.db.query(
61
- "UPDATE task_queue SET visible_from = $visibleFrom WHERE task_id = $taskId"
62
- );
63
- query.run({ $taskId: taskId, $visibleFrom: visibleFrom });
64
- }
65
-
66
- deleteTaskById(id: number) {
67
- const query = this.db.query(
68
- `DELETE FROM task_queue WHERE task_id = $taskId`
69
- );
70
- query.run({ $taskId: id });
71
- }
72
-
73
- getTaskCount() {
74
- const query = this.db.query<CountRow>(
75
- `SELECT COUNT(*) as count FROM task_queue WHERE visible_from < strftime('%s', 'now')`
76
- );
77
- return query.get()!.count;
78
- }
79
- }
@@ -1,81 +0,0 @@
1
- import type { WorkflowEvent } from "@yieldstar/core";
2
- import type { SqliteDriver } from "../sqlite-driver";
3
-
4
- class TimerRow {
5
- id!: string;
6
- delay!: number;
7
- workflow_id!: string;
8
- execution_id!: string;
9
- created_at!: number;
10
- params?: string;
11
- context?: string;
12
- }
13
-
14
- class CountRow {
15
- count!: number;
16
- }
17
-
18
- export class TimersDao {
19
- private db: SqliteDriver;
20
-
21
- constructor(db: SqliteDriver) {
22
- this.db = db;
23
- this.setupDb();
24
- }
25
-
26
- private setupDb() {
27
- this.db.run(`
28
- CREATE TABLE IF NOT EXISTS scheduled_tasks (
29
- id INTEGER PRIMARY KEY AUTOINCREMENT,
30
- delay INTEGER NOT NULL,
31
- workflow_id TEXT NOT NULL,
32
- execution_id TEXT NOT NULL,
33
- created_at INTEGER NOT NULL,
34
- params TEXT,
35
- context TEXT
36
- );
37
- `);
38
- }
39
-
40
- getExpiredTimers(): TimerRow[] {
41
- const query = this.db.query<TimerRow>(
42
- `SELECT id, delay, workflow_id, execution_id, created_at, params, context
43
- FROM scheduled_tasks
44
- WHERE (created_at + delay) < $currentTime`
45
- );
46
-
47
- return query.all({ $currentTime: Date.now() });
48
- }
49
-
50
- getTaskCount() {
51
- const query = this.db.query<CountRow>(
52
- `SELECT COUNT(*) as count
53
- FROM scheduled_tasks
54
- WHERE (created_at + delay) < $currentTime`
55
- );
56
-
57
- const count = query.get({ $currentTime: Date.now() })!;
58
- return count.count;
59
- }
60
-
61
- insertTimer(event: WorkflowEvent, delay: number) {
62
- const query = this.db.query(
63
- `INSERT INTO scheduled_tasks (delay, workflow_id, execution_id, created_at, params, context)
64
- VALUES ($delay, $workflowId, $executionId, $createdAt, $params, $context)`
65
- );
66
-
67
- query.run({
68
- $delay: delay,
69
- $workflowId: event.workflowId,
70
- $executionId: event.executionId,
71
- $createdAt: Date.now(),
72
- $params: event.params ? JSON.stringify(event.params) : null,
73
- $context: JSON.stringify(Array.from(event.context.entries())),
74
- });
75
- }
76
-
77
- deleteTimerById(id: string) {
78
- const query = this.db.query(`DELETE FROM scheduled_tasks WHERE id = $id`);
79
- query.run({ $id: id });
80
- }
81
- }
@@ -1,41 +0,0 @@
1
- import { SqliteTaskQueue } from "./sqlite-task-queue";
2
- import { SqliteTimers } from "./sqlite-timers";
3
- import type { EventProcessor } from "@yieldstar/core";
4
- import type { Logger } from "pino";
5
- import type { SqliteDriver } from "./sqlite-driver";
6
-
7
- export class SqliteEventLoop {
8
- taskQueue: SqliteTaskQueue;
9
- timers: SqliteTimers;
10
- private isRunning: boolean = false;
11
-
12
- constructor(db: SqliteDriver) {
13
- this.taskQueue = new SqliteTaskQueue(db);
14
- this.timers = new SqliteTimers({ db, taskQueue: this.taskQueue });
15
- }
16
-
17
- start(params: { onNewEvent: EventProcessor; logger: Logger }) {
18
- this.isRunning = true;
19
- this.loop(params.onNewEvent, params.logger);
20
- }
21
-
22
- stop() {
23
- this.isRunning = false;
24
- }
25
-
26
- private async loop(processEvent: EventProcessor, logger: Logger) {
27
- if (!this.isRunning) return;
28
-
29
- while (!this.taskQueue.isEmpty) {
30
- const task = this.taskQueue.process();
31
- if (task) {
32
- await processEvent(task.event, logger);
33
- this.taskQueue.remove(task.taskId);
34
- }
35
- }
36
-
37
- this.timers.processTimers();
38
-
39
- setTimeout(() => this.loop(processEvent, logger), 10);
40
- }
41
- }
@@ -1,24 +0,0 @@
1
- import type { SchedulerClient, WorkflowEvent } from "@yieldstar/core";
2
- import { SqliteTaskQueueClient } from "./sqlite-task-queue";
3
- import { SqliteTimersClient } from "./sqlite-timers";
4
-
5
- export class SqliteSchedulerClient implements SchedulerClient {
6
- private taskQueue: SqliteTaskQueueClient;
7
- private timersClient: SqliteTimersClient;
8
-
9
- constructor(params: {
10
- taskQueueClient: SqliteTaskQueueClient;
11
- timersClient: SqliteTimersClient;
12
- }) {
13
- this.taskQueue = params.taskQueueClient;
14
- this.timersClient = params.timersClient;
15
- }
16
-
17
- async requestWakeUp(event: WorkflowEvent, resumeIn?: number) {
18
- if (resumeIn) {
19
- this.timersClient.createTimer(event, resumeIn);
20
- } else {
21
- this.taskQueue.add(event);
22
- }
23
- }
24
- }
@@ -1,64 +0,0 @@
1
- import type { WorkflowEvent } from "@yieldstar/core";
2
- import { TaskQueueDao } from "./dao/task-queue-dao";
3
- import type { SqliteDriver } from "./sqlite-driver";
4
-
5
- const VISIBILITY_WINDOW = 300000;
6
-
7
- export class SqliteTaskQueue {
8
- private taskQueueDao: TaskQueueDao;
9
-
10
- constructor(db: SqliteDriver) {
11
- this.taskQueueDao = new TaskQueueDao(db);
12
- this.taskQueueDao.setupDb();
13
- }
14
-
15
- add(event: WorkflowEvent) {
16
- this.taskQueueDao.insertTask(event);
17
- }
18
-
19
- process() {
20
- const row = this.taskQueueDao.getNextTask();
21
-
22
- if (!row) return undefined;
23
-
24
- const now = Date.now();
25
- const visibilityTimeout = now + VISIBILITY_WINDOW;
26
-
27
- this.taskQueueDao.updateTaskVisibility(row.task_id, visibilityTimeout);
28
-
29
- return {
30
- taskId: row.task_id,
31
- visibilityTimeout,
32
- event: {
33
- workflowId: row.workflow_id,
34
- executionId: row.execution_id,
35
- params: row.params ? JSON.parse(row.params) : undefined,
36
- context: row.context ? new Map(JSON.parse(row.context)) : new Map(),
37
- },
38
- };
39
- }
40
-
41
- remove(taskId: number) {
42
- this.taskQueueDao.deleteTaskById(taskId);
43
- }
44
-
45
- makeVisible(taskId: number) {
46
- this.taskQueueDao.updateTaskVisibility(taskId, 0);
47
- }
48
-
49
- get isEmpty(): boolean {
50
- return this.taskQueueDao.getTaskCount() === 0;
51
- }
52
- }
53
-
54
- export class SqliteTaskQueueClient {
55
- private taskQueueDao: TaskQueueDao;
56
-
57
- constructor(db: SqliteDriver) {
58
- this.taskQueueDao = new TaskQueueDao(db);
59
- }
60
-
61
- add(event: WorkflowEvent) {
62
- this.taskQueueDao.insertTask(event);
63
- }
64
- }
@@ -1,40 +0,0 @@
1
- import { TimersDao } from "./dao/timers-dao";
2
- import { SqliteTaskQueue } from "./sqlite-task-queue";
3
- import { FreezableMap } from "@yieldstar/core";
4
- import type { WorkflowEvent } from "@yieldstar/core";
5
- import type { SqliteDriver } from "./sqlite-driver";
6
-
7
- export class SqliteTimers {
8
- private timersDao: TimersDao;
9
- private taskQueue: SqliteTaskQueue;
10
-
11
- constructor(params: { db: SqliteDriver; taskQueue: SqliteTaskQueue }) {
12
- this.timersDao = new TimersDao(params.db);
13
- this.taskQueue = params.taskQueue;
14
- }
15
-
16
- processTimers() {
17
- const timers = this.timersDao.getExpiredTimers();
18
- for (const timer of timers) {
19
- this.timersDao.deleteTimerById(timer.id);
20
- this.taskQueue.add({
21
- workflowId: timer.workflow_id,
22
- executionId: timer.execution_id,
23
- params: timer.params ? JSON.parse(timer.params) : undefined,
24
- context: timer.context ? new Map(JSON.parse(timer.context)) : new Map(),
25
- });
26
- }
27
- }
28
- }
29
-
30
- export class SqliteTimersClient {
31
- private timersDao: TimersDao;
32
-
33
- constructor(db: SqliteDriver) {
34
- this.timersDao = new TimersDao(db);
35
- }
36
-
37
- createTimer(event: WorkflowEvent, delay: number) {
38
- this.timersDao.insertTimer(event, delay);
39
- }
40
- }