zen-fs-config 0.4.2 → 0.4.4
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 +25 -11
- package/dist/index.mjs +25 -11
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1089,27 +1089,39 @@ var ConfigRepo = class {
|
|
|
1089
1089
|
async readAllBackendDescriptors() {
|
|
1090
1090
|
try {
|
|
1091
1091
|
const entries = await this.cachedFS.readdir(BACKENDS_DIR);
|
|
1092
|
-
const
|
|
1092
|
+
const items = [];
|
|
1093
1093
|
for (const entry of entries) {
|
|
1094
1094
|
if (!entry.endsWith(".json")) continue;
|
|
1095
|
+
const filePath = `${BACKENDS_DIR}/${entry}`;
|
|
1095
1096
|
try {
|
|
1096
|
-
const raw = await this.cachedFS.readFile(
|
|
1097
|
+
const raw = await this.cachedFS.readFile(filePath);
|
|
1097
1098
|
const desc = JSON.parse(new TextDecoder().decode(toUint8Array(raw)));
|
|
1098
1099
|
if (desc.id && desc.type) {
|
|
1099
|
-
|
|
1100
|
+
let mtime = 0;
|
|
1101
|
+
try {
|
|
1102
|
+
const stat = await this.cachedFS.stat(filePath);
|
|
1103
|
+
mtime = stat.mtimeMs ?? 0;
|
|
1104
|
+
} catch {
|
|
1105
|
+
}
|
|
1106
|
+
items.push({ desc, mtime });
|
|
1100
1107
|
}
|
|
1101
1108
|
} catch {
|
|
1102
1109
|
}
|
|
1103
1110
|
}
|
|
1104
1111
|
const seen = /* @__PURE__ */ new Map();
|
|
1105
1112
|
const duplicates = [];
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
const
|
|
1109
|
-
if (
|
|
1110
|
-
|
|
1113
|
+
for (const item of items) {
|
|
1114
|
+
const key = `${item.desc.type}:${JSON.stringify(item.desc.options ?? {})}`;
|
|
1115
|
+
const existing = seen.get(key);
|
|
1116
|
+
if (existing) {
|
|
1117
|
+
if (item.mtime < existing.mtime) {
|
|
1118
|
+
duplicates.push(existing.desc.id);
|
|
1119
|
+
seen.set(key, item);
|
|
1120
|
+
} else {
|
|
1121
|
+
duplicates.push(item.desc.id);
|
|
1122
|
+
}
|
|
1111
1123
|
} else {
|
|
1112
|
-
seen.set(key,
|
|
1124
|
+
seen.set(key, item);
|
|
1113
1125
|
}
|
|
1114
1126
|
}
|
|
1115
1127
|
if (duplicates.length > 0) {
|
|
@@ -1120,7 +1132,7 @@ var ConfigRepo = class {
|
|
|
1120
1132
|
await this.removeBackendDescriptor(dupId);
|
|
1121
1133
|
}
|
|
1122
1134
|
}
|
|
1123
|
-
return
|
|
1135
|
+
return Array.from(seen.values()).map((i) => i.desc);
|
|
1124
1136
|
} catch {
|
|
1125
1137
|
return [];
|
|
1126
1138
|
}
|
|
@@ -1332,8 +1344,10 @@ async function createConfigRepo(appId, options = {}) {
|
|
|
1332
1344
|
options.onConflict
|
|
1333
1345
|
);
|
|
1334
1346
|
await repo.setupSync(allBackends, LOCAL_IDB_BACKEND_ID);
|
|
1335
|
-
await repo.syncMetaToReplicas();
|
|
1336
1347
|
await repo.load();
|
|
1348
|
+
repo.syncMetaToReplicas().catch((err) => {
|
|
1349
|
+
console.error("[createConfigRepo] background syncMetaToReplicas failed:", err);
|
|
1350
|
+
});
|
|
1337
1351
|
return repo;
|
|
1338
1352
|
}
|
|
1339
1353
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.mjs
CHANGED
|
@@ -1037,27 +1037,39 @@ var ConfigRepo = class {
|
|
|
1037
1037
|
async readAllBackendDescriptors() {
|
|
1038
1038
|
try {
|
|
1039
1039
|
const entries = await this.cachedFS.readdir(BACKENDS_DIR);
|
|
1040
|
-
const
|
|
1040
|
+
const items = [];
|
|
1041
1041
|
for (const entry of entries) {
|
|
1042
1042
|
if (!entry.endsWith(".json")) continue;
|
|
1043
|
+
const filePath = `${BACKENDS_DIR}/${entry}`;
|
|
1043
1044
|
try {
|
|
1044
|
-
const raw = await this.cachedFS.readFile(
|
|
1045
|
+
const raw = await this.cachedFS.readFile(filePath);
|
|
1045
1046
|
const desc = JSON.parse(new TextDecoder().decode(toUint8Array(raw)));
|
|
1046
1047
|
if (desc.id && desc.type) {
|
|
1047
|
-
|
|
1048
|
+
let mtime = 0;
|
|
1049
|
+
try {
|
|
1050
|
+
const stat = await this.cachedFS.stat(filePath);
|
|
1051
|
+
mtime = stat.mtimeMs ?? 0;
|
|
1052
|
+
} catch {
|
|
1053
|
+
}
|
|
1054
|
+
items.push({ desc, mtime });
|
|
1048
1055
|
}
|
|
1049
1056
|
} catch {
|
|
1050
1057
|
}
|
|
1051
1058
|
}
|
|
1052
1059
|
const seen = /* @__PURE__ */ new Map();
|
|
1053
1060
|
const duplicates = [];
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
const
|
|
1057
|
-
if (
|
|
1058
|
-
|
|
1061
|
+
for (const item of items) {
|
|
1062
|
+
const key = `${item.desc.type}:${JSON.stringify(item.desc.options ?? {})}`;
|
|
1063
|
+
const existing = seen.get(key);
|
|
1064
|
+
if (existing) {
|
|
1065
|
+
if (item.mtime < existing.mtime) {
|
|
1066
|
+
duplicates.push(existing.desc.id);
|
|
1067
|
+
seen.set(key, item);
|
|
1068
|
+
} else {
|
|
1069
|
+
duplicates.push(item.desc.id);
|
|
1070
|
+
}
|
|
1059
1071
|
} else {
|
|
1060
|
-
seen.set(key,
|
|
1072
|
+
seen.set(key, item);
|
|
1061
1073
|
}
|
|
1062
1074
|
}
|
|
1063
1075
|
if (duplicates.length > 0) {
|
|
@@ -1068,7 +1080,7 @@ var ConfigRepo = class {
|
|
|
1068
1080
|
await this.removeBackendDescriptor(dupId);
|
|
1069
1081
|
}
|
|
1070
1082
|
}
|
|
1071
|
-
return
|
|
1083
|
+
return Array.from(seen.values()).map((i) => i.desc);
|
|
1072
1084
|
} catch {
|
|
1073
1085
|
return [];
|
|
1074
1086
|
}
|
|
@@ -1280,8 +1292,10 @@ async function createConfigRepo(appId, options = {}) {
|
|
|
1280
1292
|
options.onConflict
|
|
1281
1293
|
);
|
|
1282
1294
|
await repo.setupSync(allBackends, LOCAL_IDB_BACKEND_ID);
|
|
1283
|
-
await repo.syncMetaToReplicas();
|
|
1284
1295
|
await repo.load();
|
|
1296
|
+
repo.syncMetaToReplicas().catch((err) => {
|
|
1297
|
+
console.error("[createConfigRepo] background syncMetaToReplicas failed:", err);
|
|
1298
|
+
});
|
|
1285
1299
|
return repo;
|
|
1286
1300
|
}
|
|
1287
1301
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zen-fs-config",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
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",
|
|
@@ -61,6 +61,6 @@
|
|
|
61
61
|
"typescript": "^5.9.3",
|
|
62
62
|
"vitest": "^1.6.1",
|
|
63
63
|
"zen-fs-cache": "^1.0.1",
|
|
64
|
-
"zen-fs-sync": "^0.
|
|
64
|
+
"zen-fs-sync": "^0.4.1"
|
|
65
65
|
}
|
|
66
66
|
}
|