@workglow/storage 0.2.27 → 0.2.29

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 (92) hide show
  1. package/dist/browser.d.ts +0 -10
  2. package/dist/browser.d.ts.map +1 -1
  3. package/dist/browser.js +406 -4207
  4. package/dist/browser.js.map +8 -24
  5. package/dist/bun.js +341 -7235
  6. package/dist/bun.js.map +8 -35
  7. package/dist/common-server.d.ts +0 -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 +341 -7236
  12. package/dist/node.js.map +8 -35
  13. package/package.json +5 -71
  14. package/dist/kv/IndexedDbKvStorage.d.ts +0 -27
  15. package/dist/kv/IndexedDbKvStorage.d.ts.map +0 -1
  16. package/dist/kv/PostgresKvStorage.d.ts +0 -28
  17. package/dist/kv/PostgresKvStorage.d.ts.map +0 -1
  18. package/dist/kv/SqliteKvStorage.d.ts +0 -28
  19. package/dist/kv/SqliteKvStorage.d.ts.map +0 -1
  20. package/dist/kv/SupabaseKvStorage.d.ts +0 -33
  21. package/dist/kv/SupabaseKvStorage.d.ts.map +0 -1
  22. package/dist/postgres/browser.d.ts +0 -32
  23. package/dist/postgres/browser.d.ts.map +0 -1
  24. package/dist/postgres/browser.js +0 -150
  25. package/dist/postgres/browser.js.map +0 -11
  26. package/dist/postgres/node-bun.d.ts +0 -26
  27. package/dist/postgres/node-bun.d.ts.map +0 -1
  28. package/dist/postgres/node-bun.js +0 -41
  29. package/dist/postgres/node-bun.js.map +0 -10
  30. package/dist/postgres/pglite-pool.d.ts +0 -21
  31. package/dist/postgres/pglite-pool.d.ts.map +0 -1
  32. package/dist/queue/IQueueStorage.d.ts +0 -229
  33. package/dist/queue/IQueueStorage.d.ts.map +0 -1
  34. package/dist/queue/InMemoryQueueStorage.d.ts +0 -149
  35. package/dist/queue/InMemoryQueueStorage.d.ts.map +0 -1
  36. package/dist/queue/IndexedDbQueueStorage.d.ts +0 -166
  37. package/dist/queue/IndexedDbQueueStorage.d.ts.map +0 -1
  38. package/dist/queue/PostgresQueueStorage.d.ts +0 -154
  39. package/dist/queue/PostgresQueueStorage.d.ts.map +0 -1
  40. package/dist/queue/SqliteQueueStorage.d.ts +0 -149
  41. package/dist/queue/SqliteQueueStorage.d.ts.map +0 -1
  42. package/dist/queue/SupabaseQueueStorage.d.ts +0 -195
  43. package/dist/queue/SupabaseQueueStorage.d.ts.map +0 -1
  44. package/dist/queue/TelemetryQueueStorage.d.ts +0 -33
  45. package/dist/queue/TelemetryQueueStorage.d.ts.map +0 -1
  46. package/dist/queue-limiter/IRateLimiterStorage.d.ts +0 -127
  47. package/dist/queue-limiter/IRateLimiterStorage.d.ts.map +0 -1
  48. package/dist/queue-limiter/InMemoryRateLimiterStorage.d.ts +0 -43
  49. package/dist/queue-limiter/InMemoryRateLimiterStorage.d.ts.map +0 -1
  50. package/dist/queue-limiter/IndexedDbRateLimiterStorage.d.ts +0 -79
  51. package/dist/queue-limiter/IndexedDbRateLimiterStorage.d.ts.map +0 -1
  52. package/dist/queue-limiter/PostgresRateLimiterStorage.d.ts +0 -57
  53. package/dist/queue-limiter/PostgresRateLimiterStorage.d.ts.map +0 -1
  54. package/dist/queue-limiter/SqliteRateLimiterStorage.d.ts +0 -62
  55. package/dist/queue-limiter/SqliteRateLimiterStorage.d.ts.map +0 -1
  56. package/dist/queue-limiter/SupabaseRateLimiterStorage.d.ts +0 -54
  57. package/dist/queue-limiter/SupabaseRateLimiterStorage.d.ts.map +0 -1
  58. package/dist/sqlite/browser.d.ts +0 -37
  59. package/dist/sqlite/browser.d.ts.map +0 -1
  60. package/dist/sqlite/browser.js +0 -125
  61. package/dist/sqlite/browser.js.map +0 -10
  62. package/dist/sqlite/bun.d.ts +0 -32
  63. package/dist/sqlite/bun.d.ts.map +0 -1
  64. package/dist/sqlite/bun.js +0 -84
  65. package/dist/sqlite/bun.js.map +0 -10
  66. package/dist/sqlite/canonical-api.d.ts +0 -34
  67. package/dist/sqlite/canonical-api.d.ts.map +0 -1
  68. package/dist/sqlite/node.d.ts +0 -34
  69. package/dist/sqlite/node.d.ts.map +0 -1
  70. package/dist/sqlite/node.js +0 -65
  71. package/dist/sqlite/node.js.map +0 -10
  72. package/dist/tabular/IndexedDbTabularStorage.d.ts +0 -199
  73. package/dist/tabular/IndexedDbTabularStorage.d.ts.map +0 -1
  74. package/dist/tabular/PostgresTabularStorage.d.ts +0 -196
  75. package/dist/tabular/PostgresTabularStorage.d.ts.map +0 -1
  76. package/dist/tabular/SqliteTabularStorage.d.ts +0 -167
  77. package/dist/tabular/SqliteTabularStorage.d.ts.map +0 -1
  78. package/dist/tabular/SupabaseTabularStorage.d.ts +0 -174
  79. package/dist/tabular/SupabaseTabularStorage.d.ts.map +0 -1
  80. package/dist/util/IndexedDbTable.d.ts +0 -40
  81. package/dist/util/IndexedDbTable.d.ts.map +0 -1
  82. package/dist/util/traced.d.ts +0 -10
  83. package/dist/util/traced.d.ts.map +0 -1
  84. package/dist/vector/IndexedDbVectorStorage.d.ts +0 -53
  85. package/dist/vector/IndexedDbVectorStorage.d.ts.map +0 -1
  86. package/dist/vector/PostgresVectorStorage.d.ts +0 -39
  87. package/dist/vector/PostgresVectorStorage.d.ts.map +0 -1
  88. package/dist/vector/SqliteAiVectorStorage.d.ts +0 -100
  89. package/dist/vector/SqliteAiVectorStorage.d.ts.map +0 -1
  90. package/dist/vector/SqliteVectorStorage.d.ts +0 -49
  91. package/dist/vector/SqliteVectorStorage.d.ts.map +0 -1
  92. package/src/queue/README.md +0 -41
