@superbee/core 0.1.6 → 0.2.0-pre.10

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 (248) hide show
  1. package/README.md +127 -0
  2. package/dist/artifact-contract.d.ts +90 -0
  3. package/dist/artifact-contract.d.ts.map +1 -0
  4. package/dist/artifact-contract.js +205 -0
  5. package/dist/artifact-contract.js.map +1 -0
  6. package/dist/backend.d.ts +16 -1
  7. package/dist/backend.d.ts.map +1 -1
  8. package/dist/backend.js +112 -47
  9. package/dist/backend.js.map +1 -1
  10. package/dist/bundle-ops.d.ts +42 -0
  11. package/dist/bundle-ops.d.ts.map +1 -0
  12. package/dist/bundle-ops.js +88 -0
  13. package/dist/bundle-ops.js.map +1 -0
  14. package/dist/bundle.d.ts +10 -28
  15. package/dist/bundle.d.ts.map +1 -1
  16. package/dist/bundle.js +12 -69
  17. package/dist/bundle.js.map +1 -1
  18. package/dist/document-codec.d.ts +6 -1
  19. package/dist/document-codec.d.ts.map +1 -1
  20. package/dist/document-codec.js +8 -4
  21. package/dist/document-codec.js.map +1 -1
  22. package/dist/document-field-actions.d.ts +107 -0
  23. package/dist/document-field-actions.d.ts.map +1 -0
  24. package/dist/document-field-actions.js +302 -0
  25. package/dist/document-field-actions.js.map +1 -0
  26. package/dist/document-mutation.d.ts +61 -3
  27. package/dist/document-mutation.d.ts.map +1 -1
  28. package/dist/document-mutation.js +116 -25
  29. package/dist/document-mutation.js.map +1 -1
  30. package/dist/document-write-policy.d.ts +0 -1
  31. package/dist/document-write-policy.d.ts.map +1 -1
  32. package/dist/document-write-policy.js +7 -4
  33. package/dist/document-write-policy.js.map +1 -1
  34. package/dist/engine.d.ts +3 -1
  35. package/dist/engine.d.ts.map +1 -1
  36. package/dist/engine.js +6 -4
  37. package/dist/engine.js.map +1 -1
  38. package/dist/file-journaled-backend-internal.d.ts +19 -0
  39. package/dist/file-journaled-backend-internal.d.ts.map +1 -0
  40. package/dist/file-journaled-backend-internal.js +10 -0
  41. package/dist/file-journaled-backend-internal.js.map +1 -0
  42. package/dist/file-journaled-backend.d.ts +162 -0
  43. package/dist/file-journaled-backend.d.ts.map +1 -0
  44. package/dist/file-journaled-backend.js +1113 -0
  45. package/dist/file-journaled-backend.js.map +1 -0
  46. package/dist/filesystem-host.d.ts +15 -0
  47. package/dist/filesystem-host.d.ts.map +1 -0
  48. package/dist/filesystem-host.js +20 -0
  49. package/dist/filesystem-host.js.map +1 -0
  50. package/dist/filesystem-identity.d.ts +86 -4
  51. package/dist/filesystem-identity.d.ts.map +1 -1
  52. package/dist/filesystem-identity.js +338 -102
  53. package/dist/filesystem-identity.js.map +1 -1
  54. package/dist/filesystem-lock.d.ts +16 -3
  55. package/dist/filesystem-lock.d.ts.map +1 -1
  56. package/dist/filesystem-lock.js +323 -77
  57. package/dist/filesystem-lock.js.map +1 -1
  58. package/dist/filesystem-push-role.d.ts +77 -0
  59. package/dist/filesystem-push-role.d.ts.map +1 -0
  60. package/dist/filesystem-push-role.js +165 -0
  61. package/dist/filesystem-push-role.js.map +1 -0
  62. package/dist/filesystem.d.ts +17 -0
  63. package/dist/filesystem.d.ts.map +1 -0
  64. package/dist/filesystem.js +18 -0
  65. package/dist/filesystem.js.map +1 -0
  66. package/dist/freshness.d.ts +10 -7
  67. package/dist/freshness.d.ts.map +1 -1
  68. package/dist/freshness.js +14 -11
  69. package/dist/freshness.js.map +1 -1
  70. package/dist/frontmatter-contract.d.ts +2 -2
  71. package/dist/frontmatter-contract.js +2 -2
  72. package/dist/frontmatter.d.ts +11 -1
  73. package/dist/frontmatter.d.ts.map +1 -1
  74. package/dist/frontmatter.js +20 -7
  75. package/dist/frontmatter.js.map +1 -1
  76. package/dist/governed-body-write.d.ts +106 -0
  77. package/dist/governed-body-write.d.ts.map +1 -0
  78. package/dist/governed-body-write.js +251 -0
  79. package/dist/governed-body-write.js.map +1 -0
  80. package/dist/heads-digest.d.ts +32 -0
  81. package/dist/heads-digest.d.ts.map +1 -0
  82. package/dist/heads-digest.js +37 -0
  83. package/dist/heads-digest.js.map +1 -0
  84. package/dist/host-policy-snapshot.d.ts +9 -0
  85. package/dist/host-policy-snapshot.d.ts.map +1 -0
  86. package/dist/host-policy-snapshot.js +33 -0
  87. package/dist/host-policy-snapshot.js.map +1 -0
  88. package/dist/host-text.d.ts +31 -0
  89. package/dist/host-text.d.ts.map +1 -0
  90. package/dist/host-text.js +77 -0
  91. package/dist/host-text.js.map +1 -0
  92. package/dist/hosted-transport/answer-rows.d.ts +216 -0
  93. package/dist/hosted-transport/answer-rows.d.ts.map +1 -0
  94. package/dist/hosted-transport/answer-rows.js +396 -0
  95. package/dist/hosted-transport/answer-rows.js.map +1 -0
  96. package/dist/hosted-transport/carrier.d.ts +142 -0
  97. package/dist/hosted-transport/carrier.d.ts.map +1 -0
  98. package/dist/hosted-transport/carrier.js +241 -0
  99. package/dist/hosted-transport/carrier.js.map +1 -0
  100. package/dist/hosted-transport/history-pages.d.ts +55 -0
  101. package/dist/hosted-transport/history-pages.d.ts.map +1 -0
  102. package/dist/hosted-transport/history-pages.js +69 -0
  103. package/dist/hosted-transport/history-pages.js.map +1 -0
  104. package/dist/hosted-transport/index.d.ts +18 -0
  105. package/dist/hosted-transport/index.d.ts.map +1 -0
  106. package/dist/hosted-transport/index.js +18 -0
  107. package/dist/hosted-transport/index.js.map +1 -0
  108. package/dist/hosted-transport/operations.d.ts +85 -0
  109. package/dist/hosted-transport/operations.d.ts.map +1 -0
  110. package/dist/hosted-transport/operations.js +128 -0
  111. package/dist/hosted-transport/operations.js.map +1 -0
  112. package/dist/hosted-transport/paged-reads.d.ts +87 -0
  113. package/dist/hosted-transport/paged-reads.d.ts.map +1 -0
  114. package/dist/hosted-transport/paged-reads.js +238 -0
  115. package/dist/hosted-transport/paged-reads.js.map +1 -0
  116. package/dist/hosted-transport/read-adapter.d.ts +250 -0
  117. package/dist/hosted-transport/read-adapter.d.ts.map +1 -0
  118. package/dist/hosted-transport/read-adapter.js +557 -0
  119. package/dist/hosted-transport/read-adapter.js.map +1 -0
  120. package/dist/hosted-transport/root-write.d.ts +114 -0
  121. package/dist/hosted-transport/root-write.d.ts.map +1 -0
  122. package/dist/hosted-transport/root-write.js +171 -0
  123. package/dist/hosted-transport/root-write.js.map +1 -0
  124. package/dist/hosted-transport/whole-document-transport.d.ts +174 -0
  125. package/dist/hosted-transport/whole-document-transport.d.ts.map +1 -0
  126. package/dist/hosted-transport/whole-document-transport.js +411 -0
  127. package/dist/hosted-transport/whole-document-transport.js.map +1 -0
  128. package/dist/index.d.ts +29 -8
  129. package/dist/index.d.ts.map +1 -1
  130. package/dist/index.js +26 -6
  131. package/dist/index.js.map +1 -1
  132. package/dist/indexeddb-backend.d.ts +197 -0
  133. package/dist/indexeddb-backend.d.ts.map +1 -0
  134. package/dist/indexeddb-backend.js +1183 -0
  135. package/dist/indexeddb-backend.js.map +1 -0
  136. package/dist/journaled-backend.d.ts +467 -0
  137. package/dist/journaled-backend.d.ts.map +1 -0
  138. package/dist/journaled-backend.js +389 -0
  139. package/dist/journaled-backend.js.map +1 -0
  140. package/dist/kind-coverage.d.ts +99 -0
  141. package/dist/kind-coverage.d.ts.map +1 -0
  142. package/dist/kind-coverage.js +186 -0
  143. package/dist/kind-coverage.js.map +1 -0
  144. package/dist/kind-field-mutation.d.ts +15 -0
  145. package/dist/kind-field-mutation.d.ts.map +1 -0
  146. package/dist/kind-field-mutation.js +160 -0
  147. package/dist/kind-field-mutation.js.map +1 -0
  148. package/dist/kinds.d.ts +31 -1
  149. package/dist/kinds.d.ts.map +1 -1
  150. package/dist/kinds.js +86 -17
  151. package/dist/kinds.js.map +1 -1
  152. package/dist/links.d.ts +1 -1
  153. package/dist/links.d.ts.map +1 -1
  154. package/dist/links.js +5 -10
  155. package/dist/links.js.map +1 -1
  156. package/dist/managed-document-metadata.d.ts +2 -0
  157. package/dist/managed-document-metadata.d.ts.map +1 -0
  158. package/dist/managed-document-metadata.js +9 -0
  159. package/dist/managed-document-metadata.js.map +1 -0
  160. package/dist/meaningful-change-time.d.ts +6 -6
  161. package/dist/meaningful-change-time.d.ts.map +1 -1
  162. package/dist/meaningful-change-time.js +12 -13
  163. package/dist/meaningful-change-time.js.map +1 -1
  164. package/dist/memory-backend.d.ts +2 -2
  165. package/dist/memory-backend.d.ts.map +1 -1
  166. package/dist/memory-backend.js +32 -16
  167. package/dist/memory-backend.js.map +1 -1
  168. package/dist/mutation.d.ts.map +1 -1
  169. package/dist/mutation.js +2 -2
  170. package/dist/mutation.js.map +1 -1
  171. package/dist/page.d.ts.map +1 -1
  172. package/dist/page.js +2 -1
  173. package/dist/page.js.map +1 -1
  174. package/dist/paths.d.ts +6 -2
  175. package/dist/paths.d.ts.map +1 -1
  176. package/dist/paths.js +35 -33
  177. package/dist/paths.js.map +1 -1
  178. package/dist/platform.d.ts +239 -0
  179. package/dist/platform.d.ts.map +1 -0
  180. package/dist/platform.js +82 -0
  181. package/dist/platform.js.map +1 -0
  182. package/dist/portable-export.d.ts +119 -0
  183. package/dist/portable-export.d.ts.map +1 -0
  184. package/dist/portable-export.js +501 -0
  185. package/dist/portable-export.js.map +1 -0
  186. package/dist/publication-filesystem.d.ts +1 -1
  187. package/dist/publication-filesystem.d.ts.map +1 -1
  188. package/dist/publication-filesystem.js +1 -1
  189. package/dist/publication-filesystem.js.map +1 -1
  190. package/dist/query-filter.d.ts +7 -2
  191. package/dist/query-filter.d.ts.map +1 -1
  192. package/dist/query-filter.js +24 -1
  193. package/dist/query-filter.js.map +1 -1
  194. package/dist/query-order.d.ts +22 -0
  195. package/dist/query-order.d.ts.map +1 -0
  196. package/dist/query-order.js +42 -0
  197. package/dist/query-order.js.map +1 -0
  198. package/dist/recipes.d.ts +3 -1
  199. package/dist/recipes.d.ts.map +1 -1
  200. package/dist/recipes.js +4 -4
  201. package/dist/recipes.js.map +1 -1
  202. package/dist/remote-backend.d.ts +114 -22
  203. package/dist/remote-backend.d.ts.map +1 -1
  204. package/dist/remote-backend.js +285 -44
  205. package/dist/remote-backend.js.map +1 -1
  206. package/dist/remote-document-codec.d.ts +15 -0
  207. package/dist/remote-document-codec.d.ts.map +1 -0
  208. package/dist/remote-document-codec.js +103 -0
  209. package/dist/remote-document-codec.js.map +1 -0
  210. package/dist/remote-error.d.ts +38 -0
  211. package/dist/remote-error.d.ts.map +1 -0
  212. package/dist/remote-error.js +59 -0
  213. package/dist/remote-error.js.map +1 -0
  214. package/dist/remote-operations.d.ts +63 -0
  215. package/dist/remote-operations.d.ts.map +1 -0
  216. package/dist/remote-operations.js +125 -0
  217. package/dist/remote-operations.js.map +1 -0
  218. package/dist/remote-parsers.d.ts +86 -0
  219. package/dist/remote-parsers.d.ts.map +1 -0
  220. package/dist/remote-parsers.js +181 -0
  221. package/dist/remote-parsers.js.map +1 -0
  222. package/dist/remote.d.ts +7 -2
  223. package/dist/remote.d.ts.map +1 -1
  224. package/dist/remote.js +6 -1
  225. package/dist/remote.js.map +1 -1
  226. package/dist/sha256.d.ts +21 -0
  227. package/dist/sha256.d.ts.map +1 -0
  228. package/dist/sha256.js +114 -0
  229. package/dist/sha256.js.map +1 -0
  230. package/dist/storage.d.ts +8 -2
  231. package/dist/storage.d.ts.map +1 -1
  232. package/dist/storage.js +11 -2
  233. package/dist/storage.js.map +1 -1
  234. package/dist/types.d.ts +40 -5
  235. package/dist/types.d.ts.map +1 -1
  236. package/dist/uncertain-write.d.ts +178 -0
  237. package/dist/uncertain-write.d.ts.map +1 -0
  238. package/dist/uncertain-write.js +198 -0
  239. package/dist/uncertain-write.js.map +1 -0
  240. package/dist/version-transport.d.ts +7 -0
  241. package/dist/version-transport.d.ts.map +1 -1
  242. package/dist/version-transport.js +9 -0
  243. package/dist/version-transport.js.map +1 -1
  244. package/dist/versioning.d.ts +18 -7
  245. package/dist/versioning.d.ts.map +1 -1
  246. package/dist/versioning.js +23 -14
  247. package/dist/versioning.js.map +1 -1
  248. package/package.json +75 -4
