@agentshouse/mdmodel 0.1.0-alpha.9 → 0.1.0-c08b2adadd2fe

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