@agentshouse/mdmodel 0.1.0-c83456e1cebfb → 0.1.0-cc9fa0498a7f7

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 (288) hide show
  1. package/API.md +178 -113
  2. package/README.md +4 -2
  3. package/dist/blocks.d.ts.map +1 -1
  4. package/dist/blocks.js +30 -16
  5. package/dist/condition.d.ts +150 -0
  6. package/dist/condition.d.ts.map +1 -0
  7. package/dist/condition.js +497 -0
  8. package/dist/definition.d.ts +48 -24
  9. package/dist/definition.d.ts.map +1 -1
  10. package/dist/definition.js +511 -138
  11. package/dist/document.d.ts +6 -1
  12. package/dist/document.d.ts.map +1 -1
  13. package/dist/document.js +131 -25
  14. package/dist/fields.d.ts +2 -0
  15. package/dist/fields.d.ts.map +1 -1
  16. package/dist/fields.js +7 -0
  17. package/dist/index.d.ts +11 -5
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +7 -3
  20. package/dist/paths.d.ts +3 -0
  21. package/dist/paths.d.ts.map +1 -1
  22. package/dist/paths.js +20 -0
  23. package/dist/project.d.ts.map +1 -1
  24. package/dist/project.js +20 -21
  25. package/dist/references.d.ts +4 -0
  26. package/dist/references.d.ts.map +1 -0
  27. package/dist/references.js +25 -0
  28. package/dist/schema.d.ts +7 -6
  29. package/dist/schema.d.ts.map +1 -1
  30. package/dist/schema.js +157 -31
  31. package/dist/types.d.ts +17 -0
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/validate.d.ts.map +1 -1
  34. package/dist/validate.js +52 -87
  35. package/dist/yaml.d.ts +8 -3
  36. package/dist/yaml.d.ts.map +1 -1
  37. package/dist/yaml.js +103 -25
  38. package/fixtures/README.md +49 -38
  39. package/fixtures/cases/absent-link-dangles/context.json +1 -0
  40. package/fixtures/cases/absent-link-dangles/expected.json +1 -0
  41. package/fixtures/cases/absent-link-dangles/library/item.md +8 -0
  42. package/fixtures/cases/absent-link-dangles/schema.yaml +6 -0
  43. package/fixtures/cases/absent-optional-field/context.json +1 -0
  44. package/fixtures/cases/absent-optional-field/expected.json +1 -0
  45. package/fixtures/cases/absent-optional-field/library/companies/acme.md +4 -0
  46. package/fixtures/cases/absent-optional-field/library/deals/lead.md +6 -0
  47. package/fixtures/cases/absent-optional-field/schema.yaml +56 -0
  48. package/fixtures/cases/absolute-link/context.json +1 -0
  49. package/fixtures/cases/{missing-binary-image → absolute-link}/expected.json +1 -1
  50. package/fixtures/cases/absolute-link/library/item.md +8 -0
  51. package/fixtures/cases/absolute-link/schema.yaml +6 -0
  52. package/fixtures/cases/attachment-reference-any-file/context.json +1 -0
  53. package/fixtures/cases/attachment-reference-any-file/expected.json +1 -0
  54. package/fixtures/cases/attachment-reference-any-file/library/companies/acme.md +4 -0
  55. package/fixtures/cases/attachment-reference-any-file/library/deals/renewal.md +15 -0
  56. package/fixtures/cases/attachment-reference-any-file/library/places/depot.md +4 -0
  57. package/fixtures/cases/attachment-reference-any-file/library/products/seats.md +4 -0
  58. package/fixtures/cases/attachment-reference-any-file/library/products/support.md +4 -0
  59. package/fixtures/cases/attachment-reference-any-file/schema.yaml +32 -0
  60. package/fixtures/cases/attachment-reference-dangles/context.json +1 -0
  61. package/fixtures/cases/attachment-reference-dangles/expected.json +1 -0
  62. package/fixtures/cases/attachment-reference-dangles/library/companies/acme.md +4 -0
  63. package/fixtures/cases/attachment-reference-dangles/library/deals/renewal.md +15 -0
  64. package/fixtures/cases/attachment-reference-dangles/library/places/depot.md +4 -0
  65. package/fixtures/cases/attachment-reference-dangles/library/products/seats.md +4 -0
  66. package/fixtures/cases/attachment-reference-dangles/library/products/support.md +4 -0
  67. package/fixtures/cases/attachment-reference-dangles/schema.yaml +32 -0
  68. package/fixtures/cases/attachment-reference-outside/context.json +1 -0
  69. package/fixtures/cases/attachment-reference-outside/expected.json +6 -0
  70. package/fixtures/cases/attachment-reference-outside/library/companies/acme.md +4 -0
  71. package/fixtures/cases/attachment-reference-outside/library/deals/renewal.md +15 -0
  72. package/fixtures/cases/attachment-reference-outside/library/places/depot.md +4 -0
  73. package/fixtures/cases/attachment-reference-outside/library/products/seats.md +4 -0
  74. package/fixtures/cases/attachment-reference-outside/library/products/support.md +4 -0
  75. package/fixtures/cases/attachment-reference-outside/schema.yaml +32 -0
  76. package/fixtures/cases/binary-any-reference/expected.json +1 -1
  77. package/fixtures/cases/binary-any-reference/schema.yaml +4 -4
  78. package/fixtures/cases/binary-document-collision/schema.yaml +1 -2
  79. package/fixtures/cases/binary-image-dangles/expected.json +1 -0
  80. package/fixtures/cases/binary-image-dangles/schema.yaml +1 -0
  81. package/fixtures/cases/binary-link-dangles/expected.json +1 -0
  82. package/fixtures/cases/binary-link-dangles/schema.yaml +1 -0
  83. package/fixtures/cases/binary-link-outside-collection/schema.yaml +1 -2
  84. package/fixtures/cases/binary-prototype-reference/expected.json +1 -1
  85. package/fixtures/cases/binary-prototype-reference/schema.yaml +4 -4
  86. package/fixtures/cases/binary-typed-reference/expected.json +1 -1
  87. package/fixtures/cases/binary-typed-reference/schema.yaml +5 -5
  88. package/fixtures/cases/boolean-field/context.json +1 -0
  89. package/fixtures/cases/boolean-field/expected.json +6 -0
  90. package/fixtures/cases/boolean-field/library/companies/acme.md +4 -0
  91. package/fixtures/cases/boolean-field/library/deals/renewal.md +31 -0
  92. package/fixtures/cases/boolean-field/schema.yaml +56 -0
  93. package/fixtures/cases/bracketed-link-definition/schema.yaml +6 -6
  94. package/fixtures/cases/closed-nested-object/context.json +1 -0
  95. package/fixtures/cases/closed-nested-object/expected.json +6 -0
  96. package/fixtures/cases/closed-nested-object/library/companies/acme.md +4 -0
  97. package/fixtures/cases/closed-nested-object/library/deals/renewal.md +32 -0
  98. package/fixtures/cases/closed-nested-object/schema.yaml +56 -0
  99. package/fixtures/cases/composed-root-reference/context.json +1 -0
  100. package/fixtures/cases/composed-root-reference/expected.json +6 -0
  101. package/fixtures/cases/composed-root-reference/library/a.md +5 -0
  102. package/fixtures/cases/composed-root-reference/schema.yaml +13 -0
  103. package/fixtures/cases/date-time-format/context.json +1 -0
  104. package/fixtures/cases/date-time-format/expected.json +6 -0
  105. package/fixtures/cases/date-time-format/library/companies/acme.md +4 -0
  106. package/fixtures/cases/date-time-format/library/deals/renewal.md +31 -0
  107. package/fixtures/cases/date-time-format/schema.yaml +56 -0
  108. package/fixtures/cases/declared-binary-links/schema.yaml +1 -2
  109. package/fixtures/cases/default-unfilled/context.json +1 -0
  110. package/fixtures/cases/default-unfilled/expected.json +6 -0
  111. package/fixtures/cases/default-unfilled/library/companies/acme.md +4 -0
  112. package/fixtures/cases/default-unfilled/library/deals/renewal.md +29 -0
  113. package/fixtures/cases/default-unfilled/schema.yaml +56 -0
  114. package/fixtures/cases/defs-pattern/context.json +1 -0
  115. package/fixtures/cases/defs-pattern/expected.json +6 -0
  116. package/fixtures/cases/defs-pattern/library/companies/acme.md +4 -0
  117. package/fixtures/cases/defs-pattern/library/deals/renewal.md +31 -0
  118. package/fixtures/cases/defs-pattern/schema.yaml +56 -0
  119. package/fixtures/cases/dependent-rule/context.json +1 -0
  120. package/fixtures/cases/dependent-rule/expected.json +6 -0
  121. package/fixtures/cases/dependent-rule/library/companies/acme.md +4 -0
  122. package/fixtures/cases/dependent-rule/library/deals/renewal.md +30 -0
  123. package/fixtures/cases/dependent-rule/schema.yaml +56 -0
  124. package/fixtures/cases/duplicate-link-definition/schema.yaml +6 -6
  125. package/fixtures/cases/email-format/context.json +1 -0
  126. package/fixtures/cases/email-format/expected.json +6 -0
  127. package/fixtures/cases/email-format/library/companies/acme.md +4 -0
  128. package/fixtures/cases/email-format/library/deals/renewal.md +31 -0
  129. package/fixtures/cases/email-format/schema.yaml +56 -0
  130. package/fixtures/cases/fenced-link-definition/schema.yaml +6 -6
  131. package/fixtures/cases/field-enum/expected.json +2 -2
  132. package/fixtures/cases/field-enum/schema.yaml +7 -7
  133. package/fixtures/cases/frontmatter-schema/schema.yaml +3 -4
  134. package/fixtures/cases/integer-field/context.json +1 -0
  135. package/fixtures/cases/integer-field/expected.json +6 -0
  136. package/fixtures/cases/integer-field/library/companies/acme.md +4 -0
  137. package/fixtures/cases/integer-field/library/deals/renewal.md +31 -0
  138. package/fixtures/cases/integer-field/schema.yaml +56 -0
  139. package/fixtures/cases/interrupted-link-definition/schema.yaml +1 -2
  140. package/fixtures/cases/json-schema-constructs/context.json +1 -0
  141. package/fixtures/cases/json-schema-constructs/expected.json +1 -0
  142. package/fixtures/cases/json-schema-constructs/library/companies/acme.md +4 -0
  143. package/fixtures/cases/json-schema-constructs/library/deals/renewal.md +31 -0
  144. package/fixtures/cases/json-schema-constructs/schema.yaml +56 -0
  145. package/fixtures/cases/list-of-objects-closed/context.json +1 -0
  146. package/fixtures/cases/list-of-objects-closed/expected.json +6 -0
  147. package/fixtures/cases/list-of-objects-closed/library/companies/acme.md +4 -0
  148. package/fixtures/cases/list-of-objects-closed/library/deals/renewal.md +32 -0
  149. package/fixtures/cases/list-of-objects-closed/schema.yaml +56 -0
  150. package/fixtures/cases/list-of-objects-item/context.json +1 -0
  151. package/fixtures/cases/list-of-objects-item/expected.json +6 -0
  152. package/fixtures/cases/list-of-objects-item/library/companies/acme.md +4 -0
  153. package/fixtures/cases/list-of-objects-item/library/deals/renewal.md +31 -0
  154. package/fixtures/cases/list-of-objects-item/schema.yaml +56 -0
  155. package/fixtures/cases/list-of-objects-reference/context.json +1 -0
  156. package/fixtures/cases/list-of-objects-reference/expected.json +6 -0
  157. package/fixtures/cases/list-of-objects-reference/library/companies/acme.md +4 -0
  158. package/fixtures/cases/list-of-objects-reference/library/deals/renewal.md +14 -0
  159. package/fixtures/cases/list-of-objects-reference/library/places/depot.md +4 -0
  160. package/fixtures/cases/list-of-objects-reference/library/products/seats.md +4 -0
  161. package/fixtures/cases/list-of-objects-reference/library/products/support.md +4 -0
  162. package/fixtures/cases/list-of-objects-reference/schema.yaml +32 -0
  163. package/fixtures/cases/list-size/context.json +1 -0
  164. package/fixtures/cases/list-size/expected.json +6 -0
  165. package/fixtures/cases/list-size/library/companies/acme.md +4 -0
  166. package/fixtures/cases/list-size/library/deals/renewal.md +31 -0
  167. package/fixtures/cases/list-size/schema.yaml +56 -0
  168. package/fixtures/cases/long-fence-link-definition/schema.yaml +1 -2
  169. package/fixtures/cases/malformed-definition/expected.json +2 -2
  170. package/fixtures/cases/malformed-definition/schema.yaml +3 -4
  171. package/fixtures/cases/member-document/schema.yaml +5 -5
  172. package/fixtures/cases/missing-required-field/expected.json +2 -2
  173. package/fixtures/cases/missing-required-field/schema.yaml +7 -7
  174. package/fixtures/cases/missing-section-item-kind/expected.json +2 -2
  175. package/fixtures/cases/missing-section-item-kind/schema.yaml +6 -6
  176. package/fixtures/cases/misspelled-key/context.json +1 -0
  177. package/fixtures/cases/misspelled-key/expected.json +6 -0
  178. package/fixtures/cases/misspelled-key/library/companies/acme.md +4 -0
  179. package/fixtures/cases/misspelled-key/library/deals/renewal.md +32 -0
  180. package/fixtures/cases/misspelled-key/schema.yaml +56 -0
  181. package/fixtures/cases/nested-defs/context.json +1 -0
  182. package/fixtures/cases/nested-defs/expected.json +6 -0
  183. package/fixtures/cases/nested-defs/library/deal.md +6 -0
  184. package/fixtures/cases/nested-defs/schema.yaml +11 -0
  185. package/fixtures/cases/nested-object-reference/context.json +1 -0
  186. package/fixtures/cases/nested-object-reference/expected.json +6 -0
  187. package/fixtures/cases/nested-object-reference/library/companies/acme.md +4 -0
  188. package/fixtures/cases/nested-object-reference/library/deals/renewal.md +14 -0
  189. package/fixtures/cases/nested-object-reference/library/places/depot.md +4 -0
  190. package/fixtures/cases/nested-object-reference/library/products/seats.md +4 -0
  191. package/fixtures/cases/nested-object-reference/library/products/support.md +4 -0
  192. package/fixtures/cases/nested-object-reference/schema.yaml +32 -0
  193. package/fixtures/cases/nested-reference/context.json +1 -0
  194. package/fixtures/cases/nested-reference/expected.json +1 -0
  195. package/fixtures/cases/nested-reference/library/companies/acme.md +4 -0
  196. package/fixtures/cases/nested-reference/library/deals/renewal.md +15 -0
  197. package/fixtures/cases/nested-reference/library/places/depot.md +4 -0
  198. package/fixtures/cases/nested-reference/library/products/seats.md +4 -0
  199. package/fixtures/cases/nested-reference/library/products/support.md +4 -0
  200. package/fixtures/cases/nested-reference/schema.yaml +32 -0
  201. package/fixtures/cases/nested-required-field/context.json +1 -0
  202. package/fixtures/cases/nested-required-field/expected.json +6 -0
  203. package/fixtures/cases/nested-required-field/library/companies/acme.md +4 -0
  204. package/fixtures/cases/nested-required-field/library/deals/renewal.md +30 -0
  205. package/fixtures/cases/nested-required-field/schema.yaml +56 -0
  206. package/fixtures/cases/null-refused/context.json +1 -0
  207. package/fixtures/cases/null-refused/expected.json +6 -0
  208. package/fixtures/cases/null-refused/library/companies/acme.md +4 -0
  209. package/fixtures/cases/null-refused/library/deals/renewal.md +31 -0
  210. package/fixtures/cases/null-refused/schema.yaml +56 -0
  211. package/fixtures/cases/numeric-range/context.json +1 -0
  212. package/fixtures/cases/numeric-range/expected.json +6 -0
  213. package/fixtures/cases/numeric-range/library/companies/acme.md +4 -0
  214. package/fixtures/cases/numeric-range/library/deals/renewal.md +31 -0
  215. package/fixtures/cases/numeric-range/schema.yaml +56 -0
  216. package/fixtures/cases/one-of-variant/context.json +1 -0
  217. package/fixtures/cases/one-of-variant/expected.json +6 -0
  218. package/fixtures/cases/one-of-variant/library/companies/acme.md +4 -0
  219. package/fixtures/cases/one-of-variant/library/deals/renewal.md +31 -0
  220. package/fixtures/cases/one-of-variant/schema.yaml +56 -0
  221. package/fixtures/cases/open-map-value/context.json +1 -0
  222. package/fixtures/cases/open-map-value/expected.json +6 -0
  223. package/fixtures/cases/open-map-value/library/companies/acme.md +4 -0
  224. package/fixtures/cases/open-map-value/library/deals/renewal.md +31 -0
  225. package/fixtures/cases/open-map-value/schema.yaml +56 -0
  226. package/fixtures/cases/other-room-reference/context.json +1 -0
  227. package/fixtures/cases/other-room-reference/expected.json +6 -0
  228. package/fixtures/cases/other-room-reference/library/companies/acme.md +4 -0
  229. package/fixtures/cases/other-room-reference/library/deals/renewal.md +14 -0
  230. package/fixtures/cases/other-room-reference/library/places/depot.md +4 -0
  231. package/fixtures/cases/other-room-reference/library/products/seats.md +4 -0
  232. package/fixtures/cases/other-room-reference/library/products/support.md +4 -0
  233. package/fixtures/cases/other-room-reference/schema.yaml +32 -0
  234. package/fixtures/cases/paragraph-link-definition/schema.yaml +1 -2
  235. package/fixtures/cases/prototype-field/expected.json +1 -1
  236. package/fixtures/cases/prototype-field/schema.yaml +6 -6
  237. package/fixtures/cases/quoted-link-definition/library/notes/draft.md +1 -1
  238. package/fixtures/cases/quoted-link-definition/schema.yaml +1 -2
  239. package/fixtures/cases/referenced-missing-file/schema.yaml +11 -10
  240. package/fixtures/cases/remote-ref/context.json +1 -0
  241. package/fixtures/cases/remote-ref/expected.json +5 -0
  242. package/fixtures/cases/remote-ref/schema.yaml +3 -0
  243. package/fixtures/cases/second-member-document/expected.json +2 -2
  244. package/fixtures/cases/second-member-document/schema.yaml +4 -5
  245. package/fixtures/cases/section-item-enum/schema.yaml +3 -4
  246. package/fixtures/cases/section-item-kind/schema.yaml +3 -4
  247. package/fixtures/cases/section-items/library/page.md +14 -0
  248. package/fixtures/cases/section-items/schema.yaml +10 -8
  249. package/fixtures/cases/section-reference-path/schema.yaml +3 -4
  250. package/fixtures/cases/section-reference-type/schema.yaml +3 -4
  251. package/fixtures/cases/shortcut-reference-link/library/item.md +1 -1
  252. package/fixtures/cases/shortcut-reference-link/schema.yaml +6 -6
  253. package/fixtures/cases/string-length/context.json +1 -0
  254. package/fixtures/cases/string-length/expected.json +6 -0
  255. package/fixtures/cases/string-length/library/companies/acme.md +4 -0
  256. package/fixtures/cases/string-length/library/deals/renewal.md +31 -0
  257. package/fixtures/cases/string-length/schema.yaml +56 -0
  258. package/fixtures/cases/structured-section/schema.yaml +7 -7
  259. package/fixtures/cases/submission-keys/schema.yaml +4 -4
  260. package/fixtures/cases/text-field-kind/expected.json +2 -2
  261. package/fixtures/cases/text-field-kind/schema.yaml +4 -4
  262. package/fixtures/cases/truncated-link-definition/library/notes/draft.md +1 -1
  263. package/fixtures/cases/truncated-link-definition/schema.yaml +1 -2
  264. package/fixtures/cases/types-folder-content/schema.yaml +4 -4
  265. package/fixtures/cases/undeclared-field/expected.json +1 -1
  266. package/fixtures/cases/undeclared-field/schema.yaml +6 -6
  267. package/fixtures/cases/unevaluated-items-closed/context.json +1 -0
  268. package/fixtures/cases/unevaluated-items-closed/expected.json +6 -0
  269. package/fixtures/cases/unevaluated-items-closed/library/trip.md +6 -0
  270. package/fixtures/cases/unevaluated-items-closed/schema.yaml +10 -0
  271. package/fixtures/cases/unknown-type/expected.json +1 -1
  272. package/fixtures/cases/unknown-type/schema.yaml +3 -4
  273. package/fixtures/cases/unlisted-reference-type/expected.json +2 -2
  274. package/fixtures/cases/unlisted-reference-type/schema.yaml +3 -4
  275. package/fixtures/cases/unresolved-link/library/item.md +1 -1
  276. package/fixtures/cases/unresolved-link/schema.yaml +6 -6
  277. package/fixtures/cases/valid-typed-document/schema.yaml +16 -15
  278. package/fixtures/cases/wide-item-fence-link/schema.yaml +1 -2
  279. package/fixtures/division.json +1 -1
  280. package/fixtures/projection.json +33 -1
  281. package/package.json +1 -1
  282. package/fixtures/cases/missing-binary-image/schema.yaml +0 -2
  283. package/fixtures/cases/missing-binary-link/expected.json +0 -5
  284. package/fixtures/cases/missing-binary-link/schema.yaml +0 -2
  285. /package/fixtures/cases/{missing-binary-image → binary-image-dangles}/context.json +0 -0
  286. /package/fixtures/cases/{missing-binary-image → binary-image-dangles}/library/notes/draft.md +0 -0
  287. /package/fixtures/cases/{missing-binary-link → binary-link-dangles}/context.json +0 -0
  288. /package/fixtures/cases/{missing-binary-link → binary-link-dangles}/library/notes/draft.md +0 -0
