@lensjs/core 2.2.1 → 2.3.0

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 (88) hide show
  1. package/dist/abstracts/store.cjs +2 -0
  2. package/dist/abstracts/store.d.cts +1 -0
  3. package/dist/abstracts/store.d.ts +1 -0
  4. package/dist/abstracts/store.js +2 -0
  5. package/dist/core/lens.cjs +115 -23
  6. package/dist/core/lens.d.cts +3 -2
  7. package/dist/core/lens.d.ts +3 -2
  8. package/dist/core/lens.js +115 -23
  9. package/dist/{index-CMvlRWcQ.d.cts → index-CZsa0Zcm.d.ts} +3 -1
  10. package/dist/{index-CMvlRWcQ.d.ts → index-QmOJr0K-.d.cts} +3 -1
  11. package/dist/index.cjs +163 -28
  12. package/dist/index.d.cts +5 -2
  13. package/dist/index.d.ts +5 -2
  14. package/dist/index.js +162 -28
  15. package/dist/mixins/queued_store.cjs +113 -0
  16. package/dist/mixins/queued_store.d.cts +38 -0
  17. package/dist/mixins/queued_store.d.ts +38 -0
  18. package/dist/mixins/queued_store.js +78 -0
  19. package/dist/stores/better_sqlite.cjs +2 -0
  20. package/dist/stores/better_sqlite.js +2 -0
  21. package/dist/stores/index.cjs +94 -2
  22. package/dist/stores/index.d.cts +2 -0
  23. package/dist/stores/index.d.ts +2 -0
  24. package/dist/stores/index.js +92 -1
  25. package/dist/stores/queued_sqlite.cjs +278 -0
  26. package/dist/stores/queued_sqlite.d.cts +43 -0
  27. package/dist/stores/queued_sqlite.d.ts +43 -0
  28. package/dist/stores/queued_sqlite.js +245 -0
  29. package/dist/types/index.d.cts +14 -2
  30. package/dist/types/index.d.ts +14 -2
  31. package/dist/ui/assets/{CacheActionBadge-WGVr5yhe.js → CacheActionBadge-BB4uokI1.js} +1 -1
  32. package/dist/ui/assets/CacheEntriesTable-B8cUXhos.js +1 -0
  33. package/dist/ui/assets/CacheEntryContainer-WkdnGvnu.js +2 -0
  34. package/dist/ui/assets/CacheEntryDetails-BeZnoIpm.js +1 -0
  35. package/dist/ui/assets/CacheEntryDetailsContainer-DI0mEvpu.js +2 -0
  36. package/dist/ui/assets/ExceptionContainer-YNcR0F5U.js +2 -0
  37. package/dist/ui/assets/{ExceptionDetails-DX14YGmx.js → ExceptionDetails-BKHzv6hf.js} +1 -1
  38. package/dist/ui/assets/ExceptionDetailsContainer-CJHILjb3.js +2 -0
  39. package/dist/ui/assets/{ExceptionTable-Chiah5kT.js → ExceptionTable-DzBmQLLa.js} +1 -1
  40. package/dist/ui/assets/JsonViewer-D-KPN089.js +1 -0
  41. package/dist/ui/assets/{LoadMore-CosGy1fp.js → LoadMore-CLPR6Zd4.js} +1 -1
  42. package/dist/ui/assets/QueriesContainer-B_PmBkHR.js +2 -0
  43. package/dist/ui/assets/{QueryDetailsContainer-Dimuidq4.js → QueryDetailsContainer-Cqj3E6Dr.js} +16 -26
  44. package/dist/ui/assets/{QueryTable-BLpmWt7g.js → QueryTable-DmWdZSnJ.js} +1 -1
  45. package/dist/ui/assets/{RequestDetails-DeJofxSW.js → RequestDetails-CF338Kcv.js} +1 -1
  46. package/dist/ui/assets/{RequestDetailsContainer-BtDTKq1O.js → RequestDetailsContainer-aW4GLool.js} +2 -2
  47. package/dist/ui/assets/{RequestsContainer-CxIavrPj.js → RequestsContainer-DdLSvAbl.js} +2 -2
  48. package/dist/ui/assets/{RequetsTable-CUevs9X4.js → RequetsTable-Bdp_PhGU.js} +1 -1
  49. package/dist/ui/assets/StatusCode-C605nHvd.js +1 -0
  50. package/dist/ui/assets/TabbedDataViewer-ofhEq_Wj.js +2 -0
  51. package/dist/ui/assets/{Table-z_QSS7J8.js → Table-kak5sL5X.js} +1 -1
  52. package/dist/ui/assets/{columns-Bxz-DZCj.js → columns-BEyDhUNq.js} +1 -1
  53. package/dist/ui/assets/{columns-D0UC1pqC.js → columns-Bu5psHyp.js} +1 -1
  54. package/dist/ui/assets/{columns-DJaOm2Yg.js → columns-BvIUTkjN.js} +1 -1
  55. package/dist/ui/assets/copy-DzXuP4eO.js +11 -0
  56. package/dist/ui/assets/index-CsnKQ5Mh.css +1 -0
  57. package/dist/ui/assets/{index-CQJv-KV7.js → index-TW_-MgRG.js} +25 -25
  58. package/dist/ui/assets/{useCacheEntries-DWzLAzvE.js → useCacheEntries-Pvte_aNc.js} +1 -1
  59. package/dist/ui/assets/{useExceptions-BF0fHNek.js → useExceptions-P3cnURvN.js} +1 -1
  60. package/dist/ui/assets/{useLensApi-BEMg_OuP.js → useLensApi-BFdsfrzR.js} +1 -1
  61. package/dist/ui/assets/{useLoadMore-ClIkZ0Gw.js → useLoadMore-JCWak1Dg.js} +1 -1
  62. package/dist/ui/assets/{useQueries-C0vKfgzw.js → useQueries-CNquFtm0.js} +1 -1
  63. package/dist/ui/index.html +2 -2
  64. package/dist/utils/compose.cjs +32 -0
  65. package/dist/utils/compose.d.cts +11 -0
  66. package/dist/utils/compose.d.ts +11 -0
  67. package/dist/utils/compose.js +7 -0
  68. package/dist/utils/index.cjs +9 -0
  69. package/dist/utils/index.d.cts +3 -1
  70. package/dist/utils/index.d.ts +3 -1
  71. package/dist/utils/index.js +8 -0
  72. package/dist/watchers/index.cjs +45 -5
  73. package/dist/watchers/index.js +45 -5
  74. package/dist/watchers/request_watcher.cjs +45 -5
  75. package/dist/watchers/request_watcher.d.cts +12 -1
  76. package/dist/watchers/request_watcher.d.ts +12 -1
  77. package/dist/watchers/request_watcher.js +45 -5
  78. package/package.json +2 -1
  79. package/dist/ui/assets/CacheEntriesTable-txREHfFk.js +0 -1
  80. package/dist/ui/assets/CacheEntryContainer-BoeiVJN6.js +0 -2
  81. package/dist/ui/assets/CacheEntryDetails-DovbpPae.js +0 -1
  82. package/dist/ui/assets/CacheEntryDetailsContainer-DcmH8iqv.js +0 -2
  83. package/dist/ui/assets/ExceptionContainer-C0H0kKkb.js +0 -2
  84. package/dist/ui/assets/ExceptionDetailsContainer-CHAXdzwk.js +0 -2
  85. package/dist/ui/assets/QueriesContainer-CporgPyk.js +0 -2
  86. package/dist/ui/assets/StatusCode-D_bCVpUf.js +0 -1
  87. package/dist/ui/assets/TabbedDataViewer-CbZANxvH.js +0 -1
  88. package/dist/ui/assets/index-B2QCOgug.css +0 -1
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/mixins/queued_store.ts
31
+ var queued_store_exports = {};
32
+ __export(queued_store_exports, {
33
+ QueuedStore: () => QueuedStore
34
+ });
35
+ module.exports = __toCommonJS(queued_store_exports);
36
+ var import_denque = __toESM(require("denque"), 1);
37
+ function QueuedStore(Base) {
38
+ return class Queued extends Base {
39
+ queue;
40
+ processingInterval = null;
41
+ BATCH_SIZE;
42
+ PROCESS_INTERVAL_MS;
43
+ WARN_THRESHOLD;
44
+ PREALLOCATE;
45
+ constructor(...args) {
46
+ super(...args);
47
+ const config = args[0] || {};
48
+ this.BATCH_SIZE = config.batchSize ?? 100;
49
+ this.PROCESS_INTERVAL_MS = config.processIntervalMs ?? 100;
50
+ this.WARN_THRESHOLD = config.warnThreshold ?? 1e5;
51
+ this.PREALLOCATE = config.preallocate ?? true;
52
+ this.queue = this.PREALLOCATE ? new import_denque.default([], { capacity: this.WARN_THRESHOLD * 2 }) : new import_denque.default();
53
+ }
54
+ async initialize() {
55
+ if (super["initialize"]) {
56
+ await super["initialize"].call(this);
57
+ }
58
+ this.startProcessingQueue();
59
+ process.on("SIGINT", () => this.shutdown());
60
+ process.on("SIGTERM", () => this.shutdown());
61
+ }
62
+ async truncate() {
63
+ this.queue.clear();
64
+ if (super["truncate"]) {
65
+ await super["truncate"].call(this);
66
+ }
67
+ }
68
+ async save(entry) {
69
+ this.queue.push(entry);
70
+ if (this.queue.length > this.WARN_THRESHOLD) {
71
+ console.warn(`\u26A0\uFE0F LensJs Queue size very large: ${this.queue.length}`);
72
+ }
73
+ }
74
+ startProcessingQueue() {
75
+ if (this.processingInterval) clearInterval(this.processingInterval);
76
+ this.processingInterval = setInterval(
77
+ () => this.processQueue(),
78
+ this.PROCESS_INTERVAL_MS
79
+ );
80
+ }
81
+ async processQueue() {
82
+ if (this.queue.isEmpty()) return;
83
+ const batchSize = Math.min(
84
+ this.BATCH_SIZE,
85
+ Math.max(10, Math.floor(this.queue.length / 10))
86
+ );
87
+ const entriesToProcess = this.queue.remove(0, batchSize);
88
+ if (!entriesToProcess.length) return;
89
+ for (const entry of entriesToProcess) {
90
+ super["save"]?.call(this, entry).catch((error) => {
91
+ console.error("Error saving queued entry:", error);
92
+ });
93
+ }
94
+ }
95
+ async stopProcessingQueue() {
96
+ if (this.processingInterval) {
97
+ clearInterval(this.processingInterval);
98
+ this.processingInterval = null;
99
+ }
100
+ if (!this.queue.isEmpty()) {
101
+ await this.processQueue();
102
+ }
103
+ }
104
+ async shutdown() {
105
+ await this.stopProcessingQueue();
106
+ process.exit(0);
107
+ }
108
+ };
109
+ }
110
+ // Annotate the CommonJS export names for ESM import in node:
111
+ 0 && (module.exports = {
112
+ QueuedStore
113
+ });
@@ -0,0 +1,38 @@
1
+ import denque__default from 'denque';
2
+ import { Constructor, WatcherTypeEnum } from '../types/index.cjs';
3
+ import 'sql-formatter';
4
+
5
+ declare function QueuedStore<TBase extends Constructor>(Base: TBase): {
6
+ new (...args: any[]): {
7
+ [x: string]: any;
8
+ queue: denque__default<{
9
+ id?: string;
10
+ data: Record<string, any>;
11
+ minimal_data?: Record<string, any>;
12
+ type: WatcherTypeEnum;
13
+ timestamp?: string;
14
+ requestId?: string;
15
+ }>;
16
+ processingInterval: NodeJS.Timeout | null;
17
+ readonly BATCH_SIZE: number;
18
+ readonly PROCESS_INTERVAL_MS: number;
19
+ readonly WARN_THRESHOLD: number;
20
+ readonly PREALLOCATE: boolean;
21
+ initialize(): Promise<void>;
22
+ truncate(): Promise<void>;
23
+ save(entry: {
24
+ id?: string;
25
+ data: Record<string, any>;
26
+ minimal_data?: Record<string, any>;
27
+ type: WatcherTypeEnum;
28
+ timestamp?: string;
29
+ requestId?: string;
30
+ }): Promise<void>;
31
+ startProcessingQueue(): void;
32
+ processQueue(): Promise<void>;
33
+ stopProcessingQueue(): Promise<void>;
34
+ shutdown(): Promise<void>;
35
+ };
36
+ } & TBase;
37
+
38
+ export { QueuedStore };
@@ -0,0 +1,38 @@
1
+ import denque__default from 'denque';
2
+ import { Constructor, WatcherTypeEnum } from '../types/index.js';
3
+ import 'sql-formatter';
4
+
5
+ declare function QueuedStore<TBase extends Constructor>(Base: TBase): {
6
+ new (...args: any[]): {
7
+ [x: string]: any;
8
+ queue: denque__default<{
9
+ id?: string;
10
+ data: Record<string, any>;
11
+ minimal_data?: Record<string, any>;
12
+ type: WatcherTypeEnum;
13
+ timestamp?: string;
14
+ requestId?: string;
15
+ }>;
16
+ processingInterval: NodeJS.Timeout | null;
17
+ readonly BATCH_SIZE: number;
18
+ readonly PROCESS_INTERVAL_MS: number;
19
+ readonly WARN_THRESHOLD: number;
20
+ readonly PREALLOCATE: boolean;
21
+ initialize(): Promise<void>;
22
+ truncate(): Promise<void>;
23
+ save(entry: {
24
+ id?: string;
25
+ data: Record<string, any>;
26
+ minimal_data?: Record<string, any>;
27
+ type: WatcherTypeEnum;
28
+ timestamp?: string;
29
+ requestId?: string;
30
+ }): Promise<void>;
31
+ startProcessingQueue(): void;
32
+ processQueue(): Promise<void>;
33
+ stopProcessingQueue(): Promise<void>;
34
+ shutdown(): Promise<void>;
35
+ };
36
+ } & TBase;
37
+
38
+ export { QueuedStore };
@@ -0,0 +1,78 @@
1
+ // src/mixins/queued_store.ts
2
+ import Denque from "denque";
3
+ function QueuedStore(Base) {
4
+ return class Queued extends Base {
5
+ queue;
6
+ processingInterval = null;
7
+ BATCH_SIZE;
8
+ PROCESS_INTERVAL_MS;
9
+ WARN_THRESHOLD;
10
+ PREALLOCATE;
11
+ constructor(...args) {
12
+ super(...args);
13
+ const config = args[0] || {};
14
+ this.BATCH_SIZE = config.batchSize ?? 100;
15
+ this.PROCESS_INTERVAL_MS = config.processIntervalMs ?? 100;
16
+ this.WARN_THRESHOLD = config.warnThreshold ?? 1e5;
17
+ this.PREALLOCATE = config.preallocate ?? true;
18
+ this.queue = this.PREALLOCATE ? new Denque([], { capacity: this.WARN_THRESHOLD * 2 }) : new Denque();
19
+ }
20
+ async initialize() {
21
+ if (super["initialize"]) {
22
+ await super["initialize"].call(this);
23
+ }
24
+ this.startProcessingQueue();
25
+ process.on("SIGINT", () => this.shutdown());
26
+ process.on("SIGTERM", () => this.shutdown());
27
+ }
28
+ async truncate() {
29
+ this.queue.clear();
30
+ if (super["truncate"]) {
31
+ await super["truncate"].call(this);
32
+ }
33
+ }
34
+ async save(entry) {
35
+ this.queue.push(entry);
36
+ if (this.queue.length > this.WARN_THRESHOLD) {
37
+ console.warn(`\u26A0\uFE0F LensJs Queue size very large: ${this.queue.length}`);
38
+ }
39
+ }
40
+ startProcessingQueue() {
41
+ if (this.processingInterval) clearInterval(this.processingInterval);
42
+ this.processingInterval = setInterval(
43
+ () => this.processQueue(),
44
+ this.PROCESS_INTERVAL_MS
45
+ );
46
+ }
47
+ async processQueue() {
48
+ if (this.queue.isEmpty()) return;
49
+ const batchSize = Math.min(
50
+ this.BATCH_SIZE,
51
+ Math.max(10, Math.floor(this.queue.length / 10))
52
+ );
53
+ const entriesToProcess = this.queue.remove(0, batchSize);
54
+ if (!entriesToProcess.length) return;
55
+ for (const entry of entriesToProcess) {
56
+ super["save"]?.call(this, entry).catch((error) => {
57
+ console.error("Error saving queued entry:", error);
58
+ });
59
+ }
60
+ }
61
+ async stopProcessingQueue() {
62
+ if (this.processingInterval) {
63
+ clearInterval(this.processingInterval);
64
+ this.processingInterval = null;
65
+ }
66
+ if (!this.queue.isEmpty()) {
67
+ await this.processQueue();
68
+ }
69
+ }
70
+ async shutdown() {
71
+ await this.stopProcessingQueue();
72
+ process.exit(0);
73
+ }
74
+ };
75
+ }
76
+ export {
77
+ QueuedStore
78
+ };
@@ -36,6 +36,8 @@ module.exports = __toCommonJS(better_sqlite_exports);
36
36
 
