@jam-overture/loom 0.1.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.
Files changed (401) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +743 -0
  3. package/dist/catalogue.d.ts +70 -0
  4. package/dist/catalogue.js +88 -0
  5. package/dist/cli/args.d.ts +17 -0
  6. package/dist/cli/args.js +83 -0
  7. package/dist/cli/filesystem.d.ts +15 -0
  8. package/dist/cli/filesystem.js +31 -0
  9. package/dist/cli/index.d.ts +12 -0
  10. package/dist/cli/index.js +12 -0
  11. package/dist/cli/main.d.ts +3 -0
  12. package/dist/cli/main.js +30 -0
  13. package/dist/cli/namespace.d.ts +40 -0
  14. package/dist/cli/namespace.js +40 -0
  15. package/dist/cli/plan.d.ts +84 -0
  16. package/dist/cli/plan.js +113 -0
  17. package/dist/cli/run.d.ts +17 -0
  18. package/dist/cli/run.js +75 -0
  19. package/dist/cli/templates.d.ts +43 -0
  20. package/dist/cli/templates.js +134 -0
  21. package/dist/closed-set.d.ts +34 -0
  22. package/dist/closed-set.js +34 -0
  23. package/dist/data/adapter.d.ts +123 -0
  24. package/dist/data/adapter.js +91 -0
  25. package/dist/data/binding.d.ts +48 -0
  26. package/dist/data/binding.js +39 -0
  27. package/dist/data/catalogue.d.ts +26 -0
  28. package/dist/data/catalogue.js +6 -0
  29. package/dist/data/index.d.ts +14 -0
  30. package/dist/data/index.js +14 -0
  31. package/dist/data/plan.d.ts +58 -0
  32. package/dist/data/plan.js +0 -0
  33. package/dist/data/resolution.d.ts +91 -0
  34. package/dist/data/resolution.js +96 -0
  35. package/dist/data/resolve.d.ts +46 -0
  36. package/dist/data/resolve.js +37 -0
  37. package/dist/data/source.d.ts +40 -0
  38. package/dist/data/source.js +45 -0
  39. package/dist/deadline.d.ts +57 -0
  40. package/dist/deadline.js +78 -0
  41. package/dist/frame/catalogue.d.ts +24 -0
  42. package/dist/frame/catalogue.js +5 -0
  43. package/dist/frame/index.d.ts +12 -0
  44. package/dist/frame/index.js +12 -0
  45. package/dist/frame/origin.d.ts +87 -0
  46. package/dist/frame/origin.js +114 -0
  47. package/dist/frame/resolution.d.ts +85 -0
  48. package/dist/frame/resolution.js +79 -0
  49. package/dist/grammar.d.ts +26 -0
  50. package/dist/grammar.js +28 -0
  51. package/dist/ids.d.ts +57 -0
  52. package/dist/ids.js +104 -0
  53. package/dist/index.d.ts +26 -0
  54. package/dist/index.js +26 -0
  55. package/dist/interactivity.d.ts +50 -0
  56. package/dist/interactivity.js +22 -0
  57. package/dist/interpretation/anthropic.d.ts +22 -0
  58. package/dist/interpretation/anthropic.js +76 -0
  59. package/dist/interpretation/client.d.ts +83 -0
  60. package/dist/interpretation/client.js +2 -0
  61. package/dist/interpretation/draft.d.ts +234 -0
  62. package/dist/interpretation/draft.js +84 -0
  63. package/dist/interpretation/index.d.ts +15 -0
  64. package/dist/interpretation/index.js +15 -0
  65. package/dist/interpretation/interpreter.d.ts +62 -0
  66. package/dist/interpretation/interpreter.js +151 -0
  67. package/dist/interpretation/materialize.d.ts +42 -0
  68. package/dist/interpretation/materialize.js +107 -0
  69. package/dist/interpretation/prompt.d.ts +229 -0
  70. package/dist/interpretation/prompt.js +285 -0
  71. package/dist/interpretation/render.d.ts +76 -0
  72. package/dist/interpretation/render.js +272 -0
  73. package/dist/interpretation/schema.d.ts +49 -0
  74. package/dist/interpretation/schema.js +131 -0
  75. package/dist/json.d.ts +35 -0
  76. package/dist/json.js +11 -0
  77. package/dist/paging.d.ts +60 -0
  78. package/dist/paging.js +49 -0
  79. package/dist/primitive-type.d.ts +32 -0
  80. package/dist/primitive-type.js +39 -0
  81. package/dist/render/addressing.d.ts +59 -0
  82. package/dist/render/addressing.js +60 -0
  83. package/dist/render/anchor.d.ts +105 -0
  84. package/dist/render/anchor.js +84 -0
  85. package/dist/render/behaviour-adjust.d.ts +62 -0
  86. package/dist/render/behaviour-adjust.js +78 -0
  87. package/dist/render/behaviour-copy.d.ts +53 -0
  88. package/dist/render/behaviour-copy.js +75 -0
  89. package/dist/render/behaviour-disclose.d.ts +74 -0
  90. package/dist/render/behaviour-disclose.js +77 -0
  91. package/dist/render/behaviour-present.d.ts +123 -0
  92. package/dist/render/behaviour-present.js +173 -0
  93. package/dist/render/behaviour.d.ts +243 -0
  94. package/dist/render/behaviour.js +284 -0
  95. package/dist/render/control.d.ts +81 -0
  96. package/dist/render/control.js +80 -0
  97. package/dist/render/decorative.d.ts +62 -0
  98. package/dist/render/decorative.js +2 -0
  99. package/dist/render/diagnostics.d.ts +260 -0
  100. package/dist/render/diagnostics.js +61 -0
  101. package/dist/render/disclosed.d.ts +37 -0
  102. package/dist/render/disclosed.js +37 -0
  103. package/dist/render/editable.d.ts +34 -0
  104. package/dist/render/editable.js +35 -0
  105. package/dist/render/frame.d.ts +42 -0
  106. package/dist/render/frame.js +31 -0
  107. package/dist/render/index.d.ts +35 -0
  108. package/dist/render/index.js +35 -0
  109. package/dist/render/inline-variables.d.ts +77 -0
  110. package/dist/render/inline-variables.js +220 -0
  111. package/dist/render/presented.d.ts +82 -0
  112. package/dist/render/presented.js +82 -0
  113. package/dist/render/primitive.d.ts +228 -0
  114. package/dist/render/primitive.js +36 -0
  115. package/dist/render/props.d.ts +48 -0
  116. package/dist/render/props.js +2 -0
  117. package/dist/render/reads.d.ts +73 -0
  118. package/dist/render/reads.js +45 -0
  119. package/dist/render/render.d.ts +164 -0
  120. package/dist/render/render.js +571 -0
  121. package/dist/render/request.d.ts +111 -0
  122. package/dist/render/request.js +60 -0
  123. package/dist/render/text.d.ts +91 -0
  124. package/dist/render/text.js +44 -0
  125. package/dist/render/theme.d.ts +61 -0
  126. package/dist/render/theme.js +52 -0
  127. package/dist/reserved-props.d.ts +35 -0
  128. package/dist/reserved-props.js +45 -0
  129. package/dist/result.d.ts +27 -0
  130. package/dist/result.js +30 -0
  131. package/dist/role.d.ts +71 -0
  132. package/dist/role.js +22 -0
  133. package/dist/runtime/analysis.d.ts +149 -0
  134. package/dist/runtime/analysis.js +187 -0
  135. package/dist/runtime/assessment.d.ts +35 -0
  136. package/dist/runtime/assessment.js +13 -0
  137. package/dist/runtime/disposition.d.ts +102 -0
  138. package/dist/runtime/disposition.js +59 -0
  139. package/dist/runtime/events.d.ts +187 -0
  140. package/dist/runtime/events.js +7 -0
  141. package/dist/runtime/gate.d.ts +43 -0
  142. package/dist/runtime/gate.js +169 -0
  143. package/dist/runtime/index.d.ts +27 -0
  144. package/dist/runtime/index.js +27 -0
  145. package/dist/runtime/intent.d.ts +60 -0
  146. package/dist/runtime/intent.js +36 -0
  147. package/dist/runtime/interpreter.d.ts +117 -0
  148. package/dist/runtime/interpreter.js +46 -0
  149. package/dist/runtime/inverse-interpreter.d.ts +90 -0
  150. package/dist/runtime/inverse-interpreter.js +56 -0
  151. package/dist/runtime/inverse.d.ts +87 -0
  152. package/dist/runtime/inverse.js +48 -0
  153. package/dist/runtime/narration.d.ts +24 -0
  154. package/dist/runtime/narration.js +36 -0
  155. package/dist/runtime/nesting.d.ts +31 -0
  156. package/dist/runtime/nesting.js +46 -0
  157. package/dist/runtime/pipeline.d.ts +124 -0
  158. package/dist/runtime/pipeline.js +178 -0
  159. package/dist/runtime/policy-fingerprint.d.ts +29 -0
  160. package/dist/runtime/policy-fingerprint.js +119 -0
  161. package/dist/runtime/policy-source.d.ts +42 -0
  162. package/dist/runtime/policy-source.js +8 -0
  163. package/dist/runtime/policy.d.ts +156 -0
  164. package/dist/runtime/policy.js +107 -0
  165. package/dist/runtime/proposal.d.ts +423 -0
  166. package/dist/runtime/proposal.js +109 -0
  167. package/dist/runtime/redirection.d.ts +53 -0
  168. package/dist/runtime/redirection.js +38 -0
  169. package/dist/runtime/repointing.d.ts +71 -0
  170. package/dist/runtime/repointing.js +0 -0
  171. package/dist/runtime/reversibility.d.ts +36 -0
  172. package/dist/runtime/reversibility.js +39 -0
  173. package/dist/runtime/stake-level.d.ts +33 -0
  174. package/dist/runtime/stake-level.js +58 -0
  175. package/dist/runtime/stakes.d.ts +47 -0
  176. package/dist/runtime/stakes.js +305 -0
  177. package/dist/runtime/vocabulary.d.ts +122 -0
  178. package/dist/runtime/vocabulary.js +87 -0
  179. package/dist/sdk/audit.d.ts +195 -0
  180. package/dist/sdk/audit.js +128 -0
  181. package/dist/sdk/catalogue.d.ts +37 -0
  182. package/dist/sdk/catalogue.js +16 -0
  183. package/dist/sdk/conformance.d.ts +342 -0
  184. package/dist/sdk/conformance.js +494 -0
  185. package/dist/sdk/copy.d.ts +105 -0
  186. package/dist/sdk/copy.js +90 -0
  187. package/dist/sdk/definition.d.ts +242 -0
  188. package/dist/sdk/definition.js +64 -0
  189. package/dist/sdk/index.d.ts +19 -0
  190. package/dist/sdk/index.js +19 -0
  191. package/dist/sdk/interactivity.d.ts +29 -0
  192. package/dist/sdk/interactivity.js +34 -0
  193. package/dist/sdk/pairings.d.ts +124 -0
  194. package/dist/sdk/pairings.js +81 -0
  195. package/dist/sdk/registry.d.ts +162 -0
  196. package/dist/sdk/registry.js +329 -0
  197. package/dist/sdk/selection.d.ts +46 -0
  198. package/dist/sdk/selection.js +24 -0
  199. package/dist/sdk/text.d.ts +100 -0
  200. package/dist/sdk/text.js +105 -0
  201. package/dist/sdk/vocabulary.d.ts +39 -0
  202. package/dist/sdk/vocabulary.js +36 -0
  203. package/dist/signals/broadcast.d.ts +134 -0
  204. package/dist/signals/broadcast.js +451 -0
  205. package/dist/signals/collect.d.ts +184 -0
  206. package/dist/signals/collect.js +196 -0
  207. package/dist/signals/deliver.d.ts +64 -0
  208. package/dist/signals/deliver.js +85 -0
  209. package/dist/signals/fold.d.ts +112 -0
  210. package/dist/signals/fold.js +76 -0
  211. package/dist/signals/index.d.ts +31 -0
  212. package/dist/signals/index.js +31 -0
  213. package/dist/signals/ingest.d.ts +51 -0
  214. package/dist/signals/ingest.js +70 -0
  215. package/dist/signals/intake.d.ts +149 -0
  216. package/dist/signals/intake.js +154 -0
  217. package/dist/signals/journal.d.ts +94 -0
  218. package/dist/signals/journal.js +11 -0
  219. package/dist/signals/kinds.d.ts +22 -0
  220. package/dist/signals/kinds.js +22 -0
  221. package/dist/signals/ledger.d.ts +46 -0
  222. package/dist/signals/ledger.js +81 -0
  223. package/dist/signals/memory.d.ts +17 -0
  224. package/dist/signals/memory.js +99 -0
  225. package/dist/signals/migrate.d.ts +27 -0
  226. package/dist/signals/migrate.js +78 -0
  227. package/dist/signals/postgres.d.ts +7 -0
  228. package/dist/signals/postgres.js +295 -0
  229. package/dist/signals/rollup.d.ts +142 -0
  230. package/dist/signals/rollup.js +0 -0
  231. package/dist/signals/schema.d.ts +534 -0
  232. package/dist/signals/schema.js +92 -0
  233. package/dist/signals/signal.d.ts +381 -0
  234. package/dist/signals/signal.js +150 -0
  235. package/dist/signals/tally.d.ts +70 -0
  236. package/dist/signals/tally.js +2 -0
  237. package/dist/signals/view.d.ts +51 -0
  238. package/dist/signals/view.js +54 -0
  239. package/dist/store/attribution.d.ts +125 -0
  240. package/dist/store/attribution.js +116 -0
  241. package/dist/store/database.d.ts +14 -0
  242. package/dist/store/database.js +2 -0
  243. package/dist/store/driver.d.ts +29 -0
  244. package/dist/store/driver.js +39 -0
  245. package/dist/store/errors.d.ts +56 -0
  246. package/dist/store/errors.js +37 -0
  247. package/dist/store/index.d.ts +16 -0
  248. package/dist/store/index.js +16 -0
  249. package/dist/store/memory.d.ts +3 -0
  250. package/dist/store/memory.js +115 -0
  251. package/dist/store/migrate.d.ts +54 -0
  252. package/dist/store/migrate.js +122 -0
  253. package/dist/store/postgres-holds.d.ts +4 -0
  254. package/dist/store/postgres-holds.js +192 -0
  255. package/dist/store/postgres.d.ts +8 -0
  256. package/dist/store/postgres.js +262 -0
  257. package/dist/store/replay.d.ts +94 -0
  258. package/dist/store/replay.js +82 -0
  259. package/dist/store/revert.d.ts +116 -0
  260. package/dist/store/revert.js +243 -0
  261. package/dist/store/schema.d.ts +371 -0
  262. package/dist/store/schema.js +78 -0
  263. package/dist/store/source.d.ts +23 -0
  264. package/dist/store/source.js +37 -0
  265. package/dist/store/store.d.ts +231 -0
  266. package/dist/store/store.js +52 -0
  267. package/dist/store/undone.d.ts +18 -0
  268. package/dist/store/undone.js +89 -0
  269. package/dist/submit/catalogue.d.ts +20 -0
  270. package/dist/submit/catalogue.js +5 -0
  271. package/dist/submit/declaration.d.ts +39 -0
  272. package/dist/submit/declaration.js +30 -0
  273. package/dist/submit/endpoint.d.ts +131 -0
  274. package/dist/submit/endpoint.js +160 -0
  275. package/dist/submit/index.d.ts +13 -0
  276. package/dist/submit/index.js +13 -0
  277. package/dist/submit/plan.d.ts +49 -0
  278. package/dist/submit/plan.js +47 -0
  279. package/dist/submit/resolution.d.ts +61 -0
  280. package/dist/submit/resolution.js +64 -0
  281. package/dist/submit/resolve.d.ts +45 -0
  282. package/dist/submit/resolve.js +36 -0
  283. package/dist/telemetry/calibration.d.ts +132 -0
  284. package/dist/telemetry/calibration.js +151 -0
  285. package/dist/telemetry/episode.d.ts +140 -0
  286. package/dist/telemetry/episode.js +272 -0
  287. package/dist/telemetry/event.d.ts +2310 -0
  288. package/dist/telemetry/event.js +405 -0
  289. package/dist/telemetry/index.d.ts +15 -0
  290. package/dist/telemetry/index.js +15 -0
  291. package/dist/telemetry/journal.d.ts +116 -0
  292. package/dist/telemetry/journal.js +11 -0
  293. package/dist/telemetry/memory.d.ts +24 -0
  294. package/dist/telemetry/memory.js +75 -0
  295. package/dist/telemetry/migrate.d.ts +26 -0
  296. package/dist/telemetry/migrate.js +40 -0
  297. package/dist/telemetry/postgres.d.ts +6 -0
  298. package/dist/telemetry/postgres.js +139 -0
  299. package/dist/telemetry/retention.d.ts +131 -0
  300. package/dist/telemetry/retention.js +217 -0
  301. package/dist/telemetry/schema.d.ts +113 -0
  302. package/dist/telemetry/schema.js +33 -0
  303. package/dist/telemetry/sink.d.ts +42 -0
  304. package/dist/telemetry/sink.js +61 -0
  305. package/dist/testing/contracts.d.ts +34 -0
  306. package/dist/testing/contracts.js +34 -0
  307. package/dist/testing/definitions.d.ts +15 -0
  308. package/dist/testing/definitions.js +48 -0
  309. package/dist/testing/doubles.d.ts +94 -0
  310. package/dist/testing/doubles.js +141 -0
  311. package/dist/testing/episode-harness.d.ts +49 -0
  312. package/dist/testing/episode-harness.js +65 -0
  313. package/dist/testing/filesystem.d.ts +17 -0
  314. package/dist/testing/filesystem.js +17 -0
  315. package/dist/testing/fixtures.d.ts +57 -0
  316. package/dist/testing/fixtures.js +84 -0
  317. package/dist/testing/hold-contract.d.ts +19 -0
  318. package/dist/testing/hold-contract.js +374 -0
  319. package/dist/testing/index.d.ts +41 -0
  320. package/dist/testing/index.js +41 -0
  321. package/dist/testing/journal-contract.d.ts +17 -0
  322. package/dist/testing/journal-contract.js +353 -0
  323. package/dist/testing/model-replies.d.ts +34 -0
  324. package/dist/testing/model-replies.js +101 -0
  325. package/dist/testing/primitives.d.ts +7 -0
  326. package/dist/testing/primitives.js +29 -0
  327. package/dist/testing/reader-signal-contract.d.ts +38 -0
  328. package/dist/testing/reader-signal-contract.js +318 -0
  329. package/dist/testing/row-security.d.ts +17 -0
  330. package/dist/testing/row-security.js +21 -0
  331. package/dist/testing/store-contract.d.ts +25 -0
  332. package/dist/testing/store-contract.js +500 -0
  333. package/dist/theme/apply.d.ts +17 -0
  334. package/dist/theme/apply.js +60 -0
  335. package/dist/theme/contrast.d.ts +197 -0
  336. package/dist/theme/contrast.js +259 -0
  337. package/dist/theme/derive.d.ts +77 -0
  338. package/dist/theme/derive.js +167 -0
  339. package/dist/theme/faces.d.ts +73 -0
  340. package/dist/theme/faces.js +119 -0
  341. package/dist/theme/font-packs.d.ts +25 -0
  342. package/dist/theme/font-packs.js +257 -0
  343. package/dist/theme/index.d.ts +20 -0
  344. package/dist/theme/index.js +20 -0
  345. package/dist/theme/lab.d.ts +30 -0
  346. package/dist/theme/lab.js +46 -0
  347. package/dist/theme/library.d.ts +114 -0
  348. package/dist/theme/library.js +300 -0
  349. package/dist/theme/measure.d.ts +144 -0
  350. package/dist/theme/measure.js +145 -0
  351. package/dist/theme/palettes.d.ts +64 -0
  352. package/dist/theme/palettes.js +497 -0
  353. package/dist/theme/registry.d.ts +59 -0
  354. package/dist/theme/registry.js +60 -0
  355. package/dist/theme/separation.d.ts +177 -0
  356. package/dist/theme/separation.js +203 -0
  357. package/dist/theme/style-presets.d.ts +60 -0
  358. package/dist/theme/style-presets.js +124 -0
  359. package/dist/theme/theme.d.ts +253 -0
  360. package/dist/theme/theme.js +171 -0
  361. package/dist/tree/apply.d.ts +16 -0
  362. package/dist/tree/apply.js +104 -0
  363. package/dist/tree/builders.d.ts +19 -0
  364. package/dist/tree/builders.js +20 -0
  365. package/dist/tree/compare.d.ts +68 -0
  366. package/dist/tree/compare.js +75 -0
  367. package/dist/tree/configuration.d.ts +25 -0
  368. package/dist/tree/configuration.js +108 -0
  369. package/dist/tree/delta.d.ts +288 -0
  370. package/dist/tree/delta.js +88 -0
  371. package/dist/tree/errors.d.ts +69 -0
  372. package/dist/tree/errors.js +34 -0
  373. package/dist/tree/identity.d.ts +117 -0
  374. package/dist/tree/identity.js +145 -0
  375. package/dist/tree/index.d.ts +21 -0
  376. package/dist/tree/index.js +21 -0
  377. package/dist/tree/inverse.d.ts +24 -0
  378. package/dist/tree/inverse.js +112 -0
  379. package/dist/tree/mutation.d.ts +18 -0
  380. package/dist/tree/mutation.js +49 -0
  381. package/dist/tree/naming.d.ts +4 -0
  382. package/dist/tree/naming.js +35 -0
  383. package/dist/tree/navigation.d.ts +38 -0
  384. package/dist/tree/navigation.js +83 -0
  385. package/dist/tree/node.d.ts +103 -0
  386. package/dist/tree/node.js +46 -0
  387. package/dist/tree/outline.d.ts +28 -0
  388. package/dist/tree/outline.js +10 -0
  389. package/dist/tree/tree.d.ts +83 -0
  390. package/dist/tree/tree.js +62 -0
  391. package/dist/write/commit.d.ts +124 -0
  392. package/dist/write/commit.js +234 -0
  393. package/dist/write/held.d.ts +674 -0
  394. package/dist/write/held.js +185 -0
  395. package/dist/write/index.d.ts +11 -0
  396. package/dist/write/index.js +11 -0
  397. package/dist/write/liveness.d.ts +132 -0
  398. package/dist/write/liveness.js +91 -0
  399. package/dist/write/revert.d.ts +79 -0
  400. package/dist/write/revert.js +134 -0
  401. package/package.json +160 -0
