@workglow/storage 0.2.26 → 0.2.28

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 (94) hide show
  1. package/dist/browser.d.ts +0 -10
  2. package/dist/browser.d.ts.map +1 -1
  3. package/dist/browser.js +407 -4002
  4. package/dist/browser.js.map +8 -24
  5. package/dist/bun.js +496 -6711
  6. package/dist/bun.js.map +8 -34
  7. package/dist/common-server.d.ts +1 -21
  8. package/dist/common-server.d.ts.map +1 -1
  9. package/dist/common.d.ts +1 -6
  10. package/dist/common.d.ts.map +1 -1
  11. package/dist/node.js +496 -6712
  12. package/dist/node.js.map +8 -34
  13. package/dist/tabular/SharedInMemoryTabularStorage.d.ts +2 -1
  14. package/dist/tabular/SharedInMemoryTabularStorage.d.ts.map +1 -1
  15. package/package.json +5 -71
  16. package/dist/kv/IndexedDbKvStorage.d.ts +0 -27
  17. package/dist/kv/IndexedDbKvStorage.d.ts.map +0 -1
  18. package/dist/kv/PostgresKvStorage.d.ts +0 -28
  19. package/dist/kv/PostgresKvStorage.d.ts.map +0 -1
  20. package/dist/kv/SqliteKvStorage.d.ts +0 -28
  21. package/dist/kv/SqliteKvStorage.d.ts.map +0 -1
  22. package/dist/kv/SupabaseKvStorage.d.ts +0 -33
  23. package/dist/kv/SupabaseKvStorage.d.ts.map +0 -1
  24. package/dist/postgres/browser.d.ts +0 -32
  25. package/dist/postgres/browser.d.ts.map +0 -1
  26. package/dist/postgres/browser.js +0 -150
  27. package/dist/postgres/browser.js.map +0 -11
  28. package/dist/postgres/node-bun.d.ts +0 -26
  29. package/dist/postgres/node-bun.d.ts.map +0 -1
  30. package/dist/postgres/node-bun.js +0 -41
  31. package/dist/postgres/node-bun.js.map +0 -10
  32. package/dist/postgres/pglite-pool.d.ts +0 -21
  33. package/dist/postgres/pglite-pool.d.ts.map +0 -1
  34. package/dist/queue/IQueueStorage.d.ts +0 -206
  35. package/dist/queue/IQueueStorage.d.ts.map +0 -1
  36. package/dist/queue/InMemoryQueueStorage.d.ts +0 -148
  37. package/dist/queue/InMemoryQueueStorage.d.ts.map +0 -1
  38. package/dist/queue/IndexedDbQueueStorage.d.ts +0 -165
  39. package/dist/queue/IndexedDbQueueStorage.d.ts.map +0 -1
  40. package/dist/queue/PostgresQueueStorage.d.ts +0 -133
  41. package/dist/queue/PostgresQueueStorage.d.ts.map +0 -1
  42. package/dist/queue/SqliteQueueStorage.d.ts +0 -141
  43. package/dist/queue/SqliteQueueStorage.d.ts.map +0 -1
  44. package/dist/queue/SupabaseQueueStorage.d.ts +0 -194
  45. package/dist/queue/SupabaseQueueStorage.d.ts.map +0 -1
  46. package/dist/queue/TelemetryQueueStorage.d.ts +0 -32
  47. package/dist/queue/TelemetryQueueStorage.d.ts.map +0 -1
  48. package/dist/queue-limiter/IRateLimiterStorage.d.ts +0 -81
  49. package/dist/queue-limiter/IRateLimiterStorage.d.ts.map +0 -1
  50. package/dist/queue-limiter/InMemoryRateLimiterStorage.d.ts +0 -32
  51. package/dist/queue-limiter/InMemoryRateLimiterStorage.d.ts.map +0 -1
  52. package/dist/queue-limiter/IndexedDbRateLimiterStorage.d.ts +0 -52
  53. package/dist/queue-limiter/IndexedDbRateLimiterStorage.d.ts.map +0 -1
  54. package/dist/queue-limiter/PostgresRateLimiterStorage.d.ts +0 -54
  55. package/dist/queue-limiter/PostgresRateLimiterStorage.d.ts.map +0 -1
  56. package/dist/queue-limiter/SqliteRateLimiterStorage.d.ts +0 -53
  57. package/dist/queue-limiter/SqliteRateLimiterStorage.d.ts.map +0 -1
  58. package/dist/queue-limiter/SupabaseRateLimiterStorage.d.ts +0 -49
  59. package/dist/queue-limiter/SupabaseRateLimiterStorage.d.ts.map +0 -1
  60. package/dist/sqlite/browser.d.ts +0 -37
  61. package/dist/sqlite/browser.d.ts.map +0 -1
  62. package/dist/sqlite/browser.js +0 -125
  63. package/dist/sqlite/browser.js.map +0 -10
  64. package/dist/sqlite/bun.d.ts +0 -32
  65. package/dist/sqlite/bun.d.ts.map +0 -1
  66. package/dist/sqlite/bun.js +0 -84
  67. package/dist/sqlite/bun.js.map +0 -10
  68. package/dist/sqlite/canonical-api.d.ts +0 -34
  69. package/dist/sqlite/canonical-api.d.ts.map +0 -1
  70. package/dist/sqlite/node.d.ts +0 -34
  71. package/dist/sqlite/node.d.ts.map +0 -1
  72. package/dist/sqlite/node.js +0 -65
  73. package/dist/sqlite/node.js.map +0 -10
  74. package/dist/tabular/IndexedDbTabularStorage.d.ts +0 -199
  75. package/dist/tabular/IndexedDbTabularStorage.d.ts.map +0 -1
  76. package/dist/tabular/PostgresTabularStorage.d.ts +0 -196
  77. package/dist/tabular/PostgresTabularStorage.d.ts.map +0 -1
  78. package/dist/tabular/SqliteTabularStorage.d.ts +0 -167
  79. package/dist/tabular/SqliteTabularStorage.d.ts.map +0 -1
  80. package/dist/tabular/SupabaseTabularStorage.d.ts +0 -174
  81. package/dist/tabular/SupabaseTabularStorage.d.ts.map +0 -1
  82. package/dist/util/IndexedDbTable.d.ts +0 -40
  83. package/dist/util/IndexedDbTable.d.ts.map +0 -1
  84. package/dist/util/traced.d.ts +0 -10
  85. package/dist/util/traced.d.ts.map +0 -1
  86. package/dist/vector/IndexedDbVectorStorage.d.ts +0 -53
  87. package/dist/vector/IndexedDbVectorStorage.d.ts.map +0 -1
  88. package/dist/vector/PostgresVectorStorage.d.ts +0 -39
  89. package/dist/vector/PostgresVectorStorage.d.ts.map +0 -1
  90. package/dist/vector/SqliteAiVectorStorage.d.ts +0 -100
  91. package/dist/vector/SqliteAiVectorStorage.d.ts.map +0 -1
  92. package/dist/vector/SqliteVectorStorage.d.ts +0 -49
  93. package/dist/vector/SqliteVectorStorage.d.ts.map +0 -1
  94. package/src/queue/README.md +0 -41
