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

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