sliftutils 1.4.22 → 1.4.43

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sliftutils",
3
- "version": "1.4.22",
3
+ "version": "1.4.43",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -110,6 +110,13 @@ function nullJoin(a: string, b: string): string {
110
110
  return a + NULL + b;
111
111
  }
112
112
 
113
+ function fmtBytes(n: number): string {
114
+ if (n < 1024) return n + "B";
115
+ if (n < 1024 * 1024) return (n / 1024).toFixed(1) + "KB";
116
+ if (n < 1024 * 1024 * 1024) return (n / 1024 / 1024).toFixed(1) + "MB";
117
+ return (n / 1024 / 1024 / 1024).toFixed(2) + "GB";
118
+ }
119
+
113
120
  // A tiny reactivity seam so this file has zero dependency on mobx (or any specific UI framework). The
114
121
  // reactive in-memory state (the overlay map + the load/reset lifecycle) is plain; whenever it's read
115
122
  // we "observe" a signal, and whenever it changes we "invalidate" that signal. A consumer that wants
@@ -1108,6 +1115,16 @@ export class BulkDatabaseBase<T extends { key: string }> {
1108
1115
  const readers = streamReader ? [streamReader, ...bulkReaders] : bulkReaders;
1109
1116
  if (!readers.length) return false;
1110
1117
 
1118
+ // Log the inputs of a REAL merge (files + on-disk sizes). Only here, never for the planning checks
1119
+ // in testMerge/findDuplicateGroups, so the log marks actual rewrites and their before/after I/O.
1120
+ const inputs = [
1121
+ ...await Promise.all(consumedBulk.map(async f => ({ name: f.fileName, size: (await storage.getInfo(f.fileName).catch(() => undefined))?.size ?? 0 }))),
1122
+ ...streamFiles.map(f => ({ name: f.fileName, size: streamData.sizes.get(f.fileName) ?? 0 })),
1123
+ ];
1124
+ const inTotal = inputs.reduce((a, f) => a + f.size, 0);
1125
+ console.log(`${blue(this.name)} merge: reading ${inputs.length} files (${fmtBytes(inTotal)})`);
1126
+ for (const f of inputs) console.log(` in ${f.name} ${fmtBytes(f.size)}`);
1127
+
1111
1128
  const { rows, times, deletes } = await this.resolveReaders(readers);
1112
1129
 
1113
1130
  // Write all outputs BEFORE deleting any input, so a throw mid-write just leaves duplicates.
@@ -1122,11 +1139,19 @@ export class BulkDatabaseBase<T extends { key: string }> {
1122
1139
  // Carry surviving tombstones forward only if older files exist outside this merge that they still
1123
1140
  // need to suppress; when this merge includes the oldest data there's nothing older to suppress.
1124
1141
  const carriedDeletes = includesOldest ? 0 : deletes.size;
1142
+ const outNames = [...newNames];
1125
1143
  if (carriedDeletes) {
1126
1144
  const carryName = `stream_${Date.now()}_${Math.random().toString(36).slice(2, 10)}${STREAM_EXTENSION}`;
1127
1145
  await storage.set(carryName, frameDeletes([...deletes].map(([key, time]) => ({ time, key }))));
1146
+ outNames.push(carryName);
1128
1147
  }
1129
1148
 
1149
+ // Log the result (files + on-disk sizes), so the before→after of the merge is visible.
1150
+ const outputs = await Promise.all(outNames.map(async n => ({ name: n, size: (await storage.getInfo(n).catch(() => undefined))?.size ?? 0 })));
1151
+ const outTotal = outputs.reduce((a, f) => a + f.size, 0);
1152
+ console.log(`${blue(this.name)} merge: wrote ${outputs.length} files (${fmtBytes(outTotal)}, from ${fmtBytes(inTotal)})${carriedDeletes ? `, ${carriedDeletes} tombstones carried` : ""}`);
1153
+ for (const f of outputs) console.log(` out ${f.name} ${fmtBytes(f.size)}`);
1154
+
1130
1155
  const remove = async (name: string) => { try { await storage.remove(name); } catch { /* already gone */ } };
1131
1156
  for (const f of consumedBulk) await remove(f.fileName);
1132
1157
  for (const f of streamFiles) {