@@ -1,127 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import type { PrefixColumn } from "../queue/IQueueStorage";
7
- export declare const RATE_LIMITER_STORAGE: import("@workglow/util").ServiceToken<IRateLimiterStorage>;
8
- /**
9
- * Whether a rate-limiter storage's state is shared across processes.
10
- *
11
- * - `"process"` — in-memory / per-process state. Multiple workers in the same
12
- * process share it, but separate processes do not.
13
- * - `"cluster"` — state lives in shared external storage (Postgres, Supabase,
14
- * etc.) visible to every process.
15
- */
16
- export type RateLimiterStorageScope = "process" | "cluster";
17
- /**
18
- * Options for configuring rate limiter storage with prefix filters.
19
- */
20
- export interface RateLimiterStorageOptions {
21
- /** The prefix column definitions for this storage */
22
- readonly prefixes?: readonly PrefixColumn[];
23
- /** The values for each prefix column */
24
- readonly prefixValues?: Readonly<Record<string, string | number>>;
25
- }
26
- /**
27
- * Record of a job execution for rate limiting tracking.
28
- */
29
- export interface ExecutionRecord {
30
- readonly id?: unknown;
31
- readonly queue_name: string;
32
- readonly executed_at: string;
33
- }
34
- /**
35
- * Record of the next available time for a queue.
36
- */
37
- export interface NextAvailableRecord {
38
- readonly queue_name: string;
39
- readonly next_available_at: string;
40
- }
41
- /**
42
- * Interface defining the storage operations for a rate limiter.
43
- * This separates the storage concerns from the rate limiting logic.
44
- */
45
- export interface IRateLimiterStorage {
46
- /**
47
- * Whether this storage is shared across processes. In-memory backends MUST
48
- * report `"process"`. Shared databases (Postgres, Supabase) report
49
- * `"cluster"`.
50
- */
51
- readonly scope: RateLimiterStorageScope;
52
- /**
53
- * Sets up the database schema and tables.
54
- * This method should be called before using the storage.
55
- * For production use, database setup should be done via migrations.
56
- */
57
- setupDatabase(): Promise<void>;
58
- /**
59
- * Atomic check-and-record. Inserts an execution row and returns the
60
- * inserted row's id iff BOTH (a) fewer than `maxExecutions` rows have
61
- * `executed_at > (now - windowMs)` AND (b) any persisted `nextAvailableAt`
62
- * is in the past or absent. Returns `null` without writing anything
63
- * otherwise.
64
- *
65
- * The returned id MUST be passed to {@link releaseExecution} to free the
66
- * slot — otherwise concurrent acquirers would race to delete the wrong
67
- * worker's row when one of them rolls back.
68
- *
69
- * Implementations MUST serialize concurrent callers (advisory locks,
70
- * `BEGIN IMMEDIATE`, per-key mutex, etc.) so the count-then-insert window
71
- * is uninterruptible.
72
- *
73
- * @param queueName - The name of the queue
74
- * @param maxExecutions - Max allowed executions in the window
75
- * @param windowMs - Window size in milliseconds
76
- * @returns the inserted row's id on success, or `null` on failure
77
- */
78
- tryReserveExecution(queueName: string, maxExecutions: number, windowMs: number): Promise<unknown | null>;
79
- /**
80
- * Release the execution row identified by `token` (the value previously
81
- * returned from {@link tryReserveExecution}). No-op if the row no longer
82
- * exists.
83
- *
84
- * Critical: implementations MUST delete by id, NOT by recency or position.
85
- * Two concurrent workers can hold tokens for different rows; deleting the
86
- * "most recent" row would release another worker's reservation.
87
- */
88
- releaseExecution(queueName: string, token: unknown): Promise<void>;
89
- /**
90
- * Records a job execution for rate limiting tracking.
91
- * @param queueName - The name of the queue
92
- */
93
- recordExecution(queueName: string): Promise<void>;
94
- /**
95
- * Gets the count of executions within a time window.
96
- * @param queueName - The name of the queue
97
- * @param windowStartTime - The start of the time window (ISO string)
98
- * @returns The count of executions within the window
99
- */
100
- getExecutionCount(queueName: string, windowStartTime: string): Promise<number>;
101
- /**
102
- * Gets the oldest execution time within the window, offset by a count.
103
- * Used to calculate when the rate limit will allow the next execution.
104
- * @param queueName - The name of the queue
105
- * @param offset - The offset (typically maxExecutions - 1)
106
- * @returns The execution time or undefined if not enough executions
107
- */
108
- getOldestExecutionAtOffset(queueName: string, offset: number): Promise<string | undefined>;
109
- /**
110
- * Gets the next available time for a queue.
111
- * @param queueName - The name of the queue
112
- * @returns The next available time or undefined if not set
113
- */
114
- getNextAvailableTime(queueName: string): Promise<string | undefined>;
115
- /**
116
- * Sets the next available time for a queue.
117
- * @param queueName - The name of the queue
118
- * @param nextAvailableAt - The next available time (ISO string)
119
- */
120
- setNextAvailableTime(queueName: string, nextAvailableAt: string): Promise<void>;
121
- /**
122
- * Clears all rate limit entries for a queue.
123
- * @param queueName - The name of the queue
124
- */
125
- clear(queueName: string): Promise<void>;
126
- }
127
- //# sourceMappingURL=IRateLimiterStorage.d.ts.map
@@ -1 +0,0 @@
1
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AM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnE;;;OAGG;IACH,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElD;;;;;OAKG;IACH,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE/E;;;;;;OAMG;IACH,0BAA0B,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAE3F;;;;OAIG;IACH,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAErE;;;;OAIG;IACH,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhF;;;OAGG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzC"}
@@ -1,43 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import { IRateLimiterStorage, RateLimiterStorageOptions, RateLimiterStorageScope } from "./IRateLimiterStorage";
7
- export declare const IN_MEMORY_RATE_LIMITER_STORAGE: import("@workglow/util").ServiceToken<IRateLimiterStorage>;
8
- /**
9
- * In-memory implementation of rate limiter storage.
10
- * Manages execution records and next available times for rate limiting.
11
- */
12
- export declare class InMemoryRateLimiterStorage implements IRateLimiterStorage {
13
- readonly scope: RateLimiterStorageScope;
14
- /** The prefix values for filtering */
15
- protected readonly prefixValues: Readonly<Record<string, string | number>>;
16
- /** Execution records keyed by a composite of prefix values and queue name */
17
- private readonly executions;
18
- /** Next available times keyed by a composite of prefix values and queue name */
19
- private readonly nextAvailableTimes;
20
- /**
21
- * Per-key promise chain used to serialize {@link tryReserveExecution} so
22
- * concurrent callers cannot both observe `count < max` before either
23
- * inserts. Each key's chain is replaced with the next pending operation
24
- * before the current one returns, giving FIFO mutex semantics.
25
- */
26
- private readonly reserveChains;
27
- constructor(options?: RateLimiterStorageOptions);
28
- /**
29
- * Creates a storage key from the queue name and prefix values.
30
- */
31
- private makeKey;
32
- setupDatabase(): Promise<void>;
33
- private withKeyLock;
34
- tryReserveExecution(queueName: string, maxExecutions: number, windowMs: number): Promise<unknown | null>;
35
- releaseExecution(queueName: string, token: unknown): Promise<void>;
36
- recordExecution(queueName: string): Promise<void>;
37
- getExecutionCount(queueName: string, windowStartTime: string): Promise<number>;
38
- getOldestExecutionAtOffset(queueName: string, offset: number): Promise<string | undefined>;
39
- getNextAvailableTime(queueName: string): Promise<string | undefined>;
40
- setNextAvailableTime(queueName: string, nextAvailableAt: string): Promise<void>;
41
- clear(queueName: string): Promise<void>;
42
- }
43
- //# sourceMappingURL=InMemoryRateLimiterStorage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InMemoryRateLimiterStorage.d.ts","sourceRoot":"","sources":["../../src/queue-limiter/InMemoryRateLimiterStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAE/B,eAAO,MAAM,8BAA8B,4DAE1C,CAAC;AAYF;;;GAGG;AACH,qBAAa,0BAA2B,YAAW,mBAAmB;IACpE,SAAgB,KAAK,EAAE,uBAAuB,CAAa;IAE3D,sCAAsC;IACtC,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;IAE3E,6EAA6E;IAC7E,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA4C;IAEvE,gFAAgF;IAChF,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAgC;IAEnE;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4C;IAE1E,YAAY,OAAO,CAAC,EAAE,yBAAyB,EAE9C;IAED;;OAEG;IACH,OAAO,CAAC,OAAO;IAQF,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAE1C;YAOa,WAAW;IAkBZ,mBAAmB,CAC9B,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAuBzB;IAEY,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAc9E;IAEY,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAU7D;IAEY,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAM1F;IAEY,0BAA0B,CACrC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAO7B;IAEY,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAKhF;IAEY,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAI3F;IAEY,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKnD;CACF"}
@@ -1,79 +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 type { PrefixColumn } from "../queue/IQueueStorage";
8
- import { IRateLimiterStorage, RateLimiterStorageOptions, RateLimiterStorageScope } from "./IRateLimiterStorage";
9
- export declare const INDEXED_DB_RATE_LIMITER_STORAGE: import("@workglow/util").ServiceToken<IRateLimiterStorage>;
10
- /**
11
- * Extended options for IndexedDB rate limiter storage including prefix support.
12
- */
13
- export interface IndexedDbRateLimiterStorageOptions extends RateLimiterStorageOptions, MigrationOptions {
14
- }
15
- /**
16
- * IndexedDB implementation of rate limiter storage.
17
- * Manages execution records and next available times for rate limiting.
18
- *
19
- * Atomicity is `"process"`-scoped (browser tab) and the `next_available_at`
20
- * pre-check inside {@link tryReserveExecution} runs in a separate IDB
21
- * transaction from the count-and-insert. See {@link tryReserveExecution} for
22
- * the full caveat — do not assume cross-store atomicity.
23
- */
24
- export declare class IndexedDbRateLimiterStorage implements IRateLimiterStorage {
25
- /**
26
- * `"process"` — IndexedDB is per-origin and shared across tabs but not across
27
- * processes (different machines, server processes). Within a single tab the
28
- * `readwrite` transaction below provides atomicity.
29
- */
30
- readonly scope: RateLimiterStorageScope;
31
- private executionDb;
32
- private nextAvailableDb;
33
- private readonly executionTableName;
34
- private readonly nextAvailableTableName;
35
- private readonly migrationOptions;
36
- /** The prefix column definitions */
37
- protected readonly prefixes: readonly PrefixColumn[];
38
- /** The prefix values for filtering */
39
- protected readonly prefixValues: Readonly<Record<string, string | number>>;
40
- constructor(options?: IndexedDbRateLimiterStorageOptions);
41
- /**
42
- * Gets prefix column names for use in indexes.
43
- */
44
- private getPrefixColumnNames;
45
- /**
46
- * Checks if a record matches the current prefix values.
47
- */
48
- private matchesPrefixes;
49
- /**
50
- * Gets prefix values as an array in column order for index key construction.
51
- */
52
- private getPrefixKeyValues;
53
- private getExecutionDb;
54
- private getNextAvailableDb;
55
- setupDatabase(): Promise<void>;
56
- /**
57
- * Atomically reserves an execution slot in IndexedDB.
58
- *
59
- * Atomicity caveat: this implementation only serializes the `count + insert`
60
- * pair (under a single `readwrite` IDB transaction over the executions
61
- * store). The `next_available_at` lookup is a soft pre-check performed
62
- * BEFORE the tx, because the executions and next-available object stores
63
- * live in separate `IDBDatabase` instances by design (one
64
- * `ensureIndexedDbTable` call each) and IDB transaction scope cannot cross
65
- * databases. This is acceptable for IndexedDB's `"process"` scope: rate-
66
- * limit overshoot from a stale next-available read is bounded by single-
67
- * tab serial execution, and the stricter count check is what protects the
68
- * primary maxExecutions invariant.
69
- */
70
- tryReserveExecution(queueName: string, maxExecutions: number, windowMs: number): Promise<unknown | null>;
71
- releaseExecution(queueName: string, token: unknown): Promise<void>;
72
- recordExecution(queueName: string): Promise<void>;
73
- getExecutionCount(queueName: string, windowStartTime: string): Promise<number>;
74
- getOldestExecutionAtOffset(queueName: string, offset: number): Promise<string | undefined>;
75
- getNextAvailableTime(queueName: string): Promise<string | undefined>;
76
- setNextAvailableTime(queueName: string, nextAvailableAt: string): Promise<void>;
77
- clear(queueName: string): Promise<void>;
78
- }
79
- //# sourceMappingURL=IndexedDbRateLimiterStorage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IndexedDbRateLimiterStorage.d.ts","sourceRoot":"","sources":["../../src/queue-limiter/IndexedDbRateLimiterStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAGL,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAE/B,eAAO,MAAM,+BAA+B,4DAE3C,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,kCACf,SAAQ,yBAAyB,EAAE,gBAAgB;CAAG;AAqBxD;;;;;;;;GAQG;AACH,qBAAa,2BAA4B,YAAW,mBAAmB;IACrE;;;;OAIG;IACH,SAAgB,KAAK,EAAE,uBAAuB,CAAa;IAC3D,OAAO,CAAC,WAAW,CAA0B;IAC7C,OAAO,CAAC,eAAe,CAA0B;IACjD,OAAO,CAAC,QAAQ,CAAC,k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EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA4B3F;IAEY,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA2CnD;CACF"}
@@ -1,57 +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 type { PrefixColumn } from "../queue/IQueueStorage";
8
- import { IRateLimiterStorage, RateLimiterStorageOptions, RateLimiterStorageScope } from "./IRateLimiterStorage";
9
- export declare const POSTGRES_RATE_LIMITER_STORAGE: import("@workglow/util").ServiceToken<IRateLimiterStorage>;
10
- /**
11
- * PostgreSQL implementation of rate limiter storage.
12
- * Manages execution records and next available times for rate limiting.
13
- */
14
- export declare class PostgresRateLimiterStorage implements IRateLimiterStorage {
15
- protected readonly db: Pool;
16
- readonly scope: RateLimiterStorageScope;
17
- /** The prefix column definitions */
18
- protected readonly prefixes: readonly PrefixColumn[];
19
- /** The prefix values for filtering */
20
- protected readonly prefixValues: Readonly<Record<string, string | number>>;
21
- /** The table name for execution tracking */
22
- protected readonly executionTableName: string;
23
- /** The table name for next available times */
24
- protected readonly nextAvailableTableName: string;
25
- constructor(db: Pool, options?: RateLimiterStorageOptions);
26
- /**
27
- * Gets the SQL column type for a prefix column.
28
- */
29
- private getPrefixColumnType;
30
- /**
31
- * Builds the prefix columns SQL for CREATE TABLE.
32
- */
33
- private buildPrefixColumnsSql;
34
- /**
35
- * Builds prefix column names for use in queries.
36
- */
37
- private getPrefixColumnNames;
38
- /**
39
- * Builds WHERE clause conditions for prefix filtering.
40
- * @param startParam - The starting parameter number for parameterized queries
41
- */
42
- private buildPrefixWhereClause;
43
- /**
44
- * Gets prefix values as an array in column order.
45
- */
46
- private getPrefixParamValues;
47
- setupDatabase(): Promise<void>;
48
- tryReserveExecution(queueName: string, maxExecutions: number, windowMs: number): Promise<unknown | null>;
49
- releaseExecution(queueName: string, token: unknown): Promise<void>;
50
- recordExecution(queueName: string): Promise<void>;
51
- getExecutionCount(queueName: string, windowStartTime: string): Promise<number>;
52
- getOldestExecutionAtOffset(queueName: string, offset: number): Promise<string | undefined>;
53
- getNextAvailableTime(queueName: string): Promise<string | undefined>;
54
- setNextAvailableTime(queueName: string, nextAvailableAt: string): Promise<void>;
55
- clear(queueName: string): Promise<void>;
56
- }
57
- //# sourceMappingURL=PostgresRateLimiterStorage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PostgresRateLimiterStorage.d.ts","sourceRoot":"","sources":["../../src/queue-limiter/PostgresRateLimiterStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAE/B,eAAO,MAAM,6BAA6B,4DAEzC,CAAC;AAEF;;;GAGG;AACH,qBAAa,0BAA2B,YAAW,mBAAmB;IAYlE,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI;IAX7B,SAAgB,KAAK,EAAE,uBAAuB,CAAa;IAC3D,oCAAoC;IACpC,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAC;IACrD,sCAAsC;IACtC,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;IAC3E,4CAA4C;IAC5C,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IAC9C,8CAA8C;IAC9C,SAAS,CAAC,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAC;IAElD,YACqB,EAAE,EAAE,IAAI,EAC3B,OAAO,CAAC,EAAE,yBAAyB,EAcpC;IAED;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAI3B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAS7B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAI5B;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAY9B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAIf,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CA+B1C;IAEY,mBAAmB,CAC9B,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAsIzB;IAEY,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAU9E;IAEY,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAkB7D;IAEY,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAa1F;IAEY,0BAA0B,CACrC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAiB7B;IAEY,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAehF;IAEY,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAwB3F;IAEY,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAWnD;CACF"}
@@ -1,62 +0,0 @@
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/storage/sqlite";
7
- import type { PrefixColumn } from "../queue/IQueueStorage";
8
- import { IRateLimiterStorage, RateLimiterStorageOptions, RateLimiterStorageScope } from "./IRateLimiterStorage";
9
- export declare const SQLITE_RATE_LIMITER_STORAGE: import("@workglow/util").ServiceToken<IRateLimiterStorage>;
10
- /**
11
- * SQLite implementation of rate limiter storage.
12
- * Manages execution records and next available times for rate limiting.
13
- */
14
- export declare class SqliteRateLimiterStorage implements IRateLimiterStorage {
15
- protected readonly db: Sqlite.Database;
16
- /**
17
- * `"process"` because a typical SQLite deployment uses a single-process
18
- * file. Multi-process SQLite (multiple worker processes opening the same
19
- * file) is not safe for rate limiting even with WAL — separate processes
20
- * can interleave between BEGIN IMMEDIATE acquisition retries.
21
- */
22
- readonly scope: RateLimiterStorageScope;
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
- /** The table name for execution tracking */
28
- protected readonly executionTableName: string;
29
- /** The table name for next available times */
30
- protected readonly nextAvailableTableName: string;
31
- constructor(db: Sqlite.Database, options?: RateLimiterStorageOptions);
32
- /**
33
- * Gets the SQL column type for a prefix column (SQLite uses TEXT for uuid).
34
- */
35
- private getPrefixColumnType;
36
- /**
37
- * Builds the prefix columns SQL for CREATE TABLE.
38
- */
39
- private buildPrefixColumnsSql;
40
- /**
41
- * Builds prefix column names for use in queries.
42
- */
43
- private getPrefixColumnNames;
44
- /**
45
- * Builds WHERE clause conditions for prefix filtering.
46
- */
47
- private buildPrefixWhereClause;
48
- /**
49
- * Gets prefix values as an array in column order.
50
- */
51
- private getPrefixParamValues;
52
- setupDatabase(): Promise<void>;
53
- tryReserveExecution(queueName: string, maxExecutions: number, windowMs: number): Promise<unknown | null>;
54
- releaseExecution(queueName: string, token: unknown): Promise<void>;
55
- recordExecution(queueName: string): Promise<void>;
56
- getExecutionCount(queueName: string, windowStartTime: string): Promise<number>;
57
- getOldestExecutionAtOffset(queueName: string, offset: number): Promise<string | undefined>;
58
- getNextAvailableTime(queueName: string): Promise<string | undefined>;
59
- setNextAvailableTime(queueName: string, nextAvailableAt: string): Promise<void>;
60
- clear(queueName: string): Promise<void>;
61
- }
62
- //# sourceMappingURL=SqliteRateLimiterStorage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SqliteRateLimiterStorage.d.ts","sourceRoot":"","sources":["../../src/queue-limiter/SqliteRateLimiterStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAE/B,eAAO,MAAM,2BAA2B,4DAEvC,CAAC;AAEF;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,mBAAmB;IAkBhE,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC,QAAQ;IAjBxC;;;;;OAKG;IACH,SAAgB,KAAK,EAAE,uBAAuB,CAAa;IAC3D,oCAAoC;IACpC,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAC;IACrD,sCAAsC;IACtC,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;IAC3E,4CAA4C;IAC5C,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IAC9C,8CAA8C;IAC9C,SAAS,CAAC,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAC;IAElD,YACqB,EAAE,EAAE,MAAM,CAAC,QAAQ,EACtC,OAAO,CAAC,EAAE,yBAAyB,EAcpC;IAED;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAI3B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAS7B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAI5B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAQ9B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAIf,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAyB1C;IAEY,mBAAmB,CAC9B,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAoDzB;IAEY,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAY9E;IAEY,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAa7D;IAEY,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAY1F;IAEY,0BAA0B,CACrC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAe7B;IAEY,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAahF;IAEY,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAc3F;IAEY,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUnD;CACF"}
@@ -1,54 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import { SupabaseClient } from "@supabase/supabase-js";
7
- import type { PrefixColumn } from "../queue/IQueueStorage";
8
- import { IRateLimiterStorage, RateLimiterStorageOptions, RateLimiterStorageScope } from "./IRateLimiterStorage";
9
- export declare const SUPABASE_RATE_LIMITER_STORAGE: import("@workglow/util").ServiceToken<IRateLimiterStorage>;
10
- /**
11
- * Supabase implementation of rate limiter storage.
12
- * Manages execution records and next available times for rate limiting.
13
- */
14
- export declare class SupabaseRateLimiterStorage implements IRateLimiterStorage {
15
- readonly scope: RateLimiterStorageScope;
16
- protected readonly client: SupabaseClient;
17
- protected readonly prefixes: readonly PrefixColumn[];
18
- protected readonly prefixValues: Readonly<Record<string, string | number>>;
19
- protected readonly executionTableName: string;
20
- protected readonly nextAvailableTableName: string;
21
- constructor(client: unknown, options?: RateLimiterStorageOptions);
22
- /**
23
- * Gets the SQL column type for a prefix column (Supabase supports UUID natively).
24
- */
25
- private getPrefixColumnType;
26
- /**
27
- * Builds the prefix columns SQL for CREATE TABLE.
28
- */
29
- private buildPrefixColumnsSql;
30
- /**
31
- * Builds prefix column names for use in queries.
32
- */
33
- private getPrefixColumnNames;
34
- /**
35
- * Applies prefix filters to a Supabase query builder.
36
- */
37
- private applyPrefixFilters;
38
- /**
39
- * Gets prefix values as an object for inserts.
40
- */
41
- private getPrefixInsertValues;
42
- setupDatabase(): Promise<void>;
43
- /** Stable function name derived from table name (Postgres identifiers ≤63 chars). */
44
- private atomicReserveFunctionName;
45
- tryReserveExecution(queueName: string, maxExecutions: number, windowMs: number): Promise<unknown | null>;
46
- releaseExecution(queueName: string, token: unknown): Promise<void>;
47
- recordExecution(queueName: string): Promise<void>;
48
- getExecutionCount(queueName: string, windowStartTime: string): Promise<number>;
49
- getOldestExecutionAtOffset(queueName: string, offset: number): Promise<string | undefined>;
50
- getNextAvailableTime(queueName: string): Promise<string | undefined>;
51
- setNextAvailableTime(queueName: string, nextAvailableAt: string): Promise<void>;
52
- clear(queueName: string): Promise<void>;
53
- }
54
- //# sourceMappingURL=SupabaseRateLimiterStorage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SupabaseRateLimiterStorage.d.ts","sourceRoot":"","sources":["../../src/queue-limiter/SupabaseRateLimiterStorage.ts"],"names":[],"mappings":"AAAA;;;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KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAa9E;IAEY,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAS7D;IAEY,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAa1F;IAEY,0BAA0B,CACrC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAe7B;IAEY,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAiBhF;IAEY,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAkB3F;IAEY,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAanD;CACF"}
@@ -1,37 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import type { SqliteApi } from "./canonical-api";
7
- export type { SqliteApi };
8
- /**
9
- * Loads and initializes the SQLite WASM module. Idempotent; call once (and await) before
10
- * `new Sqlite.Database()` (same contract as Node and Bun).
11
- */
12
- declare function initSqlite(): Promise<void>;
13
- /**
14
- * better-sqlite3 / {@link Sqlite.Database}–shaped wrapper around sqlite-wasm {@link WasmDatabase}.
15
- */
16
- export declare class BrowserDatabase implements SqliteApi.Database {
17
- private readonly inner;
18
- constructor(filename?: string);
19
- exec(sql: string): void;
20
- prepare<BindParameters extends unknown[] | Record<string, unknown> = unknown[], Result = unknown>(sql: string): SqliteApi.Statement<BindParameters, Result>;
21
- /**
22
- * Same contract as better-sqlite3 / Bun: returns a function that runs `fn` inside a single
23
- * SQL transaction (BEGIN → COMMIT or ROLLBACK).
24
- */
25
- transaction<T extends unknown[]>(fn: (...args: T) => void): (...args: T) => void;
26
- close(): void;
27
- loadExtension(_path: string, _entryPoint?: string): void;
28
- }
29
- export declare const Sqlite: {
30
- readonly init: typeof initSqlite;
31
- readonly Database: typeof BrowserDatabase;
32
- };
33
- /** Merged with {@link Sqlite} so `Sqlite.Database` works in type positions (not only as a value). */
34
- export declare namespace Sqlite {
35
- type Database = InstanceType<typeof BrowserDatabase>;
36
- }
37
- //# sourceMappingURL=browser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/sqlite/browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,YAAY,EAAE,SAAS,EAAE,CAAC;AAmB1B;;;GAGG;AACH,iBAAS,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAcnC;AA0DD;;GAEG;AACH,qBAAa,eAAgB,YAAW,SAAS,CAAC,QAAQ;IACxD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IAErC,YAAY,QAAQ,GAAE,MAAmB,EAGxC;IAED,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEtB;IAED,OAAO,CAAC,cAAc,SAAS,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,EAAE,EAAE,MAAM,GAAG,OAAO,EAC9F,GAAG,EAAE,MAAM,GACV,SAAS,CAAC,SAAS,CAAC,cAAc,EAAE,MAAM,CAAC,CAO7C;IAED;;;OAGG;IACH,WAAW,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI,CAe/E;IAED,KAAK,IAAI,IAAI,CAEZ;IAED,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAEvD;CACF;AAED,eAAO,MAAM,MAAM;aACjB,IAAI;aACJ,QAAQ;CACA,CAAC;AAEX,qGAAqG;AACrG,yBAAiB,MAAM,CAAC,CAAC;IACvB,KAAY,QAAQ,GAAG,YAAY,CAAC,OAAO,eAAe,CAAC,CAAC;CAC7D"}
@@ -1,125 +0,0 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined")
5
- return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
- // src/sqlite/browser.ts
10
- var wasmModule;
11
- var initPromise;
12
- function assertWasmLoaded() {
13
- if (!wasmModule) {
14
- throw new Error("SQLite is not ready. Await Sqlite.init() before using new Sqlite.Database().");
15
- }
16
- return wasmModule;
17
- }
18
- function initSqlite() {
19
- return initPromise ??= (async () => {
20
- if (wasmModule) {
21
- return;
22
- }
23
- try {
24
- const { default: sqlite3InitModule } = await import("@sqlite.org/sqlite-wasm");
25
- wasmModule = await sqlite3InitModule();
26
- } catch {
27
- throw new Error("@sqlite.org/sqlite-wasm is required for @workglow/storage/sqlite in the browser. Install: bun add @sqlite.org/sqlite-wasm");
28
- }
29
- })();
30
- }
31
-
32
- class BrowserStatement {
33
- stmt;
34
- db;
35
- capi;
36
- constructor(stmt, db, capi) {
37
- this.stmt = stmt;
38
- this.db = db;
39
- this.capi = capi;
40
- }
41
- run(...params) {
42
- this.stmt.reset(true);
43
- if (params.length > 0) {
44
- this.stmt.bind(params);
45
- }
46
- while (this.stmt.step()) {}
47
- const changes = Number(this.db.changes(false, true));
48
- const lastInsertRowid = this.capi.sqlite3_last_insert_rowid(this.db);
49
- this.stmt.reset(true);
50
- return { changes, lastInsertRowid };
51
- }
52
- get(...params) {
53
- this.stmt.reset(true);
54
- if (params.length > 0) {
55
- this.stmt.bind(params);
56
- }
57
- if (!this.stmt.step()) {
58
- this.stmt.reset(true);
59
- return;
60
- }
61
- const row = this.stmt.get({});
62
- this.stmt.reset(true);
63
- return row;
64
- }
65
- all(...params) {
66
- this.stmt.reset(true);
67
- if (params.length > 0) {
68
- this.stmt.bind(params);
69
- }
70
- const rows = [];
71
- while (this.stmt.step()) {
72
- rows.push(this.stmt.get({}));
73
- }
74
- this.stmt.reset(true);
75
- return rows;
76
- }
77
- finalize() {
78
- this.stmt.finalize();
79
- }
80
- }
81
-
82
- class BrowserDatabase {
83
- inner;
84
- constructor(filename = ":memory:") {
85
- const sqlite = assertWasmLoaded();
86
- this.inner = new sqlite.oo1.DB(filename);
87
- }
88
- exec(sql) {
89
- this.inner.exec(sql);
90
- }
91
- prepare(sql) {
92
- const sqlite = assertWasmLoaded();
93
- return new BrowserStatement(this.inner.prepare(sql), this.inner, sqlite.capi);
94
- }
95
- transaction(fn) {
96
- return (...args) => {
97
- this.exec("BEGIN");
98
- try {
99
- fn(...args);
100
- this.exec("COMMIT");
101
- } catch (err) {
102
- try {
103
- this.exec("ROLLBACK");
104
- } catch {}
105
- throw err;
106
- }
107
- };
108
- }
109
- close() {
110
- this.inner.close();
111
- }
112
- loadExtension(_path, _entryPoint) {
113
- throw new Error("SQLite loadExtension is not supported in the browser WASM build.");
114
- }
115
- }
116
- var Sqlite = {
117
- init: initSqlite,
118
- Database: BrowserDatabase
119
- };
120
- export {
121
- Sqlite,
122
- BrowserDatabase
123
- };
124
-
125
- //# debugId=76CD359554DB6B6164756E2164756E21
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/sqlite/browser.ts"],
4
- "sourcesContent": [
5
- "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type * as SqliteWasmPkg from \"@sqlite.org/sqlite-wasm\";\n\nimport type { SqliteApi } from \"./canonical-api\";\n\nexport type { SqliteApi };\n\ntype WasmInit = typeof SqliteWasmPkg.default;\ntype WasmSqliteModule = Awaited<ReturnType<WasmInit>>;\n\ntype WasmDatabaseCtor = WasmSqliteModule[\"oo1\"][\"DB\"];\ntype WasmDatabase = InstanceType<WasmDatabaseCtor>;\ntype WasmStatement = ReturnType<WasmDatabase[\"prepare\"]>;\n\nlet wasmModule: WasmSqliteModule | undefined;\nlet initPromise: Promise<void> | undefined;\n\nfunction assertWasmLoaded(): WasmSqliteModule {\n if (!wasmModule) {\n throw new Error(\"SQLite is not ready. Await Sqlite.init() before using new Sqlite.Database().\");\n }\n return wasmModule;\n}\n\n/**\n * Loads and initializes the SQLite WASM module. Idempotent; call once (and await) before\n * `new Sqlite.Database()` (same contract as Node and Bun).\n */\nfunction initSqlite(): Promise<void> {\n return (initPromise ??= (async () => {\n if (wasmModule) {\n return;\n }\n try {\n const { default: sqlite3InitModule } = await import(\"@sqlite.org/sqlite-wasm\");\n wasmModule = await sqlite3InitModule();\n } catch {\n throw new Error(\n \"@sqlite.org/sqlite-wasm is required for @workglow/storage/sqlite in the browser. Install: bun add @sqlite.org/sqlite-wasm\"\n );\n }\n })());\n}\n\nclass BrowserStatement<\n BindParameters extends unknown[] | Record<string, unknown> = unknown[],\n Result = unknown,\n> implements SqliteApi.Statement<BindParameters, Result> {\n constructor(\n private readonly stmt: WasmStatement,\n private readonly db: WasmDatabase,\n private readonly capi: WasmSqliteModule[\"capi\"]\n ) {}\n\n run(...params: unknown[]): SqliteApi.RunResult {\n this.stmt.reset(true);\n if (params.length > 0) {\n this.stmt.bind(params as never);\n }\n while (this.stmt.step()) {\n // drain result rows for statements that return data\n }\n const changes = Number(this.db.changes(false, true));\n const lastInsertRowid = this.capi.sqlite3_last_insert_rowid(this.db);\n this.stmt.reset(true);\n return { changes, lastInsertRowid };\n }\n\n get(...params: unknown[]): Result | undefined {\n this.stmt.reset(true);\n if (params.length > 0) {\n this.stmt.bind(params as never);\n }\n if (!this.stmt.step()) {\n this.stmt.reset(true);\n return undefined;\n }\n const row = this.stmt.get({});\n this.stmt.reset(true);\n return row as Result;\n }\n\n all(...params: unknown[]): Result[] {\n this.stmt.reset(true);\n if (params.length > 0) {\n this.stmt.bind(params as never);\n }\n const rows: Result[] = [];\n while (this.stmt.step()) {\n rows.push(this.stmt.get({}) as Result);\n }\n this.stmt.reset(true);\n return rows;\n }\n\n finalize(): void {\n this.stmt.finalize();\n }\n}\n\n/**\n * better-sqlite3 / {@link Sqlite.Database}–shaped wrapper around sqlite-wasm {@link WasmDatabase}.\n */\nexport class BrowserDatabase implements SqliteApi.Database {\n private readonly inner: WasmDatabase;\n\n constructor(filename: string = \":memory:\") {\n const sqlite = assertWasmLoaded();\n this.inner = new sqlite.oo1.DB(filename);\n }\n\n exec(sql: string): void {\n this.inner.exec(sql);\n }\n\n prepare<BindParameters extends unknown[] | Record<string, unknown> = unknown[], Result = unknown>(\n sql: string\n ): SqliteApi.Statement<BindParameters, Result> {\n const sqlite = assertWasmLoaded();\n return new BrowserStatement<BindParameters, Result>(\n this.inner.prepare(sql),\n this.inner,\n sqlite.capi\n );\n }\n\n /**\n * Same contract as better-sqlite3 / Bun: returns a function that runs `fn` inside a single\n * SQL transaction (BEGIN → COMMIT or ROLLBACK).\n */\n transaction<T extends unknown[]>(fn: (...args: T) => void): (...args: T) => void {\n return (...args: T) => {\n this.exec(\"BEGIN\");\n try {\n fn(...args);\n this.exec(\"COMMIT\");\n } catch (err) {\n try {\n this.exec(\"ROLLBACK\");\n } catch {\n // prefer the original error if rollback fails\n }\n throw err;\n }\n };\n }\n\n close(): void {\n this.inner.close();\n }\n\n loadExtension(_path: string, _entryPoint?: string): void {\n throw new Error(\"SQLite loadExtension is not supported in the browser WASM build.\");\n }\n}\n\nexport const Sqlite = {\n init: initSqlite,\n Database: BrowserDatabase,\n} as const;\n\n/** Merged with {@link Sqlite} so `Sqlite.Database` works in type positions (not only as a value). */\nexport namespace Sqlite {\n export type Database = InstanceType<typeof BrowserDatabase>;\n}\n"
6
- ],
7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