zen-fs-config 0.7.11 → 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.
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,21 @@ 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
+ }
851
858
  function createChrootFS(inner, root, options = {}) {
852
859
  const normalizedRoot = root.replace(/\\/g, "/").replace(/\/+$/, "") || "/";
853
860
  const hiddenPrefixes = (options.hiddenPrefixes ?? []).map(
854
861
  (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
855
862
  );
863
+ const readOnlyPrefixes = (options.readOnlyPrefixes ?? []).map(
864
+ (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
865
+ );
856
866
  function rp(path) {
857
867
  return resolveChroot(normalizedRoot, path);
858
868
  }
@@ -866,12 +876,22 @@ function createChrootFS(inner, root, options = {}) {
866
876
  if (isHidden(absolute)) throw makeEnoent(path);
867
877
  return absolute;
868
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
+ }
869
889
  const promises = {
870
890
  async readFile(path, encoding) {
871
891
  return inner.readFile(visible(path), encoding);
872
892
  },
873
893
  async writeFile(path, data, writeOptions) {
874
- const target = visible(path);
894
+ const target = writable(path);
875
895
  await ensureParentDir(target);
876
896
  await inner.writeFile(target, data, writeOptions);
877
897
  if (options.onWrite) await options.onWrite(path, data);
@@ -898,21 +918,21 @@ function createChrootFS(inner, root, options = {}) {
898
918
  if (!exists) throw makeEnoent(path);
899
919
  },
900
920
  async mkdir(path, mkdirOptions) {
901
- return inner.mkdir(visible(path), mkdirOptions);
921
+ return inner.mkdir(writable(path), mkdirOptions);
902
922
  },
903
923
  async unlink(path) {
904
- const target = visible(path);
924
+ const target = writable(path);
905
925
  if (options.onUnlink) return options.onUnlink(target);
906
926
  return inner.unlink(target);
907
927
  },
908
928
  async rmdir(path) {
909
- const target = visible(path);
929
+ const target = writable(path);
910
930
  const hook = options.onRmdir ?? options.onUnlink;
911
931
  if (hook) return hook(target);
912
932
  return inner.rmdir?.(target);
913
933
  },
914
934
  async rename(oldPath, newPath) {
915
- return inner.rename?.(visible(oldPath), visible(newPath));
935
+ return inner.rename?.(writable(oldPath), writable(newPath));
916
936
  },
917
937
  async exists(path) {
918
938
  if (isHidden(rp(path))) return false;
@@ -5371,8 +5391,17 @@ var AppDataGroupImpl = class {
5371
5391
  log5.warn(`[AppDataGroup:${this.groupId}] failed to write .meta/group.json:`, err);
5372
5392
  }
5373
5393
  this.fs = createChrootFS(this.localFS, "/", {
5374
- 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
+ ],
5375
5403
  onWrite: async (path, data) => {
5404
+ if (path.startsWith(`${META_DIR}/`) || path === META_DIR) return;
5376
5405
  await this.clearTombstonesForWrite(path);
5377
5406
  await this.recordVersion(path, data);
5378
5407
  },
package/dist/index.mjs CHANGED
@@ -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;
@@ -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
  },
@@ -26822,11 +26822,21 @@ 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
+ }
26825
26832
  function createChrootFS(inner, root, options = {}) {
26826
26833
  const normalizedRoot = root.replace(/\\/g, "/").replace(/\/+$/, "") || "/";
26827
26834
  const hiddenPrefixes = (options.hiddenPrefixes ?? []).map(
26828
26835
  (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
26829
26836
  );
26837
+ const readOnlyPrefixes = (options.readOnlyPrefixes ?? []).map(
26838
+ (p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
26839
+ );
26830
26840
  function rp(path) {
26831
26841
  return resolveChroot(normalizedRoot, path);
26832
26842
  }
@@ -26840,12 +26850,22 @@ var ZenFSConfig = (() => {
26840
26850
  if (isHidden(absolute)) throw makeEnoent(path);
26841
26851
  return absolute;
26842
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
+ }
26843
26863
  const promises = {
26844
26864
  async readFile(path, encoding) {
26845
26865
  return inner.readFile(visible(path), encoding);
26846
26866
  },
26847
26867
  async writeFile(path, data, writeOptions) {
26848
- const target = visible(path);
26868
+ const target = writable(path);
26849
26869
  await ensureParentDir(target);
26850
26870
  await inner.writeFile(target, data, writeOptions);
26851
26871
  if (options.onWrite) await options.onWrite(path, data);
@@ -26872,21 +26892,21 @@ var ZenFSConfig = (() => {
26872
26892
  if (!exists3) throw makeEnoent(path);
26873
26893
  },
26874
26894
  async mkdir(path, mkdirOptions) {
26875
- return inner.mkdir(visible(path), mkdirOptions);
26895
+ return inner.mkdir(writable(path), mkdirOptions);
26876
26896
  },
26877
26897
  async unlink(path) {
26878
- const target = visible(path);
26898
+ const target = writable(path);
26879
26899
  if (options.onUnlink) return options.onUnlink(target);
26880
26900
  return inner.unlink(target);
26881
26901
  },
26882
26902
  async rmdir(path) {
26883
- const target = visible(path);
26903
+ const target = writable(path);
26884
26904
  const hook = options.onRmdir ?? options.onUnlink;
26885
26905
  if (hook) return hook(target);
26886
26906
  return inner.rmdir?.(target);
26887
26907
  },
26888
26908
  async rename(oldPath, newPath) {
26889
- return inner.rename?.(visible(oldPath), visible(newPath));
26909
+ return inner.rename?.(writable(oldPath), writable(newPath));
26890
26910
  },
26891
26911
  async exists(path) {
26892
26912
  if (isHidden(rp(path))) return false;
@@ -31328,8 +31348,17 @@ var ZenFSConfig = (() => {
31328
31348
  log9.warn(`[AppDataGroup:${this.groupId}] failed to write .meta/group.json:`, err2);
31329
31349
  }
31330
31350
  this.fs = createChrootFS(this.localFS, "/", {
31331
- 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
+ ],
31332
31360
  onWrite: async (path, data) => {
31361
+ if (path.startsWith(`${META_DIR}/`) || path === META_DIR) return;
31333
31362
  await this.clearTombstonesForWrite(path);
31334
31363
  await this.recordVersion(path, data);
31335
31364
  },
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.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",