@workglow/storage 0.0.57 → 0.0.59

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 (46) hide show
  1. package/dist/browser.js +1266 -121
  2. package/dist/browser.js.map +15 -10
  3. package/dist/bun.js +2132 -267
  4. package/dist/bun.js.map +20 -13
  5. package/dist/common-server.d.ts +4 -0
  6. package/dist/common-server.d.ts.map +1 -1
  7. package/dist/common.d.ts +2 -0
  8. package/dist/common.d.ts.map +1 -1
  9. package/dist/limiter/IRateLimiterStorage.d.ts +81 -0
  10. package/dist/limiter/IRateLimiterStorage.d.ts.map +1 -0
  11. package/dist/limiter/InMemoryRateLimiterStorage.d.ts +32 -0
  12. package/dist/limiter/InMemoryRateLimiterStorage.d.ts.map +1 -0
  13. package/dist/limiter/IndexedDbRateLimiterStorage.d.ts +52 -0
  14. package/dist/limiter/IndexedDbRateLimiterStorage.d.ts.map +1 -0
  15. package/dist/limiter/PostgresRateLimiterStorage.d.ts +54 -0
  16. package/dist/limiter/PostgresRateLimiterStorage.d.ts.map +1 -0
  17. package/dist/limiter/SqliteRateLimiterStorage.d.ts +53 -0
  18. package/dist/limiter/SqliteRateLimiterStorage.d.ts.map +1 -0
  19. package/dist/limiter/SupabaseRateLimiterStorage.d.ts +53 -0
  20. package/dist/limiter/SupabaseRateLimiterStorage.d.ts.map +1 -0
  21. package/dist/node.js +2132 -267
  22. package/dist/node.js.map +20 -13
  23. package/dist/queue/IQueueStorage.d.ts +72 -1
  24. package/dist/queue/IQueueStorage.d.ts.map +1 -1
  25. package/dist/queue/InMemoryQueueStorage.d.ts +44 -11
  26. package/dist/queue/InMemoryQueueStorage.d.ts.map +1 -1
  27. package/dist/queue/IndexedDbQueueStorage.d.ts +70 -5
  28. package/dist/queue/IndexedDbQueueStorage.d.ts.map +1 -1
  29. package/dist/queue/PostgresQueueStorage.d.ts +80 -8
  30. package/dist/queue/PostgresQueueStorage.d.ts.map +1 -1
  31. package/dist/queue/SqliteQueueStorage.d.ts +90 -34
  32. package/dist/queue/SqliteQueueStorage.d.ts.map +1 -1
  33. package/dist/queue/SupabaseQueueStorage.d.ts +98 -4
  34. package/dist/queue/SupabaseQueueStorage.d.ts.map +1 -1
  35. package/dist/tabular/ITabularRepository.d.ts +18 -0
  36. package/dist/tabular/ITabularRepository.d.ts.map +1 -1
  37. package/dist/tabular/InMemoryTabularRepository.d.ts +9 -1
  38. package/dist/tabular/InMemoryTabularRepository.d.ts.map +1 -1
  39. package/dist/tabular/SqliteTabularRepository.d.ts.map +1 -1
  40. package/dist/tabular/SupabaseTabularRepository.d.ts +21 -1
  41. package/dist/tabular/SupabaseTabularRepository.d.ts.map +1 -1
  42. package/dist/tabular/TabularRepository.d.ts +10 -1
  43. package/dist/tabular/TabularRepository.d.ts.map +1 -1
  44. package/dist/util/PollingSubscriptionManager.d.ts +112 -0
  45. package/dist/util/PollingSubscriptionManager.d.ts.map +1 -0
  46. package/package.json +5 -5
