@agentshouse/mdmodel 0.1.0-cc9fa0498a7f7 → 0.1.0-ccb295d7b1fee

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 +305 -305
  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 +40 -11
  10. package/dist/definition.d.ts.map +1 -1
  11. package/dist/definition.js +442 -106
  12. package/dist/document.d.ts +16 -6
  13. package/dist/document.d.ts.map +1 -1
  14. package/dist/document.js +1000 -221
  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 +930 -0
  28. package/dist/house-model.d.ts.map +1 -0
  29. package/dist/house-model.js +511 -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 -14
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +27 -10
  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 +26 -2
  58. package/dist/paths.d.ts.map +1 -1
  59. package/dist/paths.js +207 -16
  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 +255 -0
  64. package/dist/query/language.d.ts.map +1 -0
  65. package/dist/query/language.js +620 -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 +150 -0
  69. package/dist/query/rows.d.ts +32 -0
  70. package/dist/query/rows.d.ts.map +1 -0
  71. package/dist/query/rows.js +158 -0
  72. package/dist/query/sql.d.ts +43 -0
  73. package/dist/query/sql.d.ts.map +1 -0
  74. package/dist/query/sql.js +285 -0
  75. package/dist/query/walk.d.ts +63 -0
  76. package/dist/query/walk.d.ts.map +1 -0
  77. package/dist/query/walk.js +263 -0
  78. package/dist/references.d.ts +1 -1
  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 +136 -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 +53 -21
  94. package/dist/types.d.ts.map +1 -1
  95. package/dist/validate.d.ts +36 -2
  96. package/dist/validate.d.ts.map +1 -1
  97. package/dist/validate.js +387 -136
  98. package/dist/yaml.d.ts +7 -5
  99. package/dist/yaml.d.ts.map +1 -1
  100. package/dist/yaml.js +219 -60
  101. package/fixtures/README.md +90 -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 +1359 -0
  397. package/package.json +19 -3
  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 -150
  402. package/dist/condition.d.ts.map +0 -1
  403. package/dist/condition.js +0 -497
  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 -26
  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/paths.js CHANGED
