@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,162 @@
1
+ import { type BindingName } from "../data/source.js";
2
+ import type { InteractiveWhen } from "../interactivity.js";
3
+ import type { JsonObject } from "../json.js";
4
+ import { type PrimitiveType, type SlotName } from "../primitive-type.js";
5
+ import { type Result } from "../result.js";
6
+ import { type BehaviourName, type BehaviourResolver } from "../render/behaviour.js";
7
+ import type { FrameResolver } from "../render/frame.js";
8
+ import type { BindingDeclaration, BindingReader } from "../render/reads.js";
9
+ import type { LoomPrimitive, PrimitiveResolver } from "../render/primitive.js";
10
+ import type { PropsValidator, PropsVerdict } from "../render/props.js";
11
+ import { type PrimitiveText, type TextResolver } from "../render/text.js";
12
+ import { type PrimitiveRole } from "../role.js";
13
+ import type { CopyDeclarations } from "./copy.js";
14
+ import type { PrimitiveEntry } from "./definition.js";
15
+ /**
16
+ * The registry: the set of primitives a deployment can render, and the seam the
17
+ * renderer resolves against.
18
+ *
19
+ * It satisfies both renderer-facing interfaces — `PrimitiveResolver` and
20
+ * `PropsValidator` — because the two are only sound together. A component
21
+ * declares a narrower prop type than the tree can express, and what makes that
22
+ * claim true is that the same object which resolved the component also vetted
23
+ * the props. Wiring one without the other is possible (the interfaces are
24
+ * separate on purpose) but it is then a host's explicit decision, not an
25
+ * accident of construction.
26
+ *
27
+ * It also satisfies `TextResolver`, over the declared strings themselves. A
28
+ * deployment that translates nothing is then correct with no extra wiring, and
29
+ * translating is `textResolverFor` wrapping this same registry with a
30
+ * dictionary — the untranslated case is the base case, not a fallback path that
31
+ * only runs when something is missing.
32
+ *
33
+ * Construction is pure and does not touch the components. Nothing here calls a
34
+ * primitive, so registering cannot run someone's render as a side effect of an
35
+ * import; the checks that need to call one live in `audit.ts`, which a host runs
36
+ * in a test or a build step.
37
+ */
38
+ export type RegisteredPrimitive = {
39
+ readonly type: PrimitiveType;
40
+ readonly description: string;
41
+ readonly slots: readonly SlotName[];
42
+ readonly component: LoomPrimitive;
43
+ readonly declaredProps: PrimitiveEntry["declaredProps"];
44
+ /** The props the conformance probe can vary, from the declared schema (0075). */
45
+ readonly choices: PrimitiveEntry["choices"];
46
+ /** Declared strings in the author's language, before any dictionary. */
47
+ readonly text: PrimitiveText<string>;
48
+ /** Whether it renders a target, and what makes it one. Absent for most. */
49
+ readonly interactive: InteractiveWhen | undefined;
50
+ /** Whether its author says it posts (0065). `false` for most. */
51
+ readonly submits: boolean;
52
+ /** The props it puts in a frame (0095). Empty for all but one primitive. */
53
+ readonly frames: readonly string[];
54
+ /** The controls it takes from the runtime's vocabulary. Empty for most. */
55
+ readonly behaviours: readonly BehaviourName[];
56
+ /** What part it plays (0114). `undefined` for most, which play none. */
57
+ readonly role: PrimitiveRole | undefined;
58
+ /**
59
+ * The props a reader reads as words (0122). `undefined` where the primitive
60
+ * has not said, which is not the same answer as `[]` and is not rounded to
61
+ * it.
62
+ */
63
+ readonly copy: readonly string[] | undefined;
64
+ /**
65
+ * The binding names it reads an answer under (0181), each either a name or
66
+ * the prop that gives one (0184). `undefined` where the primitive has not
67
+ * said, which is not the same answer as `[]` and is not rounded to it — the
68
+ * walk reports under the first and stays quiet under the second.
69
+ */
70
+ readonly reads: readonly BindingDeclaration<BindingName>[] | undefined;
71
+ readonly validate: (props: JsonObject) => PropsVerdict;
72
+ };
73
+ export type RegistryError = {
74
+ readonly code: "invalid-primitive-type";
75
+ readonly type: string;
76
+ } | {
77
+ readonly code: "invalid-slot-name";
78
+ readonly type: string;
79
+ readonly slot: string;
80
+ } | {
81
+ readonly code: "invalid-text-key";
82
+ readonly type: string;
83
+ readonly key: string;
84
+ } | {
85
+ readonly code: "blank-text";
86
+ readonly type: string;
87
+ readonly key: string;
88
+ } | {
89
+ readonly code: "undeclared-interactive-prop";
90
+ readonly type: string;
91
+ readonly prop: string;
92
+ } | {
93
+ readonly code: "undeclared-frame-prop";
94
+ readonly type: string;
95
+ readonly prop: string;
96
+ } | {
97
+ readonly code: "undeclared-copy-prop";
98
+ readonly type: string;
99
+ readonly prop: string;
100
+ } | {
101
+ readonly code: "unknown-behaviour";
102
+ readonly type: string;
103
+ readonly behaviour: string;
104
+ } | {
105
+ readonly code: "unnamed-behaviour";
106
+ readonly type: string;
107
+ readonly behaviour: string;
108
+ readonly key: string;
109
+ } | {
110
+ readonly code: "undeclared-interactive-behaviour";
111
+ readonly type: string;
112
+ readonly behaviour: string;
113
+ } | {
114
+ readonly code: "unpaired-behaviour";
115
+ readonly type: string;
116
+ readonly behaviour: string;
117
+ readonly requires: string;
118
+ } | {
119
+ readonly code: "unknown-role";
120
+ readonly type: string;
121
+ readonly role: string;
122
+ } | {
123
+ readonly code: "invalid-binding-name";
124
+ readonly type: string;
125
+ readonly name: string;
126
+ } | {
127
+ readonly code: "undeclared-reads-prop";
128
+ readonly type: string;
129
+ readonly prop: string;
130
+ } | {
131
+ readonly code: "duplicate-primitive-type";
132
+ readonly type: string;
133
+ };
134
+ export type PrimitiveRegistry = PrimitiveResolver & PropsValidator & TextResolver & BehaviourResolver & FrameResolver & BindingReader & CopyDeclarations & {
135
+ /** In registration order, so a catalogue and an audit read predictably. */
136
+ readonly primitives: readonly RegisteredPrimitive[];
137
+ /**
138
+ * The types that declared a given role, in registration order (0114).
139
+ *
140
+ * Empty for a role nothing here declares, which is the honest answer and
141
+ * not a failure: a deployment that registered no heading has no heading,
142
+ * and a consumer deriving a page name from one should show what it shows
143
+ * for a page that has none.
144
+ *
145
+ * Types rather than whole registrations, because every consumer this exists
146
+ * for is matching nodes in a tree, and a node carries a type. A caller that
147
+ * wants the registration has `primitives` and this is not in its way.
148
+ */
149
+ readonly typesWithRole: (role: PrimitiveRole) => readonly PrimitiveType[];
150
+ };
151
+ export declare const describeRegistryError: (error: RegistryError) => string;
152
+ /**
153
+ * Builds a registry, or refuses. A duplicate type is refused rather than
154
+ * resolved last-wins: two registrations for one identifier means a tree's
155
+ * meaning depends on module evaluation order, which is not a thing anyone should
156
+ * have to debug from a rendered page.
157
+ *
158
+ * Lookup is a `Map`, so a primitive named `constructor` or `toString` is an
159
+ * ordinary key rather than a reach into `Object.prototype`.
160
+ */
161
+ export declare const createPrimitiveRegistry: (entries: readonly PrimitiveEntry[]) => Result<PrimitiveRegistry, RegistryError>;
162
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1,329 @@
1
+ import { BINDING_NAME_EXPECTATION, bindingNameSchema, } from "../data/source.js";
2
+ import { primitiveTypeSchema, slotNameSchema, textKeySchema, } from "../primitive-type.js";
3
+ import { err, ok } from "../result.js";
4
+ import { BEHAVIOURS, isBehaviourName, } from "../render/behaviour.js";
5
+ import { NO_TEXT } from "../render/text.js";
6
+ import { isPrimitiveRole, PRIMITIVE_ROLES } from "../role.js";
7
+ const NO_BEHAVIOUR_NAMES = Object.freeze([]);
8
+ const NO_FRAME_PROPS = Object.freeze([]);
9
+ const NO_TYPES = Object.freeze([]);
10
+ export const describeRegistryError = (error) => {
11
+ switch (error.code) {
12
+ case "invalid-primitive-type":
13
+ return `"${error.type}" is not a valid primitive type — expected dot-namespaced kebab-case, like "commerce.product-card"`;
14
+ case "invalid-slot-name":
15
+ return `"${error.slot}" is not a valid slot name on "${error.type}" — expected camelCase, like "mainContent"`;
16
+ case "invalid-text-key":
17
+ return `"${error.key}" is not a valid text key on "${error.type}" — expected camelCase with no dots, like "notIncluded"`;
18
+ case "blank-text":
19
+ return `"${error.key}" on "${error.type}" declares an empty string; a string worth translating has something in it, and a blank one renders as a control with no name`;
20
+ case "undeclared-frame-prop":
21
+ return `"${error.type}" says it frames "${error.prop}", which its props schema does not declare; the seam would then check nothing and the frame would render whatever the tree said`;
22
+ case "undeclared-copy-prop":
23
+ return `"${error.type}" says a reader reads "${error.prop}", which its props schema does not declare; a preview built on that declaration would report a word the page never shows, and go on reporting it after the prop was renamed`;
24
+ case "undeclared-interactive-prop":
25
+ return `"${error.type}" says it renders a target when "${error.prop}" is set, and its schema declares no such prop; a trigger naming a prop that cannot arrive is a target the Gate will never see`;
26
+ case "unknown-behaviour":
27
+ return `"${error.type}" takes a behaviour called "${error.behaviour}" and the runtime has none; a behaviour is implemented here, not registered, so the vocabulary is the list in \`render/behaviour.ts\``;
28
+ case "unnamed-behaviour":
29
+ return `"${error.type}" takes the "${error.behaviour}" behaviour and declares no "${error.key}" text; a control whose name a deployment cannot translate is the failure the text seam exists to prevent`;
30
+ case "undeclared-interactive-behaviour":
31
+ return `"${error.type}" takes the "${error.behaviour}" behaviour, which renders a target, and declares no \`interactive\`; the Gate would then allow one inside an anchor, where a browser silently drops one of the two`;
32
+ case "invalid-binding-name":
33
+ return `"${error.type}" says it reads a binding called "${error.name}", which is not a binding name — ${BINDING_NAME_EXPECTATION}; a tree cannot ask under a name it cannot write, so this primitive would report every binding it was ever given`;
34
+ case "unpaired-behaviour":
35
+ return `"${error.type}" takes the "${error.behaviour}" behaviour and not "${error.requires}", which it does nothing without; it would render a control that asks a region nothing opens to close`;
36
+ case "undeclared-reads-prop":
37
+ return `"${error.type}" says it reads a binding under whichever name its "${error.prop}" prop gives, which its props schema does not declare; that prop can never arrive, so the primitive would read its default for ever and go on doing so after the prop it names was renamed`;
38
+ case "unknown-role":
39
+ return `"${error.type}" declares the role "${error.role}", which the runtime has none of; the vocabulary is closed and its members are ${PRIMITIVE_ROLES.map((role) => `"${role}"`).join(", ")} — and a misspelling accepted here would read to every consumer as a primitive that declares no role at all`;
40
+ case "duplicate-primitive-type":
41
+ return `"${error.type}" is registered twice; a tree naming it would resolve to whichever registration won`;
42
+ }
43
+ };
44
+ /**
45
+ * A trigger prop that the schema does not declare, if there is one.
46
+ *
47
+ * The one thing about an interactivity declaration that can be checked without
48
+ * calling the component, and the drift that actually happens: a prop is renamed
49
+ * and the declaration keeps naming the old one, which is silent — the primitive
50
+ * still renders its anchor and the Gate stops believing it ever does.
51
+ *
52
+ * A schema whose fields cannot be enumerated answers `undefined` rather than an
53
+ * empty list, and is left alone. "I cannot tell you" is not "there are none",
54
+ * and refusing a registration on the strength of it would be refusing on a
55
+ * guess.
56
+ */
57
+ const undeclaredTriggerProp = (entry) => {
58
+ const { interactive, declaredProps } = entry;
59
+ if (!interactive || interactive === "always" || !declaredProps)
60
+ return undefined;
61
+ const declared = new Set(declaredProps.map((prop) => prop.name));
62
+ return interactive.whenProps.find((prop) => !declared.has(prop));
63
+ };
64
+ /**
65
+ * A framable prop that the schema does not declare, if there is one.
66
+ *
67
+ * The same check `undeclaredTriggerProp` makes and with more riding on it. An
68
+ * interactivity declaration that has drifted makes the Gate wrong about the
69
+ * page; a frame declaration that has drifted makes the origin allowlist stop
70
+ * applying to a URL that still reaches an `iframe` — and it fails *open*, which
71
+ * is the direction a security check must never fail in silence.
72
+ *
73
+ * A schema whose fields cannot be enumerated answers `undefined` and is left
74
+ * alone, for the reason given there: "I cannot tell you" is not "there are
75
+ * none".
76
+ */
77
+ const undeclaredFrameProp = (entry) => {
78
+ const { frames, declaredProps } = entry;
79
+ if (frames.length === 0 || !declaredProps)
80
+ return undefined;
81
+ const declared = new Set(declaredProps.map((prop) => prop.name));
82
+ return frames.find((prop) => !declared.has(prop));
83
+ };
84
+ /**
85
+ * A copy prop that the schema does not declare, if there is one.
86
+ *
87
+ * The third of these checks, and the one with the least riding on it: a drifted
88
+ * copy declaration makes a preview quieter than the page, where a drifted frame
89
+ * declaration makes an allowlist stop applying. It is here anyway because the
90
+ * failure has the same shape — a prop renamed, a declaration left pointing at
91
+ * nothing, and no way to see it from the outside — and because a reading that
92
+ * has silently stopped reporting a headline number is a reading somebody is
93
+ * approving changes against.
94
+ *
95
+ * A schema whose fields cannot be enumerated answers `undefined` and is left
96
+ * alone, and so is a primitive that declared no copy at all — there is nothing
97
+ * to check in either case, and `[]` has nothing to check by construction.
98
+ */
99
+ const undeclaredCopyProp = (entry) => {
100
+ const { copy, declaredProps } = entry;
101
+ if (!copy || copy.length === 0 || !declaredProps)
102
+ return undefined;
103
+ const declared = new Set(declaredProps.map((prop) => prop.name));
104
+ return copy.find((prop) => !declared.has(prop));
105
+ };
106
+ /**
107
+ * The declared behaviours, or the first thing wrong with them.
108
+ *
109
+ * Four checks, and each one is the whole of what can be known without calling
110
+ * the component: the name is in the vocabulary, the strings its control needs
111
+ * are strings this primitive declares, a primitive taking a control says it
112
+ * renders a target, and a control that answers to another one was declared
113
+ * beside it. Whether the primitive actually *places* what it declared needs the
114
+ * component called, which is the audit's job and not this one's.
115
+ */
116
+ const registeredBehaviours = (entry) => {
117
+ const names = [];
118
+ for (const behaviour of entry.behaviours) {
119
+ if (!isBehaviourName(behaviour)) {
120
+ return err({ code: "unknown-behaviour", type: entry.type, behaviour });
121
+ }
122
+ const missing = BEHAVIOURS[behaviour].text.find((key) => (entry.text[key] ?? "").trim() === "");
123
+ if (missing !== undefined) {
124
+ return err({ code: "unnamed-behaviour", type: entry.type, behaviour, key: missing });
125
+ }
126
+ if (BEHAVIOURS[behaviour].rendersControl && !entry.interactive) {
127
+ return err({ code: "undeclared-interactive-behaviour", type: entry.type, behaviour });
128
+ }
129
+ /**
130
+ * Checked against the entry's own raw list rather than against `names`, so
131
+ * the two may be declared in either order — a primitive that names the
132
+ * cross before the trigger is not making a mistake.
133
+ */
134
+ const requires = BEHAVIOURS[behaviour].requires;
135
+ if (requires !== undefined && !entry.behaviours.includes(requires)) {
136
+ return err({ code: "unpaired-behaviour", type: entry.type, behaviour, requires });
137
+ }
138
+ names.push(behaviour);
139
+ }
140
+ return ok(names);
141
+ };
142
+ /**
143
+ * The declared role, checked — `undefined` for the primitive that declared none,
144
+ * which is most of them.
145
+ *
146
+ * Shaped like `registeredBehaviours` because it is the same job: an entry
147
+ * carries the declaration raw, the registry is the boundary that decides whether
148
+ * it is a member, and a string that is not one is refused rather than dropped.
149
+ */
150
+ const registeredRole = (entry) => {
151
+ const role = entry.role;
152
+ if (role === undefined)
153
+ return ok(undefined);
154
+ if (!isPrimitiveRole(role))
155
+ return err({ code: "unknown-role", type: entry.type, role });
156
+ return ok(role);
157
+ };
158
+ /**
159
+ * The declared bindings, checked against the grammar a tree has to write their
160
+ * names in — `undefined` for the primitive that has not said, which is all of
161
+ * them until their authors do.
162
+ *
163
+ * Every entry carries a name to check, and the check is worth making because it
164
+ * fails in the worst direction: a name no tree could ever write is a name no
165
+ * binding can ever match, so the primitive would report every binding it was
166
+ * handed rather than none. On a prop-named entry that name is the default,
167
+ * which is what a node that says nothing reads.
168
+ *
169
+ * The prop-named form brings the one thing the first form did not have — a prop
170
+ * name, which *can* be renamed out from under the declaration — so it is
171
+ * checked against the schema exactly as `frames` and `copy` are. What the
172
+ * catalogue knows about a prop is its name and whether it is required (0009),
173
+ * so that a declared prop holds a string is not checkable here and is not
174
+ * claimed to be; a value that is not one falls back to the default at the walk.
175
+ */
176
+ const registeredReads = (entry) => {
177
+ if (entry.reads === undefined)
178
+ return ok(undefined);
179
+ const declarations = [];
180
+ for (const declaration of entry.reads) {
181
+ const written = typeof declaration === "string" ? declaration : declaration.default;
182
+ const parsed = bindingNameSchema.safeParse(written);
183
+ if (!parsed.success) {
184
+ return err({ code: "invalid-binding-name", type: entry.type, name: written });
185
+ }
186
+ if (typeof declaration === "string") {
187
+ declarations.push(parsed.data);
188
+ continue;
189
+ }
190
+ if (!declaresProp(entry, declaration.fromProp)) {
191
+ return err({ code: "undeclared-reads-prop", type: entry.type, prop: declaration.fromProp });
192
+ }
193
+ declarations.push({ fromProp: declaration.fromProp, default: parsed.data });
194
+ }
195
+ return ok(Object.freeze(declarations));
196
+ };
197
+ /**
198
+ * Whether the props schema names this prop.
199
+ *
200
+ * `true` when the schema's keys cannot be enumerated at all, which is the same
201
+ * answer `undeclaredCopyProp` gives and for the same reason: a union of shapes
202
+ * is a schema the catalogue reports as unknown, and refusing a registration on
203
+ * the strength of a list that was never built would refuse the honest along
204
+ * with the mistaken.
205
+ */
206
+ const declaresProp = (entry, prop) => !entry.declaredProps || entry.declaredProps.some((declared) => declared.name === prop);
207
+ const registerEntry = (entry) => {
208
+ const type = primitiveTypeSchema.safeParse(entry.type);
209
+ if (!type.success)
210
+ return err({ code: "invalid-primitive-type", type: entry.type });
211
+ const slots = [];
212
+ for (const slot of entry.slots) {
213
+ const parsed = slotNameSchema.safeParse(slot);
214
+ if (!parsed.success)
215
+ return err({ code: "invalid-slot-name", type: entry.type, slot });
216
+ slots.push(parsed.data);
217
+ }
218
+ for (const [key, value] of Object.entries(entry.text)) {
219
+ if (!textKeySchema.safeParse(key).success) {
220
+ return err({ code: "invalid-text-key", type: entry.type, key });
221
+ }
222
+ if (value.trim() === "")
223
+ return err({ code: "blank-text", type: entry.type, key });
224
+ }
225
+ const undeclared = undeclaredTriggerProp(entry);
226
+ if (undeclared !== undefined) {
227
+ return err({ code: "undeclared-interactive-prop", type: entry.type, prop: undeclared });
228
+ }
229
+ const unframeable = undeclaredFrameProp(entry);
230
+ if (unframeable !== undefined) {
231
+ return err({ code: "undeclared-frame-prop", type: entry.type, prop: unframeable });
232
+ }
233
+ const unreadable = undeclaredCopyProp(entry);
234
+ if (unreadable !== undefined) {
235
+ return err({ code: "undeclared-copy-prop", type: entry.type, prop: unreadable });
236
+ }
237
+ const behaviours = registeredBehaviours(entry);
238
+ if (!behaviours.ok)
239
+ return behaviours;
240
+ const role = registeredRole(entry);
241
+ if (!role.ok)
242
+ return role;
243
+ const reads = registeredReads(entry);
244
+ if (!reads.ok)
245
+ return reads;
246
+ return ok({
247
+ type: type.data,
248
+ description: entry.description,
249
+ slots,
250
+ component: entry.component,
251
+ declaredProps: entry.declaredProps,
252
+ choices: entry.choices,
253
+ text: entry.text,
254
+ interactive: entry.interactive,
255
+ submits: entry.submits,
256
+ frames: entry.frames,
257
+ behaviours: behaviours.value,
258
+ role: role.value,
259
+ copy: entry.copy ? Object.freeze([...entry.copy]) : undefined,
260
+ reads: reads.value,
261
+ validate: entry.validate,
262
+ });
263
+ };
264
+ /**
265
+ * Builds a registry, or refuses. A duplicate type is refused rather than
266
+ * resolved last-wins: two registrations for one identifier means a tree's
267
+ * meaning depends on module evaluation order, which is not a thing anyone should
268
+ * have to debug from a rendered page.
269
+ *
270
+ * Lookup is a `Map`, so a primitive named `constructor` or `toString` is an
271
+ * ordinary key rather than a reach into `Object.prototype`.
272
+ */
273
+ export const createPrimitiveRegistry = (entries) => {
274
+ const byType = new Map();
275
+ const byRole = new Map();
276
+ const primitives = [];
277
+ for (const entry of entries) {
278
+ const registered = registerEntry(entry);
279
+ if (!registered.ok)
280
+ return registered;
281
+ if (byType.has(registered.value.type)) {
282
+ return err({ code: "duplicate-primitive-type", type: registered.value.type });
283
+ }
284
+ byType.set(registered.value.type, registered.value);
285
+ primitives.push(registered.value);
286
+ const { role } = registered.value;
287
+ if (role !== undefined) {
288
+ const claimed = byRole.get(role);
289
+ if (claimed)
290
+ claimed.push(registered.value.type);
291
+ else
292
+ byRole.set(role, [registered.value.type]);
293
+ }
294
+ }
295
+ /**
296
+ * Frozen before anything can be handed one. `typesWithRole` returns the list
297
+ * itself rather than a copy — a consumer may call it per row of a listing —
298
+ * and an unfrozen array shared that way is one `push` away from a deployment's
299
+ * registry changing under a rendered page. The same reason `freezeText` copies
300
+ * and freezes, one collection along.
301
+ */
302
+ for (const types of byRole.values())
303
+ Object.freeze(types);
304
+ return ok({
305
+ primitives,
306
+ resolve: (type) => byType.get(type)?.component,
307
+ validateProps: (type, props) => byType.get(type)?.validate(props) ?? { outcome: "undeclared" },
308
+ textFor: (type) => byType.get(type)?.text ?? NO_TEXT,
309
+ behavioursFor: (type) => byType.get(type)?.behaviours ?? NO_BEHAVIOUR_NAMES,
310
+ framePropsFor: (type) => byType.get(type)?.frames ?? NO_FRAME_PROPS,
311
+ /**
312
+ * `undefined` both for a primitive that declared nothing and for a type
313
+ * this registry does not hold — the same answer, and the right one: a walk
314
+ * that cannot find the primitive has already said so as
315
+ * `unknown-primitive`, and has no standing to say anything about what that
316
+ * primitive reads.
317
+ */
318
+ bindingsReadBy: (type) => byType.get(type)?.reads,
319
+ /**
320
+ * `undefined` for a type nobody registered as well as for one that declared
321
+ * nothing, and the two collapsing here is correct: neither has said what a
322
+ * reader reads, and a consumer that treated an unknown type as showing no
323
+ * words would under-report the same way this exists to stop.
324
+ */
325
+ copyFor: (type) => byType.get(type)?.copy,
326
+ typesWithRole: (role) => byRole.get(role) ?? NO_TYPES,
327
+ });
328
+ };
329
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1,46 @@
1
+ import { type Result } from "../result.js";
2
+ import type { PrimitiveEntry } from "./definition.js";
3
+ /**
4
+ * Taking part of a primitive library rather than all of it.
5
+ *
6
+ * A library is a set to choose from. Loom's own starter set is one, and a host
7
+ * building a registry from it has always been able to *add* — the starter
8
+ * factory takes the entries a deployment defines itself and appends them — but
9
+ * never to take fewer. A deployment that wants sixty of the ninety-six had one
10
+ * move available, which was to filter the exported array on its type strings.
11
+ *
12
+ * That works and it fails quietly. A filter against a name nothing carries —
13
+ * a typo, or a primitive renamed since the list was written — yields a smaller
14
+ * registry and says nothing, so the deployment loses a primitive and finds out
15
+ * when a page fails to draw. Choosing is the operation; a choice naming
16
+ * something that is not there is a mistake, and this is where it is caught.
17
+ */
18
+ /**
19
+ * Every name the library does not carry, not just the first.
20
+ *
21
+ * Registration errors are reported one at a time because each is a defect in a
22
+ * definition, and fixing one is the only way to see the next. A selection is
23
+ * different in kind: it is a list a person wrote in one sitting, and all of its
24
+ * mistakes are mistakes now. Naming them together is the difference between one
25
+ * correction and four rounds of it.
26
+ */
27
+ export type SelectionError = {
28
+ readonly code: "unregistered-types";
29
+ readonly types: readonly string[];
30
+ };
31
+ export declare const describeSelectionError: (error: SelectionError) => string;
32
+ /**
33
+ * The entries a deployment chose, in the library's own order.
34
+ *
35
+ * The library's order rather than the caller's, because the order entries are
36
+ * registered in is the order a catalogue lists them in and the order an audit
37
+ * reads them in: a slice of a library is still that library, shorter. A host
38
+ * that wants a different order has the array and can build one.
39
+ *
40
+ * A name given twice selects one entry, because the result is a subset and a
41
+ * subset has no repeats. That matters beyond tidiness — a registry refuses a
42
+ * duplicate type, so a selection that passed one through would turn a harmless
43
+ * repetition in a list into a refusal two calls later.
44
+ */
45
+ export declare const selectPrimitives: (entries: readonly PrimitiveEntry[], types: readonly string[]) => Result<readonly PrimitiveEntry[], SelectionError>;
46
+ //# sourceMappingURL=selection.d.ts.map
@@ -0,0 +1,24 @@
1
+ import { err, ok } from "../result.js";
2
+ export const describeSelectionError = (error) => `${error.types.map((type) => `"${type}"`).join(", ")} ${error.types.length === 1 ? "is not a primitive in this library" : "are not primitives in this library"}; a selection names what to keep, so a name nothing carries is a choice that cannot be honoured rather than a smaller registry`;
3
+ /**
4
+ * The entries a deployment chose, in the library's own order.
5
+ *
6
+ * The library's order rather than the caller's, because the order entries are
7
+ * registered in is the order a catalogue lists them in and the order an audit
8
+ * reads them in: a slice of a library is still that library, shorter. A host
9
+ * that wants a different order has the array and can build one.
10
+ *
11
+ * A name given twice selects one entry, because the result is a subset and a
12
+ * subset has no repeats. That matters beyond tidiness — a registry refuses a
13
+ * duplicate type, so a selection that passed one through would turn a harmless
14
+ * repetition in a list into a refusal two calls later.
15
+ */
16
+ export const selectPrimitives = (entries, types) => {
17
+ const available = new Set(entries.map((entry) => entry.type));
18
+ const missing = [...new Set(types)].filter((type) => !available.has(type));
19
+ if (missing.length > 0)
20
+ return err({ code: "unregistered-types", types: missing });
21
+ const chosen = new Set(types);
22
+ return ok(entries.filter((entry) => chosen.has(entry.type)));
23
+ };
24
+ //# sourceMappingURL=selection.js.map
@@ -0,0 +1,100 @@
1
+ import { z } from "zod";
2
+ import type { PrimitiveType } from "../primitive-type.js";
3
+ import { type TextResolver } from "../render/text.js";
4
+ import type { PrimitiveRegistry } from "./registry.js";
5
+ /**
6
+ * Translating the strings primitives own.
7
+ *
8
+ * A registry already answers `textFor` with the strings its primitives
9
+ * declared, which is what a deployment serving the authors' own language wants.
10
+ * This is the other half: what a deployment serving a different language
11
+ * supplies, what a translator has to be given to produce it, and what tells a
12
+ * host that the two have drifted apart.
13
+ *
14
+ * All three are pure projections over a registry. Nothing here renders, and
15
+ * nothing here reads a request — which language a visitor gets is the host's to
16
+ * decide, from headers or a path segment or a stored preference, and the
17
+ * framework never guesses at it.
18
+ */
19
+ /**
20
+ * A dictionary addresses one string as `${primitive type}.${key}` — the same
21
+ * flat key a translation file uses, so a dictionary can be a JSON file a
22
+ * translator edits and a diff between two languages is readable.
23
+ *
24
+ * The address is unambiguous because a text key never contains a dot
25
+ * (`textKeySchema`), so the last dot always separates the type from the key.
26
+ */
27
+ export declare const textMessageKey: (type: string, key: string) => string;
28
+ export declare const textDictionarySchema: z.ZodObject<{
29
+ locale: z.ZodString;
30
+ /**
31
+ * Empty translations are refused rather than accepted and ignored. A
32
+ * translator who deletes a string leaves a control with no accessible name,
33
+ * which is the exact failure the seam exists to prevent; refusing the
34
+ * dictionary at the boundary is where that gets caught, because by render time
35
+ * there is nobody left to tell.
36
+ */
37
+ messages: z.ZodRecord<z.ZodString, z.ZodString>;
38
+ }, "strip", z.ZodTypeAny, {
39
+ locale: string;
40
+ messages: Record<string, string>;
41
+ }, {
42
+ locale: string;
43
+ messages: Record<string, string>;
44
+ }>;
45
+ export type TextDictionary = z.infer<typeof textDictionarySchema>;
46
+ /** One declared string, as a translator needs to see it. */
47
+ export type CataloguedText = {
48
+ readonly type: PrimitiveType;
49
+ readonly key: string;
50
+ /** What the primitive's author wrote, in their own language. */
51
+ readonly source: string;
52
+ };
53
+ /**
54
+ * Every string the registered library owns, in registration order and key-sorted
55
+ * within each primitive — the extraction a translation file is written from.
56
+ *
57
+ * Deliberately **not** part of `catalogueOf`. That catalogue is what a model is
58
+ * told it may build (0013), and these strings are the one part of the page a
59
+ * model must not write: an accessible name is a promise about what a control
60
+ * does, and it belongs to whoever wrote the control.
61
+ */
62
+ export declare const textCatalogue: (registry: PrimitiveRegistry) => readonly CataloguedText[];
63
+ /**
64
+ * A resolver over the registry's declarations with a dictionary laid on top.
65
+ *
66
+ * The merge happens once, here, rather than once per node during a walk: a page
67
+ * with fifty perks in it does fifty map reads and no string work at all. A host
68
+ * serving several languages builds one of these per dictionary and keeps them,
69
+ * which is also why this takes a dictionary rather than reading one.
70
+ *
71
+ * A key the dictionary does not carry keeps the declared string. That is not a
72
+ * failure mode to be reported at render time — it is the ordinary state of a
73
+ * translation in progress, and `textCoverage` is where a host finds out about it
74
+ * once rather than on every request.
75
+ */
76
+ export declare const textResolverFor: (registry: PrimitiveRegistry, dictionary: TextDictionary) => TextResolver;
77
+ export type TextCoverage = {
78
+ readonly locale: string;
79
+ /** How many declared strings this dictionary answers. */
80
+ readonly translated: number;
81
+ /** Declared strings it does not answer, which will render in the source language. */
82
+ readonly untranslated: readonly CataloguedText[];
83
+ /**
84
+ * Dictionary keys naming no declared string — a primitive that was renamed or
85
+ * removed, or a typo. Enumerated rather than counted because each one is a
86
+ * line somebody has to delete, and because a whole primitive's worth of them
87
+ * appearing at once is how a rename announces itself.
88
+ */
89
+ readonly unknown: readonly string[];
90
+ };
91
+ /**
92
+ * What a dictionary covers, and where it has drifted from the library.
93
+ *
94
+ * Reported, never enforced — the same bargain 0012 struck for conformance. A
95
+ * partially translated deployment is a normal state and a legitimate choice; a
96
+ * host that would rather it were not asserts on this in a test or a build step,
97
+ * which is a decision it makes rather than one registration makes for it.
98
+ */
99
+ export declare const textCoverage: (registry: PrimitiveRegistry, dictionary: TextDictionary) => TextCoverage;
100
+ //# sourceMappingURL=text.d.ts.map