@agentshouse/mdmodel 0.1.0-alpha.8 → 0.1.0-c03f6cf931ca0

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 (552) hide show
  1. package/API.md +424 -0
  2. package/README.md +41 -183
  3. package/dist/body.d.ts +85 -0
  4. package/dist/body.d.ts.map +1 -0
  5. package/dist/body.js +1083 -0
  6. package/dist/built-in.d.ts +4 -0
  7. package/dist/built-in.d.ts.map +1 -0
  8. package/dist/built-in.js +19 -0
  9. package/dist/definition.d.ts +86 -31
  10. package/dist/definition.d.ts.map +1 -1
  11. package/dist/definition.js +850 -135
  12. package/dist/divide.d.ts +3 -0
  13. package/dist/divide.d.ts.map +1 -0
  14. package/dist/divide.js +321 -0
  15. package/dist/document.d.ts +19 -3
  16. package/dist/document.d.ts.map +1 -1
  17. package/dist/document.js +1007 -188
  18. package/dist/event.d.ts +77 -0
  19. package/dist/event.d.ts.map +1 -0
  20. package/dist/event.js +200 -0
  21. package/dist/facts.d.ts +15 -0
  22. package/dist/facts.d.ts.map +1 -0
  23. package/dist/facts.js +41 -0
  24. package/dist/fields.d.ts +6 -0
  25. package/dist/fields.d.ts.map +1 -0
  26. package/dist/fields.js +10 -0
  27. package/dist/form.d.ts +4 -0
  28. package/dist/form.d.ts.map +1 -0
  29. package/dist/form.js +153 -0
  30. package/dist/house-model.d.ts +836 -0
  31. package/dist/house-model.d.ts.map +1 -0
  32. package/dist/house-model.js +463 -0
  33. package/dist/house-references/crockford.d.ts +4 -0
  34. package/dist/house-references/crockford.d.ts.map +1 -0
  35. package/dist/house-references/crockford.js +3 -0
  36. package/dist/house-references/patterns.d.ts +9 -0
  37. package/dist/house-references/patterns.d.ts.map +1 -0
  38. package/dist/house-references/patterns.js +13 -0
  39. package/dist/index.d.ts +41 -4
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +26 -5
  42. package/dist/kinds.d.ts +18 -0
  43. package/dist/kinds.d.ts.map +1 -0
  44. package/dist/kinds.js +150 -0
  45. package/dist/markdown.d.ts +75 -0
  46. package/dist/markdown.d.ts.map +1 -0
  47. package/dist/markdown.js +265 -0
  48. package/dist/media-type.d.ts +72 -0
  49. package/dist/media-type.d.ts.map +1 -0
  50. package/dist/media-type.js +157 -0
  51. package/dist/not-ready.d.ts +2 -0
  52. package/dist/not-ready.d.ts.map +1 -0
  53. package/dist/not-ready.js +5 -0
  54. package/dist/paths.d.ts +25 -5
  55. package/dist/paths.d.ts.map +1 -1
  56. package/dist/paths.js +206 -35
  57. package/dist/pattern.d.ts +10 -0
  58. package/dist/pattern.d.ts.map +1 -0
  59. package/dist/pattern.js +356 -0
  60. package/dist/project.d.ts +20 -1
  61. package/dist/project.d.ts.map +1 -1
  62. package/dist/project.js +83 -78
  63. package/dist/query/language.d.ts +254 -0
  64. package/dist/query/language.d.ts.map +1 -0
  65. package/dist/query/language.js +620 -0
  66. package/dist/query/match.d.ts +14 -0
  67. package/dist/query/match.d.ts.map +1 -0
  68. package/dist/query/match.js +150 -0
  69. package/dist/query/rows.d.ts +32 -0
  70. package/dist/query/rows.d.ts.map +1 -0
  71. package/dist/query/rows.js +161 -0
  72. package/dist/query/sql.d.ts +39 -0
  73. package/dist/query/sql.d.ts.map +1 -0
  74. package/dist/query/sql.js +285 -0
  75. package/dist/references.d.ts +4 -0
  76. package/dist/references.d.ts.map +1 -0
  77. package/dist/references.js +30 -0
  78. package/dist/refuse.d.ts +1 -0
  79. package/dist/refuse.d.ts.map +1 -1
  80. package/dist/refuse.js +3 -10
  81. package/dist/reserved.d.ts +6 -0
  82. package/dist/reserved.d.ts.map +1 -0
  83. package/dist/reserved.js +21 -0
  84. package/dist/room-types.d.ts +7 -0
  85. package/dist/room-types.d.ts.map +1 -0
  86. package/dist/room-types.js +136 -0
  87. package/dist/schema.d.ts +6 -5
  88. package/dist/schema.d.ts.map +1 -1
  89. package/dist/schema.js +143 -41
  90. package/dist/types.d.ts +101 -3
  91. package/dist/types.d.ts.map +1 -1
  92. package/dist/types.js +1 -3
  93. package/dist/validate.d.ts +35 -2
  94. package/dist/validate.d.ts.map +1 -1
  95. package/dist/validate.js +388 -153
  96. package/dist/version.d.ts +1 -1
  97. package/dist/version.d.ts.map +1 -1
  98. package/dist/version.js +1 -3
  99. package/dist/yaml.d.ts +9 -3
  100. package/dist/yaml.d.ts.map +1 -1
  101. package/dist/yaml.js +327 -202
  102. package/fixtures/README.md +128 -55
  103. package/fixtures/cases/absent-link-dangles/library/item.md +8 -0
  104. package/fixtures/cases/absent-link-dangles/schema.yaml +5 -0
  105. package/fixtures/cases/absent-optional-field/expected.json +1 -0
  106. package/fixtures/cases/absent-optional-field/library/companies/acme.md +4 -0
  107. package/fixtures/cases/absent-optional-field/library/deals/lead.md +6 -0
  108. package/fixtures/cases/absent-optional-field/schema.yaml +55 -0
  109. package/fixtures/cases/absolute-link/context.json +1 -0
  110. package/fixtures/cases/absolute-link/expected.json +5 -0
  111. package/fixtures/cases/absolute-link/library/item.md +8 -0
  112. package/fixtures/cases/absolute-link/schema.yaml +5 -0
  113. package/fixtures/cases/attachment-reference-any-file/context.json +1 -0
  114. package/fixtures/cases/attachment-reference-any-file/expected.json +1 -0
  115. package/fixtures/cases/attachment-reference-any-file/library/companies/acme.md +4 -0
  116. package/fixtures/cases/attachment-reference-any-file/library/deals/renewal.md +18 -0
  117. package/fixtures/cases/attachment-reference-any-file/library/places/depot.md +4 -0
  118. package/fixtures/cases/attachment-reference-any-file/library/products/seats.md +4 -0
  119. package/fixtures/cases/attachment-reference-any-file/library/products/support.md +4 -0
  120. package/fixtures/cases/attachment-reference-any-file/schema.yaml +32 -0
  121. package/fixtures/cases/attachment-reference-dangles/context.json +1 -0
  122. package/fixtures/cases/attachment-reference-dangles/expected.json +1 -0
  123. package/fixtures/cases/attachment-reference-dangles/library/companies/acme.md +4 -0
  124. package/fixtures/cases/attachment-reference-dangles/library/deals/renewal.md +18 -0
  125. package/fixtures/cases/attachment-reference-dangles/library/places/depot.md +4 -0
  126. package/fixtures/cases/attachment-reference-dangles/library/products/seats.md +4 -0
  127. package/fixtures/cases/attachment-reference-dangles/library/products/support.md +4 -0
  128. package/fixtures/cases/attachment-reference-dangles/schema.yaml +32 -0
  129. package/fixtures/cases/attachment-reference-outside/context.json +1 -0
  130. package/fixtures/cases/attachment-reference-outside/expected.json +7 -0
  131. package/fixtures/cases/attachment-reference-outside/library/companies/acme.md +4 -0
  132. package/fixtures/cases/attachment-reference-outside/library/deals/renewal.md +18 -0
  133. package/fixtures/cases/attachment-reference-outside/library/places/depot.md +4 -0
  134. package/fixtures/cases/attachment-reference-outside/library/products/seats.md +4 -0
  135. package/fixtures/cases/attachment-reference-outside/library/products/support.md +4 -0
  136. package/fixtures/cases/attachment-reference-outside/schema.yaml +32 -0
  137. package/fixtures/cases/binary-any-reference/expected.json +2 -2
  138. package/fixtures/cases/binary-any-reference/library/notes/draft.md +1 -1
  139. package/fixtures/cases/binary-any-reference/schema.yaml +4 -0
  140. package/fixtures/cases/binary-document-collision/expected.json +1 -2
  141. package/fixtures/cases/binary-document-collision/schema.yaml +1 -0
  142. package/fixtures/cases/binary-image-dangles/expected.json +1 -0
  143. package/fixtures/cases/binary-image-dangles/schema.yaml +1 -0
  144. package/fixtures/cases/binary-link-dangles/expected.json +1 -0
  145. package/fixtures/cases/binary-link-dangles/schema.yaml +1 -0
  146. package/fixtures/cases/binary-link-outside-collection/expected.json +1 -2
  147. package/fixtures/cases/binary-link-outside-collection/schema.yaml +1 -0
  148. package/fixtures/cases/binary-prototype-reference/expected.json +2 -2
  149. package/fixtures/cases/binary-prototype-reference/library/notes/draft.md +1 -1
  150. package/fixtures/cases/binary-prototype-reference/schema.yaml +4 -0
  151. package/fixtures/cases/binary-typed-reference/expected.json +2 -2
  152. package/fixtures/cases/binary-typed-reference/library/notes/draft.md +1 -1
  153. package/fixtures/cases/binary-typed-reference/schema.yaml +5 -0
  154. package/fixtures/cases/boolean-field/context.json +1 -0
  155. package/fixtures/cases/boolean-field/expected.json +7 -0
  156. package/fixtures/cases/boolean-field/library/companies/acme.md +4 -0
  157. package/fixtures/cases/boolean-field/library/deals/renewal.md +56 -0
  158. package/fixtures/cases/boolean-field/schema.yaml +55 -0
  159. package/fixtures/cases/bracketed-link-definition/library/item.md +1 -1
  160. package/fixtures/cases/bracketed-link-definition/schema.yaml +5 -0
  161. package/fixtures/cases/closed-nested-object/context.json +1 -0
  162. package/fixtures/cases/closed-nested-object/expected.json +7 -0
  163. package/fixtures/cases/closed-nested-object/library/companies/acme.md +4 -0
  164. package/fixtures/cases/closed-nested-object/library/deals/renewal.md +57 -0
  165. package/fixtures/cases/closed-nested-object/schema.yaml +55 -0
  166. package/fixtures/cases/composed-root-reference/context.json +1 -0
  167. package/fixtures/cases/composed-root-reference/expected.json +6 -0
  168. package/fixtures/cases/composed-root-reference/library/a.md +5 -0
  169. package/fixtures/cases/composed-root-reference/schema.yaml +13 -0
  170. package/fixtures/cases/conditional-long-text/context.json +1 -0
  171. package/fixtures/cases/conditional-long-text/expected.json +7 -0
  172. package/fixtures/cases/conditional-long-text/library/questions/hosting.md +9 -0
  173. package/fixtures/cases/conditional-long-text/library/questions/payments.md +12 -0
  174. package/fixtures/cases/conditional-long-text/schema.yaml +13 -0
  175. package/fixtures/cases/cross-room-link/context.json +1 -0
  176. package/fixtures/cases/cross-room-link/expected.json +1 -0
  177. package/fixtures/cases/cross-room-link/library/clients/acme.md +6 -0
  178. package/fixtures/cases/cross-room-link/schema.yaml +3 -0
  179. package/fixtures/cases/cross-room-reference/context.json +1 -0
  180. package/fixtures/cases/cross-room-reference/expected.json +1 -0
  181. package/fixtures/cases/cross-room-reference/library/clients/acme.md +9 -0
  182. package/fixtures/cases/cross-room-reference/schema.yaml +8 -0
  183. package/fixtures/cases/date-time-format/context.json +1 -0
  184. package/fixtures/cases/date-time-format/expected.json +7 -0
  185. package/fixtures/cases/date-time-format/library/companies/acme.md +4 -0
  186. package/fixtures/cases/date-time-format/library/deals/renewal.md +56 -0
  187. package/fixtures/cases/date-time-format/schema.yaml +55 -0
  188. package/fixtures/cases/declared-binary-links/schema.yaml +1 -0
  189. package/fixtures/cases/default-unfilled/context.json +1 -0
  190. package/fixtures/cases/default-unfilled/expected.json +6 -0
  191. package/fixtures/cases/default-unfilled/library/companies/acme.md +4 -0
  192. package/fixtures/cases/default-unfilled/library/deals/renewal.md +54 -0
  193. package/fixtures/cases/default-unfilled/schema.yaml +55 -0
  194. package/fixtures/cases/defs-pattern/context.json +1 -0
  195. package/fixtures/cases/defs-pattern/expected.json +7 -0
  196. package/fixtures/cases/defs-pattern/library/companies/acme.md +4 -0
  197. package/fixtures/cases/defs-pattern/library/deals/renewal.md +56 -0
  198. package/fixtures/cases/defs-pattern/schema.yaml +55 -0
  199. package/fixtures/cases/dependent-rule/context.json +1 -0
  200. package/fixtures/cases/dependent-rule/expected.json +6 -0
  201. package/fixtures/cases/dependent-rule/library/companies/acme.md +4 -0
  202. package/fixtures/cases/dependent-rule/library/deals/renewal.md +55 -0
  203. package/fixtures/cases/dependent-rule/schema.yaml +55 -0
  204. package/fixtures/cases/duplicate-link-definition/library/item.md +1 -1
  205. package/fixtures/cases/duplicate-link-definition/schema.yaml +5 -0
  206. package/fixtures/cases/email-format/context.json +1 -0
  207. package/fixtures/cases/email-format/expected.json +7 -0
  208. package/fixtures/cases/email-format/library/companies/acme.md +4 -0
  209. package/fixtures/cases/email-format/library/deals/renewal.md +56 -0
  210. package/fixtures/cases/email-format/schema.yaml +55 -0
  211. package/fixtures/cases/equal-labels/context.json +1 -0
  212. package/fixtures/cases/equal-labels/expected.json +5 -0
  213. package/fixtures/cases/equal-labels/schema.yaml +4 -0
  214. package/fixtures/cases/fenced-link-definition/library/item.md +1 -1
  215. package/fixtures/cases/fenced-link-definition/schema.yaml +5 -0
  216. package/fixtures/cases/field-enum/expected.json +3 -3
  217. package/fixtures/cases/field-enum/library/item.md +2 -2
  218. package/fixtures/cases/field-enum/schema.yaml +6 -0
  219. package/fixtures/cases/frontmatter-schema/context.json +1 -0
  220. package/fixtures/cases/frontmatter-schema/expected.json +5 -0
  221. package/fixtures/cases/frontmatter-schema/schema.yaml +5 -0
  222. package/fixtures/cases/integer-field/context.json +1 -0
  223. package/fixtures/cases/integer-field/expected.json +7 -0
  224. package/fixtures/cases/integer-field/library/companies/acme.md +4 -0
  225. package/fixtures/cases/integer-field/library/deals/renewal.md +56 -0
  226. package/fixtures/cases/integer-field/schema.yaml +55 -0
  227. package/fixtures/cases/interrupted-link-definition/schema.yaml +1 -0
  228. package/fixtures/cases/json-schema-constructs/context.json +1 -0
  229. package/fixtures/cases/json-schema-constructs/expected.json +1 -0
  230. package/fixtures/cases/json-schema-constructs/library/companies/acme.md +4 -0
  231. package/fixtures/cases/json-schema-constructs/library/deals/renewal.md +56 -0
  232. package/fixtures/cases/json-schema-constructs/schema.yaml +55 -0
  233. package/fixtures/cases/labels-in-the-rooms-language/context.json +1 -0
  234. package/fixtures/cases/labels-in-the-rooms-language/expected.json +1 -0
  235. package/fixtures/cases/labels-in-the-rooms-language/library/deals/atlas.md +7 -0
  236. package/fixtures/cases/labels-in-the-rooms-language/schema.yaml +9 -0
  237. package/fixtures/cases/lazy-list-item/context.json +1 -0
  238. package/fixtures/cases/lazy-list-item/expected.json +3 -0
  239. package/fixtures/cases/lazy-list-item/library/item.md +10 -0
  240. package/fixtures/cases/lazy-list-item/schema.yaml +3 -0
  241. package/fixtures/cases/link-into-a-reserved-name/context.json +1 -0
  242. package/fixtures/cases/link-into-a-reserved-name/expected.json +5 -0
  243. package/fixtures/cases/link-into-a-reserved-name/library/notes/a.md +6 -0
  244. package/fixtures/cases/link-into-a-reserved-name/schema.yaml +3 -0
  245. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/context.json +1 -0
  246. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/expected.json +5 -0
  247. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/library/notes/b.md +5 -0
  248. package/fixtures/cases/list-item-enum/context.json +1 -0
  249. package/fixtures/cases/list-item-enum/expected.json +7 -0
  250. package/fixtures/cases/list-item-enum/library/task.md +7 -0
  251. package/fixtures/cases/list-item-enum/schema.yaml +3 -0
  252. package/fixtures/cases/list-item-kind/context.json +1 -0
  253. package/fixtures/cases/list-item-kind/expected.json +7 -0
  254. package/fixtures/cases/list-item-kind/library/task.md +6 -0
  255. package/fixtures/cases/list-item-kind/schema.yaml +3 -0
  256. package/fixtures/cases/list-items/context.json +1 -0
  257. package/fixtures/cases/list-items/expected.json +1 -0
  258. package/fixtures/cases/list-items/library/other.md +3 -0
  259. package/fixtures/cases/list-items/library/page.md +26 -0
  260. package/fixtures/cases/list-items/schema.yaml +10 -0
  261. package/fixtures/cases/list-of-objects-closed/context.json +1 -0
  262. package/fixtures/cases/list-of-objects-closed/expected.json +7 -0
  263. package/fixtures/cases/list-of-objects-closed/library/companies/acme.md +4 -0
  264. package/fixtures/cases/list-of-objects-closed/library/deals/renewal.md +56 -0
  265. package/fixtures/cases/list-of-objects-closed/schema.yaml +55 -0
  266. package/fixtures/cases/list-of-objects-item/context.json +1 -0
  267. package/fixtures/cases/list-of-objects-item/expected.json +7 -0
  268. package/fixtures/cases/list-of-objects-item/library/companies/acme.md +4 -0
  269. package/fixtures/cases/list-of-objects-item/library/deals/renewal.md +56 -0
  270. package/fixtures/cases/list-of-objects-item/schema.yaml +55 -0
  271. package/fixtures/cases/list-of-objects-reference/context.json +1 -0
  272. package/fixtures/cases/list-of-objects-reference/expected.json +7 -0
  273. package/fixtures/cases/list-of-objects-reference/library/companies/acme.md +4 -0
  274. package/fixtures/cases/list-of-objects-reference/library/deals/renewal.md +17 -0
  275. package/fixtures/cases/list-of-objects-reference/library/places/depot.md +4 -0
  276. package/fixtures/cases/list-of-objects-reference/library/products/seats.md +4 -0
  277. package/fixtures/cases/list-of-objects-reference/library/products/support.md +4 -0
  278. package/fixtures/cases/list-of-objects-reference/schema.yaml +32 -0
  279. package/fixtures/cases/list-reference-path/context.json +1 -0
  280. package/fixtures/cases/list-reference-path/expected.json +7 -0
  281. package/fixtures/cases/list-reference-path/library/other.md +3 -0
  282. package/fixtures/cases/list-reference-path/library/page.md +5 -0
  283. package/fixtures/cases/list-reference-path/schema.yaml +3 -0
  284. package/fixtures/cases/list-reference-type/context.json +1 -0
  285. package/fixtures/cases/list-reference-type/expected.json +7 -0
  286. package/fixtures/cases/list-reference-type/library/note.md +1 -0
  287. package/fixtures/cases/list-reference-type/library/page.md +6 -0
  288. package/fixtures/cases/list-reference-type/schema.yaml +3 -0
  289. package/fixtures/cases/list-size/context.json +1 -0
  290. package/fixtures/cases/list-size/expected.json +7 -0
  291. package/fixtures/cases/list-size/library/companies/acme.md +4 -0
  292. package/fixtures/cases/list-size/library/deals/renewal.md +58 -0
  293. package/fixtures/cases/list-size/schema.yaml +55 -0
  294. package/fixtures/cases/long-fence-link-definition/schema.yaml +1 -0
  295. package/fixtures/cases/long-value-past-six-levels/context.json +1 -0
  296. package/fixtures/cases/long-value-past-six-levels/expected.json +5 -0
  297. package/fixtures/cases/long-value-past-six-levels/schema.yaml +15 -0
  298. package/fixtures/cases/malformed-definition/expected.json +2 -4
  299. package/fixtures/cases/malformed-definition/schema.yaml +3 -0
  300. package/fixtures/cases/malformed-list/context.json +1 -0
  301. package/fixtures/cases/malformed-list/expected.json +7 -0
  302. package/fixtures/cases/{structured-section → malformed-list}/library/item.md +1 -1
  303. package/fixtures/cases/malformed-list/schema.yaml +6 -0
  304. package/fixtures/cases/member-document/context.json +1 -0
  305. package/fixtures/cases/member-document/expected.json +1 -0
  306. package/fixtures/cases/member-document/library/people/ana.md +5 -0
  307. package/fixtures/cases/member-document/schema.yaml +5 -0
  308. package/fixtures/cases/member-on-an-untyped-document/context.json +1 -0
  309. package/fixtures/cases/member-on-an-untyped-document/expected.json +6 -0
  310. package/fixtures/cases/member-on-an-untyped-document/library/note.md +4 -0
  311. package/fixtures/cases/member-on-another-type/context.json +1 -0
  312. package/fixtures/cases/member-on-another-type/expected.json +6 -0
  313. package/fixtures/cases/member-on-another-type/library/note.md +4 -0
  314. package/fixtures/cases/member-on-another-type/schema.yaml +7 -0
  315. package/fixtures/cases/missing-required-field/expected.json +2 -3
  316. package/fixtures/cases/missing-required-field/library/item.md +1 -1
  317. package/fixtures/cases/missing-required-field/schema.yaml +6 -0
  318. package/fixtures/cases/misspelled-key/context.json +1 -0
  319. package/fixtures/cases/misspelled-key/expected.json +7 -0
  320. package/fixtures/cases/misspelled-key/library/companies/acme.md +4 -0
  321. package/fixtures/cases/misspelled-key/library/deals/renewal.md +57 -0
  322. package/fixtures/cases/misspelled-key/schema.yaml +55 -0
  323. package/fixtures/cases/name-not-a-string/context.json +1 -0
  324. package/fixtures/cases/name-not-a-string/expected.json +5 -0
  325. package/fixtures/cases/name-not-a-string/schema.yaml +5 -0
  326. package/fixtures/cases/nested-defs/context.json +1 -0
  327. package/fixtures/cases/nested-defs/expected.json +7 -0
  328. package/fixtures/cases/nested-defs/library/deal.md +6 -0
  329. package/fixtures/cases/nested-defs/schema.yaml +11 -0
  330. package/fixtures/cases/nested-object-reference/context.json +1 -0
  331. package/fixtures/cases/nested-object-reference/expected.json +7 -0
  332. package/fixtures/cases/nested-object-reference/library/companies/acme.md +4 -0
  333. package/fixtures/cases/nested-object-reference/library/deals/renewal.md +17 -0
  334. package/fixtures/cases/nested-object-reference/library/places/depot.md +4 -0
  335. package/fixtures/cases/nested-object-reference/library/products/seats.md +4 -0
  336. package/fixtures/cases/nested-object-reference/library/products/support.md +4 -0
  337. package/fixtures/cases/nested-object-reference/schema.yaml +32 -0
  338. package/fixtures/cases/nested-reference/context.json +1 -0
  339. package/fixtures/cases/nested-reference/expected.json +1 -0
  340. package/fixtures/cases/nested-reference/library/companies/acme.md +4 -0
  341. package/fixtures/cases/nested-reference/library/deals/renewal.md +18 -0
  342. package/fixtures/cases/nested-reference/library/places/depot.md +4 -0
  343. package/fixtures/cases/nested-reference/library/products/seats.md +4 -0
  344. package/fixtures/cases/nested-reference/library/products/support.md +4 -0
  345. package/fixtures/cases/nested-reference/schema.yaml +32 -0
  346. package/fixtures/cases/nested-required-field/context.json +1 -0
  347. package/fixtures/cases/nested-required-field/expected.json +7 -0
  348. package/fixtures/cases/nested-required-field/library/companies/acme.md +4 -0
  349. package/fixtures/cases/nested-required-field/library/deals/renewal.md +55 -0
  350. package/fixtures/cases/nested-required-field/schema.yaml +55 -0
  351. package/fixtures/cases/numeric-range/context.json +1 -0
  352. package/fixtures/cases/numeric-range/expected.json +7 -0
  353. package/fixtures/cases/numeric-range/library/companies/acme.md +4 -0
  354. package/fixtures/cases/numeric-range/library/deals/renewal.md +56 -0
  355. package/fixtures/cases/numeric-range/schema.yaml +55 -0
  356. package/fixtures/cases/one-key-two-labels/context.json +1 -0
  357. package/fixtures/cases/one-key-two-labels/expected.json +5 -0
  358. package/fixtures/cases/one-key-two-labels/schema.yaml +5 -0
  359. package/fixtures/cases/one-key-two-types/context.json +1 -0
  360. package/fixtures/cases/one-key-two-types/expected.json +5 -0
  361. package/fixtures/cases/one-key-two-types/schema.yaml +4 -0
  362. package/fixtures/cases/one-of-variant/context.json +1 -0
  363. package/fixtures/cases/one-of-variant/expected.json +7 -0
  364. package/fixtures/cases/one-of-variant/library/companies/acme.md +4 -0
  365. package/fixtures/cases/one-of-variant/library/deals/renewal.md +56 -0
  366. package/fixtures/cases/one-of-variant/schema.yaml +55 -0
  367. package/fixtures/cases/other-room-reference/context.json +1 -0
  368. package/fixtures/cases/other-room-reference/expected.json +7 -0
  369. package/fixtures/cases/other-room-reference/library/companies/acme.md +4 -0
  370. package/fixtures/cases/other-room-reference/library/deals/renewal.md +17 -0
  371. package/fixtures/cases/other-room-reference/library/places/depot.md +4 -0
  372. package/fixtures/cases/other-room-reference/library/products/seats.md +4 -0
  373. package/fixtures/cases/other-room-reference/library/products/support.md +4 -0
  374. package/fixtures/cases/other-room-reference/schema.yaml +32 -0
  375. package/fixtures/cases/paragraph-link-definition/schema.yaml +1 -0
  376. package/fixtures/cases/prototype-field/context.json +1 -0
  377. package/fixtures/cases/prototype-field/expected.json +7 -0
  378. package/fixtures/cases/prototype-field/library/item.md +9 -0
  379. package/fixtures/cases/prototype-field/schema.yaml +5 -0
  380. package/fixtures/cases/quoted-link-definition/expected.json +1 -2
  381. package/fixtures/cases/quoted-link-definition/library/notes/draft.md +1 -1
  382. package/fixtures/cases/quoted-link-definition/schema.yaml +1 -0
  383. package/fixtures/cases/reference-into-a-reserved-name/context.json +1 -0
  384. package/fixtures/cases/reference-into-a-reserved-name/expected.json +7 -0
  385. package/fixtures/cases/reference-into-a-reserved-name/library/notes/a.md +4 -0
  386. package/fixtures/cases/reference-into-a-reserved-name/library/settings/brief.md +1 -0
  387. package/fixtures/cases/reference-into-a-reserved-name/schema.yaml +3 -0
  388. package/fixtures/cases/referenced-missing-file/expected.json +0 -1
  389. package/fixtures/cases/referenced-missing-file/library/a.md +2 -2
  390. package/fixtures/cases/referenced-missing-file/library/b.md +2 -2
  391. package/fixtures/cases/referenced-missing-file/schema.yaml +10 -0
  392. package/fixtures/cases/remote-ref/context.json +1 -0
  393. package/fixtures/cases/remote-ref/expected.json +5 -0
  394. package/fixtures/cases/remote-ref/schema.yaml +3 -0
  395. package/fixtures/cases/room-md-declares-a-type/context.json +1 -0
  396. package/fixtures/cases/room-md-declares-a-type/expected.json +6 -0
  397. package/fixtures/cases/room-md-declares-a-type/library/ROOM.md +5 -0
  398. package/fixtures/cases/second-member-document/context.json +1 -0
  399. package/fixtures/cases/second-member-document/expected.json +5 -0
  400. package/fixtures/cases/second-member-document/schema.yaml +4 -0
  401. package/fixtures/cases/sections-keyword-refused/context.json +1 -0
  402. package/fixtures/cases/sections-keyword-refused/expected.json +5 -0
  403. package/fixtures/cases/sections-keyword-refused/schema.yaml +6 -0
  404. package/fixtures/cases/shortcut-reference-link/context.json +1 -0
  405. package/fixtures/cases/shortcut-reference-link/expected.json +5 -0
  406. package/fixtures/cases/shortcut-reference-link/library/item.md +10 -0
  407. package/fixtures/cases/shortcut-reference-link/schema.yaml +5 -0
  408. package/fixtures/cases/string-length/context.json +1 -0
  409. package/fixtures/cases/string-length/expected.json +7 -0
  410. package/fixtures/cases/string-length/library/companies/acme.md +4 -0
  411. package/fixtures/cases/string-length/library/deals/renewal.md +56 -0
  412. package/fixtures/cases/string-length/schema.yaml +55 -0
  413. package/fixtures/cases/submission-keys/context.json +1 -0
  414. package/fixtures/cases/submission-keys/expected.json +1 -0
  415. package/fixtures/cases/submission-keys/library/notes/visitor.md +8 -0
  416. package/fixtures/cases/submission-keys/schema.yaml +4 -0
  417. package/fixtures/cases/text-field-kind/context.json +1 -0
  418. package/fixtures/cases/text-field-kind/expected.json +3 -0
  419. package/fixtures/cases/text-field-kind/library/page.md +4 -0
  420. package/fixtures/cases/text-field-kind/schema.yaml +4 -0
  421. package/fixtures/cases/thematic-break-ends-the-values/context.json +1 -0
  422. package/fixtures/cases/thematic-break-ends-the-values/expected.json +1 -0
  423. package/fixtures/cases/thematic-break-ends-the-values/library/item.md +10 -0
  424. package/fixtures/cases/thematic-break-ends-the-values/schema.yaml +3 -0
  425. package/fixtures/cases/truncated-link-definition/expected.json +1 -2
  426. package/fixtures/cases/truncated-link-definition/library/notes/draft.md +1 -1
  427. package/fixtures/cases/truncated-link-definition/schema.yaml +1 -0
  428. package/fixtures/cases/typed-path-names-another-type/context.json +11 -0
  429. package/fixtures/cases/typed-path-names-another-type/expected.json +6 -0
  430. package/fixtures/cases/typed-path-names-another-type/library/settings/prefs/one.md +3 -0
  431. package/fixtures/cases/typed-path-names-another-type/schema.yaml +6 -0
  432. package/fixtures/cases/typed-path-names-its-type/context.json +11 -0
  433. package/fixtures/cases/typed-path-names-its-type/expected.json +3 -0
  434. package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/deeper/two.md +1 -0
  435. package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/one.md +4 -0
  436. package/fixtures/cases/typed-path-names-its-type/schema.yaml +6 -0
  437. package/fixtures/cases/typed-path-names-no-type/context.json +11 -0
  438. package/fixtures/cases/typed-path-names-no-type/expected.json +6 -0
  439. package/fixtures/cases/typed-path-names-no-type/library/settings/prefs/one.md +1 -0
  440. package/fixtures/cases/typed-path-names-no-type/schema.yaml +6 -0
  441. package/fixtures/cases/types-folder-content/context.json +1 -0
  442. package/fixtures/cases/types-folder-content/expected.json +1 -0
  443. package/fixtures/cases/types-folder-content/library/types/task.md +4 -0
  444. package/fixtures/cases/types-folder-content/schema.yaml +4 -0
  445. package/fixtures/cases/unclosed-frontmatter/expected.json +1 -2
  446. package/fixtures/cases/undeclared-field/context.json +1 -0
  447. package/fixtures/cases/undeclared-field/expected.json +7 -0
  448. package/fixtures/cases/undeclared-field/library/item.md +9 -0
  449. package/fixtures/cases/undeclared-field/schema.yaml +5 -0
  450. package/fixtures/cases/unevaluated-items-closed/context.json +1 -0
  451. package/fixtures/cases/unevaluated-items-closed/expected.json +7 -0
  452. package/fixtures/cases/unevaluated-items-closed/library/trip.md +16 -0
  453. package/fixtures/cases/unevaluated-items-closed/schema.yaml +10 -0
  454. package/fixtures/cases/unknown-type/context.json +1 -0
  455. package/fixtures/cases/unknown-type/expected.json +6 -0
  456. package/fixtures/cases/unknown-type/library/item.md +3 -0
  457. package/fixtures/cases/unknown-type/schema.yaml +3 -0
  458. package/fixtures/cases/unlisted-reference-type/context.json +1 -0
  459. package/fixtures/cases/unlisted-reference-type/expected.json +5 -0
  460. package/fixtures/cases/unlisted-reference-type/schema.yaml +3 -0
  461. package/fixtures/cases/unnamed-typed-path-checks-its-fields/context.json +11 -0
  462. package/fixtures/cases/unnamed-typed-path-checks-its-fields/expected.json +6 -0
  463. package/fixtures/cases/unnamed-typed-path-checks-its-fields/library/rooms/team/tasks/plan.md +5 -0
  464. package/fixtures/cases/unnamed-typed-path-checks-its-fields/schema.yaml +5 -0
  465. package/fixtures/cases/unnamed-typed-path-names-a-type/context.json +11 -0
  466. package/fixtures/cases/unnamed-typed-path-names-a-type/expected.json +6 -0
  467. package/fixtures/cases/unnamed-typed-path-names-a-type/library/rooms/team/tasks/plan.md +7 -0
  468. package/fixtures/cases/unnamed-typed-path-names-a-type/schema.yaml +5 -0
  469. package/fixtures/cases/unnamed-typed-path-reads-its-type/context.json +11 -0
  470. package/fixtures/cases/unnamed-typed-path-reads-its-type/expected.json +3 -0
  471. package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/plan.md +1 -0
  472. package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/tasks/plan.md +6 -0
  473. package/fixtures/cases/unnamed-typed-path-reads-its-type/schema.yaml +5 -0
  474. package/fixtures/cases/unnamed-typed-path-without-a-body/context.json +11 -0
  475. package/fixtures/cases/unnamed-typed-path-without-a-body/expected.json +5 -0
  476. package/fixtures/cases/unnamed-typed-path-without-a-body/library/rooms/team/tasks/plan.md +5 -0
  477. package/fixtures/cases/unnamed-typed-path-without-a-body/schema.yaml +5 -0
  478. package/fixtures/cases/unresolved-link/expected.json +1 -2
  479. package/fixtures/cases/unresolved-link/library/item.md +2 -2
  480. package/fixtures/cases/unresolved-link/schema.yaml +5 -0
  481. package/fixtures/cases/valid-typed-document/library/people/ada.md +1 -1
  482. package/fixtures/cases/valid-typed-document/library/tasks/one.md +11 -10
  483. package/fixtures/cases/valid-typed-document/schema.yaml +15 -0
  484. package/fixtures/cases/wide-item-fence-link/schema.yaml +1 -0
  485. package/fixtures/division.json +454 -0
  486. package/fixtures/forms.json +347 -0
  487. package/fixtures/preamble.json +26 -5
  488. package/fixtures/projection.json +216 -32
  489. package/fixtures/queries.json +964 -0
  490. package/package.json +20 -13
  491. package/dist/definition.js.map +0 -1
  492. package/dist/document.js.map +0 -1
  493. package/dist/index.js.map +0 -1
  494. package/dist/links.d.ts +0 -25
  495. package/dist/links.d.ts.map +0 -1
  496. package/dist/links.js +0 -380
  497. package/dist/links.js.map +0 -1
  498. package/dist/paths.js.map +0 -1
  499. package/dist/profile.d.ts +0 -6
  500. package/dist/profile.d.ts.map +0 -1
  501. package/dist/profile.js +0 -7
  502. package/dist/profile.js.map +0 -1
  503. package/dist/project.js.map +0 -1
  504. package/dist/refuse.js.map +0 -1
  505. package/dist/schema.js.map +0 -1
  506. package/dist/sections.d.ts +0 -10
  507. package/dist/sections.d.ts.map +0 -1
  508. package/dist/sections.js +0 -79
  509. package/dist/sections.js.map +0 -1
  510. package/dist/types.js.map +0 -1
  511. package/dist/validate.js.map +0 -1
  512. package/dist/version.js.map +0 -1
  513. package/dist/yaml.js.map +0 -1
  514. package/fixtures/cases/binary-any-reference/library/types/note.md +0 -5
  515. package/fixtures/cases/binary-document-collision/library/types/note.md +0 -3
  516. package/fixtures/cases/binary-link-outside-collection/library/types/note.md +0 -3
  517. package/fixtures/cases/binary-prototype-reference/library/types/note.md +0 -5
  518. package/fixtures/cases/binary-typed-reference/library/types/note.md +0 -5
  519. package/fixtures/cases/binary-typed-reference/library/types/person.md +0 -3
  520. package/fixtures/cases/bracketed-link-definition/library/types/task.md +0 -7
  521. package/fixtures/cases/declared-binary-links/library/types/note.md +0 -3
  522. package/fixtures/cases/duplicate-link-definition/library/types/task.md +0 -7
  523. package/fixtures/cases/fenced-link-definition/library/types/task.md +0 -7
  524. package/fixtures/cases/field-enum/library/types/task.md +0 -8
  525. package/fixtures/cases/interrupted-link-definition/library/types/note.md +0 -3
  526. package/fixtures/cases/long-fence-link-definition/library/types/note.md +0 -3
  527. package/fixtures/cases/malformed-definition/library/types/task.md +0 -5
  528. package/fixtures/cases/missing-binary-image/expected.json +0 -6
  529. package/fixtures/cases/missing-binary-image/library/types/note.md +0 -3
  530. package/fixtures/cases/missing-binary-link/expected.json +0 -6
  531. package/fixtures/cases/missing-binary-link/library/types/note.md +0 -3
  532. package/fixtures/cases/missing-required-field/library/types/task.md +0 -8
  533. package/fixtures/cases/paragraph-link-definition/library/types/note.md +0 -3
  534. package/fixtures/cases/prd-definition/library/types/task.md +0 -15
  535. package/fixtures/cases/quoted-link-definition/library/types/note.md +0 -3
  536. package/fixtures/cases/referenced-missing-file/library/types/person.md +0 -5
  537. package/fixtures/cases/referenced-missing-file/library/types/task.md +0 -8
  538. package/fixtures/cases/structured-section/expected.json +0 -7
  539. package/fixtures/cases/structured-section/library/types/task.md +0 -8
  540. package/fixtures/cases/truncated-link-definition/library/types/note.md +0 -3
  541. package/fixtures/cases/unresolved-link/library/types/task.md +0 -7
  542. package/fixtures/cases/valid-typed-document/library/types/person.md +0 -5
  543. package/fixtures/cases/valid-typed-document/library/types/task.md +0 -12
  544. package/fixtures/cases/wide-item-fence-link/library/types/note.md +0 -3
  545. package/markdown-syntax-profile.md +0 -9
  546. /package/fixtures/cases/{prd-definition → absent-link-dangles}/context.json +0 -0
  547. /package/fixtures/cases/{prd-definition → absent-link-dangles}/expected.json +0 -0
  548. /package/fixtures/cases/{structured-section → absent-optional-field}/context.json +0 -0
  549. /package/fixtures/cases/{missing-binary-image → binary-image-dangles}/context.json +0 -0
  550. /package/fixtures/cases/{missing-binary-image → binary-image-dangles}/library/notes/draft.md +0 -0
  551. /package/fixtures/cases/{missing-binary-link → binary-link-dangles}/context.json +0 -0
  552. /package/fixtures/cases/{missing-binary-link → binary-link-dangles}/library/notes/draft.md +0 -0
