@workglow/storage 0.0.52

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 (74) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +1015 -0
  3. package/dist/browser.js +2635 -0
  4. package/dist/browser.js.map +27 -0
  5. package/dist/bun.js +3880 -0
  6. package/dist/bun.js.map +35 -0
  7. package/dist/common-server.d.ts +23 -0
  8. package/dist/common-server.d.ts.map +1 -0
  9. package/dist/common.d.ts +16 -0
  10. package/dist/common.d.ts.map +1 -0
  11. package/dist/kv/FsFolderJsonKvRepository.d.ts +27 -0
  12. package/dist/kv/FsFolderJsonKvRepository.d.ts.map +1 -0
  13. package/dist/kv/FsFolderKvRepository.d.ts +74 -0
  14. package/dist/kv/FsFolderKvRepository.d.ts.map +1 -0
  15. package/dist/kv/IKvRepository.d.ts +65 -0
  16. package/dist/kv/IKvRepository.d.ts.map +1 -0
  17. package/dist/kv/InMemoryKvRepository.d.ts +26 -0
  18. package/dist/kv/InMemoryKvRepository.d.ts.map +1 -0
  19. package/dist/kv/IndexedDbKvRepository.d.ts +27 -0
  20. package/dist/kv/IndexedDbKvRepository.d.ts.map +1 -0
  21. package/dist/kv/KvRepository.d.ts +109 -0
  22. package/dist/kv/KvRepository.d.ts.map +1 -0
  23. package/dist/kv/KvViaTabularRepository.d.ts +64 -0
  24. package/dist/kv/KvViaTabularRepository.d.ts.map +1 -0
  25. package/dist/kv/PostgresKvRepository.d.ts +28 -0
  26. package/dist/kv/PostgresKvRepository.d.ts.map +1 -0
  27. package/dist/kv/SqliteKvRepository.d.ts +28 -0
  28. package/dist/kv/SqliteKvRepository.d.ts.map +1 -0
  29. package/dist/kv/SupabaseKvRepository.d.ts +34 -0
  30. package/dist/kv/SupabaseKvRepository.d.ts.map +1 -0
  31. package/dist/node.js +3879 -0
  32. package/dist/node.js.map +35 -0
  33. package/dist/queue/IQueueStorage.d.ts +125 -0
  34. package/dist/queue/IQueueStorage.d.ts.map +1 -0
  35. package/dist/queue/InMemoryQueueStorage.d.ts +109 -0
  36. package/dist/queue/InMemoryQueueStorage.d.ts.map +1 -0
  37. package/dist/queue/IndexedDbQueueStorage.d.ts +89 -0
  38. package/dist/queue/IndexedDbQueueStorage.d.ts.map +1 -0
  39. package/dist/queue/PostgresQueueStorage.d.ts +92 -0
  40. package/dist/queue/PostgresQueueStorage.d.ts.map +1 -0
  41. package/dist/queue/SqliteQueueStorage.d.ts +116 -0
  42. package/dist/queue/SqliteQueueStorage.d.ts.map +1 -0
  43. package/dist/queue/SupabaseQueueStorage.d.ts +93 -0
  44. package/dist/queue/SupabaseQueueStorage.d.ts.map +1 -0
  45. package/dist/tabular/BaseSqlTabularRepository.d.ts +94 -0
  46. package/dist/tabular/BaseSqlTabularRepository.d.ts.map +1 -0
  47. package/dist/tabular/CachedTabularRepository.d.ts +110 -0
  48. package/dist/tabular/CachedTabularRepository.d.ts.map +1 -0
  49. package/dist/tabular/FsFolderTabularRepository.d.ts +92 -0
  50. package/dist/tabular/FsFolderTabularRepository.d.ts.map +1 -0
  51. package/dist/tabular/ITabularRepository.d.ts +52 -0
  52. package/dist/tabular/ITabularRepository.d.ts.map +1 -0
  53. package/dist/tabular/InMemoryTabularRepository.d.ts +93 -0
  54. package/dist/tabular/InMemoryTabularRepository.d.ts.map +1 -0
  55. package/dist/tabular/IndexedDbTabularRepository.d.ts +100 -0
  56. package/dist/tabular/IndexedDbTabularRepository.d.ts.map +1 -0
  57. package/dist/tabular/PostgresTabularRepository.d.ts +133 -0
  58. package/dist/tabular/PostgresTabularRepository.d.ts.map +1 -0
  59. package/dist/tabular/SharedInMemoryTabularRepository.d.ts +126 -0
  60. package/dist/tabular/SharedInMemoryTabularRepository.d.ts.map +1 -0
  61. package/dist/tabular/SqliteTabularRepository.d.ts +110 -0
  62. package/dist/tabular/SqliteTabularRepository.d.ts.map +1 -0
  63. package/dist/tabular/SupabaseTabularRepository.d.ts +132 -0
  64. package/dist/tabular/SupabaseTabularRepository.d.ts.map +1 -0
  65. package/dist/tabular/TabularRepository.d.ts +123 -0
  66. package/dist/tabular/TabularRepository.d.ts.map +1 -0
  67. package/dist/types.d.ts +7 -0
  68. package/dist/types.d.ts.map +1 -0
  69. package/dist/util/IndexedDbTable.d.ts +40 -0
  70. package/dist/util/IndexedDbTable.d.ts.map +1 -0
  71. package/package.json +60 -0
  72. package/src/kv/README.md +159 -0
  73. package/src/queue/README.md +41 -0
  74. package/src/tabular/README.md +298 -0
