zen-fs-config 0.7.1 → 0.7.3

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
@@ -5053,10 +5053,11 @@ async function connect(appId, options = {}) {
5053
5053
  log4(`connect: failed to load app data group "${d.id}":`, err);
5054
5054
  }
5055
5055
  }
5056
- let dataGroup2 = appDataGroups2[0];
5057
- if (!dataGroup2) {
5058
- dataGroup2 = await repo2.createAppDataGroup("default", []);
5059
- appDataGroups2.push(dataGroup2);
5056
+ const dataGroup2 = appDataGroups2[0];
5057
+ if (!dataGroup2 && descriptors2.length > 0) {
5058
+ log4(
5059
+ `connect: ${descriptors2.length} data group descriptor(s) found but none could be loaded; leaving them untouched (no empty group is created)`
5060
+ );
5060
5061
  }
5061
5062
  return {
5062
5063
  groupType: options.groupType ?? "config-sync",
@@ -5114,11 +5115,17 @@ async function connect(appId, options = {}) {
5114
5115
  let dataGroup = appDataGroups[0];
5115
5116
  if (groupType === "data-sync") {
5116
5117
  if (!dataGroup) {
5117
- dataGroup = await repo.createAppDataGroup("default", []);
5118
- appDataGroups.push(dataGroup);
5118
+ if (descriptors.length > 0) {
5119
+ log4(
5120
+ `connect: ${descriptors.length} data group descriptor(s) exist but could not be loaded; refusing to create/overwrite "default"`
5121
+ );
5122
+ } else {
5123
+ dataGroup = await repo.createAppDataGroup("default", []);
5124
+ appDataGroups.push(dataGroup);
5125
+ }
5119
5126
  }
5120
5127
  const backendId = `${type}-primary`;
5121
- if (!dataGroup.listBackends().some((b) => b.id === backendId)) {
5128
+ if (dataGroup && !dataGroup.listBackends().some((b) => b.id === backendId)) {
5122
5129
  await dataGroup.addBackend(backendId, type, backendOptions);
5123
5130
  }
5124
5131
  }
package/dist/index.mjs CHANGED
@@ -4497,10 +4497,11 @@ async function connect(appId, options = {}) {
4497
4497
  log4(`connect: failed to load app data group "${d.id}":`, err);
4498
4498
  }
4499
4499
  }
4500
- let dataGroup2 = appDataGroups2[0];
4501
- if (!dataGroup2) {
4502
- dataGroup2 = await repo2.createAppDataGroup("default", []);
4503
- appDataGroups2.push(dataGroup2);
4500
+ const dataGroup2 = appDataGroups2[0];
4501
+ if (!dataGroup2 && descriptors2.length > 0) {
4502
+ log4(
4503
+ `connect: ${descriptors2.length} data group descriptor(s) found but none could be loaded; leaving them untouched (no empty group is created)`
4504
+ );
4504
4505
  }
4505
4506
  return {
4506
4507
  groupType: options.groupType ?? "config-sync",
@@ -4558,11 +4559,17 @@ async function connect(appId, options = {}) {
4558
4559
  let dataGroup = appDataGroups[0];
4559
4560
  if (groupType === "data-sync") {
4560
4561
  if (!dataGroup) {
4561
- dataGroup = await repo.createAppDataGroup("default", []);
4562
- appDataGroups.push(dataGroup);
4562
+ if (descriptors.length > 0) {
4563
+ log4(
4564
+ `connect: ${descriptors.length} data group descriptor(s) exist but could not be loaded; refusing to create/overwrite "default"`
4565
+ );
4566
+ } else {
4567
+ dataGroup = await repo.createAppDataGroup("default", []);
4568
+ appDataGroups.push(dataGroup);
4569
+ }
4563
4570
  }
4564
4571
  const backendId = `${type}-primary`;
4565
- if (!dataGroup.listBackends().some((b) => b.id === backendId)) {
4572
+ if (dataGroup && !dataGroup.listBackends().some((b) => b.id === backendId)) {
4566
4573
  await dataGroup.addBackend(backendId, type, backendOptions);
4567
4574
  }
4568
4575
  }
@@ -25487,36 +25487,6 @@ var ZenFSConfig = (() => {
25487
25487
  await visit(normalizedRoot);
25488
25488
  return results;
25489
25489
  }
25490
- async function collectDirectories(fs, root, filter) {
25491
- const results = [];
25492
- const normalizedRoot = normalizePath(root);
25493
- async function visit(dir) {
25494
- let entries2;
25495
- try {
25496
- entries2 = await fs.readdir(dir);
25497
- } catch {
25498
- return;
25499
- }
25500
- for (const entry of entries2) {
25501
- if (entry === ".zenfs-sync") continue;
25502
- const fullPath = resolvePath(dir, entry);
25503
- let relPath = fullPath.slice(normalizedRoot.length) || "/";
25504
- if (!relPath.startsWith("/")) relPath = "/" + relPath;
25505
- let stat5;
25506
- try {
25507
- stat5 = await fs.stat(fullPath);
25508
- } catch {
25509
- continue;
25510
- }
25511
- if (isDirectory(stat5)) {
25512
- if (isPathAllowed(relPath, filter)) results.push(relPath);
25513
- await visit(fullPath);
25514
- }
25515
- }
25516
- }
25517
- await visit(normalizedRoot);
25518
- return results;
25519
- }
25520
25490
  async function buildSnapshot(fs, root, filter) {
25521
25491
  const normalizedRoot = normalizePath(root);
25522
25492
  const fsName = fs.backendName || "unknown";
@@ -26031,7 +26001,6 @@ var ZenFSConfig = (() => {
26031
26001
  }
26032
26002
  }
26033
26003
  }
26034
- await this.preserveDirectories(src, tgt);
26035
26004
  return {
26036
26005
  pairId: this.pairId,
26037
26006
  direction: this.options.direction,
@@ -26232,8 +26201,6 @@ var ZenFSConfig = (() => {
26232
26201
  }
26233
26202
  }
26234
26203
  }
26235
- await this.preserveDirectories(this.source, this.target);
26236
- await this.preserveDirectories(this.target, this.source);
26237
26204
  const durationMs = Date.now() - startTime;
26238
26205
  log3(`[zen-fs-sync] syncBidirectional END pairId=${this.pairId} +${filesCreated}/~${filesUpdated}/-${filesDeleted} ${durationMs}ms`);
26239
26206
  return {
@@ -26263,28 +26230,6 @@ var ZenFSConfig = (() => {
26263
26230
  }
26264
26231
  return buildSnapshot(fs, this.root, this.options.filter);
26265
26232
  }
26266
- /**
26267
- * Preserve empty directories across backends (zen-fs-sync/docs/SyncableFS.md §2).
26268
- *
26269
- * A backend that cannot store empty directories (Git, RemoteStorage) keeps a
26270
- * directory alive with an internal `.keep` placeholder that is hidden from
26271
- * callers. Because the sync snapshot is file-based, empty directories are not
26272
- * represented, so the sync engine must explicitly `mkdir` each source
26273
- * directory on the target. The target's own `mkdir` then produces its own
26274
- * (hidden) placeholder. Best-effort: failures are logged, never thrown.
26275
- */
26276
- async preserveDirectories(source, target) {
26277
- try {
26278
- const dirs = await collectDirectories(source, this.root, this.options.filter);
26279
- for (const relDir of dirs) {
26280
- if (relDir === "/") continue;
26281
- const fullDir = resolvePath(this.root, relDir);
26282
- await ensureDir(target, fullDir);
26283
- }
26284
- } catch (err2) {
26285
- log3(`[zen-fs-sync] preserveDirectories FAIL: ${err2}`);
26286
- }
26287
- }
26288
26233
  /**
26289
26234
  * Compare two snapshots for equality (same paths, same size, same mtime).
26290
26235
  * Returns true if they are identical, false otherwise.
@@ -31067,10 +31012,11 @@ var ZenFSConfig = (() => {
31067
31012
  log8(`connect: failed to load app data group "${d.id}":`, err2);
31068
31013
  }
31069
31014
  }
31070
- let dataGroup2 = appDataGroups2[0];
31071
- if (!dataGroup2) {
31072
- dataGroup2 = await repo2.createAppDataGroup("default", []);
31073
- appDataGroups2.push(dataGroup2);
31015
+ const dataGroup2 = appDataGroups2[0];
31016
+ if (!dataGroup2 && descriptors2.length > 0) {
31017
+ log8(
31018
+ `connect: ${descriptors2.length} data group descriptor(s) found but none could be loaded; leaving them untouched (no empty group is created)`
31019
+ );
31074
31020
  }
31075
31021
  return {
31076
31022
  groupType: options.groupType ?? "config-sync",
@@ -31128,11 +31074,17 @@ var ZenFSConfig = (() => {
31128
31074
  let dataGroup = appDataGroups[0];
31129
31075
  if (groupType === "data-sync") {
31130
31076
  if (!dataGroup) {
31131
- dataGroup = await repo.createAppDataGroup("default", []);
31132
- appDataGroups.push(dataGroup);
31077
+ if (descriptors.length > 0) {
31078
+ log8(
31079
+ `connect: ${descriptors.length} data group descriptor(s) exist but could not be loaded; refusing to create/overwrite "default"`
31080
+ );
31081
+ } else {
31082
+ dataGroup = await repo.createAppDataGroup("default", []);
31083
+ appDataGroups.push(dataGroup);
31084
+ }
31133
31085
  }
31134
31086
  const backendId = `${type}-primary`;
31135
- if (!dataGroup.listBackends().some((b) => b.id === backendId)) {
31087
+ if (dataGroup && !dataGroup.listBackends().some((b) => b.id === backendId)) {
31136
31088
  await dataGroup.addBackend(backendId, type, backendOptions);
31137
31089
  }
31138
31090
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-fs-config",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
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",
@@ -49,7 +49,7 @@
49
49
  "@zenfs/core": ">=2.3.0",
50
50
  "@zenfs/dom": ">=1.0.0",
51
51
  "zen-fs-cache": ">=1.0.0",
52
- "zen-fs-sync": ">=0.4.7",
52
+ "zen-fs-sync": ">=0.4.18",
53
53
  "zen-fs-github": "*",
54
54
  "zen-fs-gitee": "*",
55
55
  "zen-fs-remotestoragejs": "*",
@@ -85,6 +85,6 @@
85
85
  "typescript": "^5.9.3",
86
86
  "vitest": "^1.6.1",
87
87
  "zen-fs-cache": "^1.0.6",
88
- "zen-fs-sync": "^0.4.17"
88
+ "zen-fs-sync": "^0.4.18"
89
89
  }
90
90
  }