zen-fs-config 0.7.10 → 0.7.12

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.
@@ -9,7 +9,7 @@ import {
9
9
  registerBackend,
10
10
  unregisterBackend,
11
11
  wrapZenFSFileSystem
12
- } from "./chunk-QBBPUTC7.mjs";
12
+ } from "./chunk-JS3F3RBC.mjs";
13
13
  export {
14
14
  createBackend,
15
15
  getAccountFields,
@@ -160,6 +160,7 @@ function unregisterBackend(type) {
160
160
  return registry.delete(type);
161
161
  }
162
162
  async function createBackend(descriptor) {
163
+ traceCreateBackend(descriptor.type, descriptor.options);
163
164
  const factory = registry.get(descriptor.type);
164
165
  if (!factory) {
165
166
  throw new Error(
@@ -168,6 +169,19 @@ async function createBackend(descriptor) {
168
169
  }
169
170
  return factory(descriptor.options);
170
171
  }
172
+ function traceCreateBackend(type, options) {
173
+ const g = globalThis;
174
+ try {
175
+ if (!Array.isArray(g.__zenfsBackendTrace)) g.__zenfsBackendTrace = [];
176
+ g.__zenfsBackendTrace.push({
177
+ type,
178
+ storeName: options?.storeName ?? null,
179
+ registered: registry.has(type),
180
+ at: Date.now()
181
+ });
182
+ } catch {
183
+ }
184
+ }
171
185
  function hasBackend(type) {
172
186
  return registry.has(type);
173
187
  }
package/dist/index.d.mts CHANGED
@@ -452,7 +452,12 @@ interface SyncGroupHandle {
452
452
  backendId: string;
453
453
  reason: string;
454
454
  }[];
455
- /** Direct fs view; metadata paths (`.meta`, `.config`) are hidden. */
455
+ /**
456
+ * Direct fs view of the group root. `.config/` is hidden (config-sync
457
+ * territory); sync bookkeeping under `.meta/` (tombstones / versions /
458
+ * conflicts / group.json) is visible but read-only — writes there fail with
459
+ * `EPERM`. Everything else, including `.meta/backends/`, is normal data.
460
+ */
456
461
  readonly fs: typeof node_fs;
457
462
  getSyncStatuses(): Map<string, SyncPairStatus>;
458
463
  getBackendSyncStates(): Map<string, BackendSyncState>;
package/dist/index.d.ts CHANGED
@@ -452,7 +452,12 @@ interface SyncGroupHandle {
452
452
  backendId: string;
453
453
  reason: string;
454
454
  }[];
455
- /** Direct fs view; metadata paths (`.meta`, `.config`) are hidden. */
455
+ /**
456
+ * Direct fs view of the group root. `.config/` is hidden (config-sync
457
+ * territory); sync bookkeeping under `.meta/` (tombstones / versions /
458
+ * conflicts / group.json) is visible but read-only — writes there fail with
459
+ * `EPERM`. Everything else, including `.meta/backends/`, is normal data.
460
+ */
456
461
  readonly fs: typeof node_fs;
457
462
  getSyncStatuses(): Map<string, SyncPairStatus>;
458
463
  getBackendSyncStates(): Map<string, BackendSyncState>;
package/dist/index.js CHANGED
@@ -209,6 +209,7 @@ function unregisterBackend(type) {
209
209
  return registry.delete(type);
210
210
  }
211
211
  async function createBackend(descriptor) {
212
+ traceCreateBackend(descriptor.type, descriptor.options);
212
213
  const factory = registry.get(descriptor.type);
213
214
  if (!factory) {
214
215
  throw new Error(
@@ -217,6 +218,19 @@ async function createBackend(descriptor) {
217
218
  }
218
219
  return factory(descriptor.options);
219
220
  }
221
+ function traceCreateBackend(type, options) {
222
+ const g = globalThis;
223
+ try {
224
+ if (!Array.isArray(g.__zenfsBackendTrace)) g.__zenfsBackendTrace = [];
225
+ g.__zenfsBackendTrace.push({
226
+ type,
227
+ storeName: options?.storeName ?? null,
228
+ registered: registry.has(type),
229
+ at: Date.now()
230
+ });
231
+ } catch {
232
+ }
233
+ }
220
234
  function hasBackend(type) {
221
235
  return registry.has(type);
222
236
  }
@@ -834,11 +848,21 @@ function makeEnoent(userPath) {
834
848
  err.code = "ENOENT";
835
849
  return err;
836
850
  }
851
+ function makeEperm(userPath) {
852
+ const err = new Error(
853
+ `EPERM: '${userPath}' is read-only (sync metadata; use the group/backend API)`
854
+ );
855
+ err.code = "EPERM";
856
+ return err;
857
+ }
837
858
  function createChrootFS(inner, root, options = {}) {
838
859
  const normalizedRoot = root.replace(/\\/g, "/").replace(/\/+$/, "") || "/";
839
860
  const hiddenPrefixes = (options.hiddenPrefixes ?? []).map(
840
861
  (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
841
862
  );
863
+ const readOnlyPrefixes = (options.readOnlyPrefixes ?? []).map(
864
+ (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
865
+ );
842
866
  function rp(path) {
843
867
  return resolveChroot(normalizedRoot, path);
844
868
  }
@@ -852,12 +876,22 @@ function createChrootFS(inner, root, options = {}) {
852
876
  if (isHidden(absolute)) throw makeEnoent(path);
853
877
  return absolute;
854
878
  }
879
+ function isReadOnly(absolutePath) {
880
+ return readOnlyPrefixes.some(
881
+ (prefix) => absolutePath === prefix || absolutePath.startsWith(`${prefix}/`)
882
+ );
883
+ }
884
+ function writable(path) {
885
+ const absolute = visible(path);
886
+ if (isReadOnly(absolute)) throw makeEperm(path);
887
+ return absolute;
888
+ }
855
889
  const promises = {
856
890
  async readFile(path, encoding) {
857
891
  return inner.readFile(visible(path), encoding);
858
892
  },
859
893
  async writeFile(path, data, writeOptions) {
860
- const target = visible(path);
894
+ const target = writable(path);
861
895
  await ensureParentDir(target);
862
896
  await inner.writeFile(target, data, writeOptions);
863
897
  if (options.onWrite) await options.onWrite(path, data);
@@ -884,21 +918,21 @@ function createChrootFS(inner, root, options = {}) {
884
918
  if (!exists) throw makeEnoent(path);
885
919
  },
886
920
  async mkdir(path, mkdirOptions) {
887
- return inner.mkdir(visible(path), mkdirOptions);
921
+ return inner.mkdir(writable(path), mkdirOptions);
888
922
  },
889
923
  async unlink(path) {
890
- const target = visible(path);
924
+ const target = writable(path);
891
925
  if (options.onUnlink) return options.onUnlink(target);
892
926
  return inner.unlink(target);
893
927
  },
894
928
  async rmdir(path) {
895
- const target = visible(path);
929
+ const target = writable(path);
896
930
  const hook = options.onRmdir ?? options.onUnlink;
897
931
  if (hook) return hook(target);
898
932
  return inner.rmdir?.(target);
899
933
  },
900
934
  async rename(oldPath, newPath) {
901
- return inner.rename?.(visible(oldPath), visible(newPath));
935
+ return inner.rename?.(writable(oldPath), writable(newPath));
902
936
  },
903
937
  async exists(path) {
904
938
  if (isHidden(rp(path))) return false;
@@ -5357,8 +5391,17 @@ var AppDataGroupImpl = class {
5357
5391
  log5.warn(`[AppDataGroup:${this.groupId}] failed to write .meta/group.json:`, err);
5358
5392
  }
5359
5393
  this.fs = createChrootFS(this.localFS, "/", {
5360
- hiddenPrefixes: [META_DIR, CONFIG_DIR],
5394
+ hiddenPrefixes: [CONFIG_DIR],
5395
+ readOnlyPrefixes: [
5396
+ TOMBSTONES_DIR,
5397
+ LEGACY_TOMBSTONES_DIR,
5398
+ VERSIONS_DIR,
5399
+ CONFLICTS_DIR,
5400
+ LEGACY_CONFLICTS_DIR,
5401
+ GROUP_DESCRIPTOR_FILE3
5402
+ ],
5361
5403
  onWrite: async (path, data) => {
5404
+ if (path.startsWith(`${META_DIR}/`) || path === META_DIR) return;
5362
5405
  await this.clearTombstonesForWrite(path);
5363
5406
  await this.recordVersion(path, data);
5364
5407
  },
package/dist/index.mjs CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  registerBackend,
10
10
  unregisterBackend,
11
11
  wrapZenFSFileSystem
12
- } from "./chunk-QBBPUTC7.mjs";
12
+ } from "./chunk-JS3F3RBC.mjs";
13
13
 
14
14
  // src/config-repo.ts
15
15
  import {
@@ -103,11 +103,21 @@ function makeEnoent(userPath) {
103
103
  err.code = "ENOENT";
104
104
  return err;
105
105
  }
106
+ function makeEperm(userPath) {
107
+ const err = new Error(
108
+ `EPERM: '${userPath}' is read-only (sync metadata; use the group/backend API)`
109
+ );
110
+ err.code = "EPERM";
111
+ return err;
112
+ }
106
113
  function createChrootFS(inner, root, options = {}) {
107
114
  const normalizedRoot = root.replace(/\\/g, "/").replace(/\/+$/, "") || "/";
108
115
  const hiddenPrefixes = (options.hiddenPrefixes ?? []).map(
109
116
  (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
110
117
  );
118
+ const readOnlyPrefixes = (options.readOnlyPrefixes ?? []).map(
119
+ (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
120
+ );
111
121
  function rp(path) {
112
122
  return resolveChroot(normalizedRoot, path);
113
123
  }
@@ -121,12 +131,22 @@ function createChrootFS(inner, root, options = {}) {
121
131
  if (isHidden(absolute)) throw makeEnoent(path);
122
132
  return absolute;
123
133
  }
134
+ function isReadOnly(absolutePath) {
135
+ return readOnlyPrefixes.some(
136
+ (prefix) => absolutePath === prefix || absolutePath.startsWith(`${prefix}/`)
137
+ );
138
+ }
139
+ function writable(path) {
140
+ const absolute = visible(path);
141
+ if (isReadOnly(absolute)) throw makeEperm(path);
142
+ return absolute;
143
+ }
124
144
  const promises = {
125
145
  async readFile(path, encoding) {
126
146
  return inner.readFile(visible(path), encoding);
127
147
  },
128
148
  async writeFile(path, data, writeOptions) {
129
- const target = visible(path);
149
+ const target = writable(path);
130
150
  await ensureParentDir(target);
131
151
  await inner.writeFile(target, data, writeOptions);
132
152
  if (options.onWrite) await options.onWrite(path, data);
@@ -153,21 +173,21 @@ function createChrootFS(inner, root, options = {}) {
153
173
  if (!exists) throw makeEnoent(path);
154
174
  },
155
175
  async mkdir(path, mkdirOptions) {
156
- return inner.mkdir(visible(path), mkdirOptions);
176
+ return inner.mkdir(writable(path), mkdirOptions);
157
177
  },
158
178
  async unlink(path) {
159
- const target = visible(path);
179
+ const target = writable(path);
160
180
  if (options.onUnlink) return options.onUnlink(target);
161
181
  return inner.unlink(target);
162
182
  },
163
183
  async rmdir(path) {
164
- const target = visible(path);
184
+ const target = writable(path);
165
185
  const hook = options.onRmdir ?? options.onUnlink;
166
186
  if (hook) return hook(target);
167
187
  return inner.rmdir?.(target);
168
188
  },
169
189
  async rename(oldPath, newPath) {
170
- return inner.rename?.(visible(oldPath), visible(newPath));
190
+ return inner.rename?.(writable(oldPath), writable(newPath));
171
191
  },
172
192
  async exists(path) {
173
193
  if (isHidden(rp(path))) return false;
@@ -465,7 +485,7 @@ function registerFolderBackend() {
465
485
  const pathMod = await import("path");
466
486
  const dir = options.path;
467
487
  const store = new FolderStore({ path: dir, label: options.label, fs, pathMod });
468
- return (await import("./backend-registry-OZ4XU76Z.mjs")).wrapZenFSFileSystem({ backend: FolderBackend, path: dir, label: options.label });
488
+ return (await import("./backend-registry-KRGXHZRB.mjs")).wrapZenFSFileSystem({ backend: FolderBackend, path: dir, label: options.label });
469
489
  },
470
490
  {
471
491
  type: "Folder",
@@ -4622,8 +4642,17 @@ var AppDataGroupImpl = class {
4622
4642
  log5.warn(`[AppDataGroup:${this.groupId}] failed to write .meta/group.json:`, err);
4623
4643
  }
4624
4644
  this.fs = createChrootFS(this.localFS, "/", {
4625
- hiddenPrefixes: [META_DIR, CONFIG_DIR],
4645
+ hiddenPrefixes: [CONFIG_DIR],
4646
+ readOnlyPrefixes: [
4647
+ TOMBSTONES_DIR,
4648
+ LEGACY_TOMBSTONES_DIR,
4649
+ VERSIONS_DIR,
4650
+ CONFLICTS_DIR,
4651
+ LEGACY_CONFLICTS_DIR,
4652
+ GROUP_DESCRIPTOR_FILE3
4653
+ ],
4626
4654
  onWrite: async (path, data) => {
4655
+ if (path.startsWith(`${META_DIR}/`) || path === META_DIR) return;
4627
4656
  await this.clearTombstonesForWrite(path);
4628
4657
  await this.recordVersion(path, data);
4629
4658
  },
@@ -24522,6 +24522,7 @@ var ZenFSConfig = (() => {
24522
24522
  return registry.delete(type);
24523
24523
  }
24524
24524
  async function createBackend(descriptor) {
24525
+ traceCreateBackend(descriptor.type, descriptor.options);
24525
24526
  const factory = registry.get(descriptor.type);
24526
24527
  if (!factory) {
24527
24528
  throw new Error(
@@ -24530,6 +24531,19 @@ var ZenFSConfig = (() => {
24530
24531
  }
24531
24532
  return factory(descriptor.options);
24532
24533
  }
24534
+ function traceCreateBackend(type, options) {
24535
+ const g = globalThis;
24536
+ try {
24537
+ if (!Array.isArray(g.__zenfsBackendTrace)) g.__zenfsBackendTrace = [];
24538
+ g.__zenfsBackendTrace.push({
24539
+ type,
24540
+ storeName: options?.storeName ?? null,
24541
+ registered: registry.has(type),
24542
+ at: Date.now()
24543
+ });
24544
+ } catch {
24545
+ }
24546
+ }
24533
24547
  function hasBackend(type) {
24534
24548
  return registry.has(type);
24535
24549
  }
@@ -26808,11 +26822,21 @@ var ZenFSConfig = (() => {
26808
26822
  err2.code = "ENOENT";
26809
26823
  return err2;
26810
26824
  }
26825
+ function makeEperm(userPath) {
26826
+ const err2 = new Error(
26827
+ `EPERM: '${userPath}' is read-only (sync metadata; use the group/backend API)`
26828
+ );
26829
+ err2.code = "EPERM";
26830
+ return err2;
26831
+ }
26811
26832
  function createChrootFS(inner, root, options = {}) {
26812
26833
  const normalizedRoot = root.replace(/\\/g, "/").replace(/\/+$/, "") || "/";
26813
26834
  const hiddenPrefixes = (options.hiddenPrefixes ?? []).map(
26814
26835
  (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
26815
26836
  );
26837
+ const readOnlyPrefixes = (options.readOnlyPrefixes ?? []).map(
26838
+ (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
26839
+ );
26816
26840
  function rp(path) {
26817
26841
  return resolveChroot(normalizedRoot, path);
26818
26842
  }
@@ -26826,12 +26850,22 @@ var ZenFSConfig = (() => {
26826
26850
  if (isHidden(absolute)) throw makeEnoent(path);
26827
26851
  return absolute;
26828
26852
  }
26853
+ function isReadOnly(absolutePath) {
26854
+ return readOnlyPrefixes.some(
26855
+ (prefix) => absolutePath === prefix || absolutePath.startsWith(`${prefix}/`)
26856
+ );
26857
+ }
26858
+ function writable(path) {
26859
+ const absolute = visible(path);
26860
+ if (isReadOnly(absolute)) throw makeEperm(path);
26861
+ return absolute;
26862
+ }
26829
26863
  const promises = {
26830
26864
  async readFile(path, encoding) {
26831
26865
  return inner.readFile(visible(path), encoding);
26832
26866
  },
26833
26867
  async writeFile(path, data, writeOptions) {
26834
- const target = visible(path);
26868
+ const target = writable(path);
26835
26869
  await ensureParentDir(target);
26836
26870
  await inner.writeFile(target, data, writeOptions);
26837
26871
  if (options.onWrite) await options.onWrite(path, data);
@@ -26858,21 +26892,21 @@ var ZenFSConfig = (() => {
26858
26892
  if (!exists3) throw makeEnoent(path);
26859
26893
  },
26860
26894
  async mkdir(path, mkdirOptions) {
26861
- return inner.mkdir(visible(path), mkdirOptions);
26895
+ return inner.mkdir(writable(path), mkdirOptions);
26862
26896
  },
26863
26897
  async unlink(path) {
26864
- const target = visible(path);
26898
+ const target = writable(path);
26865
26899
  if (options.onUnlink) return options.onUnlink(target);
26866
26900
  return inner.unlink(target);
26867
26901
  },
26868
26902
  async rmdir(path) {
26869
- const target = visible(path);
26903
+ const target = writable(path);
26870
26904
  const hook = options.onRmdir ?? options.onUnlink;
26871
26905
  if (hook) return hook(target);
26872
26906
  return inner.rmdir?.(target);
26873
26907
  },
26874
26908
  async rename(oldPath, newPath) {
26875
- return inner.rename?.(visible(oldPath), visible(newPath));
26909
+ return inner.rename?.(writable(oldPath), writable(newPath));
26876
26910
  },
26877
26911
  async exists(path) {
26878
26912
  if (isHidden(rp(path))) return false;
@@ -31314,8 +31348,17 @@ var ZenFSConfig = (() => {
31314
31348
  log9.warn(`[AppDataGroup:${this.groupId}] failed to write .meta/group.json:`, err2);
31315
31349
  }
31316
31350
  this.fs = createChrootFS(this.localFS, "/", {
31317
- hiddenPrefixes: [META_DIR, CONFIG_DIR],
31351
+ hiddenPrefixes: [CONFIG_DIR],
31352
+ readOnlyPrefixes: [
31353
+ TOMBSTONES_DIR,
31354
+ LEGACY_TOMBSTONES_DIR,
31355
+ VERSIONS_DIR,
31356
+ CONFLICTS_DIR,
31357
+ LEGACY_CONFLICTS_DIR,
31358
+ GROUP_DESCRIPTOR_FILE3
31359
+ ],
31318
31360
  onWrite: async (path, data) => {
31361
+ if (path.startsWith(`${META_DIR}/`) || path === META_DIR) return;
31319
31362
  await this.clearTombstonesForWrite(path);
31320
31363
  await this.recordVersion(path, data);
31321
31364
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-fs-config",
3
- "version": "0.7.10",
3
+ "version": "0.7.12",
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",