@@ -0,0 +1,125 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export declare const QUEUE_STORAGE: import("@workglow/util").ServiceToken<IQueueStorage<any, any>>;
7
+ export declare enum JobStatus {
8
+ PENDING = "PENDING",
9
+ PROCESSING = "PROCESSING",
10
+ COMPLETED = "COMPLETED",
11
+ ABORTING = "ABORTING",
12
+ FAILED = "FAILED",
13
+ DISABLED = "DISABLED"
14
+ }
15
+ /**
16
+ * Details about a job that reflect the structure in the database.
17
+ */
18
+ export type JobStorageFormat<Input, Output> = {
19
+ id?: unknown;
20
+ job_run_id?: string;
21
+ queue?: string;
22
+ input: Input;
23
+ output?: Output | null;
24
+ error?: string | null;
25
+ error_code?: string | null;
26
+ fingerprint?: string;
27
+ max_retries?: number;
28
+ status?: JobStatus;
29
+ created_at?: string;
30
+ deadline_at?: string | null;
31
+ last_ran_at?: string | null;
32
+ run_after: string | null;
33
+ completed_at: string | null;
34
+ run_attempts?: number;
35
+ progress?: number;
36
+ progress_message?: string;
37
+ progress_details?: Record<string, any> | null;
38
+ };
39
+ /**
40
+ * Interface defining the storage operations for a job queue
41
+ */
42
+ export interface IQueueStorage<Input, Output> {
43
+ /**
44
+ * Adds a job to the queue storage
45
+ * @param job - The job to add to the queue storage
46
+ * @returns The ID of the job
47
+ */
48
+ add(job: JobStorageFormat<Input, Output>): Promise<unknown>;
49
+ /**
50
+ * Gets a job from the queue storage by ID
51
+ * @param id - The ID of the job to get
52
+ * @returns The job with the given ID
53
+ */
54
+ get(id: unknown): Promise<JobStorageFormat<Input, Output> | undefined>;
55
+ /**
56
+ * Gets the next job from the queue storage
57
+ * @returns The next job from the queue storage
58
+ */
59
+ next(): Promise<JobStorageFormat<Input, Output> | undefined>;
60
+ /**
61
+ * Peeks at the next job(s) from the queue storage without removing them
62
+ * @param status - The status of the jobs to peek at
63
+ * @param num - The number of jobs to peek at
64
+ * @returns The jobs with the given status
65
+ */
66
+ peek(status?: JobStatus, num?: number): Promise<Array<JobStorageFormat<Input, Output>>>;
67
+ /**
68
+ * Gets the size of the queue storage
69
+ * @param status - The status of the jobs to get the size for
70
+ * @returns The size of the queue storage
71
+ */
72
+ size(status?: JobStatus): Promise<number>;
73
+ /**
74
+ * Completes a job in the queue storage
75
+ * @param job - The job to complete
76
+ */
77
+ complete(job: JobStorageFormat<Input, Output>): Promise<void>;
78
+ /**
79
+ * Deletes all jobs from the queue storage
80
+ */
81
+ deleteAll(): Promise<void>;
82
+ /**
83
+ * Gets the output for a given input from the queue storage
84
+ * @param input - The input to get the output for
85
+ * @returns The output of the job
86
+ */
87
+ outputForInput(input: Input): Promise<Output | null>;
88
+ /**
89
+ * Aborts a job in the queue storage
90
+ * @param id - The ID of the job to abort
91
+ */
92
+ abort(id: unknown): Promise<void>;
93
+ /**
94
+ * Gets the jobs by job run ID from the queue storage
95
+ * @param runId - The job run ID of the jobs to get
96
+ * @returns The jobs with the given job run ID
97
+ */
98
+ getByRunId(runId: string): Promise<Array<JobStorageFormat<Input, Output>>>;
99
+ /**
100
+ * Saves progress updates for a job in the queue storage
101
+ * @param id - The ID of the job to save the progress for
102
+ * @param progress - The progress of the job
103
+ * @param message - The message of the job
104
+ * @param details - The details of the job
105
+ */
106
+ saveProgress(id: unknown, progress: number, message: string, details: Record<string, any> | null): Promise<void>;
107
+ /**
108
+ * Deletes a job by its ID from the queue storage
109
+ * @param id - The ID of the job to delete
110
+ */
111
+ delete(id: unknown): Promise<void>;
112
+ /**
113
+ * Deletes jobs from the queue storage that are of a specific status and older than the specified time
114
+ * @param status - The status of the jobs to delete
115
+ * @param olderThanMs - The time in milliseconds that the jobs must be older than to be deleted
116
+ */
117
+ deleteJobsByStatusAndAge(status: JobStatus, olderThanMs: number): Promise<void>;
118
+ /**
119
+ * Sets up the database schema and tables.
120
+ * This method should be called before using the storage in tests.
121
+ * For production use, database setup should be done via migrations.
122
+ */
123
+ setupDatabase(): Promise<void>;
124
+ }
125
+ //# sourceMappingURL=IQueueStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IQueueStorage.d.ts","sourceRoot":"","sources":["../../src/queue/IQueueStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,eAAO,MAAM,aAAa,gEAAkE,CAAC;AAE7F,oBAAY,SAAS;IACnB,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,MAAM,WAAW;IACjB,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,KAAK,EAAE,MAAM,IAAI;IAC5C,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,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,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAErD;;;OAGG;IACH,KAAK,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElC;;;;OAIG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAE3E;;;;;;OAMG;IACH,YAAY,CACV,EAAE,EAAE,OAAO,EACX,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAClC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB;;;OAGG;IACH,MAAM,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnC;;;;OAIG;IACH,wBAAwB,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhF;;;;OAIG;IACH,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { IQueueStorage, JobStatus, JobStorageFormat } from "./IQueueStorage";
7
+ export declare const IN_MEMORY_QUEUE_STORAGE: import("@workglow/util").ServiceToken<IQueueStorage<any, any>>;
8
+ /**
9
+ * In-memory implementation of a job queue that manages asynchronous tasks.
10
+ * Supports job scheduling, status tracking, and result caching.
11
+ */
12
+ export declare class InMemoryQueueStorage<Input, Output> implements IQueueStorage<Input, Output> {
13
+ readonly queueName: string;
14
+ /**
15
+ * Creates a new in-memory job queue
16
+ * @param queue - Name of the queue
17
+ */
18
+ constructor(queueName: string);
19
+ /** Internal array storing all jobs */
20
+ jobQueue: JobStorageFormat<Input, Output>[];
21
+ /**
22
+ * Returns a filtered and sorted list of pending jobs that are ready to run
23
+ * Sorts by creation time to maintain FIFO order
24
+ */
25
+ private pendingQueue;
26
+ /**
27
+ * Adds a new job to the queue
28
+ * Generates an ID and fingerprint if not provided
29
+ */
30
+ add(job: JobStorageFormat<Input, Output>): Promise<unknown>;
31
+ /**
32
+ * Retrieves a job from the queue by its id.
33
+ * @param id - The id of the job to retrieve.
34
+ * @returns A promise that resolves to the job or undefined if the job is not found.
35
+ */
36
+ get(id: unknown): Promise<JobStorageFormat<Input, Output> | undefined>;
37
+ /**
38
+ * Retrieves a slice of jobs from anywherethe queue.
39
+ * @param status - The status of the jobs to retrieve.
40
+ * @param num - The number of jobs to retrieve.
41
+ * @returns A promise that resolves to an array of jobs.
42
+ */
43
+ peek(status?: JobStatus, num?: number): Promise<JobStorageFormat<Input, Output>[]>;
44
+ /**
45
+ * Retrieves the next available job that is ready to be processed
46
+ * Updates the job status to PROCESSING before returning
47
+ */
48
+ next(): Promise<JobStorageFormat<Input, Output> | undefined>;
49
+ /**
50
+ * Retrieves the size of the queue for a given status
51
+ * @param status - The status of the jobs to retrieve.
52
+ * @returns A promise that resolves to the number of jobs.
53
+ */
54
+ size(status?: JobStatus): Promise<number>;
55
+ /**
56
+ * Saves the progress of a job
57
+ * @param jobId - The id of the job to save the progress for.
58
+ * @param progress - The progress of the job.
59
+ * @param message - The message of the job.
60
+ * @param details - The details of the job.
61
+ */
62
+ saveProgress(id: unknown, progress: number, message: string, details: Record<string, any> | null): Promise<void>;
63
+ /**
64
+ * Marks a job as complete with its output or error
65
+ * Handles run_attempts for failed jobs and triggers completion callbacks
66
+ * @param id - ID of the job to complete
67
+ * @param output - Result of the job execution
68
+ * @param error - Optional error message if job failed
69
+ */
70
+ complete(job: JobStorageFormat<Input, Output>): Promise<void>;
71
+ /**
72
+ * Aborts a job
73
+ * @param id - The id of the job to abort.
74
+ */
75
+ abort(id: unknown): Promise<void>;
76
+ /**
77
+ * Retrieves all jobs by their job_run_id.
78
+ * @param job_run_id - The job_run_id of the jobs to retrieve.
79
+ * @returns A promise that resolves to an array of jobs.
80
+ */
81
+ getByRunId(runId: string): Promise<Array<JobStorageFormat<Input, Output>>>;
82
+ /**
83
+ * Deletes all jobs from the queue.
84
+ */
85
+ deleteAll(): Promise<void>;
86
+ /**
87
+ * Looks up cached output for a given and input
88
+ * Uses input fingerprinting for efficient matching
89
+ * @param input - The input to look up the cached output for.
90
+ * @returns The cached output or null if not found
91
+ */
92
+ outputForInput(input: Input): Promise<NonNullable<Output> | null>;
93
+ /**
94
+ * Deletes a job by its ID
95
+ */
96
+ delete(id: unknown): Promise<void>;
97
+ /**
98
+ * Delete jobs with a specific status older than a cutoff date
99
+ * @param status - Status of jobs to delete
100
+ * @param olderThanMs - Delete jobs completed more than this many milliseconds ago
101
+ */
102
+ deleteJobsByStatusAndAge(status: JobStatus, olderThanMs: number): Promise<void>;
103
+ /**
104
+ * Sets up the database schema and tables.
105
+ * No-op for in-memory storage as it doesn't require database setup.
106
+ */
107
+ setupDatabase(): Promise<void>;
108
+ }
109
+ //# sourceMappingURL=InMemoryQueueStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryQueueStorage.d.ts","sourceRoot":"","sources":["../../src/queue/InMemoryQueueStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAE7E,eAAO,MAAM,uBAAuB,gEAEnC,CAAC;AAEF;;;GAGG;AACH,qBAAa,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAE,YAAW,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC;aAK1D,SAAS,EAAE,MAAM;IAJ7C;;;OAGG;gBACyB,SAAS,EAAE,MAAM;IAI7C,sCAAsC;IAC/B,QAAQ,EAAE,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC;I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
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { MigrationOptions } from "../util/IndexedDbTable";
7
+ import { IQueueStorage, JobStatus, JobStorageFormat } from "./IQueueStorage";
8
+ export declare const INDEXED_DB_QUEUE_STORAGE: import("@workglow/util").ServiceToken<IQueueStorage<any, any>>;
9
+ /**
10
+ * IndexedDB implementation of a job queue storage.
11
+ * Provides storage and retrieval for job execution states using IndexedDB.
12
+ */
13
+ export declare class IndexedDbQueueStorage<Input, Output> implements IQueueStorage<Input, Output> {
14
+ readonly queueName: string;
15
+ private db;
16
+ private tableName;
17
+ private migrationOptions;
18
+ constructor(queueName: string, migrationOptions?: MigrationOptions);
19
+ private getDb;
20
+ /**
21
+ * Sets up the IndexedDB database table with the required schema and indexes.
22
+ * Must be called before using any other methods.
23
+ */
24
+ setupDatabase(): Promise<void>;
25
+ /**
26
+ * Adds a job to the queue.
27
+ * @param job - The job to add to the queue.
28
+ * @returns A promise that resolves to the job id.
29
+ */
30
+ add(job: JobStorageFormat<Input, Output>): Promise<unknown>;
31
+ /**
32
+ * Retrieves a job from the queue by its id.
33
+ * @param id - The id of the job to retrieve.
34
+ * @returns A promise that resolves to the job or undefined if the job is not found.
35
+ */
36
+ get(id: unknown): Promise<JobStorageFormat<Input, Output> | undefined>;
37
+ /**
38
+ * Retrieves a slice of jobs from the queue.
39
+ * @param status - The status of the jobs to retrieve.
40
+ * @param num - The number of jobs to retrieve.
41
+ * @returns A promise that resolves to an array of jobs.
42
+ */
43
+ peek(status?: JobStatus, num?: number): Promise<JobStorageFormat<Input, Output>[]>;
44
+ /**
45
+ * Retrieves the next job from the queue.
46
+ * @returns A promise that resolves to the next job or undefined if the queue is empty.
47
+ */
48
+ next(): Promise<JobStorageFormat<Input, Output> | undefined>;
49
+ /**
50
+ * Retrieves the number of jobs in the queue.
51
+ * Returns the count of jobs in the queue.
52
+ */
53
+ size(status?: JobStatus): Promise<number>;
54
+ /**
55
+ * Marks a job as complete with its output or error.
56
+ */
57
+ complete(job: JobStorageFormat<Input, Output>): Promise<void>;
58
+ /**
59
+ * Aborts a job in the queue.
60
+ */
61
+ abort(id: unknown): Promise<void>;
62
+ /**
63
+ * Gets jobs by their run ID.
64
+ */
65
+ getByRunId(job_run_id: string): Promise<JobStorageFormat<Input, Output>[]>;
66
+ /**
67
+ * Deletes all jobs from the queue.
68
+ */
69
+ deleteAll(): Promise<void>;
70
+ /**
71
+ * Gets the output for a given input.
72
+ */
73
+ outputForInput(input: Input): Promise<Output | null>;
74
+ /**
75
+ * Saves progress updates for a job.
76
+ */
77
+ saveProgress(id: unknown, progress: number, message: string, details: Record<string, any> | null): Promise<void>;
78
+ /**
79
+ * Deletes a job by its ID.
80
+ */
81
+ delete(id: unknown): Promise<void>;
82
+ /**
83
+ * Delete jobs with a specific status older than a cutoff date
84
+ * @param status - Status of jobs to delete
85
+ * @param olderThanMs - Delete jobs completed more than this many milliseconds ago
86
+ */
87
+ deleteJobsByStatusAndAge(status: JobStatus, olderThanMs: number): Promise<void>;
88
+ }
89
+ //# sourceMappingURL=IndexedDbQueueStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IndexedDbQueueStorage.d.ts","sourceRoot":"","sources":["../../src/queue/IndexedDbQueueStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAGH,gBAAgB,EACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAE7E,eAAO,MAAM,wBAAwB,gEAEpC,CAAC;AAEF;;;GAGG;AACH,qBAAa,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAE,YAAW,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC;aAMrE,SAAS,EAAE,MAAM;IALnC,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,gBAAgB,CAAmB;gBAGzB,SAAS,EAAE,MAAM,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EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAClC,OAAO,CAAC,IAAI,CAAC;IAWhB;;OAEG;IACU,MAAM,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAa/C;;;;OAIG;IACU,wBAAwB,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CA0B7F"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Pool } from "pg";
7
+ import { IQueueStorage, JobStatus, JobStorageFormat } from "./IQueueStorage";
8
+ export declare const POSTGRES_QUEUE_STORAGE: import("@workglow/util").ServiceToken<IQueueStorage<any, any>>;
9
+ /**
10
+ * PostgreSQL implementation of a job queue.
11
+ * Provides storage and retrieval for job execution states using PostgreSQL.
12
+ */
13
+ export declare class PostgresQueueStorage<Input, Output> implements IQueueStorage<Input, Output> {
14
+ protected readonly db: Pool;
15
+ protected readonly queueName: string;
16
+ constructor(db: Pool, queueName: string);
17
+ setupDatabase(): Promise<void>;
18
+ /**
19
+ * Adds a new job to the queue.
20
+ * @param job - The job to add
21
+ * @returns The ID of the added job
22
+ */
23
+ add(job: JobStorageFormat<Input, Output>): Promise<unknown>;
24
+ /**
25
+ * Retrieves a job by its ID.
26
+ * @param id - The ID of the job to retrieve
27
+ * @returns The job if found, undefined otherwise
28
+ */
29
+ get(id: number): Promise<any>;
30
+ /**
31
+ * Retrieves a slice of jobs from the queue.
32
+ * @param num - Maximum number of jobs to return
33
+ * @returns An array of jobs
34
+ */
35
+ peek(status?: JobStatus, num?: number): Promise<JobStorageFormat<Input, Output>[]>;
36
+ /**
37
+ * Retrieves the next available job that is ready to be processed.
38
+ * @returns The next job or undefined if no job is available
39
+ */
40
+ next(): Promise<JobStorageFormat<Input, Output>>;
41
+ /**
42
+ * Retrieves the number of jobs in the queue with a specific status.
43
+ * @param status - The status of the jobs to count
44
+ * @returns The count of jobs with the specified status
45
+ */
46
+ size(status?: JobStatus): Promise<number>;
47
+ /**
48
+ * Marks a job as complete with its output or error.
49
+ * Enhanced error handling:
50
+ * - For a retryable error, increments run_attempts and updates run_after.
51
+ * - Marks a job as FAILED immediately for permanent or generic errors.
52
+ */
53
+ complete(jobDetails: JobStorageFormat<Input, Output>): Promise<void>;
54
+ /**
55
+ * Clears all jobs from the queue.
56
+ */
57
+ deleteAll(): Promise<void>;
58
+ /**
59
+ * Looks up cached output for a given input
60
+ * Uses input fingerprinting for efficient matching
61
+ * @returns The cached output or null if not found
62
+ */
63
+ outputForInput(input: Input): Promise<any>;
64
+ /**
65
+ * Aborts a job by setting its status to "ABORTING".
66
+ * This method will signal the corresponding AbortController so that
67
+ * the job's execute() method (if it supports an AbortSignal parameter)
68
+ * can clean up and exit.
69
+ */
70
+ abort(jobId: number): Promise<void>;
71
+ /**
72
+ * Retrieves all jobs for a given job run ID.
73
+ * @param job_run_id - The ID of the job run to retrieve
74
+ * @returns An array of jobs
75
+ */
76
+ getByRunId(job_run_id: string): Promise<any[]>;
77
+ /**
78
+ * Implements the abstract saveProgress method from JobQueue
79
+ */
80
+ saveProgress(jobId: unknown, progress: number, message: string, details: Record<string, any>): Promise<void>;
81
+ /**
82
+ * Deletes a job by its ID
83
+ */
84
+ delete(jobId: unknown): Promise<void>;
85
+ /**
86
+ * Delete jobs with a specific status older than a cutoff date
87
+ * @param status - Status of jobs to delete
88
+ * @param olderThanMs - Delete jobs completed more than this many milliseconds ago
89
+ */
90
+ deleteJobsByStatusAndAge(status: JobStatus, olderThanMs: number): Promise<void>;
91
+ }
92
+ //# sourceMappingURL=PostgresQueueStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresQueueStorage.d.ts","sourceRoot":"","sources":["../../src/queue/PostgresQueueStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH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;IAYhB;;OAEG;IACU,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAOlD;;;;OAIG;IACU,wBAAwB,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAW7F"}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { Sqlite } from "@workglow/sqlite";
7
+ import { IQueueStorage, JobStatus, JobStorageFormat } from "./IQueueStorage";
8
+ export declare const SQLITE_QUEUE_STORAGE: import("@workglow/util").ServiceToken<IQueueStorage<any, any>>;
9
+ /**
10
+ * SQLite implementation of a job queue.
11
+ * Provides storage and retrieval for job execution states using SQLite.
12
+ */
13
+ export declare class SqliteQueueStorage<Input, Output> implements IQueueStorage<Input, Output> {
14
+ protected db: Sqlite.Database;
15
+ protected queueName: string;
16
+ protected options?: {
17
+ deleteAfterCompletionMs?: number;
18
+ deleteAfterFailureMs?: number;
19
+ } | undefined;
20
+ constructor(db: Sqlite.Database, queueName: string, options?: {
21
+ deleteAfterCompletionMs?: number;
22
+ deleteAfterFailureMs?: number;
23
+ } | undefined);
24
+ setupDatabase(): Promise<void>;
25
+ /**
26
+ * Adds a new job to the queue.
27
+ * @param job - The job to add
28
+ * @returns The ID of the added job
29
+ */
30
+ add(job: JobStorageFormat<Input, Output>): Promise<string | undefined>;
31
+ /**
32
+ * Retrieves a job by its ID.
33
+ * @param id - The ID of the job to retrieve
34
+ * @returns The job if found, undefined otherwise
35
+ */
36
+ get(id: string): Promise<(JobStorageFormat<Input, Output> & {
37
+ input: string;
38
+ output: string | null;
39
+ progress_details: string | null;
40
+ }) | undefined>;
41
+ /**
42
+ * Retrieves a slice of jobs from the queue.
43
+ * @param num - Maximum number of jobs to return
44
+ * @returns An array of jobs
45
+ */
46
+ peek(status?: JobStatus, num?: number): Promise<(JobStorageFormat<Input, Output> & {
47
+ input: string;
48
+ output: string | null;
49
+ progress_details: string | null;
50
+ })[]>;
51
+ /**
52
+ * Aborts a job by setting its status to "ABORTING".
53
+ * This method will signal the corresponding AbortController so that
54
+ * the job's execute() method (if it supports an AbortSignal parameter)
55
+ * can clean up and exit.
56
+ */
57
+ abort(jobId: string): Promise<void>;
58
+ /**
59
+ * Retrieves all jobs for a given job run ID.
60
+ * @param job_run_id - The ID of the job run to retrieve
61
+ * @returns An array of jobs
62
+ */
63
+ getByRunId(job_run_id: string): Promise<(JobStorageFormat<Input, Output> & {
64
+ input: string;
65
+ output: string | null;
66
+ progress_details: string | null;
67
+ })[]>;
68
+ /**
69
+ * Retrieves the next available job that is ready to be processed,
70
+ * and updates its status to PROCESSING.
71
+ *
72
+ * @returns The next job or undefined if no job is available
73
+ */
74
+ next(): Promise<(JobStorageFormat<Input, Output> & {
75
+ input: string;
76
+ output: string | null;
77
+ progress_details: string | null;
78
+ }) | undefined>;
79
+ /**
80
+ * Retrieves the number of jobs in the queue with a specific status.
81
+ * @param status - The status of the jobs to count
82
+ * @returns The count of jobs with the specified status
83
+ */
84
+ size(status?: JobStatus): Promise<any>;
85
+ /**
86
+ * Marks a job as complete with its output or error.
87
+ * Enhanced error handling:
88
+ * - Increments the retry count.
89
+ * - For a retryable error, updates run_after with the retry date.
90
+ * - Marks the job as FAILED for permanent or generic errors.
91
+ * - Marks the job as DISABLED for disabled jobs.
92
+ */
93
+ complete(job: JobStorageFormat<Input, Output>): Promise<void>;
94
+ deleteAll(): Promise<void>;
95
+ /**
96
+ * Looks up cached output for a input
97
+ * Uses input fingerprinting for efficient matching
98
+ * @returns The cached output or null if not found
99
+ */
100
+ outputForInput(input: Input): Promise<any>;
101
+ /**
102
+ * Implements the abstract saveProgress method from JobQueue
103
+ */
104
+ saveProgress(jobId: unknown, progress: number, message: string, details: Record<string, any>): Promise<void>;
105
+ /**
106
+ * Deletes a job by its ID
107
+ */
108
+ delete(jobId: unknown): Promise<void>;
109
+ /**
110
+ * Delete jobs with a specific status older than a cutoff date
111
+ * @param status - Status of jobs to delete
112
+ * @param olderThanMs - Delete jobs completed more than this many milliseconds ago
113
+ */
114
+ deleteJobsByStatusAndAge(status: JobStatus, olderThanMs: number): Promise<void>;
115
+ }
116
+ //# sourceMappingURL=SqliteQueueStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqliteQueueStorage.d.ts","sourceRoot":"","sources":["../../src/queue/SqliteQueueStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAE7E,eAAO,MAAM,oBAAoB,gEACuC,CAAC;AAEzE;;;GAGG;AACH,qBAAa,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAE,YAAW,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC;IAElF,SAAS,CAAC,EAAE,EAAE,MAAM,CAAC,QAAQ;IAC7B,SAAS,CAAC,SAAS,EAAE,MAAM;IAC3B,SAAS,CAAC,OAAO,CAAC,EAAE;QAClB,uBAAuB,CAAC,EAAE,MAAM,CAAC;QACjC,oBAAoB,CAAC,EAAE,MAAM,CAAC;KAC/B;gBALS,EAAE,EAAE,MAAM,CAAC,QAAQ,EACnB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE;QAClB,uBAAuB,CAAC,EAAE,MAAM,CAAC;QACjC,oBAAoB,CAAC,EAAE,MAAM,CAAC;KAC/B,YAAA;IAGU,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IA+B3C;;;;OAIG;IACU,GAAG,CAAC,GAAG,EAAE,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC;IAgErD;;;;OAIG;IACU,GAAG,CAAC,EAAE,EAAE,MAAM;eAQd,MAAM;gBACL,MAAM,GAAG,IAAI;0BACH,MAAM,GAAG,IAAI;;IAcrC;;;;OAIG;IACU,IAAI,CAAC,MAAM,GAAE,SAA6B,EAAE,GAAG,GAAE,MAAY;eAW7D,MAAM;gBACL,MAAM,GAAG,IAAI;0BACH,MAAM,GAAG,IAAI;;IAerC;;;;;OAKG;IACU,KAAK,CAAC,KAAK,EAAE,MAAM;IAShC;;;;OAIG;IACU,UAAU,CAAC,UAAU,EAAE,MAAM;eAO7B,MAAM;gBACL,MAAM,GAAG,IAAI;0BACH,MAAM,GAAG,IAAI;;IAerC;;;;;OAKG;IACU,IAAI;eAMJ,MAAM;gBACL,MAAM,GAAG,IAAI;0BACH,MAAM,GAAG,IAAI;;IA6BrC;;;;OAIG;IACU,IAAI,CAAC,MAAM,YAAoB;IAW5C;;;;;;;OAOG;IACU,QAAQ,CAAC,GAAG,EAAE,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC;IA6C7C,SAAS;IAQtB;;;;OAIG;IACU,cAAc,CAAC,KAAK,EAAE,KAAK;IAcxC;;OAEG;IACU,YAAY,CACvB,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC3B,OAAO,CAAC,IAAI,CAAC;IAYhB;;OAEG;IACU,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAQlD;;;;OAIG;IACU,wBAAwB,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAW7F"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { SupabaseClient } from "@supabase/supabase-js";
7
+ import { IQueueStorage, JobStatus, JobStorageFormat } from "./IQueueStorage";
8
+ export declare const SUPABASE_QUEUE_STORAGE: import("@workglow/util").ServiceToken<IQueueStorage<any, any>>;
9
+ /**
10
+ * Supabase implementation of a job queue.
11
+ * Provides storage and retrieval for job execution states using Supabase.
12
+ */
13
+ export declare class SupabaseQueueStorage<Input, Output> implements IQueueStorage<Input, Output> {
14
+ protected readonly client: SupabaseClient;
15
+ protected readonly queueName: string;
16
+ constructor(client: SupabaseClient, queueName: string);
17
+ setupDatabase(): Promise<void>;
18
+ /**
19
+ * Adds a new job to the queue.
20
+ * @param job - The job to add
21
+ * @returns The ID of the added job
22
+ */
23
+ add(job: JobStorageFormat<Input, Output>): Promise<unknown>;
24
+ /**
25
+ * Retrieves a job by its ID.
26
+ * @param id - The ID of the job to retrieve
27
+ * @returns The job if found, undefined otherwise
28
+ */
29
+ get(id: number): Promise<JobStorageFormat<Input, Output> | undefined>;
30
+ /**
31
+ * Retrieves a slice of jobs from the queue.
32
+ * @param status - The status to filter by
33
+ * @param num - Maximum number of jobs to return
34
+ * @returns An array of jobs
35
+ */
36
+ peek(status?: JobStatus, num?: number): Promise<JobStorageFormat<Input, Output>[]>;
37
+ /**
38
+ * Retrieves the next available job that is ready to be processed.
39
+ * @returns The next job or undefined if no job is available
40
+ */
41
+ next(): Promise<JobStorageFormat<Input, Output> | undefined>;
42
+ /**
43
+ * Retrieves the number of jobs in the queue with a specific status.
44
+ * @param status - The status of the jobs to count
45
+ * @returns The count of jobs with the specified status
46
+ */
47
+ size(status?: JobStatus): Promise<number>;
48
+ /**
49
+ * Marks a job as complete with its output or error.
50
+ * Enhanced error handling:
51
+ * - For a retryable error, increments run_attempts and updates run_after.
52
+ * - Marks a job as FAILED immediately for permanent or generic errors.
53
+ */
54
+ complete(jobDetails: JobStorageFormat<Input, Output>): Promise<void>;
55
+ /**
56
+ * Clears all jobs from the queue.
57
+ */
58
+ deleteAll(): Promise<void>;
59
+ /**
60
+ * Looks up cached output for a given input
61
+ * Uses input fingerprinting for efficient matching
62
+ * @returns The cached output or null if not found
63
+ */
64
+ outputForInput(input: Input): Promise<Output | null>;
65
+ /**
66
+ * Aborts a job by setting its status to "ABORTING".
67
+ * This method will signal the corresponding AbortController so that
68
+ * the job's execute() method (if it supports an AbortSignal parameter)
69
+ * can clean up and exit.
70
+ */
71
+ abort(jobId: unknown): Promise<void>;
72
+ /**
73
+ * Retrieves all jobs for a given job run ID.
74
+ * @param job_run_id - The ID of the job run to retrieve
75
+ * @returns An array of jobs
76
+ */
77
+ getByRunId(job_run_id: string): Promise<Array<JobStorageFormat<Input, Output>>>;
78
+ /**
79
+ * Implements the saveProgress method
80
+ */
81
+ saveProgress(jobId: unknown, progress: number, message: string, details: Record<string, any>): Promise<void>;
82
+ /**
83
+ * Deletes a job by its ID
84
+ */
85
+ delete(jobId: unknown): Promise<void>;
86
+ /**
87
+ * Delete jobs with a specific status older than a cutoff date
88
+ * @param status - Status of jobs to delete
89
+ * @param olderThanMs - Delete jobs completed more than this many milliseconds ago
90
+ */
91
+ deleteJobsByStatusAndAge(status: JobStatus, olderThanMs: number): Promise<void>;
92
+ }
93
+ //# sourceMappingURL=SupabaseQueueStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SupabaseQueueStorage.d.ts","sourceRoot":"","sources":["../../src/queue/SupabaseQueueStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAE7E,eAAO,MAAM,sBAAsB,gEAElC,CAAC;AAEF;;;GAGG;AACH,qBAAa,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAE,YAAW,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC;IAEpF,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,cAAc;IACzC,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM;gBADjB,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM;IAGz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