@agentshouse/mdmodel 0.1.0-ccf1367190878 → 0.1.0-cd1d3e3874c43

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 (458) hide show
  1. package/API.md +283 -276
  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 +233 -89
  12. package/dist/document.d.ts +16 -9
  13. package/dist/document.d.ts.map +1 -1
  14. package/dist/document.js +1000 -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 +7 -0
  88. package/dist/room-types.d.ts.map +1 -0
  89. package/dist/room-types.js +137 -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 +42 -34
  94. package/dist/types.d.ts.map +1 -1
  95. package/dist/validate.d.ts +34 -4
  96. package/dist/validate.d.ts.map +1 -1
  97. package/dist/validate.js +349 -152
  98. package/dist/yaml.d.ts +7 -5
  99. package/dist/yaml.d.ts.map +1 -1
  100. package/dist/yaml.js +190 -43
  101. package/fixtures/README.md +93 -65
  102. package/fixtures/cases/absent-link-dangles/library/item.md +1 -1
  103. package/fixtures/cases/absent-link-dangles/schema.yaml +2 -3
  104. package/fixtures/cases/absent-optional-field/library/companies/acme.md +1 -1
  105. package/fixtures/cases/absent-optional-field/library/deals/lead.md +3 -3
  106. package/fixtures/cases/absent-optional-field/schema.yaml +10 -11
  107. package/fixtures/cases/absolute-link/library/item.md +1 -1
  108. package/fixtures/cases/absolute-link/schema.yaml +2 -3
  109. package/fixtures/cases/attachment-reference-any-file/library/companies/acme.md +1 -1
  110. package/fixtures/cases/attachment-reference-any-file/library/deals/renewal.md +13 -10
  111. package/fixtures/cases/attachment-reference-any-file/library/places/depot.md +1 -1
  112. package/fixtures/cases/attachment-reference-any-file/library/products/seats.md +1 -1
  113. package/fixtures/cases/attachment-reference-any-file/library/products/support.md +1 -1
  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-outside/expected.json +2 -1
  120. package/fixtures/cases/attachment-reference-outside/library/companies/acme.md +1 -1
  121. package/fixtures/cases/attachment-reference-outside/library/deals/renewal.md +13 -10
  122. package/fixtures/cases/attachment-reference-outside/library/places/depot.md +1 -1
  123. package/fixtures/cases/attachment-reference-outside/library/products/seats.md +1 -1
  124. package/fixtures/cases/attachment-reference-outside/library/products/support.md +1 -1
  125. package/fixtures/cases/binary-any-reference/expected.json +2 -1
  126. package/fixtures/cases/binary-any-reference/library/notes/draft.md +1 -1
  127. package/fixtures/cases/binary-prototype-reference/expected.json +2 -1
  128. package/fixtures/cases/binary-prototype-reference/library/notes/draft.md +1 -1
  129. package/fixtures/cases/binary-typed-reference/expected.json +2 -1
  130. package/fixtures/cases/binary-typed-reference/library/notes/draft.md +1 -1
  131. package/fixtures/cases/block-scalar-frontmatter/library/notes/literal.md +17 -0
  132. package/fixtures/cases/block-scalar-frontmatter/library/skills/notes/SKILL.md +10 -0
  133. package/fixtures/cases/boolean-field/expected.json +2 -1
  134. package/fixtures/cases/boolean-field/library/companies/acme.md +1 -1
  135. package/fixtures/cases/boolean-field/library/deals/renewal.md +49 -24
  136. package/fixtures/cases/boolean-field/schema.yaml +10 -11
  137. package/fixtures/cases/bracketed-link-definition/library/item.md +1 -1
  138. package/fixtures/cases/bracketed-link-definition/schema.yaml +2 -3
  139. package/fixtures/cases/closed-nested-object/expected.json +2 -1
  140. package/fixtures/cases/closed-nested-object/library/companies/acme.md +1 -1
  141. package/fixtures/cases/closed-nested-object/library/deals/renewal.md +50 -25
  142. package/fixtures/cases/closed-nested-object/schema.yaml +10 -11
  143. package/fixtures/cases/composed-root-reference/library/a.md +2 -2
  144. package/fixtures/cases/conditional-long-text/expected.json +7 -0
  145. package/fixtures/cases/conditional-long-text/library/questions/hosting.md +9 -0
  146. package/fixtures/cases/conditional-long-text/library/questions/payments.md +12 -0
  147. package/fixtures/cases/conditional-long-text/schema.yaml +13 -0
  148. package/fixtures/cases/cross-room-link/expected.json +1 -0
  149. package/fixtures/cases/cross-room-link/library/clients/acme.md +6 -0
  150. package/fixtures/cases/cross-room-link/schema.yaml +3 -0
  151. package/fixtures/cases/cross-room-reference/expected.json +1 -0
  152. package/fixtures/cases/cross-room-reference/library/clients/acme.md +9 -0
  153. package/fixtures/cases/cross-room-reference/schema.yaml +8 -0
  154. package/fixtures/cases/date-time-format/expected.json +2 -1
  155. package/fixtures/cases/date-time-format/library/companies/acme.md +1 -1
  156. package/fixtures/cases/date-time-format/library/deals/renewal.md +49 -24
  157. package/fixtures/cases/date-time-format/schema.yaml +10 -11
  158. package/fixtures/cases/default-unfilled/library/companies/acme.md +1 -1
  159. package/fixtures/cases/default-unfilled/library/deals/renewal.md +47 -22
  160. package/fixtures/cases/default-unfilled/schema.yaml +10 -11
  161. package/fixtures/cases/defs-pattern/expected.json +2 -1
  162. package/fixtures/cases/defs-pattern/library/companies/acme.md +1 -1
  163. package/fixtures/cases/defs-pattern/library/deals/renewal.md +49 -24
  164. package/fixtures/cases/defs-pattern/schema.yaml +10 -11
  165. package/fixtures/cases/dependent-rule/library/companies/acme.md +1 -1
  166. package/fixtures/cases/dependent-rule/library/deals/renewal.md +48 -23
  167. package/fixtures/cases/dependent-rule/schema.yaml +10 -11
  168. package/fixtures/cases/duplicate-link-definition/library/item.md +1 -1
  169. package/fixtures/cases/duplicate-link-definition/schema.yaml +2 -3
  170. package/fixtures/cases/email-format/expected.json +2 -1
  171. package/fixtures/cases/email-format/library/companies/acme.md +1 -1
  172. package/fixtures/cases/email-format/library/deals/renewal.md +49 -24
  173. package/fixtures/cases/email-format/schema.yaml +10 -11
  174. package/fixtures/cases/equal-labels/expected.json +5 -0
  175. package/fixtures/cases/equal-labels/schema.yaml +4 -0
  176. package/fixtures/cases/fenced-link-definition/library/item.md +1 -1
  177. package/fixtures/cases/fenced-link-definition/schema.yaml +2 -3
  178. package/fixtures/cases/field-enum/expected.json +2 -1
  179. package/fixtures/cases/field-enum/library/item.md +2 -2
  180. package/fixtures/cases/field-enum/schema.yaml +3 -4
  181. package/fixtures/cases/frontmatter-construct/expected.json +7 -0
  182. package/fixtures/cases/frontmatter-construct/library/note.md +6 -0
  183. package/fixtures/cases/integer-field/expected.json +2 -1
  184. package/fixtures/cases/integer-field/library/companies/acme.md +1 -1
  185. package/fixtures/cases/integer-field/library/deals/renewal.md +49 -24
  186. package/fixtures/cases/integer-field/schema.yaml +10 -11
  187. package/fixtures/cases/json-schema-constructs/library/companies/acme.md +1 -1
  188. package/fixtures/cases/json-schema-constructs/library/deals/renewal.md +49 -24
  189. package/fixtures/cases/json-schema-constructs/schema.yaml +10 -11
  190. package/fixtures/cases/labels-in-the-rooms-language/expected.json +1 -0
  191. package/fixtures/cases/labels-in-the-rooms-language/library/deals/atlas.md +7 -0
  192. package/fixtures/cases/labels-in-the-rooms-language/schema.yaml +9 -0
  193. package/fixtures/cases/lazy-list-item/expected.json +3 -0
  194. package/fixtures/cases/lazy-list-item/library/item.md +10 -0
  195. package/fixtures/cases/lazy-list-item/schema.yaml +3 -0
  196. package/fixtures/cases/link-into-a-reserved-name/context.json +1 -0
  197. package/fixtures/cases/link-into-a-reserved-name/expected.json +5 -0
  198. package/fixtures/cases/link-into-a-reserved-name/library/notes/a.md +6 -0
  199. package/fixtures/cases/link-into-a-reserved-name/schema.yaml +3 -0
  200. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/expected.json +5 -0
  201. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/library/notes/b.md +5 -0
  202. package/fixtures/cases/list-item-enum/context.json +1 -0
  203. package/fixtures/cases/list-item-enum/expected.json +7 -0
  204. package/fixtures/cases/list-item-enum/library/task.md +7 -0
  205. package/fixtures/cases/list-item-enum/schema.yaml +3 -0
  206. package/fixtures/cases/list-item-kind/context.json +1 -0
  207. package/fixtures/cases/list-item-kind/expected.json +7 -0
  208. package/fixtures/cases/list-item-kind/library/task.md +6 -0
  209. package/fixtures/cases/list-item-kind/schema.yaml +3 -0
  210. package/fixtures/cases/list-items/context.json +1 -0
  211. package/fixtures/cases/list-items/expected.json +1 -0
  212. package/fixtures/cases/list-items/library/page.md +26 -0
  213. package/fixtures/cases/list-items/schema.yaml +10 -0
  214. package/fixtures/cases/list-of-objects-closed/expected.json +2 -1
  215. package/fixtures/cases/list-of-objects-closed/library/companies/acme.md +1 -1
  216. package/fixtures/cases/list-of-objects-closed/library/deals/renewal.md +49 -25
  217. package/fixtures/cases/list-of-objects-closed/schema.yaml +10 -11
  218. package/fixtures/cases/list-of-objects-item/expected.json +2 -1
  219. package/fixtures/cases/list-of-objects-item/library/companies/acme.md +1 -1
  220. package/fixtures/cases/list-of-objects-item/library/deals/renewal.md +49 -24
  221. package/fixtures/cases/list-of-objects-item/schema.yaml +10 -11
  222. package/fixtures/cases/list-of-objects-reference/expected.json +2 -1
  223. package/fixtures/cases/list-of-objects-reference/library/companies/acme.md +1 -1
  224. package/fixtures/cases/list-of-objects-reference/library/deals/renewal.md +12 -9
  225. package/fixtures/cases/list-of-objects-reference/library/places/depot.md +1 -1
  226. package/fixtures/cases/list-of-objects-reference/library/products/seats.md +1 -1
  227. package/fixtures/cases/list-of-objects-reference/library/products/support.md +1 -1
  228. package/fixtures/cases/list-reference-path/context.json +1 -0
  229. package/fixtures/cases/list-reference-path/expected.json +7 -0
  230. package/fixtures/cases/list-reference-path/library/page.md +5 -0
  231. package/fixtures/cases/list-reference-path/schema.yaml +3 -0
  232. package/fixtures/cases/list-reference-type/context.json +1 -0
  233. package/fixtures/cases/list-reference-type/expected.json +7 -0
  234. package/fixtures/cases/list-reference-type/library/page.md +6 -0
  235. package/fixtures/cases/list-reference-type/schema.yaml +3 -0
  236. package/fixtures/cases/list-size/expected.json +2 -1
  237. package/fixtures/cases/list-size/library/companies/acme.md +1 -1
  238. package/fixtures/cases/list-size/library/deals/renewal.md +51 -24
  239. package/fixtures/cases/list-size/schema.yaml +10 -11
  240. package/fixtures/cases/long-value-past-six-levels/context.json +1 -0
  241. package/fixtures/cases/long-value-past-six-levels/expected.json +5 -0
  242. package/fixtures/cases/long-value-past-six-levels/schema.yaml +15 -0
  243. package/fixtures/cases/malformed-list/context.json +1 -0
  244. package/fixtures/cases/malformed-list/expected.json +7 -0
  245. package/fixtures/cases/{structured-section → malformed-list}/library/item.md +1 -1
  246. package/fixtures/cases/malformed-list/schema.yaml +6 -0
  247. package/fixtures/cases/member-document/library/people/ana.md +2 -2
  248. package/fixtures/cases/member-on-an-untyped-document/context.json +1 -0
  249. package/fixtures/cases/member-on-an-untyped-document/expected.json +6 -0
  250. package/fixtures/cases/member-on-an-untyped-document/library/note.md +4 -0
  251. package/fixtures/cases/member-on-another-type/context.json +1 -0
  252. package/fixtures/cases/member-on-another-type/expected.json +6 -0
  253. package/fixtures/cases/member-on-another-type/library/note.md +4 -0
  254. package/fixtures/cases/member-on-another-type/schema.yaml +7 -0
  255. package/fixtures/cases/missing-required-field/library/item.md +1 -1
  256. package/fixtures/cases/missing-required-field/schema.yaml +3 -4
  257. package/fixtures/cases/misspelled-key/expected.json +2 -1
  258. package/fixtures/cases/misspelled-key/library/companies/acme.md +1 -1
  259. package/fixtures/cases/misspelled-key/library/deals/renewal.md +50 -25
  260. package/fixtures/cases/misspelled-key/schema.yaml +10 -11
  261. package/fixtures/cases/name-not-a-string/context.json +1 -0
  262. package/fixtures/cases/name-not-a-string/expected.json +5 -0
  263. package/fixtures/cases/name-not-a-string/schema.yaml +5 -0
  264. package/fixtures/cases/nested-defs/expected.json +2 -1
  265. package/fixtures/cases/nested-defs/library/deal.md +3 -3
  266. package/fixtures/cases/nested-object-reference/expected.json +2 -1
  267. package/fixtures/cases/nested-object-reference/library/companies/acme.md +1 -1
  268. package/fixtures/cases/nested-object-reference/library/deals/renewal.md +12 -9
  269. package/fixtures/cases/nested-object-reference/library/places/depot.md +1 -1
  270. package/fixtures/cases/nested-object-reference/library/products/seats.md +1 -1
  271. package/fixtures/cases/nested-object-reference/library/products/support.md +1 -1
  272. package/fixtures/cases/nested-reference/library/companies/acme.md +1 -1
  273. package/fixtures/cases/nested-reference/library/deals/renewal.md +13 -10
  274. package/fixtures/cases/nested-reference/library/places/depot.md +1 -1
  275. package/fixtures/cases/nested-reference/library/products/seats.md +1 -1
  276. package/fixtures/cases/nested-reference/library/products/support.md +1 -1
  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.yaml +10 -11
  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.yaml +10 -11
  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.yaml +5 -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.yaml +4 -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.yaml +10 -11
  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/prototype-field/expected.json +2 -1
  302. package/fixtures/cases/prototype-field/library/item.md +2 -2
  303. package/fixtures/cases/prototype-field/schema.yaml +2 -3
  304. package/fixtures/cases/reference-into-a-reserved-name/context.json +1 -0
  305. package/fixtures/cases/reference-into-a-reserved-name/expected.json +7 -0
  306. package/fixtures/cases/reference-into-a-reserved-name/library/notes/a.md +4 -0
  307. package/fixtures/cases/reference-into-a-reserved-name/library/settings/brief.md +1 -0
  308. package/fixtures/cases/reference-into-a-reserved-name/schema.yaml +3 -0
  309. package/fixtures/cases/reference-to-any-file-name/context.json +1 -0
  310. package/fixtures/cases/reference-to-any-file-name/expected.json +1 -0
  311. package/fixtures/cases/reference-to-any-file-name/library/people/100%.md +4 -0
  312. package/fixtures/cases/reference-to-any-file-name/library/people/C#.md +4 -0
  313. package/fixtures/cases/reference-to-any-file-name/library/people/My notes.md +4 -0
  314. package/fixtures/cases/reference-to-any-file-name/library/people/[draft].md +4 -0
  315. package/fixtures/cases/reference-to-any-file-name/library/people/c (d).md +4 -0
  316. package/fixtures/cases/reference-to-any-file-name/library/people/caf/303/251.md +4 -0
  317. package/fixtures/cases/reference-to-any-file-name/library/people//320/236/321/202/321/207/321/221/321/202.md +4 -0
  318. package/fixtures/cases/reference-to-any-file-name/library/tasks/bracket.md +9 -0
  319. package/fixtures/cases/reference-to-any-file-name/library/tasks/cyrillic.md +9 -0
  320. package/fixtures/cases/reference-to-any-file-name/library/tasks/decomposed.md +9 -0
  321. package/fixtures/cases/reference-to-any-file-name/library/tasks/hash.md +9 -0
  322. package/fixtures/cases/reference-to-any-file-name/library/tasks/parenthesis.md +9 -0
  323. package/fixtures/cases/reference-to-any-file-name/library/tasks/percent.md +9 -0
  324. package/fixtures/cases/reference-to-any-file-name/library/tasks/spaced.md +9 -0
  325. package/fixtures/cases/reference-to-any-file-name/schema.yaml +10 -0
  326. package/fixtures/cases/referenced-missing-file/library/a.md +2 -2
  327. package/fixtures/cases/referenced-missing-file/library/b.md +2 -2
  328. package/fixtures/cases/referenced-missing-file/schema.yaml +3 -4
  329. package/fixtures/cases/referenced-missing-non-latin-file/context.json +1 -0
  330. package/fixtures/cases/referenced-missing-non-latin-file/expected.json +6 -0
  331. package/fixtures/cases/referenced-missing-non-latin-file/library/tasks/a.md +9 -0
  332. package/fixtures/cases/referenced-missing-non-latin-file/library/tasks/b.md +9 -0
  333. package/fixtures/cases/referenced-missing-non-latin-file/schema.yaml +10 -0
  334. package/fixtures/cases/room-md-declares-a-type/context.json +1 -0
  335. package/fixtures/cases/room-md-declares-a-type/expected.json +6 -0
  336. package/fixtures/cases/room-md-declares-a-type/library/ROOM.md +5 -0
  337. package/fixtures/cases/sections-keyword-refused/context.json +1 -0
  338. package/fixtures/cases/sections-keyword-refused/expected.json +5 -0
  339. package/fixtures/cases/{structured-section → sections-keyword-refused}/schema.yaml +1 -2
  340. package/fixtures/cases/shortcut-reference-link/library/item.md +1 -1
  341. package/fixtures/cases/shortcut-reference-link/schema.yaml +2 -3
  342. package/fixtures/cases/string-length/expected.json +2 -1
  343. package/fixtures/cases/string-length/library/companies/acme.md +1 -1
  344. package/fixtures/cases/string-length/library/deals/renewal.md +49 -24
  345. package/fixtures/cases/string-length/schema.yaml +10 -11
  346. package/fixtures/cases/submission-keys/library/notes/visitor.md +2 -2
  347. package/fixtures/cases/text-field-kind/expected.json +1 -4
  348. package/fixtures/cases/text-field-kind/library/page.md +1 -1
  349. package/fixtures/cases/thematic-break-ends-the-values/context.json +1 -0
  350. package/fixtures/cases/thematic-break-ends-the-values/expected.json +1 -0
  351. package/fixtures/cases/thematic-break-ends-the-values/library/item.md +10 -0
  352. package/fixtures/cases/thematic-break-ends-the-values/schema.yaml +3 -0
  353. package/fixtures/cases/typed-path-names-another-type/context.json +11 -0
  354. package/fixtures/cases/typed-path-names-another-type/expected.json +6 -0
  355. package/fixtures/cases/typed-path-names-another-type/library/settings/prefs/one.md +3 -0
  356. package/fixtures/cases/typed-path-names-another-type/schema.yaml +6 -0
  357. package/fixtures/cases/typed-path-names-its-type/context.json +11 -0
  358. package/fixtures/cases/typed-path-names-its-type/expected.json +3 -0
  359. package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/deeper/two.md +1 -0
  360. package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/one.md +4 -0
  361. package/fixtures/cases/typed-path-names-its-type/schema.yaml +6 -0
  362. package/fixtures/cases/typed-path-names-no-type/context.json +11 -0
  363. package/fixtures/cases/typed-path-names-no-type/expected.json +6 -0
  364. package/fixtures/cases/typed-path-names-no-type/library/settings/prefs/one.md +1 -0
  365. package/fixtures/cases/typed-path-names-no-type/schema.yaml +6 -0
  366. package/fixtures/cases/types-folder-content/library/types/task.md +1 -1
  367. package/fixtures/cases/undeclared-field/expected.json +2 -1
  368. package/fixtures/cases/undeclared-field/library/item.md +2 -2
  369. package/fixtures/cases/undeclared-field/schema.yaml +2 -3
  370. package/fixtures/cases/unevaluated-items-closed/expected.json +2 -1
  371. package/fixtures/cases/unevaluated-items-closed/library/trip.md +13 -3
  372. package/fixtures/cases/unnamed-typed-path-checks-its-fields/context.json +11 -0
  373. package/fixtures/cases/unnamed-typed-path-checks-its-fields/expected.json +6 -0
  374. package/fixtures/cases/unnamed-typed-path-checks-its-fields/library/rooms/team/tasks/plan.md +5 -0
  375. package/fixtures/cases/unnamed-typed-path-checks-its-fields/schema.yaml +5 -0
  376. package/fixtures/cases/unnamed-typed-path-names-a-type/context.json +11 -0
  377. package/fixtures/cases/unnamed-typed-path-names-a-type/expected.json +6 -0
  378. package/fixtures/cases/unnamed-typed-path-names-a-type/library/rooms/team/tasks/plan.md +7 -0
  379. package/fixtures/cases/unnamed-typed-path-names-a-type/schema.yaml +5 -0
  380. package/fixtures/cases/unnamed-typed-path-reads-its-type/context.json +11 -0
  381. package/fixtures/cases/unnamed-typed-path-reads-its-type/expected.json +3 -0
  382. package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/plan.md +1 -0
  383. package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/tasks/plan.md +6 -0
  384. package/fixtures/cases/unnamed-typed-path-reads-its-type/schema.yaml +5 -0
  385. package/fixtures/cases/unnamed-typed-path-without-a-body/context.json +11 -0
  386. package/fixtures/cases/unnamed-typed-path-without-a-body/expected.json +5 -0
  387. package/fixtures/cases/unnamed-typed-path-without-a-body/library/rooms/team/tasks/plan.md +5 -0
  388. package/fixtures/cases/unnamed-typed-path-without-a-body/schema.yaml +5 -0
  389. package/fixtures/cases/unresolved-link/library/item.md +1 -1
  390. package/fixtures/cases/unresolved-link/schema.yaml +2 -3
  391. package/fixtures/cases/valid-typed-document/library/people/ada.md +1 -1
  392. package/fixtures/cases/valid-typed-document/library/tasks/one.md +11 -11
  393. package/fixtures/cases/valid-typed-document/schema.yaml +5 -6
  394. package/fixtures/forms.json +371 -0
  395. package/fixtures/preamble.json +29 -8
  396. package/fixtures/queries.json +1562 -0
  397. package/package.json +16 -2
  398. package/dist/blocks.d.ts +0 -11
  399. package/dist/blocks.d.ts.map +0 -1
  400. package/dist/blocks.js +0 -76
  401. package/dist/condition.d.ts +0 -149
  402. package/dist/condition.d.ts.map +0 -1
  403. package/dist/condition.js +0 -500
  404. package/dist/divide.d.ts +0 -3
  405. package/dist/divide.d.ts.map +0 -1
  406. package/dist/divide.js +0 -310
  407. package/dist/links.d.ts +0 -27
  408. package/dist/links.d.ts.map +0 -1
  409. package/dist/links.js +0 -774
  410. package/dist/profile.d.ts +0 -6
  411. package/dist/profile.d.ts.map +0 -1
  412. package/dist/profile.js +0 -5
  413. package/dist/project.d.ts +0 -21
  414. package/dist/project.d.ts.map +0 -1
  415. package/dist/project.js +0 -105
  416. package/dist/sections.d.ts +0 -11
  417. package/dist/sections.d.ts.map +0 -1
  418. package/dist/sections.js +0 -57
  419. package/fixtures/cases/missing-section-item-kind/expected.json +0 -5
  420. package/fixtures/cases/missing-section-item-kind/schema.yaml +0 -6
  421. package/fixtures/cases/null-refused/expected.json +0 -6
  422. package/fixtures/cases/null-refused/library/companies/acme.md +0 -4
  423. package/fixtures/cases/null-refused/library/deals/renewal.md +0 -31
  424. package/fixtures/cases/null-refused/schema.yaml +0 -56
  425. package/fixtures/cases/open-map-value/expected.json +0 -6
  426. package/fixtures/cases/open-map-value/library/companies/acme.md +0 -4
  427. package/fixtures/cases/open-map-value/library/deals/renewal.md +0 -31
  428. package/fixtures/cases/open-map-value/schema.yaml +0 -56
  429. package/fixtures/cases/section-item-enum/expected.json +0 -6
  430. package/fixtures/cases/section-item-enum/library/task.md +0 -8
  431. package/fixtures/cases/section-item-enum/schema.yaml +0 -3
  432. package/fixtures/cases/section-item-kind/expected.json +0 -6
  433. package/fixtures/cases/section-item-kind/library/task.md +0 -8
  434. package/fixtures/cases/section-item-kind/schema.yaml +0 -3
  435. package/fixtures/cases/section-items/library/page.md +0 -42
  436. package/fixtures/cases/section-items/schema.yaml +0 -10
  437. package/fixtures/cases/section-reference-path/expected.json +0 -6
  438. package/fixtures/cases/section-reference-path/library/page.md +0 -7
  439. package/fixtures/cases/section-reference-path/schema.yaml +0 -3
  440. package/fixtures/cases/section-reference-type/expected.json +0 -6
  441. package/fixtures/cases/section-reference-type/library/page.md +0 -7
  442. package/fixtures/cases/section-reference-type/schema.yaml +0 -3
  443. package/fixtures/cases/structured-section/expected.json +0 -6
  444. package/fixtures/division.json +0 -409
  445. package/fixtures/projection.json +0 -255
  446. /package/fixtures/cases/{missing-section-item-kind → block-scalar-frontmatter}/context.json +0 -0
  447. /package/fixtures/cases/{section-items → block-scalar-frontmatter}/expected.json +0 -0
  448. /package/fixtures/cases/{null-refused → conditional-long-text}/context.json +0 -0
  449. /package/fixtures/cases/{open-map-value → cross-room-link}/context.json +0 -0
  450. /package/fixtures/cases/{section-item-enum → cross-room-reference}/context.json +0 -0
  451. /package/fixtures/cases/{section-item-kind → equal-labels}/context.json +0 -0
  452. /package/fixtures/cases/{section-items → frontmatter-construct}/context.json +0 -0
  453. /package/fixtures/cases/{section-reference-path → labels-in-the-rooms-language}/context.json +0 -0
  454. /package/fixtures/cases/{section-reference-type → lazy-list-item}/context.json +0 -0
  455. /package/fixtures/cases/{structured-section → link-into-a-reserved-name-from-an-untyped-document}/context.json +0 -0
  456. /package/fixtures/cases/{section-items → list-items}/library/other.md +0 -0
  457. /package/fixtures/cases/{section-reference-path → list-reference-path}/library/other.md +0 -0
  458. /package/fixtures/cases/{section-reference-type → list-reference-type}/library/note.md +0 -0
