obsidian-sync-mcp 0.12.1 → 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";
@@ -13361,8 +13363,8 @@ var Vault = class _Vault {
13361
13363
  // (`nfc-path-identity-v1`, the default for databases created by LiveSync
13362
13364
  // 1.0.49+). Detected in init(); the library rejects a mismatch.
13363
13365
  pathNormalizationVersion = 0;
13364
- // Serializes attachment writes per document id (see writeAttachmentUnlocked).
13365
- attachmentLock = new KeyedLock();
13366
+ /** Per-document lock: makes an existence check and the write after it one step (see writeNoteUnlocked). */
13367
+ docLock = new KeyedLock();
13366
13368
  constructor(config) {
13367
13369
  this.config = config;
13368
13370
  this.passphrase = config.passphrase;
@@ -13623,11 +13625,23 @@ var Vault = class _Vault {
13623
13625
  }
13624
13626
  return null;
13625
13627
  }
13626
- async writeNote(path, content) {
13628
+ async writeNote(path, content, options = {}) {
13627
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" }) {
13628
13640
  clearHandlers();
13629
13641
  let ctime = Date.now();
13630
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);
13631
13645
  if (existing && "ctime" in existing) {
13632
13646
  ctime = existing.ctime;
13633
13647
  }
@@ -13640,20 +13654,27 @@ var Vault = class _Vault {
13640
13654
  }
13641
13655
  async deleteNote(path) {
13642
13656
  this.validatePath(path);
13643
- clearHandlers();
13644
- 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
+ });
13645
13662
  }
13646
13663
  async moveNote(from, to) {
13647
13664
  this.validatePath(from);
13648
13665
  this.validatePath(to);
13649
- const content = await this.readNote(from);
13650
- if (content === null) return false;
13651
- if (from === to) return true;
13652
- const wrote = await this.writeNote(to, content);
13653
- if (!wrote) return false;
13654
13666
  const fromId = await this.manipulator.path2id(from);
13655
- if (fromId === await this.manipulator.path2id(to)) return true;
13656
- 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
+ });
13657
13678
  }
13658
13679
  async getMetadata(path) {
13659
13680
  this.validatePath(path);
@@ -13688,7 +13709,7 @@ var Vault = class _Vault {
13688
13709
  async writeAttachment(path, data, options = {}) {
13689
13710
  validateAttachmentPath(path);
13690
13711
  const id = await this.manipulator.path2id(path);
13691
- return await this.attachmentLock.run([id], () => this.writeAttachmentUnlocked(path, data, options));
13712
+ return await this.docLock.run([id], () => this.writeAttachmentUnlocked(path, data, options));
13692
13713
  }
13693
13714
  /**
13694
13715
  * The library's put always writes over the current revision, so "create
@@ -13714,7 +13735,7 @@ var Vault = class _Vault {
13714
13735
  async deleteAttachment(path) {
13715
13736
  validateAttachmentPath(path);
13716
13737
  const id = await this.manipulator.path2id(path);
13717
- return await this.attachmentLock.run([id], async () => {
13738
+ return await this.docLock.run([id], async () => {
13718
13739
  clearHandlers();
13719
13740
  return await this.manipulator.delete(path);
13720
13741
  });
@@ -13724,7 +13745,7 @@ var Vault = class _Vault {
13724
13745
  validateAttachmentPath(to);
13725
13746
  const fromId = await this.manipulator.path2id(from);
13726
13747
  const toId = await this.manipulator.path2id(to);
13727
- return await this.attachmentLock.run([fromId, toId], async () => {
13748
+ return await this.docLock.run([fromId, toId], async () => {
13728
13749
  const meta = await this.manipulator.get(from, true);
13729
13750
  if (!meta) return false;
13730
13751
  if (from === to) return true;
@@ -13764,4 +13785,4 @@ var Vault = class _Vault {
13764
13785
  export {
13765
13786
  Vault
13766
13787
  };
13767
- //# sourceMappingURL=vault-AV7JZZT2.js.map
13788
+ //# sourceMappingURL=vault-MLW7WLXO.js.map