@agentshouse/mdmodel 0.1.0-c3c0e116a89f8 → 0.1.0-c420026daf4fc

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 (489) hide show
  1. package/API.md +177 -194
  2. package/README.md +25 -25
  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 +24 -11
  10. package/dist/definition.d.ts.map +1 -1
  11. package/dist/definition.js +205 -123
  12. package/dist/document.d.ts +11 -6
  13. package/dist/document.d.ts.map +1 -1
  14. package/dist/document.js +688 -105
  15. package/dist/event.d.ts +1 -2
  16. package/dist/event.d.ts.map +1 -1
  17. package/dist/event.js +2 -3
  18. package/dist/facts.d.ts.map +1 -1
  19. package/dist/facts.js +3 -2
  20. package/dist/fields.d.ts +1 -1
  21. package/dist/fields.d.ts.map +1 -1
  22. package/dist/fields.js +2 -2
  23. package/dist/form.d.ts +4 -0
  24. package/dist/form.d.ts.map +1 -0
  25. package/dist/form.js +153 -0
  26. package/dist/house-model.d.ts +912 -0
  27. package/dist/house-model.d.ts.map +1 -0
  28. package/dist/house-model.js +502 -0
  29. package/dist/house-references/crockford.d.ts +4 -0
  30. package/dist/house-references/crockford.d.ts.map +1 -0
  31. package/dist/house-references/crockford.js +3 -0
  32. package/dist/house-references/patterns.d.ts +13 -0
  33. package/dist/house-references/patterns.d.ts.map +1 -0
  34. package/dist/house-references/patterns.js +20 -0
  35. package/dist/index.d.ts +29 -14
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +19 -10
  38. package/dist/indexed.d.ts +9 -0
  39. package/dist/indexed.d.ts.map +1 -0
  40. package/dist/indexed.js +55 -0
  41. package/dist/kinds.d.ts +3 -0
  42. package/dist/kinds.d.ts.map +1 -1
  43. package/dist/kinds.js +60 -0
  44. package/dist/markdown.d.ts +27 -7
  45. package/dist/markdown.d.ts.map +1 -1
  46. package/dist/markdown.js +25 -64
  47. package/dist/media-type.d.ts +72 -0
  48. package/dist/media-type.d.ts.map +1 -0
  49. package/dist/media-type.js +157 -0
  50. package/dist/moment.d.ts +7 -0
  51. package/dist/moment.d.ts.map +1 -0
  52. package/dist/moment.js +18 -0
  53. package/dist/not-ready.d.ts +2 -0
  54. package/dist/not-ready.d.ts.map +1 -0
  55. package/dist/not-ready.js +5 -0
  56. package/dist/paths.d.ts +16 -1
  57. package/dist/paths.d.ts.map +1 -1
  58. package/dist/paths.js +102 -21
  59. package/dist/query/language.d.ts +4 -1
  60. package/dist/query/language.d.ts.map +1 -1
  61. package/dist/query/language.js +4 -3
  62. package/dist/query/match.d.ts +1 -1
  63. package/dist/query/match.d.ts.map +1 -1
  64. package/dist/query/match.js +3 -24
  65. package/dist/query/rows.d.ts +5 -1
  66. package/dist/query/rows.d.ts.map +1 -1
  67. package/dist/query/rows.js +23 -5
  68. package/dist/query/sql.d.ts +7 -1
  69. package/dist/query/sql.d.ts.map +1 -1
  70. package/dist/query/sql.js +14 -3
  71. package/dist/query/walk.d.ts +69 -0
  72. package/dist/query/walk.d.ts.map +1 -0
  73. package/dist/query/walk.js +274 -0
  74. package/dist/references.d.ts +2 -2
  75. package/dist/references.d.ts.map +1 -1
  76. package/dist/references.js +1 -1
  77. package/dist/refuse.d.ts +1 -0
  78. package/dist/refuse.d.ts.map +1 -1
  79. package/dist/refuse.js +1 -0
  80. package/dist/reserved.d.ts +1 -0
  81. package/dist/reserved.d.ts.map +1 -1
  82. package/dist/reserved.js +15 -4
  83. package/dist/room-types.d.ts +8 -0
  84. package/dist/room-types.d.ts.map +1 -0
  85. package/dist/room-types.js +144 -0
  86. package/dist/schema.d.ts +1 -3
  87. package/dist/schema.d.ts.map +1 -1
  88. package/dist/schema.js +9 -73
  89. package/dist/types.d.ts +13 -38
  90. package/dist/types.d.ts.map +1 -1
  91. package/dist/validate.d.ts +8 -2
  92. package/dist/validate.d.ts.map +1 -1
  93. package/dist/validate.js +132 -160
  94. package/dist/view.d.ts +5 -0
  95. package/dist/view.d.ts.map +1 -0
  96. package/dist/view.js +27 -0
  97. package/dist/yaml.d.ts +7 -5
  98. package/dist/yaml.d.ts.map +1 -1
  99. package/dist/yaml.js +154 -33
  100. package/fixtures/README.md +85 -70
  101. package/fixtures/cases/absent-link-dangles/library/item.md +1 -1
  102. package/fixtures/cases/absent-link-dangles/schema.md +7 -0
  103. package/fixtures/cases/absent-optional-field/library/companies/acme.md +1 -1
  104. package/fixtures/cases/absent-optional-field/library/deals/lead.md +3 -3
  105. package/fixtures/cases/absent-optional-field/{schema.yaml → schema.md} +12 -11
  106. package/fixtures/cases/absolute-link/library/item.md +1 -1
  107. package/fixtures/cases/absolute-link/schema.md +7 -0
  108. package/fixtures/cases/attachment-reference-any-file/library/companies/acme.md +1 -1
  109. package/fixtures/cases/attachment-reference-any-file/library/deals/renewal.md +13 -10
  110. package/fixtures/cases/attachment-reference-any-file/library/places/depot.md +1 -1
  111. package/fixtures/cases/attachment-reference-any-file/library/products/seats.md +1 -1
  112. package/fixtures/cases/attachment-reference-any-file/library/products/support.md +1 -1
  113. package/fixtures/cases/attachment-reference-any-file/{schema.yaml → schema.md} +2 -0
  114. package/fixtures/cases/attachment-reference-dangles/library/companies/acme.md +1 -1
  115. package/fixtures/cases/attachment-reference-dangles/library/deals/renewal.md +13 -10
  116. package/fixtures/cases/attachment-reference-dangles/library/places/depot.md +1 -1
  117. package/fixtures/cases/attachment-reference-dangles/library/products/seats.md +1 -1
  118. package/fixtures/cases/attachment-reference-dangles/library/products/support.md +1 -1
  119. package/fixtures/cases/attachment-reference-dangles/{schema.yaml → schema.md} +2 -0
  120. package/fixtures/cases/attachment-reference-outside/expected.json +2 -1
  121. package/fixtures/cases/attachment-reference-outside/library/companies/acme.md +1 -1
  122. package/fixtures/cases/attachment-reference-outside/library/deals/renewal.md +13 -10
  123. package/fixtures/cases/attachment-reference-outside/library/places/depot.md +1 -1
  124. package/fixtures/cases/attachment-reference-outside/library/products/seats.md +1 -1
  125. package/fixtures/cases/attachment-reference-outside/library/products/support.md +1 -1
  126. package/fixtures/cases/attachment-reference-outside/{schema.yaml → schema.md} +2 -0
  127. package/fixtures/cases/binary-any-reference/expected.json +2 -1
  128. package/fixtures/cases/binary-any-reference/library/notes/draft.md +1 -1
  129. package/fixtures/cases/binary-any-reference/{schema.yaml → schema.md} +2 -0
  130. package/fixtures/cases/binary-document-collision/{schema.yaml → schema.md} +2 -0
  131. package/fixtures/cases/binary-image-dangles/{schema.yaml → schema.md} +2 -0
  132. package/fixtures/cases/binary-link-dangles/{schema.yaml → schema.md} +2 -0
  133. package/fixtures/cases/binary-link-outside-collection/{schema.yaml → schema.md} +2 -0
  134. package/fixtures/cases/binary-prototype-reference/expected.json +2 -1
  135. package/fixtures/cases/binary-prototype-reference/library/notes/draft.md +1 -1
  136. package/fixtures/cases/binary-prototype-reference/{schema.yaml → schema.md} +2 -0
  137. package/fixtures/cases/binary-typed-reference/expected.json +2 -1
  138. package/fixtures/cases/binary-typed-reference/library/notes/draft.md +1 -1
  139. package/fixtures/cases/binary-typed-reference/{schema.yaml → schema.md} +2 -0
  140. package/fixtures/cases/block-scalar-frontmatter/library/notes/literal.md +17 -0
  141. package/fixtures/cases/block-scalar-frontmatter/library/skills/notes/SKILL.md +10 -0
  142. package/fixtures/cases/boolean-field/expected.json +2 -1
  143. package/fixtures/cases/boolean-field/library/companies/acme.md +1 -1
  144. package/fixtures/cases/boolean-field/library/deals/renewal.md +49 -24
  145. package/fixtures/cases/boolean-field/{schema.yaml → schema.md} +12 -11
  146. package/fixtures/cases/bracketed-link-definition/library/item.md +1 -1
  147. package/fixtures/cases/bracketed-link-definition/schema.md +7 -0
  148. package/fixtures/cases/closed-nested-object/expected.json +2 -1
  149. package/fixtures/cases/closed-nested-object/library/companies/acme.md +1 -1
  150. package/fixtures/cases/closed-nested-object/library/deals/renewal.md +50 -25
  151. package/fixtures/cases/closed-nested-object/{schema.yaml → schema.md} +12 -11
  152. package/fixtures/cases/composed-root-reference/library/a.md +2 -2
  153. package/fixtures/cases/composed-root-reference/{schema.yaml → schema.md} +2 -0
  154. package/fixtures/cases/{conditional-section → conditional-long-text}/expected.json +3 -2
  155. package/fixtures/cases/{conditional-section → conditional-long-text}/library/questions/hosting.md +2 -2
  156. package/fixtures/cases/{conditional-section → conditional-long-text}/library/questions/payments.md +2 -2
  157. package/fixtures/cases/conditional-long-text/schema.md +15 -0
  158. package/fixtures/cases/cross-room-link/library/clients/acme.md +1 -1
  159. package/fixtures/cases/cross-room-link/{schema.yaml → schema.md} +2 -0
  160. package/fixtures/cases/cross-room-reference/library/clients/acme.md +4 -4
  161. package/fixtures/cases/cross-room-reference/{schema.yaml → schema.md} +3 -2
  162. package/fixtures/cases/date-time-format/expected.json +2 -1
  163. package/fixtures/cases/date-time-format/library/companies/acme.md +1 -1
  164. package/fixtures/cases/date-time-format/library/deals/renewal.md +49 -24
  165. package/fixtures/cases/date-time-format/{schema.yaml → schema.md} +12 -11
  166. package/fixtures/cases/declared-binary-links/schema.md +3 -0
  167. package/fixtures/cases/default-unfilled/library/companies/acme.md +1 -1
  168. package/fixtures/cases/default-unfilled/library/deals/renewal.md +47 -22
  169. package/fixtures/cases/default-unfilled/schema.md +57 -0
  170. package/fixtures/cases/defs-pattern/expected.json +2 -1
  171. package/fixtures/cases/defs-pattern/library/companies/acme.md +1 -1
  172. package/fixtures/cases/defs-pattern/library/deals/renewal.md +49 -24
  173. package/fixtures/cases/defs-pattern/schema.md +57 -0
  174. package/fixtures/cases/dependent-rule/library/companies/acme.md +1 -1
  175. package/fixtures/cases/dependent-rule/library/deals/renewal.md +48 -23
  176. package/fixtures/cases/dependent-rule/schema.md +57 -0
  177. package/fixtures/cases/duplicate-link-definition/library/item.md +1 -1
  178. package/fixtures/cases/duplicate-link-definition/schema.md +7 -0
  179. package/fixtures/cases/email-format/expected.json +2 -1
  180. package/fixtures/cases/email-format/library/companies/acme.md +1 -1
  181. package/fixtures/cases/email-format/library/deals/renewal.md +49 -24
  182. package/fixtures/cases/email-format/schema.md +57 -0
  183. package/fixtures/cases/equal-labels/expected.json +5 -0
  184. package/fixtures/cases/equal-labels/schema.md +6 -0
  185. package/fixtures/cases/fenced-link-definition/library/item.md +1 -1
  186. package/fixtures/cases/fenced-link-definition/schema.md +7 -0
  187. package/fixtures/cases/field-enum/expected.json +2 -1
  188. package/fixtures/cases/field-enum/library/item.md +2 -2
  189. package/fixtures/cases/field-enum/schema.md +8 -0
  190. package/fixtures/cases/frontmatter-construct/expected.json +7 -0
  191. package/fixtures/cases/frontmatter-construct/library/note.md +6 -0
  192. package/fixtures/cases/integer-field/expected.json +2 -1
  193. package/fixtures/cases/integer-field/library/companies/acme.md +1 -1
  194. package/fixtures/cases/integer-field/library/deals/renewal.md +49 -24
  195. package/fixtures/cases/integer-field/schema.md +57 -0
  196. package/fixtures/cases/interrupted-link-definition/schema.md +3 -0
  197. package/fixtures/cases/json-schema-constructs/library/companies/acme.md +1 -1
  198. package/fixtures/cases/json-schema-constructs/library/deals/renewal.md +49 -24
  199. package/fixtures/cases/json-schema-constructs/schema.md +57 -0
  200. package/fixtures/cases/labels-in-the-rooms-language/expected.json +1 -0
  201. package/fixtures/cases/labels-in-the-rooms-language/library/deals/atlas.md +7 -0
  202. package/fixtures/cases/labels-in-the-rooms-language/schema.md +11 -0
  203. package/fixtures/cases/lazy-list-item/library/item.md +3 -1
  204. package/fixtures/cases/lazy-list-item/schema.md +5 -0
  205. package/fixtures/cases/link-into-a-reserved-name/library/notes/a.md +1 -1
  206. package/fixtures/cases/link-into-a-reserved-name/{schema.yaml → schema.md} +2 -0
  207. package/fixtures/cases/list-item-enum/expected.json +7 -0
  208. package/fixtures/cases/list-item-enum/library/task.md +7 -0
  209. package/fixtures/cases/list-item-enum/schema.md +5 -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.md +5 -0
  213. package/fixtures/cases/list-items/expected.json +1 -0
  214. package/fixtures/cases/list-items/library/page.md +26 -0
  215. package/fixtures/cases/list-items/schema.md +12 -0
  216. package/fixtures/cases/list-of-objects-closed/expected.json +2 -1
  217. package/fixtures/cases/list-of-objects-closed/library/companies/acme.md +1 -1
  218. package/fixtures/cases/list-of-objects-closed/library/deals/renewal.md +49 -25
  219. package/fixtures/cases/list-of-objects-closed/schema.md +57 -0
  220. package/fixtures/cases/list-of-objects-item/expected.json +2 -1
  221. package/fixtures/cases/list-of-objects-item/library/companies/acme.md +1 -1
  222. package/fixtures/cases/list-of-objects-item/library/deals/renewal.md +49 -24
  223. package/fixtures/cases/list-of-objects-item/schema.md +57 -0
  224. package/fixtures/cases/list-of-objects-reference/expected.json +2 -1
  225. package/fixtures/cases/list-of-objects-reference/library/companies/acme.md +1 -1
  226. package/fixtures/cases/list-of-objects-reference/library/deals/renewal.md +12 -9
  227. package/fixtures/cases/list-of-objects-reference/library/places/depot.md +1 -1
  228. package/fixtures/cases/list-of-objects-reference/library/products/seats.md +1 -1
  229. package/fixtures/cases/list-of-objects-reference/library/products/support.md +1 -1
  230. package/fixtures/cases/list-of-objects-reference/{schema.yaml → schema.md} +2 -0
  231. package/fixtures/cases/list-reference-path/expected.json +7 -0
  232. package/fixtures/cases/list-reference-path/library/page.md +5 -0
  233. package/fixtures/cases/list-reference-path/schema.md +5 -0
  234. package/fixtures/cases/list-reference-type/expected.json +7 -0
  235. package/fixtures/cases/list-reference-type/library/page.md +6 -0
  236. package/fixtures/cases/list-reference-type/schema.md +5 -0
  237. package/fixtures/cases/list-size/expected.json +2 -1
  238. package/fixtures/cases/list-size/library/companies/acme.md +1 -1
  239. package/fixtures/cases/list-size/library/deals/renewal.md +51 -24
  240. package/fixtures/cases/list-size/schema.md +57 -0
  241. package/fixtures/cases/long-fence-link-definition/schema.md +3 -0
  242. package/fixtures/cases/long-value-past-six-levels/expected.json +5 -0
  243. package/fixtures/cases/long-value-past-six-levels/schema.md +17 -0
  244. package/fixtures/cases/malformed-definition/{schema.yaml → schema.md} +2 -0
  245. package/fixtures/cases/malformed-list/expected.json +7 -0
  246. package/fixtures/cases/{structured-section → malformed-list}/library/item.md +1 -1
  247. package/fixtures/cases/malformed-list/schema.md +8 -0
  248. package/fixtures/cases/member-document/library/people/ana.md +2 -2
  249. package/fixtures/cases/member-document/{schema.yaml → schema.md} +2 -0
  250. package/fixtures/cases/member-on-another-type/library/note.md +1 -1
  251. package/fixtures/cases/member-on-another-type/{schema.yaml → schema.md} +2 -0
  252. package/fixtures/cases/missing-required-field/library/item.md +1 -1
  253. package/fixtures/cases/missing-required-field/schema.md +8 -0
  254. package/fixtures/cases/misspelled-key/expected.json +2 -1
  255. package/fixtures/cases/misspelled-key/library/companies/acme.md +1 -1
  256. package/fixtures/cases/misspelled-key/library/deals/renewal.md +50 -25
  257. package/fixtures/cases/misspelled-key/schema.md +57 -0
  258. package/fixtures/cases/name-not-a-string/context.json +1 -0
  259. package/fixtures/cases/name-not-a-string/expected.json +5 -0
  260. package/fixtures/cases/name-not-a-string/schema.md +7 -0
  261. package/fixtures/cases/nested-defs/expected.json +2 -1
  262. package/fixtures/cases/nested-defs/library/deal.md +3 -3
  263. package/fixtures/cases/nested-defs/{schema.yaml → schema.md} +2 -0
  264. package/fixtures/cases/nested-object-reference/expected.json +2 -1
  265. package/fixtures/cases/nested-object-reference/library/companies/acme.md +1 -1
  266. package/fixtures/cases/nested-object-reference/library/deals/renewal.md +12 -9
  267. package/fixtures/cases/nested-object-reference/library/places/depot.md +1 -1
  268. package/fixtures/cases/nested-object-reference/library/products/seats.md +1 -1
  269. package/fixtures/cases/nested-object-reference/library/products/support.md +1 -1
  270. package/fixtures/cases/nested-object-reference/schema.md +34 -0
  271. package/fixtures/cases/nested-reference/library/companies/acme.md +1 -1
  272. package/fixtures/cases/nested-reference/library/deals/renewal.md +13 -10
  273. package/fixtures/cases/nested-reference/library/places/depot.md +1 -1
  274. package/fixtures/cases/nested-reference/library/products/seats.md +1 -1
  275. package/fixtures/cases/nested-reference/library/products/support.md +1 -1
  276. package/fixtures/cases/nested-reference/schema.md +34 -0
  277. package/fixtures/cases/nested-required-field/expected.json +2 -1
  278. package/fixtures/cases/nested-required-field/library/companies/acme.md +1 -1
  279. package/fixtures/cases/nested-required-field/library/deals/renewal.md +48 -23
  280. package/fixtures/cases/nested-required-field/schema.md +57 -0
  281. package/fixtures/cases/numeric-range/expected.json +2 -1
  282. package/fixtures/cases/numeric-range/library/companies/acme.md +1 -1
  283. package/fixtures/cases/numeric-range/library/deals/renewal.md +49 -24
  284. package/fixtures/cases/numeric-range/schema.md +57 -0
  285. package/fixtures/cases/one-key-two-labels/context.json +1 -0
  286. package/fixtures/cases/one-key-two-labels/expected.json +5 -0
  287. package/fixtures/cases/one-key-two-labels/schema.md +7 -0
  288. package/fixtures/cases/one-key-two-types/context.json +1 -0
  289. package/fixtures/cases/one-key-two-types/expected.json +5 -0
  290. package/fixtures/cases/one-key-two-types/schema.md +6 -0
  291. package/fixtures/cases/one-of-variant/expected.json +2 -1
  292. package/fixtures/cases/one-of-variant/library/companies/acme.md +1 -1
  293. package/fixtures/cases/one-of-variant/library/deals/renewal.md +49 -24
  294. package/fixtures/cases/one-of-variant/schema.md +57 -0
  295. package/fixtures/cases/other-room-reference/expected.json +2 -1
  296. package/fixtures/cases/other-room-reference/library/companies/acme.md +1 -1
  297. package/fixtures/cases/other-room-reference/library/deals/renewal.md +12 -9
  298. package/fixtures/cases/other-room-reference/library/places/depot.md +1 -1
  299. package/fixtures/cases/other-room-reference/library/products/seats.md +1 -1
  300. package/fixtures/cases/other-room-reference/library/products/support.md +1 -1
  301. package/fixtures/cases/other-room-reference/schema.md +34 -0
  302. package/fixtures/cases/paragraph-link-definition/schema.md +3 -0
  303. package/fixtures/cases/prototype-field/expected.json +2 -1
  304. package/fixtures/cases/prototype-field/library/item.md +2 -2
  305. package/fixtures/cases/prototype-field/schema.md +7 -0
  306. package/fixtures/cases/quoted-link-definition/schema.md +3 -0
  307. package/fixtures/cases/reference-into-a-reserved-name/expected.json +2 -1
  308. package/fixtures/cases/reference-into-a-reserved-name/library/notes/a.md +1 -1
  309. package/fixtures/cases/reference-into-a-reserved-name/{schema.yaml → schema.md} +2 -0
  310. package/fixtures/cases/reference-to-any-file-name/context.json +1 -0
  311. package/fixtures/cases/reference-to-any-file-name/expected.json +1 -0
  312. package/fixtures/cases/reference-to-any-file-name/library/people/100%.md +4 -0
  313. package/fixtures/cases/reference-to-any-file-name/library/people/C#.md +4 -0
  314. package/fixtures/cases/reference-to-any-file-name/library/people/My notes.md +4 -0
  315. package/fixtures/cases/reference-to-any-file-name/library/people/[draft].md +4 -0
  316. package/fixtures/cases/reference-to-any-file-name/library/people/c (d).md +4 -0
  317. package/fixtures/cases/reference-to-any-file-name/library/people/caf/303/251.md +4 -0
  318. package/fixtures/cases/reference-to-any-file-name/library/people//320/236/321/202/321/207/321/221/321/202.md +4 -0
  319. package/fixtures/cases/reference-to-any-file-name/library/tasks/bracket.md +9 -0
  320. package/fixtures/cases/reference-to-any-file-name/library/tasks/cyrillic.md +9 -0
  321. package/fixtures/cases/reference-to-any-file-name/library/tasks/decomposed.md +9 -0
  322. package/fixtures/cases/reference-to-any-file-name/library/tasks/hash.md +9 -0
  323. package/fixtures/cases/reference-to-any-file-name/library/tasks/parenthesis.md +9 -0
  324. package/fixtures/cases/reference-to-any-file-name/library/tasks/percent.md +9 -0
  325. package/fixtures/cases/reference-to-any-file-name/library/tasks/spaced.md +9 -0
  326. package/fixtures/cases/reference-to-any-file-name/schema.md +12 -0
  327. package/fixtures/cases/referenced-missing-file/library/a.md +2 -2
  328. package/fixtures/cases/referenced-missing-file/library/b.md +2 -2
  329. package/fixtures/cases/referenced-missing-file/schema.md +12 -0
  330. package/fixtures/cases/referenced-missing-non-latin-file/context.json +1 -0
  331. package/fixtures/cases/referenced-missing-non-latin-file/expected.json +6 -0
  332. package/fixtures/cases/referenced-missing-non-latin-file/library/tasks/a.md +9 -0
  333. package/fixtures/cases/referenced-missing-non-latin-file/library/tasks/b.md +9 -0
  334. package/fixtures/cases/referenced-missing-non-latin-file/schema.md +12 -0
  335. package/fixtures/cases/remote-ref/{schema.yaml → schema.md} +2 -0
  336. package/fixtures/cases/schema-body-ignored/context.json +1 -0
  337. package/fixtures/cases/schema-body-ignored/expected.json +1 -0
  338. package/fixtures/cases/schema-body-ignored/schema.md +9 -0
  339. package/fixtures/cases/schema-type-named-folders/context.json +1 -0
  340. package/fixtures/cases/schema-type-named-folders/expected.json +5 -0
  341. package/fixtures/cases/schema-type-named-folders/schema.md +5 -0
  342. package/fixtures/cases/schema-type-named-type/context.json +1 -0
  343. package/fixtures/cases/schema-type-named-type/expected.json +5 -0
  344. package/fixtures/cases/{unknown-type/schema.yaml → schema-type-named-type/schema.md} +3 -1
  345. package/fixtures/cases/second-member-document/{schema.yaml → schema.md} +2 -0
  346. package/fixtures/cases/sections-keyword-refused/context.json +1 -0
  347. package/fixtures/cases/sections-keyword-refused/expected.json +5 -0
  348. package/fixtures/cases/{structured-section/schema.yaml → sections-keyword-refused/schema.md} +3 -2
  349. package/fixtures/cases/shortcut-reference-link/library/item.md +1 -1
  350. package/fixtures/cases/shortcut-reference-link/schema.md +7 -0
  351. package/fixtures/cases/string-length/expected.json +2 -1
  352. package/fixtures/cases/string-length/library/companies/acme.md +1 -1
  353. package/fixtures/cases/string-length/library/deals/renewal.md +49 -24
  354. package/fixtures/cases/string-length/schema.md +57 -0
  355. package/fixtures/cases/submission-keys/library/notes/visitor.md +2 -2
  356. package/fixtures/cases/submission-keys/{schema.yaml → schema.md} +2 -0
  357. package/fixtures/cases/text-field-kind/expected.json +1 -4
  358. package/fixtures/cases/text-field-kind/library/page.md +1 -1
  359. package/fixtures/cases/text-field-kind/{schema.yaml → schema.md} +2 -0
  360. package/fixtures/cases/thematic-break-ends-the-values/context.json +1 -0
  361. package/fixtures/cases/thematic-break-ends-the-values/expected.json +1 -0
  362. package/fixtures/cases/thematic-break-ends-the-values/library/item.md +10 -0
  363. package/fixtures/cases/thematic-break-ends-the-values/schema.md +5 -0
  364. package/fixtures/cases/truncated-link-definition/schema.md +3 -0
  365. package/fixtures/cases/{typed-path-names-its-type/schema.yaml → typed-path-names-another-type/schema.md} +2 -0
  366. package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/one.md +1 -1
  367. package/fixtures/cases/{typed-path-names-no-type/schema.yaml → typed-path-names-its-type/schema.md} +2 -0
  368. package/fixtures/cases/{typed-path-names-another-type/schema.yaml → typed-path-names-no-type/schema.md} +2 -0
  369. package/fixtures/cases/types-folder-content/library/types/task.md +1 -1
  370. package/fixtures/cases/types-folder-content/{schema.yaml → schema.md} +2 -0
  371. package/fixtures/cases/undeclared-field/expected.json +2 -1
  372. package/fixtures/cases/undeclared-field/library/item.md +2 -2
  373. package/fixtures/cases/undeclared-field/schema.md +7 -0
  374. package/fixtures/cases/unevaluated-items-closed/expected.json +2 -1
  375. package/fixtures/cases/unevaluated-items-closed/library/trip.md +13 -3
  376. package/fixtures/cases/unevaluated-items-closed/{schema.yaml → schema.md} +2 -0
  377. package/fixtures/cases/unlisted-reference-type/{schema.yaml → schema.md} +2 -0
  378. package/fixtures/cases/unnamed-typed-path-checks-its-fields/library/rooms/team/tasks/plan.md +2 -1
  379. package/fixtures/cases/{unnamed-typed-path-without-a-body/schema.yaml → unnamed-typed-path-checks-its-fields/schema.md} +2 -0
  380. package/fixtures/cases/unnamed-typed-path-names-a-type/library/rooms/team/tasks/plan.md +3 -2
  381. package/fixtures/cases/{unnamed-typed-path-checks-its-fields/schema.yaml → unnamed-typed-path-names-a-type/schema.md} +2 -0
  382. package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/tasks/plan.md +3 -2
  383. package/fixtures/cases/{unnamed-typed-path-names-a-type/schema.yaml → unnamed-typed-path-reads-its-type/schema.md} +2 -0
  384. package/fixtures/cases/unnamed-typed-path-without-a-body/library/rooms/team/tasks/plan.md +2 -2
  385. package/fixtures/cases/{unnamed-typed-path-reads-its-type/schema.yaml → unnamed-typed-path-without-a-body/schema.md} +2 -0
  386. package/fixtures/cases/unresolved-link/library/item.md +1 -1
  387. package/fixtures/cases/unresolved-link/schema.md +7 -0
  388. package/fixtures/cases/valid-typed-document/library/people/ada.md +1 -1
  389. package/fixtures/cases/valid-typed-document/library/tasks/one.md +11 -11
  390. package/fixtures/cases/valid-typed-document/schema.md +17 -0
  391. package/fixtures/cases/wide-item-fence-link/schema.md +3 -0
  392. package/fixtures/forms.json +371 -0
  393. package/fixtures/preamble.json +6 -6
  394. package/fixtures/queries.json +600 -2
  395. package/fixtures/references.json +15 -0
  396. package/package.json +1 -1
  397. package/dist/divide.d.ts +0 -3
  398. package/dist/divide.d.ts.map +0 -1
  399. package/dist/divide.js +0 -321
  400. package/dist/project.d.ts +0 -22
  401. package/dist/project.d.ts.map +0 -1
  402. package/dist/project.js +0 -123
  403. package/fixtures/cases/absent-link-dangles/schema.yaml +0 -6
  404. package/fixtures/cases/absolute-link/schema.yaml +0 -6
  405. package/fixtures/cases/bracketed-link-definition/schema.yaml +0 -6
  406. package/fixtures/cases/conditional-section/schema.yaml +0 -14
  407. package/fixtures/cases/declared-binary-links/schema.yaml +0 -1
  408. package/fixtures/cases/default-unfilled/schema.yaml +0 -56
  409. package/fixtures/cases/defs-pattern/schema.yaml +0 -56
  410. package/fixtures/cases/dependent-rule/schema.yaml +0 -56
  411. package/fixtures/cases/duplicate-link-definition/schema.yaml +0 -6
  412. package/fixtures/cases/email-format/schema.yaml +0 -56
  413. package/fixtures/cases/fenced-link-definition/schema.yaml +0 -6
  414. package/fixtures/cases/field-enum/schema.yaml +0 -7
  415. package/fixtures/cases/frontmatter-schema/expected.json +0 -5
  416. package/fixtures/cases/integer-field/schema.yaml +0 -56
  417. package/fixtures/cases/interrupted-link-definition/schema.yaml +0 -1
  418. package/fixtures/cases/json-schema-constructs/schema.yaml +0 -56
  419. package/fixtures/cases/lazy-list-item/schema.yaml +0 -3
  420. package/fixtures/cases/list-of-objects-closed/schema.yaml +0 -56
  421. package/fixtures/cases/list-of-objects-item/schema.yaml +0 -56
  422. package/fixtures/cases/list-size/schema.yaml +0 -56
  423. package/fixtures/cases/long-fence-link-definition/schema.yaml +0 -1
  424. package/fixtures/cases/missing-required-field/schema.yaml +0 -7
  425. package/fixtures/cases/missing-section-item-kind/expected.json +0 -5
  426. package/fixtures/cases/missing-section-item-kind/schema.yaml +0 -6
  427. package/fixtures/cases/misspelled-key/schema.yaml +0 -56
  428. package/fixtures/cases/nested-object-reference/schema.yaml +0 -32
  429. package/fixtures/cases/nested-reference/schema.yaml +0 -32
  430. package/fixtures/cases/nested-required-field/schema.yaml +0 -56
  431. package/fixtures/cases/null-refused/expected.json +0 -6
  432. package/fixtures/cases/null-refused/library/companies/acme.md +0 -4
  433. package/fixtures/cases/null-refused/library/deals/renewal.md +0 -31
  434. package/fixtures/cases/null-refused/schema.yaml +0 -56
  435. package/fixtures/cases/numeric-range/schema.yaml +0 -56
  436. package/fixtures/cases/one-of-variant/schema.yaml +0 -56
  437. package/fixtures/cases/open-map-value/expected.json +0 -6
  438. package/fixtures/cases/open-map-value/library/companies/acme.md +0 -4
  439. package/fixtures/cases/open-map-value/library/deals/renewal.md +0 -31
  440. package/fixtures/cases/open-map-value/schema.yaml +0 -56
  441. package/fixtures/cases/other-room-reference/schema.yaml +0 -32
  442. package/fixtures/cases/paragraph-link-definition/schema.yaml +0 -1
  443. package/fixtures/cases/prototype-field/schema.yaml +0 -6
  444. package/fixtures/cases/quoted-link-definition/schema.yaml +0 -1
  445. package/fixtures/cases/referenced-missing-file/schema.yaml +0 -11
  446. package/fixtures/cases/section-item-enum/expected.json +0 -6
  447. package/fixtures/cases/section-item-enum/library/task.md +0 -8
  448. package/fixtures/cases/section-item-enum/schema.yaml +0 -3
  449. package/fixtures/cases/section-item-kind/expected.json +0 -6
  450. package/fixtures/cases/section-item-kind/library/task.md +0 -8
  451. package/fixtures/cases/section-item-kind/schema.yaml +0 -3
  452. package/fixtures/cases/section-items/library/page.md +0 -42
  453. package/fixtures/cases/section-items/schema.yaml +0 -10
  454. package/fixtures/cases/section-reference-path/expected.json +0 -6
  455. package/fixtures/cases/section-reference-path/library/page.md +0 -7
  456. package/fixtures/cases/section-reference-path/schema.yaml +0 -3
  457. package/fixtures/cases/section-reference-type/expected.json +0 -6
  458. package/fixtures/cases/section-reference-type/library/page.md +0 -7
  459. package/fixtures/cases/section-reference-type/schema.yaml +0 -3
  460. package/fixtures/cases/shortcut-reference-link/schema.yaml +0 -6
  461. package/fixtures/cases/string-length/schema.yaml +0 -56
  462. package/fixtures/cases/structured-section/expected.json +0 -6
  463. package/fixtures/cases/thematic-break-in-a-list-section/expected.json +0 -6
  464. package/fixtures/cases/thematic-break-in-a-list-section/library/item.md +0 -7
  465. package/fixtures/cases/thematic-break-in-a-list-section/schema.yaml +0 -3
  466. package/fixtures/cases/truncated-link-definition/schema.yaml +0 -1
  467. package/fixtures/cases/undeclared-field/schema.yaml +0 -6
  468. package/fixtures/cases/unresolved-link/schema.yaml +0 -6
  469. package/fixtures/cases/valid-typed-document/schema.yaml +0 -16
  470. package/fixtures/cases/wide-item-fence-link/schema.yaml +0 -1
  471. package/fixtures/division.json +0 -454
  472. package/fixtures/projection.json +0 -358
  473. /package/fixtures/cases/{conditional-section → block-scalar-frontmatter}/context.json +0 -0
  474. /package/fixtures/cases/{section-items → block-scalar-frontmatter}/expected.json +0 -0
  475. /package/fixtures/cases/{frontmatter-schema → conditional-long-text}/context.json +0 -0
  476. /package/fixtures/cases/{missing-section-item-kind → equal-labels}/context.json +0 -0
  477. /package/fixtures/cases/{null-refused → frontmatter-construct}/context.json +0 -0
  478. /package/fixtures/cases/{open-map-value → labels-in-the-rooms-language}/context.json +0 -0
  479. /package/fixtures/cases/{section-item-enum → list-item-enum}/context.json +0 -0
  480. /package/fixtures/cases/{section-item-kind → list-item-kind}/context.json +0 -0
  481. /package/fixtures/cases/{section-items → list-items}/context.json +0 -0
  482. /package/fixtures/cases/{section-items → list-items}/library/other.md +0 -0
  483. /package/fixtures/cases/{section-reference-path → list-reference-path}/context.json +0 -0
  484. /package/fixtures/cases/{section-reference-path → list-reference-path}/library/other.md +0 -0
  485. /package/fixtures/cases/{section-reference-type → list-reference-type}/context.json +0 -0
  486. /package/fixtures/cases/{section-reference-type → list-reference-type}/library/note.md +0 -0
  487. /package/fixtures/cases/{structured-section → long-value-past-six-levels}/context.json +0 -0
  488. /package/fixtures/cases/{thematic-break-in-a-list-section → malformed-list}/context.json +0 -0
  489. /package/fixtures/cases/{frontmatter-schema/schema.yaml → unknown-type/schema.md} +0 -0
