obsidian-sync-mcp 0.12.0 → 0.13.0

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.
@@ -9,13 +9,15 @@ import {
9
9
  AttachmentExistsError,
10
10
  AttachmentMoveIncompleteError,
11
11
  AttachmentTooLargeError,
12
+ NoteExistsError,
13
+ NoteNotFoundError,
12
14
  __reExport,
13
15
  isValidAttachmentPath,
14
16
  isValidNotePath,
15
17
  parseFrontmatterAndLinks,
16
18
  validateAttachmentPath,
17
19
  validateNotePath
18
- } from "./chunk-XZ4HUASL.js";
20
+ } from "./chunk-IQ2E4UFT.js";
19
21
 
20
22
  // lib/livesync-commonlib/src/API/DirectFileManipulatorV2.ts
21
23
  import { MemoryValueStore } from "@vrtmrz/value-store";
@@ -13279,10 +13281,16 @@ function idDerivationOptions(obfuscatePaths, idDerivationKey) {
13279
13281
  }
13280
13282
 
13281
13283
  // src/id-format.ts
13284
+ var ID_SAMPLE_TARGET = 100;
13285
+ var NAMESPACE_PREFIXES = ["i:", "ix:", "ps:"];
13286
+ function isNamespacedId(id) {
13287
+ return NAMESPACE_PREFIXES.some((p) => id.startsWith(p));
13288
+ }
13282
13289
  function classifyIds(ids) {
13283
13290
  let obfuscated = 0;
13284
13291
  let plain = 0;
13285
13292
  for (const id of ids) {
13293
+ if (isNamespacedId(id)) continue;
13286
13294
  if (id.startsWith("f:")) obfuscated++;
13287
13295
  else plain++;
13288
13296
  }
@@ -13355,8 +13363,8 @@ var Vault = class _Vault {
13355
13363
  // (`nfc-path-identity-v1`, the default for databases created by LiveSync
13356
13364
  // 1.0.49+). Detected in init(); the library rejects a mismatch.
13357
13365
  pathNormalizationVersion = 0;
13358
- // Serializes attachment writes per document id (see writeAttachmentUnlocked).
13359
- attachmentLock = new KeyedLock();
13366
+ /** Per-document lock: makes an existence check and the write after it one step (see writeNoteUnlocked). */
13367
+ docLock = new KeyedLock();
13360
13368
  constructor(config) {
13361
13369
  this.config = config;
13362
13370
  this.passphrase = config.passphrase;
@@ -13448,7 +13456,7 @@ var Vault = class _Vault {
13448
13456
  */
13449
13457
  async reconcileObfuscation() {
13450
13458
  const configured = !!this.config.obfuscatePaths;
13451
- const format = await this.detectIdFormat();
13459
+ const format = classifyIds(await this.sampleNoteIds());
13452
13460
  if (format === "empty") return;
13453
13461
  if (format === "mixed") {
13454
13462
  console.warn(
@@ -13471,14 +13479,17 @@ var Vault = class _Vault {
13471
13479
  this.manipulator = new DirectFileManipulator(this.options(actual));
13472
13480
  await this.awaitManipulatorReady();
13473
13481
  }
13474
- /** Sample file-entry docs from the changes feed and classify their IDs. */
13475
- async detectIdFormat() {
13476
- const SAMPLE_TARGET = 20;
13482
+ /**
13483
+ * Sample note-document IDs from the changes feed, oldest first. Namespaced
13484
+ * file documents (`i:`, `ix:`, `ps:`) are skipped: their prefix hides the ID
13485
+ * format (#62).
13486
+ */
13487
+ async sampleNoteIds() {
13477
13488
  const BATCH_SIZE2 = 100;
13478
13489
  const db = this.manipulator.liveSyncLocalDB.localDatabase;
13479
13490
  const ids = [];
13480
13491
  let since = 0;
13481
- while (ids.length < SAMPLE_TARGET) {
13492
+ while (ids.length < ID_SAMPLE_TARGET) {
13482
13493
  const result = await db.changes({
13483
13494
  since,
13484
13495
  limit: BATCH_SIZE2,
@@ -13487,13 +13498,13 @@ var Vault = class _Vault {
13487
13498
  live: false
13488
13499
  });
13489
13500
  for (const change of result.results) {
13490
- if (ids.length >= SAMPLE_TARGET) break;
13491
- ids.push(change.id);
13501
+ if (ids.length >= ID_SAMPLE_TARGET) break;
13502
+ if (!isNamespacedId(change.id)) ids.push(change.id);
13492
13503
  }
13493
13504
  if (result.results.length < BATCH_SIZE2) break;
13494
13505
  since = result.last_seq;
13495
13506
  }
13496
- return classifyIds(ids);
13507
+ return ids;
13497
13508
  }
13498
13509
  async close() {
13499
13510
  await _Vault.closeManipulator(this.manipulator);
@@ -13614,11 +13625,23 @@ var Vault = class _Vault {
13614
13625
  }
13615
13626
  return null;
13616
13627
  }
13617
- async writeNote(path, content) {
13628
+ async writeNote(path, content, options = {}) {
13618
13629
  this.validatePath(path);
13630
+ const id = await this.manipulator.path2id(path);
13631
+ return await this.docLock.run([id], () => this.writeNoteUnlocked(path, content, options));
13632
+ }
13633
+ /**
13634
+ * As with attachments, the library's put can't be made conditional, so the
13635
+ * create/update checks rely on the caller holding the document's lock. That
13636
+ * covers writes made by this server; a concurrent write from Obsidian is
13637
+ * left to LiveSync's conflict handling.
13638
+ */
13639
+ async writeNoteUnlocked(path, content, { mode = "upsert" }) {
13619
13640
  clearHandlers();
13620
13641
  let ctime = Date.now();
13621
13642
  const existing = await this.manipulator.get(path, true);
13643
+ if (existing && mode === "create") throw new NoteExistsError(path);
13644
+ if (!existing && mode === "update") throw new NoteNotFoundError(path);
13622
13645
  if (existing && "ctime" in existing) {
13623
13646
  ctime = existing.ctime;
13624
13647
  }
@@ -13631,20 +13654,27 @@ var Vault = class _Vault {
13631
13654
  }
13632
13655
  async deleteNote(path) {
13633
13656
  this.validatePath(path);
13634
- clearHandlers();
13635
- return await this.manipulator.delete(path);
13657
+ const id = await this.manipulator.path2id(path);
13658
+ return await this.docLock.run([id], async () => {
13659
+ clearHandlers();
13660
+ return await this.manipulator.delete(path);
13661
+ });
13636
13662
  }
13637
13663
  async moveNote(from, to) {
13638
13664
  this.validatePath(from);
13639
13665
  this.validatePath(to);
13640
- const content = await this.readNote(from);
13641
- if (content === null) return false;
13642
- if (from === to) return true;
13643
- const wrote = await this.writeNote(to, content);
13644
- if (!wrote) return false;
13645
13666
  const fromId = await this.manipulator.path2id(from);
13646
- if (fromId === await this.manipulator.path2id(to)) return true;
13647
- return await this.deleteNote(from);
13667
+ const toId = await this.manipulator.path2id(to);
13668
+ return await this.docLock.run([fromId, toId], async () => {
13669
+ const content = await this.readNote(from);
13670
+ if (content === null) return false;
13671
+ if (from === to) return true;
13672
+ if (fromId === toId) return await this.writeNoteUnlocked(to, content, { mode: "upsert" });
13673
+ const wrote = await this.writeNoteUnlocked(to, content, { mode: "create" });
13674
+ if (!wrote) return false;
13675
+ clearHandlers();
13676
+ return await this.manipulator.delete(from);
13677
+ });
13648
13678
  }
13649
13679
  async getMetadata(path) {
13650
13680
  this.validatePath(path);
@@ -13679,7 +13709,7 @@ var Vault = class _Vault {
13679
13709
  async writeAttachment(path, data, options = {}) {
13680
13710
  validateAttachmentPath(path);
13681
13711
  const id = await this.manipulator.path2id(path);
13682
- return await this.attachmentLock.run([id], () => this.writeAttachmentUnlocked(path, data, options));
13712
+ return await this.docLock.run([id], () => this.writeAttachmentUnlocked(path, data, options));
13683
13713
  }
13684
13714
  /**
13685
13715
  * The library's put always writes over the current revision, so "create
@@ -13705,7 +13735,7 @@ var Vault = class _Vault {
13705
13735
  async deleteAttachment(path) {
13706
13736
  validateAttachmentPath(path);
13707
13737
  const id = await this.manipulator.path2id(path);
13708
- return await this.attachmentLock.run([id], async () => {
13738
+ return await this.docLock.run([id], async () => {
13709
13739
  clearHandlers();
13710
13740
  return await this.manipulator.delete(path);
13711
13741
  });
@@ -13715,7 +13745,7 @@ var Vault = class _Vault {
13715
13745
  validateAttachmentPath(to);
13716
13746
  const fromId = await this.manipulator.path2id(from);
13717
13747
  const toId = await this.manipulator.path2id(to);
13718
- return await this.attachmentLock.run([fromId, toId], async () => {
13748
+ return await this.docLock.run([fromId, toId], async () => {
13719
13749
  const meta = await this.manipulator.get(from, true);
13720
13750
  if (!meta) return false;
13721
13751
  if (from === to) return true;
@@ -13755,4 +13785,4 @@ var Vault = class _Vault {
13755
13785
  export {
13756
13786
  Vault
13757
13787
  };
13758
- //# sourceMappingURL=vault-XZDTCOVA.js.map
13788
+ //# sourceMappingURL=vault-MLW7WLXO.js.map