package/dist/condition.js DELETED
@@ -1,500 +0,0 @@
1
- import { ARRAY_INDEX, escapePointer, fieldFacts, itemFacts, memberFacts, pointerSegments, } from './definition.js';
2
- import { target } from './paths.js';
3
- import { isRecord, plain } from './yaml.js';
4
- export const WRITE_DOORS = ['browser', 'agent', 'client'];
5
- const PROSE = { kind: 'prose' };
6
- const NULL = { kind: 'null' };
7
- const UNREADABLE = { kind: 'unreadable' };
8
- const UNREAD = { present: undefined, values: [undefined], items: [undefined] };
9
- const NO_ITEM = { present: false, values: [], items: [] };
10
- const DATE = /^\d{4}-\d{2}-\d{2}$/u;
11
- const DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(?:[Zz]|([+-])(\d{2}):(\d{2}))$/u;
12
- export function factKind(facts) {
13
- if (facts.reference !== undefined)
14
- return 'reference';
15
- if (facts.values !== undefined)
16
- return 'enum';
17
- if (facts.type === 'number' || facts.type === 'integer')
18
- return 'number';
19
- if (facts.type === 'boolean')
20
- return 'boolean';
21
- if (facts.type !== 'string')
22
- return null;
23
- if (facts.format === 'date')
24
- return 'date';
25
- if (facts.format === 'date-time')
26
- return 'time';
27
- return 'string';
28
- }
29
- function fits(kind, facts, value) {
30
- if (!scalar(value))
31
- return false;
32
- if (kind === 'enum')
33
- return (facts.values ?? []).includes(value);
34
- if (kind === 'number')
35
- return typeof value === 'number';
36
- if (kind === 'boolean')
37
- return typeof value === 'boolean';
38
- if (typeof value !== 'string')
39
- return false;
40
- if (kind === 'date')
41
- return dated(value);
42
- if (kind === 'time')
43
- return instant(value) !== undefined;
44
- return true;
45
- }
46
- function factOf(value, declared, place) {
47
- if (value === null)
48
- return NULL;
49
- if (Array.isArray(value)) {
50
- if (declared?.type !== undefined && declared.type !== 'array')
51
- return UNREADABLE;
52
- return {
53
- kind: 'list',
54
- items: value.map((item, index) => factOf(item, declared === undefined ? undefined : itemFacts(declared, index), place)),
55
- };
56
- }
57
- if (plain(value)) {
58
- if (declared?.type !== undefined && declared.type !== 'object')
59
- return UNREADABLE;
60
- const fields = Object.create(null);
61
- for (const [key, held] of Object.entries(value))
62
- fields[key] = factOf(held, declared === undefined ? undefined : memberFacts(declared, key), place);
63
- return { kind: 'object', fields };
64
- }
65
- if (declared?.type === 'array' || declared?.type === 'object')
66
- return UNREADABLE;
67
- const kind = declared === undefined || declared.prose ? null : factKind(declared);
68
- if (kind === null)
69
- return PROSE;
70
- if (!fits(kind, declared, value))
71
- return UNREADABLE;
72
- if (kind !== 'reference')
73
- return { kind, value };
74
- const reached = target(place.path, value);
75
- const resolved = reached === null ? undefined : place.resolve(reached);
76
- if (resolved === undefined)
77
- return UNREADABLE;
78
- return resolved.member === undefined
79
- ? { kind, value: resolved.id }
80
- : { kind, value: resolved.id, member: resolved.member };
81
- }
82
- export function facts(document, at, model, resolve) {
83
- const type = document.type ?? null;
84
- const definition = type !== null && Object.hasOwn(model.types, type) ? model.types[type] : null;
85
- const fields = Object.create(null);
86
- const place = { path: at.path, resolve };
87
- for (const [name, value] of Object.entries(document.fields)) {
88
- const declared = definition === null ? undefined : fieldFacts(definition, name);
89
- if (declared !== undefined)
90
- fields[name] = factOf(value, declared, place);
91
- }
92
- return {
93
- id: at.id,
94
- path: `/${at.path}`,
95
- type,
96
- fields,
97
- sections: Object.keys(document.sections).sort(),
98
- };
99
- }
100
- function rootOf(facts, prefix) {
101
- return { pointer: prefix, fact: { kind: 'object', fields: facts.fields } };
102
- }
103
- export function prosePaths(facts) {
104
- const paths = facts.sections.map((heading) => `/sections/${heading}`);
105
- const visit = ({ pointer, fact }) => {
106
- if (fact.kind === 'prose')
107
- paths.push(pointer);
108
- if (fact.kind === 'list')
109
- fact.items.forEach((item, index) => visit({ pointer: `${pointer}/${index}`, fact: item }));
110
- if (fact.kind === 'object')
111
- for (const [key, held] of Object.entries(fact.fields))
112
- visit({ pointer: `${pointer}/${escapePointer(key)}`, fact: held });
113
- };
114
- visit(rootOf(facts, '/fields'));
115
- return paths.sort();
116
- }
117
- function walked(start, pointer) {
118
- let reached = [start];
119
- let several = false;
120
- let missing = false;
121
- const each = (from, next) => from.flatMap((one) => {
122
- const found = next(one);
123
- if (found === null)
124
- missing = true;
125
- return found ?? [];
126
- });
127
- for (const token of pointerSegments(pointer)) {
128
- const step = ({ pointer: at, fact }) => {
129
- if (fact.kind === 'unreadable')
130
- return [{ pointer: at, fact }];
131
- if (fact.kind === 'object')
132
- return Object.hasOwn(fact.fields, token)
133
- ? [{ pointer: `${at}/${escapePointer(token)}`, fact: fact.fields[token] }]
134
- : null;
135
- if (fact.kind !== 'list')
136
- return null;
137
- if (ARRAY_INDEX.test(token)) {
138
- const item = fact.items[Number(token)];
139
- return item === undefined ? null : [{ pointer: `${at}/${token}`, fact: item }];
140
- }
141
- several = true;
142
- return each(fact.items.map((item, index) => ({ pointer: `${at}/${index}`, fact: item })), step);
143
- };
144
- reached = each(reached, step);
145
- }
146
- return { reached, several, missing };
147
- }
148
- function expand(fact) {
149
- return fact.kind === 'list' ? fact.items.flatMap(expand) : [fact];
150
- }
151
- function fieldHeld(fact) {
152
- if (fact.kind === 'unreadable')
153
- return undefined;
154
- if (fact.kind === 'null')
155
- return { kind: 'null' };
156
- return 'value' in fact ? { kind: fact.kind, value: fact.value } : { kind: 'prose' };
157
- }
158
- function memberHeld(fact) {
159
- if (fact.kind === 'unreadable')
160
- return undefined;
161
- return fact.kind === 'reference' && fact.member !== undefined
162
- ? { kind: 'member', value: fact.member }
163
- : null;
164
- }
165
- function single(held) {
166
- return { present: true, values: [held], items: null };
167
- }
168
- function documentRead({ reached, several, missing }, held) {
169
- if (reached.length === 0)
170
- return missing ? undefined : NO_ITEM;
171
- const facts = reached.map(({ fact }) => fact);
172
- const kept = (all) => all.map(held).filter((value) => value !== null);
173
- const unknown = missing ? [undefined] : [];
174
- const values = kept(facts.filter((fact) => fact.kind !== 'list'));
175
- const listed = several || facts.some((fact) => fact.kind === 'list');
176
- const present = facts.some((fact) => fact.kind === 'list') || values.some(Boolean);
177
- return {
178
- present: present ? true : values.length > 0 ? undefined : false,
179
- values: [...values, ...unknown],
180
- items: listed ? [...kept(facts.flatMap(expand)), ...unknown] : null,
181
- };
182
- }
183
- function readDocument(facts, path) {
184
- if (path === '/path')
185
- return single({ kind: 'path', value: facts.path });
186
- if (path === '/type')
187
- return facts.type === null ? undefined : single({ kind: 'string', value: facts.type });
188
- if (path.startsWith('/sections/'))
189
- return facts.sections.includes(path.slice('/sections/'.length))
190
- ? single({ kind: 'prose' })
191
- : undefined;
192
- if (path.startsWith('/fields/'))
193
- return documentRead(walked(rootOf(facts, '/fields'), path.slice('/fields'.length)), fieldHeld);
194
- if (path.startsWith('/members/'))
195
- return documentRead(walked(rootOf(facts, '/members'), path.slice('/members'.length)), memberHeld);
196
- return undefined;
197
- }
198
- function readActor(actor, path) {
199
- const value = path === '/user'
200
- ? actor.user
201
- : path === '/site'
202
- ? actor.site
203
- : path === '/door'
204
- ? actor.door
205
- : undefined;
206
- return value === undefined ? undefined : single({ kind: 'actor', value });
207
- }
208
- export function datePointers(fields) {
209
- return Object.entries(fields)
210
- .filter(([, facts]) => facts.type === 'string' && facts.format === 'date')
211
- .map(([name]) => `/fields/${name}`)
212
- .sort();
213
- }
214
- export function dated(value) {
215
- return (typeof value === 'string' && DATE.test(value) && instant(`${value}T00:00:00Z`) !== undefined);
216
- }
217
- export function instant(value) {
218
- if (typeof value !== 'string')
219
- return undefined;
220
- const parts = DATE_TIME.exec(value);
221
- if (parts === null)
222
- return undefined;
223
- const [year, month, day, hour, minute, second, offsetHours, offsetMinutes] = [
224
- 1, 2, 3, 4, 5, 6, 9, 10,
225
- ].map((at) => Number(parts[at] ?? 0));
226
- const at = new Date(0);
227
- at.setUTCFullYear(year, month - 1, day);
228
- at.setUTCHours(hour, minute, second);
229
- if (at.getUTCFullYear() !== year ||
230
- at.getUTCMonth() !== month - 1 ||
231
- at.getUTCDate() !== day ||
232
- at.getUTCHours() !== hour ||
233
- at.getUTCMinutes() !== minute ||
234
- offsetHours > 23 ||
235
- offsetMinutes > 59)
236
- return undefined;
237
- const offset = (parts[8] === '-' ? -1 : 1) * (offsetHours * 60 + offsetMinutes);
238
- const fraction = (parts[7] ?? '').padEnd(9, '0').slice(0, 9);
239
- return (BigInt(at.getTime()) - BigInt(offset) * 60000n) * 1000000n + BigInt(fraction);
240
- }
241
- export function pointed(value, pointer) {
242
- if (pointer === '')
243
- return value;
244
- let reached = value;
245
- for (const part of pointer.slice(1).split('/')) {
246
- const token = part.replaceAll('~1', '/').replaceAll('~0', '~');
247
- if (Array.isArray(reached)) {
248
- if (!ARRAY_INDEX.test(token))
249
- return undefined;
250
- reached = reached[Number(token)];
251
- }
252
- else if (plain(reached) && Object.hasOwn(reached, token)) {
253
- reached = reached[token];
254
- }
255
- else {
256
- return undefined;
257
- }
258
- }
259
- return reached;
260
- }
261
- function scalar(value) {
262
- return (typeof value === 'string' ||
263
- typeof value === 'boolean' ||
264
- (typeof value === 'number' && Number.isFinite(value)));
265
- }
266
- function jsonHeld(value) {
267
- if (typeof value === 'string')
268
- return {
269
- kind: dated(value) ? 'date' : instant(value) === undefined ? 'string' : 'time',
270
- value,
271
- };
272
- if (typeof value === 'boolean')
273
- return { kind: 'boolean', value };
274
- return { kind: 'number', value };
275
- }
276
- function jsonRead(value) {
277
- if (value === undefined)
278
- return undefined;
279
- if (scalar(value))
280
- return single(jsonHeld(value));
281
- if (!Array.isArray(value))
282
- return single({ kind: 'prose' });
283
- return { present: true, values: [], items: value.filter(scalar).map(jsonHeld), loose: true };
284
- }
285
- function readItem(item, path) {
286
- if (path.startsWith('/json/')) {
287
- if (item.json === null)
288
- return UNREAD;
289
- return jsonRead(pointed(item.json.value, path.slice('/json'.length)));
290
- }
291
- if (path.startsWith('/headers/')) {
292
- const name = path.slice('/headers/'.length);
293
- return Object.hasOwn(item.headers, name)
294
- ? single({ kind: 'string', value: item.headers[name] })
295
- : undefined;
296
- }
297
- if (path === '/has_attachment')
298
- return single({ kind: 'boolean', value: item.has_attachment });
299
- const value = path === '/delivery'
300
- ? item.delivery
301
- : path === '/source'
302
- ? item.source
303
- : path === '/container'
304
- ? item.container
305
- : path === '/author'
306
- ? item.author
307
- : null;
308
- return value === null ? undefined : single({ kind: 'string', value });
309
- }
310
- function wanted(value, owner) {
311
- return isRecord(value) && value.owner === true ? owner : value;
312
- }
313
- function equal(held, value, owner) {
314
- if (!('value' in held))
315
- return undefined;
316
- const expected = wanted(value, owner);
317
- if (typeof expected !== typeof held.value)
318
- return undefined;
319
- if (held.kind !== 'time')
320
- return expected === held.value;
321
- const left = instant(held.value);
322
- const right = instant(expected);
323
- return left === undefined || right === undefined ? undefined : left === right;
324
- }
325
- function sign(left, right) {
326
- return left < right ? -1 : left > right ? 1 : 0;
327
- }
328
- function ordered(held, value, compare) {
329
- if (!('value' in held))
330
- return undefined;
331
- if (held.kind === 'number') {
332
- if (typeof value !== 'number' || typeof held.value !== 'number')
333
- return undefined;
334
- return compare(Math.sign(held.value - value));
335
- }
336
- if (held.kind === 'date') {
337
- if (!dated(value) || !dated(held.value))
338
- return undefined;
339
- return compare(sign(held.value, value));
340
- }
341
- if (held.kind !== 'time')
342
- return undefined;
343
- const at = instant(held.value);
344
- const wanted = instant(value);
345
- if (at === undefined || wanted === undefined)
346
- return undefined;
347
- return compare(sign(at, wanted));
348
- }
349
- function anyOf(truths) {
350
- if (truths.some((truth) => truth === true))
351
- return true;
352
- return truths.some((truth) => truth === undefined) ? undefined : false;
353
- }
354
- function allOf(truths) {
355
- if (truths.some((truth) => truth === false))
356
- return false;
357
- return truths.some((truth) => truth === undefined) ? undefined : true;
358
- }
359
- function compared(test, held, owner) {
360
- if ('eq' in test)
361
- return equal(held, test.eq, owner);
362
- if ('in' in test)
363
- return anyOf(test.in.map((value) => equal(held, value, owner)));
364
- if ('prefix' in test) {
365
- if (!('value' in held) || typeof held.value !== 'string')
366
- return undefined;
367
- if (held.kind === 'number' || held.kind === 'reference' || held.kind === 'member')
368
- return undefined;
369
- return held.value.startsWith(test.prefix);
370
- }
371
- if ('gt' in test)
372
- return ordered(held, test.gt, (sign) => sign > 0);
373
- if ('gte' in test)
374
- return ordered(held, test.gte, (sign) => sign >= 0);
375
- if ('lt' in test)
376
- return ordered(held, test.lt, (sign) => sign < 0);
377
- return ordered(held, test.lte, (sign) => sign <= 0);
378
- }
379
- function leaf(test, read, owner) {
380
- if ('exists' in test) {
381
- const present = read === undefined ? false : read.present;
382
- return present === undefined ? undefined : present === test.exists;
383
- }
384
- if (read === undefined)
385
- return undefined;
386
- if ('contains' in test) {
387
- if (read.items === null)
388
- return undefined;
389
- const truths = read.items.map((item) => item === undefined ? undefined : equal(item, test.contains, owner));
390
- return read.loose === true && !truths.includes(true) ? false : anyOf(truths);
391
- }
392
- if (read.values.length === 0)
393
- return read === NO_ITEM ? false : undefined;
394
- return anyOf(read.values.map((value) => (value === undefined ? undefined : compared(test, value, owner))));
395
- }
396
- function evaluated(test, read, owner) {
397
- if ('all' in test)
398
- return allOf(test.all.map((part) => evaluated(part, read, owner)));
399
- if ('any' in test)
400
- return anyOf(test.any.map((part) => evaluated(part, read, owner)));
401
- if ('not' in test) {
402
- const truth = evaluated(test.not, read, owner);
403
- return truth === undefined ? undefined : !truth;
404
- }
405
- return leaf(test, read(test.path), owner);
406
- }
407
- export function holds(test, document, owner) {
408
- return evaluated(test, (path) => readDocument(document, path), owner);
409
- }
410
- function inScope(scope, document) {
411
- if (document === null)
412
- return false;
413
- if ('type' in scope)
414
- return document.type === scope.type;
415
- if ('document' in scope)
416
- return document.id === scope.document;
417
- return scope.folder === '/' || document.path.startsWith(`${scope.folder}/`);
418
- }
419
- function matched(condition, test, document, owner) {
420
- if (!inScope(condition.scope, document))
421
- return false;
422
- return test === undefined || holds(test, document, owner) === true;
423
- }
424
- function reachedAt(document, field) {
425
- if (document === null)
426
- return [];
427
- if (field.startsWith('/sections/'))
428
- return document.sections.includes(field.slice('/sections/'.length))
429
- ? [{ pointer: field, fact: PROSE }]
430
- : [];
431
- if (!field.startsWith('/fields/'))
432
- return [];
433
- return walked(rootOf(document, '/fields'), field.slice('/fields'.length)).reached;
434
- }
435
- function valueOf(fact) {
436
- if (fact.kind === 'list')
437
- return { kind: fact.kind, items: fact.items.map(valueOf) };
438
- if (fact.kind === 'object')
439
- return {
440
- kind: fact.kind,
441
- fields: Object.keys(fact.fields)
442
- .sort()
443
- .map((key) => [key, valueOf(fact.fields[key])]),
444
- };
445
- if (fact.kind === 'time') {
446
- const at = instant(fact.value);
447
- if (at !== undefined)
448
- return { kind: fact.kind, at: String(at) };
449
- }
450
- return 'value' in fact ? { kind: fact.kind, value: fact.value } : fact;
451
- }
452
- function signature(reached) {
453
- return JSON.stringify(reached.map(({ fact }) => valueOf(fact)));
454
- }
455
- function among(values, document, field, owner) {
456
- return holds({ path: field, in: values }, document, owner) === true;
457
- }
458
- function fieldChanged(condition, event, owner) {
459
- const { field, from, to } = condition;
460
- const before = reachedAt(event.before, field);
461
- const after = reachedAt(event.after, field);
462
- const pointers = [field, ...[...before, ...after].map(({ pointer }) => pointer)];
463
- const prose = event.changed.some((changed) => pointers.some((pointer) => changed === pointer || changed.startsWith(`${pointer}/`)));
464
- if (from === undefined && to === undefined && prose)
465
- return true;
466
- if (before.length === 0 && after.length === 0)
467
- return false;
468
- if (event.before !== null && event.after !== null && signature(before) === signature(after))
469
- return false;
470
- if (from === 'new'
471
- ? event.before !== null
472
- : from !== undefined && (event.before === null || !among(from, event.before, field, owner)))
473
- return false;
474
- if (to === 'deleted'
475
- ? event.after !== null
476
- : to !== undefined && (event.after === null || !among(to, event.after, field, owner)))
477
- return false;
478
- return true;
479
- }
480
- export function fires(condition, event, owner) {
481
- if (condition.by !== undefined &&
482
- evaluated(condition.by, (path) => readActor(event.by, path), owner) !== true)
483
- return false;
484
- if (condition.mode === 'starts_matching') {
485
- if (event.before === null && !condition.new_documents)
486
- return false;
487
- return (matched(condition, condition.match, event.after, owner) &&
488
- !matched(condition, condition.match, event.before, owner));
489
- }
490
- const side = event.after ?? event.before;
491
- return matched(condition, condition.match, side, owner) && fieldChanged(condition, event, owner);
492
- }
493
- export function itemFires(condition, item, owner) {
494
- if (condition.source !== undefined && item.source !== condition.source)
495
- return false;
496
- if (condition.address !== undefined && item.address !== condition.address)
497
- return false;
498
- return (condition.match === undefined ||
499
- evaluated(condition.match, (path) => readItem(item, path), owner) === true);
500
- }
package/dist/divide.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { Division, DivisionContext, Document } from './types.js';
2
- export declare function divide(document: Document, file: string, context: DivisionContext): Division;
3
- //# sourceMappingURL=divide.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"divide.d.ts","sourceRoot":"","sources":["../src/divide.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAgB,MAAM,YAAY,CAAC;AA4WpF,wBAAgB,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,QAAQ,CAc3F"}