@@ -4,6 +4,28 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
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
+ }
7
29
  export declare enum JobStatus {
8
30
  PENDING = "PENDING",
9
31
  PROCESSING = "PROCESSING",
@@ -12,6 +34,46 @@ export declare enum JobStatus {
12
34
  FAILED = "FAILED",
13
35
  DISABLED = "DISABLED"
14
36
  }
37
+ /**
38
+ * Type of change that occurred in the queue
39
+ */
40
+ export type QueueChangeType = "INSERT" | "UPDATE" | "DELETE";
41
+ /**
42
+ * Payload describing a change to a job
43
+ */
44
+ export interface QueueChangePayload<Input, Output> {
45
+ readonly type: QueueChangeType;
46
+ readonly old?: JobStorageFormat<Input, Output>;
47
+ readonly new?: JobStorageFormat<Input, Output>;
48
+ }
49
+ /**
50
+ * Options for subscribing to queue changes
51
+ */
52
+ export interface QueueSubscribeOptions {
53
+ /** Polling interval in milliseconds (used by implementations that rely on polling) */
54
+ readonly pollingIntervalMs?: number;
55
+ /**
56
+ * Custom prefix filter for this subscription.
57
+ *
58
+ * - If not provided (undefined): Uses the storage instance's configured prefixValues
59
+ * - If empty object ({}): Receives ALL changes across all prefix combinations
60
+ * - If partial object: Receives changes matching the specified subset of prefixes
61
+ *
62
+ * @example
63
+ * // Storage configured with prefixes: [{name: "user_id"}, {name: "project_id"}]
64
+ * // and prefixValues: {user_id: "abc", project_id: "123"}
65
+ *
66
+ * // Subscribe to only this user+project (default behavior)
67
+ * storage.subscribeToChanges(callback);
68
+ *
69
+ * // Subscribe to all projects for this user
70
+ * storage.subscribeToChanges(callback, { prefixFilter: { user_id: "abc" } });
71
+ *
72
+ * // Subscribe to ALL jobs in this queue (admin/supervisor view)
73
+ * storage.subscribeToChanges(callback, { prefixFilter: {} });
74
+ */
75
+ readonly prefixFilter?: Readonly<Record<string, string | number>>;
76
+ }
15
77
  /**
16
78
  * Details about a job that reflect the structure in the database.
17
79
  */
@@ -35,6 +97,7 @@ export type JobStorageFormat<Input, Output> = {
35
97
  progress?: number;
36
98
  progress_message?: string;
37
99
  progress_details?: Record<string, any> | null;
100
+ worker_id?: string | null;
38
101
  };
39
102
  /**
40
103
  * Interface defining the storage operations for a job queue
@@ -54,9 +117,10 @@ export interface IQueueStorage<Input, Output> {
54
117
  get(id: unknown): Promise<JobStorageFormat<Input, Output> | undefined>;
55
118
  /**
56
119
  * Gets the next job from the queue storage
120
+ * @param workerId - Optional worker ID to associate with the job
57
121
  * @returns The next job from the queue storage
58
122
  */
59
- next(): Promise<JobStorageFormat<Input, Output> | undefined>;
123
+ next(workerId?: string): Promise<JobStorageFormat<Input, Output> | undefined>;
60
124
  /**
61
125
  * Peeks at the next job(s) from the queue storage without removing them
62
126
  * @param status - The status of the jobs to peek at
@@ -121,5 +185,12 @@ export interface IQueueStorage<Input, Output> {
121
185
  * For production use, database setup should be done via migrations.
122
186
  */
123
187
  setupDatabase(): Promise<void>;
188
+ /**
189
+ * Subscribes to changes in the queue (including remote changes).
190
+ * @param callback - Function called when a change occurs
191
+ * @param options - Optional subscription options (e.g., polling interval)
192
+ * @returns Unsubscribe function
193
+ */
194
+ subscribeToChanges(callback: (change: QueueChangePayload<Input, Output>) => void, options?: QueueSubscribeOptions): () => void;
124
195
  }
125
196
  //# sourceMappingURL=IQueueStorage.d.ts.map
@@ -1 +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,E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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"}
@@ -3,21 +3,37 @@
3
3
  * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { IQueueStorage, JobStatus, JobStorageFormat } from "./IQueueStorage";
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
+ };
7
14
  export declare const IN_MEMORY_QUEUE_STORAGE: import("@workglow/util").ServiceToken<IQueueStorage<any, any>>;
8
15
  /**
9
16
  * In-memory implementation of a job queue that manages asynchronous tasks.
10
- * Supports job scheduling, status tracking, and result caching.
17
+ * Supports job scheduling, status tracking, result caching, and prefix-based filtering.
11
18
  */