37
37
  // src/abstracts/store.ts
38
38
  var Store = class {
39
+ constructor(...args) {
40
+ }
39
41
  getAllExceptions(_paginationParams) {
40
42
  return this.defaultMinimalPaginate();
41
43
  }
@@ -1,5 +1,7 @@
1
1
  // src/abstracts/store.ts
2
2
  var Store = class {
3
+ constructor(...args) {
4
+ }
3
5
  getAllExceptions(_paginationParams) {
4
6
  return this.defaultMinimalPaginate();
5
7
  }
@@ -30,12 +30,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/stores/index.ts
31
31
  var stores_exports = {};
32
32
  __export(stores_exports, {
33
- BetterSqliteStore: () => BetterSqliteStore
33
+ BetterSqliteStore: () => BetterSqliteStore,
34
+ QueuedSqliteStore: () => QueuedSqliteStore
34
35
  });
35
36
  module.exports = __toCommonJS(stores_exports);
36
37
 
37
38
  // src/abstracts/store.ts
38
39
  var Store = class {
40
+ constructor(...args) {
41
+ }
39
42
  getAllExceptions(_paginationParams) {
40
43
  return this.defaultMinimalPaginate();
41
44
  }
@@ -186,7 +189,96 @@ var BetterSqliteStore = class extends Store {
186
189
  return `SELECT id, minimal_data, type, created_at, lens_entry_id ${includeFullData ? ",data" : ""}`;
187
190
  }
188
191
  };
192
+
193
+ // src/mixins/queued_store.ts
194
+ var import_denque = __toESM(require("denque"), 1);
195
+ function QueuedStore(Base) {
196
+ return class Queued extends Base {
197
+ queue;
198
+ processingInterval = null;
199
+ BATCH_SIZE;
200
+ PROCESS_INTERVAL_MS;
201
+ WARN_THRESHOLD;
202
+ PREALLOCATE;
203
+ constructor(...args) {
204
+ super(...args);
205
+ const config = args[0] || {};
206
+ this.BATCH_SIZE = config.batchSize ?? 100;
207
+ this.PROCESS_INTERVAL_MS = config.processIntervalMs ?? 100;
208
+ this.WARN_THRESHOLD = config.warnThreshold ?? 1e5;
209
+ this.PREALLOCATE = config.preallocate ?? true;
210
+ this.queue = this.PREALLOCATE ? new import_denque.default([], { capacity: this.WARN_THRESHOLD * 2 }) : new import_denque.default();
211
+ }
212
+ async initialize() {
213
+ if (super["initialize"]) {
214
+ await super["initialize"].call(this);
215
+ }
216
+ this.startProcessingQueue();
217
+ process.on("SIGINT", () => this.shutdown());
218
+ process.on("SIGTERM", () => this.shutdown());
219
+ }
220
+ async truncate() {
221
+ this.queue.clear();
222
+ if (super["truncate"]) {
223
+ await super["truncate"].call(this);
224
+ }
225
+ }
226
+ async save(entry) {
227
+ this.queue.push(entry);
228
+ if (this.queue.length > this.WARN_THRESHOLD) {
229
+ console.warn(`\u26A0\uFE0F LensJs Queue size very large: ${this.queue.length}`);
230
+ }
231
+ }
232
+ startProcessingQueue() {
233
+ if (this.processingInterval) clearInterval(this.processingInterval);
234
+ this.processingInterval = setInterval(
235
+ () => this.processQueue(),
236
+ this.PROCESS_INTERVAL_MS
237
+ );
238
+ }
239
+ async processQueue() {
240
+ if (this.queue.isEmpty()) return;
241
+ const batchSize = Math.min(
242
+ this.BATCH_SIZE,
243
+ Math.max(10, Math.floor(this.queue.length / 10))
244
+ );
245
+ const entriesToProcess = this.queue.remove(0, batchSize);
246
+ if (!entriesToProcess.length) return;
247
+ for (const entry of entriesToProcess) {
248
+ super["save"]?.call(this, entry).catch((error) => {
249
+ console.error("Error saving queued entry:", error);
250
+ });
251
+ }
252
+ }
253
+ async stopProcessingQueue() {
254
+ if (this.processingInterval) {
255
+ clearInterval(this.processingInterval);
256
+ this.processingInterval = null;
257
+ }
258
+ if (!this.queue.isEmpty()) {
259
+ await this.processQueue();
260
+ }
261
+ }
262
+ async shutdown() {
263
+ await this.stopProcessingQueue();
264
+ process.exit(0);
265
+ }
266
+ };
267
+ }
268
+
269
+ // src/utils/compose.ts
270
+ function compose(superclass, ...mixins) {
271
+ return mixins.reduce((c, mixin) => mixin(c), superclass);
272
+ }
273
+
274
+ // src/stores/queued_sqlite.ts
275
+ var QueuedSqliteStore = class extends compose(
276
+ BetterSqliteStore,
277
+ QueuedStore
278
+ ) {
279
+ };
189
280
  // Annotate the CommonJS export names for ESM import in node:
190
281
  0 && (module.exports = {
191
- BetterSqliteStore
282
+ BetterSqliteStore,
283
+ QueuedSqliteStore
192
284
  });
@@ -1,5 +1,7 @@
1
1
  export { default as BetterSqliteStore } from './better_sqlite.cjs';
2
+ export { default as QueuedSqliteStore } from './queued_sqlite.cjs';
2
3
  import '../abstracts/store.cjs';
3
4
  import '../types/index.cjs';
4
5
  import 'sql-formatter';
5
6
  import 'libsql';
7
+ import 'denque';
@@ -1,5 +1,7 @@
1
1
  export { default as BetterSqliteStore } from './better_sqlite.js';
2
+ export { default as QueuedSqliteStore } from './queued_sqlite.js';
2
3
  import '../abstracts/store.js';
3
4
  import '../types/index.js';
4
5
  import 'sql-formatter';
5
6
  import 'libsql';
7
+ import 'denque';
@@ -1,5 +1,7 @@
1
1
  // src/abstracts/store.ts
2
2
  var Store = class {
3
+ constructor(...args) {
4
+ }
3
5
  getAllExceptions(_paginationParams) {
4
6
  return this.defaultMinimalPaginate();
5
7
  }
@@ -150,6 +152,95 @@ var BetterSqliteStore = class extends Store {
150
152
  return `SELECT id, minimal_data, type, created_at, lens_entry_id ${includeFullData ? ",data" : ""}`;
151
153
  }
152
154
  };
155
+
156
+ // src/mixins/queued_store.ts
157
+ import Denque from "denque";
158
+ function QueuedStore(Base) {
159
+ return class Queued extends Base {
160
+ queue;
161
+ processingInterval = null;
162
+ BATCH_SIZE;
163
+ PROCESS_INTERVAL_MS;
164
+ WARN_THRESHOLD;
165
+ PREALLOCATE;
166
+ constructor(...args) {
167
+ super(...args);
168
+ const config = args[0] || {};
169
+ this.BATCH_SIZE = config.batchSize ?? 100;
170
+ this.PROCESS_INTERVAL_MS = config.processIntervalMs ?? 100;
171
+ this.WARN_THRESHOLD = config.warnThreshold ?? 1e5;
172
+ this.PREALLOCATE = config.preallocate ?? true;
173
+ this.queue = this.PREALLOCATE ? new Denque([], { capacity: this.WARN_THRESHOLD * 2 }) : new Denque();
174
+ }
175
+ async initialize() {
176
+ if (super["initialize"]) {
177
+ await super["initialize"].call(this);
178
+ }
179
+ this.startProcessingQueue();
180
+ process.on("SIGINT", () => this.shutdown());
181
+ process.on("SIGTERM", () => this.shutdown());
182
+ }
183
+ async truncate() {
184
+ this.queue.clear();
185
+ if (super["truncate"]) {
186
+ await super["truncate"].call(this);
187
+ }
188
+ }
189
+ async save(entry) {
190
+ this.queue.push(entry);
191
+ if (this.queue.length > this.WARN_THRESHOLD) {
192
+ console.warn(`\u26A0\uFE0F LensJs Queue size very large: ${this.queue.length}`);
193
+ }
194
+ }
195
+ startProcessingQueue() {
196
+ if (this.processingInterval) clearInterval(this.processingInterval);
197
+ this.processingInterval = setInterval(
198
+ () => this.processQueue(),
199
+ this.PROCESS_INTERVAL_MS
200
+ );
201
+ }
202
+ async processQueue() {
203
+ if (this.queue.isEmpty()) return;
204
+ const batchSize = Math.min(
205
+ this.BATCH_SIZE,
206
+ Math.max(10, Math.floor(this.queue.length / 10))
207
+ );
208
+ const entriesToProcess = this.queue.remove(0, batchSize);
209
+ if (!entriesToProcess.length) return;
210
+ for (const entry of entriesToProcess) {
211
+ super["save"]?.call(this, entry).catch((error) => {
212
+ console.error("Error saving queued entry:", error);
213
+ });
214
+ }
215
+ }
216
+ async stopProcessingQueue() {
217
+ if (this.processingInterval) {
218
+ clearInterval(this.processingInterval);
219
+ this.processingInterval = null;
220
+ }
221
+ if (!this.queue.isEmpty()) {
222
+ await this.processQueue();
223
+ }
224
+ }
225
+ async shutdown() {
226
+ await this.stopProcessingQueue();
227
+ process.exit(0);
228
+ }
229
+ };
230
+ }
231
+
232
+ // src/utils/compose.ts
233
+ function compose(superclass, ...mixins) {
234
+ return mixins.reduce((c, mixin) => mixin(c), superclass);
235
+ }
236
+
237
+ // src/stores/queued_sqlite.ts
238
+ var QueuedSqliteStore = class extends compose(
239
+ BetterSqliteStore,
240
+ QueuedStore
241
+ ) {
242
+ };
153
243
  export {
154
- BetterSqliteStore
244
+ BetterSqliteStore,
245
+ QueuedSqliteStore
155
246
  };