zen-fs-config 0.3.22 → 0.3.23
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 +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +42 -4
- package/dist/index.mjs +42 -4
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -244,6 +244,9 @@ 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;
|
|
247
250
|
getSyncStatuses(): Map<string, SyncPairStatus>;
|
|
248
251
|
resolveConflict(conflictId: string, mergedContent: unknown): Promise<void>;
|
|
249
252
|
listConflicts(): Promise<ConflictArchive[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -244,6 +244,9 @@ 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;
|
|
247
250
|
getSyncStatuses(): Map<string, SyncPairStatus>;
|
|
248
251
|
resolveConflict(conflictId: string, mergedContent: unknown): Promise<void>;
|
|
249
252
|
listConflicts(): Promise<ConflictArchive[]>;
|
package/dist/index.js
CHANGED
|
@@ -670,12 +670,33 @@ var ConfigRepo = class {
|
|
|
670
670
|
try {
|
|
671
671
|
const content = await this.cachedFS.readFile(BACKENDS_FILE);
|
|
672
672
|
const vPath = versionPathFor(BACKENDS_FILE);
|
|
673
|
-
|
|
673
|
+
let vContent;
|
|
674
|
+
try {
|
|
675
|
+
vContent = await this.cachedFS.readFile(vPath);
|
|
676
|
+
} catch {
|
|
677
|
+
}
|
|
674
678
|
for (const [id, replica] of this.replicaBackends) {
|
|
675
679
|
try {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
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
|
+
}
|
|
679
700
|
} catch (err) {
|
|
680
701
|
console.error(`[ConfigRepo] Failed to sync ${BACKENDS_FILE} to ${id}:`, err.message);
|
|
681
702
|
}
|
|
@@ -683,6 +704,23 @@ var ConfigRepo = class {
|
|
|
683
704
|
} catch {
|
|
684
705
|
}
|
|
685
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;
|
|
714
|
+
}
|
|
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
|
+
}
|
|
686
724
|
getSyncStatuses() {
|
|
687
725
|
this.assertNotDisposed();
|
|
688
726
|
return this.syncEngine.getStatusAll();
|
package/dist/index.mjs
CHANGED
|
@@ -621,12 +621,33 @@ var ConfigRepo = class {
|
|
|
621
621
|
try {
|
|
622
622
|
const content = await this.cachedFS.readFile(BACKENDS_FILE);
|
|
623
623
|
const vPath = versionPathFor(BACKENDS_FILE);
|
|
624
|
-
|
|
624
|
+
let vContent;
|
|
625
|
+
try {
|
|
626
|
+
vContent = await this.cachedFS.readFile(vPath);
|
|
627
|
+
} catch {
|
|
628
|
+
}
|
|
625
629
|
for (const [id, replica] of this.replicaBackends) {
|
|
626
630
|
try {
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
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
|
+
}
|
|
630
651
|
} catch (err) {
|
|
631
652
|
console.error(`[ConfigRepo] Failed to sync ${BACKENDS_FILE} to ${id}:`, err.message);
|
|
632
653
|
}
|
|
@@ -634,6 +655,23 @@ var ConfigRepo = class {
|
|
|
634
655
|
} catch {
|
|
635
656
|
}
|
|
636
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;
|
|
665
|
+
}
|
|
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
|
+
}
|
|
637
675
|
getSyncStatuses() {
|
|
638
676
|
this.assertNotDisposed();
|
|
639
677
|
return this.syncEngine.getStatusAll();
|