12
19
  export declare class InMemoryQueueStorage<Input, Output> implements IQueueStorage<Input, Output> {
13
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>>;
14
25
  /**
15
26
  * Creates a new in-memory job queue
16
- * @param queue - Name of the queue
27
+ * @param queueName - Name of the queue
28
+ * @param options - Optional configuration including prefix filters
17
29
  */
18
- constructor(queueName: string);
30
+ constructor(queueName: string, options?: QueueStorageOptions);
19
31
  /** Internal array storing all jobs */
20
- jobQueue: JobStorageFormat<Input, Output>[];
32
+ jobQueue: Array<JobStorageFormat<Input, Output> & Record<string, unknown>>;
33
+ /**
34
+ * Checks if a job matches the current prefix values
35
+ */
36
+ private matchesPrefixes;
21
37
  /**
22
38
  * Returns a filtered and sorted list of pending jobs that are ready to run
23
39
  * Sorts by creation time to maintain FIFO order
@@ -35,17 +51,18 @@ export declare class InMemoryQueueStorage<Input, Output> implements IQueueStorag
35
51
  */
36
52
  get(id: unknown): Promise<JobStorageFormat<Input, Output> | undefined>;
37
53
  /**
38
- * Retrieves a slice of jobs from anywherethe queue.
54
+ * Retrieves a slice of jobs from the queue.
39
55
  * @param status - The status of the jobs to retrieve.
40
56
  * @param num - The number of jobs to retrieve.
41
57
  * @returns A promise that resolves to an array of jobs.
42
58
  */
43
- peek(status?: JobStatus, num?: number): Promise<JobStorageFormat<Input, Output>[]>;
59
+ peek(status?: JobStatus, num?: number): Promise<Array<JobStorageFormat<Input, Output>>>;
44
60
  /**
45
61
  * Retrieves the next available job that is ready to be processed
46
62
  * Updates the job status to PROCESSING before returning
63
+ * @param workerId - Optional worker ID to associate with the job
47
64
  */
48
- next(): Promise<JobStorageFormat<Input, Output> | undefined>;
65
+ next(workerId?: string): Promise<(JobStorageFormat<Input, Output> & Record<string, unknown>) | undefined>;
49
66
  /**
50
67
  * Retrieves the size of the queue for a given status
51
68
  * @param status - The status of the jobs to retrieve.
@@ -80,16 +97,16 @@ export declare class InMemoryQueueStorage<Input, Output> implements IQueueStorag
80
97
  */
81
98
  getByRunId(runId: string): Promise<Array<JobStorageFormat<Input, Output>>>;
82
99
  /**
83
- * Deletes all jobs from the queue.
100
+ * Deletes all jobs from the queue that match the current prefix values.
84
101
  */
85
102
  deleteAll(): Promise<void>;
86
103
  /**
87
- * Looks up cached output for a given and input
104
+ * Looks up cached output for a given input
88
105
  * Uses input fingerprinting for efficient matching
89
106
  * @param input - The input to look up the cached output for.
90
107
  * @returns The cached output or null if not found
91
108
  */
92
- outputForInput(input: Input): Promise<NonNullable<Output> | null>;
109
+ outputForInput(input: Input): Promise<Output | null>;
93
110
  /**
94
111
  * Deletes a job by its ID
95
112
  */
@@ -105,5 +122,21 @@ export declare class InMemoryQueueStorage<Input, Output> implements IQueueStorag
105
122
  * No-op for in-memory storage as it doesn't require database setup.
106
123
  */
107
124
  setupDatabase(): Promise<void>;
125
+ /**
126
+ * Checks if a job matches the specified prefix filter
127
+ * @param job - The job to check
128
+ * @param prefixFilter - The prefix filter (undefined = use instance prefixes, {} = no filter)
129
+ */
130
+ private matchesPrefixFilter;
131
+ /**
132
+ * Subscribes to changes in the queue.
133
+ * Since InMemory is both client and server, changes are detected via local events.
134
+ *
135
+ * @param callback - Function called when a change occurs
136
+ * @param options - Subscription options including prefix filter
137
+ * @returns Unsubscribe function
138
+ */
139
+ subscribeToChanges(callback: (change: QueueChangePayload<Input, Output>) => void, options?: QueueSubscribeOptions): () => void;
108
140
  }
141
+ export {};
109
142
  //# sourceMappingURL=InMemoryQueueStorage.d.ts.map