@@ -1,7 +1,12 @@
1
- import type { ApplyResult, Change, Document, Link, ParseResult } from './types.js';
1
+ import { type Definition } from './definition.js';
2
+ import type { ApplyResult, BodyResult, Change, Document, Link, ParseResult } from './types.js';
2
3
  import { type YamlMap } from './yaml.js';
3
4
  export declare function parse(content: string, file?: string): ParseResult;
5
+ export declare function relativize(document: Document, file: string, handle: string, definition?: Definition): ApplyResult;
6
+ export declare function relativizeBody(body: string, file: string, handle: string): BodyResult;
7
+ export declare function relinkBody(body: string, file: string, moves: ReadonlyMap<string, string>): BodyResult;
4
8
  export declare function links(document: Document, file: string): readonly Link[];
9
+ export declare function bodyLinks(body: string, file: string): readonly Link[];
5
10
  export declare function apply(document: Document, change: Change): ApplyResult;
6
11
  export declare function serialize(document: Document): string;
7
12
  export declare function frontmatter(document: Document): YamlMap | null;
@@ -1 +1 @@
1
- {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACnF,OAAO,EAYL,KAAK,OAAO,EACb,MAAM,WAAW,CAAC;AAwCnB,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,SAAK,GAAG,WAAW,CAkD7D;AAkHD,wBAAgB,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,IAAI,EAAE,CAWvE;AAED,wBAAgB,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAarE;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAEpD;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,GAAG,IAAI,CAE9D"}
1
+ {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAMhF,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,WAAW,EAEZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAaL,KAAK,OAAO,EAEb,MAAM,WAAW,CAAC;AAwCnB,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,SAAK,GAAG,WAAW,CAkD7D;AA+KD,wBAAgB,UAAU,CACxB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,UAAU,CAAC,EAAE,UAAU,GACtB,WAAW,CAYb;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAOrF;AAED,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACjC,UAAU,CAeZ;AAeD,wBAAgB,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,IAAI,EAAE,CAEvE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,IAAI,EAAE,CAErE;AAED,wBAAgB,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAOrE;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAEpD;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,GAAG,IAAI,CAE9D"}
package/dist/document.js CHANGED
@@ -1,8 +1,10 @@
1
+ import { ARRAY_INDEX, pointerSegments } from './definition.js';
1
2
  import { hrefOccurrences } from './links.js';
2
- import { retarget, target } from './paths.js';
3
+ import { relative, retarget, SHELL_ROOMS, shellTarget, target } from './paths.js';
4
+ import { references } from './references.js';
3
5
  import { headingSpans, sectionsRecord } from './sections.js';
4
6
  import { refusal } from './refuse.js';
5
- import { bodyStartAfterYaml, bodyStartOf, equalValue, extractFrontmatter, jsValue, lineEnding, mapEntry, parseYamlMapping, serializeJs, serializeKey, YamlError, } from './yaml.js';
7
+ import { bodyStartAfterYaml, bodyStartOf, equalValue, extractFrontmatter, frontmatterValue, jsValue, lineEnding, mapEntry, parseYamlMapping, serializeJs, serializeKey, YamlError, } from './yaml.js';
6
8
  const internals = new WeakMap();
7
9
  function refuse(file, rule, location) {
8
10
  return location === undefined ? refusal(file, rule) : refusal(file, rule, { location });
@@ -76,10 +78,18 @@ function applyField(document, name, value, prior) {
76
78
  if (!equalValue(document.fields[name], prior)) {
77
79
  return { outcome: 'stale', document };
78
80
  }
81
+ if (!frontmatterValue(value)) {
82
+ return { outcome: 'refuse', refusal: refuse('', 'frontmatter-fence', name) };
83
+ }
79
84
  let nextContent;
80
85
  const existing = mapEntry(internal.root, name);
81
86
  if (existing !== undefined) {
82
- nextContent = splice(document.content, existing.value.start, existing.value.end, serializeJs(value));
87
+ const held = existing.value;
88
+ const inline = held.start > existing.after &&
89
+ !/[\r\n]/.test(document.content.slice(existing.after, held.start));
90
+ nextContent = inline
91
+ ? splice(document.content, held.start, held.end, serializeJs(value))
92
+ : splice(document.content, existing.after, held.end, ` ${serializeJs(value)}`);
83
93
  }
84
94
  else if (document.content[internal.root.start] === '{') {
85
95
  nextContent = splice(document.content, internal.root.end - 1, internal.root.end - 1, `${internal.root.entries.length === 0 ? '' : ', '}${serializeKey(name)}: ${serializeJs(value)}`);
@@ -150,32 +160,128 @@ function destinationText(to, bracketed) {
150
160
  return `<${to}>`;
151
161
  return null;
152
162
  }
153
- function applyLink(document, href, to) {
154
- const content = document.content;
155
- const bodyStart = bodyStartOf(content);
156
- const matches = hrefOccurrences(content.slice(bodyStart)).filter((occurrence) => occurrence.href === href);
157
- if (matches.length === 0)
158
- return { outcome: 'stale', document };
163
+ function relinked(content, bodyStart, href, to) {
159
164
  const written = retarget(href, to);
160
165
  let rewritten = '';
161
166
  let cursor = 0;
162
- for (const match of matches) {
167
+ for (const match of hrefOccurrences(content.slice(bodyStart))) {
168
+ if (match.href !== href)
169
+ continue;
163
170
  const text = destinationText(written, match.bracketed);
164
171
  if (text === null)
165
- return { outcome: 'refuse', refusal: refuse('', 'unwritable-link', written) };
172
+ return refuse('', 'unwritable-link', written);
166
173
  rewritten += content.slice(cursor, bodyStart + match.start);
167
174
  rewritten += text;
168
175
  cursor = bodyStart + match.end;
169
176
  }
170
- const parsed = parse(rewritten + content.slice(cursor));
177
+ return rewritten + content.slice(cursor);
178
+ }
179
+ function shellRelinked(content, bodyStart, file, handle) {
180
+ const hrefs = new Set(hrefOccurrences(content.slice(bodyStart)).map(({ href }) => href));
181
+ let held = content;
182
+ for (const href of hrefs) {
183
+ const path = shellTarget(href, handle);
184
+ if (path === null)
185
+ continue;
186
+ const text = relinked(held, bodyStart, href, relative(file, path));
187
+ if (typeof text !== 'string')
188
+ return text;
189
+ held = text;
190
+ }
191
+ return held;
192
+ }
193
+ function reparsed(document, content) {
194
+ if (typeof content !== 'string')
195
+ return { outcome: 'refuse', refusal: content };
196
+ if (content === document.content)
197
+ return { outcome: 'applied', document };
198
+ const parsed = parse(content);
171
199
  if (!parsed.ok)
172
200
  return { outcome: 'refuse', refusal: parsed.refusal };
173
201
  return { outcome: 'applied', document: parsed.document };
174
202
  }
175
- export function links(document, file) {
203
+ function applyLink(document, href, to) {
204
+ const content = document.content;
205
+ const bodyStart = bodyStartOf(content);
206
+ if (!hrefOccurrences(content.slice(bodyStart)).some((occurrence) => occurrence.href === href))
207
+ return { outcome: 'stale', document };
208
+ return reparsed(document, relinked(content, bodyStart, href, to));
209
+ }
210
+ function nodeAt(root, pointer) {
211
+ let node = root;
212
+ for (const key of pointerSegments(pointer)) {
213
+ if (node?.kind === 'map')
214
+ node = mapEntry(node, key)?.value;
215
+ else if (node?.kind === 'seq' && ARRAY_INDEX.test(key))
216
+ node = node.items[Number(key)];
217
+ else
218
+ return undefined;
219
+ }
220
+ return node;
221
+ }
222
+ function scalarText(source, value) {
223
+ if (source === "'")
224
+ return `'${value.replaceAll("'", "''")}'`;
225
+ if (source === '"')
226
+ return JSON.stringify(value);
227
+ return serializeJs(value);
228
+ }
229
+ function applyReference(document, pointer, value, prior) {
230
+ const root = internals.get(document)?.root;
231
+ const node = root === null || root === undefined ? undefined : nodeAt(root, pointer);
232
+ if (node?.kind !== 'scalar' || node.value !== prior)
233
+ return { outcome: 'stale', document };
234
+ const text = scalarText(document.content[node.start], value);
235
+ const parsed = parse(splice(document.content, node.start, node.end, text));
236
+ if (!parsed.ok)
237
+ return { outcome: 'refuse', refusal: parsed.refusal };
238
+ return { outcome: 'applied', document: parsed.document };
239
+ }
240
+ export function relativize(document, file, handle, definition) {
241
+ let held = document;
242
+ for (const { pointer, value } of definition === undefined
243
+ ? []
244
+ : references(document, definition)) {
245
+ const path = shellTarget(value, handle);
246
+ if (path === null)
247
+ continue;
248
+ const result = applyReference(held, pointer, retarget(value, relative(file, path)), value);
249
+ if (result.outcome !== 'applied')
250
+ return result;
251
+ held = result.document;
252
+ }
253
+ return reparsed(held, shellRelinked(held.content, bodyStartOf(held.content), file, handle));
254
+ }
255
+ export function relativizeBody(body, file, handle) {
256
+ const relinkedBody = shellRelinked(body, 0, file, handle);
257
+ if (typeof relinkedBody !== 'string')
258
+ return { outcome: 'refuse', refusal: relinkedBody };
259
+ const elsewhere = hrefOccurrences(relinkedBody).find(({ href }) => href.startsWith(SHELL_ROOMS));
260
+ if (elsewhere !== undefined)
261
+ return { outcome: 'refuse', refusal: refuse(file, 'unresolved-link', elsewhere.href) };
262
+ return { outcome: 'applied', body: relinkedBody };
263
+ }
264
+ export function relinkBody(body, file, moves) {
265
+ let rewritten = '';
266
+ let cursor = 0;
267
+ for (const match of hrefOccurrences(body)) {
268
+ const from = target(file, match.href);
269
+ const to = from === null ? undefined : moves.get(from);
270
+ if (to === undefined)
271
+ continue;
272
+ const written = retarget(match.href, relative(file, to));
273
+ const text = destinationText(written, match.bracketed);
274
+ if (text === null)
275
+ return { outcome: 'refuse', refusal: refuse(file, 'unwritable-link', written) };
276
+ rewritten += body.slice(cursor, match.start) + text;
277
+ cursor = match.end;
278
+ }
279
+ return { outcome: 'applied', body: rewritten + body.slice(cursor) };
280
+ }
281
+ function linksIn(text, file) {
176
282
  const found = [];
177
283
  const seen = new Set();
178
- for (const occurrence of hrefOccurrences(document.content.slice(bodyStartOf(document.content)))) {
284
+ for (const occurrence of hrefOccurrences(text)) {
179
285
  if (seen.has(occurrence.href))
180
286
  continue;
181
287
  const resolved = target(file, occurrence.href);
@@ -186,22 +292,22 @@ export function links(document, file) {
186
292
  }
187
293
  return found;
188
294
  }
295
+ export function links(document, file) {
296
+ return linksIn(document.content.slice(bodyStartOf(document.content)), file);
297
+ }
298
+ export function bodyLinks(body, file) {
299
+ return linksIn(body, file);
300
+ }
189
301
  export function apply(document, change) {
190
302
  if (change.kind === 'link')
191
303
  return applyLink(document, change.href, change.to);
304
+ if (change.kind === 'reference')
305
+ return applyReference(document, change.pointer, change.value, change.prior);
192
306
  if (change.kind === 'preamble')
193
307
  return applyPreamble(document, change.value, change.prior);
194
- try {
195
- if (change.kind === 'field')
196
- return applyField(document, change.name, change.value, change.prior);
197
- return applySection(document, change.name, change.value, change.prior);
198
- }
199
- catch (error) {
200
- if (error instanceof YamlError) {
201
- return { outcome: 'refuse', refusal: refuse('', 'frontmatter-fence', change.name) };
202
- }
203
- throw error;
204
- }
308
+ if (change.kind === 'field')
309
+ return applyField(document, change.name, change.value, change.prior);
310
+ return applySection(document, change.name, change.value, change.prior);
205
311
  }
206
312
  export function serialize(document) {
207
313
  return document.content;
package/dist/fields.d.ts CHANGED
@@ -1,4 +1,6 @@
1
+ export declare const TYPE_FIELD = "type";
1
2
  export declare const MEMBER_FIELD = "member";
2
3
  export declare const SITE_FIELD = "site";
3
4
  export declare const RECEIVED_FIELD = "received";
5
+ export declare const HOUSE_FIELDS: readonly string[];
4
6
  //# sourceMappingURL=fields.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,WAAW,CAAC;AAErC,eAAO,MAAM,UAAU,SAAS,CAAC;AAEjC,eAAO,MAAM,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,SAAS,CAAC;AAEjC,eAAO,MAAM,YAAY,WAAW,CAAC;AAErC,eAAO,MAAM,UAAU,SAAS,CAAC;AAEjC,eAAO,MAAM,cAAc,aAAa,CAAC;AAEzC,eAAO,MAAM,YAAY,EAAE,SAAS,MAAM,EAKzC,CAAC"}
package/dist/fields.js CHANGED
@@ -1,3 +1,10 @@
1
+ export const TYPE_FIELD = 'type';
1
2
  export const MEMBER_FIELD = 'member';
2
3
  export const SITE_FIELD = 'site';
3
4
  export const RECEIVED_FIELD = 'received';
5
+ export const HOUSE_FIELDS = [
6
+ TYPE_FIELD,
7
+ SITE_FIELD,
8
+ RECEIVED_FIELD,
9
+ MEMBER_FIELD,
10
+ ];
package/dist/index.d.ts CHANGED
@@ -1,11 +1,17 @@
1
+ export { dated, datePointers, factKind, facts, fires, holds, instant, itemFires, pointed, prosePaths, WRITE_DOORS, } from './condition.js';
2
+ export type { Actor, Condition, ConditionScope, ConditionTest, ConditionValue, CronCondition, DateCondition, DocumentCondition, DocumentEvent, DocumentFacts, Fact, FactKind, ItemCondition, ItemFacts, Resolved, WriteDoor, } from './condition.js';
1
3
  export { divide } from './divide.js';
2
- export { apply, links, parse, serialize } from './document.js';
3
- export { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD } from './fields.js';
4
- export { retarget, target } from './paths.js';
4
+ export { apply, bodyLinks, links, parse, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
5
+ export { HOUSE_FIELDS, MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
6
+ export { relative, retarget, target } from './paths.js';
5
7
  export { MARKDOWN_SYNTAX_PROFILE } from './profile.js';
6
8
  export { project } from './project.js';
7
- export type { Definition, FieldSpec, SectionSpec } from './definition.js';
8
- export type { ApplyResult, Change, Division, DivisionContext, Document, Library, ModelVerification, Link, ParseResult, Projection, ProjectionContext, Refusal, Span, Validation, ValidationContext, VerifiedModel, } from './types.js';
9
+ export { references } from './references.js';
10
+ export { ARRAY_INDEX, ATTACHMENT, crossedFacts, escapePointer, itemFacts, memberFacts, pointerFacts, pointerSegments, } from './definition.js';
11
+ export type { Definition, JsonType, PatternFacts, PointerFacts, SectionSpec, Shape, ValueFacts, } from './definition.js';
12
+ export type { ApplyResult, BodyResult, Change, Division, DivisionContext, Document, Library, ModelVerification, Link, ParseResult, Projection, ProjectionContext, Reference, Refusal, Span, Validation, ValidationContext, VerifiedModel, } from './types.js';
9
13
  export { validate, verify } from './validate.js';
10
14
  export { VERSION } from './version.js';
15
+ export { equalValue, frontmatterValue } from './yaml.js';
16
+ export type { FrontmatterValue } from './yaml.js';
11
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC1E,YAAY,EACV,WAAW,EACX,MAAM,EACN,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,OAAO,EACP,iBAAiB,EACjB,IAAI,EACJ,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,OAAO,EACP,IAAI,EACJ,UAAU,EACV,iBAAiB,EACjB,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,YAAY,EACZ,QAAQ,EACR,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,SAAS,EACT,OAAO,EACP,UAAU,EACV,WAAW,GACZ,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,KAAK,EACL,SAAS,EACT,cAAc,EACd,aAAa,EACb,cAAc,EACd,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,SAAS,EACT,QAAQ,EACR,SAAS,GACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,KAAK,EACL,SAAS,EACT,KAAK,EACL,KAAK,EACL,UAAU,EACV,cAAc,EACd,UAAU,EACV,SAAS,GACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACjG,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,WAAW,EACX,UAAU,EACV,YAAY,EACZ,aAAa,EACb,SAAS,EACT,WAAW,EACX,YAAY,EACZ,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,KAAK,EACL,UAAU,GACX,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,OAAO,EACP,iBAAiB,EACjB,IAAI,EACJ,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,OAAO,EACP,IAAI,EACJ,UAAU,EACV,iBAAiB,EACjB,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AACzD,YAAY,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,12 @@
1
+ export { dated, datePointers, factKind, facts, fires, holds, instant, itemFires, pointed, prosePaths, WRITE_DOORS, } from './condition.js';
1
2
  export { divide } from './divide.js';
2
- export { apply, links, parse, serialize } from './document.js';
3
- export { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD } from './fields.js';
4
- export { retarget, target } from './paths.js';
3
+ export { apply, bodyLinks, links, parse, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
4
+ export { HOUSE_FIELDS, MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
5
+ export { relative, retarget, target } from './paths.js';
5
6
  export { MARKDOWN_SYNTAX_PROFILE } from './profile.js';
6
7
  export { project } from './project.js';
8
+ export { references } from './references.js';
9
+ export { ARRAY_INDEX, ATTACHMENT, crossedFacts, escapePointer, itemFacts, memberFacts, pointerFacts, pointerSegments, } from './definition.js';
7
10
  export { validate, verify } from './validate.js';
8
11
  export { VERSION } from './version.js';
12
+ export { equalValue, frontmatterValue } from './yaml.js';
package/dist/paths.d.ts CHANGED
@@ -11,4 +11,7 @@ export declare function classifyHref(from: string, href: string): {
11
11
  };
12
12
  export declare function target(from: string, href: string): string | null;
13
13
  export declare function retarget(href: string, to: string): string;
14
+ export declare function relative(from: string, target: string): string;
15
+ export declare const SHELL_ROOMS = "/rooms/";
16
+ export declare function shellTarget(href: string, handle: string): string | null;
14
17
  //# 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,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"}
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;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAW7D;AAED,eAAO,MAAM,WAAW,YAAY,CAAC;AAErC,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKvE"}
package/dist/paths.js CHANGED
@@ -47,3 +47,23 @@ export function retarget(href, to) {
47
47
  const match = /[?#]/.exec(trimmed);
48
48
  return match === null ? to : to + trimmed.slice(match.index);
49
49
  }
50
+ export function relative(from, target) {
51
+ const base = dirname(from)
52
+ .split('/')
53
+ .filter((part) => part !== '');
54
+ const parts = target.split('/');
55
+ let shared = 0;
56
+ while (shared < base.length && shared + 1 < parts.length && base[shared] === parts[shared]) {
57
+ shared += 1;
58
+ }
59
+ const up = Array.from({ length: base.length - shared }, () => '..');
60
+ return [...up, ...parts.slice(shared)].join('/');
61
+ }
62
+ export const SHELL_ROOMS = '/rooms/';
63
+ export function shellTarget(href, handle) {
64
+ const prefix = `${SHELL_ROOMS}${handle}/`;
65
+ if (!href.startsWith(prefix))
66
+ return null;
67
+ const path = normalize(href.slice(prefix.length).replace(/[?#].*$/s, ''));
68
+ return path === null || path === '' ? null : path;
69
+ }
@@ -1 +1 @@
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;AA8BD,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"}
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,9 +1,10 @@
1
+ import { memberFacts } from './definition.js';
1
2
  import { frontmatter } from './document.js';
2
3
  import { linkInventory } from './links.js';
3
4
  import { target } from './paths.js';
4
5
  import { refusal } from './refuse.js';
5
6
  import { headingSpans } from './sections.js';
6
- import { bodyStartOf, mapEntry } from './yaml.js';
7
+ import { bodyStartOf } from './yaml.js';
7
8
  function internalEdits(content, bodyStart, file, documentTargets) {
8
9
  const inventory = linkInventory(content.slice(bodyStart));
9
10
  const internal = new Set();
@@ -43,32 +44,30 @@ export function rangeText(content, range, edits) {
43
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;
48
+ }
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;
56
+ }
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);
47
64
  }
48
65
  function freeTextValues(definition, document) {
49
66
  const root = frontmatter(document);
50
67
  if (root === null)
51
68
  return [];
52
69
  const values = [];
53
- for (const [name, spec] of Object.entries(definition.fields)) {
54
- const entry = mapEntry(root, name);
55
- if (entry === undefined)
56
- continue;
57
- const node = entry.value;
58
- if (spec.kind === 'text') {
59
- if (node.kind === 'scalar' && typeof node.value === 'string') {
60
- values.push({ start: node.start, end: node.end, text: `${node.value}\n\n` });
61
- }
62
- continue;
63
- }
64
- if (spec.kind !== 'list' || spec.of.kind !== 'text' || node.kind !== 'seq')
65
- continue;
66
- for (const item of node.items) {
67
- if (item.kind === 'scalar' && typeof item.value === 'string') {
68
- values.push({ start: item.start, end: item.end, text: `${item.value}\n\n` });
69
- }
70
- }
71
- }
70
+ proseValues(root, definition.frontmatter, values);
72
71
  return values;
73
72
  }
74
73
  export function projectionInput(document, file, context) {
@@ -0,0 +1,4 @@
1
+ import { type Definition } from './definition.js';
2
+ import type { Document, Reference } from './types.js';
3
+ export declare function references(document: Document, definition: Definition): readonly Reference[];
4
+ //# sourceMappingURL=references.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,UAAU,EAEhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAwBtD,wBAAgB,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,GAAG,SAAS,SAAS,EAAE,CAI3F"}
@@ -0,0 +1,25 @@
1
+ import { escapePointer, itemFacts, memberFacts, } from './definition.js';
2
+ import { isRecord } from './yaml.js';
3
+ function collect(value, facts, pointer, found) {
4
+ if (facts === undefined)
5
+ return;
6
+ if (typeof value === 'string') {
7
+ if (facts.reference !== undefined)
8
+ found.push({ pointer, value, to: facts.reference });
9
+ return;
10
+ }
11
+ if (Array.isArray(value)) {
12
+ for (const [index, item] of value.entries())
13
+ collect(item, itemFacts(facts, index), `${pointer}/${index}`, found);
14
+ return;
15
+ }
16
+ if (!isRecord(value))
17
+ return;
18
+ for (const [key, held] of Object.entries(value))
19
+ collect(held, memberFacts(facts, key), `${pointer}/${escapePointer(key)}`, found);
20
+ }
21
+ export function references(document, definition) {
22
+ const found = [];
23
+ collect(document.fields, definition.frontmatter, '', found);
24
+ return found;
25
+ }
package/dist/schema.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import type { FieldSpec, ScalarSpec } 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;
6
- export declare function fitsKind(spec: ScalarSpec, text: string): boolean;
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;
7
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,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAoB7D,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;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAGhE"}
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"}