zen-fs-config 0.5.46 → 0.5.48
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 +302 -34
- package/dist/index.d.ts +302 -34
- package/dist/index.js +1218 -289
- package/dist/index.mjs +1204 -290
- package/dist/zen-fs-config.js +1196 -290
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -347,6 +347,8 @@ interface AppDataGroupDescriptor {
|
|
|
347
347
|
groupType: 'data-sync';
|
|
348
348
|
/** User-editable display name. `id` is the stable identifier. */
|
|
349
349
|
name?: string;
|
|
350
|
+
/** Capability overrides (versions/conflicts are opt-in for data groups). */
|
|
351
|
+
features?: Partial<SyncGroupFeatures>;
|
|
350
352
|
backends: AppDataBackendDescriptor[];
|
|
351
353
|
}
|
|
352
354
|
/** Descriptor for the config-sync group itself (display metadata only). */
|
|
@@ -355,7 +357,7 @@ interface ConfigSyncGroupDescriptor {
|
|
|
355
357
|
/** User-editable display name. The group has no separate id. */
|
|
356
358
|
name?: string;
|
|
357
359
|
}
|
|
358
|
-
/** Per-backend sync state of a
|
|
360
|
+
/** Per-backend sync state of a group. */
|
|
359
361
|
interface BackendSyncState {
|
|
360
362
|
backendId: string;
|
|
361
363
|
/** Pair id when the backend instance was created and paired successfully. */
|
|
@@ -369,40 +371,68 @@ interface BackendSyncState {
|
|
|
369
371
|
timestamp: number;
|
|
370
372
|
};
|
|
371
373
|
}
|
|
372
|
-
/**
|
|
373
|
-
|
|
374
|
+
/** Structural discriminator for a sync group. */
|
|
375
|
+
type SyncGroupKind = 'config' | 'data';
|
|
376
|
+
/** Capability switches, derived from `kind` + the group descriptor. */
|
|
377
|
+
interface SyncGroupFeatures {
|
|
378
|
+
tombstones: boolean;
|
|
379
|
+
versions: boolean;
|
|
380
|
+
conflicts: boolean;
|
|
381
|
+
/** Config payload: app config, node config, group descriptors. */
|
|
382
|
+
configHost: boolean;
|
|
383
|
+
/** Whether the product layer may read/write the group root directly. */
|
|
384
|
+
appData: boolean;
|
|
385
|
+
}
|
|
386
|
+
/** Content of `.meta/group.json` — the unified group descriptor. */
|
|
387
|
+
interface GroupDescriptor {
|
|
388
|
+
schemaVersion: 1;
|
|
389
|
+
kind: SyncGroupKind;
|
|
390
|
+
/** Group id (`config` for the config-sync group, the descriptor id otherwise). */
|
|
391
|
+
id?: string;
|
|
392
|
+
/** User-editable display name. */
|
|
393
|
+
name?: string;
|
|
394
|
+
features?: Partial<SyncGroupFeatures>;
|
|
395
|
+
updatedAt?: number;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Common handle shared by config-sync and data-sync groups.
|
|
399
|
+
* The config group is the capability superset (see ConfigSyncGroupHandle).
|
|
400
|
+
*/
|
|
401
|
+
interface SyncGroupHandle {
|
|
374
402
|
readonly groupId: string;
|
|
375
403
|
readonly appId: string;
|
|
376
|
-
|
|
404
|
+
readonly kind: SyncGroupKind;
|
|
405
|
+
/** Derived, never persisted separately from the descriptor. */
|
|
406
|
+
readonly features: SyncGroupFeatures;
|
|
407
|
+
readonly name?: string;
|
|
408
|
+
/** Direct fs view; metadata paths (`.meta`, `.config`) are hidden. */
|
|
377
409
|
readonly fs: typeof node_fs;
|
|
378
|
-
/** Get sync status for this data group's sync pairs. */
|
|
379
410
|
getSyncStatuses(): Map<string, SyncPairStatus>;
|
|
380
|
-
/**
|
|
381
|
-
* Per-backend sync state, including descriptors that failed to connect and
|
|
382
|
-
* therefore have no pair (they do not appear in getSyncStatuses()).
|
|
383
|
-
*/
|
|
384
411
|
getBackendSyncStates(): Map<string, BackendSyncState>;
|
|
385
|
-
/** Manually flush pending sync. */
|
|
386
412
|
flush(): Promise<SyncResult[]>;
|
|
387
|
-
/** Stop sync and release resources. */
|
|
388
413
|
dispose(): Promise<void>;
|
|
389
|
-
/**
|
|
390
|
-
* Dynamically add a data backend to this group.
|
|
391
|
-
* Creates the backend instance, sets up bi-directional sync, and triggers initial sync.
|
|
392
|
-
* @param id Unique backend ID within this group
|
|
393
|
-
* @param type Backend type name (must be registered)
|
|
394
|
-
* @param options Backend options (storage location fields; account fields can be resolved via accountBackendId in the descriptor)
|
|
395
|
-
* @param description Optional human-readable description
|
|
396
|
-
*/
|
|
397
414
|
addBackend(id: string, type: string, options: Record<string, unknown>, description?: string): Promise<void>;
|
|
398
|
-
/**
|
|
399
|
-
* Dynamically remove a data backend from this group.
|
|
400
|
-
* Tears down the sync pair and disposes the backend instance.
|
|
401
|
-
* @param id Backend ID to remove
|
|
402
|
-
*/
|
|
403
415
|
removeBackend(id: string): Promise<void>;
|
|
404
|
-
/** List all backend descriptors in this group. */
|
|
405
416
|
listBackends(): AppDataBackendDescriptor[];
|
|
417
|
+
/** Update the display name only (descriptor-only). */
|
|
418
|
+
rename(name: string): Promise<void>;
|
|
419
|
+
/** Write a tombstone, delete the file + version record, trigger sync. */
|
|
420
|
+
deleteFile(path: string): Promise<void>;
|
|
421
|
+
listConflicts(): Promise<ConflictArchive[]>;
|
|
422
|
+
resolveConflict(conflictId: string, mergedContent: unknown): Promise<void>;
|
|
423
|
+
readConflictBackup(conflictId: string, fileType: 'source' | 'target' | 'resolved'): Promise<string>;
|
|
424
|
+
purgeMtimeSidecars(options?: {
|
|
425
|
+
root?: string;
|
|
426
|
+
dryRun?: boolean;
|
|
427
|
+
}): Promise<MtimePurgeResult>;
|
|
428
|
+
purgeKeepFiles(options?: {
|
|
429
|
+
root?: string;
|
|
430
|
+
dryRun?: boolean;
|
|
431
|
+
}): Promise<KeepPurgeResult>;
|
|
432
|
+
}
|
|
433
|
+
/** Handle to a data-sync group, providing direct fs access. */
|
|
434
|
+
interface AppDataGroup extends SyncGroupHandle {
|
|
435
|
+
readonly kind: 'data';
|
|
406
436
|
}
|
|
407
437
|
/** Options for the unified connect() entry point. */
|
|
408
438
|
interface ConnectOptions {
|
|
@@ -451,6 +481,10 @@ interface ConnectResult {
|
|
|
451
481
|
* model this is always present — it hosts the data groups' topology.
|
|
452
482
|
*/
|
|
453
483
|
repo?: IConfigRepo;
|
|
484
|
+
/** The config-sync group as a unified handle (same object as `repo`). */
|
|
485
|
+
configGroup?: ConfigSyncGroupHandle;
|
|
486
|
+
/** All groups for this app: config group first, then data groups. */
|
|
487
|
+
groups?: SyncGroupHandle[];
|
|
454
488
|
/**
|
|
455
489
|
* Handle to the default (`default`) app data group. Always owned by `repo`;
|
|
456
490
|
* present on first launch and when a data-sync backend was connected.
|
|
@@ -465,6 +499,14 @@ interface IConfigRepo {
|
|
|
465
499
|
readonly appId: string;
|
|
466
500
|
/** Node ID. */
|
|
467
501
|
readonly nodeId: string;
|
|
502
|
+
/** Fixed group id of the config-sync group (`config`). */
|
|
503
|
+
readonly groupId: string;
|
|
504
|
+
/** Structural discriminator — always `'config'`. */
|
|
505
|
+
readonly kind: 'config';
|
|
506
|
+
/** Capability switches (config group is the superset: all true). */
|
|
507
|
+
readonly features: SyncGroupFeatures;
|
|
508
|
+
/** User-editable display name (from `.config/config-sync-group.json`). */
|
|
509
|
+
readonly name?: string;
|
|
468
510
|
/** ZenFS-compatible fs object, context-isolated to this app's directories. */
|
|
469
511
|
readonly fs: typeof node_fs;
|
|
470
512
|
/** Un-chrooted fs for low-level browsing (includes /.meta/, all app dirs). */
|
|
@@ -489,6 +531,14 @@ interface IConfigRepo {
|
|
|
489
531
|
flush(): Promise<SyncResult[]>;
|
|
490
532
|
/** Get sync status for all registered sync pairs. */
|
|
491
533
|
getSyncStatuses(): Map<string, SyncPairStatus>;
|
|
534
|
+
/**
|
|
535
|
+
* Per-backend sync state, including replica descriptors that failed to
|
|
536
|
+
* connect and therefore have no pair (they do not appear in
|
|
537
|
+
* getSyncStatuses()).
|
|
538
|
+
*/
|
|
539
|
+
getBackendSyncStates(): Map<string, BackendSyncState>;
|
|
540
|
+
/** Update the config-sync group's display name only. */
|
|
541
|
+
rename(name: string): Promise<void>;
|
|
492
542
|
/** Resolve a conflict with custom merged content. */
|
|
493
543
|
resolveConflict(conflictId: string, mergedContent: unknown): Promise<void>;
|
|
494
544
|
/** List all conflict archives. */
|
|
@@ -558,7 +608,10 @@ interface IConfigRepo {
|
|
|
558
608
|
* Each backend can optionally reference a config-sync backend's account
|
|
559
609
|
* via `accountBackendId` to reuse credentials.
|
|
560
610
|
*/
|
|
561
|
-
createAppDataGroup(id: string, backends: AppDataBackendDescriptor[]
|
|
611
|
+
createAppDataGroup(id: string, backends: AppDataBackendDescriptor[], options?: {
|
|
612
|
+
name?: string;
|
|
613
|
+
features?: Partial<SyncGroupFeatures>;
|
|
614
|
+
}): Promise<AppDataGroup>;
|
|
562
615
|
/** Get an existing data-sync group handle. */
|
|
563
616
|
getAppDataGroup(id: string): Promise<AppDataGroup>;
|
|
564
617
|
/** List all data-sync group descriptors for this app. */
|
|
@@ -577,6 +630,21 @@ interface IConfigRepo {
|
|
|
577
630
|
updateConfigSyncGroupDescriptor(patch: {
|
|
578
631
|
name: string;
|
|
579
632
|
}): Promise<ConfigSyncGroupDescriptor>;
|
|
633
|
+
/**
|
|
634
|
+
* Replace a backend's parameters while keeping its id.
|
|
635
|
+
*
|
|
636
|
+
* Changing parameters means switching to a different remote target:
|
|
637
|
+
* the old sync pair is torn down, the new backend is instantiated, paired
|
|
638
|
+
* and initially synced. Old remote data is NOT migrated. If the new
|
|
639
|
+
* parameters cannot be instantiated, the old backend/pair is left intact
|
|
640
|
+
* and the error is rethrown.
|
|
641
|
+
*/
|
|
642
|
+
replaceBackend(id: string, type: string, options: Record<string, unknown>, description?: string): Promise<void>;
|
|
643
|
+
/**
|
|
644
|
+
* Replace a data-sync backend's parameters (same semantics as
|
|
645
|
+
* replaceBackend: old pair is rebuilt against the new target).
|
|
646
|
+
*/
|
|
647
|
+
replaceAppDataGroupBackend(groupId: string, backendId: string, type: string, options: Record<string, unknown>, description?: string): Promise<AppDataGroup>;
|
|
580
648
|
/** Remove a data-sync group (stops sync, removes descriptor). */
|
|
581
649
|
removeAppDataGroup(id: string): Promise<void>;
|
|
582
650
|
/**
|
|
@@ -586,6 +654,11 @@ interface IConfigRepo {
|
|
|
586
654
|
* Excludes the local IndexedDB primary.
|
|
587
655
|
*/
|
|
588
656
|
listAccountBackends(): Promise<BackendDescriptor[]>;
|
|
657
|
+
/**
|
|
658
|
+
* List registered replica backend descriptors (excludes the implicit local
|
|
659
|
+
* primary). Unified handle method shared with data groups.
|
|
660
|
+
*/
|
|
661
|
+
listBackends(): AppDataBackendDescriptor[];
|
|
589
662
|
/** Write the group-type marker file if it doesn't exist. */
|
|
590
663
|
ensureGroupType(type: SyncGroupType): Promise<void>;
|
|
591
664
|
/** Read the group-type marker. Returns null if not set. */
|
|
@@ -593,6 +666,13 @@ interface IConfigRepo {
|
|
|
593
666
|
/** Dispose: stop all sync, release cache FS and resources. */
|
|
594
667
|
dispose(): Promise<void>;
|
|
595
668
|
}
|
|
669
|
+
/**
|
|
670
|
+
* The config-sync group as a unified handle. It is the capability superset:
|
|
671
|
+
* `SyncGroupHandle` + config payload / node config / topology management.
|
|
672
|
+
*/
|
|
673
|
+
interface ConfigSyncGroupHandle extends IConfigRepo, SyncGroupHandle {
|
|
674
|
+
readonly kind: 'config';
|
|
675
|
+
}
|
|
596
676
|
|
|
597
677
|
/**
|
|
598
678
|
* zen-fs-config — Config Serializers
|
|
@@ -824,6 +904,13 @@ interface MinimalAsyncFS extends BackendInstance {
|
|
|
824
904
|
declare class ConfigRepo implements IConfigRepo {
|
|
825
905
|
readonly appId: string;
|
|
826
906
|
readonly nodeId: string;
|
|
907
|
+
/** Fixed id for the unified sync-group model. */
|
|
908
|
+
readonly groupId = "config";
|
|
909
|
+
readonly kind: "config";
|
|
910
|
+
/** Capability switches — the config group is the superset. */
|
|
911
|
+
readonly features: SyncGroupFeatures;
|
|
912
|
+
/** Display name, hydrated from `.config/config-sync-group.json`. */
|
|
913
|
+
name?: string;
|
|
827
914
|
/** Chroot-isolated fs for app-facing API. Typed as `any` to match `typeof import('node:fs')` duck-typically. */
|
|
828
915
|
readonly fs: any;
|
|
829
916
|
/** Un-chrooted fs for low-level browsing. */
|
|
@@ -842,6 +929,10 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
842
929
|
private readonly pollIntervalMs?;
|
|
843
930
|
/** Tombstone cache — avoids redundant reads within a single flush() cycle. */
|
|
844
931
|
private tombstoneCache;
|
|
932
|
+
/** Per-backend sync state (successful pairs + connect failures). */
|
|
933
|
+
private backendStates;
|
|
934
|
+
/** Last known backend descriptors, for the synchronous unified handle API. */
|
|
935
|
+
private backendDescriptorCache;
|
|
845
936
|
/**
|
|
846
937
|
* Tracks the background initial sync started by createConfigRepo().
|
|
847
938
|
* `flush()` and `dispose()` will await this if it hasn't completed yet,
|
|
@@ -973,6 +1064,15 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
973
1064
|
*/
|
|
974
1065
|
syncMetaToReplicas(): Promise<void>;
|
|
975
1066
|
getSyncStatuses(): Map<string, SyncPairStatus>;
|
|
1067
|
+
/**
|
|
1068
|
+
* Per-backend sync state. Includes replica descriptors that failed to connect
|
|
1069
|
+
* (they have no sync pair, so they never show up in getSyncStatuses()).
|
|
1070
|
+
*/
|
|
1071
|
+
getBackendSyncStates(): Map<string, BackendSyncState>;
|
|
1072
|
+
/** Registered replica backend descriptors (excludes the implicit local primary). */
|
|
1073
|
+
listBackends(): AppDataBackendDescriptor[];
|
|
1074
|
+
/** Update the config-sync group's display name only. */
|
|
1075
|
+
rename(name: string): Promise<void>;
|
|
976
1076
|
resolveConflict(conflictId: string, mergedContent: unknown): Promise<void>;
|
|
977
1077
|
listConflicts(): Promise<ConflictArchive[]>;
|
|
978
1078
|
readConflictBackup(conflictId: string, fileType: 'source' | 'target' | 'resolved'): Promise<string>;
|
|
@@ -991,36 +1091,75 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
991
1091
|
private walkDir;
|
|
992
1092
|
writeMetaFile(path: string, data: unknown): Promise<void>;
|
|
993
1093
|
readMetaFile<T>(path: string): Promise<T | null>;
|
|
994
|
-
/** Path for a single backend descriptor: .
|
|
1094
|
+
/** Path for a single backend descriptor: .config/backends/{id}.json */
|
|
995
1095
|
backendFilePath(id: string): string;
|
|
1096
|
+
/** Legacy path: .meta/backends/{id}.json (read + dual-write for one cycle). */
|
|
1097
|
+
legacyBackendFilePath(id: string): string;
|
|
1098
|
+
/** Read every parseable descriptor in one directory. */
|
|
1099
|
+
private readBackendDescriptorsFrom;
|
|
996
1100
|
/**
|
|
997
|
-
* Read all backend descriptors from
|
|
1101
|
+
* Read all backend descriptors from `.config/backends/*.json` with legacy
|
|
1102
|
+
* `.meta/backends/*.json` as a one-cycle fallback (new layout wins by id).
|
|
998
1103
|
*
|
|
999
1104
|
* If duplicate backends are detected (same type + options but different id),
|
|
1000
1105
|
* only the first one (sorted by id) is kept and the rest are removed
|
|
1001
1106
|
* (including their version sidecar files).
|
|
1002
1107
|
*/
|
|
1003
1108
|
readAllBackendDescriptors(): Promise<BackendDescriptor[]>;
|
|
1004
|
-
/**
|
|
1109
|
+
/**
|
|
1110
|
+
* Write a single backend descriptor to `.config/backends/{id}.json`,
|
|
1111
|
+
* mirroring to the legacy `.meta/backends/{id}.json` for one release cycle
|
|
1112
|
+
* so older clients still see the backend.
|
|
1113
|
+
*/
|
|
1005
1114
|
writeBackendDescriptor(desc: BackendDescriptor): Promise<void>;
|
|
1006
|
-
/** Remove a single backend descriptor file + its version sidecar */
|
|
1115
|
+
/** Remove a single backend descriptor file + its version sidecar (both layouts) */
|
|
1007
1116
|
removeBackendDescriptor(id: string): Promise<void>;
|
|
1008
1117
|
getBackends(): Promise<BackendsMeta | null>;
|
|
1009
1118
|
updateBackends(meta: BackendsMeta): Promise<void>;
|
|
1010
1119
|
addBackend(id: string, type: string, options: Record<string, unknown>, description?: string): Promise<void>;
|
|
1120
|
+
/**
|
|
1121
|
+
* Instantiate a config-sync replica, persist its descriptor, create its
|
|
1122
|
+
* sync pair, register lifecycle hooks and run the initial sync/watch.
|
|
1123
|
+
* Shared by addBackend() and replaceBackend().
|
|
1124
|
+
*/
|
|
1125
|
+
private setupReplica;
|
|
1011
1126
|
removeBackend(id: string): Promise<void>;
|
|
1127
|
+
/**
|
|
1128
|
+
* Replace a config-sync backend's parameters in place (same id).
|
|
1129
|
+
*
|
|
1130
|
+
* Probe the new parameters first: if the backend cannot even be created
|
|
1131
|
+
* (e.g. missing token), nothing is touched and the error is rethrown.
|
|
1132
|
+
* Otherwise the old pair is removed, the descriptor rewritten, and a new
|
|
1133
|
+
* pair created against the new target with an initial sync. If that fails,
|
|
1134
|
+
* the old descriptor and pair are restored. The descriptor file is never
|
|
1135
|
+
* tombstoned, so this never delete-then-recreates it.
|
|
1136
|
+
*/
|
|
1137
|
+
replaceBackend(id: string, type: string, options: Record<string, unknown>, description?: string): Promise<void>;
|
|
1012
1138
|
/** Write the group-type marker file if it doesn't exist. */
|
|
1013
1139
|
ensureGroupType(type: SyncGroupType): Promise<void>;
|
|
1014
|
-
/** Read the group-type marker. Returns null if not set. */
|
|
1140
|
+
/** Read the group-type marker. Returns null if not set (new path, then legacy). */
|
|
1015
1141
|
getGroupType(): Promise<SyncGroupType | null>;
|
|
1016
|
-
/** Path for a single app data group descriptor: .
|
|
1142
|
+
/** Path for a single app data group descriptor: .config/app-data-groups/{appId}/{id}.json */
|
|
1017
1143
|
private appDataGroupFilePath;
|
|
1144
|
+
/** Legacy descriptor path: .meta/app-data-groups/{appId}/{id}.json */
|
|
1145
|
+
private legacyAppDataGroupFilePath;
|
|
1146
|
+
/** Write a data-group descriptor to the new path, mirroring to the legacy one. */
|
|
1147
|
+
private writeAppDataGroupDescriptorFile;
|
|
1018
1148
|
/**
|
|
1019
1149
|
* Resolve a backend descriptor's options by merging account fields
|
|
1020
1150
|
* from the referenced config-sync backend (if accountBackendId is set).
|
|
1021
1151
|
*/
|
|
1022
1152
|
private resolveAppDataBackendOptions;
|
|
1023
|
-
|
|
1153
|
+
/**
|
|
1154
|
+
* Reject two groups pointing at the exact same remote endpoint. Two groups
|
|
1155
|
+
* syncing the same files independently would fight over deletions and
|
|
1156
|
+
* tombstones (see SYNC-GROUP-UNIFICATION §4.3).
|
|
1157
|
+
*/
|
|
1158
|
+
private assertNoSharedRemote;
|
|
1159
|
+
createAppDataGroup(id: string, backends: AppDataBackendDescriptor[], options?: {
|
|
1160
|
+
name?: string;
|
|
1161
|
+
features?: Partial<SyncGroupFeatures>;
|
|
1162
|
+
}): Promise<AppDataGroup>;
|
|
1024
1163
|
/**
|
|
1025
1164
|
* Rewrite an app data group's descriptor (e.g. after addBackend/removeBackend)
|
|
1026
1165
|
* into .meta/app-data-groups/{appId}/{id}.json, keeping config-sync as the
|
|
@@ -1032,6 +1171,16 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
1032
1171
|
* and remote data are untouched, so existing sync pairs keep working.
|
|
1033
1172
|
*/
|
|
1034
1173
|
updateAppDataGroupName(id: string, name: string): Promise<void>;
|
|
1174
|
+
/**
|
|
1175
|
+
* Replace a data-sync backend's parameters in place (same backend id).
|
|
1176
|
+
*
|
|
1177
|
+
* Changing parameters means switching to a different remote target: the live
|
|
1178
|
+
* group is disposed (old pairs torn down), the descriptor is rewritten, and a
|
|
1179
|
+
* fresh group instance creates pairs + performs the initial sync. Old remote
|
|
1180
|
+
* data is NOT migrated. If the new options cannot be instantiated, nothing is
|
|
1181
|
+
* touched; if re-initialisation fails, the old descriptor is restored.
|
|
1182
|
+
*/
|
|
1183
|
+
replaceAppDataGroupBackend(groupId: string, backendId: string, type: string, options: Record<string, unknown>, description?: string): Promise<AppDataGroup>;
|
|
1035
1184
|
getConfigSyncGroupDescriptor(): Promise<ConfigSyncGroupDescriptor | null>;
|
|
1036
1185
|
/**
|
|
1037
1186
|
* Change the config-sync group's display name only. Backends, the local
|
|
@@ -1196,4 +1345,123 @@ declare function incrementVersion(fs: SyncableFS, configFilePath: string, newCon
|
|
|
1196
1345
|
*/
|
|
1197
1346
|
declare function verifyOrRepairVersion(fs: SyncableFS, configFilePath: string, author: string): Promise<VersionMeta | null>;
|
|
1198
1347
|
|
|
1199
|
-
|
|
1348
|
+
/**
|
|
1349
|
+
* zen-fs-config — Shared Sync-Group Metadata
|
|
1350
|
+
*
|
|
1351
|
+
* Implements the layout agreed in SYNC-GROUP-UNIFICATION.zh-CN.md:
|
|
1352
|
+
*
|
|
1353
|
+
* /.meta/group.json # group descriptor (kind/id/features)
|
|
1354
|
+
* /.meta/tombstones/{encoded}.json # tombstones (legacy: /.meta/.deleted)
|
|
1355
|
+
* /.meta/versions/{encoded}.json # version records for data groups
|
|
1356
|
+
* /.meta/conflicts/{conflictId}/ # conflict archives (legacy: /.meta/.conflicts)
|
|
1357
|
+
* /.config/** # config-sync only (not synced by data groups)
|
|
1358
|
+
*
|
|
1359
|
+
* Both the config-sync group and the data-sync groups use the `.meta/` helpers
|
|
1360
|
+
* below; `.config/` paths stay in config-repo.ts because only that group owns
|
|
1361
|
+
* them.
|
|
1362
|
+
*/
|
|
1363
|
+
|
|
1364
|
+
declare const META_DIR = "/.meta";
|
|
1365
|
+
declare const GROUP_DESCRIPTOR_FILE = "/.meta/group.json";
|
|
1366
|
+
declare const TOMBSTONES_DIR = "/.meta/tombstones";
|
|
1367
|
+
declare const LEGACY_TOMBSTONES_DIR = "/.meta/.deleted";
|
|
1368
|
+
declare const VERSIONS_DIR = "/.meta/versions";
|
|
1369
|
+
declare const CONFLICTS_DIR = "/.meta/conflicts";
|
|
1370
|
+
declare const LEGACY_CONFLICTS_DIR = "/.meta/.conflicts";
|
|
1371
|
+
declare const CONFIG_DIR = "/.config";
|
|
1372
|
+
/** Default features for a data-sync group: tombstones on, versions/conflicts opt-in. */
|
|
1373
|
+
declare const DATA_GROUP_DEFAULT_FEATURES: SyncGroupFeatures;
|
|
1374
|
+
type MetaFS = {
|
|
1375
|
+
readFile(path: string, encoding?: string): Promise<any>;
|
|
1376
|
+
writeFile(path: string, data: any): Promise<void>;
|
|
1377
|
+
readdir(path: string): Promise<string[]>;
|
|
1378
|
+
mkdir(path: string): Promise<any>;
|
|
1379
|
+
unlink(path: string): Promise<void>;
|
|
1380
|
+
exists?(path: string): Promise<boolean>;
|
|
1381
|
+
};
|
|
1382
|
+
/**
|
|
1383
|
+
* Encode a file path into a flat metadata entry name.
|
|
1384
|
+
* `/a/b.json` → `a__b++json`
|
|
1385
|
+
*/
|
|
1386
|
+
declare function encodeMetaPath(filePath: string): string;
|
|
1387
|
+
/** Read `.meta/group.json`. */
|
|
1388
|
+
declare function readGroupDescriptor(fs: MetaFS): Promise<GroupDescriptor | null>;
|
|
1389
|
+
/** Write `.meta/group.json` (idempotent). */
|
|
1390
|
+
declare function writeGroupDescriptor(fs: MetaFS, descriptor: GroupDescriptor): Promise<void>;
|
|
1391
|
+
interface TombstoneTarget {
|
|
1392
|
+
id: string;
|
|
1393
|
+
fs: any;
|
|
1394
|
+
}
|
|
1395
|
+
/**
|
|
1396
|
+
* Tombstone store for a group's local store.
|
|
1397
|
+
*
|
|
1398
|
+
* New writes go to `/.meta/tombstones/`; for one release cycle a mirror copy is
|
|
1399
|
+
* also written to the legacy `/.meta/.deleted/` path so older clients still see
|
|
1400
|
+
* deletions. Reads accept both.
|
|
1401
|
+
*/
|
|
1402
|
+
declare class TombstoneStore {
|
|
1403
|
+
private fs;
|
|
1404
|
+
private author;
|
|
1405
|
+
constructor(fs: MetaFS, author: string);
|
|
1406
|
+
private pathFor;
|
|
1407
|
+
/** All tombstones, new path first, legacy only for paths not already seen. */
|
|
1408
|
+
list(): Promise<TombstoneMeta[]>;
|
|
1409
|
+
/** Write a tombstone (new + legacy mirror). */
|
|
1410
|
+
write(tombstone: TombstoneMeta): Promise<void>;
|
|
1411
|
+
/** Persist an updated tombstone (confirmations) to whichever paths exist. */
|
|
1412
|
+
save(tombstone: TombstoneMeta): Promise<void>;
|
|
1413
|
+
/** Delete a tombstone from both layouts. */
|
|
1414
|
+
remove(tombstone: TombstoneMeta): Promise<void>;
|
|
1415
|
+
/**
|
|
1416
|
+
* Delete every tombstoned file (and its version record) on the local store
|
|
1417
|
+
* and on each target backend, so bi-directional sync cannot resurrect it.
|
|
1418
|
+
*/
|
|
1419
|
+
process(targets?: TombstoneTarget[]): Promise<void>;
|
|
1420
|
+
private deleteEverywhere;
|
|
1421
|
+
/** Add the given backend ids to every tombstone's confirmation set. */
|
|
1422
|
+
confirm(backendIds: string[]): Promise<number>;
|
|
1423
|
+
/** Remove tombstones confirmed by every connected backend (and their mirrors). */
|
|
1424
|
+
gc(allBackendIds: string[], targets?: TombstoneTarget[]): Promise<void>;
|
|
1425
|
+
}
|
|
1426
|
+
/**
|
|
1427
|
+
* Version records for data files, stored centrally under `/.meta/versions/`.
|
|
1428
|
+
* Config-sync keeps its historical `<file>.version` sidecars; only data groups
|
|
1429
|
+
* use this store (see SYNC-GROUP-UNIFICATION §4.4 for the migration note).
|
|
1430
|
+
*/
|
|
1431
|
+
declare class VersionStore {
|
|
1432
|
+
private fs;
|
|
1433
|
+
private author;
|
|
1434
|
+
constructor(fs: MetaFS, author: string);
|
|
1435
|
+
/** `null` for metadata paths and version files themselves. */
|
|
1436
|
+
pathFor(filePath: string): string | null;
|
|
1437
|
+
read(filePath: string): Promise<VersionMeta | null>;
|
|
1438
|
+
record(filePath: string, content: Uint8Array): Promise<VersionMeta | null>;
|
|
1439
|
+
remove(filePath: string): Promise<void>;
|
|
1440
|
+
}
|
|
1441
|
+
interface RawConflict {
|
|
1442
|
+
path: string;
|
|
1443
|
+
sourceContent: string;
|
|
1444
|
+
targetContent: string;
|
|
1445
|
+
resolvedWith?: string;
|
|
1446
|
+
}
|
|
1447
|
+
/**
|
|
1448
|
+
* Conflict archives for data files, stored under `/.meta/conflicts/`.
|
|
1449
|
+
* Legacy `/.meta/.conflicts/` archives stay readable (list/read fallback).
|
|
1450
|
+
*/
|
|
1451
|
+
declare class ConflictStore {
|
|
1452
|
+
private fs;
|
|
1453
|
+
private appId;
|
|
1454
|
+
private nodeId;
|
|
1455
|
+
private versions;
|
|
1456
|
+
constructor(fs: MetaFS, appId: string, nodeId: string, versions: VersionStore);
|
|
1457
|
+
/** Persist source/target backups + meta.json. Returns the archive record. */
|
|
1458
|
+
archive(conflict: RawConflict, timestamp?: number): Promise<ConflictArchive>;
|
|
1459
|
+
/** All archives, new layout first, legacy entries only when not shadowed. */
|
|
1460
|
+
list(): Promise<ConflictArchive[]>;
|
|
1461
|
+
private candidatesFor;
|
|
1462
|
+
readBackup(conflictId: string, fileType: 'source' | 'target' | 'resolved'): Promise<string>;
|
|
1463
|
+
/** Resolve a conflict with raw (already serialized) content. */
|
|
1464
|
+
resolve(conflictId: string, mergedContent: string | Uint8Array): Promise<void>;
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
export { type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type BackendDescriptor, type BackendFactory, type BackendInstance, type BackendMetadata, type BackendParamDef, type BackendSyncState, type BackendsMeta, CONFIG_DIR, CONFLICTS_DIR, type CacheOptions, ConfigRepo, type ConfigRepoOptions, type ConfigSerializer, type ConfigSyncGroupDescriptor, type ConfigSyncGroupHandle, type ConflictArchive, type ConflictInfo, ConflictStore, type ConnectOptions, type ConnectResult, DATA_GROUP_DEFAULT_FEATURES, FolderStore, GROUP_DESCRIPTOR_FILE, type GroupDescriptor, type IConfigRepo, type KeepPurgeResult, LEGACY_CONFLICTS_DIR, LEGACY_TOMBSTONES_DIR, LOCAL_IDB_BACKEND_ID, META_DIR, type MigrateLocalFS, type MigrateReplicaFS, type MtimePurgeResult, type PurgeKeepOptions, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, configKeyToFilePath, connect, createBackend, createConfigRepo, createSerializerChain, encodeMetaPath, getAccountFields, getBackendMetadata, getExtension, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isMtimeSidecar, legacyVersionPathFor, listBackendMetadata, listBackends, localPrimaryType, mergeAccountFields, migrateVersionSidecars, purgeKeepFiles, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveLocalPrimary, sha256, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };
|