@lensjs/core 1.0.1 → 1.0.2

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
@@ -1,39 +1,44 @@
1
+ import {
2
+ __export
3
+ } from "./chunk-MLKGABMK.js";
4
+
5
+ // src/utils/index.ts
6
+ var utils_exports = {};
7
+ __export(utils_exports, {
8
+ convertToUTC: () => convertToUTC,
9
+ formatSqlQuery: () => formatSqlQuery,
10
+ generateRandomUuid: () => generateRandomUuid,
11
+ getMeta: () => getMeta,
12
+ interpolateQuery: () => interpolateQuery,
13
+ isStaticFile: () => isStaticFile,
14
+ now: () => now,
15
+ nowISO: () => nowISO,
16
+ prepareIgnoredPaths: () => prepareIgnoredPaths,
17
+ prettyHrTime: () => prettyHrTime,
18
+ shouldIgnoreCurrentPath: () => shouldIgnoreCurrentPath,
19
+ sqlDateTime: () => sqlDateTime,
20
+ stripBeforeAssetsPath: () => stripBeforeAssetsPath
21
+ });
1
22
  import { DateTime } from "luxon";
2
- import { format, SqlLanguage } from "sql-formatter";
23
+ import { format } from "sql-formatter";
3
24
  import { randomUUID } from "crypto";
4
25
  import { fileURLToPath } from "url";
5
26
  import path from "path/posix";
