@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.
Files changed (93) hide show
  1. package/README.md +69 -0
  2. package/dist/abstracts/store.cjs +23 -0
  3. package/dist/abstracts/store.d.cts +7 -2
  4. package/dist/abstracts/store.d.ts +7 -2
  5. package/dist/abstracts/store.js +23 -0
  6. package/dist/core/api_controller.cjs +47 -4
  7. package/dist/core/api_controller.d.cts +7 -3
  8. package/dist/core/api_controller.d.ts +7 -3
  9. package/dist/core/api_controller.js +47 -4
  10. package/dist/core/lens.cjs +109 -10
  11. package/dist/core/lens.js +110 -11
  12. package/dist/exception-3AZsPtAg.d.ts +52 -0
  13. package/dist/exception-C69UCHPk.d.cts +52 -0
  14. package/dist/index.cjs +301 -19
  15. package/dist/index.d.cts +7 -2
  16. package/dist/index.d.ts +7 -2
  17. package/dist/index.js +296 -20
  18. package/dist/stores/better_sqlite.cjs +40 -6
  19. package/dist/stores/better_sqlite.d.cts +17 -1
  20. package/dist/stores/better_sqlite.d.ts +17 -1
  21. package/dist/stores/better_sqlite.js +41 -7
  22. package/dist/stores/index.cjs +40 -6
  23. package/dist/stores/index.js +41 -7
  24. package/dist/types/index.cjs +2 -0
  25. package/dist/types/index.d.cts +49 -2
  26. package/dist/types/index.d.ts +49 -2
  27. package/dist/types/index.js +2 -0
  28. package/dist/ui/assets/CacheActionBadge-3t8U516j.js +1 -0
  29. package/dist/ui/assets/CacheEntriesTable-BqLquILg.js +1 -0
  30. package/dist/ui/assets/CacheEntryContainer-B86waEsR.js +2 -0
  31. package/dist/ui/assets/CacheEntryDetails-Dm-oXALj.js +1 -0
  32. package/dist/ui/assets/CacheEntryDetailsContainer-BCyXGgkx.js +2 -0
  33. package/dist/ui/assets/ExceptionContainer-DSQBz5cb.js +2 -0
  34. package/dist/ui/assets/ExceptionDetails-gmpSQ_eu.js +16 -0
  35. package/dist/ui/assets/ExceptionDetailsContainer-BHIz-TUv.js +2 -0
  36. package/dist/ui/assets/ExceptionTable-BhrX9MSS.js +1 -0
  37. package/dist/ui/assets/LoadMore-26PcNWcP.js +1 -0
  38. package/dist/ui/assets/QueriesContainer-BSF-O4s3.js +2 -0
  39. package/dist/ui/assets/{QueryDetailsContainer-E7P-IO7f.js → QueryDetailsContainer-BjQM9QIb.js} +15 -15
  40. package/dist/ui/assets/QueryTable-szgIT5Uc.js +1 -0
  41. package/dist/ui/assets/RequestDetails-CvQhX-2F.js +1 -0
  42. package/dist/ui/assets/{RequestDetailsContainer-DuDo-IqS.js → RequestDetailsContainer-XYPFJFX0.js} +2 -2
  43. package/dist/ui/assets/RequestsContainer-D0QPK2Ii.js +2 -0
  44. package/dist/ui/assets/RequetsTable-6Fqchsrt.js +1 -0
  45. package/dist/ui/assets/{StatusCode-FQEjz7gK.js → StatusCode-CfVCLID2.js} +1 -1
  46. package/dist/ui/assets/TabbedDataViewer-Cl5ednx4.js +1 -0
  47. package/dist/ui/assets/{Table-DYaXk80S.js → Table-CGe8JwTO.js} +2 -2
  48. package/dist/ui/assets/columns-BFxCubt5.js +1 -0
  49. package/dist/ui/assets/columns-Cw7tw3Em.js +1 -0
  50. package/dist/ui/assets/columns-RiCoo9Ea.js +1 -0
  51. package/dist/ui/assets/{index-CpP2Ap5X.js → index-BRRKsoNv.js} +1 -1
  52. package/dist/ui/assets/index-BzFeZyjf.css +1 -0
  53. package/dist/ui/assets/{index-BS8XxorB.js → index-XoJlyTFO.js} +32 -22
  54. package/dist/ui/assets/useCacheEntries-SCADuxKq.js +1 -0
  55. package/dist/ui/assets/useExceptions-BMGL3nir.js +1 -0
  56. package/dist/ui/assets/useLensApi-BYyiIIZR.js +1 -0
  57. package/dist/ui/assets/{useLoadMore-CJltToLI.js → useLoadMore-CksOcXOF.js} +1 -1
  58. package/dist/ui/assets/useQueries-6nYr0oG5.js +1 -0
  59. package/dist/ui/index.html +2 -2
  60. package/dist/utils/async_context.cjs +144 -0
  61. package/dist/utils/async_context.d.cts +13 -0
  62. package/dist/utils/async_context.d.ts +13 -0
  63. package/dist/utils/async_context.js +108 -0
  64. package/dist/utils/event_emitter.cjs +5 -2
  65. package/dist/utils/event_emitter.d.cts +8 -1
  66. package/dist/utils/event_emitter.d.ts +8 -1
  67. package/dist/utils/event_emitter.js +3 -1
  68. package/dist/utils/exception.cjs +130 -0
  69. package/dist/utils/exception.d.cts +3 -0
  70. package/dist/utils/exception.d.ts +3 -0
  71. package/dist/utils/exception.js +91 -0
  72. package/dist/watchers/cache_watcher.cjs +107 -0
  73. package/dist/watchers/cache_watcher.d.cts +11 -0
  74. package/dist/watchers/cache_watcher.d.ts +11 -0
  75. package/dist/watchers/cache_watcher.js +84 -0
  76. package/dist/watchers/exception_watcher.cjs +108 -0
  77. package/dist/watchers/exception_watcher.d.cts +10 -0
  78. package/dist/watchers/exception_watcher.d.ts +10 -0
  79. package/dist/watchers/exception_watcher.js +75 -0
  80. package/dist/watchers/index.cjs +81 -0
  81. package/dist/watchers/index.d.cts +2 -0
  82. package/dist/watchers/index.d.ts +2 -0
  83. package/dist/watchers/index.js +69 -0
  84. package/package.json +8 -6
  85. package/dist/ui/assets/QueriesContainer-CAAsjjW5.js +0 -2
  86. package/dist/ui/assets/QueryTable-BcrtUssT.js +0 -1
  87. package/dist/ui/assets/RequestDetails-C2DZBu5H.js +0 -1
  88. package/dist/ui/assets/RequestsContainer-DK3hQVz9.js +0 -2
  89. package/dist/ui/assets/RequetsTable-DgP8p60b.js +0 -1
  90. package/dist/ui/assets/TabbedDataViewer-cBDdPwIz.js +0 -1
  91. package/dist/ui/assets/index-DzNHqeKh.css +0 -1
  92. package/dist/ui/assets/useLensApi-DG6atd6d.js +0 -1
  93. package/dist/ui/assets/useQueries-C8mDDDc6.js +0 -1
