@lensjs/core 1.0.1 → 1.0.3

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 (197) hide show
  1. package/dist/abstracts/adapter.cjs +8 -0
  2. package/dist/abstracts/adapter.d.cts +19 -0
  3. package/dist/abstracts/adapter.d.ts +19 -0
  4. package/dist/abstracts/adapter.js +8 -0
  5. package/dist/abstracts/store.cjs +7 -0
  6. package/dist/abstracts/store.d.cts +23 -0
  7. package/dist/abstracts/store.d.ts +23 -0
  8. package/dist/abstracts/store.js +7 -0
  9. package/dist/chunk-2HRVJRKV.cjs +10 -0
  10. package/dist/chunk-3R5QARPT.cjs +14 -0
  11. package/{src/watchers/request_watcher.ts → dist/chunk-4HLDYZJA.js} +18 -11
  12. package/dist/chunk-5PYQWLAZ.js +129 -0
  13. package/dist/chunk-75ZPJI57.cjs +9 -0
  14. package/dist/chunk-7EKM5HB5.cjs +1 -0
  15. package/dist/chunk-AUDSBNLF.cjs +122 -0
  16. package/dist/chunk-BFFOUTTE.cjs +32 -0
  17. package/dist/chunk-BL4Z6JFH.cjs +34 -0
  18. package/dist/chunk-CQ2Z4TCR.js +7 -0
  19. package/dist/chunk-EHOWCXZV.cjs +7 -0
  20. package/{src/utils/index.ts → dist/chunk-EJ5BW35V.js} +69 -86
  21. package/dist/chunk-EKG3FVLV.cjs +7 -0
  22. package/dist/chunk-FCMQ3WE3.cjs +129 -0
  23. package/dist/chunk-FKMBNWX4.js +7 -0
  24. package/dist/chunk-FLOVBBFU.js +10 -0
  25. package/dist/chunk-GI7SJDNQ.cjs +38 -0
  26. package/dist/chunk-IPMTMCFP.js +122 -0
  27. package/dist/chunk-JZ2JLQXL.cjs +87 -0
  28. package/dist/chunk-MLKGABMK.js +9 -0
  29. package/dist/chunk-QRZUNYF6.cjs +16 -0
  30. package/dist/chunk-RMZ4UAQ2.js +14 -0
  31. package/dist/chunk-SJXZARBJ.cjs +22 -0
  32. package/dist/chunk-TJDE6AZM.js +87 -0
  33. package/dist/chunk-TPUVRGYT.js +32 -0
  34. package/dist/chunk-UF5HFNMI.js +22 -0
  35. package/dist/chunk-VD5IMUWL.js +0 -0
  36. package/dist/chunk-WU6IZUEV.cjs +159 -0
  37. package/dist/chunk-XXYRWHSQ.js +0 -0
  38. package/dist/chunk-XYXPHWEI.js +16 -0
  39. package/dist/chunk-XZFXXD3A.cjs +1 -0
  40. package/dist/chunk-YC6T4XWI.js +38 -0
  41. package/dist/context/container.cjs +7 -0
  42. package/dist/context/container.d.cts +28 -0
  43. package/dist/context/container.d.ts +28 -0
  44. package/dist/context/container.js +7 -0
  45. package/dist/context/context.cjs +10 -0
  46. package/dist/context/context.d.cts +15 -0
  47. package/dist/context/context.d.ts +15 -0
  48. package/dist/context/context.js +10 -0
  49. package/dist/core/api_controller.cjs +10 -0
  50. package/dist/core/api_controller.d.cts +25 -0
  51. package/dist/core/api_controller.d.ts +25 -0
  52. package/dist/core/api_controller.js +10 -0
  53. package/dist/core/lens.cjs +15 -0
  54. package/dist/core/lens.d.cts +24 -0
  55. package/dist/core/lens.d.ts +24 -0
  56. package/dist/core/lens.js +15 -0
  57. package/dist/core/watcher.cjs +7 -0
  58. package/dist/core/watcher.d.cts +9 -0
  59. package/dist/core/watcher.d.ts +9 -0
  60. package/dist/core/watcher.js +7 -0
  61. package/dist/index-D0Vszdac.d.cts +49 -0
  62. package/dist/index-D0Vszdac.d.ts +49 -0
  63. package/dist/index.cjs +55 -0
  64. package/dist/index.d.cts +16 -0
  65. package/dist/index.d.ts +16 -0
  66. package/dist/index.js +55 -0
  67. package/dist/stores/better_sqlite.cjs +10 -0
  68. package/dist/stores/better_sqlite.d.cts +51 -0
  69. package/dist/stores/better_sqlite.d.ts +51 -0
  70. package/dist/stores/better_sqlite.js +10 -0
  71. package/dist/stores/index.cjs +11 -0
  72. package/dist/stores/index.d.cts +5 -0
  73. package/dist/stores/index.d.ts +5 -0
  74. package/dist/stores/index.js +11 -0
  75. package/dist/types/index.cjs +7 -0
  76. package/dist/types/index.d.cts +91 -0
  77. package/dist/types/index.d.ts +91 -0
  78. package/dist/types/index.js +7 -0
  79. package/dist/ui/assets/QueriesContainer-Bxr99HkT.js +2 -0
  80. package/dist/ui/assets/QueryDetailsContainer-BcbxQyxT.js +48 -0
  81. package/dist/ui/assets/QueryTable-Dx1MyXwe.js +1 -0
  82. package/dist/ui/assets/RequestDetails-B9rQn1tY.js +1 -0
  83. package/dist/ui/assets/RequestDetailsContainer-C0sOvaO2.js +2 -0
  84. package/dist/ui/assets/RequestsContainer-DYNNLt6S.js +2 -0
  85. package/dist/ui/assets/RequetsTable-BN-1fud-.js +1 -0
  86. package/dist/ui/assets/StatusCode-ByIHR7Pe.js +1 -0
  87. package/dist/ui/assets/TabbedDataViewer-CoLeLuBm.js +1 -0
  88. package/dist/ui/assets/Table-CXg4Wfwf.js +6 -0
  89. package/dist/ui/assets/date-BXZFS9Wq.js +1 -0
  90. package/dist/ui/assets/index-BPTSPdZM.css +1 -0
  91. package/dist/ui/assets/index-C3XpMOuU.js +114 -0
  92. package/dist/ui/assets/useLensApi-BlL4RwJa.js +1 -0
  93. package/dist/ui/assets/useLoadMore-BqF649Mm.js +1 -0
  94. package/dist/ui/assets/useQueries-Iwl8o-Xk.js +1 -0
  95. package/dist/ui/favicon.ico +0 -0
  96. package/dist/ui/index.html +14 -0
  97. package/dist/utils/event_emitter.cjs +11 -0
  98. package/dist/utils/event_emitter.d.cts +16 -0
  99. package/dist/utils/event_emitter.d.ts +16 -0
  100. package/dist/utils/event_emitter.js +11 -0
  101. package/dist/utils/index.cjs +31 -0
  102. package/dist/utils/index.d.cts +3 -0
  103. package/dist/utils/index.d.ts +3 -0
  104. package/dist/utils/index.js +31 -0
  105. package/dist/watchers/index.cjs +16 -0
  106. package/dist/watchers/index.d.cts +5 -0
  107. package/dist/watchers/index.d.ts +5 -0
  108. package/dist/watchers/index.js +16 -0
  109. package/dist/watchers/query_watcher.cjs +11 -0
  110. package/dist/watchers/query_watcher.d.cts +10 -0
  111. package/dist/watchers/query_watcher.d.ts +10 -0
  112. package/dist/watchers/query_watcher.js +11 -0
  113. package/dist/watchers/request_watcher.cjs +11 -0
  114. package/dist/watchers/request_watcher.d.cts +10 -0
  115. package/dist/watchers/request_watcher.d.ts +10 -0
  116. package/dist/watchers/request_watcher.js +11 -0
  117. package/package.json +4 -1
  118. package/copy-front-build.cjs +0 -16
  119. package/src/abstracts/adapter.ts +0 -41
  120. package/src/abstracts/store.ts +0 -36
  121. package/src/context/container.ts +0 -67
  122. package/src/context/context.ts +0 -9
  123. package/src/core/api_controller.ts +0 -116
  124. package/src/core/lens.ts +0 -147
  125. package/src/core/watcher.ts +0 -6
  126. package/src/index.ts +0 -11
  127. package/src/stores/better_sqlite.ts +0 -176
  128. package/src/stores/index.ts +0 -1
  129. package/src/types/index.ts +0 -103
  130. package/src/ui/README.md +0 -69
  131. package/src/ui/bun.lock +0 -750
  132. package/src/ui/eslint.config.js +0 -27
  133. package/src/ui/index.html +0 -13
  134. package/src/ui/package-lock.json +0 -2953
  135. package/src/ui/package.json +0 -40
  136. package/src/ui/src/App.tsx +0 -40
  137. package/src/ui/src/components/DetailPanel.tsx +0 -70
  138. package/src/ui/src/components/JsonViewer.tsx +0 -232
  139. package/src/ui/src/components/LoadMore.tsx +0 -25
  140. package/src/ui/src/components/MethodBadge.tsx +0 -19
  141. package/src/ui/src/components/Modal.tsx +0 -48
  142. package/src/ui/src/components/StatusCode.tsx +0 -20
  143. package/src/ui/src/components/Table.tsx +0 -127
  144. package/src/ui/src/components/layout/DeleteButton.tsx +0 -60
  145. package/src/ui/src/components/layout/Footer.tsx +0 -12
  146. package/src/ui/src/components/layout/Header.tsx +0 -40
  147. package/src/ui/src/components/layout/Layout.tsx +0 -49
  148. package/src/ui/src/components/layout/LoadingScreen.tsx +0 -14
  149. package/src/ui/src/components/layout/Sidebar.tsx +0 -67
  150. package/src/ui/src/components/queryFormatters/MongoViewer.tsx +0 -92
  151. package/src/ui/src/components/queryFormatters/QueryViewer.tsx +0 -18
  152. package/src/ui/src/components/queryFormatters/SqlViewer.tsx +0 -105
  153. package/src/ui/src/components/table/NoData.tsx +0 -26
  154. package/src/ui/src/components/tabs/TabbedDataViewer.tsx +0 -77
  155. package/src/ui/src/containers/queries/QueriesContainer.tsx +0 -21
  156. package/src/ui/src/containers/queries/QueryDetailsContainer.tsx +0 -15
  157. package/src/ui/src/containers/requests/RequestDetailsContainer.tsx +0 -16
  158. package/src/ui/src/containers/requests/RequestsContainer.tsx +0 -22
  159. package/src/ui/src/hooks/useLensApi.ts +0 -92
  160. package/src/ui/src/hooks/useLoadMore.ts +0 -48
  161. package/src/ui/src/hooks/useQueries.ts +0 -58
  162. package/src/ui/src/hooks/useRequests.ts +0 -79
  163. package/src/ui/src/hooks/useTanstackApi.ts +0 -126
  164. package/src/ui/src/index.css +0 -78
  165. package/src/ui/src/interfaces/index.ts +0 -10
  166. package/src/ui/src/main.tsx +0 -33
  167. package/src/ui/src/router/Router.ts +0 -11
  168. package/src/ui/src/router/routes/Loading.tsx +0 -5
  169. package/src/ui/src/router/routes/index.tsx +0 -85
  170. package/src/ui/src/types/index.ts +0 -95
  171. package/src/ui/src/utils/api.ts +0 -7
  172. package/src/ui/src/utils/context.ts +0 -24
  173. package/src/ui/src/utils/date.ts +0 -36
  174. package/src/ui/src/views/queries/QueryDetails.tsx +0 -58
  175. package/src/ui/src/views/queries/QueryTable.tsx +0 -21
  176. package/src/ui/src/views/queries/columns.tsx +0 -83
  177. package/src/ui/src/views/requests/BasicRequestDetails.tsx +0 -82
  178. package/src/ui/src/views/requests/RequestDetails.tsx +0 -70
  179. package/src/ui/src/views/requests/RequetsTable.tsx +0 -19
  180. package/src/ui/src/views/requests/columns.tsx +0 -62
  181. package/src/ui/src/vite-env.d.ts +0 -1
  182. package/src/ui/tsconfig.app.json +0 -27
  183. package/src/ui/tsconfig.json +0 -7
  184. package/src/ui/tsconfig.node.json +0 -25
  185. package/src/ui/vite.config.ts +0 -9
  186. package/src/utils/event_emitter.ts +0 -13
  187. package/src/watchers/index.ts +0 -2
  188. package/src/watchers/query_watcher.ts +0 -15
  189. package/tests/core/lens.test.ts +0 -89
  190. package/tests/stores/better_sqlite.test.ts +0 -168
  191. package/tests/utils/index.test.ts +0 -182
  192. package/tests/watchers/query_watcher.test.ts +0 -35
  193. package/tests/watchers/request_watcher.test.ts +0 -59
  194. package/tsconfig.json +0 -3
  195. package/tsup.config.ts +0 -15
  196. package/vitest.config.ts +0 -9
  197. /package/{src/ui/public/favicon.ico → dist/ui/assets/favicon-D0UnoCWN.ico} +0 -0
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkBFFOUTTEcjs = require('../chunk-BFFOUTTE.cjs');
4
+ require('../chunk-WU6IZUEV.cjs');
5
+ require('../chunk-75ZPJI57.cjs');
6
+
7
+
8
+ exports.default = _chunkBFFOUTTEcjs.Adapter;
@@ -0,0 +1,19 @@
1
+ import Watcher from '../core/watcher.cjs';
2
+ import { RouteDefinition } from '../types/index.cjs';
3
+ import 'sql-formatter';
4
+
5
+ declare abstract class Adapter {
6
+ private watchers;
7
+ protected ignoredPaths: RegExp[];
8
+ protected onlyPaths: RegExp[];
9
+ abstract setup(): void;
10
+ setWatchers(watchers: Watcher[]): this;
11
+ setIgnoredPaths(paths: RegExp[]): this;
12
+ setOnlyPaths(paths: RegExp[]): this;
13
+ getWatchers(): Watcher[];
14
+ shouldIgnorePath(path: string): boolean;
15
+ abstract registerRoutes(routes: RouteDefinition[]): void;
16
+ abstract serveUI(uiPath: string, spaRoute: string, dataToInject: Record<string, any>): void;
17
+ }
18
+
19
+ export { Adapter as default };
@@ -0,0 +1,19 @@
1
+ import Watcher from '../core/watcher.js';
2
+ import { RouteDefinition } from '../types/index.js';
3
+ import 'sql-formatter';
4
+
5
+ declare abstract class Adapter {
6
+ private watchers;
7
+ protected ignoredPaths: RegExp[];
8
+ protected onlyPaths: RegExp[];
9
+ abstract setup(): void;
10
+ setWatchers(watchers: Watcher[]): this;
11
+ setIgnoredPaths(paths: RegExp[]): this;
12
+ setOnlyPaths(paths: RegExp[]): this;
13
+ getWatchers(): Watcher[];
14
+ shouldIgnorePath(path: string): boolean;
15
+ abstract registerRoutes(routes: RouteDefinition[]): void;
16
+ abstract serveUI(uiPath: string, spaRoute: string, dataToInject: Record<string, any>): void;
17
+ }
18
+
19
+ export { Adapter as default };
@@ -0,0 +1,8 @@
1
+ import {
2
+ Adapter
3
+ } from "../chunk-TPUVRGYT.js";
4
+ import "../chunk-EJ5BW35V.js";
5
+ import "../chunk-MLKGABMK.js";
6
+ export {
7
+ Adapter as default
8
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkEHOWCXZVcjs = require('../chunk-EHOWCXZV.cjs');
4
+ require('../chunk-75ZPJI57.cjs');
5
+
6
+
7
+ exports.default = _chunkEHOWCXZVcjs.Store;
@@ -0,0 +1,23 @@
1
+ import { WatcherTypeEnum, PaginationParams, Paginator, LensEntry } from '../types/index.cjs';
2
+ import 'sql-formatter';
3
+
4
+ declare abstract class Store {
5
+ abstract initialize(): Promise<void>;
6
+ abstract save(entry: {
7
+ id?: string;
8
+ data: Record<string, any>;
9
+ minimal_data?: Record<string, any>;
10
+ type: WatcherTypeEnum;
11
+ timestamp?: string;
12
+ requestId?: string;
13
+ }): Promise<void>;
14
+ abstract getAllRequests(paginationParams: PaginationParams): Promise<Paginator<Omit<LensEntry, "data">[]>>;
15
+ abstract getAllQueries(paginationParams: PaginationParams): Promise<Paginator<LensEntry[]>>;
16
+ abstract allByRequestId(requestId: string, type: WatcherTypeEnum): Promise<LensEntry[]>;
17
+ abstract find(type: WatcherTypeEnum, id: string): Promise<LensEntry | null>;
18
+ abstract truncate(): Promise<void>;
19
+ abstract paginate<T>(type: WatcherTypeEnum, pagination: PaginationParams): Promise<Paginator<T>>;
20
+ abstract count(type: WatcherTypeEnum): Promise<number>;
21
+ }
22
+
23
+ export { Store as default };
@@ -0,0 +1,23 @@
1
+ import { WatcherTypeEnum, PaginationParams, Paginator, LensEntry } from '../types/index.js';
2
+ import 'sql-formatter';
3
+
4
+ declare abstract class Store {
5
+ abstract initialize(): Promise<void>;
6
+ abstract save(entry: {
7
+ id?: string;
8
+ data: Record<string, any>;
9
+ minimal_data?: Record<string, any>;
10
+ type: WatcherTypeEnum;
11
+ timestamp?: string;
12
+ requestId?: string;
13
+ }): Promise<void>;
14
+ abstract getAllRequests(paginationParams: PaginationParams): Promise<Paginator<Omit<LensEntry, "data">[]>>;
15
+ abstract getAllQueries(paginationParams: PaginationParams): Promise<Paginator<LensEntry[]>>;
16
+ abstract allByRequestId(requestId: string, type: WatcherTypeEnum): Promise<LensEntry[]>;
17
+ abstract find(type: WatcherTypeEnum, id: string): Promise<LensEntry | null>;
18
+ abstract truncate(): Promise<void>;
19
+ abstract paginate<T>(type: WatcherTypeEnum, pagination: PaginationParams): Promise<Paginator<T>>;
20
+ abstract count(type: WatcherTypeEnum): Promise<number>;
21
+ }
22
+
23
+ export { Store as default };
@@ -0,0 +1,7 @@
1
+ import {
2
+ Store
3
+ } from "../chunk-FKMBNWX4.js";
4
+ import "../chunk-MLKGABMK.js";
5
+ export {
6
+ Store as default
7
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/types/index.ts
2
+ var WatcherTypeEnum = /* @__PURE__ */ ((WatcherTypeEnum2) => {
3
+ WatcherTypeEnum2["REQUEST"] = "request";
4
+ WatcherTypeEnum2["QUERY"] = "query";
5
+ return WatcherTypeEnum2;
6
+ })(WatcherTypeEnum || {});
7
+
8
+
9
+
10
+ exports.WatcherTypeEnum = WatcherTypeEnum;
@@ -0,0 +1,14 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/utils/event_emitter.ts
2
+ var _async_hooks = require('async_hooks');
3
+ var _emittery = require('emittery'); var _emittery2 = _interopRequireDefault(_emittery);
4
+ var createEmittery = () => {
5
+ return new (0, _emittery2.default)();
6
+ };
7
+ var lensResource = new (0, _async_hooks.AsyncResource)("lens-emitter");
8
+ var lensEmitter = new (0, _emittery2.default)();
9
+
10
+
11
+
12
+
13
+
14
+ exports.createEmittery = createEmittery; exports.lensResource = lensResource; exports.lensEmitter = lensEmitter;
@@ -1,11 +1,14 @@
1
- import { getStore } from "../context/context";
2
- import Watcher from "../core/watcher";
3
- import { WatcherTypeEnum, type RequestEntry } from "../types/index";
1
+ import {
2
+ getStore
3
+ } from "./chunk-XYXPHWEI.js";
4
+ import {
5
+ Watcher
6
+ } from "./chunk-CQ2Z4TCR.js";
4
7
 
5
- export default class RequestWatcher extends Watcher {
6
- name = WatcherTypeEnum.REQUEST;
7
-
8
- async log(data: RequestEntry) {
8
+ // src/watchers/request_watcher.ts
9
+ var RequestWatcher = class extends Watcher {
10
+ name = "request" /* REQUEST */;
11
+ async log(data) {
9
12
  await getStore().save({
10
13
  id: data.request.id,
11
14
  type: this.name,
@@ -15,13 +18,17 @@ export default class RequestWatcher extends Watcher {
15
18
  path: data.request.path,
16
19
  duration: data.request.duration,
17
20
  createdAt: data.request.createdAt,
18
- status: data.request.status,
21
+ status: data.request.status
19
22
  },
20
23
  data: {
21
24
  ...data.request,
22
25
  user: data.user,
23
- response: data.response,
24
- },
26
+ response: data.response
27
+ }
25
28
  });
26
29
  }
27
- }
30
+ };
31
+
32
+ export {
33
+ RequestWatcher
34
+ };
@@ -0,0 +1,129 @@
1
+ import {
2
+ BetterSqliteStore
3
+ } from "./chunk-IPMTMCFP.js";
4
+ import {
5
+ getMeta
6
+ } from "./chunk-EJ5BW35V.js";
7
+ import {
8
+ ApiController
9
+ } from "./chunk-TJDE6AZM.js";
10
+ import {
11
+ getUiConfig
12
+ } from "./chunk-XYXPHWEI.js";
13
+ import {
14
+ Container
15
+ } from "./chunk-YC6T4XWI.js";
16
+
17
+ // src/core/lens.ts
18
+ import * as path from "path";
19
+ var Lens = class {
20
+ static watchers = /* @__PURE__ */ new Map();
21
+ static store;
22
+ static adapter;
23
+ static watch(watcher) {
24
+ this.watchers.set(watcher.name, watcher);
25
+ return this;
26
+ }
27
+ static setWatchers(watchers) {
28
+ this.watchers = new Map(watchers.map((watcher) => [watcher.name, watcher]));
29
+ return this;
30
+ }
31
+ static async start(config = {
32
+ basePath: "lens",
33
+ appName: "Lens",
34
+ enabled: true
35
+ }) {
36
+ if (!config.enabled) {
37
+ return;
38
+ }
39
+ await this.bindContainerDeps(config);
40
+ let adapter = this.getAdapter();
41
+ adapter.setWatchers(Array.from(this.watchers.values())).setup();
42
+ const { apiRoutes } = this.getRoutes({
43
+ basePath: config.basePath
44
+ });
45
+ adapter.registerRoutes(apiRoutes);
46
+ const { __dirname } = getMeta(import.meta.url);
47
+ const uiPath = path.resolve(this.normalizeDirName(__dirname), "ui");
48
+ adapter.serveUI(uiPath, config.basePath, getUiConfig());
49
+ }
50
+ static setStore(store) {
51
+ this.store = store;
52
+ return this;
53
+ }
54
+ static async getStore() {
55
+ return this.store ?? await this.getDefaultStore();
56
+ }
57
+ static setAdapter(adapter) {
58
+ this.adapter = adapter;
59
+ return this;
60
+ }
61
+ static getAdapter() {
62
+ if (!this.adapter) {
63
+ throw new Error("No adapter has been set");
64
+ }
65
+ return this.adapter;
66
+ }
67
+ static async bindContainerDeps(config) {
68
+ const dbStore = await this.getStore();
69
+ Container.singleton("store", () => dbStore);
70
+ Container.singleton("uiConfig", () => {
71
+ return {
72
+ appName: config.appName,
73
+ path: `/${config.basePath}`,
74
+ api: {
75
+ requests: `/${config.basePath}/api/requests`,
76
+ queries: `/${config.basePath}/api/queries`,
77
+ truncate: `/${config.basePath}/api/truncate`
78
+ }
79
+ };
80
+ });
81
+ }
82
+ static getRoutes({ basePath }) {
83
+ const apiRoutes = [
84
+ {
85
+ method: "GET",
86
+ path: `/lens-config`,
87
+ handler: () => ApiController.fetchUiConfig()
88
+ },
89
+ {
90
+ method: "GET",
91
+ path: `${basePath}/api/requests`,
92
+ handler: async (data) => await ApiController.getRequests(data)
93
+ },
94
+ {
95
+ method: "GET",
96
+ path: `${basePath}/api/requests/:id`,
97
+ handler: async (data) => await ApiController.getRequest(data)
98
+ },
99
+ {
100
+ method: "GET",
101
+ path: `${basePath}/api/queries`,
102
+ handler: async (data) => await ApiController.getQueries(data)
103
+ },
104
+ {
105
+ method: "GET",
106
+ path: `${basePath}/api/queries/:id`,
107
+ handler: async (data) => await ApiController.getQuery(data)
108
+ },
109
+ {
110
+ method: "DELETE",
111
+ path: `${basePath}/api/truncate`,
112
+ handler: async () => await ApiController.truncate()
113
+ }
114
+ ];
115
+ return { apiRoutes };
116
+ }
117
+ static async getDefaultStore() {
118
+ const store = new BetterSqliteStore();
119
+ await store.initialize();
120
+ return store;
121
+ }
122
+ static normalizeDirName(path2) {
123
+ return path2.replace(/(\/packages\/)[^/]+(?=\/dist)/, "$1core");
124
+ }
125
+ };
126
+
127
+ export {
128
+ Lens
129
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});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
+
8
+
9
+ exports.__export = __export;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,122 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunkWU6IZUEVcjs = require('./chunk-WU6IZUEV.cjs');
4
+
5
+
6
+ var _chunkEHOWCXZVcjs = require('./chunk-EHOWCXZV.cjs');
7
+
8
+ // src/stores/better_sqlite.ts
9
+ var _crypto = require('crypto');
10
+ var _libsql = require('libsql'); var _libsql2 = _interopRequireDefault(_libsql);
11
+ var TABLE_NAME = "lens_entries";
12
+ var BetterSqliteStore = class extends _chunkEHOWCXZVcjs.Store {
13
+
14
+ async initialize() {
15
+ this.connection = new (0, _libsql2.default)("lens.db");
16
+ this.setupSchema();
17
+ console.log("Connected to Lens (SQLite) database.");
18
+ }
19
+ async truncate() {
20
+ this.connection.prepare(`DELETE FROM ${TABLE_NAME};`).run();
21
+ }
22
+ async save(entry) {
23
+ this.connection.prepare(
24
+ `INSERT INTO ${TABLE_NAME} (id, data, type, created_at, lens_entry_id, minimal_data) values($id, $data, $type, $created_at, $lens_entry_id, $minimalData)`
25
+ ).run({
26
+ id: _nullishCoalesce(entry.id, () => ( _crypto.randomUUID.call(void 0, ))),
27
+ data: JSON.stringify(entry.data),
28
+ type: entry.type,
29
+ created_at: _nullishCoalesce(entry.timestamp, () => ( _chunkWU6IZUEVcjs.sqlDateTime.call(void 0, ))),
30
+ lens_entry_id: entry.requestId || null,
31
+ minimalData: JSON.stringify(_nullishCoalesce(entry.minimal_data, () => ( {})))
32
+ });
33
+ }
34
+ async getAllQueries(pagination) {
35
+ return await this.paginate("query" /* QUERY */, pagination);
36
+ }
37
+ async getAllRequests(pagination) {
38
+ return await this.paginate("request" /* REQUEST */, pagination, false);
39
+ }
40
+ async allByRequestId(requestId, type) {
41
+ const rows = this.connection.prepare(
42
+ `${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE type = $type AND lens_entry_id = $requestId ORDER BY created_at DESC`
43
+ ).all({ type, requestId });
44
+ return this.mapRows(rows);
45
+ }
46
+ async paginate(type, { page, perPage }, includeFullData = true) {
47
+ const offset = (page - 1) * perPage;
48
+ const query = `${this.getSelectedColumns(
49
+ includeFullData
50
+ )} FROM ${TABLE_NAME} WHERE type = ? ORDER BY created_at DESC LIMIT ? OFFSET ?`;
51
+ const count = await this.count(type);
52
+ const rows = this.connection.prepare(query).all(type, perPage, offset);
53
+ const mappedRows = this.mapRows(rows, includeFullData);
54
+ return {
55
+ meta: {
56
+ total: count,
57
+ lastPage: Math.ceil(count / perPage),
58
+ currentPage: page
59
+ },
60
+ data: mappedRows
61
+ };
62
+ }
63
+ async count(type) {
64
+ const result = this.connection.prepare(`SELECT count(*) as count FROM ${TABLE_NAME} WHERE type = ?`).get(type);
65
+ return Number(result.count);
66
+ }
67
+ async find(type, id) {
68
+ const row = this.connection.prepare(
69
+ `${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE id = ? AND type = ? LIMIT 1`
70
+ ).get(id, type);
71
+ if (!row) {
72
+ return null;
73
+ }
74
+ return this.mapRow(row, true);
75
+ }
76
+ setupSchema() {
77
+ const createTable = `
78
+ CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
79
+ id TEXT PRIMARY KEY,
80
+ minimal_data TEXT,
81
+ data TEXT NOT NULL,
82
+ type TEXT NOT NULL,
83
+ created_at TEXT NOT NULL,
84
+ updated_at TEXT,
85
+ lens_entry_id TEXT NULL
86
+ );
87
+ `;
88
+ const createIndex = `
89
+ CREATE INDEX IF NOT EXISTS lens_entries_id_type_index
90
+ ON ${TABLE_NAME} (id, type);
91
+ `;
92
+ this.connection.exec(createTable);
93
+ this.connection.exec(createIndex);
94
+ }
95
+ mapRow(row, includeFullData = true) {
96
+ let data = includeFullData ? JSON.parse(row.data) : {};
97
+ if (!includeFullData) {
98
+ data = JSON.parse(row.minimal_data);
99
+ }
100
+ return {
101
+ id: row.id,
102
+ type: row.type,
103
+ created_at: row.created_at,
104
+ lens_entry_id: row.lens_entry_id,
105
+ data
106
+ };
107
+ }
108
+ mapRows(rows, includeFullData = true) {
109
+ let mappedRows = [];
110
+ for (const row of rows) {
111
+ mappedRows.push(this.mapRow(row, includeFullData));
112
+ }
113
+ return mappedRows;
114
+ }
115
+ getSelectedColumns(includeFullData = true) {
116
+ return `SELECT id, minimal_data, type, created_at, lens_entry_id ${includeFullData ? ",data" : ""}`;
117
+ }
118
+ };
119
+
120
+
121
+
122
+ exports.BetterSqliteStore = BetterSqliteStore;
@@ -0,0 +1,32 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
2
+
3
+ var _chunkWU6IZUEVcjs = require('./chunk-WU6IZUEV.cjs');
4
+
5
+ // src/abstracts/adapter.ts
6
+ var Adapter = (_class = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this); }
7
+ __init() {this.watchers = []}
8
+ __init2() {this.ignoredPaths = []}
9
+ __init3() {this.onlyPaths = []}
10
+ setWatchers(watchers) {
11
+ this.watchers = watchers;
12
+ return this;
13
+ }
14
+ setIgnoredPaths(paths) {
15
+ this.ignoredPaths = paths;
16
+ return this;
17
+ }
18
+ setOnlyPaths(paths) {
19
+ this.onlyPaths = paths;
20
+ return this;
21
+ }
22
+ getWatchers() {
23
+ return this.watchers;
24
+ }
25
+ shouldIgnorePath(path) {
26
+ return _chunkWU6IZUEVcjs.shouldIgnoreCurrentPath.call(void 0, path, this.ignoredPaths, this.onlyPaths);
27
+ }
28
+ }, _class);
29
+
30
+
31
+
32
+ exports.Adapter = Adapter;
@@ -0,0 +1,34 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
2
+
3
+ var _chunkQRZUNYF6cjs = require('./chunk-QRZUNYF6.cjs');
4
+
5
+
6
+ var _chunkEKG3FVLVcjs = require('./chunk-EKG3FVLV.cjs');
7
+
8
+ // src/watchers/request_watcher.ts
9
+ var RequestWatcher = (_class = class extends _chunkEKG3FVLVcjs.Watcher {constructor(...args) { super(...args); _class.prototype.__init.call(this); }
10
+ __init() {this.name = "request"} /* REQUEST */
11
+ async log(data) {
12
+ await _chunkQRZUNYF6cjs.getStore.call(void 0, ).save({
13
+ id: data.request.id,
14
+ type: this.name,
15
+ minimal_data: {
16
+ id: data.request.id,
17
+ method: data.request.method,
18
+ path: data.request.path,
19
+ duration: data.request.duration,
20
+ createdAt: data.request.createdAt,
21
+ status: data.request.status
22
+ },
23
+ data: {
24
+ ...data.request,
25
+ user: data.user,
26
+ response: data.response
27
+ }
28
+ });
29
+ }
30
+ }, _class);
31
+
32
+
33
+
34
+ exports.RequestWatcher = RequestWatcher;
@@ -0,0 +1,7 @@
1
+ // src/core/watcher.ts
2
+ var Watcher = class {
3
+ };
4
+
5
+ export {
6
+ Watcher
7
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/abstracts/store.ts
2
+ var Store = class {
3
+ };
4
+
5
+
6
+
7
+ exports.Store = Store;