zen-fs-config 0.7.0 → 0.7.1

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.js CHANGED
@@ -2120,6 +2120,45 @@ async function removeDirectoryTree(fs, dir) {
2120
2120
  } catch {
2121
2121
  }
2122
2122
  }
2123
+ async function collectFilesUnderAny(surfaces, dir, onError) {
2124
+ const merged = /* @__PURE__ */ new Set();
2125
+ for (const surface of surfaces) {
2126
+ try {
2127
+ for (const file of await collectFilesUnder(surface.fs, dir)) merged.add(file);
2128
+ } catch (error) {
2129
+ onError(surface.label, error);
2130
+ }
2131
+ }
2132
+ return [...merged];
2133
+ }
2134
+ async function collectDirectoriesUnderStrict(fs, dir, out = []) {
2135
+ out.push(dir);
2136
+ const entries = await fs.readdir(dir);
2137
+ for (const entry of entries) {
2138
+ const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
2139
+ if (await isDirectoryPath(fs, child)) await collectDirectoriesUnderStrict(fs, child, out);
2140
+ }
2141
+ return out;
2142
+ }
2143
+ async function collectDirectoriesUnderAny(surfaces, dir, onError) {
2144
+ const merged = /* @__PURE__ */ new Set();
2145
+ for (const surface of surfaces) {
2146
+ const found = [];
2147
+ try {
2148
+ await collectDirectoriesUnderStrict(surface.fs, dir, found);
2149
+ } catch (error) {
2150
+ onError(surface.label, error);
2151
+ }
2152
+ for (const child of found) merged.add(child);
2153
+ }
2154
+ return [...merged];
2155
+ }
2156
+ async function isDirectoryAny(surfaces, path) {
2157
+ for (const surface of surfaces) {
2158
+ if (await isDirectoryPath(surface.fs, path)) return true;
2159
+ }
2160
+ return false;
2161
+ }
2123
2162
  function isNotFoundError(err) {
2124
2163
  const code = err?.code;
2125
2164
  if (code === "ENOENT" || code === "ENOTDIR") return true;
@@ -2461,10 +2500,20 @@ var ConfigRepo = class {
2461
2500
  async deleteFile(path) {
2462
2501
  this.assertNotDisposed();
2463
2502
  const normalizedPath = path.startsWith("/") ? path : "/" + path;
2464
- if (await isDirectoryPath(this.cachedFS, normalizedPath)) {
2465
- const files = await collectFilesUnder(this.cachedFS, normalizedPath);
2503
+ const surfaces = [{ label: "local-cache", fs: this.cachedFS }];
2504
+ for (const [id, replica] of this.replicaBackends) {
2505
+ surfaces.push({ label: id, fs: replica.instance });
2506
+ }
2507
+ const onEnumerateError = (label, error) => {
2508
+ const reason = error?.message ?? String(error);
2509
+ log3.warn(
2510
+ `[ConfigRepo] deleteFile(directory): cannot enumerate "${label}" under ${normalizedPath}: ${reason}`
2511
+ );
2512
+ };
2513
+ if (await isDirectoryAny(surfaces, normalizedPath)) {
2514
+ const files = await collectFilesUnderAny(surfaces, normalizedPath, onEnumerateError);
2466
2515
  for (const file of files) await this.deleteFile(file);
2467
- for (const dir of await collectDirectoriesUnder(this.cachedFS, normalizedPath)) {
2516
+ for (const dir of await collectDirectoriesUnderAny(surfaces, normalizedPath, onEnumerateError)) {
2468
2517
  const keepPath = dir === "/" ? "/.keep" : `${dir}/.keep`;
2469
2518
  await this.writeTombstoneFor(keepPath);
2470
2519
  await this.writeTombstoneFor(`${keepPath}.mtime`);
package/dist/index.mjs CHANGED
@@ -1565,6 +1565,45 @@ async function removeDirectoryTree(fs, dir) {
1565
1565
  } catch {
1566
1566
  }
1567
1567
  }
1568
+ async function collectFilesUnderAny(surfaces, dir, onError) {
1569
+ const merged = /* @__PURE__ */ new Set();
1570
+ for (const surface of surfaces) {
1571
+ try {
1572
+ for (const file of await collectFilesUnder(surface.fs, dir)) merged.add(file);
1573
+ } catch (error) {
1574
+ onError(surface.label, error);
1575
+ }
1576
+ }
1577
+ return [...merged];
1578
+ }
1579
+ async function collectDirectoriesUnderStrict(fs, dir, out = []) {
1580
+ out.push(dir);
1581
+ const entries = await fs.readdir(dir);
1582
+ for (const entry of entries) {
1583
+ const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
1584
+ if (await isDirectoryPath(fs, child)) await collectDirectoriesUnderStrict(fs, child, out);
1585
+ }
1586
+ return out;
1587
+ }
1588
+ async function collectDirectoriesUnderAny(surfaces, dir, onError) {
1589
+ const merged = /* @__PURE__ */ new Set();
1590
+ for (const surface of surfaces) {
1591
+ const found = [];
1592
+ try {
1593
+ await collectDirectoriesUnderStrict(surface.fs, dir, found);
1594
+ } catch (error) {
1595
+ onError(surface.label, error);
1596
+ }
1597
+ for (const child of found) merged.add(child);
1598
+ }
1599
+ return [...merged];
1600
+ }
1601
+ async function isDirectoryAny(surfaces, path) {
1602
+ for (const surface of surfaces) {
1603
+ if (await isDirectoryPath(surface.fs, path)) return true;
1604
+ }
1605
+ return false;
1606
+ }
1568
1607
  function isNotFoundError(err) {
1569
1608
  const code = err?.code;
1570
1609
  if (code === "ENOENT" || code === "ENOTDIR") return true;
@@ -1906,10 +1945,20 @@ var ConfigRepo = class {
1906
1945
  async deleteFile(path) {
1907
1946
  this.assertNotDisposed();
1908
1947
  const normalizedPath = path.startsWith("/") ? path : "/" + path;
1909
- if (await isDirectoryPath(this.cachedFS, normalizedPath)) {
1910
- const files = await collectFilesUnder(this.cachedFS, normalizedPath);
1948
+ const surfaces = [{ label: "local-cache", fs: this.cachedFS }];
1949
+ for (const [id, replica] of this.replicaBackends) {
1950
+ surfaces.push({ label: id, fs: replica.instance });
1951
+ }
1952
+ const onEnumerateError = (label, error) => {
1953
+ const reason = error?.message ?? String(error);
1954
+ log3.warn(
1955
+ `[ConfigRepo] deleteFile(directory): cannot enumerate "${label}" under ${normalizedPath}: ${reason}`
1956
+ );
1957
+ };
1958
+ if (await isDirectoryAny(surfaces, normalizedPath)) {
1959
+ const files = await collectFilesUnderAny(surfaces, normalizedPath, onEnumerateError);
1911
1960
  for (const file of files) await this.deleteFile(file);
1912
- for (const dir of await collectDirectoriesUnder(this.cachedFS, normalizedPath)) {
1961
+ for (const dir of await collectDirectoriesUnderAny(surfaces, normalizedPath, onEnumerateError)) {
1913
1962
  const keepPath = dir === "/" ? "/.keep" : `${dir}/.keep`;
1914
1963
  await this.writeTombstoneFor(keepPath);
1915
1964
  await this.writeTombstoneFor(`${keepPath}.mtime`);
@@ -28134,6 +28134,45 @@ var ZenFSConfig = (() => {
28134
28134
  } catch {
28135
28135
  }
28136
28136
  }
28137
+ async function collectFilesUnderAny(surfaces, dir, onError) {
28138
+ const merged = /* @__PURE__ */ new Set();
28139
+ for (const surface of surfaces) {
28140
+ try {
28141
+ for (const file of await collectFilesUnder(surface.fs, dir)) merged.add(file);
28142
+ } catch (error) {
28143
+ onError(surface.label, error);
28144
+ }
28145
+ }
28146
+ return [...merged];
28147
+ }
28148
+ async function collectDirectoriesUnderStrict(fs, dir, out = []) {
28149
+ out.push(dir);
28150
+ const entries2 = await fs.readdir(dir);
28151
+ for (const entry of entries2) {
28152
+ const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
28153
+ if (await isDirectoryPath(fs, child)) await collectDirectoriesUnderStrict(fs, child, out);
28154
+ }
28155
+ return out;
28156
+ }
28157
+ async function collectDirectoriesUnderAny(surfaces, dir, onError) {
28158
+ const merged = /* @__PURE__ */ new Set();
28159
+ for (const surface of surfaces) {
28160
+ const found = [];
28161
+ try {
28162
+ await collectDirectoriesUnderStrict(surface.fs, dir, found);
28163
+ } catch (error) {
28164
+ onError(surface.label, error);
28165
+ }
28166
+ for (const child of found) merged.add(child);
28167
+ }
28168
+ return [...merged];
28169
+ }
28170
+ async function isDirectoryAny(surfaces, path) {
28171
+ for (const surface of surfaces) {
28172
+ if (await isDirectoryPath(surface.fs, path)) return true;
28173
+ }
28174
+ return false;
28175
+ }
28137
28176
  function isNotFoundError(err2) {
28138
28177
  const code = err2?.code;
28139
28178
  if (code === "ENOENT" || code === "ENOTDIR") return true;
@@ -28481,10 +28520,20 @@ var ZenFSConfig = (() => {
28481
28520
  async deleteFile(path) {
28482
28521
  this.assertNotDisposed();
28483
28522
  const normalizedPath = path.startsWith("/") ? path : "/" + path;
28484
- if (await isDirectoryPath(this.cachedFS, normalizedPath)) {
28485
- const files = await collectFilesUnder(this.cachedFS, normalizedPath);
28523
+ const surfaces = [{ label: "local-cache", fs: this.cachedFS }];
28524
+ for (const [id, replica] of this.replicaBackends) {
28525
+ surfaces.push({ label: id, fs: replica.instance });
28526
+ }
28527
+ const onEnumerateError = (label, error) => {
28528
+ const reason = error?.message ?? String(error);
28529
+ log7.warn(
28530
+ `[ConfigRepo] deleteFile(directory): cannot enumerate "${label}" under ${normalizedPath}: ${reason}`
28531
+ );
28532
+ };
28533
+ if (await isDirectoryAny(surfaces, normalizedPath)) {
28534
+ const files = await collectFilesUnderAny(surfaces, normalizedPath, onEnumerateError);
28486
28535
  for (const file of files) await this.deleteFile(file);
28487
- for (const dir of await collectDirectoriesUnder(this.cachedFS, normalizedPath)) {
28536
+ for (const dir of await collectDirectoriesUnderAny(surfaces, normalizedPath, onEnumerateError)) {
28488
28537
  const keepPath = dir === "/" ? "/.keep" : `${dir}/.keep`;
28489
28538
  await this.writeTombstoneFor(keepPath);
28490
28539
  await this.writeTombstoneFor(`${keepPath}.mtime`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-fs-config",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
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",