@@ -0,0 +1 @@
1
+ import{r as t}from"./index-XoJlyTFO.js";import{D as I,u as h}from"./useLensApi-BYyiIIZR.js";function C(){const[n,r]=t.useState([]),[l,m]=t.useState(),[c,a]=t.useState(!1),[i,u]=t.useState(I),{getCacheEntries:e,getCacheEntryById:f}=h(),d=t.useCallback(async o=>{a(!0),f(o).then(s=>{m(s.data)}).finally(()=>{a(!1)})},[e]),g=t.useCallback(async o=>{a(!0),await e(o??1).then(s=>{r(s.data),u(s.meta)}).finally(()=>{a(!1)})},[e]);return{loadMoreItems:t.useMemo(()=>({initialData:n,meta:i,loading:c,fetchRawPage:e}),[n,i,c,e]),getItems:g,getItem:d,items:n,item:l}}export{C as u};
@@ -0,0 +1 @@
1
+ import{r as t}from"./index-XoJlyTFO.js";import{D as g,u as I}from"./useLensApi-BYyiIIZR.js";function M(){const[o,l]=t.useState([]),[m,u]=t.useState(),[c,a]=t.useState(!1),[i,r]=t.useState(g),{getExceptions:e,getExceptionById:f}=I(),p=t.useCallback(async n=>{a(!0),f(n).then(s=>{u(s.data)}).finally(()=>{a(!1)})},[e]),d=t.useCallback(async n=>{a(!0),await e(n??1).then(s=>{l(s.data),r(s.meta)}).finally(()=>{a(!1)})},[e]);return{loadMoreItems:t.useMemo(()=>({initialData:o,meta:i,loading:c,fetchRawPage:e}),[o,i,c,e]),getItems:d,getItem:p,items:o,item:m}}export{M as u};
@@ -0,0 +1 @@
1
+ import{k as p,l as s}from"./index-XoJlyTFO.js";const B={currentPage:1,lastPage:1,total:0},I=()=>{const t=p();async function n(e,a){const r=await fetch(e,{headers:{"Content-Type":"application/json"},...a});if(!r.ok)throw new Error(`Failed to fetch: ${e}`);return r.json()}const c=(e,a)=>{const r=new URLSearchParams(Object.entries(a||{}).reduce((i,[u,o])=>(o!=null&&(i[u]=String(o)),i),{}));return`${e}${r.toString()?`?${r}`:""}`};return{getAllRequests:async e=>n(s(c(t.api.requests,{page:e}))),getRequestById:async e=>n(s(`${t.api.requests}/${e}`)),getQueries:async e=>n(s(c(t.api.queries,{page:e}))),getQueryById:async e=>n(s(`${t.api.queries}/${e}`)),getCacheEntries:async e=>n(s(c(t.api.cache,{page:e}))),getCacheEntryById:async e=>n(s(`${t.api.cache}/${e}`)),getExceptions:async e=>n(s(c(t.api.exceptions,{page:e}))),getExceptionById:async e=>n(s(`${t.api.exceptions}/${e}`))}};export{B as D,I as u};
@@ -1 +1 @@
1
- import{r as e}from"./index-BS8XxorB.js";function D({paginatedPage:t}){const[f,r]=e.useState([]),[m,l]=e.useState(1),[c,s]=e.useState(!1),[n,o]=e.useState(!1);return e.useEffect(()=>{s(t.loading),o(t.meta.currentPage<t.meta.lastPage),l(1),t.loading||r(t.initialData)},[t.initialData,t.loading,t.meta.currentPage,t.meta.lastPage]),{data:f,loading:c,hasMore:n,loadMore:async()=>{if(c||!n)return;s(!0);const u=m+1,a=await t.fetchRawPage(u);r(i=>[...i,...a.data]),l(u),a?.meta?o(a.meta.currentPage<a.meta.lastPage):o(!1),s(!1)}}}export{D as u};
1
+ import{r as e}from"./index-XoJlyTFO.js";function D({paginatedPage:t}){const[f,r]=e.useState([]),[m,l]=e.useState(1),[c,s]=e.useState(!1),[n,o]=e.useState(!1);return e.useEffect(()=>{s(t.loading),o(t.meta.currentPage<t.meta.lastPage),l(1),t.loading||r(t.initialData)},[t.initialData,t.loading,t.meta.currentPage,t.meta.lastPage]),{data:f,loading:c,hasMore:n,loadMore:async()=>{if(c||!n)return;s(!0);const u=m+1,a=await t.fetchRawPage(u);r(i=>[...i,...a.data]),l(u),a?.meta?o(a.meta.currentPage<a.meta.lastPage):o(!1),s(!1)}}}export{D as u};
@@ -0,0 +1 @@
1
+ import{r as e}from"./index-XoJlyTFO.js";import{D as Q,u as g}from"./useLensApi-BYyiIIZR.js";function q(){const[u,c]=e.useState([]),[i,l]=e.useState(),[r,s]=e.useState(!1),[n,f]=e.useState(Q),{getQueries:t,getQueryById:y}=g(),d=e.useCallback(async o=>{s(!0),y(o).then(a=>{l(a.data)}).finally(()=>{s(!1)})},[t]),m=e.useCallback(async o=>{s(!0),await t(o??1).then(a=>{c(a.data),f(a.meta)}).finally(()=>{s(!1)})},[t]);return{loadMoreRequests:e.useMemo(()=>({initialData:u,meta:n,loading:r,fetchRawPage:t}),[u,n,r,t]),fetchQueries:m,fetchQuery:d,queries:u,query:i}}export{q as u};
@@ -5,8 +5,8 @@
5
5
  <link rel="icon" type="image/svg+xml" href="./assets/favicon-CwRXoGYE.ico" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>Lens</title>
