@lensjs/core 1.0.12 → 2.1.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/README.md +69 -0
- package/dist/abstracts/store.cjs +23 -0
- package/dist/abstracts/store.d.cts +7 -2
- package/dist/abstracts/store.d.ts +7 -2
- package/dist/abstracts/store.js +23 -0
- package/dist/core/api_controller.cjs +47 -4
- package/dist/core/api_controller.d.cts +7 -3
- package/dist/core/api_controller.d.ts +7 -3
- package/dist/core/api_controller.js +47 -4
- package/dist/core/lens.cjs +109 -10
- package/dist/core/lens.js +110 -11
- package/dist/exception-3AZsPtAg.d.ts +52 -0
- package/dist/exception-C69UCHPk.d.cts +52 -0
- package/dist/index.cjs +301 -19
- package/dist/index.d.cts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +296 -20
- package/dist/stores/better_sqlite.cjs +40 -6
- package/dist/stores/better_sqlite.d.cts +17 -1
- package/dist/stores/better_sqlite.d.ts +17 -1
- package/dist/stores/better_sqlite.js +41 -7
- package/dist/stores/index.cjs +40 -6
- package/dist/stores/index.js +41 -7
- package/dist/types/index.cjs +2 -0
- package/dist/types/index.d.cts +49 -2
- package/dist/types/index.d.ts +49 -2
- package/dist/types/index.js +2 -0
- package/dist/ui/assets/CacheActionBadge-3t8U516j.js +1 -0
- package/dist/ui/assets/CacheEntriesTable-BqLquILg.js +1 -0
- package/dist/ui/assets/CacheEntryContainer-B86waEsR.js +2 -0
- package/dist/ui/assets/CacheEntryDetails-Dm-oXALj.js +1 -0
- package/dist/ui/assets/CacheEntryDetailsContainer-BCyXGgkx.js +2 -0
- package/dist/ui/assets/ExceptionContainer-DSQBz5cb.js +2 -0
- package/dist/ui/assets/ExceptionDetails-gmpSQ_eu.js +16 -0
- package/dist/ui/assets/ExceptionDetailsContainer-BHIz-TUv.js +2 -0
- package/dist/ui/assets/ExceptionTable-BhrX9MSS.js +1 -0
- package/dist/ui/assets/LoadMore-26PcNWcP.js +1 -0
- package/dist/ui/assets/QueriesContainer-BSF-O4s3.js +2 -0
- package/dist/ui/assets/{QueryDetailsContainer-E7P-IO7f.js → QueryDetailsContainer-BjQM9QIb.js} +15 -15
- package/dist/ui/assets/QueryTable-szgIT5Uc.js +1 -0
- package/dist/ui/assets/RequestDetails-CvQhX-2F.js +1 -0
- package/dist/ui/assets/{RequestDetailsContainer-DuDo-IqS.js → RequestDetailsContainer-XYPFJFX0.js} +2 -2
- package/dist/ui/assets/RequestsContainer-D0QPK2Ii.js +2 -0
- package/dist/ui/assets/RequetsTable-6Fqchsrt.js +1 -0
- package/dist/ui/assets/{StatusCode-FQEjz7gK.js → StatusCode-CfVCLID2.js} +1 -1
- package/dist/ui/assets/TabbedDataViewer-Cl5ednx4.js +1 -0
- package/dist/ui/assets/{Table-DYaXk80S.js → Table-CGe8JwTO.js} +2 -2
- package/dist/ui/assets/columns-BFxCubt5.js +1 -0
- package/dist/ui/assets/columns-Cw7tw3Em.js +1 -0
- package/dist/ui/assets/columns-RiCoo9Ea.js +1 -0
- package/dist/ui/assets/{index-CpP2Ap5X.js → index-BRRKsoNv.js} +1 -1
- package/dist/ui/assets/index-BzFeZyjf.css +1 -0
- package/dist/ui/assets/{index-BS8XxorB.js → index-XoJlyTFO.js} +32 -22
- package/dist/ui/assets/useCacheEntries-SCADuxKq.js +1 -0
- package/dist/ui/assets/useExceptions-BMGL3nir.js +1 -0
- package/dist/ui/assets/useLensApi-BYyiIIZR.js +1 -0
- package/dist/ui/assets/{useLoadMore-CJltToLI.js → useLoadMore-CksOcXOF.js} +1 -1
- package/dist/ui/assets/useQueries-6nYr0oG5.js +1 -0
- package/dist/ui/index.html +2 -2
- package/dist/utils/async_context.cjs +144 -0
- package/dist/utils/async_context.d.cts +13 -0
- package/dist/utils/async_context.d.ts +13 -0
- package/dist/utils/async_context.js +108 -0
- package/dist/utils/event_emitter.cjs +5 -2
- package/dist/utils/event_emitter.d.cts +8 -1
- package/dist/utils/event_emitter.d.ts +8 -1
- package/dist/utils/event_emitter.js +3 -1
- package/dist/utils/exception.cjs +130 -0
- package/dist/utils/exception.d.cts +3 -0
- package/dist/utils/exception.d.ts +3 -0
- package/dist/utils/exception.js +91 -0
- package/dist/watchers/cache_watcher.cjs +107 -0
- package/dist/watchers/cache_watcher.d.cts +11 -0
- package/dist/watchers/cache_watcher.d.ts +11 -0
- package/dist/watchers/cache_watcher.js +84 -0
- package/dist/watchers/exception_watcher.cjs +108 -0
- package/dist/watchers/exception_watcher.d.cts +10 -0
- package/dist/watchers/exception_watcher.d.ts +10 -0
- package/dist/watchers/exception_watcher.js +75 -0
- package/dist/watchers/index.cjs +81 -0
- package/dist/watchers/index.d.cts +2 -0
- package/dist/watchers/index.d.ts +2 -0
- package/dist/watchers/index.js +69 -0
- package/package.json +8 -6
- package/dist/ui/assets/QueriesContainer-CAAsjjW5.js +0 -2
- package/dist/ui/assets/QueryTable-BcrtUssT.js +0 -1
- package/dist/ui/assets/RequestDetails-C2DZBu5H.js +0 -1
- package/dist/ui/assets/RequestsContainer-DK3hQVz9.js +0 -2
- package/dist/ui/assets/RequetsTable-DgP8p60b.js +0 -1
- package/dist/ui/assets/TabbedDataViewer-cBDdPwIz.js +0 -1
- package/dist/ui/assets/index-DzNHqeKh.css +0 -1
- package/dist/ui/assets/useLensApi-DG6atd6d.js +0 -1
- package/dist/ui/assets/useQueries-C8mDDDc6.js +0 -1
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
BetterSqliteStore: () => BetterSqliteStore,
|
|
34
|
+
CacheWatcher: () => CacheWatcher,
|
|
35
|
+
ExceptionWatcher: () => ExceptionWatcher,
|
|
34
36
|
Lens: () => Lens,
|
|
35
37
|
LensAdapter: () => Adapter,
|
|
36
38
|
LensStore: () => Store,
|
|
@@ -40,6 +42,10 @@ __export(index_exports, {
|
|
|
40
42
|
WatcherTypeEnum: () => WatcherTypeEnum,
|
|
41
43
|
createEmittery: () => createEmittery,
|
|
42
44
|
getLensStore: () => getStore,
|
|
45
|
+
handleUncaughExceptions: () => handleUncaughExceptions,
|
|
46
|
+
lensContext: () => lensContext,
|
|
47
|
+
lensEmitter: () => lensEmitter,
|
|
48
|
+
lensExceptionUtils: () => exception_exports,
|
|
43
49
|
lensUtils: () => utils_exports
|
|
44
50
|
});
|
|
45
51
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -91,6 +97,8 @@ var getUiConfig = () => {
|
|
|
91
97
|
var WatcherTypeEnum = /* @__PURE__ */ ((WatcherTypeEnum2) => {
|
|
92
98
|
WatcherTypeEnum2["REQUEST"] = "request";
|
|
93
99
|
WatcherTypeEnum2["QUERY"] = "query";
|
|
100
|
+
WatcherTypeEnum2["CACHE"] = "cache";
|
|
101
|
+
WatcherTypeEnum2["EXCEPTION"] = "exception";
|
|
94
102
|
return WatcherTypeEnum2;
|
|
95
103
|
})(WatcherTypeEnum || {});
|
|
96
104
|
|
|
@@ -101,14 +109,30 @@ var ApiController = class {
|
|
|
101
109
|
await getStore().getAllRequests(this.extractPaginationParams(qs))
|
|
102
110
|
);
|
|
103
111
|
}
|
|
104
|
-
static async getRequest({
|
|
105
|
-
params
|
|
106
|
-
}) {
|
|
112
|
+
static async getRequest({ params }) {
|
|
107
113
|
const request = await getStore().find("request" /* REQUEST */, params.id);
|
|
108
114
|
if (!request) {
|
|
109
115
|
return this.notFoundResponse();
|
|
110
116
|
}
|
|
111
|
-
|
|
117
|
+
const queries = await getStore().allByRequestId(
|
|
118
|
+
request.id,
|
|
119
|
+
"query" /* QUERY */
|
|
120
|
+
);
|
|
121
|
+
const cacheEntries = await getStore().allByRequestId(
|
|
122
|
+
request.id,
|
|
123
|
+
"cache" /* CACHE */
|
|
124
|
+
);
|
|
125
|
+
const exceptions = await getStore().allByRequestId(
|
|
126
|
+
request.id,
|
|
127
|
+
"exception" /* EXCEPTION */,
|
|
128
|
+
false
|
|
129
|
+
);
|
|
130
|
+
return this.resourceResponse({
|
|
131
|
+
request,
|
|
132
|
+
queries,
|
|
133
|
+
cacheEntries,
|
|
134
|
+
exceptions
|
|
135
|
+
});
|
|
112
136
|
}
|
|
113
137
|
static async getQueries({
|
|
114
138
|
qs
|
|
@@ -127,6 +151,33 @@ var ApiController = class {
|
|
|
127
151
|
}
|
|
128
152
|
return this.resourceResponse(query);
|
|
129
153
|
}
|
|
154
|
+
static async getCacheEntries({ qs }) {
|
|
155
|
+
return this.paginatedResponse(
|
|
156
|
+
await getStore().getAllCacheEntries(this.extractPaginationParams(qs))
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
static async getCacheEntry({ params }) {
|
|
160
|
+
const cacheEntry = await getStore().find("cache" /* CACHE */, params.id);
|
|
161
|
+
if (!cacheEntry) {
|
|
162
|
+
return this.notFoundResponse();
|
|
163
|
+
}
|
|
164
|
+
return this.resourceResponse(cacheEntry);
|
|
165
|
+
}
|
|
166
|
+
static async getExceptions({ qs }) {
|
|
167
|
+
return this.paginatedResponse(
|
|
168
|
+
await getStore().getAllExceptions(this.extractPaginationParams(qs))
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
static async getException({ params }) {
|
|
172
|
+
const exception = await getStore().find(
|
|
173
|
+
"exception" /* EXCEPTION */,
|
|
174
|
+
params.id
|
|
175
|
+
);
|
|
176
|
+
if (!exception) {
|
|
177
|
+
return this.notFoundResponse();
|
|
178
|
+
}
|
|
179
|
+
return this.resourceResponse(exception);
|
|
180
|
+
}
|
|
130
181
|
static async truncate() {
|
|
131
182
|
await getStore().truncate();
|
|
132
183
|
return this.baseResponse({}, 200, "All entries cleared");
|
|
@@ -178,6 +229,29 @@ var path2 = __toESM(require("path"), 1);
|
|
|
178
229
|
|
|
179
230
|
// src/abstracts/store.ts
|
|
180
231
|
var Store = class {
|
|
232
|
+
getAllExceptions(_paginationParams) {
|
|
233
|
+
return this.defaultMinimalPaginate();
|
|
234
|
+
}
|
|
235
|
+
stringifyData(data) {
|
|
236
|
+
if (typeof data === "string") {
|
|
237
|
+
return data;
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
return JSON.stringify(data);
|
|
241
|
+
} catch (e) {
|
|
242
|
+
console.error(`Failed to stringify lens data: ${e}`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
defaultMinimalPaginate() {
|
|
246
|
+
return Promise.resolve({
|
|
247
|
+
data: [],
|
|
248
|
+
meta: {
|
|
249
|
+
currentPage: 0,
|
|
250
|
+
lastPage: 0,
|
|
251
|
+
total: 0
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
181
255
|
};
|
|
182
256
|
|
|
183
257
|
// src/stores/better_sqlite.ts
|
|
@@ -200,11 +274,11 @@ var BetterSqliteStore = class extends Store {
|
|
|
200
274
|
`INSERT INTO ${TABLE_NAME} (id, data, type, created_at, lens_entry_id, minimal_data) values($id, $data, $type, $created_at, $lens_entry_id, $minimalData)`
|
|
201
275
|
).run({
|
|
202
276
|
id: entry.id ?? (0, import_crypto.randomUUID)(),
|
|
203
|
-
data:
|
|
277
|
+
data: this.stringifyData(entry.data),
|
|
204
278
|
type: entry.type,
|
|
205
|
-
created_at: entry.timestamp ?? (0, import_date.
|
|
279
|
+
created_at: entry.timestamp ?? (0, import_date.nowISO)(),
|
|
206
280
|
lens_entry_id: entry.requestId || null,
|
|
207
|
-
minimalData:
|
|
281
|
+
minimalData: this.stringifyData(entry.minimal_data ?? {})
|
|
208
282
|
});
|
|
209
283
|
}
|
|
210
284
|
async getAllQueries(pagination) {
|
|
@@ -213,11 +287,17 @@ var BetterSqliteStore = class extends Store {
|
|
|
213
287
|
async getAllRequests(pagination) {
|
|
214
288
|
return await this.paginate("request" /* REQUEST */, pagination, false);
|
|
215
289
|
}
|
|
216
|
-
async
|
|
290
|
+
async getAllCacheEntries(pagination) {
|
|
291
|
+
return await this.paginate("cache" /* CACHE */, pagination);
|
|
292
|
+
}
|
|
293
|
+
async getAllExceptions(pagination) {
|
|
294
|
+
return await this.paginate("exception" /* EXCEPTION */, pagination, false);
|
|
295
|
+
}
|
|
296
|
+
async allByRequestId(requestId, type, includeFullData = true) {
|
|
217
297
|
const rows = this.connection.prepare(
|
|
218
|
-
`${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE type = $type AND lens_entry_id = $requestId ORDER BY created_at DESC`
|
|
298
|
+
`${this.getSelectedColumns(includeFullData)} FROM ${TABLE_NAME} WHERE type = $type AND lens_entry_id = $requestId ORDER BY created_at DESC`
|
|
219
299
|
).all({ type, requestId });
|
|
220
|
-
return this.mapRows(rows);
|
|
300
|
+
return this.mapRows(rows, includeFullData);
|
|
221
301
|
}
|
|
222
302
|
async paginate(type, { page, perPage }, includeFullData = true) {
|
|
223
303
|
const offset = (page - 1) * perPage;
|
|
@@ -265,8 +345,13 @@ var BetterSqliteStore = class extends Store {
|
|
|
265
345
|
CREATE INDEX IF NOT EXISTS lens_entries_id_type_index
|
|
266
346
|
ON ${TABLE_NAME} (id, type);
|
|
267
347
|
`;
|
|
348
|
+
const lensEntryIdIndex = `
|
|
349
|
+
CREATE INDEX IF NOT EXISTS lens_entry_id_index
|
|
350
|
+
ON ${TABLE_NAME} (lens_entry_id);
|
|
351
|
+
`;
|
|
268
352
|
this.connection.exec(createTable);
|
|
269
353
|
this.connection.exec(createIndex);
|
|
354
|
+
this.connection.exec(lensEntryIdIndex);
|
|
270
355
|
}
|
|
271
356
|
mapRow(row, includeFullData = true) {
|
|
272
357
|
let data = includeFullData ? JSON.parse(row.data) : {};
|
|
@@ -378,8 +463,8 @@ function stripBeforeAssetsPath(url) {
|
|
|
378
463
|
const match = url.match(/assets.*/);
|
|
379
464
|
return match ? match[0] : url;
|
|
380
465
|
}
|
|
381
|
-
function prepareIgnoredPaths(
|
|
382
|
-
const normalizedPath =
|
|
466
|
+
function prepareIgnoredPaths(path4, ignoredPaths) {
|
|
467
|
+
const normalizedPath = path4.replace(/^\/+|\/+$/g, "");
|
|
383
468
|
ignoredPaths = [
|
|
384
469
|
...ignoredPaths,
|
|
385
470
|
new RegExp(`^/?${normalizedPath}(/|$)`),
|
|
@@ -388,11 +473,11 @@ function prepareIgnoredPaths(path3, ignoredPaths) {
|
|
|
388
473
|
];
|
|
389
474
|
return { ignoredPaths, normalizedPath };
|
|
390
475
|
}
|
|
391
|
-
function shouldIgnoreCurrentPath(
|
|
476
|
+
function shouldIgnoreCurrentPath(path4, ignoredPaths, onlyPaths) {
|
|
392
477
|
if (onlyPaths.length > 0) {
|
|
393
|
-
return !onlyPaths.some((pattern) => pattern.test(
|
|
478
|
+
return !onlyPaths.some((pattern) => pattern.test(path4));
|
|
394
479
|
}
|
|
395
|
-
return ignoredPaths.some((pattern) => pattern.test(
|
|
480
|
+
return ignoredPaths.some((pattern) => pattern.test(path4));
|
|
396
481
|
}
|
|
397
482
|
function prettyHrTime(hrtime, verbose = false) {
|
|
398
483
|
const seconds = hrtime[0];
|
|
@@ -475,6 +560,8 @@ var Lens = class {
|
|
|
475
560
|
api: {
|
|
476
561
|
requests: `/${config.basePath}/api/requests`,
|
|
477
562
|
queries: `/${config.basePath}/api/queries`,
|
|
563
|
+
cache: `/${config.basePath}/api/cache`,
|
|
564
|
+
exceptions: `/${config.basePath}/api/exceptions`,
|
|
478
565
|
truncate: `/${config.basePath}/api/truncate`
|
|
479
566
|
}
|
|
480
567
|
};
|
|
@@ -507,6 +594,26 @@ var Lens = class {
|
|
|
507
594
|
path: `${basePath}/api/queries/:id`,
|
|
508
595
|
handler: async (data) => await ApiController.getQuery(data)
|
|
509
596
|
},
|
|
597
|
+
{
|
|
598
|
+
method: "GET",
|
|
599
|
+
path: `${basePath}/api/cache`,
|
|
600
|
+
handler: async (data) => await ApiController.getCacheEntries(data)
|
|
601
|
+
},
|
|
602
|
+
{
|
|
603
|
+
method: "GET",
|
|
604
|
+
path: `${basePath}/api/cache/:id`,
|
|
605
|
+
handler: async (data) => await ApiController.getCacheEntry(data)
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
method: "GET",
|
|
609
|
+
path: `${basePath}/api/exceptions`,
|
|
610
|
+
handler: async (data) => await ApiController.getExceptions(data)
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
method: "GET",
|
|
614
|
+
path: `${basePath}/api/exceptions/:id`,
|
|
615
|
+
handler: async (data) => await ApiController.getException(data)
|
|
616
|
+
},
|
|
510
617
|
{
|
|
511
618
|
method: "DELETE",
|
|
512
619
|
path: `${basePath}/api/truncate`,
|
|
@@ -520,8 +627,8 @@ var Lens = class {
|
|
|
520
627
|
await store.initialize();
|
|
521
628
|
return store;
|
|
522
629
|
}
|
|
523
|
-
static normalizeDirName(
|
|
524
|
-
return
|
|
630
|
+
static normalizeDirName(path4) {
|
|
631
|
+
return path4.replace(/(\/packages\/)[^/]+(?=\/dist)/, "$1core");
|
|
525
632
|
}
|
|
526
633
|
};
|
|
527
634
|
|
|
@@ -565,6 +672,63 @@ var RequestWatcher = class extends Watcher {
|
|
|
565
672
|
}
|
|
566
673
|
};
|
|
567
674
|
|
|
675
|
+
// src/watchers/cache_watcher.ts
|
|
676
|
+
var CacheWatcher = class extends Watcher {
|
|
677
|
+
name = "cache" /* CACHE */;
|
|
678
|
+
async log(data) {
|
|
679
|
+
const payload = {
|
|
680
|
+
action: data.action,
|
|
681
|
+
data: this.normalizePayload(data),
|
|
682
|
+
requestId: data.requestId ?? "",
|
|
683
|
+
createdAt: data.createdAt
|
|
684
|
+
};
|
|
685
|
+
await getStore().save({
|
|
686
|
+
requestId: data.requestId ?? "",
|
|
687
|
+
type: this.name,
|
|
688
|
+
data: payload,
|
|
689
|
+
minimal_data: {
|
|
690
|
+
action: data.action,
|
|
691
|
+
key: payload.data.key,
|
|
692
|
+
createdAt: payload.createdAt
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
normalizePayload(data) {
|
|
697
|
+
let key = "";
|
|
698
|
+
let value = "";
|
|
699
|
+
if ("data" in data && typeof data.data === "object" && data.data !== null) {
|
|
700
|
+
if ("key" in data.data) {
|
|
701
|
+
key = String(data.data.key);
|
|
702
|
+
}
|
|
703
|
+
if ("value" in data.data) {
|
|
704
|
+
value = data.data.value;
|
|
705
|
+
}
|
|
706
|
+
} else if (typeof data.data === "string") {
|
|
707
|
+
value = data.data;
|
|
708
|
+
}
|
|
709
|
+
return { key, value };
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
// src/watchers/exception_watcher.ts
|
|
714
|
+
var ExceptionWatcher = class extends Watcher {
|
|
715
|
+
name = "exception" /* EXCEPTION */;
|
|
716
|
+
async log(payload) {
|
|
717
|
+
await getStore().save({
|
|
718
|
+
id: generateRandomUuid(),
|
|
719
|
+
type: "exception" /* EXCEPTION */,
|
|
720
|
+
requestId: payload.requestId,
|
|
721
|
+
timestamp: payload.createdAt,
|
|
722
|
+
data: payload,
|
|
723
|
+
minimal_data: {
|
|
724
|
+
name: payload.name,
|
|
725
|
+
message: payload.message,
|
|
726
|
+
createdAt: payload.createdAt
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
|
|
568
732
|
// src/abstracts/adapter.ts
|
|
569
733
|
var Adapter = class {
|
|
570
734
|
watchers = [];
|
|
@@ -585,19 +749,133 @@ var Adapter = class {
|
|
|
585
749
|
getWatchers() {
|
|
586
750
|
return this.watchers;
|
|
587
751
|
}
|
|
588
|
-
shouldIgnorePath(
|
|
589
|
-
return shouldIgnoreCurrentPath(
|
|
752
|
+
shouldIgnorePath(path4) {
|
|
753
|
+
return shouldIgnoreCurrentPath(path4, this.ignoredPaths, this.onlyPaths);
|
|
590
754
|
}
|
|
591
755
|
};
|
|
592
756
|
|
|
757
|
+
// src/utils/exception.ts
|
|
758
|
+
var exception_exports = {};
|
|
759
|
+
__export(exception_exports, {
|
|
760
|
+
cleanStack: () => cleanStack,
|
|
761
|
+
constructErrorObject: () => constructErrorObject,
|
|
762
|
+
extractCodeFrame: () => extractCodeFrame,
|
|
763
|
+
getFileInfo: () => getFileInfo,
|
|
764
|
+
getStackTrace: () => getStackTrace
|
|
765
|
+
});
|
|
766
|
+
var import_stack_utils = __toESM(require("stack-utils"), 1);
|
|
767
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
768
|
+
var import_node_fs = require("fs");
|
|
769
|
+
var import_date2 = require("@lensjs/date");
|
|
770
|
+
var stackUtils = new import_stack_utils.default({
|
|
771
|
+
cwd: process.cwd(),
|
|
772
|
+
internals: import_stack_utils.default.nodeInternals()
|
|
773
|
+
});
|
|
774
|
+
function cleanStack(stack) {
|
|
775
|
+
if (!stack) return "";
|
|
776
|
+
return stackUtils.clean(stack);
|
|
777
|
+
}
|
|
778
|
+
function getFileInfo(stack) {
|
|
779
|
+
if (!stack) {
|
|
780
|
+
return { file: "", line: 0, column: 0, function: "" };
|
|
781
|
+
}
|
|
782
|
+
const firstLine = stack.split("\n")[1] ?? "";
|
|
783
|
+
const fileInfo = stackUtils.parseLine(firstLine) ?? {
|
|
784
|
+
file: "",
|
|
785
|
+
line: 0,
|
|
786
|
+
column: 0,
|
|
787
|
+
function: ""
|
|
788
|
+
};
|
|
789
|
+
return {
|
|
790
|
+
file: fileInfo.file ? import_node_path.default.resolve(process.cwd(), fileInfo.file) : "",
|
|
791
|
+
line: fileInfo.line ?? 0,
|
|
792
|
+
column: fileInfo.column ?? 0,
|
|
793
|
+
function: fileInfo.function ?? ""
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
function getStackTrace(stack) {
|
|
797
|
+
if (!stack) return [];
|
|
798
|
+
return cleanStack(stack).split("\n").filter((frame) => Boolean(frame));
|
|
799
|
+
}
|
|
800
|
+
function extractCodeFrame({
|
|
801
|
+
file,
|
|
802
|
+
line,
|
|
803
|
+
column,
|
|
804
|
+
contextLines = 6
|
|
805
|
+
}) {
|
|
806
|
+
if (!file) return null;
|
|
807
|
+
const fullPath = import_node_path.default.isAbsolute(file) ? file : import_node_path.default.resolve(process.cwd(), file);
|
|
808
|
+
if (!(0, import_node_fs.existsSync)(fullPath)) return null;
|
|
809
|
+
const fileContent = (0, import_node_fs.readFileSync)(fullPath, "utf-8");
|
|
810
|
+
const lines = fileContent.split(/\r?\n/);
|
|
811
|
+
if (line < 1 || line > lines.length) return null;
|
|
812
|
+
const start = Math.max(0, line - 1 - contextLines);
|
|
813
|
+
const end = Math.min(lines.length, line - 1 + contextLines + 1);
|
|
814
|
+
const snippet = lines.slice(start, end);
|
|
815
|
+
const relativeLine = line - 1 - start;
|
|
816
|
+
const errorLine = lines[line - 1] ?? "";
|
|
817
|
+
return {
|
|
818
|
+
file: fullPath,
|
|
819
|
+
line,
|
|
820
|
+
column,
|
|
821
|
+
context: {
|
|
822
|
+
pre: snippet.slice(0, relativeLine),
|
|
823
|
+
error: errorLine,
|
|
824
|
+
post: snippet.slice(relativeLine + 1)
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
function constructErrorObject(err) {
|
|
829
|
+
const fileInfo = getFileInfo(err.stack);
|
|
830
|
+
const codeFrame = extractCodeFrame({
|
|
831
|
+
file: fileInfo.file,
|
|
832
|
+
line: fileInfo.line,
|
|
833
|
+
column: fileInfo.column
|
|
834
|
+
});
|
|
835
|
+
return {
|
|
836
|
+
name: err.name,
|
|
837
|
+
message: err.message,
|
|
838
|
+
createdAt: (0, import_date2.nowISO)(),
|
|
839
|
+
fileInfo: {
|
|
840
|
+
file: fileInfo.file,
|
|
841
|
+
function: fileInfo.function
|
|
842
|
+
},
|
|
843
|
+
cause: err.cause ?? null,
|
|
844
|
+
trace: getStackTrace(err.stack),
|
|
845
|
+
codeFrame,
|
|
846
|
+
originalStack: codeFrame === null ? cleanStack(err.stack) : null
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
|
|
593
850
|
// src/utils/event_emitter.ts
|
|
594
851
|
var import_emittery = __toESM(require("emittery"), 1);
|
|
595
852
|
var createEmittery = () => {
|
|
596
853
|
return new import_emittery.default();
|
|
597
854
|
};
|
|
855
|
+
var lensEmitter = createEmittery();
|
|
856
|
+
|
|
857
|
+
// src/utils/async_context.ts
|
|
858
|
+
var import_async_hooks = require("async_hooks");
|
|
859
|
+
var lensContext = new import_async_hooks.AsyncLocalStorage();
|
|
860
|
+
var handleUncaughExceptions = (logger) => {
|
|
861
|
+
process.on("uncaughtExceptionMonitor", async (err) => {
|
|
862
|
+
await logger.log({
|
|
863
|
+
...constructErrorObject(err),
|
|
864
|
+
requestId: lensContext.getStore()?.requestId
|
|
865
|
+
});
|
|
866
|
+
});
|
|
867
|
+
process.on("uncaughtException", async (err) => {
|
|
868
|
+
await logger.log({
|
|
869
|
+
...constructErrorObject(err),
|
|
870
|
+
requestId: lensContext.getStore()?.requestId
|
|
871
|
+
});
|
|
872
|
+
});
|
|
873
|
+
};
|
|
598
874
|
// Annotate the CommonJS export names for ESM import in node:
|
|
599
875
|
0 && (module.exports = {
|
|
600
876
|
BetterSqliteStore,
|
|
877
|
+
CacheWatcher,
|
|
878
|
+
ExceptionWatcher,
|
|
601
879
|
Lens,
|
|
602
880
|
LensAdapter,
|
|
603
881
|
LensStore,
|
|
@@ -607,5 +885,9 @@ var createEmittery = () => {
|
|
|
607
885
|
WatcherTypeEnum,
|
|
608
886
|
createEmittery,
|
|
609
887
|
getLensStore,
|
|
888
|
+
handleUncaughExceptions,
|
|
889
|
+
lensContext,
|
|
890
|
+
lensEmitter,
|
|
891
|
+
lensExceptionUtils,
|
|
610
892
|
lensUtils
|
|
611
893
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -2,13 +2,18 @@ export { default as Lens } from './core/lens.cjs';
|
|
|
2
2
|
export { default as BetterSqliteStore } from './stores/better_sqlite.cjs';
|
|
3
3
|
export { default as QueryWatcher } from './watchers/query_watcher.cjs';
|
|
4
4
|
export { default as RequestWatcher } from './watchers/request_watcher.cjs';
|
|
5
|
-
export {
|
|
5
|
+
export { default as CacheWatcher } from './watchers/cache_watcher.cjs';
|
|
6
|
+
export { default as ExceptionWatcher } from './watchers/exception_watcher.cjs';
|
|
7
|
+
export { ApiResponse, CacheAction, CacheEntry, Entry, ExceptionEntry, HttpMethod, LensConfig, LensEntry, PaginationParams, Paginator, QueryEntry, QueryType, RequestEntry, RouteDefinition, RouteDefinitionHandler, RouteHttpMethod, SqlQueryType, UserEntry, WatcherTypeEnum } from './types/index.cjs';
|
|
6
8
|
export { default as LensAdapter } from './abstracts/adapter.cjs';
|
|
7
9
|
export { default as LensStore } from './abstracts/store.cjs';
|
|
8
10
|
export { default as LensWatcher } from './core/watcher.cjs';
|
|
9
11
|
export { getStore as getLensStore } from './context/context.cjs';
|
|
10
12
|
export { i as lensUtils } from './index-DiLfwsvc.cjs';
|
|
11
|
-
export {
|
|
13
|
+
export { e as lensExceptionUtils } from './exception-C69UCHPk.cjs';
|
|
14
|
+
export { createEmittery, lensEmitter } from './utils/event_emitter.cjs';
|
|
15
|
+
export { handleUncaughExceptions, lensContext } from './utils/async_context.cjs';
|
|
12
16
|
import 'libsql';
|
|
13
17
|
import 'sql-formatter';
|
|
14
18
|
import 'emittery';
|
|
19
|
+
import 'async_hooks';
|
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,18 @@ export { default as Lens } from './core/lens.js';
|
|
|
2
2
|
export { default as BetterSqliteStore } from './stores/better_sqlite.js';
|
|
3
3
|
export { default as QueryWatcher } from './watchers/query_watcher.js';
|
|
4
4
|
export { default as RequestWatcher } from './watchers/request_watcher.js';
|
|
5
|
-
export {
|
|
5
|
+
export { default as CacheWatcher } from './watchers/cache_watcher.js';
|
|
6
|
+
export { default as ExceptionWatcher } from './watchers/exception_watcher.js';
|
|
7
|
+
export { ApiResponse, CacheAction, CacheEntry, Entry, ExceptionEntry, HttpMethod, LensConfig, LensEntry, PaginationParams, Paginator, QueryEntry, QueryType, RequestEntry, RouteDefinition, RouteDefinitionHandler, RouteHttpMethod, SqlQueryType, UserEntry, WatcherTypeEnum } from './types/index.js';
|
|
6
8
|
export { default as LensAdapter } from './abstracts/adapter.js';
|
|
7
9
|
export { default as LensStore } from './abstracts/store.js';
|
|
8
10
|
export { default as LensWatcher } from './core/watcher.js';
|
|
9
11
|
export { getStore as getLensStore } from './context/context.js';
|
|
10
12
|
export { i as lensUtils } from './index-DiLfwsvc.js';
|
|
11
|
-
export {
|
|
13
|
+
export { e as lensExceptionUtils } from './exception-3AZsPtAg.js';
|
|
14
|
+
export { createEmittery, lensEmitter } from './utils/event_emitter.js';
|
|
15
|
+
export { handleUncaughExceptions, lensContext } from './utils/async_context.js';
|
|
12
16
|
import 'libsql';
|
|
13
17
|
import 'sql-formatter';
|
|
14
18
|
import 'emittery';
|
|
19
|
+
import 'async_hooks';
|