@jr2804/livesync-cli 1.0.30-cli.1 → 1.0.32-cli.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.
Files changed (2) hide show
  1. package/dist/index.cjs +96 -53
  2. package/package.json +2 -2
package/dist/index.cjs CHANGED
@@ -6222,6 +6222,9 @@ var globalConcurrencyController = Semaphore(50);
6222
6222
  function determineTypeFromBlob(data) {
6223
6223
  return isTextBlob$1(data) ? "plain" : "newnote";
6224
6224
  }
6225
+ function isRemediationModeActive(settings) {
6226
+ return (settings.maxMTimeForReflectEvents ?? 0) > 0;
6227
+ }
6225
6228
  function isAnyNote(doc) {
6226
6229
  return "type" in doc && (doc.type == "newnote" || doc.type == "plain");
6227
6230
  }
@@ -6333,34 +6336,24 @@ function isValidFilenameInWidows(filename) {
6333
6336
  if (/(\\|\/)(COM\d|LPT\d|CON|PRN|AUX|NUL|CLOCK$)($|\.)/gi.test(filename)) return false;
6334
6337
  return true;
6335
6338
  }
6336
- function isFilePath(path) {
6337
- if (path.indexOf(":") === -1) return true;
6338
- return false;
6339
- }
6340
6339
  function stripAllPrefixes(prefixedPath) {
6341
- if (isFilePath(prefixedPath)) return prefixedPath;
6342
- const [, body] = expandFilePathPrefix(prefixedPath);
6343
- return stripAllPrefixes(body);
6340
+ return stripPrefix(prefixedPath);
6344
6341
  }
6345
6342
  function addPrefix(path, prefix) {
6346
6343
  if (prefix && path.startsWith(prefix)) return path;
6347
6344
  return `${prefix ?? ""}${path}`;
6348
6345
  }
6349
6346
  function expandFilePathPrefix(path) {
6350
- let [prefix, body] = path.split(":", 2);
6351
- if (!body) {
6352
- body = prefix;
6353
- prefix = "";
6354
- } else prefix = prefix + ":";
6355
- return [prefix, body];
6347
+ for (const prefix of [
6348
+ "i:",
6349
+ "ix:",
6350
+ "ps:"
6351
+ ]) if (path.startsWith(prefix)) return [prefix, path.substring(prefix.length)];
6352
+ return ["", path];
6356
6353
  }
6357
6354
  function expandDocumentIDPrefix(id) {
6358
- let [prefix, body] = id.split(":", 2);
6359
- if (!body) {
6360
- body = prefix;
6361
- prefix = "";
6362
- } else prefix = prefix + ":";
6363
- return [prefix, body];
6355
+ for (const prefix of ["h:", "f:"]) if (id.startsWith(prefix)) return [prefix, id.substring(prefix.length)];
6356
+ return expandFilePathPrefix(id);
6364
6357
  }
