@loggerjs/node 0.6.0 → 0.7.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 +5 -4
- package/dist/bullmq-integration.cjs +2 -145
- package/dist/bullmq-integration.cjs.map +1 -1
- package/dist/bullmq-integration.js +1 -144
- package/dist/bullmq-integration.js.map +1 -1
- package/dist/chunks/node-destination-DvP8jBvm.cjs +254 -0
- package/dist/chunks/node-destination-DvP8jBvm.cjs.map +1 -0
- package/dist/chunks/node-destination-YnpYbctz.js +243 -0
- package/dist/chunks/node-destination-YnpYbctz.js.map +1 -0
- package/dist/context.cjs +1 -1
- package/dist/context.js +1 -1
- package/dist/diagnostics-channel-integration.cjs +1 -1
- package/dist/file-transport.cjs +3 -232
- package/dist/file-transport.cjs.map +1 -1
- package/dist/file-transport.js +3 -232
- package/dist/file-transport.js.map +1 -1
- package/dist/http-transport.cjs +25 -4
- package/dist/http-transport.cjs.map +1 -1
- package/dist/http-transport.d.ts +15 -0
- package/dist/http-transport.d.ts.map +1 -1
- package/dist/http-transport.js +25 -4
- package/dist/http-transport.js.map +1 -1
- package/dist/index.cjs +54 -2375
- package/dist/index.d.ts +211 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -2347
- package/dist/internal-types.d.ts +1 -0
- package/dist/internal-types.d.ts.map +1 -1
- package/dist/logger-diagnostics.cjs +4 -5
- package/dist/logger-diagnostics.cjs.map +1 -1
- package/dist/logger-diagnostics.d.ts +1 -1
- package/dist/logger-diagnostics.d.ts.map +1 -1
- package/dist/logger-diagnostics.js +1 -1
- package/dist/logger-diagnostics.js.map +1 -1
- package/dist/nest-integration.cjs +2 -127
- package/dist/nest-integration.cjs.map +1 -1
- package/dist/nest-integration.js +1 -126
- package/dist/nest-integration.js.map +1 -1
- package/dist/node-destination.d.ts.map +1 -1
- package/dist/payload-transforms.cjs +2 -2
- package/dist/payload-transforms.cjs.map +1 -1
- package/dist/payload-transforms.d.ts.map +1 -1
- package/dist/payload-transforms.js +1 -1
- package/dist/payload-transforms.js.map +1 -1
- package/dist/prisma-integration.cjs +2 -125
- package/dist/prisma-integration.cjs.map +1 -1
- package/dist/prisma-integration.js +1 -124
- package/dist/prisma-integration.js.map +1 -1
- package/dist/redis-integration.cjs +2 -125
- package/dist/redis-integration.cjs.map +1 -1
- package/dist/redis-integration.js +1 -124
- package/dist/redis-integration.js.map +1 -1
- package/dist/rotating-file-transport.cjs +24 -239
- package/dist/rotating-file-transport.cjs.map +1 -1
- package/dist/rotating-file-transport.d.ts.map +1 -1
- package/dist/rotating-file-transport.js +24 -239
- package/dist/rotating-file-transport.js.map +1 -1
- package/dist/stdout-transport.cjs +3 -162
- package/dist/stdout-transport.cjs.map +1 -1
- package/dist/stdout-transport.js +3 -162
- package/dist/stdout-transport.js.map +1 -1
- package/dist/syslog-transport.cjs +1 -1
- package/dist/syslog-transport.js +1 -1
- package/dist/worker-transport.cjs +5 -4
- package/dist/worker-transport.cjs.map +1 -1
- package/dist/worker-transport.d.ts.map +1 -1
- package/dist/worker-transport.js +3 -2
- package/dist/worker-transport.js.map +1 -1
- package/package.json +5 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -30,12 +30,12 @@ import {
|
|
|
30
30
|
captureProcessIntegration,
|
|
31
31
|
createLogger,
|
|
32
32
|
installAsyncLocalStorageContext,
|
|
33
|
-
nodeCompressionPayloadTransform,
|
|
34
|
-
nodeFetchIntegration,
|
|
35
|
-
nodeHttpClientIntegration,
|
|
36
33
|
nodeHttpTransport,
|
|
37
34
|
stdoutTransport,
|
|
38
35
|
} from "@loggerjs/node";
|
|
36
|
+
import { nodeCompressionPayloadTransform } from "@loggerjs/node/payload-transforms";
|
|
37
|
+
import { nodeFetchIntegration } from "@loggerjs/node/integration-fetch";
|
|
38
|
+
import { nodeHttpClientIntegration } from "@loggerjs/node/integration-http-client";
|
|
39
39
|
|
|
40
40
|
installAsyncLocalStorageContext(); // once at startup — context follows async execution
|
|
41
41
|
|
|
@@ -67,7 +67,8 @@ fastify.register(fastifyIntegration(logger, { captureAll: true })); // Fastify p
|
|
|
67
67
|
### Other destinations
|
|
68
68
|
|
|
69
69
|
```ts
|
|
70
|
-
import {
|
|
70
|
+
import { rotatingFileTransport } from "@loggerjs/node";
|
|
71
|
+
import { nodeSyslogTransport } from "@loggerjs/node/transport-syslog";
|
|
71
72
|
|
|
72
73
|
nodeSyslogTransport({ host: "127.0.0.1", port: 514, facility: 16 });
|
|
73
74
|
rotatingFileTransport({ path: "audit.log", maxBytes: 10 * 1024 * 1024 });
|
|
@@ -1,148 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
3
|
-
//#region src/queue-integration.ts
|
|
4
|
-
const defaultMethods = [
|
|
5
|
-
"add",
|
|
6
|
-
"ack",
|
|
7
|
-
"consume",
|
|
8
|
-
"dequeue",
|
|
9
|
-
"nack",
|
|
10
|
-
"process",
|
|
11
|
-
"publish",
|
|
12
|
-
"receive",
|
|
13
|
-
"send",
|
|
14
|
-
"sendToQueue"
|
|
15
|
-
];
|
|
16
|
-
const defaultRandom = () => Math.random();
|
|
17
|
-
function defaultLevel(_durationMs, error) {
|
|
18
|
-
return error ? "error" : "debug";
|
|
19
|
-
}
|
|
20
|
-
function isPromiseLike(value) {
|
|
21
|
-
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
22
|
-
}
|
|
23
|
-
function defaultOperation(method) {
|
|
24
|
-
switch (method) {
|
|
25
|
-
case "add":
|
|
26
|
-
case "publish":
|
|
27
|
-
case "send":
|
|
28
|
-
case "sendToQueue": return "publish";
|
|
29
|
-
case "consume":
|
|
30
|
-
case "dequeue":
|
|
31
|
-
case "process":
|
|
32
|
-
case "receive": return "consume";
|
|
33
|
-
case "ack": return "ack";
|
|
34
|
-
case "nack": return "nack";
|
|
35
|
-
default: return "other";
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function defaultPayload(args) {
|
|
39
|
-
return typeof args[0] === "string" && args.length > 1 ? args[1] : args[0];
|
|
40
|
-
}
|
|
41
|
-
function defaultMessageId(args) {
|
|
42
|
-
const payload = defaultPayload(args);
|
|
43
|
-
if (typeof payload !== "object" || payload === null) return void 0;
|
|
44
|
-
const value = payload.messageId ?? payload.id;
|
|
45
|
-
return value === void 0 ? void 0 : String(value);
|
|
46
|
-
}
|
|
47
|
-
function payloadFor(args, method, options) {
|
|
48
|
-
if (!options.capturePayload) return void 0;
|
|
49
|
-
const payload = options.getPayload?.(args, method) ?? defaultPayload(args);
|
|
50
|
-
return payload === void 0 ? void 0 : (0, _loggerjs_core.normalizeValue)(payload, {
|
|
51
|
-
maxDepth: 4,
|
|
52
|
-
maxObjectKeys: 80
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
function queueIntegration(options = {}) {
|
|
56
|
-
const targets = options.targets ?? (options.client ? [{
|
|
57
|
-
client: options.client,
|
|
58
|
-
name: options.name,
|
|
59
|
-
system: options.system,
|
|
60
|
-
queueName: options.queueName,
|
|
61
|
-
methods: options.methods
|
|
62
|
-
}] : []);
|
|
63
|
-
const captureAll = options.captureAll ?? options.captureSuccessful ?? false;
|
|
64
|
-
const sampleRate = options.sampleRate ?? 1;
|
|
65
|
-
const random = options.random ?? defaultRandom;
|
|
66
|
-
const levelFor = options.level ?? defaultLevel;
|
|
67
|
-
const shouldCapture = (durationMs, error) => {
|
|
68
|
-
if (error) return true;
|
|
69
|
-
if (options.minDurationMs !== void 0 && durationMs >= options.minDurationMs) return true;
|
|
70
|
-
if (!captureAll) return false;
|
|
71
|
-
return sampleRate >= 1 || random() < sampleRate;
|
|
72
|
-
};
|
|
73
|
-
return {
|
|
74
|
-
name: "queue",
|
|
75
|
-
setup(api) {
|
|
76
|
-
const capture = api.guard((input) => api.capture(input));
|
|
77
|
-
const disposers = [];
|
|
78
|
-
let disposed = false;
|
|
79
|
-
const captureResult = (info, started, args, error) => {
|
|
80
|
-
const durationMs = Date.now() - started;
|
|
81
|
-
if (disposed || !shouldCapture(durationMs, error)) return;
|
|
82
|
-
capture({
|
|
83
|
-
level: levelFor(durationMs, error, info),
|
|
84
|
-
message: error ? `Queue error ${info.operation} ${info.queueName ?? info.method}` : `Queue ${info.operation} ${info.queueName ?? info.method}`,
|
|
85
|
-
error,
|
|
86
|
-
props: { queue: {
|
|
87
|
-
kind: info.target,
|
|
88
|
-
system: info.system,
|
|
89
|
-
queueName: info.queueName,
|
|
90
|
-
method: info.method,
|
|
91
|
-
operation: info.operation,
|
|
92
|
-
durationMs,
|
|
93
|
-
messageId: options.getMessageId?.(args, info.method) ?? defaultMessageId(args),
|
|
94
|
-
payload: payloadFor(args, info.method, options)
|
|
95
|
-
} }
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
for (const target of targets) {
|
|
99
|
-
const methods = target.methods ?? options.methods ?? defaultMethods;
|
|
100
|
-
for (const method of methods) {
|
|
101
|
-
const original = target.client[method];
|
|
102
|
-
if (typeof original !== "function") continue;
|
|
103
|
-
const originalMethod = original;
|
|
104
|
-
const targetName = target.name ?? options.name ?? "queue";
|
|
105
|
-
const system = target.system ?? options.system;
|
|
106
|
-
target.client[method] = function wrappedQueueMethod(...args) {
|
|
107
|
-
const started = Date.now();
|
|
108
|
-
const operation = options.getOperation?.(method, args) ?? defaultOperation(method);
|
|
109
|
-
const info = {
|
|
110
|
-
target: targetName,
|
|
111
|
-
system,
|
|
112
|
-
queueName: options.getQueueName?.(args, method) ?? target.queueName ?? options.queueName ?? (typeof args[0] === "string" ? args[0] : void 0),
|
|
113
|
-
method,
|
|
114
|
-
operation
|
|
115
|
-
};
|
|
116
|
-
try {
|
|
117
|
-
const result = originalMethod.apply(this, args);
|
|
118
|
-
if (isPromiseLike(result)) return result.then((value) => {
|
|
119
|
-
captureResult(info, started, args, void 0);
|
|
120
|
-
return value;
|
|
121
|
-
}, (error) => {
|
|
122
|
-
captureResult(info, started, args, error);
|
|
123
|
-
throw error;
|
|
124
|
-
});
|
|
125
|
-
captureResult(info, started, args, void 0);
|
|
126
|
-
return result;
|
|
127
|
-
} catch (error) {
|
|
128
|
-
captureResult(info, started, args, error);
|
|
129
|
-
throw error;
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
disposers.push(() => {
|
|
133
|
-
target.client[method] = originalMethod;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return () => {
|
|
138
|
-
if (disposed) return;
|
|
139
|
-
disposed = true;
|
|
140
|
-
for (const dispose of disposers) dispose();
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
//#endregion
|
|
2
|
+
const require_queue_integration = require("./queue-integration.cjs");
|
|
146
3
|
//#region src/bullmq-integration.ts
|
|
147
4
|
const bullMqMethods = [
|
|
148
5
|
"add",
|
|
@@ -159,7 +16,7 @@ function operationFor(method) {
|
|
|
159
16
|
return "other";
|
|
160
17
|
}
|
|
161
18
|
function bullMqIntegration(options) {
|
|
162
|
-
return queueIntegration({
|
|
19
|
+
return require_queue_integration.queueIntegration({
|
|
163
20
|
...options,
|
|
164
21
|
name: options.name ?? "bullmq",
|
|
165
22
|
system: "bullmq",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bullmq-integration.cjs","names":[],"sources":["../src/queue-integration.ts","../src/bullmq-integration.ts"],"sourcesContent":["import {\n normalizeValue,\n type CaptureInput,\n type Integration,\n type IntegrationSetupContext,\n type LoggerLevel,\n} from \"@loggerjs/core\";\n\nexport type QueueOperation = \"publish\" | \"consume\" | \"ack\" | \"nack\" | \"other\";\n\nexport interface QueueClientLike {\n [method: string]: unknown;\n}\n\nexport interface QueueIntegrationTarget {\n client: QueueClientLike;\n name?: string;\n system?: string;\n queueName?: string;\n methods?: readonly string[];\n}\n\nexport interface QueueOperationInfo {\n target: string;\n system?: string;\n queueName?: string;\n method: string;\n operation: QueueOperation;\n}\n\nexport interface QueueIntegrationOptions {\n client?: QueueClientLike;\n targets?: readonly QueueIntegrationTarget[];\n name?: string;\n system?: string;\n queueName?: string;\n methods?: readonly string[];\n captureAll?: boolean;\n captureSuccessful?: boolean;\n minDurationMs?: number;\n sampleRate?: number;\n random?: () => number;\n capturePayload?: boolean;\n getOperation?: (method: string, args: readonly unknown[]) => QueueOperation;\n getQueueName?: (args: readonly unknown[], method: string) => string | undefined;\n getMessageId?: (args: readonly unknown[], method: string) => string | undefined;\n getPayload?: (args: readonly unknown[], method: string) => unknown;\n level?: (durationMs: number, error: unknown, info: QueueOperationInfo) => LoggerLevel;\n}\n\ntype QueueMethod = (this: unknown, ...args: unknown[]) => unknown;\n\nconst defaultMethods = [\n \"add\",\n \"ack\",\n \"consume\",\n \"dequeue\",\n \"nack\",\n \"process\",\n \"publish\",\n \"receive\",\n \"send\",\n \"sendToQueue\",\n] as const;\nconst defaultRandom = () => Math.random();\n\nfunction defaultLevel(_durationMs: number, error: unknown): LoggerLevel {\n return error ? \"error\" : \"debug\";\n}\n\nfunction isPromiseLike(value: unknown): value is PromiseLike<unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as { then?: unknown }).then === \"function\"\n );\n}\n\nfunction defaultOperation(method: string): QueueOperation {\n switch (method) {\n case \"add\":\n case \"publish\":\n case \"send\":\n case \"sendToQueue\":\n return \"publish\";\n case \"consume\":\n case \"dequeue\":\n case \"process\":\n case \"receive\":\n return \"consume\";\n case \"ack\":\n return \"ack\";\n case \"nack\":\n return \"nack\";\n default:\n return \"other\";\n }\n}\n\nfunction defaultPayload(args: readonly unknown[]) {\n return typeof args[0] === \"string\" && args.length > 1 ? args[1] : args[0];\n}\n\nfunction defaultMessageId(args: readonly unknown[]) {\n const payload = defaultPayload(args);\n if (typeof payload !== \"object\" || payload === null) return undefined;\n const value =\n (payload as { id?: unknown; messageId?: unknown }).messageId ??\n (payload as { id?: unknown }).id;\n return value === undefined ? undefined : String(value);\n}\n\nfunction payloadFor(args: readonly unknown[], method: string, options: QueueIntegrationOptions) {\n if (!options.capturePayload) return undefined;\n const payload = options.getPayload?.(args, method) ?? defaultPayload(args);\n return payload === undefined\n ? undefined\n : normalizeValue(payload, { maxDepth: 4, maxObjectKeys: 80 });\n}\n\nexport function queueIntegration(options: QueueIntegrationOptions = {}): Integration {\n const targets =\n options.targets ??\n (options.client\n ? [\n {\n client: options.client,\n name: options.name,\n system: options.system,\n queueName: options.queueName,\n methods: options.methods,\n },\n ]\n : []);\n const captureAll = options.captureAll ?? options.captureSuccessful ?? false;\n const sampleRate = options.sampleRate ?? 1;\n const random = options.random ?? defaultRandom;\n const levelFor = options.level ?? defaultLevel;\n\n const shouldCapture = (durationMs: number, error: unknown) => {\n if (error) return true;\n if (options.minDurationMs !== undefined && durationMs >= options.minDurationMs) return true;\n if (!captureAll) return false;\n return sampleRate >= 1 || random() < sampleRate;\n };\n\n return {\n name: \"queue\",\n setup(api: IntegrationSetupContext) {\n const capture = api.guard((input: CaptureInput) => api.capture(input));\n const disposers: Array<() => void> = [];\n let disposed = false;\n\n const captureResult = (\n info: QueueOperationInfo,\n started: number,\n args: readonly unknown[],\n error: unknown,\n ) => {\n const durationMs = Date.now() - started;\n if (disposed || !shouldCapture(durationMs, error)) return;\n capture({\n level: levelFor(durationMs, error, info),\n message: error\n ? `Queue error ${info.operation} ${info.queueName ?? info.method}`\n : `Queue ${info.operation} ${info.queueName ?? info.method}`,\n error,\n props: {\n queue: {\n kind: info.target,\n system: info.system,\n queueName: info.queueName,\n method: info.method,\n operation: info.operation,\n durationMs,\n messageId: options.getMessageId?.(args, info.method) ?? defaultMessageId(args),\n payload: payloadFor(args, info.method, options),\n },\n },\n });\n };\n\n for (const target of targets) {\n const methods = target.methods ?? options.methods ?? defaultMethods;\n for (const method of methods) {\n const original = target.client[method];\n if (typeof original !== \"function\") continue;\n const originalMethod = original as QueueMethod;\n const targetName = target.name ?? options.name ?? \"queue\";\n const system = target.system ?? options.system;\n\n target.client[method] = function wrappedQueueMethod(this: unknown, ...args: unknown[]) {\n const started = Date.now();\n const operation = options.getOperation?.(method, args) ?? defaultOperation(method);\n const info: QueueOperationInfo = {\n target: targetName,\n system,\n queueName:\n options.getQueueName?.(args, method) ??\n target.queueName ??\n options.queueName ??\n (typeof args[0] === \"string\" ? args[0] : undefined),\n method,\n operation,\n };\n try {\n const result = originalMethod.apply(this, args);\n if (isPromiseLike(result)) {\n return result.then(\n (value) => {\n captureResult(info, started, args, undefined);\n return value;\n },\n (error) => {\n captureResult(info, started, args, error);\n throw error;\n },\n );\n }\n captureResult(info, started, args, undefined);\n return result;\n } catch (error) {\n captureResult(info, started, args, error);\n throw error;\n }\n };\n\n disposers.push(() => {\n target.client[method] = originalMethod;\n });\n }\n }\n\n return () => {\n if (disposed) return;\n disposed = true;\n for (const dispose of disposers) dispose();\n };\n },\n };\n}\n","import {\n queueIntegration,\n type QueueClientLike,\n type QueueIntegrationOptions,\n type QueueOperation,\n} from \"./queue-integration\";\n\nexport interface BullMqIntegrationOptions extends Omit<\n QueueIntegrationOptions,\n \"client\" | \"system\" | \"methods\" | \"getQueueName\"\n> {\n /**\n * Queue-like BullMQ object. By default LoggerJS wraps `add`, `addBulk`, and a\n * legacy `process` method when present; it does not hook `Worker` or\n * `QueueEvents` lifecycle events such as `completed`, `failed`, or `stalled`.\n */\n client: QueueClientLike & { name?: string };\n methods?: readonly string[];\n}\n\nconst bullMqMethods = [\"add\", \"addBulk\", \"process\"] as const;\n\nfunction queueName(args: readonly unknown[], fallback: string | undefined) {\n const first = args[0];\n return typeof first === \"string\" ? first : fallback;\n}\n\nfunction operationFor(method: string): QueueOperation {\n if (method === \"process\") return \"consume\";\n if (method === \"add\" || method === \"addBulk\") return \"publish\";\n return \"other\";\n}\n\nexport function bullMqIntegration(options: BullMqIntegrationOptions) {\n return queueIntegration({\n ...options,\n name: options.name ?? \"bullmq\",\n system: \"bullmq\",\n methods: options.methods ?? bullMqMethods,\n getOperation: options.getOperation ?? operationFor,\n queueName: options.queueName ?? options.client.name,\n getQueueName: (args) => queueName(args, options.queueName ?? options.client.name),\n });\n}\n"],"mappings":";;;AAoDA,MAAM,iBAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AACA,MAAM,sBAAsB,KAAK,OAAO;AAExC,SAAS,aAAa,aAAqB,OAA6B;CACtE,OAAO,QAAQ,UAAU;AAC3B;AAEA,SAAS,cAAc,OAA+C;CACpE,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA6B,SAAS;AAElD;AAEA,SAAS,iBAAiB,QAAgC;CACxD,QAAQ,QAAR;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,eACH,OAAO;EACT,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,WACH,OAAO;EACT,KAAK,OACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AAEA,SAAS,eAAe,MAA0B;CAChD,OAAO,OAAO,KAAK,OAAO,YAAY,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK;AACzE;AAEA,SAAS,iBAAiB,MAA0B;CAClD,MAAM,UAAU,eAAe,IAAI;CACnC,IAAI,OAAO,YAAY,YAAY,YAAY,MAAM,OAAO,KAAA;CAC5D,MAAM,QACH,QAAkD,aAClD,QAA6B;CAChC,OAAO,UAAU,KAAA,IAAY,KAAA,IAAY,OAAO,KAAK;AACvD;AAEA,SAAS,WAAW,MAA0B,QAAgB,SAAkC;CAC9F,IAAI,CAAC,QAAQ,gBAAgB,OAAO,KAAA;CACpC,MAAM,UAAU,QAAQ,aAAa,MAAM,MAAM,KAAK,eAAe,IAAI;CACzE,OAAO,YAAY,KAAA,IACf,KAAA,KAAA,GAAA,eAAA,eAAA,CACe,SAAS;EAAE,UAAU;EAAG,eAAe;CAAG,CAAC;AAChE;AAEA,SAAgB,iBAAiB,UAAmC,CAAC,GAAgB;CACnF,MAAM,UACJ,QAAQ,YACP,QAAQ,SACL,CACE;EACE,Q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,WAAW,OAAO;CACrD,OAAO;AACT;AAEA,SAAgB,kBAAkB,SAAmC;CACnE,OAAO,iBAAiB;EACtB,GAAG;EACH,MAAM,QAAQ,QAAQ;EACtB,QAAQ;EACR,SAAS,QAAQ,WAAW;EAC5B,cAAc,QAAQ,gBAAgB;EACtC,WAAW,QAAQ,aAAa,QAAQ,OAAO;EAC/C,eAAe,SAAS,UAAU,MAAM,QAAQ,aAAa,QAAQ,OAAO,IAAI;CAClF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"bullmq-integration.cjs","names":["queueIntegration"],"sources":["../src/bullmq-integration.ts"],"sourcesContent":["import {\n queueIntegration,\n type QueueClientLike,\n type QueueIntegrationOptions,\n type QueueOperation,\n} from \"./queue-integration\";\n\nexport interface BullMqIntegrationOptions extends Omit<\n QueueIntegrationOptions,\n \"client\" | \"system\" | \"methods\" | \"getQueueName\"\n> {\n /**\n * Queue-like BullMQ object. By default LoggerJS wraps `add`, `addBulk`, and a\n * legacy `process` method when present; it does not hook `Worker` or\n * `QueueEvents` lifecycle events such as `completed`, `failed`, or `stalled`.\n */\n client: QueueClientLike & { name?: string };\n methods?: readonly string[];\n}\n\nconst bullMqMethods = [\"add\", \"addBulk\", \"process\"] as const;\n\nfunction queueName(args: readonly unknown[], fallback: string | undefined) {\n const first = args[0];\n return typeof first === \"string\" ? first : fallback;\n}\n\nfunction operationFor(method: string): QueueOperation {\n if (method === \"process\") return \"consume\";\n if (method === \"add\" || method === \"addBulk\") return \"publish\";\n return \"other\";\n}\n\nexport function bullMqIntegration(options: BullMqIntegrationOptions) {\n return queueIntegration({\n ...options,\n name: options.name ?? \"bullmq\",\n system: \"bullmq\",\n methods: options.methods ?? bullMqMethods,\n getOperation: options.getOperation ?? operationFor,\n queueName: options.queueName ?? options.client.name,\n getQueueName: (args) => queueName(args, options.queueName ?? options.client.name),\n });\n}\n"],"mappings":";;;AAoBA,MAAM,gBAAgB;CAAC;CAAO;CAAW;AAAS;AAElD,SAAS,UAAU,MAA0B,UAA8B;CACzE,MAAM,QAAQ,KAAK;CACnB,OAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAEA,SAAS,aAAa,QAAgC;CACpD,IAAI,WAAW,WAAW,OAAO;CACjC,IAAI,WAAW,SAAS,WAAW,WAAW,OAAO;CACrD,OAAO;AACT;AAEA,SAAgB,kBAAkB,SAAmC;CACnE,OAAOA,0BAAAA,iBAAiB;EACtB,GAAG;EACH,MAAM,QAAQ,QAAQ;EACtB,QAAQ;EACR,SAAS,QAAQ,WAAW;EAC5B,cAAc,QAAQ,gBAAgB;EACtC,WAAW,QAAQ,aAAa,QAAQ,OAAO;EAC/C,eAAe,SAAS,UAAU,MAAM,QAAQ,aAAa,QAAQ,OAAO,IAAI;CAClF,CAAC;AACH"}
|
|
@@ -1,147 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//#region src/queue-integration.ts
|
|
3
|
-
const defaultMethods = [
|
|
4
|
-
"add",
|
|
5
|
-
"ack",
|
|
6
|
-
"consume",
|
|
7
|
-
"dequeue",
|
|
8
|
-
"nack",
|
|
9
|
-
"process",
|
|
10
|
-
"publish",
|
|
11
|
-
"receive",
|
|
12
|
-
"send",
|
|
13
|
-
"sendToQueue"
|
|
14
|
-
];
|
|
15
|
-
const defaultRandom = () => Math.random();
|
|
16
|
-
function defaultLevel(_durationMs, error) {
|
|
17
|
-
return error ? "error" : "debug";
|
|
18
|
-
}
|
|
19
|
-
function isPromiseLike(value) {
|
|
20
|
-
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
21
|
-
}
|
|
22
|
-
function defaultOperation(method) {
|
|
23
|
-
switch (method) {
|
|
24
|
-
case "add":
|
|
25
|
-
case "publish":
|
|
26
|
-
case "send":
|
|
27
|
-
case "sendToQueue": return "publish";
|
|
28
|
-
case "consume":
|
|
29
|
-
case "dequeue":
|
|
30
|
-
case "process":
|
|
31
|
-
case "receive": return "consume";
|
|
32
|
-
case "ack": return "ack";
|
|
33
|
-
case "nack": return "nack";
|
|
34
|
-
default: return "other";
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function defaultPayload(args) {
|
|
38
|
-
return typeof args[0] === "string" && args.length > 1 ? args[1] : args[0];
|
|
39
|
-
}
|
|
40
|
-
function defaultMessageId(args) {
|
|
41
|
-
const payload = defaultPayload(args);
|
|
42
|
-
if (typeof payload !== "object" || payload === null) return void 0;
|
|
43
|
-
const value = payload.messageId ?? payload.id;
|
|
44
|
-
return value === void 0 ? void 0 : String(value);
|
|
45
|
-
}
|
|
46
|
-
function payloadFor(args, method, options) {
|
|
47
|
-
if (!options.capturePayload) return void 0;
|
|
48
|
-
const payload = options.getPayload?.(args, method) ?? defaultPayload(args);
|
|
49
|
-
return payload === void 0 ? void 0 : normalizeValue(payload, {
|
|
50
|
-
maxDepth: 4,
|
|
51
|
-
maxObjectKeys: 80
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
function queueIntegration(options = {}) {
|
|
55
|
-
const targets = options.targets ?? (options.client ? [{
|
|
56
|
-
client: options.client,
|
|
57
|
-
name: options.name,
|
|
58
|
-
system: options.system,
|
|
59
|
-
queueName: options.queueName,
|
|
60
|
-
methods: options.methods
|
|
61
|
-
}] : []);
|
|
62
|
-
const captureAll = options.captureAll ?? options.captureSuccessful ?? false;
|
|
63
|
-
const sampleRate = options.sampleRate ?? 1;
|
|
64
|
-
const random = options.random ?? defaultRandom;
|
|
65
|
-
const levelFor = options.level ?? defaultLevel;
|
|
66
|
-
const shouldCapture = (durationMs, error) => {
|
|
67
|
-
if (error) return true;
|
|
68
|
-
if (options.minDurationMs !== void 0 && durationMs >= options.minDurationMs) return true;
|
|
69
|
-
if (!captureAll) return false;
|
|
70
|
-
return sampleRate >= 1 || random() < sampleRate;
|
|
71
|
-
};
|
|
72
|
-
return {
|
|
73
|
-
name: "queue",
|
|
74
|
-
setup(api) {
|
|
75
|
-
const capture = api.guard((input) => api.capture(input));
|
|
76
|
-
const disposers = [];
|
|
77
|
-
let disposed = false;
|
|
78
|
-
const captureResult = (info, started, args, error) => {
|
|
79
|
-
const durationMs = Date.now() - started;
|
|
80
|
-
if (disposed || !shouldCapture(durationMs, error)) return;
|
|
81
|
-
capture({
|
|
82
|
-
level: levelFor(durationMs, error, info),
|
|
83
|
-
message: error ? `Queue error ${info.operation} ${info.queueName ?? info.method}` : `Queue ${info.operation} ${info.queueName ?? info.method}`,
|
|
84
|
-
error,
|
|
85
|
-
props: { queue: {
|
|
86
|
-
kind: info.target,
|
|
87
|
-
system: info.system,
|
|
88
|
-
queueName: info.queueName,
|
|
89
|
-
method: info.method,
|
|
90
|
-
operation: info.operation,
|
|
91
|
-
durationMs,
|
|
92
|
-
messageId: options.getMessageId?.(args, info.method) ?? defaultMessageId(args),
|
|
93
|
-
payload: payloadFor(args, info.method, options)
|
|
94
|
-
} }
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
for (const target of targets) {
|
|
98
|
-
const methods = target.methods ?? options.methods ?? defaultMethods;
|
|
99
|
-
for (const method of methods) {
|
|
100
|
-
const original = target.client[method];
|
|
101
|
-
if (typeof original !== "function") continue;
|
|
102
|
-
const originalMethod = original;
|
|
103
|
-
const targetName = target.name ?? options.name ?? "queue";
|
|
104
|
-
const system = target.system ?? options.system;
|
|
105
|
-
target.client[method] = function wrappedQueueMethod(...args) {
|
|
106
|
-
const started = Date.now();
|
|
107
|
-
const operation = options.getOperation?.(method, args) ?? defaultOperation(method);
|
|
108
|
-
const info = {
|
|
109
|
-
target: targetName,
|
|
110
|
-
system,
|
|
111
|
-
queueName: options.getQueueName?.(args, method) ?? target.queueName ?? options.queueName ?? (typeof args[0] === "string" ? args[0] : void 0),
|
|
112
|
-
method,
|
|
113
|
-
operation
|
|
114
|
-
};
|
|
115
|
-
try {
|
|
116
|
-
const result = originalMethod.apply(this, args);
|
|
117
|
-
if (isPromiseLike(result)) return result.then((value) => {
|
|
118
|
-
captureResult(info, started, args, void 0);
|
|
119
|
-
return value;
|
|
120
|
-
}, (error) => {
|
|
121
|
-
captureResult(info, started, args, error);
|
|
122
|
-
throw error;
|
|
123
|
-
});
|
|
124
|
-
captureResult(info, started, args, void 0);
|
|
125
|
-
return result;
|
|
126
|
-
} catch (error) {
|
|
127
|
-
captureResult(info, started, args, error);
|
|
128
|
-
throw error;
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
disposers.push(() => {
|
|
132
|
-
target.client[method] = originalMethod;
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return () => {
|
|
137
|
-
if (disposed) return;
|
|
138
|
-
disposed = true;
|
|
139
|
-
for (const dispose of disposers) dispose();
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
//#endregion
|
|
1
|
+
import { queueIntegration } from "./queue-integration.js";
|
|
145
2
|
//#region src/bullmq-integration.ts
|
|
146
3
|
const bullMqMethods = [
|
|
147
4
|
"add",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bullmq-integration.js","names":[],"sources":["../src/queue-integration.ts","../src/bullmq-integration.ts"],"sourcesContent":["import {\n normalizeValue,\n type CaptureInput,\n type Integration,\n type IntegrationSetupContext,\n type LoggerLevel,\n} from \"@loggerjs/core\";\n\nexport type QueueOperation = \"publish\" | \"consume\" | \"ack\" | \"nack\" | \"other\";\n\nexport interface QueueClientLike {\n [method: string]: unknown;\n}\n\nexport interface QueueIntegrationTarget {\n client: QueueClientLike;\n name?: string;\n system?: string;\n queueName?: string;\n methods?: readonly string[];\n}\n\nexport interface QueueOperationInfo {\n target: string;\n system?: string;\n queueName?: string;\n method: string;\n operation: QueueOperation;\n}\n\nexport interface QueueIntegrationOptions {\n client?: QueueClientLike;\n targets?: readonly QueueIntegrationTarget[];\n name?: string;\n system?: string;\n queueName?: string;\n methods?: readonly string[];\n captureAll?: boolean;\n captureSuccessful?: boolean;\n minDurationMs?: number;\n sampleRate?: number;\n random?: () => number;\n capturePayload?: boolean;\n getOperation?: (method: string, args: readonly unknown[]) => QueueOperation;\n getQueueName?: (args: readonly unknown[], method: string) => string | undefined;\n getMessageId?: (args: readonly unknown[], method: string) => string | undefined;\n getPayload?: (args: readonly unknown[], method: string) => unknown;\n level?: (durationMs: number, error: unknown, info: QueueOperationInfo) => LoggerLevel;\n}\n\ntype QueueMethod = (this: unknown, ...args: unknown[]) => unknown;\n\nconst defaultMethods = [\n \"add\",\n \"ack\",\n \"consume\",\n \"dequeue\",\n \"nack\",\n \"process\",\n \"publish\",\n \"receive\",\n \"send\",\n \"sendToQueue\",\n] as const;\nconst defaultRandom = () => Math.random();\n\nfunction defaultLevel(_durationMs: number, error: unknown): LoggerLevel {\n return error ? \"error\" : \"debug\";\n}\n\nfunction isPromiseLike(value: unknown): value is PromiseLike<unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as { then?: unknown }).then === \"function\"\n );\n}\n\nfunction defaultOperation(method: string): QueueOperation {\n switch (method) {\n case \"add\":\n case \"publish\":\n case \"send\":\n case \"sendToQueue\":\n return \"publish\";\n case \"consume\":\n case \"dequeue\":\n case \"process\":\n case \"receive\":\n return \"consume\";\n case \"ack\":\n return \"ack\";\n case \"nack\":\n return \"nack\";\n default:\n return \"other\";\n }\n}\n\nfunction defaultPayload(args: readonly unknown[]) {\n return typeof args[0] === \"string\" && args.length > 1 ? args[1] : args[0];\n}\n\nfunction defaultMessageId(args: readonly unknown[]) {\n const payload = defaultPayload(args);\n if (typeof payload !== \"object\" || payload === null) return undefined;\n const value =\n (payload as { id?: unknown; messageId?: unknown }).messageId ??\n (payload as { id?: unknown }).id;\n return value === undefined ? undefined : String(value);\n}\n\nfunction payloadFor(args: readonly unknown[], method: string, options: QueueIntegrationOptions) {\n if (!options.capturePayload) return undefined;\n const payload = options.getPayload?.(args, method) ?? defaultPayload(args);\n return payload === undefined\n ? undefined\n : normalizeValue(payload, { maxDepth: 4, maxObjectKeys: 80 });\n}\n\nexport function queueIntegration(options: QueueIntegrationOptions = {}): Integration {\n const targets =\n options.targets ??\n (options.client\n ? [\n {\n client: options.client,\n name: options.name,\n system: options.system,\n queueName: options.queueName,\n methods: options.methods,\n },\n ]\n : []);\n const captureAll = options.captureAll ?? options.captureSuccessful ?? false;\n const sampleRate = options.sampleRate ?? 1;\n const random = options.random ?? defaultRandom;\n const levelFor = options.level ?? defaultLevel;\n\n const shouldCapture = (durationMs: number, error: unknown) => {\n if (error) return true;\n if (options.minDurationMs !== undefined && durationMs >= options.minDurationMs) return true;\n if (!captureAll) return false;\n return sampleRate >= 1 || random() < sampleRate;\n };\n\n return {\n name: \"queue\",\n setup(api: IntegrationSetupContext) {\n const capture = api.guard((input: CaptureInput) => api.capture(input));\n const disposers: Array<() => void> = [];\n let disposed = false;\n\n const captureResult = (\n info: QueueOperationInfo,\n started: number,\n args: readonly unknown[],\n error: unknown,\n ) => {\n const durationMs = Date.now() - started;\n if (disposed || !shouldCapture(durationMs, error)) return;\n capture({\n level: levelFor(durationMs, error, info),\n message: error\n ? `Queue error ${info.operation} ${info.queueName ?? info.method}`\n : `Queue ${info.operation} ${info.queueName ?? info.method}`,\n error,\n props: {\n queue: {\n kind: info.target,\n system: info.system,\n queueName: info.queueName,\n method: info.method,\n operation: info.operation,\n durationMs,\n messageId: options.getMessageId?.(args, info.method) ?? defaultMessageId(args),\n payload: payloadFor(args, info.method, options),\n },\n },\n });\n };\n\n for (const target of targets) {\n const methods = target.methods ?? options.methods ?? defaultMethods;\n for (const method of methods) {\n const original = target.client[method];\n if (typeof original !== \"function\") continue;\n const originalMethod = original as QueueMethod;\n const targetName = target.name ?? options.name ?? \"queue\";\n const system = target.system ?? options.system;\n\n target.client[method] = function wrappedQueueMethod(this: unknown, ...args: unknown[]) {\n const started = Date.now();\n const operation = options.getOperation?.(method, args) ?? defaultOperation(method);\n const info: QueueOperationInfo = {\n target: targetName,\n system,\n queueName:\n options.getQueueName?.(args, method) ??\n target.queueName ??\n options.queueName ??\n (typeof args[0] === \"string\" ? args[0] : undefined),\n method,\n operation,\n };\n try {\n const result = originalMethod.apply(this, args);\n if (isPromiseLike(result)) {\n return result.then(\n (value) => {\n captureResult(info, started, args, undefined);\n return value;\n },\n (error) => {\n captureResult(info, started, args, error);\n throw error;\n },\n );\n }\n captureResult(info, started, args, undefined);\n return result;\n } catch (error) {\n captureResult(info, started, args, error);\n throw error;\n }\n };\n\n disposers.push(() => {\n target.client[method] = originalMethod;\n });\n }\n }\n\n return () => {\n if (disposed) return;\n disposed = true;\n for (const dispose of disposers) dispose();\n };\n },\n };\n}\n","import {\n queueIntegration,\n type QueueClientLike,\n type QueueIntegrationOptions,\n type QueueOperation,\n} from \"./queue-integration\";\n\nexport interface BullMqIntegrationOptions extends Omit<\n QueueIntegrationOptions,\n \"client\" | \"system\" | \"methods\" | \"getQueueName\"\n> {\n /**\n * Queue-like BullMQ object. By default LoggerJS wraps `add`, `addBulk`, and a\n * legacy `process` method when present; it does not hook `Worker` or\n * `QueueEvents` lifecycle events such as `completed`, `failed`, or `stalled`.\n */\n client: QueueClientLike & { name?: string };\n methods?: readonly string[];\n}\n\nconst bullMqMethods = [\"add\", \"addBulk\", \"process\"] as const;\n\nfunction queueName(args: readonly unknown[], fallback: string | undefined) {\n const first = args[0];\n return typeof first === \"string\" ? first : fallback;\n}\n\nfunction operationFor(method: string): QueueOperation {\n if (method === \"process\") return \"consume\";\n if (method === \"add\" || method === \"addBulk\") return \"publish\";\n return \"other\";\n}\n\nexport function bullMqIntegration(options: BullMqIntegrationOptions) {\n return queueIntegration({\n ...options,\n name: options.name ?? \"bullmq\",\n system: \"bullmq\",\n methods: options.methods ?? bullMqMethods,\n getOperation: options.getOperation ?? operationFor,\n queueName: options.queueName ?? options.client.name,\n getQueueName: (args) => queueName(args, options.queueName ?? options.client.name),\n });\n}\n"],"mappings":";;AAoDA,MAAM,iBAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AACA,MAAM,sBAAsB,KAAK,OAAO;AAExC,SAAS,a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,OAAO;EAC/C,eAAe,SAAS,UAAU,MAAM,QAAQ,aAAa,QAAQ,OAAO,IAAI;CAClF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"bullmq-integration.js","names":[],"sources":["../src/bullmq-integration.ts"],"sourcesContent":["import {\n queueIntegration,\n type QueueClientLike,\n type QueueIntegrationOptions,\n type QueueOperation,\n} from \"./queue-integration\";\n\nexport interface BullMqIntegrationOptions extends Omit<\n QueueIntegrationOptions,\n \"client\" | \"system\" | \"methods\" | \"getQueueName\"\n> {\n /**\n * Queue-like BullMQ object. By default LoggerJS wraps `add`, `addBulk`, and a\n * legacy `process` method when present; it does not hook `Worker` or\n * `QueueEvents` lifecycle events such as `completed`, `failed`, or `stalled`.\n */\n client: QueueClientLike & { name?: string };\n methods?: readonly string[];\n}\n\nconst bullMqMethods = [\"add\", \"addBulk\", \"process\"] as const;\n\nfunction queueName(args: readonly unknown[], fallback: string | undefined) {\n const first = args[0];\n return typeof first === \"string\" ? first : fallback;\n}\n\nfunction operationFor(method: string): QueueOperation {\n if (method === \"process\") return \"consume\";\n if (method === \"add\" || method === \"addBulk\") return \"publish\";\n return \"other\";\n}\n\nexport function bullMqIntegration(options: BullMqIntegrationOptions) {\n return queueIntegration({\n ...options,\n name: options.name ?? \"bullmq\",\n system: \"bullmq\",\n methods: options.methods ?? bullMqMethods,\n getOperation: options.getOperation ?? operationFor,\n queueName: options.queueName ?? options.client.name,\n getQueueName: (args) => queueName(args, options.queueName ?? options.client.name),\n });\n}\n"],"mappings":";;AAoBA,MAAM,gBAAgB;CAAC;CAAO;CAAW;AAAS;AAElD,SAAS,UAAU,MAA0B,UAA8B;CACzE,MAAM,QAAQ,KAAK;CACnB,OAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAEA,SAAS,aAAa,QAAgC;CACpD,IAAI,WAAW,WAAW,OAAO;CACjC,IAAI,WAAW,SAAS,WAAW,WAAW,OAAO;CACrD,OAAO;AACT;AAEA,SAAgB,kBAAkB,SAAmC;CACnE,OAAO,iBAAiB;EACtB,GAAG;EACH,MAAM,QAAQ,QAAQ;EACtB,QAAQ;EACR,SAAS,QAAQ,WAAW;EAC5B,cAAc,QAAQ,gBAAgB;EACtC,WAAW,QAAQ,aAAa,QAAQ,OAAO;EAC/C,eAAe,SAAS,UAAU,MAAM,QAAQ,aAAa,QAAQ,OAAO,IAAI;CAClF,CAAC;AACH"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
let fs = require("fs");
|
|
2
|
+
let path = require("path");
|
|
3
|
+
//#region src/node-destination.ts
|
|
4
|
+
const encoder = new TextEncoder();
|
|
5
|
+
const normalizeError = (error) => error instanceof Error ? error : new Error(String(error));
|
|
6
|
+
function byteLength(payload) {
|
|
7
|
+
return typeof payload === "string" ? encoder.encode(payload).byteLength : payload.byteLength;
|
|
8
|
+
}
|
|
9
|
+
function coalescePayloads(payloads) {
|
|
10
|
+
if (payloads.every((payload) => typeof payload === "string")) return payloads.join("");
|
|
11
|
+
const buffers = payloads.map((payload) => typeof payload === "string" ? Buffer.from(payload) : Buffer.from(payload));
|
|
12
|
+
return Buffer.concat(buffers);
|
|
13
|
+
}
|
|
14
|
+
function isEpipe(error) {
|
|
15
|
+
return Boolean(error) && typeof error === "object" && error.code === "EPIPE";
|
|
16
|
+
}
|
|
17
|
+
function normalizeMinLength(value) {
|
|
18
|
+
if (value === void 0 || !Number.isFinite(value) || value <= 0) return 0;
|
|
19
|
+
return Math.floor(value);
|
|
20
|
+
}
|
|
21
|
+
function createNodeStreamDestination(options) {
|
|
22
|
+
const minLength = normalizeMinLength(options.minLength);
|
|
23
|
+
const ignoreEpipe = options.ignoreEpipe ?? false;
|
|
24
|
+
const waiters = [];
|
|
25
|
+
const buffer = [];
|
|
26
|
+
const pendingPayloads = [];
|
|
27
|
+
let bufferedBytes = 0;
|
|
28
|
+
let pendingWrites = 0;
|
|
29
|
+
let pendingDrains = 0;
|
|
30
|
+
let lastError;
|
|
31
|
+
let lastContext;
|
|
32
|
+
let closed = false;
|
|
33
|
+
const reportInternalError = (error, operation) => {
|
|
34
|
+
if (ignoreEpipe && isEpipe(error)) return;
|
|
35
|
+
lastContext?.reportInternalError(error, {
|
|
36
|
+
phase: "transport",
|
|
37
|
+
transport: options.name,
|
|
38
|
+
operation
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
const settleWaitersIfIdle = () => {
|
|
42
|
+
if (pendingWrites + pendingDrains > 0) return;
|
|
43
|
+
if (waiters.length === 0) return;
|
|
44
|
+
const error = lastError;
|
|
45
|
+
lastError = void 0;
|
|
46
|
+
for (const waiter of waiters.splice(0)) if (error) waiter.reject(error);
|
|
47
|
+
else waiter.resolve();
|
|
48
|
+
};
|
|
49
|
+
const recordError = (error, operation) => {
|
|
50
|
+
if (ignoreEpipe && isEpipe(error)) {
|
|
51
|
+
closed = true;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
lastError = normalizeError(error);
|
|
55
|
+
reportInternalError(lastError, operation);
|
|
56
|
+
};
|
|
57
|
+
const releaseDrainsIfDestroyed = () => {
|
|
58
|
+
if (options.stream.destroyed) pendingDrains = 0;
|
|
59
|
+
};
|
|
60
|
+
const onStreamError = (error) => {
|
|
61
|
+
recordError(error, "stream-error");
|
|
62
|
+
releaseDrainsIfDestroyed();
|
|
63
|
+
settleWaitersIfIdle();
|
|
64
|
+
};
|
|
65
|
+
const offError = () => options.stream.off?.("error", onStreamError);
|
|
66
|
+
options.stream.on?.("error", onStreamError);
|
|
67
|
+
const waitForDrain = () => {
|
|
68
|
+
if (!options.stream.once || options.stream.destroyed) return;
|
|
69
|
+
pendingDrains += 1;
|
|
70
|
+
options.stream.once("drain", () => {
|
|
71
|
+
pendingDrains -= 1;
|
|
72
|
+
settleWaitersIfIdle();
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
const removePending = (payload) => {
|
|
76
|
+
const index = pendingPayloads.indexOf(payload);
|
|
77
|
+
if (index >= 0) pendingPayloads.splice(index, 1);
|
|
78
|
+
};
|
|
79
|
+
const writeNow = (payload) => {
|
|
80
|
+
if (closed) return;
|
|
81
|
+
pendingPayloads.push(payload);
|
|
82
|
+
pendingWrites += 1;
|
|
83
|
+
try {
|
|
84
|
+
if (options.stream.write(payload, (error) => {
|
|
85
|
+
removePending(payload);
|
|
86
|
+
pendingWrites -= 1;
|
|
87
|
+
if (error) recordError(error, options.reportOperation ?? "write");
|
|
88
|
+
releaseDrainsIfDestroyed();
|
|
89
|
+
settleWaitersIfIdle();
|
|
90
|
+
}) === false) waitForDrain();
|
|
91
|
+
} catch (error) {
|
|
92
|
+
removePending(payload);
|
|
93
|
+
pendingWrites -= 1;
|
|
94
|
+
recordError(error, options.reportOperation ?? "write");
|
|
95
|
+
settleWaitersIfIdle();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const flushBuffered = () => {
|
|
99
|
+
if (buffer.length === 0) return;
|
|
100
|
+
const payload = coalescePayloads(buffer.splice(0));
|
|
101
|
+
bufferedBytes = 0;
|
|
102
|
+
writeNow(payload);
|
|
103
|
+
};
|
|
104
|
+
const destination = {
|
|
105
|
+
write(payload, context) {
|
|
106
|
+
if (closed) return;
|
|
107
|
+
lastContext = context;
|
|
108
|
+
if (minLength > 0) {
|
|
109
|
+
buffer.push(payload);
|
|
110
|
+
bufferedBytes += byteLength(payload);
|
|
111
|
+
if (bufferedBytes >= minLength) flushBuffered();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
writeNow(payload);
|
|
115
|
+
},
|
|
116
|
+
flush() {
|
|
117
|
+
flushBuffered();
|
|
118
|
+
releaseDrainsIfDestroyed();
|
|
119
|
+
if (pendingWrites + pendingDrains === 0) {
|
|
120
|
+
const error = lastError;
|
|
121
|
+
lastError = void 0;
|
|
122
|
+
if (error) return Promise.reject(error);
|
|
123
|
+
return Promise.resolve();
|
|
124
|
+
}
|
|
125
|
+
return new Promise((resolve, reject) => {
|
|
126
|
+
waiters.push({
|
|
127
|
+
resolve,
|
|
128
|
+
reject
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
flushSync() {
|
|
133
|
+
if (!options.syncWrite) {
|
|
134
|
+
flushBuffered();
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
for (const payload of buffer.splice(0)) options.syncWrite(payload);
|
|
138
|
+
bufferedBytes = 0;
|
|
139
|
+
for (const payload of pendingPayloads.splice(0)) options.syncWrite(payload);
|
|
140
|
+
},
|
|
141
|
+
close() {
|
|
142
|
+
return destination.flush().then(() => new Promise((resolve, reject) => {
|
|
143
|
+
if (!options.stream.end) {
|
|
144
|
+
closed = true;
|
|
145
|
+
offError();
|
|
146
|
+
resolve();
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
options.stream.end((error) => {
|
|
150
|
+
closed = true;
|
|
151
|
+
offError();
|
|
152
|
+
if (error && !(ignoreEpipe && isEpipe(error))) reject(error);
|
|
153
|
+
else resolve();
|
|
154
|
+
});
|
|
155
|
+
}), (error) => {
|
|
156
|
+
offError();
|
|
157
|
+
return Promise.reject(error);
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
closeSync() {
|
|
161
|
+
destination.flushSync();
|
|
162
|
+
closed = true;
|
|
163
|
+
offError();
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
return destination;
|
|
167
|
+
}
|
|
168
|
+
function createNodeFileDestination(options) {
|
|
169
|
+
const flags = options.flags ?? (options.append === false ? "w" : "a");
|
|
170
|
+
if (options.mkdir) (0, fs.mkdirSync)((0, path.dirname)(options.path), { recursive: true });
|
|
171
|
+
let fd;
|
|
172
|
+
let syncFlags = options.sync ? flags : "a";
|
|
173
|
+
const getFd = () => {
|
|
174
|
+
if (fd === void 0) {
|
|
175
|
+
fd = (0, fs.openSync)(options.path, syncFlags);
|
|
176
|
+
syncFlags = "a";
|
|
177
|
+
}
|
|
178
|
+
return fd;
|
|
179
|
+
};
|
|
180
|
+
const syncWrite = (payload) => {
|
|
181
|
+
if (typeof payload === "string") (0, fs.writeSync)(getFd(), payload);
|
|
182
|
+
else (0, fs.writeSync)(getFd(), payload);
|
|
183
|
+
};
|
|
184
|
+
if (options.sync) {
|
|
185
|
+
let closed = false;
|
|
186
|
+
const releaseSync = () => {
|
|
187
|
+
if (fd !== void 0) {
|
|
188
|
+
(0, fs.closeSync)(fd);
|
|
189
|
+
fd = void 0;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
return {
|
|
193
|
+
write(payload) {
|
|
194
|
+
if (closed) return;
|
|
195
|
+
syncWrite(payload);
|
|
196
|
+
},
|
|
197
|
+
flush() {
|
|
198
|
+
return Promise.resolve();
|
|
199
|
+
},
|
|
200
|
+
flushSync() {},
|
|
201
|
+
close() {
|
|
202
|
+
releaseSync();
|
|
203
|
+
closed = true;
|
|
204
|
+
return Promise.resolve();
|
|
205
|
+
},
|
|
206
|
+
closeSync() {
|
|
207
|
+
releaseSync();
|
|
208
|
+
closed = true;
|
|
209
|
+
},
|
|
210
|
+
releaseSync
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const stream = (0, fs.createWriteStream)(options.path, { flags });
|
|
214
|
+
stream.on("error", () => {});
|
|
215
|
+
const destination = createNodeStreamDestination({
|
|
216
|
+
name: options.name,
|
|
217
|
+
stream,
|
|
218
|
+
minLength: options.minLength,
|
|
219
|
+
syncWrite
|
|
220
|
+
});
|
|
221
|
+
const releaseSync = () => {
|
|
222
|
+
if (fd !== void 0) {
|
|
223
|
+
(0, fs.closeSync)(fd);
|
|
224
|
+
fd = void 0;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
return {
|
|
228
|
+
...destination,
|
|
229
|
+
stream,
|
|
230
|
+
close() {
|
|
231
|
+
return destination.close().finally(releaseSync);
|
|
232
|
+
},
|
|
233
|
+
closeSync() {
|
|
234
|
+
destination.closeSync();
|
|
235
|
+
releaseSync();
|
|
236
|
+
},
|
|
237
|
+
releaseSync
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
//#endregion
|
|
241
|
+
Object.defineProperty(exports, "createNodeFileDestination", {
|
|
242
|
+
enumerable: true,
|
|
243
|
+
get: function() {
|
|
244
|
+
return createNodeFileDestination;
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
Object.defineProperty(exports, "createNodeStreamDestination", {
|
|
248
|
+
enumerable: true,
|
|
249
|
+
get: function() {
|
|
250
|
+
return createNodeStreamDestination;
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
//# sourceMappingURL=node-destination-DvP8jBvm.cjs.map
|