@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.
- package/dist/abstracts/store.cjs +2 -0
- package/dist/abstracts/store.d.cts +1 -0
- package/dist/abstracts/store.d.ts +1 -0
- package/dist/abstracts/store.js +2 -0
- package/dist/core/lens.cjs +115 -23
- package/dist/core/lens.d.cts +3 -2
- package/dist/core/lens.d.ts +3 -2
- package/dist/core/lens.js +115 -23
- package/dist/{index-CMvlRWcQ.d.cts → index-CZsa0Zcm.d.ts} +3 -1
- package/dist/{index-CMvlRWcQ.d.ts → index-QmOJr0K-.d.cts} +3 -1
- package/dist/index.cjs +163 -28
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +162 -28
- package/dist/mixins/queued_store.cjs +113 -0
- package/dist/mixins/queued_store.d.cts +38 -0
- package/dist/mixins/queued_store.d.ts +38 -0
- package/dist/mixins/queued_store.js +78 -0
- package/dist/stores/better_sqlite.cjs +2 -0
- package/dist/stores/better_sqlite.js +2 -0
- package/dist/stores/index.cjs +94 -2
- package/dist/stores/index.d.cts +2 -0
- package/dist/stores/index.d.ts +2 -0
- package/dist/stores/index.js +92 -1
- package/dist/stores/queued_sqlite.cjs +278 -0
- package/dist/stores/queued_sqlite.d.cts +43 -0
- package/dist/stores/queued_sqlite.d.ts +43 -0
- package/dist/stores/queued_sqlite.js +245 -0
- package/dist/types/index.d.cts +14 -2
- package/dist/types/index.d.ts +14 -2
- package/dist/ui/assets/{CacheActionBadge-WGVr5yhe.js → CacheActionBadge-BB4uokI1.js} +1 -1
- package/dist/ui/assets/CacheEntriesTable-B8cUXhos.js +1 -0
- package/dist/ui/assets/CacheEntryContainer-WkdnGvnu.js +2 -0
- package/dist/ui/assets/CacheEntryDetails-BeZnoIpm.js +1 -0
- package/dist/ui/assets/CacheEntryDetailsContainer-DI0mEvpu.js +2 -0
- package/dist/ui/assets/ExceptionContainer-YNcR0F5U.js +2 -0
- package/dist/ui/assets/{ExceptionDetails-DX14YGmx.js → ExceptionDetails-BKHzv6hf.js} +1 -1
- package/dist/ui/assets/ExceptionDetailsContainer-CJHILjb3.js +2 -0
- package/dist/ui/assets/{ExceptionTable-Chiah5kT.js → ExceptionTable-DzBmQLLa.js} +1 -1
- package/dist/ui/assets/JsonViewer-D-KPN089.js +1 -0
- package/dist/ui/assets/{LoadMore-CosGy1fp.js → LoadMore-CLPR6Zd4.js} +1 -1
- package/dist/ui/assets/QueriesContainer-B_PmBkHR.js +2 -0
- package/dist/ui/assets/{QueryDetailsContainer-Dimuidq4.js → QueryDetailsContainer-Cqj3E6Dr.js} +16 -26
- package/dist/ui/assets/{QueryTable-BLpmWt7g.js → QueryTable-DmWdZSnJ.js} +1 -1
- package/dist/ui/assets/{RequestDetails-DeJofxSW.js → RequestDetails-CF338Kcv.js} +1 -1
- package/dist/ui/assets/{RequestDetailsContainer-BtDTKq1O.js → RequestDetailsContainer-aW4GLool.js} +2 -2
- package/dist/ui/assets/{RequestsContainer-CxIavrPj.js → RequestsContainer-DdLSvAbl.js} +2 -2
- package/dist/ui/assets/{RequetsTable-CUevs9X4.js → RequetsTable-Bdp_PhGU.js} +1 -1
- package/dist/ui/assets/StatusCode-C605nHvd.js +1 -0
- package/dist/ui/assets/TabbedDataViewer-ofhEq_Wj.js +2 -0
- package/dist/ui/assets/{Table-z_QSS7J8.js → Table-kak5sL5X.js} +1 -1
- package/dist/ui/assets/{columns-Bxz-DZCj.js → columns-BEyDhUNq.js} +1 -1
- package/dist/ui/assets/{columns-D0UC1pqC.js → columns-Bu5psHyp.js} +1 -1
- package/dist/ui/assets/{columns-DJaOm2Yg.js → columns-BvIUTkjN.js} +1 -1
- package/dist/ui/assets/copy-DzXuP4eO.js +11 -0
- package/dist/ui/assets/index-CsnKQ5Mh.css +1 -0
- package/dist/ui/assets/{index-CQJv-KV7.js → index-TW_-MgRG.js} +25 -25
- package/dist/ui/assets/{useCacheEntries-DWzLAzvE.js → useCacheEntries-Pvte_aNc.js} +1 -1
- package/dist/ui/assets/{useExceptions-BF0fHNek.js → useExceptions-P3cnURvN.js} +1 -1
- package/dist/ui/assets/{useLensApi-BEMg_OuP.js → useLensApi-BFdsfrzR.js} +1 -1
- package/dist/ui/assets/{useLoadMore-ClIkZ0Gw.js → useLoadMore-JCWak1Dg.js} +1 -1
- package/dist/ui/assets/{useQueries-C0vKfgzw.js → useQueries-CNquFtm0.js} +1 -1
- package/dist/ui/index.html +2 -2
- package/dist/utils/compose.cjs +32 -0
- package/dist/utils/compose.d.cts +11 -0
- package/dist/utils/compose.d.ts +11 -0
- package/dist/utils/compose.js +7 -0
- package/dist/utils/index.cjs +9 -0
- package/dist/utils/index.d.cts +3 -1
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.js +8 -0
- package/dist/watchers/index.cjs +45 -5
- package/dist/watchers/index.js +45 -5
- package/dist/watchers/request_watcher.cjs +45 -5
- package/dist/watchers/request_watcher.d.cts +12 -1
- package/dist/watchers/request_watcher.d.ts +12 -1
- package/dist/watchers/request_watcher.js +45 -5
- package/package.json +2 -1
- package/dist/ui/assets/CacheEntriesTable-txREHfFk.js +0 -1
- package/dist/ui/assets/CacheEntryContainer-BoeiVJN6.js +0 -2
- package/dist/ui/assets/CacheEntryDetails-DovbpPae.js +0 -1
- package/dist/ui/assets/CacheEntryDetailsContainer-DcmH8iqv.js +0 -2
- package/dist/ui/assets/ExceptionContainer-C0H0kKkb.js +0 -2
- package/dist/ui/assets/ExceptionDetailsContainer-CHAXdzwk.js +0 -2
- package/dist/ui/assets/QueriesContainer-CporgPyk.js +0 -2
- package/dist/ui/assets/StatusCode-D_bCVpUf.js +0 -1
- package/dist/ui/assets/TabbedDataViewer-CbZANxvH.js +0 -1
- package/dist/ui/assets/index-B2QCOgug.css +0 -1
package/dist/abstracts/store.cjs
CHANGED
package/dist/abstracts/store.js
CHANGED
package/dist/core/lens.cjs
CHANGED
|
@@ -204,6 +204,8 @@ var path2 = __toESM(require("path"), 1);
|
|
|
204
204
|
|
|
205
205
|
// src/abstracts/store.ts
|
|
206
206
|
var Store = class {
|
|
207
|
+
constructor(...args) {
|
|
208
|
+
}
|
|
207
209
|
getAllExceptions(_paginationParams) {
|
|
208
210
|
return this.defaultMinimalPaginate();
|
|
209
211
|
}
|
|
@@ -355,6 +357,94 @@ var BetterSqliteStore = class extends Store {
|
|
|
355
357
|
}
|
|
356
358
|
};
|
|
357
359
|
|
|
360
|
+
// src/mixins/queued_store.ts
|
|
361
|
+
var import_denque = __toESM(require("denque"), 1);
|
|
362
|
+
function QueuedStore(Base) {
|
|
363
|
+
return class Queued extends Base {
|
|
364
|
+
queue;
|
|
365
|
+
processingInterval = null;
|
|
366
|
+
BATCH_SIZE;
|
|
367
|
+
PROCESS_INTERVAL_MS;
|
|
368
|
+
WARN_THRESHOLD;
|
|
369
|
+
PREALLOCATE;
|
|
370
|
+
constructor(...args) {
|
|
371
|
+
super(...args);
|
|
372
|
+
const config = args[0] || {};
|
|
373
|
+
this.BATCH_SIZE = config.batchSize ?? 100;
|
|
374
|
+
this.PROCESS_INTERVAL_MS = config.processIntervalMs ?? 100;
|
|
375
|
+
this.WARN_THRESHOLD = config.warnThreshold ?? 1e5;
|
|
376
|
+
this.PREALLOCATE = config.preallocate ?? true;
|
|
377
|
+
this.queue = this.PREALLOCATE ? new import_denque.default([], { capacity: this.WARN_THRESHOLD * 2 }) : new import_denque.default();
|
|
378
|
+
}
|
|
379
|
+
async initialize() {
|
|
380
|
+
if (super["initialize"]) {
|
|
381
|
+
await super["initialize"].call(this);
|
|
382
|
+
}
|
|
383
|
+
this.startProcessingQueue();
|
|
384
|
+
process.on("SIGINT", () => this.shutdown());
|
|
385
|
+
process.on("SIGTERM", () => this.shutdown());
|
|
386
|
+
}
|
|
387
|
+
async truncate() {
|
|
388
|
+
this.queue.clear();
|
|
389
|
+
if (super["truncate"]) {
|
|
390
|
+
await super["truncate"].call(this);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
async save(entry) {
|
|
394
|
+
this.queue.push(entry);
|
|
395
|
+
if (this.queue.length > this.WARN_THRESHOLD) {
|
|
396
|
+
console.warn(`\u26A0\uFE0F LensJs Queue size very large: ${this.queue.length}`);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
startProcessingQueue() {
|
|
400
|
+
if (this.processingInterval) clearInterval(this.processingInterval);
|
|
401
|
+
this.processingInterval = setInterval(
|
|
402
|
+
() => this.processQueue(),
|
|
403
|
+
this.PROCESS_INTERVAL_MS
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
async processQueue() {
|
|
407
|
+
if (this.queue.isEmpty()) return;
|
|
408
|
+
const batchSize = Math.min(
|
|
409
|
+
this.BATCH_SIZE,
|
|
410
|
+
Math.max(10, Math.floor(this.queue.length / 10))
|
|
411
|
+
);
|
|
412
|
+
const entriesToProcess = this.queue.remove(0, batchSize);
|
|
413
|
+
if (!entriesToProcess.length) return;
|
|
414
|
+
for (const entry of entriesToProcess) {
|
|
415
|
+
super["save"]?.call(this, entry).catch((error) => {
|
|
416
|
+
console.error("Error saving queued entry:", error);
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
async stopProcessingQueue() {
|
|
421
|
+
if (this.processingInterval) {
|
|
422
|
+
clearInterval(this.processingInterval);
|
|
423
|
+
this.processingInterval = null;
|
|
424
|
+
}
|
|
425
|
+
if (!this.queue.isEmpty()) {
|
|
426
|
+
await this.processQueue();
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
async shutdown() {
|
|
430
|
+
await this.stopProcessingQueue();
|
|
431
|
+
process.exit(0);
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// src/utils/compose.ts
|
|
437
|
+
function compose(superclass, ...mixins) {
|
|
438
|
+
return mixins.reduce((c, mixin) => mixin(c), superclass);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// src/stores/queued_sqlite.ts
|
|
442
|
+
var QueuedSqliteStore = class extends compose(
|
|
443
|
+
BetterSqliteStore,
|
|
444
|
+
QueuedStore
|
|
445
|
+
) {
|
|
446
|
+
};
|
|
447
|
+
|
|
358
448
|
// src/utils/index.ts
|
|
359
449
|
var import_luxon = require("luxon");
|
|
360
450
|
var import_sql_formatter = require("sql-formatter");
|
|
@@ -381,6 +471,7 @@ var Lens = class {
|
|
|
381
471
|
static watchers = /* @__PURE__ */ new Map();
|
|
382
472
|
static store;
|
|
383
473
|
static adapter;
|
|
474
|
+
static config;
|
|
384
475
|
static watch(watcher) {
|
|
385
476
|
this.watchers.set(watcher.name, watcher);
|
|
386
477
|
return this;
|
|
@@ -390,22 +481,23 @@ var Lens = class {
|
|
|
390
481
|
return this;
|
|
391
482
|
}
|
|
392
483
|
static async start(config = {
|
|
393
|
-
|
|
484
|
+
path: "lens",
|
|
394
485
|
appName: "Lens",
|
|
395
486
|
enabled: true
|
|
396
487
|
}) {
|
|
397
488
|
if (!config.enabled) {
|
|
398
489
|
return;
|
|
399
490
|
}
|
|
400
|
-
|
|
491
|
+
this.config = config;
|
|
492
|
+
await this.bindContainerDeps();
|
|
401
493
|
let adapter = this.getAdapter();
|
|
402
494
|
adapter.setWatchers(Array.from(this.watchers.values())).setup();
|
|
403
495
|
const { apiRoutes } = this.getRoutes({
|
|
404
|
-
|
|
496
|
+
path: config.path
|
|
405
497
|
});
|
|
406
498
|
adapter.registerRoutes(apiRoutes);
|
|
407
499
|
const uiPath = this.getUiPath();
|
|
408
|
-
adapter.serveUI(uiPath, config.
|
|
500
|
+
adapter.serveUI(uiPath, config.path, getUiConfig());
|
|
409
501
|
}
|
|
410
502
|
static setStore(store) {
|
|
411
503
|
this.store = store;
|
|
@@ -428,7 +520,7 @@ var Lens = class {
|
|
|
428
520
|
const { __dirname: __dirname2 } = getMeta(import_meta.url);
|
|
429
521
|
return path2.resolve(this.normalizeDirName(__dirname2), "ui");
|
|
430
522
|
}
|
|
431
|
-
static getRoutes({
|
|
523
|
+
static getRoutes({ path: path3 }) {
|
|
432
524
|
const apiRoutes = [
|
|
433
525
|
{
|
|
434
526
|
method: "GET",
|
|
@@ -437,71 +529,71 @@ var Lens = class {
|
|
|
437
529
|
},
|
|
438
530
|
{
|
|
439
531
|
method: "GET",
|
|
440
|
-
path: `/${
|
|
532
|
+
path: `/${path3}/api/requests`,
|
|
441
533
|
handler: async (data) => await ApiController.getRequests(data)
|
|
442
534
|
},
|
|
443
535
|
{
|
|
444
536
|
method: "GET",
|
|
445
|
-
path: `/${
|
|
537
|
+
path: `/${path3}/api/requests/:id`,
|
|
446
538
|
handler: async (data) => await ApiController.getRequest(data)
|
|
447
539
|
},
|
|
448
540
|
{
|
|
449
541
|
method: "GET",
|
|
450
|
-
path: `/${
|
|
542
|
+
path: `/${path3}/api/queries`,
|
|
451
543
|
handler: async (data) => await ApiController.getQueries(data)
|
|
452
544
|
},
|
|
453
545
|
{
|
|
454
546
|
method: "GET",
|
|
455
|
-
path: `/${
|
|
547
|
+
path: `/${path3}/api/queries/:id`,
|
|
456
548
|
handler: async (data) => await ApiController.getQuery(data)
|
|
457
549
|
},
|
|
458
550
|
{
|
|
459
551
|
method: "GET",
|
|
460
|
-
path: `/${
|
|
552
|
+
path: `/${path3}/api/cache`,
|
|
461
553
|
handler: async (data) => await ApiController.getCacheEntries(data)
|
|
462
554
|
},
|
|
463
555
|
{
|
|
464
556
|
method: "GET",
|
|
465
|
-
path: `/${
|
|
557
|
+
path: `/${path3}/api/cache/:id`,
|
|
466
558
|
handler: async (data) => await ApiController.getCacheEntry(data)
|
|
467
559
|
},
|
|
468
560
|
{
|
|
469
561
|
method: "GET",
|
|
470
|
-
path: `/${
|
|
562
|
+
path: `/${path3}/api/exceptions`,
|
|
471
563
|
handler: async (data) => await ApiController.getExceptions(data)
|
|
472
564
|
},
|
|
473
565
|
{
|
|
474
566
|
method: "GET",
|
|
475
|
-
path: `/${
|
|
567
|
+
path: `/${path3}/api/exceptions/:id`,
|
|
476
568
|
handler: async (data) => await ApiController.getException(data)
|
|
477
569
|
},
|
|
478
570
|
{
|
|
479
571
|
method: "DELETE",
|
|
480
|
-
path: `/${
|
|
572
|
+
path: `/${path3}/api/truncate`,
|
|
481
573
|
handler: async () => await ApiController.truncate()
|
|
482
574
|
}
|
|
483
575
|
];
|
|
484
576
|
return { apiRoutes };
|
|
485
577
|
}
|
|
486
|
-
static async bindContainerDeps(
|
|
578
|
+
static async bindContainerDeps() {
|
|
487
579
|
const dbStore = await this.getStore();
|
|
488
580
|
Container.singleton("store", () => dbStore);
|
|
489
581
|
Container.singleton("uiConfig", () => {
|
|
490
582
|
return {
|
|
491
|
-
appName: config.appName,
|
|
492
|
-
path: `/${config.
|
|
583
|
+
appName: this.config.appName,
|
|
584
|
+
path: `/${this.config.path}`,
|
|
493
585
|
api: {
|
|
494
|
-
requests: `/${config.
|
|
495
|
-
queries: `/${config.
|
|
496
|
-
cache: `/${config.
|
|
497
|
-
exceptions: `/${config.
|
|
498
|
-
truncate: `/${config.
|
|
586
|
+
requests: `/${this.config.path}/api/requests`,
|
|
587
|
+
queries: `/${this.config.path}/api/queries`,
|
|
588
|
+
cache: `/${this.config.path}/api/cache`,
|
|
589
|
+
exceptions: `/${this.config.path}/api/exceptions`,
|
|
590
|
+
truncate: `/${this.config.path}/api/truncate`
|
|
499
591
|
}
|
|
500
592
|
};
|
|
501
593
|
});
|
|
502
594
|
}
|
|
503
595
|
static async getDefaultStore() {
|
|
504
|
-
const store = new
|
|
596
|
+
const store = new QueuedSqliteStore(this.config.storeQueueConfig);
|
|
505
597
|
await store.initialize();
|
|
506
598
|
return store;
|
|
507
599
|
}
|
package/dist/core/lens.d.cts
CHANGED
|
@@ -8,6 +8,7 @@ declare class Lens {
|
|
|
8
8
|
private static watchers;
|
|
9
9
|
private static store;
|
|
10
10
|
private static adapter;
|
|
11
|
+
private static config;
|
|
11
12
|
static watch(watcher: Watcher): typeof Lens;
|
|
12
13
|
static setWatchers(watchers: Watcher[]): typeof Lens;
|
|
13
14
|
static start(config?: LensConfig): Promise<void>;
|
|
@@ -16,8 +17,8 @@ declare class Lens {
|
|
|
16
17
|
static setAdapter(adapter: Adapter): typeof Lens;
|
|
17
18
|
static getAdapter(): Adapter;
|
|
18
19
|
static getUiPath(): string;
|
|
19
|
-
static getRoutes({
|
|
20
|
-
|
|
20
|
+
static getRoutes({ path }: {
|
|
21
|
+
path: string;
|
|
21
22
|
}): {
|
|
22
23
|
apiRoutes: ({
|
|
23
24
|
method: "GET";
|
package/dist/core/lens.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare class Lens {
|
|
|
8
8
|
private static watchers;
|
|
9
9
|
private static store;
|
|
10
10
|
private static adapter;
|
|
11
|
+
private static config;
|
|
11
12
|
static watch(watcher: Watcher): typeof Lens;
|
|
12
13
|
static setWatchers(watchers: Watcher[]): typeof Lens;
|
|
13
14
|
static start(config?: LensConfig): Promise<void>;
|
|
@@ -16,8 +17,8 @@ declare class Lens {
|
|
|
16
17
|
static setAdapter(adapter: Adapter): typeof Lens;
|
|
17
18
|
static getAdapter(): Adapter;
|
|
18
19
|
static getUiPath(): string;
|
|
19
|
-
static getRoutes({
|
|
20
|
-
|
|
20
|
+
static getRoutes({ path }: {
|
|
21
|
+
path: string;
|
|
21
22
|
}): {
|
|
22
23
|
apiRoutes: ({
|
|
23
24
|
method: "GET";
|
package/dist/core/lens.js
CHANGED
|
@@ -168,6 +168,8 @@ import * as path2 from "path";
|
|
|
168
168
|
|
|
169
169
|
// src/abstracts/store.ts
|
|
170
170
|
var Store = class {
|
|
171
|
+
constructor(...args) {
|
|
172
|
+
}
|
|
171
173
|
getAllExceptions(_paginationParams) {
|
|
172
174
|
return this.defaultMinimalPaginate();
|
|
173
175
|
}
|
|
@@ -319,6 +321,94 @@ var BetterSqliteStore = class extends Store {
|
|
|
319
321
|
}
|
|
320
322
|
};
|
|
321
323
|
|
|
324
|
+
// src/mixins/queued_store.ts
|
|
325
|
+
import Denque from "denque";
|
|
326
|
+
function QueuedStore(Base) {
|
|
327
|
+
return class Queued extends Base {
|
|
328
|
+
queue;
|
|
329
|
+
processingInterval = null;
|
|
330
|
+
BATCH_SIZE;
|
|
331
|
+
PROCESS_INTERVAL_MS;
|
|
332
|
+
WARN_THRESHOLD;
|
|
333
|
+
PREALLOCATE;
|
|
334
|
+
constructor(...args) {
|
|
335
|
+
super(...args);
|
|
336
|
+
const config = args[0] || {};
|
|
337
|
+
this.BATCH_SIZE = config.batchSize ?? 100;
|
|
338
|
+
this.PROCESS_INTERVAL_MS = config.processIntervalMs ?? 100;
|
|
339
|
+
this.WARN_THRESHOLD = config.warnThreshold ?? 1e5;
|
|
340
|
+
this.PREALLOCATE = config.preallocate ?? true;
|
|
341
|
+
this.queue = this.PREALLOCATE ? new Denque([], { capacity: this.WARN_THRESHOLD * 2 }) : new Denque();
|
|
342
|
+
}
|
|
343
|
+
async initialize() {
|
|
344
|
+
if (super["initialize"]) {
|
|
345
|
+
await super["initialize"].call(this);
|
|
346
|
+
}
|
|
347
|
+
this.startProcessingQueue();
|
|
348
|
+
process.on("SIGINT", () => this.shutdown());
|
|
349
|
+
process.on("SIGTERM", () => this.shutdown());
|
|
350
|
+
}
|
|
351
|
+
async truncate() {
|
|
352
|
+
this.queue.clear();
|
|
353
|
+
if (super["truncate"]) {
|
|
354
|
+
await super["truncate"].call(this);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
async save(entry) {
|
|
358
|
+
this.queue.push(entry);
|
|
359
|
+
if (this.queue.length > this.WARN_THRESHOLD) {
|
|
360
|
+
console.warn(`\u26A0\uFE0F LensJs Queue size very large: ${this.queue.length}`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
startProcessingQueue() {
|
|
364
|
+
if (this.processingInterval) clearInterval(this.processingInterval);
|
|
365
|
+
this.processingInterval = setInterval(
|
|
366
|
+
() => this.processQueue(),
|
|
367
|
+
this.PROCESS_INTERVAL_MS
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
async processQueue() {
|
|
371
|
+
if (this.queue.isEmpty()) return;
|
|
372
|
+
const batchSize = Math.min(
|
|
373
|
+
this.BATCH_SIZE,
|
|
374
|
+
Math.max(10, Math.floor(this.queue.length / 10))
|
|
375
|
+
);
|
|
376
|
+
const entriesToProcess = this.queue.remove(0, batchSize);
|
|
377
|
+
if (!entriesToProcess.length) return;
|
|
378
|
+
for (const entry of entriesToProcess) {
|
|
379
|
+
super["save"]?.call(this, entry).catch((error) => {
|
|
380
|
+
console.error("Error saving queued entry:", error);
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
async stopProcessingQueue() {
|
|
385
|
+
if (this.processingInterval) {
|
|
386
|
+
clearInterval(this.processingInterval);
|
|
387
|
+
this.processingInterval = null;
|
|
388
|
+
}
|
|
389
|
+
if (!this.queue.isEmpty()) {
|
|
390
|
+
await this.processQueue();
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
async shutdown() {
|
|
394
|
+
await this.stopProcessingQueue();
|
|
395
|
+
process.exit(0);
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// src/utils/compose.ts
|
|
401
|
+
function compose(superclass, ...mixins) {
|
|
402
|
+
return mixins.reduce((c, mixin) => mixin(c), superclass);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// src/stores/queued_sqlite.ts
|
|
406
|
+
var QueuedSqliteStore = class extends compose(
|
|
407
|
+
BetterSqliteStore,
|
|
408
|
+
QueuedStore
|
|
409
|
+
) {
|
|
410
|
+
};
|
|
411
|
+
|
|
322
412
|
// src/utils/index.ts
|
|
323
413
|
import { DateTime } from "luxon";
|
|
324
414
|
import { format } from "sql-formatter";
|
|
@@ -344,6 +434,7 @@ var Lens = class {
|
|
|
344
434
|
static watchers = /* @__PURE__ */ new Map();
|
|
345
435
|
static store;
|
|
346
436
|
static adapter;
|
|
437
|
+
static config;
|
|
347
438
|
static watch(watcher) {
|
|
348
439
|
this.watchers.set(watcher.name, watcher);
|
|
349
440
|
return this;
|
|
@@ -353,22 +444,23 @@ var Lens = class {
|
|
|
353
444
|
return this;
|
|
354
445
|
}
|
|
355
446
|
static async start(config = {
|
|
356
|
-
|
|
447
|
+
path: "lens",
|
|
357
448
|
appName: "Lens",
|
|
358
449
|
enabled: true
|
|
359
450
|
}) {
|
|
360
451
|
if (!config.enabled) {
|
|
361
452
|
return;
|
|
362
453
|
}
|
|
363
|
-
|
|
454
|
+
this.config = config;
|
|
455
|
+
await this.bindContainerDeps();
|
|
364
456
|
let adapter = this.getAdapter();
|
|
365
457
|
adapter.setWatchers(Array.from(this.watchers.values())).setup();
|
|
366
458
|
const { apiRoutes } = this.getRoutes({
|
|
367
|
-
|
|
459
|
+
path: config.path
|
|
368
460
|
});
|
|
369
461
|
adapter.registerRoutes(apiRoutes);
|
|
370
462
|
const uiPath = this.getUiPath();
|
|
371
|
-
adapter.serveUI(uiPath, config.
|
|
463
|
+
adapter.serveUI(uiPath, config.path, getUiConfig());
|
|
372
464
|
}
|
|
373
465
|
static setStore(store) {
|
|
374
466
|
this.store = store;
|
|
@@ -391,7 +483,7 @@ var Lens = class {
|
|
|
391
483
|
const { __dirname: __dirname2 } = getMeta(import.meta.url);
|
|
392
484
|
return path2.resolve(this.normalizeDirName(__dirname2), "ui");
|
|
393
485
|
}
|
|
394
|
-
static getRoutes({
|
|
486
|
+
static getRoutes({ path: path3 }) {
|
|
395
487
|
const apiRoutes = [
|
|
396
488
|
{
|
|
397
489
|
method: "GET",
|
|
@@ -400,71 +492,71 @@ var Lens = class {
|
|
|
400
492
|
},
|
|
401
493
|
{
|
|
402
494
|
method: "GET",
|
|
403
|
-
path: `/${
|
|
495
|
+
path: `/${path3}/api/requests`,
|
|
404
496
|
handler: async (data) => await ApiController.getRequests(data)
|
|
405
497
|
},
|
|
406
498
|
{
|
|
407
499
|
method: "GET",
|
|
408
|
-
path: `/${
|
|
500
|
+
path: `/${path3}/api/requests/:id`,
|
|
409
501
|
handler: async (data) => await ApiController.getRequest(data)
|
|
410
502
|
},
|
|
411
503
|
{
|
|
412
504
|
method: "GET",
|
|
413
|
-
path: `/${
|
|
505
|
+
path: `/${path3}/api/queries`,
|
|
414
506
|
handler: async (data) => await ApiController.getQueries(data)
|
|
415
507
|
},
|
|
416
508
|
{
|
|
417
509
|
method: "GET",
|
|
418
|
-
path: `/${
|
|
510
|
+
path: `/${path3}/api/queries/:id`,
|
|
419
511
|
handler: async (data) => await ApiController.getQuery(data)
|
|
420
512
|
},
|
|
421
513
|
{
|
|
422
514
|
method: "GET",
|
|
423
|
-
path: `/${
|
|
515
|
+
path: `/${path3}/api/cache`,
|
|
424
516
|
handler: async (data) => await ApiController.getCacheEntries(data)
|
|
425
517
|
},
|
|
426
518
|
{
|
|
427
519
|
method: "GET",
|
|
428
|
-
path: `/${
|
|
520
|
+
path: `/${path3}/api/cache/:id`,
|
|
429
521
|
handler: async (data) => await ApiController.getCacheEntry(data)
|
|
430
522
|
},
|
|
431
523
|
{
|
|
432
524
|
method: "GET",
|
|
433
|
-
path: `/${
|
|
525
|
+
path: `/${path3}/api/exceptions`,
|
|
434
526
|
handler: async (data) => await ApiController.getExceptions(data)
|
|
435
527
|
},
|
|
436
528
|
{
|
|
437
529
|
method: "GET",
|
|
438
|
-
path: `/${
|
|
530
|
+
path: `/${path3}/api/exceptions/:id`,
|
|
439
531
|
handler: async (data) => await ApiController.getException(data)
|
|
440
532
|
},
|
|
441
533
|
{
|
|
442
534
|
method: "DELETE",
|
|
443
|
-
path: `/${
|
|
535
|
+
path: `/${path3}/api/truncate`,
|
|
444
536
|
handler: async () => await ApiController.truncate()
|
|
445
537
|
}
|
|
446
538
|
];
|
|
447
539
|
return { apiRoutes };
|
|
448
540
|
}
|
|
449
|
-
static async bindContainerDeps(
|
|
541
|
+
static async bindContainerDeps() {
|
|
450
542
|
const dbStore = await this.getStore();
|
|
451
543
|
Container.singleton("store", () => dbStore);
|
|
452
544
|
Container.singleton("uiConfig", () => {
|
|
453
545
|
return {
|
|
454
|
-
appName: config.appName,
|
|
455
|
-
path: `/${config.
|
|
546
|
+
appName: this.config.appName,
|
|
547
|
+
path: `/${this.config.path}`,
|
|
456
548
|
api: {
|
|
457
|
-
requests: `/${config.
|
|
458
|
-
queries: `/${config.
|
|
459
|
-
cache: `/${config.
|
|
460
|
-
exceptions: `/${config.
|
|
461
|
-
truncate: `/${config.
|
|
549
|
+
requests: `/${this.config.path}/api/requests`,
|
|
550
|
+
queries: `/${this.config.path}/api/queries`,
|
|
551
|
+
cache: `/${this.config.path}/api/cache`,
|
|
552
|
+
exceptions: `/${this.config.path}/api/exceptions`,
|
|
553
|
+
truncate: `/${this.config.path}/api/truncate`
|
|
462
554
|
}
|
|
463
555
|
};
|
|
464
556
|
});
|
|
465
557
|
}
|
|
466
558
|
static async getDefaultStore() {
|
|
467
|
-
const store = new
|
|
559
|
+
const store = new QueuedSqliteStore(this.config.storeQueueConfig);
|
|
468
560
|
await store.initialize();
|
|
469
561
|
return store;
|
|
470
562
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SqlLanguage } from 'sql-formatter';
|
|
2
|
+
import { compose } from './utils/compose.js';
|
|
2
3
|
|
|
3
4
|
declare const generateRandomUuid: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
4
5
|
/**
|
|
@@ -24,6 +25,7 @@ declare function shouldIgnoreCurrentPath(path: string, ignoredPaths: RegExp[], o
|
|
|
24
25
|
declare function prettyHrTime(hrtime: [number, number], verbose?: boolean): string;
|
|
25
26
|
declare function normalizePath(path: string): string;
|
|
26
27
|
|
|
28
|
+
declare const index_compose: typeof compose;
|
|
27
29
|
declare const index_formatSqlQuery: typeof formatSqlQuery;
|
|
28
30
|
declare const index_generateRandomUuid: typeof generateRandomUuid;
|
|
29
31
|
declare const index_getMeta: typeof getMeta;
|
|
@@ -35,7 +37,7 @@ declare const index_prettyHrTime: typeof prettyHrTime;
|
|
|
35
37
|
declare const index_shouldIgnoreCurrentPath: typeof shouldIgnoreCurrentPath;
|
|
36
38
|
declare const index_stripBeforeAssetsPath: typeof stripBeforeAssetsPath;
|
|
37
39
|
declare namespace index {
|
|
38
|
-
export { index_formatSqlQuery as formatSqlQuery, index_generateRandomUuid as generateRandomUuid, index_getMeta as getMeta, index_interpolateQuery as interpolateQuery, index_isStaticFile as isStaticFile, index_normalizePath as normalizePath, index_prepareIgnoredPaths as prepareIgnoredPaths, index_prettyHrTime as prettyHrTime, index_shouldIgnoreCurrentPath as shouldIgnoreCurrentPath, index_stripBeforeAssetsPath as stripBeforeAssetsPath };
|
|
40
|
+
export { index_compose as compose, index_formatSqlQuery as formatSqlQuery, index_generateRandomUuid as generateRandomUuid, index_getMeta as getMeta, index_interpolateQuery as interpolateQuery, index_isStaticFile as isStaticFile, index_normalizePath as normalizePath, index_prepareIgnoredPaths as prepareIgnoredPaths, index_prettyHrTime as prettyHrTime, index_shouldIgnoreCurrentPath as shouldIgnoreCurrentPath, index_stripBeforeAssetsPath as stripBeforeAssetsPath };
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
export { interpolateQuery as a, getMeta as b, isStaticFile as c, shouldIgnoreCurrentPath as d, prettyHrTime as e, formatSqlQuery as f, generateRandomUuid as g, index as i, normalizePath as n, prepareIgnoredPaths as p, stripBeforeAssetsPath as s };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SqlLanguage } from 'sql-formatter';
|
|
2
|
+
import { compose } from './utils/compose.cjs';
|
|
2
3
|
|
|
3
4
|
declare const generateRandomUuid: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
4
5
|
/**
|
|
@@ -24,6 +25,7 @@ declare function shouldIgnoreCurrentPath(path: string, ignoredPaths: RegExp[], o
|
|
|
24
25
|
declare function prettyHrTime(hrtime: [number, number], verbose?: boolean): string;
|
|
25
26
|
declare function normalizePath(path: string): string;
|
|
26
27
|
|
|
28
|
+
declare const index_compose: typeof compose;
|
|
27
29
|
declare const index_formatSqlQuery: typeof formatSqlQuery;
|
|
28
30
|
declare const index_generateRandomUuid: typeof generateRandomUuid;
|
|
29
31
|
declare const index_getMeta: typeof getMeta;
|
|
@@ -35,7 +37,7 @@ declare const index_prettyHrTime: typeof prettyHrTime;
|
|
|
35
37
|
declare const index_shouldIgnoreCurrentPath: typeof shouldIgnoreCurrentPath;
|
|
36
38
|
declare const index_stripBeforeAssetsPath: typeof stripBeforeAssetsPath;
|
|
37
39
|
declare namespace index {
|
|
38
|
-
export { index_formatSqlQuery as formatSqlQuery, index_generateRandomUuid as generateRandomUuid, index_getMeta as getMeta, index_interpolateQuery as interpolateQuery, index_isStaticFile as isStaticFile, index_normalizePath as normalizePath, index_prepareIgnoredPaths as prepareIgnoredPaths, index_prettyHrTime as prettyHrTime, index_shouldIgnoreCurrentPath as shouldIgnoreCurrentPath, index_stripBeforeAssetsPath as stripBeforeAssetsPath };
|
|
40
|
+
export { index_compose as compose, index_formatSqlQuery as formatSqlQuery, index_generateRandomUuid as generateRandomUuid, index_getMeta as getMeta, index_interpolateQuery as interpolateQuery, index_isStaticFile as isStaticFile, index_normalizePath as normalizePath, index_prepareIgnoredPaths as prepareIgnoredPaths, index_prettyHrTime as prettyHrTime, index_shouldIgnoreCurrentPath as shouldIgnoreCurrentPath, index_stripBeforeAssetsPath as stripBeforeAssetsPath };
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
export { interpolateQuery as a, getMeta as b, isStaticFile as c, shouldIgnoreCurrentPath as d, prettyHrTime as e, formatSqlQuery as f, generateRandomUuid as g, index as i, normalizePath as n, prepareIgnoredPaths as p, stripBeforeAssetsPath as s };
|