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

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 (320) hide show
  1. package/API.md +300 -0
  2. package/README.md +34 -189
  3. package/dist/blocks.d.ts +11 -0
  4. package/dist/blocks.d.ts.map +1 -0
  5. package/dist/blocks.js +62 -0
  6. package/dist/condition.d.ts +137 -0
  7. package/dist/condition.d.ts.map +1 -0
  8. package/dist/condition.js +394 -0
  9. package/dist/definition.d.ts +42 -27
  10. package/dist/definition.d.ts.map +1 -1
  11. package/dist/definition.js +473 -152
  12. package/dist/divide.d.ts +3 -0
  13. package/dist/divide.d.ts.map +1 -0
  14. package/dist/divide.js +310 -0
  15. package/dist/document.d.ts +2 -0
  16. package/dist/document.d.ts.map +1 -1
  17. package/dist/document.js +89 -120
  18. package/dist/fields.d.ts +4 -0
  19. package/dist/fields.d.ts.map +1 -0
  20. package/dist/fields.js +3 -0
  21. package/dist/index.d.ts +9 -2
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +6 -3
  24. package/dist/links.d.ts +1 -0
  25. package/dist/links.d.ts.map +1 -1
  26. package/dist/links.js +618 -224
  27. package/dist/paths.d.ts +2 -3
  28. package/dist/paths.d.ts.map +1 -1
  29. package/dist/paths.js +27 -37
  30. package/dist/profile.js +1 -3
  31. package/dist/project.d.ts +19 -1
  32. package/dist/project.d.ts.map +1 -1
  33. package/dist/project.js +77 -94
  34. package/dist/refuse.d.ts.map +1 -1
  35. package/dist/refuse.js +2 -10
  36. package/dist/schema.d.ts +7 -5
  37. package/dist/schema.d.ts.map +1 -1
  38. package/dist/schema.js +156 -41
  39. package/dist/sections.d.ts +2 -1
  40. package/dist/sections.d.ts.map +1 -1
  41. package/dist/sections.js +44 -66
  42. package/dist/types.d.ts +30 -2
  43. package/dist/types.d.ts.map +1 -1
  44. package/dist/types.js +1 -3
  45. package/dist/validate.d.ts +3 -2
  46. package/dist/validate.d.ts.map +1 -1
  47. package/dist/validate.js +138 -141
  48. package/dist/version.d.ts +1 -1
  49. package/dist/version.d.ts.map +1 -1
  50. package/dist/version.js +1 -3
  51. package/dist/yaml.d.ts +2 -0
  52. package/dist/yaml.d.ts.map +1 -1
  53. package/dist/yaml.js +254 -190
  54. package/fixtures/README.md +85 -56
  55. package/fixtures/cases/absent-optional-field/library/companies/acme.md +4 -0
  56. package/fixtures/cases/absent-optional-field/library/deals/lead.md +6 -0
  57. package/fixtures/cases/absent-optional-field/schema.yaml +56 -0
  58. package/fixtures/cases/binary-any-reference/expected.json +1 -2
  59. package/fixtures/cases/binary-any-reference/schema.yaml +4 -0
  60. package/fixtures/cases/binary-document-collision/expected.json +1 -2
  61. package/fixtures/cases/binary-document-collision/schema.yaml +1 -0
  62. package/fixtures/cases/binary-link-outside-collection/expected.json +1 -2
  63. package/fixtures/cases/binary-link-outside-collection/schema.yaml +1 -0
  64. package/fixtures/cases/binary-prototype-reference/expected.json +1 -2
  65. package/fixtures/cases/binary-prototype-reference/schema.yaml +4 -0
  66. package/fixtures/cases/binary-typed-reference/expected.json +1 -2
  67. package/fixtures/cases/binary-typed-reference/schema.yaml +5 -0
  68. package/fixtures/cases/boolean-field/context.json +1 -0
  69. package/fixtures/cases/boolean-field/expected.json +6 -0
  70. package/fixtures/cases/boolean-field/library/companies/acme.md +4 -0
  71. package/fixtures/cases/boolean-field/library/deals/renewal.md +31 -0
  72. package/fixtures/cases/boolean-field/schema.yaml +56 -0
  73. package/fixtures/cases/bracketed-link-definition/schema.yaml +6 -0
  74. package/fixtures/cases/closed-nested-object/context.json +1 -0
  75. package/fixtures/cases/closed-nested-object/expected.json +6 -0
  76. package/fixtures/cases/closed-nested-object/library/companies/acme.md +4 -0
  77. package/fixtures/cases/closed-nested-object/library/deals/renewal.md +32 -0
  78. package/fixtures/cases/closed-nested-object/schema.yaml +56 -0
  79. package/fixtures/cases/composed-root-reference/context.json +1 -0
  80. package/fixtures/cases/composed-root-reference/expected.json +6 -0
  81. package/fixtures/cases/composed-root-reference/library/a.md +5 -0
  82. package/fixtures/cases/composed-root-reference/schema.yaml +13 -0
  83. package/fixtures/cases/date-time-format/context.json +1 -0
  84. package/fixtures/cases/date-time-format/expected.json +6 -0
  85. package/fixtures/cases/date-time-format/library/companies/acme.md +4 -0
  86. package/fixtures/cases/date-time-format/library/deals/renewal.md +31 -0
  87. package/fixtures/cases/date-time-format/schema.yaml +56 -0
  88. package/fixtures/cases/declared-binary-links/schema.yaml +1 -0
  89. package/fixtures/cases/default-unfilled/context.json +1 -0
  90. package/fixtures/cases/default-unfilled/expected.json +6 -0
  91. package/fixtures/cases/default-unfilled/library/companies/acme.md +4 -0
  92. package/fixtures/cases/default-unfilled/library/deals/renewal.md +29 -0
  93. package/fixtures/cases/default-unfilled/schema.yaml +56 -0
  94. package/fixtures/cases/defs-pattern/context.json +1 -0
  95. package/fixtures/cases/defs-pattern/expected.json +6 -0
  96. package/fixtures/cases/defs-pattern/library/companies/acme.md +4 -0
  97. package/fixtures/cases/defs-pattern/library/deals/renewal.md +31 -0
  98. package/fixtures/cases/defs-pattern/schema.yaml +56 -0
  99. package/fixtures/cases/dependent-rule/context.json +1 -0
  100. package/fixtures/cases/dependent-rule/expected.json +6 -0
  101. package/fixtures/cases/dependent-rule/library/companies/acme.md +4 -0
  102. package/fixtures/cases/dependent-rule/library/deals/renewal.md +30 -0
  103. package/fixtures/cases/dependent-rule/schema.yaml +56 -0
  104. package/fixtures/cases/duplicate-link-definition/schema.yaml +6 -0
  105. package/fixtures/cases/email-format/context.json +1 -0
  106. package/fixtures/cases/email-format/expected.json +6 -0
  107. package/fixtures/cases/email-format/library/companies/acme.md +4 -0
  108. package/fixtures/cases/email-format/library/deals/renewal.md +31 -0
  109. package/fixtures/cases/email-format/schema.yaml +56 -0
  110. package/fixtures/cases/fenced-link-definition/schema.yaml +6 -0
  111. package/fixtures/cases/field-enum/expected.json +2 -3
  112. package/fixtures/cases/field-enum/schema.yaml +7 -0
  113. package/fixtures/cases/frontmatter-schema/context.json +1 -0
  114. package/fixtures/cases/frontmatter-schema/expected.json +5 -0
  115. package/fixtures/cases/frontmatter-schema/schema.yaml +5 -0
  116. package/fixtures/cases/integer-field/context.json +1 -0
  117. package/fixtures/cases/integer-field/expected.json +6 -0
  118. package/fixtures/cases/integer-field/library/companies/acme.md +4 -0
  119. package/fixtures/cases/integer-field/library/deals/renewal.md +31 -0
  120. package/fixtures/cases/integer-field/schema.yaml +56 -0
  121. package/fixtures/cases/interrupted-link-definition/schema.yaml +1 -0
  122. package/fixtures/cases/json-schema-constructs/context.json +1 -0
  123. package/fixtures/cases/json-schema-constructs/expected.json +1 -0
  124. package/fixtures/cases/json-schema-constructs/library/companies/acme.md +4 -0
  125. package/fixtures/cases/json-schema-constructs/library/deals/renewal.md +31 -0
  126. package/fixtures/cases/json-schema-constructs/schema.yaml +56 -0
  127. package/fixtures/cases/list-of-objects-closed/context.json +1 -0
  128. package/fixtures/cases/list-of-objects-closed/expected.json +6 -0
  129. package/fixtures/cases/list-of-objects-closed/library/companies/acme.md +4 -0
  130. package/fixtures/cases/list-of-objects-closed/library/deals/renewal.md +32 -0
  131. package/fixtures/cases/list-of-objects-closed/schema.yaml +56 -0
  132. package/fixtures/cases/list-of-objects-item/context.json +1 -0
  133. package/fixtures/cases/list-of-objects-item/expected.json +6 -0
  134. package/fixtures/cases/list-of-objects-item/library/companies/acme.md +4 -0
  135. package/fixtures/cases/list-of-objects-item/library/deals/renewal.md +31 -0
  136. package/fixtures/cases/list-of-objects-item/schema.yaml +56 -0
  137. package/fixtures/cases/list-size/context.json +1 -0
  138. package/fixtures/cases/list-size/expected.json +6 -0
  139. package/fixtures/cases/list-size/library/companies/acme.md +4 -0
  140. package/fixtures/cases/list-size/library/deals/renewal.md +31 -0
  141. package/fixtures/cases/list-size/schema.yaml +56 -0
  142. package/fixtures/cases/long-fence-link-definition/schema.yaml +1 -0
  143. package/fixtures/cases/malformed-definition/expected.json +2 -4
  144. package/fixtures/cases/malformed-definition/schema.yaml +3 -0
  145. package/fixtures/cases/member-document/context.json +1 -0
  146. package/fixtures/cases/member-document/expected.json +1 -0
  147. package/fixtures/cases/member-document/library/people/ana.md +5 -0
  148. package/fixtures/cases/member-document/schema.yaml +5 -0
  149. package/fixtures/cases/missing-binary-image/expected.json +1 -2
  150. package/fixtures/cases/missing-binary-image/schema.yaml +1 -0
  151. package/fixtures/cases/missing-binary-link/expected.json +1 -2
  152. package/fixtures/cases/missing-binary-link/schema.yaml +1 -0
  153. package/fixtures/cases/missing-required-field/expected.json +2 -3
  154. package/fixtures/cases/missing-required-field/schema.yaml +7 -0
  155. package/fixtures/cases/missing-section-item-kind/expected.json +2 -4
  156. package/fixtures/cases/missing-section-item-kind/schema.yaml +6 -0
  157. package/fixtures/cases/misspelled-key/context.json +1 -0
  158. package/fixtures/cases/misspelled-key/expected.json +6 -0
  159. package/fixtures/cases/misspelled-key/library/companies/acme.md +4 -0
  160. package/fixtures/cases/misspelled-key/library/deals/renewal.md +32 -0
  161. package/fixtures/cases/misspelled-key/schema.yaml +56 -0
  162. package/fixtures/cases/nested-defs/context.json +1 -0
  163. package/fixtures/cases/nested-defs/expected.json +6 -0
  164. package/fixtures/cases/nested-defs/library/deal.md +6 -0
  165. package/fixtures/cases/nested-defs/schema.yaml +11 -0
  166. package/fixtures/cases/nested-required-field/context.json +1 -0
  167. package/fixtures/cases/nested-required-field/expected.json +6 -0
  168. package/fixtures/cases/nested-required-field/library/companies/acme.md +4 -0
  169. package/fixtures/cases/nested-required-field/library/deals/renewal.md +30 -0
  170. package/fixtures/cases/nested-required-field/schema.yaml +56 -0
  171. package/fixtures/cases/null-refused/context.json +1 -0
  172. package/fixtures/cases/null-refused/expected.json +6 -0
  173. package/fixtures/cases/null-refused/library/companies/acme.md +4 -0
  174. package/fixtures/cases/null-refused/library/deals/renewal.md +31 -0
  175. package/fixtures/cases/null-refused/schema.yaml +56 -0
  176. package/fixtures/cases/numeric-range/context.json +1 -0
  177. package/fixtures/cases/numeric-range/expected.json +6 -0
  178. package/fixtures/cases/numeric-range/library/companies/acme.md +4 -0
  179. package/fixtures/cases/numeric-range/library/deals/renewal.md +31 -0
  180. package/fixtures/cases/numeric-range/schema.yaml +56 -0
  181. package/fixtures/cases/one-of-variant/context.json +1 -0
  182. package/fixtures/cases/one-of-variant/expected.json +6 -0
  183. package/fixtures/cases/one-of-variant/library/companies/acme.md +4 -0
  184. package/fixtures/cases/one-of-variant/library/deals/renewal.md +31 -0
  185. package/fixtures/cases/one-of-variant/schema.yaml +56 -0
  186. package/fixtures/cases/open-map-value/context.json +1 -0
  187. package/fixtures/cases/open-map-value/expected.json +6 -0
  188. package/fixtures/cases/open-map-value/library/companies/acme.md +4 -0
  189. package/fixtures/cases/open-map-value/library/deals/renewal.md +31 -0
  190. package/fixtures/cases/open-map-value/schema.yaml +56 -0
  191. package/fixtures/cases/paragraph-link-definition/schema.yaml +1 -0
  192. package/fixtures/cases/prototype-field/expected.json +2 -3
  193. package/fixtures/cases/prototype-field/schema.yaml +6 -0
  194. package/fixtures/cases/quoted-link-definition/expected.json +1 -2
  195. package/fixtures/cases/quoted-link-definition/schema.yaml +1 -0
  196. package/fixtures/cases/referenced-missing-file/expected.json +0 -1
  197. package/fixtures/cases/referenced-missing-file/schema.yaml +11 -0
  198. package/fixtures/cases/remote-ref/context.json +1 -0
  199. package/fixtures/cases/remote-ref/expected.json +5 -0
  200. package/fixtures/cases/remote-ref/schema.yaml +3 -0
  201. package/fixtures/cases/second-member-document/context.json +1 -0
  202. package/fixtures/cases/second-member-document/expected.json +5 -0
  203. package/fixtures/cases/second-member-document/schema.yaml +4 -0
  204. package/fixtures/cases/section-item-enum/context.json +1 -0
  205. package/fixtures/cases/section-item-enum/expected.json +6 -0
  206. package/fixtures/cases/section-item-enum/library/task.md +8 -0
  207. package/fixtures/cases/section-item-enum/schema.yaml +3 -0
  208. package/fixtures/cases/section-item-kind/context.json +1 -0
  209. package/fixtures/cases/section-item-kind/expected.json +6 -0
  210. package/fixtures/cases/section-item-kind/library/task.md +8 -0
  211. package/fixtures/cases/section-item-kind/schema.yaml +3 -0
  212. package/fixtures/cases/section-items/context.json +1 -0
  213. package/fixtures/cases/section-items/expected.json +1 -0
  214. package/fixtures/cases/section-items/library/other.md +3 -0
  215. package/fixtures/cases/section-items/library/page.md +42 -0
  216. package/fixtures/cases/section-items/schema.yaml +10 -0
  217. package/fixtures/cases/section-reference-path/context.json +1 -0
  218. package/fixtures/cases/section-reference-path/expected.json +6 -0
  219. package/fixtures/cases/section-reference-path/library/other.md +3 -0
  220. package/fixtures/cases/section-reference-path/library/page.md +7 -0
  221. package/fixtures/cases/section-reference-path/schema.yaml +3 -0
  222. package/fixtures/cases/section-reference-type/context.json +1 -0
  223. package/fixtures/cases/section-reference-type/expected.json +6 -0
  224. package/fixtures/cases/section-reference-type/library/note.md +1 -0
  225. package/fixtures/cases/section-reference-type/library/page.md +7 -0
  226. package/fixtures/cases/section-reference-type/schema.yaml +3 -0
  227. package/fixtures/cases/shortcut-reference-link/context.json +1 -0
  228. package/fixtures/cases/shortcut-reference-link/expected.json +5 -0
  229. package/fixtures/cases/shortcut-reference-link/library/item.md +10 -0
  230. package/fixtures/cases/shortcut-reference-link/schema.yaml +6 -0
  231. package/fixtures/cases/string-length/context.json +1 -0
  232. package/fixtures/cases/string-length/expected.json +6 -0
  233. package/fixtures/cases/string-length/library/companies/acme.md +4 -0
  234. package/fixtures/cases/string-length/library/deals/renewal.md +31 -0
  235. package/fixtures/cases/string-length/schema.yaml +56 -0
  236. package/fixtures/cases/structured-section/expected.json +1 -2
  237. package/fixtures/cases/structured-section/schema.yaml +7 -0
  238. package/fixtures/cases/submission-keys/context.json +1 -0
  239. package/fixtures/cases/submission-keys/expected.json +1 -0
  240. package/fixtures/cases/submission-keys/library/notes/visitor.md +8 -0
  241. package/fixtures/cases/submission-keys/schema.yaml +4 -0
  242. package/fixtures/cases/text-field-kind/context.json +1 -0
  243. package/fixtures/cases/text-field-kind/expected.json +6 -0
  244. package/fixtures/cases/text-field-kind/library/page.md +4 -0
  245. package/fixtures/cases/text-field-kind/schema.yaml +4 -0
  246. package/fixtures/cases/truncated-link-definition/expected.json +1 -2
  247. package/fixtures/cases/truncated-link-definition/schema.yaml +1 -0
  248. package/fixtures/cases/types-folder-content/context.json +1 -0
  249. package/fixtures/cases/types-folder-content/expected.json +1 -0
  250. package/fixtures/cases/types-folder-content/library/types/task.md +4 -0
  251. package/fixtures/cases/types-folder-content/schema.yaml +4 -0
  252. package/fixtures/cases/unclosed-frontmatter/expected.json +1 -2
  253. package/fixtures/cases/undeclared-field/expected.json +2 -3
  254. package/fixtures/cases/undeclared-field/schema.yaml +6 -0
  255. package/fixtures/cases/unevaluated-items-closed/context.json +1 -0
  256. package/fixtures/cases/unevaluated-items-closed/expected.json +6 -0
  257. package/fixtures/cases/unevaluated-items-closed/library/trip.md +6 -0
  258. package/fixtures/cases/unevaluated-items-closed/schema.yaml +10 -0
  259. package/fixtures/cases/unknown-type/context.json +1 -0
  260. package/fixtures/cases/unknown-type/expected.json +6 -0
  261. package/fixtures/cases/unknown-type/library/item.md +3 -0
  262. package/fixtures/cases/unknown-type/schema.yaml +3 -0
  263. package/fixtures/cases/unlisted-reference-type/context.json +1 -0
  264. package/fixtures/cases/unlisted-reference-type/expected.json +5 -0
  265. package/fixtures/cases/unlisted-reference-type/schema.yaml +3 -0
  266. package/fixtures/cases/unresolved-link/expected.json +1 -2
  267. package/fixtures/cases/unresolved-link/schema.yaml +6 -0
  268. package/fixtures/cases/valid-typed-document/schema.yaml +16 -0
  269. package/fixtures/cases/wide-item-fence-link/schema.yaml +1 -0
  270. package/fixtures/division.json +409 -0
  271. package/fixtures/projection.json +90 -21
  272. package/package.json +3 -12
  273. package/dist/definition.js.map +0 -1
  274. package/dist/document.js.map +0 -1
  275. package/dist/index.js.map +0 -1
  276. package/dist/links.js.map +0 -1
  277. package/dist/paths.js.map +0 -1
  278. package/dist/profile.js.map +0 -1
  279. package/dist/project.js.map +0 -1
  280. package/dist/refuse.js.map +0 -1
  281. package/dist/schema.js.map +0 -1
  282. package/dist/sections.js.map +0 -1
  283. package/dist/types.js.map +0 -1
  284. package/dist/validate.js.map +0 -1
  285. package/dist/version.js.map +0 -1
  286. package/dist/yaml.js.map +0 -1
  287. package/fixtures/cases/binary-any-reference/library/types/note.md +0 -5
  288. package/fixtures/cases/binary-document-collision/library/types/note.md +0 -3
  289. package/fixtures/cases/binary-link-outside-collection/library/types/note.md +0 -3
  290. package/fixtures/cases/binary-prototype-reference/library/types/note.md +0 -5
  291. package/fixtures/cases/binary-typed-reference/library/types/note.md +0 -5
  292. package/fixtures/cases/binary-typed-reference/library/types/person.md +0 -3
  293. package/fixtures/cases/bracketed-link-definition/library/types/task.md +0 -7
  294. package/fixtures/cases/declared-binary-links/library/types/note.md +0 -3
  295. package/fixtures/cases/duplicate-link-definition/library/types/task.md +0 -7
  296. package/fixtures/cases/fenced-link-definition/library/types/task.md +0 -7
  297. package/fixtures/cases/field-enum/library/types/task.md +0 -8
  298. package/fixtures/cases/interrupted-link-definition/library/types/note.md +0 -3
  299. package/fixtures/cases/long-fence-link-definition/library/types/note.md +0 -3
  300. package/fixtures/cases/malformed-definition/library/types/task.md +0 -5
  301. package/fixtures/cases/missing-binary-image/library/types/note.md +0 -3
  302. package/fixtures/cases/missing-binary-link/library/types/note.md +0 -3
  303. package/fixtures/cases/missing-required-field/library/types/task.md +0 -8
  304. package/fixtures/cases/missing-section-item-kind/library/types/task.md +0 -7
  305. package/fixtures/cases/paragraph-link-definition/library/types/note.md +0 -3
  306. package/fixtures/cases/prd-definition/library/types/task.md +0 -16
  307. package/fixtures/cases/prototype-field/library/types/task.md +0 -7
  308. package/fixtures/cases/quoted-link-definition/library/types/note.md +0 -3
  309. package/fixtures/cases/referenced-missing-file/library/types/person.md +0 -5
  310. package/fixtures/cases/referenced-missing-file/library/types/task.md +0 -8
  311. package/fixtures/cases/structured-section/library/types/task.md +0 -8
  312. package/fixtures/cases/truncated-link-definition/library/types/note.md +0 -3
  313. package/fixtures/cases/undeclared-field/library/types/task.md +0 -7
  314. package/fixtures/cases/unresolved-link/library/types/task.md +0 -7
  315. package/fixtures/cases/valid-typed-document/library/types/person.md +0 -5
  316. package/fixtures/cases/valid-typed-document/library/types/task.md +0 -13
  317. package/fixtures/cases/wide-item-fence-link/library/types/note.md +0 -3
  318. package/markdown-syntax-profile.md +0 -9
  319. /package/fixtures/cases/{prd-definition → absent-optional-field}/context.json +0 -0
  320. /package/fixtures/cases/{prd-definition → absent-optional-field}/expected.json +0 -0
