@agentshouse/mdmodel 0.1.0-cbce4f1da228f → 0.1.0-cbd3c46de90bf

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 (461) hide show
  1. package/API.md +287 -278
  2. package/README.md +28 -29
  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 +26 -11
  10. package/dist/definition.d.ts.map +1 -1
  11. package/dist/definition.js +259 -93
  12. package/dist/document.d.ts +16 -9
  13. package/dist/document.d.ts.map +1 -1
  14. package/dist/document.js +996 -254
  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 +41 -0
  21. package/dist/fields.d.ts +1 -1
  22. package/dist/fields.d.ts.map +1 -1
  23. package/dist/fields.js +2 -2
  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 +45 -16
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +27 -11
  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 +25 -2
  58. package/dist/paths.d.ts.map +1 -1
  59. package/dist/paths.js +129 -18
  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 +2 -2
  79. package/dist/references.d.ts.map +1 -1
  80. package/dist/references.js +7 -2
  81. package/dist/refuse.d.ts +1 -0
  82. package/dist/refuse.d.ts.map +1 -1
  83. package/dist/refuse.js +1 -0
  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 +1 -2
  91. package/dist/schema.d.ts.map +1 -1
  92. package/dist/schema.js +10 -23
  93. package/dist/types.d.ts +44 -34
  94. package/dist/types.d.ts.map +1 -1
  95. package/dist/validate.d.ts +34 -5
  96. package/dist/validate.d.ts.map +1 -1
  97. package/dist/validate.js +345 -151
  98. package/dist/view.d.ts +5 -0
  99. package/dist/view.d.ts.map +1 -0
  100. package/dist/view.js +27 -0
  101. package/dist/yaml.d.ts +7 -5
  102. package/dist/yaml.d.ts.map +1 -1
  103. package/dist/yaml.js +190 -43
  104. package/fixtures/README.md +93 -65
  105. package/fixtures/cases/absent-link-dangles/library/item.md +1 -1
  106. package/fixtures/cases/absent-link-dangles/schema.yaml +2 -3
  107. package/fixtures/cases/absent-optional-field/library/companies/acme.md +1 -1
  108. package/fixtures/cases/absent-optional-field/library/deals/lead.md +3 -3
  109. package/fixtures/cases/absent-optional-field/schema.yaml +10 -11
  110. package/fixtures/cases/absolute-link/library/item.md +1 -1
  111. package/fixtures/cases/absolute-link/schema.yaml +2 -3
  112. package/fixtures/cases/attachment-reference-any-file/library/companies/acme.md +1 -1
  113. package/fixtures/cases/attachment-reference-any-file/library/deals/renewal.md +13 -10
  114. package/fixtures/cases/attachment-reference-any-file/library/places/depot.md +1 -1
  115. package/fixtures/cases/attachment-reference-any-file/library/products/seats.md +1 -1
  116. package/fixtures/cases/attachment-reference-any-file/library/products/support.md +1 -1
  117. package/fixtures/cases/attachment-reference-dangles/library/companies/acme.md +1 -1
  118. package/fixtures/cases/attachment-reference-dangles/library/deals/renewal.md +13 -10
  119. package/fixtures/cases/attachment-reference-dangles/library/places/depot.md +1 -1
  120. package/fixtures/cases/attachment-reference-dangles/library/products/seats.md +1 -1
  121. package/fixtures/cases/attachment-reference-dangles/library/products/support.md +1 -1
  122. package/fixtures/cases/attachment-reference-outside/expected.json +2 -1
  123. package/fixtures/cases/attachment-reference-outside/library/companies/acme.md +1 -1
  124. package/fixtures/cases/attachment-reference-outside/library/deals/renewal.md +13 -10
  125. package/fixtures/cases/attachment-reference-outside/library/places/depot.md +1 -1
  126. package/fixtures/cases/attachment-reference-outside/library/products/seats.md +1 -1
  127. package/fixtures/cases/attachment-reference-outside/library/products/support.md +1 -1
  128. package/fixtures/cases/binary-any-reference/expected.json +2 -1
  129. package/fixtures/cases/binary-any-reference/library/notes/draft.md +1 -1
  130. package/fixtures/cases/binary-prototype-reference/expected.json +2 -1
  131. package/fixtures/cases/binary-prototype-reference/library/notes/draft.md +1 -1
  132. package/fixtures/cases/binary-typed-reference/expected.json +2 -1
  133. package/fixtures/cases/binary-typed-reference/library/notes/draft.md +1 -1
  134. package/fixtures/cases/block-scalar-frontmatter/library/notes/literal.md +17 -0
  135. package/fixtures/cases/block-scalar-frontmatter/library/skills/notes/SKILL.md +10 -0
  136. package/fixtures/cases/boolean-field/expected.json +2 -1
  137. package/fixtures/cases/boolean-field/library/companies/acme.md +1 -1
  138. package/fixtures/cases/boolean-field/library/deals/renewal.md +49 -24
  139. package/fixtures/cases/boolean-field/schema.yaml +10 -11
  140. package/fixtures/cases/bracketed-link-definition/library/item.md +1 -1
  141. package/fixtures/cases/bracketed-link-definition/schema.yaml +2 -3
  142. package/fixtures/cases/closed-nested-object/expected.json +2 -1
  143. package/fixtures/cases/closed-nested-object/library/companies/acme.md +1 -1
  144. package/fixtures/cases/closed-nested-object/library/deals/renewal.md +50 -25
  145. package/fixtures/cases/closed-nested-object/schema.yaml +10 -11
  146. package/fixtures/cases/composed-root-reference/library/a.md +2 -2
  147. package/fixtures/cases/conditional-long-text/expected.json +7 -0
  148. package/fixtures/cases/conditional-long-text/library/questions/hosting.md +9 -0
  149. package/fixtures/cases/conditional-long-text/library/questions/payments.md +12 -0
  150. package/fixtures/cases/conditional-long-text/schema.yaml +13 -0
  151. package/fixtures/cases/cross-room-link/expected.json +1 -0
  152. package/fixtures/cases/cross-room-link/library/clients/acme.md +6 -0
  153. package/fixtures/cases/cross-room-link/schema.yaml +3 -0
  154. package/fixtures/cases/cross-room-reference/expected.json +1 -0
  155. package/fixtures/cases/cross-room-reference/library/clients/acme.md +9 -0
  156. package/fixtures/cases/cross-room-reference/schema.yaml +8 -0
  157. package/fixtures/cases/date-time-format/expected.json +2 -1
  158. package/fixtures/cases/date-time-format/library/companies/acme.md +1 -1
  159. package/fixtures/cases/date-time-format/library/deals/renewal.md +49 -24
  160. package/fixtures/cases/date-time-format/schema.yaml +10 -11
  161. package/fixtures/cases/default-unfilled/library/companies/acme.md +1 -1
  162. package/fixtures/cases/default-unfilled/library/deals/renewal.md +47 -22
  163. package/fixtures/cases/default-unfilled/schema.yaml +10 -11
  164. package/fixtures/cases/defs-pattern/expected.json +2 -1
  165. package/fixtures/cases/defs-pattern/library/companies/acme.md +1 -1
  166. package/fixtures/cases/defs-pattern/library/deals/renewal.md +49 -24
  167. package/fixtures/cases/defs-pattern/schema.yaml +10 -11
  168. package/fixtures/cases/dependent-rule/library/companies/acme.md +1 -1
  169. package/fixtures/cases/dependent-rule/library/deals/renewal.md +48 -23
  170. package/fixtures/cases/dependent-rule/schema.yaml +10 -11
  171. package/fixtures/cases/duplicate-link-definition/library/item.md +1 -1
  172. package/fixtures/cases/duplicate-link-definition/schema.yaml +2 -3
  173. package/fixtures/cases/email-format/expected.json +2 -1
  174. package/fixtures/cases/email-format/library/companies/acme.md +1 -1
  175. package/fixtures/cases/email-format/library/deals/renewal.md +49 -24
  176. package/fixtures/cases/email-format/schema.yaml +10 -11
  177. package/fixtures/cases/equal-labels/expected.json +5 -0
  178. package/fixtures/cases/equal-labels/schema.yaml +4 -0
  179. package/fixtures/cases/fenced-link-definition/library/item.md +1 -1
  180. package/fixtures/cases/fenced-link-definition/schema.yaml +2 -3
  181. package/fixtures/cases/field-enum/expected.json +2 -1
  182. package/fixtures/cases/field-enum/library/item.md +2 -2
  183. package/fixtures/cases/field-enum/schema.yaml +3 -4
  184. package/fixtures/cases/frontmatter-construct/expected.json +7 -0
  185. package/fixtures/cases/frontmatter-construct/library/note.md +6 -0
  186. package/fixtures/cases/integer-field/expected.json +2 -1
  187. package/fixtures/cases/integer-field/library/companies/acme.md +1 -1
  188. package/fixtures/cases/integer-field/library/deals/renewal.md +49 -24
  189. package/fixtures/cases/integer-field/schema.yaml +10 -11
  190. package/fixtures/cases/json-schema-constructs/library/companies/acme.md +1 -1
  191. package/fixtures/cases/json-schema-constructs/library/deals/renewal.md +49 -24
  192. package/fixtures/cases/json-schema-constructs/schema.yaml +10 -11
  193. package/fixtures/cases/labels-in-the-rooms-language/expected.json +1 -0
  194. package/fixtures/cases/labels-in-the-rooms-language/library/deals/atlas.md +7 -0
  195. package/fixtures/cases/labels-in-the-rooms-language/schema.yaml +9 -0
  196. package/fixtures/cases/lazy-list-item/expected.json +3 -0
  197. package/fixtures/cases/lazy-list-item/library/item.md +10 -0
  198. package/fixtures/cases/lazy-list-item/schema.yaml +3 -0
  199. package/fixtures/cases/link-into-a-reserved-name/context.json +1 -0
  200. package/fixtures/cases/link-into-a-reserved-name/expected.json +5 -0
  201. package/fixtures/cases/link-into-a-reserved-name/library/notes/a.md +6 -0
  202. package/fixtures/cases/link-into-a-reserved-name/schema.yaml +3 -0
  203. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/expected.json +5 -0
  204. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/library/notes/b.md +5 -0
  205. package/fixtures/cases/list-item-enum/context.json +1 -0
  206. package/fixtures/cases/list-item-enum/expected.json +7 -0
  207. package/fixtures/cases/list-item-enum/library/task.md +7 -0
  208. package/fixtures/cases/list-item-enum/schema.yaml +3 -0
  209. package/fixtures/cases/list-item-kind/context.json +1 -0
  210. package/fixtures/cases/list-item-kind/expected.json +7 -0
  211. package/fixtures/cases/list-item-kind/library/task.md +6 -0
  212. package/fixtures/cases/list-item-kind/schema.yaml +3 -0
  213. package/fixtures/cases/list-items/context.json +1 -0
  214. package/fixtures/cases/list-items/expected.json +1 -0
  215. package/fixtures/cases/list-items/library/page.md +26 -0
  216. package/fixtures/cases/list-items/schema.yaml +10 -0
  217. package/fixtures/cases/list-of-objects-closed/expected.json +2 -1
  218. package/fixtures/cases/list-of-objects-closed/library/companies/acme.md +1 -1
  219. package/fixtures/cases/list-of-objects-closed/library/deals/renewal.md +49 -25
  220. package/fixtures/cases/list-of-objects-closed/schema.yaml +10 -11
  221. package/fixtures/cases/list-of-objects-item/expected.json +2 -1
  222. package/fixtures/cases/list-of-objects-item/library/companies/acme.md +1 -1
  223. package/fixtures/cases/list-of-objects-item/library/deals/renewal.md +49 -24
  224. package/fixtures/cases/list-of-objects-item/schema.yaml +10 -11
  225. package/fixtures/cases/list-of-objects-reference/expected.json +2 -1
  226. package/fixtures/cases/list-of-objects-reference/library/companies/acme.md +1 -1
  227. package/fixtures/cases/list-of-objects-reference/library/deals/renewal.md +12 -9
  228. package/fixtures/cases/list-of-objects-reference/library/places/depot.md +1 -1
  229. package/fixtures/cases/list-of-objects-reference/library/products/seats.md +1 -1
  230. package/fixtures/cases/list-of-objects-reference/library/products/support.md +1 -1
  231. package/fixtures/cases/list-reference-path/context.json +1 -0
  232. package/fixtures/cases/list-reference-path/expected.json +7 -0
  233. package/fixtures/cases/list-reference-path/library/page.md +5 -0
  234. package/fixtures/cases/list-reference-path/schema.yaml +3 -0
  235. package/fixtures/cases/list-reference-type/context.json +1 -0
  236. package/fixtures/cases/list-reference-type/expected.json +7 -0
  237. package/fixtures/cases/list-reference-type/library/page.md +6 -0
  238. package/fixtures/cases/list-reference-type/schema.yaml +3 -0
  239. package/fixtures/cases/list-size/expected.json +2 -1
  240. package/fixtures/cases/list-size/library/companies/acme.md +1 -1
  241. package/fixtures/cases/list-size/library/deals/renewal.md +51 -24
  242. package/fixtures/cases/list-size/schema.yaml +10 -11
  243. package/fixtures/cases/long-value-past-six-levels/context.json +1 -0
  244. package/fixtures/cases/long-value-past-six-levels/expected.json +5 -0
  245. package/fixtures/cases/long-value-past-six-levels/schema.yaml +15 -0
  246. package/fixtures/cases/malformed-list/context.json +1 -0
  247. package/fixtures/cases/malformed-list/expected.json +7 -0
  248. package/fixtures/cases/{structured-section → malformed-list}/library/item.md +1 -1
  249. package/fixtures/cases/malformed-list/schema.yaml +6 -0
  250. package/fixtures/cases/member-document/library/people/ana.md +2 -2
  251. package/fixtures/cases/member-on-an-untyped-document/context.json +1 -0
  252. package/fixtures/cases/member-on-an-untyped-document/expected.json +6 -0
  253. package/fixtures/cases/member-on-an-untyped-document/library/note.md +4 -0
  254. package/fixtures/cases/member-on-another-type/context.json +1 -0
  255. package/fixtures/cases/member-on-another-type/expected.json +6 -0
  256. package/fixtures/cases/member-on-another-type/library/note.md +4 -0
  257. package/fixtures/cases/member-on-another-type/schema.yaml +7 -0
  258. package/fixtures/cases/missing-required-field/library/item.md +1 -1
  259. package/fixtures/cases/missing-required-field/schema.yaml +3 -4
  260. package/fixtures/cases/misspelled-key/expected.json +2 -1
  261. package/fixtures/cases/misspelled-key/library/companies/acme.md +1 -1
  262. package/fixtures/cases/misspelled-key/library/deals/renewal.md +50 -25
  263. package/fixtures/cases/misspelled-key/schema.yaml +10 -11
  264. package/fixtures/cases/name-not-a-string/context.json +1 -0
  265. package/fixtures/cases/name-not-a-string/expected.json +5 -0
  266. package/fixtures/cases/name-not-a-string/schema.yaml +5 -0
  267. package/fixtures/cases/nested-defs/expected.json +2 -1
  268. package/fixtures/cases/nested-defs/library/deal.md +3 -3
  269. package/fixtures/cases/nested-object-reference/expected.json +2 -1
  270. package/fixtures/cases/nested-object-reference/library/companies/acme.md +1 -1
  271. package/fixtures/cases/nested-object-reference/library/deals/renewal.md +12 -9
  272. package/fixtures/cases/nested-object-reference/library/places/depot.md +1 -1
  273. package/fixtures/cases/nested-object-reference/library/products/seats.md +1 -1
  274. package/fixtures/cases/nested-object-reference/library/products/support.md +1 -1
  275. package/fixtures/cases/nested-reference/library/companies/acme.md +1 -1
  276. package/fixtures/cases/nested-reference/library/deals/renewal.md +13 -10
  277. package/fixtures/cases/nested-reference/library/places/depot.md +1 -1
  278. package/fixtures/cases/nested-reference/library/products/seats.md +1 -1
  279. package/fixtures/cases/nested-reference/library/products/support.md +1 -1
  280. package/fixtures/cases/nested-required-field/expected.json +2 -1
  281. package/fixtures/cases/nested-required-field/library/companies/acme.md +1 -1
  282. package/fixtures/cases/nested-required-field/library/deals/renewal.md +48 -23
  283. package/fixtures/cases/nested-required-field/schema.yaml +10 -11
  284. package/fixtures/cases/numeric-range/expected.json +2 -1
  285. package/fixtures/cases/numeric-range/library/companies/acme.md +1 -1
  286. package/fixtures/cases/numeric-range/library/deals/renewal.md +49 -24
  287. package/fixtures/cases/numeric-range/schema.yaml +10 -11
  288. package/fixtures/cases/one-key-two-labels/context.json +1 -0
  289. package/fixtures/cases/one-key-two-labels/expected.json +5 -0
  290. package/fixtures/cases/one-key-two-labels/schema.yaml +5 -0
  291. package/fixtures/cases/one-key-two-types/context.json +1 -0
  292. package/fixtures/cases/one-key-two-types/expected.json +5 -0
  293. package/fixtures/cases/one-key-two-types/schema.yaml +4 -0
  294. package/fixtures/cases/one-of-variant/expected.json +2 -1
  295. package/fixtures/cases/one-of-variant/library/companies/acme.md +1 -1
  296. package/fixtures/cases/one-of-variant/library/deals/renewal.md +49 -24
  297. package/fixtures/cases/one-of-variant/schema.yaml +10 -11
  298. package/fixtures/cases/other-room-reference/expected.json +2 -1
  299. package/fixtures/cases/other-room-reference/library/companies/acme.md +1 -1
  300. package/fixtures/cases/other-room-reference/library/deals/renewal.md +12 -9
  301. package/fixtures/cases/other-room-reference/library/places/depot.md +1 -1
  302. package/fixtures/cases/other-room-reference/library/products/seats.md +1 -1
  303. package/fixtures/cases/other-room-reference/library/products/support.md +1 -1
  304. package/fixtures/cases/prototype-field/expected.json +2 -1
  305. package/fixtures/cases/prototype-field/library/item.md +2 -2
  306. package/fixtures/cases/prototype-field/schema.yaml +2 -3
  307. package/fixtures/cases/reference-into-a-reserved-name/context.json +1 -0
  308. package/fixtures/cases/reference-into-a-reserved-name/expected.json +7 -0
  309. package/fixtures/cases/reference-into-a-reserved-name/library/notes/a.md +4 -0
  310. package/fixtures/cases/reference-into-a-reserved-name/library/settings/brief.md +1 -0
  311. package/fixtures/cases/reference-into-a-reserved-name/schema.yaml +3 -0
  312. package/fixtures/cases/reference-to-any-file-name/context.json +1 -0
  313. package/fixtures/cases/reference-to-any-file-name/expected.json +1 -0
  314. package/fixtures/cases/reference-to-any-file-name/library/people/100%.md +4 -0
  315. package/fixtures/cases/reference-to-any-file-name/library/people/C#.md +4 -0
  316. package/fixtures/cases/reference-to-any-file-name/library/people/My notes.md +4 -0
  317. package/fixtures/cases/reference-to-any-file-name/library/people/[draft].md +4 -0
  318. package/fixtures/cases/reference-to-any-file-name/library/people/c (d).md +4 -0
  319. package/fixtures/cases/reference-to-any-file-name/library/people/caf/303/251.md +4 -0
  320. package/fixtures/cases/reference-to-any-file-name/library/people//320/236/321/202/321/207/321/221/321/202.md +4 -0
  321. package/fixtures/cases/reference-to-any-file-name/library/tasks/bracket.md +9 -0
  322. package/fixtures/cases/reference-to-any-file-name/library/tasks/cyrillic.md +9 -0
  323. package/fixtures/cases/reference-to-any-file-name/library/tasks/decomposed.md +9 -0
  324. package/fixtures/cases/reference-to-any-file-name/library/tasks/hash.md +9 -0
  325. package/fixtures/cases/reference-to-any-file-name/library/tasks/parenthesis.md +9 -0
  326. package/fixtures/cases/reference-to-any-file-name/library/tasks/percent.md +9 -0
  327. package/fixtures/cases/reference-to-any-file-name/library/tasks/spaced.md +9 -0
  328. package/fixtures/cases/reference-to-any-file-name/schema.yaml +10 -0
  329. package/fixtures/cases/referenced-missing-file/library/a.md +2 -2
  330. package/fixtures/cases/referenced-missing-file/library/b.md +2 -2
  331. package/fixtures/cases/referenced-missing-file/schema.yaml +3 -4
  332. package/fixtures/cases/referenced-missing-non-latin-file/context.json +1 -0
  333. package/fixtures/cases/referenced-missing-non-latin-file/expected.json +6 -0
  334. package/fixtures/cases/referenced-missing-non-latin-file/library/tasks/a.md +9 -0
  335. package/fixtures/cases/referenced-missing-non-latin-file/library/tasks/b.md +9 -0
  336. package/fixtures/cases/referenced-missing-non-latin-file/schema.yaml +10 -0
  337. package/fixtures/cases/room-md-declares-a-type/context.json +1 -0
  338. package/fixtures/cases/room-md-declares-a-type/expected.json +6 -0
  339. package/fixtures/cases/room-md-declares-a-type/library/ROOM.md +5 -0
  340. package/fixtures/cases/sections-keyword-refused/context.json +1 -0
  341. package/fixtures/cases/sections-keyword-refused/expected.json +5 -0
  342. package/fixtures/cases/{structured-section → sections-keyword-refused}/schema.yaml +1 -2
  343. package/fixtures/cases/shortcut-reference-link/library/item.md +1 -1
  344. package/fixtures/cases/shortcut-reference-link/schema.yaml +2 -3
  345. package/fixtures/cases/string-length/expected.json +2 -1
  346. package/fixtures/cases/string-length/library/companies/acme.md +1 -1
  347. package/fixtures/cases/string-length/library/deals/renewal.md +49 -24
  348. package/fixtures/cases/string-length/schema.yaml +10 -11
  349. package/fixtures/cases/submission-keys/library/notes/visitor.md +2 -2
  350. package/fixtures/cases/text-field-kind/expected.json +1 -4
  351. package/fixtures/cases/text-field-kind/library/page.md +1 -1
  352. package/fixtures/cases/thematic-break-ends-the-values/context.json +1 -0
  353. package/fixtures/cases/thematic-break-ends-the-values/expected.json +1 -0
  354. package/fixtures/cases/thematic-break-ends-the-values/library/item.md +10 -0
  355. package/fixtures/cases/thematic-break-ends-the-values/schema.yaml +3 -0
  356. package/fixtures/cases/typed-path-names-another-type/context.json +11 -0
  357. package/fixtures/cases/typed-path-names-another-type/expected.json +6 -0
  358. package/fixtures/cases/typed-path-names-another-type/library/settings/prefs/one.md +3 -0
  359. package/fixtures/cases/typed-path-names-another-type/schema.yaml +6 -0
  360. package/fixtures/cases/typed-path-names-its-type/context.json +11 -0
  361. package/fixtures/cases/typed-path-names-its-type/expected.json +3 -0
  362. package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/deeper/two.md +1 -0
  363. package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/one.md +4 -0
  364. package/fixtures/cases/typed-path-names-its-type/schema.yaml +6 -0
  365. package/fixtures/cases/typed-path-names-no-type/context.json +11 -0
  366. package/fixtures/cases/typed-path-names-no-type/expected.json +6 -0
  367. package/fixtures/cases/typed-path-names-no-type/library/settings/prefs/one.md +1 -0
  368. package/fixtures/cases/typed-path-names-no-type/schema.yaml +6 -0
  369. package/fixtures/cases/types-folder-content/library/types/task.md +1 -1
  370. package/fixtures/cases/undeclared-field/expected.json +2 -1
  371. package/fixtures/cases/undeclared-field/library/item.md +2 -2
  372. package/fixtures/cases/undeclared-field/schema.yaml +2 -3
  373. package/fixtures/cases/unevaluated-items-closed/expected.json +2 -1
  374. package/fixtures/cases/unevaluated-items-closed/library/trip.md +13 -3
  375. package/fixtures/cases/unnamed-typed-path-checks-its-fields/context.json +11 -0
  376. package/fixtures/cases/unnamed-typed-path-checks-its-fields/expected.json +6 -0
  377. package/fixtures/cases/unnamed-typed-path-checks-its-fields/library/rooms/team/tasks/plan.md +5 -0
  378. package/fixtures/cases/unnamed-typed-path-checks-its-fields/schema.yaml +5 -0
  379. package/fixtures/cases/unnamed-typed-path-names-a-type/context.json +11 -0
  380. package/fixtures/cases/unnamed-typed-path-names-a-type/expected.json +6 -0
  381. package/fixtures/cases/unnamed-typed-path-names-a-type/library/rooms/team/tasks/plan.md +7 -0
  382. package/fixtures/cases/unnamed-typed-path-names-a-type/schema.yaml +5 -0
  383. package/fixtures/cases/unnamed-typed-path-reads-its-type/context.json +11 -0
  384. package/fixtures/cases/unnamed-typed-path-reads-its-type/expected.json +3 -0
  385. package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/plan.md +1 -0
  386. package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/tasks/plan.md +6 -0
  387. package/fixtures/cases/unnamed-typed-path-reads-its-type/schema.yaml +5 -0
  388. package/fixtures/cases/unnamed-typed-path-without-a-body/context.json +11 -0
  389. package/fixtures/cases/unnamed-typed-path-without-a-body/expected.json +5 -0
  390. package/fixtures/cases/unnamed-typed-path-without-a-body/library/rooms/team/tasks/plan.md +5 -0
  391. package/fixtures/cases/unnamed-typed-path-without-a-body/schema.yaml +5 -0
  392. package/fixtures/cases/unresolved-link/library/item.md +1 -1
  393. package/fixtures/cases/unresolved-link/schema.yaml +2 -3
  394. package/fixtures/cases/valid-typed-document/library/people/ada.md +1 -1
  395. package/fixtures/cases/valid-typed-document/library/tasks/one.md +11 -11
  396. package/fixtures/cases/valid-typed-document/schema.yaml +5 -6
  397. package/fixtures/forms.json +371 -0
  398. package/fixtures/preamble.json +29 -8
  399. package/fixtures/queries.json +1562 -0
  400. package/package.json +16 -2
  401. package/dist/blocks.d.ts +0 -11
  402. package/dist/blocks.d.ts.map +0 -1
  403. package/dist/blocks.js +0 -69
  404. package/dist/condition.d.ts +0 -149
  405. package/dist/condition.d.ts.map +0 -1
  406. package/dist/condition.js +0 -500
  407. package/dist/divide.d.ts +0 -3
  408. package/dist/divide.d.ts.map +0 -1
  409. package/dist/divide.js +0 -320
  410. package/dist/links.d.ts +0 -28
  411. package/dist/links.d.ts.map +0 -1
  412. package/dist/links.js +0 -785
  413. package/dist/profile.d.ts +0 -6
  414. package/dist/profile.d.ts.map +0 -1
  415. package/dist/profile.js +0 -5
  416. package/dist/project.d.ts +0 -22
  417. package/dist/project.d.ts.map +0 -1
  418. package/dist/project.js +0 -128
  419. package/dist/sections.d.ts +0 -11
  420. package/dist/sections.d.ts.map +0 -1
  421. package/dist/sections.js +0 -57
  422. package/fixtures/cases/missing-section-item-kind/expected.json +0 -5
  423. package/fixtures/cases/missing-section-item-kind/schema.yaml +0 -6
  424. package/fixtures/cases/null-refused/expected.json +0 -6
  425. package/fixtures/cases/null-refused/library/companies/acme.md +0 -4
  426. package/fixtures/cases/null-refused/library/deals/renewal.md +0 -31
  427. package/fixtures/cases/null-refused/schema.yaml +0 -56
  428. package/fixtures/cases/open-map-value/expected.json +0 -6
  429. package/fixtures/cases/open-map-value/library/companies/acme.md +0 -4
  430. package/fixtures/cases/open-map-value/library/deals/renewal.md +0 -31
  431. package/fixtures/cases/open-map-value/schema.yaml +0 -56
  432. package/fixtures/cases/section-item-enum/expected.json +0 -6
  433. package/fixtures/cases/section-item-enum/library/task.md +0 -8
  434. package/fixtures/cases/section-item-enum/schema.yaml +0 -3
  435. package/fixtures/cases/section-item-kind/expected.json +0 -6
  436. package/fixtures/cases/section-item-kind/library/task.md +0 -8
  437. package/fixtures/cases/section-item-kind/schema.yaml +0 -3
  438. package/fixtures/cases/section-items/library/page.md +0 -42
  439. package/fixtures/cases/section-items/schema.yaml +0 -10
  440. package/fixtures/cases/section-reference-path/expected.json +0 -6
  441. package/fixtures/cases/section-reference-path/library/page.md +0 -7
  442. package/fixtures/cases/section-reference-path/schema.yaml +0 -3
  443. package/fixtures/cases/section-reference-type/expected.json +0 -6
  444. package/fixtures/cases/section-reference-type/library/page.md +0 -7
  445. package/fixtures/cases/section-reference-type/schema.yaml +0 -3
  446. package/fixtures/cases/structured-section/expected.json +0 -6
  447. package/fixtures/division.json +0 -409
  448. package/fixtures/projection.json +0 -255
  449. /package/fixtures/cases/{missing-section-item-kind → block-scalar-frontmatter}/context.json +0 -0
  450. /package/fixtures/cases/{section-items → block-scalar-frontmatter}/expected.json +0 -0
  451. /package/fixtures/cases/{null-refused → conditional-long-text}/context.json +0 -0
  452. /package/fixtures/cases/{open-map-value → cross-room-link}/context.json +0 -0
  453. /package/fixtures/cases/{section-item-enum → cross-room-reference}/context.json +0 -0
  454. /package/fixtures/cases/{section-item-kind → equal-labels}/context.json +0 -0
  455. /package/fixtures/cases/{section-items → frontmatter-construct}/context.json +0 -0
  456. /package/fixtures/cases/{section-reference-path → labels-in-the-rooms-language}/context.json +0 -0
  457. /package/fixtures/cases/{section-reference-type → lazy-list-item}/context.json +0 -0
  458. /package/fixtures/cases/{structured-section → link-into-a-reserved-name-from-an-untyped-document}/context.json +0 -0
  459. /package/fixtures/cases/{section-items → list-items}/library/other.md +0 -0
  460. /package/fixtures/cases/{section-reference-path → list-reference-path}/library/other.md +0 -0
  461. /package/fixtures/cases/{section-reference-type → list-reference-type}/library/note.md +0 -0