@@ -1,206 +0,0 @@
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
- /**
8
- * The type of a prefix column.
9
- * - "uuid" maps to UUID in PostgreSQL/Supabase, TEXT in SQLite/IndexedDB/InMemory
10
- * - "number" maps to INTEGER in PostgreSQL/Supabase/SQLite, number in IndexedDB/InMemory
11
- */
12
- export type PrefixColumnType = "uuid" | "number";
13
- /**
14
- * Defines a prefix column for queue storage filtering.
15
- */
16
- export interface PrefixColumn {
17
- readonly name: string;
18
- readonly type: PrefixColumnType;
19
- }
20
- /**
21
- * Options for configuring queue storage with prefix filters.
22
- */
23
- export interface QueueStorageOptions {
24
- /** The prefix column definitions for this storage */
25
- readonly prefixes?: readonly PrefixColumn[];
26
- /** The values for each prefix column */
27
- readonly prefixValues?: Readonly<Record<string, string | number>>;
28
- }
29
- export type JobStatus = "PENDING" | "PROCESSING" | "COMPLETED" | "ABORTING" | "FAILED" | "DISABLED";
30
- export declare const JobStatus: {
31
- readonly PENDING: "PENDING";
32
- readonly PROCESSING: "PROCESSING";
33
- readonly COMPLETED: "COMPLETED";
34
- readonly ABORTING: "ABORTING";
35
- readonly FAILED: "FAILED";
36
- readonly DISABLED: "DISABLED";
37
- };
38
- /**
39
- * Type of change that occurred in the queue
40
- */
41
- export type QueueChangeType = "INSERT" | "UPDATE" | "DELETE";
42
- /**
43
- * Payload describing a change to a job
44
- */
45
- export interface QueueChangePayload<Input, Output> {
46
- readonly type: QueueChangeType;
47
- readonly old?: JobStorageFormat<Input, Output>;
48
- readonly new?: JobStorageFormat<Input, Output>;
49
- }
50
- /**
51
- * Options for subscribing to queue changes
52
- */
53
- export interface QueueSubscribeOptions {
54
- /** Polling interval in milliseconds (used by implementations that rely on polling) */
55
- readonly pollingIntervalMs?: number;
56
- /**
57
- * Custom prefix filter for this subscription.
58
- *
59
- * - If not provided (undefined): Uses the storage instance's configured prefixValues
60
- * - If empty object ({}): Receives ALL changes across all prefix combinations
61
- * - If partial object: Receives changes matching the specified subset of prefixes
62
- *
63
- * @example
64
- * // Storage configured with prefixes: [{name: "user_id"}, {name: "project_id"}]
65
- * // and prefixValues: {user_id: "abc", project_id: "123"}
66
- *
67
- * // Subscribe to only this user+project (default behavior)
68
- * storage.subscribeToChanges(callback);
69
- *
70
- * // Subscribe to all projects for this user
71
- * storage.subscribeToChanges(callback, { prefixFilter: { user_id: "abc" } });
72
- *
73
- * // Subscribe to ALL jobs in this queue (admin/supervisor view)
74
- * storage.subscribeToChanges(callback, { prefixFilter: {} });
75
- */
76
- readonly prefixFilter?: Readonly<Record<string, string | number>>;
77
- }
78
- /**
79
- * Details about a job that reflect the structure in the database.
80
- */
81
- export type JobStorageFormat<Input, Output> = {
82
- id?: unknown;
83
- job_run_id?: string;
84
- queue?: string;
85
- input: Input;
86
- output?: Output | null;
87
- error?: string | null;
88
- error_code?: string | null;
89
- fingerprint?: string;
90
- max_retries?: number;
91
- status?: JobStatus;
92
- created_at?: string;
93
- deadline_at?: string | null;
94
- last_ran_at?: string | null;
95
- run_after: string | null;
96
- completed_at: string | null;
97
- run_attempts?: number;
98
- progress?: number;
99
- progress_message?: string;
100
- progress_details?: Record<string, any> | null;
101
- worker_id?: string | null;
102
- };
103
- /**
104
- * Interface defining the storage operations for a job queue
105
- */
106
- export interface IQueueStorage<Input, Output> {
107
- /**
108
- * Adds a job to the queue storage
109
- * @param job - The job to add to the queue storage
110
- * @returns The ID of the job
111
- */
112
- add(job: JobStorageFormat<Input, Output>): Promise<unknown>;
113
- /**
114
- * Gets a job from the queue storage by ID
115
- * @param id - The ID of the job to get
116
- * @returns The job with the given ID
117
- */
118
- get(id: unknown): Promise<JobStorageFormat<Input, Output> | undefined>;
119
- /**
120
- * Gets the next job from the queue storage
121
- * @param workerId - Worker ID to associate with the job (required)
122
- * @returns The next job from the queue storage
123
- */
124
- next(workerId: string): Promise<JobStorageFormat<Input, Output> | undefined>;
125
- /**
126
- * Releases a job that was just claimed by {@link next} but won't be
127
- * processed (e.g. the worker was stopped mid-claim). Resets status to
128
- * PENDING and clears worker_id WITHOUT incrementing run_attempts —
129
- * the worker never actually attempted execution, so the retry budget
130
- * must be preserved.
131
- * @param id - The id of the claimed job to release.
132
- */
133
- release(id: unknown): Promise<void>;
134
- /**
135
- * Peeks at the next job(s) from the queue storage without removing them
136
- * @param status - The status of the jobs to peek at
137
- * @param num - The number of jobs to peek at
138
- * @returns The jobs with the given status
139
- */
140
- peek(status?: JobStatus, num?: number): Promise<Array<JobStorageFormat<Input, Output>>>;
141
- /**
142
- * Gets the size of the queue storage
143
- * @param status - The status of the jobs to get the size for
144
- * @returns The size of the queue storage
145
- */
146
- size(status?: JobStatus): Promise<number>;
147
- /**
148
- * Completes a job in the queue storage
149
- * @param job - The job to complete
150
- */
151
- complete(job: JobStorageFormat<Input, Output>): Promise<void>;
152
- /**
153
- * Deletes all jobs from the queue storage
154
- */
155
- deleteAll(): Promise<void>;
156
- /**
157
- * Gets the output for a given input from the queue storage
158
- * @param input - The input to get the output for
159
- * @returns The output of the job
160
- */
161
- outputForInput(input: Input): Promise<Output | null>;
162
- /**
163
- * Aborts a job in the queue storage
164
- * @param id - The ID of the job to abort
165
- */
166
- abort(id: unknown): Promise<void>;
167
- /**
168
- * Gets the jobs by job run ID from the queue storage
169
- * @param runId - The job run ID of the jobs to get
170
- * @returns The jobs with the given job run ID
171
- */
172
- getByRunId(runId: string): Promise<Array<JobStorageFormat<Input, Output>>>;
173
- /**
174
- * Saves progress updates for a job in the queue storage
175
- * @param id - The ID of the job to save the progress for
176
- * @param progress - The progress of the job
177
- * @param message - The message of the job
178
- * @param details - The details of the job
179
- */
180
- saveProgress(id: unknown, progress: number, message: string, details: Record<string, any> | null): Promise<void>;
181
- /**
182
- * Deletes a job by its ID from the queue storage
183
- * @param id - The ID of the job to delete
184
- */
185
- delete(id: unknown): Promise<void>;
186
- /**
187
- * Deletes jobs from the queue storage that are of a specific status and older than the specified time
188
- * @param status - The status of the jobs to delete
189
- * @param olderThanMs - The time in milliseconds that the jobs must be older than to be deleted
190
- */
191
- deleteJobsByStatusAndAge(status: JobStatus, olderThanMs: number): Promise<void>;
192
- /**
193
- * Sets up the database schema and tables.
194
- * This method should be called before using the storage in tests.
195
- * For production use, database setup should be done via migrations.
196
- */
197
- setupDatabase(): Promise<void>;
198
- /**
199
- * Subscribes to changes in the queue (including remote changes).
200
- * @param callback - Function called when a change occurs
201
- * @param options - Optional subscription options (e.g., polling interval)
202
- * @returns Unsubscribe function
203
- */
204
- subscribeToChanges(callback: (change: QueueChangePayload<Input, Output>) => void, options?: QueueSubscribeOptions): () => void;
205
- }
206
- //# sourceMappingURL=IQueueStorage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IQueueStorage.d.ts","sourceRoot":"","sources":["../../src/queue/IQueueStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,eAAO,MAAM,aAAa,gEAAkE,CAAC;AAE7F;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,qDAAqD;IACrD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAC5C,wCAAwC;IACxC,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;CACnE;AAED,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,YAAY,GAAG,WAAW,GAAG,UAAU,GAAG,QAAQ,GAAG,UAAU,CAAC;AACpG,eAAO,MAAM,SAAS;sBACX,SAAS;yBACN,YAAY;wBACb,WAAW;uBACZ,UAAU;qBACZ,QAAQ;uBACN,UAAU;CAC2B,CAAC;AAElD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,G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AAC,IAAI,CAAC,CAAC;IAE3B;;;;OAIG;IACH,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,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;IAE/B;;;;;OAKG;IACH,kBAAkB,CAChB,QAAQ,EAAE,CAAC,MAAM,EAAE,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAC7D,OAAO,CAAC,EAAE,qBAAqB,GAC9B,MAAM,IAAI,CAAC;CACf"}
@@ -1,148 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import { EventEmitter } from "@workglow/util";
7
- import { IQueueStorage, JobStatus, JobStorageFormat, QueueChangePayload, QueueStorageOptions, QueueSubscribeOptions } from "./IQueueStorage";
8
- /**
9
- * Event listeners for queue storage events
10
- */
11
- type QueueEventListeners<Input, Output> = {
12
- change: (payload: QueueChangePayload<Input, Output>) => void;
13
- };
14
- export declare const IN_MEMORY_QUEUE_STORAGE: import("@workglow/util").ServiceToken<IQueueStorage<any, any>>;
15
- /**
16
- * In-memory implementation of a job queue that manages asynchronous tasks.
17
- * Supports job scheduling, status tracking, result caching, and prefix-based filtering.
18
- */
19
- export declare class InMemoryQueueStorage<Input, Output> implements IQueueStorage<Input, Output> {
20
- readonly queueName: string;
21
- /** The prefix values for filtering jobs */
22
- protected readonly prefixValues: Readonly<Record<string, string | number>>;
23
- /** Event emitter for change notifications */
24
- protected readonly events: EventEmitter<QueueEventListeners<Input, Output>>;
25
- /**
26
- * Creates a new in-memory job queue
27
- * @param queueName - Name of the queue
28
- * @param options - Optional configuration including prefix filters
29
- */
30
- constructor(queueName: string, options?: QueueStorageOptions);
31
- /** Internal array storing all jobs */
32
- jobQueue: Array<JobStorageFormat<Input, Output> & Record<string, unknown>>;
33
- /**
34
- * Checks if a job matches the current prefix values
35
- */
36
- private matchesPrefixes;
37
- /**
38
- * Returns a filtered and sorted list of pending jobs that are ready to run
39
- * Sorts by creation time to maintain FIFO order
40
- */
41
- private pendingQueue;
42
- /**
43
- * Adds a new job to the queue
44
- * Generates an ID and fingerprint if not provided
45
- */
46
- add(job: JobStorageFormat<Input, Output>): Promise<unknown>;
47
- /**
48
- * Retrieves a job from the queue by its id.
49
- * @param id - The id of the job to retrieve.
50
- * @returns A promise that resolves to the job or undefined if the job is not found.
51
- */
52
- get(id: unknown): Promise<JobStorageFormat<Input, Output> | undefined>;
53
- /**
54
- * Retrieves a slice of jobs from the queue.
55
- * @param status - The status of the jobs to retrieve.
56
- * @param num - The number of jobs to retrieve.
57
- * @returns A promise that resolves to an array of jobs.
58
- */
59
- peek(status?: JobStatus, num?: number): Promise<Array<JobStorageFormat<Input, Output>>>;
60
- /**
61
- * Retrieves the next available job that is ready to be processed
62
- * Updates the job status to PROCESSING before returning
63
- * @param workerId - Worker ID to associate with the job
64
- * @returns The next job or undefined if no job is available
65
- */
66
- next(workerId: string): Promise<JobStorageFormat<Input, Output> | undefined>;
67
- /**
68
- * Retrieves the size of the queue for a given status
69
- * @param status - The status of the jobs to retrieve.
70
- * @returns A promise that resolves to the number of jobs.
71
- */
72
- size(status?: "PENDING"): Promise<number>;
73
- /**
74
- * Saves the progress of a job
75
- * @param jobId - The id of the job to save the progress for.
76
- * @param progress - The progress of the job.
77
- * @param message - The message of the job.
78
- * @param details - The details of the job.
79
- */
80
- saveProgress(id: unknown, progress: number, message: string, details: Record<string, any> | null): Promise<void>;
81
- /**
82
- * Marks a job as complete with its output or error
83
- * Handles run_attempts for failed jobs and triggers completion callbacks
84
- * @param id - ID of the job to complete
85
- * @param output - Result of the job execution
86
- * @param error - Optional error message if job failed
87
- */
88
- complete(job: JobStorageFormat<Input, Output>): Promise<void>;
89
- /**
90
- * Releases a claimed job back to PENDING without incrementing run_attempts.
91
- * @param id - The id of the claimed job to release.
92
- */
93
- release(id: unknown): Promise<void>;
94
- /**
95
- * Aborts a job
96
- * @param id - The id of the job to abort.
97
- */
98
- abort(id: unknown): Promise<void>;
99
- /**
100
- * Retrieves all jobs by their job_run_id.
101
- * @param job_run_id - The job_run_id of the jobs to retrieve.
102
- * @returns A promise that resolves to an array of jobs.
103
- */
104
- getByRunId(runId: string): Promise<Array<JobStorageFormat<Input, Output>>>;
105
- /**
106
- * Deletes all jobs from the queue that match the current prefix values.
107
- */
108
- deleteAll(): Promise<void>;
109
- /**
110
- * Looks up cached output for a given input
111
- * Uses input fingerprinting for efficient matching
112
- * @param input - The input to look up the cached output for.
113
- * @returns The cached output or null if not found
114
- */
115
- outputForInput(input: Input): Promise<Output | null>;
116
- /**
117
- * Deletes a job by its ID
118
- */
119
- delete(id: unknown): Promise<void>;
120
- /**
121
- * Delete jobs with a specific status older than a cutoff date
122
- * @param status - Status of jobs to delete
123
- * @param olderThanMs - Delete jobs completed more than this many milliseconds ago
124
- */
125
- deleteJobsByStatusAndAge(status: JobStatus, olderThanMs: number): Promise<void>;
126
- /**
127
- * Sets up the database schema and tables.
128
- * No-op for in-memory storage as it doesn't require database setup.
129
- */
130
- setupDatabase(): Promise<void>;
131
- /**
132
- * Checks if a job matches the specified prefix filter
133
- * @param job - The job to check
134
- * @param prefixFilter - The prefix filter (undefined = use instance prefixes, {} = no filter)
135
- */
136
- private matchesPrefixFilter;
137
- /**
138
- * Subscribes to changes in the queue.
139
- * Since InMemory is both client and server, changes are detected via local events.
140
- *
141
- * @param callback - Function called when a change occurs
142
- * @param options - Subscription options including prefix filter
143
- * @returns Unsubscribe function
144
- */
145
- subscribeToChanges(callback: (change: QueueChangePayload<Input, Output>) => void, options?: QueueSubscribeOptions): () => void;
146
- }
147
- export {};
148
- //# sourceMappingURL=InMemoryQueueStorage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InMemoryQueueStorage.d.ts","sourceRoot":"","sources":["../../src/queue/InMemoryQueueStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,YAAY,EAKb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AAEzB;;GAEG;AACH,KAAK,mBAAmB,CAAC,KAAK,EAAE,MAAM,IAAI;IACxC,MAAM,EAAE,CAAC,OAAO,EAAE,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;CAC9D,CAAC;AAEF,eAAO,MAAM,uBAAuB,gEAEnC,CAAC;AAEF;;;GAGG;AACH,qBAAa,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAE,YAAW,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC;aAYpE,SAAS,EAAE,MAAM;IAXnC,2CAA2C;IAC3C,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,MAA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I,CAAC,CAkCf;IAED;;;;;;OAMG;IACU,QAAQ,CAAC,GAAG,EAAE,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,iBAezD;IAED;;;OAGG;IACU,OAAO,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAY/C;IAED;;;OAGG;IACU,KAAK,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ7C;IAED;;;;OAIG;IACU,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAGtF;IAED;;OAEG;IACU,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAOtC;IAED;;;;;OAKG;IACU,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAWhE;IAED;;OAEG;IACU,MAAM,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAO9C;IAED;;;;OAIG;IACU,wBAAwB,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAoB3F;IAED;;;OAGG;IACU,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAE1C;IAED;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IA2B3B;;;;;;;OAOG;IACI,kBAAkB,CACvB,QAAQ,EAAE,CAAC,MAAM,EAAE,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAC7D,OAAO,CAAC,EAAE,qBAAqB,GAC9B,MAAM,IAAI,CAiBZ;CACF"}
@@ -1,165 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import { MigrationOptions } from "../util/IndexedDbTable";
7
- import { IQueueStorage, JobStatus, JobStorageFormat, PrefixColumn, QueueChangePayload, QueueStorageOptions, QueueSubscribeOptions } from "./IQueueStorage";
8
- export declare const INDEXED_DB_QUEUE_STORAGE: import("@workglow/util").ServiceToken<IQueueStorage<any, any>>;
9
- /**
10
- * Extended options for IndexedDB queue storage including prefix support
11
- */
12
- export interface IndexedDbQueueStorageOptions extends QueueStorageOptions, MigrationOptions {
13
- /** Enable BroadcastChannel notifications (default: true) */
14
- readonly useBroadcastChannel?: boolean;
15
- /** Backup polling interval in ms (default: 5000, 0 to disable) */
16
- readonly backupPollingIntervalMs?: number;
17
- }
18
- /**
19
- * IndexedDB implementation of a job queue storage.
20
- * Provides storage and retrieval for job execution states using IndexedDB.
21
- */
22
- export declare class IndexedDbQueueStorage<Input, Output> implements IQueueStorage<Input, Output> {
23
- readonly queueName: string;
24
- private db;
25
- private readonly tableName;
26
- private readonly migrationOptions;
27
- /** The prefix column definitions */
28
- protected readonly prefixes: readonly PrefixColumn[];
29
- /** The prefix values for filtering */
30
- protected readonly prefixValues: Readonly<Record<string, string | number>>;
31
- /** Shared hybrid subscription manager */
32
- private hybridManager;
33
- /** Hybrid subscription options */
34
- private readonly hybridOptions;
35
- constructor(queueName: string, options?: IndexedDbQueueStorageOptions);
36
- /**
37
- * Gets prefix column names for use in indexes
38
- */
39
- private getPrefixColumnNames;
40
- /**
41
- * Checks if a job matches the current prefix values
42
- */
43
- private matchesPrefixes;
44
- /**
45
- * Gets prefix values as an array in column order for index key construction
46
- */
47
- private getPrefixKeyValues;
48
- private getDb;
49
- /**
50
- * Sets up the IndexedDB database table with the required schema and indexes.
51
- * Must be called before using any other methods.
52
- */
53
- setupDatabase(): Promise<void>;
54
- /**
55
- * Adds a job to the queue.
56
- * @param job - The job to add to the queue.
57
- * @returns A promise that resolves to the job id.
58
- */
59
- add(job: JobStorageFormat<Input, Output>): Promise<unknown>;
60
- /**
61
- * Retrieves a job from the queue by its id.
62
- * @param id - The id of the job to retrieve.
63
- * @returns A promise that resolves to the job or undefined if the job is not found.
64
- */
65
- get(id: unknown): Promise<JobStorageFormat<Input, Output> | undefined>;
66
- /**
67
- * Retrieves a slice of jobs from the queue.
68
- * @param status - The status of the jobs to retrieve.
69
- * @param num - The number of jobs to retrieve.
70
- * @returns A promise that resolves to an array of jobs.
71
- */
72
- peek(status?: JobStatus, num?: number): Promise<JobStorageFormat<Input, Output>[]>;
73
- /**
74
- * Retrieves the next job from the queue using optimistic locking. In case multiple workers
75
- * claim the same job, the first worker to claim it will process it and the other workers will return undefined.
76
- * This ONLY happens if workers are running in multiple tabs.
77
- *
78
- * IndexedDB uses snapshot isolation, so concurrent transactions can both see the same
79
- * PENDING job. To prevent processing the same job multiple times, this method:
80
- * 1. Claims a job by setting it to PROCESSING with a unique claim token
81
- * 2. After the transaction completes, re-reads the job to verify the claim succeeded
82
- * 3. If another worker claimed it first (different claim token), returns undefined
83
- *
84
- * @param workerId - Worker ID to associate with the job (required)
85
- * @returns A promise that resolves to the next job or undefined if the queue is empty.
86
- */
87
- next(workerId: string): Promise<JobStorageFormat<Input, Output> | undefined>;
88
- /**
89
- * Retrieves the number of jobs in the queue.
90
- * Returns the count of jobs in the queue.
91
- */
92
- size(status?: "PENDING"): Promise<number>;
93
- /**
94
- * Marks a job as complete with its output or error.
95
- */
96
- complete(job: JobStorageFormat<Input, Output>): Promise<void>;
97
- /**
98
- * Releases a claimed job without consuming a retry attempt.
99
- */
100
- release(id: unknown): Promise<void>;
101
- /**
102
- * Aborts a job in the queue.
103
- */
104
- abort(id: unknown): Promise<void>;
105
- /**
106
- * Gets jobs by their run ID.
107
- */
108
- getByRunId(job_run_id: string): Promise<JobStorageFormat<Input, Output>[]>;
109
- /**
110
- * Deletes all jobs from the queue.
111
- */
112
- deleteAll(): Promise<void>;
113
- /**
114
- * Gets the output for a given input.
115
- */
116
- outputForInput(input: Input): Promise<Output | null>;
117
- /**
118
- * Saves progress updates for a job.
119
- */
120
- saveProgress(id: unknown, progress: number, message: string, details: Record<string, any> | null): Promise<void>;
121
- private put;
122
- /**
123
- * Deletes a job by its ID.
124
- */
125
- delete(id: unknown): Promise<void>;
126
- /**
127
- * Delete jobs with a specific status older than a cutoff date
128
- * @param status - Status of jobs to delete
129
- * @param olderThanMs - Delete jobs completed more than this many milliseconds ago
130
- */
131
- deleteJobsByStatusAndAge(status: JobStatus, olderThanMs: number): Promise<void>;
132
- private getAllJobs;
133
- private getAllJobsWithFilter;
134
- /**
135
- * Checks if a prefix filter is custom (different from instance's prefixes).
136
- */
137
- private isCustomPrefixFilter;
138
- /**
139
- * Gets or creates the shared hybrid subscription manager for normal subscriptions.
140
- * This ensures all normal subscriptions share a single manager.
141
- */
142
- private getHybridManager;
143
- /**
144
- * Creates a dedicated polling subscription for custom prefix filters.
145
- * This runs separately from the normal polling manager.
146
- */
147
- private subscribeWithCustomPrefixFilter;
148
- /**
149
- * Subscribes to changes in the queue.
150
- * Uses polling since IndexedDB has no native cross-tab change notifications.
151
- *
152
- * Normal subscriptions (no custom prefix filter) share a single polling loop for efficiency.
153
- * Custom prefix filter subscriptions get their own dedicated polling loop with DB-level filtering.
154
- *
155
- * @param callback - Function called when a change occurs
156
- * @param options - Subscription options including polling interval and prefix filter
157
- * @returns Unsubscribe function
158
- */
159
- subscribeToChanges(callback: (change: QueueChangePayload<Input, Output>) => void, options?: QueueSubscribeOptions): () => void;
160
- /**
161
- * Cleanup method to destroy the hybrid manager
162
- */
163
- destroy(): void;
164
- }
165
- //# sourceMappingURL=IndexedDbQueueStorage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IndexedDbQueueStorage.d.ts","sourceRoot":"","sources":["../../src/queue/IndexedDbQueueStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAGL,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,iBAAiB,C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IAAI,CAAC,CASf;YAKa,GAAG;IA0BjB;;OAEG;IACU,MAAM,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAkB9C;IAED;;;;OAIG;IACU,wBAAwB,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAsC3F;YAQa,UAAU;YAwCV,oBAAoB;IA8ClC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAuB5B;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAoCxB;;;OAGG;IACH,OAAO,CAAC,+BAA+B;IA8CvC;;;;;;;;;;OAUG;IACI,kBAAkB,CACvB,QAAQ,EAAE,CAAC,MAAM,EAAE,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAC7D,OAAO,CAAC,EAAE,qBAAqB,GAC9B,MAAM,IAAI,CAYZ;IAED;;OAEG;IACH,OAAO,IAAI,IAAI,CAKd;CACF"}
@@ -1,133 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import type { Pool } from "@workglow/storage/postgres";
7
- import { IQueueStorage, JobStatus, JobStorageFormat, PrefixColumn, QueueChangePayload, QueueStorageOptions, QueueSubscribeOptions } 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
- /** The prefix column definitions */
17
- protected readonly prefixes: readonly PrefixColumn[];
18
- /** The prefix values for filtering */
19
- protected readonly prefixValues: Readonly<Record<string, string | number>>;
20
- /** The table name for the job queue */
21
- protected readonly tableName: string;
22
- constructor(db: Pool, queueName: string, options?: QueueStorageOptions);
23
- /**
24
- * Gets the SQL column type for a prefix column
25
- */
26
- private getPrefixColumnType;
27
- /**
28
- * Builds the prefix columns SQL for CREATE TABLE
29
- */
30
- private buildPrefixColumnsSql;
31
- /**
32
- * Builds prefix column names for use in queries
33
- */
34
- private getPrefixColumnNames;
35
- /**
36
- * Builds WHERE clause conditions for prefix filtering
37
- * @param startParam - The starting parameter number for parameterized queries
38
- * @returns Object with conditions string and parameter values
39
- */
40
- private buildPrefixWhereClause;
41
- /**
42
- * Gets prefix values as an array in column order
43
- */
44
- private getPrefixParamValues;
45
- setupDatabase(): Promise<void>;
46
- /**
47
- * Adds a new job to the queue.
48
- * @param job - The job to add
49
- * @returns The ID of the added job
50
- */
51
- add(job: JobStorageFormat<Input, Output>): Promise<unknown>;
52
- /**
53
- * Retrieves a job by its ID.
54
- * @param id - The ID of the job to retrieve
55
- * @returns The job if found, undefined otherwise
56
- */
57
- get(id: unknown): Promise<JobStorageFormat<Input, Output> | undefined>;
58
- /**
59
- * Retrieves a slice of jobs from the queue.
60
- * @param num - Maximum number of jobs to return
61
- * @returns An array of jobs
62
- */
63
- peek(status?: JobStatus, num?: number): Promise<Array<JobStorageFormat<Input, Output>>>;
64
- /**
65
- * Retrieves the next available job that is ready to be processed.
66
- * @param workerId - Worker ID to associate with the job (required)
67
- * @returns The next job or undefined if no job is available
68
- */
69
- next(workerId: string): Promise<JobStorageFormat<Input, Output> | undefined>;
70
- /**
71
- * Retrieves the number of jobs in the queue with a specific status.
72
- * @param status - The status of the jobs to count
73
- * @returns The count of jobs with the specified status
74
- */
75
- size(status?: "PENDING"): Promise<number>;
76
- /**
77
- * Marks a job as complete with its output or error.
78
- * Enhanced error handling:
79
- * - For a retryable error, increments run_attempts and updates run_after.
80
- * - Marks a job as FAILED immediately for permanent or generic errors.
81
- */
82
- complete(jobDetails: JobStorageFormat<Input, Output>): Promise<void>;
83
- /**
84
- * Clears all jobs from the queue.
85
- */
86
- deleteAll(): Promise<void>;
87
- /**
88
- * Looks up cached output for a given input
89
- * Uses input fingerprinting for efficient matching
90
- * @returns The cached output or null if not found
91
- */
92
- outputForInput(input: Input): Promise<Output | null>;
93
- /**
94
- * Aborts a job by setting its status to "ABORTING".
95
- * This method will signal the corresponding AbortController so that
96
- * the job's execute() method (if it supports an AbortSignal parameter)
97
- * can clean up and exit.
98
- */
99
- abort(jobId: unknown): Promise<void>;
100
- /**
101
- * Releases a claimed job back to PENDING without incrementing run_attempts.
102
- * @param jobId - The id of the claimed job to release.
103
- */
104
- release(jobId: unknown): Promise<void>;
105
- /**
106
- * Retrieves all jobs for a given job run ID.
107
- * @param job_run_id - The ID of the job run to retrieve
108
- * @returns An array of jobs
109
- */
110
- getByRunId(job_run_id: string): Promise<Array<JobStorageFormat<Input, Output>>>;
111
- /**
112
- * Implements the abstract saveProgress method from JobQueue
113
- */
114
- saveProgress(jobId: unknown, progress: number, message: string, details: Record<string, any>): Promise<void>;
115
- /**
116
- * Deletes a job by its ID
117
- */
118
- delete(jobId: unknown): Promise<void>;
119
- /**
120
- * Delete jobs with a specific status older than a cutoff date
121
- * @param status - Status of jobs to delete
122
- * @param olderThanMs - Delete jobs completed more than this many milliseconds ago
123
- */
124
- deleteJobsByStatusAndAge(status: JobStatus, olderThanMs: number): Promise<void>;
125
- /**
126
- * Subscribes to changes in the queue.
127
- * NOT IMPLEMENTED for PostgreSQL storage.
128
- *
129
- * @throws Error always - subscribeToChanges is not supported for PostgreSQL storage
130
- */
131
- subscribeToChanges(callback: (change: QueueChangePayload<Input, Output>) => void, options?: QueueSubscribeOptions): () => void;
132
- }
133
- //# sourceMappingURL=PostgresQueueStorage.d.ts.map