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

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