@@ -0,0 +1,621 @@
1
+ import { crossedFacts, escapePointer, pointerFacts, pointerSegments, } from '../definition.js';
2
+ import { fitsKind, kindOf, kindWords } from '../kinds.js';
3
+ import { normalize } from '../paths.js';
4
+ import { plain } from '../yaml.js';
5
+ export class QueryError extends Error {
6
+ code;
7
+ place;
8
+ accepts;
9
+ retryable = false;
10
+ constructor(code, at, problem, accepts = []) {
11
+ super(`${code} at ${placeText(placed(at))}: ${problem}`);
12
+ this.code = code;
13
+ this.place = placed(at);
14
+ this.accepts = accepts;
15
+ }
16
+ }
17
+ const RANGE = ['$gt', '$gte', '$lt', '$lte'];
18
+ const SINGLE = ['$eq', '$ne', '$in', '$nin', '$all', '$size', '$exists', '$prefix'];
19
+ const FILTER = [
20
+ 'rooms',
21
+ 'types',
22
+ 'where',
23
+ 'pathPrefix',
24
+ 'outside',
25
+ 'folder',
26
+ 'paths',
27
+ 'fileIds',
28
+ 'hop',
29
+ 'backlinks',
30
+ 'text',
31
+ ];
32
+ const RELATED = ['types', 'where', 'pathPrefix', 'field'];
33
+ const HOP = [...RELATED, 'none'];
34
+ const PARTS = [
35
+ 'fields',
36
+ 'sections',
37
+ 'preamble',
38
+ 'markdown',
39
+ 'backlinks',
40
+ 'change',
41
+ 'fileId',
42
+ 'revision',
43
+ 'size',
44
+ 'created',
45
+ ];
46
+ const GROUP_PARTS = ['size', 'updated', 'greatest'];
47
+ const DOCUMENT_KEYS = ['room', 'path', 'type', 'folder', 'size', 'created', 'updated'];
48
+ const GROUP_KEYS = ['room', 'type', 'folder', 'subfolder'];
49
+ const GROUP_ORDERS = ['count', 'size', 'updated', 'greatest'];
50
+ const ORDER = ['by', 'direction', 'nulls', 'stringSort', 'locale', 'localeOptions'];
51
+ const STRAY_ESCAPE = /~(?![01])/u;
52
+ export function bodied(shape) {
53
+ return shape.sections !== null || shape.preamble || shape.markdown;
54
+ }
55
+ export function invalid(at, problem, accepts = []) {
56
+ throw new QueryError('invalid-query', at, problem, accepts);
57
+ }
58
+ function placed(at) {
59
+ if (typeof at !== 'string')
60
+ return at;
61
+ return at === '' ? [] : [at];
62
+ }
63
+ export function placeText(at) {
64
+ return at.reduce((text, step) => {
65
+ if (typeof step === 'number')
66
+ return `${text}[${step}]`;
67
+ if (step.startsWith('/') || text === '')
68
+ return `${text}${step}`;
69
+ return `${text}.${step}`;
70
+ }, '');
71
+ }
72
+ function place(at, step) {
73
+ return [...placed(at), step];
74
+ }
75
+ export function known(value, allowed, at) {
76
+ for (const name of Object.keys(value)) {
77
+ if (!allowed.includes(name))
78
+ invalid(place(at, name), 'unknown part', allowed);
79
+ }
80
+ }
81
+ function list(input, at) {
82
+ if (!Array.isArray(input))
83
+ invalid(at, 'expects a list');
84
+ return input;
85
+ }
86
+ function value(input, at) {
87
+ if (Array.isArray(input))
88
+ invalid(at, 'a list is not a value');
89
+ if (input !== null &&
90
+ typeof input !== 'string' &&
91
+ typeof input !== 'boolean' &&
92
+ !(typeof input === 'number' && Number.isFinite(input))) {
93
+ invalid(at, 'not a value');
94
+ }
95
+ return input;
96
+ }
97
+ function values(input, at) {
98
+ return list(input, at).map((item, index) => value(item, place(at, index)));
99
+ }
100
+ function names(input, at) {
101
+ const listed = list(input, at);
102
+ if (listed.some((item) => typeof item !== 'string'))
103
+ invalid(at, 'expects a list of names');
104
+ return [...new Set(listed)].sort();
105
+ }
106
+ function pathsOf(input) {
107
+ const listed = list(input, 'paths');
108
+ if (listed.some((item) => typeof item !== 'string' || item === '' || normalize(item) !== item)) {
109
+ invalid('paths', 'expects a list of Paths');
110
+ }
111
+ return [...new Set(listed)].sort();
112
+ }
113
+ function fileIdsOf(input) {
114
+ const listed = list(input, 'fileIds');
115
+ if (listed.some((item) => typeof item !== 'string' || item === '')) {
116
+ invalid('fileIds', 'expects a list of file IDs');
117
+ }
118
+ return [...new Set(listed)].sort();
119
+ }
120
+ function phrase(input) {
121
+ if (typeof input !== 'string' || input === '')
122
+ invalid('text', 'expects a phrase');
123
+ return input;
124
+ }
125
+ function directory(input, at) {
126
+ if (typeof input !== 'string' || normalize(input) !== input) {
127
+ invalid(at, 'expects a normalized directory');
128
+ }
129
+ return input;
130
+ }
131
+ function itemOf(facts) {
132
+ return facts.type === 'array' ? facts.items : facts;
133
+ }
134
+ function fits(facts, value) {
135
+ const item = itemOf(facts);
136
+ if (item === undefined || (item.type === undefined && item.values === undefined))
137
+ return true;
138
+ const kind = kindOf(item);
139
+ return kind !== null && fitsKind(kind, item, value);
140
+ }
141
+ export function textless(facts) {
142
+ const item = itemOf(facts);
143
+ if (item?.values !== undefined)
144
+ return !item.values.some((held) => typeof held === 'string');
145
+ return item?.type !== undefined && item.type !== 'string';
146
+ }
147
+ function typing(facts, rooms, types, at) {
148
+ const read = rooms === null ? facts.rooms : facts.rooms.filter((room) => rooms.includes(room.locator));
149
+ const acquiring = !facts.listed &&
150
+ (rooms === null ||
151
+ rooms.some((locator) => !facts.rooms.some((room) => room.locator === locator)));
152
+ const available = !acquiring && read.every((room) => room.available);
153
+ const declared = read.flatMap((room) => room.types);
154
+ for (const name of types ?? []) {
155
+ if (name === 'any' || !available || declared.some((type) => type.name === name))
156
+ continue;
157
+ throw new QueryError('unknown-type', place(at, 'types'), `no model it reads declares ${name}`, [...new Set(declared.map((type) => type.name))].sort());
158
+ }
159
+ return {
160
+ untyped: types === null || types.includes('any') || !available,
161
+ types: types === null ? declared : declared.filter((type) => types.includes(type.name)),
162
+ };
163
+ }
164
+ function pointer(input, at) {
165
+ if (typeof input !== 'string' || !input.startsWith('/') || STRAY_ESCAPE.test(input)) {
166
+ invalid(at, 'expects a JSON Pointer');
167
+ }
168
+ return input;
169
+ }
170
+ function specs(typed, input, at) {
171
+ const field = pointer(input, at);
172
+ const declared = typed.types.flatMap((type) => {
173
+ const spec = pointerFacts(type, field);
174
+ return spec === undefined ? [] : [spec];
175
+ });
176
+ if (declared.length === 0 && !typed.untyped) {
177
+ throw new QueryError('unknown-field', at, `no MD Type it reads declares ${field}`, nearby(typed.types, field));
178
+ }
179
+ if (!declared.some((spec) => spec.conditional))
180
+ return declared;
181
+ return declared.map((spec) => ({
182
+ facts: { prose: false },
183
+ through: several(spec),
184
+ conditional: true,
185
+ }));
186
+ }
187
+ function nearby(types, field) {
188
+ const segments = pointerSegments(field);
189
+ for (let length = segments.length - 1; length > 0; length -= 1) {
190
+ const prefix = segments
191
+ .slice(0, length)
192
+ .map((segment) => `/${escapePointer(segment)}`)
193
+ .join('');
194
+ const children = types.flatMap((type) => {
195
+ const reached = pointerFacts(type, prefix);
196
+ return (reached === undefined ? [] : crossedFacts(reached.facts)).flatMap((crossed) => Object.keys(crossed.properties ?? {}).map((key) => `${prefix}/${escapePointer(key)}`));
197
+ });
198
+ if (children.length > 0)
199
+ return [...new Set(children)].sort();
200
+ }
201
+ return [
202
+ ...new Set(types.flatMap((type) => Object.keys(type.fields).map((name) => `/${escapePointer(name)}`))),
203
+ ].sort();
204
+ }
205
+ function several(spec) {
206
+ return spec.through || spec.facts.type === 'array';
207
+ }
208
+ function single(spec) {
209
+ return spec.facts.type !== undefined && spec.facts.type !== 'array';
210
+ }
211
+ function every(declared, holds) {
212
+ return declared.length > 0 && declared.every(holds);
213
+ }
214
+ function kind(declared, checked, at) {
215
+ if (checked === null ||
216
+ declared.length === 0 ||
217
+ declared.some((spec) => fits(spec.facts, checked))) {
218
+ return;
219
+ }
220
+ throw new QueryError('wrong-kind', at, `${JSON.stringify(checked)} is not of its field's kind`, [
221
+ ...new Set(declared.flatMap((spec) => kindWords(itemOf(spec.facts)))),
222
+ ]);
223
+ }
224
+ function test(declared, input, at) {
225
+ if (!plain(input)) {
226
+ const equal = value(input, at);
227
+ kind(declared, equal, at);
228
+ return { op: 'eq', value: equal };
229
+ }
230
+ const operators = Object.keys(input);
231
+ if (operators.length === 0)
232
+ invalid(at, 'names no operator');
233
+ if (operators.some((operator) => RANGE.includes(operator))) {
234
+ const stray = operators.find((operator) => !RANGE.includes(operator));
235
+ if (stray !== undefined)
236
+ invalid(place(at, stray), 'cannot join a range');
237
+ if (every(declared, (spec) => spec.facts.type === 'array'))
238
+ invalid(at, 'a range on a list');
239
+ if (every(declared, (spec) => spec.facts.type === 'boolean' || spec.facts.type === 'object')) {
240
+ throw new QueryError('wrong-kind', at, 'its field does not compare in order');
241
+ }
242
+ return {
243
+ op: 'range',
244
+ bounds: RANGE.filter((operator) => operators.includes(operator)).map((operator) => {
245
+ const bound = value(input[operator], place(at, operator));
246
+ if (bound === null)
247
+ invalid(place(at, operator), 'a range bound is never null');
248
+ kind(declared, bound, place(at, operator));
249
+ return [operator.slice(1), bound];
250
+ }),
251
+ };
252
+ }
253
+ if (operators.length > 1)
254
+ invalid(place(at, operators[1]), 'names a second operator');
255
+ const [operator] = operators;
256
+ const where = place(at, operator);
257
+ if (!SINGLE.includes(operator)) {
258
+ invalid(where, 'unknown operator', [...SINGLE, ...RANGE]);
259
+ }
260
+ const operand = input[operator];
261
+ if (operator === '$eq' || operator === '$ne') {
262
+ const compared = value(operand, where);
263
+ kind(declared, compared, where);
264
+ return operator === '$eq' ? { op: 'eq', value: compared } : { op: 'ne', value: compared };
265
+ }
266
+ if (operator === '$in' || operator === '$nin' || operator === '$all') {
267
+ const compared = values(operand, where);
268
+ compared.forEach((item, index) => kind(declared, item, place(where, index)));
269
+ if (operator === '$in')
270
+ return { op: 'in', values: compared };
271
+ if (operator === '$nin')
272
+ return { op: 'nin', values: compared };
273
+ if (compared.includes(null))
274
+ invalid(where, 'a list holds no null');
275
+ if (every(declared, single))
276
+ invalid(where, 'the field is not a list');
277
+ return { op: 'all', values: compared };
278
+ }
279
+ if (operator === '$size') {
280
+ if (!Number.isSafeInteger(operand) || operand < 0) {
281
+ invalid(where, 'expects a nonnegative integer');
282
+ }
283
+ if (every(declared, single))
284
+ invalid(where, 'the field is not a list');
285
+ return { op: 'size', size: operand };
286
+ }
287
+ if (operator === '$prefix') {
288
+ if (typeof operand !== 'string')
289
+ invalid(where, 'expects a string');
290
+ if (every(declared, (spec) => textless(spec.facts))) {
291
+ throw new QueryError('wrong-kind', where, 'its field holds no text');
292
+ }
293
+ return { op: 'prefix', prefix: operand };
294
+ }
295
+ if (typeof operand !== 'boolean')
296
+ invalid(where, 'expects true or false');
297
+ return { op: 'exists', exists: operand };
298
+ }
299
+ function condition(typed, input, at) {
300
+ if (!plain(input))
301
+ invalid(at, 'expects an object of field predicates');
302
+ const conditions = [];
303
+ for (const name of Object.keys(input).sort()) {
304
+ const where = place(at, name);
305
+ const entry = input[name];
306
+ if (name === '$and' || name === '$or') {
307
+ const nested = list(entry, where).map((item, index) => condition(typed, item, place(where, index)));
308
+ if (nested.length === 0)
309
+ invalid(where, 'expects a nonempty list');
310
+ conditions.push(name === '$and' ? { every: nested } : { some: nested });
311
+ continue;
312
+ }
313
+ if (name.startsWith('$'))
314
+ invalid(where, 'unknown operator');
315
+ conditions.push({ field: name, test: test(specs(typed, name, where), entry, where) });
316
+ }
317
+ if (conditions.length === 0)
318
+ invalid(at, 'names no field');
319
+ return conditions.length === 1 ? conditions[0] : { every: conditions };
320
+ }
321
+ function scope(facts, rooms, input, at) {
322
+ const types = input.types === undefined ? null : names(input.types, place(at, 'types'));
323
+ const typed = typing(facts, rooms, types, at);
324
+ return {
325
+ typed,
326
+ types,
327
+ where: input.where === undefined || (plain(input.where) && Object.keys(input.where).length === 0)
328
+ ? null
329
+ : condition(typed, input.where, place(at, 'where')),
330
+ pathPrefix: input.pathPrefix === undefined ? null : directory(input.pathPrefix, place(at, 'pathPrefix')),
331
+ };
332
+ }
333
+ function referenceName(typed, field, at) {
334
+ const declared = specs(typed, field, at);
335
+ if (declared.length > 0 &&
336
+ !declared.some((spec) => spec.conditional ||
337
+ spec.facts.reference !== undefined ||
338
+ spec.facts.items?.reference !== undefined)) {
339
+ invalid(at, 'not a reference field');
340
+ }
341
+ return field;
342
+ }
343
+ function hopOf(facts, rooms, root, input) {
344
+ if (!plain(input))
345
+ invalid('hop', 'expects an object');
346
+ known(input, HOP, 'hop');
347
+ const field = referenceName(root, input.field, ['hop', 'field']);
348
+ const { types, where, pathPrefix } = scope(facts, rooms, input, 'hop');
349
+ return { types, where, pathPrefix, field, none: flag(input.none, ['hop', 'none']) };
350
+ }
351
+ function backlinksOf(facts, rooms, input) {
352
+ if (!plain(input))
353
+ invalid('backlinks', 'expects an object');
354
+ known(input, RELATED, 'backlinks');
355
+ const { typed, types, where, pathPrefix } = scope(facts, rooms, input, 'backlinks');
356
+ const field = input.field === undefined ? null : referenceName(typed, input.field, ['backlinks', 'field']);
357
+ return { types, where, pathPrefix, field };
358
+ }
359
+ function oneField(typed, input, at) {
360
+ if (specs(typed, input.field, place(at, 'field')).some(several)) {
361
+ invalid(place(at, 'field'), 'a path that can hold several values');
362
+ }
363
+ return input.field;
364
+ }
365
+ function keyPlan(typed, input, at, keys) {
366
+ if (typeof input === 'string' && keys.includes(input))
367
+ return { of: input };
368
+ if (plain(input) && Object.hasOwn(input, 'field') && Object.keys(input).length === 1) {
369
+ return { of: 'field', field: oneField(typed, input, at) };
370
+ }
371
+ return invalid(at, `expects ${keys.join(', ')} or a field`);
372
+ }
373
+ function direction(input, at) {
374
+ if (input === undefined)
375
+ return 'asc';
376
+ if (input !== 'asc' && input !== 'desc')
377
+ invalid(at, 'expects asc or desc');
378
+ return input;
379
+ }
380
+ function nulls(input, at) {
381
+ if (input === undefined)
382
+ return null;
383
+ if (input !== 'first' && input !== 'last')
384
+ invalid(at, 'expects first or last');
385
+ return input;
386
+ }
387
+ function orderOptions(input, at) {
388
+ const options = {
389
+ direction: direction(input.direction, place(at, 'direction')),
390
+ };
391
+ const placed = nulls(input.nulls, place(at, 'nulls'));
392
+ if (placed !== null)
393
+ options.nulls = placed;
394
+ if (input.stringSort !== undefined) {
395
+ if (input.stringSort !== 'lexical' && input.stringSort !== 'locale') {
396
+ invalid(place(at, 'stringSort'), 'expects lexical or locale');
397
+ }
398
+ options.stringSort = input.stringSort;
399
+ }
400
+ if (input.locale !== undefined) {
401
+ if (typeof input.locale !== 'string' || !collates(input.locale, undefined)) {
402
+ invalid(place(at, 'locale'), 'expects a locale name');
403
+ }
404
+ options.locale = input.locale;
405
+ }
406
+ if (input.localeOptions !== undefined) {
407
+ if (!plain(input.localeOptions) || !collates(options.locale, input.localeOptions)) {
408
+ invalid(place(at, 'localeOptions'), 'expects collation options');
409
+ }
410
+ options.localeOptions = input.localeOptions;
411
+ }
412
+ return options;
413
+ }
414
+ function collates(locale, options) {
415
+ try {
416
+ ''.localeCompare('', locale, options);
417
+ return true;
418
+ }
419
+ catch {
420
+ return false;
421
+ }
422
+ }
423
+ function parts(typed, input, at, fields) {
424
+ if (input === undefined)
425
+ return null;
426
+ if (input === 'all')
427
+ return 'all';
428
+ const named = list(input, at);
429
+ named.forEach((name, index) => {
430
+ if (fields)
431
+ specs(typed, name, place(at, index));
432
+ else if (typeof name !== 'string')
433
+ invalid(place(at, index), 'expects a name');
434
+ });
435
+ return named;
436
+ }
437
+ function flag(input, at) {
438
+ if (input === undefined)
439
+ return false;
440
+ if (input !== true)
441
+ invalid(at, 'expects true');
442
+ return true;
443
+ }
444
+ function documentShape(typed, input) {
445
+ const orderBy = (input.orderBy === undefined ? [] : list(input.orderBy, 'orderBy')).map((clause, index) => {
446
+ const at = place('orderBy', index);
447
+ if (!plain(clause))
448
+ invalid(at, 'expects an order clause');
449
+ known(clause, ORDER, at);
450
+ return {
451
+ key: keyPlan(typed, clause.by, place(at, 'by'), DOCUMENT_KEYS),
452
+ options: orderOptions(clause, at),
453
+ };
454
+ });
455
+ const select = input.select;
456
+ if (select === 'all') {
457
+ return {
458
+ kind: 'documents',
459
+ fields: 'all',
460
+ sections: 'all',
461
+ preamble: true,
462
+ markdown: true,
463
+ backlinks: true,
464
+ change: true,
465
+ fileId: true,
466
+ revision: true,
467
+ size: true,
468
+ created: true,
469
+ orderBy,
470
+ };
471
+ }
472
+ if (!plain(select))
473
+ invalid('select', "expects 'all' or the parts to return");
474
+ known(select, PARTS, 'select');
475
+ return {
476
+ kind: 'documents',
477
+ fields: parts(typed, select.fields, ['select', 'fields'], true),
478
+ sections: parts(typed, select.sections, ['select', 'sections'], false),
479
+ preamble: flag(select.preamble, ['select', 'preamble']),
480
+ markdown: flag(select.markdown, ['select', 'markdown']),
481
+ backlinks: flag(select.backlinks, ['select', 'backlinks']),
482
+ change: flag(select.change, ['select', 'change']),
483
+ fileId: flag(select.fileId, ['select', 'fileId']),
484
+ revision: flag(select.revision, ['select', 'revision']),
485
+ size: flag(select.size, ['select', 'size']),
486
+ created: flag(select.created, ['select', 'created']),
487
+ orderBy,
488
+ };
489
+ }
490
+ function greatestOf(typed, input) {
491
+ if (input === undefined)
492
+ return null;
493
+ const at = ['select', 'greatest'];
494
+ if (!plain(input))
495
+ invalid(at, 'expects the field whose greatest value each group answers');
496
+ known(input, ['field'], at);
497
+ if (!Object.hasOwn(input, 'field'))
498
+ invalid(at, 'names no field');
499
+ return oneField(typed, input, at);
500
+ }
501
+ function groupShape(typed, input) {
502
+ const groupBy = list(input.groupBy, 'groupBy').map((key, index) => keyPlan(typed, key, place('groupBy', index), GROUP_KEYS));
503
+ if (groupBy.length === 0)
504
+ invalid('groupBy', 'names no key');
505
+ const select = input.select ?? {};
506
+ if (!plain(select))
507
+ invalid('select', 'expects the totals each group answers');
508
+ known(select, GROUP_PARTS, 'select');
509
+ const greatest = greatestOf(typed, select.greatest);
510
+ const grouped = groupBy.map((key) => JSON.stringify(key));
511
+ const orderBy = (input.orderBy === undefined ? [] : list(input.orderBy, 'orderBy')).map((clause, index) => {
512
+ const at = place('orderBy', index);
513
+ if (!plain(clause))
514
+ invalid(at, 'expects an order clause');
515
+ known(clause, ['by', 'direction', 'nulls'], at);
516
+ const by = typeof clause.by === 'string' && GROUP_ORDERS.includes(clause.by)
517
+ ? clause.by
518
+ : grouped.indexOf(JSON.stringify(keyPlan(typed, clause.by, place(at, 'by'), [...GROUP_ORDERS, ...GROUP_KEYS])));
519
+ if (by === -1)
520
+ invalid(place(at, 'by'), 'orders by a key the query does not group by');
521
+ if (by === 'greatest' && greatest === null) {
522
+ invalid(place(at, 'by'), 'orders by a greatest value the query does not select');
523
+ }
524
+ return {
525
+ by,
526
+ direction: direction(clause.direction, place(at, 'direction')),
527
+ nulls: nulls(clause.nulls, place(at, 'nulls')),
528
+ };
529
+ });
530
+ return {
531
+ kind: 'groups',
532
+ groupBy,
533
+ size: flag(select.size, ['select', 'size']),
534
+ updated: flag(select.updated, ['select', 'updated']),
535
+ greatest,
536
+ orderBy,
537
+ };
538
+ }
539
+ function outsideOf(input) {
540
+ const listed = list(input, 'outside');
541
+ listed.forEach((item, index) => {
542
+ if (directory(item, place('outside', index)) === '') {
543
+ invalid(place('outside', index), 'names no directory');
544
+ }
545
+ });
546
+ return [...new Set(listed)].sort();
547
+ }
548
+ export function planOf(input, facts) {
549
+ if (!plain(input))
550
+ invalid('query', 'expects a query object');
551
+ const grouped = input.groupBy !== undefined;
552
+ if (!grouped && input.select === undefined)
553
+ invalid('select', 'a Document query must select');
554
+ known(input, [...FILTER, 'orderBy', 'limit', 'after', 'total', 'select', 'groupBy'], '');
555
+ const limit = limitOf(input.limit);
556
+ const rooms = input.rooms === undefined ? null : names(input.rooms, 'rooms');
557
+ const { typed, ...root } = scope(facts, rooms, input, '');
558
+ const shape = grouped ? groupShape(typed, input) : documentShape(typed, input);
559
+ return {
560
+ key: queryKey(input),
561
+ rooms,
562
+ root,
563
+ outside: input.outside === undefined ? null : outsideOf(input.outside),
564
+ folder: input.folder === undefined ? null : directory(input.folder, 'folder'),
565
+ paths: input.paths === undefined ? null : pathsOf(input.paths),
566
+ fileIds: input.fileIds === undefined ? null : fileIdsOf(input.fileIds),
567
+ hop: input.hop === undefined ? null : hopOf(facts, rooms, typed, input.hop),
568
+ backlinks: input.backlinks === undefined ? null : backlinksOf(facts, rooms, input.backlinks),
569
+ text: input.text === undefined ? null : phrase(input.text),
570
+ shape,
571
+ limit,
572
+ after: continuationOf(input.after, shape.orderBy.length + 1),
573
+ total: flag(input.total, 'total'),
574
+ };
575
+ }
576
+ function continuationOf(input, arity) {
577
+ if (input === undefined)
578
+ return null;
579
+ const values = typeof input === 'string' ? decodedCursor(input) : null;
580
+ if (values === null || (values.length !== 0 && values.length !== arity)) {
581
+ invalid('after', 'expects the next an earlier result of this query returned');
582
+ }
583
+ return { text: input, values: values.length === 0 ? null : values };
584
+ }
585
+ function limitOf(input) {
586
+ if (input === undefined)
587
+ return null;
588
+ if (!Number.isSafeInteger(input) || input < 0) {
589
+ invalid('limit', 'expects a nonnegative integer');
590
+ }
591
+ return input;
592
+ }
593
+ export function cursorOf(values) {
594
+ return JSON.stringify(values);
595
+ }
596
+ export function decodedCursor(text) {
597
+ try {
598
+ const decoded = JSON.parse(text);
599
+ return Array.isArray(decoded) ? decoded : null;
600
+ }
601
+ catch {
602
+ return null;
603
+ }
604
+ }
605
+ export function queryKey(query) {
606
+ return canonical(query);
607
+ }
608
+ function canonical(value) {
609
+ if (Array.isArray(value))
610
+ return `[${value.map(canonical).join(',')}]`;
611
+ if (typeof value === 'object' && value !== null) {
612
+ return `{${Object.keys(value)
613
+ .sort()
614
+ .map((name) => `${JSON.stringify(name)}:${canonical(value[name])}`)
615
+ .join(',')}}`;
616
+ }
617
+ return JSON.stringify(value);
618
+ }
619
+ export function identityOf(plan) {
620
+ return canonical(plan);
621
+ }
@@ -0,0 +1,14 @@
1
+ import type { Definition } from '../definition.js';
2
+ import { type QueryPlan } from './language.js';
3
+ import { type HeldValue } from './rows.js';
4
+ export type Candidate = {
5
+ readonly path: string;
6
+ readonly type: string | null;
7
+ readonly fileId: string | null;
8
+ readonly fields: Readonly<Record<string, unknown>>;
9
+ readonly definition?: Pick<Definition, 'root'>;
10
+ readonly text: string | null;
11
+ };
12
+ export declare function heldAt(candidate: Candidate, field: string): readonly HeldValue[];
13
+ export declare function matches(plan: QueryPlan, candidate: Candidate): boolean;
14
+ //# sourceMappingURL=match.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../../src/query/match.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGnD,OAAO,EAGL,KAAK,SAAS,EAIf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAE9D,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,CAAC;AAqGF,wBAAgB,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,SAAS,EAAE,CAMhF;AAiCD,wBAAgB,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAYtE"}