@@ -0,0 +1,75 @@
1
+ import { nodeLabel } from "./node.js";
2
+ import { outlineTree } from "./outline.js";
3
+ /**
4
+ * Props are compared by their serialisation rather than key by key.
5
+ *
6
+ * Every prop is JSON by construction, and `JSON.stringify` is order-sensitive on
7
+ * object keys — which is correct here and not a false positive waiting to
8
+ * happen: a delta rewrites a props bag wholesale (0009), so two bags that differ
9
+ * only in key order came from two different writes, and an audit that called
10
+ * them equal would be hiding one of them.
11
+ */
12
+ const sameJson = (left, right) => JSON.stringify(left) === JSON.stringify(right);
13
+ const facetsOf = (base, compared) => {
14
+ if (base.kind !== compared.kind)
15
+ return ["kind"];
16
+ if (base.kind === "element" && compared.kind === "element") {
17
+ return [
18
+ ...(base.type === compared.type ? [] : ["type"]),
19
+ ...(sameJson(base.props, compared.props) ? [] : ["props"]),
20
+ ];
21
+ }
22
+ if (base.kind === "slot" && compared.kind === "slot") {
23
+ return base.name === compared.name ? [] : ["name"];
24
+ }
25
+ if (base.kind === "text" && compared.kind === "text") {
26
+ return base.value === compared.value ? [] : ["text"];
27
+ }
28
+ return [];
29
+ };
30
+ const placedById = (tree) => new Map(outlineTree(tree.root).map((entry) => [
31
+ entry.node.id,
32
+ { node: entry.node, parentId: entry.parentId, index: entry.index },
33
+ ]));
34
+ const differenceFor = (base, compared) => {
35
+ const facets = [
36
+ ...facetsOf(base.node, compared.node),
37
+ ...(base.parentId === compared.parentId ? [] : ["parent"]),
38
+ ...(base.index === compared.index ? [] : ["position"]),
39
+ ];
40
+ return facets.length === 0
41
+ ? undefined
42
+ : { code: "changed", nodeId: base.node.id, label: nodeLabel(base.node), facets };
43
+ };
44
+ /**
45
+ * Every way `compared` differs from `base`, one entry per node.
46
+ *
47
+ * In document order of whichever tree holds the node, base first: a reader is
48
+ * looking at a tree, and a list ordered by id would scatter one broken subtree
49
+ * across the whole report.
50
+ *
51
+ * A moved node produces one `changed` with a `parent` or `position` facet, not a
52
+ * `missing` and an `extra`. The id is what makes that possible, and it is the
53
+ * reason this is worth having over a structural diff — a structural diff of a
54
+ * moved card reports the entire subtree twice.
55
+ */
56
+ export const compareTrees = (base, compared) => {
57
+ const left = placedById(base);
58
+ const right = placedById(compared);
59
+ const fromBase = Array.from(left.entries()).flatMap(([nodeId, placed]) => {
60
+ const other = right.get(nodeId);
61
+ if (other === undefined)
62
+ return [{ code: "missing", nodeId, label: nodeLabel(placed.node) }];
63
+ const difference = differenceFor(placed, other);
64
+ return difference === undefined ? [] : [difference];
65
+ });
66
+ const onlyCompared = Array.from(right.entries())
67
+ .filter(([nodeId]) => !left.has(nodeId))
68
+ .map(([nodeId, placed]) => ({
69
+ code: "extra",
70
+ nodeId,
71
+ label: nodeLabel(placed.node),
72
+ }));
73
+ return [...fromBase, ...onlyCompared];
74
+ };
75
+ //# sourceMappingURL=compare.js.map
@@ -0,0 +1,25 @@
1
+ import type { JsonObject } from "../json.js";
2
+ import { type Result } from "../result.js";
3
+ import type { TreeError } from "./errors.js";
4
+ import type { LoomNode } from "./node.js";
5
+ /**
6
+ * `configure` is one operation across three node kinds, so each kind exposes
7
+ * its settable surface as a plain JSON record:
8
+ *
9
+ * - element → its props, an open key space
10
+ * - text → `{ value }`
11
+ * - slot → `{ name }`
12
+ *
13
+ * Element props are open because the primitive owns their meaning; text and
14
+ * slot expose exactly one required key each, so unsetting it is rejected
15
+ * rather than silently producing a malformed node. Keeping the surface uniform
16
+ * is what lets the delta model stay at four operations instead of growing one
17
+ * per node kind.
18
+ */
19
+ export declare const configurationOf: (node: LoomNode) => JsonObject;
20
+ export type NodeConfigurationPatch = {
21
+ readonly set: JsonObject;
22
+ readonly unset: readonly string[];
23
+ };
24
+ export declare const configureNode: (node: LoomNode, patch: NodeConfigurationPatch) => Result<LoomNode, TreeError>;
25
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1,108 @@
1
+ import { slotNameSchema } from "../primitive-type.js";
2
+ import { assertNever, err, ok } from "../result.js";
3
+ /**
4
+ * `configure` is one operation across three node kinds, so each kind exposes
5
+ * its settable surface as a plain JSON record:
6
+ *
7
+ * - element → its props, an open key space
8
+ * - text → `{ value }`
9
+ * - slot → `{ name }`
10
+ *
11
+ * Element props are open because the primitive owns their meaning; text and
12
+ * slot expose exactly one required key each, so unsetting it is rejected
13
+ * rather than silently producing a malformed node. Keeping the surface uniform
14
+ * is what lets the delta model stay at four operations instead of growing one
15
+ * per node kind.
16
+ */
17
+ export const configurationOf = (node) => {
18
+ switch (node.kind) {
19
+ case "element":
20
+ return node.props;
21
+ case "text":
22
+ return { value: node.value };
23
+ case "slot":
24
+ return { name: node.name };
25
+ default:
26
+ return assertNever(node, "configurationOf");
27
+ }
28
+ };
29
+ const applyPatch = (base, patch) => {
30
+ const merged = { ...base, ...patch.set };
31
+ for (const key of patch.unset)
32
+ delete merged[key];
33
+ return merged;
34
+ };
35
+ const fixedKeyPatch = (node, patch, key) => {
36
+ const rejectedKey = Object.keys(patch.set).find((candidate) => candidate !== key) ??
37
+ patch.unset.find((candidate) => candidate !== key);
38
+ if (rejectedKey !== undefined) {
39
+ return err({
40
+ code: "unconfigurable-key",
41
+ nodeId: node.id,
42
+ nodeKind: node.kind,
43
+ key: rejectedKey,
44
+ });
45
+ }
46
+ if (patch.unset.includes(key)) {
47
+ return err({
48
+ code: "invalid-configuration",
49
+ nodeId: node.id,
50
+ nodeKind: node.kind,
51
+ detail: `"${key}" is required and cannot be unset`,
52
+ });
53
+ }
54
+ return ok(applyPatch(configurationOf(node), patch));
55
+ };
56
+ const configureElement = (node, patch) => ok({ ...node, props: applyPatch(node.props, patch) });
57
+ const configureText = (node, patch) => {
58
+ const patched = fixedKeyPatch(node, patch, "value");
59
+ if (!patched.ok)
60
+ return patched;
61
+ const value = patched.value["value"];
62
+ if (typeof value !== "string") {
63
+ return err({
64
+ code: "invalid-configuration",
65
+ nodeId: node.id,
66
+ nodeKind: node.kind,
67
+ detail: `"value" must be a string`,
68
+ });
69
+ }
70
+ return ok({ ...node, value });
71
+ };
72
+ const configureSlot = (node, patch) => {
73
+ const patched = fixedKeyPatch(node, patch, "name");
74
+ if (!patched.ok)
75
+ return patched;
76
+ const parsed = slotNameSchema.safeParse(patched.value["name"]);
77
+ if (!parsed.success) {
78
+ return err({
79
+ code: "invalid-configuration",
80
+ nodeId: node.id,
81
+ nodeKind: node.kind,
82
+ detail: `"name" must be a camelCase slot name`,
83
+ });
84
+ }
85
+ return ok({ ...node, name: parsed.data });
86
+ };
87
+ export const configureNode = (node, patch) => {
88
+ const collision = patch.unset.find((key) => key in patch.set);
89
+ if (collision !== undefined) {
90
+ return err({
91
+ code: "invalid-configuration",
92
+ nodeId: node.id,
93
+ nodeKind: node.kind,
94
+ detail: `"${collision}" appears in both set and unset`,
95
+ });
96
+ }
97
+ switch (node.kind) {
98
+ case "element":
99
+ return configureElement(node, patch);
100
+ case "text":
101
+ return configureText(node, patch);
102
+ case "slot":
103
+ return configureSlot(node, patch);
104
+ default:
105
+ return assertNever(node, "configureNode");
106
+ }
107
+ };
108
+ //# sourceMappingURL=configuration.js.map
@@ -0,0 +1,288 @@
1
+ import { z } from "zod";
2
+ import { type DeltaId, type NodeId, type TreeId } from "../ids.js";
3
+ import { type JsonObject } from "../json.js";
4
+ import { type Result } from "../result.js";
5
+ import type { TreeError } from "./errors.js";
6
+ import { type LoomNode } from "./node.js";
7
+ /**
8
+ * A TreeDelta is the only way a tree changes.
9
+ *
10
+ * Four discrete operations, chosen so that every structural edit is expressible
11
+ * and every operation is individually reviewable by the Gate: you can reason
12
+ * about "insert a checkout button into the sidebar" without diffing two trees.
13
+ * A whole-tree replacement would collapse that reasoning into a single opaque
14
+ * change, so it is deliberately not an operation.
15
+ *
16
+ * Operations within a delta are ordered and applied atomically — a delta that
17
+ * fails halfway leaves the tree untouched. Each operation observes the effects
18
+ * of the ones before it, so `index` in a `move` refers to the child list
19
+ * *after* the node has been detached.
20
+ */
21
+ export declare const insertOperationSchema: z.ZodObject<{
22
+ op: z.ZodLiteral<"insert">;
23
+ parentId: z.ZodBranded<z.ZodString, "NodeId">;
24
+ index: z.ZodNumber;
25
+ node: z.ZodType<LoomNode, z.ZodTypeDef, unknown>;
26
+ }, "strip", z.ZodTypeAny, {
27
+ index: number;
28
+ op: "insert";
29
+ parentId: string & z.BRAND<"NodeId">;
30
+ node: LoomNode;
31
+ }, {
32
+ index: number;
33
+ op: "insert";
34
+ parentId: string;
35
+ node?: unknown;
36
+ }>;
37
+ export declare const removeOperationSchema: z.ZodObject<{
38
+ op: z.ZodLiteral<"remove">;
39
+ nodeId: z.ZodBranded<z.ZodString, "NodeId">;
40
+ }, "strip", z.ZodTypeAny, {
41
+ op: "remove";
42
+ nodeId: string & z.BRAND<"NodeId">;
43
+ }, {
44
+ op: "remove";
45
+ nodeId: string;
46
+ }>;
47
+ export declare const moveOperationSchema: z.ZodObject<{
48
+ op: z.ZodLiteral<"move">;
49
+ nodeId: z.ZodBranded<z.ZodString, "NodeId">;
50
+ parentId: z.ZodBranded<z.ZodString, "NodeId">;
51
+ index: z.ZodNumber;
52
+ }, "strip", z.ZodTypeAny, {
53
+ index: number;
54
+ op: "move";
55
+ parentId: string & z.BRAND<"NodeId">;
56
+ nodeId: string & z.BRAND<"NodeId">;
57
+ }, {
58
+ index: number;
59
+ op: "move";
60
+ parentId: string;
61
+ nodeId: string;
62
+ }>;
63
+ export declare const configureOperationSchema: z.ZodObject<{
64
+ op: z.ZodLiteral<"configure">;
65
+ nodeId: z.ZodBranded<z.ZodString, "NodeId">;
66
+ set: z.ZodDefault<z.ZodType<JsonObject, z.ZodTypeDef, JsonObject>>;
67
+ unset: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
68
+ }, "strip", z.ZodTypeAny, {
69
+ set: JsonObject;
70
+ op: "configure";
71
+ nodeId: string & z.BRAND<"NodeId">;
72
+ unset: string[];
73
+ }, {
74
+ op: "configure";
75
+ nodeId: string;
76
+ set?: JsonObject | undefined;
77
+ unset?: string[] | undefined;
78
+ }>;
79
+ export declare const treeOperationSchema: z.ZodDiscriminatedUnion<"op", [z.ZodObject<{
80
+ op: z.ZodLiteral<"insert">;
81
+ parentId: z.ZodBranded<z.ZodString, "NodeId">;
82
+ index: z.ZodNumber;
83
+ node: z.ZodType<LoomNode, z.ZodTypeDef, unknown>;
84
+ }, "strip", z.ZodTypeAny, {
85
+ index: number;
86
+ op: "insert";
87
+ parentId: string & z.BRAND<"NodeId">;
88
+ node: LoomNode;
89
+ }, {
90
+ index: number;
91
+ op: "insert";
92
+ parentId: string;
93
+ node?: unknown;
94
+ }>, z.ZodObject<{
95
+ op: z.ZodLiteral<"remove">;
96
+ nodeId: z.ZodBranded<z.ZodString, "NodeId">;
97
+ }, "strip", z.ZodTypeAny, {
98
+ op: "remove";
99
+ nodeId: string & z.BRAND<"NodeId">;
100
+ }, {
101
+ op: "remove";
102
+ nodeId: string;
103
+ }>, z.ZodObject<{
104
+ op: z.ZodLiteral<"move">;
105
+ nodeId: z.ZodBranded<z.ZodString, "NodeId">;
106
+ parentId: z.ZodBranded<z.ZodString, "NodeId">;
107
+ index: z.ZodNumber;
108
+ }, "strip", z.ZodTypeAny, {
109
+ index: number;
110
+ op: "move";
111
+ parentId: string & z.BRAND<"NodeId">;
112
+ nodeId: string & z.BRAND<"NodeId">;
113
+ }, {
114
+ index: number;
115
+ op: "move";
116
+ parentId: string;
117
+ nodeId: string;
118
+ }>, z.ZodObject<{
119
+ op: z.ZodLiteral<"configure">;
120
+ nodeId: z.ZodBranded<z.ZodString, "NodeId">;
121
+ set: z.ZodDefault<z.ZodType<JsonObject, z.ZodTypeDef, JsonObject>>;
122
+ unset: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
123
+ }, "strip", z.ZodTypeAny, {
124
+ set: JsonObject;
125
+ op: "configure";
126
+ nodeId: string & z.BRAND<"NodeId">;
127
+ unset: string[];
128
+ }, {
129
+ op: "configure";
130
+ nodeId: string;
131
+ set?: JsonObject | undefined;
132
+ unset?: string[] | undefined;
133
+ }>]>;
134
+ export type InsertOperation = {
135
+ readonly op: "insert";
136
+ readonly parentId: NodeId;
137
+ readonly index: number;
138
+ readonly node: LoomNode;
139
+ };
140
+ export type RemoveOperation = {
141
+ readonly op: "remove";
142
+ readonly nodeId: NodeId;
143
+ };
144
+ export type MoveOperation = {
145
+ readonly op: "move";
146
+ readonly nodeId: NodeId;
147
+ readonly parentId: NodeId;
148
+ readonly index: number;
149
+ };
150
+ export type ConfigureOperation = {
151
+ readonly op: "configure";
152
+ readonly nodeId: NodeId;
153
+ readonly set: JsonObject;
154
+ readonly unset: readonly string[];
155
+ };
156
+ export type TreeOperation = InsertOperation | RemoveOperation | MoveOperation | ConfigureOperation;
157
+ export type TreeOperationName = TreeOperation["op"];
158
+ /**
159
+ * The whole vocabulary of structural change, in the order the doc comment above
160
+ * argues it.
161
+ *
162
+ * Four is a claim this project makes about itself in prose — on the front door,
163
+ * in the course, in the reference — and until now every one of those was a digit
164
+ * somebody typed. A sentence that counts a list in `src/` and cannot be checked
165
+ * against it is the shape that has broken the build eleven times over a
166
+ * different number; the remedy is the same one `EPISODE_RESOLUTION_KINDS` and
167
+ * `UNJUDGED_REASONS` already are, and it costs a line.
168
+ *
169
+ * A fifth operation would be a change to what Loom is rather than an addition to
170
+ * it, so this list is not expected to grow. That is exactly why it is worth
171
+ * exporting: a number nobody expects to move is the one nobody re-checks.
172
+ */
173
+ export declare const TREE_OPERATIONS: readonly TreeOperationName[];
174
+ export declare const treeDeltaSchema: z.ZodObject<{
175
+ deltaId: z.ZodBranded<z.ZodString, "DeltaId">;
176
+ treeId: z.ZodBranded<z.ZodString, "TreeId">;
177
+ baseRevision: z.ZodNumber;
178
+ operations: z.ZodArray<z.ZodDiscriminatedUnion<"op", [z.ZodObject<{
179
+ op: z.ZodLiteral<"insert">;
180
+ parentId: z.ZodBranded<z.ZodString, "NodeId">;
181
+ index: z.ZodNumber;
182
+ node: z.ZodType<LoomNode, z.ZodTypeDef, unknown>;
183
+ }, "strip", z.ZodTypeAny, {
184
+ index: number;
185
+ op: "insert";
186
+ parentId: string & z.BRAND<"NodeId">;
187
+ node: LoomNode;
188
+ }, {
189
+ index: number;
190
+ op: "insert";
191
+ parentId: string;
192
+ node?: unknown;
193
+ }>, z.ZodObject<{
194
+ op: z.ZodLiteral<"remove">;
195
+ nodeId: z.ZodBranded<z.ZodString, "NodeId">;
196
+ }, "strip", z.ZodTypeAny, {
197
+ op: "remove";
198
+ nodeId: string & z.BRAND<"NodeId">;
199
+ }, {
200
+ op: "remove";
201
+ nodeId: string;
202
+ }>, z.ZodObject<{
203
+ op: z.ZodLiteral<"move">;
204
+ nodeId: z.ZodBranded<z.ZodString, "NodeId">;
205
+ parentId: z.ZodBranded<z.ZodString, "NodeId">;
206
+ index: z.ZodNumber;
207
+ }, "strip", z.ZodTypeAny, {
208
+ index: number;
209
+ op: "move";
210
+ parentId: string & z.BRAND<"NodeId">;
211
+ nodeId: string & z.BRAND<"NodeId">;
212
+ }, {
213
+ index: number;
214
+ op: "move";
215
+ parentId: string;
216
+ nodeId: string;
217
+ }>, z.ZodObject<{
218
+ op: z.ZodLiteral<"configure">;
219
+ nodeId: z.ZodBranded<z.ZodString, "NodeId">;
220
+ set: z.ZodDefault<z.ZodType<JsonObject, z.ZodTypeDef, JsonObject>>;
221
+ unset: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
222
+ }, "strip", z.ZodTypeAny, {
223
+ set: JsonObject;
224
+ op: "configure";
225
+ nodeId: string & z.BRAND<"NodeId">;
226
+ unset: string[];
227
+ }, {
228
+ op: "configure";
229
+ nodeId: string;
230
+ set?: JsonObject | undefined;
231
+ unset?: string[] | undefined;
232
+ }>]>, "many">;
233
+ }, "strip", z.ZodTypeAny, {
234
+ treeId: string & z.BRAND<"TreeId">;
235
+ operations: ({
236
+ index: number;
237
+ op: "insert";
238
+ parentId: string & z.BRAND<"NodeId">;
239
+ node: LoomNode;
240
+ } | {
241
+ op: "remove";
242
+ nodeId: string & z.BRAND<"NodeId">;
243
+ } | {
244
+ index: number;
245
+ op: "move";
246
+ parentId: string & z.BRAND<"NodeId">;
247
+ nodeId: string & z.BRAND<"NodeId">;
248
+ } | {
249
+ set: JsonObject;
250
+ op: "configure";
251
+ nodeId: string & z.BRAND<"NodeId">;
252
+ unset: string[];
253
+ })[];
254
+ deltaId: string & z.BRAND<"DeltaId">;
255
+ baseRevision: number;
256
+ }, {
257
+ treeId: string;
258
+ operations: ({
259
+ index: number;
260
+ op: "insert";
261
+ parentId: string;
262
+ node?: unknown;
263
+ } | {
264
+ op: "remove";
265
+ nodeId: string;
266
+ } | {
267
+ index: number;
268
+ op: "move";
269
+ parentId: string;
270
+ nodeId: string;
271
+ } | {
272
+ op: "configure";
273
+ nodeId: string;
274
+ set?: JsonObject | undefined;
275
+ unset?: string[] | undefined;
276
+ })[];
277
+ deltaId: string;
278
+ baseRevision: number;
279
+ }>;
280
+ export type TreeDelta = {
281
+ readonly deltaId: DeltaId;
282
+ readonly treeId: TreeId;
283
+ readonly baseRevision: number;
284
+ readonly operations: readonly TreeOperation[];
285
+ };
286
+ /** The boundary parse for deltas arriving from AI interpretation or the wire. */
287
+ export declare const parseDelta: (input: unknown) => Result<TreeDelta, TreeError>;
288
+ //# sourceMappingURL=delta.d.ts.map
@@ -0,0 +1,88 @@
1
+ import { z } from "zod";
2
+ import { deltaIdSchema, nodeIdSchema, treeIdSchema } from "../ids.js";
3
+ import { jsonObjectSchema } from "../json.js";
4
+ import { err, ok } from "../result.js";
5
+ import { loomNodeSchema } from "./node.js";
6
+ /**
7
+ * A TreeDelta is the only way a tree changes.
8
+ *
9
+ * Four discrete operations, chosen so that every structural edit is expressible
10
+ * and every operation is individually reviewable by the Gate: you can reason
11
+ * about "insert a checkout button into the sidebar" without diffing two trees.
12
+ * A whole-tree replacement would collapse that reasoning into a single opaque
13
+ * change, so it is deliberately not an operation.
14
+ *
15
+ * Operations within a delta are ordered and applied atomically — a delta that
16
+ * fails halfway leaves the tree untouched. Each operation observes the effects
17
+ * of the ones before it, so `index` in a `move` refers to the child list
18
+ * *after* the node has been detached.
19
+ */
20
+ export const insertOperationSchema = z.object({
21
+ op: z.literal("insert"),
22
+ parentId: nodeIdSchema,
23
+ index: z.number().int().nonnegative(),
24
+ node: loomNodeSchema,
25
+ });
26
+ export const removeOperationSchema = z.object({
27
+ op: z.literal("remove"),
28
+ nodeId: nodeIdSchema,
29
+ });
30
+ export const moveOperationSchema = z.object({
31
+ op: z.literal("move"),
32
+ nodeId: nodeIdSchema,
33
+ parentId: nodeIdSchema,
34
+ index: z.number().int().nonnegative(),
35
+ });
36
+ export const configureOperationSchema = z.object({
37
+ op: z.literal("configure"),
38
+ nodeId: nodeIdSchema,
39
+ set: jsonObjectSchema.default({}),
40
+ unset: z.array(z.string()).default([]),
41
+ });
42
+ export const treeOperationSchema = z.discriminatedUnion("op", [
43
+ insertOperationSchema,
44
+ removeOperationSchema,
45
+ moveOperationSchema,
46
+ configureOperationSchema,
47
+ ]);
48
+ /**
49
+ * The whole vocabulary of structural change, in the order the doc comment above
50
+ * argues it.
51
+ *
52
+ * Four is a claim this project makes about itself in prose — on the front door,
53
+ * in the course, in the reference — and until now every one of those was a digit
54
+ * somebody typed. A sentence that counts a list in `src/` and cannot be checked
55
+ * against it is the shape that has broken the build eleven times over a
56
+ * different number; the remedy is the same one `EPISODE_RESOLUTION_KINDS` and
57
+ * `UNJUDGED_REASONS` already are, and it costs a line.
58
+ *
59
+ * A fifth operation would be a change to what Loom is rather than an addition to
60
+ * it, so this list is not expected to grow. That is exactly why it is worth
61
+ * exporting: a number nobody expects to move is the one nobody re-checks.
62
+ */
63
+ export const TREE_OPERATIONS = [
64
+ "insert",
65
+ "remove",
66
+ "move",
67
+ "configure",
68
+ ];
69
+ export const treeDeltaSchema = z.object({
70
+ deltaId: deltaIdSchema,
71
+ treeId: treeIdSchema,
72
+ baseRevision: z.number().int().nonnegative(),
73
+ operations: z.array(treeOperationSchema).min(1),
74
+ });
75
+ /** The boundary parse for deltas arriving from AI interpretation or the wire. */
76
+ export const parseDelta = (input) => {
77
+ const parsed = treeDeltaSchema.safeParse(input);
78
+ if (!parsed.success) {
79
+ const [issue] = parsed.error.issues;
80
+ return err({
81
+ code: "schema-violation",
82
+ path: issue ? issue.path.join(".") : "",
83
+ detail: issue?.message ?? "unknown schema violation",
84
+ });
85
+ }
86
+ return ok(parsed.data);
87
+ };
88
+ //# sourceMappingURL=delta.js.map
@@ -0,0 +1,69 @@
1
+ import type { NodeId, TreeId } from "../ids.js";
2
+ import type { NodeKind } from "./node.js";
3
+ /**
4
+ * What a tree operation says when it refuses.
5
+ *
6
+ * Every failure in this module is a value rather than an exception, and every
7
+ * one of them is a case a caller can handle — a node that is not there, an id
8
+ * used twice, a move into a node that holds nothing.
9
+ */
10
+ /**
11
+ * Every way a tree operation can legitimately fail. Data only — rendering a
12
+ * message is a separate concern so hosts can localise or structure it however
13
+ * they like.
14
+ */
15
+ export type TreeError = {
16
+ readonly code: "node-not-found";
17
+ readonly nodeId: NodeId;
18
+ } | {
19
+ readonly code: "duplicate-node-id";
20
+ readonly nodeId: NodeId;
21
+ }
22
+ /** An id this delta removed, re-inserted as a different node (0038). */
23
+ | {
24
+ readonly code: "recycled-node-id";
25
+ readonly nodeId: NodeId;
26
+ } | {
27
+ readonly code: "not-a-container";
28
+ readonly nodeId: NodeId;
29
+ readonly nodeKind: NodeKind;
30
+ } | {
31
+ readonly code: "index-out-of-range";
32
+ readonly parentId: NodeId;
33
+ readonly index: number;
34
+ readonly childCount: number;
35
+ } | {
36
+ readonly code: "move-into-self";
37
+ readonly nodeId: NodeId;
38
+ } | {
39
+ readonly code: "move-into-descendant";
40
+ readonly nodeId: NodeId;
41
+ readonly parentId: NodeId;
42
+ } | {
43
+ readonly code: "root-not-detachable";
44
+ readonly nodeId: NodeId;
45
+ } | {
46
+ readonly code: "unconfigurable-key";
47
+ readonly nodeId: NodeId;
48
+ readonly nodeKind: NodeKind;
49
+ readonly key: string;
50
+ } | {
51
+ readonly code: "invalid-configuration";
52
+ readonly nodeId: NodeId;
53
+ readonly nodeKind: NodeKind;
54
+ readonly detail: string;
55
+ } | {
56
+ readonly code: "revision-mismatch";
57
+ readonly expected: number;
58
+ readonly actual: number;
59
+ } | {
60
+ readonly code: "tree-mismatch";
61
+ readonly expected: TreeId;
62
+ readonly actual: TreeId;
63
+ } | {
64
+ readonly code: "schema-violation";
65
+ readonly path: string;
66
+ readonly detail: string;
67
+ };
68
+ export declare const describeTreeError: (error: TreeError) => string;
69
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,34 @@
1
+ import { assertNever } from "../result.js";
2
+ export const describeTreeError = (error) => {
3
+ switch (error.code) {
4
+ case "node-not-found":
5
+ return `No node ${error.nodeId} in this tree.`;
6
+ case "duplicate-node-id":
7
+ return `Node id ${error.nodeId} already exists in this tree.`;
8
+ case "recycled-node-id":
9
+ return `Node id ${error.nodeId} was removed earlier in this delta and cannot come back as a different node.`;
10
+ case "not-a-container":
11
+ return `Node ${error.nodeId} is a ${error.nodeKind} node and cannot hold children.`;
12
+ case "index-out-of-range":
13
+ return `Index ${error.index} is outside 0..${error.childCount} for parent ${error.parentId}.`;
14
+ case "move-into-self":
15
+ return `Node ${error.nodeId} cannot be moved into itself.`;
16
+ case "move-into-descendant":
17
+ return `Node ${error.nodeId} cannot be moved into its own descendant ${error.parentId}.`;
18
+ case "root-not-detachable":
19
+ return `Node ${error.nodeId} is the root and cannot be removed or moved.`;
20
+ case "unconfigurable-key":
21
+ return `Key "${error.key}" is not configurable on a ${error.nodeKind} node (${error.nodeId}).`;
22
+ case "invalid-configuration":
23
+ return `Invalid configuration for ${error.nodeKind} node ${error.nodeId}: ${error.detail}`;
24
+ case "revision-mismatch":
25
+ return `Delta targets revision ${error.expected} but the tree is at revision ${error.actual}.`;
26
+ case "tree-mismatch":
27
+ return `Delta targets tree ${error.expected} but was applied to ${error.actual}.`;
28
+ case "schema-violation":
29
+ return `Schema violation at ${error.path}: ${error.detail}`;
30
+ default:
31
+ return assertNever(error, "describeTreeError");
32
+ }
33
+ };
34
+ //# sourceMappingURL=errors.js.map