@reqray/transport-file 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ruslan Kryklyvyi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,56 @@
1
- # Temporary Holding Version
1
+ # @reqray/transport-file
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Reqray's request log on disk: every recorded request as one line of JSON, a
4
+ file per day. A database is what the panel reads; this is what `grep` reads,
5
+ what `tail -f` follows and what a log shipper picks up.
6
+
7
+ Part of [Reqray](https://github.com/reqray/reqray) — a dev panel and request inspector for Node.js. It
8
+ instruments HTTP, SQL, outgoing calls and cache on its own, shows every
9
+ request as a waterfall, and finds N+1 down to the file and the line.
10
+
11
+ ## Use
12
+
13
+ ```bash
14
+ npm install @reqray/transport-file
15
+ ```
16
+
17
+ ```js
18
+ import { fileTransport, retentionPolicy } from '@reqray/transport-file';
19
+ import { sqliteTransport } from '@reqray/store-sqlite';
20
+
21
+ const retention = retentionPolicy({ days: 7, file: '.reqray/retention.json' });
22
+
23
+ await app.register(reqray, {
24
+ retention,
25
+ transport: [
26
+ sqliteTransport({ file: '.reqray/requests.db', retention }),
27
+ fileTransport({ dir: '.reqray/log', retention }),
28
+ ],
29
+ });
30
+ ```
31
+
32
+ Writing is streamed and never on the request path. A write that fails takes
33
+ the log down and nothing else; a log that falls behind the application drops
34
+ lines and counts them rather than growing the heap.
35
+
36
+ ## Options
37
+
38
+ | Option | Default | |
39
+ |---|---|---|
40
+ | `dir` | required | Directory the daily files go to |
41
+ | `retention` | none | A shared `retentionPolicy`, so the log and the store evict by one number |
42
+ | `days` | none | How many days of files to keep, when no shared policy is given |
43
+ | `maxBytes` | none | Total size of the log on disk |
44
+
45
+ On the collector it is two variables: `REQRAY_LOG=/var/lib/reqray/log` and
46
+ `REQRAY_DAYS=7`.
47
+
48
+ ## More
49
+
50
+ Everything else — the detectors, security defaults, measured overhead and a
51
+ demo that runs with one command — is in the
52
+ [main README](https://github.com/reqray/reqray#readme).
53
+
54
+ ## License
55
+
56
+ [MIT](https://github.com/reqray/reqray/blob/main/LICENSE)
package/dist/index.cjs ADDED
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ dayOf: () => dayOf,
24
+ fileTransport: () => fileTransport,
25
+ midnightOf: () => midnightOf,
26
+ retentionPolicy: () => import_core2.retentionPolicy
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+ var import_node_fs = require("fs");
30
+ var import_node_path = require("path");
31
+ var import_core = require("@reqray/core");
32
+ var import_core2 = require("@reqray/core");
33
+ var DEFAULT_DAYS = 7;
34
+ var DEFAULT_MAX_BYTES = 512 * 1024 * 1024;
35
+ var DEFAULT_PREFIX = "requests";
36
+ var DEFAULT_PENDING = 8 * 1024 * 1024;
37
+ var SWEEP_EVERY_MS = 6e4;
38
+ function dayOf(at) {
39
+ const date = new Date(at);
40
+ const two = (value) => String(value).padStart(2, "0");
41
+ return `${date.getFullYear()}-${two(date.getMonth() + 1)}-${two(date.getDate())}`;
42
+ }
43
+ function midnightOf(day) {
44
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(day);
45
+ if (!match) return null;
46
+ const [, year, month, date] = match;
47
+ return new Date(Number(year), Number(month) - 1, Number(date)).getTime();
48
+ }
49
+ function fileTransport(options) {
50
+ const dir = options.dir;
51
+ const prefix = options.prefix ?? DEFAULT_PREFIX;
52
+ const maxPending = options.maxPendingBytes ?? DEFAULT_PENDING;
53
+ const clock = options.now ?? Date.now;
54
+ const own = {
55
+ days: options.days === void 0 ? DEFAULT_DAYS : options.days,
56
+ maxBytes: options.maxBytes === void 0 ? DEFAULT_MAX_BYTES : options.maxBytes,
57
+ maxRequests: null
58
+ };
59
+ const limits = () => {
60
+ const shared = options.retention?.current();
61
+ return shared ? { ...shared, maxBytes: shared.maxBytes ?? own.maxBytes } : own;
62
+ };
63
+ let stream = null;
64
+ let openDay = "";
65
+ let written = 0;
66
+ let dropped = 0;
67
+ let writing = true;
68
+ let sweptAt = 0;
69
+ const fileFor = (day) => (0, import_node_path.join)(dir, `${prefix}-${day}.jsonl`);
70
+ const stop = (reason) => {
71
+ writing = false;
72
+ stream?.destroy();
73
+ stream = null;
74
+ (0, import_core.warnOnce)("log.write", `the request log is off: ${reason}`);
75
+ };
76
+ function open(day) {
77
+ try {
78
+ (0, import_node_fs.mkdirSync)(dir, { recursive: true });
79
+ const path = fileFor(day);
80
+ const fd = (0, import_node_fs.openSync)(path, "a");
81
+ const next = (0, import_node_fs.createWriteStream)(path, { fd, flags: "a" });
82
+ next.on("error", (error) => stop(error.message));
83
+ stream?.end();
84
+ stream = next;
85
+ openDay = day;
86
+ } catch (error) {
87
+ stop(error instanceof Error ? error.message : String(error));
88
+ }
89
+ }
90
+ function files() {
91
+ let names;
92
+ try {
93
+ names = (0, import_node_fs.readdirSync)(dir);
94
+ } catch {
95
+ return [];
96
+ }
97
+ const found = [];
98
+ for (const name of names) {
99
+ const match = new RegExp(`^${prefix}-(\\d{4}-\\d{2}-\\d{2})\\.jsonl$`).exec(name);
100
+ const day = match?.[1];
101
+ const at = day ? midnightOf(day) : null;
102
+ if (!day || at === null) continue;
103
+ const path = (0, import_node_path.join)(dir, name);
104
+ const size = (0, import_node_fs.statSync)(path, { throwIfNoEntry: false })?.size;
105
+ if (size === void 0) continue;
106
+ found.push({ path, day, at, bytes: size });
107
+ }
108
+ return found.sort((a, b) => a.at - b.at);
109
+ }
110
+ function sweep(now = clock()) {
111
+ sweptAt = now;
112
+ const { days, maxBytes } = limits();
113
+ const cutoff = (0, import_core.cutoffOf)({ days, maxBytes, maxRequests: null }, now);
114
+ let removed = 0;
115
+ let bytesFreed = 0;
116
+ const remaining = files();
117
+ const drop = (index) => {
118
+ const entry = remaining[index];
119
+ if (!entry) return;
120
+ try {
121
+ (0, import_node_fs.unlinkSync)(entry.path);
122
+ removed++;
123
+ bytesFreed += entry.bytes;
124
+ remaining.splice(index, 1);
125
+ } catch (error) {
126
+ const reason = error instanceof Error ? error.message : String(error);
127
+ (0, import_core.warnOnce)("log.sweep", `a log file could not be removed (${entry.path}): ${reason}`);
128
+ remaining.splice(index, 1);
129
+ }
130
+ };
131
+ if (cutoff !== null) {
132
+ for (let index = remaining.length - 1; index >= 0; index--) {
133
+ const entry = remaining[index];
134
+ if (entry && entry.at + import_core.DAY_MS <= cutoff) drop(index);
135
+ }
136
+ }
137
+ if (maxBytes !== null) {
138
+ let total = remaining.reduce((sum, entry) => sum + entry.bytes, 0);
139
+ while (total > maxBytes && remaining.length > 1) {
140
+ const oldest = remaining[0];
141
+ if (!oldest) break;
142
+ total -= oldest.bytes;
143
+ drop(0);
144
+ }
145
+ if (total > maxBytes) {
146
+ (0, import_core.warnOnce)(
147
+ "log.size",
148
+ `today's log file alone is over the ${maxBytes} byte limit; nothing older is left to remove`
149
+ );
150
+ }
151
+ }
152
+ return { removed, bytesFreed };
153
+ }
154
+ sweep();
155
+ options.retention?.subscribe(() => void sweep());
156
+ return {
157
+ name: "file",
158
+ dir,
159
+ send(request) {
160
+ if (!writing) return;
161
+ const now = clock();
162
+ const day = dayOf(now);
163
+ if (day !== openDay) {
164
+ open(day);
165
+ sweep(now);
166
+ } else if (now - sweptAt > SWEEP_EVERY_MS) {
167
+ sweep(now);
168
+ }
169
+ if (!stream) return;
170
+ let line;
171
+ try {
172
+ line = `${JSON.stringify(request)}
173
+ `;
174
+ } catch (error) {
175
+ const reason = error instanceof Error ? error.message : String(error);
176
+ (0, import_core.warnOnce)("log.serialize", `a request could not be written to the log: ${reason}`);
177
+ return;
178
+ }
179
+ if (stream.writableLength > maxPending) {
180
+ dropped++;
181
+ (0, import_core.warnOnce)(
182
+ "log.behind",
183
+ "the request log is behind the application and lines are being dropped"
184
+ );
185
+ return;
186
+ }
187
+ stream.write(line);
188
+ written++;
189
+ },
190
+ stats() {
191
+ const all = files();
192
+ return {
193
+ files: all.length,
194
+ bytes: all.reduce((sum, entry) => sum + entry.bytes, 0),
195
+ oldestAt: all[0]?.at ?? null,
196
+ written,
197
+ dropped,
198
+ writing
199
+ };
200
+ },
201
+ sweep,
202
+ async flush() {
203
+ const open2 = stream;
204
+ if (!open2) return;
205
+ await new Promise((resolve) => {
206
+ open2.write("", () => resolve());
207
+ });
208
+ },
209
+ async close() {
210
+ const open2 = stream;
211
+ stream = null;
212
+ if (!open2) return;
213
+ await new Promise((resolve) => {
214
+ open2.end(() => resolve());
215
+ open2.once("error", (error) => {
216
+ (0, import_core.warn)(`the request log did not close cleanly: ${error.message}`);
217
+ resolve();
218
+ });
219
+ });
220
+ }
221
+ };
222
+ }
223
+ // Annotate the CommonJS export names for ESM import in node:
224
+ 0 && (module.exports = {
225
+ dayOf,
226
+ fileTransport,
227
+ midnightOf,
228
+ retentionPolicy
229
+ });
230
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@reqray/transport-file` — the request log on disk.\n *\n * One line of JSON per recorded request, in a file per day. Not a store: the\n * panel never reads it. It is what a store on disk cannot be — something\n * `grep` understands, `tail -f` follows, a log shipper picks up and an\n * operator copies off the machine after the container is gone.\n *\n * It runs beside a store rather than instead of one:\n *\n * ```js\n * const retention = retentionPolicy({ days: 7, file: '.reqray/retention.json' });\n * reqray({\n * retention,\n * transport: [\n * sqliteTransport({ file: '.reqray/requests.db', retention }),\n * fileTransport({ dir: '.reqray/log', retention }),\n * ],\n * });\n * ```\n *\n * Writing is off the hot path — `send` is called after the response — but it\n * is still someone's process: writes are streamed, a write that fails takes\n * the log down and nothing else, and a queue that grows past its cap drops\n * lines and says how many rather than eating the heap.\n */\n\nimport {\n createWriteStream,\n mkdirSync,\n openSync,\n readdirSync,\n statSync,\n unlinkSync,\n type WriteStream,\n} from 'node:fs';\nimport { join } from 'node:path';\nimport {\n cutoffOf,\n DAY_MS,\n type RetentionPolicy,\n type Transport,\n warn,\n warnOnce,\n} from '@reqray/core';\nimport type { RecordedRequest, RetentionLimits } from '@reqray/protocol';\n\n/** Options for {@link fileTransport}. */\nexport interface FileTransportOptions {\n /** Directory the log files live in. Created if it is not there. */\n readonly dir: string;\n /**\n * The retention policy, shared with the store.\n *\n * Without one the limits below apply and nothing can change them from the\n * panel.\n */\n readonly retention?: RetentionPolicy;\n /** How many days of log to keep, when no policy says otherwise. */\n readonly days?: number | null;\n /** How much disk the log may take, when no policy says otherwise. */\n readonly maxBytes?: number | null;\n /** File name prefix; the date and `.jsonl` follow it. */\n readonly prefix?: string;\n /**\n * How much may wait in memory for the disk, bytes.\n *\n * Past this, lines are dropped and counted. A log is worth less than the\n * application it is a log of.\n */\n readonly maxPendingBytes?: number;\n /**\n * What time it is.\n *\n * Only tests pass this: rotation happens at midnight, and waiting for one\n * is not a test.\n */\n readonly now?: () => number;\n}\n\n/** What the log holds right now. */\nexport interface FileLogStats {\n readonly files: number;\n /** How much disk they take. */\n readonly bytes: number;\n /** The day of the oldest file, epoch ms at local midnight. `null` if empty. */\n readonly oldestAt: number | null;\n /** How many requests this process has written. */\n readonly written: number;\n /** How many it had to drop because the disk could not keep up. */\n readonly dropped: number;\n /** `false` once a write has failed: the log is off, the application is not. */\n readonly writing: boolean;\n}\n\n/** What was removed by one sweep. */\nexport interface SweepResult {\n readonly removed: number;\n readonly bytesFreed: number;\n}\n\n/** A transport that writes a log and answers questions about it. */\nexport interface FileLog extends Transport {\n readonly dir: string;\n stats(): FileLogStats;\n /** Applies the retention limits now. Called on rotation and on a timer. */\n sweep(now?: number): SweepResult;\n flush(): Promise<void>;\n close(): Promise<void>;\n}\n\n/** A week of history: long enough for \"what happened yesterday\". */\nconst DEFAULT_DAYS = 7;\n/** Half a gigabyte, the same order as the SQLite store's own cap. */\nconst DEFAULT_MAX_BYTES = 512 * 1024 * 1024;\nconst DEFAULT_PREFIX = 'requests';\nconst DEFAULT_PENDING = 8 * 1024 * 1024;\n/** How often a sweep may run while writing. */\nconst SWEEP_EVERY_MS = 60_000;\n\n/** The local day a moment falls in, as `2026-08-20`. */\nexport function dayOf(at: number): string {\n const date = new Date(at);\n const two = (value: number) => String(value).padStart(2, '0');\n return `${date.getFullYear()}-${two(date.getMonth() + 1)}-${two(date.getDate())}`;\n}\n\n/** Local midnight of a day named the way {@link dayOf} names it. */\nexport function midnightOf(day: string): number | null {\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(day);\n if (!match) return null;\n const [, year, month, date] = match;\n return new Date(Number(year), Number(month) - 1, Number(date)).getTime();\n}\n\nexport function fileTransport(options: FileTransportOptions): FileLog {\n const dir = options.dir;\n const prefix = options.prefix ?? DEFAULT_PREFIX;\n const maxPending = options.maxPendingBytes ?? DEFAULT_PENDING;\n const clock = options.now ?? Date.now;\n const own: RetentionLimits = {\n days: options.days === undefined ? DEFAULT_DAYS : options.days,\n maxBytes: options.maxBytes === undefined ? DEFAULT_MAX_BYTES : options.maxBytes,\n maxRequests: null,\n };\n\n /**\n * The limits in force: the shared policy if there is one, ours otherwise.\n *\n * A policy that says nothing about size leaves this log's own cap standing,\n * the way the SQLite store reads the same policy. `{ days: 7 }` is what\n * most people write, and it must not mean \"and as many bytes as the disk\n * has\".\n */\n const limits = (): RetentionLimits => {\n const shared = options.retention?.current();\n return shared ? { ...shared, maxBytes: shared.maxBytes ?? own.maxBytes } : own;\n };\n\n let stream: WriteStream | null = null;\n let openDay = '';\n let written = 0;\n let dropped = 0;\n let writing = true;\n let sweptAt = 0;\n\n const fileFor = (day: string) => join(dir, `${prefix}-${day}.jsonl`);\n\n const stop = (reason: string): void => {\n writing = false;\n stream?.destroy();\n stream = null;\n warnOnce('log.write', `the request log is off: ${reason}`);\n };\n\n function open(day: string): void {\n try {\n mkdirSync(dir, { recursive: true });\n // The descriptor is opened here rather than by the stream, which opens\n // on a later tick. Two things go wrong with a late open: the file is\n // not there to be swept or counted until it happens, and an open that\n // lands after a sweep has removed the name creates the file again —\n // yesterday's log, resurrected empty.\n const path = fileFor(day);\n const fd = openSync(path, 'a');\n const next = createWriteStream(path, { fd, flags: 'a' });\n next.on('error', (error) => stop(error.message));\n stream?.end();\n stream = next;\n openDay = day;\n } catch (error) {\n stop(error instanceof Error ? error.message : String(error));\n }\n }\n\n /** Every log file this directory holds, oldest first. */\n function files(): Array<{ path: string; day: string; at: number; bytes: number }> {\n let names: string[];\n try {\n names = readdirSync(dir);\n } catch {\n return [];\n }\n\n const found: Array<{ path: string; day: string; at: number; bytes: number }> = [];\n for (const name of names) {\n const match = new RegExp(`^${prefix}-(\\\\d{4}-\\\\d{2}-\\\\d{2})\\\\.jsonl$`).exec(name);\n const day = match?.[1];\n const at = day ? midnightOf(day) : null;\n if (!day || at === null) continue;\n const path = join(dir, name);\n const size = statSync(path, { throwIfNoEntry: false })?.size;\n if (size === undefined) continue;\n found.push({ path, day, at, bytes: size });\n }\n return found.sort((a, b) => a.at - b.at);\n }\n\n function sweep(now = clock()): SweepResult {\n sweptAt = now;\n const { days, maxBytes } = limits();\n const cutoff = cutoffOf({ days, maxBytes, maxRequests: null }, now);\n let removed = 0;\n let bytesFreed = 0;\n\n const remaining = files();\n const drop = (index: number): void => {\n const entry = remaining[index];\n if (!entry) return;\n try {\n unlinkSync(entry.path);\n removed++;\n bytesFreed += entry.bytes;\n remaining.splice(index, 1);\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n warnOnce('log.sweep', `a log file could not be removed (${entry.path}): ${reason}`);\n remaining.splice(index, 1);\n }\n };\n\n // By age first. A day's file is only past the cutoff once the whole day\n // is: a file named for today holds requests from a minute ago.\n if (cutoff !== null) {\n for (let index = remaining.length - 1; index >= 0; index--) {\n const entry = remaining[index];\n if (entry && entry.at + DAY_MS <= cutoff) drop(index);\n }\n }\n\n // Then by size, oldest first — and never the file being written to, which\n // is the only one that would take the current day's requests with it.\n if (maxBytes !== null) {\n let total = remaining.reduce((sum, entry) => sum + entry.bytes, 0);\n while (total > maxBytes && remaining.length > 1) {\n const oldest = remaining[0];\n if (!oldest) break;\n total -= oldest.bytes;\n drop(0);\n }\n if (total > maxBytes) {\n warnOnce(\n 'log.size',\n `today's log file alone is over the ${maxBytes} byte limit; nothing older is left to remove`,\n );\n }\n }\n\n return { removed, bytesFreed };\n }\n\n // Old files are swept at startup too: an application that starts and gets no\n // traffic still has yesterday's limits to honour.\n sweep();\n options.retention?.subscribe(() => void sweep());\n\n return {\n name: 'file',\n dir,\n\n send(request: RecordedRequest) {\n if (!writing) return;\n\n const now = clock();\n const day = dayOf(now);\n if (day !== openDay) {\n open(day);\n sweep(now);\n } else if (now - sweptAt > SWEEP_EVERY_MS) {\n sweep(now);\n }\n if (!stream) return;\n\n let line: string;\n try {\n line = `${JSON.stringify(request)}\\n`;\n } catch (error) {\n // A record that will not serialize is one record, not a reason to stop.\n const reason = error instanceof Error ? error.message : String(error);\n warnOnce('log.serialize', `a request could not be written to the log: ${reason}`);\n return;\n }\n\n // What the stream still owes the disk, asked of the stream itself: a\n // count of refused writes would miss the case where nothing has been\n // refused yet and megabytes are already queued.\n if (stream.writableLength > maxPending) {\n dropped++;\n warnOnce(\n 'log.behind',\n 'the request log is behind the application and lines are being dropped',\n );\n return;\n }\n\n stream.write(line);\n written++;\n },\n\n stats(): FileLogStats {\n const all = files();\n return {\n files: all.length,\n bytes: all.reduce((sum, entry) => sum + entry.bytes, 0),\n oldestAt: all[0]?.at ?? null,\n written,\n dropped,\n writing,\n };\n },\n\n sweep,\n\n async flush() {\n const open = stream;\n if (!open) return;\n // An empty write with a callback: `drain` only ever fires after a write\n // that was refused, so waiting for one is how a flush hangs forever.\n await new Promise<void>((resolve) => {\n open.write('', () => resolve());\n });\n },\n\n async close() {\n const open = stream;\n stream = null;\n if (!open) return;\n await new Promise<void>((resolve) => {\n open.end(() => resolve());\n open.once('error', (error) => {\n warn(`the request log did not close cleanly: ${error.message}`);\n resolve();\n });\n });\n },\n };\n}\n\n/**\n * The retention policy, re-exported.\n *\n * Anyone keeping requests on disk installs this package; making them add\n * `@reqray/core` as well to say how long to keep them would be a dependency\n * for one function. It is the same object either way.\n */\nexport {\n type RetentionLimits,\n type RetentionOptions,\n type RetentionPolicy,\n retentionPolicy,\n} from '@reqray/core';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2BA,qBAQO;AACP,uBAAqB;AACrB,kBAOO;AAiUP,IAAAA,eAKO;AAlQP,IAAM,eAAe;AAErB,IAAM,oBAAoB,MAAM,OAAO;AACvC,IAAM,iBAAiB;AACvB,IAAM,kBAAkB,IAAI,OAAO;AAEnC,IAAM,iBAAiB;AAGhB,SAAS,MAAM,IAAoB;AACxC,QAAM,OAAO,IAAI,KAAK,EAAE;AACxB,QAAM,MAAM,CAAC,UAAkB,OAAO,KAAK,EAAE,SAAS,GAAG,GAAG;AAC5D,SAAO,GAAG,KAAK,YAAY,CAAC,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,CAAC,IAAI,IAAI,KAAK,QAAQ,CAAC,CAAC;AACjF;AAGO,SAAS,WAAW,KAA4B;AACrD,QAAM,QAAQ,4BAA4B,KAAK,GAAG;AAClD,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,CAAC,EAAE,MAAM,OAAO,IAAI,IAAI;AAC9B,SAAO,IAAI,KAAK,OAAO,IAAI,GAAG,OAAO,KAAK,IAAI,GAAG,OAAO,IAAI,CAAC,EAAE,QAAQ;AACzE;AAEO,SAAS,cAAc,SAAwC;AACpE,QAAM,MAAM,QAAQ;AACpB,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,aAAa,QAAQ,mBAAmB;AAC9C,QAAM,QAAQ,QAAQ,OAAO,KAAK;AAClC,QAAM,MAAuB;AAAA,IAC3B,MAAM,QAAQ,SAAS,SAAY,eAAe,QAAQ;AAAA,IAC1D,UAAU,QAAQ,aAAa,SAAY,oBAAoB,QAAQ;AAAA,IACvE,aAAa;AAAA,EACf;AAUA,QAAM,SAAS,MAA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,IAAI,QAAc,CAAC,YAAY;AACnC,QAAAA,MAAK,MAAM,IAAI,MAAM,QAAQ,CAAC;AAAA,MAChC,CAAC;AAAA,IACH;AAAA,IAEA,MAAM,QAAQ;AACZ,YAAMA,QAAO;AACb,eAAS;AACT,UAAI,CAACA,MAAM;AACX,YAAM,IAAI,QAAc,CAAC,YAAY;AACnC,QAAAA,MAAK,IAAI,MAAM,QAAQ,CAAC;AACxB,QAAAA,MAAK,KAAK,SAAS,CAAC,UAAU;AAC5B,gCAAK,0CAA0C,MAAM,OAAO,EAAE;AAC9D,kBAAQ;AAAA,QACV,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["import_core","open"]}
@@ -0,0 +1,97 @@
1
+ import { Transport, RetentionPolicy } from '@reqray/core';
2
+ export { RetentionLimits, RetentionOptions, RetentionPolicy, retentionPolicy } from '@reqray/core';
3
+
4
+ /**
5
+ * `@reqray/transport-file` — the request log on disk.
6
+ *
7
+ * One line of JSON per recorded request, in a file per day. Not a store: the
8
+ * panel never reads it. It is what a store on disk cannot be — something
9
+ * `grep` understands, `tail -f` follows, a log shipper picks up and an
10
+ * operator copies off the machine after the container is gone.
11
+ *
12
+ * It runs beside a store rather than instead of one:
13
+ *
14
+ * ```js
15
+ * const retention = retentionPolicy({ days: 7, file: '.reqray/retention.json' });
16
+ * reqray({
17
+ * retention,
18
+ * transport: [
19
+ * sqliteTransport({ file: '.reqray/requests.db', retention }),
20
+ * fileTransport({ dir: '.reqray/log', retention }),
21
+ * ],
22
+ * });
23
+ * ```
24
+ *
25
+ * Writing is off the hot path — `send` is called after the response — but it
26
+ * is still someone's process: writes are streamed, a write that fails takes
27
+ * the log down and nothing else, and a queue that grows past its cap drops
28
+ * lines and says how many rather than eating the heap.
29
+ */
30
+
31
+ /** Options for {@link fileTransport}. */
32
+ interface FileTransportOptions {
33
+ /** Directory the log files live in. Created if it is not there. */
34
+ readonly dir: string;
35
+ /**
36
+ * The retention policy, shared with the store.
37
+ *
38
+ * Without one the limits below apply and nothing can change them from the
39
+ * panel.
40
+ */
41
+ readonly retention?: RetentionPolicy;
42
+ /** How many days of log to keep, when no policy says otherwise. */
43
+ readonly days?: number | null;
44
+ /** How much disk the log may take, when no policy says otherwise. */
45
+ readonly maxBytes?: number | null;
46
+ /** File name prefix; the date and `.jsonl` follow it. */
47
+ readonly prefix?: string;
48
+ /**
49
+ * How much may wait in memory for the disk, bytes.
50
+ *
51
+ * Past this, lines are dropped and counted. A log is worth less than the
52
+ * application it is a log of.
53
+ */
54
+ readonly maxPendingBytes?: number;
55
+ /**
56
+ * What time it is.
57
+ *
58
+ * Only tests pass this: rotation happens at midnight, and waiting for one
59
+ * is not a test.
60
+ */
61
+ readonly now?: () => number;
62
+ }
63
+ /** What the log holds right now. */
64
+ interface FileLogStats {
65
+ readonly files: number;
66
+ /** How much disk they take. */
67
+ readonly bytes: number;
68
+ /** The day of the oldest file, epoch ms at local midnight. `null` if empty. */
69
+ readonly oldestAt: number | null;
70
+ /** How many requests this process has written. */
71
+ readonly written: number;
72
+ /** How many it had to drop because the disk could not keep up. */
73
+ readonly dropped: number;
74
+ /** `false` once a write has failed: the log is off, the application is not. */
75
+ readonly writing: boolean;
76
+ }
77
+ /** What was removed by one sweep. */
78
+ interface SweepResult {
79
+ readonly removed: number;
80
+ readonly bytesFreed: number;
81
+ }
82
+ /** A transport that writes a log and answers questions about it. */
83
+ interface FileLog extends Transport {
84
+ readonly dir: string;
85
+ stats(): FileLogStats;
86
+ /** Applies the retention limits now. Called on rotation and on a timer. */
87
+ sweep(now?: number): SweepResult;
88
+ flush(): Promise<void>;
89
+ close(): Promise<void>;
90
+ }
91
+ /** The local day a moment falls in, as `2026-08-20`. */
92
+ declare function dayOf(at: number): string;
93
+ /** Local midnight of a day named the way {@link dayOf} names it. */
94
+ declare function midnightOf(day: string): number | null;
95
+ declare function fileTransport(options: FileTransportOptions): FileLog;
96
+
97
+ export { type FileLog, type FileLogStats, type FileTransportOptions, type SweepResult, dayOf, fileTransport, midnightOf };
@@ -0,0 +1,97 @@
1
+ import { Transport, RetentionPolicy } from '@reqray/core';
2
+ export { RetentionLimits, RetentionOptions, RetentionPolicy, retentionPolicy } from '@reqray/core';
3
+
4
+ /**
5
+ * `@reqray/transport-file` — the request log on disk.
6
+ *
7
+ * One line of JSON per recorded request, in a file per day. Not a store: the
8
+ * panel never reads it. It is what a store on disk cannot be — something
9
+ * `grep` understands, `tail -f` follows, a log shipper picks up and an
10
+ * operator copies off the machine after the container is gone.
11
+ *
12
+ * It runs beside a store rather than instead of one:
13
+ *
14
+ * ```js
15
+ * const retention = retentionPolicy({ days: 7, file: '.reqray/retention.json' });
16
+ * reqray({
17
+ * retention,
18
+ * transport: [
19
+ * sqliteTransport({ file: '.reqray/requests.db', retention }),
20
+ * fileTransport({ dir: '.reqray/log', retention }),
21
+ * ],
22
+ * });
23
+ * ```
24
+ *
25
+ * Writing is off the hot path — `send` is called after the response — but it
26
+ * is still someone's process: writes are streamed, a write that fails takes
27
+ * the log down and nothing else, and a queue that grows past its cap drops
28
+ * lines and says how many rather than eating the heap.
29
+ */
30
+
31
+ /** Options for {@link fileTransport}. */
32
+ interface FileTransportOptions {
33
+ /** Directory the log files live in. Created if it is not there. */
34
+ readonly dir: string;
35
+ /**
36
+ * The retention policy, shared with the store.
37
+ *
38
+ * Without one the limits below apply and nothing can change them from the
39
+ * panel.
40
+ */
41
+ readonly retention?: RetentionPolicy;
42
+ /** How many days of log to keep, when no policy says otherwise. */
43
+ readonly days?: number | null;
44
+ /** How much disk the log may take, when no policy says otherwise. */
45
+ readonly maxBytes?: number | null;
46
+ /** File name prefix; the date and `.jsonl` follow it. */
47
+ readonly prefix?: string;
48
+ /**
49
+ * How much may wait in memory for the disk, bytes.
50
+ *
51
+ * Past this, lines are dropped and counted. A log is worth less than the
52
+ * application it is a log of.
53
+ */
54
+ readonly maxPendingBytes?: number;
55
+ /**
56
+ * What time it is.
57
+ *
58
+ * Only tests pass this: rotation happens at midnight, and waiting for one
59
+ * is not a test.
60
+ */
61
+ readonly now?: () => number;
62
+ }
63
+ /** What the log holds right now. */
64
+ interface FileLogStats {
65
+ readonly files: number;
66
+ /** How much disk they take. */
67
+ readonly bytes: number;
68
+ /** The day of the oldest file, epoch ms at local midnight. `null` if empty. */
69
+ readonly oldestAt: number | null;
70
+ /** How many requests this process has written. */
71
+ readonly written: number;
72
+ /** How many it had to drop because the disk could not keep up. */
73
+ readonly dropped: number;
74
+ /** `false` once a write has failed: the log is off, the application is not. */
75
+ readonly writing: boolean;
76
+ }
77
+ /** What was removed by one sweep. */
78
+ interface SweepResult {
79
+ readonly removed: number;
80
+ readonly bytesFreed: number;
81
+ }
82
+ /** A transport that writes a log and answers questions about it. */
83
+ interface FileLog extends Transport {
84
+ readonly dir: string;
85
+ stats(): FileLogStats;
86
+ /** Applies the retention limits now. Called on rotation and on a timer. */
87
+ sweep(now?: number): SweepResult;
88
+ flush(): Promise<void>;
89
+ close(): Promise<void>;
90
+ }
91
+ /** The local day a moment falls in, as `2026-08-20`. */
92
+ declare function dayOf(at: number): string;
93
+ /** Local midnight of a day named the way {@link dayOf} names it. */
94
+ declare function midnightOf(day: string): number | null;
95
+ declare function fileTransport(options: FileTransportOptions): FileLog;
96
+
97
+ export { type FileLog, type FileLogStats, type FileTransportOptions, type SweepResult, dayOf, fileTransport, midnightOf };
package/dist/index.js ADDED
@@ -0,0 +1,216 @@
1
+ // src/index.ts
2
+ import {
3
+ createWriteStream,
4
+ mkdirSync,
5
+ openSync,
6
+ readdirSync,
7
+ statSync,
8
+ unlinkSync
9
+ } from "fs";
10
+ import { join } from "path";
11
+ import {
12
+ cutoffOf,
13
+ DAY_MS,
14
+ warn,
15
+ warnOnce
16
+ } from "@reqray/core";
17
+ import {
18
+ retentionPolicy
19
+ } from "@reqray/core";
20
+ var DEFAULT_DAYS = 7;
21
+ var DEFAULT_MAX_BYTES = 512 * 1024 * 1024;
22
+ var DEFAULT_PREFIX = "requests";
23
+ var DEFAULT_PENDING = 8 * 1024 * 1024;
24
+ var SWEEP_EVERY_MS = 6e4;
25
+ function dayOf(at) {
26
+ const date = new Date(at);
27
+ const two = (value) => String(value).padStart(2, "0");
28
+ return `${date.getFullYear()}-${two(date.getMonth() + 1)}-${two(date.getDate())}`;
29
+ }
30
+ function midnightOf(day) {
31
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(day);
32
+ if (!match) return null;
33
+ const [, year, month, date] = match;
34
+ return new Date(Number(year), Number(month) - 1, Number(date)).getTime();
35
+ }
36
+ function fileTransport(options) {
37
+ const dir = options.dir;
38
+ const prefix = options.prefix ?? DEFAULT_PREFIX;
39
+ const maxPending = options.maxPendingBytes ?? DEFAULT_PENDING;
40
+ const clock = options.now ?? Date.now;
41
+ const own = {
42
+ days: options.days === void 0 ? DEFAULT_DAYS : options.days,
43
+ maxBytes: options.maxBytes === void 0 ? DEFAULT_MAX_BYTES : options.maxBytes,
44
+ maxRequests: null
45
+ };
46
+ const limits = () => {
47
+ const shared = options.retention?.current();
48
+ return shared ? { ...shared, maxBytes: shared.maxBytes ?? own.maxBytes } : own;
49
+ };
50
+ let stream = null;
51
+ let openDay = "";
52
+ let written = 0;
53
+ let dropped = 0;
54
+ let writing = true;
55
+ let sweptAt = 0;
56
+ const fileFor = (day) => join(dir, `${prefix}-${day}.jsonl`);
57
+ const stop = (reason) => {
58
+ writing = false;
59
+ stream?.destroy();
60
+ stream = null;
61
+ warnOnce("log.write", `the request log is off: ${reason}`);
62
+ };
63
+ function open(day) {
64
+ try {
65
+ mkdirSync(dir, { recursive: true });
66
+ const path = fileFor(day);
67
+ const fd = openSync(path, "a");
68
+ const next = createWriteStream(path, { fd, flags: "a" });
69
+ next.on("error", (error) => stop(error.message));
70
+ stream?.end();
71
+ stream = next;
72
+ openDay = day;
73
+ } catch (error) {
74
+ stop(error instanceof Error ? error.message : String(error));
75
+ }
76
+ }
77
+ function files() {
78
+ let names;
79
+ try {
80
+ names = readdirSync(dir);
81
+ } catch {
82
+ return [];
83
+ }
84
+ const found = [];
85
+ for (const name of names) {
86
+ const match = new RegExp(`^${prefix}-(\\d{4}-\\d{2}-\\d{2})\\.jsonl$`).exec(name);
87
+ const day = match?.[1];
88
+ const at = day ? midnightOf(day) : null;
89
+ if (!day || at === null) continue;
90
+ const path = join(dir, name);
91
+ const size = statSync(path, { throwIfNoEntry: false })?.size;
92
+ if (size === void 0) continue;
93
+ found.push({ path, day, at, bytes: size });
94
+ }
95
+ return found.sort((a, b) => a.at - b.at);
96
+ }
97
+ function sweep(now = clock()) {
98
+ sweptAt = now;
99
+ const { days, maxBytes } = limits();
100
+ const cutoff = cutoffOf({ days, maxBytes, maxRequests: null }, now);
101
+ let removed = 0;
102
+ let bytesFreed = 0;
103
+ const remaining = files();
104
+ const drop = (index) => {
105
+ const entry = remaining[index];
106
+ if (!entry) return;
107
+ try {
108
+ unlinkSync(entry.path);
109
+ removed++;
110
+ bytesFreed += entry.bytes;
111
+ remaining.splice(index, 1);
112
+ } catch (error) {
113
+ const reason = error instanceof Error ? error.message : String(error);
114
+ warnOnce("log.sweep", `a log file could not be removed (${entry.path}): ${reason}`);
115
+ remaining.splice(index, 1);
116
+ }
117
+ };
118
+ if (cutoff !== null) {
119
+ for (let index = remaining.length - 1; index >= 0; index--) {
120
+ const entry = remaining[index];
121
+ if (entry && entry.at + DAY_MS <= cutoff) drop(index);
122
+ }
123
+ }
124
+ if (maxBytes !== null) {
125
+ let total = remaining.reduce((sum, entry) => sum + entry.bytes, 0);
126
+ while (total > maxBytes && remaining.length > 1) {
127
+ const oldest = remaining[0];
128
+ if (!oldest) break;
129
+ total -= oldest.bytes;
130
+ drop(0);
131
+ }
132
+ if (total > maxBytes) {
133
+ warnOnce(
134
+ "log.size",
135
+ `today's log file alone is over the ${maxBytes} byte limit; nothing older is left to remove`
136
+ );
137
+ }
138
+ }
139
+ return { removed, bytesFreed };
140
+ }
141
+ sweep();
142
+ options.retention?.subscribe(() => void sweep());
143
+ return {
144
+ name: "file",
145
+ dir,
146
+ send(request) {
147
+ if (!writing) return;
148
+ const now = clock();
149
+ const day = dayOf(now);
150
+ if (day !== openDay) {
151
+ open(day);
152
+ sweep(now);
153
+ } else if (now - sweptAt > SWEEP_EVERY_MS) {
154
+ sweep(now);
155
+ }
156
+ if (!stream) return;
157
+ let line;
158
+ try {
159
+ line = `${JSON.stringify(request)}
160
+ `;
161
+ } catch (error) {
162
+ const reason = error instanceof Error ? error.message : String(error);
163
+ warnOnce("log.serialize", `a request could not be written to the log: ${reason}`);
164
+ return;
165
+ }
166
+ if (stream.writableLength > maxPending) {
167
+ dropped++;
168
+ warnOnce(
169
+ "log.behind",
170
+ "the request log is behind the application and lines are being dropped"
171
+ );
172
+ return;
173
+ }
174
+ stream.write(line);
175
+ written++;
176
+ },
177
+ stats() {
178
+ const all = files();
179
+ return {
180
+ files: all.length,
181
+ bytes: all.reduce((sum, entry) => sum + entry.bytes, 0),
182
+ oldestAt: all[0]?.at ?? null,
183
+ written,
184
+ dropped,
185
+ writing
186
+ };
187
+ },
188
+ sweep,
189
+ async flush() {
190
+ const open2 = stream;
191
+ if (!open2) return;
192
+ await new Promise((resolve) => {
193
+ open2.write("", () => resolve());
194
+ });
195
+ },
196
+ async close() {
197
+ const open2 = stream;
198
+ stream = null;
199
+ if (!open2) return;
200
+ await new Promise((resolve) => {
201
+ open2.end(() => resolve());
202
+ open2.once("error", (error) => {
203
+ warn(`the request log did not close cleanly: ${error.message}`);
204
+ resolve();
205
+ });
206
+ });
207
+ }
208
+ };
209
+ }
210
+ export {
211
+ dayOf,
212
+ fileTransport,
213
+ midnightOf,
214
+ retentionPolicy
215
+ };
216
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@reqray/transport-file` — the request log on disk.\n *\n * One line of JSON per recorded request, in a file per day. Not a store: the\n * panel never reads it. It is what a store on disk cannot be — something\n * `grep` understands, `tail -f` follows, a log shipper picks up and an\n * operator copies off the machine after the container is gone.\n *\n * It runs beside a store rather than instead of one:\n *\n * ```js\n * const retention = retentionPolicy({ days: 7, file: '.reqray/retention.json' });\n * reqray({\n * retention,\n * transport: [\n * sqliteTransport({ file: '.reqray/requests.db', retention }),\n * fileTransport({ dir: '.reqray/log', retention }),\n * ],\n * });\n * ```\n *\n * Writing is off the hot path — `send` is called after the response — but it\n * is still someone's process: writes are streamed, a write that fails takes\n * the log down and nothing else, and a queue that grows past its cap drops\n * lines and says how many rather than eating the heap.\n */\n\nimport {\n createWriteStream,\n mkdirSync,\n openSync,\n readdirSync,\n statSync,\n unlinkSync,\n type WriteStream,\n} from 'node:fs';\nimport { join } from 'node:path';\nimport {\n cutoffOf,\n DAY_MS,\n type RetentionPolicy,\n type Transport,\n warn,\n warnOnce,\n} from '@reqray/core';\nimport type { RecordedRequest, RetentionLimits } from '@reqray/protocol';\n\n/** Options for {@link fileTransport}. */\nexport interface FileTransportOptions {\n /** Directory the log files live in. Created if it is not there. */\n readonly dir: string;\n /**\n * The retention policy, shared with the store.\n *\n * Without one the limits below apply and nothing can change them from the\n * panel.\n */\n readonly retention?: RetentionPolicy;\n /** How many days of log to keep, when no policy says otherwise. */\n readonly days?: number | null;\n /** How much disk the log may take, when no policy says otherwise. */\n readonly maxBytes?: number | null;\n /** File name prefix; the date and `.jsonl` follow it. */\n readonly prefix?: string;\n /**\n * How much may wait in memory for the disk, bytes.\n *\n * Past this, lines are dropped and counted. A log is worth less than the\n * application it is a log of.\n */\n readonly maxPendingBytes?: number;\n /**\n * What time it is.\n *\n * Only tests pass this: rotation happens at midnight, and waiting for one\n * is not a test.\n */\n readonly now?: () => number;\n}\n\n/** What the log holds right now. */\nexport interface FileLogStats {\n readonly files: number;\n /** How much disk they take. */\n readonly bytes: number;\n /** The day of the oldest file, epoch ms at local midnight. `null` if empty. */\n readonly oldestAt: number | null;\n /** How many requests this process has written. */\n readonly written: number;\n /** How many it had to drop because the disk could not keep up. */\n readonly dropped: number;\n /** `false` once a write has failed: the log is off, the application is not. */\n readonly writing: boolean;\n}\n\n/** What was removed by one sweep. */\nexport interface SweepResult {\n readonly removed: number;\n readonly bytesFreed: number;\n}\n\n/** A transport that writes a log and answers questions about it. */\nexport interface FileLog extends Transport {\n readonly dir: string;\n stats(): FileLogStats;\n /** Applies the retention limits now. Called on rotation and on a timer. */\n sweep(now?: number): SweepResult;\n flush(): Promise<void>;\n close(): Promise<void>;\n}\n\n/** A week of history: long enough for \"what happened yesterday\". */\nconst DEFAULT_DAYS = 7;\n/** Half a gigabyte, the same order as the SQLite store's own cap. */\nconst DEFAULT_MAX_BYTES = 512 * 1024 * 1024;\nconst DEFAULT_PREFIX = 'requests';\nconst DEFAULT_PENDING = 8 * 1024 * 1024;\n/** How often a sweep may run while writing. */\nconst SWEEP_EVERY_MS = 60_000;\n\n/** The local day a moment falls in, as `2026-08-20`. */\nexport function dayOf(at: number): string {\n const date = new Date(at);\n const two = (value: number) => String(value).padStart(2, '0');\n return `${date.getFullYear()}-${two(date.getMonth() + 1)}-${two(date.getDate())}`;\n}\n\n/** Local midnight of a day named the way {@link dayOf} names it. */\nexport function midnightOf(day: string): number | null {\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(day);\n if (!match) return null;\n const [, year, month, date] = match;\n return new Date(Number(year), Number(month) - 1, Number(date)).getTime();\n}\n\nexport function fileTransport(options: FileTransportOptions): FileLog {\n const dir = options.dir;\n const prefix = options.prefix ?? DEFAULT_PREFIX;\n const maxPending = options.maxPendingBytes ?? DEFAULT_PENDING;\n const clock = options.now ?? Date.now;\n const own: RetentionLimits = {\n days: options.days === undefined ? DEFAULT_DAYS : options.days,\n maxBytes: options.maxBytes === undefined ? DEFAULT_MAX_BYTES : options.maxBytes,\n maxRequests: null,\n };\n\n /**\n * The limits in force: the shared policy if there is one, ours otherwise.\n *\n * A policy that says nothing about size leaves this log's own cap standing,\n * the way the SQLite store reads the same policy. `{ days: 7 }` is what\n * most people write, and it must not mean \"and as many bytes as the disk\n * has\".\n */\n const limits = (): RetentionLimits => {\n const shared = options.retention?.current();\n return shared ? { ...shared, maxBytes: shared.maxBytes ?? own.maxBytes } : own;\n };\n\n let stream: WriteStream | null = null;\n let openDay = '';\n let written = 0;\n let dropped = 0;\n let writing = true;\n let sweptAt = 0;\n\n const fileFor = (day: string) => join(dir, `${prefix}-${day}.jsonl`);\n\n const stop = (reason: string): void => {\n writing = false;\n stream?.destroy();\n stream = null;\n warnOnce('log.write', `the request log is off: ${reason}`);\n };\n\n function open(day: string): void {\n try {\n mkdirSync(dir, { recursive: true });\n // The descriptor is opened here rather than by the stream, which opens\n // on a later tick. Two things go wrong with a late open: the file is\n // not there to be swept or counted until it happens, and an open that\n // lands after a sweep has removed the name creates the file again —\n // yesterday's log, resurrected empty.\n const path = fileFor(day);\n const fd = openSync(path, 'a');\n const next = createWriteStream(path, { fd, flags: 'a' });\n next.on('error', (error) => stop(error.message));\n stream?.end();\n stream = next;\n openDay = day;\n } catch (error) {\n stop(error instanceof Error ? error.message : String(error));\n }\n }\n\n /** Every log file this directory holds, oldest first. */\n function files(): Array<{ path: string; day: string; at: number; bytes: number }> {\n let names: string[];\n try {\n names = readdirSync(dir);\n } catch {\n return [];\n }\n\n const found: Array<{ path: string; day: string; at: number; bytes: number }> = [];\n for (const name of names) {\n const match = new RegExp(`^${prefix}-(\\\\d{4}-\\\\d{2}-\\\\d{2})\\\\.jsonl$`).exec(name);\n const day = match?.[1];\n const at = day ? midnightOf(day) : null;\n if (!day || at === null) continue;\n const path = join(dir, name);\n const size = statSync(path, { throwIfNoEntry: false })?.size;\n if (size === undefined) continue;\n found.push({ path, day, at, bytes: size });\n }\n return found.sort((a, b) => a.at - b.at);\n }\n\n function sweep(now = clock()): SweepResult {\n sweptAt = now;\n const { days, maxBytes } = limits();\n const cutoff = cutoffOf({ days, maxBytes, maxRequests: null }, now);\n let removed = 0;\n let bytesFreed = 0;\n\n const remaining = files();\n const drop = (index: number): void => {\n const entry = remaining[index];\n if (!entry) return;\n try {\n unlinkSync(entry.path);\n removed++;\n bytesFreed += entry.bytes;\n remaining.splice(index, 1);\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n warnOnce('log.sweep', `a log file could not be removed (${entry.path}): ${reason}`);\n remaining.splice(index, 1);\n }\n };\n\n // By age first. A day's file is only past the cutoff once the whole day\n // is: a file named for today holds requests from a minute ago.\n if (cutoff !== null) {\n for (let index = remaining.length - 1; index >= 0; index--) {\n const entry = remaining[index];\n if (entry && entry.at + DAY_MS <= cutoff) drop(index);\n }\n }\n\n // Then by size, oldest first — and never the file being written to, which\n // is the only one that would take the current day's requests with it.\n if (maxBytes !== null) {\n let total = remaining.reduce((sum, entry) => sum + entry.bytes, 0);\n while (total > maxBytes && remaining.length > 1) {\n const oldest = remaining[0];\n if (!oldest) break;\n total -= oldest.bytes;\n drop(0);\n }\n if (total > maxBytes) {\n warnOnce(\n 'log.size',\n `today's log file alone is over the ${maxBytes} byte limit; nothing older is left to remove`,\n );\n }\n }\n\n return { removed, bytesFreed };\n }\n\n // Old files are swept at startup too: an application that starts and gets no\n // traffic still has yesterday's limits to honour.\n sweep();\n options.retention?.subscribe(() => void sweep());\n\n return {\n name: 'file',\n dir,\n\n send(request: RecordedRequest) {\n if (!writing) return;\n\n const now = clock();\n const day = dayOf(now);\n if (day !== openDay) {\n open(day);\n sweep(now);\n } else if (now - sweptAt > SWEEP_EVERY_MS) {\n sweep(now);\n }\n if (!stream) return;\n\n let line: string;\n try {\n line = `${JSON.stringify(request)}\\n`;\n } catch (error) {\n // A record that will not serialize is one record, not a reason to stop.\n const reason = error instanceof Error ? error.message : String(error);\n warnOnce('log.serialize', `a request could not be written to the log: ${reason}`);\n return;\n }\n\n // What the stream still owes the disk, asked of the stream itself: a\n // count of refused writes would miss the case where nothing has been\n // refused yet and megabytes are already queued.\n if (stream.writableLength > maxPending) {\n dropped++;\n warnOnce(\n 'log.behind',\n 'the request log is behind the application and lines are being dropped',\n );\n return;\n }\n\n stream.write(line);\n written++;\n },\n\n stats(): FileLogStats {\n const all = files();\n return {\n files: all.length,\n bytes: all.reduce((sum, entry) => sum + entry.bytes, 0),\n oldestAt: all[0]?.at ?? null,\n written,\n dropped,\n writing,\n };\n },\n\n sweep,\n\n async flush() {\n const open = stream;\n if (!open) return;\n // An empty write with a callback: `drain` only ever fires after a write\n // that was refused, so waiting for one is how a flush hangs forever.\n await new Promise<void>((resolve) => {\n open.write('', () => resolve());\n });\n },\n\n async close() {\n const open = stream;\n stream = null;\n if (!open) return;\n await new Promise<void>((resolve) => {\n open.end(() => resolve());\n open.once('error', (error) => {\n warn(`the request log did not close cleanly: ${error.message}`);\n resolve();\n });\n });\n },\n };\n}\n\n/**\n * The retention policy, re-exported.\n *\n * Anyone keeping requests on disk installs this package; making them add\n * `@reqray/core` as well to say how long to keep them would be a dependency\n * for one function. It is the same object either way.\n */\nexport {\n type RetentionLimits,\n type RetentionOptions,\n type RetentionPolicy,\n retentionPolicy,\n} from '@reqray/core';\n"],"mappings":";AA2BA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AAiUP;AAAA,EAIE;AAAA,OACK;AAlQP,IAAM,eAAe;AAErB,IAAM,oBAAoB,MAAM,OAAO;AACvC,IAAM,iBAAiB;AACvB,IAAM,kBAAkB,IAAI,OAAO;AAEnC,IAAM,iBAAiB;AAGhB,SAAS,MAAM,IAAoB;AACxC,QAAM,OAAO,IAAI,KAAK,EAAE;AACxB,QAAM,MAAM,CAAC,UAAkB,OAAO,KAAK,EAAE,SAAS,GAAG,GAAG;AAC5D,SAAO,GAAG,KAAK,YAAY,CAAC,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,CAAC,IAAI,IAAI,KAAK,QAAQ,CAAC,CAAC;AACjF;AAGO,SAAS,WAAW,KAA4B;AACrD,QAAM,QAAQ,4BAA4B,K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BAAiB,8CAA8C,MAAM,EAAE;AAChF;AAAA,MACF;AAKA,UAAI,OAAO,iBAAiB,YAAY;AACtC;AACA;AAAA,UACE;AAAA,UACA;AAAA,QACF;AACA;AAAA,MACF;AAEA,aAAO,MAAM,IAAI;AACjB;AAAA,IACF;AAAA,IAEA,QAAsB;AACpB,YAAM,MAAM,MAAM;AAClB,aAAO;AAAA,QACL,OAAO,IAAI;AAAA,QACX,OAAO,IAAI,OAAO,CAAC,KAAK,UAAU,MAAM,MAAM,OAAO,CAAC;AAAA,QACtD,UAAU,IAAI,CAAC,GAAG,MAAM;AAAA,QACxB;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,IAEA;AAAA,IAEA,MAAM,QAAQ;AACZ,YAAMA,QAAO;AACb,UAAI,CAACA,MAAM;AAGX,YAAM,IAAI,QAAc,CAAC,YAAY;AACnC,QAAAA,MAAK,MAAM,IAAI,MAAM,QAAQ,CAAC;AAAA,MAChC,CAAC;AAAA,IACH;AAAA,IAEA,MAAM,QAAQ;AACZ,YAAMA,QAAO;AACb,eAAS;AACT,UAAI,CAACA,MAAM;AACX,YAAM,IAAI,QAAc,CAAC,YAAY;AACnC,QAAAA,MAAK,IAAI,MAAM,QAAQ,CAAC;AACxB,QAAAA,MAAK,KAAK,SAAS,CAAC,UAAU;AAC5B,eAAK,0CAA0C,MAAM,OAAO,EAAE;AAC9D,kBAAQ;AAAA,QACV,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["open"]}
package/package.json CHANGED
@@ -1,6 +1,63 @@
1
1
  {
2
2
  "name": "@reqray/transport-file",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Reqray request log: every recorded request as a line of JSON, rotated by day and swept by the retention policy.",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "nodejs",
8
+ "debugging",
9
+ "profiling",
10
+ "n+1",
11
+ "sql",
12
+ "observability",
13
+ "devtools",
14
+ "fastify",
15
+ "express",
16
+ "nestjs"
17
+ ],
18
+ "homepage": "https://github.com/reqray/reqray#readme",
19
+ "bugs": "https://github.com/reqray/reqray/issues",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/reqray/reqray.git",
23
+ "directory": "packages/transport-file"
24
+ },
25
+ "type": "module",
26
+ "engines": {
27
+ "node": ">=20"
28
+ },
29
+ "exports": {
30
+ ".": {
31
+ "import": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/index.d.cts",
37
+ "default": "./dist/index.cjs"
38
+ }
39
+ }
40
+ },
41
+ "main": "./dist/index.cjs",
42
+ "module": "./dist/index.js",
43
+ "types": "./dist/index.d.ts",
44
+ "files": [
45
+ "dist"
46
+ ],
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "dependencies": {
51
+ "@reqray/core": "^0.1.1",
52
+ "@reqray/protocol": "^0.1.1"
53
+ },
54
+ "devDependencies": {
55
+ "@types/node": "^26.2.0",
56
+ "tsup": "^8.5.1",
57
+ "typescript": "^6.0.3"
58
+ },
59
+ "scripts": {
60
+ "build": "tsup",
61
+ "typecheck": "tsc --noEmit"
62
+ }
6
63
  }