zen-fs-config 0.2.0 → 0.3.0
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 +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +112 -0
- package/dist/index.mjs +112 -0
- package/package.json +4 -1
package/dist/index.d.mts
CHANGED
|
@@ -160,6 +160,14 @@ interface IConfigRepo {
|
|
|
160
160
|
resolveConflict(conflictId: string, mergedContent: unknown): Promise<void>;
|
|
161
161
|
/** List all conflict archives. */
|
|
162
162
|
listConflicts(): Promise<ConflictArchive[]>;
|
|
163
|
+
/** Read .meta/backends.json. */
|
|
164
|
+
getBackends(): Promise<BackendsMeta | null>;
|
|
165
|
+
/** Write .meta/backends.json. */
|
|
166
|
+
updateBackends(meta: BackendsMeta): Promise<void>;
|
|
167
|
+
/** Read .meta/sync-rules.json. */
|
|
168
|
+
getSyncRules(): Promise<SyncRulesMeta | null>;
|
|
169
|
+
/** Write .meta/sync-rules.json. */
|
|
170
|
+
updateSyncRules(meta: SyncRulesMeta): Promise<void>;
|
|
163
171
|
/** Dispose: stop all sync, release cache FS and resources. */
|
|
164
172
|
dispose(): Promise<void>;
|
|
165
173
|
}
|
|
@@ -252,6 +260,10 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
252
260
|
private walkDir;
|
|
253
261
|
writeMetaFile(path: string, data: BackendsMeta | SyncRulesMeta): Promise<void>;
|
|
254
262
|
readMetaFile<T>(path: string): Promise<T | null>;
|
|
263
|
+
getBackends(): Promise<BackendsMeta | null>;
|
|
264
|
+
updateBackends(meta: BackendsMeta): Promise<void>;
|
|
265
|
+
getSyncRules(): Promise<SyncRulesMeta | null>;
|
|
266
|
+
updateSyncRules(meta: SyncRulesMeta): Promise<void>;
|
|
255
267
|
private tryParse;
|
|
256
268
|
private assertNotDisposed;
|
|
257
269
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -160,6 +160,14 @@ interface IConfigRepo {
|
|
|
160
160
|
resolveConflict(conflictId: string, mergedContent: unknown): Promise<void>;
|
|
161
161
|
/** List all conflict archives. */
|
|
162
162
|
listConflicts(): Promise<ConflictArchive[]>;
|
|
163
|
+
/** Read .meta/backends.json. */
|
|
164
|
+
getBackends(): Promise<BackendsMeta | null>;
|
|
165
|
+
/** Write .meta/backends.json. */
|
|
166
|
+
updateBackends(meta: BackendsMeta): Promise<void>;
|
|
167
|
+
/** Read .meta/sync-rules.json. */
|
|
168
|
+
getSyncRules(): Promise<SyncRulesMeta | null>;
|
|
169
|
+
/** Write .meta/sync-rules.json. */
|
|
170
|
+
updateSyncRules(meta: SyncRulesMeta): Promise<void>;
|
|
163
171
|
/** Dispose: stop all sync, release cache FS and resources. */
|
|
164
172
|
dispose(): Promise<void>;
|
|
165
173
|
}
|
|
@@ -252,6 +260,10 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
252
260
|
private walkDir;
|
|
253
261
|
writeMetaFile(path: string, data: BackendsMeta | SyncRulesMeta): Promise<void>;
|
|
254
262
|
readMetaFile<T>(path: string): Promise<T | null>;
|
|
263
|
+
getBackends(): Promise<BackendsMeta | null>;
|
|
264
|
+
updateBackends(meta: BackendsMeta): Promise<void>;
|
|
265
|
+
getSyncRules(): Promise<SyncRulesMeta | null>;
|
|
266
|
+
updateSyncRules(meta: SyncRulesMeta): Promise<void>;
|
|
255
267
|
private tryParse;
|
|
256
268
|
private assertNotDisposed;
|
|
257
269
|
}
|
package/dist/index.js
CHANGED
|
@@ -364,6 +364,99 @@ registerBackend("InMemory", async (options) => {
|
|
|
364
364
|
};
|
|
365
365
|
return backend;
|
|
366
366
|
});
|
|
367
|
+
var idbCounter = 0;
|
|
368
|
+
registerBackend("IndexedDB", async (options) => {
|
|
369
|
+
const zenfs = await import("@zenfs/core");
|
|
370
|
+
const { IndexedDB } = await import("@zenfs/dom");
|
|
371
|
+
const storeName = options.storeName ?? `zen-fs-config-${++idbCounter}`;
|
|
372
|
+
await zenfs.configureSingle({ backend: IndexedDB, storeName });
|
|
373
|
+
const pfs = zenfs.fs.promises;
|
|
374
|
+
const backend = {
|
|
375
|
+
async readFile(path, ...args) {
|
|
376
|
+
return args.length > 0 ? pfs.readFile(path, ...args) : pfs.readFile(path);
|
|
377
|
+
},
|
|
378
|
+
async writeFile(path, data, options2) {
|
|
379
|
+
return pfs.writeFile(path, data, options2);
|
|
380
|
+
},
|
|
381
|
+
async readdir(path) {
|
|
382
|
+
const entries = await pfs.readdir(path);
|
|
383
|
+
return entries.map((e) => typeof e === "string" ? e : e.name);
|
|
384
|
+
},
|
|
385
|
+
async stat(path, ...args) {
|
|
386
|
+
return pfs.stat(path, ...args);
|
|
387
|
+
},
|
|
388
|
+
async exists(path) {
|
|
389
|
+
try {
|
|
390
|
+
await pfs.stat(path);
|
|
391
|
+
return true;
|
|
392
|
+
} catch {
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
async mkdir(path, options2) {
|
|
397
|
+
return pfs.mkdir(path, options2);
|
|
398
|
+
},
|
|
399
|
+
async unlink(path) {
|
|
400
|
+
return pfs.unlink(path);
|
|
401
|
+
},
|
|
402
|
+
async rmdir(path) {
|
|
403
|
+
return pfs.rmdir(path);
|
|
404
|
+
},
|
|
405
|
+
async rename(oldPath, newPath) {
|
|
406
|
+
return pfs.rename(oldPath, newPath);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
return backend;
|
|
410
|
+
});
|
|
411
|
+
registerBackend("WebStorage", async (options) => {
|
|
412
|
+
const zenfs = await import("@zenfs/core");
|
|
413
|
+
const { WebStorage } = await import("@zenfs/dom");
|
|
414
|
+
const storageType = options.storageType ?? "localStorage";
|
|
415
|
+
let storage;
|
|
416
|
+
if (storageType === "sessionStorage" && typeof sessionStorage !== "undefined") {
|
|
417
|
+
storage = sessionStorage;
|
|
418
|
+
} else {
|
|
419
|
+
storage = localStorage;
|
|
420
|
+
}
|
|
421
|
+
await zenfs.configureSingle({ backend: WebStorage, storage });
|
|
422
|
+
const pfs = zenfs.fs.promises;
|
|
423
|
+
const backend = {
|
|
424
|
+
async readFile(path, ...args) {
|
|
425
|
+
return args.length > 0 ? pfs.readFile(path, ...args) : pfs.readFile(path);
|
|
426
|
+
},
|
|
427
|
+
async writeFile(path, data, options2) {
|
|
428
|
+
return pfs.writeFile(path, data, options2);
|
|
429
|
+
},
|
|
430
|
+
async readdir(path) {
|
|
431
|
+
const entries = await pfs.readdir(path);
|
|
432
|
+
return entries.map((e) => typeof e === "string" ? e : e.name);
|
|
433
|
+
},
|
|
434
|
+
async stat(path, ...args) {
|
|
435
|
+
return pfs.stat(path, ...args);
|
|
436
|
+
},
|
|
437
|
+
async exists(path) {
|
|
438
|
+
try {
|
|
439
|
+
await pfs.stat(path);
|
|
440
|
+
return true;
|
|
441
|
+
} catch {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
async mkdir(path, options2) {
|
|
446
|
+
return pfs.mkdir(path, options2);
|
|
447
|
+
},
|
|
448
|
+
async unlink(path) {
|
|
449
|
+
return pfs.unlink(path);
|
|
450
|
+
},
|
|
451
|
+
async rmdir(path) {
|
|
452
|
+
return pfs.rmdir(path);
|
|
453
|
+
},
|
|
454
|
+
async rename(oldPath, newPath) {
|
|
455
|
+
return pfs.rename(oldPath, newPath);
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
return backend;
|
|
459
|
+
});
|
|
367
460
|
registerBackend("GitHub", async (options) => {
|
|
368
461
|
const token = options.token ?? "";
|
|
369
462
|
const owner = options.owner ?? "";
|
|
@@ -1194,6 +1287,25 @@ var ConfigRepo = class {
|
|
|
1194
1287
|
return null;
|
|
1195
1288
|
}
|
|
1196
1289
|
}
|
|
1290
|
+
// -----------------------------------------------------------------------
|
|
1291
|
+
// IConfigRepo — Meta file access (no chroot)
|
|
1292
|
+
// -----------------------------------------------------------------------
|
|
1293
|
+
async getBackends() {
|
|
1294
|
+
this.assertNotDisposed();
|
|
1295
|
+
return this.readMetaFile(BACKENDS_FILE);
|
|
1296
|
+
}
|
|
1297
|
+
async updateBackends(meta) {
|
|
1298
|
+
this.assertNotDisposed();
|
|
1299
|
+
await this.writeMetaFile(BACKENDS_FILE, meta);
|
|
1300
|
+
}
|
|
1301
|
+
async getSyncRules() {
|
|
1302
|
+
this.assertNotDisposed();
|
|
1303
|
+
return this.readMetaFile(SYNC_RULES_FILE);
|
|
1304
|
+
}
|
|
1305
|
+
async updateSyncRules(meta) {
|
|
1306
|
+
this.assertNotDisposed();
|
|
1307
|
+
await this.writeMetaFile(SYNC_RULES_FILE, meta);
|
|
1308
|
+
}
|
|
1197
1309
|
tryParse(content) {
|
|
1198
1310
|
try {
|
|
1199
1311
|
return JSON.parse(content);
|
package/dist/index.mjs
CHANGED
|
@@ -317,6 +317,99 @@ registerBackend("InMemory", async (options) => {
|
|
|
317
317
|
};
|
|
318
318
|
return backend;
|
|
319
319
|
});
|
|
320
|
+
var idbCounter = 0;
|
|
321
|
+
registerBackend("IndexedDB", async (options) => {
|
|
322
|
+
const zenfs = await import("@zenfs/core");
|
|
323
|
+
const { IndexedDB } = await import("@zenfs/dom");
|
|
324
|
+
const storeName = options.storeName ?? `zen-fs-config-${++idbCounter}`;
|
|
325
|
+
await zenfs.configureSingle({ backend: IndexedDB, storeName });
|
|
326
|
+
const pfs = zenfs.fs.promises;
|
|
327
|
+
const backend = {
|
|
328
|
+
async readFile(path, ...args) {
|
|
329
|
+
return args.length > 0 ? pfs.readFile(path, ...args) : pfs.readFile(path);
|
|
330
|
+
},
|
|
331
|
+
async writeFile(path, data, options2) {
|
|
332
|
+
return pfs.writeFile(path, data, options2);
|
|
333
|
+
},
|
|
334
|
+
async readdir(path) {
|
|
335
|
+
const entries = await pfs.readdir(path);
|
|
336
|
+
return entries.map((e) => typeof e === "string" ? e : e.name);
|
|
337
|
+
},
|
|
338
|
+
async stat(path, ...args) {
|
|
339
|
+
return pfs.stat(path, ...args);
|
|
340
|
+
},
|
|
341
|
+
async exists(path) {
|
|
342
|
+
try {
|
|
343
|
+
await pfs.stat(path);
|
|
344
|
+
return true;
|
|
345
|
+
} catch {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
async mkdir(path, options2) {
|
|
350
|
+
return pfs.mkdir(path, options2);
|
|
351
|
+
},
|
|
352
|
+
async unlink(path) {
|
|
353
|
+
return pfs.unlink(path);
|
|
354
|
+
},
|
|
355
|
+
async rmdir(path) {
|
|
356
|
+
return pfs.rmdir(path);
|
|
357
|
+
},
|
|
358
|
+
async rename(oldPath, newPath) {
|
|
359
|
+
return pfs.rename(oldPath, newPath);
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
return backend;
|
|
363
|
+
});
|
|
364
|
+
registerBackend("WebStorage", async (options) => {
|
|
365
|
+
const zenfs = await import("@zenfs/core");
|
|
366
|
+
const { WebStorage } = await import("@zenfs/dom");
|
|
367
|
+
const storageType = options.storageType ?? "localStorage";
|
|
368
|
+
let storage;
|
|
369
|
+
if (storageType === "sessionStorage" && typeof sessionStorage !== "undefined") {
|
|
370
|
+
storage = sessionStorage;
|
|
371
|
+
} else {
|
|
372
|
+
storage = localStorage;
|
|
373
|
+
}
|
|
374
|
+
await zenfs.configureSingle({ backend: WebStorage, storage });
|
|
375
|
+
const pfs = zenfs.fs.promises;
|
|
376
|
+
const backend = {
|
|
377
|
+
async readFile(path, ...args) {
|
|
378
|
+
return args.length > 0 ? pfs.readFile(path, ...args) : pfs.readFile(path);
|
|
379
|
+
},
|
|
380
|
+
async writeFile(path, data, options2) {
|
|
381
|
+
return pfs.writeFile(path, data, options2);
|
|
382
|
+
},
|
|
383
|
+
async readdir(path) {
|
|
384
|
+
const entries = await pfs.readdir(path);
|
|
385
|
+
return entries.map((e) => typeof e === "string" ? e : e.name);
|
|
386
|
+
},
|
|
387
|
+
async stat(path, ...args) {
|
|
388
|
+
return pfs.stat(path, ...args);
|
|
389
|
+
},
|
|
390
|
+
async exists(path) {
|
|
391
|
+
try {
|
|
392
|
+
await pfs.stat(path);
|
|
393
|
+
return true;
|
|
394
|
+
} catch {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
async mkdir(path, options2) {
|
|
399
|
+
return pfs.mkdir(path, options2);
|
|
400
|
+
},
|
|
401
|
+
async unlink(path) {
|
|
402
|
+
return pfs.unlink(path);
|
|
403
|
+
},
|
|
404
|
+
async rmdir(path) {
|
|
405
|
+
return pfs.rmdir(path);
|
|
406
|
+
},
|
|
407
|
+
async rename(oldPath, newPath) {
|
|
408
|
+
return pfs.rename(oldPath, newPath);
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
return backend;
|
|
412
|
+
});
|
|
320
413
|
registerBackend("GitHub", async (options) => {
|
|
321
414
|
const token = options.token ?? "";
|
|
322
415
|
const owner = options.owner ?? "";
|
|
@@ -1147,6 +1240,25 @@ var ConfigRepo = class {
|
|
|
1147
1240
|
return null;
|
|
1148
1241
|
}
|
|
1149
1242
|
}
|
|
1243
|
+
// -----------------------------------------------------------------------
|
|
1244
|
+
// IConfigRepo — Meta file access (no chroot)
|
|
1245
|
+
// -----------------------------------------------------------------------
|
|
1246
|
+
async getBackends() {
|
|
1247
|
+
this.assertNotDisposed();
|
|
1248
|
+
return this.readMetaFile(BACKENDS_FILE);
|
|
1249
|
+
}
|
|
1250
|
+
async updateBackends(meta) {
|
|
1251
|
+
this.assertNotDisposed();
|
|
1252
|
+
await this.writeMetaFile(BACKENDS_FILE, meta);
|
|
1253
|
+
}
|
|
1254
|
+
async getSyncRules() {
|
|
1255
|
+
this.assertNotDisposed();
|
|
1256
|
+
return this.readMetaFile(SYNC_RULES_FILE);
|
|
1257
|
+
}
|
|
1258
|
+
async updateSyncRules(meta) {
|
|
1259
|
+
this.assertNotDisposed();
|
|
1260
|
+
await this.writeMetaFile(SYNC_RULES_FILE, meta);
|
|
1261
|
+
}
|
|
1150
1262
|
tryParse(content) {
|
|
1151
1263
|
try {
|
|
1152
1264
|
return JSON.parse(content);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zen-fs-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|
|
@@ -47,5 +47,8 @@
|
|
|
47
47
|
"typescript": "^5.9.3",
|
|
48
48
|
"zen-fs-cache": "^1.0.1",
|
|
49
49
|
"zen-fs-sync": "^0.1.0"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@zenfs/dom": "^1.2.9"
|
|
50
53
|
}
|
|
51
54
|
}
|