@kamilio/wire 0.1.56 → 0.1.58

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 (124) hide show
  1. package/README.md +44 -1
  2. package/dist/adapters/document-shell.d.ts +7 -0
  3. package/dist/adapters/document-shell.d.ts.map +1 -0
  4. package/dist/adapters/document-shell.js +51 -0
  5. package/dist/adapters/document-shell.js.map +1 -0
  6. package/dist/adapters/root.d.ts.map +1 -1
  7. package/dist/adapters/root.js +69 -4
  8. package/dist/adapters/root.js.map +1 -1
  9. package/dist/cli.d.ts.map +1 -1
  10. package/dist/cli.js +8 -2
  11. package/dist/cli.js.map +1 -1
  12. package/dist/document-shell-engine.mjs +1880 -0
  13. package/dist/executable.js +1 -1
  14. package/dist/executable.js.map +1 -1
  15. package/dist/hooks.d.ts.map +1 -1
  16. package/dist/hooks.js +19 -19
  17. package/dist/hooks.js.map +1 -1
  18. package/node_modules/provider-asana/dist/asana-project.d.ts +8 -1
  19. package/node_modules/provider-asana/dist/asana-project.d.ts.map +1 -1
  20. package/node_modules/provider-asana/dist/asana-task.d.ts +8 -1
  21. package/node_modules/provider-asana/dist/asana-task.d.ts.map +1 -1
  22. package/node_modules/provider-asana/dist/index.d.ts +16 -2
  23. package/node_modules/provider-asana/dist/index.d.ts.map +1 -1
  24. package/node_modules/provider-chatgpt/dist/chatgpt.d.ts +8 -1
  25. package/node_modules/provider-chatgpt/dist/chatgpt.d.ts.map +1 -1
  26. package/node_modules/provider-chatgpt/dist/index.d.ts +8 -1
  27. package/node_modules/provider-chatgpt/dist/index.d.ts.map +1 -1
  28. package/node_modules/provider-gmail/dist/gmail.d.ts +8 -1
  29. package/node_modules/provider-gmail/dist/gmail.d.ts.map +1 -1
  30. package/node_modules/provider-gmail/dist/index.d.ts +8 -1
  31. package/node_modules/provider-gmail/dist/index.d.ts.map +1 -1
  32. package/node_modules/provider-google-docs/dist/doc-blocks.d.ts.map +1 -1
  33. package/node_modules/provider-google-docs/dist/doc-blocks.js +6 -2
  34. package/node_modules/provider-google-docs/dist/doc-blocks.js.map +1 -1
  35. package/node_modules/provider-google-docs/dist/google-docs.d.ts +8 -1
  36. package/node_modules/provider-google-docs/dist/google-docs.d.ts.map +1 -1
  37. package/node_modules/provider-google-docs/dist/google-docs.js +31 -10
  38. package/node_modules/provider-google-docs/dist/google-docs.js.map +1 -1
  39. package/node_modules/provider-google-docs/dist/google-forms.d.ts +8 -1
  40. package/node_modules/provider-google-docs/dist/google-forms.d.ts.map +1 -1
  41. package/node_modules/provider-google-docs/dist/index.d.ts +16 -2
  42. package/node_modules/provider-google-docs/dist/index.d.ts.map +1 -1
  43. package/node_modules/provider-google-docs/src/doc-blocks.ts +8 -2
  44. package/node_modules/provider-google-docs/src/google-docs.ts +26 -10
  45. package/node_modules/provider-lattice/dist/index.d.ts +16 -2
  46. package/node_modules/provider-lattice/dist/index.d.ts.map +1 -1
  47. package/node_modules/provider-notion/dist/index.d.ts +8 -1
  48. package/node_modules/provider-notion/dist/index.d.ts.map +1 -1
  49. package/node_modules/provider-notion/dist/notion-sync.d.ts +2 -2
  50. package/node_modules/provider-notion/dist/notion-sync.d.ts.map +1 -1
  51. package/node_modules/provider-notion/dist/notion-sync.js +24 -15
  52. package/node_modules/provider-notion/dist/notion-sync.js.map +1 -1
  53. package/node_modules/provider-notion/dist/notion.d.ts +8 -1
  54. package/node_modules/provider-notion/dist/notion.d.ts.map +1 -1
  55. package/node_modules/provider-notion/dist/notion.js +1 -1
  56. package/node_modules/provider-notion/dist/notion.js.map +1 -1
  57. package/node_modules/provider-notion/src/notion-sync.ts +23 -15
  58. package/node_modules/provider-notion/src/notion.ts +1 -1
  59. package/node_modules/provider-slack/dist/index.d.ts +8 -1
  60. package/node_modules/provider-slack/dist/index.d.ts.map +1 -1
  61. package/node_modules/provider-slack/dist/slack.d.ts +8 -1
  62. package/node_modules/provider-slack/dist/slack.d.ts.map +1 -1
  63. package/node_modules/provider-zoom/dist/index.d.ts +8 -1
  64. package/node_modules/provider-zoom/dist/index.d.ts.map +1 -1
  65. package/node_modules/provider-zoom/dist/zoom-hub.d.ts +8 -1
  66. package/node_modules/provider-zoom/dist/zoom-hub.d.ts.map +1 -1
  67. package/node_modules/wire-core/dist/core/editor-receipts.d.ts +5 -0
  68. package/node_modules/wire-core/dist/core/editor-receipts.d.ts.map +1 -0
  69. package/node_modules/wire-core/dist/core/editor-receipts.js +9 -0
  70. package/node_modules/wire-core/dist/core/editor-receipts.js.map +1 -0
  71. package/node_modules/wire-core/dist/core/model.d.ts +6 -1
  72. package/node_modules/wire-core/dist/core/model.d.ts.map +1 -1
  73. package/node_modules/wire-core/dist/core/owner.d.ts +3 -0
  74. package/node_modules/wire-core/dist/core/owner.d.ts.map +1 -0
  75. package/node_modules/wire-core/dist/core/owner.js +16 -0
  76. package/node_modules/wire-core/dist/core/owner.js.map +1 -0
  77. package/node_modules/wire-core/dist/core/source.d.ts +4 -1
  78. package/node_modules/wire-core/dist/core/source.d.ts.map +1 -1
  79. package/node_modules/wire-core/dist/core/source.js +15 -2
  80. package/node_modules/wire-core/dist/core/source.js.map +1 -1
  81. package/node_modules/wire-core/dist/index.d.ts +1 -1
  82. package/node_modules/wire-core/dist/index.d.ts.map +1 -1
  83. package/node_modules/wire-core/dist/index.js +1 -1
  84. package/node_modules/wire-core/dist/index.js.map +1 -1
  85. package/node_modules/wire-core/dist/operations.d.ts +11 -2
  86. package/node_modules/wire-core/dist/operations.d.ts.map +1 -1
  87. package/node_modules/wire-core/dist/operations.js +404 -31
  88. package/node_modules/wire-core/dist/operations.js.map +1 -1
  89. package/node_modules/wire-core/dist/storage/editor-receipts.d.ts +17 -0
  90. package/node_modules/wire-core/dist/storage/editor-receipts.d.ts.map +1 -0
  91. package/node_modules/wire-core/dist/storage/editor-receipts.js +27 -0
  92. package/node_modules/wire-core/dist/storage/editor-receipts.js.map +1 -0
  93. package/node_modules/wire-core/dist/storage/history-integrity.d.ts +4 -0
  94. package/node_modules/wire-core/dist/storage/history-integrity.d.ts.map +1 -0
  95. package/node_modules/wire-core/dist/storage/history-integrity.js +32 -0
  96. package/node_modules/wire-core/dist/storage/history-integrity.js.map +1 -0
  97. package/node_modules/wire-core/dist/storage/history.d.ts +93 -0
  98. package/node_modules/wire-core/dist/storage/history.d.ts.map +1 -0
  99. package/node_modules/wire-core/dist/storage/history.js +450 -0
  100. package/node_modules/wire-core/dist/storage/history.js.map +1 -0
  101. package/node_modules/wire-core/dist/storage/registry.d.ts +2 -2
  102. package/node_modules/wire-core/dist/storage/registry.d.ts.map +1 -1
  103. package/node_modules/wire-core/dist/storage/registry.js +34 -14
  104. package/node_modules/wire-core/dist/storage/registry.js.map +1 -1
  105. package/node_modules/wire-core/dist/storage/workspace.d.ts.map +1 -1
  106. package/node_modules/wire-core/dist/storage/workspace.js +183 -40
  107. package/node_modules/wire-core/dist/storage/workspace.js.map +1 -1
  108. package/node_modules/wire-core/src/core/editor-receipts.ts +8 -0
  109. package/node_modules/wire-core/src/core/model.ts +6 -1
  110. package/node_modules/wire-core/src/core/owner.ts +16 -0
  111. package/node_modules/wire-core/src/core/source.ts +17 -1
  112. package/node_modules/wire-core/src/index.ts +1 -1
  113. package/node_modules/wire-core/src/operations.ts +344 -33
  114. package/node_modules/wire-core/src/storage/editor-receipts.ts +27 -0
  115. package/node_modules/wire-core/src/storage/history-integrity.ts +25 -0
  116. package/node_modules/wire-core/src/storage/history.ts +331 -0
  117. package/node_modules/wire-core/src/storage/registry.ts +22 -15
  118. package/node_modules/wire-core/src/storage/workspace.ts +129 -34
  119. package/package.json +6 -2
  120. package/src/adapters/document-shell.ts +43 -0
  121. package/src/adapters/root.ts +71 -4
  122. package/src/cli.ts +8 -2
  123. package/src/executable.ts +1 -1
  124. package/src/hooks.ts +19 -18
