@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/core/lens.js
CHANGED
|
@@ -48,14 +48,30 @@ var ApiController = class {
|
|
|
48
48
|
await getStore().getAllRequests(this.extractPaginationParams(qs))
|
|
49
49
|
);
|
|
50
50
|
}
|
|
51
|
-
static async getRequest({
|
|
52
|
-
params
|
|
53
|
-
}) {
|
|
51
|
+
static async getRequest({ params }) {
|
|
54
52
|
const request = await getStore().find("request" /* REQUEST */, params.id);
|
|
55
53
|
if (!request) {
|
|
56
54
|
return this.notFoundResponse();
|
|
57
55
|
}
|
|
58
|
-
|
|
56
|
+
const queries = await getStore().allByRequestId(
|
|
57
|
+
request.id,
|
|
58
|
+
"query" /* QUERY */
|
|
59
|
+
);
|
|
60
|
+
const cacheEntries = await getStore().allByRequestId(
|
|
61
|
+
request.id,
|
|
62
|
+
"cache" /* CACHE */
|
|
63
|
+
);
|
|
64
|
+
const exceptions = await getStore().allByRequestId(
|
|
65
|
+
request.id,
|
|
66
|
+
"exception" /* EXCEPTION */,
|
|
67
|
+
false
|
|
68
|
+
);
|
|
69
|
+
return this.resourceResponse({
|
|
70
|
+
request,
|
|
71
|
+
queries,
|
|
72
|
+
cacheEntries,
|
|
73
|
+
exceptions
|
|
74
|
+
});
|
|
59
75
|
}
|
|
60
76
|
static async getQueries({
|
|
61
77
|
qs
|
|
@@ -74,6 +90,33 @@ var ApiController = class {
|
|
|
74
90
|
}
|
|
75
91
|
return this.resourceResponse(query);
|
|
76
92
|
}
|
|
93
|
+
static async getCacheEntries({ qs }) {
|
|
94
|
+
return this.paginatedResponse(
|
|
95
|
+
await getStore().getAllCacheEntries(this.extractPaginationParams(qs))
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
static async getCacheEntry({ params }) {
|
|
99
|
+
const cacheEntry = await getStore().find("cache" /* CACHE */, params.id);
|
|
100
|
+
if (!cacheEntry) {
|
|
101
|
+
return this.notFoundResponse();
|
|
102
|
+
}
|
|
103
|
+
return this.resourceResponse(cacheEntry);
|
|
104
|
+
}
|
|
105
|
+
static async getExceptions({ qs }) {
|
|
106
|
+
return this.paginatedResponse(
|
|
107
|
+
await getStore().getAllExceptions(this.extractPaginationParams(qs))
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
static async getException({ params }) {
|
|
111
|
+
const exception = await getStore().find(
|
|
112
|
+
"exception" /* EXCEPTION */,
|
|
113
|
+
params.id
|
|
114
|
+
);
|
|
115
|
+
if (!exception) {
|
|
116
|
+
return this.notFoundResponse();
|
|
117
|
+
}
|
|
118
|
+
return this.resourceResponse(exception);
|
|
119
|
+
}
|
|
77
120
|
static async truncate() {
|
|
78
121
|
await getStore().truncate();
|
|
79
122
|
return this.baseResponse({}, 200, "All entries cleared");
|
|
@@ -125,12 +168,35 @@ import * as path2 from "path";
|
|
|
125
168
|
|
|
126
169
|
// src/abstracts/store.ts
|
|
127
170
|
var Store = class {
|
|
171
|
+
getAllExceptions(_paginationParams) {
|
|
172
|
+
return this.defaultMinimalPaginate();
|
|
173
|
+
}
|
|
174
|
+
stringifyData(data) {
|
|
175
|
+
if (typeof data === "string") {
|
|
176
|
+
return data;
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
return JSON.stringify(data);
|
|
180
|
+
} catch (e) {
|
|
181
|
+
console.error(`Failed to stringify lens data: ${e}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
defaultMinimalPaginate() {
|
|
185
|
+
return Promise.resolve({
|
|
186
|
+
data: [],
|
|
187
|
+
meta: {
|
|
188
|
+
currentPage: 0,
|
|
189
|
+
lastPage: 0,
|
|
190
|
+
total: 0
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
128
194
|
};
|
|
129
195
|
|
|
130
196
|
// src/stores/better_sqlite.ts
|
|
131
197
|
import { randomUUID } from "crypto";
|
|
132
198
|
import Database from "libsql";
|
|
133
|
-
import {
|
|
199
|
+
import { nowISO } from "@lensjs/date";
|
|
134
200
|
var TABLE_NAME = "lens_entries";
|
|
135
201
|
var BetterSqliteStore = class extends Store {
|
|
136
202
|
connection;
|
|
@@ -147,11 +213,11 @@ var BetterSqliteStore = class extends Store {
|
|
|
147
213
|
`INSERT INTO ${TABLE_NAME} (id, data, type, created_at, lens_entry_id, minimal_data) values($id, $data, $type, $created_at, $lens_entry_id, $minimalData)`
|
|
148
214
|
).run({
|
|
149
215
|
id: entry.id ?? randomUUID(),
|
|
150
|
-
data:
|
|
216
|
+
data: this.stringifyData(entry.data),
|
|
151
217
|
type: entry.type,
|
|
152
|
-
created_at: entry.timestamp ??
|
|
218
|
+
created_at: entry.timestamp ?? nowISO(),
|
|
153
219
|
lens_entry_id: entry.requestId || null,
|
|
154
|
-
minimalData:
|
|
220
|
+
minimalData: this.stringifyData(entry.minimal_data ?? {})
|
|
155
221
|
});
|
|
156
222
|
}
|
|
157
223
|
async getAllQueries(pagination) {
|
|
@@ -160,11 +226,17 @@ var BetterSqliteStore = class extends Store {
|
|
|
160
226
|
async getAllRequests(pagination) {
|
|
161
227
|
return await this.paginate("request" /* REQUEST */, pagination, false);
|
|
162
228
|
}
|
|
163
|
-
async
|
|
229
|
+
async getAllCacheEntries(pagination) {
|
|
230
|
+
return await this.paginate("cache" /* CACHE */, pagination);
|
|
231
|
+
}
|
|
232
|
+
async getAllExceptions(pagination) {
|
|
233
|
+
return await this.paginate("exception" /* EXCEPTION */, pagination, false);
|
|
234
|
+
}
|
|
235
|
+
async allByRequestId(requestId, type, includeFullData = true) {
|
|
164
236
|
const rows = this.connection.prepare(
|
|
165
|
-
`${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE type = $type AND lens_entry_id = $requestId ORDER BY created_at DESC`
|
|
237
|
+
`${this.getSelectedColumns(includeFullData)} FROM ${TABLE_NAME} WHERE type = $type AND lens_entry_id = $requestId ORDER BY created_at DESC`
|
|
166
238
|
).all({ type, requestId });
|
|
167
|
-
return this.mapRows(rows);
|
|
239
|
+
return this.mapRows(rows, includeFullData);
|
|
168
240
|
}
|
|
169
241
|
async paginate(type, { page, perPage }, includeFullData = true) {
|
|
170
242
|
const offset = (page - 1) * perPage;
|
|
@@ -212,8 +284,13 @@ var BetterSqliteStore = class extends Store {
|
|
|
212
284
|
CREATE INDEX IF NOT EXISTS lens_entries_id_type_index
|
|
213
285
|
ON ${TABLE_NAME} (id, type);
|
|
214
286
|
`;
|
|
287
|
+
const lensEntryIdIndex = `
|
|
288
|
+
CREATE INDEX IF NOT EXISTS lens_entry_id_index
|
|
289
|
+
ON ${TABLE_NAME} (lens_entry_id);
|
|
290
|
+
`;
|
|
215
291
|
this.connection.exec(createTable);
|
|
216
292
|
this.connection.exec(createIndex);
|
|
293
|
+
this.connection.exec(lensEntryIdIndex);
|
|
217
294
|
}
|
|
218
295
|
mapRow(row, includeFullData = true) {
|
|
219
296
|
let data = includeFullData ? JSON.parse(row.data) : {};
|
|
@@ -319,6 +396,8 @@ var Lens = class {
|
|
|
319
396
|
api: {
|
|
320
397
|
requests: `/${config.basePath}/api/requests`,
|
|
321
398
|
queries: `/${config.basePath}/api/queries`,
|
|
399
|
+
cache: `/${config.basePath}/api/cache`,
|
|
400
|
+
exceptions: `/${config.basePath}/api/exceptions`,
|
|
322
401
|
truncate: `/${config.basePath}/api/truncate`
|
|
323
402
|
}
|
|
324
403
|
};
|
|
@@ -351,6 +430,26 @@ var Lens = class {
|
|
|
351
430
|
path: `${basePath}/api/queries/:id`,
|
|
352
431
|
handler: async (data) => await ApiController.getQuery(data)
|
|
353
432
|
},
|
|
433
|
+
{
|
|
434
|
+
method: "GET",
|
|
435
|
+
path: `${basePath}/api/cache`,
|
|
436
|
+
handler: async (data) => await ApiController.getCacheEntries(data)
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
method: "GET",
|
|
440
|
+
path: `${basePath}/api/cache/:id`,
|
|
441
|
+
handler: async (data) => await ApiController.getCacheEntry(data)
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
method: "GET",
|
|
445
|
+
path: `${basePath}/api/exceptions`,
|
|
446
|
+
handler: async (data) => await ApiController.getExceptions(data)
|
|
447
|
+
},
|
|
448
|
+
{
|
|
449
|
+
method: "GET",
|
|
450
|
+
path: `${basePath}/api/exceptions/:id`,
|
|
451
|
+
handler: async (data) => await ApiController.getException(data)
|
|
452
|
+
},
|
|
354
453
|
{
|
|
355
454
|
method: "DELETE",
|
|
356
455
|
path: `${basePath}/api/truncate`,
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ExceptionEntry } from './types/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Clean a raw stack trace string, removing internal Node.js frames.
|
|
5
|
+
*/
|
|
6
|
+
declare function cleanStack(stack?: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Extract file information from the top frame of a stack trace.
|
|
9
|
+
*/
|
|
10
|
+
declare function getFileInfo(stack?: string): {
|
|
11
|
+
file: string;
|
|
12
|
+
line: number;
|
|
13
|
+
column: number;
|
|
14
|
+
function: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Parse a stack trace into an array of structured frames.
|
|
18
|
+
*/
|
|
19
|
+
declare function getStackTrace(stack?: string): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Extract surrounding code lines (context) from a file where the error occurred.
|
|
22
|
+
*/
|
|
23
|
+
declare function extractCodeFrame({ file, line, column, contextLines, }: {
|
|
24
|
+
file: string;
|
|
25
|
+
line: number;
|
|
26
|
+
column: number;
|
|
27
|
+
contextLines?: number;
|
|
28
|
+
}): {
|
|
29
|
+
file: string;
|
|
30
|
+
line: number;
|
|
31
|
+
column: number;
|
|
32
|
+
context: {
|
|
33
|
+
pre: string[];
|
|
34
|
+
error: string;
|
|
35
|
+
post: string[];
|
|
36
|
+
};
|
|
37
|
+
} | null;
|
|
38
|
+
/**
|
|
39
|
+
* Construct a normalized error object with metadata, stack trace, and code frame.
|
|
40
|
+
*/
|
|
41
|
+
declare function constructErrorObject(err: Error): ExceptionEntry;
|
|
42
|
+
|
|
43
|
+
declare const exception_cleanStack: typeof cleanStack;
|
|
44
|
+
declare const exception_constructErrorObject: typeof constructErrorObject;
|
|
45
|
+
declare const exception_extractCodeFrame: typeof extractCodeFrame;
|
|
46
|
+
declare const exception_getFileInfo: typeof getFileInfo;
|
|
47
|
+
declare const exception_getStackTrace: typeof getStackTrace;
|
|
48
|
+
declare namespace exception {
|
|
49
|
+
export { exception_cleanStack as cleanStack, exception_constructErrorObject as constructErrorObject, exception_extractCodeFrame as extractCodeFrame, exception_getFileInfo as getFileInfo, exception_getStackTrace as getStackTrace };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { getStackTrace as a, extractCodeFrame as b, cleanStack as c, constructErrorObject as d, exception as e, getFileInfo as g };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ExceptionEntry } from './types/index.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Clean a raw stack trace string, removing internal Node.js frames.
|
|
5
|
+
*/
|
|
6
|
+
declare function cleanStack(stack?: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Extract file information from the top frame of a stack trace.
|
|
9
|
+
*/
|
|
10
|
+
declare function getFileInfo(stack?: string): {
|
|
11
|
+
file: string;
|
|
12
|
+
line: number;
|
|
13
|
+
column: number;
|
|
14
|
+
function: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Parse a stack trace into an array of structured frames.
|
|
18
|
+
*/
|
|
19
|
+
declare function getStackTrace(stack?: string): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Extract surrounding code lines (context) from a file where the error occurred.
|
|
22
|
+
*/
|
|
23
|
+
declare function extractCodeFrame({ file, line, column, contextLines, }: {
|
|
24
|
+
file: string;
|
|
25
|
+
line: number;
|
|
26
|
+
column: number;
|
|
27
|
+
contextLines?: number;
|
|
28
|
+
}): {
|
|
29
|
+
file: string;
|
|
30
|
+
line: number;
|
|
31
|
+
column: number;
|
|
32
|
+
context: {
|
|
33
|
+
pre: string[];
|
|
34
|
+
error: string;
|
|
35
|
+
post: string[];
|
|
36
|
+
};
|
|
37
|
+
} | null;
|
|
38
|
+
/**
|
|
39
|
+
* Construct a normalized error object with metadata, stack trace, and code frame.
|
|
40
|
+
*/
|
|
41
|
+
declare function constructErrorObject(err: Error): ExceptionEntry;
|
|
42
|
+
|
|
43
|
+
declare const exception_cleanStack: typeof cleanStack;
|
|
44
|
+
declare const exception_constructErrorObject: typeof constructErrorObject;
|
|
45
|
+
declare const exception_extractCodeFrame: typeof extractCodeFrame;
|
|
46
|
+
declare const exception_getFileInfo: typeof getFileInfo;
|
|
47
|
+
declare const exception_getStackTrace: typeof getStackTrace;
|
|
48
|
+
declare namespace exception {
|
|
49
|
+
export { exception_cleanStack as cleanStack, exception_constructErrorObject as constructErrorObject, exception_extractCodeFrame as extractCodeFrame, exception_getFileInfo as getFileInfo, exception_getStackTrace as getStackTrace };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { getStackTrace as a, extractCodeFrame as b, cleanStack as c, constructErrorObject as d, exception as e, getFileInfo as g };
|