8
- <script type="module" crossorigin src="./assets/index-BS8XxorB.js"></script>
9
- <link rel="stylesheet" crossorigin href="./assets/index-DzNHqeKh.css">
8
+ <script type="module" crossorigin src="./assets/index-XoJlyTFO.js"></script>
9
+ <link rel="stylesheet" crossorigin href="./assets/index-BzFeZyjf.css">
10
10
  </head>
11
11
  <body>
12
12
  <div id="root"></div>
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/utils/async_context.ts
31
+ var async_context_exports = {};
32
+ __export(async_context_exports, {
33
+ handleUncaughExceptions: () => handleUncaughExceptions,
34
+ lensContext: () => lensContext
35
+ });
36
+ module.exports = __toCommonJS(async_context_exports);
37
+ var import_async_hooks = require("async_hooks");
38
+
39
+ // src/utils/exception.ts
40
+ var import_stack_utils = __toESM(require("stack-utils"), 1);
41
+ var import_node_path = __toESM(require("path"), 1);
42
+ var import_node_fs = require("fs");
43
+ var import_date = require("@lensjs/date");
44
+ var stackUtils = new import_stack_utils.default({
45
+ cwd: process.cwd(),
46
+ internals: import_stack_utils.default.nodeInternals()
47
+ });
48
+ function cleanStack(stack) {
49
+ if (!stack) return "";
50
+ return stackUtils.clean(stack);
51
+ }
52
+ function getFileInfo(stack) {
53
+ if (!stack) {
54
+ return { file: "", line: 0, column: 0, function: "" };
55
+ }
56
+ const firstLine = stack.split("\n")[1] ?? "";
57
+ const fileInfo = stackUtils.parseLine(firstLine) ?? {
58
+ file: "",
59
+ line: 0,
60
+ column: 0,
61
+ function: ""
62
+ };
63
+ return {
64
+ file: fileInfo.file ? import_node_path.default.resolve(process.cwd(), fileInfo.file) : "",
65
+ line: fileInfo.line ?? 0,
66
+ column: fileInfo.column ?? 0,
67
+ function: fileInfo.function ?? ""
68
+ };
69
+ }
70
+ function getStackTrace(stack) {
71
+ if (!stack) return [];
72
+ return cleanStack(stack).split("\n").filter((frame) => Boolean(frame));
73
+ }
74
+ function extractCodeFrame({
75
+ file,
76
+ line,
77
+ column,
78
+ contextLines = 6
79
+ }) {
80
+ if (!file) return null;
81
+ const fullPath = import_node_path.default.isAbsolute(file) ? file : import_node_path.default.resolve(process.cwd(), file);
82
+ if (!(0, import_node_fs.existsSync)(fullPath)) return null;
83
+ const fileContent = (0, import_node_fs.readFileSync)(fullPath, "utf-8");
84
+ const lines = fileContent.split(/\r?\n/);
85
+ if (line < 1 || line > lines.length) return null;
86
+ const start = Math.max(0, line - 1 - contextLines);
87
+ const end = Math.min(lines.length, line - 1 + contextLines + 1);
88
+ const snippet = lines.slice(start, end);
89
+ const relativeLine = line - 1 - start;
90
+ const errorLine = lines[line - 1] ?? "";
91
+ return {
92
+ file: fullPath,
93
+ line,
94
+ column,
95
+ context: {
96
+ pre: snippet.slice(0, relativeLine),
97
+ error: errorLine,
98
+ post: snippet.slice(relativeLine + 1)
99
+ }
100
+ };
101
+ }
102
+ function constructErrorObject(err) {
103
+ const fileInfo = getFileInfo(err.stack);
104
+ const codeFrame = extractCodeFrame({
105
+ file: fileInfo.file,
106
+ line: fileInfo.line,
107
+ column: fileInfo.column
108
+ });
109
+ return {
110
+ name: err.name,
111
+ message: err.message,
112
+ createdAt: (0, import_date.nowISO)(),
113
+ fileInfo: {
114
+ file: fileInfo.file,
115
+ function: fileInfo.function
116
+ },
117
+ cause: err.cause ?? null,
118
+ trace: getStackTrace(err.stack),
119
+ codeFrame,
120
+ originalStack: codeFrame === null ? cleanStack(err.stack) : null
121
+ };
122
+ }
123
+
124
+ // src/utils/async_context.ts
125
+ var lensContext = new import_async_hooks.AsyncLocalStorage();
126
+ var handleUncaughExceptions = (logger) => {
127
+ process.on("uncaughtExceptionMonitor", async (err) => {
128
+ await logger.log({
129
+ ...constructErrorObject(err),
130
+ requestId: lensContext.getStore()?.requestId
131
+ });
132
+ });
133
+ process.on("uncaughtException", async (err) => {
134
+ await logger.log({
135
+ ...constructErrorObject(err),
136
+ requestId: lensContext.getStore()?.requestId
137
+ });
138
+ });
139
+ };
140
+ // Annotate the CommonJS export names for ESM import in node:
141
+ 0 && (module.exports = {
142
+ handleUncaughExceptions,
143
+ lensContext
144
+ });
@@ -0,0 +1,13 @@
1
+ import { AsyncLocalStorage } from 'async_hooks';
2
+ import ExceptionWatcher from '../watchers/exception_watcher.cjs';
3
+ import '../core/watcher.cjs';
4
+ import '../types/index.cjs';
5
+ import 'sql-formatter';
6
+
7
+ type LensContext = {
8
+ requestId: string;
9
+ };
10
+ declare const lensContext: AsyncLocalStorage<LensContext>;
11
+ declare const handleUncaughExceptions: (logger: ExceptionWatcher) => void;
12
+
13
+ export { handleUncaughExceptions, lensContext };
@@ -0,0 +1,13 @@
1
+ import { AsyncLocalStorage } from 'async_hooks';
2
+ import ExceptionWatcher from '../watchers/exception_watcher.js';
3
+ import '../core/watcher.js';
4
+ import '../types/index.js';
5
+ import 'sql-formatter';
6
+
7
+ type LensContext = {
8
+ requestId: string;
9
+ };
10
+ declare const lensContext: AsyncLocalStorage<LensContext>;
11
+ declare const handleUncaughExceptions: (logger: ExceptionWatcher) => void;
12
+
13
+ export { handleUncaughExceptions, lensContext };
@@ -0,0 +1,108 @@
1
+ // src/utils/async_context.ts
2
+ import { AsyncLocalStorage } from "async_hooks";
3
+
4
+ // src/utils/exception.ts
5
+ import StackUtils from "stack-utils";
6
+ import path from "path";
7
+ import { existsSync, readFileSync } from "fs";
8
+ import { nowISO } from "@lensjs/date";
9
+ var stackUtils = new StackUtils({
10
+ cwd: process.cwd(),
11
+ internals: StackUtils.nodeInternals()
12
+ });
13
+ function cleanStack(stack) {
14
+ if (!stack) return "";
15
+ return stackUtils.clean(stack);
16
+ }
17
+ function getFileInfo(stack) {
18
+ if (!stack) {
19
+ return { file: "", line: 0, column: 0, function: "" };
20
+ }
21
+ const firstLine = stack.split("\n")[1] ?? "";
22
+ const fileInfo = stackUtils.parseLine(firstLine) ?? {
23
+ file: "",
24
+ line: 0,
25
+ column: 0,
26
+ function: ""
27
+ };
28
+ return {
29
+ file: fileInfo.file ? path.resolve(process.cwd(), fileInfo.file) : "",
30
+ line: fileInfo.line ?? 0,
31
+ column: fileInfo.column ?? 0,
32
+ function: fileInfo.function ?? ""
33
+ };
34
+ }
35
+ function getStackTrace(stack) {
36
+ if (!stack) return [];
37
+ return cleanStack(stack).split("\n").filter((frame) => Boolean(frame));
38
+ }
39
+ function extractCodeFrame({
40
+ file,
41
+ line,
42
+ column,
43
+ contextLines = 6
44
+ }) {
45
+ if (!file) return null;
46
+ const fullPath = path.isAbsolute(file) ? file : path.resolve(process.cwd(), file);
47
+ if (!existsSync(fullPath)) return null;
48
+ const fileContent = readFileSync(fullPath, "utf-8");
49
+ const lines = fileContent.split(/\r?\n/);
50
+ if (line < 1 || line > lines.length) return null;
51
+ const start = Math.max(0, line - 1 - contextLines);
52
+ const end = Math.min(lines.length, line - 1 + contextLines + 1);
53
+ const snippet = lines.slice(start, end);
54
+ const relativeLine = line - 1 - start;
55
+ const errorLine = lines[line - 1] ?? "";
56
+ return {
57
+ file: fullPath,
58
+ line,
59
+ column,
60
+ context: {
61
+ pre: snippet.slice(0, relativeLine),
62
+ error: errorLine,
63
+ post: snippet.slice(relativeLine + 1)
64
+ }
65
+ };
66
+ }
67
+ function constructErrorObject(err) {
68
+ const fileInfo = getFileInfo(err.stack);
69
+ const codeFrame = extractCodeFrame({
70
+ file: fileInfo.file,
71
+ line: fileInfo.line,
72
+ column: fileInfo.column
73
+ });
74
+ return {
75
+ name: err.name,
76
+ message: err.message,
77
+ createdAt: nowISO(),
78
+ fileInfo: {
79
+ file: fileInfo.file,
80
+ function: fileInfo.function
81
+ },
82
+ cause: err.cause ?? null,
83
+ trace: getStackTrace(err.stack),
84
+ codeFrame,
85
+ originalStack: codeFrame === null ? cleanStack(err.stack) : null
86
+ };
87
+ }
88
+
89
+ // src/utils/async_context.ts
90
+ var lensContext = new AsyncLocalStorage();
91
+ var handleUncaughExceptions = (logger) => {
92
+ process.on("uncaughtExceptionMonitor", async (err) => {
93
+ await logger.log({
94
+ ...constructErrorObject(err),
95
+ requestId: lensContext.getStore()?.requestId
96
+ });
97
+ });
98
+ process.on("uncaughtException", async (err) => {
99
+ await logger.log({
100
+ ...constructErrorObject(err),
101
+ requestId: lensContext.getStore()?.requestId
102
+ });
103
+ });
104
+ };
105
+ export {
106
+ handleUncaughExceptions,
107
+ lensContext
108
+ };
@@ -30,14 +30,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/utils/event_emitter.ts
31
31
  var event_emitter_exports = {};