6
-
7
- export const generateRandomUuid = () => {
27
+ var generateRandomUuid = () => {
8
28
  return randomUUID();
9
29
  };
10
-
11
- type Bindings = any[] | Record<string, any>;
12
-
13
- /**
14
- * Interpolates SQL query placeholders with actual values.
15
- * Supports:
16
- * - ? (array-based)
17
- * - $1, $name (numeric or named)
18
- * - :name (named)
19
- */
20
- export function interpolateQuery(query: string, bindings: Bindings): string {
21
- // Helper to convert a value into a safe SQL literal
22
- const formatValue = (value: any): string => {
23
- if (value === null || value === undefined) return "NULL";
30
+ function interpolateQuery(query, bindings) {
31
+ const formatValue = (value) => {
32
+ if (value === null || value === void 0) return "NULL";
24
33
  if (typeof value === "string") return `'${value.replace(/'/g, "''")}'`;
25
34
  if (value instanceof DateTime) return `'${value.toISO()}'`;
26
35
  if (value instanceof Date) return `'${value.toISOString()}'`;
27
36
  if (Array.isArray(value))
28
- return value
29
- .map((v) => (typeof v === "string" ? `'${v.replace(/'/g, "''")}'` : v))
30
- .join(", ");
37
+ return value.map((v) => typeof v === "string" ? `'${v.replace(/'/g, "''")}'` : v).join(", ");
31
38
  if (typeof value === "object")
32
39
  return `'${JSON.stringify(value).replace(/'/g, "''")}'`;
33
40
  return value.toString();
34
41
  };
35
-
36
- // Case 1: Array-based bindings for '?' placeholders
37
42
  if (Array.isArray(bindings)) {
38
43
  let i = 0;
39
44
  return query.replace(/\?/g, () => {
@@ -42,120 +47,83 @@ export function interpolateQuery(query: string, bindings: Bindings): string {
42
47
  return formatValue(bindings[i++]);
43
48
  });
44
49
  }
45
-
46
- // Case 2: Named or numeric placeholders ($1, $name, :name)
47
50
  return query.replace(/(\$|\:)(\w+)/g, (match, prefix, keyOrIndex) => {
48
51
  let value;
49
-
50
52
  if (prefix === "$" && /^\d+$/.test(keyOrIndex)) {
51
- // Numeric placeholder: $1, $2, ...
52
53
  const index = parseInt(keyOrIndex, 10) - 1;
53
54
  const keys = Object.keys(bindings);
54
55
  if (index < 0 || index >= keys.length)
55
56
  throw new Error(`Missing binding for ${match}`);
56
- // @ts-expect-error
57
57
  value = bindings[keys[index]];
58
58
  } else {
59
- // Named placeholder: $name or :name
60
59
  if (!(keyOrIndex in bindings))
61
60
  throw new Error(`Missing binding for ${match}`);
62
61
  value = bindings[keyOrIndex];
63
62
  }
64
-
65
63
  return formatValue(value);
66
64
  });
67
65
  }
68
-
69
- export const formatSqlQuery = (query: string, language: SqlLanguage) => {
66
+ var formatSqlQuery = (query, language) => {
70
67
  return format(query, {
71
68
  language,
72
69
  dataTypeCase: "upper",
73
70
  keywordCase: "upper",
74
- functionCase: "upper",
71
+ functionCase: "upper"
75
72
  });
76
73
  };
77
-
78
- export function now() {
74
+ function now() {
79
75
  return DateTime.now().setZone("utc");
80
76
  }
81
-
82
- export function nowISO() {
83
- return now().toISO({ includeOffset: false }) as string;
77
+ function nowISO() {
78
+ return now().toISO({ includeOffset: false });
84
79
  }
85
-
86
- export function sqlDateTime(dateTime?: DateTime | null) {
80
+ function sqlDateTime(dateTime) {
87
81
  const time = dateTime ?? now();
88
-
89
82
  return time.toSQL({ includeOffset: false });
90
83
  }
91
-
92
- export function convertToUTC(dateTime: string) {
93
- return DateTime.fromISO(dateTime)
94
- .setZone("utc")
95
- .toISO({ includeOffset: false }) as string;
84
+ function convertToUTC(dateTime) {
85
+ return DateTime.fromISO(dateTime).setZone("utc").toISO({ includeOffset: false });
96
86
  }
97
-
98
- export function getMeta(metaUrl?: string): {
99
- __filename: string;
100
- __dirname: string;
101
- } {
87
+ function getMeta(metaUrl) {
102
88
  const isESM = typeof __dirname === "undefined";
103
-
104
89
  if (isESM) {
105
90
  if (!metaUrl) {
106
91
  throw new Error("In ESM, you must pass import.meta.url to getMeta()");
107
92
  }
108
-
109
- const __filename = fileURLToPath(metaUrl);
110
- const __dirname = path.dirname(__filename);
111
- return { __filename, __dirname };
93
+ const __filename2 = fileURLToPath(metaUrl);
94
+ const __dirname2 = path.dirname(__filename2);
95
+ return { __filename: __filename2, __dirname: __dirname2 };
112
96
  } else {
113
- // @ts-ignore - available only in CJS
114
97
  return { __filename, __dirname };
115
98
  }
116
99
  }
117
-
118
- export function isStaticFile(params: string[]) {
100
+ function isStaticFile(params) {
119
101
  return params.includes("assets");
120
102
  }
121
-
122
- export function stripBeforeAssetsPath(url: string) {
103
+ function stripBeforeAssetsPath(url) {
123
104
  const match = url.match(/assets.*/);
124
105
  return match ? match[0] : url;
125
106
  }
126
-
127
- export function prepareIgnoredPaths(path: string, ignoredPaths: RegExp[]) {
128
- const normalizedPath = path.replace(/^\/+|\/+$/g, "");
107
+ function prepareIgnoredPaths(path2, ignoredPaths) {
108
+ const normalizedPath = path2.replace(/^\/+|\/+$/g, "");
129
109
  ignoredPaths = [
130
110
  ...ignoredPaths,
131
- new RegExp(`^\/?${normalizedPath}(\/|$)`),
111
+ new RegExp(`^/?${normalizedPath}(/|$)`),
132
112
  /^\/?lens-config$/,
133
- /^\/\.well-known\//,
113
+ /^\/\.well-known\//
134
114
  ];
135
-
136
115
  return { ignoredPaths, normalizedPath };
137
116
  }
138
-
139
- export function shouldIgnoreCurrentPath(
140
- path: string,
141
- ignoredPaths: RegExp[],
142
- onlyPaths: RegExp[],
143
- ) {
117
+ function shouldIgnoreCurrentPath(path2, ignoredPaths, onlyPaths) {
144
118
  if (onlyPaths.length > 0) {
145
- return !onlyPaths.some((pattern) => pattern.test(path));
119
+ return !onlyPaths.some((pattern) => pattern.test(path2));
146
120
  }
147
-
148
- return ignoredPaths.some((pattern) => pattern.test(path));
121
+ return ignoredPaths.some((pattern) => pattern.test(path2));
149
122
  }
150
-
151
- export function prettyHrTime(
152
- hrtime: [number, number],
153
- verbose = false,
154
- ): string {
123
+ function prettyHrTime(hrtime, verbose = false) {
155
124
  const seconds = hrtime[0];
156
125
  const nanoseconds = hrtime[1];
157
- const ms = seconds * 1000 + nanoseconds / 1e6;
158
-
126
+ const ms = seconds * 1e3 + nanoseconds / 1e6;
159
127
  if (verbose) {
160
128
  if (seconds > 60) {
161
129
  const minutes = Math.floor(seconds / 60);
@@ -167,10 +135,25 @@ export function prettyHrTime(
167
135
  }
168
136
  return `${ms.toFixed(3)} ms`;
169
137
  }
170
-
171
- if (ms < 1000) {
138
+ if (ms < 1e3) {
172
139
  return `${ms.toFixed(0)} ms`;
173
140
  }
174
-
175
- return `${(ms / 1000).toFixed(1)} s`;
141
+ return `${(ms / 1e3).toFixed(1)} s`;
176
142
  }
143
+
144
+ export {
145
+ generateRandomUuid,
146
+ interpolateQuery,
147
+ formatSqlQuery,
148
+ now,
149
+ nowISO,
150
+ sqlDateTime,
151
+ convertToUTC,
152
+ getMeta,
153
+ isStaticFile,
154
+ stripBeforeAssetsPath,
155
+ prepareIgnoredPaths,
156
+ shouldIgnoreCurrentPath,
157
+ prettyHrTime,
158
+ utils_exports
159
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/core/watcher.ts
2
+ var Watcher = class {
3
+ };
4
+
5
+
6
+
7
+ exports.Watcher = Watcher;
@@ -0,0 +1,129 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } var _class;
2
+
3
+ var _chunkAUDSBNLFcjs = require('./chunk-AUDSBNLF.cjs');
4
+
5
+
6
+ var _chunkWU6IZUEVcjs = require('./chunk-WU6IZUEV.cjs');
7
+
8
+
9
+ var _chunkJZ2JLQXLcjs = require('./chunk-JZ2JLQXL.cjs');
10
+
11
+
12
+ var _chunkQRZUNYF6cjs = require('./chunk-QRZUNYF6.cjs');
13
+
14
+
15
+ var _chunkGI7SJDNQcjs = require('./chunk-GI7SJDNQ.cjs');
16
+
17
+ // src/core/lens.ts
18
+ var _path = require('path'); var path = _interopRequireWildcard(_path);
19
+ var Lens = (_class = class {
20
+ static __initStatic() {this.watchers = /* @__PURE__ */ new Map()}
21
+
22
+
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 } = _chunkWU6IZUEVcjs.getMeta.call(void 0, import.meta.url);
47
+ const uiPath = path.resolve(this.normalizeDirName(__dirname), "ui");
48
+ adapter.serveUI(uiPath, config.basePath, _chunkQRZUNYF6cjs.getUiConfig.call(void 0, ));
49
+ }
50
+ static setStore(store) {
51
+ this.store = store;
52
+ return this;
53
+ }
54
+ static async getStore() {
55
+ return await _asyncNullishCoalesce(this.store, async () => ( 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
+ _chunkGI7SJDNQcjs.Container.singleton("store", () => dbStore);
70
+ _chunkGI7SJDNQcjs.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: () => _chunkJZ2JLQXLcjs.ApiController.fetchUiConfig()
88
+ },
89
+ {
90
+ method: "GET",
91
+ path: `${basePath}/api/requests`,
92
+ handler: async (data) => await _chunkJZ2JLQXLcjs.ApiController.getRequests(data)
93
+ },
94
+ {
95
+ method: "GET",
96
+ path: `${basePath}/api/requests/:id`,
97
+ handler: async (data) => await _chunkJZ2JLQXLcjs.ApiController.getRequest(data)
98
+ },
99
+ {
100
+ method: "GET",
101
+ path: `${basePath}/api/queries`,
102
+ handler: async (data) => await _chunkJZ2JLQXLcjs.ApiController.getQueries(data)
103
+ },
104
+ {
105
+ method: "GET",
106
+ path: `${basePath}/api/queries/:id`,
107
+ handler: async (data) => await _chunkJZ2JLQXLcjs.ApiController.getQuery(data)
108
+ },
109
+ {
110
+ method: "DELETE",
111
+ path: `${basePath}/api/truncate`,
112
+ handler: async () => await _chunkJZ2JLQXLcjs.ApiController.truncate()
113
+ }
114
+ ];
115
+ return { apiRoutes };
116
+ }
117
+ static async getDefaultStore() {
118
+ const store = new (0, _chunkAUDSBNLFcjs.BetterSqliteStore)();
119
+ await store.initialize();
120
+ return store;
121
+ }
122
+ static normalizeDirName(path2) {
123
+ return path2.replace(/(\/packages\/)[^/]+(?=\/dist)/, "$1core");
124
+ }
125
+ }, _class.__initStatic(), _class);
126
+
127
+
128
+
129
+ exports.Lens = Lens;
@@ -0,0 +1,7 @@
1
+ // src/abstracts/store.ts
2
+ var Store = class {
3
+ };
4
+
5
+ export {
6
+ Store
7
+ };
@@ -0,0 +1,10 @@
1
+ // src/types/index.ts
2
+ var WatcherTypeEnum = /* @__PURE__ */ ((WatcherTypeEnum2) => {
3
+ WatcherTypeEnum2["REQUEST"] = "request";
4
+ WatcherTypeEnum2["QUERY"] = "query";
5
+ return WatcherTypeEnum2;
6
+ })(WatcherTypeEnum || {});
7
+
8
+ export {
9
+ WatcherTypeEnum
10
+ };
@@ -0,0 +1,38 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;// src/context/container.ts
2
+ var Container = (_class = class {
3
+ static __initStatic() {this.bindings = /* @__PURE__ */ new Map()}
4
+ static __initStatic2() {this.singletons = /* @__PURE__ */ new Map()}
5
+ static __initStatic3() {this.instances = /* @__PURE__ */ new Map()}
6
+ static bind(key, factory) {
7
+ this.bindings.set(key, factory);
8
+ }
9
+ static singleton(key, factory) {
10
+ this.singletons.set(key, factory);
11
+ }
12
+ static make(key) {
13
+ if (this.instances.has(key)) {
14
+ return this.instances.get(key);
15
+ }
16
+ if (this.singletons.has(key)) {
17
+ const instance = this.singletons.get(key)();
18
+ this.instances.set(key, instance);
19
+ return instance;
20
+ }
21
+ if (this.bindings.has(key)) {
22
+ return this.bindings.get(key)();
23
+ }
24
+ throw new Error(`Service "${key}" is not bound in the container`);
25
+ }
26
+ static has(key) {
27
+ return this.bindings.has(key) || this.singletons.has(key) || this.instances.has(key);
28
+ }
29
+ static clear() {
30
+ this.bindings.clear();
31
+ this.singletons.clear();
32
+ this.instances.clear();
33
+ }
34
+ }, _class.__initStatic(), _class.__initStatic2(), _class.__initStatic3(), _class);
35
+
36
+
37
+
38
+ exports.Container = Container;
@@ -0,0 +1,122 @@
1
+ import {
2
+ sqlDateTime
3
+ } from "./chunk-EJ5BW35V.js";
4
+ import {
5
+ Store
6
+ } from "./chunk-FKMBNWX4.js";
7
+
8
+ // src/stores/better_sqlite.ts
9
+ import { randomUUID } from "crypto";
10
+ import Database from "libsql";
11
+ var TABLE_NAME = "lens_entries";
12
+ var BetterSqliteStore = class extends Store {
13
+ connection;
14
+ async initialize() {
15
+ this.connection = new Database("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: entry.id ?? randomUUID(),
27
+ data: JSON.stringify(entry.data),
28
+ type: entry.type,
29
+ created_at: entry.timestamp ?? sqlDateTime(),
30
+ lens_entry_id: entry.requestId || null,
31
+ minimalData: JSON.stringify(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
+ export {
121
+ BetterSqliteStore
122
+ };
@@ -0,0 +1,87 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkQRZUNYF6cjs = require('./chunk-QRZUNYF6.cjs');
5
+
6
+ // src/core/api_controller.ts
7
+ var ApiController = class {
8
+ static async getRequests({ qs }) {
9
+ return this.paginatedResponse(
10
+ await _chunkQRZUNYF6cjs.getStore.call(void 0, ).getAllRequests(this.extractPaginationParams(qs))
11
+ );
12
+ }
13
+ static async getRequest({
14
+ params
15
+ }) {
16
+ const request = await _chunkQRZUNYF6cjs.getStore.call(void 0, ).find("request" /* REQUEST */, params.id);
17
+ if (!request) {
18
+ return this.notFoundResponse();
19
+ }
20
+ return this.resourceResponse(request);
21
+ }
22
+ static async getQueries({
23
+ qs
24
+ }) {
25
+ const queries = await _chunkQRZUNYF6cjs.getStore.call(void 0, ).getAllQueries(
26
+ this.extractPaginationParams(qs)
27
+ );
28
+ return this.paginatedResponse(queries);
29
+ }
30
+ static async getQuery({
31
+ params
32
+ }) {
33
+ const query = await _chunkQRZUNYF6cjs.getStore.call(void 0, ).find("query" /* QUERY */, params.id);
34
+ if (!query) {
35
+ return this.notFoundResponse();
36
+ }
37
+ return this.resourceResponse(query);
38
+ }
39
+ static async truncate() {
40
+ await _chunkQRZUNYF6cjs.getStore.call(void 0, ).truncate();
41
+ return this.baseResponse({}, 200, "All entries cleared");
42
+ }
43
+ static fetchUiConfig() {
44
+ return _chunkQRZUNYF6cjs.getUiConfig.call(void 0, );
45
+ }
46
+ static extractPaginationParams(qs) {
47
+ if (!qs || Object.keys(qs).length === 0) {
48
+ return { page: 1, perPage: 100 };
49
+ }
50
+ let page = Number(qs.page);
51
+ let perPage = Number(qs.perPage);
52
+ if (!Number.isInteger(perPage) || perPage > 100 || perPage < 5) {
53
+ perPage = 100;
54
+ }
55
+ if (!Number.isInteger(page) || page < 1) {
56
+ page = 1;
57
+ }
58
+ return { page, perPage };
59
+ }
60
+ static resourceResponse(data) {
61
+ return this.baseResponse(data, 200, "Data fetched successfully");
62
+ }
63
+ static notFoundResponse(message = "Could not find the requested resource") {
64
+ return this.baseResponse(null, 404, message);
65
+ }
66
+ static paginatedResponse(data) {
67
+ return this.baseResponse(data, 200, "Data fetched successfully");
68
+ }
69
+ static baseResponse(data, status, message) {
70
+ if (!data) {
71
+ return { status, message, data: null };
72
+ }
73
+ if ("meta" in data) {
74
+ return {
75
+ status,
76
+ message,
77
+ data: data.data,
78
+ meta: data.meta
79
+ };
80
+ }
81
+ return { status, message, data };
82
+ }
83
+ };
84
+
85
+
86
+
87
+ exports.ApiController = ApiController;
@@ -0,0 +1,9 @@
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
+ export {
8
+ __export
9
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkGI7SJDNQcjs = require('./chunk-GI7SJDNQ.cjs');
4
+
5
+ // src/context/context.ts
6
+ var getStore = () => {
7
+ return _chunkGI7SJDNQcjs.Container.make("store");
8
+ };
9
+ var getUiConfig = () => {
10
+ return _chunkGI7SJDNQcjs.Container.make("uiConfig");
11
+ };
12
+
13
+
14
+
15
+
16
+ exports.getStore = getStore; exports.getUiConfig = getUiConfig;
@@ -0,0 +1,14 @@
1
+ // src/utils/event_emitter.ts
2
+ import { AsyncResource } from "async_hooks";
3
+ import Emittery from "emittery";
4
+ var createEmittery = () => {
5
+ return new Emittery();
6
+ };
7
+ var lensResource = new AsyncResource("lens-emitter");
8
+ var lensEmitter = new Emittery();
9
+
10
+ export {
11
+ createEmittery,
12
+ lensResource,
13
+ lensEmitter
14
+ };