@@ -1,165 +1,880 @@
1
- import { typeNameFromPath } from './paths.js';
2
- import { refusal } from './refuse.js';
3
- function refuse(file, rule, location) {
4
- return location === undefined ? refusal(file, rule) : refusal(file, rule, {
5
- location
6
- });
1
+ import { MEMBER_FIELD, SITE_FIELD, SUBMITTED_FIELD, TYPE_FIELD } from './fields.js';
2
+ import { MEDIA_TYPES } from './media-type.js';
3
+ import { linearPattern } from './pattern.js';
4
+ import { equalValue, isRecord, jsValue, parseYamlMapping, YamlError } from './yaml.js';
5
+ export const JSON_TYPES = [
6
+ 'string',
7
+ 'number',
8
+ 'integer',
9
+ 'boolean',
10
+ 'object',
11
+ 'array',
12
+ 'null',
13
+ ];
14
+ export const BUILT_IN_TYPE = 'any';
15
+ export const ATTACHMENT = 'attachment';
16
+ const COMPOSITES = ['array', 'object'];
17
+ const ANNOTATIONS = new Set([
18
+ '$comment',
19
+ 'title',
20
+ 'description',
21
+ 'default',
22
+ 'examples',
23
+ 'deprecated',
24
+ 'readOnly',
25
+ 'writeOnly',
26
+ ]);
27
+ export const OPENING = ['additionalProperties', 'unevaluatedProperties'];
28
+ const FIELD_RULES = ['change_roles', 'initial_roles', 'transitions'];
29
+ const PROVIDED_KEYWORDS = ['create_roles', 'delete_roles'];
30
+ const NO_TYPES = Object.freeze({ types: Object.freeze({}) });
31
+ const DEFS_REFERENCE = '#/$defs/';
32
+ const UNBOUNDED_FORMAT = 'url';
33
+ const UNIONS = ['anyOf', 'oneOf'];
34
+ const UNRESOLVED = /[\u0000-\u001f\u007f%[\]\\^{|}]|\s$/u;
35
+ export const ARRAY_INDEX = /^(?:0|[1-9][0-9]*)$/u;
36
+ export const JSON_POINTER = /^(?:\/(?:[^~/]|~[01])*)*$/u;
37
+ const HOUSE_KEYS = {
38
+ [TYPE_FIELD]: { prose: false },
39
+ [SITE_FIELD]: { prose: false },
40
+ [SUBMITTED_FIELD]: { prose: false },
41
+ };
42
+ export function refuse(rule, location) {
43
+ return { rule, location };
44
+ }
45
+ export function escapePointer(key) {
46
+ return key.replaceAll('~', '~0').replaceAll('/', '~1');
47
+ }
48
+ function unescapePointer(segment) {
49
+ return segment.replaceAll('~1', '/').replaceAll('~0', '~');
50
+ }
51
+ export function pointerSegments(pointer) {
52
+ return pointer.split('/').slice(1).map(unescapePointer);
53
+ }
54
+ export function refTarget(reference, defs) {
55
+ const pointer = reference.slice('#'.length);
56
+ if (!reference.startsWith(DEFS_REFERENCE) ||
57
+ UNRESOLVED.test(reference) ||
58
+ !JSON_POINTER.test(pointer))
59
+ return undefined;
60
+ const [, name = '', ...rest] = pointerSegments(pointer);
61
+ if (!Object.hasOwn(defs, name))
62
+ return undefined;
63
+ let node = defs[name];
64
+ for (let index = 0; index < rest.length; index += 1) {
65
+ const keyword = rest[index];
66
+ if (!isRecord(node) || !Object.hasOwn(node, keyword) || !Object.hasOwn(KEYWORDS, keyword))
67
+ return undefined;
68
+ const check = KEYWORDS[keyword];
69
+ const held = node[keyword];
70
+ if (check === SCHEMA) {
71
+ node = held;
72
+ continue;
73
+ }
74
+ const key = rest[index + 1];
75
+ index += 1;
76
+ if (check === SCHEMA_LIST && Array.isArray(held) && key !== undefined && ARRAY_INDEX.test(key))
77
+ node = held[Number(key)];
78
+ else if (check === SCHEMA_MAP &&
79
+ isRecord(held) &&
80
+ key !== undefined &&
81
+ Object.hasOwn(held, key))
82
+ node = held[key];
83
+ else
84
+ return undefined;
85
+ if (node === undefined)
86
+ return undefined;
87
+ }
88
+ return { name, node };
89
+ }
90
+ function compiles(pattern) {
91
+ return typeof pattern === 'string' && linearPattern(pattern) !== null;
92
+ }
93
+ function finite(value) {
94
+ return typeof value === 'number' && Number.isFinite(value);
95
+ }
96
+ function count(value) {
97
+ return Number.isSafeInteger(value) && value >= 0;
7
98
  }
8
- function isRecord(value) {
9
- return value !== null && typeof value === 'object' && !Array.isArray(value);
99
+ function strings(value) {
100
+ return (Array.isArray(value) &&
101
+ value.every((item) => typeof item === 'string') &&
102
+ new Set(value).size === value.length);
10
103
  }
11
- function requiredFlag(value) {
12
- if (value === undefined) return false;
13
- if (typeof value === 'boolean') return value;
104
+ function schemaFailure(value, at, context) {
105
+ if (!context.checked || typeof value === 'boolean')
106
+ return undefined;
107
+ if (!isRecord(value))
108
+ return refuse('schema', at);
109
+ for (const [key, held] of Object.entries(value)) {
110
+ const where = `${at}/${escapePointer(key)}`;
111
+ if (!Object.hasOwn(KEYWORDS, key))
112
+ return refuse('schema-keyword', where);
113
+ const check = KEYWORDS[key];
114
+ if (check === SCHEMA) {
115
+ const failure = schemaFailure(held, where, context);
116
+ if (failure !== undefined)
117
+ return failure;
118
+ continue;
119
+ }
120
+ if (check === SCHEMA_LIST) {
121
+ if (!Array.isArray(held) || held.length === 0)
122
+ return refuse(key, where);
123
+ for (const [index, item] of held.entries()) {
124
+ const failure = schemaFailure(item, `${where}/${index}`, context);
125
+ if (failure !== undefined)
126
+ return failure;
127
+ }
128
+ continue;
129
+ }
130
+ if (check === SCHEMA_MAP) {
131
+ if (!isRecord(held))
132
+ return refuse(key, where);
133
+ for (const [name, item] of Object.entries(held)) {
134
+ if (key === 'patternProperties' && !compiles(name))
135
+ return refuse(key, `${where}/${escapePointer(name)}`);
136
+ const failure = schemaFailure(item, `${where}/${escapePointer(name)}`, context);
137
+ if (failure !== undefined)
138
+ return failure;
139
+ }
140
+ continue;
141
+ }
142
+ if (!check(held, where, value, context))
143
+ return refuse(key, where);
144
+ }
14
145
  return undefined;
15
146
  }
16
- function stringList(value) {
17
- if (!Array.isArray(value) || value.length === 0) return undefined;
18
- if (!value.every((item)=>typeof item === 'string' && item !== '')) return undefined;
19
- return value;
147
+ const SCHEMA = () => true;
148
+ const SCHEMA_LIST = () => true;
149
+ const SCHEMA_MAP = () => true;
150
+ const ANY = () => true;
151
+ const TEXT = (value) => typeof value === 'string';
152
+ const FLAG = (value) => typeof value === 'boolean';
153
+ const NUMBER = finite;
154
+ const COUNT = count;
155
+ const KEYWORDS = {
156
+ $comment: TEXT,
157
+ $ref: (value, _at, _node, context) => typeof value === 'string' && refTarget(value, context.defs) !== undefined,
158
+ $defs: SCHEMA_MAP,
159
+ allOf: SCHEMA_LIST,
160
+ anyOf: SCHEMA_LIST,
161
+ oneOf: SCHEMA_LIST,
162
+ prefixItems: SCHEMA_LIST,
163
+ not: SCHEMA,
164
+ if: SCHEMA,
165
+ then: SCHEMA,
166
+ else: SCHEMA,
167
+ items: SCHEMA,
168
+ contains: SCHEMA,
169
+ additionalProperties: SCHEMA,
170
+ unevaluatedProperties: SCHEMA,
171
+ unevaluatedItems: SCHEMA,
172
+ propertyNames: SCHEMA,
173
+ contentSchema: SCHEMA,
174
+ properties: SCHEMA_MAP,
175
+ patternProperties: SCHEMA_MAP,
176
+ dependentSchemas: SCHEMA_MAP,
177
+ type: (value) => (typeof value === 'string' && JSON_TYPES.includes(value)) ||
178
+ (Array.isArray(value) &&
179
+ value.length > 0 &&
180
+ strings(value) &&
181
+ value.every((item) => JSON_TYPES.includes(item))),
182
+ enum: (value) => Array.isArray(value) && value.length > 0,
183
+ const: ANY,
184
+ multipleOf: (value) => finite(value) && value > 0,
185
+ maximum: NUMBER,
186
+ exclusiveMaximum: NUMBER,
187
+ minimum: NUMBER,
188
+ exclusiveMinimum: NUMBER,
189
+ maxLength: COUNT,
190
+ minLength: COUNT,
191
+ maxItems: COUNT,
192
+ minItems: COUNT,
193
+ maxContains: COUNT,
194
+ minContains: COUNT,
195
+ maxProperties: COUNT,
196
+ minProperties: COUNT,
197
+ pattern: compiles,
198
+ uniqueItems: FLAG,
199
+ required: strings,
200
+ dependentRequired: (value) => isRecord(value) && Object.values(value).every(strings),
201
+ format: (value) => typeof value === 'string' && value !== UNBOUNDED_FORMAT,
202
+ contentEncoding: TEXT,
203
+ contentMediaType: TEXT,
204
+ title: TEXT,
205
+ description: TEXT,
206
+ default: ANY,
207
+ examples: (value) => Array.isArray(value),
208
+ deprecated: FLAG,
209
+ readOnly: FLAG,
210
+ writeOnly: FLAG,
211
+ reference: (value, _at, node, context) => {
212
+ if (node.type !== 'string')
213
+ return false;
214
+ const named = typeof value === 'string' ? [value] : value;
215
+ return (Array.isArray(named) &&
216
+ named.length > 0 &&
217
+ strings(named) &&
218
+ named.every((name) => name === BUILT_IN_TYPE ||
219
+ name === ATTACHMENT ||
220
+ context.types.has(name) ||
221
+ node.cross_room === true));
222
+ },
223
+ cross_room: (value, _at, node) => typeof value === 'boolean' && node.reference !== undefined,
224
+ };
225
+ function sharedType(values) {
226
+ if (values.length === 0)
227
+ return undefined;
228
+ if (values.every((value) => typeof value === 'string'))
229
+ return 'string';
230
+ if (values.every((value) => typeof value === 'number'))
231
+ return 'number';
232
+ if (values.every((value) => typeof value === 'boolean'))
233
+ return 'boolean';
234
+ return undefined;
20
235
  }
21
- const SCALAR_KINDS = new Set([
22
- 'string',
23
- 'number',
24
- 'date',
25
- 'enum',
26
- 'reference'
27
- ]);
28
- function parseScalar(file, location, spec, required) {
29
- const kind = spec.kind;
30
- if (kind === 'string') return {
31
- kind: 'string',
32
- required
236
+ function singleType(type) {
237
+ if (typeof type === 'string')
238
+ return type;
239
+ if (!Array.isArray(type))
240
+ return undefined;
241
+ const kept = type.filter((one) => one !== 'null');
242
+ return kept.length === 1 ? kept[0] : undefined;
243
+ }
244
+ function firstOf(held, read) {
245
+ for (const node of held) {
246
+ const value = read(node);
247
+ if (value !== undefined)
248
+ return value;
249
+ }
250
+ return undefined;
251
+ }
252
+ export function conjoined(declared, defs, ancestry) {
253
+ const held = [];
254
+ const reached = new Set(ancestry);
255
+ const visit = (node, at) => {
256
+ if (!isRecord(node) || held.some((one) => one.node === node))
257
+ return;
258
+ held.push({ node, at });
259
+ if (typeof node.$ref === 'string') {
260
+ const target = refTarget(node.$ref, defs)?.node;
261
+ if (target !== undefined && !reached.has(target)) {
262
+ reached.add(target);
263
+ visit(target, node.$ref.slice('#'.length));
264
+ }
265
+ }
266
+ if (Array.isArray(node.allOf))
267
+ node.allOf.forEach((one, index) => visit(one, `${at}/allOf/${index}`));
33
268
  };
34
- if (kind === 'number') return {
35
- kind: 'number',
36
- required
269
+ for (const { node, at } of declared)
270
+ visit(node, at);
271
+ return { held, ancestry: reached };
272
+ }
273
+ export function variantsOf({ node, at }) {
274
+ const listed = (keyword) => {
275
+ const branches = node[keyword];
276
+ return Array.isArray(branches)
277
+ ? branches.map((branch, index) => ({ node: branch, at: `${at}/${keyword}/${index}` }))
278
+ : [];
37
279
  };
38
- if (kind === 'date') return {
39
- kind: 'date',
40
- required
280
+ return [
281
+ ...listed('anyOf'),
282
+ ...listed('oneOf'),
283
+ { node: node.then, at: `${at}/then` },
284
+ { node: node.else, at: `${at}/else` },
285
+ ...Object.entries(isRecord(node.dependentSchemas) ? node.dependentSchemas : {}).map(([key, branch]) => ({ node: branch, at: `${at}/dependentSchemas/${escapePointer(key)}` })),
286
+ ].filter((one) => isRecord(one.node));
287
+ }
288
+ function united(left, right) {
289
+ if (left === undefined || right === undefined)
290
+ return undefined;
291
+ return [...left, ...right.filter((value) => !left.some((held) => equalValue(held, value)))];
292
+ }
293
+ function both(left, right) {
294
+ return left !== undefined && right !== undefined ? joined(left, right) : undefined;
295
+ }
296
+ function joined(left, right) {
297
+ const type = left.type === right.type ? left.type : undefined;
298
+ const format = left.format === right.format ? left.format : undefined;
299
+ const values = united(left.values, right.values);
300
+ const reference = united(left.reference, right.reference);
301
+ const crossRoom = left.crossRoom === true || right.crossRoom === true;
302
+ const items = both(left.items, right.items);
303
+ const prefix = left.prefix === undefined && right.prefix === undefined
304
+ ? undefined
305
+ : Array.from({ length: Math.max(left.prefix?.length ?? 0, right.prefix?.length ?? 0) }, (_, index) => both(itemFacts(left, index), itemFacts(right, index)) ?? { prose: false });
306
+ const properties = Object.create(null);
307
+ for (const [name, facts] of Object.entries(left.properties ?? {})) {
308
+ const shared = both(facts, right.properties?.[name]);
309
+ if (shared !== undefined)
310
+ properties[name] = shared;
311
+ }
312
+ const patterns = (left.patterns ?? []).flatMap(({ pattern, facts }) => {
313
+ const shared = both(facts, right.patterns?.find((one) => one.pattern === pattern)?.facts);
314
+ return shared === undefined ? [] : [{ pattern, facts: shared }];
315
+ });
316
+ const additional = both(left.additional, right.additional);
317
+ const title = left.title ?? right.title;
318
+ return {
319
+ ...(type === undefined ? {} : { type }),
320
+ ...(format === undefined ? {} : { format }),
321
+ ...(values === undefined ? {} : { values }),
322
+ ...(reference === undefined ? {} : { reference }),
323
+ ...(reference !== undefined && crossRoom ? { crossRoom: true } : {}),
324
+ prose: left.prose && right.prose,
325
+ ...(title === undefined ? {} : { title }),
326
+ ...(left.markdown === true || right.markdown === true ? { markdown: true } : {}),
327
+ ...(left.json === true || right.json === true ? { json: true } : {}),
328
+ ...(prefix === undefined ? {} : { prefix }),
329
+ ...(items === undefined ? {} : { items }),
330
+ ...(Object.keys(properties).length === 0 ? {} : { properties }),
331
+ ...(patterns.length === 0 ? {} : { patterns }),
332
+ ...(additional === undefined ? {} : { additional }),
41
333
  };
42
- if (kind === 'enum') {
43
- const values = stringList(spec.values);
44
- if (values === undefined) return refuse(file, 'definition-enum-values', location);
45
- return {
46
- kind: 'enum',
47
- required,
48
- values
49
- };
334
+ }
335
+ function propertiesOf(held, variants, defs, ancestry) {
336
+ const declared = new Map();
337
+ for (const node of held) {
338
+ if (!isRecord(node.properties))
339
+ continue;
340
+ for (const [name, schema] of Object.entries(node.properties))
341
+ declared.set(name, [...(declared.get(name) ?? []), schema]);
50
342
  }
51
- if (kind === 'reference') {
52
- if (typeof spec.to !== 'string' || spec.to === '') return refuse(file, 'definition-reference-to', location);
53
- return {
54
- kind: 'reference',
55
- required,
56
- to: spec.to
57
- };
343
+ const properties = Object.create(null);
344
+ for (const [name, schemas] of declared)
345
+ properties[name] = factsOf(schemas, defs, ancestry);
346
+ const conditional = Object.create(null);
347
+ for (const branch of variants.values()) {
348
+ for (const [name, facts] of Object.entries(branch.properties ?? {})) {
349
+ if (Object.hasOwn(properties, name))
350
+ continue;
351
+ conditional[name] = Object.hasOwn(conditional, name)
352
+ ? joined(conditional[name], facts)
353
+ : facts;
354
+ }
58
355
  }
59
- return refuse(file, 'definition-field-kind', location);
356
+ for (const [name, facts] of Object.entries(conditional))
357
+ properties[name] = { ...facts, conditional: true };
358
+ return Object.keys(properties).length === 0 ? undefined : properties;
359
+ }
360
+ function nullOnly(facts) {
361
+ return facts.type === 'null' || (facts.values?.every((value) => value === null) ?? false);
362
+ }
363
+ function alternativesOf(held, variants) {
364
+ return held.flatMap((node) => [node.anyOf, node.oneOf].flatMap((branches) => {
365
+ if (!Array.isArray(branches))
366
+ return [];
367
+ const kept = branches
368
+ .flatMap((branch) => {
369
+ const facts = isRecord(branch) ? variants.get(branch) : undefined;
370
+ return facts === undefined ? [] : [facts];
371
+ })
372
+ .filter((facts) => !nullOnly(facts));
373
+ return kept.length === 0 ? [] : [kept];
374
+ }));
375
+ }
376
+ function inheritedOf(held) {
377
+ return held.flatMap((node) => {
378
+ const kept = Object.fromEntries(['type', 'items', 'prefixItems'].flatMap((key) => node[key] === undefined ? [] : [[key, node[key]]]));
379
+ return Object.keys(kept).length === 0 ? [] : [kept];
380
+ });
381
+ }
382
+ function typeSet(type) {
383
+ const listed = typeof type === 'string' ? [type] : Array.isArray(type) ? type : null;
384
+ return listed === null
385
+ ? null
386
+ : new Set(listed.map((one) => (one === 'integer' ? 'number' : String(one))));
387
+ }
388
+ function valueType(value) {
389
+ if (value === null)
390
+ return 'null';
391
+ if (Array.isArray(value))
392
+ return 'array';
393
+ return typeof value;
60
394
  }
61
- function extraKeys(spec, allowed) {
62
- return Object.keys(spec).some((key)=>!allowed.includes(key));
395
+ function narrowed(left, right) {
396
+ if (left === null)
397
+ return right;
398
+ if (right === null)
399
+ return left;
400
+ return new Set([...left].filter((one) => right.has(one)));
63
401
  }
64
- function parseField(file, location, value) {
65
- if (!isRecord(value) || typeof value.kind !== 'string') return refuse(file, 'definition-field', location);
66
- const required = requiredFlag(value.required);
67
- if (required === undefined) return refuse(file, 'definition-field', location);
68
- if (value.kind === 'list') {
69
- if (typeof value.of !== 'string' || !SCALAR_KINDS.has(value.of)) {
70
- return refuse(file, 'definition-list-of', location);
402
+ function admitted(nodes, defs, ancestry) {
403
+ const conjunction = conjoined(nodes.map((node) => ({ node, at: '' })), defs, ancestry);
404
+ let kept = null;
405
+ for (const { node } of conjunction.held) {
406
+ kept = narrowed(kept, typeSet(node.type));
407
+ if (Array.isArray(node.enum))
408
+ kept = narrowed(kept, new Set(node.enum.map(valueType)));
409
+ if (Object.hasOwn(node, 'const'))
410
+ kept = narrowed(kept, new Set([valueType(node.const)]));
411
+ for (const keyword of UNIONS) {
412
+ const branches = node[keyword];
413
+ if (!Array.isArray(branches))
414
+ continue;
415
+ let union = new Set();
416
+ for (const branch of branches) {
417
+ const one = admitted([branch], defs, conjunction.ancestry);
418
+ if (one === null) {
419
+ union = null;
420
+ break;
421
+ }
422
+ for (const type of one)
423
+ union.add(type);
424
+ }
425
+ kept = narrowed(kept, union);
71
426
  }
72
- const allowed = value.of === 'enum' ? [
73
- 'kind',
74
- 'required',
75
- 'of',
76
- 'values'
77
- ] : value.of === 'reference' ? [
78
- 'kind',
79
- 'required',
80
- 'of',
81
- 'to'
82
- ] : [
83
- 'kind',
84
- 'required',
85
- 'of'
86
- ];
87
- if (extraKeys(value, allowed)) return refuse(file, 'definition-field', location);
88
- const inner = parseScalar(file, location, {
89
- ...value,
90
- kind: value.of
91
- }, false);
92
- if ('rule' in inner) return inner;
93
- return {
94
- kind: 'list',
95
- required,
96
- of: inner
97
- };
98
427
  }
99
- const allowed = value.kind === 'enum' ? [
100
- 'kind',
101
- 'required',
102
- 'values'
103
- ] : value.kind === 'reference' ? [
104
- 'kind',
105
- 'required',
106
- 'to'
107
- ] : [
108
- 'kind',
109
- 'required'
428
+ return kept;
429
+ }
430
+ function structuredUnion(held, defs, ancestry) {
431
+ return held.some((node) => UNIONS.some((keyword) => Array.isArray(node[keyword]) &&
432
+ node[keyword].some((branch) => {
433
+ const types = admitted([branch], defs, ancestry);
434
+ return types === null || types.has('object') || types.has('array');
435
+ })));
436
+ }
437
+ function openWhole(held) {
438
+ return held.some((node) => OPENING.some((keyword) => node[keyword] === true));
439
+ }
440
+ function writtenAsJson(held, defs, ancestry) {
441
+ const types = admitted(held, defs, ancestry);
442
+ if (types === null || types.size !== 1)
443
+ return true;
444
+ return structuredUnion(held, defs, ancestry) || (types.has('object') && openWhole(held));
445
+ }
446
+ function factsOf(nodes, defs, ancestry) {
447
+ const conjunction = conjoined(nodes.map((node) => ({ node, at: '' })), defs, ancestry);
448
+ const reached = conjunction.ancestry;
449
+ const held = conjunction.held.map(({ node }) => node);
450
+ const inherited = inheritedOf(held);
451
+ const variants = new Map(conjunction.held
452
+ .flatMap(variantsOf)
453
+ .map(({ node: branch }) => [branch, factsOf([branch, ...inherited], defs, reached)]));
454
+ const unions = alternativesOf(held, variants);
455
+ const alternatives = unions.map((kept) => kept.reduce(joined));
456
+ const listed = [
457
+ ...held.flatMap((node) => Array.isArray(node.enum) ? [node.enum] : node.const !== undefined ? [[node.const]] : []),
458
+ ...alternatives.flatMap((facts) => (facts.values === undefined ? [] : [facts.values])),
459
+ ];
460
+ const values = listed.length === 0
461
+ ? undefined
462
+ : listed.reduce((kept, list) => kept.filter((value) => list.some((other) => equalValue(other, value))));
463
+ const type = firstOf(held, (node) => singleType(node.type)) ??
464
+ (values === undefined ? undefined : sharedType(values)) ??
465
+ alternatives.find((facts) => facts.type !== undefined)?.type;
466
+ const reference = firstOf(held, (node) => typeof node.reference === 'string'
467
+ ? [node.reference]
468
+ : Array.isArray(node.reference)
469
+ ? node.reference
470
+ : undefined) ?? alternatives.find((facts) => facts.reference !== undefined)?.reference;
471
+ const crossRoom = firstOf(held, (node) => node.reference === undefined ? undefined : node.cross_room === true) ?? alternatives.find((facts) => facts.reference !== undefined)?.crossRoom === true;
472
+ const format = firstOf(held, (node) => (typeof node.format === 'string' ? node.format : undefined)) ??
473
+ alternatives.find((facts) => facts.format !== undefined)?.format;
474
+ const prose = type === 'string' &&
475
+ values === undefined &&
476
+ format === undefined &&
477
+ reference === undefined &&
478
+ held.every((node) => node.pattern === undefined) &&
479
+ unions.every((kept) => kept.every((facts) => facts.type !== 'string' || facts.prose));
480
+ const listedItems = held.flatMap((node) => (node.items === undefined ? [] : [node.items]));
481
+ const items = type !== 'array'
482
+ ? undefined
483
+ : (alternatives.find((facts) => facts.items !== undefined)?.items ??
484
+ (listedItems.length > 0 ? factsOf(listedItems, defs, reached) : undefined));
485
+ const tuples = held.flatMap((node) => Array.isArray(node.prefixItems) ? [node.prefixItems] : []);
486
+ const prefix = type !== 'array'
487
+ ? undefined
488
+ : (alternatives.find((facts) => facts.prefix !== undefined)?.prefix ??
489
+ (tuples.length === 0
490
+ ? undefined
491
+ : Array.from({ length: Math.max(...tuples.map((tuple) => tuple.length)) }, (_, index) => factsOf(tuples.flatMap((tuple) => (index < tuple.length ? [tuple[index]] : [])), defs, reached))));
492
+ const mapped = type === 'object' || type === undefined;
493
+ const properties = mapped ? propertiesOf(held, variants, defs, reached) : undefined;
494
+ const patterns = mapped
495
+ ? held.flatMap((node) => Object.entries(isRecord(node.patternProperties) ? node.patternProperties : {}).map(([pattern, schema]) => ({ pattern, facts: factsOf([schema], defs, reached) })))
496
+ : [];
497
+ const opened = mapped
498
+ ? held.flatMap((node) => OPENING.map((keyword) => (node[keyword] === true ? {} : node[keyword])).filter(isRecord))
499
+ : [];
500
+ const additional = opened.length === 0 ? undefined : factsOf(opened, defs, reached);
501
+ const title = firstOf(nodes.filter(isRecord), (node) => typeof node.title === 'string' ? node.title : undefined);
502
+ const markdown = held.some((node) => node.contentMediaType === MEDIA_TYPES.markdown);
503
+ return {
504
+ ...(type === undefined ? {} : { type }),
505
+ ...(format === undefined ? {} : { format }),
506
+ ...(values === undefined ? {} : { values }),
507
+ ...(reference === undefined ? {} : { reference }),
508
+ ...(reference !== undefined && crossRoom ? { crossRoom: true } : {}),
509
+ prose,
510
+ ...(title === undefined ? {} : { title }),
511
+ ...(markdown ? { markdown: true } : {}),
512
+ ...(writtenAsJson(held, defs, ancestry) ? { json: true } : {}),
513
+ ...(prefix === undefined ? {} : { prefix }),
514
+ ...(items === undefined ? {} : { items }),
515
+ ...(properties === undefined ? {} : { properties }),
516
+ ...(patterns.length === 0 ? {} : { patterns }),
517
+ ...(additional === undefined ? {} : { additional }),
518
+ };
519
+ }
520
+ export function valueFacts(node, defs) {
521
+ return factsOf([node], defs, new Set());
522
+ }
523
+ export function itemFacts(facts, index) {
524
+ return facts.prefix?.[index] ?? facts.items;
525
+ }
526
+ export function memberFacts(facts, key) {
527
+ if (facts.properties !== undefined && Object.hasOwn(facts.properties, key))
528
+ return facts.properties[key];
529
+ const pattern = facts.patterns?.find((one) => linearPattern(one.pattern).test(key));
530
+ return pattern === undefined ? facts.additional : pattern.facts;
531
+ }
532
+ export function crossedFacts(facts) {
533
+ if (facts.type !== 'array')
534
+ return [facts];
535
+ return [...(facts.prefix ?? []), ...(facts.items === undefined ? [] : [facts.items])].flatMap(crossedFacts);
536
+ }
537
+ export function fieldFacts(definition, key) {
538
+ if (Object.hasOwn(definition.fields, key))
539
+ return definition.fields[key];
540
+ if (Object.hasOwn(HOUSE_KEYS, key))
541
+ return undefined;
542
+ return memberFacts(definition.root, key);
543
+ }
544
+ function stepped({ facts, through, conditional }, token) {
545
+ if (facts.type === 'array' && ARRAY_INDEX.test(token)) {
546
+ const item = itemFacts(facts, Number(token));
547
+ return item === undefined ? [] : [{ facts: item, through, conditional }];
548
+ }
549
+ return crossedFacts(facts).flatMap((crossed) => {
550
+ const member = memberFacts(crossed, token);
551
+ return member === undefined
552
+ ? []
553
+ : [
554
+ {
555
+ facts: member,
556
+ through: through || facts.type === 'array',
557
+ conditional: conditional || member.conditional === true,
558
+ },
559
+ ];
560
+ });
561
+ }
562
+ export function pointerFacts(definition, pointer) {
563
+ const [field, ...rest] = pointerSegments(pointer);
564
+ const declared = field === undefined ? undefined : fieldFacts(definition, field);
565
+ if (declared === undefined)
566
+ return undefined;
567
+ let reached = [
568
+ { facts: declared, through: false, conditional: declared.conditional === true },
110
569
  ];
111
- if (extraKeys(value, allowed)) return refuse(file, 'definition-field', location);
112
- return parseScalar(file, location, value, required);
570
+ for (const token of rest)
571
+ reached = reached.flatMap((held) => stepped(held, token));
572
+ if (reached.length === 0)
573
+ return undefined;
574
+ return reached.reduce((kept, held) => ({
575
+ facts: joined(kept.facts, held.facts),
576
+ through: kept.through || held.through,
577
+ conditional: kept.conditional || held.conditional,
578
+ }));
113
579
  }
114
- function parseSection(file, location, value) {
115
- if (!isRecord(value) || value.kind !== 'text' && value.kind !== 'list') {
116
- return refuse(file, 'definition-section-kind', location);
580
+ function reachedDefs(value, defs, reached) {
581
+ if (Array.isArray(value)) {
582
+ for (const item of value)
583
+ reachedDefs(item, defs, reached);
584
+ return;
585
+ }
586
+ if (!isRecord(value))
587
+ return;
588
+ for (const [key, held] of Object.entries(value)) {
589
+ if (key === '$ref' && typeof held === 'string') {
590
+ const name = refTarget(held, defs)?.name;
591
+ if (name === undefined || Object.hasOwn(reached, name))
592
+ continue;
593
+ reached[name] = defs[name];
594
+ reachedDefs(defs[name], defs, reached);
595
+ continue;
596
+ }
597
+ reachedDefs(held, defs, reached);
117
598
  }
118
- const required = requiredFlag(value.required);
119
- if (required === undefined || extraKeys(value, [
120
- 'kind',
121
- 'required'
122
- ])) {
123
- return refuse(file, 'definition-section', location);
599
+ }
600
+ function untitledSchema(node) {
601
+ if (!isRecord(node))
602
+ return node;
603
+ const kept = {};
604
+ for (const [key, held] of Object.entries(node)) {
605
+ if (key === 'title' && typeof held === 'string')
606
+ continue;
607
+ const check = Object.hasOwn(KEYWORDS, key) ? KEYWORDS[key] : undefined;
608
+ if (check === SCHEMA)
609
+ kept[key] = untitledSchema(held);
610
+ else if (check === SCHEMA_LIST && Array.isArray(held))
611
+ kept[key] = held.map(untitledSchema);
612
+ else if (check === SCHEMA_MAP && isRecord(held))
613
+ kept[key] = untitledMap(held);
614
+ else
615
+ kept[key] = held;
124
616
  }
617
+ return kept;
618
+ }
619
+ function untitledMap(map) {
620
+ return Object.fromEntries(Object.entries(map).map(([key, held]) => [key, untitledSchema(held)]));
621
+ }
622
+ function untitledFacts(facts) {
623
+ const { title: _title, prefix, items, properties, patterns, additional, ...kept } = facts;
125
624
  return {
126
- kind: value.kind,
127
- required
625
+ ...kept,
626
+ ...(prefix === undefined ? {} : { prefix: prefix.map(untitledFacts) }),
627
+ ...(items === undefined ? {} : { items: untitledFacts(items) }),
628
+ ...(properties === undefined
629
+ ? {}
630
+ : {
631
+ properties: Object.fromEntries(Object.entries(properties).map(([key, held]) => [key, untitledFacts(held)])),
632
+ }),
633
+ ...(patterns === undefined
634
+ ? {}
635
+ : {
636
+ patterns: patterns.map(({ pattern, facts: held }) => ({
637
+ pattern,
638
+ facts: untitledFacts(held),
639
+ })),
640
+ }),
641
+ ...(additional === undefined ? {} : { additional: untitledFacts(additional) }),
128
642
  };
129
643
  }
130
- export function readDefinition(file, document) {
131
- if (document.type !== 'definition') return refuse(file, 'definition-type');
132
- const name = typeNameFromPath(file);
133
- if (name === '') return refuse(file, 'definition-type');
134
- for (const key of Object.keys(document.fields)){
135
- if (key !== 'type' && key !== 'fields' && key !== 'sections') {
136
- return refuse(file, 'definition-shape', key);
137
- }
644
+ export function untitled(definition) {
645
+ return {
646
+ ...definition,
647
+ root: untitledFacts(definition.root),
648
+ fields: Object.fromEntries(Object.entries(definition.fields).map(([key, held]) => [key, untitledFacts(held)])),
649
+ shape: {
650
+ schema: untitledSchema(definition.shape.schema),
651
+ defs: untitledMap(definition.shape.defs),
652
+ },
653
+ };
654
+ }
655
+ function deepFreeze(value) {
656
+ if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
657
+ Object.freeze(value);
658
+ for (const held of Object.values(value))
659
+ deepFreeze(held);
138
660
  }
139
- const fieldsValue = document.fields.fields;
140
- const sectionsValue = document.fields.sections;
141
- if (fieldsValue !== undefined && !isRecord(fieldsValue)) return refuse(file, 'definition-fields', 'fields');
142
- if (sectionsValue !== undefined && !isRecord(sectionsValue)) {
143
- return refuse(file, 'definition-sections', 'sections');
661
+ return value;
662
+ }
663
+ function ruleValue(value) {
664
+ return value === null || typeof value === 'string' || typeof value === 'boolean' || finite(value);
665
+ }
666
+ function roleNames(value) {
667
+ return strings(value) && value.every((name) => name !== '');
668
+ }
669
+ function compositesOf(value) {
670
+ return Array.isArray(value) ? ['array'] : isRecord(value) ? ['object'] : [];
671
+ }
672
+ function typed(type) {
673
+ const types = typeof type === 'string' ? [type] : type;
674
+ return Array.isArray(types) ? COMPOSITES.filter((kind) => types.includes(kind)) : undefined;
675
+ }
676
+ function admittedWhole(node) {
677
+ if (node === true)
678
+ return COMPOSITES;
679
+ if (!isRecord(node) || Object.keys(node).some((key) => key !== 'type' && !ANNOTATIONS.has(key)))
680
+ return [];
681
+ return typed(node.type) ?? COMPOSITES;
682
+ }
683
+ function composites(node, defs, seen) {
684
+ if (node === false)
685
+ return [];
686
+ if (!isRecord(node))
687
+ return COMPOSITES;
688
+ const each = (nodes) => Array.isArray(nodes) ? nodes.map((one) => composites(one, defs, seen)) : [];
689
+ const target = typeof node.$ref === 'string' ? refTarget(node.$ref, defs)?.node : undefined;
690
+ const conditioned = () => {
691
+ const met = composites(node.then ?? true, defs, seen);
692
+ const condition = composites(node.if, defs, seen);
693
+ const otherwise = composites(node.else ?? true, defs, seen);
694
+ return COMPOSITES.filter((kind) => (condition.includes(kind) && met.includes(kind)) || otherwise.includes(kind));
695
+ };
696
+ const bounds = [
697
+ typed(node.type),
698
+ Array.isArray(node.enum) ? node.enum.flatMap(compositesOf) : undefined,
699
+ Object.hasOwn(node, 'const') ? compositesOf(node.const) : undefined,
700
+ target === undefined || seen.has(target)
701
+ ? undefined
702
+ : composites(target, defs, new Set([...seen, target])),
703
+ ...each(node.allOf),
704
+ ...[node.anyOf, node.oneOf].filter(Array.isArray).map((branches) => each(branches).flat()),
705
+ Object.hasOwn(node, 'if') ? conditioned() : undefined,
706
+ Object.hasOwn(node, 'not')
707
+ ? COMPOSITES.filter((kind) => !admittedWhole(node.not).includes(kind))
708
+ : undefined,
709
+ ];
710
+ return COMPOSITES.filter((kind) => bounds.every((bound) => bound?.includes(kind) ?? true));
711
+ }
712
+ function transitionOf(value) {
713
+ if (!isRecord(value) || !Object.hasOwn(value, 'from') || !Object.hasOwn(value, 'to'))
714
+ return undefined;
715
+ const { from, to, roles, ...rest } = value;
716
+ if (Object.keys(rest).length > 0 || !ruleValue(from) || !ruleValue(to))
717
+ return undefined;
718
+ if (roles === undefined)
719
+ return { from, to };
720
+ return roleNames(roles) ? { from, to, roles } : undefined;
721
+ }
722
+ function fieldRules(written, field, at, defs) {
723
+ const { change_roles: changeRoles, initial_roles: initialRoles, transitions } = written;
724
+ if (changeRoles !== undefined && !roleNames(changeRoles))
725
+ return refuse('change_roles', `${at}/change_roles`);
726
+ if (initialRoles !== undefined && !roleNames(initialRoles))
727
+ return refuse('initial_roles', `${at}/initial_roles`);
728
+ if (transitions === undefined)
729
+ return {
730
+ ...(changeRoles === undefined ? {} : { changeRoles }),
731
+ ...(initialRoles === undefined ? {} : { initialRoles }),
732
+ };
733
+ if (!Array.isArray(transitions) || composites(field, defs, new Set()).length > 0)
734
+ return refuse('transitions', `${at}/transitions`);
735
+ const listed = [];
736
+ for (const [index, held] of transitions.entries()) {
737
+ const transition = transitionOf(held);
738
+ if (transition === undefined)
739
+ return refuse('transitions', `${at}/transitions/${index}`);
740
+ listed.push(transition);
144
741
  }
145
- const fields = {};
146
- for (const [fieldName, spec] of Object.entries(fieldsValue ?? {})){
147
- const parsed = parseField(file, fieldName, spec);
148
- if ('rule' in parsed) return parsed;
149
- fields[fieldName] = parsed;
742
+ return {
743
+ ...(changeRoles === undefined ? {} : { changeRoles }),
744
+ ...(initialRoles === undefined ? {} : { initialRoles }),
745
+ transitions: listed,
746
+ };
747
+ }
748
+ function unruled(schema) {
749
+ const written = new Map();
750
+ if (!isRecord(schema.properties))
751
+ return { schema, written };
752
+ const properties = Object.create(null);
753
+ for (const [field, node] of Object.entries(schema.properties)) {
754
+ if (!isRecord(node) || !FIELD_RULES.some((keyword) => Object.hasOwn(node, keyword))) {
755
+ properties[field] = node;
756
+ continue;
757
+ }
758
+ written.set(field, node);
759
+ properties[field] = Object.fromEntries(Object.entries(node).filter(([keyword]) => !FIELD_RULES.includes(keyword)));
150
760
  }
151
- const sections = {};
152
- for (const [sectionName, spec] of Object.entries(sectionsValue ?? {})){
153
- const parsed = parseSection(file, sectionName, spec);
154
- if ('rule' in parsed) return parsed;
155
- sections[sectionName] = parsed;
761
+ return { schema: written.size === 0 ? schema : { ...schema, properties }, written };
762
+ }
763
+ function providedType(name, value, provided, checked) {
764
+ const at = `/${escapePointer(name)}`;
765
+ if (checked && provided.nameable?.includes(name) !== true)
766
+ return refuse('provided-type', at);
767
+ if (!isRecord(value))
768
+ return refuse('schema', at);
769
+ const declared = Object.keys(value).find((key) => !PROVIDED_KEYWORDS.includes(key));
770
+ if (checked && declared !== undefined)
771
+ return refuse('provided-type', `${at}/${escapePointer(declared)}`);
772
+ const { create_roles: createRoles, delete_roles: deleteRoles } = value;
773
+ if (createRoles !== undefined && !roleNames(createRoles))
774
+ return refuse('create_roles', `${at}/create_roles`);
775
+ if (deleteRoles !== undefined && !roleNames(deleteRoles))
776
+ return refuse('delete_roles', `${at}/delete_roles`);
777
+ return {
778
+ ...provided.types[name],
779
+ ...(createRoles === undefined ? {} : { createRoles }),
780
+ ...(deleteRoles === undefined ? {} : { deleteRoles }),
781
+ };
782
+ }
783
+ function readType(name, value, context) {
784
+ const at = `/${escapePointer(name)}`;
785
+ if (!isRecord(value))
786
+ return refuse('schema', at);
787
+ const { member_document: mark, create_roles: createRoles, delete_roles: deleteRoles, ...ruled } = value;
788
+ if (mark !== undefined && typeof mark !== 'boolean')
789
+ return refuse('member_document', `${at}/member_document`);
790
+ if (createRoles !== undefined && !roleNames(createRoles))
791
+ return refuse('create_roles', `${at}/create_roles`);
792
+ if (deleteRoles !== undefined && !roleNames(deleteRoles))
793
+ return refuse('delete_roles', `${at}/delete_roles`);
794
+ const { schema, written } = unruled(ruled);
795
+ const failure = schemaFailure(schema, at, context);
796
+ if (failure !== undefined)
797
+ return failure;
798
+ const rules = Object.create(null);
799
+ for (const [field, keywords] of written) {
800
+ const properties = schema.properties;
801
+ const where = `${at}/properties/${escapePointer(field)}`;
802
+ const ruling = fieldRules(keywords, properties[field], where, context.defs);
803
+ if ('rule' in ruling)
804
+ return ruling;
805
+ rules[field] = ruling;
156
806
  }
807
+ const memberDocument = mark === true;
808
+ const root = valueFacts(schema, context.defs);
809
+ const fields = Object.assign(Object.create(null), root.properties);
810
+ if (memberDocument && !Object.hasOwn(fields, MEMBER_FIELD))
811
+ fields[MEMBER_FIELD] = { type: 'string', prose: false };
812
+ const defs = Object.create(null);
813
+ reachedDefs(value, context.defs, defs);
814
+ const { create_roles: _create, delete_roles: _delete, ...shaped } = value;
157
815
  return {
158
816
  name,
159
- file,
817
+ memberDocument,
818
+ root: { ...root, properties: { ...HOUSE_KEYS, ...fields } },
160
819
  fields,
161
- sections
820
+ rules,
821
+ ...(createRoles === undefined ? {} : { createRoles }),
822
+ ...(deleteRoles === undefined ? {} : { deleteRoles }),
823
+ shape: {
824
+ schema: written.size === 0 ? shaped : { ...shaped, properties: schema.properties },
825
+ defs,
826
+ },
162
827
  };
163
828
  }
164
-
165
- //# sourceMappingURL=definition.js.map
829
+ function lineAt(text, offset) {
830
+ return text.slice(0, offset).split(/\r\n|\r|\n/).length;
831
+ }
832
+ export function readSchema(text, provided = NO_TYPES, checked = true) {
833
+ let root;
834
+ try {
835
+ root = jsValue(parseYamlMapping(text, 0, text.length));
836
+ }
837
+ catch (error) {
838
+ if (error instanceof YamlError)
839
+ return refuse('schema-yaml', `line ${lineAt(text, error.offset)}`);
840
+ throw error;
841
+ }
842
+ const defs = root.$defs ?? Object.create(null);
843
+ if (!isRecord(defs))
844
+ return refuse('$defs', '/$defs');
845
+ const names = Object.keys(root).filter((key) => key !== '$defs');
846
+ for (const name of checked ? names : []) {
847
+ if (name === '' || name.startsWith('$') || name === BUILT_IN_TYPE || name === ATTACHMENT)
848
+ return refuse('schema-type-name', `/${escapePointer(name)}`);
849
+ }
850
+ const context = {
851
+ defs,
852
+ types: new Set([...names, ...Object.keys(provided.types)]),
853
+ checked,
854
+ };
855
+ for (const [name, def] of Object.entries(defs)) {
856
+ const failure = schemaFailure(def, `/$defs/${escapePointer(name)}`, context);
857
+ if (failure !== undefined)
858
+ return failure;
859
+ }
860
+ const types = Object.create(null);
861
+ let marked = false;
862
+ for (const name of names) {
863
+ const definition = Object.hasOwn(provided.types, name)
864
+ ? providedType(name, root[name], provided, checked)
865
+ : readType(name, root[name], context);
866
+ if ('rule' in definition)
867
+ return definition;
868
+ if (checked && definition.memberDocument) {
869
+ if (marked)
870
+ return refuse('member_document', `/${escapePointer(name)}/member_document`);
871
+ marked = true;
872
+ }
873
+ types[name] = deepFreeze(definition);
874
+ }
875
+ for (const [name, definition] of Object.entries(provided.types)) {
876
+ if (!Object.hasOwn(types, name))
877
+ types[name] = definition;
878
+ }
879
+ return Object.freeze({ types: Object.freeze(types) });
880
+ }