@@ -2,6 +2,8 @@ export { latticeReviewDraft, listLatticeReviewRequests, syncLatticeDrafts } from
2
2
  import { type AddMarkdown, type RuntimeCapabilities } from "wire-core";
3
3
  export declare const latticeService: Readonly<{
4
4
  name: string;
5
+ owner?: string;
6
+ supportsEditorReceipts?: boolean;
5
7
  matches(url: URL): boolean;
6
8
  parse(url: URL): import("wire-core").Source;
7
9
  fetch(input: RuntimeCapabilities, url: string, source: Readonly<{
@@ -20,17 +22,24 @@ export declare const latticeService: Readonly<{
20
22
  identifier: string;
21
23
  type: import("wire-core").ResourceType;
22
24
  }>, write: import("wire-core").DownloadWriter, addMarkdown?: AddMarkdown): Promise<import("wire-core").DownloadedDocument | null>;
25
+ mergeDrafts?(base: string, editor: string, shell: string): string;
23
26
  synchronize?(input: RuntimeCapabilities, url: string, source: Readonly<{
24
27
  [key: string]: import("wire-core").JsonValue;
25
28
  service: string;
26
29
  identifier: string;
27
30
  type: import("wire-core").ResourceType;
28
- }>, base: import("wire-core").JsonValue, markdown: string, markdownPath: string): Promise<import("wire-core").SynchronizedDocument>;
31
+ }>, base: import("wire-core").JsonValue, markdown: string, markdownPath: string, observeRemote?: (remote: Readonly<{
32
+ title: string;
33
+ markdown: string;
34
+ data: import("wire-core").JsonValue;
35
+ }>) => void | Promise<void>, requireConditionalWrite?: boolean, expectedFile?: string): Promise<import("wire-core").SynchronizedDocument>;
29
36
  upload?(input: RuntimeCapabilities, markdown: string, markdownPath: string): Promise<import("wire-core").UploadedDocument>;