@@ -1,3 +1,10 @@
1
+ import { decodeNamedCharacterReference } from 'decode-named-character-reference';
2
+ import { decodeNumericCharacterReference } from 'micromark-util-decode-numeric-character-reference';
3
+ const BACKSLASH = 0x5c;
4
+ const PUNCTUATION = /^[!-/:-@[-`{-~]$/;
5
+ function escapes(text, index) {
6
+ return text.charCodeAt(index) === BACKSLASH && PUNCTUATION.test(text[index + 1] ?? '');
7
+ }
1
8
  export function dirname(path) {
2
9
  const index = path.lastIndexOf('/');
3
10
  return index === -1 ? '' : path.slice(0, index);
@@ -22,30 +29,186 @@ export function normalize(path) {
22
29
  }
23
30
  return parts.join('/');
24
31
  }
25
- export function classifyHref(from, href) {
26
- const trimmed = href.trim();
27
- if (trimmed === '' || trimmed.startsWith('#'))
28
- return { kind: 'skip' };
29
- if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(trimmed))
32
+ const REFERENCE = /&(?:#[xX]([0-9a-fA-F]{1,6})|#([0-9]{1,7})|([A-Za-z][A-Za-z0-9]{0,31}));/y;
33
+ const PERCENT = /^%[0-9a-fA-F]{2}/;
34
+ function referenceAt(text, at) {
35
+ REFERENCE.lastIndex = at;
36
+ const match = REFERENCE.exec(text);
37
+ if (match === null)
38
+ return null;
39
+ const [whole, hex, decimal, name] = match;
40
+ const end = at + whole.length;
41
+ if (name !== undefined) {
42
+ const decoded = decodeNamedCharacterReference(name);
43
+ return decoded === false ? null : { text: decoded, end };
44
+ }
45
+ return {
46
+ text: decodeNumericCharacterReference(hex ?? decimal, hex === undefined ? 10 : 16),
47
+ end,
48
+ };
49
+ }
50
+ function spelled(written, from, stops) {
51
+ let text = '';
52
+ let i = from;
53
+ while (i < written.length) {
54
+ const escaped = escapes(written, i);
55
+ const reference = escaped || written[i] !== '&' ? null : referenceAt(written, i);
56
+ const one = escaped ? written[i + 1] : (reference?.text ?? written[i]);
57
+ if (stops && (one.startsWith('?') || one.startsWith('#')))
58
+ return { text, end: i };
59
+ text += one;
60
+ i = escaped ? i + 2 : (reference?.end ?? i + 1);
61
+ }
62
+ return { text, end: written.length };
63
+ }
64
+ function unescaped(written) {
65
+ const { text, end } = spelled(written, 0, true);
66
+ return { base: text, suffix: end };
67
+ }
68
+ function located(href) {
69
+ const written = href.trim();
70
+ const { base, suffix } = unescaped(written);
71
+ const url = base.replace(/[\t\n\r]/g, '').replace(/^[\u0000-\u0020]+/, '');
72
+ return {
73
+ base: suffix === written.length ? url.replace(/(?<![\u0000-\u0020])[\u0000-\u0020]+$/, '') : url,
74
+ suffix,
75
+ };
76
+ }
77
+ const ENCODED = /(?:%[0-9a-fA-F]{2})+/g;
78
+ function decodedRun(run) {
79
+ try {
80
+ return decodeURIComponent(run);
81
+ }
82
+ catch {
83
+ return null;
84
+ }
85
+ }
86
+ export function destinationPath(href) {
87
+ const base = located(href).base;
88
+ let path = '';
89
+ let cursor = 0;
90
+ for (const match of base.matchAll(ENCODED)) {
91
+ const decoded = decodedRun(match[0]);
92
+ if (decoded === null)
93
+ return null;
94
+ path += base.slice(cursor, match.index) + decoded;
95
+ cursor = match.index + match[0].length;
96
+ }
97
+ return (path + base.slice(cursor)).normalize('NFC');
98
+ }
99
+ const SPACE = /\s/u;
100
+ function written(path) {
101
+ let text = '';
102
+ for (let i = 0; i < path.length; i += 1) {
103
+ const char = path[i];
104
+ if (char === '?' || char === '#' || char < ' ')
105
+ text += encodeURIComponent(char);
106
+ else if (SPACE.test(char) && (i === 0 || i === path.length - 1))
107
+ text += encodeURIComponent(char);
108
+ else if (char === '%' && PERCENT.test(path.slice(i)))
109
+ text += '%25';
110
+ else if (escapes(path, i))
111
+ text += '%5C';
112
+ else if (char === '&' && referenceAt(path, i) !== null)
113
+ text += '%26';
114
+ else
115
+ text += char;
116
+ }
117
+ return text;
118
+ }
119
+ function roomAt(path) {
120
+ if (!path.startsWith(SHELL_ROOMS))
121
+ return null;
122
+ const rest = path.slice(SHELL_ROOMS.length);
123
+ const slash = rest.indexOf('/');
124
+ const handle = slash === -1 ? rest : rest.slice(0, slash);
125
+ if (handle === '' || handle === '.' || handle === '..')
126
+ return null;
127
+ const within = normalize(slash === -1 ? '' : rest.slice(slash + 1));
128
+ return within === null ? null : { handle, path: within };
129
+ }
130
+ function roomTargetOf(path) {
131
+ const room = roomAt(path);
132
+ return room === null || room.path === '' ? null : room;
133
+ }
134
+ function resolvedOf(from, href) {
135
+ const base = located(href).base;
136
+ if (base === '')
30
137
  return { kind: 'skip' };
31
- if (trimmed.startsWith('/'))
32
- return { kind: 'invalid' };
33
- const bare = trimmed.replace(/[?#].*$/, '');
34
- if (bare === '')
138
+ if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(base))
35
139
  return { kind: 'skip' };
36
- const resolved = normalize(join(dirname(from), bare));
37
- if (resolved === null || resolved === '')
140
+ const path = destinationPath(href);
141
+ if (path === null)
38
142
  return { kind: 'invalid' };
39
- return { kind: 'path', path: resolved };
143
+ if (path.startsWith('/')) {
144
+ const room = roomAt(path);
145
+ return room === null ? { kind: 'invalid' } : { kind: 'room', ...room };
146
+ }
147
+ const resolved = normalize(join(dirname(from), path));
148
+ return resolved === null ? { kind: 'invalid' } : { kind: 'path', path: resolved };
149
+ }
150
+ export function classifyHref(from, href) {
151
+ const resolved = resolvedOf(from, href);
152
+ return 'path' in resolved && resolved.path === '' ? { kind: 'invalid' } : resolved;
153
+ }
154
+ export function roomTarget(href) {
155
+ const path = destinationPath(href);
156
+ return path === null ? null : roomTargetOf(path);
157
+ }
158
+ export function roomPath(href) {
159
+ const room = roomTarget(href);
160
+ return room === null ? null : `${SHELL_ROOMS}${room.handle}/${room.path}`;
40
161
  }
41
162
  export function target(from, href) {
42
163
  const resolved = classifyHref(from, href);
43
164
  return resolved.kind === 'path' ? resolved.path : null;
44
165
  }
166
+ export function linkedPath(from, href) {
167
+ const resolved = located(href).base === '' ? { kind: 'path', path: from } : resolvedOf(from, href);
168
+ if (!('path' in resolved))
169
+ return null;
170
+ const written = href.trim();
171
+ const suffix = spelled(written, unescaped(written).suffix, false).text;
172
+ const hash = suffix.indexOf('#');
173
+ const fragment = hash === -1 ? '' : suffix.slice(hash + 1);
174
+ return {
175
+ handle: resolved.kind === 'room' ? resolved.handle : null,
176
+ path: resolved.path,
177
+ fragment: fragment === '' ? null : (decodedRun(fragment) ?? fragment),
178
+ };
179
+ }
180
+ const LINK_KEY = /^\?key=([A-Za-z0-9._~-]+)(?:#|$)/u;
181
+ export function keyedLink(href) {
182
+ const written = href.trim();
183
+ if (!written.includes('?') && !written.includes('&'))
184
+ return null;
185
+ const key = LINK_KEY.exec(spelled(written, unescaped(written).suffix, false).text)?.[1];
186
+ if (key === undefined)
187
+ return null;
188
+ const room = roomTarget(href);
189
+ return room === null ? null : { ...room, key };
190
+ }
191
+ export function urlDestination(url) {
192
+ return url.replace(/[\\&]/g, '\\$&');
193
+ }
194
+ const URL_KEPT = /^[A-Za-z0-9._~-]$/u;
195
+ function urlSegment(name) {
196
+ let text = '';
197
+ for (const char of name) {
198
+ const point = char.codePointAt(0);
199
+ text +=
200
+ point >= 0x80 || URL_KEPT.test(char)
201
+ ? char
202
+ : `%${point.toString(16).toUpperCase().padStart(2, '0')}`;
203
+ }
204
+ return text;
205
+ }
206
+ export function keyedDestination(path, key) {
207
+ return `${path.split('/').map(urlSegment).join('/')}?key=${key}`;
208
+ }
45
209
  export function retarget(href, to) {
46
210
  const trimmed = href.trim();
47
- const match = /[?#]/.exec(trimmed);
48
- return match === null ? to : to + trimmed.slice(match.index);
211
+ return written(to) + trimmed.slice(unescaped(trimmed).suffix);
49
212
  }
50
213
  export function relative(from, target) {
51
214
  const base = dirname(from)
@@ -62,8 +225,36 @@ export function relative(from, target) {
62
225
  export const SHELL_ROOMS = '/rooms/';
63
226
  export function shellTarget(href, handle) {
64
227
  const prefix = `${SHELL_ROOMS}${handle}/`;
65
- if (!href.startsWith(prefix))
228
+ const decoded = destinationPath(href);
229
+ if (decoded === null || !decoded.startsWith(prefix))
66
230
  return null;
67
- const path = normalize(href.slice(prefix.length).replace(/[?#].*$/s, ''));
231
+ const path = normalize(decoded.slice(prefix.length));
68
232
  return path === null || path === '' ? null : path;
69
233
  }
234
+ function fitsBare(to) {
235
+ if (to === '' || to.startsWith('<'))
236
+ return false;
237
+ let depth = 0;
238
+ for (const character of to) {
239
+ if (/[\s\u0000-\u001f\u007f]/.test(character))
240
+ return false;
241
+ if (character === '(')
242
+ depth += 1;
243
+ else if (character === ')') {
244
+ if (depth === 0)
245
+ return false;
246
+ depth -= 1;
247
+ }
248
+ }
249
+ return depth === 0;
250
+ }
251
+ function fitsBrackets(to) {
252
+ return to !== '' && !/[<>\n\r]/.test(to);
253
+ }
254
+ export function destinationText(to, bracketed) {
255
+ if (fitsBare(to))
256
+ return bracketed && fitsBrackets(to) ? `<${to}>` : to;
257
+ if (fitsBrackets(to))
258
+ return `<${to}>`;
259
+ return null;
260
+ }
@@ -0,0 +1,10 @@
1
+ export declare const PATTERN_STATES = 1000;
2
+ export declare class PatternTooCostly extends Error {
3
+ }
4
+ export type Pattern = {
5
+ readonly test: (text: string) => boolean;
6
+ };
7
+ export declare function linearPattern(source: string): Pattern | null;
8
+ export declare function withLinearRegExp<T>(run: () => T): T;
9
+ export declare function openPatternBudget(): () => void;
10
+ //# sourceMappingURL=pattern.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pattern.d.ts","sourceRoot":"","sources":["../src/pattern.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,OAAQ,CAAC;AAMpC,qBAAa,gBAAiB,SAAQ,KAAK;CAAG;AAQ9C,MAAM,MAAM,OAAO,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAA;CAAE,CAAC;AAkUnE,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAM5D;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CAkBnD;AAED,wBAAgB,iBAAiB,IAAI,MAAM,IAAI,CAM9C"}
@@ -0,0 +1,356 @@
1
+ const NativeRegExp = RegExp;
2
+ export const PATTERN_STATES = 1_000;
3
+ const VISIT_BUDGET = 100_000_000;
4
+ const HELD_PATTERNS = 512;
5
+ export class PatternTooCostly extends Error {
6
+ }
7
+ let scope = null;
8
+ const ASCII = 128;
9
+ class Unsupported extends Error {
10
+ }
11
+ const ATOM = 0;
12
+ const SPLIT = 1;
13
+ const ASSERT = 2;
14
+ const MATCH = 3;
15
+ class Atom {
16
+ literal;
17
+ ascii = new Int8Array(ASCII);
18
+ matcher;
19
+ constructor(source, literal) {
20
+ this.literal = literal;
21
+ this.matcher = new NativeRegExp(`^(?:${source})$`, 'u');
22
+ }
23
+ holds(point) {
24
+ if (this.literal !== null)
25
+ return point === this.literal;
26
+ if (point >= ASCII)
27
+ return this.matcher.test(String.fromCodePoint(point));
28
+ const known = this.ascii[point];
29
+ if (known !== 0)
30
+ return known > 0;
31
+ const held = this.matcher.test(String.fromCharCode(point));
32
+ this.ascii[point] = held ? 1 : -1;
33
+ return held;
34
+ }
35
+ }
36
+ class Reader {
37
+ source;
38
+ at = 0;
39
+ constructor(source) {
40
+ this.source = source;
41
+ }
42
+ peek(offset = 0) {
43
+ return this.source[this.at + offset];
44
+ }
45
+ starts(text) {
46
+ return this.source.startsWith(text, this.at);
47
+ }
48
+ }
49
+ function digits(reader) {
50
+ const from = reader.at;
51
+ while (/[0-9]/.test(reader.peek() ?? ''))
52
+ reader.at += 1;
53
+ return reader.at === from ? null : Number(reader.source.slice(from, reader.at));
54
+ }
55
+ function escapeEnd(source, at) {
56
+ const next = source[at + 1];
57
+ if (next === 'c')
58
+ return at + 3;
59
+ if (next === 'x')
60
+ return at + 4;
61
+ if ((next === 'u' && source[at + 2] === '{') || next === 'p' || next === 'P')
62
+ return source.indexOf('}', at + 2) + 1;
63
+ if (next !== 'u')
64
+ return at + 2;
65
+ const end = at + 6;
66
+ const lead = Number.parseInt(source.slice(at + 2, end), 16);
67
+ const trail = /^\\u([0-9a-fA-F]{4})$/.exec(source.slice(end, end + 6))?.[1];
68
+ const paired = lead >= 0xd800 &&
69
+ lead <= 0xdbff &&
70
+ trail !== undefined &&
71
+ Number.parseInt(trail, 16) >= 0xdc00 &&
72
+ Number.parseInt(trail, 16) <= 0xdfff;
73
+ return paired ? end + 6 : end;
74
+ }
75
+ function classEnd(source, at) {
76
+ let i = at + 1;
77
+ while (source[i] !== ']')
78
+ i += source[i] === '\\' ? 2 : 1;
79
+ return i + 1;
80
+ }
81
+ function escaped(reader) {
82
+ const next = reader.peek(1);
83
+ if (next === 'b' || next === 'B') {
84
+ reader.at += 2;
85
+ return { kind: 'assert', assertion: next === 'b' ? 'boundary' : 'inside' };
86
+ }
87
+ if (/[1-9k]/.test(next))
88
+ throw new Unsupported();
89
+ const end = escapeEnd(reader.source, reader.at);
90
+ const source = reader.source.slice(reader.at, end);
91
+ reader.at = end;
92
+ return { kind: 'atom', source, literal: false };
93
+ }
94
+ function group(reader) {
95
+ reader.at += 1;
96
+ if (reader.starts('?:'))
97
+ reader.at += 2;
98
+ else if (reader.starts('?<') && !reader.starts('?<=') && !reader.starts('?<!'))
99
+ reader.at = reader.source.indexOf('>', reader.at) + 1;
100
+ else if (reader.peek() === '?')
101
+ throw new Unsupported();
102
+ const alternatives = disjunction(reader);
103
+ reader.at += 1;
104
+ return { kind: 'group', alternatives };
105
+ }
106
+ function atom(reader) {
107
+ const character = reader.peek();
108
+ if (character === '^' || character === '$') {
109
+ reader.at += 1;
110
+ return { kind: 'assert', assertion: character === '^' ? 'start' : 'end' };
111
+ }
112
+ if (character === '\\')
113
+ return escaped(reader);
114
+ if (character === '(')
115
+ return group(reader);
116
+ if (character === '[' || character === '.') {
117
+ const end = character === '[' ? classEnd(reader.source, reader.at) : reader.at + 1;
118
+ const source = reader.source.slice(reader.at, end);
119
+ reader.at = end;
120
+ return { kind: 'atom', source, literal: false };
121
+ }
122
+ const source = String.fromCodePoint(reader.source.codePointAt(reader.at));
123
+ reader.at += source.length;
124
+ return { kind: 'atom', source, literal: true };
125
+ }
126
+ function quantified(reader, node) {
127
+ const sign = reader.peek();
128
+ let least = 1;
129
+ let most = 1;
130
+ if (sign === '*' || sign === '+' || sign === '?') {
131
+ reader.at += 1;
132
+ least = sign === '+' ? 1 : 0;
133
+ most = sign === '?' ? 1 : Infinity;
134
+ }
135
+ else if (sign === '{') {
136
+ reader.at += 1;
137
+ least = digits(reader);
138
+ most = least;
139
+ if (reader.peek() === ',') {
140
+ reader.at += 1;
141
+ most = digits(reader) ?? Infinity;
142
+ }
143
+ reader.at += 1;
144
+ }
145
+ else
146
+ return { node, least, most };
147
+ if (reader.peek() === '?')
148
+ reader.at += 1;
149
+ if (least > PATTERN_STATES || (Number.isFinite(most) && most > PATTERN_STATES))
150
+ throw new Unsupported();
151
+ return { node, least, most };
152
+ }
153
+ function disjunction(reader) {
154
+ const alternatives = [[]];
155
+ while (reader.at < reader.source.length && reader.peek() !== ')') {
156
+ if (reader.peek() === '|') {
157
+ reader.at += 1;
158
+ alternatives.push([]);
159
+ continue;
160
+ }
161
+ alternatives.at(-1).push(quantified(reader, atom(reader)));
162
+ }
163
+ return alternatives;
164
+ }
165
+ class Machine {
166
+ kinds = [];
167
+ outs = [];
168
+ alternates = [];
169
+ atoms = [];
170
+ assertions = [];
171
+ atomed = new Map();
172
+ state(kind, out, alternate = -1) {
173
+ if (this.kinds.length >= PATTERN_STATES)
174
+ throw new Unsupported();
175
+ this.kinds.push(kind);
176
+ this.outs.push(out);
177
+ this.alternates.push(alternate);
178
+ return this.kinds.length - 1;
179
+ }
180
+ atom(source, literal) {
181
+ const known = this.atomed.get(source);
182
+ if (known !== undefined)
183
+ return known;
184
+ this.atoms.push(new Atom(source, literal ? source.codePointAt(0) : null));
185
+ this.atomed.set(source, this.atoms.length - 1);
186
+ return this.atoms.length - 1;
187
+ }
188
+ node(node, next) {
189
+ if (node.kind === 'atom')
190
+ return this.state(ATOM, next, this.atom(node.source, node.literal));
191
+ if (node.kind === 'assert') {
192
+ this.assertions.push(node.assertion);
193
+ return this.state(ASSERT, next, this.assertions.length - 1);
194
+ }
195
+ return this.alternatives(node.alternatives, next);
196
+ }
197
+ alternatives(alternatives, next) {
198
+ let entry = this.sequence(alternatives.at(-1), next);
199
+ for (let index = alternatives.length - 2; index >= 0; index -= 1)
200
+ entry = this.state(SPLIT, this.sequence(alternatives[index], next), entry);
201
+ return entry;
202
+ }
203
+ sequence(terms, next) {
204
+ let entry = next;
205
+ for (let index = terms.length - 1; index >= 0; index -= 1)
206
+ entry = this.term(terms[index], entry);
207
+ return entry;
208
+ }
209
+ term({ node, least, most }, next) {
210
+ if (least === 1 && most === 1)
211
+ return this.node(node, next);
212
+ let entry = next;
213
+ if (most === Infinity) {
214
+ const loop = this.state(SPLIT, -1, next);
215
+ const body = this.node(node, loop);
216
+ if (body === loop)
217
+ return next;
218
+ this.outs[loop] = body;
219
+ entry = loop;
220
+ }
221
+ else
222
+ for (let copy = least; copy < most; copy += 1) {
223
+ const body = this.node(node, entry);
224
+ if (body === entry)
225
+ return next;
226
+ entry = this.state(SPLIT, body, entry);
227
+ }
228
+ for (let copy = 0; copy < least; copy += 1) {
229
+ const body = this.node(node, entry);
230
+ if (body === entry)
231
+ return next;
232
+ entry = body;
233
+ }
234
+ return entry;
235
+ }
236
+ }
237
+ function word(point) {
238
+ return ((point >= 0x30 && point <= 0x39) ||
239
+ (point >= 0x41 && point <= 0x5a) ||
240
+ (point >= 0x61 && point <= 0x7a) ||
241
+ point === 0x5f);
242
+ }
243
+ function holds(assertion, at, point, across) {
244
+ if (assertion === 'start')
245
+ return at === 0;
246
+ if (assertion === 'end')
247
+ return point === -1;
248
+ return assertion === 'boundary' ? across : !across;
249
+ }
250
+ class Linear {
251
+ machine;
252
+ start;
253
+ marks;
254
+ generation = 0;
255
+ constructor(machine, start) {
256
+ this.machine = machine;
257
+ this.start = start;
258
+ this.marks = new Float64Array(machine.kinds.length);
259
+ }
260
+ test(text) {
261
+ const { kinds, outs, alternates, atoms, assertions } = this.machine;
262
+ const marks = this.marks;
263
+ const budget = scope ?? { left: VISIT_BUDGET };
264
+ let seeds = [];
265
+ let wordBefore = false;
266
+ for (let at = 0;;) {
267
+ const point = at < text.length ? text.codePointAt(at) : -1;
268
+ const wordAt = word(point);
269
+ const across = wordBefore !== wordAt;
270
+ const generation = (this.generation += 1);
271
+ const active = [];
272
+ seeds.push(this.start);
273
+ while (seeds.length > 0) {
274
+ const state = seeds.pop();
275
+ if (marks[state] === generation)
276
+ continue;
277
+ marks[state] = generation;
278
+ if ((budget.left -= 1) < 0)
279
+ throw new PatternTooCostly();
280
+ const kind = kinds[state];
281
+ if (kind === MATCH)
282
+ return true;
283
+ if (kind === ATOM)
284
+ active.push(state);
285
+ else if (kind === SPLIT)
286
+ seeds.push(alternates[state], outs[state]);
287
+ else if (holds(assertions[alternates[state]], at, point, across))
288
+ seeds.push(outs[state]);
289
+ }
290
+ if (point === -1)
291
+ return false;
292
+ for (const state of active)
293
+ if (atoms[alternates[state]].holds(point))
294
+ seeds.push(outs[state]);
295
+ wordBefore = wordAt;
296
+ at += point > 0xffff ? 2 : 1;
297
+ }
298
+ }
299
+ }
300
+ function compiled(source) {
301
+ try {
302
+ new NativeRegExp(source, 'u');
303
+ }
304
+ catch {
305
+ return null;
306
+ }
307
+ try {
308
+ const alternatives = disjunction(new Reader(source));
309
+ const machine = new Machine();
310
+ const start = machine.alternatives(alternatives, machine.state(MATCH, -1));
311
+ return new Linear(machine, start);
312
+ }
313
+ catch (error) {
314
+ if (error instanceof Unsupported)
315
+ return null;
316
+ throw error;
317
+ }
318
+ }
319
+ const held = new Map();
320
+ export function linearPattern(source) {
321
+ if (held.has(source))
322
+ return held.get(source);
323
+ const made = compiled(source);
324
+ if (held.size >= HELD_PATTERNS)
325
+ held.delete(held.keys().next().value);
326
+ held.set(source, made);
327
+ return made;
328
+ }
329
+ export function withLinearRegExp(run) {
330
+ const native = globalThis.RegExp;
331
+ function LinearRegExp(source) {
332
+ new NativeRegExp(source, 'u');
333
+ return {
334
+ test(text) {
335
+ const pattern = linearPattern(source);
336
+ if (pattern === null)
337
+ throw new SyntaxError(`the pattern ${source} is not linear`);
338
+ return pattern.test(text);
339
+ },
340
+ };
341
+ }
342
+ globalThis.RegExp = LinearRegExp;
343
+ try {
344
+ return run();
345
+ }
346
+ finally {
347
+ globalThis.RegExp = native;
348
+ }
349
+ }
350
+ export function openPatternBudget() {
351
+ const outer = scope;
352
+ scope = outer ?? { left: VISIT_BUDGET };
353
+ return () => {
354
+ scope = outer;
355
+ };
356
+ }