@@ -1,5 +1,5 @@
1
1
  import { ARRAY_INDEX, escapePointer, itemFacts, memberFacts, } from '../definition.js';
2
- import { instantKey, kindOf } from '../kinds.js';
2
+ import { instantOf } from '../kinds.js';
3
3
  import { target } from '../paths.js';
4
4
  export function placedOf(pointer, reach) {
5
5
  const [first = '', ...rest] = pointer.split('/').slice(1);
@@ -25,6 +25,27 @@ export function placedOf(pointer, reach) {
25
25
  glob: /[[*]/u.test(places),
26
26
  };
27
27
  }
28
+ function globbed(pattern) {
29
+ let source = '';
30
+ for (let at = 0; at < pattern.length; at += 1) {
31
+ const char = pattern[at];
32
+ if (char === '*')
33
+ source += '.*';
34
+ else if (char === '[') {
35
+ const end = pattern.indexOf(']', at);
36
+ source += pattern.slice(at, end + 1);
37
+ at = end;
38
+ }
39
+ else
40
+ source += char.replace(/[.\\^$+?()|{}/]/gu, '\\$&');
41
+ }
42
+ return new RegExp(`^${source}$`, 'u');
43
+ }
44
+ export function placedIn(rows, pointer, reach) {
45
+ const { keys, places, glob } = placedOf(pointer, reach);
46
+ const matched = glob ? globbed(places) : null;
47
+ return rows.filter((row) => row.keys === keys && (matched === null ? row.places === places : matched.test(row.places)));
48
+ }
28
49
  function placesOf({ done, head, tail }) {
29
50
  return `${done}/${head}${tail}.`;
30
51
  }
@@ -67,9 +88,6 @@ function scalarOf(value) {
67
88
  return JSON.stringify(value);
68
89
  return null;
69
90
  }
70
- function instantOf(facts, value) {
71
- return facts !== undefined && kindOf(facts) === 'date-time' ? instantKey(value) : null;
72
- }
73
91
  function held(reading, at, places, value, items) {
74
92
  reading.values.push({
75
93
  keys: at.keys,
@@ -154,7 +172,7 @@ export function indexed(path, fields, definition) {
154
172
  head: '',
155
173
  tail: '',
156
174
  exact: `/${segment}`,
157
- facts: definition === undefined ? undefined : memberFacts(definition.frontmatter, name),
175
+ facts: definition === undefined ? undefined : memberFacts(definition.root, name),
158
176
  });
159
177
  }
160
178
  return { values: reading.values, links: reading.links };
@@ -19,6 +19,7 @@ export type Following = {
19
19
  readonly equal: Fragment;
20
20
  };
21
21
  export declare const VALUE_TABLE = "CREATE TABLE replica_values (doc INTEGER NOT NULL, keys TEXT NOT NULL, places TEXT NOT NULL, item INTEGER NOT NULL, kind TEXT NOT NULL, value, size INTEGER, instant TEXT, PRIMARY KEY (doc, keys, places, item)) WITHOUT ROWID";
22
+ export type Targets = (link: string, document: string) => Fragment;
22
23
  export declare const HOLDS_PHRASE = "holds_phrase";
23
24
  export declare function holdsPhrase(_context: number, text: unknown, phrase: unknown): number;
24
25
  export declare function fragment(sql: string, bind?: readonly SqlValue[]): Fragment;
@@ -28,10 +29,15 @@ export declare function any(parts: readonly Fragment[]): Fragment;
28
29
  export declare function grouped(part: Fragment): Fragment;
29
30
  export declare function listed(values: readonly SqlValue[]): Fragment;
30
31
  export declare function exists(part: Fragment): Fragment;
31
- export declare function insertedValues(doc: number, values: readonly HeldValue[]): Fragment;
32
+ export type HeldValues = {
33
+ readonly doc: number;
34
+ readonly values: readonly HeldValue[];
35
+ };
36
+ export declare function insertedValues(held: readonly HeldValues[]): Fragment;
32
37
  export declare function placed(alias: string, field: string, reach: Reach): Fragment;
33
38
  export declare function scoped(alias: string, scope: Scope, byPaths?: boolean): Fragment;
34
39
  export declare function tests(alias: string, plan: QueryPlan): Fragment;
40
+ export declare function hopped(alias: string, hop: NonNullable<QueryPlan['hop']>, targets: Targets): Fragment;
35
41
  export declare function sortValue(kind: SqlValue | undefined, value: unknown, instant: SqlValue | undefined): unknown;
36
42
  export declare function sorted(collate: Collate, term: Term): Fragment;
37
43
  export declare function beyond(collate: Collate, term: Term, value: unknown): Following;
@@ -1 +1 @@
1
- {"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../src/query/sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAU,SAAS,EAAE,KAAK,EAAe,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAY,KAAK,SAAS,EAAE,KAAK,KAAK,EAAE,MAAM,WAAW,CAAC;AAEjE,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,IAAI,CAAC;AAEpE,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,QAAQ,EAAE,CAAA;CAAE,CAAC;AAEpF,MAAM,MAAM,OAAO,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,KAAK,MAAM,GAAG,IAAI,CAAC;AAE5F,MAAM,MAAM,IAAI,GAAG;IACjB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EA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Ac,CAAC,IAAI,EAAE,SAAS,UAAU,EAAE,GAAG,QAAQ,CAWpE;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,QAAQ,CAG3E;AA+ID,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,UAAQ,GAAG,QAAQ,CAgB7E;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,QAAQ,CAqB9D;AAED,wBAAgB,MAAM,CACpB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAClC,OAAO,EAAE,OAAO,GACf,QAAQ,CAeV;AAUD,wBAAgB,SAAS,CACvB,IAAI,EAAE,QAAQ,GAAG,SAAS,EAC1B,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,QAAQ,GAAG,SAAS,WAG9B;AAsDD,wBAAgB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,QAAQ,CAc7D;AAED,wBAAgB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,SAAS,CAgC9E;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,GAAG,EAAE,QAAQ,GAAG,QAAQ,CAM9E"}
package/dist/query/sql.js CHANGED
@@ -54,9 +54,9 @@ function scalarText(value) {
54
54
  return '-Infinity';
55
55
  return JSON.stringify(value);
56
56
  }
57
- export function insertedValues(doc, values) {
58
- const rows = values.map((value) => `[${JSON.stringify(value.keys)},${JSON.stringify(value.places)},${value.item},${JSON.stringify(value.kind)},${scalarText(value.value)},${JSON.stringify(value.size)},${JSON.stringify(value.instant)}]`);
59
- return fragment('INSERT INTO replica_values (doc, keys, places, item, kind, value, size, instant) SELECT ?, value ->> 0, value ->> 1, value ->> 2, value ->> 3, value ->> 4, value ->> 5, value ->> 6 FROM json_each(?)', [doc, `[${rows.join(',')}]`]);
57
+ export function insertedValues(held) {
58
+ const rows = held.flatMap(({ doc, values }) => values.map((value) => `[${doc},${JSON.stringify(value.keys)},${JSON.stringify(value.places)},${value.item},${JSON.stringify(value.kind)},${scalarText(value.value)},${JSON.stringify(value.size)},${JSON.stringify(value.instant)}]`));
59
+ return fragment('INSERT INTO replica_values (doc, keys, places, item, kind, value, size, instant) SELECT value ->> 0, value ->> 1, value ->> 2, value ->> 3, value ->> 4, value ->> 5, value ->> 6, value ->> 7 FROM json_each(?)', [`[${rows.join(',')}]`]);
60
60
  }
61
61
  export function placed(alias, field, reach) {
62
62
  const { keys, places, glob } = placedOf(field, reach);
@@ -182,6 +182,17 @@ export function tests(alias, plan) {
182
182
  : [fragment(`${HOLDS_PHRASE}(${alias}.content, ?)`, [plan.text.toLowerCase()])]),
183
183
  ]);
184
184
  }
185
+ export function hopped(alias, hop, targets) {
186
+ const linked = exists(joined([
187
+ fragment('SELECT 1 FROM replica_links l JOIN '),
188
+ targets('l', 'm'),
189
+ fragment(` WHERE l.doc = ${alias}.id AND l.kind = 'field' AND `),
190
+ grouped(placed('l', hop.field, 'link')),
191
+ fragment(' AND '),
192
+ grouped(scoped('m', hop)),
193
+ ], ''));
194
+ return hop.none ? not(linked) : linked;
195
+ }
185
196
  function instantMark(value) {
186
197
  if (typeof value !== 'object' || value === null || Array.isArray(value))
187
198
  return null;
@@ -0,0 +1,69 @@
1
+ import { type Definition } from '../definition.js';
2
+ import type { VerifiedModel } from '../types.js';
3
+ import { type Direction, type QueryPlan } from './language.js';
4
+ export type KeyBound = {
5
+ readonly key: Uint8Array;
6
+ readonly inclusive: boolean;
7
+ };
8
+ export type KeyRange = {
9
+ readonly lower: KeyBound;
10
+ readonly upper: KeyBound | null;
11
+ };
12
+ export type WalkRun = {
13
+ readonly by: 'key';
14
+ readonly key: Uint8Array;
15
+ readonly after: boolean;
16
+ } | {
17
+ readonly by: 'range';
18
+ readonly range: KeyRange;
19
+ };
20
+ export type PageOrder = {
21
+ readonly by: 'path';
22
+ readonly direction: Direction;
23
+ } | {
24
+ readonly by: 'field';
25
+ readonly field: string;
26
+ readonly direction: Direction;
27
+ readonly nulls: 'first' | 'last';
28
+ readonly lexical: boolean;
29
+ readonly after: {
30
+ readonly key: Uint8Array;
31
+ readonly tie: unknown;
32
+ } | null;
33
+ };
34
+ export type Walk = {
35
+ readonly by: 'path';
36
+ readonly direction: Direction;
37
+ } | {
38
+ readonly by: 'keys';
39
+ readonly field: string;
40
+ readonly direction: Direction;
41
+ readonly types: readonly {
42
+ readonly type: string;
43
+ readonly keys: readonly Uint8Array[];
44
+ }[];
45
+ } | {
46
+ readonly by: 'order';
47
+ readonly field: string;
48
+ readonly direction: Direction;
49
+ readonly types: readonly {
50
+ readonly type: string;
51
+ readonly runs: readonly WalkRun[];
52
+ }[];
53
+ };
54
+ export type Count = {
55
+ readonly walk: Walk;
56
+ readonly fields: readonly string[];
57
+ };
58
+ export type WalkedFacts = {
59
+ readonly path: string;
60
+ readonly type: string | null;
61
+ readonly fields: Readonly<Record<string, unknown>> | null;
62
+ };
63
+ export declare function pageOrder(plan: QueryPlan): PageOrder;
64
+ export declare function walkOf(plan: QueryPlan, model: VerifiedModel): Walk;
65
+ export declare function countShape(plan: QueryPlan): boolean;
66
+ export declare function countOf(plan: QueryPlan, model: VerifiedModel, where: unknown): Count | null;
67
+ export declare function walkedValue(definition: Definition, field: string, value: unknown): unknown;
68
+ export declare function hopTargets(plan: QueryPlan, model: VerifiedModel, row: WalkedFacts): string[];
69
+ //# sourceMappingURL=walk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../../src/query/walk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,UAAU,EAAmB,MAAM,kBAAkB,CAAC;AAEpG,OAAO,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CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAoBnD;AAwCD,wBAAgB,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,IAAI,CAqB3F;AAED,wBAAgB,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAG1F;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,WAAW,GAAG,MAAM,EAAE,CAO5F"}
@@ -0,0 +1,274 @@
1
+ import { escapePointer, pointerSegments } from '../definition.js';
2
+ import { byCodePoint, indexKey, instantOf, sortedKey } from '../kinds.js';
3
+ import { definitionAt } from '../validate.js';
4
+ import { plain } from '../yaml.js';
5
+ import { invalid, textless, } from './language.js';
6
+ import { indexed, placedIn } from './rows.js';
7
+ function keyOrder(left, right) {
8
+ for (let at = 0; at < Math.min(left.length, right.length); at += 1) {
9
+ if (left[at] !== right[at])
10
+ return left[at] - right[at];
11
+ }
12
+ return left.length - right.length;
13
+ }
14
+ function tighter(held, bound, sign) {
15
+ if (held === null)
16
+ return bound;
17
+ const order = sign * keyOrder(bound.key, held.key);
18
+ return order > 0 || (order === 0 && !bound.inclusive) ? bound : held;
19
+ }
20
+ function everyValue(facts) {
21
+ return { lower: { key: indexKey(facts, null), inclusive: false }, upper: null };
22
+ }
23
+ function rangeOf(facts, bounds) {
24
+ let { lower } = everyValue(facts);
25
+ let upper = null;
26
+ for (const [operator, value] of bounds) {
27
+ const bound = { key: indexKey(facts, value), inclusive: operator.endsWith('e') };
28
+ if (operator.startsWith('g'))
29
+ lower = tighter(lower, bound, 1);
30
+ else
31
+ upper = tighter(upper, bound, -1);
32
+ }
33
+ return { lower, upper };
34
+ }
35
+ function distinct(keys) {
36
+ return [...new Map(keys.map((key) => [key.join(','), key])).values()];
37
+ }
38
+ function testedKeys(facts, test) {
39
+ if (test.op === 'eq')
40
+ return { keys: [indexKey(facts, test.value)] };
41
+ if (test.op === 'in')
42
+ return { keys: distinct(test.values.map((value) => indexKey(facts, value))) };
43
+ if (test.op === 'range')
44
+ return { range: rangeOf(facts, test.bounds) };
45
+ return null;
46
+ }
47
+ function conjuncts(where) {
48
+ if (where === null || 'some' in where)
49
+ return [];
50
+ return 'every' in where ? where.every.flatMap(conjuncts) : [where];
51
+ }
52
+ function named(pointer) {
53
+ const segments = pointerSegments(pointer);
54
+ return segments.length === 1 ? segments[0] : null;
55
+ }
56
+ function indexing(model, types, field) {
57
+ const definitions = types.map((type) => Object.hasOwn(model.types, type) ? model.types[type] : null);
58
+ return definitions.every((definition) => definition?.indexed?.includes(field) === true)
59
+ ? definitions
60
+ : null;
61
+ }
62
+ function afterOf(plan) {
63
+ const values = plan.after?.values ?? null;
64
+ if (values === null)
65
+ return null;
66
+ const key = sortedKey(values[0]);
67
+ if (key === null)
68
+ invalid('after', 'expects the next an earlier result of this query returned');
69
+ return { key, tie: values[1] };
70
+ }
71
+ export function pageOrder(plan) {
72
+ if (plan.shape.kind !== 'documents')
73
+ return invalid('groupBy', 'a page answers Documents');
74
+ const [term, second] = plan.shape.orderBy;
75
+ if (second !== undefined)
76
+ invalid(['orderBy', 1], 'a page orders by one term');
77
+ if (term === undefined)
78
+ return { by: 'path', direction: 'asc' };
79
+ const { key, options } = term;
80
+ if (key.of === 'path') {
81
+ if (options.stringSort !== 'lexical')
82
+ invalid(['orderBy', 0, 'stringSort'], 'a page orders Paths by code point, as lexical');
83
+ return { by: 'path', direction: options.direction };
84
+ }
85
+ const field = key.of === 'field' ? named(key.field) : null;
86
+ if (field === null)
87
+ return invalid(['orderBy', 0, 'by'], 'a page orders by Path or by a field its types index');
88
+ if (plan.root.types === null)
89
+ invalid('types', 'an order by a field names the types whose index it walks');
90
+ return {
91
+ by: 'field',
92
+ field,
93
+ direction: options.direction,
94
+ nulls: options.nulls ?? 'first',
95
+ lexical: options.stringSort === 'lexical',
96
+ after: afterOf(plan),
97
+ };
98
+ }
99
+ function keysWalk(plan, model, direction) {
100
+ const types = plan.root.types;
101
+ for (const { field: pointer, test } of conjuncts(plan.root.where)) {
102
+ const field = named(pointer);
103
+ if (types === null || field === null || (test.op !== 'eq' && test.op !== 'in'))
104
+ continue;
105
+ const definitions = indexing(model, types, field);
106
+ if (definitions === null)
107
+ continue;
108
+ return {
109
+ by: 'keys',
110
+ field,
111
+ direction,
112
+ types: definitions.map((definition) => ({
113
+ type: definition.name,
114
+ keys: testedKeys(definition.fields[field], test).keys,
115
+ })),
116
+ };
117
+ }
118
+ return { by: 'path', direction };
119
+ }
120
+ function common(types) {
121
+ const [first, ...rest] = types;
122
+ return (first?.indexed ?? [])
123
+ .filter((field) => rest.every((definition) => definition.indexed?.includes(field)))
124
+ .map((field) => `/${escapePointer(field)}`);
125
+ }
126
+ function ranged(facts, tests) {
127
+ if (tests.length === 0)
128
+ return null;
129
+ return tests
130
+ .map(({ test }) => testedKeys(facts, test).range)
131
+ .reduce((held, range) => ({
132
+ lower: tighter(held.lower, range.lower, 1),
133
+ upper: range.upper === null ? held.upper : tighter(held.upper, range.upper, -1),
134
+ }));
135
+ }
136
+ function past(range, key, direction) {
137
+ const beyond = { key, inclusive: false };
138
+ return direction === 'asc'
139
+ ? { ...range, lower: tighter(range.lower, beyond, 1) }
140
+ : { ...range, upper: tighter(range.upper, beyond, -1) };
141
+ }
142
+ function runsOf(facts, order, range) {
143
+ const missing = indexKey(facts, null);
144
+ const cursor = order.after?.key ?? null;
145
+ const amongNulls = cursor !== null && keyOrder(cursor, missing) === 0;
146
+ const nulls = range === null ? [{ by: 'key', key: missing, after: amongNulls }] : [];
147
+ const span = range ?? everyValue(facts);
148
+ if (cursor === null || amongNulls) {
149
+ if (order.nulls === 'first')
150
+ return [...nulls, { by: 'range', range: span }];
151
+ return amongNulls ? nulls : [{ by: 'range', range: span }, ...nulls];
152
+ }
153
+ const values = [
154
+ { by: 'key', key: cursor, after: true },
155
+ { by: 'range', range: past(span, cursor, order.direction) },
156
+ ];
157
+ return order.nulls === 'first' ? values : [...values, ...nulls];
158
+ }
159
+ function unindexed(model, types, at, problem) {
160
+ const declared = types.flatMap((type) => Object.hasOwn(model.types, type) ? [model.types[type]] : []);
161
+ return invalid(at, problem, declared.length === types.length ? common(declared) : []);
162
+ }
163
+ export function walkOf(plan, model) {
164
+ const order = pageOrder(plan);
165
+ if (order.by === 'path')
166
+ return keysWalk(plan, model, order.direction);
167
+ const types = plan.root.types;
168
+ const definitions = indexing(model, types, order.field);
169
+ if (definitions === null)
170
+ return unindexed(model, types, ['orderBy', 0, 'by'], 'orders by a field every type it names indexes');
171
+ if (!order.lexical &&
172
+ definitions.some((definition) => !textless(definition.fields[order.field])))
173
+ invalid(['orderBy', 0, 'stringSort'], 'a page orders text by code point, as lexical');
174
+ const bounding = conjuncts(plan.root.where).filter(({ field, test }) => test.op === 'range' && named(field) === order.field);
175
+ return {
176
+ by: 'order',
177
+ field: order.field,
178
+ direction: order.direction,
179
+ types: definitions.map((definition) => {
180
+ const facts = definition.fields[order.field];
181
+ return { type: definition.name, runs: runsOf(facts, order, ranged(facts, bounding)) };
182
+ }),
183
+ };
184
+ }
185
+ export function countShape(plan) {
186
+ const { shape } = plan;
187
+ if (shape.kind === 'documents' && !plan.total)
188
+ return false;
189
+ if (plan.root.types === null)
190
+ invalid('types', 'a count names the types whose index it reads');
191
+ if (plan.text !== null)
192
+ invalid('text', 'a count tests no text');
193
+ if (plan.hop !== null)
194
+ invalid('hop', 'a count tests no hop');
195
+ if (shape.kind === 'documents')
196
+ return true;
197
+ if (plan.total)
198
+ invalid('total', 'a page of groups answers no total');
199
+ const key = shape.groupBy[0];
200
+ if (shape.groupBy.length > 1)
201
+ invalid(['groupBy', 1], 'a page groups by one field');
202
+ if (key.of !== 'field' || named(key.field) === null)
203
+ invalid(['groupBy', 0], 'a page groups by a field its types index');
204
+ for (const part of ['size', 'updated', 'greatest'])
205
+ if (shape[part] !== false && shape[part] !== null)
206
+ invalid(['select', part], 'a group selects only its count');
207
+ shape.orderBy.forEach(({ by }, index) => {
208
+ if (typeof by === 'string' && by !== 'count')
209
+ invalid(['orderBy', index, 'by'], 'a page of groups orders by its count or its key');
210
+ });
211
+ return true;
212
+ }
213
+ function testedPlaces(where, at) {
214
+ if (!plain(where))
215
+ return [];
216
+ return Object.keys(where)
217
+ .sort()
218
+ .flatMap((name) => name === '$and' || name === '$or'
219
+ ? where[name].flatMap((part, index) => testedPlaces(part, [...at, name, index]))
220
+ : [{ pointer: name, place: [...at, name] }]);
221
+ }
222
+ function countWalk(plan, model) {
223
+ const keyed = keysWalk(plan, model, 'asc');
224
+ if (keyed.by !== 'path')
225
+ return keyed;
226
+ const tests = conjuncts(plan.root.where);
227
+ for (const { field: pointer, test } of tests) {
228
+ const field = named(pointer);
229
+ if (test.op !== 'range' || field === null)
230
+ continue;
231
+ const definitions = indexing(model, plan.root.types, field);
232
+ if (definitions === null)
233
+ continue;
234
+ const bounding = tests.filter((bounded) => bounded.test.op === 'range' && bounded.field === pointer);
235
+ return {
236
+ by: 'order',
237
+ field,
238
+ direction: 'asc',
239
+ types: definitions.map((definition) => ({
240
+ type: definition.name,
241
+ runs: [{ by: 'range', range: ranged(definition.fields[field], bounding) }],
242
+ })),
243
+ };
244
+ }
245
+ return keyed;
246
+ }
247
+ export function countOf(plan, model, where) {
248
+ if (!countShape(plan))
249
+ return null;
250
+ const types = plan.root.types;
251
+ const grouped = plan.shape.kind === 'groups'
252
+ ? [{ pointer: plan.shape.groupBy[0].field, place: ['groupBy', 0] }]
253
+ : [];
254
+ const fields = [...grouped, ...testedPlaces(where, ['where'])].map(({ pointer, place }) => {
255
+ const field = named(pointer);
256
+ if (field === null || indexing(model, types, field) === null)
257
+ return unindexed(model, types, place, place[0] === 'groupBy'
258
+ ? 'groups by a field every type it names indexes'
259
+ : 'a count tests only fields every type it names indexes');
260
+ return field;
261
+ });
262
+ return { walk: countWalk(plan, model), fields: [...new Set(fields)].sort() };
263
+ }
264
+ export function walkedValue(definition, field, value) {
265
+ const instant = instantOf(definition.fields[field], value);
266
+ return instant === null ? (value ?? null) : { instant };
267
+ }
268
+ export function hopTargets(plan, model, row) {
269
+ if (plan.hop === null || row.type === null || row.fields === null)
270
+ return [];
271
+ const definition = definitionAt(model, row.path)(row.type);
272
+ const { links } = indexed(row.path, row.fields, definition);
273
+ return [...new Set(placedIn(links, plan.hop.field, 'link').map(({ target }) => target))].sort(byCodePoint);
274
+ }
@@ -1,4 +1,4 @@
1
1
  import { type Definition } from './definition.js';
2
- import type { Frontmatter, Reference } from './types.js';
3
- export declare function references(document: Pick<Frontmatter, 'fields'>, definition: Definition): readonly Reference[];
2
+ import type { Document, Reference } from './types.js';
3
+ export declare function references(document: Pick<Document, 'fields'>, definition: Definition): readonly Reference[];
4
4
  //# sourceMappingURL=references.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,UAAU,EAEhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA8BzD,wBAAgB,UAAU,CACxB,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,EACrC,UAAU,EAAE,UAAU,GACrB,SAAS,SAAS,EAAE,CAItB"}
1
+ {"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,UAAU,EAEhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA8BtD,wBAAgB,UAAU,CACxB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAClC,UAAU,EAAE,UAAU,GACrB,SAAS,SAAS,EAAE,CAItB"}
@@ -25,6 +25,6 @@ function collect(value, facts, pointer, found) {
25
25
  }
26
26
  export function references(document, definition) {
27
27
  const found = [];
28
- collect(document.fields, definition.frontmatter, '', found);
28
+ collect(document.fields, definition.root, '', found);
29
29
  return found;
30
30
  }
package/dist/refuse.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { Refusal } from './types.js';
2
2
  export declare function refusal(file: string, rule: string, extra?: {
3
3
  location?: string;
4
+ line?: number;
4
5
  referrers?: readonly string[];
5
6
  }): Refusal;
6
7
  //# sourceMappingURL=refuse.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"refuse.d.ts","sourceRoot":"","sources":["../src/refuse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,wBAAgB,OAAO,CACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAC3D,OAAO,CAOT"}
1
+ {"version":3,"file":"refuse.d.ts","sourceRoot":"","sources":["../src/refuse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,wBAAgB,OAAO,CACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAC1E,OAAO,CAQT"}
package/dist/refuse.js CHANGED
@@ -3,6 +3,7 @@ export function refusal(file, rule, extra) {
3
3
  file,
4
4
  rule,
5
5
  ...(extra?.location === undefined ? {} : { location: extra.location }),
6
+ ...(extra?.line === undefined ? {} : { line: extra.line }),
6
7
  ...(extra?.referrers === undefined ? {} : { referrers: extra.referrers }),
7
8
  };
8
9
  }
@@ -1,6 +1,7 @@
1
1
  export declare const ROOM_DESCRIPTION = "ROOM.md";
2
2
  export declare const CAPTURE_HOME = "capture";
3
3
  export declare const RESERVED_NAMES: readonly string[];
4
+ export declare function foldedName(name: string): string;
4
5
  export declare function isReservedName(name: string): boolean;
5
6
  export declare function isDocumentPath(path: string): boolean;
6
7
  //# sourceMappingURL=reserved.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reserved.d.ts","sourceRoot":"","sources":["../src/reserved.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAE1C,eAAO,MAAM,YAAY,YAAY,CAAC;AAEtC,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAO3C,CAAC;AAQF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGpD"}
1
+ {"version":3,"file":"reserved.d.ts","sourceRoot":"","sources":["../src/reserved.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAE1C,eAAO,MAAM,YAAY,YAAY,CAAC;AAEtC,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAO3C,CAAC;AAYF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI/C;AAID,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGpD"}
package/dist/reserved.js CHANGED
@@ -8,12 +8,23 @@ export const RESERVED_NAMES = [
8
8
  'agents',
9
9
  'house',
10
10
  ];
11
- function folded(name) {
12
- return name.replace(/[A-Z]/g, (letter) => letter.toLowerCase());
11
+ const DOTLESS_I = 'ı';
12
+ const CHEROKEE_SMALL = /[\u13F8-\u13FD\uAB70-\uABBF]/u;
13
+ function foldedPoint(point) {
14
+ if (point === DOTLESS_I)
15
+ return point;
16
+ const folded = point.toLowerCase().toUpperCase().toLowerCase();
17
+ return CHEROKEE_SMALL.test(folded) ? folded.toUpperCase() : folded;
13
18
  }
14
- const FOLDED_RESERVED_NAMES = new Set(RESERVED_NAMES.map(folded));
19
+ export function foldedName(name) {
20
+ let folded = '';
21
+ for (const point of name.normalize('NFC'))
22
+ folded += foldedPoint(point);
23
+ return folded.normalize('NFC');
24
+ }
25
+ const FOLDED_RESERVED_NAMES = new Set(RESERVED_NAMES.map(foldedName));
15
26
  export function isReservedName(name) {
16
- return FOLDED_RESERVED_NAMES.has(folded(name));
27
+ return FOLDED_RESERVED_NAMES.has(foldedName(name));
17
28
  }
18
29
  export function isDocumentPath(path) {
19
30
  const first = path.split('/', 1)[0];
@@ -0,0 +1,8 @@
1
+ export declare const CHAT_TYPE = "chat";
2
+ export declare const CHAT_MESSAGE_TYPE = "chat-message";
3
+ export declare const INBOX_TYPES: readonly string[];
4
+ export declare const INBOX_CHANNEL_KINDS: readonly ['telegram-bot', 'telegram-business', 'whatsapp', 'messenger', 'instagram', 'tiktok', 'viber'];
5
+ export type InboxChannelKind = (typeof INBOX_CHANNEL_KINDS)[number];
6
+ export declare const VIEW_TYPE = "view";
7
+ export declare const ROOM_TYPES_TEXT: string;
8
+ //# sourceMappingURL=room-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"room-types.d.ts","sourceRoot":"","sources":["../src/room-types.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,SAAS,CAAC;AAEhC,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAEhD,eAAO,MAAM,WAAW,EAAE,SAAS,MAAM,EAAmC,CAAC;AAE7E,eAAO,MAAM,mBAAmB,YAC9B,cAAc,EACd,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,WAAW,EACX,QAAQ,EACR,OAAO,CACC,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAMpE,eAAO,MAAM,SAAS,SAAS,CAAC;AA8BhC,eAAO,MAAM,eAAe,QAuGhB,CAAC"}