@@ -1 +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;IAEnD;;;OAGG;IACH,OAAO,CAAC,YAAY;IAQpB;;;OAGG;IACU,GAAG,CAAC,GAAG,EAAE,gBAAgB,CAAC,KAAK,EAAE,M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,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAC7D,OAAO,CAAC,EAAE,qBAAqB,GAC9B,MAAM,IAAI;CAkBd"}
@@ -4,8 +4,13 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { MigrationOptions } from "../util/IndexedDbTable";
7
- import { IQueueStorage, JobStatus, JobStorageFormat } from "./IQueueStorage";
7
+ import { IQueueStorage, JobStatus, JobStorageFormat, PrefixColumn, QueueChangePayload, QueueStorageOptions, QueueSubscribeOptions } from "./IQueueStorage";
8
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
+ }
9
14
  /**
10
15
  * IndexedDB implementation of a job queue storage.
11
16
  * Provides storage and retrieval for job execution states using IndexedDB.
@@ -13,9 +18,27 @@ export declare const INDEXED_DB_QUEUE_STORAGE: import("@workglow/util").ServiceT
13
18
  export declare class IndexedDbQueueStorage<Input, Output> implements IQueueStorage<Input, Output> {
14
19
  readonly queueName: string;
15
20
  private db;
16
- private tableName;
17
- private migrationOptions;
18
- constructor(queueName: string, migrationOptions?: MigrationOptions);
21
+ private readonly tableName;
22
+ private readonly migrationOptions;
23
+ /** The prefix column definitions */
24
+ protected readonly prefixes: readonly PrefixColumn[];
25
+ /** The prefix values for filtering */
26
+ protected readonly prefixValues: Readonly<Record<string, string | number>>;
27
+ /** Shared polling subscription manager */
28
+ private pollingManager;
29
+ constructor(queueName: string, options?: IndexedDbQueueStorageOptions);
30
+ /**
31
+ * Gets prefix column names for use in indexes
32
+ */
33
+ private getPrefixColumnNames;
34
+ /**
35
+ * Checks if a job matches the current prefix values
36
+ */
37
+ private matchesPrefixes;
38
+ /**
39
+ * Gets prefix values as an array in column order for index key construction
40
+ */
41
+ private getPrefixKeyValues;
19
42
  private getDb;
20
43
  /**
21
44
  * Sets up the IndexedDB database table with the required schema and indexes.
@@ -43,9 +66,10 @@ export declare class IndexedDbQueueStorage<Input, Output> implements IQueueStora
43
66
  peek(status?: JobStatus, num?: number): Promise<JobStorageFormat<Input, Output>[]>;
44
67
  /**
45
68
  * Retrieves the next job from the queue.
69
+ * @param workerId - Optional worker ID to associate with the job
46
70
  * @returns A promise that resolves to the next job or undefined if the queue is empty.
47
71
  */
48
- next(): Promise<JobStorageFormat<Input, Output> | undefined>;
72
+ next(workerId?: string): Promise<JobStorageFormat<Input, Output> | undefined>;
49
73
  /**
50
74
  * Retrieves the number of jobs in the queue.
51
75
  * Returns the count of jobs in the queue.
@@ -85,5 +109,46 @@ export declare class IndexedDbQueueStorage<Input, Output> implements IQueueStora
85
109
  * @param olderThanMs - Delete jobs completed more than this many milliseconds ago
86
110
  */
87
111
  deleteJobsByStatusAndAge(status: JobStatus, olderThanMs: number): Promise<void>;
112
+ /**
113
+ * Gets all jobs from the queue that match the current prefix values.
114
+ * Used internally for normal polling-based subscriptions (efficient - filters at DB level).
115
+ *
116
+ * @returns A promise that resolves to an array of jobs
117
+ */
118
+ private getAllJobs;
119
+ /**
120
+ * Gets all jobs from the queue with a custom prefix filter.
121
+ * Used for subscriptions with custom prefix filters (filters at DB level where possible).
122
+ *
123
+ * @param prefixFilter - The prefix values to filter by (empty object = all jobs)
124
+ * @returns A promise that resolves to an array of jobs
125
+ */
126
+ private getAllJobsWithFilter;
127
+ /**
128
+ * Checks if a prefix filter is custom (different from instance's prefixes).
129
+ */
130
+ private isCustomPrefixFilter;
131
+ /**
132
+ * Gets or creates the shared polling subscription manager for normal subscriptions.
133
+ * This ensures all normal subscriptions share a single polling loop per interval.
134
+ */
135
+ private getPollingManager;
136
+ /**
137
+ * Creates a dedicated polling subscription for custom prefix filters.
138
+ * This runs separately from the normal polling manager.
139
+ */
140
+ private subscribeWithCustomPrefixFilter;
141
+ /**
142
+ * Subscribes to changes in the queue.
143
+ * Uses polling since IndexedDB has no native cross-tab change notifications.
144
+ *
145
+ * Normal subscriptions (no custom prefix filter) share a single polling loop for efficiency.
146
+ * Custom prefix filter subscriptions get their own dedicated polling loop with DB-level filtering.
147
+ *
148
+ * @param callback - Function called when a change occurs
149
+ * @param options - Subscription options including polling interval and prefix filter
150
+ * @returns Unsubscribe function
151
+ */
152
+ subscribeToChanges(callback: (change: QueueChangePayload<Input, Output>) => void, options?: QueueSubscribeOptions): () => void;
88
153
  }
