zen-fs-config 0.3.5 → 0.3.7
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 +59 -45
- package/dist/index.mjs +59 -45
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1196,10 +1196,14 @@ var ConfigRepo = class {
|
|
|
1196
1196
|
for (const part of parts) {
|
|
1197
1197
|
current += `/${part}`;
|
|
1198
1198
|
const exists = await this.fullFS.exists(current);
|
|
1199
|
+
console.log(`[ensureDir] ${current} exists=${exists}`);
|
|
1199
1200
|
if (!exists) {
|
|
1200
1201
|
try {
|
|
1201
|
-
|
|
1202
|
-
|
|
1202
|
+
console.log(`[ensureDir] mkdir(${current})`);
|
|
1203
|
+
await this.fullFS.mkdir(current);
|
|
1204
|
+
console.log(`[ensureDir] mkdir(${current}) OK`);
|
|
1205
|
+
} catch (err) {
|
|
1206
|
+
console.error(`[ensureDir] mkdir(${current}) FAILED:`, err.message);
|
|
1203
1207
|
}
|
|
1204
1208
|
}
|
|
1205
1209
|
}
|
|
@@ -1230,11 +1234,14 @@ var ConfigRepo = class {
|
|
|
1230
1234
|
return results;
|
|
1231
1235
|
}
|
|
1232
1236
|
async writeMetaFile(path, data) {
|
|
1237
|
+
console.log(`[writeMetaFile] ${path}, ensuring dir...`);
|
|
1233
1238
|
await this.ensureDir(path);
|
|
1239
|
+
console.log(`[writeMetaFile] ${path}, writing ${JSON.stringify(data).length} bytes...`);
|
|
1234
1240
|
await this.cachedFS.writeFile(
|
|
1235
1241
|
path,
|
|
1236
1242
|
new TextEncoder().encode(JSON.stringify(data, null, 2))
|
|
1237
1243
|
);
|
|
1244
|
+
console.log(`[writeMetaFile] ${path} done`);
|
|
1238
1245
|
}
|
|
1239
1246
|
async readMetaFile(path) {
|
|
1240
1247
|
try {
|
|
@@ -1311,24 +1318,27 @@ async function createConfigRepo(appId, options) {
|
|
|
1311
1318
|
void 0
|
|
1312
1319
|
);
|
|
1313
1320
|
let backendsMeta = await tempRepo.readMetaFile(BACKENDS_FILE);
|
|
1314
|
-
if (options.bootstrap) {
|
|
1315
|
-
backendsMeta = {
|
|
1316
|
-
version: 1,
|
|
1317
|
-
backends: options.bootstrap.backends
|
|
1318
|
-
};
|
|
1319
|
-
console.log(`[createConfigRepo] Using bootstrap backends: ${backendsMeta.backends.map((b) => b.id).join(", ")}`);
|
|
1320
|
-
}
|
|
1321
1321
|
if (!backendsMeta) {
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1322
|
+
if (options.bootstrap) {
|
|
1323
|
+
backendsMeta = {
|
|
1324
|
+
version: 1,
|
|
1325
|
+
backends: options.bootstrap.backends
|
|
1326
|
+
};
|
|
1327
|
+
console.log(`[createConfigRepo] First init: using bootstrap backends: ${backendsMeta.backends.map((b) => b.id).join(", ")}`);
|
|
1328
|
+
} else {
|
|
1329
|
+
backendsMeta = {
|
|
1330
|
+
version: 1,
|
|
1331
|
+
backends: [
|
|
1332
|
+
{
|
|
1333
|
+
id: options.primaryBackendId,
|
|
1334
|
+
type: options.backendInfo.type,
|
|
1335
|
+
options: options.backendInfo.options
|
|
1336
|
+
}
|
|
1337
|
+
]
|
|
1338
|
+
};
|
|
1339
|
+
}
|
|
1340
|
+
} else {
|
|
1341
|
+
console.log(`[createConfigRepo] Reconnect: using stored backends: ${backendsMeta.backends.map((b) => b.id).join(", ")}`);
|
|
1332
1342
|
}
|
|
1333
1343
|
const hasPrimary = backendsMeta.backends.some(
|
|
1334
1344
|
(b) => b.id === options.primaryBackendId
|
|
@@ -1342,33 +1352,37 @@ async function createConfigRepo(appId, options) {
|
|
|
1342
1352
|
}
|
|
1343
1353
|
await tempRepo.writeMetaFile(BACKENDS_FILE, backendsMeta);
|
|
1344
1354
|
let syncRulesMeta = await tempRepo.readMetaFile(SYNC_RULES_FILE);
|
|
1345
|
-
if (options.bootstrap) {
|
|
1346
|
-
syncRulesMeta = {
|
|
1347
|
-
version: 1,
|
|
1348
|
-
rules: options.bootstrap.syncRules
|
|
1349
|
-
};
|
|
1350
|
-
console.log(`[createConfigRepo] Using bootstrap syncRules: ${syncRulesMeta.rules.length} rules`);
|
|
1351
|
-
}
|
|
1352
1355
|
if (!syncRulesMeta) {
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1356
|
+
if (options.bootstrap) {
|
|
1357
|
+
syncRulesMeta = {
|
|
1358
|
+
version: 1,
|
|
1359
|
+
rules: options.bootstrap.syncRules
|
|
1360
|
+
};
|
|
1361
|
+
console.log(`[createConfigRepo] First init: using bootstrap syncRules: ${syncRulesMeta.rules.length} rules`);
|
|
1362
|
+
} else {
|
|
1363
|
+
syncRulesMeta = {
|
|
1364
|
+
version: 1,
|
|
1365
|
+
rules: [
|
|
1366
|
+
{
|
|
1367
|
+
prefix: `/${appId}/`,
|
|
1368
|
+
direction: "one-way",
|
|
1369
|
+
conflictStrategy: "source-wins",
|
|
1370
|
+
replicas: backendsMeta.backends.map((b) => b.id)
|
|
1371
|
+
},
|
|
1372
|
+
{
|
|
1373
|
+
prefix: `${SHARED_DIR}/`,
|
|
1374
|
+
direction: "bi-directional",
|
|
1375
|
+
conflictStrategy: "merge",
|
|
1376
|
+
replicas: backendsMeta.backends.map((b) => b.id)
|
|
1377
|
+
},
|
|
1378
|
+
{ prefix: `${NODES_DIR}/`, direction: "none" },
|
|
1379
|
+
{ prefix: `${META_DIR}/`, direction: "none" }
|
|
1380
|
+
]
|
|
1381
|
+
};
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
if (syncRulesMeta) {
|
|
1385
|
+
console.log(`[createConfigRepo] Reconnect: using stored syncRules: ${syncRulesMeta.rules.length} rules`);
|
|
1372
1386
|
}
|
|
1373
1387
|
await tempRepo.writeMetaFile(SYNC_RULES_FILE, syncRulesMeta);
|
|
1374
1388
|
let nodeId = options.nodeId;
|
package/dist/index.mjs
CHANGED
|
@@ -1149,10 +1149,14 @@ var ConfigRepo = class {
|
|
|
1149
1149
|
for (const part of parts) {
|
|
1150
1150
|
current += `/${part}`;
|
|
1151
1151
|
const exists = await this.fullFS.exists(current);
|
|
1152
|
+
console.log(`[ensureDir] ${current} exists=${exists}`);
|
|
1152
1153
|
if (!exists) {
|
|
1153
1154
|
try {
|
|
1154
|
-
|
|
1155
|
-
|
|
1155
|
+
console.log(`[ensureDir] mkdir(${current})`);
|
|
1156
|
+
await this.fullFS.mkdir(current);
|
|
1157
|
+
console.log(`[ensureDir] mkdir(${current}) OK`);
|
|
1158
|
+
} catch (err) {
|
|
1159
|
+
console.error(`[ensureDir] mkdir(${current}) FAILED:`, err.message);
|
|
1156
1160
|
}
|
|
1157
1161
|
}
|
|
1158
1162
|
}
|
|
@@ -1183,11 +1187,14 @@ var ConfigRepo = class {
|
|
|
1183
1187
|
return results;
|
|
1184
1188
|
}
|
|
1185
1189
|
async writeMetaFile(path, data) {
|
|
1190
|
+
console.log(`[writeMetaFile] ${path}, ensuring dir...`);
|
|
1186
1191
|
await this.ensureDir(path);
|
|
1192
|
+
console.log(`[writeMetaFile] ${path}, writing ${JSON.stringify(data).length} bytes...`);
|
|
1187
1193
|
await this.cachedFS.writeFile(
|
|
1188
1194
|
path,
|
|
1189
1195
|
new TextEncoder().encode(JSON.stringify(data, null, 2))
|
|
1190
1196
|
);
|
|
1197
|
+
console.log(`[writeMetaFile] ${path} done`);
|
|
1191
1198
|
}
|
|
1192
1199
|
async readMetaFile(path) {
|
|
1193
1200
|
try {
|
|
@@ -1264,24 +1271,27 @@ async function createConfigRepo(appId, options) {
|
|
|
1264
1271
|
void 0
|
|
1265
1272
|
);
|
|
1266
1273
|
let backendsMeta = await tempRepo.readMetaFile(BACKENDS_FILE);
|
|
1267
|
-
if (options.bootstrap) {
|
|
1268
|
-
backendsMeta = {
|
|
1269
|
-
version: 1,
|
|
1270
|
-
backends: options.bootstrap.backends
|
|
1271
|
-
};
|
|
1272
|
-
console.log(`[createConfigRepo] Using bootstrap backends: ${backendsMeta.backends.map((b) => b.id).join(", ")}`);
|
|
1273
|
-
}
|
|
1274
1274
|
if (!backendsMeta) {
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1275
|
+
if (options.bootstrap) {
|
|
1276
|
+
backendsMeta = {
|
|
1277
|
+
version: 1,
|
|
1278
|
+
backends: options.bootstrap.backends
|
|
1279
|
+
};
|
|
1280
|
+
console.log(`[createConfigRepo] First init: using bootstrap backends: ${backendsMeta.backends.map((b) => b.id).join(", ")}`);
|
|
1281
|
+
} else {
|
|
1282
|
+
backendsMeta = {
|
|
1283
|
+
version: 1,
|
|
1284
|
+
backends: [
|
|
1285
|
+
{
|
|
1286
|
+
id: options.primaryBackendId,
|
|
1287
|
+
type: options.backendInfo.type,
|
|
1288
|
+
options: options.backendInfo.options
|
|
1289
|
+
}
|
|
1290
|
+
]
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
} else {
|
|
1294
|
+
console.log(`[createConfigRepo] Reconnect: using stored backends: ${backendsMeta.backends.map((b) => b.id).join(", ")}`);
|
|
1285
1295
|
}
|
|
1286
1296
|
const hasPrimary = backendsMeta.backends.some(
|
|
1287
1297
|
(b) => b.id === options.primaryBackendId
|
|
@@ -1295,33 +1305,37 @@ async function createConfigRepo(appId, options) {
|
|
|
1295
1305
|
}
|
|
1296
1306
|
await tempRepo.writeMetaFile(BACKENDS_FILE, backendsMeta);
|
|
1297
1307
|
let syncRulesMeta = await tempRepo.readMetaFile(SYNC_RULES_FILE);
|
|
1298
|
-
if (options.bootstrap) {
|
|
1299
|
-
syncRulesMeta = {
|
|
1300
|
-
version: 1,
|
|
1301
|
-
rules: options.bootstrap.syncRules
|
|
1302
|
-
};
|
|
1303
|
-
console.log(`[createConfigRepo] Using bootstrap syncRules: ${syncRulesMeta.rules.length} rules`);
|
|
1304
|
-
}
|
|
1305
1308
|
if (!syncRulesMeta) {
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1309
|
+
if (options.bootstrap) {
|
|
1310
|
+
syncRulesMeta = {
|
|
1311
|
+
version: 1,
|
|
1312
|
+
rules: options.bootstrap.syncRules
|
|
1313
|
+
};
|
|
1314
|
+
console.log(`[createConfigRepo] First init: using bootstrap syncRules: ${syncRulesMeta.rules.length} rules`);
|
|
1315
|
+
} else {
|
|
1316
|
+
syncRulesMeta = {
|
|
1317
|
+
version: 1,
|
|
1318
|
+
rules: [
|
|
1319
|
+
{
|
|
1320
|
+
prefix: `/${appId}/`,
|
|
1321
|
+
direction: "one-way",
|
|
1322
|
+
conflictStrategy: "source-wins",
|
|
1323
|
+
replicas: backendsMeta.backends.map((b) => b.id)
|
|
1324
|
+
},
|
|
1325
|
+
{
|
|
1326
|
+
prefix: `${SHARED_DIR}/`,
|
|
1327
|
+
direction: "bi-directional",
|
|
1328
|
+
conflictStrategy: "merge",
|
|
1329
|
+
replicas: backendsMeta.backends.map((b) => b.id)
|
|
1330
|
+
},
|
|
1331
|
+
{ prefix: `${NODES_DIR}/`, direction: "none" },
|
|
1332
|
+
{ prefix: `${META_DIR}/`, direction: "none" }
|
|
1333
|
+
]
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
if (syncRulesMeta) {
|
|
1338
|
+
console.log(`[createConfigRepo] Reconnect: using stored syncRules: ${syncRulesMeta.rules.length} rules`);
|
|
1325
1339
|
}
|
|
1326
1340
|
await tempRepo.writeMetaFile(SYNC_RULES_FILE, syncRulesMeta);
|
|
1327
1341
|
let nodeId = options.nodeId;
|