@lensjs/core 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -0
- package/dist/abstracts/store.cjs +13 -0
- package/dist/abstracts/store.d.cts +6 -3
- package/dist/abstracts/store.d.ts +6 -3
- package/dist/abstracts/store.js +13 -0
- package/dist/core/api_controller.cjs +22 -1
- package/dist/core/api_controller.d.cts +4 -2
- package/dist/core/api_controller.d.ts +4 -2
- package/dist/core/api_controller.js +22 -1
- package/dist/core/lens.cjs +52 -4
- package/dist/core/lens.js +52 -4
- package/dist/exception-3AZsPtAg.d.ts +52 -0
- package/dist/exception-C69UCHPk.d.cts +52 -0
- package/dist/index.cjs +206 -29
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +203 -29
- package/dist/stores/better_sqlite.cjs +19 -3
- package/dist/stores/better_sqlite.d.cts +9 -1
- package/dist/stores/better_sqlite.d.ts +9 -1
- package/dist/stores/better_sqlite.js +19 -3
- package/dist/stores/index.cjs +19 -3
- package/dist/stores/index.js +19 -3
- package/dist/types/index.cjs +1 -0
- package/dist/types/index.d.cts +26 -2
- package/dist/types/index.d.ts +26 -2
- package/dist/types/index.js +1 -0
- package/dist/ui/assets/{CacheActionBadge-3jjmNjC6.js → CacheActionBadge-3t8U516j.js} +1 -1
- package/dist/ui/assets/CacheEntriesTable-BqLquILg.js +1 -0
- package/dist/ui/assets/CacheEntryContainer-B86waEsR.js +2 -0
- package/dist/ui/assets/{CacheEntryDetails-CHt_pNTk.js → CacheEntryDetails-Dm-oXALj.js} +1 -1
- package/dist/ui/assets/CacheEntryDetailsContainer-BCyXGgkx.js +2 -0
- package/dist/ui/assets/ExceptionContainer-DSQBz5cb.js +2 -0
- package/dist/ui/assets/ExceptionDetails-gmpSQ_eu.js +16 -0
- package/dist/ui/assets/ExceptionDetailsContainer-BHIz-TUv.js +2 -0
- package/dist/ui/assets/ExceptionTable-BhrX9MSS.js +1 -0
- package/dist/ui/assets/{LoadMore-DHOrhPsi.js → LoadMore-26PcNWcP.js} +1 -1
- package/dist/ui/assets/QueriesContainer-BSF-O4s3.js +2 -0
- package/dist/ui/assets/{QueryDetailsContainer-eoLkgEjj.js → QueryDetailsContainer-BjQM9QIb.js} +7 -7
- package/dist/ui/assets/{QueryTable-BXSzT-Cm.js → QueryTable-szgIT5Uc.js} +1 -1
- package/dist/ui/assets/RequestDetails-CvQhX-2F.js +1 -0
- package/dist/ui/assets/{RequestDetailsContainer-BaH6fUK7.js → RequestDetailsContainer-XYPFJFX0.js} +2 -2
- package/dist/ui/assets/RequestsContainer-D0QPK2Ii.js +2 -0
- package/dist/ui/assets/{RequetsTable-B51VXisk.js → RequetsTable-6Fqchsrt.js} +1 -1
- package/dist/ui/assets/{StatusCode-DVhX11V3.js → StatusCode-CfVCLID2.js} +1 -1
- package/dist/ui/assets/TabbedDataViewer-Cl5ednx4.js +1 -0
- package/dist/ui/assets/{Table-D1Kpw7PA.js → Table-CGe8JwTO.js} +1 -1
- package/dist/ui/assets/{columns-BIDLCW64.js → columns-BFxCubt5.js} +1 -1
- package/dist/ui/assets/columns-Cw7tw3Em.js +1 -0
- package/dist/ui/assets/{columns-jYfhBxOM.js → columns-RiCoo9Ea.js} +1 -1
- package/dist/ui/assets/{index-CpP2Ap5X.js → index-BRRKsoNv.js} +1 -1
- package/dist/ui/assets/index-BzFeZyjf.css +1 -0
- package/dist/ui/assets/{index-BdvbrZNf.js → index-XoJlyTFO.js} +26 -21
- package/dist/ui/assets/{useCacheEntries-vuHEIj6E.js → useCacheEntries-SCADuxKq.js} +1 -1
- package/dist/ui/assets/useExceptions-BMGL3nir.js +1 -0
- package/dist/ui/assets/useLensApi-BYyiIIZR.js +1 -0
- package/dist/ui/assets/{useLoadMore-twYxPJ-d.js → useLoadMore-CksOcXOF.js} +1 -1
- package/dist/ui/assets/{useQueries-BYFLoUQR.js → useQueries-6nYr0oG5.js} +1 -1
- package/dist/ui/index.html +2 -2
- package/dist/utils/async_context.cjs +113 -0
- package/dist/utils/async_context.d.cts +6 -1
- package/dist/utils/async_context.d.ts +6 -1
- package/dist/utils/async_context.js +102 -0
- package/dist/utils/exception.cjs +130 -0
- package/dist/utils/exception.d.cts +3 -0
- package/dist/utils/exception.d.ts +3 -0
- package/dist/utils/exception.js +91 -0
- package/dist/watchers/cache_watcher.cjs +12 -16
- package/dist/watchers/cache_watcher.js +12 -16
- package/dist/watchers/exception_watcher.cjs +108 -0
- package/dist/watchers/exception_watcher.d.cts +10 -0
- package/dist/watchers/exception_watcher.d.ts +10 -0
- package/dist/watchers/exception_watcher.js +75 -0
- package/dist/watchers/index.cjs +53 -16
- package/dist/watchers/index.d.cts +1 -0
- package/dist/watchers/index.d.ts +1 -0
- package/dist/watchers/index.js +42 -16
- package/package.json +8 -6
- package/dist/ui/assets/CacheEntriesTable-DPLre6br.js +0 -1
- package/dist/ui/assets/CacheEntryContainer-WN6LkoCR.js +0 -2
- package/dist/ui/assets/CacheEntryDetailsContainer-BhquSApO.js +0 -2
- package/dist/ui/assets/QueriesContainer-Cl6rq4dH.js +0 -2
- package/dist/ui/assets/RequestDetails-CIB7_XWh.js +0 -1
- package/dist/ui/assets/RequestsContainer-DLS17BWP.js +0 -2
- package/dist/ui/assets/TabbedDataViewer-CNSEhc6h.js +0 -1
- package/dist/ui/assets/index-C04tuZDI.css +0 -1
- package/dist/ui/assets/useLensApi-Bzmx8hps.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as t}from"./index-
|
|
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-
|
|
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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./index-
|
|
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};
|
package/dist/ui/index.html
CHANGED
|
@@ -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-
|
|
9
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
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>
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,17 +17,128 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/utils/async_context.ts
|
|
21
31
|
var async_context_exports = {};
|
|
22
32
|
__export(async_context_exports, {
|
|
33
|
+
handleUncaughExceptions: () => handleUncaughExceptions,
|
|
23
34
|
lensContext: () => lensContext
|
|
24
35
|
});
|
|
25
36
|
module.exports = __toCommonJS(async_context_exports);
|
|
26
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
|
|
27
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
|
+
};
|
|
28
140
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29
141
|
0 && (module.exports = {
|
|
142
|
+
handleUncaughExceptions,
|
|
30
143
|
lensContext
|
|
31
144
|
});
|
|
@@ -1,8 +1,13 @@
|
|
|
1
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';
|
|
2
6
|
|
|
3
7
|
type LensContext = {
|
|
4
8
|
requestId: string;
|
|
5
9
|
};
|
|
6
10
|
declare const lensContext: AsyncLocalStorage<LensContext>;
|
|
11
|
+
declare const handleUncaughExceptions: (logger: ExceptionWatcher) => void;
|
|
7
12
|
|
|
8
|
-
export { lensContext };
|
|
13
|
+
export { handleUncaughExceptions, lensContext };
|
|
@@ -1,8 +1,13 @@
|
|
|
1
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';
|
|
2
6
|
|
|
3
7
|
type LensContext = {
|
|
4
8
|
requestId: string;
|
|
5
9
|
};
|
|
6
10
|
declare const lensContext: AsyncLocalStorage<LensContext>;
|
|
11
|
+
declare const handleUncaughExceptions: (logger: ExceptionWatcher) => void;
|
|
7
12
|
|
|
8
|
-
export { lensContext };
|
|
13
|
+
export { handleUncaughExceptions, lensContext };
|
|
@@ -1,6 +1,108 @@
|
|
|
1
1
|
// src/utils/async_context.ts
|
|
2
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
|
|
3
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
|
+
};
|
|
4
105
|
export {
|
|
106
|
+
handleUncaughExceptions,
|
|
5
107
|
lensContext
|
|
6
108
|
};
|
|
@@ -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,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
|
+
};
|
|
@@ -90,22 +90,18 @@ var CacheWatcher = class extends Watcher {
|
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
normalizePayload(data) {
|
|
93
|
-
let
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
value
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
normalizedData.key = "";
|
|
105
|
-
}
|
|
106
|
-
if (!normalizedData["value"]) {
|
|
107
|
-
normalizedData["value"] = "";
|
|
93
|
+
let key = "";
|
|
94
|
+
let value = "";
|
|
95
|
+
if ("data" in data && typeof data.data === "object" && data.data !== null) {
|
|
96
|
+
if ("key" in data.data) {
|
|
97
|
+
key = String(data.data.key);
|
|
98
|
+
}
|
|
99
|
+
if ("value" in data.data) {
|
|
100
|
+
value = data.data.value;
|
|
101
|
+
}
|
|
102
|
+
} else if (typeof data.data === "string") {
|
|
103
|
+
value = data.data;
|
|
108
104
|
}
|
|
109
|
-
return
|
|
105
|
+
return { key, value };
|
|
110
106
|
}
|
|
111
107
|
};
|
|
@@ -64,23 +64,19 @@ var CacheWatcher = class extends Watcher {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
normalizePayload(data) {
|
|
67
|
-
let
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
value
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
normalizedData.key = "";
|
|
79
|
-
}
|
|
80
|
-
if (!normalizedData["value"]) {
|
|
81
|
-
normalizedData["value"] = "";
|
|
67
|
+
let key = "";
|
|
68
|
+
let value = "";
|
|
69
|
+
if ("data" in data && typeof data.data === "object" && data.data !== null) {
|
|
70
|
+
if ("key" in data.data) {
|
|
71
|
+
key = String(data.data.key);
|
|
72
|
+
}
|
|
73
|
+
if ("value" in data.data) {
|
|
74
|
+
value = data.data.value;
|
|
75
|
+
}
|
|
76
|
+
} else if (typeof data.data === "string") {
|
|
77
|
+
value = data.data;
|
|
82
78
|
}
|
|
83
|
-
return
|
|
79
|
+
return { key, value };
|
|
84
80
|
}
|
|
85
81
|
};
|
|
86
82
|
export {
|