zen-fs-config 0.7.11 → 0.7.13

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
@@ -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
@@ -848,11 +848,31 @@ function makeEnoent(userPath) {
848
848
  err.code = "ENOENT";
849
849
  return err;
850
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
+ }
858
+ function makeEconfirm(userPath) {
859
+ const err = new Error(
860
+ `ECONFIRM: '${userPath}' changes sync metadata \u2014 retry with { confirm: true } after warning the user`
861
+ );
862
+ err.code = "ECONFIRM";
863
+ return err;
864
+ }
851
865
  function createChrootFS(inner, root, options = {}) {
852
866
  const normalizedRoot = root.replace(/\\/g, "/").replace(/\/+$/, "") || "/";
853
867
  const hiddenPrefixes = (options.hiddenPrefixes ?? []).map(
854
868
  (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
855
869
  );
870
+ const readOnlyPrefixes = (options.readOnlyPrefixes ?? []).map(
871
+ (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
872
+ );
873
+ const confirmPrefixes = (options.confirmPrefixes ?? []).map(
874
+ (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
875
+ );
856
876
  function rp(path) {
857
877
  return resolveChroot(normalizedRoot, path);
858
878
  }
@@ -866,12 +886,28 @@ function createChrootFS(inner, root, options = {}) {
866
886
  if (isHidden(absolute)) throw makeEnoent(path);
867
887
  return absolute;
868
888
  }
889
+ function isReadOnly(absolutePath) {
890
+ return readOnlyPrefixes.some(
891
+ (prefix) => absolutePath === prefix || absolutePath.startsWith(`${prefix}/`)
892
+ );
893
+ }
894
+ function needsConfirm(absolutePath) {
895
+ return confirmPrefixes.some(
896
+ (prefix) => absolutePath === prefix || absolutePath.startsWith(`${prefix}/`)
897
+ );
898
+ }
899
+ function writable(path, writeOptions) {
900
+ const absolute = visible(path);
901
+ if (isReadOnly(absolute)) throw makeEperm(path);
902
+ if (needsConfirm(absolute) && writeOptions?.confirm !== true) throw makeEconfirm(path);
903
+ return absolute;
904
+ }
869
905
  const promises = {
870
906
  async readFile(path, encoding) {
871
907
  return inner.readFile(visible(path), encoding);
872
908
  },
873
909
  async writeFile(path, data, writeOptions) {
874
- const target = visible(path);
910
+ const target = writable(path, writeOptions);
875
911
  await ensureParentDir(target);
876
912
  await inner.writeFile(target, data, writeOptions);
877
913
  if (options.onWrite) await options.onWrite(path, data);
@@ -898,21 +934,21 @@ function createChrootFS(inner, root, options = {}) {
898
934
  if (!exists) throw makeEnoent(path);
899
935
  },
900
936
  async mkdir(path, mkdirOptions) {
901
- return inner.mkdir(visible(path), mkdirOptions);
937
+ return inner.mkdir(writable(path, mkdirOptions), mkdirOptions);
902
938
  },
903
- async unlink(path) {
904
- const target = visible(path);
939
+ async unlink(path, unlinkOptions) {
940
+ const target = writable(path, unlinkOptions);
905
941
  if (options.onUnlink) return options.onUnlink(target);
906
942
  return inner.unlink(target);
907
943
  },
908
- async rmdir(path) {
909
- const target = visible(path);
944
+ async rmdir(path, rmdirOptions) {
945
+ const target = writable(path, rmdirOptions);
910
946
  const hook = options.onRmdir ?? options.onUnlink;
911
947
  if (hook) return hook(target);
912
948
  return inner.rmdir?.(target);
913
949
  },
914
- async rename(oldPath, newPath) {
915
- return inner.rename?.(visible(oldPath), visible(newPath));
950
+ async rename(oldPath, newPath, renameOptions) {
951
+ return inner.rename?.(writable(oldPath, renameOptions), writable(newPath, renameOptions));
916
952
  },
917
953
  async exists(path) {
918
954
  if (isHidden(rp(path))) return false;
@@ -5371,8 +5407,17 @@ var AppDataGroupImpl = class {
5371
5407
  log5.warn(`[AppDataGroup:${this.groupId}] failed to write .meta/group.json:`, err);
5372
5408
  }
5373
5409
  this.fs = createChrootFS(this.localFS, "/", {
5374
- hiddenPrefixes: [META_DIR, CONFIG_DIR],
5410
+ hiddenPrefixes: [CONFIG_DIR],
5411
+ readOnlyPrefixes: [
5412
+ TOMBSTONES_DIR,
5413
+ LEGACY_TOMBSTONES_DIR,
5414
+ VERSIONS_DIR,
5415
+ CONFLICTS_DIR,
5416
+ LEGACY_CONFLICTS_DIR
5417
+ ],
5418
+ confirmPrefixes: [GROUP_DESCRIPTOR_FILE3],
5375
5419
  onWrite: async (path, data) => {
5420
+ if (path.startsWith(`${META_DIR}/`) || path === META_DIR) return;
5376
5421
  await this.clearTombstonesForWrite(path);
5377
5422
  await this.recordVersion(path, data);
5378
5423
  },
package/dist/index.mjs CHANGED
@@ -103,11 +103,31 @@ 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
+ }
113
+ function makeEconfirm(userPath) {
114
+ const err = new Error(
115
+ `ECONFIRM: '${userPath}' changes sync metadata \u2014 retry with { confirm: true } after warning the user`
116
+ );
117
+ err.code = "ECONFIRM";
118
+ return err;
119
+ }
106
120
  function createChrootFS(inner, root, options = {}) {
107
121
  const normalizedRoot = root.replace(/\\/g, "/").replace(/\/+$/, "") || "/";
108
122
  const hiddenPrefixes = (options.hiddenPrefixes ?? []).map(
109
123
  (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
110
124
  );
125
+ const readOnlyPrefixes = (options.readOnlyPrefixes ?? []).map(
126
+ (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
127
+ );
128
+ const confirmPrefixes = (options.confirmPrefixes ?? []).map(
129
+ (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
130
+ );
111
131
  function rp(path) {
112
132
  return resolveChroot(normalizedRoot, path);
113
133
  }
@@ -121,12 +141,28 @@ function createChrootFS(inner, root, options = {}) {
121
141
  if (isHidden(absolute)) throw makeEnoent(path);
122
142
  return absolute;
123
143
  }
144
+ function isReadOnly(absolutePath) {
145
+ return readOnlyPrefixes.some(
146
+ (prefix) => absolutePath === prefix || absolutePath.startsWith(`${prefix}/`)
147
+ );
148
+ }
149
+ function needsConfirm(absolutePath) {
150
+ return confirmPrefixes.some(
151
+ (prefix) => absolutePath === prefix || absolutePath.startsWith(`${prefix}/`)
152
+ );
153
+ }
154
+ function writable(path, writeOptions) {
155
+ const absolute = visible(path);
156
+ if (isReadOnly(absolute)) throw makeEperm(path);
157
+ if (needsConfirm(absolute) && writeOptions?.confirm !== true) throw makeEconfirm(path);
158
+ return absolute;
159
+ }
124
160
  const promises = {
125
161
  async readFile(path, encoding) {
126
162
  return inner.readFile(visible(path), encoding);
127
163
  },
128
164
  async writeFile(path, data, writeOptions) {
129
- const target = visible(path);
165
+ const target = writable(path, writeOptions);
130
166
  await ensureParentDir(target);
131
167
  await inner.writeFile(target, data, writeOptions);
132
168
  if (options.onWrite) await options.onWrite(path, data);
@@ -153,21 +189,21 @@ function createChrootFS(inner, root, options = {}) {
153
189
  if (!exists) throw makeEnoent(path);
154
190
  },
155
191
  async mkdir(path, mkdirOptions) {
156
- return inner.mkdir(visible(path), mkdirOptions);
192
+ return inner.mkdir(writable(path, mkdirOptions), mkdirOptions);
157
193
  },
158
- async unlink(path) {
159
- const target = visible(path);
194
+ async unlink(path, unlinkOptions) {
195
+ const target = writable(path, unlinkOptions);
160
196
  if (options.onUnlink) return options.onUnlink(target);
161
197
  return inner.unlink(target);
162
198
  },
163
- async rmdir(path) {
164
- const target = visible(path);
199
+ async rmdir(path, rmdirOptions) {
200
+ const target = writable(path, rmdirOptions);
165
201
  const hook = options.onRmdir ?? options.onUnlink;
166
202
  if (hook) return hook(target);
167
203
  return inner.rmdir?.(target);
168
204
  },
169
- async rename(oldPath, newPath) {
170
- return inner.rename?.(visible(oldPath), visible(newPath));
205
+ async rename(oldPath, newPath, renameOptions) {
206
+ return inner.rename?.(writable(oldPath, renameOptions), writable(newPath, renameOptions));
171
207
  },
172
208
  async exists(path) {
173
209
  if (isHidden(rp(path))) return false;
@@ -4622,8 +4658,17 @@ var AppDataGroupImpl = class {
4622
4658
  log5.warn(`[AppDataGroup:${this.groupId}] failed to write .meta/group.json:`, err);
4623
4659
  }
4624
4660
  this.fs = createChrootFS(this.localFS, "/", {
4625
- hiddenPrefixes: [META_DIR, CONFIG_DIR],
4661
+ hiddenPrefixes: [CONFIG_DIR],
4662
+ readOnlyPrefixes: [
4663
+ TOMBSTONES_DIR,
4664
+ LEGACY_TOMBSTONES_DIR,
4665
+ VERSIONS_DIR,
4666
+ CONFLICTS_DIR,
4667
+ LEGACY_CONFLICTS_DIR
4668
+ ],
4669
+ confirmPrefixes: [GROUP_DESCRIPTOR_FILE3],
4626
4670
  onWrite: async (path, data) => {
4671
+ if (path.startsWith(`${META_DIR}/`) || path === META_DIR) return;
4627
4672
  await this.clearTombstonesForWrite(path);
4628
4673
  await this.recordVersion(path, data);
4629
4674
  },
@@ -26822,11 +26822,31 @@ var ZenFSConfig = (() => {
26822
26822
  err2.code = "ENOENT";
26823
26823
  return err2;
26824
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
+ }
26832
+ function makeEconfirm(userPath) {
26833
+ const err2 = new Error(
26834
+ `ECONFIRM: '${userPath}' changes sync metadata \u2014 retry with { confirm: true } after warning the user`
26835
+ );
26836
+ err2.code = "ECONFIRM";
26837
+ return err2;
26838
+ }
26825
26839
  function createChrootFS(inner, root, options = {}) {
26826
26840
  const normalizedRoot = root.replace(/\\/g, "/").replace(/\/+$/, "") || "/";
26827
26841
  const hiddenPrefixes = (options.hiddenPrefixes ?? []).map(
26828
26842
  (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
26829
26843
  );
26844
+ const readOnlyPrefixes = (options.readOnlyPrefixes ?? []).map(
26845
+ (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
26846
+ );
26847
+ const confirmPrefixes = (options.confirmPrefixes ?? []).map(
26848
+ (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
26849
+ );
26830
26850
  function rp(path) {
26831
26851
  return resolveChroot(normalizedRoot, path);
26832
26852
  }
@@ -26840,12 +26860,28 @@ var ZenFSConfig = (() => {
26840
26860
  if (isHidden(absolute)) throw makeEnoent(path);
26841
26861
  return absolute;
26842
26862
  }
26863
+ function isReadOnly(absolutePath) {
26864
+ return readOnlyPrefixes.some(
26865
+ (prefix) => absolutePath === prefix || absolutePath.startsWith(`${prefix}/`)
26866
+ );
26867
+ }
26868
+ function needsConfirm(absolutePath) {
26869
+ return confirmPrefixes.some(
26870
+ (prefix) => absolutePath === prefix || absolutePath.startsWith(`${prefix}/`)
26871
+ );
26872
+ }
26873
+ function writable(path, writeOptions) {
26874
+ const absolute = visible(path);
26875
+ if (isReadOnly(absolute)) throw makeEperm(path);
26876
+ if (needsConfirm(absolute) && writeOptions?.confirm !== true) throw makeEconfirm(path);
26877
+ return absolute;
26878
+ }
26843
26879
  const promises = {
26844
26880
  async readFile(path, encoding) {
26845
26881
  return inner.readFile(visible(path), encoding);
26846
26882
  },
26847
26883
  async writeFile(path, data, writeOptions) {
26848
- const target = visible(path);
26884
+ const target = writable(path, writeOptions);
26849
26885
  await ensureParentDir(target);
26850
26886
  await inner.writeFile(target, data, writeOptions);
26851
26887
  if (options.onWrite) await options.onWrite(path, data);
@@ -26872,21 +26908,21 @@ var ZenFSConfig = (() => {
26872
26908
  if (!exists3) throw makeEnoent(path);
26873
26909
  },
26874
26910
  async mkdir(path, mkdirOptions) {
26875
- return inner.mkdir(visible(path), mkdirOptions);
26911
+ return inner.mkdir(writable(path, mkdirOptions), mkdirOptions);
26876
26912
  },
26877
- async unlink(path) {
26878
- const target = visible(path);
26913
+ async unlink(path, unlinkOptions) {
26914
+ const target = writable(path, unlinkOptions);
26879
26915
  if (options.onUnlink) return options.onUnlink(target);
26880
26916
  return inner.unlink(target);
26881
26917
  },
26882
- async rmdir(path) {
26883
- const target = visible(path);
26918
+ async rmdir(path, rmdirOptions) {
26919
+ const target = writable(path, rmdirOptions);
26884
26920
  const hook = options.onRmdir ?? options.onUnlink;
26885
26921
  if (hook) return hook(target);
26886
26922
  return inner.rmdir?.(target);
26887
26923
  },
26888
- async rename(oldPath, newPath) {
26889
- return inner.rename?.(visible(oldPath), visible(newPath));
26924
+ async rename(oldPath, newPath, renameOptions) {
26925
+ return inner.rename?.(writable(oldPath, renameOptions), writable(newPath, renameOptions));
26890
26926
  },
26891
26927
  async exists(path) {
26892
26928
  if (isHidden(rp(path))) return false;
@@ -31328,8 +31364,17 @@ var ZenFSConfig = (() => {
31328
31364
  log9.warn(`[AppDataGroup:${this.groupId}] failed to write .meta/group.json:`, err2);
31329
31365
  }
31330
31366
  this.fs = createChrootFS(this.localFS, "/", {
31331
- hiddenPrefixes: [META_DIR, CONFIG_DIR],
31367
+ hiddenPrefixes: [CONFIG_DIR],
31368
+ readOnlyPrefixes: [
31369
+ TOMBSTONES_DIR,
31370
+ LEGACY_TOMBSTONES_DIR,
31371
+ VERSIONS_DIR,
31372
+ CONFLICTS_DIR,
31373
+ LEGACY_CONFLICTS_DIR
31374
+ ],
31375
+ confirmPrefixes: [GROUP_DESCRIPTOR_FILE3],
31332
31376
  onWrite: async (path, data) => {
31377
+ if (path.startsWith(`${META_DIR}/`) || path === META_DIR) return;
31333
31378
  await this.clearTombstonesForWrite(path);
31334
31379
  await this.recordVersion(path, data);
31335
31380
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-fs-config",
3
- "version": "0.7.11",
3
+ "version": "0.7.13",
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",