@vaultgradient/pipequery-cli 0.13.3 → 0.14.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/__tests__/event-log.test.ts +2 -3
- package/dist/index.js +7 -2
- package/package.json +1 -1
- package/src/telegram/event-log.ts +10 -5
|
@@ -213,8 +213,7 @@ describe('createEventLogger — JSONL file output', () => {
|
|
|
213
213
|
];
|
|
214
214
|
for (const e of events) logger.log(e);
|
|
215
215
|
|
|
216
|
-
|
|
217
|
-
await new Promise((r) => setTimeout(r, 50));
|
|
216
|
+
await logger.flush();
|
|
218
217
|
const content = await readFile(file, 'utf8');
|
|
219
218
|
const lines = content.trim().split('\n');
|
|
220
219
|
expect(lines).toHaveLength(3);
|
|
@@ -258,7 +257,7 @@ describe('createEventLogger — JSONL file output', () => {
|
|
|
258
257
|
now: () => FIXED_TS,
|
|
259
258
|
});
|
|
260
259
|
logger.log({ kind: 'command', user: { id: 1 }, cmd: '/help', outcome: 'success', latencyMs: 1 });
|
|
261
|
-
await
|
|
260
|
+
await logger.flush();
|
|
262
261
|
const obj = JSON.parse((await readFile(file, 'utf8')).trim()) as Record<string, unknown>;
|
|
263
262
|
expect(obj.rowCount).toBeUndefined();
|
|
264
263
|
expect(obj.error).toBeUndefined();
|
package/dist/index.js
CHANGED
|
@@ -4577,7 +4577,7 @@ import chalk3 from "chalk";
|
|
|
4577
4577
|
// package.json
|
|
4578
4578
|
var package_default = {
|
|
4579
4579
|
name: "@andreadito/pq",
|
|
4580
|
-
version: "0.
|
|
4580
|
+
version: "0.14.0",
|
|
4581
4581
|
description: "CLI for PipeQuery \u2014 data sources, aggregations, APIs, and terminal dashboards",
|
|
4582
4582
|
type: "module",
|
|
4583
4583
|
bin: {
|
|
@@ -7419,13 +7419,17 @@ function createEventLogger(opts = {}) {
|
|
|
7419
7419
|
const writeStderr = opts.writeStderr ?? ((line) => process.stderr.write(line));
|
|
7420
7420
|
const now = opts.now ?? (() => /* @__PURE__ */ new Date());
|
|
7421
7421
|
const filePath = opts.filePath;
|
|
7422
|
+
let chain = Promise.resolve();
|
|
7422
7423
|
return {
|
|
7423
7424
|
log(event) {
|
|
7424
7425
|
const ts = now();
|
|
7425
7426
|
writeStderr(formatPretty(event, ts) + "\n");
|
|
7426
7427
|
if (filePath) {
|
|
7427
7428
|
const json = JSON.stringify({ ts: ts.toISOString(), ...flattenForJson(event) });
|
|
7428
|
-
|
|
7429
|
+
chain = chain.then(
|
|
7430
|
+
() => appendFile(filePath, json + "\n"),
|
|
7431
|
+
() => appendFile(filePath, json + "\n")
|
|
7432
|
+
).catch((err) => {
|
|
7429
7433
|
writeStderr(
|
|
7430
7434
|
chalk7.hex("#ef4444")(" \u2717") + " [pipequery-telegram] log-file write failed: " + (err instanceof Error ? err.message : String(err)) + "\n"
|
|
7431
7435
|
);
|
|
@@ -7433,6 +7437,7 @@ function createEventLogger(opts = {}) {
|
|
|
7433
7437
|
}
|
|
7434
7438
|
},
|
|
7435
7439
|
async flush() {
|
|
7440
|
+
await chain;
|
|
7436
7441
|
}
|
|
7437
7442
|
};
|
|
7438
7443
|
}
|
package/package.json
CHANGED
|
@@ -83,6 +83,8 @@ export function createEventLogger(opts: EventLoggerOptions = {}): EventLogger {
|
|
|
83
83
|
const writeStderr = opts.writeStderr ?? ((line) => process.stderr.write(line));
|
|
84
84
|
const now = opts.now ?? (() => new Date());
|
|
85
85
|
const filePath = opts.filePath;
|
|
86
|
+
// Chain writes sequentially so they land on disk in log-order.
|
|
87
|
+
let chain: Promise<void> = Promise.resolve();
|
|
86
88
|
|
|
87
89
|
return {
|
|
88
90
|
log(event: BotEvent): void {
|
|
@@ -90,10 +92,13 @@ export function createEventLogger(opts: EventLoggerOptions = {}): EventLogger {
|
|
|
90
92
|
writeStderr(formatPretty(event, ts) + '\n');
|
|
91
93
|
if (filePath) {
|
|
92
94
|
const json = JSON.stringify({ ts: ts.toISOString(), ...flattenForJson(event) });
|
|
93
|
-
//
|
|
94
|
-
// doesn't
|
|
95
|
-
//
|
|
96
|
-
|
|
95
|
+
// Chain each append onto the previous one so ordering is preserved.
|
|
96
|
+
// The bot doesn't await the chain — a slow disk won't back-pressure
|
|
97
|
+
// incoming Telegram messages. Errors surface on stderr.
|
|
98
|
+
chain = chain.then(
|
|
99
|
+
() => appendFile(filePath, json + '\n'),
|
|
100
|
+
() => appendFile(filePath, json + '\n'),
|
|
101
|
+
).catch((err) => {
|
|
97
102
|
writeStderr(
|
|
98
103
|
chalk.hex('#ef4444')(' ✗') +
|
|
99
104
|
' [pipequery-telegram] log-file write failed: ' +
|
|
@@ -104,7 +109,7 @@ export function createEventLogger(opts: EventLoggerOptions = {}): EventLogger {
|
|
|
104
109
|
}
|
|
105
110
|
},
|
|
106
111
|
async flush(): Promise<void> {
|
|
107
|
-
|
|
112
|
+
await chain;
|
|
108
113
|
},
|
|
109
114
|
};
|
|
110
115
|
}
|