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

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 (563) hide show
  1. package/API.md +434 -0
  2. package/README.md +42 -197
  3. package/dist/body.d.ts +85 -0
  4. package/dist/body.d.ts.map +1 -0
  5. package/dist/body.js +1083 -0
  6. package/dist/built-in.d.ts +4 -0
  7. package/dist/built-in.d.ts.map +1 -0
  8. package/dist/built-in.js +19 -0
  9. package/dist/definition.d.ts +91 -34
  10. package/dist/definition.d.ts.map +1 -1
  11. package/dist/definition.js +862 -144
  12. package/dist/divide.d.ts +3 -0
  13. package/dist/divide.d.ts.map +1 -0
  14. package/dist/divide.js +321 -0
  15. package/dist/document.d.ts +19 -3
  16. package/dist/document.d.ts.map +1 -1
  17. package/dist/document.js +1033 -188
  18. package/dist/event.d.ts +77 -0
  19. package/dist/event.d.ts.map +1 -0
  20. package/dist/event.js +200 -0
  21. package/dist/facts.d.ts +15 -0
  22. package/dist/facts.d.ts.map +1 -0
  23. package/dist/facts.js +41 -0
  24. package/dist/fields.d.ts +6 -0
  25. package/dist/fields.d.ts.map +1 -0
  26. package/dist/fields.js +10 -0
  27. package/dist/form.d.ts +4 -0
  28. package/dist/form.d.ts.map +1 -0
  29. package/dist/form.js +153 -0
  30. package/dist/house-model.d.ts +870 -0
  31. package/dist/house-model.d.ts.map +1 -0
  32. package/dist/house-model.js +472 -0
  33. package/dist/house-references/crockford.d.ts +4 -0
  34. package/dist/house-references/crockford.d.ts.map +1 -0
  35. package/dist/house-references/crockford.js +3 -0
  36. package/dist/house-references/patterns.d.ts +9 -0
  37. package/dist/house-references/patterns.d.ts.map +1 -0
  38. package/dist/house-references/patterns.js +13 -0
  39. package/dist/index.d.ts +47 -4
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +29 -5
  42. package/dist/indexed.d.ts +9 -0
  43. package/dist/indexed.d.ts.map +1 -0
  44. package/dist/indexed.js +55 -0
  45. package/dist/kinds.d.ts +21 -0
  46. package/dist/kinds.d.ts.map +1 -0
  47. package/dist/kinds.js +210 -0
  48. package/dist/markdown.d.ts +75 -0
  49. package/dist/markdown.d.ts.map +1 -0
  50. package/dist/markdown.js +265 -0
  51. package/dist/media-type.d.ts +72 -0
  52. package/dist/media-type.d.ts.map +1 -0
  53. package/dist/media-type.js +157 -0
  54. package/dist/moment.d.ts +7 -0
  55. package/dist/moment.d.ts.map +1 -0
  56. package/dist/moment.js +18 -0
  57. package/dist/not-ready.d.ts +2 -0
  58. package/dist/not-ready.d.ts.map +1 -0
  59. package/dist/not-ready.js +5 -0
  60. package/dist/paths.d.ts +30 -5
  61. package/dist/paths.d.ts.map +1 -1
  62. package/dist/paths.js +220 -35
  63. package/dist/pattern.d.ts +10 -0
  64. package/dist/pattern.d.ts.map +1 -0
  65. package/dist/pattern.js +356 -0
  66. package/dist/project.d.ts +20 -1
  67. package/dist/project.d.ts.map +1 -1
  68. package/dist/project.js +80 -101
  69. package/dist/query/language.d.ts +255 -0
  70. package/dist/query/language.d.ts.map +1 -0
  71. package/dist/query/language.js +620 -0
  72. package/dist/query/match.d.ts +14 -0
  73. package/dist/query/match.d.ts.map +1 -0
  74. package/dist/query/match.js +150 -0
  75. package/dist/query/rows.d.ts +32 -0
  76. package/dist/query/rows.d.ts.map +1 -0
  77. package/dist/query/rows.js +158 -0
  78. package/dist/query/sql.d.ts +39 -0
  79. package/dist/query/sql.d.ts.map +1 -0
  80. package/dist/query/sql.js +285 -0
  81. package/dist/query/walk.d.ts +57 -0
  82. package/dist/query/walk.d.ts.map +1 -0
  83. package/dist/query/walk.js +183 -0
  84. package/dist/references.d.ts +4 -0
  85. package/dist/references.d.ts.map +1 -0
  86. package/dist/references.js +30 -0
  87. package/dist/refuse.d.ts +1 -0
  88. package/dist/refuse.d.ts.map +1 -1
  89. package/dist/refuse.js +3 -10
  90. package/dist/reserved.d.ts +6 -0
  91. package/dist/reserved.d.ts.map +1 -0
  92. package/dist/reserved.js +21 -0
  93. package/dist/room-types.d.ts +7 -0
  94. package/dist/room-types.d.ts.map +1 -0
  95. package/dist/room-types.js +136 -0
  96. package/dist/schema.d.ts +6 -5
  97. package/dist/schema.d.ts.map +1 -1
  98. package/dist/schema.js +143 -41
  99. package/dist/types.d.ts +101 -3
  100. package/dist/types.d.ts.map +1 -1
  101. package/dist/types.js +1 -3
  102. package/dist/validate.d.ts +37 -2
  103. package/dist/validate.d.ts.map +1 -1
  104. package/dist/validate.js +392 -158
  105. package/dist/version.d.ts +1 -1
  106. package/dist/version.d.ts.map +1 -1
  107. package/dist/version.js +1 -3
  108. package/dist/yaml.d.ts +9 -3
  109. package/dist/yaml.d.ts.map +1 -1
  110. package/dist/yaml.js +326 -201
  111. package/fixtures/README.md +136 -56
  112. package/fixtures/cases/absent-link-dangles/library/item.md +8 -0
  113. package/fixtures/cases/absent-link-dangles/schema.yaml +5 -0
  114. package/fixtures/cases/absent-optional-field/expected.json +1 -0
  115. package/fixtures/cases/absent-optional-field/library/companies/acme.md +4 -0
  116. package/fixtures/cases/absent-optional-field/library/deals/lead.md +6 -0
  117. package/fixtures/cases/absent-optional-field/schema.yaml +55 -0
  118. package/fixtures/cases/absolute-link/expected.json +5 -0
  119. package/fixtures/cases/absolute-link/library/item.md +8 -0
  120. package/fixtures/cases/absolute-link/schema.yaml +5 -0
  121. package/fixtures/cases/attachment-reference-any-file/context.json +1 -0
  122. package/fixtures/cases/attachment-reference-any-file/expected.json +1 -0
  123. package/fixtures/cases/attachment-reference-any-file/library/companies/acme.md +4 -0
  124. package/fixtures/cases/attachment-reference-any-file/library/deals/renewal.md +18 -0
  125. package/fixtures/cases/attachment-reference-any-file/library/places/depot.md +4 -0
  126. package/fixtures/cases/attachment-reference-any-file/library/products/seats.md +4 -0
  127. package/fixtures/cases/attachment-reference-any-file/library/products/support.md +4 -0
  128. package/fixtures/cases/attachment-reference-any-file/schema.yaml +32 -0
  129. package/fixtures/cases/attachment-reference-dangles/context.json +1 -0
  130. package/fixtures/cases/attachment-reference-dangles/expected.json +1 -0
  131. package/fixtures/cases/attachment-reference-dangles/library/companies/acme.md +4 -0
  132. package/fixtures/cases/attachment-reference-dangles/library/deals/renewal.md +18 -0
  133. package/fixtures/cases/attachment-reference-dangles/library/places/depot.md +4 -0
  134. package/fixtures/cases/attachment-reference-dangles/library/products/seats.md +4 -0
  135. package/fixtures/cases/attachment-reference-dangles/library/products/support.md +4 -0
  136. package/fixtures/cases/attachment-reference-dangles/schema.yaml +32 -0
  137. package/fixtures/cases/attachment-reference-outside/context.json +1 -0
  138. package/fixtures/cases/attachment-reference-outside/expected.json +7 -0
  139. package/fixtures/cases/attachment-reference-outside/library/companies/acme.md +4 -0
  140. package/fixtures/cases/attachment-reference-outside/library/deals/renewal.md +18 -0
  141. package/fixtures/cases/attachment-reference-outside/library/places/depot.md +4 -0
  142. package/fixtures/cases/attachment-reference-outside/library/products/seats.md +4 -0
  143. package/fixtures/cases/attachment-reference-outside/library/products/support.md +4 -0
  144. package/fixtures/cases/attachment-reference-outside/schema.yaml +32 -0
  145. package/fixtures/cases/binary-any-reference/expected.json +2 -2
  146. package/fixtures/cases/binary-any-reference/library/notes/draft.md +1 -1
  147. package/fixtures/cases/binary-any-reference/schema.yaml +4 -0
  148. package/fixtures/cases/binary-document-collision/expected.json +1 -2
  149. package/fixtures/cases/binary-document-collision/schema.yaml +1 -0
  150. package/fixtures/cases/binary-image-dangles/expected.json +1 -0
  151. package/fixtures/cases/binary-image-dangles/schema.yaml +1 -0
  152. package/fixtures/cases/binary-link-dangles/expected.json +1 -0
  153. package/fixtures/cases/binary-link-dangles/schema.yaml +1 -0
  154. package/fixtures/cases/binary-link-outside-collection/expected.json +1 -2
  155. package/fixtures/cases/binary-link-outside-collection/schema.yaml +1 -0
  156. package/fixtures/cases/binary-prototype-reference/expected.json +2 -2
  157. package/fixtures/cases/binary-prototype-reference/library/notes/draft.md +1 -1
  158. package/fixtures/cases/binary-prototype-reference/schema.yaml +4 -0
  159. package/fixtures/cases/binary-typed-reference/expected.json +2 -2
  160. package/fixtures/cases/binary-typed-reference/library/notes/draft.md +1 -1
  161. package/fixtures/cases/binary-typed-reference/schema.yaml +5 -0
  162. package/fixtures/cases/boolean-field/context.json +1 -0
  163. package/fixtures/cases/boolean-field/expected.json +7 -0
  164. package/fixtures/cases/boolean-field/library/companies/acme.md +4 -0
  165. package/fixtures/cases/boolean-field/library/deals/renewal.md +56 -0
  166. package/fixtures/cases/boolean-field/schema.yaml +55 -0
  167. package/fixtures/cases/bracketed-link-definition/library/item.md +1 -1
  168. package/fixtures/cases/bracketed-link-definition/schema.yaml +5 -0
  169. package/fixtures/cases/closed-nested-object/context.json +1 -0
  170. package/fixtures/cases/closed-nested-object/expected.json +7 -0
  171. package/fixtures/cases/closed-nested-object/library/companies/acme.md +4 -0
  172. package/fixtures/cases/closed-nested-object/library/deals/renewal.md +57 -0
  173. package/fixtures/cases/closed-nested-object/schema.yaml +55 -0
  174. package/fixtures/cases/composed-root-reference/context.json +1 -0
  175. package/fixtures/cases/composed-root-reference/expected.json +6 -0
  176. package/fixtures/cases/composed-root-reference/library/a.md +5 -0
  177. package/fixtures/cases/composed-root-reference/schema.yaml +13 -0
  178. package/fixtures/cases/conditional-long-text/context.json +1 -0
  179. package/fixtures/cases/conditional-long-text/expected.json +7 -0
  180. package/fixtures/cases/conditional-long-text/library/questions/hosting.md +9 -0
  181. package/fixtures/cases/conditional-long-text/library/questions/payments.md +12 -0
  182. package/fixtures/cases/conditional-long-text/schema.yaml +13 -0
  183. package/fixtures/cases/cross-room-link/context.json +1 -0
  184. package/fixtures/cases/cross-room-link/expected.json +1 -0
  185. package/fixtures/cases/cross-room-link/library/clients/acme.md +6 -0
  186. package/fixtures/cases/cross-room-link/schema.yaml +3 -0
  187. package/fixtures/cases/cross-room-reference/context.json +1 -0
  188. package/fixtures/cases/cross-room-reference/expected.json +1 -0
  189. package/fixtures/cases/cross-room-reference/library/clients/acme.md +9 -0
  190. package/fixtures/cases/cross-room-reference/schema.yaml +8 -0
  191. package/fixtures/cases/date-time-format/context.json +1 -0
  192. package/fixtures/cases/date-time-format/expected.json +7 -0
  193. package/fixtures/cases/date-time-format/library/companies/acme.md +4 -0
  194. package/fixtures/cases/date-time-format/library/deals/renewal.md +56 -0
  195. package/fixtures/cases/date-time-format/schema.yaml +55 -0
  196. package/fixtures/cases/declared-binary-links/schema.yaml +1 -0
  197. package/fixtures/cases/default-unfilled/context.json +1 -0
  198. package/fixtures/cases/default-unfilled/expected.json +6 -0
  199. package/fixtures/cases/default-unfilled/library/companies/acme.md +4 -0
  200. package/fixtures/cases/default-unfilled/library/deals/renewal.md +54 -0
  201. package/fixtures/cases/default-unfilled/schema.yaml +55 -0
  202. package/fixtures/cases/defs-pattern/context.json +1 -0
  203. package/fixtures/cases/defs-pattern/expected.json +7 -0
  204. package/fixtures/cases/defs-pattern/library/companies/acme.md +4 -0
  205. package/fixtures/cases/defs-pattern/library/deals/renewal.md +56 -0
  206. package/fixtures/cases/defs-pattern/schema.yaml +55 -0
  207. package/fixtures/cases/dependent-rule/context.json +1 -0
  208. package/fixtures/cases/dependent-rule/expected.json +6 -0
  209. package/fixtures/cases/dependent-rule/library/companies/acme.md +4 -0
  210. package/fixtures/cases/dependent-rule/library/deals/renewal.md +55 -0
  211. package/fixtures/cases/dependent-rule/schema.yaml +55 -0
  212. package/fixtures/cases/duplicate-link-definition/library/item.md +1 -1
  213. package/fixtures/cases/duplicate-link-definition/schema.yaml +5 -0
  214. package/fixtures/cases/email-format/context.json +1 -0
  215. package/fixtures/cases/email-format/expected.json +7 -0
  216. package/fixtures/cases/email-format/library/companies/acme.md +4 -0
  217. package/fixtures/cases/email-format/library/deals/renewal.md +56 -0
  218. package/fixtures/cases/email-format/schema.yaml +55 -0
  219. package/fixtures/cases/equal-labels/context.json +1 -0
  220. package/fixtures/cases/equal-labels/expected.json +5 -0
  221. package/fixtures/cases/equal-labels/schema.yaml +4 -0
  222. package/fixtures/cases/fenced-link-definition/library/item.md +1 -1
  223. package/fixtures/cases/fenced-link-definition/schema.yaml +5 -0
  224. package/fixtures/cases/field-enum/expected.json +3 -3
  225. package/fixtures/cases/field-enum/library/item.md +2 -2
  226. package/fixtures/cases/field-enum/schema.yaml +6 -0
  227. package/fixtures/cases/frontmatter-schema/context.json +1 -0
  228. package/fixtures/cases/frontmatter-schema/expected.json +5 -0
  229. package/fixtures/cases/frontmatter-schema/schema.yaml +5 -0
  230. package/fixtures/cases/integer-field/context.json +1 -0
  231. package/fixtures/cases/integer-field/expected.json +7 -0
  232. package/fixtures/cases/integer-field/library/companies/acme.md +4 -0
  233. package/fixtures/cases/integer-field/library/deals/renewal.md +56 -0
  234. package/fixtures/cases/integer-field/schema.yaml +55 -0
  235. package/fixtures/cases/interrupted-link-definition/schema.yaml +1 -0
  236. package/fixtures/cases/json-schema-constructs/context.json +1 -0
  237. package/fixtures/cases/json-schema-constructs/expected.json +1 -0
  238. package/fixtures/cases/json-schema-constructs/library/companies/acme.md +4 -0
  239. package/fixtures/cases/json-schema-constructs/library/deals/renewal.md +56 -0
  240. package/fixtures/cases/json-schema-constructs/schema.yaml +55 -0
  241. package/fixtures/cases/labels-in-the-rooms-language/context.json +1 -0
  242. package/fixtures/cases/labels-in-the-rooms-language/expected.json +1 -0
  243. package/fixtures/cases/labels-in-the-rooms-language/library/deals/atlas.md +7 -0
  244. package/fixtures/cases/labels-in-the-rooms-language/schema.yaml +9 -0
  245. package/fixtures/cases/lazy-list-item/context.json +1 -0
  246. package/fixtures/cases/lazy-list-item/expected.json +3 -0
  247. package/fixtures/cases/lazy-list-item/library/item.md +10 -0
  248. package/fixtures/cases/lazy-list-item/schema.yaml +3 -0
  249. package/fixtures/cases/link-into-a-reserved-name/context.json +1 -0
  250. package/fixtures/cases/link-into-a-reserved-name/expected.json +5 -0
  251. package/fixtures/cases/link-into-a-reserved-name/library/notes/a.md +6 -0
  252. package/fixtures/cases/link-into-a-reserved-name/schema.yaml +3 -0
  253. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/context.json +1 -0
  254. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/expected.json +5 -0
  255. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/library/notes/b.md +5 -0
  256. package/fixtures/cases/list-item-enum/context.json +1 -0
  257. package/fixtures/cases/list-item-enum/expected.json +7 -0
  258. package/fixtures/cases/list-item-enum/library/task.md +7 -0
  259. package/fixtures/cases/list-item-enum/schema.yaml +3 -0
  260. package/fixtures/cases/list-item-kind/context.json +1 -0
  261. package/fixtures/cases/list-item-kind/expected.json +7 -0
  262. package/fixtures/cases/list-item-kind/library/task.md +6 -0
  263. package/fixtures/cases/list-item-kind/schema.yaml +3 -0
  264. package/fixtures/cases/list-items/context.json +1 -0
  265. package/fixtures/cases/list-items/expected.json +1 -0
  266. package/fixtures/cases/list-items/library/other.md +3 -0
  267. package/fixtures/cases/list-items/library/page.md +26 -0
  268. package/fixtures/cases/list-items/schema.yaml +10 -0
  269. package/fixtures/cases/list-of-objects-closed/context.json +1 -0
  270. package/fixtures/cases/list-of-objects-closed/expected.json +7 -0
  271. package/fixtures/cases/list-of-objects-closed/library/companies/acme.md +4 -0
  272. package/fixtures/cases/list-of-objects-closed/library/deals/renewal.md +56 -0
  273. package/fixtures/cases/list-of-objects-closed/schema.yaml +55 -0
  274. package/fixtures/cases/list-of-objects-item/context.json +1 -0
  275. package/fixtures/cases/list-of-objects-item/expected.json +7 -0
  276. package/fixtures/cases/list-of-objects-item/library/companies/acme.md +4 -0
  277. package/fixtures/cases/list-of-objects-item/library/deals/renewal.md +56 -0
  278. package/fixtures/cases/list-of-objects-item/schema.yaml +55 -0
  279. package/fixtures/cases/list-of-objects-reference/context.json +1 -0
  280. package/fixtures/cases/list-of-objects-reference/expected.json +7 -0
  281. package/fixtures/cases/list-of-objects-reference/library/companies/acme.md +4 -0
  282. package/fixtures/cases/list-of-objects-reference/library/deals/renewal.md +17 -0
  283. package/fixtures/cases/list-of-objects-reference/library/places/depot.md +4 -0
  284. package/fixtures/cases/list-of-objects-reference/library/products/seats.md +4 -0
  285. package/fixtures/cases/list-of-objects-reference/library/products/support.md +4 -0
  286. package/fixtures/cases/list-of-objects-reference/schema.yaml +32 -0
  287. package/fixtures/cases/list-reference-path/context.json +1 -0
  288. package/fixtures/cases/list-reference-path/expected.json +7 -0
  289. package/fixtures/cases/list-reference-path/library/other.md +3 -0
  290. package/fixtures/cases/list-reference-path/library/page.md +5 -0
  291. package/fixtures/cases/list-reference-path/schema.yaml +3 -0
  292. package/fixtures/cases/list-reference-type/context.json +1 -0
  293. package/fixtures/cases/list-reference-type/expected.json +7 -0
  294. package/fixtures/cases/list-reference-type/library/note.md +1 -0
  295. package/fixtures/cases/list-reference-type/library/page.md +6 -0
  296. package/fixtures/cases/list-reference-type/schema.yaml +3 -0
  297. package/fixtures/cases/list-size/context.json +1 -0
  298. package/fixtures/cases/list-size/expected.json +7 -0
  299. package/fixtures/cases/list-size/library/companies/acme.md +4 -0
  300. package/fixtures/cases/list-size/library/deals/renewal.md +58 -0
  301. package/fixtures/cases/list-size/schema.yaml +55 -0
  302. package/fixtures/cases/long-fence-link-definition/schema.yaml +1 -0
  303. package/fixtures/cases/long-value-past-six-levels/context.json +1 -0
  304. package/fixtures/cases/long-value-past-six-levels/expected.json +5 -0
  305. package/fixtures/cases/long-value-past-six-levels/schema.yaml +15 -0
  306. package/fixtures/cases/malformed-definition/expected.json +2 -4
  307. package/fixtures/cases/malformed-definition/schema.yaml +3 -0
  308. package/fixtures/cases/malformed-list/context.json +1 -0
  309. package/fixtures/cases/malformed-list/expected.json +7 -0
  310. package/fixtures/cases/{structured-section → malformed-list}/library/item.md +1 -1
  311. package/fixtures/cases/malformed-list/schema.yaml +6 -0
  312. package/fixtures/cases/member-document/context.json +1 -0
  313. package/fixtures/cases/member-document/expected.json +1 -0
  314. package/fixtures/cases/member-document/library/people/ana.md +5 -0
  315. package/fixtures/cases/member-document/schema.yaml +5 -0
  316. package/fixtures/cases/member-on-an-untyped-document/context.json +1 -0
  317. package/fixtures/cases/member-on-an-untyped-document/expected.json +6 -0
  318. package/fixtures/cases/member-on-an-untyped-document/library/note.md +4 -0
  319. package/fixtures/cases/member-on-another-type/context.json +1 -0
  320. package/fixtures/cases/member-on-another-type/expected.json +6 -0
  321. package/fixtures/cases/member-on-another-type/library/note.md +4 -0
  322. package/fixtures/cases/member-on-another-type/schema.yaml +7 -0
  323. package/fixtures/cases/missing-required-field/expected.json +2 -3
  324. package/fixtures/cases/missing-required-field/library/item.md +1 -1
  325. package/fixtures/cases/missing-required-field/schema.yaml +6 -0
  326. package/fixtures/cases/misspelled-key/context.json +1 -0
  327. package/fixtures/cases/misspelled-key/expected.json +7 -0
  328. package/fixtures/cases/misspelled-key/library/companies/acme.md +4 -0
  329. package/fixtures/cases/misspelled-key/library/deals/renewal.md +57 -0
  330. package/fixtures/cases/misspelled-key/schema.yaml +55 -0
  331. package/fixtures/cases/name-not-a-string/context.json +1 -0
  332. package/fixtures/cases/name-not-a-string/expected.json +5 -0
  333. package/fixtures/cases/name-not-a-string/schema.yaml +5 -0
  334. package/fixtures/cases/nested-defs/context.json +1 -0
  335. package/fixtures/cases/nested-defs/expected.json +7 -0
  336. package/fixtures/cases/nested-defs/library/deal.md +6 -0
  337. package/fixtures/cases/nested-defs/schema.yaml +11 -0
  338. package/fixtures/cases/nested-object-reference/context.json +1 -0
  339. package/fixtures/cases/nested-object-reference/expected.json +7 -0
  340. package/fixtures/cases/nested-object-reference/library/companies/acme.md +4 -0
  341. package/fixtures/cases/nested-object-reference/library/deals/renewal.md +17 -0
  342. package/fixtures/cases/nested-object-reference/library/places/depot.md +4 -0
  343. package/fixtures/cases/nested-object-reference/library/products/seats.md +4 -0
  344. package/fixtures/cases/nested-object-reference/library/products/support.md +4 -0
  345. package/fixtures/cases/nested-object-reference/schema.yaml +32 -0
  346. package/fixtures/cases/nested-reference/context.json +1 -0
  347. package/fixtures/cases/nested-reference/expected.json +1 -0
  348. package/fixtures/cases/nested-reference/library/companies/acme.md +4 -0
  349. package/fixtures/cases/nested-reference/library/deals/renewal.md +18 -0
  350. package/fixtures/cases/nested-reference/library/places/depot.md +4 -0
  351. package/fixtures/cases/nested-reference/library/products/seats.md +4 -0
  352. package/fixtures/cases/nested-reference/library/products/support.md +4 -0
  353. package/fixtures/cases/nested-reference/schema.yaml +32 -0
  354. package/fixtures/cases/nested-required-field/context.json +1 -0
  355. package/fixtures/cases/nested-required-field/expected.json +7 -0
  356. package/fixtures/cases/nested-required-field/library/companies/acme.md +4 -0
  357. package/fixtures/cases/nested-required-field/library/deals/renewal.md +55 -0
  358. package/fixtures/cases/nested-required-field/schema.yaml +55 -0
  359. package/fixtures/cases/numeric-range/context.json +1 -0
  360. package/fixtures/cases/numeric-range/expected.json +7 -0
  361. package/fixtures/cases/numeric-range/library/companies/acme.md +4 -0
  362. package/fixtures/cases/numeric-range/library/deals/renewal.md +56 -0
  363. package/fixtures/cases/numeric-range/schema.yaml +55 -0
  364. package/fixtures/cases/one-key-two-labels/context.json +1 -0
  365. package/fixtures/cases/one-key-two-labels/expected.json +5 -0
  366. package/fixtures/cases/one-key-two-labels/schema.yaml +5 -0
  367. package/fixtures/cases/one-key-two-types/context.json +1 -0
  368. package/fixtures/cases/one-key-two-types/expected.json +5 -0
  369. package/fixtures/cases/one-key-two-types/schema.yaml +4 -0
  370. package/fixtures/cases/one-of-variant/context.json +1 -0
  371. package/fixtures/cases/one-of-variant/expected.json +7 -0
  372. package/fixtures/cases/one-of-variant/library/companies/acme.md +4 -0
  373. package/fixtures/cases/one-of-variant/library/deals/renewal.md +56 -0
  374. package/fixtures/cases/one-of-variant/schema.yaml +55 -0
  375. package/fixtures/cases/other-room-reference/context.json +1 -0
  376. package/fixtures/cases/other-room-reference/expected.json +7 -0
  377. package/fixtures/cases/other-room-reference/library/companies/acme.md +4 -0
  378. package/fixtures/cases/other-room-reference/library/deals/renewal.md +17 -0
  379. package/fixtures/cases/other-room-reference/library/places/depot.md +4 -0
  380. package/fixtures/cases/other-room-reference/library/products/seats.md +4 -0
  381. package/fixtures/cases/other-room-reference/library/products/support.md +4 -0
  382. package/fixtures/cases/other-room-reference/schema.yaml +32 -0
  383. package/fixtures/cases/paragraph-link-definition/schema.yaml +1 -0
  384. package/fixtures/cases/prototype-field/expected.json +3 -3
  385. package/fixtures/cases/prototype-field/library/item.md +2 -2
  386. package/fixtures/cases/prototype-field/schema.yaml +5 -0
  387. package/fixtures/cases/quoted-link-definition/expected.json +1 -2
  388. package/fixtures/cases/quoted-link-definition/library/notes/draft.md +1 -1
  389. package/fixtures/cases/quoted-link-definition/schema.yaml +1 -0
  390. package/fixtures/cases/reference-into-a-reserved-name/context.json +1 -0
  391. package/fixtures/cases/reference-into-a-reserved-name/expected.json +7 -0
  392. package/fixtures/cases/reference-into-a-reserved-name/library/notes/a.md +4 -0
  393. package/fixtures/cases/reference-into-a-reserved-name/library/settings/brief.md +1 -0
  394. package/fixtures/cases/reference-into-a-reserved-name/schema.yaml +3 -0
  395. package/fixtures/cases/referenced-missing-file/expected.json +0 -1
  396. package/fixtures/cases/referenced-missing-file/library/a.md +2 -2
  397. package/fixtures/cases/referenced-missing-file/library/b.md +2 -2
  398. package/fixtures/cases/referenced-missing-file/schema.yaml +10 -0
  399. package/fixtures/cases/remote-ref/context.json +1 -0
  400. package/fixtures/cases/remote-ref/expected.json +5 -0
  401. package/fixtures/cases/remote-ref/schema.yaml +3 -0
  402. package/fixtures/cases/room-md-declares-a-type/context.json +1 -0
  403. package/fixtures/cases/room-md-declares-a-type/expected.json +6 -0
  404. package/fixtures/cases/room-md-declares-a-type/library/ROOM.md +5 -0
  405. package/fixtures/cases/second-member-document/context.json +1 -0
  406. package/fixtures/cases/second-member-document/expected.json +5 -0
  407. package/fixtures/cases/second-member-document/schema.yaml +4 -0
  408. package/fixtures/cases/sections-keyword-refused/context.json +1 -0
  409. package/fixtures/cases/sections-keyword-refused/expected.json +5 -0
  410. package/fixtures/cases/sections-keyword-refused/schema.yaml +6 -0
  411. package/fixtures/cases/shortcut-reference-link/context.json +1 -0
  412. package/fixtures/cases/shortcut-reference-link/expected.json +5 -0
  413. package/fixtures/cases/shortcut-reference-link/library/item.md +10 -0
  414. package/fixtures/cases/shortcut-reference-link/schema.yaml +5 -0
  415. package/fixtures/cases/string-length/context.json +1 -0
  416. package/fixtures/cases/string-length/expected.json +7 -0
  417. package/fixtures/cases/string-length/library/companies/acme.md +4 -0
  418. package/fixtures/cases/string-length/library/deals/renewal.md +56 -0
  419. package/fixtures/cases/string-length/schema.yaml +55 -0
  420. package/fixtures/cases/submission-keys/context.json +1 -0
  421. package/fixtures/cases/submission-keys/expected.json +1 -0
  422. package/fixtures/cases/submission-keys/library/notes/visitor.md +8 -0
  423. package/fixtures/cases/submission-keys/schema.yaml +4 -0
  424. package/fixtures/cases/text-field-kind/context.json +1 -0
  425. package/fixtures/cases/text-field-kind/expected.json +3 -0
  426. package/fixtures/cases/text-field-kind/library/page.md +4 -0
  427. package/fixtures/cases/text-field-kind/schema.yaml +4 -0
  428. package/fixtures/cases/thematic-break-ends-the-values/context.json +1 -0
  429. package/fixtures/cases/thematic-break-ends-the-values/expected.json +1 -0
  430. package/fixtures/cases/thematic-break-ends-the-values/library/item.md +10 -0
  431. package/fixtures/cases/thematic-break-ends-the-values/schema.yaml +3 -0
  432. package/fixtures/cases/truncated-link-definition/expected.json +1 -2
  433. package/fixtures/cases/truncated-link-definition/library/notes/draft.md +1 -1
  434. package/fixtures/cases/truncated-link-definition/schema.yaml +1 -0
  435. package/fixtures/cases/typed-path-names-another-type/context.json +11 -0
  436. package/fixtures/cases/typed-path-names-another-type/expected.json +6 -0
  437. package/fixtures/cases/typed-path-names-another-type/library/settings/prefs/one.md +3 -0
  438. package/fixtures/cases/typed-path-names-another-type/schema.yaml +6 -0
  439. package/fixtures/cases/typed-path-names-its-type/context.json +11 -0
  440. package/fixtures/cases/typed-path-names-its-type/expected.json +3 -0
  441. package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/deeper/two.md +1 -0
  442. package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/one.md +4 -0
  443. package/fixtures/cases/typed-path-names-its-type/schema.yaml +6 -0
  444. package/fixtures/cases/typed-path-names-no-type/context.json +11 -0
  445. package/fixtures/cases/typed-path-names-no-type/expected.json +6 -0
  446. package/fixtures/cases/typed-path-names-no-type/library/settings/prefs/one.md +1 -0
  447. package/fixtures/cases/typed-path-names-no-type/schema.yaml +6 -0
  448. package/fixtures/cases/types-folder-content/context.json +1 -0
  449. package/fixtures/cases/types-folder-content/expected.json +1 -0
  450. package/fixtures/cases/types-folder-content/library/types/task.md +4 -0
  451. package/fixtures/cases/types-folder-content/schema.yaml +4 -0
  452. package/fixtures/cases/unclosed-frontmatter/expected.json +1 -2
  453. package/fixtures/cases/undeclared-field/expected.json +3 -3
  454. package/fixtures/cases/undeclared-field/library/item.md +2 -2
  455. package/fixtures/cases/undeclared-field/schema.yaml +5 -0
  456. package/fixtures/cases/unevaluated-items-closed/context.json +1 -0
  457. package/fixtures/cases/unevaluated-items-closed/expected.json +7 -0
  458. package/fixtures/cases/unevaluated-items-closed/library/trip.md +16 -0
  459. package/fixtures/cases/unevaluated-items-closed/schema.yaml +10 -0
  460. package/fixtures/cases/unknown-type/context.json +1 -0
  461. package/fixtures/cases/unknown-type/expected.json +6 -0
  462. package/fixtures/cases/unknown-type/library/item.md +3 -0
  463. package/fixtures/cases/unknown-type/schema.yaml +3 -0
  464. package/fixtures/cases/unlisted-reference-type/context.json +1 -0
  465. package/fixtures/cases/unlisted-reference-type/expected.json +5 -0
  466. package/fixtures/cases/unlisted-reference-type/schema.yaml +3 -0
  467. package/fixtures/cases/unnamed-typed-path-checks-its-fields/context.json +11 -0
  468. package/fixtures/cases/unnamed-typed-path-checks-its-fields/expected.json +6 -0
  469. package/fixtures/cases/unnamed-typed-path-checks-its-fields/library/rooms/team/tasks/plan.md +5 -0
  470. package/fixtures/cases/unnamed-typed-path-checks-its-fields/schema.yaml +5 -0
  471. package/fixtures/cases/unnamed-typed-path-names-a-type/context.json +11 -0
  472. package/fixtures/cases/unnamed-typed-path-names-a-type/expected.json +6 -0
  473. package/fixtures/cases/unnamed-typed-path-names-a-type/library/rooms/team/tasks/plan.md +7 -0
  474. package/fixtures/cases/unnamed-typed-path-names-a-type/schema.yaml +5 -0
  475. package/fixtures/cases/unnamed-typed-path-reads-its-type/context.json +11 -0
  476. package/fixtures/cases/unnamed-typed-path-reads-its-type/expected.json +3 -0
  477. package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/plan.md +1 -0
  478. package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/tasks/plan.md +6 -0
  479. package/fixtures/cases/unnamed-typed-path-reads-its-type/schema.yaml +5 -0
  480. package/fixtures/cases/unnamed-typed-path-without-a-body/context.json +11 -0
  481. package/fixtures/cases/unnamed-typed-path-without-a-body/expected.json +5 -0
  482. package/fixtures/cases/unnamed-typed-path-without-a-body/library/rooms/team/tasks/plan.md +5 -0
  483. package/fixtures/cases/unnamed-typed-path-without-a-body/schema.yaml +5 -0
  484. package/fixtures/cases/unresolved-link/expected.json +1 -2
  485. package/fixtures/cases/unresolved-link/library/item.md +2 -2
  486. package/fixtures/cases/unresolved-link/schema.yaml +5 -0
  487. package/fixtures/cases/valid-typed-document/library/people/ada.md +1 -1
  488. package/fixtures/cases/valid-typed-document/library/tasks/one.md +11 -11
  489. package/fixtures/cases/valid-typed-document/schema.yaml +15 -0
  490. package/fixtures/cases/wide-item-fence-link/schema.yaml +1 -0
  491. package/fixtures/division.json +454 -0
  492. package/fixtures/forms.json +347 -0
  493. package/fixtures/preamble.json +29 -8
  494. package/fixtures/projection.json +204 -32
  495. package/fixtures/queries.json +1359 -0
  496. package/package.json +20 -13
  497. package/dist/definition.js.map +0 -1
  498. package/dist/document.js.map +0 -1
  499. package/dist/index.js.map +0 -1
  500. package/dist/links.d.ts +0 -25
  501. package/dist/links.d.ts.map +0 -1
  502. package/dist/links.js +0 -380
  503. package/dist/links.js.map +0 -1
  504. package/dist/paths.js.map +0 -1
  505. package/dist/profile.d.ts +0 -6
  506. package/dist/profile.d.ts.map +0 -1
  507. package/dist/profile.js +0 -7
  508. package/dist/profile.js.map +0 -1
  509. package/dist/project.js.map +0 -1
  510. package/dist/refuse.js.map +0 -1
  511. package/dist/schema.js.map +0 -1
  512. package/dist/sections.d.ts +0 -10
  513. package/dist/sections.d.ts.map +0 -1
  514. package/dist/sections.js +0 -79
  515. package/dist/sections.js.map +0 -1
  516. package/dist/types.js.map +0 -1
  517. package/dist/validate.js.map +0 -1
  518. package/dist/version.js.map +0 -1
  519. package/dist/yaml.js.map +0 -1
  520. package/fixtures/cases/binary-any-reference/library/types/note.md +0 -5
  521. package/fixtures/cases/binary-document-collision/library/types/note.md +0 -3
  522. package/fixtures/cases/binary-link-outside-collection/library/types/note.md +0 -3
  523. package/fixtures/cases/binary-prototype-reference/library/types/note.md +0 -5
  524. package/fixtures/cases/binary-typed-reference/library/types/note.md +0 -5
  525. package/fixtures/cases/binary-typed-reference/library/types/person.md +0 -3
  526. package/fixtures/cases/bracketed-link-definition/library/types/task.md +0 -7
  527. package/fixtures/cases/declared-binary-links/library/types/note.md +0 -3
  528. package/fixtures/cases/duplicate-link-definition/library/types/task.md +0 -7
  529. package/fixtures/cases/fenced-link-definition/library/types/task.md +0 -7
  530. package/fixtures/cases/field-enum/library/types/task.md +0 -8
  531. package/fixtures/cases/interrupted-link-definition/library/types/note.md +0 -3
  532. package/fixtures/cases/long-fence-link-definition/library/types/note.md +0 -3
  533. package/fixtures/cases/malformed-definition/library/types/task.md +0 -5
  534. package/fixtures/cases/missing-binary-image/expected.json +0 -6
  535. package/fixtures/cases/missing-binary-image/library/types/note.md +0 -3
  536. package/fixtures/cases/missing-binary-link/expected.json +0 -6
  537. package/fixtures/cases/missing-binary-link/library/types/note.md +0 -3
  538. package/fixtures/cases/missing-required-field/library/types/task.md +0 -8
  539. package/fixtures/cases/missing-section-item-kind/expected.json +0 -7
  540. package/fixtures/cases/missing-section-item-kind/library/types/task.md +0 -7
  541. package/fixtures/cases/paragraph-link-definition/library/types/note.md +0 -3
  542. package/fixtures/cases/prd-definition/library/types/task.md +0 -16
  543. package/fixtures/cases/prototype-field/library/types/task.md +0 -7
  544. package/fixtures/cases/quoted-link-definition/library/types/note.md +0 -3
  545. package/fixtures/cases/referenced-missing-file/library/types/person.md +0 -5
  546. package/fixtures/cases/referenced-missing-file/library/types/task.md +0 -8
  547. package/fixtures/cases/structured-section/expected.json +0 -7
  548. package/fixtures/cases/structured-section/library/types/task.md +0 -8
  549. package/fixtures/cases/truncated-link-definition/library/types/note.md +0 -3
  550. package/fixtures/cases/undeclared-field/library/types/task.md +0 -7
  551. package/fixtures/cases/unresolved-link/library/types/task.md +0 -7
  552. package/fixtures/cases/valid-typed-document/library/types/person.md +0 -5
  553. package/fixtures/cases/valid-typed-document/library/types/task.md +0 -13
  554. package/fixtures/cases/wide-item-fence-link/library/types/note.md +0 -3
  555. package/markdown-syntax-profile.md +0 -9
  556. /package/fixtures/cases/{missing-section-item-kind → absent-link-dangles}/context.json +0 -0
  557. /package/fixtures/cases/{prd-definition → absent-link-dangles}/expected.json +0 -0
  558. /package/fixtures/cases/{prd-definition → absent-optional-field}/context.json +0 -0
  559. /package/fixtures/cases/{structured-section → absolute-link}/context.json +0 -0
  560. /package/fixtures/cases/{missing-binary-image → binary-image-dangles}/context.json +0 -0
  561. /package/fixtures/cases/{missing-binary-image → binary-image-dangles}/library/notes/draft.md +0 -0
  562. /package/fixtures/cases/{missing-binary-link → binary-link-dangles}/context.json +0 -0
  563. /package/fixtures/cases/{missing-binary-link → binary-link-dangles}/library/notes/draft.md +0 -0
