@rigxyz/tapd 0.4.1 → 0.5.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/bin.js +2 -2
- package/dist/bin.js.map +1 -1
- package/dist/{chunk-JBX2ZRMD.js → chunk-XMYPUAYD.js} +96 -81
- package/dist/chunk-XMYPUAYD.js.map +1 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +1 -1
- package/package.json +1 -3
- package/dist/chunk-JBX2ZRMD.js.map +0 -1
|
@@ -293,9 +293,8 @@ function joinUrl(base, suffix) {
|
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
// src/state-db.ts
|
|
296
|
-
import { mkdirSync as mkdirSync2 } from "fs";
|
|
296
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2, renameSync } from "fs";
|
|
297
297
|
import { dirname as dirname2 } from "path";
|
|
298
|
-
import Database from "better-sqlite3";
|
|
299
298
|
var CURSOR_PREFIX = "chg_";
|
|
300
299
|
function cursorGreaterThan(a, b) {
|
|
301
300
|
const an = a.startsWith(CURSOR_PREFIX) ? safeBigInt(a.slice(CURSOR_PREFIX.length)) : null;
|
|
@@ -311,93 +310,109 @@ function safeBigInt(s) {
|
|
|
311
310
|
return null;
|
|
312
311
|
}
|
|
313
312
|
}
|
|
314
|
-
var
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
);
|
|
327
|
-
|
|
313
|
+
var pendingFlushers = /* @__PURE__ */ new Set();
|
|
314
|
+
var exitHookInstalled = false;
|
|
315
|
+
function installExitHook() {
|
|
316
|
+
if (exitHookInstalled) return;
|
|
317
|
+
exitHookInstalled = true;
|
|
318
|
+
process.once("exit", () => {
|
|
319
|
+
for (const flush of pendingFlushers) {
|
|
320
|
+
try {
|
|
321
|
+
flush();
|
|
322
|
+
} catch {
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
function loadStore(dbPath) {
|
|
328
|
+
try {
|
|
329
|
+
const parsed = JSON.parse(readFileSync2(dbPath, "utf8"));
|
|
330
|
+
if (parsed && parsed.version === 1 && parsed.meta && parsed.paths) {
|
|
331
|
+
return { version: 1, meta: parsed.meta, paths: parsed.paths };
|
|
332
|
+
}
|
|
333
|
+
} catch {
|
|
334
|
+
}
|
|
335
|
+
return { version: 1, meta: {}, paths: {} };
|
|
336
|
+
}
|
|
328
337
|
function openStateDb(dbPath) {
|
|
329
338
|
mkdirSync2(dirname2(dbPath), { recursive: true });
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
339
|
+
const store = loadStore(dbPath);
|
|
340
|
+
let dirty = false;
|
|
341
|
+
let timer = null;
|
|
342
|
+
const flush = () => {
|
|
343
|
+
if (timer) {
|
|
344
|
+
clearTimeout(timer);
|
|
345
|
+
timer = null;
|
|
346
|
+
}
|
|
347
|
+
if (!dirty) return;
|
|
348
|
+
const tmp = `${dbPath}.tmp`;
|
|
349
|
+
writeFileSync2(tmp, JSON.stringify(store), "utf8");
|
|
350
|
+
renameSync(tmp, dbPath);
|
|
351
|
+
dirty = false;
|
|
352
|
+
};
|
|
353
|
+
const schedule = () => {
|
|
354
|
+
dirty = true;
|
|
355
|
+
if (timer) return;
|
|
356
|
+
timer = setTimeout(flush, 100);
|
|
357
|
+
timer.unref?.();
|
|
358
|
+
};
|
|
359
|
+
pendingFlushers.add(flush);
|
|
360
|
+
installExitHook();
|
|
350
361
|
return {
|
|
351
362
|
getCursor() {
|
|
352
|
-
|
|
353
|
-
return row?.value ?? "chg_0";
|
|
363
|
+
return store.meta.cursor ?? "chg_0";
|
|
354
364
|
},
|
|
355
365
|
setCursor(cursor) {
|
|
356
|
-
const current =
|
|
366
|
+
const current = store.meta.cursor;
|
|
357
367
|
if (current && !cursorGreaterThan(cursor, current)) return;
|
|
358
|
-
|
|
368
|
+
store.meta.cursor = cursor;
|
|
369
|
+
schedule();
|
|
359
370
|
},
|
|
360
371
|
upsertPath(state) {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
372
|
+
store.paths[state.path] = {
|
|
373
|
+
lastAppliedChangeId: state.lastAppliedChangeId,
|
|
374
|
+
lastSeenHash: state.lastSeenHash,
|
|
375
|
+
localDirty: state.localDirty,
|
|
376
|
+
lastScanAt: state.lastScanAt
|
|
377
|
+
};
|
|
378
|
+
schedule();
|
|
368
379
|
},
|
|
369
380
|
getPath(path) {
|
|
370
|
-
const
|
|
371
|
-
if (!
|
|
381
|
+
const r = store.paths[path];
|
|
382
|
+
if (!r) return null;
|
|
372
383
|
return {
|
|
373
|
-
path
|
|
374
|
-
lastAppliedChangeId:
|
|
375
|
-
lastSeenHash:
|
|
376
|
-
localDirty:
|
|
377
|
-
lastScanAt:
|
|
384
|
+
path,
|
|
385
|
+
lastAppliedChangeId: r.lastAppliedChangeId,
|
|
386
|
+
lastSeenHash: r.lastSeenHash,
|
|
387
|
+
localDirty: r.localDirty,
|
|
388
|
+
lastScanAt: r.lastScanAt
|
|
378
389
|
};
|
|
379
390
|
},
|
|
380
391
|
deletePath(path) {
|
|
381
|
-
|
|
392
|
+
if (path in store.paths) {
|
|
393
|
+
delete store.paths[path];
|
|
394
|
+
schedule();
|
|
395
|
+
}
|
|
382
396
|
},
|
|
383
397
|
listPaths() {
|
|
384
|
-
return
|
|
398
|
+
return Object.keys(store.paths);
|
|
385
399
|
},
|
|
386
400
|
setMeta(key, value) {
|
|
387
|
-
|
|
401
|
+
store.meta[key] = value;
|
|
402
|
+
schedule();
|
|
388
403
|
},
|
|
389
404
|
getMeta(key) {
|
|
390
|
-
|
|
391
|
-
return row?.value ?? null;
|
|
405
|
+
return store.meta[key] ?? null;
|
|
392
406
|
},
|
|
393
407
|
close() {
|
|
394
|
-
|
|
408
|
+
flush();
|
|
409
|
+
pendingFlushers.delete(flush);
|
|
395
410
|
}
|
|
396
411
|
};
|
|
397
412
|
}
|
|
398
413
|
|
|
399
414
|
// src/tapignore.ts
|
|
400
|
-
import { existsSync as existsSync2, readFileSync as
|
|
415
|
+
import { existsSync as existsSync2, readFileSync as readFileSync3 } from "fs";
|
|
401
416
|
import { join as join2 } from "path";
|
|
402
417
|
import ignore from "ignore";
|
|
403
418
|
var BUILTIN_IGNORE_LINES = [
|
|
@@ -433,7 +448,7 @@ function loadIgnore(rootDir) {
|
|
|
433
448
|
ig.add(BUILTIN_IGNORE_LINES.join("\n"));
|
|
434
449
|
const projectIgnore = join2(rootDir, ".tapignore");
|
|
435
450
|
if (existsSync2(projectIgnore)) {
|
|
436
|
-
ig.add(
|
|
451
|
+
ig.add(readFileSync3(projectIgnore, "utf8"));
|
|
437
452
|
}
|
|
438
453
|
return ig;
|
|
439
454
|
}
|
|
@@ -568,7 +583,7 @@ async function hashFile(absPath) {
|
|
|
568
583
|
|
|
569
584
|
// src/init.ts
|
|
570
585
|
import { createHash as createHash2 } from "crypto";
|
|
571
|
-
import { readFileSync as
|
|
586
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
572
587
|
import { join as join4 } from "path";
|
|
573
588
|
|
|
574
589
|
// src/pool.ts
|
|
@@ -647,7 +662,7 @@ async function init(opts) {
|
|
|
647
662
|
reused += 1;
|
|
648
663
|
return;
|
|
649
664
|
}
|
|
650
|
-
const bytes =
|
|
665
|
+
const bytes = readFileSync4(join4(opts.rootDir, f.path));
|
|
651
666
|
const actual = sha256OfBuffer(bytes);
|
|
652
667
|
if (actual !== f.hash) {
|
|
653
668
|
mutatedDuringScan.add(f.path);
|
|
@@ -818,10 +833,10 @@ import {
|
|
|
818
833
|
existsSync as existsSync3,
|
|
819
834
|
mkdirSync as mkdirSync3,
|
|
820
835
|
readdirSync as readdirSync2,
|
|
821
|
-
readFileSync as
|
|
836
|
+
readFileSync as readFileSync5,
|
|
822
837
|
realpathSync,
|
|
823
838
|
statSync as statSync2,
|
|
824
|
-
writeFileSync as
|
|
839
|
+
writeFileSync as writeFileSync3
|
|
825
840
|
} from "fs";
|
|
826
841
|
import { dirname as dirname3, isAbsolute, join as join6, relative } from "path";
|
|
827
842
|
var NAME_RE = /^[a-z0-9][a-z0-9_-]*$/;
|
|
@@ -907,14 +922,14 @@ var MOUNT_FILE_SUFFIX = ".local.json";
|
|
|
907
922
|
function writeImportMount(rootDir, name, mount) {
|
|
908
923
|
const path = importMountFile(rootDir, name);
|
|
909
924
|
mkdirSync3(dirname3(path), { recursive: true });
|
|
910
|
-
|
|
925
|
+
writeFileSync3(path, JSON.stringify(mount, null, 2) + "\n", { mode: 384 });
|
|
911
926
|
}
|
|
912
927
|
function readImportMount(rootDir, name) {
|
|
913
928
|
const file = importMountFile(rootDir, name);
|
|
914
929
|
if (!existsSync3(file)) return { ok: false, reason: "missing_token_file" };
|
|
915
930
|
let parsed;
|
|
916
931
|
try {
|
|
917
|
-
parsed = JSON.parse(
|
|
932
|
+
parsed = JSON.parse(readFileSync5(file, "utf8"));
|
|
918
933
|
} catch {
|
|
919
934
|
return { ok: false, reason: "malformed_json" };
|
|
920
935
|
}
|
|
@@ -998,7 +1013,7 @@ function pathsOverlap(a, b) {
|
|
|
998
1013
|
}
|
|
999
1014
|
|
|
1000
1015
|
// src/import-invite.ts
|
|
1001
|
-
import { existsSync as existsSync4, readFileSync as
|
|
1016
|
+
import { existsSync as existsSync4, readFileSync as readFileSync6, rmSync } from "fs";
|
|
1002
1017
|
import { dirname as dirname4, join as joinPath2 } from "path";
|
|
1003
1018
|
var ImportValidationFailed = class extends Error {
|
|
1004
1019
|
constructor(reason) {
|
|
@@ -1095,7 +1110,7 @@ function readRawMount(rootDir, name) {
|
|
|
1095
1110
|
const file = importMountFile(rootDir, name);
|
|
1096
1111
|
if (!existsSync4(file)) return null;
|
|
1097
1112
|
try {
|
|
1098
|
-
return JSON.parse(
|
|
1113
|
+
return JSON.parse(readFileSync6(file, "utf8"));
|
|
1099
1114
|
} catch {
|
|
1100
1115
|
return null;
|
|
1101
1116
|
}
|
|
@@ -1147,11 +1162,11 @@ import {
|
|
|
1147
1162
|
lstatSync,
|
|
1148
1163
|
mkdirSync as mkdirSync4,
|
|
1149
1164
|
readdirSync as readdirSync3,
|
|
1150
|
-
readFileSync as
|
|
1151
|
-
renameSync,
|
|
1165
|
+
readFileSync as readFileSync7,
|
|
1166
|
+
renameSync as renameSync2,
|
|
1152
1167
|
rmdirSync,
|
|
1153
1168
|
rmSync as rmSync2,
|
|
1154
|
-
writeFileSync as
|
|
1169
|
+
writeFileSync as writeFileSync4
|
|
1155
1170
|
} from "fs";
|
|
1156
1171
|
import { basename, dirname as dirname5, extname, join as join7, sep as sep2 } from "path";
|
|
1157
1172
|
var STATE_KEY_CONFLICT_COUNT = "conflict_count";
|
|
@@ -1173,7 +1188,7 @@ function sha256Hex(bytes) {
|
|
|
1173
1188
|
return createHash3("sha256").update(bytes).digest("hex");
|
|
1174
1189
|
}
|
|
1175
1190
|
function sha256OfFile(absPath) {
|
|
1176
|
-
return `sha256:${sha256Hex(
|
|
1191
|
+
return `sha256:${sha256Hex(readFileSync7(absPath))}`;
|
|
1177
1192
|
}
|
|
1178
1193
|
function conflictSidecarPath(path, ev) {
|
|
1179
1194
|
const dir = dirname5(path);
|
|
@@ -1306,8 +1321,8 @@ async function applyEvent(opts) {
|
|
|
1306
1321
|
const sidecarAbs = join7(rootDir, sidecarPath);
|
|
1307
1322
|
mkdirSync4(dirname5(sidecarAbs), { recursive: true });
|
|
1308
1323
|
const tmp2 = `${sidecarAbs}.tap-tmp.${randomBytes(6).toString("hex")}`;
|
|
1309
|
-
|
|
1310
|
-
|
|
1324
|
+
writeFileSync4(tmp2, bytes, { mode: ev.executable ? 493 : 420 });
|
|
1325
|
+
renameSync2(tmp2, sidecarAbs);
|
|
1311
1326
|
stateDb.upsertPath({
|
|
1312
1327
|
path: ev.path,
|
|
1313
1328
|
lastAppliedChangeId: ev.id,
|
|
@@ -1320,8 +1335,8 @@ async function applyEvent(opts) {
|
|
|
1320
1335
|
}
|
|
1321
1336
|
mkdirSync4(dirname5(abs), { recursive: true });
|
|
1322
1337
|
const tmp = `${abs}.tap-tmp.${randomBytes(6).toString("hex")}`;
|
|
1323
|
-
|
|
1324
|
-
|
|
1338
|
+
writeFileSync4(tmp, bytes, { mode: ev.executable ? 493 : 420 });
|
|
1339
|
+
renameSync2(tmp, abs);
|
|
1325
1340
|
stateDb.upsertPath({
|
|
1326
1341
|
path: ev.path,
|
|
1327
1342
|
lastAppliedChangeId: ev.id,
|
|
@@ -1633,7 +1648,7 @@ async function startSubscription(opts) {
|
|
|
1633
1648
|
|
|
1634
1649
|
// src/uploader.ts
|
|
1635
1650
|
import { createHash as createHash4 } from "crypto";
|
|
1636
|
-
import { readFileSync as
|
|
1651
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
1637
1652
|
import { join as join8 } from "path";
|
|
1638
1653
|
var UPLOAD_CONCURRENCY2 = 8;
|
|
1639
1654
|
function sha256OfBuffer2(bytes) {
|
|
@@ -1713,7 +1728,7 @@ async function scanAndPush(opts) {
|
|
|
1713
1728
|
reused += 1;
|
|
1714
1729
|
return;
|
|
1715
1730
|
}
|
|
1716
|
-
const bytes =
|
|
1731
|
+
const bytes = readFileSync8(join8(rootDir, f.path));
|
|
1717
1732
|
const actual = sha256OfBuffer2(bytes);
|
|
1718
1733
|
if (actual !== f.hash) {
|
|
1719
1734
|
mutatedPaths.add(f.path);
|
|
@@ -2022,4 +2037,4 @@ export {
|
|
|
2022
2037
|
scanAndPush,
|
|
2023
2038
|
start
|
|
2024
2039
|
};
|
|
2025
|
-
//# sourceMappingURL=chunk-
|
|
2040
|
+
//# sourceMappingURL=chunk-XMYPUAYD.js.map
|