32
32
  __export(event_emitter_exports, {
33
- createEmittery: () => createEmittery
33
+ createEmittery: () => createEmittery,
34
+ lensEmitter: () => lensEmitter
34
35
  });
35
36
  module.exports = __toCommonJS(event_emitter_exports);
36
37
  var import_emittery = __toESM(require("emittery"), 1);
37
38
  var createEmittery = () => {
38
39
  return new import_emittery.default();
39
40
  };
41
+ var lensEmitter = createEmittery();
40
42
  // Annotate the CommonJS export names for ESM import in node:
41
43
  0 && (module.exports = {
42
- createEmittery
44
+ createEmittery,
45
+ lensEmitter
43
46
  });
@@ -1,6 +1,13 @@
1
1
  import * as emittery from 'emittery';
2
2
  import emittery__default from 'emittery';
3
+ import { CacheEntry } from '../types/index.cjs';
4
+ import 'sql-formatter';
3
5
 
4
6
  declare const createEmittery: <T extends Record<string, any>>() => emittery__default<T, T & emittery.OmnipresentEventData, emittery.DatalessEventNames<T>>;
7
+ declare const lensEmitter: emittery__default<{
8
+ cache: CacheEntry;
9
+ }, {
10
+ cache: CacheEntry;
11
+ } & emittery.OmnipresentEventData, never>;
5
12
 