89
154
  //# sourceMappingURL=IndexedDbQueueStorage.d.ts.map
@@ -1 +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,EACjC,gBAAgB,GAAE,gBAAqB;YAM3B,KAAK;IAMnB;;;OAGG;IACU,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAiC3C;;;;OAIG;IACU,GAAG,CAAC,GAAG,EAAE,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IA2BxE;;;;OAIG;IACG,GAAG,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAY5E;;;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wB,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoC5F;;;;;OAKG;YACW,UAAU;IAiCxB;;;;;;OAMG;YACW,oBAAoB;IA8ClC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAuB5B;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IA2BzB;;;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;CAad"}
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { Pool } from "pg";
7
- import { IQueueStorage, JobStatus, JobStorageFormat } from "./IQueueStorage";
7
+ import { IQueueStorage, JobStatus, JobStorageFormat, PrefixColumn, QueueChangePayload, QueueStorageOptions, QueueSubscribeOptions } from "./IQueueStorage";
8
8
  export declare const POSTGRES_QUEUE_STORAGE: import("@workglow/util").ServiceToken<IQueueStorage<any, any>>;
9
9
  /**
10
10
  * PostgreSQL implementation of a job queue.
@@ -13,7 +13,37 @@ export declare const POSTGRES_QUEUE_STORAGE: import("@workglow/util").ServiceTok
13
13
  export declare class PostgresQueueStorage<Input, Output> implements IQueueStorage<Input, Output> {
14
14
  protected readonly db: Pool;
15
15
  protected readonly queueName: string;
16
- constructor(db: Pool, 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
+ /** Shared polling subscription manager */
23
+ private pollingManager;
24
+ constructor(db: Pool, queueName: string, options?: QueueStorageOptions);
25
+ /**
26
+ * Gets the SQL column type for a prefix column
27
+ */
28
+ private getPrefixColumnType;
29
+ /**
30
+ * Builds the prefix columns SQL for CREATE TABLE
31
+ */
32
+ private buildPrefixColumnsSql;
33
+ /**
34
+ * Builds prefix column names for use in queries
35
+ */
36
+ private getPrefixColumnNames;
37
+ /**
38
+ * Builds WHERE clause conditions for prefix filtering
39
+ * @param startParam - The starting parameter number for parameterized queries
40
+ * @returns Object with conditions string and parameter values
41
+ */
42
+ private buildPrefixWhereClause;
43
+ /**
44
+ * Gets prefix values as an array in column order
45
+ */
46
+ private getPrefixParamValues;
17
47
  setupDatabase(): Promise<void>;
18
48
  /**
19
49
  * Adds a new job to the queue.
@@ -26,18 +56,19 @@ export declare class PostgresQueueStorage<Input, Output> implements IQueueStorag
26
56
  * @param id - The ID of the job to retrieve
27
57
  * @returns The job if found, undefined otherwise
28
58
  */
29
- get(id: number): Promise<any>;
59
+ get(id: unknown): Promise<JobStorageFormat<Input, Output> | undefined>;
30
60
  /**
31
61
  * Retrieves a slice of jobs from the queue.
32
62
  * @param num - Maximum number of jobs to return
33
63
  * @returns An array of jobs
34
64
  */
35
- peek(status?: JobStatus, num?: number): Promise<JobStorageFormat<Input, Output>[]>;
65
+ peek(status?: JobStatus, num?: number): Promise<Array<JobStorageFormat<Input, Output>>>;
36
66
  /**
37
67
  * Retrieves the next available job that is ready to be processed.
68
+ * @param workerId - Optional worker ID to associate with the job
38
69
  * @returns The next job or undefined if no job is available
39
70
  */
40
- next(): Promise<JobStorageFormat<Input, Output>>;
71
+ next(workerId?: string): Promise<JobStorageFormat<Input, Output> | undefined>;
41
72
  /**
42
73
  * Retrieves the number of jobs in the queue with a specific status.
43
74
  * @param status - The status of the jobs to count
@@ -60,20 +91,20 @@ export declare class PostgresQueueStorage<Input, Output> implements IQueueStorag
60
91
  * Uses input fingerprinting for efficient matching
61
92
  * @returns The cached output or null if not found
62
93
  */