package/dist/paths.js CHANGED
@@ -1,17 +1,27 @@
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);
4
11
  }
5
12
  export function join(base, relative) {
6
- if (base === '') return relative;
13
+ if (base === '')
14
+ return relative;
7
15
  return `${base}/${relative}`;
8
16
  }
9
17
  export function normalize(path) {
10
18
  const parts = [];
11
- for (const part of path.split('/')){
12
- if (part === '' || part === '.') continue;
19
+ for (const part of path.split('/')) {
20
+ if (part === '' || part === '.')
21
+ continue;
13
22
  if (part === '..') {
14
- if (parts.length === 0) return null;
23
+ if (parts.length === 0)
24
+ return null;
15
25
  parts.pop();
16
26
  continue;
17
27
  }
@@ -19,41 +29,216 @@ export function normalize(path) {
19
29
  }
20
30
  return parts.join('/');
21
31
  }
22
- export function isTypesPath(path) {
23
- return path === 'types' || path.startsWith('types/');
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
+ };
24
49
  }
25
- export function typeNameFromPath(path) {
26
- const base = path.slice(path.lastIndexOf('/') + 1);
27
- return base.endsWith('.md') ? base.slice(0, -3) : base;
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 };
28
63
  }
29
- export function hrefSuffix(href) {
30
- const trimmed = href.trim();
31
- const match = /[?#]/.exec(trimmed);
32
- return match === null ? '' : trimmed.slice(match.index);
64
+ function unescaped(written) {
65
+ const { text, end } = spelled(written, 0, true);
66
+ return { base: text, suffix: end };
33
67
  }
34
- export function classifyHref(from, href) {
35
- const trimmed = href.trim();
36
- if (trimmed === '' || trimmed.startsWith('#')) return {
37
- kind: 'skip'
38
- };
39
- if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(trimmed)) return {
40
- kind: 'skip'
41
- };
42
- if (trimmed.startsWith('/')) return {
43
- kind: 'invalid'
44
- };
45
- const bare = trimmed.replace(/[?#].*$/, '');
46
- if (bare === '') return {
47
- kind: 'skip'
48
- };
49
- const resolved = normalize(join(dirname(from), bare));
50
- if (resolved === null || resolved === '') return {
51
- kind: 'invalid'
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,
52
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);
98
+ }
99
+ function written(path) {
100
+ let text = '';
101
+ for (let i = 0; i < path.length; i += 1) {
102
+ const char = path[i];
103
+ if (char === '?' || char === '#' || char < ' ')
104
+ text += encodeURIComponent(char);
105
+ else if (char === ' ' && (i === 0 || i === path.length - 1))
106
+ text += '%20';
107
+ else if (char === '%' && PERCENT.test(path.slice(i)))
108
+ text += '%25';
109
+ else if (escapes(path, i))
110
+ text += '%5C';
111
+ else if (char === '&' && referenceAt(path, i) !== null)
112
+ text += '%26';
113
+ else
114
+ text += char;
115
+ }
116
+ return text;
117
+ }
118
+ function roomAt(path) {
119
+ if (!path.startsWith(SHELL_ROOMS))
120
+ return null;
121
+ const rest = path.slice(SHELL_ROOMS.length);
122
+ const slash = rest.indexOf('/');
123
+ const handle = slash === -1 ? rest : rest.slice(0, slash);
124
+ if (handle === '' || handle === '.' || handle === '..')
125
+ return null;
126
+ const within = normalize(slash === -1 ? '' : rest.slice(slash + 1));
127
+ return within === null ? null : { handle, path: within };
128
+ }
129
+ function roomTargetOf(path) {
130
+ const room = roomAt(path);
131
+ return room === null || room.path === '' ? null : room;
132
+ }
133
+ function resolvedOf(from, href) {
134
+ const base = located(href).base;
135
+ if (base === '')
136
+ return { kind: 'skip' };
137
+ if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(base))
138
+ return { kind: 'skip' };
139
+ const path = destinationPath(href);
140
+ if (path === null)
141
+ return { kind: 'invalid' };
142
+ if (path.startsWith('/')) {
143
+ const room = roomAt(path);
144
+ return room === null ? { kind: 'invalid' } : { kind: 'room', ...room };
145
+ }
146
+ const resolved = normalize(join(dirname(from), path));
147
+ return resolved === null ? { kind: 'invalid' } : { kind: 'path', path: resolved };
148
+ }
149
+ export function classifyHref(from, href) {
150
+ const resolved = resolvedOf(from, href);
151
+ return 'path' in resolved && resolved.path === '' ? { kind: 'invalid' } : resolved;
152
+ }
153
+ export function roomTarget(href) {
154
+ const path = destinationPath(href);
155
+ return path === null ? null : roomTargetOf(path);
156
+ }
157
+ export function roomPath(href) {
158
+ const room = roomTarget(href);
159
+ return room === null ? null : `${SHELL_ROOMS}${room.handle}/${room.path}`;
160
+ }
161
+ export function target(from, href) {
162
+ const resolved = classifyHref(from, href);
163
+ return resolved.kind === 'path' ? resolved.path : null;
164
+ }
165
+ export function linkedPath(from, href) {
166
+ const resolved = located(href).base === '' ? { kind: 'path', path: from } : resolvedOf(from, href);
167
+ if (!('path' in resolved))
168
+ return null;
169
+ const written = href.trim();
170
+ const suffix = spelled(written, unescaped(written).suffix, false).text;
171
+ const hash = suffix.indexOf('#');
172
+ const fragment = hash === -1 ? '' : suffix.slice(hash + 1);
53
173
  return {
54
- kind: 'path',
55
- path: resolved
174
+ handle: resolved.kind === 'room' ? resolved.handle : null,
175
+ path: resolved.path,
176
+ fragment: fragment === '' ? null : (decodedRun(fragment) ?? fragment),
56
177
  };
57
178
  }
58
-
59
- //# sourceMappingURL=paths.js.map
179
+ const LINK_KEY = /^\?key=([A-Za-z0-9._~-]+)(?:#|$)/u;
180
+ export function keyedLink(href) {
181
+ const written = href.trim();
182
+ if (!written.includes('?') && !written.includes('&'))
183
+ return null;
184
+ const key = LINK_KEY.exec(spelled(written, unescaped(written).suffix, false).text)?.[1];
185
+ if (key === undefined)
186
+ return null;
187
+ const room = roomTarget(href);
188
+ return room === null ? null : { ...room, key };
189
+ }
190
+ export function keyedDestination(path, key) {
191
+ return `${written(path)}?key=${key}`;
192
+ }
193
+ export function retarget(href, to) {
194
+ const trimmed = href.trim();
195
+ return written(to) + trimmed.slice(unescaped(trimmed).suffix);
196
+ }
197
+ export function relative(from, target) {
198
+ const base = dirname(from)
199
+ .split('/')
200
+ .filter((part) => part !== '');
201
+ const parts = target.split('/');
202
+ let shared = 0;
203
+ while (shared < base.length && shared + 1 < parts.length && base[shared] === parts[shared]) {
204
+ shared += 1;
205
+ }
206
+ const up = Array.from({ length: base.length - shared }, () => '..');
207
+ return [...up, ...parts.slice(shared)].join('/');
208
+ }
209
+ export const SHELL_ROOMS = '/rooms/';
210
+ export function shellTarget(href, handle) {
211
+ const prefix = `${SHELL_ROOMS}${handle}/`;
212
+ const decoded = destinationPath(href);
213
+ if (decoded === null || !decoded.startsWith(prefix))
214
+ return null;
215
+ const path = normalize(decoded.slice(prefix.length));
216
+ return path === null || path === '' ? null : path;
217
+ }
218
+ function fitsBare(to) {
219
+ if (to === '' || to.startsWith('<'))
220
+ return false;
221
+ let depth = 0;
222
+ for (const character of to) {
223
+ if (/[\s\u0000-\u001f\u007f]/.test(character))
224
+ return false;
225
+ if (character === '(')
226
+ depth += 1;
227
+ else if (character === ')') {
228
+ if (depth === 0)
229
+ return false;
230
+ depth -= 1;
231
+ }
232
+ }
233
+ return depth === 0;
234
+ }
235
+ function fitsBrackets(to) {
236
+ return to !== '' && !/[<>\n\r]/.test(to);
237
+ }
238
+ export function destinationText(to, bracketed) {
239
+ if (fitsBare(to))
240
+ return bracketed && fitsBrackets(to) ? `<${to}>` : to;
241
+ if (fitsBrackets(to))
242
+ return `<${to}>`;
243
+ return null;
244
+ }
@@ -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
+ }
package/dist/project.d.ts CHANGED
@@ -1,3 +1,22 @@
1
- import type { Document, Projection, ProjectionContext } from './types.js';
1
+ import type { Document, Extent, Projection, ProjectionContext, Refusal } from './types.js';
2
+ export type Piece = Extent & {
3
+ readonly text: string;
4
+ };
5
+ export type Edit = Piece;
6
+ export type Input = {
7
+ readonly values: readonly Piece[];
8
+ readonly ranges: readonly Extent[];
9
+ readonly edits: readonly Edit[];
10
+ };
11
+ export type InputResult = {
12
+ readonly ok: true;
13
+ readonly input: Input;
14
+ } | {
15
+ readonly ok: false;
16
+ readonly refusal: Refusal;
17
+ };
18
+ export declare function firstEditFrom(edits: readonly Edit[], start: number): number;
19
+ export declare function rangeText(content: string, range: Extent, edits: readonly Edit[]): string;
20
+ export declare function projectionInput(document: Document, file: string, context: ProjectionContext): InputResult;
2
21
  export declare function project(document: Document, file: string, context?: ProjectionContext): Projection;
3
22
  //# sourceMappingURL=project.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAgE1E,wBAAgB,OAAO,CACrB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,iBAA2C,GACnD,UAAU,CA2BZ"}
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG3F,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD,MAAM,MAAM,IAAI,GAAG,KAAK,CAAC;AAEzB,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAC5C;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAqCtD,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAS3E;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,MAAM,CAWxF;AAOD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,GACzB,WAAW,CA4Bb;AAED,wBAAgB,OAAO,CACrB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,iBAA2C,GACnD,UAAU,CAMZ"}