package/dist/paths.d.ts CHANGED
@@ -1,9 +1,6 @@
1
1
  export declare function dirname(path: string): string;
2
2
  export declare function join(base: string, relative: string): string;
3
3
  export declare function normalize(path: string): string | null;
4
- export declare function isTypesPath(path: string): boolean;
5
- export declare function typeNameFromPath(path: string): string;
6
- export declare function hrefSuffix(href: string): string;
7
4
  export declare function classifyHref(from: string, href: string): {
8
5
  kind: 'skip';
9
6
  } | {
@@ -12,4 +9,6 @@ export declare function classifyHref(from: string, href: string): {
12
9
  } | {
13
10
  kind: 'invalid';
14
11
  };
12
+ export declare function target(from: string, href: string): string | null;
13
+ export declare function retarget(href: string, to: string): string;
15
14
  //# sourceMappingURL=paths.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG5C;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG3D;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYrD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI/C;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAUzE"}
1
+ {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG5C;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG3D;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYrD;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAUzE;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGhE;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAIzD"}
package/dist/paths.js CHANGED
@@ -3,15 +3,18 @@ export function dirname(path) {
3
3
  return index === -1 ? '' : path.slice(0, index);
4
4
  }
5
5
  export function join(base, relative) {
6
- if (base === '') return relative;
6
+ if (base === '')
7
+ return relative;
7
8
  return `${base}/${relative}`;
8
9
  }
9
10
  export function normalize(path) {
10
11
  const parts = [];
11
- for (const part of path.split('/')){
12
- if (part === '' || part === '.') continue;
12
+ for (const part of path.split('/')) {
13
+ if (part === '' || part === '.')
14
+ continue;
13
15
  if (part === '..') {
14
- if (parts.length === 0) return null;
16
+ if (parts.length === 0)
17
+ return null;
15
18
  parts.pop();
16
19
  continue;
17
20
  }
@@ -19,41 +22,28 @@ export function normalize(path) {
19
22
  }
20
23
  return parts.join('/');
21
24
  }
22
- export function isTypesPath(path) {
23
- return path === 'types' || path.startsWith('types/');
24
- }
25
- export function typeNameFromPath(path) {
26
- const base = path.slice(path.lastIndexOf('/') + 1);
27
- return base.endsWith('.md') ? base.slice(0, -3) : base;
28
- }
29
- export function hrefSuffix(href) {
30
- const trimmed = href.trim();
31
- const match = /[?#]/.exec(trimmed);
32
- return match === null ? '' : trimmed.slice(match.index);
33
- }
34
25
  export function classifyHref(from, href) {
35
26
  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
- };
27
+ if (trimmed === '' || trimmed.startsWith('#'))
28
+ return { kind: 'skip' };
29
+ if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(trimmed))
30
+ return { kind: 'skip' };
31
+ if (trimmed.startsWith('/'))
32
+ return { kind: 'invalid' };
45
33
  const bare = trimmed.replace(/[?#].*$/, '');
46
- if (bare === '') return {
47
- kind: 'skip'
48
- };
34
+ if (bare === '')
35
+ return { kind: 'skip' };
49
36
  const resolved = normalize(join(dirname(from), bare));
50
- if (resolved === null || resolved === '') return {
51
- kind: 'invalid'
52
- };
53
- return {
54
- kind: 'path',
55
- path: resolved
56
- };
37
+ if (resolved === null || resolved === '')
38
+ return { kind: 'invalid' };
39
+ return { kind: 'path', path: resolved };
40
+ }
41
+ export function target(from, href) {
42
+ const resolved = classifyHref(from, href);
43
+ return resolved.kind === 'path' ? resolved.path : null;
44
+ }
45
+ export function retarget(href, to) {
46
+ const trimmed = href.trim();
47
+ const match = /[?#]/.exec(trimmed);
48
+ return match === null ? to : to + trimmed.slice(match.index);
57
49
  }
58
-
59
- //# sourceMappingURL=paths.js.map
package/dist/profile.js CHANGED
@@ -1,7 +1,5 @@
1
1
  export const MARKDOWN_SYNTAX_PROFILE = {
2
2
  name: 'GitHub Flavored Markdown',
3
3
  spec: '0.29',
4
- url: 'https://github.github.com/gfm/'
4
+ url: 'https://github.github.com/gfm/',
5
5
  };
6
-
7
- //# sourceMappingURL=profile.js.map
package/dist/project.d.ts CHANGED
@@ -1,3 +1,21 @@
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 rangeText(content: string, range: Extent, edits: readonly Edit[]): string;
19
+ export declare function projectionInput(document: Document, file: string, context: ProjectionContext): InputResult;
2
20
  export declare function project(document: Document, file: string, context?: ProjectionContext): Projection;
3
21
  //# 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":"AAMA,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;AAmCtD,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,MAAM,CASxF;AA4BD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,GACzB,WAAW,CAyBb;AAED,wBAAgB,OAAO,CACrB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,iBAA2C,GACnD,UAAU,CAMZ"}
package/dist/project.js CHANGED
@@ -1,122 +1,105 @@
1
- import { readDefinition } from './definition.js';
2
- import { parse } from './document.js';
1
+ import { memberFacts } from './definition.js';
2
+ import { frontmatter } from './document.js';
3
3
  import { linkInventory } from './links.js';
4
- import { classifyHref } from './paths.js';
4
+ import { target } from './paths.js';
5
5
  import { refusal } from './refuse.js';
6
6
  import { headingSpans } from './sections.js';
7
7
  import { bodyStartOf } from './yaml.js';
8
- function internalEdits(body, file, documentTargets) {
9
- const inventory = linkInventory(body);
8
+ function internalEdits(content, bodyStart, file, documentTargets) {
9
+ const inventory = linkInventory(content.slice(bodyStart));
10
10
  const internal = new Set();
11
11
  const edits = [];
12
- for (const use of inventory.uses){
13
- const resolved = classifyHref(file, use.destination.href);
14
- if (resolved.kind !== 'path' || !documentTargets.has(resolved.path)) continue;
12
+ const uses = [...inventory.uses].sort((left, right) => left.end - left.start - (right.end - right.start));
13
+ for (const use of uses) {
14
+ const resolved = target(file, use.destination.href);
15
+ if (resolved === null || !documentTargets.has(resolved))
16
+ continue;
15
17
  internal.add(use.destination.start);
18
+ const label = { start: bodyStart + use.labelStart, end: bodyStart + use.labelEnd };
19
+ const inner = edits
20
+ .filter((edit) => edit.start >= label.start && edit.end <= label.end)
21
+ .sort((left, right) => left.start - right.start);
16
22
  edits.push({
17
- start: use.start,
18
- end: use.end,
19
- text: body.slice(use.labelStart, use.labelEnd)
23
+ start: bodyStart + use.start,
24
+ end: bodyStart + use.end,
25
+ text: rangeText(content, label, inner),
20
26
  });
21
27
  }
22
- for (const block of inventory.blocks){
23
- if (!internal.has(block.destination.start)) continue;
24
- edits.push({
25
- start: block.start,
26
- end: block.end,
27
- text: ''
28
- });
28
+ for (const block of inventory.blocks) {
29
+ if (!internal.has(block.destination.start))
30
+ continue;
31
+ edits.push({ start: bodyStart + block.start, end: bodyStart + block.end, text: '' });
29
32
  }
30
- return edits.sort((left, right)=>left.start - right.start);
33
+ return edits.sort((left, right) => left.start - right.start);
31
34
  }
32
- function projected(body, spans, edits) {
35
+ export function rangeText(content, range, edits) {
33
36
  let text = '';
34
- for (const [from, to] of spans){
35
- let cursor = from;
36
- for (const edit of edits){
37
- if (edit.start < cursor || edit.end > to) continue;
38
- text += body.slice(cursor, edit.start) + edit.text;
39
- cursor = edit.end;
40
- }
41
- text += body.slice(cursor, to);
37
+ let cursor = range.start;
38
+ for (const edit of edits) {
39
+ if (edit.start < cursor || edit.end > range.end)
40
+ continue;
41
+ text += content.slice(cursor, edit.start) + edit.text;
42
+ cursor = edit.end;
42
43
  }
43
- return text;
44
+ return text + content.slice(cursor, range.end);
44
45
  }
45
46
  function structural(spec) {
46
- return spec.kind === 'list' && spec.of.kind !== 'text';
47
+ return spec.kind === 'list' && !spec.items.prose;
47
48
  }
48
- function freeText(definition, fields) {
49
- let text = '';
50
- for (const [name, spec] of Object.entries(definition.fields)){
51
- const value = fields[name];
52
- if (spec.kind === 'text') {
53
- if (typeof value === 'string') text += `${value}\n\n`;
54
- continue;
55
- }
56
- if (spec.kind !== 'list' || spec.of.kind !== 'text' || !Array.isArray(value)) continue;
57
- for (const item of value)if (typeof item === 'string') text += `${item}\n\n`;
49
+ function proseValues(node, facts, values) {
50
+ if (facts === undefined)
51
+ return;
52
+ if (node.kind === 'scalar') {
53
+ if (facts.prose && typeof node.value === 'string')
54
+ values.push({ start: node.start, end: node.end, text: `${node.value}\n\n` });
55
+ return;
58
56
  }
59
- return text;
57
+ if (node.kind === 'seq') {
58
+ for (const item of node.items)
59
+ proseValues(item, facts.items, values);
60
+ return;
61
+ }
62
+ for (const entry of node.entries)
63
+ proseValues(entry.value, memberFacts(facts, entry.key), values);
64
+ }
65
+ function freeTextValues(definition, document) {
66
+ const root = frontmatter(document);
67
+ if (root === null)
68
+ return [];
69
+ const values = [];
70
+ proseValues(root, definition.frontmatter, values);
71
+ return values;
60
72
  }
61
- export function project(document, file, context = {
62
- documentTargets: []
63
- }) {
64
- const bodyStart = bodyStartOf(document.content);
65
- const body = document.content.slice(bodyStart);
66
- const edits = internalEdits(body, file, new Set(context.documentTargets));
73
+ export function projectionInput(document, file, context) {
74
+ const content = document.content;
75
+ const bodyStart = bodyStartOf(content);
76
+ const edits = internalEdits(content, bodyStart, file, new Set(context.documentTargets));
67
77
  const declared = document.type;
68
78
  if (declared === undefined || declared === 'any') {
69
79
  return {
70
80
  ok: true,
71
- text: projected(body, [
72
- [
73
- 0,
74
- body.length
75
- ]
76
- ], edits)
81
+ input: { values: [], ranges: [{ start: bodyStart, end: content.length }], edits },
77
82
  };
78
83
  }
79
- const source = context.definition;
80
- if (source === undefined) {
81
- return {
82
- ok: false,
83
- refusal: refusal(file, 'unknown-type', {
84
- location: 'type'
85
- })
86
- };
84
+ const definition = context.definition;
85
+ if (definition === undefined) {
86
+ return { ok: false, refusal: refusal(file, 'unknown-type', { location: 'type' }) };
87
87
  }
88
- const definitionFile = `types/${declared}.md`;
89
- const parsed = parse(source, definitionFile);
90
- if (!parsed.ok) return {
91
- ok: false,
92
- refusal: parsed.refusal
93
- };
94
- const definition = readDefinition(definitionFile, parsed.document);
95
- if ('rule' in definition) return {
96
- ok: false,
97
- refusal: definition
98
- };
99
- const structure = new Set(Object.entries(definition.sections).flatMap(([name, spec])=>structural(spec) ? [
100
- name
101
- ] : []));
102
- const headings = headingSpans(document.content, bodyStart);
103
- const spans = [
104
- [
105
- 0,
106
- (headings[0]?.headingStart ?? document.content.length) - bodyStart
107
- ]
108
- ];
109
- for (const heading of headings){
110
- if (structure.has(heading.name)) continue;
111
- spans.push([
112
- heading.headingStart - bodyStart,
113
- heading.bodyEnd - bodyStart
114
- ]);
88
+ const structure = new Set(Object.entries(definition.sections).flatMap(([name, spec]) => (structural(spec) ? [name] : [])));
89
+ const headings = headingSpans(content, bodyStart);
90
+ const ranges = [{ start: bodyStart, end: headings[0]?.headingStart ?? content.length }];
91
+ for (const heading of headings) {
92
+ if (structure.has(heading.name))
93
+ continue;
94
+ ranges.push({ start: heading.headingStart, end: heading.bodyEnd });
115
95
  }
116
- return {
117
- ok: true,
118
- text: freeText(definition, document.fields) + projected(body, spans, edits)
119
- };
96
+ return { ok: true, input: { values: freeTextValues(definition, document), ranges, edits } };
97
+ }
98
+ export function project(document, file, context = { documentTargets: [] }) {
99
+ const result = projectionInput(document, file, context);
100
+ if (!result.ok)
101
+ return { ok: false, refusal: result.refusal };
102
+ const { values, ranges, edits } = result.input;
103
+ const prose = ranges.map((range) => rangeText(document.content, range, edits)).join('');
104
+ return { ok: true, text: values.map((value) => value.text).join('') + prose };
120
105
  }
121
-
122
- //# sourceMappingURL=project.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"refuse.d.ts","sourceRoot":"","sources":["../src/refuse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG1C,wBAAgB,OAAO,CACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAC3D,OAAO,CAQT"}
1
+ {"version":3,"file":"refuse.d.ts","sourceRoot":"","sources":["../src/refuse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,wBAAgB,OAAO,CACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAC3D,OAAO,CAOT"}
package/dist/refuse.js CHANGED
@@ -1,16 +1,8 @@
1
- import { VERSION } from './version.js';
2
1
  export function refusal(file, rule, extra) {
3
2
  return {
4
3
  file,
5
4
  rule,
6
- version: VERSION,
7
- ...extra?.location === undefined ? {} : {
8
- location: extra.location
9
- },
10
- ...extra?.referrers === undefined ? {} : {
11
- referrers: extra.referrers
12
- }
5
+ ...(extra?.location === undefined ? {} : { location: extra.location }),
6
+ ...(extra?.referrers === undefined ? {} : { referrers: extra.referrers }),
13
7
  };
14
8
  }
15
-
16
- //# sourceMappingURL=refuse.js.map
package/dist/schema.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import type { FieldSpec } from './definition.js';
2
- export declare function validateFields(fields: Readonly<Record<string, FieldSpec>>, values: Readonly<Record<string, unknown>>): {
3
- field: string;
4
- rule: 'required-field' | 'field-enum' | 'field-kind';
5
- } | undefined;
1
+ import { type Definition } from './definition.js';
2
+ export type SchemaRefusal = {
3
+ readonly rule: string;
4
+ readonly location: string;
5
+ };
6
+ export declare function frontmatterRefusal(definition: Definition, fields: Readonly<Record<string, unknown>>): SchemaRefusal | undefined;
7
+ export declare function fitsItem(definition: Definition, section: string, text: string): boolean;
6
8
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,iBAAiB,CAAC;AAmB7D,wBAAgB,cAAc,CAC5B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,EAC3C,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACxC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,gBAAgB,GAAG,YAAY,GAAG,YAAY,CAAA;CAAE,GAAG,SAAS,CAUrF"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAS5E,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AA2KjF,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACxC,aAAa,GAAG,SAAS,CAG3B;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAMvF"}
package/dist/schema.js CHANGED
@@ -1,48 +1,163 @@
1
1
  import { Validator } from '@cfworker/json-schema';
2
- function scalarSchema(spec) {
3
- if (spec.kind === 'text' || spec.kind === 'string' || spec.kind === 'reference') return {
4
- type: 'string'
5
- };
6
- if (spec.kind === 'number') return {
7
- type: 'number'
8
- };
9
- if (spec.kind === 'date') return {
10
- type: 'string',
11
- format: 'date'
12
- };
13
- return {
14
- type: 'string',
15
- enum: [
16
- ...spec.values
17
- ]
18
- };
2
+ import { escapePointer, refTarget } from './definition.js';
3
+ import { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD } from './fields.js';
4
+ import { interpretPlain, isRecord } from './yaml.js';
5
+ const STANDING_MAPS = ['properties', 'patternProperties'];
6
+ const STANDING = [
7
+ 'additionalProperties',
8
+ 'unevaluatedProperties',
9
+ 'items',
10
+ 'unevaluatedItems',
11
+ 'contains',
12
+ ];
13
+ const STANDING_LISTS = ['prefixItems'];
14
+ const IN_PLACE = ['if', 'then', 'else'];
15
+ const IN_PLACE_LISTS = ['allOf', 'anyOf', 'oneOf'];
16
+ const IN_PLACE_MAPS = ['dependentSchemas'];
17
+ const PASSING = new Set([
18
+ 'properties',
19
+ 'patternProperties',
20
+ '$ref',
21
+ 'items',
22
+ 'prefixItems',
23
+ 'unevaluatedItems',
24
+ 'allOf',
25
+ 'if',
26
+ 'dependentSchemas',
27
+ ]);
28
+ const OPENING = new Set(['additionalProperties', 'unevaluatedProperties']);
29
+ const REQUIRED = /required property "([\s\S]*)"\.$/u;
30
+ const compiled = new WeakMap();
31
+ function mapped(value, map) {
32
+ return Object.fromEntries(Object.entries(value).map(([key, held]) => [key, map(held)]));
19
33
  }
20
- function fieldSchema(spec) {
21
- if (spec.kind === 'list') return {
22
- type: 'array',
23
- items: scalarSchema(spec.of)
24
- };
25
- return scalarSchema(spec);
34
+ function objectSchema(node) {
35
+ const type = node.type;
36
+ return (type === 'object' ||
37
+ (Array.isArray(type) && type.includes('object')) ||
38
+ node.properties !== undefined ||
39
+ node.patternProperties !== undefined);
26
40
  }
27
- function ruleFor(error) {
28
- return error.keyword === 'enum' ? 'field-enum' : 'field-kind';
41
+ function inPlaceChildren(node) {
42
+ return [
43
+ ...IN_PLACE.map((key) => node[key]),
44
+ ...IN_PLACE_LISTS.flatMap((key) => (Array.isArray(node[key]) ? node[key] : [])),
45
+ ...IN_PLACE_MAPS.flatMap((key) => (isRecord(node[key]) ? Object.values(node[key]) : [])),
46
+ ];
29
47
  }
30
- export function validateFields(fields, values) {
31
- for (const [name, spec] of Object.entries(fields)){
32
- if (spec.required && values[name] === undefined) return {
33
- field: name,
34
- rule: 'required-field'
35
- };
48
+ function objecty(node, defs, seen) {
49
+ if (!isRecord(node))
50
+ return false;
51
+ if (objectSchema(node))
52
+ return true;
53
+ if (typeof node.$ref === 'string') {
54
+ const target = refTarget(node.$ref, defs)?.node;
55
+ if (target !== undefined &&
56
+ !seen.has(target) &&
57
+ objecty(target, defs, new Set([...seen, target])))
58
+ return true;
36
59
  }
37
- for (const [name, spec] of Object.entries(fields)){
38
- if (values[name] === undefined) continue;
39
- const result = new Validator(fieldSchema(spec), '2020-12', false).validate(values[name]);
40
- if (!result.valid) return {
41
- field: name,
42
- rule: ruleFor(result.errors[0])
43
- };
60
+ return inPlaceChildren(node).some((child) => objecty(child, defs, seen));
61
+ }
62
+ function closed(node, inPlace, defs, always = false) {
63
+ if (!isRecord(node))
64
+ return node;
65
+ const out = { ...node };
66
+ const standing = (held) => closed(held, false, defs);
67
+ const nested = (held) => closed(held, true, defs);
68
+ for (const key of STANDING_MAPS)
69
+ if (isRecord(node[key]))
70
+ out[key] = mapped(node[key], standing);
71
+ for (const key of STANDING)
72
+ if (node[key] !== undefined)
73
+ out[key] = standing(node[key]);
74
+ for (const key of STANDING_LISTS)
75
+ if (Array.isArray(node[key]))
76
+ out[key] = node[key].map(standing);
77
+ for (const key of IN_PLACE)
78
+ if (node[key] !== undefined)
79
+ out[key] = nested(node[key]);
80
+ for (const key of IN_PLACE_LISTS)
81
+ if (Array.isArray(node[key]))
82
+ out[key] = node[key].map(nested);
83
+ for (const key of IN_PLACE_MAPS)
84
+ if (isRecord(node[key]))
85
+ out[key] = mapped(node[key], nested);
86
+ if (isRecord(node.$defs))
87
+ out.$defs = mapped(node.$defs, nested);
88
+ if (!inPlace &&
89
+ node.additionalProperties === undefined &&
90
+ node.unevaluatedProperties === undefined &&
91
+ (always || objecty(node, defs, new Set())))
92
+ out.unevaluatedProperties = false;
93
+ return out;
94
+ }
95
+ function copied(value) {
96
+ return JSON.parse(JSON.stringify(value));
97
+ }
98
+ function compile(definition) {
99
+ const defs = copied(definition.shape.defs);
100
+ const { sections, member_document: _mark, ...root } = copied(definition.shape.schema);
101
+ const closedDefs = mapped(defs, (held) => closed(held, true, defs));
102
+ const declared = isRecord(root.properties) ? root.properties : {};
103
+ const properties = {
104
+ type: true,
105
+ [SITE_FIELD]: true,
106
+ [RECEIVED_FIELD]: true,
107
+ ...(definition.memberDocument ? { [MEMBER_FIELD]: { type: 'string' } } : {}),
108
+ ...declared,
109
+ };
110
+ const frontmatter = new Validator({ ...closed({ ...root, properties }, false, defs, true), $defs: closedDefs }, '2020-12', false);
111
+ const lists = new Map();
112
+ for (const [name, spec] of Object.entries(isRecord(sections) ? sections : {})) {
113
+ if (!isRecord(spec) || spec.kind !== 'list')
114
+ continue;
115
+ lists.set(name, new Validator({ ...closed(spec.items, false, defs), $defs: closedDefs }, '2020-12', false));
44
116
  }
45
- return undefined;
117
+ return { frontmatter, sections: lists };
118
+ }
119
+ function compiledOf(definition) {
120
+ const held = compiled.get(definition);
121
+ if (held !== undefined)
122
+ return held;
123
+ const made = compile(definition);
124
+ compiled.set(definition, made);
125
+ return made;
126
+ }
127
+ function pointer(location) {
128
+ return decodeURI(location.slice(1));
129
+ }
130
+ function refusalOf(errors) {
131
+ for (const [index, error] of errors.entries()) {
132
+ const next = errors[index + 1];
133
+ if (OPENING.has(error.keyword)) {
134
+ if (next?.keyword === 'false')
135
+ return { rule: 'undeclared-field', location: pointer(next.instanceLocation) };
136
+ if (next !== undefined)
137
+ continue;
138
+ }
139
+ if (PASSING.has(error.keyword) && next !== undefined)
140
+ continue;
141
+ if (error.keyword === 'required') {
142
+ const missing = REQUIRED.exec(error.error)?.[1] ?? '';
143
+ return {
144
+ rule: 'required',
145
+ location: `${pointer(error.instanceLocation)}/${escapePointer(missing)}`,
146
+ };
147
+ }
148
+ return { rule: error.keyword, location: pointer(error.instanceLocation) };
149
+ }
150
+ return { rule: 'schema', location: '' };
151
+ }
152
+ export function frontmatterRefusal(definition, fields) {
153
+ const result = compiledOf(definition).frontmatter.validate(fields);
154
+ return result.valid ? undefined : refusalOf(result.errors);
155
+ }
156
+ export function fitsItem(definition, section, text) {
157
+ const spec = definition.sections[section];
158
+ const validator = compiledOf(definition).sections.get(section);
159
+ if (spec?.kind !== 'list' || validator === undefined)
160
+ return false;
161
+ const typed = spec.items.type === 'string' ? text : interpretPlain(text);
162
+ return validator.validate(typed).valid;
46
163
  }
47
-
48
- //# sourceMappingURL=schema.js.map
@@ -1,3 +1,4 @@
1
+ import type { Extent } from './types.js';
1
2
  export type SectionSpan = {
2
3
  readonly name: string;
3
4
  readonly headingStart: number;
@@ -6,5 +7,5 @@ export type SectionSpan = {
6
7
  };
7
8
  export declare function headingSpans(content: string, bodyStart: number): SectionSpan[];
8
9
  export declare function sectionsRecord(spans: readonly SectionSpan[], content: string): Record<string, string>;
9
- export declare function parseListSection(body: string): boolean;
10
+ export declare function listItems(content: string, from: number, to: number): Extent[] | null;
10
11
  //# sourceMappingURL=sections.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sections.d.ts","sourceRoot":"","sources":["../src/sections.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAqBF,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,WAAW,EAAE,CAwB9E;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,OAAO,EAAE,MAAM,GACd,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAiBtD"}
1
+ {"version":3,"file":"sections.d.ts","sourceRoot":"","sources":["../src/sections.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAIF,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,WAAW,EAAE,CAc9E;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,OAAO,EAAE,MAAM,GACd,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB;AASD,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAoBpF"}