@curless/hotel-storefront 0.90.0 → 0.91.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/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/usage/bookings-import.d.ts.map +1 -1
- package/dist/usage/bookings-import.js +1 -2
- package/dist/usage/bookings-import.js.map +1 -1
- package/dist/usage/boot.d.ts +1 -1
- package/dist/usage/boot.d.ts.map +1 -1
- package/dist/usage/boot.js +17 -68
- package/dist/usage/boot.js.map +1 -1
- package/dist/usage/platform.d.ts +1 -1
- package/dist/usage/platform.d.ts.map +1 -1
- package/dist/usage/platform.js.map +1 -1
- package/dist/usage/recorder.d.ts +1 -3
- package/dist/usage/recorder.d.ts.map +1 -1
- package/dist/usage/recorder.js.map +1 -1
- package/dist/usage/shadow-import.d.ts +1 -1
- package/dist/usage/shadow-import.d.ts.map +1 -1
- package/dist/usage/shadow-import.js +1 -1
- package/dist/usage/shadow-import.js.map +1 -1
- package/dist/usage-cli.js +7 -8
- package/dist/usage-cli.js.map +1 -1
- package/package.json +3 -2
- package/dist/usage/geo.d.ts +0 -88
- package/dist/usage/geo.d.ts.map +0 -1
- package/dist/usage/geo.js +0 -396
- package/dist/usage/geo.js.map +0 -1
- package/dist/usage/maintain.d.ts +0 -26
- package/dist/usage/maintain.d.ts.map +0 -1
- package/dist/usage/maintain.js +0 -177
- package/dist/usage/maintain.js.map +0 -1
- package/dist/usage/pseudonym.d.ts +0 -28
- package/dist/usage/pseudonym.d.ts.map +0 -1
- package/dist/usage/pseudonym.js +0 -73
- package/dist/usage/pseudonym.js.map +0 -1
- package/dist/usage/range.d.ts +0 -18
- package/dist/usage/range.d.ts.map +0 -1
- package/dist/usage/range.js +0 -97
- package/dist/usage/range.js.map +0 -1
- package/dist/usage/report.d.ts +0 -258
- package/dist/usage/report.d.ts.map +0 -1
- package/dist/usage/report.js +0 -862
- package/dist/usage/report.js.map +0 -1
- package/dist/usage/store.d.ts +0 -258
- package/dist/usage/store.d.ts.map +0 -1
- package/dist/usage/store.js +0 -475
- package/dist/usage/store.js.map +0 -1
package/dist/usage/store.js
DELETED
|
@@ -1,475 +0,0 @@
|
|
|
1
|
-
// Copied from @curless/shopify-storefront src/usage/store.ts (0.77.2): the files
|
|
2
|
-
// are the format of docs/usage-events.md, which both packages write and the
|
|
3
|
-
// dashboard reads. What the hotels add to it - `booking`, `member`, `res`,
|
|
4
|
-
// `signUp`, `import-shadow` - is in that page too (§3).
|
|
5
|
-
//
|
|
6
|
-
// Where the usage statistics live: one JSON line per event, one file per UTC day.
|
|
7
|
-
//
|
|
8
|
-
// <dir>/events/2026-11-12.jsonl recorded by the connector (13 months)
|
|
9
|
-
// <dir>/events/2026-10-20.import.jsonl imported from Caddy's access log (13 months)
|
|
10
|
-
// <dir>/daily/2026-11-12.json that day's totals (kept for good)
|
|
11
|
-
//
|
|
12
|
-
// Files, not a database: the connector has none (it reads one shop and links to
|
|
13
|
-
// one checkout), the volume is small, a day is deleted by deleting a file, and
|
|
14
|
-
// "is there an address in here" is answered by grep. Written behind the answer,
|
|
15
|
-
// never in front of it: `add` queues and returns; a failed write is a fault
|
|
16
|
-
// counted and logged, never an error a shopper sees.
|
|
17
|
-
import { promises as fs, createReadStream } from 'node:fs';
|
|
18
|
-
import { join } from 'node:path';
|
|
19
|
-
import { createInterface } from 'node:readline';
|
|
20
|
-
/** How long the event lines are kept: 13 months (robin, 2026-11-12). */
|
|
21
|
-
export const RETAIN_MONTHS = 13;
|
|
22
|
-
/**
|
|
23
|
-
* The lines that are about an order, not about use (0.78.1): an order number arriving late, a
|
|
24
|
-
* cancellation, and what the one-off import of the booking file wrote. Reports, totals and the
|
|
25
|
-
* daily summaries leave them out - they are for reconciling orders (the dashboard's 订单).
|
|
26
|
-
*/
|
|
27
|
-
export const isOrderLine = (e) => e.e === 'booking_update' || e.e === 'booking_cancel' || e.src === 'import-bookings';
|
|
28
|
-
/** `2026-11-12` for a time. UTC, so a day means the same thing on every machine. */
|
|
29
|
-
export const dayOf = (t) => new Date(t).toISOString().slice(0, 10);
|
|
30
|
-
/** The first day still kept on `today`: the same date 13 months back. */
|
|
31
|
-
export const firstKeptDay = (today) => {
|
|
32
|
-
const d = new Date(`${today}T00:00:00Z`);
|
|
33
|
-
d.setUTCMonth(d.getUTCMonth() - RETAIN_MONTHS);
|
|
34
|
-
return dayOf(d);
|
|
35
|
-
};
|
|
36
|
-
const DAY_FILE = /^(\d{4}-\d{2}-\d{2})(\.import)?\.jsonl$/;
|
|
37
|
-
/** An import's day while it is being written (ImportWriter). */
|
|
38
|
-
const IMPORT_TMP = /^\d{4}-\d{2}-\d{2}\.import\.jsonl\.tmp-/;
|
|
39
|
-
/** An import left behind this long ago was cut off: it runs for minutes, not a day. */
|
|
40
|
-
const STALE_TMP_MS = 24 * 60 * 60_000;
|
|
41
|
-
/**
|
|
42
|
-
* ⚠️ BOUNDED (security review of 0.77.0, P1). Anyone can make requests, so the
|
|
43
|
-
* lines a day can grow to, and the directory as a whole, have a ceiling: past
|
|
44
|
-
* it a line is counted (`capped`) and a fault noted, and nothing more is
|
|
45
|
-
* written - the requests themselves are untouched.
|
|
46
|
-
*/
|
|
47
|
-
export const MAX_DAY_BYTES = 64 * 1024 * 1024;
|
|
48
|
-
export const MAX_TOTAL_BYTES = 2 * 1024 * 1024 * 1024;
|
|
49
|
-
/** Give the event loop a turn every this many lines read. */
|
|
50
|
-
const YIELD_EVERY = 1_000;
|
|
51
|
-
const yieldTurn = () => new Promise((r) => setImmediate(r));
|
|
52
|
-
export class UsageStore {
|
|
53
|
-
dir;
|
|
54
|
-
queue = [];
|
|
55
|
-
timer = null;
|
|
56
|
-
writing = Promise.resolve();
|
|
57
|
-
flushMs;
|
|
58
|
-
onFault;
|
|
59
|
-
now;
|
|
60
|
-
/** Lines written, and faults - for /healthz. */
|
|
61
|
-
written = 0;
|
|
62
|
-
faults = 0;
|
|
63
|
-
/** Lines dropped because the queue was full - a stuck disk must not grow memory. */
|
|
64
|
-
dropped = 0;
|
|
65
|
-
/** Lines not written because a day's file or the directory reached its ceiling. */
|
|
66
|
-
capped = 0;
|
|
67
|
-
/** Bytes in the directory, as last measured plus what was written since. */
|
|
68
|
-
bytes = 0;
|
|
69
|
-
maxDayBytes;
|
|
70
|
-
maxTotalBytes;
|
|
71
|
-
fullHits = 0;
|
|
72
|
-
lastMeasure = 0;
|
|
73
|
-
static MAX_QUEUE = 5_000;
|
|
74
|
-
constructor(opts) {
|
|
75
|
-
this.dir = opts.dir;
|
|
76
|
-
this.flushMs = opts.flushMs ?? 1_000;
|
|
77
|
-
this.maxDayBytes = opts.maxDayBytes ?? MAX_DAY_BYTES;
|
|
78
|
-
this.maxTotalBytes = opts.maxTotalBytes ?? MAX_TOTAL_BYTES;
|
|
79
|
-
this.onFault = opts.onFault ?? (() => { });
|
|
80
|
-
this.now = opts.now ?? (() => Date.now());
|
|
81
|
-
}
|
|
82
|
-
get eventsDir() {
|
|
83
|
-
return join(this.dir, 'events');
|
|
84
|
-
}
|
|
85
|
-
get dailyDir() {
|
|
86
|
-
return join(this.dir, 'daily');
|
|
87
|
-
}
|
|
88
|
-
/** Queue one event. Never throws, never waits. */
|
|
89
|
-
add(event) {
|
|
90
|
-
try {
|
|
91
|
-
const line = JSON.stringify(event);
|
|
92
|
-
if (this.bytes + Buffer.byteLength(line) + 1 > this.maxTotalBytes) {
|
|
93
|
-
this.capped++;
|
|
94
|
-
// A fault on the first line refused and every thousandth after.
|
|
95
|
-
if (this.fullHits++ % 1_000 === 0)
|
|
96
|
-
this.fault('total-cap', new Error('usage directory full'));
|
|
97
|
-
// Measured again at most once a minute while full: days cleared by
|
|
98
|
-
// hand (`usage-cli purge`) are room again without a restart.
|
|
99
|
-
const now = this.now();
|
|
100
|
-
if (now - this.lastMeasure > 60_000) {
|
|
101
|
-
this.lastMeasure = now;
|
|
102
|
-
void this.measure().catch((err) => this.fault('measure', err));
|
|
103
|
-
}
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
if (this.queue.length >= UsageStore.MAX_QUEUE) {
|
|
107
|
-
this.dropped++;
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
this.queue.push({ day: event.t.slice(0, 10), line });
|
|
111
|
-
if (!this.timer) {
|
|
112
|
-
this.timer = setTimeout(() => void this.flush(), this.flushMs);
|
|
113
|
-
this.timer.unref?.();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
catch (err) {
|
|
117
|
-
this.fault('queue', err);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
/** Write what is queued. Resolves when it is on disk (or counted as a fault). */
|
|
121
|
-
flush() {
|
|
122
|
-
if (this.timer) {
|
|
123
|
-
clearTimeout(this.timer);
|
|
124
|
-
this.timer = null;
|
|
125
|
-
}
|
|
126
|
-
const lines = this.queue;
|
|
127
|
-
this.queue = [];
|
|
128
|
-
if (lines.length === 0)
|
|
129
|
-
return this.writing;
|
|
130
|
-
this.writing = this.writing.then(() => this.append(lines));
|
|
131
|
-
return this.writing;
|
|
132
|
-
}
|
|
133
|
-
async append(lines) {
|
|
134
|
-
// By the day of each line, not of the flush: a batch can straddle midnight.
|
|
135
|
-
const byDay = new Map();
|
|
136
|
-
for (const { day, line } of lines) {
|
|
137
|
-
if (!/^\d{4}-\d{2}-\d{2}$/.test(day))
|
|
138
|
-
continue;
|
|
139
|
-
const list = byDay.get(day) ?? [];
|
|
140
|
-
list.push(line);
|
|
141
|
-
byDay.set(day, list);
|
|
142
|
-
}
|
|
143
|
-
try {
|
|
144
|
-
await fs.mkdir(this.eventsDir, { recursive: true, mode: 0o700 });
|
|
145
|
-
for (const [day, list] of byDay) {
|
|
146
|
-
const file = join(this.eventsDir, `${day}.jsonl`);
|
|
147
|
-
// Asked every batch, not remembered: a day cleared by hand counts as empty at once.
|
|
148
|
-
const size = await fs.stat(file).then((st) => st.size, () => 0);
|
|
149
|
-
// As many as fit under the day's ceiling and the directory's.
|
|
150
|
-
let room = Math.min(this.maxDayBytes - size, this.maxTotalBytes - this.bytes);
|
|
151
|
-
const keep = [];
|
|
152
|
-
for (const line of list) {
|
|
153
|
-
const n = Buffer.byteLength(line) + 1;
|
|
154
|
-
if (n > room)
|
|
155
|
-
break;
|
|
156
|
-
keep.push(line);
|
|
157
|
-
room -= n;
|
|
158
|
-
}
|
|
159
|
-
if (keep.length < list.length) {
|
|
160
|
-
this.capped += list.length - keep.length;
|
|
161
|
-
this.fault('day-cap', new Error(`usage ${day} at its ceiling`));
|
|
162
|
-
}
|
|
163
|
-
if (!keep.length)
|
|
164
|
-
continue;
|
|
165
|
-
const text = `${keep.join('\n')}\n`;
|
|
166
|
-
await fs.appendFile(file, text, { mode: 0o600 });
|
|
167
|
-
this.bytes += Buffer.byteLength(text);
|
|
168
|
-
this.written += keep.length;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
catch (err) {
|
|
172
|
-
this.fault('write', err);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
/** How much the directory holds now - at boot and after each prune. */
|
|
176
|
-
async measure() {
|
|
177
|
-
this.lastMeasure = this.now();
|
|
178
|
-
let total = 0;
|
|
179
|
-
for (const sub of [this.eventsDir, this.dailyDir]) {
|
|
180
|
-
let names;
|
|
181
|
-
try {
|
|
182
|
-
names = await fs.readdir(sub);
|
|
183
|
-
}
|
|
184
|
-
catch {
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
for (const name of names) {
|
|
188
|
-
total += await fs.stat(join(sub, name)).then((st) => st.size, () => 0);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
this.bytes = total;
|
|
192
|
-
return total;
|
|
193
|
-
}
|
|
194
|
-
fault(what, err) {
|
|
195
|
-
this.faults++;
|
|
196
|
-
try {
|
|
197
|
-
this.onFault(what, err);
|
|
198
|
-
}
|
|
199
|
-
catch {
|
|
200
|
-
// a logger that throws is not a reason to throw
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
/** Days with event files, oldest first: `{ day, files }`. */
|
|
204
|
-
async days() {
|
|
205
|
-
let names;
|
|
206
|
-
try {
|
|
207
|
-
names = await fs.readdir(this.eventsDir);
|
|
208
|
-
}
|
|
209
|
-
catch {
|
|
210
|
-
return [];
|
|
211
|
-
}
|
|
212
|
-
const byDay = new Map();
|
|
213
|
-
for (const name of names) {
|
|
214
|
-
const m = DAY_FILE.exec(name);
|
|
215
|
-
if (!m)
|
|
216
|
-
continue;
|
|
217
|
-
const day = m[1];
|
|
218
|
-
byDay.set(day, [...(byDay.get(day) ?? []), join(this.eventsDir, name)]);
|
|
219
|
-
}
|
|
220
|
-
return [...byDay.entries()]
|
|
221
|
-
.sort(([a], [b]) => (a < b ? -1 : 1))
|
|
222
|
-
.map(([day, files]) => ({ day, files: files.sort() }));
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Every event of the UTC days `from`..`to` (inclusive), in file order -
|
|
226
|
-
* streamed a line at a time, never a whole file in memory, with a turn for
|
|
227
|
-
* the event loop every thousand lines.
|
|
228
|
-
*/
|
|
229
|
-
async *read(from = '0000-00-00', to = '9999-99-99') {
|
|
230
|
-
let n = 0;
|
|
231
|
-
for (const { day, files } of await this.days()) {
|
|
232
|
-
if (day < from || day > to)
|
|
233
|
-
continue;
|
|
234
|
-
for (const file of files) {
|
|
235
|
-
let lines;
|
|
236
|
-
try {
|
|
237
|
-
await fs.access(file);
|
|
238
|
-
lines = createInterface({
|
|
239
|
-
input: createReadStream(file),
|
|
240
|
-
crlfDelay: Number.POSITIVE_INFINITY,
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
catch {
|
|
244
|
-
continue;
|
|
245
|
-
}
|
|
246
|
-
for await (const line of lines) {
|
|
247
|
-
if (++n % YIELD_EVERY === 0)
|
|
248
|
-
await yieldTurn();
|
|
249
|
-
if (!line)
|
|
250
|
-
continue;
|
|
251
|
-
try {
|
|
252
|
-
const ev = JSON.parse(line);
|
|
253
|
-
if (ev && ev.v === 1)
|
|
254
|
-
yield ev;
|
|
255
|
-
}
|
|
256
|
-
catch {
|
|
257
|
-
// a torn last line after a crash: skip it
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
/** The earliest recorded (not imported) event time, or null. */
|
|
264
|
-
async firstLiveTime() {
|
|
265
|
-
for (const { files } of await this.days()) {
|
|
266
|
-
const live = files.find((f) => f.endsWith('.jsonl') && !f.endsWith('.import.jsonl'));
|
|
267
|
-
if (!live)
|
|
268
|
-
continue;
|
|
269
|
-
try {
|
|
270
|
-
// The first line only - a day's file can be large.
|
|
271
|
-
const lines = createInterface({
|
|
272
|
-
input: createReadStream(live),
|
|
273
|
-
crlfDelay: Number.POSITIVE_INFINITY,
|
|
274
|
-
});
|
|
275
|
-
for await (const first of lines) {
|
|
276
|
-
lines.close();
|
|
277
|
-
if (first)
|
|
278
|
-
return Date.parse(JSON.parse(first).t);
|
|
279
|
-
break;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
catch {
|
|
283
|
-
// unreadable: look at the next day
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
return null;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Delete the event files of UTC days `from`..`to` by hand - for a store
|
|
290
|
-
* flooded to its ceiling (总线程's review of 0.77.1, P3: otherwise it stays
|
|
291
|
-
* full until the flood is 13 months old). `totals` takes the days' totals
|
|
292
|
-
* too. Returns what went; the running connector sees the room within a
|
|
293
|
-
* minute.
|
|
294
|
-
*/
|
|
295
|
-
async purge(from, to, opts = {}) {
|
|
296
|
-
const files = [];
|
|
297
|
-
for (const { day, files: list } of await this.days()) {
|
|
298
|
-
if (day >= from && day <= to)
|
|
299
|
-
files.push(...list);
|
|
300
|
-
}
|
|
301
|
-
if (opts.totals) {
|
|
302
|
-
let names = [];
|
|
303
|
-
try {
|
|
304
|
-
names = await fs.readdir(this.dailyDir);
|
|
305
|
-
}
|
|
306
|
-
catch {
|
|
307
|
-
// none yet
|
|
308
|
-
}
|
|
309
|
-
for (const name of names) {
|
|
310
|
-
const day = name.slice(0, 10);
|
|
311
|
-
if (/^\d{4}-\d{2}-\d{2}\.json$/.test(name) && day >= from && day <= to) {
|
|
312
|
-
files.push(join(this.dailyDir, name));
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
let bytes = 0;
|
|
317
|
-
for (const f of files) {
|
|
318
|
-
bytes += await fs.stat(f).then((st) => st.size, () => 0);
|
|
319
|
-
if (!opts.dryRun)
|
|
320
|
-
await fs.unlink(f).catch((err) => this.fault('purge', err));
|
|
321
|
-
}
|
|
322
|
-
for (const f of await this.staleImports()) {
|
|
323
|
-
files.push(f);
|
|
324
|
-
bytes += await fs.stat(f).then((st) => st.size, () => 0);
|
|
325
|
-
if (!opts.dryRun)
|
|
326
|
-
await fs.unlink(f).catch((err) => this.fault('purge', err));
|
|
327
|
-
}
|
|
328
|
-
if (!opts.dryRun)
|
|
329
|
-
await this.measure();
|
|
330
|
-
return { files, bytes };
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Imports cut off midway (storefront 0.77.3 - 总线程's review of 0.77.2, P3; brought
|
|
334
|
-
* over in 0.71.1): their `*.import.jsonl.tmp-*` is no day's file, so neither the 13
|
|
335
|
-
* months nor a purge of days would ever take it - yet it counts toward the ceiling.
|
|
336
|
-
* Gone with the next prune or purge once a day old.
|
|
337
|
-
*/
|
|
338
|
-
async staleImports() {
|
|
339
|
-
let names;
|
|
340
|
-
try {
|
|
341
|
-
names = await fs.readdir(this.eventsDir);
|
|
342
|
-
}
|
|
343
|
-
catch {
|
|
344
|
-
return [];
|
|
345
|
-
}
|
|
346
|
-
const out = [];
|
|
347
|
-
for (const name of names) {
|
|
348
|
-
if (!IMPORT_TMP.test(name))
|
|
349
|
-
continue;
|
|
350
|
-
const f = join(this.eventsDir, name);
|
|
351
|
-
const st = await fs.lstat(f).catch(() => null);
|
|
352
|
-
if (st && this.now() - st.mtimeMs > STALE_TMP_MS)
|
|
353
|
-
out.push(f);
|
|
354
|
-
}
|
|
355
|
-
return out;
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* Delete event files older than 13 months, and imports cut off a day ago or
|
|
359
|
-
* more. The day's totals (daily/) stay - they hold counts, no pseudonym.
|
|
360
|
-
* Returns the days deleted.
|
|
361
|
-
*/
|
|
362
|
-
async prune(today = dayOf(this.now())) {
|
|
363
|
-
const keepFrom = firstKeptDay(today);
|
|
364
|
-
for (const f of await this.staleImports()) {
|
|
365
|
-
await fs.unlink(f).catch((err) => this.fault('prune', err));
|
|
366
|
-
}
|
|
367
|
-
const gone = [];
|
|
368
|
-
for (const { day, files } of await this.days()) {
|
|
369
|
-
if (day >= keepFrom)
|
|
370
|
-
break;
|
|
371
|
-
for (const f of files) {
|
|
372
|
-
try {
|
|
373
|
-
await fs.unlink(f);
|
|
374
|
-
}
|
|
375
|
-
catch (err) {
|
|
376
|
-
this.fault('prune', err);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
gone.push(day);
|
|
380
|
-
}
|
|
381
|
-
return gone;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
/** Lines in a file, counted a line at a time; 0 for none. */
|
|
385
|
-
export const countLines = async (file) => {
|
|
386
|
-
let n = 0;
|
|
387
|
-
try {
|
|
388
|
-
await fs.access(file);
|
|
389
|
-
}
|
|
390
|
-
catch {
|
|
391
|
-
return 0;
|
|
392
|
-
}
|
|
393
|
-
const lines = createInterface({
|
|
394
|
-
input: createReadStream(file),
|
|
395
|
-
crlfDelay: Number.POSITIVE_INFINITY,
|
|
396
|
-
});
|
|
397
|
-
for await (const line of lines)
|
|
398
|
-
if (line)
|
|
399
|
-
n++;
|
|
400
|
-
return n;
|
|
401
|
-
};
|
|
402
|
-
/**
|
|
403
|
-
* An import's lines, written as they come - never a whole import in memory
|
|
404
|
-
* (总线程's review of 0.77.1, P3) - and held to the same ceilings as the
|
|
405
|
-
* connector's own: a day's file and the directory. Each day goes to a
|
|
406
|
-
* temporary file first, then replaces that day's earlier import whole - unless
|
|
407
|
-
* the earlier one had more lines (a log that has since rolled part of the day
|
|
408
|
-
* away).
|
|
409
|
-
*/
|
|
410
|
-
export class ImportWriter {
|
|
411
|
-
store;
|
|
412
|
-
buffers = new Map();
|
|
413
|
-
sizes = new Map();
|
|
414
|
-
counts = new Map();
|
|
415
|
-
capped = new Map();
|
|
416
|
-
added = 0;
|
|
417
|
-
tag = `${process.pid}-${Date.now()}`;
|
|
418
|
-
constructor(store) {
|
|
419
|
-
this.store = store;
|
|
420
|
-
}
|
|
421
|
-
tmp(day) {
|
|
422
|
-
return join(this.store.eventsDir, `${day}.import.jsonl.tmp-${this.tag}`);
|
|
423
|
-
}
|
|
424
|
-
async write(day) {
|
|
425
|
-
const lines = this.buffers.get(day);
|
|
426
|
-
if (!lines?.length)
|
|
427
|
-
return;
|
|
428
|
-
this.buffers.set(day, []);
|
|
429
|
-
await fs.mkdir(this.store.eventsDir, { recursive: true, mode: 0o700 });
|
|
430
|
-
await fs.appendFile(this.tmp(day), lines.join(''), { mode: 0o600 });
|
|
431
|
-
}
|
|
432
|
-
async add(e) {
|
|
433
|
-
const day = e.t.slice(0, 10);
|
|
434
|
-
if (!/^\d{4}-\d{2}-\d{2}$/.test(day))
|
|
435
|
-
return;
|
|
436
|
-
const line = `${JSON.stringify(e)}\n`;
|
|
437
|
-
const n = Buffer.byteLength(line);
|
|
438
|
-
const size = this.sizes.get(day) ?? 0;
|
|
439
|
-
if (size + n > this.store.maxDayBytes ||
|
|
440
|
-
this.store.bytes + this.added + n > this.store.maxTotalBytes) {
|
|
441
|
-
this.capped.set(day, (this.capped.get(day) ?? 0) + 1);
|
|
442
|
-
return;
|
|
443
|
-
}
|
|
444
|
-
this.sizes.set(day, size + n);
|
|
445
|
-
this.counts.set(day, (this.counts.get(day) ?? 0) + 1);
|
|
446
|
-
this.added += n;
|
|
447
|
-
const buf = this.buffers.get(day) ?? [];
|
|
448
|
-
buf.push(line);
|
|
449
|
-
this.buffers.set(day, buf);
|
|
450
|
-
if (buf.length >= 1_000)
|
|
451
|
-
await this.write(day);
|
|
452
|
-
}
|
|
453
|
-
async finish() {
|
|
454
|
-
const out = [];
|
|
455
|
-
const days = [...new Set([...this.counts.keys(), ...this.capped.keys()])].sort();
|
|
456
|
-
for (const day of days) {
|
|
457
|
-
await this.write(day);
|
|
458
|
-
const events = this.counts.get(day) ?? 0;
|
|
459
|
-
const capped = this.capped.get(day);
|
|
460
|
-
const file = join(this.store.eventsDir, `${day}.import.jsonl`);
|
|
461
|
-
const before = await countLines(file);
|
|
462
|
-
if (before > events) {
|
|
463
|
-
await fs.unlink(this.tmp(day)).catch(() => { });
|
|
464
|
-
out.push({ day, events, kept: before, ...(capped ? { capped } : {}) });
|
|
465
|
-
continue;
|
|
466
|
-
}
|
|
467
|
-
if (events)
|
|
468
|
-
await fs.rename(this.tmp(day), file);
|
|
469
|
-
out.push({ day, events, ...(capped ? { capped } : {}) });
|
|
470
|
-
}
|
|
471
|
-
await this.store.measure();
|
|
472
|
-
return out;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
//# sourceMappingURL=store.js.map
|
package/dist/usage/store.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/usage/store.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,4EAA4E;AAC5E,2EAA2E;AAC3E,wDAAwD;AACxD,EAAE;AACF,kFAAkF;AAClF,EAAE;AACF,iFAAiF;AACjF,wFAAwF;AACxF,6EAA6E;AAC7E,EAAE;AACF,gFAAgF;AAChF,+EAA+E;AAC/E,gFAAgF;AAChF,4EAA4E;AAC5E,qDAAqD;AACrD,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,EA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