6
- export { createEmittery };
13
+ export { createEmittery, lensEmitter };
@@ -1,6 +1,13 @@
1
1
  import * as emittery from 'emittery';
2
2
  import emittery__default from 'emittery';
3
+ import { CacheEntry } from '../types/index.js';
4
+ import 'sql-formatter';
3
5
 
4
6
  declare const createEmittery: <T extends Record<string, any>>() => emittery__default<T, T & emittery.OmnipresentEventData, emittery.DatalessEventNames<T>>;
7
+ declare const lensEmitter: emittery__default<{
8
+ cache: CacheEntry;
9
+ }, {
10
+ cache: CacheEntry;
11
+ } & emittery.OmnipresentEventData, never>;
5
12
 
6
- export { createEmittery };
13
+ export { createEmittery, lensEmitter };
@@ -3,6 +3,8 @@ import Emittery from "emittery";
3
3
  var createEmittery = () => {
4
4
  return new Emittery();
5
5
  };
6
+ var lensEmitter = createEmittery();
6
7
  export {
7
- createEmittery
8
+ createEmittery,
9
+ lensEmitter
8
10
  };
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/utils/exception.ts
31
+ var exception_exports = {};
32
+ __export(exception_exports, {
33
+ cleanStack: () => cleanStack,
34
+ constructErrorObject: () => constructErrorObject,
35
+ extractCodeFrame: () => extractCodeFrame,
36
+ getFileInfo: () => getFileInfo,
37
+ getStackTrace: () => getStackTrace
38
+ });
39
+ module.exports = __toCommonJS(exception_exports);
40
+ var import_stack_utils = __toESM(require("stack-utils"), 1);
41
+ var import_node_path = __toESM(require("path"), 1);
42
+ var import_node_fs = require("fs");
43
+ var import_date = require("@lensjs/date");
44
+ var stackUtils = new import_stack_utils.default({
45
+ cwd: process.cwd(),
46
+ internals: import_stack_utils.default.nodeInternals()
47
+ });
48
+ function cleanStack(stack) {
49
+ if (!stack) return "";
50
+ return stackUtils.clean(stack);
51
+ }
52
+ function getFileInfo(stack) {
53
+ if (!stack) {
54
+ return { file: "", line: 0, column: 0, function: "" };
55
+ }
56
+ const firstLine = stack.split("\n")[1] ?? "";
57
+ const fileInfo = stackUtils.parseLine(firstLine) ?? {
58
+ file: "",
59
+ line: 0,
60
+ column: 0,
61
+ function: ""
62
+ };
63
+ return {
64
+ file: fileInfo.file ? import_node_path.default.resolve(process.cwd(), fileInfo.file) : "",
65
+ line: fileInfo.line ?? 0,
66
+ column: fileInfo.column ?? 0,
67
+ function: fileInfo.function ?? ""
68
+ };
69
+ }
70
+ function getStackTrace(stack) {
71
+ if (!stack) return [];
72
+ return cleanStack(stack).split("\n").filter((frame) => Boolean(frame));
73
+ }
74
+ function extractCodeFrame({
75
+ file,
76
+ line,
77
+ column,
78
+ contextLines = 6
79
+ }) {
80
+ if (!file) return null;
81
+ const fullPath = import_node_path.default.isAbsolute(file) ? file : import_node_path.default.resolve(process.cwd(), file);
82
+ if (!(0, import_node_fs.existsSync)(fullPath)) return null;
83
+ const fileContent = (0, import_node_fs.readFileSync)(fullPath, "utf-8");
84
+ const lines = fileContent.split(/\r?\n/);
85
+ if (line < 1 || line > lines.length) return null;
86
+ const start = Math.max(0, line - 1 - contextLines);
87
+ const end = Math.min(lines.length, line - 1 + contextLines + 1);
88
+ const snippet = lines.slice(start, end);
89
+ const relativeLine = line - 1 - start;
90
+ const errorLine = lines[line - 1] ?? "";
91
+ return {
92
+ file: fullPath,
93
+ line,
94
+ column,
95
+ context: {
96
+ pre: snippet.slice(0, relativeLine),
97
+ error: errorLine,
98
+ post: snippet.slice(relativeLine + 1)
99
+ }
100
+ };
101
+ }
102
+ function constructErrorObject(err) {
103
+ const fileInfo = getFileInfo(err.stack);
104
+ const codeFrame = extractCodeFrame({
105
+ file: fileInfo.file,
106
+ line: fileInfo.line,
107
+ column: fileInfo.column
108
+ });
109
+ return {
110
+ name: err.name,
111
+ message: err.message,
112
+ createdAt: (0, import_date.nowISO)(),
113
+ fileInfo: {
114
+ file: fileInfo.file,
115
+ function: fileInfo.function
116
+ },
117
+ cause: err.cause ?? null,
118
+ trace: getStackTrace(err.stack),
119
+ codeFrame,
120
+ originalStack: codeFrame === null ? cleanStack(err.stack) : null
121
+ };
122
+ }
123
+ // Annotate the CommonJS export names for ESM import in node:
124
+ 0 && (module.exports = {
125
+ cleanStack,
126
+ constructErrorObject,
127
+ extractCodeFrame,
128
+ getFileInfo,
129
+ getStackTrace
130
+ });
@@ -0,0 +1,3 @@
1
+ import '../types/index.cjs';
2
+ export { c as cleanStack, d as constructErrorObject, b as extractCodeFrame, g as getFileInfo, a as getStackTrace } from '../exception-C69UCHPk.cjs';
3
+ import 'sql-formatter';
@@ -0,0 +1,3 @@
1
+ import '../types/index.js';
2
+ export { c as cleanStack, d as constructErrorObject, b as extractCodeFrame, g as getFileInfo, a as getStackTrace } from '../exception-3AZsPtAg.js';
3
+ import 'sql-formatter';
@@ -0,0 +1,91 @@
1
+ // src/utils/exception.ts
2
+ import StackUtils from "stack-utils";
3
+ import path from "path";
4
+ import { existsSync, readFileSync } from "fs";
5
+ import { nowISO } from "@lensjs/date";
6
+ var stackUtils = new StackUtils({
7
+ cwd: process.cwd(),
8
+ internals: StackUtils.nodeInternals()
9
+ });
10
+ function cleanStack(stack) {
11
+ if (!stack) return "";
12
+ return stackUtils.clean(stack);
13
+ }
14
+ function getFileInfo(stack) {
15
+ if (!stack) {
16
+ return { file: "", line: 0, column: 0, function: "" };
17
+ }
18
+ const firstLine = stack.split("\n")[1] ?? "";
19
+ const fileInfo = stackUtils.parseLine(firstLine) ?? {
20
+ file: "",
21
+ line: 0,
22
+ column: 0,
23
+ function: ""
24
+ };
25
+ return {
26
+ file: fileInfo.file ? path.resolve(process.cwd(), fileInfo.file) : "",
27
+ line: fileInfo.line ?? 0,
28
+ column: fileInfo.column ?? 0,
29
+ function: fileInfo.function ?? ""
30
+ };
31
+ }
32
+ function getStackTrace(stack) {
33
+ if (!stack) return [];
34
+ return cleanStack(stack).split("\n").filter((frame) => Boolean(frame));
35
+ }
36
+ function extractCodeFrame({
37
+ file,
38
+ line,
39
+ column,
40
+ contextLines = 6
41
+ }) {
42
+ if (!file) return null;
43
+ const fullPath = path.isAbsolute(file) ? file : path.resolve(process.cwd(), file);
44
+ if (!existsSync(fullPath)) return null;
45
+ const fileContent = readFileSync(fullPath, "utf-8");
46
+ const lines = fileContent.split(/\r?\n/);
47
+ if (line < 1 || line > lines.length) return null;
48
+ const start = Math.max(0, line - 1 - contextLines);
49
+ const end = Math.min(lines.length, line - 1 + contextLines + 1);
50
+ const snippet = lines.slice(start, end);
51
+ const relativeLine = line - 1 - start;
52
+ const errorLine = lines[line - 1] ?? "";
53
+ return {
54
+ file: fullPath,
55
+ line,
56
+ column,
57
+ context: {
58
+ pre: snippet.slice(0, relativeLine),
59
+ error: errorLine,
60
+ post: snippet.slice(relativeLine + 1)
61
+ }
62
+ };
63
+ }
64
+ function constructErrorObject(err) {
65
+ const fileInfo = getFileInfo(err.stack);
66
+ const codeFrame = extractCodeFrame({
67
+ file: fileInfo.file,
68
+ line: fileInfo.line,
69
+ column: fileInfo.column
70
+ });
71
+ return {
72
+ name: err.name,
73
+ message: err.message,
74
+ createdAt: nowISO(),
75
+ fileInfo: {
76
+ file: fileInfo.file,
77
+ function: fileInfo.function
78
+ },
79
+ cause: err.cause ?? null,
80
+ trace: getStackTrace(err.stack),
81
+ codeFrame,
82
+ originalStack: codeFrame === null ? cleanStack(err.stack) : null
83
+ };
84
+ }
85
+ export {
86
+ cleanStack,
87
+ constructErrorObject,
88
+ extractCodeFrame,
89
+ getFileInfo,
90
+ getStackTrace
91
+ };