6365
6358
  var _hashString = memorizeFuncWithLRUCache(async (key) => {
6366
6359
  const buff = writeString(key);
@@ -6394,6 +6387,9 @@ function id2path_base(id, entry) {
6394
6387
  function getPath(entry) {
6395
6388
  return id2path_base(entry._id, entry);
6396
6389
  }
6390
+ function stripPrefix(prefixedPath) {
6391
+ return expandFilePathPrefix(prefixedPath)[1];
6392
+ }
6397
6393
  function shouldBeIgnored(filename) {
6398
6394
  if (filename == FLAGMD_REDFLAG) return true;
6399
6395
  if (filename == FLAGMD_REDFLAG2) return true;
@@ -6515,18 +6511,12 @@ var PathService = class extends ServiceBase {
6515
6511
  this.getPathObfuscationPassphrase = dependencies.getPathObfuscationPassphrase;
6516
6512
  }
6517
6513
  _id2path(id, entry) {
6518
- const temp = id2path_base(id, entry).split(":");
6519
- const path = temp.pop();
6520
- const normalizedPath = this.normalizePath(path);
6521
- temp.push(normalizedPath);
6522
- return temp.join(":");
6514
+ const [prefix, path] = expandFilePathPrefix(id2path_base(id, entry));
6515
+ return prefix + this.normalizePath(path);
6523
6516
  }
6524
6517
  async _path2id(filename, obfuscatePassphrase, caseInsensitive) {
6525
- const temp = filename.split(":");
6526
- const path = temp.pop();
6527
- const normalizedPath = this.normalizePath(path);
6528
- temp.push(normalizedPath);
6529
- return await path2id_base(temp.join(":"), obfuscatePassphrase, caseInsensitive);
6518
+ const [prefix, path] = expandFilePathPrefix(filename);
6519
+ return await path2id_base(prefix + this.normalizePath(path), obfuscatePassphrase, caseInsensitive);
6530
6520
  }
6531
6521
  /**
6532
6522
  * Convert a document ID or entry to a virtual file path.
@@ -11101,19 +11091,19 @@ async function outgoingDecryptHKDF(doc, migrationDecrypt, decrypted, passphrase,
11101
11091
  Logger(ex);
11102
11092
  throw ex;
11103
11093
  }
11104
- if (isObfuscatedEntry(loadDoc)) {
11094
+ if (isObfuscatedEntry(loadDoc)) if (isEncryptedMeta(loadDoc)) {
11095
+ const pbkdf2salt = await getPBKDF2Salt();
11096
+ try {
11097
+ const metadata = await decryptMetaWithHKDF(loadDoc.path, passphrase, pbkdf2salt);
11098
+ for (const key of Object.keys(metadata)) loadDoc[key] = metadata[key];
11099
+ } catch (ex) {
11100
+ Logger(`${DECRYPTION_HKDF_FAILED} on Path`, 64);
11101
+ Logger(ex);
11102
+ throw ex;
11103
+ }
11104
+ } else {
11105
11105
  const path = getPath(loadDoc);
11106
- if (isEncryptedMeta(loadDoc)) {
11107
- const pbkdf2salt = await getPBKDF2Salt();
11108
- try {
11109
- const metadata = await decryptMetaWithHKDF(path, passphrase, pbkdf2salt);
11110
- for (const key of Object.keys(metadata)) loadDoc[key] = metadata[key];
11111
- } catch (ex) {
11112
- Logger(`${DECRYPTION_HKDF_FAILED} on Path`, 64);
11113
- Logger(ex);
11114
- throw ex;
11115
- }
11116
- } else if (isPathProbablyObfuscated(path)) {
11106
+ if (isPathProbablyObfuscated(path)) {
11117
11107
  const decryptedPath = await tryDecryptV1AsFallback(path, passphrase, useDynamicIterationCount);
11118
11108
  if (decryptedPath === false) {
11119
11109
  Logger(`${MESSAGE_FALLBACK_DECRYPT_FAILED} on Path`, 64);
@@ -11891,10 +11881,10 @@ var HeadlessAPIService = class extends InjectableAPIService {
11891
11881
  return "headless-app";
11892
11882
  }
11893
11883
  getAppVersion() {
11894
- return `1.0.30`;
11884
+ return `1.0.32`;
11895
11885
  }
11896
11886
  getPluginVersion() {
11897
- return `1.0.30`;
11887
+ return `1.0.32`;
11898
11888
  }
11899
11889
  getPlatform() {
11900
11890
  return "server";
@@ -16237,7 +16227,7 @@ function isTargetFile(host, filenameSrc) {
16237
16227
  const file = filenameSrc.startsWith("i:") ? filenameSrc.substring(2) : filenameSrc;
16238
16228
  if (file.startsWith("ix:")) return true;
16239
16229
  if (file.startsWith("ps:")) return true;
16240
- if (file.includes(":")) return false;
16230
+ if (file.startsWith(IDPrefixes.Chunk) || file.startsWith(IDPrefixes.Obfuscated)) return false;
16241
16231
  if (!settings.syncInternalFiles) {
16242
16232
  if (file.startsWith(".")) return false;
16243
16233
  }
@@ -34769,8 +34759,8 @@ var ModuleResolvingMismatchedTweaks = class extends AbstractModule {
34769
34759
  };
34770
34760
  //#endregion
34771
34761
  //#region ../../../node_modules/@vrtmrz/livesync-commonlib/dist/common/coreEnvVars.js
34772
- var manifestVersion = "1.0.30";
34773
- var packageVersion = "1.0.30";
34762
+ var manifestVersion = "1.0.32";
34763
+ var packageVersion = "1.0.32";
34774
34764
  //#endregion
34775
34765
  //#region ../../../node_modules/octagonal-wheels/dist/iterable/map.js
34776
34766
  /**
@@ -34948,6 +34938,7 @@ async function syncFileBetweenDBandStorage(host, log, file, doc) {
34948
34938
  return FilePairProcessResults.SKIPPED;
34949
34939
  }
34950
34940
  case EVEN:
34941
+ if (doc._rev) await host.serviceModules.fileHandler.tryRecordUntrackedFileRevision(file, doc._rev);
34951
34942
  log("STORAGE == DB :" + file.path, -1);
34952
34943
  return FilePairProcessResults.COMPLETED;
34953
34944
  default:
@@ -34970,7 +34961,7 @@ function canProceedScan(host, errorManager, log, showingNotice = false, ignoreSu
34970
34961
  }
34971
34962
  errorManager.clearError(ERR_SUSPENDING);
34972
34963
  const MSG_IN_REMEDIATION = `Started in remediation Mode! (Max mtime for reflect events is set). Synchronising between the storage and the local database is now prevented.`;
34973
- if (settings.maxMTimeForReflectEvents > 0) {
34964
+ if (isRemediationModeActive(settings)) {
34974
34965
  errorManager.showError(MSG_IN_REMEDIATION, 64);
34975
34966
  return false;
34976
34967
  }
@@ -57784,8 +57775,21 @@ var ReplicateResultProcessor = class {
57784
57775
  this.updateProcessingActivity();
57785
57776
  fireAndForget(() => this.runProcessQueue());
57786
57777
  }
57778
+ /**
57779
+ * Whether the application accepts replicated documents being applied.
57780
+ *
57781
+ * Remediation mode refuses the reconciliation scan which readiness depends upon, so the
57782
+ * application stays unready for as long as the modification-time limit is configured.
57783
+ * Applying the received documents is what that mode exists for, and `parseDocumentChange` keeps
57784
+ * each one within the limit, so readiness is not required while the mode is active.
57785
+ */
57786
+ get acceptsResultApplication() {
57787
+ if (this.services.appLifecycle.isReady()) return true;
57788
+ if (this.context.currentSettings().maxMTimeForReflectEvents <= 0) return false;
57789
+ return this.services.database.isDatabaseReady();
57790
+ }
57787
57791
  get isSuspended() {
57788
- return this._suspended || !this.services.appLifecycle.isReady() || this.context.currentSettings().suspendParseReplicationResult || this.services.appLifecycle.isSuspended();
57792
+ return this._suspended || !this.acceptsResultApplication || this.context.currentSettings().suspendParseReplicationResult || this.services.appLifecycle.isSuspended();
57789
57793
  }
57790
57794
  /**
57791
57795
  * Take a snapshot of the current processing state.
@@ -58132,6 +58136,7 @@ function useReplicationFeature(core) {
58132
58136
  runLocalApplicationActivity: async (task, options) => localApplicationActivityOwner ? await localApplicationActivityOwner.runBoundedLocalApplicationActivity(task, options) : await task(),
58133
58137
  services: {
58134
58138
  appLifecycle: services.appLifecycle,
58139
+ database: services.database,
58135
58140
  path: services.path,
58136
58141
  replication: services.replication,
58137
58142
  vault: services.vault
@@ -59322,6 +59327,10 @@ Please enable them from the settings screen after setup is complete.`, ["OK"]);
59322
59327
  await this.informOptionalFeatures();
59323
59328
  }
59324
59329
  async performRebuildEverything() {
59330
+ if (isRemediationModeActive(this.setting.currentSettings())) {
59331
+ this._log(`Rebuilding has been refused: remediation mode is active. Clear the modification-time limit to rebuild.`, 64);
59332
+ throw new Error("Rebuilding is not available while remediation mode is active. Clear the modification-time limit first.");
59333
+ }
59325
59334
  this.appLifecycle.resetIsReady();
59326
59335
  await this.setting.suspendExtraSync();
59327
59336
  await this.setting.applyPartial({
@@ -59443,7 +59452,7 @@ Please enable them from the settings screen after setup is complete.`, ["OK"]);
59443
59452
  suspendParseReplicationResult: false,
59444
59453
  suspendFileWatching: false
59445
59454
  });
59446
- if (!await this.vault.scanVault(true)) return false;
59455
+ if (!isRemediationModeActive(this.setting.currentSettings()) && !await this.vault.scanVault(true)) return false;
59447
59456
  if (!await this.replication.onBeforeReplicate(false)) return false;
59448
59457
  return true;
59449
59458
  }
@@ -59467,7 +59476,7 @@ Please enable them from the settings screen after setup is complete.`, ["OK"]);
59467
59476
  notifyThresholdOfRemoteStorageSize: DEFAULT_SETTINGS.notifyThresholdOfRemoteStorageSize
59468
59477
  });
59469
59478
  const settings = this.setting.currentSettings();
59470
- if (settings.maxMTimeForReflectEvents > 0) {
59479
+ if (isRemediationModeActive(settings)) {
59471
59480
  const ask = `Your settings restrict file reflection times to no later than ${new Date(settings.maxMTimeForReflectEvents).toLocaleString()}.
59472
59481
 
59473
59482
  **This is a recovery configuration.**
@@ -59502,7 +59511,8 @@ Are you sure you wish to proceed?`;
59502
59511
  await this.resetLocalDatabase();
59503
59512
  this.clearFastFetchCheckpoint();
59504
59513
  await delay$1(1e3);
59505
- if (makeLocalChunkBeforeSync) await this.fileHandler.createAllChunks(true);
59514
+ if (isRemediationModeActive(this.setting.currentSettings())) this._log(`Remediation mode: the files in storage are not stored in the database before fetching.`, 64);
59515
+ else if (makeLocalChunkBeforeSync) await this.fileHandler.createAllChunks(true);
59506
59516
  else if (!preventMakeLocalFilesBeforeSync) await this.prepareLocalDatabaseForRebuild();
59507
59517
  await this.replication.markResolved();
59508
59518
  await delay$1(500);
@@ -59615,7 +59625,7 @@ Total bytes fetched: ${sizeToHumanReadable(progress.totalBytes)}`, 64, "fetch-in
59615
59625
  if (!await this.resumeReflectingDatabase(ignoreMinIO)) return false;
59616
59626
  if (!await this.fileProcessing.commitPendingFileEvents()) return false;
59617
59627
  if (controlsReflection) await this.setting.saveSettingData();
59618
- this.appLifecycle.markIsReady();
59628
+ if (!isRemediationModeActive(this.setting.currentSettings())) this.appLifecycle.markIsReady();
59619
59629
  completed = true;
59620
59630
  return true;
59621
59631
  } finally {
@@ -59862,6 +59872,39 @@ var ServiceFileHandlerBase = class extends ServiceModuleBase {
59862
59872
  if (!readFile) throw new Error(`File ${file.path} is not exist on the storage`);
59863
59873
  return readFile;
59864
59874
  }
59875
+ async tryRecordUntrackedFileRevision(info, expectedRevision) {
59876
+ if (!this.fileReflectionProvenance || !expectedRevision) return false;
59877
+ const path = getStoragePathFromUXFileInfo(info);
59878
+ try {
59879
+ return await this.serializedByFileEventPaths([path], async () => {
59880
+ const provenance = this.fileReflectionProvenance;
59881
+ if (await provenance.get(path)) return false;
59882
+ const stub = await this.storage.getStub(path);
59883
+ if (!stub || isFolderInfo(stub) || stub.path !== path) return false;
59884
+ const file = await this.readFileFromStub(stub);
59885
+ const current = await this.db.fetchEntryMeta(path, void 0, true);
59886
+ if (!current || current._rev !== expectedRevision || current.deleted || current._deleted) return false;
59887
+ if ((await this.db.getConflictedRevs(path)).length > 0) return false;
59888
+ const entry = await this.db.fetchEntry(path, expectedRevision, true, true, true);
59889
+ if (!entry || entry._rev !== expectedRevision || entry.deleted || entry._deleted) return false;
59890
+ if (!await isDocContentSame(readContent(entry), file.body)) return false;
59891
+ const latest = await this.db.fetchEntryMeta(path, void 0, true);
59892
+ if (!latest || latest._rev !== expectedRevision || latest.deleted || latest._deleted) return false;
59893
+ if ((await this.db.getConflictedRevs(path)).length > 0) return false;
59894
+ if (!await this.currentStorageSnapshotMatches(file, void 0)) return false;
59895
+ if (await provenance.get(path)) return false;
59896
+ await provenance.set(path, {
59897
+ revision: expectedRevision,
59898
+ observedStorageMtime: file.stat.mtime
59899
+ });
59900
+ return true;
59901
+ });
59902
+ } catch (ex) {
59903
+ this._log(`Could not record unchanged file provenance for ${path}`, 16);
59904
+ this._log(ex, 16);
59905
+ return false;
59906
+ }
59907
+ }
59865
59908
  async infoToStub(info) {
59866
59909
  if (info == null) return null;
59867
59910
  return typeof info === "string" ? await this.storage.getFileStub(info) : info;
@@ -61977,7 +62020,7 @@ var StorageEventManagerBase = class extends StorageEventManager {
61977
62020
  const settings = this.settings;
61978
62021
  if (!settings.isConfigured) return;
61979
62022
  if (settings.suspendFileWatching) return;
61980
- if (settings.maxMTimeForReflectEvents > 0) return;
62023
+ if (isRemediationModeActive(settings)) return;
61981
62024
  this.fileProcessing.onStorageFileEvent();
61982
62025
  for (const param of params) {
61983
62026
  const atomicKey = [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jr2804/livesync-cli",
3
- "version": "1.0.30-cli.1",
4
- "description": "SEA-packaged livesync-cli from vrtmrz/obsidian-livesync — multiplatform binaries + npm",
3
+ "version": "1.0.32-cli.1",
4
+ "description": "SEA-packaged livesync-cli from vrtmrz/obsidian-livesync \u2014 multiplatform binaries + npm",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "livesync-cli": "./bin/livesync-cli.cjs"