30
37
  }>;
31
38
  export declare const latticeProvider: Readonly<{
32
39
  services: readonly [Readonly<{
33
40
  name: string;
41
+ owner?: string;
42
+ supportsEditorReceipts?: boolean;
34
43
  matches(url: URL): boolean;
35
44
  parse(url: URL): import("wire-core").Source;
36
45
  fetch(input: RuntimeCapabilities, url: string, source: Readonly<{
@@ -49,12 +58,17 @@ export declare const latticeProvider: Readonly<{
49
58
  identifier: string;
50
59
  type: import("wire-core").ResourceType;
51
60
  }>, write: import("wire-core").DownloadWriter, addMarkdown?: AddMarkdown): Promise<import("wire-core").DownloadedDocument | null>;
61
+ mergeDrafts?(base: string, editor: string, shell: string): string;
52
62
  synchronize?(input: RuntimeCapabilities, url: string, source: Readonly<{
53
63
  [key: string]: import("wire-core").JsonValue;
54
64
  service: string;
55
65
  identifier: string;
56
66
  type: import("wire-core").ResourceType;
57
- }>, base: import("wire-core").JsonValue, markdown: string, markdownPath: string): Promise<import("wire-core").SynchronizedDocument>;
67
+ }>, base: import("wire-core").JsonValue, markdown: string, markdownPath: string, observeRemote?: (remote: Readonly<{
68
+ title: string;
69
+ markdown: string;
70
+ data: import("wire-core").JsonValue;
71
+ }>) => void | Promise<void>, requireConditionalWrite?: boolean, expectedFile?: string): Promise<import("wire-core").SynchronizedDocument>;
58
72
  upload?(input: RuntimeCapabilities, markdown: string, markdownPath: string): Promise<import("wire-core").UploadedDocument>;
59
73
  }>];
