zen-fs-config 0.11.0 → 0.11.3
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/README.md +19 -0
- package/README.zh-CN.md +18 -0
- package/dist/{backend-registry-5KJGMNZX.mjs → backend-registry-R6L6MFJS.mjs} +1 -1
- package/dist/backends/gitee.mjs +1 -1
- package/dist/backends/github.mjs +1 -1
- package/dist/backends/remotestorage.mjs +1 -1
- package/dist/backends/webdav.mjs +1 -1
- package/dist/{chunk-S2OW2HJC.mjs → chunk-7QFHGFCG.mjs} +130 -17
- package/dist/index.d.mts +39 -1
- package/dist/index.d.ts +39 -1
- package/dist/index.js +143 -18
- package/dist/index.mjs +10 -2
- package/dist/zen-fs-config.js +202 -50
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -36,6 +36,24 @@ npm install zen-fs-remotestoragejs # RemoteStorage replica
|
|
|
36
36
|
>
|
|
37
37
|
> **Cloud backends are optional peer dependencies, installed by you (the consumer), not bundled by `zen-fs-config`.** The core *pre-registers* the `GitHub`, `Gitee`, and `RemoteStorage` backend **types** (so you can pass `type: 'Gitee'`, etc. straight to `addBackend`/`connect` without calling `registerBackend`), but it does **not** ship their implementations. You must `npm install` the matching package yourself; otherwise `createBackend()` throws a clear "package not installed — run `npm install <pkg>`" hint. This keeps the core bundle small and avoids forcing an internet dependency on everyone.
|
|
38
38
|
|
|
39
|
+
### Installing behind a mirror (without dirtying the lockfile)
|
|
40
|
+
|
|
41
|
+
This repo commits an `.npmrc` with `registry=https://registry.npmjs.org/`, so the `resolved` hosts in `package-lock.json` always point at the official registry. If they don't, CI running npm 12 (`allow-remote=none`) refuses to install with `EALLOWREMOTE`.
|
|
42
|
+
|
|
43
|
+
To use a mirror locally **without touching the lockfile**, run `npm ci` with a one-off registry override:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# installs only — npm rewrites the npmjs hosts to this registry for download
|
|
47
|
+
npm ci --registry=https://registry.npmmirror.com
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Do **not** pass the mirror when adding or updating packages: `npm install <pkg>` stamps the then-current registry's absolute URL into the lock. If it happens, normalise before committing:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm i --package-lock-only --registry=https://registry.npmjs.org
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
|
|
39
57
|
## Usage via `<script>` tag (no build step)
|
|
40
58
|
|
|
41
59
|
A self-contained browser bundle is published at `dist/zen-fs-config.js`. It bundles the **core** dependencies (`@zenfs/core`, `@zenfs/dom`, `zen-fs-sync`, `zen-fs-cache`) and exposes the library on the global `window.ZenFSConfig`. No npm install, no bundler — just drop it into any HTML page. **Cloud backends (GitHub / Gitee / RemoteStorage) are NOT bundled** — see the section below to enable them in `<script>` mode with **no import map required**.
|
|
@@ -103,6 +121,7 @@ import 'zen-fs-config/backends/remotestorage' // → zen-fs-remotestoragejs
|
|
|
103
121
|
```
|
|
104
122
|
|
|
105
123
|
Notes:
|
|
124
|
+
- **If your host lets users pick the backend type in the UI, import all four entries.** The registry only knows the backends whose entry you imported. Skip one (say you imported gitee + webdav only) and the moment a user selects the missing one (e.g. RemoteStorage) it fails at runtime with the *same* `Backend package "zen-fs-remotestoragejs" is not available` message — indistinguishable from "the package isn't installed", which sends debugging in the wrong direction. The entries themselves cost almost nothing: the backend package still lives in its own lazy chunk and is never downloaded unless that backend is used.
|
|
106
125
|
- Importing an entry does **not** duplicate the registry: all entries share one chunk with the main entry, so the backend map stays single-instance, and the package itself is still code-split (only fetched when the backend is first used).
|
|
107
126
|
- The backend metadata (options schema, identity/account fields) always comes from the library — hosts should not re-declare it.
|
|
108
127
|
- If you prefer to own the registration, the same entries work with an injected loader:
|
package/README.zh-CN.md
CHANGED
|
@@ -33,6 +33,23 @@ npm install zen-fs-remotestoragejs # RemoteStorage 副本
|
|
|
33
33
|
>
|
|
34
34
|
> **云后端是可选对等依赖,由你(使用者)自行安装,`zen-fs-config` 并不打包它们。** 核心会**预注册** `GitHub`、`Gitee`、`RemoteStorage` 这三种后端**类型**(因此你可以直接把 `type: 'Gitee'` 等传给 `addBackend`/`connect`,无需调用 `registerBackend`),但**不包含它们的实现包**。你必须自己 `npm install` 对应包;否则 `createBackend()` 会抛出明确的"未安装——请运行 `npm install <pkg>`"提示。这样可保持核心包体积精简,也不会强制所有人都带上网络依赖。
|
|
35
35
|
|
|
36
|
+
### 国内镜像 / 本地加速(不改动 lockfile)
|
|
37
|
+
|
|
38
|
+
本仓库根目录提交了 `.npmrc`(`registry=https://registry.npmjs.org/`),保证 `package-lock.json` 里的 `resolved` 主机名始终是官方 registry——否则 CI 一旦用 npm 12(`allow-remote=none`)就会 `EALLOWREMOTE` 拒装。
|
|
39
|
+
|
|
40
|
+
本地想走镜像而不污染 lockfile,用 `npm ci` 加一次性 registry 覆盖即可:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# 只装、不改 lock:npm 会把锁里的 npmjs 地址改写为当前 registry 去下载
|
|
44
|
+
npm ci --registry=https://registry.npmmirror.com
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**加/升级依赖时不要带镜像参数**(`npm install <pkg>` 会把当时 registry 的绝对 URL 写进 lock),若不慎写入,提交前归一化:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm i --package-lock-only --registry=https://registry.npmjs.org
|
|
51
|
+
```
|
|
52
|
+
|
|
36
53
|
## 通过 `<script>` 标签直接使用(无需构建)
|
|
37
54
|
|
|
38
55
|
包内置了一个自包含的浏览器构建 `dist/zen-fs-config.js`,它把**核心**依赖(`@zenfs/core`、`@zenfs/dom`、`zen-fs-sync`、`zen-fs-cache`)打包在一起,并将库挂载到全局变量 `window.ZenFSConfig`。无需 npm install、无需打包工具,直接放入任意 HTML 页面即可。**云后端(GitHub / Gitee / RemoteStorage)并不包含在自包含包内**——见下方小节,了解如何在 `<script>` 模式下启用它们(**无需 import map**)。
|
|
@@ -100,6 +117,7 @@ import 'zen-fs-config/backends/remotestorage' // → zen-fs-remotestoragejs
|
|
|
100
117
|
```
|
|
101
118
|
|
|
102
119
|
说明:
|
|
120
|
+
- **宿主如果让用户在界面上选后端类型,就把四个入口全引一遍。** 注册表里只有你引过的入口对应的后端;少引一个(例如只引了 gitee + webdav),用户一旦切到没引的那个(比如 RemoteStorage),运行时报的错和「包没装」长得一模一样(同样是 `Backend package "zen-fs-remotestoragejs" is not available`),排查很容易走偏。入口本身几乎没成本——后端包仍是独立的懒加载 chunk,没选到的后端不会下载。
|
|
103
121
|
- 引入入口**不会**产生第二份注册表:所有入口与主入口共享同一个 chunk,后端列表仍是单实例;后端包本身依旧按需分包(首次使用时才下载)。
|
|
104
122
|
- 后端的元数据(参数 schema、identity/account 字段)始终由库提供,宿主不要另抄一份。
|
|
105
123
|
- 如果你想自己掌控注册:`import { registerGiteeBackend } from 'zen-fs-config'; registerGiteeBackend(() => import('zen-fs-gitee'));`(字面量写在你这一侧)。
|
package/dist/backends/gitee.mjs
CHANGED
package/dist/backends/github.mjs
CHANGED
package/dist/backends/webdav.mjs
CHANGED
|
@@ -19,27 +19,27 @@ function openDB(name) {
|
|
|
19
19
|
const factory = idb();
|
|
20
20
|
if (!factory) return Promise.resolve(null);
|
|
21
21
|
return new Promise((resolve) => {
|
|
22
|
-
let
|
|
22
|
+
let req2;
|
|
23
23
|
try {
|
|
24
|
-
|
|
24
|
+
req2 = factory.open(name);
|
|
25
25
|
} catch {
|
|
26
26
|
resolve(null);
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
req2.onupgradeneeded = () => {
|
|
30
30
|
try {
|
|
31
|
-
|
|
31
|
+
req2.transaction?.abort();
|
|
32
32
|
} catch {
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
req2.onsuccess = () => resolve(req2.result);
|
|
36
|
+
req2.onerror = () => resolve(null);
|
|
37
|
+
req2.onblocked = () => resolve(null);
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
-
var request = (
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
var request = (req2) => new Promise((resolve, reject) => {
|
|
41
|
+
req2.onsuccess = () => resolve(req2.result);
|
|
42
|
+
req2.onerror = () => reject(req2.error);
|
|
43
43
|
});
|
|
44
44
|
function isDecodableListing(bytes) {
|
|
45
45
|
if (bytes.length === 0) return false;
|
|
@@ -145,6 +145,121 @@ async function repairIndexedDBStore(storeName) {
|
|
|
145
145
|
return result;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
// src/idb-alloc.ts
|
|
149
|
+
var INO_BLOCK = 32768;
|
|
150
|
+
var META_DB_SUFFIX = "__ino";
|
|
151
|
+
var META_STORE = "meta";
|
|
152
|
+
var HWM_KEY = "inoHwm";
|
|
153
|
+
function idbFactory() {
|
|
154
|
+
return globalThis.indexedDB ?? null;
|
|
155
|
+
}
|
|
156
|
+
function req(request2) {
|
|
157
|
+
return new Promise((resolve, reject) => {
|
|
158
|
+
request2.onsuccess = () => resolve(request2.result);
|
|
159
|
+
request2.onerror = () => reject(request2.error);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
function txDone(tx) {
|
|
163
|
+
return new Promise((resolve, reject) => {
|
|
164
|
+
tx.oncomplete = () => resolve();
|
|
165
|
+
tx.onerror = () => reject(tx.error);
|
|
166
|
+
tx.onabort = () => reject(tx.error);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function openStoreDb(name) {
|
|
170
|
+
const factory = idbFactory();
|
|
171
|
+
if (!factory) return Promise.reject(new Error("IndexedDB is not available"));
|
|
172
|
+
return new Promise((resolve, reject) => {
|
|
173
|
+
const request2 = factory.open(name);
|
|
174
|
+
request2.onupgradeneeded = () => {
|
|
175
|
+
const db = request2.result;
|
|
176
|
+
if (db.objectStoreNames.contains(name)) db.deleteObjectStore(name);
|
|
177
|
+
db.createObjectStore(name);
|
|
178
|
+
};
|
|
179
|
+
request2.onsuccess = () => resolve(request2.result);
|
|
180
|
+
request2.onerror = () => reject(request2.error);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function openMetaDb(name) {
|
|
184
|
+
const factory = idbFactory();
|
|
185
|
+
if (!factory) return Promise.reject(new Error("IndexedDB is not available"));
|
|
186
|
+
return new Promise((resolve, reject) => {
|
|
187
|
+
const request2 = factory.open(name, 1);
|
|
188
|
+
request2.onupgradeneeded = () => {
|
|
189
|
+
const db = request2.result;
|
|
190
|
+
if (!db.objectStoreNames.contains(META_STORE)) db.createObjectStore(META_STORE);
|
|
191
|
+
};
|
|
192
|
+
request2.onsuccess = () => resolve(request2.result);
|
|
193
|
+
request2.onerror = () => reject(request2.error);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
async function attachAllocId(store, storeName, db) {
|
|
197
|
+
const keys = await req(
|
|
198
|
+
db.transaction(storeName, "readonly").objectStore(storeName).getAllKeys()
|
|
199
|
+
);
|
|
200
|
+
let diskMax = 0;
|
|
201
|
+
for (const raw of keys) {
|
|
202
|
+
const n = Number(raw);
|
|
203
|
+
if (Number.isFinite(n) && n > diskMax) diskMax = n;
|
|
204
|
+
}
|
|
205
|
+
const metaDb = await openMetaDb(storeName + META_DB_SUFFIX);
|
|
206
|
+
let base;
|
|
207
|
+
let end;
|
|
208
|
+
try {
|
|
209
|
+
const tx = metaDb.transaction(META_STORE, "readwrite");
|
|
210
|
+
const meta = tx.objectStore(META_STORE);
|
|
211
|
+
const persisted = Number(await req(meta.get(HWM_KEY))) || 0;
|
|
212
|
+
base = Math.max(persisted, diskMax);
|
|
213
|
+
if (base % 2 !== 0) base += 1;
|
|
214
|
+
end = base + INO_BLOCK;
|
|
215
|
+
meta.put(end, HWM_KEY);
|
|
216
|
+
await txDone(tx);
|
|
217
|
+
} finally {
|
|
218
|
+
try {
|
|
219
|
+
metaDb.close?.();
|
|
220
|
+
} catch {
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
let next = base + 2;
|
|
224
|
+
store.allocId = () => {
|
|
225
|
+
if (next >= end) {
|
|
226
|
+
throw new Error(
|
|
227
|
+
`[zen-fs-config] ${storeName}: inode \u53F7\u6BB5\u5DF2\u7528\u5C3D\uFF08${base}~${end}\uFF09\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00\u8BE5\u5E93`
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
const id = next;
|
|
231
|
+
next += 2;
|
|
232
|
+
return [id, id + 1];
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
function withAllocId(base) {
|
|
236
|
+
return {
|
|
237
|
+
name: base?.name ?? "IndexedDB",
|
|
238
|
+
options: base?.options ?? {},
|
|
239
|
+
isAvailable: base?.isAvailable?.bind?.(base) ?? (() => !!idbFactory()),
|
|
240
|
+
async create(options) {
|
|
241
|
+
const storeName = String(options?.storeName ?? "zen-fs-config");
|
|
242
|
+
await repairIndexedDBStore(storeName);
|
|
243
|
+
const db = await openStoreDb(storeName);
|
|
244
|
+
db.onversionchange = () => {
|
|
245
|
+
try {
|
|
246
|
+
db.close();
|
|
247
|
+
} catch {
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
const { IndexedDBStore } = await import("@zenfs/dom");
|
|
251
|
+
const store = new IndexedDBStore(db);
|
|
252
|
+
await attachAllocId(store, storeName, db);
|
|
253
|
+
const zenfs = await import("@zenfs/core");
|
|
254
|
+
const fs = new zenfs.StoreFS(store);
|
|
255
|
+
if (!options?.disableAsyncCache) {
|
|
256
|
+
await store.transaction().preload();
|
|
257
|
+
}
|
|
258
|
+
return fs;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
148
263
|
// src/backend-registry.ts
|
|
149
264
|
var registry = /* @__PURE__ */ new Map();
|
|
150
265
|
var metadataRegistry = /* @__PURE__ */ new Map();
|
|
@@ -359,13 +474,7 @@ registerBackend("IndexedDB", async (options) => {
|
|
|
359
474
|
const { IndexedDB } = await import("@zenfs/dom");
|
|
360
475
|
const storeName = options.storeName ?? "zen-fs-config";
|
|
361
476
|
const label = options.label ?? storeName;
|
|
362
|
-
|
|
363
|
-
if (repaired?.repaired) {
|
|
364
|
-
console.warn(
|
|
365
|
-
`[Backend:IndexedDB] ${storeName}: reset ${repaired.repaired} corrupted directory listing(s): ` + repaired.details.map((d) => `ino ${d.key}\u2192slot ${d.data} (${d.reason})`).join(", ")
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
return wrapZenFSFileSystem({ backend: IndexedDB, storeName, label });
|
|
477
|
+
return wrapZenFSFileSystem({ backend: withAllocId(IndexedDB), storeName, label });
|
|
369
478
|
}, {
|
|
370
479
|
type: "IndexedDB",
|
|
371
480
|
label: "IndexedDB",
|
|
@@ -680,6 +789,10 @@ function registerWebdavBackend(getModule = () => importOptionalBackend("zen-fs-w
|
|
|
680
789
|
registerWebdavBackend();
|
|
681
790
|
|
|
682
791
|
export {
|
|
792
|
+
INO_BLOCK,
|
|
793
|
+
openStoreDb,
|
|
794
|
+
attachAllocId,
|
|
795
|
+
withAllocId,
|
|
683
796
|
registerBackend,
|
|
684
797
|
unregisterBackend,
|
|
685
798
|
createBackend,
|
package/dist/index.d.mts
CHANGED
|
@@ -2823,6 +2823,44 @@ declare function getUiConnection(repo: AppRepo): UiConnection;
|
|
|
2823
2823
|
*/
|
|
2824
2824
|
declare function connectV2(appId: string, options?: ConnectV2Options): Promise<AppRepo>;
|
|
2825
2825
|
|
|
2826
|
+
/**
|
|
2827
|
+
* StoreFS inode 撞号(id collision)防护。
|
|
2828
|
+
*
|
|
2829
|
+
* 背景
|
|
2830
|
+
* ----
|
|
2831
|
+
* `@zenfs/core` 的 StoreFS 打开库时用 `_populate` 把目录树展开成内存索引;
|
|
2832
|
+
* `allocNew()` 在没有 `store.allocId` 的情况下用 `max(_paths.keys()) + 2` 推导
|
|
2833
|
+
* 下一个 inode 号。`_populate` 只要遇到一个解不开的目录表就整体中断,索引残缺
|
|
2834
|
+
* → 推导出的号落在已有节点上 → `commitNew` 覆盖别人的 data slot(目录表被文件
|
|
2835
|
+
* 字节顶掉),此后每次 readdir 都报 `Cannot convert <path> to a BigInt`,同步再
|
|
2836
|
+
* 把这个损坏推给远端。
|
|
2837
|
+
*
|
|
2838
|
+
* `allocNew` 的第一行就是 `if (this.store.allocId) { ... }`:官方把发号权留给
|
|
2839
|
+
* Store(SingleBuffer v2 就用持久化原子计数器实现)。IndexedDB 的 store
|
|
2840
|
+
* (`@zenfs/dom`)没有实现它,所以永远走推导分支 —— 这就是缺口。
|
|
2841
|
+
*
|
|
2842
|
+
* 做法
|
|
2843
|
+
* ----
|
|
2844
|
+
* 打开库时从持久化高水位里**预占一段连续号**,把区间放在内存,`allocId()` 同步
|
|
2845
|
+
* 从区间里取号:满足接口的同步签名,且完全不再依赖内存索引。预占写在独立的
|
|
2846
|
+
* meta 库里,用 readwrite 事务完成;IndexedDB 对同一 object store 的读写事务
|
|
2847
|
+
* 天然串行,多个标签页拿到的是互不相交的区间,不需要额外加锁。
|
|
2848
|
+
*/
|
|
2849
|
+
/** 每次打开预占的号段长度(含 ino 与 data 槽,实际可用约 1.6 万个新节点)。 */
|
|
2850
|
+
declare const INO_BLOCK = 32768;
|
|
2851
|
+
/** 打开(必要时创建)StoreFS 使用的库,与 `@zenfs/dom` 的 createDB 行为一致。 */
|
|
2852
|
+
declare function openStoreDb(name: string): Promise<any>;
|
|
2853
|
+
/**
|
|
2854
|
+
* 给任意 IndexedDB store 实例挂上 `allocId`:
|
|
2855
|
+
* 高水位 = max(持久化值, 磁盘上已有的最大 key),再原子推进一整段。
|
|
2856
|
+
*/
|
|
2857
|
+
declare function attachAllocId(store: any, storeName: string, db: any): Promise<void>;
|
|
2858
|
+
/**
|
|
2859
|
+
* 把 `@zenfs/dom` 的 IndexedDB 后端描述符包一层,create 时构造带 `allocId` 的
|
|
2860
|
+
* store。保持 name / options / isAvailable 不变,`resolveMountConfig` 照旧可用。
|
|
2861
|
+
*/
|
|
2862
|
+
declare function withAllocId(base: any): any;
|
|
2863
|
+
|
|
2826
2864
|
/**
|
|
2827
2865
|
* zen-fs-config — Sidecar Version File Management
|
|
2828
2866
|
*
|
|
@@ -3192,4 +3230,4 @@ interface EnsureDataGroupResult {
|
|
|
3192
3230
|
*/
|
|
3193
3231
|
declare function ensureDataGroup(source: DataGroupSource, appId: string, opts?: EnsureDataGroupOptions): Promise<EnsureDataGroupResult>;
|
|
3194
3232
|
|
|
3195
|
-
export { ALIASES_DIR, type AddBackendResult, type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type AppRepo, BackendAlreadyExistsError, type BackendConflictInfo, type BackendConflictReason, type BackendConflictResolution, type BackendConflictResolutionResult, type BackendDescriptor, BackendEndpointConflictError, type BackendFactory, BackendIdentityError, type BackendInstance, type BackendMetadata, type BackendModuleLoader, type BackendParamDef, type BackendSyncState, type BackendsMeta, CONFIG_DIR, CONFLICTS_DIR, type CacheOptions, type ConfigBackendInput, ConfigNotReadyError, ConfigRepo, type ConfigRepoOptions, type ConfigSerializer, type ConfigSyncGroupDescriptor, type ConfigSyncGroupHandle, type ConflictArchive, type ConflictInfo, ConflictStore, ConnectFailedError, type ConnectOptions, type ConnectResult, ConnectV2Error, type ConnectV2Options, DATA_GROUP_DEFAULT_FEATURES, DATA_GROUP_PREFERENCE_PREFIX, type DataBackendInput, type DataGroup, DataGroupBackendError, type DataGroupCandidate, DataGroupCreateError, type DataGroupFlushResult, type DataGroupInfo, DataGroupNotFoundError, DataGroupOperationError, type DataGroupSource, type DataGroupSyncEvent, type DataGroupSyncProgress, type DataGroupSyncResult, type DerivedIdentityInput, type EnsureDataGroupOptions, type EnsureDataGroupResult, FolderStore, GITEE_BACKEND_METADATA, GITHUB_BACKEND_METADATA, GROUP_DESCRIPTOR_FILE, type GroupAliasDescriptor, type GroupDescriptor, type GroupIdentity, type GroupInstanceIdRootResult, type GroupProbeResult, type GroupProbeState, type IConfigRepo, type IdentityBindingResult, type IdentityCandidate, type IdentityCandidateSource, type IdentityConflictReason, type IdentityResolutionMode, type IdentityResolutionResult, InvalidBackendError, type KeepPurgeResult, LEGACY_CONFLICTS_DIR, LEGACY_TOMBSTONES_DIR, LOCAL_IDB_BACKEND_ID, LOCAL_STORAGE_UNAVAILABLE, type LocalStorageUnavailableDetails, LocalStorageUnavailableError, type LocalStoreDeletionResult, META_DIR, type MigrateLocalFS, type MigrateReplicaFS, type MtimePurgeResult, NeedsInitError, type PreferenceOptions, type PreferenceStorage, type PurgeKeepOptions, type PurgeLocalSyncConfigOptions, type PurgeLocalSyncConfigResult, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, REMOTESTORAGE_BACKEND_METADATA, type RemoteIdentitySnapshot, type RemoteIdentityState, RemoteUnreachableError, type ReplicaSetupSummary, type ResolveDataGroupOptions, type SetGroupInstanceIdOptions, type SetGroupInstanceIdResult, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupSyncEvent, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, type UiConnection, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, WEBDAV_BACKEND_METADATA, backendSupportsAccessMode, bindRemoteGroupIdentity, bindRemoteGroupIdentityDetailed, collectDataGroupCandidates, configKeyToFilePath, connect, connectV2, connectionToAppRepo, createBackend, createConfigRepo, createSerializerChain, dataGroupLocalStoreName, deleteDataGroupLocalStore, deleteIndexedDbStore, deriveGroupInstanceId, encodeMetaPath, ensureDataGroup, getAccountFields, getBackendMetadata, getExtension, getPreferredDataGroupId, getUiConnection, groupAliasFilePath, groupHasPath, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalBackendType, isLocalStorageUnavailableError, isMtimeSidecar, isValidGroupInstanceId, legacyVersionPathFor, listBackendMetadata, listBackends, listDataGroupCandidates, localPrimaryType, localSyncStoreNames, mergeAccountFields, migrateVersionSidecars, newGroupInstanceId, probeGroupTypeDetailed, purgeKeepFiles, purgeLocalSyncConfig, purgeMtimeSidecars, readGroupAlias, readGroupAliases, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, registerGiteeBackend, registerGithubBackend, registerRemoteStorageBackend, registerWebdavBackend, resolveDataGroup, resolveLocalPrimary, resolveRemoteIdentity, setPreferredDataGroupId, sha256, shortInstanceId, stripAccountFields, summarizeIdentity, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupAlias, writeGroupDescriptor, writeVersion };
|
|
3233
|
+
export { ALIASES_DIR, type AddBackendResult, type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type AppRepo, BackendAlreadyExistsError, type BackendConflictInfo, type BackendConflictReason, type BackendConflictResolution, type BackendConflictResolutionResult, type BackendDescriptor, BackendEndpointConflictError, type BackendFactory, BackendIdentityError, type BackendInstance, type BackendMetadata, type BackendModuleLoader, type BackendParamDef, type BackendSyncState, type BackendsMeta, CONFIG_DIR, CONFLICTS_DIR, type CacheOptions, type ConfigBackendInput, ConfigNotReadyError, ConfigRepo, type ConfigRepoOptions, type ConfigSerializer, type ConfigSyncGroupDescriptor, type ConfigSyncGroupHandle, type ConflictArchive, type ConflictInfo, ConflictStore, ConnectFailedError, type ConnectOptions, type ConnectResult, ConnectV2Error, type ConnectV2Options, DATA_GROUP_DEFAULT_FEATURES, DATA_GROUP_PREFERENCE_PREFIX, type DataBackendInput, type DataGroup, DataGroupBackendError, type DataGroupCandidate, DataGroupCreateError, type DataGroupFlushResult, type DataGroupInfo, DataGroupNotFoundError, DataGroupOperationError, type DataGroupSource, type DataGroupSyncEvent, type DataGroupSyncProgress, type DataGroupSyncResult, type DerivedIdentityInput, type EnsureDataGroupOptions, type EnsureDataGroupResult, FolderStore, GITEE_BACKEND_METADATA, GITHUB_BACKEND_METADATA, GROUP_DESCRIPTOR_FILE, type GroupAliasDescriptor, type GroupDescriptor, type GroupIdentity, type GroupInstanceIdRootResult, type GroupProbeResult, type GroupProbeState, type IConfigRepo, INO_BLOCK, type IdentityBindingResult, type IdentityCandidate, type IdentityCandidateSource, type IdentityConflictReason, type IdentityResolutionMode, type IdentityResolutionResult, InvalidBackendError, type KeepPurgeResult, LEGACY_CONFLICTS_DIR, LEGACY_TOMBSTONES_DIR, LOCAL_IDB_BACKEND_ID, LOCAL_STORAGE_UNAVAILABLE, type LocalStorageUnavailableDetails, LocalStorageUnavailableError, type LocalStoreDeletionResult, META_DIR, type MigrateLocalFS, type MigrateReplicaFS, type MtimePurgeResult, NeedsInitError, type PreferenceOptions, type PreferenceStorage, type PurgeKeepOptions, type PurgeLocalSyncConfigOptions, type PurgeLocalSyncConfigResult, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, REMOTESTORAGE_BACKEND_METADATA, type RemoteIdentitySnapshot, type RemoteIdentityState, RemoteUnreachableError, type ReplicaSetupSummary, type ResolveDataGroupOptions, type SetGroupInstanceIdOptions, type SetGroupInstanceIdResult, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupSyncEvent, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, type UiConnection, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, WEBDAV_BACKEND_METADATA, attachAllocId, backendSupportsAccessMode, bindRemoteGroupIdentity, bindRemoteGroupIdentityDetailed, collectDataGroupCandidates, configKeyToFilePath, connect, connectV2, connectionToAppRepo, createBackend, createConfigRepo, createSerializerChain, dataGroupLocalStoreName, deleteDataGroupLocalStore, deleteIndexedDbStore, deriveGroupInstanceId, encodeMetaPath, ensureDataGroup, getAccountFields, getBackendMetadata, getExtension, getPreferredDataGroupId, getUiConnection, groupAliasFilePath, groupHasPath, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalBackendType, isLocalStorageUnavailableError, isMtimeSidecar, isValidGroupInstanceId, legacyVersionPathFor, listBackendMetadata, listBackends, listDataGroupCandidates, localPrimaryType, localSyncStoreNames, mergeAccountFields, migrateVersionSidecars, newGroupInstanceId, openStoreDb, probeGroupTypeDetailed, purgeKeepFiles, purgeLocalSyncConfig, purgeMtimeSidecars, readGroupAlias, readGroupAliases, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, registerGiteeBackend, registerGithubBackend, registerRemoteStorageBackend, registerWebdavBackend, resolveDataGroup, resolveLocalPrimary, resolveRemoteIdentity, setPreferredDataGroupId, sha256, shortInstanceId, stripAccountFields, summarizeIdentity, unregisterBackend, verifyOrRepairVersion, versionPathFor, withAllocId, wrapZenFSFileSystem, writeGroupAlias, writeGroupDescriptor, writeVersion };
|
package/dist/index.d.ts
CHANGED
|
@@ -2823,6 +2823,44 @@ declare function getUiConnection(repo: AppRepo): UiConnection;
|
|
|
2823
2823
|
*/
|
|
2824
2824
|
declare function connectV2(appId: string, options?: ConnectV2Options): Promise<AppRepo>;
|
|
2825
2825
|
|
|
2826
|
+
/**
|
|
2827
|
+
* StoreFS inode 撞号(id collision)防护。
|
|
2828
|
+
*
|
|
2829
|
+
* 背景
|
|
2830
|
+
* ----
|
|
2831
|
+
* `@zenfs/core` 的 StoreFS 打开库时用 `_populate` 把目录树展开成内存索引;
|
|
2832
|
+
* `allocNew()` 在没有 `store.allocId` 的情况下用 `max(_paths.keys()) + 2` 推导
|
|
2833
|
+
* 下一个 inode 号。`_populate` 只要遇到一个解不开的目录表就整体中断,索引残缺
|
|
2834
|
+
* → 推导出的号落在已有节点上 → `commitNew` 覆盖别人的 data slot(目录表被文件
|
|
2835
|
+
* 字节顶掉),此后每次 readdir 都报 `Cannot convert <path> to a BigInt`,同步再
|
|
2836
|
+
* 把这个损坏推给远端。
|
|
2837
|
+
*
|
|
2838
|
+
* `allocNew` 的第一行就是 `if (this.store.allocId) { ... }`:官方把发号权留给
|
|
2839
|
+
* Store(SingleBuffer v2 就用持久化原子计数器实现)。IndexedDB 的 store
|
|
2840
|
+
* (`@zenfs/dom`)没有实现它,所以永远走推导分支 —— 这就是缺口。
|
|
2841
|
+
*
|
|
2842
|
+
* 做法
|
|
2843
|
+
* ----
|
|
2844
|
+
* 打开库时从持久化高水位里**预占一段连续号**,把区间放在内存,`allocId()` 同步
|
|
2845
|
+
* 从区间里取号:满足接口的同步签名,且完全不再依赖内存索引。预占写在独立的
|
|
2846
|
+
* meta 库里,用 readwrite 事务完成;IndexedDB 对同一 object store 的读写事务
|
|
2847
|
+
* 天然串行,多个标签页拿到的是互不相交的区间,不需要额外加锁。
|
|
2848
|
+
*/
|
|
2849
|
+
/** 每次打开预占的号段长度(含 ino 与 data 槽,实际可用约 1.6 万个新节点)。 */
|
|
2850
|
+
declare const INO_BLOCK = 32768;
|
|
2851
|
+
/** 打开(必要时创建)StoreFS 使用的库,与 `@zenfs/dom` 的 createDB 行为一致。 */
|
|
2852
|
+
declare function openStoreDb(name: string): Promise<any>;
|
|
2853
|
+
/**
|
|
2854
|
+
* 给任意 IndexedDB store 实例挂上 `allocId`:
|
|
2855
|
+
* 高水位 = max(持久化值, 磁盘上已有的最大 key),再原子推进一整段。
|
|
2856
|
+
*/
|
|
2857
|
+
declare function attachAllocId(store: any, storeName: string, db: any): Promise<void>;
|
|
2858
|
+
/**
|
|
2859
|
+
* 把 `@zenfs/dom` 的 IndexedDB 后端描述符包一层,create 时构造带 `allocId` 的
|
|
2860
|
+
* store。保持 name / options / isAvailable 不变,`resolveMountConfig` 照旧可用。
|
|
2861
|
+
*/
|
|
2862
|
+
declare function withAllocId(base: any): any;
|
|
2863
|
+
|
|
2826
2864
|
/**
|
|
2827
2865
|
* zen-fs-config — Sidecar Version File Management
|
|
2828
2866
|
*
|
|
@@ -3192,4 +3230,4 @@ interface EnsureDataGroupResult {
|
|
|
3192
3230
|
*/
|
|
3193
3231
|
declare function ensureDataGroup(source: DataGroupSource, appId: string, opts?: EnsureDataGroupOptions): Promise<EnsureDataGroupResult>;
|
|
3194
3232
|
|
|
3195
|
-
export { ALIASES_DIR, type AddBackendResult, type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type AppRepo, BackendAlreadyExistsError, type BackendConflictInfo, type BackendConflictReason, type BackendConflictResolution, type BackendConflictResolutionResult, type BackendDescriptor, BackendEndpointConflictError, type BackendFactory, BackendIdentityError, type BackendInstance, type BackendMetadata, type BackendModuleLoader, type BackendParamDef, type BackendSyncState, type BackendsMeta, CONFIG_DIR, CONFLICTS_DIR, type CacheOptions, type ConfigBackendInput, ConfigNotReadyError, ConfigRepo, type ConfigRepoOptions, type ConfigSerializer, type ConfigSyncGroupDescriptor, type ConfigSyncGroupHandle, type ConflictArchive, type ConflictInfo, ConflictStore, ConnectFailedError, type ConnectOptions, type ConnectResult, ConnectV2Error, type ConnectV2Options, DATA_GROUP_DEFAULT_FEATURES, DATA_GROUP_PREFERENCE_PREFIX, type DataBackendInput, type DataGroup, DataGroupBackendError, type DataGroupCandidate, DataGroupCreateError, type DataGroupFlushResult, type DataGroupInfo, DataGroupNotFoundError, DataGroupOperationError, type DataGroupSource, type DataGroupSyncEvent, type DataGroupSyncProgress, type DataGroupSyncResult, type DerivedIdentityInput, type EnsureDataGroupOptions, type EnsureDataGroupResult, FolderStore, GITEE_BACKEND_METADATA, GITHUB_BACKEND_METADATA, GROUP_DESCRIPTOR_FILE, type GroupAliasDescriptor, type GroupDescriptor, type GroupIdentity, type GroupInstanceIdRootResult, type GroupProbeResult, type GroupProbeState, type IConfigRepo, type IdentityBindingResult, type IdentityCandidate, type IdentityCandidateSource, type IdentityConflictReason, type IdentityResolutionMode, type IdentityResolutionResult, InvalidBackendError, type KeepPurgeResult, LEGACY_CONFLICTS_DIR, LEGACY_TOMBSTONES_DIR, LOCAL_IDB_BACKEND_ID, LOCAL_STORAGE_UNAVAILABLE, type LocalStorageUnavailableDetails, LocalStorageUnavailableError, type LocalStoreDeletionResult, META_DIR, type MigrateLocalFS, type MigrateReplicaFS, type MtimePurgeResult, NeedsInitError, type PreferenceOptions, type PreferenceStorage, type PurgeKeepOptions, type PurgeLocalSyncConfigOptions, type PurgeLocalSyncConfigResult, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, REMOTESTORAGE_BACKEND_METADATA, type RemoteIdentitySnapshot, type RemoteIdentityState, RemoteUnreachableError, type ReplicaSetupSummary, type ResolveDataGroupOptions, type SetGroupInstanceIdOptions, type SetGroupInstanceIdResult, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupSyncEvent, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, type UiConnection, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, WEBDAV_BACKEND_METADATA, backendSupportsAccessMode, bindRemoteGroupIdentity, bindRemoteGroupIdentityDetailed, collectDataGroupCandidates, configKeyToFilePath, connect, connectV2, connectionToAppRepo, createBackend, createConfigRepo, createSerializerChain, dataGroupLocalStoreName, deleteDataGroupLocalStore, deleteIndexedDbStore, deriveGroupInstanceId, encodeMetaPath, ensureDataGroup, getAccountFields, getBackendMetadata, getExtension, getPreferredDataGroupId, getUiConnection, groupAliasFilePath, groupHasPath, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalBackendType, isLocalStorageUnavailableError, isMtimeSidecar, isValidGroupInstanceId, legacyVersionPathFor, listBackendMetadata, listBackends, listDataGroupCandidates, localPrimaryType, localSyncStoreNames, mergeAccountFields, migrateVersionSidecars, newGroupInstanceId, probeGroupTypeDetailed, purgeKeepFiles, purgeLocalSyncConfig, purgeMtimeSidecars, readGroupAlias, readGroupAliases, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, registerGiteeBackend, registerGithubBackend, registerRemoteStorageBackend, registerWebdavBackend, resolveDataGroup, resolveLocalPrimary, resolveRemoteIdentity, setPreferredDataGroupId, sha256, shortInstanceId, stripAccountFields, summarizeIdentity, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupAlias, writeGroupDescriptor, writeVersion };
|
|
3233
|
+
export { ALIASES_DIR, type AddBackendResult, type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type AppRepo, BackendAlreadyExistsError, type BackendConflictInfo, type BackendConflictReason, type BackendConflictResolution, type BackendConflictResolutionResult, type BackendDescriptor, BackendEndpointConflictError, type BackendFactory, BackendIdentityError, type BackendInstance, type BackendMetadata, type BackendModuleLoader, type BackendParamDef, type BackendSyncState, type BackendsMeta, CONFIG_DIR, CONFLICTS_DIR, type CacheOptions, type ConfigBackendInput, ConfigNotReadyError, ConfigRepo, type ConfigRepoOptions, type ConfigSerializer, type ConfigSyncGroupDescriptor, type ConfigSyncGroupHandle, type ConflictArchive, type ConflictInfo, ConflictStore, ConnectFailedError, type ConnectOptions, type ConnectResult, ConnectV2Error, type ConnectV2Options, DATA_GROUP_DEFAULT_FEATURES, DATA_GROUP_PREFERENCE_PREFIX, type DataBackendInput, type DataGroup, DataGroupBackendError, type DataGroupCandidate, DataGroupCreateError, type DataGroupFlushResult, type DataGroupInfo, DataGroupNotFoundError, DataGroupOperationError, type DataGroupSource, type DataGroupSyncEvent, type DataGroupSyncProgress, type DataGroupSyncResult, type DerivedIdentityInput, type EnsureDataGroupOptions, type EnsureDataGroupResult, FolderStore, GITEE_BACKEND_METADATA, GITHUB_BACKEND_METADATA, GROUP_DESCRIPTOR_FILE, type GroupAliasDescriptor, type GroupDescriptor, type GroupIdentity, type GroupInstanceIdRootResult, type GroupProbeResult, type GroupProbeState, type IConfigRepo, INO_BLOCK, type IdentityBindingResult, type IdentityCandidate, type IdentityCandidateSource, type IdentityConflictReason, type IdentityResolutionMode, type IdentityResolutionResult, InvalidBackendError, type KeepPurgeResult, LEGACY_CONFLICTS_DIR, LEGACY_TOMBSTONES_DIR, LOCAL_IDB_BACKEND_ID, LOCAL_STORAGE_UNAVAILABLE, type LocalStorageUnavailableDetails, LocalStorageUnavailableError, type LocalStoreDeletionResult, META_DIR, type MigrateLocalFS, type MigrateReplicaFS, type MtimePurgeResult, NeedsInitError, type PreferenceOptions, type PreferenceStorage, type PurgeKeepOptions, type PurgeLocalSyncConfigOptions, type PurgeLocalSyncConfigResult, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, REMOTESTORAGE_BACKEND_METADATA, type RemoteIdentitySnapshot, type RemoteIdentityState, RemoteUnreachableError, type ReplicaSetupSummary, type ResolveDataGroupOptions, type SetGroupInstanceIdOptions, type SetGroupInstanceIdResult, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupSyncEvent, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, type UiConnection, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, WEBDAV_BACKEND_METADATA, attachAllocId, backendSupportsAccessMode, bindRemoteGroupIdentity, bindRemoteGroupIdentityDetailed, collectDataGroupCandidates, configKeyToFilePath, connect, connectV2, connectionToAppRepo, createBackend, createConfigRepo, createSerializerChain, dataGroupLocalStoreName, deleteDataGroupLocalStore, deleteIndexedDbStore, deriveGroupInstanceId, encodeMetaPath, ensureDataGroup, getAccountFields, getBackendMetadata, getExtension, getPreferredDataGroupId, getUiConnection, groupAliasFilePath, groupHasPath, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalBackendType, isLocalStorageUnavailableError, isMtimeSidecar, isValidGroupInstanceId, legacyVersionPathFor, listBackendMetadata, listBackends, listDataGroupCandidates, localPrimaryType, localSyncStoreNames, mergeAccountFields, migrateVersionSidecars, newGroupInstanceId, openStoreDb, probeGroupTypeDetailed, purgeKeepFiles, purgeLocalSyncConfig, purgeMtimeSidecars, readGroupAlias, readGroupAliases, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, registerGiteeBackend, registerGithubBackend, registerRemoteStorageBackend, registerWebdavBackend, resolveDataGroup, resolveLocalPrimary, resolveRemoteIdentity, setPreferredDataGroupId, sha256, shortInstanceId, stripAccountFields, summarizeIdentity, unregisterBackend, verifyOrRepairVersion, versionPathFor, withAllocId, wrapZenFSFileSystem, writeGroupAlias, writeGroupDescriptor, writeVersion };
|
package/dist/index.js
CHANGED
|
@@ -47,22 +47,22 @@ function openDB(name) {
|
|
|
47
47
|
const factory = idb();
|
|
48
48
|
if (!factory) return Promise.resolve(null);
|
|
49
49
|
return new Promise((resolve) => {
|
|
50
|
-
let
|
|
50
|
+
let req2;
|
|
51
51
|
try {
|
|
52
|
-
|
|
52
|
+
req2 = factory.open(name);
|
|
53
53
|
} catch {
|
|
54
54
|
resolve(null);
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
req2.onupgradeneeded = () => {
|
|
58
58
|
try {
|
|
59
|
-
|
|
59
|
+
req2.transaction?.abort();
|
|
60
60
|
} catch {
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
req2.onsuccess = () => resolve(req2.result);
|
|
64
|
+
req2.onerror = () => resolve(null);
|
|
65
|
+
req2.onblocked = () => resolve(null);
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
function isDecodableListing(bytes) {
|
|
@@ -176,13 +176,135 @@ var init_idb_repair = __esm({
|
|
|
176
176
|
S_IFMT = 61440;
|
|
177
177
|
S_IFDIR = 16384;
|
|
178
178
|
LEGACY_LISTING_MAGIC = 123;
|
|
179
|
-
request = (
|
|
180
|
-
|
|
181
|
-
|
|
179
|
+
request = (req2) => new Promise((resolve, reject) => {
|
|
180
|
+
req2.onsuccess = () => resolve(req2.result);
|
|
181
|
+
req2.onerror = () => reject(req2.error);
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
184
|
});
|
|
185
185
|
|
|
186
|
+
// src/idb-alloc.ts
|
|
187
|
+
function idbFactory() {
|
|
188
|
+
return globalThis.indexedDB ?? null;
|
|
189
|
+
}
|
|
190
|
+
function req(request2) {
|
|
191
|
+
return new Promise((resolve, reject) => {
|
|
192
|
+
request2.onsuccess = () => resolve(request2.result);
|
|
193
|
+
request2.onerror = () => reject(request2.error);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
function txDone(tx) {
|
|
197
|
+
return new Promise((resolve, reject) => {
|
|
198
|
+
tx.oncomplete = () => resolve();
|
|
199
|
+
tx.onerror = () => reject(tx.error);
|
|
200
|
+
tx.onabort = () => reject(tx.error);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
function openStoreDb(name) {
|
|
204
|
+
const factory = idbFactory();
|
|
205
|
+
if (!factory) return Promise.reject(new Error("IndexedDB is not available"));
|
|
206
|
+
return new Promise((resolve, reject) => {
|
|
207
|
+
const request2 = factory.open(name);
|
|
208
|
+
request2.onupgradeneeded = () => {
|
|
209
|
+
const db = request2.result;
|
|
210
|
+
if (db.objectStoreNames.contains(name)) db.deleteObjectStore(name);
|
|
211
|
+
db.createObjectStore(name);
|
|
212
|
+
};
|
|
213
|
+
request2.onsuccess = () => resolve(request2.result);
|
|
214
|
+
request2.onerror = () => reject(request2.error);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function openMetaDb(name) {
|
|
218
|
+
const factory = idbFactory();
|
|
219
|
+
if (!factory) return Promise.reject(new Error("IndexedDB is not available"));
|
|
220
|
+
return new Promise((resolve, reject) => {
|
|
221
|
+
const request2 = factory.open(name, 1);
|
|
222
|
+
request2.onupgradeneeded = () => {
|
|
223
|
+
const db = request2.result;
|
|
224
|
+
if (!db.objectStoreNames.contains(META_STORE)) db.createObjectStore(META_STORE);
|
|
225
|
+
};
|
|
226
|
+
request2.onsuccess = () => resolve(request2.result);
|
|
227
|
+
request2.onerror = () => reject(request2.error);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
async function attachAllocId(store, storeName, db) {
|
|
231
|
+
const keys = await req(
|
|
232
|
+
db.transaction(storeName, "readonly").objectStore(storeName).getAllKeys()
|
|
233
|
+
);
|
|
234
|
+
let diskMax = 0;
|
|
235
|
+
for (const raw of keys) {
|
|
236
|
+
const n = Number(raw);
|
|
237
|
+
if (Number.isFinite(n) && n > diskMax) diskMax = n;
|
|
238
|
+
}
|
|
239
|
+
const metaDb = await openMetaDb(storeName + META_DB_SUFFIX);
|
|
240
|
+
let base;
|
|
241
|
+
let end;
|
|
242
|
+
try {
|
|
243
|
+
const tx = metaDb.transaction(META_STORE, "readwrite");
|
|
244
|
+
const meta = tx.objectStore(META_STORE);
|
|
245
|
+
const persisted = Number(await req(meta.get(HWM_KEY))) || 0;
|
|
246
|
+
base = Math.max(persisted, diskMax);
|
|
247
|
+
if (base % 2 !== 0) base += 1;
|
|
248
|
+
end = base + INO_BLOCK;
|
|
249
|
+
meta.put(end, HWM_KEY);
|
|
250
|
+
await txDone(tx);
|
|
251
|
+
} finally {
|
|
252
|
+
try {
|
|
253
|
+
metaDb.close?.();
|
|
254
|
+
} catch {
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
let next = base + 2;
|
|
258
|
+
store.allocId = () => {
|
|
259
|
+
if (next >= end) {
|
|
260
|
+
throw new Error(
|
|
261
|
+
`[zen-fs-config] ${storeName}: inode \u53F7\u6BB5\u5DF2\u7528\u5C3D\uFF08${base}~${end}\uFF09\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00\u8BE5\u5E93`
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
const id = next;
|
|
265
|
+
next += 2;
|
|
266
|
+
return [id, id + 1];
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
function withAllocId(base) {
|
|
270
|
+
return {
|
|
271
|
+
name: base?.name ?? "IndexedDB",
|
|
272
|
+
options: base?.options ?? {},
|
|
273
|
+
isAvailable: base?.isAvailable?.bind?.(base) ?? (() => !!idbFactory()),
|
|
274
|
+
async create(options) {
|
|
275
|
+
const storeName = String(options?.storeName ?? "zen-fs-config");
|
|
276
|
+
await repairIndexedDBStore(storeName);
|
|
277
|
+
const db = await openStoreDb(storeName);
|
|
278
|
+
db.onversionchange = () => {
|
|
279
|
+
try {
|
|
280
|
+
db.close();
|
|
281
|
+
} catch {
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
const { IndexedDBStore } = await import("@zenfs/dom");
|
|
285
|
+
const store = new IndexedDBStore(db);
|
|
286
|
+
await attachAllocId(store, storeName, db);
|
|
287
|
+
const zenfs = await import("@zenfs/core");
|
|
288
|
+
const fs = new zenfs.StoreFS(store);
|
|
289
|
+
if (!options?.disableAsyncCache) {
|
|
290
|
+
await store.transaction().preload();
|
|
291
|
+
}
|
|
292
|
+
return fs;
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
var INO_BLOCK, META_DB_SUFFIX, META_STORE, HWM_KEY;
|
|
297
|
+
var init_idb_alloc = __esm({
|
|
298
|
+
"src/idb-alloc.ts"() {
|
|
299
|
+
"use strict";
|
|
300
|
+
init_idb_repair();
|
|
301
|
+
INO_BLOCK = 32768;
|
|
302
|
+
META_DB_SUFFIX = "__ino";
|
|
303
|
+
META_STORE = "meta";
|
|
304
|
+
HWM_KEY = "inoHwm";
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
|
|
186
308
|
// src/backend-registry.ts
|
|
187
309
|
var backend_registry_exports = {};
|
|
188
310
|
__export(backend_registry_exports, {
|
|
@@ -591,7 +713,7 @@ var registry, metadataRegistry, REGISTRY_TOKEN, REGISTRY_GLOBAL_KEY, inMemoryCou
|
|
|
591
713
|
var init_backend_registry = __esm({
|
|
592
714
|
"src/backend-registry.ts"() {
|
|
593
715
|
"use strict";
|
|
594
|
-
|
|
716
|
+
init_idb_alloc();
|
|
595
717
|
registry = /* @__PURE__ */ new Map();
|
|
596
718
|
metadataRegistry = /* @__PURE__ */ new Map();
|
|
597
719
|
REGISTRY_TOKEN = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
@@ -630,13 +752,7 @@ var init_backend_registry = __esm({
|
|
|
630
752
|
const { IndexedDB } = await import("@zenfs/dom");
|
|
631
753
|
const storeName = options.storeName ?? "zen-fs-config";
|
|
632
754
|
const label = options.label ?? storeName;
|
|
633
|
-
|
|
634
|
-
if (repaired?.repaired) {
|
|
635
|
-
console.warn(
|
|
636
|
-
`[Backend:IndexedDB] ${storeName}: reset ${repaired.repaired} corrupted directory listing(s): ` + repaired.details.map((d) => `ino ${d.key}\u2192slot ${d.data} (${d.reason})`).join(", ")
|
|
637
|
-
);
|
|
638
|
-
}
|
|
639
|
-
return wrapZenFSFileSystem({ backend: IndexedDB, storeName, label });
|
|
755
|
+
return wrapZenFSFileSystem({ backend: withAllocId(IndexedDB), storeName, label });
|
|
640
756
|
}, {
|
|
641
757
|
type: "IndexedDB",
|
|
642
758
|
label: "IndexedDB",
|
|
@@ -812,6 +928,7 @@ __export(index_exports, {
|
|
|
812
928
|
GITEE_BACKEND_METADATA: () => GITEE_BACKEND_METADATA,
|
|
813
929
|
GITHUB_BACKEND_METADATA: () => GITHUB_BACKEND_METADATA,
|
|
814
930
|
GROUP_DESCRIPTOR_FILE: () => GROUP_DESCRIPTOR_FILE2,
|
|
931
|
+
INO_BLOCK: () => INO_BLOCK,
|
|
815
932
|
InvalidBackendError: () => InvalidBackendError,
|
|
816
933
|
LEGACY_CONFLICTS_DIR: () => LEGACY_CONFLICTS_DIR,
|
|
817
934
|
LEGACY_TOMBSTONES_DIR: () => LEGACY_TOMBSTONES_DIR,
|
|
@@ -827,6 +944,7 @@ __export(index_exports, {
|
|
|
827
944
|
VERSIONS_DIR: () => VERSIONS_DIR,
|
|
828
945
|
VersionStore: () => VersionStore,
|
|
829
946
|
WEBDAV_BACKEND_METADATA: () => WEBDAV_BACKEND_METADATA,
|
|
947
|
+
attachAllocId: () => attachAllocId,
|
|
830
948
|
backendSupportsAccessMode: () => backendSupportsAccessMode,
|
|
831
949
|
bindRemoteGroupIdentity: () => bindRemoteGroupIdentity,
|
|
832
950
|
bindRemoteGroupIdentityDetailed: () => bindRemoteGroupIdentityDetailed,
|
|
@@ -868,6 +986,7 @@ __export(index_exports, {
|
|
|
868
986
|
mergeAccountFields: () => mergeAccountFields,
|
|
869
987
|
migrateVersionSidecars: () => migrateVersionSidecars,
|
|
870
988
|
newGroupInstanceId: () => newGroupInstanceId,
|
|
989
|
+
openStoreDb: () => openStoreDb,
|
|
871
990
|
probeGroupTypeDetailed: () => probeGroupTypeDetailed,
|
|
872
991
|
purgeKeepFiles: () => purgeKeepFiles,
|
|
873
992
|
purgeLocalSyncConfig: () => purgeLocalSyncConfig,
|
|
@@ -893,6 +1012,7 @@ __export(index_exports, {
|
|
|
893
1012
|
unregisterBackend: () => unregisterBackend,
|
|
894
1013
|
verifyOrRepairVersion: () => verifyOrRepairVersion,
|
|
895
1014
|
versionPathFor: () => versionPathFor,
|
|
1015
|
+
withAllocId: () => withAllocId,
|
|
896
1016
|
wrapZenFSFileSystem: () => wrapZenFSFileSystem,
|
|
897
1017
|
writeGroupAlias: () => writeGroupAlias,
|
|
898
1018
|
writeGroupDescriptor: () => writeGroupDescriptor,
|
|
@@ -9681,6 +9801,7 @@ function normalizeOptions(options) {
|
|
|
9681
9801
|
|
|
9682
9802
|
// src/index.ts
|
|
9683
9803
|
init_backend_registry();
|
|
9804
|
+
init_idb_alloc();
|
|
9684
9805
|
init_backend_registry();
|
|
9685
9806
|
|
|
9686
9807
|
// src/data-group-selection.ts
|
|
@@ -9899,6 +10020,7 @@ async function ensureDataGroup(source, appId, opts = {}) {
|
|
|
9899
10020
|
GITEE_BACKEND_METADATA,
|
|
9900
10021
|
GITHUB_BACKEND_METADATA,
|
|
9901
10022
|
GROUP_DESCRIPTOR_FILE,
|
|
10023
|
+
INO_BLOCK,
|
|
9902
10024
|
InvalidBackendError,
|
|
9903
10025
|
LEGACY_CONFLICTS_DIR,
|
|
9904
10026
|
LEGACY_TOMBSTONES_DIR,
|
|
@@ -9914,6 +10036,7 @@ async function ensureDataGroup(source, appId, opts = {}) {
|
|
|
9914
10036
|
VERSIONS_DIR,
|
|
9915
10037
|
VersionStore,
|
|
9916
10038
|
WEBDAV_BACKEND_METADATA,
|
|
10039
|
+
attachAllocId,
|
|
9917
10040
|
backendSupportsAccessMode,
|
|
9918
10041
|
bindRemoteGroupIdentity,
|
|
9919
10042
|
bindRemoteGroupIdentityDetailed,
|
|
@@ -9955,6 +10078,7 @@ async function ensureDataGroup(source, appId, opts = {}) {
|
|
|
9955
10078
|
mergeAccountFields,
|
|
9956
10079
|
migrateVersionSidecars,
|
|
9957
10080
|
newGroupInstanceId,
|
|
10081
|
+
openStoreDb,
|
|
9958
10082
|
probeGroupTypeDetailed,
|
|
9959
10083
|
purgeKeepFiles,
|
|
9960
10084
|
purgeLocalSyncConfig,
|
|
@@ -9980,6 +10104,7 @@ async function ensureDataGroup(source, appId, opts = {}) {
|
|
|
9980
10104
|
unregisterBackend,
|
|
9981
10105
|
verifyOrRepairVersion,
|
|
9982
10106
|
versionPathFor,
|
|
10107
|
+
withAllocId,
|
|
9983
10108
|
wrapZenFSFileSystem,
|
|
9984
10109
|
writeGroupAlias,
|
|
9985
10110
|
writeGroupDescriptor,
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
GITEE_BACKEND_METADATA,
|
|
3
3
|
GITHUB_BACKEND_METADATA,
|
|
4
|
+
INO_BLOCK,
|
|
4
5
|
REMOTESTORAGE_BACKEND_METADATA,
|
|
5
6
|
WEBDAV_BACKEND_METADATA,
|
|
7
|
+
attachAllocId,
|
|
6
8
|
backendSupportsAccessMode,
|
|
7
9
|
createBackend,
|
|
8
10
|
getAccountFields,
|
|
@@ -11,6 +13,7 @@ import {
|
|
|
11
13
|
listBackendMetadata,
|
|
12
14
|
listBackends,
|
|
13
15
|
mergeAccountFields,
|
|
16
|
+
openStoreDb,
|
|
14
17
|
registerBackend,
|
|
15
18
|
registerGiteeBackend,
|
|
16
19
|
registerGithubBackend,
|
|
@@ -18,8 +21,9 @@ import {
|
|
|
18
21
|
registerWebdavBackend,
|
|
19
22
|
stripAccountFields,
|
|
20
23
|
unregisterBackend,
|
|
24
|
+
withAllocId,
|
|
21
25
|
wrapZenFSFileSystem
|
|
22
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-7QFHGFCG.mjs";
|
|
23
27
|
|
|
24
28
|
// src/config-repo.ts
|
|
25
29
|
import {
|
|
@@ -511,7 +515,7 @@ function registerFolderBackend() {
|
|
|
511
515
|
const pathMod = await import("path");
|
|
512
516
|
const dir = options.path;
|
|
513
517
|
const store = new FolderStore({ path: dir, label: options.label, fs, pathMod });
|
|
514
|
-
return (await import("./backend-registry-
|
|
518
|
+
return (await import("./backend-registry-R6L6MFJS.mjs")).wrapZenFSFileSystem({ backend: FolderBackend, path: dir, label: options.label });
|
|
515
519
|
},
|
|
516
520
|
{
|
|
517
521
|
type: "Folder",
|
|
@@ -9012,6 +9016,7 @@ export {
|
|
|
9012
9016
|
GITEE_BACKEND_METADATA,
|
|
9013
9017
|
GITHUB_BACKEND_METADATA,
|
|
9014
9018
|
GROUP_DESCRIPTOR_FILE2 as GROUP_DESCRIPTOR_FILE,
|
|
9019
|
+
INO_BLOCK,
|
|
9015
9020
|
InvalidBackendError,
|
|
9016
9021
|
LEGACY_CONFLICTS_DIR,
|
|
9017
9022
|
LEGACY_TOMBSTONES_DIR,
|
|
@@ -9027,6 +9032,7 @@ export {
|
|
|
9027
9032
|
VERSIONS_DIR,
|
|
9028
9033
|
VersionStore,
|
|
9029
9034
|
WEBDAV_BACKEND_METADATA,
|
|
9035
|
+
attachAllocId,
|
|
9030
9036
|
backendSupportsAccessMode,
|
|
9031
9037
|
bindRemoteGroupIdentity,
|
|
9032
9038
|
bindRemoteGroupIdentityDetailed,
|
|
@@ -9068,6 +9074,7 @@ export {
|
|
|
9068
9074
|
mergeAccountFields,
|
|
9069
9075
|
migrateVersionSidecars,
|
|
9070
9076
|
newGroupInstanceId,
|
|
9077
|
+
openStoreDb,
|
|
9071
9078
|
probeGroupTypeDetailed,
|
|
9072
9079
|
purgeKeepFiles,
|
|
9073
9080
|
purgeLocalSyncConfig,
|
|
@@ -9093,6 +9100,7 @@ export {
|
|
|
9093
9100
|
unregisterBackend,
|
|
9094
9101
|
verifyOrRepairVersion,
|
|
9095
9102
|
versionPathFor,
|
|
9103
|
+
withAllocId,
|
|
9096
9104
|
wrapZenFSFileSystem,
|
|
9097
9105
|
writeGroupAlias,
|
|
9098
9106
|
writeGroupDescriptor,
|
package/dist/zen-fs-config.js
CHANGED
|
@@ -66,22 +66,22 @@ var ZenFSConfig = (() => {
|
|
|
66
66
|
const factory = idb();
|
|
67
67
|
if (!factory) return Promise.resolve(null);
|
|
68
68
|
return new Promise((resolve4) => {
|
|
69
|
-
let
|
|
69
|
+
let req2;
|
|
70
70
|
try {
|
|
71
|
-
|
|
71
|
+
req2 = factory.open(name);
|
|
72
72
|
} catch {
|
|
73
73
|
resolve4(null);
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
req2.onupgradeneeded = () => {
|
|
77
77
|
try {
|
|
78
|
-
|
|
78
|
+
req2.transaction?.abort();
|
|
79
79
|
} catch {
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
req2.onsuccess = () => resolve4(req2.result);
|
|
83
|
+
req2.onerror = () => resolve4(null);
|
|
84
|
+
req2.onblocked = () => resolve4(null);
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
87
|
function isDecodableListing(bytes) {
|
|
@@ -195,9 +195,9 @@ var ZenFSConfig = (() => {
|
|
|
195
195
|
S_IFMT = 61440;
|
|
196
196
|
S_IFDIR = 16384;
|
|
197
197
|
LEGACY_LISTING_MAGIC = 123;
|
|
198
|
-
request = (
|
|
199
|
-
|
|
200
|
-
|
|
198
|
+
request = (req2) => new Promise((resolve4, reject) => {
|
|
199
|
+
req2.onsuccess = () => resolve4(req2.result);
|
|
200
|
+
req2.onerror = () => reject(req2.error);
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
203
|
});
|
|
@@ -19435,7 +19435,7 @@ var ZenFSConfig = (() => {
|
|
|
19435
19435
|
return { response, data: raw ? new Uint8Array(raw) : void 0 };
|
|
19436
19436
|
}
|
|
19437
19437
|
async function get2(url, options, init2 = {}) {
|
|
19438
|
-
const
|
|
19438
|
+
const req2 = new Request(url, init2);
|
|
19439
19439
|
if (typeof options.start != "number" || typeof options.end != "number") {
|
|
19440
19440
|
const { data } = await _fetch(url, init2);
|
|
19441
19441
|
new Resource(url, data.byteLength, options, resourcesCache).add(data, 0);
|
|
@@ -19443,7 +19443,7 @@ var ZenFSConfig = (() => {
|
|
|
19443
19443
|
}
|
|
19444
19444
|
if (typeof options.size != "number") {
|
|
19445
19445
|
options.warn?.(url + ": Size not provided, an additional HEAD request is being made");
|
|
19446
|
-
const { headers } = await fetch(
|
|
19446
|
+
const { headers } = await fetch(req2, { method: "HEAD" });
|
|
19447
19447
|
const size2 = parseInt(headers.get("Content-Length") ?? "");
|
|
19448
19448
|
if (typeof size2 != "number")
|
|
19449
19449
|
throw {
|
|
@@ -19454,9 +19454,9 @@ var ZenFSConfig = (() => {
|
|
|
19454
19454
|
}
|
|
19455
19455
|
const { size, start, end } = options;
|
|
19456
19456
|
const resource = resourcesCache.get(url) ?? new Resource(url, size, options, resourcesCache);
|
|
19457
|
-
|
|
19457
|
+
req2.headers.set("If-Range", (/* @__PURE__ */ new Date()).toUTCString());
|
|
19458
19458
|
for (const { start: from2, end: to } of resource.missing(start, end)) {
|
|
19459
|
-
const { data, response } = await _fetch(
|
|
19459
|
+
const { data, response } = await _fetch(req2, { headers: { Range: `bytes=${from2}-${to}` } });
|
|
19460
19460
|
if (response.status == 206) {
|
|
19461
19461
|
resource.add(data, from2);
|
|
19462
19462
|
continue;
|
|
@@ -20317,7 +20317,7 @@ var ZenFSConfig = (() => {
|
|
|
20317
20317
|
port.send({ ...request3, _zenfs: true, id, stack });
|
|
20318
20318
|
return promise;
|
|
20319
20319
|
}
|
|
20320
|
-
function __requestMethod(
|
|
20320
|
+
function __requestMethod(req2) {
|
|
20321
20321
|
}
|
|
20322
20322
|
function __responseMethod(res, ...t) {
|
|
20323
20323
|
return t.includes(res.method);
|
|
@@ -24061,29 +24061,29 @@ var ZenFSConfig = (() => {
|
|
|
24061
24061
|
});
|
|
24062
24062
|
}
|
|
24063
24063
|
async function createDB(name, indexedDB2 = globalThis.indexedDB) {
|
|
24064
|
-
const
|
|
24065
|
-
|
|
24066
|
-
const db =
|
|
24064
|
+
const req2 = indexedDB2.open(name);
|
|
24065
|
+
req2.onupgradeneeded = () => {
|
|
24066
|
+
const db = req2.result;
|
|
24067
24067
|
if (db.objectStoreNames.contains(name)) {
|
|
24068
24068
|
log_exports.warn("Found unexpected object store: " + name);
|
|
24069
24069
|
db.deleteObjectStore(name);
|
|
24070
24070
|
}
|
|
24071
24071
|
db.createObjectStore(name);
|
|
24072
24072
|
};
|
|
24073
|
-
return await wrap2(
|
|
24073
|
+
return await wrap2(req2);
|
|
24074
24074
|
}
|
|
24075
|
-
async function testAvailability(
|
|
24076
|
-
if (!(
|
|
24075
|
+
async function testAvailability(idbFactory2) {
|
|
24076
|
+
if (!(idbFactory2 instanceof IDBFactory))
|
|
24077
24077
|
return false;
|
|
24078
24078
|
try {
|
|
24079
|
-
const
|
|
24080
|
-
const db = await wrap2(
|
|
24079
|
+
const req2 = idbFactory2.open("__zenfs_test");
|
|
24080
|
+
const db = await wrap2(req2);
|
|
24081
24081
|
db.close();
|
|
24082
24082
|
return true;
|
|
24083
24083
|
} catch {
|
|
24084
24084
|
return false;
|
|
24085
24085
|
} finally {
|
|
24086
|
-
|
|
24086
|
+
idbFactory2?.deleteDatabase("__zenfs_test");
|
|
24087
24087
|
}
|
|
24088
24088
|
}
|
|
24089
24089
|
var IndexedDBTransaction, IndexedDBStore, idbTests, _IndexedDB, IndexedDB;
|
|
@@ -24179,11 +24179,11 @@ var ZenFSConfig = (() => {
|
|
|
24179
24179
|
storeName: { type: "string", required: false },
|
|
24180
24180
|
idbFactory: { type: "object", required: false }
|
|
24181
24181
|
},
|
|
24182
|
-
async isAvailable({ idbFactory = globalThis.indexedDB }) {
|
|
24183
|
-
if (idbTests.has(
|
|
24184
|
-
return idbTests.get(
|
|
24185
|
-
const result = testAvailability(
|
|
24186
|
-
idbTests.set(
|
|
24182
|
+
async isAvailable({ idbFactory: idbFactory2 = globalThis.indexedDB }) {
|
|
24183
|
+
if (idbTests.has(idbFactory2))
|
|
24184
|
+
return idbTests.get(idbFactory2);
|
|
24185
|
+
const result = testAvailability(idbFactory2);
|
|
24186
|
+
idbTests.set(idbFactory2, result);
|
|
24187
24187
|
return result;
|
|
24188
24188
|
},
|
|
24189
24189
|
async create(options) {
|
|
@@ -24496,6 +24496,128 @@ var ZenFSConfig = (() => {
|
|
|
24496
24496
|
}
|
|
24497
24497
|
});
|
|
24498
24498
|
|
|
24499
|
+
// src/idb-alloc.ts
|
|
24500
|
+
function idbFactory() {
|
|
24501
|
+
return globalThis.indexedDB ?? null;
|
|
24502
|
+
}
|
|
24503
|
+
function req(request3) {
|
|
24504
|
+
return new Promise((resolve4, reject) => {
|
|
24505
|
+
request3.onsuccess = () => resolve4(request3.result);
|
|
24506
|
+
request3.onerror = () => reject(request3.error);
|
|
24507
|
+
});
|
|
24508
|
+
}
|
|
24509
|
+
function txDone(tx) {
|
|
24510
|
+
return new Promise((resolve4, reject) => {
|
|
24511
|
+
tx.oncomplete = () => resolve4();
|
|
24512
|
+
tx.onerror = () => reject(tx.error);
|
|
24513
|
+
tx.onabort = () => reject(tx.error);
|
|
24514
|
+
});
|
|
24515
|
+
}
|
|
24516
|
+
function openStoreDb(name) {
|
|
24517
|
+
const factory = idbFactory();
|
|
24518
|
+
if (!factory) return Promise.reject(new Error("IndexedDB is not available"));
|
|
24519
|
+
return new Promise((resolve4, reject) => {
|
|
24520
|
+
const request3 = factory.open(name);
|
|
24521
|
+
request3.onupgradeneeded = () => {
|
|
24522
|
+
const db = request3.result;
|
|
24523
|
+
if (db.objectStoreNames.contains(name)) db.deleteObjectStore(name);
|
|
24524
|
+
db.createObjectStore(name);
|
|
24525
|
+
};
|
|
24526
|
+
request3.onsuccess = () => resolve4(request3.result);
|
|
24527
|
+
request3.onerror = () => reject(request3.error);
|
|
24528
|
+
});
|
|
24529
|
+
}
|
|
24530
|
+
function openMetaDb(name) {
|
|
24531
|
+
const factory = idbFactory();
|
|
24532
|
+
if (!factory) return Promise.reject(new Error("IndexedDB is not available"));
|
|
24533
|
+
return new Promise((resolve4, reject) => {
|
|
24534
|
+
const request3 = factory.open(name, 1);
|
|
24535
|
+
request3.onupgradeneeded = () => {
|
|
24536
|
+
const db = request3.result;
|
|
24537
|
+
if (!db.objectStoreNames.contains(META_STORE)) db.createObjectStore(META_STORE);
|
|
24538
|
+
};
|
|
24539
|
+
request3.onsuccess = () => resolve4(request3.result);
|
|
24540
|
+
request3.onerror = () => reject(request3.error);
|
|
24541
|
+
});
|
|
24542
|
+
}
|
|
24543
|
+
async function attachAllocId(store, storeName, db) {
|
|
24544
|
+
const keys = await req(
|
|
24545
|
+
db.transaction(storeName, "readonly").objectStore(storeName).getAllKeys()
|
|
24546
|
+
);
|
|
24547
|
+
let diskMax = 0;
|
|
24548
|
+
for (const raw of keys) {
|
|
24549
|
+
const n = Number(raw);
|
|
24550
|
+
if (Number.isFinite(n) && n > diskMax) diskMax = n;
|
|
24551
|
+
}
|
|
24552
|
+
const metaDb = await openMetaDb(storeName + META_DB_SUFFIX);
|
|
24553
|
+
let base;
|
|
24554
|
+
let end;
|
|
24555
|
+
try {
|
|
24556
|
+
const tx = metaDb.transaction(META_STORE, "readwrite");
|
|
24557
|
+
const meta = tx.objectStore(META_STORE);
|
|
24558
|
+
const persisted = Number(await req(meta.get(HWM_KEY))) || 0;
|
|
24559
|
+
base = Math.max(persisted, diskMax);
|
|
24560
|
+
if (base % 2 !== 0) base += 1;
|
|
24561
|
+
end = base + INO_BLOCK;
|
|
24562
|
+
meta.put(end, HWM_KEY);
|
|
24563
|
+
await txDone(tx);
|
|
24564
|
+
} finally {
|
|
24565
|
+
try {
|
|
24566
|
+
metaDb.close?.();
|
|
24567
|
+
} catch {
|
|
24568
|
+
}
|
|
24569
|
+
}
|
|
24570
|
+
let next = base + 2;
|
|
24571
|
+
store.allocId = () => {
|
|
24572
|
+
if (next >= end) {
|
|
24573
|
+
throw new Error(
|
|
24574
|
+
`[zen-fs-config] ${storeName}: inode \u53F7\u6BB5\u5DF2\u7528\u5C3D\uFF08${base}~${end}\uFF09\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00\u8BE5\u5E93`
|
|
24575
|
+
);
|
|
24576
|
+
}
|
|
24577
|
+
const id = next;
|
|
24578
|
+
next += 2;
|
|
24579
|
+
return [id, id + 1];
|
|
24580
|
+
};
|
|
24581
|
+
}
|
|
24582
|
+
function withAllocId(base) {
|
|
24583
|
+
return {
|
|
24584
|
+
name: base?.name ?? "IndexedDB",
|
|
24585
|
+
options: base?.options ?? {},
|
|
24586
|
+
isAvailable: base?.isAvailable?.bind?.(base) ?? (() => !!idbFactory()),
|
|
24587
|
+
async create(options) {
|
|
24588
|
+
const storeName = String(options?.storeName ?? "zen-fs-config");
|
|
24589
|
+
await repairIndexedDBStore(storeName);
|
|
24590
|
+
const db = await openStoreDb(storeName);
|
|
24591
|
+
db.onversionchange = () => {
|
|
24592
|
+
try {
|
|
24593
|
+
db.close();
|
|
24594
|
+
} catch {
|
|
24595
|
+
}
|
|
24596
|
+
};
|
|
24597
|
+
const { IndexedDBStore: IndexedDBStore2 } = await Promise.resolve().then(() => (init_dist5(), dist_exports2));
|
|
24598
|
+
const store = new IndexedDBStore2(db);
|
|
24599
|
+
await attachAllocId(store, storeName, db);
|
|
24600
|
+
const zenfs = await Promise.resolve().then(() => (init_dist4(), dist_exports));
|
|
24601
|
+
const fs = new zenfs.StoreFS(store);
|
|
24602
|
+
if (!options?.disableAsyncCache) {
|
|
24603
|
+
await store.transaction().preload();
|
|
24604
|
+
}
|
|
24605
|
+
return fs;
|
|
24606
|
+
}
|
|
24607
|
+
};
|
|
24608
|
+
}
|
|
24609
|
+
var INO_BLOCK, META_DB_SUFFIX, META_STORE, HWM_KEY;
|
|
24610
|
+
var init_idb_alloc = __esm({
|
|
24611
|
+
"src/idb-alloc.ts"() {
|
|
24612
|
+
"use strict";
|
|
24613
|
+
init_idb_repair();
|
|
24614
|
+
INO_BLOCK = 32768;
|
|
24615
|
+
META_DB_SUFFIX = "__ino";
|
|
24616
|
+
META_STORE = "meta";
|
|
24617
|
+
HWM_KEY = "inoHwm";
|
|
24618
|
+
}
|
|
24619
|
+
});
|
|
24620
|
+
|
|
24499
24621
|
// src/backend-registry.ts
|
|
24500
24622
|
var backend_registry_exports = {};
|
|
24501
24623
|
__export(backend_registry_exports, {
|
|
@@ -24904,7 +25026,7 @@ var ZenFSConfig = (() => {
|
|
|
24904
25026
|
var init_backend_registry = __esm({
|
|
24905
25027
|
"src/backend-registry.ts"() {
|
|
24906
25028
|
"use strict";
|
|
24907
|
-
|
|
25029
|
+
init_idb_alloc();
|
|
24908
25030
|
registry = /* @__PURE__ */ new Map();
|
|
24909
25031
|
metadataRegistry = /* @__PURE__ */ new Map();
|
|
24910
25032
|
REGISTRY_TOKEN = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
@@ -24943,13 +25065,7 @@ var ZenFSConfig = (() => {
|
|
|
24943
25065
|
const { IndexedDB: IndexedDB2 } = await Promise.resolve().then(() => (init_dist5(), dist_exports2));
|
|
24944
25066
|
const storeName = options.storeName ?? "zen-fs-config";
|
|
24945
25067
|
const label = options.label ?? storeName;
|
|
24946
|
-
|
|
24947
|
-
if (repaired?.repaired) {
|
|
24948
|
-
console.warn(
|
|
24949
|
-
`[Backend:IndexedDB] ${storeName}: reset ${repaired.repaired} corrupted directory listing(s): ` + repaired.details.map((d) => `ino ${d.key}\u2192slot ${d.data} (${d.reason})`).join(", ")
|
|
24950
|
-
);
|
|
24951
|
-
}
|
|
24952
|
-
return wrapZenFSFileSystem({ backend: IndexedDB2, storeName, label });
|
|
25068
|
+
return wrapZenFSFileSystem({ backend: withAllocId(IndexedDB2), storeName, label });
|
|
24953
25069
|
}, {
|
|
24954
25070
|
type: "IndexedDB",
|
|
24955
25071
|
label: "IndexedDB",
|
|
@@ -25407,15 +25523,15 @@ var ZenFSConfig = (() => {
|
|
|
25407
25523
|
return Promise.reject(new Error("IndexedDB unavailable"));
|
|
25408
25524
|
}
|
|
25409
25525
|
this.dbPromise = new Promise((resolve4, reject) => {
|
|
25410
|
-
const
|
|
25411
|
-
|
|
25412
|
-
const db =
|
|
25526
|
+
const req2 = indexedDB.open(this.dbName, 1);
|
|
25527
|
+
req2.onupgradeneeded = () => {
|
|
25528
|
+
const db = req2.result;
|
|
25413
25529
|
if (!db.objectStoreNames.contains(this.storeName)) {
|
|
25414
25530
|
db.createObjectStore(this.storeName);
|
|
25415
25531
|
}
|
|
25416
25532
|
};
|
|
25417
|
-
|
|
25418
|
-
|
|
25533
|
+
req2.onsuccess = () => resolve4(req2.result);
|
|
25534
|
+
req2.onerror = () => reject(req2.error);
|
|
25419
25535
|
});
|
|
25420
25536
|
return this.dbPromise;
|
|
25421
25537
|
}
|
|
@@ -25427,9 +25543,9 @@ var ZenFSConfig = (() => {
|
|
|
25427
25543
|
const db = await this.open();
|
|
25428
25544
|
return await new Promise((resolve4, reject) => {
|
|
25429
25545
|
const tx = db.transaction(this.storeName, "readonly");
|
|
25430
|
-
const
|
|
25431
|
-
|
|
25432
|
-
|
|
25546
|
+
const req2 = tx.objectStore(this.storeName).get(this.key(key));
|
|
25547
|
+
req2.onsuccess = () => resolve4(req2.result ?? void 0);
|
|
25548
|
+
req2.onerror = () => reject(req2.error);
|
|
25433
25549
|
});
|
|
25434
25550
|
} catch {
|
|
25435
25551
|
return void 0;
|
|
@@ -25477,16 +25593,16 @@ var ZenFSConfig = (() => {
|
|
|
25477
25593
|
await new Promise((resolve4, reject) => {
|
|
25478
25594
|
const tx = db.transaction(this.storeName, "readwrite");
|
|
25479
25595
|
const store = tx.objectStore(this.storeName);
|
|
25480
|
-
const
|
|
25481
|
-
|
|
25482
|
-
const keys =
|
|
25596
|
+
const req2 = store.getAllKeys();
|
|
25597
|
+
req2.onsuccess = () => {
|
|
25598
|
+
const keys = req2.result ?? [];
|
|
25483
25599
|
for (const raw of keys) {
|
|
25484
25600
|
const path = raw.startsWith(this.prefix) ? raw.slice(this.prefix.length) : raw;
|
|
25485
25601
|
const base = path === "/" ? "" : path.split("/").pop() ?? "";
|
|
25486
25602
|
if (base === ".keep") store.delete(raw);
|
|
25487
25603
|
}
|
|
25488
25604
|
};
|
|
25489
|
-
|
|
25605
|
+
req2.onerror = () => reject(req2.error);
|
|
25490
25606
|
tx.oncomplete = () => resolve4();
|
|
25491
25607
|
tx.onerror = () => reject(tx.error);
|
|
25492
25608
|
});
|
|
@@ -25561,6 +25677,7 @@ var ZenFSConfig = (() => {
|
|
|
25561
25677
|
GITEE_BACKEND_METADATA: () => GITEE_BACKEND_METADATA,
|
|
25562
25678
|
GITHUB_BACKEND_METADATA: () => GITHUB_BACKEND_METADATA,
|
|
25563
25679
|
GROUP_DESCRIPTOR_FILE: () => GROUP_DESCRIPTOR_FILE2,
|
|
25680
|
+
INO_BLOCK: () => INO_BLOCK,
|
|
25564
25681
|
InvalidBackendError: () => InvalidBackendError,
|
|
25565
25682
|
LEGACY_CONFLICTS_DIR: () => LEGACY_CONFLICTS_DIR,
|
|
25566
25683
|
LEGACY_TOMBSTONES_DIR: () => LEGACY_TOMBSTONES_DIR,
|
|
@@ -25576,6 +25693,7 @@ var ZenFSConfig = (() => {
|
|
|
25576
25693
|
VERSIONS_DIR: () => VERSIONS_DIR,
|
|
25577
25694
|
VersionStore: () => VersionStore,
|
|
25578
25695
|
WEBDAV_BACKEND_METADATA: () => WEBDAV_BACKEND_METADATA,
|
|
25696
|
+
attachAllocId: () => attachAllocId,
|
|
25579
25697
|
backendSupportsAccessMode: () => backendSupportsAccessMode,
|
|
25580
25698
|
bindRemoteGroupIdentity: () => bindRemoteGroupIdentity,
|
|
25581
25699
|
bindRemoteGroupIdentityDetailed: () => bindRemoteGroupIdentityDetailed,
|
|
@@ -25617,6 +25735,7 @@ var ZenFSConfig = (() => {
|
|
|
25617
25735
|
mergeAccountFields: () => mergeAccountFields,
|
|
25618
25736
|
migrateVersionSidecars: () => migrateVersionSidecars,
|
|
25619
25737
|
newGroupInstanceId: () => newGroupInstanceId,
|
|
25738
|
+
openStoreDb: () => openStoreDb,
|
|
25620
25739
|
probeGroupTypeDetailed: () => probeGroupTypeDetailed,
|
|
25621
25740
|
purgeKeepFiles: () => purgeKeepFiles,
|
|
25622
25741
|
purgeLocalSyncConfig: () => purgeLocalSyncConfig,
|
|
@@ -25642,6 +25761,7 @@ var ZenFSConfig = (() => {
|
|
|
25642
25761
|
unregisterBackend: () => unregisterBackend,
|
|
25643
25762
|
verifyOrRepairVersion: () => verifyOrRepairVersion,
|
|
25644
25763
|
versionPathFor: () => versionPathFor,
|
|
25764
|
+
withAllocId: () => withAllocId,
|
|
25645
25765
|
wrapZenFSFileSystem: () => wrapZenFSFileSystem,
|
|
25646
25766
|
writeGroupAlias: () => writeGroupAlias,
|
|
25647
25767
|
writeGroupDescriptor: () => writeGroupDescriptor,
|
|
@@ -25988,6 +26108,10 @@ var ZenFSConfig = (() => {
|
|
|
25988
26108
|
}
|
|
25989
26109
|
};
|
|
25990
26110
|
var log3 = createLogger2("sync");
|
|
26111
|
+
var logMtime = createLogger2("mtime");
|
|
26112
|
+
function fmtMtime(ms) {
|
|
26113
|
+
return Number.isFinite(ms) ? `${ms}@${new Date(ms).toISOString()}` : String(ms);
|
|
26114
|
+
}
|
|
25991
26115
|
var SyncPair = class {
|
|
25992
26116
|
constructor(source, target, options = {}, syncRoot = "/") {
|
|
25993
26117
|
__publicField(this, "syncRoot");
|
|
@@ -26084,7 +26208,11 @@ var ZenFSConfig = (() => {
|
|
|
26084
26208
|
result.durationMs = Date.now() - startTime;
|
|
26085
26209
|
this.lastResult = result;
|
|
26086
26210
|
if (result.errors && result.errors.length > 0) {
|
|
26087
|
-
|
|
26211
|
+
const first = result.errors[0];
|
|
26212
|
+
const where = first.path ? `${first.path}: ` : "";
|
|
26213
|
+
this.lastError = { message: where + first.message, timestamp: result.timestamp };
|
|
26214
|
+
} else if (this.lastError) {
|
|
26215
|
+
this.lastError = void 0;
|
|
26088
26216
|
}
|
|
26089
26217
|
this.totalSyncs++;
|
|
26090
26218
|
this.state = this.pollTimers.length > 0 ? "watching" : "idle";
|
|
@@ -26400,6 +26528,8 @@ var ZenFSConfig = (() => {
|
|
|
26400
26528
|
let filesUpdated = 0;
|
|
26401
26529
|
let filesDeleted = 0;
|
|
26402
26530
|
let filesSkipped = 0;
|
|
26531
|
+
let comparedSame = 0;
|
|
26532
|
+
let comparedDiff = 0;
|
|
26403
26533
|
const conflicts = [];
|
|
26404
26534
|
const changes = [];
|
|
26405
26535
|
const errors = [];
|
|
@@ -26469,8 +26599,11 @@ var ZenFSConfig = (() => {
|
|
|
26469
26599
|
}
|
|
26470
26600
|
} else if (srcEntry && tgtEntry) {
|
|
26471
26601
|
if (srcEntry.mtimeMs === tgtEntry.mtimeMs && srcEntry.size === tgtEntry.size) {
|
|
26602
|
+
comparedSame++;
|
|
26472
26603
|
continue;
|
|
26473
26604
|
}
|
|
26605
|
+
comparedDiff++;
|
|
26606
|
+
logMtime(`[compare] ${path} src=${fmtMtime(srcEntry.mtimeMs)} tgt=${fmtMtime(tgtEntry.mtimeMs)} dMtime=${srcEntry.mtimeMs - tgtEntry.mtimeMs}ms srcSize=${srcEntry.size} tgtSize=${tgtEntry.size} sameMtime=${srcEntry.mtimeMs === tgtEntry.mtimeMs} sameSize=${srcEntry.size === tgtEntry.size}`);
|
|
26474
26607
|
if (srcEntry.mtimeMs !== tgtEntry.mtimeMs) {
|
|
26475
26608
|
const fullPath = resolvePath(this.root, path);
|
|
26476
26609
|
let srcContent;
|
|
@@ -26487,6 +26620,7 @@ var ZenFSConfig = (() => {
|
|
|
26487
26620
|
if (srcContent === tgtContent) {
|
|
26488
26621
|
const oldestMtime = Math.min(srcEntry.mtimeMs, tgtEntry.mtimeMs);
|
|
26489
26622
|
const keptOn = srcEntry.mtimeMs <= tgtEntry.mtimeMs ? "src" : "tgt";
|
|
26623
|
+
logMtime(`[decision] NORMALIZE ${path} sameContent=true src=${fmtMtime(srcEntry.mtimeMs)} tgt=${fmtMtime(tgtEntry.mtimeMs)} \u2192 ${fmtMtime(oldestMtime)} kept=${keptOn} bytes=${srcContent.length}`);
|
|
26490
26624
|
await this.normalizeMtimeBoth(path, srcContent, oldestMtime);
|
|
26491
26625
|
filesSkipped++;
|
|
26492
26626
|
log3(`[zen-fs-sync] MTIME NORMALIZE ${path} \u2192 mtime=${oldestMtime} (content identical; src=${srcEntry.mtimeMs} tgt=${tgtEntry.mtimeMs}; kept=oldest(${keptOn}); real mtime stored in sidecar .${path}.mtime)`);
|
|
@@ -26495,6 +26629,7 @@ var ZenFSConfig = (() => {
|
|
|
26495
26629
|
const fromFs = newerIsSource ? this.source : this.target;
|
|
26496
26630
|
const toFs = newerIsSource ? this.target : this.source;
|
|
26497
26631
|
const fromLabel = newerIsSource ? "source\u2192target" : "target\u2192source";
|
|
26632
|
+
logMtime(`[decision] NEWER_WINS ${path} winner=${newerIsSource ? "src" : "tgt"} src=${fmtMtime(srcEntry.mtimeMs)} tgt=${fmtMtime(tgtEntry.mtimeMs)} dMtime=${srcEntry.mtimeMs - tgtEntry.mtimeMs}ms srcSize=${srcEntry.size} tgtSize=${tgtEntry.size}`);
|
|
26498
26633
|
try {
|
|
26499
26634
|
const wrote = await this.copyFile(fromFs, toFs, path);
|
|
26500
26635
|
if (wrote) {
|
|
@@ -26538,6 +26673,7 @@ var ZenFSConfig = (() => {
|
|
|
26538
26673
|
}
|
|
26539
26674
|
const durationMs = Date.now() - startTime;
|
|
26540
26675
|
log3(`[zen-fs-sync] syncBidirectional END pairId=${this.pairId} +${filesCreated}/~${filesUpdated}/-${filesDeleted} ${durationMs}ms`);
|
|
26676
|
+
logMtime(`[cycle] END pairId=${this.pairId} compared=${comparedSame + comparedDiff} identical=${comparedSame} differing=${comparedDiff} created=${filesCreated} updated=${filesUpdated} deleted=${filesDeleted} skipped=${filesSkipped} ${durationMs}ms`);
|
|
26541
26677
|
return {
|
|
26542
26678
|
pairId: this.pairId,
|
|
26543
26679
|
direction: "bi-directional",
|
|
@@ -26584,10 +26720,13 @@ var ZenFSConfig = (() => {
|
|
|
26584
26720
|
}
|
|
26585
26721
|
async copyFile(from2, to, relPath) {
|
|
26586
26722
|
const fullPath = resolvePath(this.root, relPath);
|
|
26723
|
+
const dirLabel = to === this.target ? "source\u2192target" : "target\u2192source";
|
|
26724
|
+
const fromLabel = from2 === this.source ? "source" : "target";
|
|
26587
26725
|
const srcContent = await from2.readFile(fullPath, "utf-8");
|
|
26588
26726
|
try {
|
|
26589
26727
|
const tgtContent = await to.readFile(fullPath, "utf-8");
|
|
26590
26728
|
if (srcContent === tgtContent) {
|
|
26729
|
+
logMtime(`[write] SKIP content-identical ${dirLabel} ${relPath} bytes=${srcContent.length}`);
|
|
26591
26730
|
return false;
|
|
26592
26731
|
}
|
|
26593
26732
|
} catch {
|
|
@@ -26595,13 +26734,17 @@ var ZenFSConfig = (() => {
|
|
|
26595
26734
|
await ensureDir(to, fullPath.substring(0, fullPath.lastIndexOf("/")));
|
|
26596
26735
|
if (to.writeFileWithMtime) {
|
|
26597
26736
|
let srcMtimeMs = Date.now();
|
|
26737
|
+
let mtimeOrigin = "now(stat-failed)";
|
|
26598
26738
|
try {
|
|
26599
26739
|
const srcStat = await from2.stat(fullPath);
|
|
26600
26740
|
srcMtimeMs = srcStat.mtimeMs;
|
|
26741
|
+
mtimeOrigin = `${fromLabel}.stat`;
|
|
26601
26742
|
} catch {
|
|
26602
26743
|
}
|
|
26744
|
+
logMtime(`[write] ${dirLabel} ${relPath} bytes=${srcContent.length} mtime=${fmtMtime(srcMtimeMs)} origin=${mtimeOrigin}`);
|
|
26603
26745
|
await to.writeFileWithMtime(fullPath, srcContent, srcMtimeMs);
|
|
26604
26746
|
} else {
|
|
26747
|
+
logMtime(`[write] ${dirLabel} ${relPath} bytes=${srcContent.length} mtime=implicit(Date.now) via=writeFile`);
|
|
26605
26748
|
await to.writeFile(fullPath, srcContent);
|
|
26606
26749
|
}
|
|
26607
26750
|
return true;
|
|
@@ -26636,12 +26779,20 @@ var ZenFSConfig = (() => {
|
|
|
26636
26779
|
*/
|
|
26637
26780
|
async normalizeMtimeBoth(relPath, content, mtimeMs) {
|
|
26638
26781
|
const fullPath = resolvePath(this.root, relPath);
|
|
26782
|
+
const sides = [];
|
|
26639
26783
|
if (this.source.writeFileWithMtime) {
|
|
26640
26784
|
await this.source.writeFileWithMtime(fullPath, content, mtimeMs);
|
|
26785
|
+
sides.push("source");
|
|
26786
|
+
} else {
|
|
26787
|
+
sides.push("source:skip(no writeFileWithMtime)");
|
|
26641
26788
|
}
|
|
26642
26789
|
if (this.target.writeFileWithMtime) {
|
|
26643
26790
|
await this.target.writeFileWithMtime(fullPath, content, mtimeMs);
|
|
26791
|
+
sides.push("target");
|
|
26792
|
+
} else {
|
|
26793
|
+
sides.push("target:skip(no writeFileWithMtime)");
|
|
26644
26794
|
}
|
|
26795
|
+
logMtime(`[write] NORMALIZE ${relPath} mtime=${fmtMtime(mtimeMs)} bytes=${content.length} wrote=${sides.join("+")}`);
|
|
26645
26796
|
}
|
|
26646
26797
|
/**
|
|
26647
26798
|
* 本地变更回调(由实现了 onChange 的后端在 writeFile/unlink 后触发)。
|
|
@@ -35635,6 +35786,7 @@ var ZenFSConfig = (() => {
|
|
|
35635
35786
|
|
|
35636
35787
|
// src/index.ts
|
|
35637
35788
|
init_backend_registry();
|
|
35789
|
+
init_idb_alloc();
|
|
35638
35790
|
init_backend_registry();
|
|
35639
35791
|
|
|
35640
35792
|
// src/data-group-selection.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zen-fs-config",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.3",
|
|
4
4
|
"description": "Distributed config management library built on ZenFS, zen-fs-cache, and zen-fs-sync",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsup",
|
|
40
40
|
"build:npm": "tsup --format cjs,esm --dts",
|
|
41
|
-
"build:browser": "tsup
|
|
41
|
+
"build:browser": "tsup",
|
|
42
42
|
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
43
43
|
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
44
44
|
"typecheck": "tsc --noEmit",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"zen-fs-gitee": "*",
|
|
69
69
|
"zen-fs-github": "*",
|
|
70
70
|
"zen-fs-remotestoragejs": "*",
|
|
71
|
-
"zen-fs-sync": "
|
|
71
|
+
"zen-fs-sync": "^0.4.19",
|
|
72
72
|
"zen-fs-webdav": "*"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
@@ -97,14 +97,15 @@
|
|
|
97
97
|
"devDependencies": {
|
|
98
98
|
"@zenfs/core": "^2.5.7",
|
|
99
99
|
"@zenfs/dom": "^1.0.0",
|
|
100
|
+
"fake-indexeddb": "^6.2.8",
|
|
100
101
|
"tsup": "^8.5.1",
|
|
101
102
|
"typescript": "^5.9.3",
|
|
102
103
|
"vitest": "^1.6.1",
|
|
103
104
|
"zen-fs-cache": "^1.0.6",
|
|
104
|
-
"zen-fs-gitee": "^1.2.
|
|
105
|
+
"zen-fs-gitee": "^1.2.44",
|
|
105
106
|
"zen-fs-github": "^1.1.3",
|
|
106
107
|
"zen-fs-remotestoragejs": "^1.3.27",
|
|
107
|
-
"zen-fs-sync": "^0.4.
|
|
108
|
+
"zen-fs-sync": "^0.4.19",
|
|
108
109
|
"zen-fs-webdav": "^0.1.7"
|
|
109
110
|
}
|
|
110
111
|
}
|