@@ -1 +1 @@
1
- {"version":3,"file":"bundle.d.ts","sourceRoot":"","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,EACV,UAAU,EACV,QAAQ,EACR,oBAAoB,EACpB,OAAO,EACP,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,iBAAiB,EACjB,2BAA2B,GAC5B,MAAM,iBAAiB,CAAC;AAIzB,eAAO,MAAM,gCAAgC,yBAA0B,CAAC;AACxE,eAAO,MAAM,6BAA6B,QAAQ,CAAC;AAEnD,wBAAgB,0BAA0B,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CASrE;AAED,qDAAqD;AACrD,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,EAAE,iBAAiB,GAAE,wBAA6B,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBjJ"}
package/dist/bundle.js CHANGED
@@ -1,24 +1,22 @@
1
1
  /**
2
- * Legacy bundle-shaped core API.
2
+ * Legacy bundle-shaped core API, Node entry.
3
3
  *
4
- * Portable semantics live in `engine.ts` and receive a backend explicitly. This adapter preserves
5
- * the historical `{ root, backend? }` signatures and filesystem fallback used by Node consumers.
4
+ * Portable semantics live in `engine.ts` and receive a backend explicitly; the bundle-shaped
5
+ * `{ root, backend? }` wrappers live in `bundle-ops.ts` so they bundle for the browser. This
6
+ * module owns what only a Node host can: the filesystem default for a bare `{ root }` and
7
+ * on-disk bundle initialization. Loading it installs that default, which is why `index.ts`
8
+ * imports it and why the package manifest marks it side-effectful.
6
9
  */
