zen-fs-config 0.3.23 → 0.3.24
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/index.d.mts +0 -3
- package/dist/index.d.ts +0 -3
- package/dist/index.js +5 -52
- package/dist/index.mjs +5 -52
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -244,9 +244,6 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
244
244
|
* Called automatically by createConfigRepo() after setupSync().
|
|
245
245
|
*/
|
|
246
246
|
syncMetaToReplicas(): Promise<void>;
|
|
247
|
-
/** Compare two file contents (handles Uint8Array, ArrayBuffer, string, Buffer). */
|
|
248
|
-
private bufferEqual;
|
|
249
|
-
private toUint8Array;
|
|
250
247
|
getSyncStatuses(): Map<string, SyncPairStatus>;
|
|
251
248
|
resolveConflict(conflictId: string, mergedContent: unknown): Promise<void>;
|
|
252
249
|
listConflicts(): Promise<ConflictArchive[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -244,9 +244,6 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
244
244
|
* Called automatically by createConfigRepo() after setupSync().
|
|
245
245
|
*/
|
|
246
246
|
syncMetaToReplicas(): Promise<void>;
|
|
247
|
-
/** Compare two file contents (handles Uint8Array, ArrayBuffer, string, Buffer). */
|
|
248
|
-
private bufferEqual;
|
|
249
|
-
private toUint8Array;
|
|
250
247
|
getSyncStatuses(): Map<string, SyncPairStatus>;
|
|
251
248
|
resolveConflict(conflictId: string, mergedContent: unknown): Promise<void>;
|
|
252
249
|
listConflicts(): Promise<ConflictArchive[]>;
|
package/dist/index.js
CHANGED
|
@@ -667,59 +667,12 @@ var ConfigRepo = class {
|
|
|
667
667
|
*/
|
|
668
668
|
async syncMetaToReplicas() {
|
|
669
669
|
this.assertNotDisposed();
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
vContent = await this.cachedFS.readFile(vPath);
|
|
676
|
-
} catch {
|
|
677
|
-
}
|
|
678
|
-
for (const [id, replica] of this.replicaBackends) {
|
|
679
|
-
try {
|
|
680
|
-
let needWrite = true;
|
|
681
|
-
try {
|
|
682
|
-
const existing = await replica.syncable.readFile(BACKENDS_FILE);
|
|
683
|
-
if (this.bufferEqual(content, existing)) {
|
|
684
|
-
needWrite = false;
|
|
685
|
-
console.log(`[ConfigRepo] ${BACKENDS_FILE} already up-to-date on ${id}, skipping`);
|
|
686
|
-
}
|
|
687
|
-
} catch {
|
|
688
|
-
}
|
|
689
|
-
if (needWrite) {
|
|
690
|
-
await replica.syncable.writeFile(BACKENDS_FILE, content);
|
|
691
|
-
console.log(`[ConfigRepo] Synced ${BACKENDS_FILE} to replica ${id}`);
|
|
692
|
-
}
|
|
693
|
-
if (vContent) {
|
|
694
|
-
try {
|
|
695
|
-
await replica.syncable.writeFile(vPath, vContent);
|
|
696
|
-
} catch (err) {
|
|
697
|
-
console.error(`[ConfigRepo] Failed to sync ${vPath} to ${id}:`, err.message);
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
} catch (err) {
|
|
701
|
-
console.error(`[ConfigRepo] Failed to sync ${BACKENDS_FILE} to ${id}:`, err.message);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
} catch {
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
/** Compare two file contents (handles Uint8Array, ArrayBuffer, string, Buffer). */
|
|
708
|
-
bufferEqual(a, b) {
|
|
709
|
-
const ua = this.toUint8Array(a);
|
|
710
|
-
const ub = this.toUint8Array(b);
|
|
711
|
-
if (ua.length !== ub.length) return false;
|
|
712
|
-
for (let i = 0; i < ua.length; i++) {
|
|
713
|
-
if (ua[i] !== ub[i]) return false;
|
|
670
|
+
const results = await this.flush();
|
|
671
|
+
for (const result of results) {
|
|
672
|
+
console.log(
|
|
673
|
+
`[ConfigRepo] syncMetaToReplicas: ${result.pairId} +${result.filesCreated}/~${result.filesUpdated}/-${result.filesDeleted} skip:${result.filesSkipped} ${result.durationMs}ms`
|
|
674
|
+
);
|
|
714
675
|
}
|
|
715
|
-
return true;
|
|
716
|
-
}
|
|
717
|
-
toUint8Array(raw) {
|
|
718
|
-
if (raw instanceof ArrayBuffer) return new Uint8Array(raw);
|
|
719
|
-
if (raw instanceof Uint8Array) return raw;
|
|
720
|
-
if (typeof raw === "string") return new TextEncoder().encode(raw);
|
|
721
|
-
if (Buffer.isBuffer(raw)) return new Uint8Array(raw.buffer, raw.byteOffset, raw.byteLength);
|
|
722
|
-
return new Uint8Array(raw);
|
|
723
676
|
}
|
|
724
677
|
getSyncStatuses() {
|
|
725
678
|
this.assertNotDisposed();
|
package/dist/index.mjs
CHANGED
|
@@ -618,59 +618,12 @@ var ConfigRepo = class {
|
|
|
618
618
|
*/
|
|
619
619
|
async syncMetaToReplicas() {
|
|
620
620
|
this.assertNotDisposed();
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
vContent = await this.cachedFS.readFile(vPath);
|
|
627
|
-
} catch {
|
|
628
|
-
}
|
|
629
|
-
for (const [id, replica] of this.replicaBackends) {
|
|
630
|
-
try {
|
|
631
|
-
let needWrite = true;
|
|
632
|
-
try {
|
|
633
|
-
const existing = await replica.syncable.readFile(BACKENDS_FILE);
|
|
634
|
-
if (this.bufferEqual(content, existing)) {
|
|
635
|
-
needWrite = false;
|
|
636
|
-
console.log(`[ConfigRepo] ${BACKENDS_FILE} already up-to-date on ${id}, skipping`);
|
|
637
|
-
}
|
|
638
|
-
} catch {
|
|
639
|
-
}
|
|
640
|
-
if (needWrite) {
|
|
641
|
-
await replica.syncable.writeFile(BACKENDS_FILE, content);
|
|
642
|
-
console.log(`[ConfigRepo] Synced ${BACKENDS_FILE} to replica ${id}`);
|
|
643
|
-
}
|
|
644
|
-
if (vContent) {
|
|
645
|
-
try {
|
|
646
|
-
await replica.syncable.writeFile(vPath, vContent);
|
|
647
|
-
} catch (err) {
|
|
648
|
-
console.error(`[ConfigRepo] Failed to sync ${vPath} to ${id}:`, err.message);
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
} catch (err) {
|
|
652
|
-
console.error(`[ConfigRepo] Failed to sync ${BACKENDS_FILE} to ${id}:`, err.message);
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
} catch {
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
/** Compare two file contents (handles Uint8Array, ArrayBuffer, string, Buffer). */
|
|
659
|
-
bufferEqual(a, b) {
|
|
660
|
-
const ua = this.toUint8Array(a);
|
|
661
|
-
const ub = this.toUint8Array(b);
|
|
662
|
-
if (ua.length !== ub.length) return false;
|
|
663
|
-
for (let i = 0; i < ua.length; i++) {
|
|
664
|
-
if (ua[i] !== ub[i]) return false;
|
|
621
|
+
const results = await this.flush();
|
|
622
|
+
for (const result of results) {
|
|
623
|
+
console.log(
|
|
624
|
+
`[ConfigRepo] syncMetaToReplicas: ${result.pairId} +${result.filesCreated}/~${result.filesUpdated}/-${result.filesDeleted} skip:${result.filesSkipped} ${result.durationMs}ms`
|
|
625
|
+
);
|
|
665
626
|
}
|
|
666
|
-
return true;
|
|
667
|
-
}
|
|
668
|
-
toUint8Array(raw) {
|
|
669
|
-
if (raw instanceof ArrayBuffer) return new Uint8Array(raw);
|
|
670
|
-
if (raw instanceof Uint8Array) return raw;
|
|
671
|
-
if (typeof raw === "string") return new TextEncoder().encode(raw);
|
|
672
|
-
if (Buffer.isBuffer(raw)) return new Uint8Array(raw.buffer, raw.byteOffset, raw.byteLength);
|
|
673
|
-
return new Uint8Array(raw);
|
|
674
627
|
}
|
|
675
628
|
getSyncStatuses() {
|
|
676
629
|
this.assertNotDisposed();
|