@tracepanel/js 0.3.4 → 0.4.1
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 +50 -4
- package/dist/agent.d.ts +23 -1
- package/dist/agent.js +72 -22
- package/dist/agent.js.map +1 -1
- package/dist/body.d.ts +32 -0
- package/dist/body.js +314 -0
- package/dist/body.js.map +1 -0
- package/dist/bullmq.d.ts +76 -1
- package/dist/bullmq.js +215 -6
- package/dist/bullmq.js.map +1 -1
- package/dist/bun.js +81 -11
- package/dist/bun.js.map +1 -1
- package/dist/config.d.ts +20 -0
- package/dist/config.js +13 -0
- package/dist/config.js.map +1 -1
- package/dist/console.d.ts +5 -0
- package/dist/console.js +16 -0
- package/dist/console.js.map +1 -1
- package/dist/express.js +94 -23
- package/dist/express.js.map +1 -1
- package/dist/headers.js +54 -8
- package/dist/headers.js.map +1 -1
- package/dist/inspector.d.ts +9 -0
- package/dist/inspector.js +47 -0
- package/dist/inspector.js.map +1 -0
- package/dist/locals.d.ts +51 -0
- package/dist/locals.js +269 -0
- package/dist/locals.js.map +1 -0
- package/dist/loggers.d.ts +50 -0
- package/dist/loggers.js +201 -0
- package/dist/loggers.js.map +1 -0
- package/dist/model.d.ts +23 -2
- package/dist/model.js.map +1 -1
- package/dist/next.js +6 -0
- package/dist/next.js.map +1 -1
- package/dist/nuxt-plugin.d.ts +1 -0
- package/dist/nuxt-plugin.js +6 -0
- package/dist/nuxt-plugin.js.map +1 -1
- package/dist/processor.d.ts +23 -2
- package/dist/processor.js +61 -14
- package/dist/processor.js.map +1 -1
- package/dist/profile.d.ts +63 -0
- package/dist/profile.js +300 -0
- package/dist/profile.js.map +1 -0
- package/dist/request.d.ts +61 -0
- package/dist/request.js +244 -0
- package/dist/request.js.map +1 -0
- package/dist/session.d.ts +10 -0
- package/dist/session.js +45 -0
- package/dist/session.js.map +1 -0
- package/dist/setup.js +10 -1
- package/dist/setup.js.map +1 -1
- package/dist/stack.d.ts +27 -3
- package/dist/stack.js +106 -9
- package/dist/stack.js.map +1 -1
- package/dist/widget.d.ts +24 -0
- package/dist/widget.js +62 -1
- package/dist/widget.js.map +1 -1
- package/package.json +16 -4
package/dist/express.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
// `app.use(tracepanel())`: every response gets what the badge reads (Tracepanel-Id, Server-Timing), and HTML pages
|
|
2
|
-
// get widget.min.js.
|
|
2
|
+
// get widget.min.js. A response the handler ends at once (a page, a JSON answer) is held until then; one written in
|
|
3
|
+
// pieces without a Content-Length is a stream, and goes out as it comes, an HTML page with the script put in as it
|
|
4
|
+
// passes. What the request carried goes into its trace as the response goes out: its headers, query, cookies, the
|
|
5
|
+
// body a body parser read (`req.body`, an upload's files), the session (`req.session`), and the response's headers. A redirect that answers a
|
|
6
|
+
// page's navigation (a form's POST) sets the cookie that shows it in the next page's panel.
|
|
7
|
+
import { hasBody, parsedBody, redirectCookie, requestAttrs, responseHeaders, searchOf } from "./request.js";
|
|
3
8
|
import { runtime } from "./runtime.js";
|
|
4
|
-
import {
|
|
9
|
+
import { expressSession } from "./session.js";
|
|
10
|
+
import { badge, exposedHeaders, inject, Stream, streamablePage } from "./widget.js";
|
|
5
11
|
function toBuffer(chunk, encoding) {
|
|
6
12
|
if (Buffer.isBuffer(chunk))
|
|
7
13
|
return chunk;
|
|
@@ -9,6 +15,27 @@ function toBuffer(chunk, encoding) {
|
|
|
9
15
|
return Buffer.from(chunk);
|
|
10
16
|
return Buffer.from(String(chunk), encoding);
|
|
11
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* What the request carried, the body as far as the app's body parser read it, the session as the handler left it
|
|
20
|
+
* (express-session's, cookie-session's), and the response's headers so far.
|
|
21
|
+
*/
|
|
22
|
+
function carried(req, res) {
|
|
23
|
+
const upload = req;
|
|
24
|
+
const body = hasBody(req.headers)
|
|
25
|
+
? parsedBody({
|
|
26
|
+
contentType: req.headers["content-type"] ?? "",
|
|
27
|
+
body: req.body,
|
|
28
|
+
file: upload.file,
|
|
29
|
+
files: upload.files,
|
|
30
|
+
})
|
|
31
|
+
: {};
|
|
32
|
+
return {
|
|
33
|
+
...requestAttrs(req.headers, searchOf(req.originalUrl ?? req.url)),
|
|
34
|
+
...body,
|
|
35
|
+
...expressSession(upload.session),
|
|
36
|
+
...responseHeaders(Object.entries(res.getHeaders())),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
12
39
|
export function tracepanel() {
|
|
13
40
|
const tp = runtime();
|
|
14
41
|
return function tracepanelMiddleware(req, res, next) {
|
|
@@ -22,15 +49,60 @@ export function tracepanel() {
|
|
|
22
49
|
const write = res.write.bind(res);
|
|
23
50
|
const end = res.end.bind(res);
|
|
24
51
|
let streaming = false;
|
|
52
|
+
// A streamed HTML page: what puts the script into it.
|
|
53
|
+
let script;
|
|
25
54
|
const flushHeld = () => {
|
|
26
55
|
if (chunks.length > 0)
|
|
27
56
|
write(Buffer.concat(chunks.splice(0)));
|
|
28
57
|
};
|
|
58
|
+
let recorded = false;
|
|
59
|
+
/** What the request carried, into its trace once, before the badge's headers join the response's. */
|
|
60
|
+
const record = () => {
|
|
61
|
+
if (recorded || !tp.config.captureRequest)
|
|
62
|
+
return;
|
|
63
|
+
recorded = true;
|
|
64
|
+
tp.processor.setTraceAttrs(carried(req, res));
|
|
65
|
+
};
|
|
66
|
+
/** The badge's headers on the response; its script tag when it is a page that gets one. */
|
|
67
|
+
const mark = (page) => {
|
|
68
|
+
record();
|
|
69
|
+
const framework = tp.processor.framework() ?? "Express";
|
|
70
|
+
const marks = badge(tp, { method: req.method, status: res.statusCode, startedMs, page, framework });
|
|
71
|
+
if (!marks)
|
|
72
|
+
return undefined;
|
|
73
|
+
for (const [name, value] of Object.entries(marks.headers))
|
|
74
|
+
res.setHeader(name, value);
|
|
75
|
+
const redirect = redirectCookie(marks.headers["Tracepanel-Id"] ?? "", res.statusCode, req.headers);
|
|
76
|
+
if (redirect)
|
|
77
|
+
res.appendHeader("Set-Cookie", redirect);
|
|
78
|
+
const expose = exposedHeaders(res.getHeader("access-control-allow-origin"), res.getHeader("access-control-expose-headers"));
|
|
79
|
+
if (expose)
|
|
80
|
+
res.setHeader("Access-Control-Expose-Headers", expose);
|
|
81
|
+
return marks.script;
|
|
82
|
+
};
|
|
83
|
+
/** A stream: the badge's headers now, with the time so far, and the script for an HTML page as it is. */
|
|
84
|
+
const startStream = () => {
|
|
85
|
+
streaming = true;
|
|
86
|
+
if (res.headersSent) {
|
|
87
|
+
record();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const page = streamablePage((name) => res.getHeader(name));
|
|
91
|
+
const tag = mark(page);
|
|
92
|
+
if (page && tag)
|
|
93
|
+
script = new Stream(tag);
|
|
94
|
+
};
|
|
29
95
|
res.write = ((chunk, encoding, callback) => {
|
|
30
|
-
|
|
31
|
-
|
|
96
|
+
// Its size declared, a body in pieces is held whole like a page ended at once; without one it is a stream.
|
|
97
|
+
if (!streaming && res.getHeader("content-length") === undefined)
|
|
98
|
+
startStream();
|
|
99
|
+
if (streaming) {
|
|
32
100
|
flushHeld();
|
|
33
|
-
|
|
101
|
+
if (!script)
|
|
102
|
+
return write(chunk, encoding, callback);
|
|
103
|
+
const done = (typeof encoding === "function" ? encoding : callback);
|
|
104
|
+
const piece = toBuffer(chunk, typeof encoding === "string" ? encoding : undefined);
|
|
105
|
+
return done ? write(script.feed(piece), done) : write(script.feed(piece));
|
|
34
106
|
}
|
|
35
107
|
chunks.push(toBuffer(chunk, typeof encoding === "string" ? encoding : undefined));
|
|
36
108
|
if (typeof encoding === "function")
|
|
@@ -43,30 +115,29 @@ export function tracepanel() {
|
|
|
43
115
|
res.write = write;
|
|
44
116
|
res.end = end;
|
|
45
117
|
if (typeof chunk === "function")
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
118
|
+
[chunk, encoding, callback] = [undefined, undefined, chunk];
|
|
119
|
+
else if (typeof encoding === "function")
|
|
120
|
+
[encoding, callback] = [undefined, encoding];
|
|
121
|
+
const last = chunk === undefined || chunk === null
|
|
122
|
+
? undefined
|
|
123
|
+
: toBuffer(chunk, typeof encoding === "string" ? encoding : undefined);
|
|
124
|
+
if (streaming) {
|
|
125
|
+
flushHeld();
|
|
126
|
+
const rest = script ? Buffer.concat([script.feed(last ?? Buffer.alloc(0)), script.end()]) : last;
|
|
127
|
+
return rest && rest.length > 0 ? end(rest, callback) : end(callback);
|
|
52
128
|
}
|
|
53
|
-
if (
|
|
129
|
+
if (last)
|
|
130
|
+
chunks.push(last);
|
|
131
|
+
if (res.headersSent) {
|
|
132
|
+
record();
|
|
54
133
|
flushHeld();
|
|
55
134
|
return end(callback);
|
|
56
135
|
}
|
|
57
136
|
let body = Buffer.concat(chunks);
|
|
58
137
|
const page = String(res.getHeader("content-type") ?? "").includes("text/html");
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
for (const [name, value] of Object.entries(marks.headers))
|
|
63
|
-
res.setHeader(name, value);
|
|
64
|
-
const expose = exposedHeaders(res.getHeader("access-control-allow-origin"), res.getHeader("access-control-expose-headers"));
|
|
65
|
-
if (expose)
|
|
66
|
-
res.setHeader("Access-Control-Expose-Headers", expose);
|
|
67
|
-
if (marks.script)
|
|
68
|
-
body = Buffer.from(inject(body.toString("utf8"), marks.script));
|
|
69
|
-
}
|
|
138
|
+
const tag = mark(page);
|
|
139
|
+
if (tag)
|
|
140
|
+
body = Buffer.from(inject(body.toString("utf8"), tag));
|
|
70
141
|
if (!res.getHeader("transfer-encoding"))
|
|
71
142
|
res.setHeader("Content-Length", body.length);
|
|
72
143
|
return end(body, callback);
|
package/dist/express.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.js","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":"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AiB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAiB,CAAC,CAAC;YACzF,CAAC;YACD,IAAI,IAAI;gBAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC5B,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC;gBACpB,MAAM,EAAE,CAAC;gBACT,SAAS,EAAE,CAAC;gBACZ,OAAO,GAAG,CAAC,QAAiB,CAAC,CAAC;YAChC,CAAC;YACD,IAAI,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACjC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;YAC/E,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;YACvB,IAAI,GAAG;gBAAE,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;YAChE,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,mBAAmB,CAAC;gBAAE,GAAG,CAAC,SAAS,CAAC,gBAAgB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YACtF,OAAO,GAAG,CAAC,IAAI,EAAE,QAAiB,CAAC,CAAC;QACtC,CAAC,CAAQ,CAAC;QAEV,IAAI,EAAE,CAAC;IACT,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/headers.js
CHANGED
|
@@ -1,9 +1,35 @@
|
|
|
1
1
|
// For frameworks that answer from their own server (Next.js, Nuxt): every response of a traced request gets what the
|
|
2
|
-
// widget and the badge read, Tracepanel-Id, Tracepanel-Url and Server-Timing, as its headers go out.
|
|
3
|
-
|
|
2
|
+
// widget and the badge read, Tracepanel-Id, Tracepanel-Url and Server-Timing, as its headers go out. Then too, what
|
|
3
|
+
// the request carried goes into its trace (headers, query, cookies, the body as far as the framework read it for the
|
|
4
|
+
// app), with the response's headers; and a redirect that answers a page's navigation sets the cookie that shows it in
|
|
5
|
+
// the next page's panel. A request's body is tapped as the server hands the request over: the framework reads it from
|
|
6
|
+
// the stream, and its pieces pass the tap on their way (body.ts).
|
|
7
|
+
import http, { ServerResponse } from "node:http";
|
|
8
|
+
import https from "node:https";
|
|
9
|
+
import { tapIncoming, tapOf } from "./body.js";
|
|
10
|
+
import { hasBody, redirectCookie, requestAttrs, responseHeaders, searchOf } from "./request.js";
|
|
4
11
|
import { exposedHeaders } from "./widget.js";
|
|
5
12
|
const PATCHED = Symbol.for("tracepanel.headers");
|
|
13
|
+
const TAPPING = Symbol.for("tracepanel.body.tapping");
|
|
14
|
+
/** The app's HTTP servers (made before this runs too) tap the body of each request that has one. */
|
|
15
|
+
function tapBodies(tracepanel) {
|
|
16
|
+
for (const prototype of [http.Server.prototype, https.Server.prototype]) {
|
|
17
|
+
const server = prototype;
|
|
18
|
+
if (server[TAPPING])
|
|
19
|
+
continue;
|
|
20
|
+
server[TAPPING] = true;
|
|
21
|
+
const emit = server.emit;
|
|
22
|
+
server.emit = function (event, ...args) {
|
|
23
|
+
const req = args[0];
|
|
24
|
+
if (event === "request" && req && tracepanel.config.captureRequest && hasBody(req.headers) && !tapOf(req)) {
|
|
25
|
+
tapIncoming(req);
|
|
26
|
+
}
|
|
27
|
+
return emit.call(this, event, ...args);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
6
31
|
export function headersOnResponses(tracepanel, framework) {
|
|
32
|
+
tapBodies(tracepanel);
|
|
7
33
|
const prototype = ServerResponse.prototype;
|
|
8
34
|
if (prototype[PATCHED])
|
|
9
35
|
return;
|
|
@@ -11,10 +37,24 @@ export function headersOnResponses(tracepanel, framework) {
|
|
|
11
37
|
const writeHead = prototype.writeHead;
|
|
12
38
|
prototype.writeHead = function (...args) {
|
|
13
39
|
if (!this.headersSent) {
|
|
40
|
+
const method = this.req?.method ?? "GET";
|
|
41
|
+
const url = this.req?.url ?? "/";
|
|
42
|
+
const status = typeof args[0] === "number" ? args[0] : this.statusCode;
|
|
43
|
+
// Headers passed to writeHead itself (an object) count too: CORS middleware often sets them there.
|
|
44
|
+
const given = [args[1], args[2]].find((arg) => arg !== null && typeof arg === "object" && !Array.isArray(arg));
|
|
45
|
+
const passed = (given ?? {});
|
|
46
|
+
if (tracepanel.config.captureRequest && this.req) {
|
|
47
|
+
// Before the badge: a response sent outside the request's context finds its trace by the URL until then.
|
|
48
|
+
tracepanel.processor.setTraceAttrs({
|
|
49
|
+
...requestAttrs(this.req.headers, searchOf(url)),
|
|
50
|
+
...tapOf(this.req)?.attrs(),
|
|
51
|
+
...responseHeaders([...Object.entries(this.getHeaders()), ...Object.entries(passed)]),
|
|
52
|
+
}, { method, url });
|
|
53
|
+
}
|
|
14
54
|
const marks = tracepanel.badge({
|
|
15
|
-
method
|
|
16
|
-
url
|
|
17
|
-
status
|
|
55
|
+
method,
|
|
56
|
+
url,
|
|
57
|
+
status,
|
|
18
58
|
startedMs: performance.now(),
|
|
19
59
|
page: false,
|
|
20
60
|
framework: tracepanel.processor.framework() ?? framework,
|
|
@@ -23,13 +63,19 @@ export function headersOnResponses(tracepanel, framework) {
|
|
|
23
63
|
if (!this.hasHeader(name))
|
|
24
64
|
this.setHeader(name, value);
|
|
25
65
|
}
|
|
26
|
-
// Headers passed to writeHead itself (an object) count too: CORS middleware often sets them there.
|
|
27
|
-
const given = [args[1], args[2]].find((arg) => arg !== null && typeof arg === "object" && !Array.isArray(arg));
|
|
28
|
-
const passed = (given ?? {});
|
|
29
66
|
const lower = Object.fromEntries(Object.entries(passed ?? {}).map(([name, value]) => [name.toLowerCase(), value]));
|
|
30
67
|
const expose = marks
|
|
31
68
|
? exposedHeaders(this.getHeader("access-control-allow-origin") ?? lower["access-control-allow-origin"], this.getHeader("access-control-expose-headers") ?? lower["access-control-expose-headers"])
|
|
32
69
|
: undefined;
|
|
70
|
+
const redirect = marks && this.req ? redirectCookie(marks.headers["Tracepanel-Id"] ?? "", status, this.req.headers) : undefined;
|
|
71
|
+
if (redirect) {
|
|
72
|
+
// One passed to writeHead would replace the response's own: the cookie joins it there.
|
|
73
|
+
const named = Object.keys(passed).find((name) => name.toLowerCase() === "set-cookie");
|
|
74
|
+
if (named)
|
|
75
|
+
passed[named] = [...[passed[named]].flat(), redirect];
|
|
76
|
+
else
|
|
77
|
+
this.appendHeader("Set-Cookie", redirect);
|
|
78
|
+
}
|
|
33
79
|
if (expose) {
|
|
34
80
|
this.setHeader("Access-Control-Expose-Headers", expose);
|
|
35
81
|
delete passed["access-control-expose-headers"];
|
package/dist/headers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../src/headers.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,
|
|
1
|
+
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../src/headers.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,oHAAoH;AACpH,qHAAqH;AACrH,sHAAsH;AACtH,sHAAsH;AACtH,kEAAkE;AAElE,OAAO,IAAI,EAAE,EAAwB,cAAc,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEhG,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;AACjD,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAEtD,oGAAoG;AACpG,SAAS,SAAS,CAAC,UAAmB;IACpC,KAAK,MAAM,SAAS,IAAI,CAAC,IAAI,CAAC,MAAM,CA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M,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC;;oBAC5D,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;YACjD,CAAC;YACD,IAAI,MAAM,EAAE,CAAC;gBACX,IAAI,CAAC,SAAS,CAAC,+BAA+B,EAAE,MAAM,CAAC,CAAC;gBACxD,OAAQ,MAAkC,CAAC,+BAA+B,CAAC,CAAC;gBAC5E,OAAQ,MAAkC,CAAC,+BAA+B,CAAC,CAAC;YAC9E,CAAC;QACH,CAAC;QACD,OAAQ,SAAsD,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACnF,CAAqB,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type Inspector = typeof import("node:inspector");
|
|
2
|
+
type Session = InstanceType<Inspector["Session"]>;
|
|
3
|
+
/** node:inspector, or null where there is none. */
|
|
4
|
+
export declare function inspector(): Inspector | null;
|
|
5
|
+
/** A session with this thread's inspector, connected; undefined where there is none. */
|
|
6
|
+
export declare function connect(): Session | undefined;
|
|
7
|
+
/** A call on a session of this thread, answered before it returns: its result, or the error it failed with. */
|
|
8
|
+
export declare function call<T = Record<string, unknown>>(session: Session, method: string, params?: object): T;
|
|
9
|
+
export type { Session };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Node's inspector, from inside the app: what the profiler and the error's local variables read. A session in the
|
|
2
|
+
// app's own thread answers each call at once, while the call is made, so both stay synchronous. Loaded on first use:
|
|
3
|
+
// a Node built without the inspector, and Bun, which has none to speak of, get neither feature and nothing breaks.
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
let loaded;
|
|
6
|
+
/** node:inspector, or null where there is none. */
|
|
7
|
+
export function inspector() {
|
|
8
|
+
if (loaded !== undefined)
|
|
9
|
+
return loaded;
|
|
10
|
+
loaded = null;
|
|
11
|
+
if (process.versions.bun !== undefined || !process.features.inspector)
|
|
12
|
+
return loaded;
|
|
13
|
+
try {
|
|
14
|
+
loaded = createRequire(import.meta.url)("node:inspector");
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
// Not in this build of Node.
|
|
18
|
+
}
|
|
19
|
+
return loaded;
|
|
20
|
+
}
|
|
21
|
+
/** A session with this thread's inspector, connected; undefined where there is none. */
|
|
22
|
+
export function connect() {
|
|
23
|
+
const found = inspector();
|
|
24
|
+
if (!found)
|
|
25
|
+
return undefined;
|
|
26
|
+
try {
|
|
27
|
+
const session = new found.Session();
|
|
28
|
+
session.connect();
|
|
29
|
+
return session;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** A call on a session of this thread, answered before it returns: its result, or the error it failed with. */
|
|
36
|
+
export function call(session, method, params) {
|
|
37
|
+
let failure = null;
|
|
38
|
+
let result;
|
|
39
|
+
session.post(method, params ?? {}, (error, answer) => {
|
|
40
|
+
failure = error;
|
|
41
|
+
result = answer;
|
|
42
|
+
});
|
|
43
|
+
if (failure)
|
|
44
|
+
throw failure;
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=inspector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspector.js","sourceRoot":"","sources":["../src/inspector.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,qHAAqH;AACrH,mHAAmH;AAEnH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAK5C,IAAI,MAAoC,CAAC;AAEzC,mDAAmD;AACnD,MAAM,UAAU,SAAS;IACvB,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC;IACxC,MAAM,GAAG,IAAI,CAAC;IACd,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS;QAAE,OAAO,MAAM,CAAC;IACrF,IAAI,CAAC;QACH,MAAM,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,gBAAgB,CAAc,CAAC;IACzE,CAAC;IAAC,MAAM,CAAC;QACP,6BAA6B;IAC/B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,OAAO;IACrB,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;IAC1B,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QACpC,OAAO,CAAC,OAAO,EAAE,CAAC;QAClB,OAAO,OAAO,CAAC;IACjB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,+GAA+G;AAC/G,MAAM,UAAU,IAAI,CAA8B,OAAgB,EAAE,MAAc,EAAE,MAAe;IACjG,IAAI,OAAO,GAAiB,IAAI,CAAC;IACjC,IAAI,MAAe,CAAC;IACpB,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,IAAI,EAAE,EAAE,CAAC,KAAmB,EAAE,MAAgB,EAAE,EAAE;QAC3E,OAAO,GAAG,KAAK,CAAC;QAChB,MAAM,GAAG,MAAM,CAAC;IAClB,CAAC,CAAC,CAAC;IACH,IAAI,OAAO;QAAE,MAAM,OAAO,CAAC;IAC3B,OAAO,MAAW,CAAC;AACrB,CAAC"}
|
package/dist/locals.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** The local variables of an error's frames, by the frame's place in its stack (innermost first). */
|
|
2
|
+
export type FrameLocals = (Record<string, string> | undefined)[];
|
|
3
|
+
/**
|
|
4
|
+
* A value as the console shows it, as Python's reprlib cuts one: a plain object, an array, a Map or a Set by its
|
|
5
|
+
* items, nested two deep, ten of each at most; anything else (a class's instance: a request, a connection) and a
|
|
6
|
+
* string at most 160 characters. Masked under a sensitive name.
|
|
7
|
+
*/
|
|
8
|
+
export declare function repr(name: string, value: unknown): string;
|
|
9
|
+
/** A frame's variables as text, from its scope objects, innermost first: an inner name hides an outer one. */
|
|
10
|
+
export declare function variables(scopes: object[]): Record<string, string>;
|
|
11
|
+
/** Whether an error, by its stack, is one Next.js throws to steer a render. */
|
|
12
|
+
export declare function steers(stack: string): boolean;
|
|
13
|
+
/** Reads the locals of errors thrown in a trace, for its errors to carry. */
|
|
14
|
+
export declare class Locals {
|
|
15
|
+
private readonly session;
|
|
16
|
+
private readonly root;
|
|
17
|
+
private readonly traceId;
|
|
18
|
+
private tracing;
|
|
19
|
+
private limited;
|
|
20
|
+
private second;
|
|
21
|
+
private pauses;
|
|
22
|
+
private state;
|
|
23
|
+
/** The objects the hook was passed. */
|
|
24
|
+
private received;
|
|
25
|
+
/**
|
|
26
|
+
* What was read, by the error's stack (its trace records that), and the trace it was thrown in. Thrown again in the
|
|
27
|
+
* same trace, an error keeps its first throw's.
|
|
28
|
+
*/
|
|
29
|
+
private readonly errors;
|
|
30
|
+
private readonly hookName;
|
|
31
|
+
private constructor();
|
|
32
|
+
/** The reader, with the inspector's debugger on; undefined where there is none, or a debugger is attached. */
|
|
33
|
+
static start(root: string, traceId: () => string | undefined): Locals | undefined;
|
|
34
|
+
/** Whether a trace runs: errors pause only then. */
|
|
35
|
+
traces(running: boolean): void;
|
|
36
|
+
/** The locals read for the error with this stack, taken: each error's are given once. */
|
|
37
|
+
take(stack: string | undefined): FrameLocals | undefined;
|
|
38
|
+
private pauseOn;
|
|
39
|
+
/** At most MAX_PAUSES a second: past them, no pause until the second is over. */
|
|
40
|
+
private budget;
|
|
41
|
+
/** The objects of these ids, handed over by the paused app: called on `objectId`, the hook is passed them. */
|
|
42
|
+
private objects;
|
|
43
|
+
private paused;
|
|
44
|
+
/**
|
|
45
|
+
* The app's frames of the error's stack and the scopes of the frames that run them, paired by line or name: both go
|
|
46
|
+
* from the throw outwards. The stack's `async` callers have no frame running; its innermost frame may have none
|
|
47
|
+
* either, an error made in a helper and thrown by its caller. An error thrown again elsewhere (made outside a trace,
|
|
48
|
+
* thrown in one) has another stack than the debugger's: nothing pairs with its first frames, and none is read.
|
|
49
|
+
*/
|
|
50
|
+
private frames;
|
|
51
|
+
}
|