@visulima/pail 4.0.0-alpha.1 → 4.0.0-alpha.11
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/CHANGELOG.md +204 -0
- package/LICENSE.md +434 -52
- package/README.md +323 -0
- package/dist/error.d.ts +104 -0
- package/dist/error.js +76 -0
- package/dist/index.browser.d.ts +3 -1
- package/dist/index.browser.js +1490 -3
- package/dist/index.server.d.ts +3 -5
- package/dist/index.server.js +2380 -110
- package/dist/middleware/elysia.d.ts +71 -0
- package/dist/middleware/elysia.js +70 -0
- package/dist/middleware/express.d.ts +86 -0
- package/dist/middleware/express.js +29 -0
- package/dist/middleware/fastify.d.ts +81 -0
- package/dist/middleware/fastify.js +46 -0
- package/dist/middleware/hono.d.ts +85 -0
- package/dist/middleware/hono.js +33 -0
- package/dist/middleware/next/handler.d.ts +36 -0
- package/dist/middleware/next/handler.js +53 -0
- package/dist/middleware/next/middleware.d.ts +59 -0
- package/dist/middleware/next/storage.d.ts +14 -0
- package/dist/middleware/shared/create-middleware-logger.d.ts +82 -0
- package/dist/middleware/shared/headers.d.ts +14 -0
- package/dist/middleware/shared/routes.d.ts +30 -0
- package/dist/middleware/shared/storage.d.ts +29 -0
- package/dist/middleware/sveltekit.d.ts +123 -0
- package/dist/middleware/sveltekit.js +43 -0
- package/dist/object-tree.d.ts +2 -2
- package/dist/object-tree.js +7 -7
- package/dist/packem_shared/{AbstractJsonReporter-BaZ33PlE.js → AbstractJsonReporter-BO8Calb4.js} +112 -32
- package/dist/packem_shared/AbstractJsonReporter-nOj0Ft1F.js +284 -0
- package/dist/packem_shared/{JsonReporter-BRw4skd5.js → JsonReporter-CCmj7oYL.js} +2 -2
- package/dist/packem_shared/{JsonReporter-VzgyLEYz.js → JsonReporter-Ck2PIAEw.js} +2 -2
- package/dist/packem_shared/PrettyReporter-BCvyNzXO.js +2720 -0
- package/dist/packem_shared/{PrettyReporter-DySIXBjQ.js → PrettyReporter-BtTr13Ha.js} +55 -11
- package/dist/packem_shared/abstract-pretty-reporter-CXAKYCb8.js +2635 -0
- package/dist/packem_shared/constants-B1RjD_ps.js +99 -0
- package/dist/packem_shared/createPailError-B_sgL0nF.js +76 -0
- package/dist/packem_shared/headers-BxHWM6KI.js +127 -0
- package/dist/packem_shared/{index-BomQ3E6J.js → index-Bx3-C0j9.js} +29 -21
- package/dist/packem_shared/pailMiddleware-Ci88geIF.js +24 -0
- package/dist/packem_shared/storage-D0vqz8OX.js +36 -0
- package/dist/packem_shared/{InteractiveStreamHook-DiSubbJ1.js → useLogger-D0rU3lcX.js} +13 -1
- package/dist/packem_shared/{write-console-log-based-on-level-DBmRYXpj.js → write-console-log-based-on-level-ree2lDPw.js} +5 -4
- package/dist/packem_shared/{write-stream-BG8fhcs3.js → write-stream-MDqyXmc_.js} +1 -1
- package/dist/pail.browser.d.ts +1 -1
- package/dist/pail.server.d.ts +1 -76
- package/dist/processor/caller/caller-processor.js +1 -1
- package/dist/processor/environment-processor.d.ts +124 -0
- package/dist/processor/environment-processor.js +89 -0
- package/dist/processor/message-formatter-processor.d.ts +2 -3
- package/dist/processor/message-formatter-processor.js +654 -5
- package/dist/processor/opentelemetry-processor.js +4 -4
- package/dist/processor/redact-processor.d.ts +1 -1
- package/dist/processor/redact-processor.js +2 -1
- package/dist/processor/sampling-processor.d.ts +111 -0
- package/dist/processor/sampling-processor.js +59 -0
- package/dist/reporter/file/json-file-reporter.js +1 -1
- package/dist/reporter/http/abstract-http-reporter.js +23 -26
- package/dist/reporter/http/http-reporter.edge-light.js +134 -57
- package/dist/reporter/json/abstract-json-reporter.d.ts +1 -1
- package/dist/reporter/json/index.browser.js +2 -2
- package/dist/reporter/json/index.js +2 -2
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/pretty/pretty-reporter.server.d.ts +1 -1
- package/dist/reporter/raw/raw-reporter.server.d.ts +1 -1
- package/dist/reporter/simple/simple-reporter.server.d.ts +1 -1
- package/dist/reporter/simple/simple-reporter.server.js +8 -12
- package/dist/types.d.ts +4 -4
- package/dist/utils/write-console-log-based-on-level.d.ts +1 -1
- package/dist/wide-event.d.ts +300 -0
- package/dist/wide-event.js +284 -0
- package/package.json +73 -20
- package/dist/interactive/index.d.ts +0 -2
- package/dist/interactive/index.js +0 -2
- package/dist/interactive/interactive-manager.d.ts +0 -108
- package/dist/interactive/interactive-stream-hook.d.ts +0 -68
- package/dist/packem_shared/InteractiveManager-CZ85hGNW.js +0 -172
- package/dist/packem_shared/PrettyReporter-DgZB2eBG.js +0 -222
- package/dist/packem_shared/abstract-pretty-reporter-Di_sdm2r.js +0 -50
- package/dist/packem_shared/format-label-De49vNPd.js +0 -1193
- package/dist/packem_shared/get-longest-label-C9PWeyKq.js +0 -9
- package/dist/packem_shared/index-DqKWykfa.js +0 -1146
- package/dist/packem_shared/interactive-stream-hook-DG4BtN12.js +0 -141
- package/dist/packem_shared/pail.browser-u2CSR_af.js +0 -1427
- package/dist/progress-bar.d.ts +0 -136
- package/dist/progress-bar.js +0 -404
- package/dist/spinner.d.ts +0 -220
- package/dist/spinner.js +0 -2150
- package/dist/utils/ansi-escapes.d.ts +0 -4
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
const LEVEL_PRIORITY = {
|
|
2
|
+
debug: 0,
|
|
3
|
+
error: 3,
|
|
4
|
+
info: 1,
|
|
5
|
+
warn: 2
|
|
6
|
+
};
|
|
7
|
+
const LEVEL_TO_LOG_TYPE = {
|
|
8
|
+
debug: "debug",
|
|
9
|
+
error: "error",
|
|
10
|
+
info: "info",
|
|
11
|
+
warn: "warn"
|
|
12
|
+
};
|
|
13
|
+
const deepMerge = (target, source) => {
|
|
14
|
+
const result = { ...target };
|
|
15
|
+
const keys = Object.keys(source);
|
|
16
|
+
for (let i = 0; i < keys.length; i += 1) {
|
|
17
|
+
const key = keys[i];
|
|
18
|
+
const sourceValue = source[key];
|
|
19
|
+
const targetValue = result[key];
|
|
20
|
+
if (sourceValue !== null && typeof sourceValue === "object" && !Array.isArray(sourceValue) && targetValue !== null && typeof targetValue === "object" && !Array.isArray(targetValue)) {
|
|
21
|
+
result[key] = deepMerge(targetValue, sourceValue);
|
|
22
|
+
} else {
|
|
23
|
+
result[key] = sourceValue;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
const formatDuration = (ms) => {
|
|
29
|
+
if (ms < 1e3) {
|
|
30
|
+
return `${String(ms)}ms`;
|
|
31
|
+
}
|
|
32
|
+
return `${(ms / 1e3).toFixed(2)}s`;
|
|
33
|
+
};
|
|
34
|
+
const serializeError = (error) => {
|
|
35
|
+
const serialized = {
|
|
36
|
+
message: error.message,
|
|
37
|
+
name: error.name
|
|
38
|
+
};
|
|
39
|
+
if (error.stack) {
|
|
40
|
+
serialized.stack = error.stack;
|
|
41
|
+
}
|
|
42
|
+
const errorWithStatus = error;
|
|
43
|
+
if (errorWithStatus.status !== void 0) {
|
|
44
|
+
serialized.status = errorWithStatus.status;
|
|
45
|
+
} else if (errorWithStatus.statusCode !== void 0) {
|
|
46
|
+
serialized.status = errorWithStatus.statusCode;
|
|
47
|
+
}
|
|
48
|
+
if (errorWithStatus.data !== void 0) {
|
|
49
|
+
serialized.data = errorWithStatus.data;
|
|
50
|
+
}
|
|
51
|
+
if (error.cause instanceof Error) {
|
|
52
|
+
serialized.cause = serializeError(error.cause);
|
|
53
|
+
}
|
|
54
|
+
return serialized;
|
|
55
|
+
};
|
|
56
|
+
class WideEvent {
|
|
57
|
+
name;
|
|
58
|
+
autoEmit;
|
|
59
|
+
data;
|
|
60
|
+
emitted;
|
|
61
|
+
attachedError;
|
|
62
|
+
level;
|
|
63
|
+
pail;
|
|
64
|
+
requestLogs;
|
|
65
|
+
service;
|
|
66
|
+
startTime;
|
|
67
|
+
status;
|
|
68
|
+
timestamp;
|
|
69
|
+
// @ts-expect-error TS6133 -- preserved for future use (richer event categorization)
|
|
70
|
+
_type;
|
|
71
|
+
constructor(options) {
|
|
72
|
+
this.name = options.name;
|
|
73
|
+
this.pail = options.pail;
|
|
74
|
+
this.data = {};
|
|
75
|
+
this.startTime = performance.now();
|
|
76
|
+
this.timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
77
|
+
this.emitted = false;
|
|
78
|
+
this.autoEmit = options.autoEmit ?? true;
|
|
79
|
+
this._type = options.type ?? "info";
|
|
80
|
+
this.level = "info";
|
|
81
|
+
this.requestLogs = [];
|
|
82
|
+
this.service = options.service;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Record a debug-level lifecycle log entry.
|
|
86
|
+
* Does not escalate the event level.
|
|
87
|
+
* @param message Description of what happened
|
|
88
|
+
* @param context Optional structured context
|
|
89
|
+
* @returns `this` for chaining
|
|
90
|
+
*/
|
|
91
|
+
debug(message, context) {
|
|
92
|
+
return this.addLogEntry("debug", message, context);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Emit the wide event through the pail logger. Can only be called once;
|
|
96
|
+
* subsequent calls are no-ops.
|
|
97
|
+
*
|
|
98
|
+
* Automatically calculates duration, determines the log type based on
|
|
99
|
+
* the highest severity level reached, and serializes any attached error.
|
|
100
|
+
*
|
|
101
|
+
* Prefer `finish()` for HTTP request contexts where you have a status code.
|
|
102
|
+
* @param typeOverride Override the log type for this emission
|
|
103
|
+
*/
|
|
104
|
+
emit(typeOverride) {
|
|
105
|
+
if (this.emitted) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
this.emitted = true;
|
|
109
|
+
const durationMs = Math.round(performance.now() - this.startTime);
|
|
110
|
+
const resolvedLevel = this.attachedError ? "error" : this.level;
|
|
111
|
+
const type = typeOverride ?? LEVEL_TO_LOG_TYPE[resolvedLevel];
|
|
112
|
+
const payload = {
|
|
113
|
+
duration: formatDuration(durationMs),
|
|
114
|
+
duration_ms: durationMs,
|
|
115
|
+
event: this.name,
|
|
116
|
+
timestamp: this.timestamp,
|
|
117
|
+
...this.data
|
|
118
|
+
};
|
|
119
|
+
if (this.service) {
|
|
120
|
+
payload.service = this.service;
|
|
121
|
+
}
|
|
122
|
+
if (this.status !== void 0) {
|
|
123
|
+
payload.status = this.status;
|
|
124
|
+
}
|
|
125
|
+
if (this.attachedError) {
|
|
126
|
+
payload.error = serializeError(this.attachedError);
|
|
127
|
+
}
|
|
128
|
+
if (this.requestLogs.length > 0) {
|
|
129
|
+
payload.requestLogs = this.requestLogs;
|
|
130
|
+
}
|
|
131
|
+
const logFunction = this.pail[type];
|
|
132
|
+
logFunction({ message: payload });
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Record an error-level lifecycle log entry and attach the error.
|
|
136
|
+
* Escalates the event level to "error".
|
|
137
|
+
* @param message Description of what went wrong
|
|
138
|
+
* @param error The error that occurred
|
|
139
|
+
* @param context Optional structured context
|
|
140
|
+
* @returns `this` for chaining
|
|
141
|
+
*/
|
|
142
|
+
error(message, error, context) {
|
|
143
|
+
if (error) {
|
|
144
|
+
this.attachedError = error;
|
|
145
|
+
}
|
|
146
|
+
return this.addLogEntry("error", message, context);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Finish and emit the wide event with HTTP context.
|
|
150
|
+
* Sets the response status and optional error before emitting.
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* ev.finish({ status: 200 });
|
|
154
|
+
* ev.finish({ status: 500, error: new Error("DB timeout") });
|
|
155
|
+
* ```
|
|
156
|
+
* @param options Status code and/or error
|
|
157
|
+
*/
|
|
158
|
+
finish(options) {
|
|
159
|
+
if (options?.status !== void 0) {
|
|
160
|
+
this.status = options.status;
|
|
161
|
+
}
|
|
162
|
+
if (options?.error) {
|
|
163
|
+
this.attachedError = options.error;
|
|
164
|
+
}
|
|
165
|
+
this.emit();
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Get a read-only snapshot of the accumulated data.
|
|
169
|
+
*/
|
|
170
|
+
getData() {
|
|
171
|
+
return this.data;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get the current severity level of the event.
|
|
175
|
+
* The level auto-escalates as `warn()` or `error()` entries are added.
|
|
176
|
+
*/
|
|
177
|
+
getLevel() {
|
|
178
|
+
return this.attachedError ? "error" : this.level;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Get a read-only copy of the request lifecycle log entries.
|
|
182
|
+
*/
|
|
183
|
+
getRequestLogs() {
|
|
184
|
+
return this.requestLogs;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Record an info-level lifecycle log entry.
|
|
188
|
+
* Does not escalate the event level.
|
|
189
|
+
* @param message Description of what happened
|
|
190
|
+
* @param context Optional structured context
|
|
191
|
+
* @returns `this` for chaining
|
|
192
|
+
*/
|
|
193
|
+
info(message, context) {
|
|
194
|
+
return this.addLogEntry("info", message, context);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Accumulate context into the wide event via deep merge.
|
|
198
|
+
* Call as many times as needed throughout the operation.
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* ev.set({ user: { id: 1 } });
|
|
202
|
+
* ev.set({ user: { plan: "pro" } });
|
|
203
|
+
* // data = { user: { id: 1, plan: "pro" } }
|
|
204
|
+
* ```
|
|
205
|
+
* @param data Partial data to merge into the event
|
|
206
|
+
* @returns `this` for chaining
|
|
207
|
+
*/
|
|
208
|
+
set(data) {
|
|
209
|
+
this.data = deepMerge(this.data, data);
|
|
210
|
+
return this;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Attach an error to the event. Automatically escalates the event
|
|
214
|
+
* level to "error".
|
|
215
|
+
* @param error The error to attach
|
|
216
|
+
* @returns `this` for chaining
|
|
217
|
+
*/
|
|
218
|
+
setError(error) {
|
|
219
|
+
this.attachedError = error;
|
|
220
|
+
return this;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Set the HTTP response status code.
|
|
224
|
+
* @param status HTTP status code
|
|
225
|
+
* @returns `this` for chaining
|
|
226
|
+
*/
|
|
227
|
+
setStatus(status) {
|
|
228
|
+
this.status = status;
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Record a warn-level lifecycle log entry.
|
|
233
|
+
* Escalates the event level to "warn" (unless already "error").
|
|
234
|
+
* @param message Description of the warning
|
|
235
|
+
* @param context Optional structured context
|
|
236
|
+
* @returns `this` for chaining
|
|
237
|
+
*/
|
|
238
|
+
warn(message, context) {
|
|
239
|
+
return this.addLogEntry("warn", message, context);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Disposable implementation. Auto-emits the event if `autoEmit` is true
|
|
243
|
+
* and the event hasn't been manually emitted yet.
|
|
244
|
+
*
|
|
245
|
+
* Enables usage with TC39 Explicit Resource Management:
|
|
246
|
+
* ```typescript
|
|
247
|
+
* using ev = createWideEvent({ pail: logger, name: "api.checkout" });
|
|
248
|
+
* ev.set({ user: { id: 1 } });
|
|
249
|
+
* // auto-emits here when scope exits
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
[Symbol.dispose]() {
|
|
253
|
+
if (this.autoEmit && !this.emitted) {
|
|
254
|
+
this.emit();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Add an entry to the request lifecycle log and escalate level if needed.
|
|
259
|
+
*/
|
|
260
|
+
addLogEntry(level, message, context) {
|
|
261
|
+
const entry = {
|
|
262
|
+
level,
|
|
263
|
+
message,
|
|
264
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
265
|
+
};
|
|
266
|
+
if (context) {
|
|
267
|
+
entry.context = context;
|
|
268
|
+
}
|
|
269
|
+
this.requestLogs.push(entry);
|
|
270
|
+
this.escalateLevel(level);
|
|
271
|
+
return this;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Escalate the event level if the new level has higher severity.
|
|
275
|
+
*/
|
|
276
|
+
escalateLevel(level) {
|
|
277
|
+
if ((LEVEL_PRIORITY[level] ?? 0) > (LEVEL_PRIORITY[this.level] ?? 0)) {
|
|
278
|
+
this.level = level;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const createWideEvent = (options) => new WideEvent(options);
|
|
283
|
+
|
|
284
|
+
export { WideEvent, createWideEvent };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/pail",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.11",
|
|
4
4
|
"description": "Highly configurable Logger for Node.js, Edge and Browser.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ansi",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"warning-logging",
|
|
56
56
|
"winston"
|
|
57
57
|
],
|
|
58
|
-
"homepage": "https://
|
|
58
|
+
"homepage": "https://visulima.com/packages/pail/",
|
|
59
59
|
"bugs": {
|
|
60
60
|
"url": "https://github.com/visulima/visulima/issues"
|
|
61
61
|
},
|
|
@@ -114,6 +114,18 @@
|
|
|
114
114
|
"types": "./dist/processor/opentelemetry-processor.d.ts",
|
|
115
115
|
"default": "./dist/processor/opentelemetry-processor.js"
|
|
116
116
|
},
|
|
117
|
+
"./processor/sampling": {
|
|
118
|
+
"types": "./dist/processor/sampling-processor.d.ts",
|
|
119
|
+
"default": "./dist/processor/sampling-processor.js"
|
|
120
|
+
},
|
|
121
|
+
"./processor/environment": {
|
|
122
|
+
"types": "./dist/processor/environment-processor.d.ts",
|
|
123
|
+
"default": "./dist/processor/environment-processor.js"
|
|
124
|
+
},
|
|
125
|
+
"./error": {
|
|
126
|
+
"types": "./dist/error.d.ts",
|
|
127
|
+
"default": "./dist/error.js"
|
|
128
|
+
},
|
|
117
129
|
"./reporter/file": {
|
|
118
130
|
"types": "./dist/reporter/file/json-file-reporter.d.ts",
|
|
119
131
|
"default": "./dist/reporter/file/json-file-reporter.js"
|
|
@@ -178,22 +190,38 @@
|
|
|
178
190
|
"default": "./dist/reporter/http/http-reporter.js"
|
|
179
191
|
}
|
|
180
192
|
},
|
|
181
|
-
"./progress-bar": {
|
|
182
|
-
"types": "./dist/progress-bar.d.ts",
|
|
183
|
-
"default": "./dist/progress-bar.js"
|
|
184
|
-
},
|
|
185
|
-
"./spinner": {
|
|
186
|
-
"types": "./dist/spinner.d.ts",
|
|
187
|
-
"default": "./dist/spinner.js"
|
|
188
|
-
},
|
|
189
|
-
"./interactive": {
|
|
190
|
-
"types": "./dist/interactive/index.d.ts",
|
|
191
|
-
"default": "./dist/interactive/index.js"
|
|
192
|
-
},
|
|
193
193
|
"./object-tree": {
|
|
194
194
|
"types": "./dist/object-tree.d.ts",
|
|
195
195
|
"default": "./dist/object-tree.js"
|
|
196
196
|
},
|
|
197
|
+
"./wide-event": {
|
|
198
|
+
"types": "./dist/wide-event.d.ts",
|
|
199
|
+
"default": "./dist/wide-event.js"
|
|
200
|
+
},
|
|
201
|
+
"./middleware/express": {
|
|
202
|
+
"types": "./dist/middleware/express.d.ts",
|
|
203
|
+
"default": "./dist/middleware/express.js"
|
|
204
|
+
},
|
|
205
|
+
"./middleware/fastify": {
|
|
206
|
+
"types": "./dist/middleware/fastify.d.ts",
|
|
207
|
+
"default": "./dist/middleware/fastify.js"
|
|
208
|
+
},
|
|
209
|
+
"./middleware/hono": {
|
|
210
|
+
"types": "./dist/middleware/hono.d.ts",
|
|
211
|
+
"default": "./dist/middleware/hono.js"
|
|
212
|
+
},
|
|
213
|
+
"./middleware/elysia": {
|
|
214
|
+
"types": "./dist/middleware/elysia.d.ts",
|
|
215
|
+
"default": "./dist/middleware/elysia.js"
|
|
216
|
+
},
|
|
217
|
+
"./middleware/sveltekit": {
|
|
218
|
+
"types": "./dist/middleware/sveltekit.d.ts",
|
|
219
|
+
"default": "./dist/middleware/sveltekit.js"
|
|
220
|
+
},
|
|
221
|
+
"./middleware/next": {
|
|
222
|
+
"types": "./dist/middleware/next/handler.d.ts",
|
|
223
|
+
"default": "./dist/middleware/next/handler.js"
|
|
224
|
+
},
|
|
197
225
|
"./package.json": "./package.json"
|
|
198
226
|
},
|
|
199
227
|
"files": [
|
|
@@ -203,27 +231,52 @@
|
|
|
203
231
|
"LICENSE.md"
|
|
204
232
|
],
|
|
205
233
|
"dependencies": {
|
|
206
|
-
"
|
|
207
|
-
"@visulima/
|
|
234
|
+
"@visulima/colorize": "2.0.0-alpha.10",
|
|
235
|
+
"@visulima/interactive-manager": "1.0.0-alpha.2",
|
|
236
|
+
"type-fest": "5.6.0"
|
|
208
237
|
},
|
|
209
238
|
"peerDependencies": {
|
|
210
|
-
"@opentelemetry/api": "
|
|
211
|
-
"@
|
|
212
|
-
"
|
|
239
|
+
"@opentelemetry/api": "1.9.1",
|
|
240
|
+
"@sveltejs/kit": ">=2.0",
|
|
241
|
+
"@visulima/redact": "3.0.0-alpha.10",
|
|
242
|
+
"elysia": ">=1.0",
|
|
243
|
+
"express": ">=4.0",
|
|
244
|
+
"fastify": ">=4.0",
|
|
245
|
+
"hono": ">=4.0",
|
|
246
|
+
"next": ">=14.0",
|
|
247
|
+
"rotating-file-stream": "3.2.9"
|
|
213
248
|
},
|
|
214
249
|
"peerDependenciesMeta": {
|
|
215
250
|
"@opentelemetry/api": {
|
|
216
251
|
"optional": true
|
|
217
252
|
},
|
|
253
|
+
"@sveltejs/kit": {
|
|
254
|
+
"optional": true
|
|
255
|
+
},
|
|
218
256
|
"@visulima/redact": {
|
|
219
257
|
"optional": true
|
|
220
258
|
},
|
|
259
|
+
"elysia": {
|
|
260
|
+
"optional": true
|
|
261
|
+
},
|
|
262
|
+
"express": {
|
|
263
|
+
"optional": true
|
|
264
|
+
},
|
|
265
|
+
"fastify": {
|
|
266
|
+
"optional": true
|
|
267
|
+
},
|
|
268
|
+
"hono": {
|
|
269
|
+
"optional": true
|
|
270
|
+
},
|
|
271
|
+
"next": {
|
|
272
|
+
"optional": true
|
|
273
|
+
},
|
|
221
274
|
"rotating-file-stream": {
|
|
222
275
|
"optional": true
|
|
223
276
|
}
|
|
224
277
|
},
|
|
225
278
|
"engines": {
|
|
226
|
-
"node": "
|
|
279
|
+
"node": "^22.14.0 || >=24.10.0"
|
|
227
280
|
},
|
|
228
281
|
"os": [
|
|
229
282
|
"darwin",
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import type InteractiveStreamHook from "./interactive-stream-hook.d.ts";
|
|
2
|
-
/** Supported stream types for interactive output */
|
|
3
|
-
type StreamType = "stderr" | "stdout";
|
|
4
|
-
/**
|
|
5
|
-
* Interactive Manager.
|
|
6
|
-
*
|
|
7
|
-
* Manages interactive terminal output by coordinating stdout and stderr streams.
|
|
8
|
-
* Enables features like progress bars, spinners, and dynamic updates by temporarily
|
|
9
|
-
* capturing and controlling terminal output. Supports suspending and resuming
|
|
10
|
-
* interactive mode for external output.
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* const manager = new InteractiveManager(stdoutHook, stderrHook);
|
|
14
|
-
*
|
|
15
|
-
* // Start interactive mode
|
|
16
|
-
* manager.hook();
|
|
17
|
-
*
|
|
18
|
-
* // Update output dynamically
|
|
19
|
-
* manager.update("stdout", ["Processing...", "50% complete"]);
|
|
20
|
-
*
|
|
21
|
-
* // Temporarily suspend for external output
|
|
22
|
-
* manager.suspend("stdout");
|
|
23
|
-
* console.log("External message");
|
|
24
|
-
* manager.resume("stdout");
|
|
25
|
-
*
|
|
26
|
-
* // End interactive mode and show final output
|
|
27
|
-
* manager.unhook();
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
declare class InteractiveManager {
|
|
31
|
-
#private;
|
|
32
|
-
/**
|
|
33
|
-
* Creates a new InteractiveManager with the given stream hooks.
|
|
34
|
-
* @param stdout Hook for stdout stream
|
|
35
|
-
* @param stderr Hook for stderr stream
|
|
36
|
-
*/
|
|
37
|
-
constructor(stdout: InteractiveStreamHook, stderr: InteractiveStreamHook);
|
|
38
|
-
/**
|
|
39
|
-
* Last printed rows count.
|
|
40
|
-
*
|
|
41
|
-
* Tracks the number of rows that were last written to the terminal.
|
|
42
|
-
* Used internally for managing cursor positioning and output updates.
|
|
43
|
-
*/
|
|
44
|
-
get lastLength(): number;
|
|
45
|
-
/**
|
|
46
|
-
* Rows count outside editable area.
|
|
47
|
-
*
|
|
48
|
-
* Tracks the number of rows that extend beyond the current terminal height.
|
|
49
|
-
* Used for managing scrolling and ensuring all output remains visible.
|
|
50
|
-
*/
|
|
51
|
-
get outside(): number;
|
|
52
|
-
/**
|
|
53
|
-
* Hook activity status.
|
|
54
|
-
*
|
|
55
|
-
* Indicates whether the interactive hooks are currently active.
|
|
56
|
-
* When true, streams are being intercepted for interactive output.
|
|
57
|
-
*/
|
|
58
|
-
get isHooked(): boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Suspend status for active hooks.
|
|
61
|
-
*
|
|
62
|
-
* Indicates whether interactive mode is temporarily suspended.
|
|
63
|
-
* When suspended, external output can be written without interference.
|
|
64
|
-
*/
|
|
65
|
-
get isSuspended(): boolean;
|
|
66
|
-
/**
|
|
67
|
-
* Removes lines from the terminal output.
|
|
68
|
-
*
|
|
69
|
-
* Erases the specified number of lines from the bottom of the output,
|
|
70
|
-
* moving the cursor up and clearing the lines. Useful for removing
|
|
71
|
-
* previous interactive output before displaying new content.
|
|
72
|
-
* @param stream The stream to erase lines from ("stdout" or "stderr")
|
|
73
|
-
* @param count Number of lines to remove (defaults to lastLength)
|
|
74
|
-
* @throws {TypeError} If the specified stream is not available
|
|
75
|
-
*/
|
|
76
|
-
erase(stream: StreamType, count?: number): void;
|
|
77
|
-
/**
|
|
78
|
-
* Hook stdout and stderr streams.
|
|
79
|
-
* @returns Success status
|
|
80
|
-
*/
|
|
81
|
-
hook(): boolean;
|
|
82
|
-
/**
|
|
83
|
-
* Resume suspend hooks.
|
|
84
|
-
* @param stream Stream to resume
|
|
85
|
-
* @param eraseRowCount erase output rows count
|
|
86
|
-
*/
|
|
87
|
-
resume(stream: StreamType, eraseRowCount?: number): void;
|
|
88
|
-
/**
|
|
89
|
-
* Suspend active hooks for external output.
|
|
90
|
-
* @param stream Stream to suspend
|
|
91
|
-
* @param erase erase output
|
|
92
|
-
*/
|
|
93
|
-
suspend(stream: StreamType, erase?: boolean): void;
|
|
94
|
-
/**
|
|
95
|
-
* Unhooks both stdout and stderr streams and print their story of logs.
|
|
96
|
-
* @param separateHistory If `true`, will add an empty line to the history output for individual recorded lines and console logs
|
|
97
|
-
* @returns Success status
|
|
98
|
-
*/
|
|
99
|
-
unhook(separateHistory?: boolean): boolean;
|
|
100
|
-
/**
|
|
101
|
-
* Update output.
|
|
102
|
-
* @param stream Stream to write to
|
|
103
|
-
* @param rows Text lines to write to standard output
|
|
104
|
-
* @param from Index of the line starting from which the contents of the terminal are being overwritten
|
|
105
|
-
*/
|
|
106
|
-
update(stream: StreamType, rows: string[], from?: number): void;
|
|
107
|
-
}
|
|
108
|
-
export default InteractiveManager;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interactive Stream Hook.
|
|
3
|
-
*
|
|
4
|
-
* A utility class that hooks into Node.js WriteStreams to capture output
|
|
5
|
-
* for interactive terminal applications. It allows temporarily intercepting
|
|
6
|
-
* stream writes to enable features like progress bars and dynamic updates.
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* const hook = new InteractiveStreamHook(process.stdout);
|
|
10
|
-
* hook.active(); // Start capturing output
|
|
11
|
-
*
|
|
12
|
-
* // Output will be stored in history instead of being written to stdout
|
|
13
|
-
* console.log("This won't appear immediately");
|
|
14
|
-
*
|
|
15
|
-
* hook.inactive(); // Stop capturing and replay stored output
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
declare class InteractiveStreamHook {
|
|
19
|
-
#private;
|
|
20
|
-
/** Constant indicating the stream write operation was successful */
|
|
21
|
-
static readonly DRAIN = true;
|
|
22
|
-
/**
|
|
23
|
-
* Creates a new InteractiveStreamHook for the given stream.
|
|
24
|
-
* @param stream The Node.js WriteStream to hook into (usually stdout or stderr)
|
|
25
|
-
*/
|
|
26
|
-
constructor(stream: NodeJS.WriteStream);
|
|
27
|
-
/**
|
|
28
|
-
* Activates the stream hook.
|
|
29
|
-
*
|
|
30
|
-
* When active, all writes to the stream are captured in history instead of
|
|
31
|
-
* being written immediately. This allows for interactive features like
|
|
32
|
-
* progress bars that can update dynamically.
|
|
33
|
-
*/
|
|
34
|
-
active(): void;
|
|
35
|
-
/**
|
|
36
|
-
* Erases the specified number of lines from the terminal.
|
|
37
|
-
*
|
|
38
|
-
* Uses ANSI escape sequences to remove lines from the current cursor position
|
|
39
|
-
* upwards, which is useful for clearing previous output in interactive applications.
|
|
40
|
-
* @param count Number of lines to erase (including the current line)
|
|
41
|
-
*/
|
|
42
|
-
erase(count: number): void;
|
|
43
|
-
/**
|
|
44
|
-
* Deactivates the stream hook and replays captured output.
|
|
45
|
-
*
|
|
46
|
-
* Restores normal stream operation and outputs all captured history.
|
|
47
|
-
* Optionally adds a newline separator before replaying the history.
|
|
48
|
-
* @param separateHistory Whether to add a newline before replaying history
|
|
49
|
-
*/
|
|
50
|
-
inactive(separateHistory?: boolean): void;
|
|
51
|
-
/**
|
|
52
|
-
* Renews the stream hook state.
|
|
53
|
-
*
|
|
54
|
-
* Restores the original stream write method and shows the cursor.
|
|
55
|
-
* This is typically called when temporarily suspending interactive mode.
|
|
56
|
-
*/
|
|
57
|
-
renew(): void;
|
|
58
|
-
/**
|
|
59
|
-
* Writes a message directly to the underlying stream.
|
|
60
|
-
*
|
|
61
|
-
* Bypasses the hook mechanism and writes directly using the original
|
|
62
|
-
* stream write method. Useful for writing control sequences or
|
|
63
|
-
* messages that should not be captured in history.
|
|
64
|
-
* @param message The message to write to the stream
|
|
65
|
-
*/
|
|
66
|
-
write(message: string): void;
|
|
67
|
-
}
|
|
68
|
-
export default InteractiveStreamHook;
|