obsidian-sync-mcp 0.5.6 → 0.5.8

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.
@@ -10995,27 +10995,102 @@ var DirectFileManipulator = class {
10995
10995
 
10996
10996
  // src/vault.ts
10997
10997
  import { isPathProbablyObfuscated as isPathProbablyObfuscated2, decrypt as decrypt4 } from "octagonal-wheels/encryption/encryption";
10998
+
10999
+ // src/id-format.ts
11000
+ function classifyIds(ids) {
11001
+ let obfuscated = 0;
11002
+ let plain = 0;
11003
+ for (const id of ids) {
11004
+ if (id.startsWith("f:")) obfuscated++;
11005
+ else plain++;
11006
+ }
11007
+ if (obfuscated === 0 && plain === 0) return "empty";
11008
+ if (obfuscated > 0 && plain > 0) return "mixed";
11009
+ return obfuscated > 0 ? "obfuscated" : "plain";
11010
+ }
11011
+
11012
+ // src/vault.ts
10998
11013
  var Vault = class _Vault {
10999
11014
  manipulator;
11000
11015
  passphrase;
11016
+ config;
11001
11017
  constructor(config) {
11018
+ this.config = config;
11002
11019
  this.passphrase = config.passphrase;
11003
- const opts = {
11020
+ this.manipulator = new DirectFileManipulator(_Vault.buildOptions(config, !!config.obfuscatePaths));
11021
+ }
11022
+ static buildOptions(config, obfuscatePaths) {
11023
+ return {
11004
11024
  url: config.couchdbUrl,
11005
11025
  username: config.couchdbUser,
11006
11026
  password: config.couchdbPassword,
11007
11027
  database: config.database,
11008
11028
  passphrase: config.passphrase,
11009
- obfuscatePassphrase: config.obfuscatePaths ? config.passphrase : void 0,
11029
+ obfuscatePassphrase: obfuscatePaths ? config.passphrase : void 0,
11010
11030
  useEden: false,
11011
11031
  enableCompression: false,
11012
11032
  handleFilenameCaseSensitive: false,
11013
11033
  doNotUseFixedRevisionForChunks: false
11014
11034
  };
11015
- this.manipulator = new DirectFileManipulator(opts);
11016
11035
  }
11017
11036
  async init() {
11018
11037
  await this.manipulator.ready.promise;
11038
+ await this.reconcileObfuscation();
11039
+ }
11040
+ /**
11041
+ * Detect whether the vault's document IDs are obfuscated and, if the
11042
+ * configured COUCHDB_OBFUSCATE_PROPERTIES doesn't match, correct it.
11043
+ * A mismatched setting can never work: path→id resolution misses every
11044
+ * existing note on read, and writes produce docs LiveSync clients ignore
11045
+ * (issues #4, #10). The database is the ground truth.
11046
+ */
11047
+ async reconcileObfuscation() {
11048
+ const configured = !!this.config.obfuscatePaths;
11049
+ const format = await this.detectIdFormat();
11050
+ if (format === "empty") return;
11051
+ if (format === "mixed") {
11052
+ console.warn(
11053
+ `Warning: vault contains both obfuscated and plaintext document IDs. Keeping COUCHDB_OBFUSCATE_PROPERTIES=${configured}. This usually means "Obfuscate properties" was toggled without rebuilding the database \u2014 consider rebuilding it from LiveSync.`
11054
+ );
11055
+ return;
11056
+ }
11057
+ const actual = format === "obfuscated";
11058
+ if (actual === configured) return;
11059
+ if (actual && !this.passphrase) {
11060
+ throw new Error(
11061
+ 'Vault uses obfuscated document IDs (LiveSync "Obfuscate properties"), which requires the E2E passphrase. Set COUCHDB_PASSPHRASE and COUCHDB_OBFUSCATE_PROPERTIES=true.'
11062
+ );
11063
+ }
11064
+ console.warn(
11065
+ actual ? "Warning: vault uses obfuscated document IDs but COUCHDB_OBFUSCATE_PROPERTIES is not set to true. Enabling path obfuscation automatically \u2014 set COUCHDB_OBFUSCATE_PROPERTIES=true to silence this warning." : "Warning: COUCHDB_OBFUSCATE_PROPERTIES=true but vault uses plaintext document IDs. Disabling path obfuscation automatically \u2014 set COUCHDB_OBFUSCATE_PROPERTIES=false to silence this warning."
11066
+ );
11067
+ await this.manipulator.close();
11068
+ this.manipulator = new DirectFileManipulator(_Vault.buildOptions(this.config, actual));
11069
+ await this.manipulator.ready.promise;
11070
+ }
11071
+ /** Sample file-entry docs from the changes feed and classify their IDs. */
11072
+ async detectIdFormat() {
11073
+ const SAMPLE_TARGET = 20;
11074
+ const BATCH_SIZE2 = 100;
11075
+ const db = this.manipulator.liveSyncLocalDB.localDatabase;
11076
+ const ids = [];
11077
+ let since = 0;
11078
+ while (ids.length < SAMPLE_TARGET) {
11079
+ const result = await db.changes({
11080
+ since,
11081
+ limit: BATCH_SIZE2,
11082
+ // Only real file entries — excludes chunks, versioninfo, milestones, sync params.
11083
+ selector: { type: { $in: ["plain", "newnote"] } },
11084
+ live: false
11085
+ });
11086
+ for (const change of result.results) {
11087
+ if (ids.length >= SAMPLE_TARGET) break;
11088
+ ids.push(change.id);
11089
+ }
11090
+ if (result.results.length < BATCH_SIZE2) break;
11091
+ since = result.last_seq;
11092
+ }
11093
+ return classifyIds(ids);
11019
11094
  }
11020
11095
  async close() {
11021
11096
  this.manipulator.endWatch();
@@ -11154,4 +11229,4 @@ var Vault = class _Vault {
11154
11229
  export {
11155
11230
  Vault
11156
11231
  };
11157
- //# sourceMappingURL=vault-BL4NJC75.js.map
11232
+ //# sourceMappingURL=vault-JCVXDVR6.js.map