@lensjs/core 1.0.7 → 1.0.10

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 (100) hide show
  1. package/dist/abstracts/adapter.cjs +70 -5
  2. package/dist/abstracts/adapter.js +37 -5
  3. package/dist/abstracts/store.cjs +26 -6
  4. package/dist/abstracts/store.js +3 -4
  5. package/dist/context/container.cjs +57 -6
  6. package/dist/context/container.js +34 -4
  7. package/dist/context/context.cjs +71 -7
  8. package/dist/context/context.js +42 -6
  9. package/dist/core/api_controller.cjs +148 -7
  10. package/dist/core/api_controller.js +121 -7
  11. package/dist/core/lens.cjs +404 -12
  12. package/dist/core/lens.js +370 -12
  13. package/dist/core/watcher.cjs +26 -6
  14. package/dist/core/watcher.js +3 -4
  15. package/dist/{index-D0Vszdac.d.ts → index-DiLfwsvc.d.cts} +2 -11
  16. package/dist/{index-D0Vszdac.d.cts → index-DiLfwsvc.d.ts} +2 -11
  17. package/dist/index.cjs +611 -55
  18. package/dist/index.d.cts +2 -4
  19. package/dist/index.d.ts +2 -4
  20. package/dist/index.js +556 -42
  21. package/dist/stores/better_sqlite.cjs +149 -7
  22. package/dist/stores/better_sqlite.js +116 -7
  23. package/dist/stores/index.cjs +153 -8
  24. package/dist/stores/index.js +116 -8
  25. package/dist/types/index.cjs +33 -6
  26. package/dist/types/index.js +6 -4
  27. package/dist/ui/assets/QueriesContainer-CAAsjjW5.js +2 -0
  28. package/dist/ui/assets/{QueryDetailsContainer-BkaktbOw.js → QueryDetailsContainer-E7P-IO7f.js} +19 -19
  29. package/dist/ui/assets/QueryTable-BcrtUssT.js +1 -0
  30. package/dist/ui/assets/RequestDetails-C2DZBu5H.js +1 -0
  31. package/dist/ui/assets/RequestDetailsContainer-DuDo-IqS.js +2 -0
  32. package/dist/ui/assets/{RequestsContainer-zoWMoB7o.js → RequestsContainer-DK3hQVz9.js} +2 -2
  33. package/dist/ui/assets/RequetsTable-DgP8p60b.js +1 -0
  34. package/dist/ui/assets/{StatusCode-DH20lQ6a.js → StatusCode-FQEjz7gK.js} +1 -1
  35. package/dist/ui/assets/TabbedDataViewer-cBDdPwIz.js +1 -0
  36. package/dist/ui/assets/{Table-HwlddLhp.js → Table-DYaXk80S.js} +2 -2
  37. package/dist/ui/assets/index-BS8XxorB.js +114 -0
  38. package/dist/ui/assets/index-CpP2Ap5X.js +1 -0
  39. package/dist/ui/assets/index-DzNHqeKh.css +1 -0
  40. package/dist/ui/assets/{useLensApi-Bmk2bGb0.js → useLensApi-DG6atd6d.js} +1 -1
  41. package/dist/ui/assets/{useLoadMore-CvIajdjM.js → useLoadMore-CJltToLI.js} +1 -1
  42. package/dist/ui/assets/{useQueries-DuyhGJyf.js → useQueries-C8mDDDc6.js} +1 -1
  43. package/dist/ui/index.html +2 -2
  44. package/dist/utils/event_emitter.cjs +42 -10
  45. package/dist/utils/event_emitter.d.cts +1 -11
  46. package/dist/utils/event_emitter.d.ts +1 -11
  47. package/dist/utils/event_emitter.js +6 -9
  48. package/dist/utils/index.cjs +163 -31
  49. package/dist/utils/index.d.cts +1 -2
  50. package/dist/utils/index.d.ts +1 -2
  51. package/dist/utils/index.js +109 -20
  52. package/dist/watchers/index.cjs +105 -10
  53. package/dist/watchers/index.js +79 -12
  54. package/dist/watchers/query_watcher.cjs +78 -8
  55. package/dist/watchers/query_watcher.js +55 -8
  56. package/dist/watchers/request_watcher.cjs +90 -8
  57. package/dist/watchers/request_watcher.js +67 -8
  58. package/package.json +18 -18
  59. package/README.md +0 -1
  60. package/dist/chunk-2HRVJRKV.cjs +0 -10
  61. package/dist/chunk-3R5QARPT.cjs +0 -14
  62. package/dist/chunk-4HLDYZJA.js +0 -34
  63. package/dist/chunk-5PYQWLAZ.js +0 -129
  64. package/dist/chunk-75ZPJI57.cjs +0 -9
  65. package/dist/chunk-7EKM5HB5.cjs +0 -1
  66. package/dist/chunk-AUDSBNLF.cjs +0 -122
  67. package/dist/chunk-BFFOUTTE.cjs +0 -32
  68. package/dist/chunk-BL4Z6JFH.cjs +0 -34
  69. package/dist/chunk-CQ2Z4TCR.js +0 -7
  70. package/dist/chunk-EHOWCXZV.cjs +0 -7
  71. package/dist/chunk-EJ5BW35V.js +0 -159
  72. package/dist/chunk-EKG3FVLV.cjs +0 -7
  73. package/dist/chunk-FCMQ3WE3.cjs +0 -129
  74. package/dist/chunk-FKMBNWX4.js +0 -7
  75. package/dist/chunk-FLOVBBFU.js +0 -10
  76. package/dist/chunk-GI7SJDNQ.cjs +0 -38
  77. package/dist/chunk-IPMTMCFP.js +0 -122
  78. package/dist/chunk-JZ2JLQXL.cjs +0 -87
  79. package/dist/chunk-MLKGABMK.js +0 -9
  80. package/dist/chunk-QRZUNYF6.cjs +0 -16
  81. package/dist/chunk-RMZ4UAQ2.js +0 -14
  82. package/dist/chunk-SJXZARBJ.cjs +0 -22
  83. package/dist/chunk-TJDE6AZM.js +0 -87
  84. package/dist/chunk-TPUVRGYT.js +0 -32
  85. package/dist/chunk-UF5HFNMI.js +0 -22
  86. package/dist/chunk-VD5IMUWL.js +0 -0
  87. package/dist/chunk-WU6IZUEV.cjs +0 -159
  88. package/dist/chunk-XXYRWHSQ.js +0 -0
  89. package/dist/chunk-XYXPHWEI.js +0 -16
  90. package/dist/chunk-XZFXXD3A.cjs +0 -1
  91. package/dist/chunk-YC6T4XWI.js +0 -38
  92. package/dist/ui/assets/QueriesContainer-DHnHEGG1.js +0 -2
  93. package/dist/ui/assets/QueryTable-DegVNDkJ.js +0 -1
  94. package/dist/ui/assets/RequestDetails-zrL0n6gL.js +0 -1
  95. package/dist/ui/assets/RequestDetailsContainer-CsHWDxn7.js +0 -2
  96. package/dist/ui/assets/RequetsTable-1K9hhs0W.js +0 -1
  97. package/dist/ui/assets/TabbedDataViewer-DDVxzZiW.js +0 -1
  98. package/dist/ui/assets/date-CZdBf-JH.js +0 -1
  99. package/dist/ui/assets/index-C-9tn0L6.js +0 -114
  100. package/dist/ui/assets/index-DaNx3ROH.css +0 -1
