zen-fs-config 0.3.0 → 0.3.2

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 CHANGED
@@ -136,6 +136,8 @@ interface IConfigRepo {
136
136
  readonly nodeId: string;
137
137
  /** ZenFS-compatible fs object, context-isolated to this app's directories. */
138
138
  readonly fs: typeof node_fs;
139
+ /** Un-chrooted fs for low-level browsing (includes /.meta/, all app dirs). */
140
+ readonly rootFS: typeof node_fs;
139
141
  /** Load or reload configuration from a raw string. */
140
142
  load(rawConfig: string): Promise<void>;
141
143
  /** Read a config value. */
@@ -229,6 +231,8 @@ declare class ConfigRepo implements IConfigRepo {
229
231
  readonly nodeId: string;
230
232
  /** Chroot-isolated fs for app-facing API. Typed as `any` to match `typeof import('node:fs')` duck-typically. */
231
233
  readonly fs: any;
234
+ /** Un-chrooted fs for low-level browsing. */
235
+ readonly rootFS: any;
232
236
  private cachedFS;
233
237
  private fullFS;
234
238
  private serializer;
package/dist/index.d.ts CHANGED
@@ -136,6 +136,8 @@ interface IConfigRepo {
136
136
  readonly nodeId: string;
137
137
  /** ZenFS-compatible fs object, context-isolated to this app's directories. */
138
138
  readonly fs: typeof node_fs;
139
+ /** Un-chrooted fs for low-level browsing (includes /.meta/, all app dirs). */
140
+ readonly rootFS: typeof node_fs;
139
141
  /** Load or reload configuration from a raw string. */
140
142
  load(rawConfig: string): Promise<void>;
141
143
  /** Read a config value. */
@@ -229,6 +231,8 @@ declare class ConfigRepo implements IConfigRepo {
229
231
  readonly nodeId: string;
230
232
  /** Chroot-isolated fs for app-facing API. Typed as `any` to match `typeof import('node:fs')` duck-typically. */
231
233
  readonly fs: any;
234
+ /** Un-chrooted fs for low-level browsing. */
235
+ readonly rootFS: any;
232
236
  private cachedFS;
233
237
  private fullFS;
234
238
  private serializer;
package/dist/index.js CHANGED
@@ -316,23 +316,16 @@ function hasBackend(type) {
316
316
  function listBackends() {
317
317
  return Array.from(registry.keys());
318
318
  }
319
- var inMemoryCounter = 0;
320
- registerBackend("InMemory", async (options) => {
319
+ async function wrapZenFSFileSystem(config) {
321
320
  const zenfs = await import("@zenfs/core");
322
- const { InMemory } = zenfs;
323
- const maxSize = options.maxSize ?? 100 * 1024 * 1024;
324
- const label = options.label ?? `zen-fs-config-${++inMemoryCounter}`;
325
- await zenfs.configureSingle({ backend: InMemory, maxSize, label });
326
- const pfs = zenfs.fs.promises;
327
- const backend = {
321
+ const isolatedFS = await zenfs.resolveMountConfig(config);
322
+ const pfs = isolatedFS.promises;
323
+ return {
328
324
  async readFile(path, ...args) {
329
- if (args.length > 0) {
330
- return pfs.readFile(path, ...args);
331
- }
332
- return pfs.readFile(path);
325
+ return args.length > 0 ? pfs.readFile(path, ...args) : pfs.readFile(path);
333
326
  },
334
- async writeFile(path, data, options2) {
335
- return pfs.writeFile(path, data, options2);
327
+ async writeFile(path, data, options) {
328
+ return pfs.writeFile(path, data, options);
336
329
  },
337
330
  async readdir(path) {
338
331
  const entries = await pfs.readdir(path);
@@ -349,8 +342,8 @@ registerBackend("InMemory", async (options) => {
349
342
  return false;
350
343
  }
351
344
  },
352
- async mkdir(path, options2) {
353
- return pfs.mkdir(path, options2);
345
+ async mkdir(path, options) {
346
+ return pfs.mkdir(path, options);
354
347
  },
355
348
  async unlink(path) {
356
349
  return pfs.unlink(path);
@@ -362,54 +355,21 @@ registerBackend("InMemory", async (options) => {
362
355
  return pfs.rename(oldPath, newPath);
363
356
  }
364
357
  };
365
- return backend;
358
+ }
359
+ var inMemoryCounter = 0;
360
+ registerBackend("InMemory", async (options) => {
361
+ const { InMemory } = await import("@zenfs/core");
362
+ const maxSize = options.maxSize ?? 100 * 1024 * 1024;
363
+ const label = options.label ?? `zen-fs-config-${++inMemoryCounter}`;
364
+ return wrapZenFSFileSystem({ backend: InMemory, maxSize, label });
366
365
  });
367
366
  var idbCounter = 0;
368
367
  registerBackend("IndexedDB", async (options) => {
369
- const zenfs = await import("@zenfs/core");
370
368
  const { IndexedDB } = await import("@zenfs/dom");
371
369
  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;
370
+ return wrapZenFSFileSystem({ backend: IndexedDB, storeName });
410
371
  });
411
372
  registerBackend("WebStorage", async (options) => {
412
- const zenfs = await import("@zenfs/core");
413
373
  const { WebStorage } = await import("@zenfs/dom");
414
374
  const storageType = options.storageType ?? "localStorage";
415
375
  let storage;
@@ -418,44 +378,7 @@ registerBackend("WebStorage", async (options) => {
418
378
  } else {
419
379
  storage = localStorage;
420
380
  }
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;
381
+ return wrapZenFSFileSystem({ backend: WebStorage, storage });
459
382
  });
460
383
  registerBackend("GitHub", async (options) => {
461
384
  const token = options.token ?? "";
@@ -883,6 +806,8 @@ var ConfigRepo = class {
883
806
  nodeId;
884
807
  /** Chroot-isolated fs for app-facing API. Typed as `any` to match `typeof import('node:fs')` duck-typically. */
885
808
  fs;
809
+ /** Un-chrooted fs for low-level browsing. */
810
+ rootFS;
886
811
  cachedFS;
887
812
  fullFS;
888
813
  serializer;
@@ -901,6 +826,7 @@ var ConfigRepo = class {
901
826
  this.onConflictCallback = onConflict;
902
827
  this.fullFS = cachedFSToSyncableFS(cachedFS);
903
828
  this.fs = createChrootFS(cachedFS, `/${appId}`);
829
+ this.rootFS = createChrootFS(cachedFS, "/");
904
830
  }
905
831
  // -----------------------------------------------------------------------
906
832
  // IConfigRepo — Load
package/dist/index.mjs CHANGED
@@ -269,23 +269,16 @@ function hasBackend(type) {
269
269
  function listBackends() {
270
270
  return Array.from(registry.keys());
271
271
  }
272
- var inMemoryCounter = 0;
273
- registerBackend("InMemory", async (options) => {
272
+ async function wrapZenFSFileSystem(config) {
274
273
  const zenfs = await import("@zenfs/core");
275
- const { InMemory } = zenfs;
276
- const maxSize = options.maxSize ?? 100 * 1024 * 1024;
277
- const label = options.label ?? `zen-fs-config-${++inMemoryCounter}`;
278
- await zenfs.configureSingle({ backend: InMemory, maxSize, label });
279
- const pfs = zenfs.fs.promises;
280
- const backend = {
274
+ const isolatedFS = await zenfs.resolveMountConfig(config);
275
+ const pfs = isolatedFS.promises;
276
+ return {
281
277
  async readFile(path, ...args) {
282
- if (args.length > 0) {
283
- return pfs.readFile(path, ...args);
284
- }
285
- return pfs.readFile(path);
278
+ return args.length > 0 ? pfs.readFile(path, ...args) : pfs.readFile(path);
286
279
  },
287
- async writeFile(path, data, options2) {
288
- return pfs.writeFile(path, data, options2);
280
+ async writeFile(path, data, options) {
281
+ return pfs.writeFile(path, data, options);
289
282
  },
290
283
  async readdir(path) {
291
284
  const entries = await pfs.readdir(path);
@@ -302,8 +295,8 @@ registerBackend("InMemory", async (options) => {
302
295
  return false;
303
296
  }
304
297
  },
305
- async mkdir(path, options2) {
306
- return pfs.mkdir(path, options2);
298
+ async mkdir(path, options) {
299
+ return pfs.mkdir(path, options);
307
300
  },
308
301
  async unlink(path) {
309
302
  return pfs.unlink(path);
@@ -315,54 +308,21 @@ registerBackend("InMemory", async (options) => {
315
308
  return pfs.rename(oldPath, newPath);
316
309
  }
317
310
  };
318
- return backend;
311
+ }
312
+ var inMemoryCounter = 0;
313
+ registerBackend("InMemory", async (options) => {
314
+ const { InMemory } = await import("@zenfs/core");
315
+ const maxSize = options.maxSize ?? 100 * 1024 * 1024;
316
+ const label = options.label ?? `zen-fs-config-${++inMemoryCounter}`;
317
+ return wrapZenFSFileSystem({ backend: InMemory, maxSize, label });
319
318
  });
320
319
  var idbCounter = 0;
321
320
  registerBackend("IndexedDB", async (options) => {
322
- const zenfs = await import("@zenfs/core");
323
321
  const { IndexedDB } = await import("@zenfs/dom");
324
322
  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;
323
+ return wrapZenFSFileSystem({ backend: IndexedDB, storeName });
363
324
  });
364
325
  registerBackend("WebStorage", async (options) => {
365
- const zenfs = await import("@zenfs/core");
366
326
  const { WebStorage } = await import("@zenfs/dom");
367
327
  const storageType = options.storageType ?? "localStorage";
368
328
  let storage;
@@ -371,44 +331,7 @@ registerBackend("WebStorage", async (options) => {
371
331
  } else {
372
332
  storage = localStorage;
373
333
  }
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;
334
+ return wrapZenFSFileSystem({ backend: WebStorage, storage });
412
335
  });
413
336
  registerBackend("GitHub", async (options) => {
414
337
  const token = options.token ?? "";
@@ -836,6 +759,8 @@ var ConfigRepo = class {
836
759
  nodeId;
837
760
  /** Chroot-isolated fs for app-facing API. Typed as `any` to match `typeof import('node:fs')` duck-typically. */
838
761
  fs;
762
+ /** Un-chrooted fs for low-level browsing. */
763
+ rootFS;
839
764
  cachedFS;
840
765
  fullFS;
841
766
  serializer;
@@ -854,6 +779,7 @@ var ConfigRepo = class {
854
779
  this.onConflictCallback = onConflict;
855
780
  this.fullFS = cachedFSToSyncableFS(cachedFS);
856
781
  this.fs = createChrootFS(cachedFS, `/${appId}`);
782
+ this.rootFS = createChrootFS(cachedFS, "/");
857
783
  }
858
784
  // -----------------------------------------------------------------------
859
785
  // IConfigRepo — Load
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-fs-config",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
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",