63
- outputForInput(input: Input): Promise<any>;
94
+ outputForInput(input: Input): Promise<Output | null>;
64
95
  /**
65
96
  * Aborts a job by setting its status to "ABORTING".
66
97
  * This method will signal the corresponding AbortController so that
67
98
  * the job's execute() method (if it supports an AbortSignal parameter)
68
99
  * can clean up and exit.
69
100
  */
70
- abort(jobId: number): Promise<void>;
101
+ abort(jobId: unknown): Promise<void>;
71
102
  /**
72
103
  * Retrieves all jobs for a given job run ID.
73
104
  * @param job_run_id - The ID of the job run to retrieve
74
105
  * @returns An array of jobs
75
106
  */
76
- getByRunId(job_run_id: string): Promise<any[]>;
107
+ getByRunId(job_run_id: string): Promise<Array<JobStorageFormat<Input, Output>>>;
77
108
  /**
78
109
  * Implements the abstract saveProgress method from JobQueue
79
110
  */
@@ -88,5 +119,46 @@ export declare class PostgresQueueStorage<Input, Output> implements IQueueStorag
88
119
  * @param olderThanMs - Delete jobs completed more than this many milliseconds ago
89
120
  */
90
121
  deleteJobsByStatusAndAge(status: JobStatus, olderThanMs: number): Promise<void>;
122
+ /**
123
+ * Gets all jobs from the queue that match the current prefix values.
124
+ * Used internally for normal polling-based subscriptions (efficient - filters at DB level).
125
+ *
126
+ * @returns A promise that resolves to an array of jobs
127
+ */
128
+ private getAllJobs;
129
+ /**
130
+ * Gets all jobs from the queue with a custom prefix filter.
131
+ * Used for subscriptions with custom prefix filters (filters at DB level).
132
+ *
133
+ * @param prefixFilter - The prefix values to filter by (empty object = all jobs)
134
+ * @returns A promise that resolves to an array of jobs
135
+ */
136
+ private getAllJobsWithFilter;
137
+ /**
138
+ * Checks if a prefix filter is custom (different from instance's prefixes).
139
+ */
140
+ private isCustomPrefixFilter;
141
+ /**
142
+ * Gets or creates the shared polling subscription manager for normal subscriptions.
143
+ * This ensures all normal subscriptions share a single polling loop per interval.
144
+ */
145
+ private getPollingManager;
146
+ /**
147
+ * Creates a dedicated polling subscription for custom prefix filters.
148
+ * This runs separately from the normal polling manager with DB-level filtering.
149
+ */
150
+ private subscribeWithCustomPrefixFilter;
151
+ /**
152
+ * Subscribes to changes in the queue.
153
+ * Uses polling since this PostgreSQL implementation doesn't use LISTEN/NOTIFY.
154
+ *
155
+ * Normal subscriptions (no custom prefix filter) share a single polling loop for efficiency.
156
+ * Custom prefix filter subscriptions get their own dedicated polling loop with DB-level filtering.
157
+ *
158
+ * @param callback - Function called when a change occurs
159
+ * @param options - Subscription options including polling interval and prefix filter
160
+ * @returns Unsubscribe function
161
+ */
162
+ subscribeToChanges(callback: (change: QueueChangePayload<Input, Output>) => void, options?: QueueSubscribeOptions): () => void;
91
163
  }
92
164
  //# sourceMappingURL=PostgresQueueStorage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PostgresQueueStorage.d.ts","sourceRoot":"","sources":["../../src/queue/PostgresQueueStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAE7E,eAAO,MAAM,sBAAsB,gEAElC,CAAC;AAIF;;;GAGG;AACH,qBAAa,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAE,YAAW,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC;IAEpF,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI;IAC3B,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM;gBADjB,EAAE,EAAE,IAAI,EACR,SAAS,EAAE,MAAM;IAGzB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAqD3C;;;;OAIG;IACU,GAAG,CAAC,GAAG,EAAE,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC;IAiDrD;;;;OAIG;IACU,GAAG,CAAC,EAAE,EAAE,MAAM;IAc3B;;;;OAIG;IACU,IAAI,CAAC,MAAM,GAAE,SAA6B,EAAE,GAAG,GAAE,MAAY;IAoB1E;;;OAGG;IACU,IAAI;IAyBjB;;;;OAIG;IACU,IAAI,CAAC,MAAM,YAAoB;IAa5C;;;;;OAKG;IACU,QAAQ,CAAC,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