zen-fs-config 0.7.4 → 0.7.5
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/DESIGN.md +20 -0
- package/README.md +16 -0
- package/README.zh-CN.md +16 -0
- package/dist/{backend-registry-RBKWNJZI.mjs → backend-registry-47NQOGMU.mjs} +1 -1
- package/dist/{chunk-S2S3XBK2.mjs → chunk-H2F4TFQD.mjs} +8 -1
- package/dist/index.d.mts +26 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +336 -140
- package/dist/index.mjs +328 -139
- package/dist/zen-fs-config.js +334 -139
- package/package.json +1 -1
package/DESIGN.md
CHANGED
|
@@ -98,6 +98,26 @@ A **sync group** is a set of backends that synchronize with each other. There ar
|
|
|
98
98
|
| `data-sync` | Lightweight: data backends only, direct read/write, no config meta layer |
|
|
99
99
|
| absent | New empty backend; caller decides group type at creation time |
|
|
100
100
|
|
|
101
|
+
**Group type is write-once, and sync may not change it**: besides the connect-time
|
|
102
|
+
check (`connect()` throws when `options.groupType` disagrees with the detected
|
|
103
|
+
type), every `SyncableFS` handed to the sync engine is wrapped by
|
|
104
|
+
`wrapGroupTypeGuard()` (`src/group-type-guard.ts`). The guard compares the
|
|
105
|
+
identity the sync write would produce with what the target side already holds and
|
|
106
|
+
drops the write when they differ, so a wrongly-wired replica can never flip a
|
|
107
|
+
config-sync group into a data-sync group (or the other way round). Guarded
|
|
108
|
+
identity fields:
|
|
109
|
+
|
|
110
|
+
| Path | Identity field | Allowed change |
|
|
111
|
+
|---|---|---|
|
|
112
|
+
| `.config/group-type`, `.meta/group-type` | trimmed text (`config-sync` / `data-sync`) | first write, or same value |
|
|
113
|
+
| `.meta/group.json` | `kind` (`config` / `data`) | first write, or same `kind` (name/features still update freely) |
|
|
114
|
+
| `.config/app-data-groups/{appId}/{id}.json` | `groupType` (`data-sync`) | first write, or same value |
|
|
115
|
+
|
|
116
|
+
Blocking is deliberately non-fatal: the write is skipped, a
|
|
117
|
+
`[GroupType] blocked group-type change on <side>` warning is logged once per
|
|
118
|
+
distinct (side, path, from→to) signature, and the repo stays usable. Fix the
|
|
119
|
+
group wiring instead of syncing the marker.
|
|
120
|
+
|
|
101
121
|
## 3. File System Structure
|
|
102
122
|
|
|
103
123
|
### 3.1 Config-Sync Group
|
package/README.md
CHANGED
|
@@ -201,6 +201,22 @@ Detection & dispatch rules:
|
|
|
201
201
|
|
|
202
202
|
`connect()` accepts the same options as `createConfigRepo` (`backendInfo`, `primaryBackendId`, `idbStoreName`, `nodeId`, `folderPath`, `cache`, `serializer`, `onConflict`, `syncPollIntervalMs`) plus `groupType`. On Node.js, pass `folderPath` (or set `ZEN_FS_CONFIG_HOME`) to enable local disk persistence.
|
|
203
203
|
|
|
204
|
+
## App data group path semantics
|
|
205
|
+
|
|
206
|
+
`dataGroup.fs` exposes the **logical root of the data group** (the application's data directory). It is not a view of one backend's physical root.
|
|
207
|
+
|
|
208
|
+
- A write to a group-root-relative path such as `/struct/a.json` is replicated to every backend in the group.
|
|
209
|
+
- Each backend maps that same logical path into its own physical root: the Gitee/GitHub repo root, the RemoteStorage `basePath`, the WebDAV directory, etc.
|
|
210
|
+
- Backend `basePath` / repo root values are **physical roots**, not a shared logical prefix. Multiple backends with different physical roots are valid; do not reject a group just because their `basePath` values differ.
|
|
211
|
+
- Always use the same group-root-relative path for all backends. If the application defines a namespace inside the group (for example `app_data/folders`), that is an explicit application-level convention; do not derive it from backend `basePath`.
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
// dataGroup.fs is the logical group root; all attached backends receive this path.
|
|
215
|
+
await dataGroup.fs.promises.writeFile('/struct/host.json', json);
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
A common mistake is to compare every backend's `basePath` and try to compute one "common write prefix". That conflates the logical group root with physical backend roots and incorrectly rejects otherwise valid multi-backend groups.
|
|
219
|
+
|
|
204
220
|
## Directory Structure
|
|
205
221
|
|
|
206
222
|
```
|
package/README.zh-CN.md
CHANGED
|
@@ -194,6 +194,22 @@ if (result.groupType === 'data-sync') {
|
|
|
194
194
|
|
|
195
195
|
`connect()` 接受与 `createConfigRepo` 相同的选项(`backendInfo`、`primaryBackendId`、`idbStoreName`、`nodeId`、`folderPath`、`cache`、`serializer`、`onConflict`、`syncPollIntervalMs`),另加 `groupType`。在 Node.js 上通过 `folderPath`(或设 `ZEN_FS_CONFIG_HOME`)开启本地磁盘持久化。
|
|
196
196
|
|
|
197
|
+
## 数据组的路径语义
|
|
198
|
+
|
|
199
|
+
`dataGroup.fs` 暴露的是**数据组的逻辑根**(应用数据目录),不是某一个后端的物理根。
|
|
200
|
+
|
|
201
|
+
- 往组根相对路径(例如 `/struct/a.json`)写入,会同步到组内所有后端。
|
|
202
|
+
- 每个后端会把同一个逻辑路径映射到自己的物理根:Gitee/GitHub 仓库根、RemoteStorage 的 `basePath`、WebDAV 目录等。
|
|
203
|
+
- 后端的 `basePath` / 仓库根是**物理根**,不是所有后端共用的逻辑前缀。多个后端拥有不同的物理根是合法的;不要因为 `basePath` 不一致就判定数据组不可用。
|
|
204
|
+
- 所有后端都应使用同一个组根相对路径。如果应用要在组根下划一个命名空间(例如 `app_data/folders`),那是应用层显式约定,不能从后端 `basePath` 反推。
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
// dataGroup.fs 是数据组逻辑根;组内所有后端都会收到这个路径。
|
|
208
|
+
await dataGroup.fs.promises.writeFile('/struct/host.json', json);
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
一个常见错误是逐个比较后端的 `basePath`,再试图算出一个“公共写入前缀”。这把逻辑组根和物理后端根混为一谈,会误拒绝本来可用的多后端数据组。
|
|
212
|
+
|
|
197
213
|
## 目录结构
|
|
198
214
|
|
|
199
215
|
```
|
|
@@ -74,7 +74,14 @@ async function wrapZenFSFileSystem(config) {
|
|
|
74
74
|
await isolatedFS.mkdir(dir, { uid: 0, gid: 0, mode: 493 });
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
let currentSize = 0;
|
|
78
|
+
if (await isolatedFS.exists(path)) {
|
|
79
|
+
currentSize = (await isolatedFS.stat(path)).size;
|
|
80
|
+
} else {
|
|
81
|
+
await isolatedFS.createFile(path, { uid: 0, gid: 0, mode: 420 });
|
|
82
|
+
}
|
|
83
|
+
if (currentSize > 0) {
|
|
84
|
+
await isolatedFS.unlink(path);
|
|
78
85
|
await isolatedFS.createFile(path, { uid: 0, gid: 0, mode: 420 });
|
|
79
86
|
}
|
|
80
87
|
await isolatedFS.write(path, bytes, 0);
|
package/dist/index.d.mts
CHANGED
|
@@ -1025,6 +1025,18 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
1025
1025
|
private refreshSyncExclusions;
|
|
1026
1026
|
/** Invalidate the tombstone cache — call after tombstones are modified. */
|
|
1027
1027
|
private invalidateTombstoneCache;
|
|
1028
|
+
/**
|
|
1029
|
+
* 判定墓碑目标路径是否在删除之后被重新创建。
|
|
1030
|
+
*
|
|
1031
|
+
* 墓碑表达的是「删除意图」,但删除之后同一路径完全可能被再次写入。同步类工具
|
|
1032
|
+
* 的锁文件(`.sync.lock`)就是每轮「删除 → 重建」;若把墓碑当作永久否决权,
|
|
1033
|
+
* 这个路径会被每一轮 sync 反复删除,表现为「刚写进去 1 秒后就消失」、锁永远拿
|
|
1034
|
+
* 不到、深层目录刚建就没了。
|
|
1035
|
+
*
|
|
1036
|
+
* 判定依据是文件 mtime 晚于 `deletedAt`:写入必然刷新 mtime,因此 mtime 比删除
|
|
1037
|
+
* 时刻新就意味着这条墓碑已经被写操作撤销。
|
|
1038
|
+
*/
|
|
1039
|
+
private isPathRecreatedAfterTombstone;
|
|
1028
1040
|
/**
|
|
1029
1041
|
* Before sync: for each tombstone, delete the actual file on all replicas.
|
|
1030
1042
|
* This prevents bi-directional sync from copying the file back.
|
|
@@ -1626,8 +1638,22 @@ declare class TombstoneStore {
|
|
|
1626
1638
|
/**
|
|
1627
1639
|
* Delete every tombstoned file (and its version record) on the local store
|
|
1628
1640
|
* and on each target backend, so bi-directional sync cannot resurrect it.
|
|
1641
|
+
*
|
|
1642
|
+
* 墓碑只对「删除之后没有再写入」的路径有效。同步类工具会不断重建某些文件
|
|
1643
|
+
* (最典型的是 `.sync.lock`:每轮删除 → 重建),若墓碑永久生效,路径会被每一
|
|
1644
|
+
* 轮 preSync 删掉,表现为「刚写完 1 秒就消失、锁永远拿不到」。因此这里先判定
|
|
1645
|
+
* 目标路径是否在 `deletedAt` 之后被重新写入:是则墓碑已被用户写操作撤销,保留
|
|
1646
|
+
* 文件并删除墓碑;否则按删除传播处理。
|
|
1629
1647
|
*/
|
|
1630
1648
|
process(targets?: TombstoneTarget[]): Promise<void>;
|
|
1649
|
+
/**
|
|
1650
|
+
* 本地存储上该路径的 mtime 是否晚于墓碑的删除时刻。
|
|
1651
|
+
*
|
|
1652
|
+
* 只看本地主存储:副本上的同路径文件可能只是「删除之前的旧副本」,它的 mtime
|
|
1653
|
+
* 本来就旧,用副本判定既不可靠又会掩盖真正的删除传播。
|
|
1654
|
+
*/
|
|
1655
|
+
private wasRecreatedAfterDeletion;
|
|
1656
|
+
private mtimeOf;
|
|
1631
1657
|
private deleteEverywhere;
|
|
1632
1658
|
/** Add the given backend ids to every tombstone's confirmation set. */
|
|
1633
1659
|
confirm(backendIds: string[]): Promise<number>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1025,6 +1025,18 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
1025
1025
|
private refreshSyncExclusions;
|
|
1026
1026
|
/** Invalidate the tombstone cache — call after tombstones are modified. */
|
|
1027
1027
|
private invalidateTombstoneCache;
|
|
1028
|
+
/**
|
|
1029
|
+
* 判定墓碑目标路径是否在删除之后被重新创建。
|
|
1030
|
+
*
|
|
1031
|
+
* 墓碑表达的是「删除意图」,但删除之后同一路径完全可能被再次写入。同步类工具
|
|
1032
|
+
* 的锁文件(`.sync.lock`)就是每轮「删除 → 重建」;若把墓碑当作永久否决权,
|
|
1033
|
+
* 这个路径会被每一轮 sync 反复删除,表现为「刚写进去 1 秒后就消失」、锁永远拿
|
|
1034
|
+
* 不到、深层目录刚建就没了。
|
|
1035
|
+
*
|
|
1036
|
+
* 判定依据是文件 mtime 晚于 `deletedAt`:写入必然刷新 mtime,因此 mtime 比删除
|
|
1037
|
+
* 时刻新就意味着这条墓碑已经被写操作撤销。
|
|
1038
|
+
*/
|
|
1039
|
+
private isPathRecreatedAfterTombstone;
|
|
1028
1040
|
/**
|
|
1029
1041
|
* Before sync: for each tombstone, delete the actual file on all replicas.
|
|
1030
1042
|
* This prevents bi-directional sync from copying the file back.
|
|
@@ -1626,8 +1638,22 @@ declare class TombstoneStore {
|
|
|
1626
1638
|
/**
|
|
1627
1639
|
* Delete every tombstoned file (and its version record) on the local store
|
|
1628
1640
|
* and on each target backend, so bi-directional sync cannot resurrect it.
|
|
1641
|
+
*
|
|
1642
|
+
* 墓碑只对「删除之后没有再写入」的路径有效。同步类工具会不断重建某些文件
|
|
1643
|
+
* (最典型的是 `.sync.lock`:每轮删除 → 重建),若墓碑永久生效,路径会被每一
|
|
1644
|
+
* 轮 preSync 删掉,表现为「刚写完 1 秒就消失、锁永远拿不到」。因此这里先判定
|
|
1645
|
+
* 目标路径是否在 `deletedAt` 之后被重新写入:是则墓碑已被用户写操作撤销,保留
|
|
1646
|
+
* 文件并删除墓碑;否则按删除传播处理。
|
|
1629
1647
|
*/
|
|
1630
1648
|
process(targets?: TombstoneTarget[]): Promise<void>;
|
|
1649
|
+
/**
|
|
1650
|
+
* 本地存储上该路径的 mtime 是否晚于墓碑的删除时刻。
|
|
1651
|
+
*
|
|
1652
|
+
* 只看本地主存储:副本上的同路径文件可能只是「删除之前的旧副本」,它的 mtime
|
|
1653
|
+
* 本来就旧,用副本判定既不可靠又会掩盖真正的删除传播。
|
|
1654
|
+
*/
|
|
1655
|
+
private wasRecreatedAfterDeletion;
|
|
1656
|
+
private mtimeOf;
|
|
1631
1657
|
private deleteEverywhere;
|
|
1632
1658
|
/** Add the given backend ids to every tombstone's confirmation set. */
|
|
1633
1659
|
confirm(backendIds: string[]): Promise<number>;
|