7
10
  import path from "node:path";
8
11
  import { FilesystemBackend } from "./backend.js";
9
- import * as engine from "./engine.js";
12
+ import { setDefaultBackendFactory } from "./bundle-ops.js";
10
13
  import { InvalidInputError } from "./errors.js";
11
14
  import { stringifyWithData } from "./frontmatter.js";
12
15
  import { GENERATED_INDEX_MARKER } from "./index-marker.js";
13
16
  import { VersionConflict } from "./versioning.js";
14
17
  export { matchesFilter } from "./query-filter.js";
15
- /** Resolve the backend a legacy bundle operation should use. */
16
- export function backendFor(bundle) {
17
- return bundle.backend ?? new FilesystemBackend(bundle.root);
18
- }
19
- export async function readBundleOkfVersion(bundle) {
20
- return engine.readBundleOkfVersion(backendFor(bundle));
21
- }
18
+ export { backendFor, backlinks, deleteBlob, deleteDoc, docVersions, existsBlob, existsDoc, list, listBlobs, parseLinks, query, queryEdges, queryHeads, readBlob, readBundleOkfVersion, readDoc, readDocVersioned, writeBlob, writeDoc, writeDocVersioned, writeDocVersionedForEdition, } from "./bundle-ops.js";
19
+ setDefaultBackendFactory((root) => new FilesystemBackend(root));
22
20
  export const SUPPORTED_OKF_AUTHORING_VERSIONS = ["0.1", "0.2"];