package/dist/index.js CHANGED
@@ -1,43 +1,559 @@
1
- import {
2
- createEmittery,
3
- lensEmitter,
4
- lensResource
5
- } from "./chunk-RMZ4UAQ2.js";
6
- import "./chunk-XXYRWHSQ.js";
7
- import {
8
- QueryWatcher
9
- } from "./chunk-UF5HFNMI.js";
10
- import {
11
- RequestWatcher
12
- } from "./chunk-4HLDYZJA.js";
13
- import {
14
- Adapter
15
- } from "./chunk-TPUVRGYT.js";
16
- import {
17
- Lens
18
- } from "./chunk-5PYQWLAZ.js";
19
- import "./chunk-VD5IMUWL.js";
20
- import {
21
- BetterSqliteStore
22
- } from "./chunk-IPMTMCFP.js";
23
- import {
24
- utils_exports
25
- } from "./chunk-EJ5BW35V.js";
26
- import {
27
- Store
28
- } from "./chunk-FKMBNWX4.js";
29
- import "./chunk-TJDE6AZM.js";
30
- import {
31
- WatcherTypeEnum
32
- } from "./chunk-FLOVBBFU.js";
33
- import {
34
- getStore
35
- } from "./chunk-XYXPHWEI.js";
36
- import "./chunk-YC6T4XWI.js";
37
- import {
38
- Watcher
39
- } from "./chunk-CQ2Z4TCR.js";
40
- import "./chunk-MLKGABMK.js";
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/context/container.ts
8
+ var Container = class {
9
+ static bindings = /* @__PURE__ */ new Map();
10
+ static singletons = /* @__PURE__ */ new Map();
11
+ static instances = /* @__PURE__ */ new Map();
12
+ static bind(key, factory) {
13
+ this.bindings.set(key, factory);
14
+ }
15
+ static singleton(key, factory) {
16
+ this.singletons.set(key, factory);
17
+ }
18
+ static make(key) {
19
+ if (this.instances.has(key)) {
20
+ return this.instances.get(key);
21
+ }
22
+ if (this.singletons.has(key)) {
23
+ const instance = this.singletons.get(key)();
24
+ this.instances.set(key, instance);
25
+ return instance;
26
+ }
27
+ if (this.bindings.has(key)) {
28
+ return this.bindings.get(key)();
29
+ }
30
+ throw new Error(`Service "${key}" is not bound in the container`);
31
+ }
32
+ static has(key) {
33
+ return this.bindings.has(key) || this.singletons.has(key) || this.instances.has(key);
34
+ }
35
+ static clear() {
36
+ this.bindings.clear();
37
+ this.singletons.clear();
38
+ this.instances.clear();
39
+ }
40
+ };
41
+
42
+ // src/context/context.ts
43
+ var getStore = () => {
44
+ return Container.make("store");
45
+ };
46
+ var getUiConfig = () => {
47
+ return Container.make("uiConfig");
48
+ };
49
+
50
+ // src/types/index.ts
51
+ var WatcherTypeEnum = /* @__PURE__ */ ((WatcherTypeEnum2) => {
52
+ WatcherTypeEnum2["REQUEST"] = "request";
53
+ WatcherTypeEnum2["QUERY"] = "query";
54
+ return WatcherTypeEnum2;
55
+ })(WatcherTypeEnum || {});
56
+
57
+ // src/core/api_controller.ts
58
+ var ApiController = class {
59
+ static async getRequests({ qs }) {
60
+ return this.paginatedResponse(
61
+ await getStore().getAllRequests(this.extractPaginationParams(qs))
62
+ );
63
+ }
64
+ static async getRequest({
65
+ params
66
+ }) {
67
+ const request = await getStore().find("request" /* REQUEST */, params.id);
68
+ if (!request) {
69
+ return this.notFoundResponse();
70
+ }
71
+ return this.resourceResponse(request);
72
+ }
73
+ static async getQueries({
74
+ qs
75
+ }) {
76
+ const queries = await getStore().getAllQueries(
77
+ this.extractPaginationParams(qs)
78
+ );
79
+ return this.paginatedResponse(queries);
80
+ }
81
+ static async getQuery({
82
+ params
83
+ }) {
84
+ const query = await getStore().find("query" /* QUERY */, params.id);
85
+ if (!query) {
86
+ return this.notFoundResponse();
87
+ }
88
+ return this.resourceResponse(query);
89
+ }
90
+ static async truncate() {
91
+ await getStore().truncate();
92
+ return this.baseResponse({}, 200, "All entries cleared");
93
+ }
94
+ static fetchUiConfig() {
95
+ return getUiConfig();
96
+ }
97
+ static extractPaginationParams(qs) {
98
+ if (!qs || Object.keys(qs).length === 0) {
99
+ return { page: 1, perPage: 100 };
100
+ }
101
+ let page = Number(qs.page);
102
+ let perPage = Number(qs.perPage);
103
+ if (!Number.isInteger(perPage) || perPage > 100 || perPage < 5) {
104
+ perPage = 100;
105
+ }
106
+ if (!Number.isInteger(page) || page < 1) {
107
+ page = 1;
108
+ }
109
+ return { page, perPage };
110
+ }
111
+ static resourceResponse(data) {
112
+ return this.baseResponse(data, 200, "Data fetched successfully");
113
+ }
114
+ static notFoundResponse(message = "Could not find the requested resource") {
115
+ return this.baseResponse(null, 404, message);
116
+ }
117
+ static paginatedResponse(data) {
118
+ return this.baseResponse(data, 200, "Data fetched successfully");
119
+ }
120
+ static baseResponse(data, status, message) {
121
+ if (!data) {
122
+ return { status, message, data: null };
123
+ }
124
+ if ("meta" in data) {
125
+ return {
126
+ status,
127
+ message,
128
+ data: data.data,
129
+ meta: data.meta
130
+ };
131
+ }
132
+ return { status, message, data };
133
+ }
134
+ };
135
+
136
+ // src/core/lens.ts
137
+ import * as path2 from "path";
138
+
139
+ // src/abstracts/store.ts
140
+ var Store = class {
141
+ };
142
+
143
+ // src/stores/better_sqlite.ts
144
+ import { randomUUID } from "crypto";
145
+ import Database from "libsql";
146
+ import { sqlDateTime } from "@lensjs/date";
147
+ var TABLE_NAME = "lens_entries";
148
+ var BetterSqliteStore = class extends Store {
149
+ connection;
150
+ async initialize() {
151
+ this.connection = new Database("lens.db");
152
+ this.setupSchema();
153
+ console.log("Connected to Lens (SQLite) database.");
154
+ }
155
+ async truncate() {
156
+ this.connection.prepare(`DELETE FROM ${TABLE_NAME};`).run();
157
+ }
158
+ async save(entry) {
159
+ this.connection.prepare(
160
+ `INSERT INTO ${TABLE_NAME} (id, data, type, created_at, lens_entry_id, minimal_data) values($id, $data, $type, $created_at, $lens_entry_id, $minimalData)`
161
+ ).run({
162
+ id: entry.id ?? randomUUID(),
163
+ data: JSON.stringify(entry.data),
164
+ type: entry.type,
165
+ created_at: entry.timestamp ?? sqlDateTime(),
166
+ lens_entry_id: entry.requestId || null,
167
+ minimalData: JSON.stringify(entry.minimal_data ?? {})
168
+ });
169
+ }
170
+ async getAllQueries(pagination) {
171
+ return await this.paginate("query" /* QUERY */, pagination);
172
+ }
173
+ async getAllRequests(pagination) {
174
+ return await this.paginate("request" /* REQUEST */, pagination, false);
175
+ }
176
+ async allByRequestId(requestId, type) {
177
+ const rows = this.connection.prepare(
178
+ `${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE type = $type AND lens_entry_id = $requestId ORDER BY created_at DESC`
179
+ ).all({ type, requestId });
180
+ return this.mapRows(rows);
181
+ }
182
+ async paginate(type, { page, perPage }, includeFullData = true) {
183
+ const offset = (page - 1) * perPage;
184
+ const query = `${this.getSelectedColumns(
185
+ includeFullData
186
+ )} FROM ${TABLE_NAME} WHERE type = ? ORDER BY created_at DESC LIMIT ? OFFSET ?`;
187
+ const count = await this.count(type);
188
+ const rows = this.connection.prepare(query).all(type, perPage, offset);
189
+ const mappedRows = this.mapRows(rows, includeFullData);
190
+ return {
191
+ meta: {
192
+ total: count,
193
+ lastPage: Math.ceil(count / perPage),
194
+ currentPage: page
195
+ },
196
+ data: mappedRows
197
+ };
198
+ }
199
+ async count(type) {
200
+ const result = this.connection.prepare(`SELECT count(*) as count FROM ${TABLE_NAME} WHERE type = ?`).get(type);
201
+ return Number(result.count);
202
+ }
203
+ async find(type, id) {
204
+ const row = this.connection.prepare(
205
+ `${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE id = ? AND type = ? LIMIT 1`
206
+ ).get(id, type);
207
+ if (!row) {
208
+ return null;
209
+ }
210
+ return this.mapRow(row, true);
211
+ }
212
+ setupSchema() {
213
+ const createTable = `
214
+ CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
215
+ id TEXT PRIMARY KEY,
216
+ minimal_data TEXT,
217
+ data TEXT NOT NULL,
218
+ type TEXT NOT NULL,
219
+ created_at TEXT NOT NULL,
220
+ updated_at TEXT,
221
+ lens_entry_id TEXT NULL
222
+ );
223
+ `;
224
+ const createIndex = `
225
+ CREATE INDEX IF NOT EXISTS lens_entries_id_type_index
226
+ ON ${TABLE_NAME} (id, type);
227
+ `;
228
+ this.connection.exec(createTable);
229
+ this.connection.exec(createIndex);
230
+ }
231
+ mapRow(row, includeFullData = true) {
232
+ let data = includeFullData ? JSON.parse(row.data) : {};
233
+ if (!includeFullData) {
234
+ data = JSON.parse(row.minimal_data);
235
+ }
236
+ return {
237
+ id: row.id,
238
+ type: row.type,
239
+ created_at: row.created_at,
240
+ lens_entry_id: row.lens_entry_id,
241
+ data
242
+ };
243
+ }
244
+ mapRows(rows, includeFullData = true) {
245
+ let mappedRows = [];
246
+ for (const row of rows) {
247
+ mappedRows.push(this.mapRow(row, includeFullData));
248
+ }
249
+ return mappedRows;
250
+ }
251
+ getSelectedColumns(includeFullData = true) {
252
+ return `SELECT id, minimal_data, type, created_at, lens_entry_id ${includeFullData ? ",data" : ""}`;
253
+ }
254
+ };
255
+
256
+ // src/utils/index.ts
257
+ var utils_exports = {};
258
+ __export(utils_exports, {
259
+ formatSqlQuery: () => formatSqlQuery,
260
+ generateRandomUuid: () => generateRandomUuid,
261
+ getMeta: () => getMeta,
262
+ interpolateQuery: () => interpolateQuery,
263
+ isStaticFile: () => isStaticFile,
264
+ prepareIgnoredPaths: () => prepareIgnoredPaths,
265
+ prettyHrTime: () => prettyHrTime,
266
+ shouldIgnoreCurrentPath: () => shouldIgnoreCurrentPath,
267
+ stripBeforeAssetsPath: () => stripBeforeAssetsPath
268
+ });
269
+ import { DateTime } from "luxon";
270
+ import { format } from "sql-formatter";
271
+ import { randomUUID as randomUUID2 } from "crypto";
272
+ import { fileURLToPath } from "url";
273
+ import * as path from "path";
274
+ var generateRandomUuid = () => {
275
+ return randomUUID2();
276
+ };
277
+ function interpolateQuery(query, bindings) {
278
+ const formatValue = (value) => {
279
+ if (value === null || value === void 0) return "NULL";
280
+ if (typeof value === "string") return `'${value.replace(/'/g, "''")}'`;
281
+ if (value instanceof DateTime) return `'${value.toISO()}'`;
282
+ if (value instanceof Date) return `'${value.toISOString()}'`;
283
+ if (Array.isArray(value))
284
+ return value.map((v) => typeof v === "string" ? `'${v.replace(/'/g, "''")}'` : v).join(", ");
285
+ if (typeof value === "object")
286
+ return `'${JSON.stringify(value).replace(/'/g, "''")}'`;
287
+ return value.toString();
288
+ };
289
+ if (Array.isArray(bindings)) {
290
+ let i = 0;
291
+ return query.replace(/\?/g, () => {
292
+ if (i >= bindings.length)
293
+ throw new Error("Not enough bindings for placeholders");
294
+ return formatValue(bindings[i++]);
295
+ });
296
+ }
297
+ return query.replace(/(\$|\:)(\w+)/g, (match, prefix, keyOrIndex) => {
298
+ let value;
299
+ if (prefix === "$" && /^\d+$/.test(keyOrIndex)) {
300
+ const index = parseInt(keyOrIndex, 10) - 1;
301
+ const keys = Object.keys(bindings);
302
+ if (index < 0 || index >= keys.length)
303
+ throw new Error(`Missing binding for ${match}`);
304
+ value = bindings[keys[index]];
305
+ } else {
306
+ if (!(keyOrIndex in bindings))
307
+ throw new Error(`Missing binding for ${match}`);
308
+ value = bindings[keyOrIndex];
309
+ }
310
+ return formatValue(value);
311
+ });
312
+ }
313
+ var formatSqlQuery = (query, language) => {
314
+ return format(query, {
315
+ language,
316
+ dataTypeCase: "upper",
317
+ keywordCase: "upper",
318
+ functionCase: "upper"
319
+ });
320
+ };
321
+ function getMeta(metaUrl) {
322
+ const isESM = typeof __dirname === "undefined";
323
+ if (isESM) {
324
+ if (!metaUrl) {
325
+ throw new Error("In ESM, you must pass import.meta.url to getMeta()");
326
+ }
327
+ const __filename2 = fileURLToPath(metaUrl);
328
+ const __dirname2 = path.dirname(__filename2);
329
+ return { __filename: __filename2, __dirname: __dirname2 };
330
+ } else {
331
+ return { __filename, __dirname };
332
+ }
333
+ }
334
+ function isStaticFile(params) {
335
+ return params.includes("assets");
336
+ }
337
+ function stripBeforeAssetsPath(url) {
338
+ const match = url.match(/assets.*/);
339
+ return match ? match[0] : url;
340
+ }
341
+ function prepareIgnoredPaths(path3, ignoredPaths) {
342
+ const normalizedPath = path3.replace(/^\/+|\/+$/g, "");
343
+ ignoredPaths = [
344
+ ...ignoredPaths,
345
+ new RegExp(`^/?${normalizedPath}(/|$)`),
346
+ /^\/?lens-config$/,
347
+ /^\/\.well-known\//
348
+ ];
349
+ return { ignoredPaths, normalizedPath };
350
+ }
351
+ function shouldIgnoreCurrentPath(path3, ignoredPaths, onlyPaths) {
352
+ if (onlyPaths.length > 0) {
353
+ return !onlyPaths.some((pattern) => pattern.test(path3));
354
+ }
355
+ return ignoredPaths.some((pattern) => pattern.test(path3));
356
+ }
357
+ function prettyHrTime(hrtime, verbose = false) {
358
+ const seconds = hrtime[0];
359
+ const nanoseconds = hrtime[1];
360
+ const ms = seconds * 1e3 + nanoseconds / 1e6;
361
+ if (verbose) {
362
+ if (seconds > 60) {
363
+ const minutes = Math.floor(seconds / 60);
364
+ const remainingSeconds = seconds % 60;
365
+ return `${minutes}m ${remainingSeconds}s`;
366
+ }
367
+ if (seconds >= 1) {
368
+ return `${seconds}.${Math.floor(nanoseconds / 1e7)}s`;
369
+ }
370
+ return `${ms.toFixed(3)} ms`;
371
+ }
372
+ if (ms < 1e3) {
373
+ return `${ms.toFixed(0)} ms`;
374
+ }
375
+ return `${(ms / 1e3).toFixed(1)} s`;
376
+ }
377
+
378
+ // src/core/lens.ts
379
+ var Lens = class {
380
+ static watchers = /* @__PURE__ */ new Map();
381
+ static store;
382
+ static adapter;
383
+ static watch(watcher) {
384
+ this.watchers.set(watcher.name, watcher);
385
+ return this;
386
+ }
387
+ static setWatchers(watchers) {
388
+ this.watchers = new Map(watchers.map((watcher) => [watcher.name, watcher]));
389
+ return this;
390
+ }
391
+ static async start(config = {
392
+ basePath: "lens",
393
+ appName: "Lens",
394
+ enabled: true
395
+ }) {
396
+ if (!config.enabled) {
397
+ return;
398
+ }
399
+ await this.bindContainerDeps(config);
400
+ let adapter = this.getAdapter();
401
+ adapter.setWatchers(Array.from(this.watchers.values())).setup();
402
+ const { apiRoutes } = this.getRoutes({
403
+ basePath: config.basePath
404
+ });
405
+ adapter.registerRoutes(apiRoutes);
406
+ const { __dirname: __dirname2 } = getMeta(import.meta.url);
407
+ const uiPath = path2.resolve(this.normalizeDirName(__dirname2), "ui");
408
+ adapter.serveUI(uiPath, config.basePath, getUiConfig());
409
+ }
410
+ static setStore(store) {
411
+ this.store = store;
412
+ return this;
413
+ }
414
+ static async getStore() {
415
+ return this.store ?? await this.getDefaultStore();
416
+ }
417
+ static setAdapter(adapter) {
418
+ this.adapter = adapter;
419
+ return this;
420
+ }
421
+ static getAdapter() {
422
+ if (!this.adapter) {
423
+ throw new Error("No adapter has been set");
424
+ }
425
+ return this.adapter;
426
+ }
427
+ static async bindContainerDeps(config) {
428
+ const dbStore = await this.getStore();
429
+ Container.singleton("store", () => dbStore);
430
+ Container.singleton("uiConfig", () => {
431
+ return {
432
+ appName: config.appName,
433
+ path: `/${config.basePath}`,
434
+ api: {
435
+ requests: `/${config.basePath}/api/requests`,
436
+ queries: `/${config.basePath}/api/queries`,
437
+ truncate: `/${config.basePath}/api/truncate`
438
+ }
439
+ };
440
+ });
441
+ }
442
+ static getRoutes({ basePath }) {
443
+ const apiRoutes = [
444
+ {
445
+ method: "GET",
446
+ path: `/lens-config`,
447
+ handler: () => ApiController.fetchUiConfig()
448
+ },
449
+ {
450
+ method: "GET",
451
+ path: `${basePath}/api/requests`,
452
+ handler: async (data) => await ApiController.getRequests(data)
453
+ },
454
+ {
455
+ method: "GET",
456
+ path: `${basePath}/api/requests/:id`,
457
+ handler: async (data) => await ApiController.getRequest(data)
458
+ },
459
+ {
460
+ method: "GET",
461
+ path: `${basePath}/api/queries`,
462
+ handler: async (data) => await ApiController.getQueries(data)
463
+ },
464
+ {
465
+ method: "GET",
466
+ path: `${basePath}/api/queries/:id`,
467
+ handler: async (data) => await ApiController.getQuery(data)
468
+ },
469
+ {
470
+ method: "DELETE",
471
+ path: `${basePath}/api/truncate`,
472
+ handler: async () => await ApiController.truncate()
473
+ }
474
+ ];
475
+ return { apiRoutes };
476
+ }
477
+ static async getDefaultStore() {
478
+ const store = new BetterSqliteStore();
479
+ await store.initialize();
480
+ return store;
481
+ }
482
+ static normalizeDirName(path3) {
483
+ return path3.replace(/(\/packages\/)[^/]+(?=\/dist)/, "$1core");
484
+ }
485
+ };
486
+
487
+ // src/core/watcher.ts
488
+ var Watcher = class {
489
+ };
490
+
491
+ // src/watchers/query_watcher.ts
492
+ var QueryWatcher = class extends Watcher {
493
+ name = "query" /* QUERY */;
494
+ async log(entry) {
495
+ await getStore().save({
496
+ type: this.name,
497
+ data: entry.data,
498
+ requestId: entry.requestId ?? ""
499
+ });
500
+ }
501
+ };
502
+
503
+ // src/watchers/request_watcher.ts
504
+ var RequestWatcher = class extends Watcher {
505
+ name = "request" /* REQUEST */;
506
+ async log(data) {
507
+ await getStore().save({
508
+ id: data.request.id,
509
+ type: this.name,
510
+ minimal_data: {
511
+ id: data.request.id,
512
+ method: data.request.method,
513
+ path: data.request.path,
514
+ duration: data.request.duration,
515
+ createdAt: data.request.createdAt,
516
+ status: data.request.status
517
+ },
518
+ data: {
519
+ ...data.request,
520
+ user: data.user,
521
+ response: data.response
522
+ }
523
+ });
524
+ }
525
+ };
526
+
527
+ // src/abstracts/adapter.ts
528
+ var Adapter = class {
529
+ watchers = [];
530
+ ignoredPaths = [];
531
+ onlyPaths = [];
532
+ setWatchers(watchers) {
533
+ this.watchers = watchers;
534
+ return this;
535
+ }
536
+ setIgnoredPaths(paths) {
537
+ this.ignoredPaths = paths;
538
+ return this;
539
+ }
540
+ setOnlyPaths(paths) {
541
+ this.onlyPaths = paths;
542
+ return this;
543
+ }
544
+ getWatchers() {
545
+ return this.watchers;
546
+ }
547
+ shouldIgnorePath(path3) {
548
+ return shouldIgnoreCurrentPath(path3, this.ignoredPaths, this.onlyPaths);
549
+ }
550
+ };
551
+
552
+ // src/utils/event_emitter.ts
553
+ import Emittery from "emittery";
554
+ var createEmittery = () => {
555
+ return new Emittery();
556
+ };
41
557
  export {
42
558
  BetterSqliteStore,
43
559
  Lens,
@@ -49,7 +565,5 @@ export {
49
565
  WatcherTypeEnum,
50
566
  createEmittery,
51
567
  getStore as getLensStore,
52
- lensEmitter,
53
- lensResource,
54
568
  utils_exports as lensUtils
55
569
  };