60
74
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC9F,OAAO,EAAiB,KAAK,WAAW,EAAwB,KAAK,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAmd5G,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBzB,CAAC;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAyD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC9F,OAAO,EAAiB,KAAK,WAAW,EAAwB,KAAK,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAmd5G,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBzB,CAAC;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAyD,CAAC"}
@@ -4,6 +4,8 @@ export type { NotionBlock, NotionDiffSummary, NotionOperation, NotionRichText, N
4
4
  export declare const notionProvider: Readonly<{
5
5
  services: readonly [Readonly<{
6
6
  name: string;
7
+ owner?: string;
8
+ supportsEditorReceipts?: boolean;
7
9
  matches(url: URL): boolean;
8
10
  parse(url: URL): import("wire-core").Source;
9
11
  fetch(input: import("wire-core").RuntimeCapabilities, url: string, source: Readonly<{
@@ -22,12 +24,17 @@ export declare const notionProvider: Readonly<{
22
24
  identifier: string;
23
25
  type: import("wire-core").ResourceType;
24
26
  }>, write: import("wire-core").DownloadWriter, addMarkdown?: import("wire-core").AddMarkdown): Promise<import("wire-core").DownloadedDocument | null>;
27
+ mergeDrafts?(base: string, editor: string, shell: string): string;
25
28
  synchronize?(input: import("wire-core").RuntimeCapabilities, url: string, source: Readonly<{
26
29
  [key: string]: import("wire-core").JsonValue;
27
30
  service: string;
28
31
  identifier: string;
29
32
  type: import("wire-core").ResourceType;
30
- }>, base: import("wire-core").JsonValue, markdown: string, markdownPath: string): Promise<import("wire-core").SynchronizedDocument>;
33
+ }>, base: import("wire-core").JsonValue, markdown: string, markdownPath: string, observeRemote?: (remote: Readonly<{
34
+ title: string;
35
+ markdown: string;
36
+ data: import("wire-core").JsonValue;
37
+ }>) => void | Promise<void>, requireConditionalWrite?: boolean, expectedFile?: string): Promise<import("wire-core").SynchronizedDocument>;
31
38
  upload?(input: import("wire-core").RuntimeCapabilities, markdown: string, markdownPath: string): Promise<import("wire-core").UploadedDocument>;
32
39
  }>];
33
40
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC3O,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,eAAe,EAAE,cAAc,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACxI,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEzB,CAAC;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC3O,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,eAAe,EAAE,cAAc,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACxI,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEzB,CAAC;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { DownloadedDocument, DownloadWriter, FetchedDocument, JsonObject, JsonValue, Source, UploadedDocument } from "wire-core";
1
+ import type { DownloadedDocument, DownloadWriter, FetchedDocument, JsonObject, JsonValue, Source, SynchronizedDocument, UploadedDocument } from "wire-core";
2
2
  import type { RuntimeCapabilities } from "wire-core";
3
3
  export type NotionRichText = JsonValue[][];
4
4
  export type NotionBlock = Readonly<{
@@ -54,6 +54,6 @@ export declare function lookupNotionUsers(runtime: RuntimeCapabilities, query: s
54
54
  export declare function fetchNotionDocument(runtime: RuntimeCapabilities, url: string, source: Source): Promise<FetchedDocument>;
55
55
  export declare function downloadNotionDirectory(runtime: RuntimeCapabilities, url: string, source: Source, write: DownloadWriter): Promise<DownloadedDocument | null>;
56
56
  export declare function uploadNotionDocument(runtime: RuntimeCapabilities, markdown: string, _markdownPath: string): Promise<UploadedDocument>;
57
- export declare function synchronizeNotionDocument(runtime: RuntimeCapabilities, url: string, source: Source, base: JsonValue, markdown: string, _markdownPath: string): Promise<FetchedDocument>;
57
+ export declare function synchronizeNotionDocument(runtime: RuntimeCapabilities, url: string, source: Source, base: JsonValue, markdown: string, _markdownPath: string, observeRemote?: (remote: FetchedDocument) => void | Promise<void>, requireConditionalWrite?: boolean): Promise<SynchronizedDocument>;
58
58
  export {};
59
59
  //# sourceMappingURL=notion-sync.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"notion-sync.d.ts","sourceRoot":"","sources":["../src/notion-sync.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAEtI,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAErD,MAAM,MAAM,cAAc,GAAG,SAAS,EAAE,EAAE,CAAC;AAC3C,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,cAAc,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AACzI,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,SAAS,UAAU,EAAE,CAAA;CAAE,CAAC,CAAC;AACtG,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IAAE,OAAO,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,SAAS,SAAS,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,SAAS,CAA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";
3
+ import { WireMergeConflict, markdownFilename, stableJsonCompact, stableJsonPretty } from "wire-core";
4
4
  function object(value) { return value; }
5
5
  function array(value) { return value; }
6
6
  function text(value) { return value; }
@@ -1256,12 +1256,22 @@ function splitTitle(markdown) {
1256
1256
  return { title: first.replace(/^#+\s+/, "").trim(), body: lines.slice(1).join("\n") };
1257
1257
  return { title: "", body: markdown };
1258
1258
  }
1259
- export async function synchronizeNotionDocument(runtime, url, source, base, markdown, _markdownPath) {
1259
+ export async function synchronizeNotionDocument(runtime, url, source, base, markdown, _markdownPath, observeRemote, requireConditionalWrite = false) {
1260
1260
  const remote = await fetchTree(runtime, url, source);
1261
+ const save = async (operations) => {
1262
+ if (operations.length === 0)
1263
+ return;
1264
+ // saveTransactionsFanout cannot check the tree revision at commit time.
1265
+ if (requireConditionalWrite)
1266
+ throw new Error("Notion cannot condition a save on the revision read. Local draft preserved; apply the edit in Notion.");
1267
+ await notionPost(runtime, "saveTransactionsFanout", remote.cookie, { requestId: randomUUID(), transactions: [{ id: randomUUID(), spaceId: remote.spaceId, operations }] }, remote.headers);
1268
+ };
1261
1269
  const baseObject = object(base);
1262
1270
  const mentions = baseUserMentions(baseObject);
1263
1271
  const emailMentions = { ...baseObject["email_mentions"] };
1264
- const currentMarkdown = renderNotionTreeToMarkdown(remote.tree, mentions, emailMentions);
1272
+ const observed = notionDocument(remote.tree.id, remote.tree, mentions, { ...emailMentions }, remote.comments);
1273
+ await observeRemote?.(observed);
1274
+ const currentMarkdown = withoutComments(observed.markdown);
1265
1275
  const baseMarkdown = baseObject["markdown"] === undefined ? undefined : withoutComments(baseObject["markdown"]);
1266
1276
  let split = splitTitle(withoutComments(markdown));
1267
1277
  const currentSplit = splitTitle(currentMarkdown);
@@ -1273,7 +1283,7 @@ export async function synchronizeNotionDocument(runtime, url, source, base, mark
1273
1283
  const localBodyChanged = baseSplit.body !== split.body;
1274
1284
  const remoteBodyChanged = baseSplit.body !== currentSplit.body;
1275
1285
  if (localTitleChanged && remoteTitleChanged && split.title !== "" && split.title !== currentSplit.title || localBodyChanged && remoteBodyChanged && split.body !== currentSplit.body)
1276
- throw new Error("Markdown and Notion changed since last sync");
1286
+ throw new WireMergeConflict("Markdown and Notion changed since last sync");
1277
1287
  if ((localTitleChanged || localBodyChanged) && (remoteTitleChanged || remoteBodyChanged)) {
1278
1288
  split = { title: localTitleChanged ? split.title : currentSplit.title, body: localBodyChanged ? split.body : currentSplit.body };
1279
1289
  fieldMerged = true;
@@ -1285,28 +1295,28 @@ export async function synchronizeNotionDocument(runtime, url, source, base, mark
1285
1295
  const localTitleChanged = baseSplit.title !== split.title;
1286
1296
  const remoteTitleChanged = baseSplit.title !== currentSplit.title;
1287
1297
  if (!localTitleChanged && remoteTitleChanged)
1288
- return notionDocument(remote.tree.id, remote.tree, mentions, emailMentions, remote.comments);
1298
+ return { ...observed, wroteRemote: false };
1289
1299
  if (localTitleChanged && remoteTitleChanged && split.title !== currentSplit.title)
1290
- throw new Error("Markdown and Notion changed since last sync");
1300
+ throw new WireMergeConflict("Markdown and Notion changed since last sync");
1291
1301
  if (localTitleChanged && remoteTitleChanged)
1292
- return notionDocument(remote.tree.id, remote.tree, mentions, emailMentions, remote.comments);
1302
+ return { ...observed, wroteRemote: false };
1293
1303
  }
1294
1304
  const titleRich = split.title === "" ? object(remote.tree.block["properties"])["title"] : titleRichText(split.title);
1295
1305
  const titleChanged = split.title !== "" && compact(object(remote.tree.block["properties"])["title"]) !== compact(titleRich);
1296
1306
  if (titleChanged)
1297
- await notionPost(runtime, "saveTransactionsFanout", remote.cookie, { requestId: randomUUID(), transactions: [{ id: randomUUID(), spaceId: remote.spaceId, operations: [{ pointer: pointer(remote.tree.id, remote.spaceId), path: ["properties", "title"], command: "updateBlockPropertyValue", args: { primitiveOp: { command: "set", args: titleRich } } }, { pointer: pointer(remote.tree.id, remote.spaceId), path: ["last_edited_time"], command: "set", args: runtime.clock.now().getTime() }] }] }, remote.headers);
1307
+ await save([{ pointer: pointer(remote.tree.id, remote.spaceId), path: ["properties", "title"], command: "updateBlockPropertyValue", args: { primitiveOp: { command: "set", args: titleRich } } }, { pointer: pointer(remote.tree.id, remote.spaceId), path: ["last_edited_time"], command: "set", args: runtime.clock.now().getTime() }]);
1298
1308
  const outputTree = { ...remote.tree, block: { ...remote.tree.block, properties: { ...object(remote.tree.block["properties"]), title: titleRich } } };
1299
- return notionDocument(remote.tree.id, outputTree, mentions, emailMentions, remote.comments);
1309
+ return { ...notionDocument(remote.tree.id, outputTree, mentions, emailMentions, remote.comments), wroteRemote: titleChanged };
1300
1310
  }
1301
1311
  if (baseMarkdown !== undefined) {
1302
1312
  const localChanged = baseMarkdown !== targetMarkdown;
1303
1313
  const remoteChanged = baseMarkdown !== currentMarkdown;
1304
1314
  if (!localChanged && remoteChanged)
1305
- return notionDocument(remote.tree.id, remote.tree, mentions, emailMentions, remote.comments);
1315
+ return { ...observed, wroteRemote: false };
1306
1316
  if (localChanged && remoteChanged && targetMarkdown !== currentMarkdown && !fieldMerged)
1307
- throw new Error("Markdown and Notion changed since last sync");
1317
+ throw new WireMergeConflict("Markdown and Notion changed since last sync");
1308
1318
  if (localChanged && remoteChanged && targetMarkdown === currentMarkdown)
1309
- return notionDocument(remote.tree.id, remote.tree, mentions, emailMentions, remote.comments);
1319
+ return { ...observed, wroteRemote: false };
1310
1320
  }
1311
1321
  const localBody = mentions === undefined ? split.body : hydrateUserMentions(split.body, mentions);
1312
1322
  const localBlocks = parseNotionMarkdown(localBody);
@@ -1317,9 +1327,8 @@ export async function synchronizeNotionDocument(runtime, url, source, base, mark
1317
1327
  const titleRich = split.title === "" ? object(remote.tree.block["properties"])["title"] : titleRichText(split.title);
1318
1328
  if (split.title !== "" && compact(object(remote.tree.block["properties"])["title"]) !== compact(titleRich))
1319
1329
  operations.unshift({ pointer: pointer(remote.tree.id, remote.spaceId), path: ["properties", "title"], command: "updateBlockPropertyValue", args: { primitiveOp: { command: "set", args: titleRich } } });
1320
- if (operations.length > 0)
1321
- await notionPost(runtime, "saveTransactionsFanout", remote.cookie, { requestId: randomUUID(), transactions: [{ id: randomUUID(), spaceId: remote.spaceId, operations }] }, remote.headers);
1330
+ await save(operations);
1322
1331
  const outputTree = { id: remote.tree.id, block: { ...remote.tree.block, properties: { ...object(remote.tree.block["properties"]), title: titleRich } }, children: localTree(localBlocks).map((node, index) => outputNode(node, remote.tree.children[index], remote.tree.id, remote, ambient.currentTime)) };
1323
- return notionDocument(remote.tree.id, outputTree, mentions, emailMentions, remote.comments);
1332
+ return { ...notionDocument(remote.tree.id, outputTree, mentions, emailMentions, remote.comments), wroteRemote: operations.length > 0 };
1324
1333
  }
1325
1334
  //# sourceMappingURL=notion-sync.js.map