23
21
  export const DEFAULT_OKF_AUTHORING_VERSION = "0.2";
24
22
  export function resolveOkfAuthoringVersion(requested) {
@@ -30,10 +28,10 @@ export function resolveOkfAuthoringVersion(requested) {
30
28
  return version;
31
29
  }
32
30
  /** Initialize or open a filesystem-backed bundle. */
33
- export async function initBundle(root, options = {}) {
31
+ export async function initBundle(root, options = {}, filesystemOptions = {}) {
34
32
  const okfVersion = resolveOkfAuthoringVersion(options.okfVersion);
35
33
  const resolved = path.resolve(root);
36
- const backend = new FilesystemBackend(resolved);
34
+ const backend = new FilesystemBackend(resolved, filesystemOptions);
37
35
  if (options.expectNew || (await backend.readReserved("", "index.md")) === null) {
38
36
  const name = path.basename(resolved);
39
37
  const body = `${GENERATED_INDEX_MARKER}\n# ${name}\n\nAn Open Knowledge Format bundle.\n`;
@@ -47,61 +45,6 @@ export async function initBundle(root, options = {}) {
47
45
  throw err;
48
46
  }
49
47
  }
50
- return { root: resolved };
51
- }
52
- export async function writeDocVersioned(bundle, doc, options) {
53
- return engine.writeDocVersioned(backendFor(bundle), doc, options);
54
- }
55
- export async function writeDocVersionedForEdition(bundle, doc, okfVersion, options) {
56
- return engine.writeDocVersionedForEdition(backendFor(bundle), doc, okfVersion, options);
57
- }
58
- export async function writeDoc(bundle, doc, options) {
59
- return engine.writeDoc(backendFor(bundle), doc, options);
60
- }
61
- export async function readDocVersioned(bundle, id) {
62
- return engine.readDocVersioned(backendFor(bundle), id);
63
- }
64
- export async function readDoc(bundle, id) {
65
- return engine.readDoc(backendFor(bundle), id);
66
- }
67
- export async function existsDoc(bundle, id) {
68
- return engine.existsDoc(backendFor(bundle), id);
69
- }
70
- export async function docVersions(bundle, id) {
71
- return engine.docVersions(backendFor(bundle), id);
72
- }
73
- export async function deleteDoc(bundle, id, options) {
74
- return engine.deleteDoc(backendFor(bundle), id, options);
75
- }
76
- export async function query(bundle, filter = {}, options = {}) {
77
- return engine.query(backendFor(bundle), filter, options);
78
- }
79
- export const list = query;
80
- export async function queryHeads(bundle, filter = {}, options = {}) {
81
- return engine.queryHeads(backendFor(bundle), filter, options);
82
- }
83
- export function parseLinks(_bundle, doc) {
84
- return engine.parseLinks(doc);
85
- }
86
- export async function queryEdges(bundle, filter = {}) {
87
- return engine.queryEdges(backendFor(bundle), filter);
88
- }
89
- export async function backlinks(bundle, target) {
90
- return engine.backlinks(backendFor(bundle), target);
91
- }
92
- export async function readBlob(bundle, key) {
93
- return engine.readBlob(backendFor(bundle), key);
94
- }
95
- export async function writeBlob(bundle, key, bytes, contentType, options) {
96
- return engine.writeBlob(backendFor(bundle), key, bytes, contentType, options);
97
- }
98
- export async function existsBlob(bundle, key) {
99
- return engine.existsBlob(backendFor(bundle), key);
100
- }
101
- export async function listBlobs(bundle, prefix) {
102
- return engine.listBlobs(backendFor(bundle), prefix);
103
- }
104
- export async function deleteBlob(bundle, key, options) {
105
- return engine.deleteBlob(backendFor(bundle), key, options);
48
+ return { root: resolved, backend };
106
49
  }
107
50
  //# sourceMappingURL=bundle.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bundle.js","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,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E,CAAC;AACrC,CAAC"}
@@ -5,8 +5,13 @@
5
5
  */
6
6
  export { parseMarkdown, stringifyDoc, stringifyWithData, normalizeDocumentBodyForStorage, MalformedDocumentError, } from "./frontmatter.js";
7
7
  export { resolveContentType } from "./content-type.js";
8
+ export { captureRemoteFrontmatter, RemoteDocumentValueError } from "./remote-document-codec.js";
8
9
  export type { Frontmatter, OkfDocument, Version } from "./types.js";
9
10
  import type { Version } from "./types.js";
10
- /** SHA-256 version of exact bytes, including binary data, using Web Crypto. */
11
+ /**
12
+ * SHA-256 version of exact bytes, including binary data. Minted by the same pure
13
+ * implementation as every other version token, so one digest owner serves Node and
14
+ * browser runtimes; the async signature is kept for the codec's existing callers.
15
+ */
11
16
  export declare function versionFromBytes(bytes: Uint8Array): Promise<Version>;
12
17
  //# sourceMappingURL=document-codec.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"document-codec.d.ts","sourceRoot":"","sources":["../src/document-codec.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,+BAA+B,EAC/B,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,+EAA+E;AAC/E,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAI1E"}
1
+ {"version":3,"file":"document-codec.d.ts","sourceRoot":"","sources":["../src/document-codec.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,+BAA+B,EAC/B,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAChG,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAE1E"}
@@ -5,10 +5,14 @@
5
5
  */
6
6
  export { parseMarkdown, stringifyDoc, stringifyWithData, normalizeDocumentBodyForStorage, MalformedDocumentError, } from "./frontmatter.js";
7
7
  export { resolveContentType } from "./content-type.js";
8
- /** SHA-256 version of exact bytes, including binary data, using Web Crypto. */
8
+ export { captureRemoteFrontmatter, RemoteDocumentValueError } from "./remote-document-codec.js";
9
+ import { sha256HexOfBytes } from "./sha256.js";
10
+ /**
11
+ * SHA-256 version of exact bytes, including binary data. Minted by the same pure
12
+ * implementation as every other version token, so one digest owner serves Node and
13
+ * browser runtimes; the async signature is kept for the codec's existing callers.
14
+ */
9
15
  export async function versionFromBytes(bytes) {
10
- const digest = await globalThis.crypto.subtle.digest("SHA-256", new Uint8Array(bytes).buffer);
11
- const hex = Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("");
12
- return `sha256:${hex}`;
16
+ return `sha256:${sha256HexOfBytes(bytes)}`;
13
17
  }
14
18
  //# sourceMappingURL=document-codec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"document-codec.js","sourceRoot":"","sources":["../src/document-codec.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,+BAA+B,EAC/B,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAKvD,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,KAAiB;IACtD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;IAC9F,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACtG,OAAO,UAAU,GAAG,EAAE,CAAC;AACzB,CAAC"}
1
+ {"version":3,"file":"document-codec.js","sourceRoot":"","sources":["../src/document-codec.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,+BAA+B,EAC/B,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAGhG,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,KAAiB;IACtD,OAAO,UAAU,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,107 @@
1
+ import { InvalidInputError } from "./errors.js";
2
+ import { type KindRegistry } from "./kinds.js";
3
+ import type { Frontmatter, OkfDocument } from "./types.js";
4
+ import type { DocumentMutationCandidate } from "./document-mutation.js";
5
+ export type SourceEntry = {
6
+ resource: string;
7
+ id?: string;
8
+ [property: string]: unknown;
9
+ };
10
+ export type SourceSelector = {
11
+ id: string;
12
+ resource?: never;
13
+ } | {
14
+ resource: string;
15
+ id?: never;
16
+ };
17
+ export interface SourceCandidateIdentity {
18
+ id?: string;
19
+ resource?: string;
20
+ title?: string;
21
+ }
22
+ export interface FieldActionErrorDetails {
23
+ reason: "ambiguous-source" | "source-has-id" | "source-not-found" | "source-id-conflict" | "invalid-source-id" | "unsupported-set-field";
24
+ field: string;
25
+ supportedFields?: string[];
26
+ selector?: SourceSelector;
27
+ recommendedSelector?: SourceSelector;
28
+ candidates?: SourceCandidateIdentity[];
29
+ total?: number;
30
+ }
31
+ /** Adapters can render corrective commands without parsing prose or repeating selection. */
32
+ export declare class FieldActionError extends InvalidInputError {
33
+ readonly details: FieldActionErrorDetails;
34
+ constructor(message: string, details: FieldActionErrorDetails);
35
+ }
36
+ export type FieldAction = {
37
+ action: "set";
38
+ field: string;
39
+ value: unknown;
40
+ } | {
41
+ action: "add";
42
+ field: "tags";
43
+ value: string;
44
+ } | {
45
+ action: "add";
46
+ field: "sources";
47
+ value: SourceEntry;
48
+ } | {
49
+ action: "remove";
50
+ field: "tags";
51
+ value: string;
52
+ } | {
53
+ action: "remove";
54
+ field: "sources";
55
+ selector: SourceSelector;
56
+ } | {
57
+ action: "edit";
58
+ field: "sources";
59
+ selector: SourceSelector;
60
+ patch: Record<string, unknown>;
61
+ }
62
+ /**
63
+ * Select the one entry whose (`resource`, `id`) pair equals the value's, by the shared
64
+ * `sources[]` identity rule, and merge the value's properties into it; append the value when
65
+ * no entry carries the pair. The ID must be nonempty because an upsert may mint it, and it
66
+ * may not already name an entry under another resource.
67
+ */
68
+ | {
69
+ action: "upsert";
70
+ field: "sources";
71
+ value: SourceEntry & {
72
+ id: string;
73
+ };
74
+ } | {
75
+ action: "replace-all";
76
+ field: "tags";
77
+ value: string[];
78
+ } | {
79
+ action: "replace-all";
80
+ field: "sources";
81
+ value: SourceEntry[];
82
+ };
83
+ export interface FieldActionScope {
84
+ field: string;
85
+ action: FieldAction["action"];
86
+ outcome: "added" | "removed" | "edited" | "unchanged" | "replaced";
87
+ selector?: SourceSelector;
88
+ affectedSourceIds?: string[];
89
+ }
90
+ export interface FieldActionContext {
91
+ registry: KindRegistry;
92
+ okfVersion: "0.1" | "0.2";
93
+ now?: () => string;
94
+ }
95
+ export interface PreparedDocumentFieldAction {
96
+ candidate: DocumentMutationCandidate;
97
+ scope: FieldActionScope;
98
+ storageField: string;
99
+ }
100
+ export declare function isStandardDocumentSetField(field: string, okfVersion: "0.1" | "0.2"): boolean;
101
+ export declare function containsCollection(value: unknown): boolean;
102
+ export declare function assertNonCollectionAssignment(field: string, previous: unknown, value: unknown): void;
103
+ export declare function assertOrdinaryPatch(existing: Frontmatter, proposed: Frontmatter): void;
104
+ /** Semantic legacy assignments retain input intent, including explicitly equal assignments. */
105
+ export declare function prepareDocumentAssignments(existing: OkfDocument, assignments: Record<string, unknown>): DocumentMutationCandidate;
106
+ export declare function prepareDocumentFieldAction(existing: OkfDocument, action: FieldAction, context: FieldActionContext): PreparedDocumentFieldAction;
107
+ //# sourceMappingURL=document-field-actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-field-actions.d.ts","sourceRoot":"","sources":["../src/document-field-actions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAmD,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAEhG,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAExE,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AACzF,MAAM,MAAM,cAAc,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,KAAK,CAAA;C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K,GAAG,KAAK,GAAG,OAAO,CAE5F;AAiBD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE1D;AACD,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAOpG;AACD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,GAAG,IAAI,CAItF;AAKD,+FAA+F;AAC/F,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,yBAAyB,CAOjI;AAkCD,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,kBAAkB,GAAG,2BAA2B,CAoI/I"}
@@ -0,0 +1,302 @@
1
+ /** Explicit frontmatter intent. Collection construction is owned here, before CAS metadata. */
2
+ import { isManagedDocumentMetadataField } from "./managed-document-metadata.js";
3
+ import { InvalidInputError } from "./errors.js";
4
+ import { okfValuesEqual } from "./okf-authored-values.js";
5
+ import { kindInputFieldNames, resolveKindFieldCoordinate } from "./kinds.js";
6
+ import { matchesSourceIdentity } from "./query-filter.js";
7
+ /** Adapters can render corrective commands without parsing prose or repeating selection. */
8
+ export class FieldActionError extends InvalidInputError {
9
+ details;
10
+ constructor(message, details) {
11
+ super(message);
12
+ this.name = "FieldActionError";
13
+ this.details = details;
14
+ }
15
+ }
16
+ const standard = new Set(["title", "description", "type", "resource"]);
17
+ const v02 = new Set(["status", "stale_after", "usage_window"]);
18
+ export function isStandardDocumentSetField(field, okfVersion) {
19
+ return standard.has(field) || (okfVersion === "0.2" && v02.has(field));
20
+ }
21
+ function record(value) {
22
+ return value !== null && typeof value === "object" && !Array.isArray(value);
23
+ }
24
+ function has(object, key) { return Object.prototype.hasOwnProperty.call(object, key); }
25
+ function sourceCandidates(rows) {
26
+ return {
27
+ total: rows.length,
28
+ candidates: rows.slice(0, 5).map(row => {
29
+ const identity = {};
30
+ for (const key of ["id", "resource", "title"]) {
31
+ if (record(row) && has(row, key) && typeof row[key] === "string")
32
+ identity[key] = row[key];
33
+ }
34
+ return identity;
35
+ }),
36
+ };
37
+ }
38
+ export function containsCollection(value) {
39
+ return Array.isArray(value) || (record(value) && Object.values(value).some(containsCollection));
40
+ }
41
+ export function assertNonCollectionAssignment(field, previous, value) {
42
+ if (containsCollection(previous) || containsCollection(value)) {
43
+ const correction = field === "tags" || field === "sources"
44
+ ? `Use an explicit ${field} add/remove/replace-all collection action.`
45
+ : "Use complete-document replacement: pull --doc-key <id>.md --out <file>, edit that file, then promote <file> --doc-key <id>.md --expected-version <version-from-pull>.";
46
+ throw new InvalidInputError(`Cannot assign '${field}': the old or new subtree contains a list. ${correction}`);
47
+ }
48
+ }
49
+ export function assertOrdinaryPatch(existing, proposed) {
50
+ for (const field of new Set([...Object.keys(existing), ...Object.keys(proposed)])) {
51
+ if (!okfValuesEqual(existing[field], proposed[field]))
52
+ assertNonCollectionAssignment(field, existing[field], proposed[field]);
53
+ }
54
+ }
55
+ function assertAssignmentName(field) {
56
+ if (isManagedDocumentMetadataField(field))
57
+ throw new InvalidInputError(`'${field}' is managed metadata and cannot be assigned by a field action.`);
58
+ if (field === "tags" || field === "sources")
59
+ throw new InvalidInputError(`'${field}' requires an explicit collection add/remove/replace-all action.`);
60
+ }
61
+ /** Semantic legacy assignments retain input intent, including explicitly equal assignments. */
62
+ export function prepareDocumentAssignments(existing, assignments) {
63
+ if (!record(assignments))
64
+ throw new InvalidInputError("assignments must be a mapping");
65
+ for (const [field, value] of Object.entries(assignments)) {
66
+ assertAssignmentName(field);
67
+ assertNonCollectionAssignment(field, existing.frontmatter[field], value);
68
+ }
69
+ return { frontmatter: { ...existing.frontmatter, ...structuredClone(assignments) }, body: existing.body };
70
+ }
71
+ function sourceRow(value) {
72
+ if (!record(value) || typeof value.resource !== "string" || value.resource.trim() === "")
73
+ throw new InvalidInputError("A source entry requires a nonempty resource string.");
74
+ if (has(value, "id") && typeof value.id !== "string")
75
+ throw new InvalidInputError("A supplied source ID must be a string.");
76
+ }
77
+ function selectorIndex(rows, selector, edit) {
78
+ if (!record(selector) || Object.keys(selector).length !== 1 || !(has(selector, "id") || has(selector, "resource")))
79
+ throw new InvalidInputError("Select one source by exactly one id or resource.");
80
+ const key = has(selector, "id") ? "id" : "resource";
81
+ const value = selector[key];
82
+ // An imported empty ID is still an existing ID; it may be selected exactly but is never minted.
83
+ if (typeof value !== "string" || (key === "resource" && value.trim() === ""))
84
+ throw new InvalidInputError(`Source ${key} selector must be a string.`);
85
+ const matches = rows.flatMap((row, index) => record(row) && has(row, key) && row[key] === value ? [index] : []);
86
+ if (matches.length > 1)
87
+ throw new FieldActionError(`Source selector is ambiguous (${matches.length} matches); inspect sources and use a unique ID or version-guarded replace-all.`, {
88
+ reason: "ambiguous-source", field: "sources", selector: structuredClone(selector), ...sourceCandidates(matches.map(index => rows[index])),
89
+ });
90
+ if (matches.length === 0) {
91
+ if (edit)
92
+ throw new FieldActionError(`Source ${key} '${value}' was not found.`, {
93
+ reason: "source-not-found", field: "sources", selector: structuredClone(selector), ...sourceCandidates([]),
94
+ });
95
+ return -1;
96
+ }
97
+ const index = matches[0];
98
+ if (key === "resource" && has(rows[index], "id")) {
99
+ const id = rows[index].id;
100
+ if (typeof id !== "string")
101
+ throw new FieldActionError("This source has a malformed ID; repair it with version-guarded replace-all.", {
102
+ reason: "invalid-source-id", field: "sources", selector: structuredClone(selector), ...sourceCandidates([rows[index]]),
103
+ });
104
+ throw new FieldActionError(`This resource has source ID '${id}'; select it with --id.`, {
105
+ reason: "source-has-id", field: "sources", selector: structuredClone(selector), recommendedSelector: { id }, ...sourceCandidates([rows[index]]),
106
+ });
107
+ }
108
+ return index;
109
+ }
110
+ export function prepareDocumentFieldAction(existing, action, context) {
111
+ if (!record(action) || typeof action.field !== "string")
112
+ throw new InvalidInputError("A field action requires a field name.");
113
+ if (action.action === "set")
114
+ assertAssignmentName(action.field);
115
+ const keys = action.action === "edit" ? ["action", "field", "selector", "patch"]
116
+ : action.action === "remove" && action.field === "sources" ? ["action", "field", "selector"]
117
+ : ["action", "field", "value"];
118
+ if (Object.keys(action).some(key => !keys.includes(key)) || keys.some(key => !has(action, key)))
119
+ throw new InvalidInputError("Field action has missing or incompatible input properties.");
120
+ if ("value" in action && action.value === undefined)
121
+ throw new InvalidInputError("A field action value must be supplied; removing a field is not supported.");
122
+ let storageField = action.field;
123
+ let candidate = { frontmatter: structuredClone(existing.frontmatter), body: existing.body };
124
+ const scope = { field: action.field, action: action.action, outcome: "unchanged" };
125
+ if (action.action === "set") {
126
+ const kind = context.registry.kinds.get(String(existing.frontmatter.type));
127
+ const coordinate = kind && resolveKindFieldCoordinate(context.okfVersion, kind, action.field);
128
+ if (context.okfVersion === "0.1" && (action.field === "stale_after" || action.field === "usage_window"))
129
+ throw new InvalidInputError(`'${action.field}' requires OKF v0.2.`);
130
+ if (!isStandardDocumentSetField(action.field, context.okfVersion) && !coordinate) {
131
+ const supportedFields = [...new Set([
132
+ ...standard,
133
+ ...(context.okfVersion === "0.2" ? v02 : []),
134
+ ...(kind ? kindInputFieldNames(context.okfVersion, kind) : []),
135
+ ])].filter(field => {
136
+ if (isManagedDocumentMetadataField(field) || field === "tags" || field === "sources")
137
+ return false;
138
+ if (context.okfVersion === "0.1" && (field === "stale_after" || field === "usage_window"))
139
+ return false;
140
+ const storage = kind && resolveKindFieldCoordinate(context.okfVersion, kind, field);
141
+ return !containsCollection(existing.frontmatter[storage?.storageField ?? field]);
142
+ }).sort();
143
+ throw new FieldActionError(`Unsupported set field '${action.field}'; supported fields: ${supportedFields.join(", ")}.`, {
144
+ reason: "unsupported-set-field", field: action.field, supportedFields,
145
+ });
146
+ }
147
+ storageField = coordinate?.storageField ?? action.field;
148
+ candidate = prepareDocumentAssignments(existing, { [storageField]: action.value });
149
+ if (!okfValuesEqual(existing.frontmatter[storageField], action.value))
150
+ scope.outcome = "edited";
151
+ if (scope.outcome !== "unchanged" && context.okfVersion === "0.1")
152
+ candidate.frontmatter.timestamp = (context.now ?? (() => new Date().toISOString()))();
153
+ return { candidate, scope, storageField };
154
+ }
155
+ if (action.field !== "tags" && action.field !== "sources")
156
+ throw new InvalidInputError("Collection actions support only tags and sources.");
157
+ if (!["add", "remove", "edit", "replace-all", "upsert"].includes(action.action))
158
+ throw new InvalidInputError("Unknown field action.");
159
+ if (action.field === "sources" && context.okfVersion !== "0.2")
160
+ throw new InvalidInputError("sources actions require OKF v0.2.");
161
+ const previous = existing.frontmatter[action.field];
162
+ let rows;
163
+ if (action.action === "replace-all") {
164
+ if (!Array.isArray(action.value))
165
+ throw new InvalidInputError("replace-all requires a complete list (including [] to empty it).");
166
+ // Authored-value validation owns row compatibility; replacement permits deliberate duplicates.
167
+ rows = structuredClone(action.value);
168
+ if (action.field === "tags" && rows.some(value => typeof value !== "string"))
169
+ throw new InvalidInputError("tags must be a list of strings.");
170
+ scope.outcome = okfValuesEqual(previous, rows) ? "unchanged" : "replaced";
171
+ }
172
+ else {
173
+ if (previous !== undefined && !Array.isArray(previous))
174
+ throw new InvalidInputError(`'${action.field}' is not a list; repair it with version-guarded replace-all.`);
175
+ rows = structuredClone(previous ?? []);
176
+ if (action.field === "tags") {
177
+ if (["edit", "upsert"].includes(action.action))
178
+ throw new InvalidInputError(`tags supports add/remove/replace-all, not ${action.action}.`);
179
+ if (typeof action.value !== "string")
180
+ throw new InvalidInputError("A tag must be a string.");
181
+ if (action.action === "add" && !rows.includes(action.value)) {
182
+ rows.push(action.value);
183
+ scope.outcome = "added";
184
+ }
185
+ if (action.action === "remove" && rows.includes(action.value)) {
186
+ rows = rows.filter(row => row !== action.value);
187
+ scope.outcome = "removed";
188
+ }
189
+ }
190
+ else if (action.action === "upsert") {
191
+ sourceRow(action.value);
192
+ const value = action.value;
193
+ if (typeof value.id !== "string" || value.id.trim() === "")
194
+ throw new InvalidInputError("A source upsert requires a nonempty id.");
195
+ for (const [property, entry] of Object.entries(value)) {
196
+ if (entry === undefined)
197
+ throw new InvalidInputError("Source upsert properties must have values.");
198
+ if (containsCollection(entry))
199
+ throw new InvalidInputError(`Cannot assign source property '${property}': the new subtree contains a list. Use sources replace-all with an observed version.`);
200
+ }
201
+ const identity = { resource: value.resource, id: value.id };
202
+ const matches = rows.flatMap((row, index) => matchesSourceIdentity(row, identity) ? [index] : []);
203
+ if (matches.length > 1)
204
+ throw new FieldActionError(`Source identity is ambiguous (${matches.length} matches); repair duplicates with version-guarded replace-all.`, {
205
+ reason: "ambiguous-source", field: "sources", selector: { id: value.id }, ...sourceCandidates(matches.map(index => rows[index])),
206
+ });
207
+ scope.affectedSourceIds = [value.id];
208
+ if (matches.length === 1) {
209
+ const old = rows[matches[0]];
210
+ for (const property of Object.keys(value)) {
211
+ if (containsCollection(old[property]))
212
+ throw new InvalidInputError(`Cannot assign source property '${property}': the old subtree contains a list. Use sources replace-all with an observed version.`);
213
+ }
214
+ const next = { ...old, ...structuredClone(value) };
215
+ if (!okfValuesEqual(old, next)) {
216
+ rows[matches[0]] = next;
217
+ scope.outcome = "edited";
218
+ }
219
+ }
220
+ else {
221
+ const sameId = rows.filter(row => record(row) && row.id === value.id);
222
+ if (sameId.length > 0)
223
+ throw new FieldActionError(`Source ID '${value.id}' already names an entry under another resource; a document-local ID is never minted twice.`, {
224
+ reason: "source-id-conflict", field: "sources", selector: { id: value.id }, recommendedSelector: { id: value.id }, ...sourceCandidates(sameId),
225
+ });
226
+ rows.push(structuredClone(value));
227
+ scope.outcome = "added";
228
+ }
229
+ }
230
+ else if (action.action === "add") {
231
+ sourceRow(action.value);
232
+ if (has(action.value, "id")) {
233
+ const matches = rows.filter(row => record(row) && row.id === action.value.id);
234
+ if (matches.length > 1)
235
+ throw new FieldActionError("Source ID is ambiguous; repair duplicate IDs with replace-all.", {
236
+ reason: "ambiguous-source", field: "sources", selector: { id: action.value.id }, ...sourceCandidates(matches),
237
+ });
238
+ if (matches.length === 1 && !okfValuesEqual(matches[0], action.value))
239
+ throw new FieldActionError("Source ID conflicts with an existing entry; use edit with its observed version.", {
240
+ reason: "source-id-conflict", field: "sources", selector: { id: action.value.id }, recommendedSelector: { id: action.value.id }, ...sourceCandidates(matches),
241
+ });
242
+ }
243
+ if (!rows.some(row => okfValuesEqual(row, action.value))) {
244
+ rows.push(structuredClone(action.value));
245
+ scope.outcome = "added";
246
+ }
247
+ if (action.value.id !== undefined)
248
+ scope.affectedSourceIds = [action.value.id];
249
+ }
250
+ else {
251
+ const index = selectorIndex(rows, action.selector, action.action === "edit");
252
+ scope.selector = structuredClone(action.selector);
253
+ if (index >= 0) {
254
+ const old = rows[index];
255
+ if (typeof old.id === "string")
256
+ scope.affectedSourceIds = [old.id];
257
+ if (action.action === "remove") {
258
+ rows.splice(index, 1);
259
+ scope.outcome = "removed";
260
+ }
261
+ else {
262
+ if (!record(action.patch))
263
+ throw new InvalidInputError("A source edit requires a property mapping.");
264
+ for (const [property, value] of Object.entries(action.patch)) {
265
+ if (value === undefined)
266
+ throw new InvalidInputError("Source edit properties must have values.");
267
+ if (containsCollection(old[property]) || containsCollection(value))
268
+ throw new InvalidInputError(`Cannot assign source property '${property}': the old or new subtree contains a list. Use sources replace-all with an observed version.`);
269
+ }
270
+ if (has(action.patch, "id")) {
271
+ if (has(old, "id")) {
272
+ if (action.patch.id !== old.id)
273
+ throw new InvalidInputError("An existing source ID cannot change or be removed; use replace-all.");
274
+ }
275
+ else {
276
+ if (typeof action.patch.id !== "string" || action.patch.id.trim() === "")
277
+ throw new InvalidInputError("The first source ID must be a nonempty string.");
278
+ if (rows.some((row, i) => i !== index && record(row) && row.id === action.patch.id))
279
+ throw new InvalidInputError("The first source ID collides with an existing ID.");
280
+ scope.affectedSourceIds = [action.patch.id];
281
+ }
282
+ }
283
+ const next = { ...old, ...structuredClone(action.patch) };
284
+ if (!okfValuesEqual(old, next)) {
285
+ rows[index] = next;
286
+ scope.outcome = "edited";
287
+ }
288
+ }
289
+ }
290
+ }
291
+ }
292
+ // A missing collection removed from remains missing: a membership no-op writes no normalization.
293
+ if (scope.outcome !== "unchanged")
294
+ candidate.frontmatter[action.field] = rows;
295
+ if (action.field === "sources" && action.action === "replace-all") {
296
+ scope.affectedSourceIds = [...new Set([...(Array.isArray(previous) ? previous : []), ...rows].flatMap(row => record(row) && typeof row.id === "string" ? [row.id] : []))];
297
+ }
298
+ if (scope.outcome !== "unchanged" && context.okfVersion === "0.1")
299
+ candidate.frontmatter.timestamp = (context.now ?? (() => new Date().toISOString()))();
300
+ return { candidate, scope, storageField };
301
+ }
302
+ //# sourceMappingURL=document-field-actions.js.map