@agentshouse/mdmodel 0.1.0-ca3c1be3cd1a3 → 0.1.0-caaa5bad9995d

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 (247) hide show
  1. package/API.md +56 -104
  2. package/README.md +0 -1
  3. package/dist/definition.d.ts +2 -1
  4. package/dist/definition.d.ts.map +1 -1
  5. package/dist/definition.js +48 -9
  6. package/dist/document.d.ts +3 -1
  7. package/dist/document.d.ts.map +1 -1
  8. package/dist/document.js +69 -17
  9. package/dist/facts.d.ts.map +1 -1
  10. package/dist/facts.js +3 -2
  11. package/dist/house-model.d.ts +67 -25
  12. package/dist/house-model.d.ts.map +1 -1
  13. package/dist/house-model.js +44 -14
  14. package/dist/house-references/patterns.d.ts +5 -1
  15. package/dist/house-references/patterns.d.ts.map +1 -1
  16. package/dist/house-references/patterns.js +8 -1
  17. package/dist/index.d.ts +10 -10
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +8 -9
  20. package/dist/indexed.d.ts +1 -0
  21. package/dist/indexed.d.ts.map +1 -1
  22. package/dist/indexed.js +8 -0
  23. package/dist/kinds.d.ts +7 -1
  24. package/dist/kinds.d.ts.map +1 -1
  25. package/dist/kinds.js +19 -0
  26. package/dist/markdown.d.ts +0 -4
  27. package/dist/markdown.d.ts.map +1 -1
  28. package/dist/markdown.js +1 -34
  29. package/dist/paths.d.ts +1 -0
  30. package/dist/paths.d.ts.map +1 -1
  31. package/dist/paths.js +20 -4
  32. package/dist/query/language.d.ts +4 -1
  33. package/dist/query/language.d.ts.map +1 -1
  34. package/dist/query/language.js +4 -3
  35. package/dist/query/match.d.ts.map +1 -1
  36. package/dist/query/match.js +3 -24
  37. package/dist/query/rows.d.ts +4 -0
  38. package/dist/query/rows.d.ts.map +1 -1
  39. package/dist/query/rows.js +21 -0
  40. package/dist/query/sql.d.ts +7 -1
  41. package/dist/query/sql.d.ts.map +1 -1
  42. package/dist/query/sql.js +14 -3
  43. package/dist/query/walk.d.ts +69 -0
  44. package/dist/query/walk.d.ts.map +1 -0
  45. package/dist/query/walk.js +274 -0
  46. package/dist/reserved.d.ts +1 -0
  47. package/dist/reserved.d.ts.map +1 -1
  48. package/dist/reserved.js +15 -4
  49. package/dist/room-types.d.ts +2 -1
  50. package/dist/room-types.d.ts.map +1 -1
  51. package/dist/room-types.js +8 -0
  52. package/dist/types.d.ts +10 -21
  53. package/dist/types.d.ts.map +1 -1
  54. package/dist/validate.d.ts +2 -0
  55. package/dist/validate.d.ts.map +1 -1
  56. package/dist/validate.js +41 -12
  57. package/dist/view.d.ts +5 -0
  58. package/dist/view.d.ts.map +1 -0
  59. package/dist/view.js +27 -0
  60. package/dist/yaml.d.ts +3 -1
  61. package/dist/yaml.d.ts.map +1 -1
  62. package/dist/yaml.js +153 -32
  63. package/fixtures/README.md +53 -56
  64. package/fixtures/cases/absent-link-dangles/{schema.yaml → schema.md} +2 -0
  65. package/fixtures/cases/absent-optional-field/{schema.yaml → schema.md} +2 -0
  66. package/fixtures/cases/absolute-link/{schema.yaml → schema.md} +2 -0
  67. package/fixtures/cases/attachment-reference-any-file/{schema.yaml → schema.md} +2 -0
  68. package/fixtures/cases/attachment-reference-dangles/{schema.yaml → schema.md} +2 -0
  69. package/fixtures/cases/attachment-reference-outside/{schema.yaml → schema.md} +2 -0
  70. package/fixtures/cases/binary-any-reference/{schema.yaml → schema.md} +2 -0
  71. package/fixtures/cases/binary-document-collision/{schema.yaml → schema.md} +2 -0
  72. package/fixtures/cases/binary-image-dangles/{schema.yaml → schema.md} +2 -0
  73. package/fixtures/cases/binary-link-dangles/{schema.yaml → schema.md} +2 -0
  74. package/fixtures/cases/binary-link-outside-collection/{schema.yaml → schema.md} +2 -0
  75. package/fixtures/cases/binary-prototype-reference/{schema.yaml → schema.md} +2 -0
  76. package/fixtures/cases/binary-typed-reference/{schema.yaml → schema.md} +2 -0
  77. package/fixtures/cases/block-scalar-frontmatter/expected.json +1 -0
  78. package/fixtures/cases/block-scalar-frontmatter/library/notes/literal.md +17 -0
  79. package/fixtures/cases/block-scalar-frontmatter/library/skills/notes/SKILL.md +10 -0
  80. package/fixtures/cases/boolean-field/{schema.yaml → schema.md} +2 -0
  81. package/fixtures/cases/{duplicate-link-definition/schema.yaml → bracketed-link-definition/schema.md} +2 -0
  82. package/fixtures/cases/closed-nested-object/{schema.yaml → schema.md} +2 -0
  83. package/fixtures/cases/composed-root-reference/{schema.yaml → schema.md} +2 -0
  84. package/fixtures/cases/conditional-long-text/{schema.yaml → schema.md} +2 -0
  85. package/fixtures/cases/cross-room-link/{schema.yaml → schema.md} +2 -0
  86. package/fixtures/cases/cross-room-reference/{schema.yaml → schema.md} +2 -0
  87. package/fixtures/cases/date-time-format/{schema.yaml → schema.md} +2 -0
  88. package/fixtures/cases/declared-binary-links/schema.md +3 -0
  89. package/fixtures/cases/default-unfilled/schema.md +57 -0
  90. package/fixtures/cases/defs-pattern/schema.md +57 -0
  91. package/fixtures/cases/dependent-rule/schema.md +57 -0
  92. package/fixtures/cases/{bracketed-link-definition/schema.yaml → duplicate-link-definition/schema.md} +2 -0
  93. package/fixtures/cases/email-format/schema.md +57 -0
  94. package/fixtures/cases/equal-labels/{schema.yaml → schema.md} +2 -0
  95. package/fixtures/cases/fenced-link-definition/schema.md +7 -0
  96. package/fixtures/cases/field-enum/{schema.yaml → schema.md} +2 -0
  97. package/fixtures/cases/frontmatter-construct/context.json +1 -0
  98. package/fixtures/cases/frontmatter-construct/expected.json +7 -0
  99. package/fixtures/cases/frontmatter-construct/library/note.md +6 -0
  100. package/fixtures/cases/integer-field/schema.md +57 -0
  101. package/fixtures/cases/interrupted-link-definition/schema.md +3 -0
  102. package/fixtures/cases/json-schema-constructs/schema.md +57 -0
  103. package/fixtures/cases/labels-in-the-rooms-language/{schema.yaml → schema.md} +2 -0
  104. package/fixtures/cases/lazy-list-item/{schema.yaml → schema.md} +2 -0
  105. package/fixtures/cases/link-into-a-reserved-name/{schema.yaml → schema.md} +2 -0
  106. package/fixtures/cases/list-item-enum/{schema.yaml → schema.md} +2 -0
  107. package/fixtures/cases/list-item-kind/{schema.yaml → schema.md} +2 -0
  108. package/fixtures/cases/list-items/{schema.yaml → schema.md} +2 -0
  109. package/fixtures/cases/list-of-objects-closed/schema.md +57 -0
  110. package/fixtures/cases/list-of-objects-item/schema.md +57 -0
  111. package/fixtures/cases/list-of-objects-reference/{schema.yaml → schema.md} +2 -0
  112. package/fixtures/cases/list-reference-path/{schema.yaml → schema.md} +2 -0
  113. package/fixtures/cases/list-reference-type/{schema.yaml → schema.md} +2 -0
  114. package/fixtures/cases/list-size/schema.md +57 -0
  115. package/fixtures/cases/long-fence-link-definition/schema.md +3 -0
  116. package/fixtures/cases/long-value-past-six-levels/{schema.yaml → schema.md} +2 -0
  117. package/fixtures/cases/malformed-definition/{schema.yaml → schema.md} +2 -0
  118. package/fixtures/cases/malformed-list/{schema.yaml → schema.md} +2 -0
  119. package/fixtures/cases/member-document/{schema.yaml → schema.md} +2 -0
  120. package/fixtures/cases/member-on-another-type/{schema.yaml → schema.md} +2 -0
  121. package/fixtures/cases/missing-required-field/{schema.yaml → schema.md} +2 -0
  122. package/fixtures/cases/misspelled-key/schema.md +57 -0
  123. package/fixtures/cases/name-not-a-string/{schema.yaml → schema.md} +2 -0
  124. package/fixtures/cases/nested-defs/{schema.yaml → schema.md} +2 -0
  125. package/fixtures/cases/nested-object-reference/schema.md +34 -0
  126. package/fixtures/cases/nested-reference/schema.md +34 -0
  127. package/fixtures/cases/nested-required-field/schema.md +57 -0
  128. package/fixtures/cases/numeric-range/schema.md +57 -0
  129. package/fixtures/cases/one-key-two-labels/{schema.yaml → schema.md} +2 -0
  130. package/fixtures/cases/one-key-two-types/{schema.yaml → schema.md} +2 -0
  131. package/fixtures/cases/one-of-variant/schema.md +57 -0
  132. package/fixtures/cases/other-room-reference/schema.md +34 -0
  133. package/fixtures/cases/paragraph-link-definition/schema.md +3 -0
  134. package/fixtures/cases/prototype-field/schema.md +7 -0
  135. package/fixtures/cases/quoted-link-definition/schema.md +3 -0
  136. package/fixtures/cases/reference-into-a-reserved-name/{schema.yaml → schema.md} +2 -0
  137. package/fixtures/cases/reference-to-any-file-name/context.json +1 -0
  138. package/fixtures/cases/reference-to-any-file-name/expected.json +1 -0
  139. package/fixtures/cases/reference-to-any-file-name/library/people/100%.md +4 -0
  140. package/fixtures/cases/reference-to-any-file-name/library/people/C#.md +4 -0
  141. package/fixtures/cases/reference-to-any-file-name/library/people/My notes.md +4 -0
  142. package/fixtures/cases/reference-to-any-file-name/library/people/[draft].md +4 -0
  143. package/fixtures/cases/reference-to-any-file-name/library/people/c (d).md +4 -0
  144. package/fixtures/cases/reference-to-any-file-name/library/people/caf/303/251.md +4 -0
  145. package/fixtures/cases/reference-to-any-file-name/library/people//320/236/321/202/321/207/321/221/321/202.md +4 -0
  146. package/fixtures/cases/reference-to-any-file-name/library/tasks/bracket.md +9 -0
  147. package/fixtures/cases/reference-to-any-file-name/library/tasks/cyrillic.md +9 -0
  148. package/fixtures/cases/reference-to-any-file-name/library/tasks/decomposed.md +9 -0
  149. package/fixtures/cases/reference-to-any-file-name/library/tasks/hash.md +9 -0
  150. package/fixtures/cases/reference-to-any-file-name/library/tasks/parenthesis.md +9 -0
  151. package/fixtures/cases/reference-to-any-file-name/library/tasks/percent.md +9 -0
  152. package/fixtures/cases/reference-to-any-file-name/library/tasks/spaced.md +9 -0
  153. package/fixtures/cases/{referenced-missing-file/schema.yaml → reference-to-any-file-name/schema.md} +2 -0
  154. package/fixtures/cases/referenced-missing-file/schema.md +12 -0
  155. package/fixtures/cases/referenced-missing-non-latin-file/context.json +1 -0
  156. package/fixtures/cases/referenced-missing-non-latin-file/expected.json +6 -0
  157. package/fixtures/cases/referenced-missing-non-latin-file/library/tasks/a.md +9 -0
  158. package/fixtures/cases/referenced-missing-non-latin-file/library/tasks/b.md +9 -0
  159. package/fixtures/cases/referenced-missing-non-latin-file/schema.md +12 -0
  160. package/fixtures/cases/remote-ref/{schema.yaml → schema.md} +2 -0
  161. package/fixtures/cases/schema-body-ignored/context.json +1 -0
  162. package/fixtures/cases/schema-body-ignored/expected.json +1 -0
  163. package/fixtures/cases/schema-body-ignored/schema.md +9 -0
  164. package/fixtures/cases/schema-type-named-folders/context.json +1 -0
  165. package/fixtures/cases/schema-type-named-folders/expected.json +5 -0
  166. package/fixtures/cases/schema-type-named-folders/schema.md +5 -0
  167. package/fixtures/cases/schema-type-named-type/context.json +1 -0
  168. package/fixtures/cases/schema-type-named-type/expected.json +5 -0
  169. package/fixtures/cases/{unknown-type/schema.yaml → schema-type-named-type/schema.md} +3 -1
  170. package/fixtures/cases/second-member-document/{schema.yaml → schema.md} +2 -0
  171. package/fixtures/cases/sections-keyword-refused/{schema.yaml → schema.md} +2 -0
  172. package/fixtures/cases/shortcut-reference-link/schema.md +7 -0
  173. package/fixtures/cases/string-length/schema.md +57 -0
  174. package/fixtures/cases/submission-keys/{schema.yaml → schema.md} +2 -0
  175. package/fixtures/cases/text-field-kind/{schema.yaml → schema.md} +2 -0
  176. package/fixtures/cases/thematic-break-ends-the-values/{schema.yaml → schema.md} +2 -0
  177. package/fixtures/cases/truncated-link-definition/schema.md +3 -0
  178. package/fixtures/cases/typed-path-names-another-type/{schema.yaml → schema.md} +2 -0
  179. package/fixtures/cases/typed-path-names-its-type/{schema.yaml → schema.md} +2 -0
  180. package/fixtures/cases/typed-path-names-no-type/{schema.yaml → schema.md} +2 -0
  181. package/fixtures/cases/types-folder-content/{schema.yaml → schema.md} +2 -0
  182. package/fixtures/cases/undeclared-field/schema.md +7 -0
  183. package/fixtures/cases/unevaluated-items-closed/{schema.yaml → schema.md} +2 -0
  184. package/fixtures/cases/unique-in-app-schema/context.json +1 -0
  185. package/fixtures/cases/unique-in-app-schema/expected.json +5 -0
  186. package/fixtures/cases/unique-in-app-schema/schema.yaml +7 -0
  187. package/fixtures/cases/unique-indexed-field/context.json +1 -0
  188. package/fixtures/cases/unique-indexed-field/expected.json +1 -0
  189. package/fixtures/cases/unique-indexed-field/library/tickets/first.md +8 -0
  190. package/fixtures/cases/unique-indexed-field/library/tickets/second.md +8 -0
  191. package/fixtures/cases/unique-indexed-field/schema.md +9 -0
  192. package/fixtures/cases/unique-off-indexed-field/context.json +1 -0
  193. package/fixtures/cases/unique-off-indexed-field/expected.json +5 -0
  194. package/fixtures/cases/unique-off-indexed-field/schema.md +9 -0
  195. package/fixtures/cases/unlisted-reference-type/{schema.yaml → schema.md} +2 -0
  196. package/fixtures/cases/unnamed-typed-path-checks-its-fields/{schema.yaml → schema.md} +2 -0
  197. package/fixtures/cases/unnamed-typed-path-names-a-type/{schema.yaml → schema.md} +2 -0
  198. package/fixtures/cases/unnamed-typed-path-reads-its-type/{schema.yaml → schema.md} +2 -0
  199. package/fixtures/cases/unnamed-typed-path-without-a-body/{schema.yaml → schema.md} +2 -0
  200. package/fixtures/cases/unresolved-link/schema.md +7 -0
  201. package/fixtures/cases/valid-typed-document/{schema.yaml → schema.md} +2 -0
  202. package/fixtures/cases/wide-item-fence-link/schema.md +3 -0
  203. package/fixtures/forms.json +24 -0
  204. package/fixtures/preamble.json +4 -4
  205. package/fixtures/queries.json +413 -1
  206. package/fixtures/references.json +15 -0
  207. package/package.json +1 -1
  208. package/dist/divide.d.ts +0 -3
  209. package/dist/divide.d.ts.map +0 -1
  210. package/dist/divide.js +0 -321
  211. package/dist/project.d.ts +0 -22
  212. package/dist/project.d.ts.map +0 -1
  213. package/dist/project.js +0 -101
  214. package/fixtures/cases/declared-binary-links/schema.yaml +0 -1
  215. package/fixtures/cases/default-unfilled/schema.yaml +0 -55
  216. package/fixtures/cases/defs-pattern/schema.yaml +0 -55
  217. package/fixtures/cases/dependent-rule/schema.yaml +0 -55
  218. package/fixtures/cases/email-format/schema.yaml +0 -55
  219. package/fixtures/cases/fenced-link-definition/schema.yaml +0 -5
  220. package/fixtures/cases/frontmatter-schema/expected.json +0 -5
  221. package/fixtures/cases/integer-field/schema.yaml +0 -55
  222. package/fixtures/cases/interrupted-link-definition/schema.yaml +0 -1
  223. package/fixtures/cases/json-schema-constructs/schema.yaml +0 -55
  224. package/fixtures/cases/list-of-objects-closed/schema.yaml +0 -55
  225. package/fixtures/cases/list-of-objects-item/schema.yaml +0 -55
  226. package/fixtures/cases/list-size/schema.yaml +0 -55
  227. package/fixtures/cases/long-fence-link-definition/schema.yaml +0 -1
  228. package/fixtures/cases/misspelled-key/schema.yaml +0 -55
  229. package/fixtures/cases/nested-object-reference/schema.yaml +0 -32
  230. package/fixtures/cases/nested-reference/schema.yaml +0 -32
  231. package/fixtures/cases/nested-required-field/schema.yaml +0 -55
  232. package/fixtures/cases/numeric-range/schema.yaml +0 -55
  233. package/fixtures/cases/one-of-variant/schema.yaml +0 -55
  234. package/fixtures/cases/other-room-reference/schema.yaml +0 -32
  235. package/fixtures/cases/paragraph-link-definition/schema.yaml +0 -1
  236. package/fixtures/cases/prototype-field/schema.yaml +0 -5
  237. package/fixtures/cases/quoted-link-definition/schema.yaml +0 -1
  238. package/fixtures/cases/shortcut-reference-link/schema.yaml +0 -5
  239. package/fixtures/cases/string-length/schema.yaml +0 -55
  240. package/fixtures/cases/truncated-link-definition/schema.yaml +0 -1
  241. package/fixtures/cases/undeclared-field/schema.yaml +0 -5
  242. package/fixtures/cases/unresolved-link/schema.yaml +0 -5
  243. package/fixtures/cases/wide-item-fence-link/schema.yaml +0 -1
  244. package/fixtures/division.json +0 -454
  245. package/fixtures/projection.json +0 -358
  246. /package/fixtures/cases/{frontmatter-schema → block-scalar-frontmatter}/context.json +0 -0
  247. /package/fixtures/cases/{frontmatter-schema/schema.yaml → unknown-type/schema.md} +0 -0
package/dist/divide.js DELETED
@@ -1,321 +0,0 @@
1
- import { readingOf } from './document.js';
2
- import { blockRanges, headingsIn } from './markdown.js';
3
- import { firstEditFrom, projectionInput, rangeText, } from './project.js';
4
- import { refusal } from './refuse.js';
5
- const SMALLEST_BOUND = 2;
6
- function node(draft) {
7
- return {
8
- start: draft.start,
9
- end: draft.end,
10
- bodyStart: draft.bodyStart,
11
- heading: draft.heading,
12
- children: draft.children.map(node),
13
- };
14
- }
15
- function forest(state, range) {
16
- const headings = headingsIn(state.reading, range.start, range.end);
17
- const roots = [];
18
- const open = [];
19
- const first = headings[0]?.start ?? range.end;
20
- if (first > range.start) {
21
- roots.push({
22
- level: 0,
23
- start: range.start,
24
- end: first,
25
- bodyStart: range.start,
26
- heading: '',
27
- children: [],
28
- });
29
- }
30
- for (const heading of headings) {
31
- while ((open[open.length - 1]?.level ?? 0) >= heading.level) {
32
- open.pop().end = heading.start;
33
- }
34
- const draft = {
35
- level: heading.level,
36
- start: heading.start,
37
- end: range.end,
38
- bodyStart: heading.next,
39
- heading: `${textOf(state, { start: heading.start, end: heading.textEnd })}\n\n`,
40
- children: [],
41
- };
42
- (open[open.length - 1]?.children ?? roots).push(draft);
43
- open.push(draft);
44
- }
45
- return roots.map(node);
46
- }
47
- function isSpace(character) {
48
- return character === ' ' || character === '\t' || character === '\n' || character === '\r';
49
- }
50
- const TERMINATORS = new Set(['.', '!', '?', '…', '。', '!', '?']);
51
- function isTerminator(character) {
52
- return TERMINATORS.has(character);
53
- }
54
- const CLOSERS = new Set(['"', "'", ')', ']', '»', '”']);
55
- function isCloser(character) {
56
- return CLOSERS.has(character);
57
- }
58
- function sentenceBounds(text) {
59
- const bounds = [0];
60
- let i = 0;
61
- while (i < text.length) {
62
- if (!isTerminator(text[i])) {
63
- i += 1;
64
- continue;
65
- }
66
- let after = i + 1;
67
- while (after < text.length && isCloser(text[after]))
68
- after += 1;
69
- if (after >= text.length || !isSpace(text[after])) {
70
- i = after + 1;
71
- continue;
72
- }
73
- while (after < text.length && isSpace(text[after]))
74
- after += 1;
75
- if (after < text.length)
76
- bounds.push(after);
77
- i = after;
78
- }
79
- bounds.push(text.length);
80
- return bounds;
81
- }
82
- function isTrailingSurrogate(text, index) {
83
- const code = text.charCodeAt(index);
84
- return code >= 0xdc00 && code <= 0xdfff;
85
- }
86
- function characterLength(text, index) {
87
- return isTrailingSurrogate(text, index + 1) ? 2 : 1;
88
- }
89
- function boundOf(cutting, from, to, bound) {
90
- const limit = from + bound;
91
- if (limit >= to)
92
- return to;
93
- for (let index = limit; index > from + 1; index -= 1) {
94
- if (isSpace(cutting.text[index]))
95
- return index;
96
- }
97
- const inside = cutting.masks.find((mask) => limit > mask.start && limit < mask.end);
98
- if (inside !== undefined)
99
- return inside.start > from ? inside.start : Math.min(inside.end, to);
100
- return isTrailingSurrogate(cutting.text, limit) ? limit - 1 : limit;
101
- }
102
- function utf8Size(code) {
103
- if (code < 0x80)
104
- return 1;
105
- if (code < 0x800)
106
- return 2;
107
- if (code < 0x10000)
108
- return 3;
109
- return 4;
110
- }
111
- function byteBounds(content, spans) {
112
- const marks = [...new Set(spans.flatMap((span) => [span.start, span.end]))].sort((left, right) => left - right);
113
- const bytes = new Map();
114
- let index = 0;
115
- let count = 0;
116
- for (const mark of marks) {
117
- while (index < mark) {
118
- const code = content.codePointAt(index);
119
- count += utf8Size(code);
120
- index += code > 0xffff ? 2 : 1;
121
- }
122
- bytes.set(mark, count);
123
- }
124
- return spans.map((span) => ({
125
- ...span,
126
- start: bytes.get(span.start),
127
- end: bytes.get(span.end),
128
- }));
129
- }
130
- function textOf(state, extent) {
131
- return rangeText(state.content, extent, state.edits);
132
- }
133
- function sourceCutting(state, extent) {
134
- const source = state.content.slice(extent.start, extent.end);
135
- const masks = [];
136
- for (let index = firstEditFrom(state.edits, extent.start); index < state.edits.length; index += 1) {
137
- const edit = state.edits[index];
138
- if (edit.start > extent.end)
139
- break;
140
- if (edit.end > extent.end)
141
- continue;
142
- masks.push({ start: edit.start - extent.start, end: edit.end - extent.start });
143
- }
144
- let text = '';
145
- let cursor = 0;
146
- for (const mask of masks) {
147
- if (mask.end <= cursor)
148
- continue;
149
- const from = Math.max(mask.start, cursor);
150
- text += `${source.slice(cursor, from)}${'x'.repeat(mask.end - from)}`;
151
- cursor = mask.end;
152
- }
153
- text += source.slice(cursor);
154
- return {
155
- text,
156
- masks,
157
- piece: (from, to) => {
158
- const cut = { start: extent.start + from, end: extent.start + to };
159
- return { ...cut, text: textOf(state, cut) };
160
- },
161
- };
162
- }
163
- function valueCutting(value) {
164
- return {
165
- text: value.text,
166
- masks: [],
167
- piece: (from, to) => ({ start: value.start, end: value.end, text: value.text.slice(from, to) }),
168
- };
169
- }
170
- function prefixOf(state, body) {
171
- if (body.emitted === 0 || body.heading.length >= state.bound)
172
- return '';
173
- return body.heading;
174
- }
175
- function available(state, body) {
176
- return state.bound - prefixOf(state, body).length;
177
- }
178
- function emit(state, body, piece, bare = false) {
179
- if (piece.text.trim() === '')
180
- return;
181
- const text = (bare ? '' : prefixOf(state, body)) + piece.text;
182
- state.spans.push({ start: piece.start, end: piece.end, text });
183
- body.emitted += 1;
184
- }
185
- function merge(run) {
186
- return {
187
- start: Math.min(...run.map((unit) => unit.start)),
188
- end: Math.max(...run.map((unit) => unit.end)),
189
- text: run.map((unit) => unit.text).join(''),
190
- };
191
- }
192
- function divideUnits(state, body, units) {
193
- let run = [];
194
- let length = 0;
195
- const flush = () => {
196
- if (run.length === 0)
197
- return;
198
- emit(state, body, merge(run));
199
- run = [];
200
- length = 0;
201
- };
202
- for (const unit of units) {
203
- if (run.length > 0 && length + unit.text.length > available(state, body))
204
- flush();
205
- if (unit.text.length > available(state, body)) {
206
- flush();
207
- unit.descend();
208
- continue;
209
- }
210
- run.push(unit);
211
- length += unit.text.length;
212
- }
213
- flush();
214
- }
215
- function divideBound(state, body, cutting, range) {
216
- let start = range.start;
217
- while (start < range.end) {
218
- const bare = available(state, body) < characterLength(cutting.text, start);
219
- const room = bare ? state.bound : available(state, body);
220
- const stop = boundOf(cutting, start, range.end, room);
221
- const piece = cutting.piece(start, stop);
222
- if (cutting.masks.length === 0 || piece.text.length <= room) {
223
- emit(state, body, piece, bare);
224
- }
225
- else {
226
- divideBound(state, body, valueCutting(piece), { start: 0, end: piece.text.length });
227
- }
228
- start = stop;
229
- }
230
- }
231
- function divideSentences(state, body, cutting) {
232
- const cut = cutting.piece;
233
- const bounds = sentenceBounds(cutting.text);
234
- let index = 0;
235
- while (index + 1 < bounds.length) {
236
- const alone = { start: bounds[index], end: bounds[index + 1] };
237
- if (cut(alone.start, alone.end).text.length > available(state, body)) {
238
- divideBound(state, body, cutting, alone);
239
- index += 1;
240
- continue;
241
- }
242
- const carried = bounds[Math.max(index - 1, 0)];
243
- const from = cut(carried, alone.end).text.length <= available(state, body) ? carried : alone.start;
244
- let last = index;
245
- while (last + 2 < bounds.length &&
246
- cut(from, bounds[last + 2]).text.length <= available(state, body)) {
247
- last += 1;
248
- }
249
- emit(state, body, cut(from, bounds[last + 1]));
250
- index = last + 1;
251
- }
252
- }
253
- function blockUnit(state, body, block) {
254
- return {
255
- start: block.start,
256
- end: block.end,
257
- text: textOf(state, block),
258
- descend: () => divideSentences(state, body, sourceCutting(state, block)),
259
- };
260
- }
261
- function valueUnit(state, body, value) {
262
- return {
263
- start: value.start,
264
- end: value.end,
265
- text: value.text,
266
- descend: () => divideSentences(state, body, valueCutting(value)),
267
- };
268
- }
269
- function nodeUnit(state, subject) {
270
- return {
271
- start: subject.start,
272
- end: subject.end,
273
- text: textOf(state, subject),
274
- descend: () => divideNode(state, subject),
275
- };
276
- }
277
- function ownBlocks(subject, end, blocks) {
278
- const first = blocks[0];
279
- return first === undefined
280
- ? [{ start: subject.start, end }]
281
- : [{ start: subject.start, end: first.end }, ...blocks.slice(1)];
282
- }
283
- function divideNode(state, subject) {
284
- const end = subject.children[0]?.start ?? subject.end;
285
- const blocks = blockRanges(state.reading, subject.bodyStart, end);
286
- const children = { heading: '', emitted: 0 };
287
- if (blocks.length === 0 && subject.children.length > 0) {
288
- const [first, ...rest] = subject.children;
289
- const led = [{ ...first, start: subject.start }, ...rest];
290
- divideUnits(state, children, led.map((child) => nodeUnit(state, child)));
291
- return;
292
- }
293
- const body = { heading: subject.heading, emitted: 0 };
294
- const own = ownBlocks(subject, end, blocks);
295
- divideUnits(state, body, own.map((block) => blockUnit(state, body, block)));
296
- divideUnits(state, children, subject.children.map((child) => nodeUnit(state, child)));
297
- }
298
- function divideInput(state, input) {
299
- const body = { heading: '', emitted: 0 };
300
- divideUnits(state, body, [
301
- ...input.values.map((value) => valueUnit(state, body, value)),
302
- ...input.ranges.flatMap((range) => forest(state, range).map((subject) => nodeUnit(state, subject))),
303
- ]);
304
- }
305
- export function divide(document, file, context) {
306
- if (!Number.isInteger(context.bound) || context.bound < SMALLEST_BOUND) {
307
- return { ok: false, refusal: refusal(file, 'division-bound') };
308
- }
309
- const result = projectionInput(document, file, context);
310
- if (!result.ok)
311
- return { ok: false, refusal: result.refusal };
312
- const state = {
313
- content: document.content,
314
- reading: readingOf(document),
315
- edits: result.input.edits,
316
- bound: context.bound,
317
- spans: [],
318
- };
319
- divideInput(state, result.input);
320
- return { ok: true, spans: byteBounds(document.content, state.spans) };
321
- }
package/dist/project.d.ts DELETED
@@ -1,22 +0,0 @@
1
- import type { Document, Extent, Projection, ProjectionContext, Refusal } from './types.js';
2
- export type Piece = Extent & {
3
- readonly text: string;
4
- };
5
- export type Edit = Piece;
6
- export type Input = {
7
- readonly values: readonly Piece[];
8
- readonly ranges: readonly Extent[];
9
- readonly edits: readonly Edit[];
10
- };
11
- export type InputResult = {
12
- readonly ok: true;
13
- readonly input: Input;
14
- } | {
15
- readonly ok: false;
16
- readonly refusal: Refusal;
17
- };
18
- export declare function firstEditFrom(edits: readonly Edit[], start: number): number;
19
- export declare function rangeText(content: string, range: Extent, edits: readonly Edit[]): string;
20
- export declare function projectionInput(document: Document, file: string, context: ProjectionContext): InputResult;
21
- export declare function project(document: Document, file: string, context?: ProjectionContext): Projection;
22
- //# sourceMappingURL=project.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG3F,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD,MAAM,MAAM,IAAI,GAAG,KAAK,CAAC;AAEzB,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAC5C;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAqCtD,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAS3E;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,MAAM,CAWxF;AAOD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,GACzB,WAAW,CA4Bb;AAED,wBAAgB,OAAO,CACrB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,iBAA2C,GACnD,UAAU,CAMZ"}
package/dist/project.js DELETED
@@ -1,101 +0,0 @@
1
- import { bodyWith, readingOf } from './document.js';
2
- import { classifyHref } from './paths.js';
3
- import { refusal } from './refuse.js';
4
- import { bodyStartOf } from './yaml.js';
5
- function internalEdits(content, reading, file, documentTargets) {
6
- const internal = new Set();
7
- const uses = reading.uses
8
- .filter((use) => {
9
- const resolved = classifyHref(file, use.destination.href);
10
- return (resolved.kind === 'room' || (resolved.kind === 'path' && documentTargets.has(resolved.path)));
11
- })
12
- .sort((left, right) => left.start - right.start);
13
- const edits = [];
14
- for (let index = uses.length - 1; index >= 0; index -= 1) {
15
- const use = uses[index];
16
- internal.add(use.destination.start);
17
- const label = { start: use.labelStart, end: use.labelEnd };
18
- const inner = [];
19
- for (let nested = index + 1; nested < uses.length; nested += 1) {
20
- const edit = edits[uses.length - 1 - nested];
21
- if (edit.start >= label.end)
22
- break;
23
- if (edit.end <= label.end)
24
- inner.push(edit);
25
- }
26
- edits.push({ start: use.start, end: use.end, text: rangeText(content, label, inner) });
27
- }
28
- for (const block of reading.definitions) {
29
- if (!internal.has(block.destination.start))
30
- continue;
31
- edits.push({ start: block.start, end: block.end, text: '' });
32
- }
33
- return edits.sort((left, right) => left.start - right.start);
34
- }
35
- export function firstEditFrom(edits, start) {
36
- let low = 0;
37
- let high = edits.length;
38
- while (low < high) {
39
- const middle = (low + high) >>> 1;
40
- if (edits[middle].start < start)
41
- low = middle + 1;
42
- else
43
- high = middle;
44
- }
45
- return low;
46
- }
47
- export function rangeText(content, range, edits) {
48
- let text = '';
49
- let cursor = range.start;
50
- for (let index = firstEditFrom(edits, range.start); index < edits.length; index += 1) {
51
- const edit = edits[index];
52
- if (edit.start > range.end)
53
- break;
54
- if (edit.start < cursor || edit.end > range.end)
55
- continue;
56
- text += content.slice(cursor, edit.start) + edit.text;
57
- cursor = edit.end;
58
- }
59
- return text + content.slice(cursor, range.end);
60
- }
61
- function linked(edits, range) {
62
- const at = firstEditFrom(edits, range.start);
63
- return at < edits.length && edits[at].start < range.end;
64
- }
65
- export function projectionInput(document, file, context) {
66
- const content = document.content;
67
- const bodyStart = bodyStartOf(content);
68
- const reading = readingOf(document);
69
- const edits = internalEdits(content, reading, file, new Set(context.documentTargets));
70
- const declared = document.type;
71
- const definition = context.definition;
72
- if (definition === undefined && declared !== undefined && declared !== 'any')
73
- return { ok: false, refusal: refusal(file, 'unknown-type') };
74
- const body = definition === undefined ? null : bodyWith(document, definition);
75
- if (body === null || !('top' in body)) {
76
- return {
77
- ok: true,
78
- input: { values: [], ranges: [{ start: bodyStart, end: content.length }], edits },
79
- };
80
- }
81
- const values = body.prose
82
- .filter((one) => !one.markdown)
83
- .map((one) => ({
84
- start: one.start,
85
- end: one.end,
86
- text: `${linked(edits, one) ? rangeText(content, one, edits) : one.text}\n\n`,
87
- }));
88
- const ranges = [
89
- ...body.prose.filter((one) => one.markdown).map(({ start, end }) => ({ start, end })),
90
- ...body.free,
91
- ].sort((left, right) => left.start - right.start);
92
- return { ok: true, input: { values, ranges, edits } };
93
- }
94
- export function project(document, file, context = { documentTargets: [] }) {
95
- const result = projectionInput(document, file, context);
96
- if (!result.ok)
97
- return { ok: false, refusal: result.refusal };
98
- const { values, ranges, edits } = result.input;
99
- const prose = ranges.map((range) => rangeText(document.content, range, edits)).join('');
100
- return { ok: true, text: values.map((value) => value.text).join('') + prose };
101
- }
@@ -1 +0,0 @@
1
- note: {}
@@ -1,55 +0,0 @@
1
- $defs:
2
- address:
3
- type: object
4
- properties:
5
- city: { type: string }
6
- country: { type: string, pattern: '^[A-Z]{2}$' }
7
- required: [ city ]
8
- company:
9
- properties:
10
- name: { type: string }
11
- deal:
12
- type: object
13
- properties:
14
- title: { type: string, minLength: 1, maxLength: 40 }
15
- company: { type: string, reference: company }
16
- stage: { enum: [ lead, proposal, won, lost ], default: lead }
17
- amount: { type: integer, minimum: 0 }
18
- probability: { type: number, minimum: 0, maximum: 1 }
19
- open: { type: boolean }
20
- closes_at: { type: string, format: date-time }
21
- contact_email: { type: string, format: email }
22
- note: { type: [ string, 'null' ] }
23
- shipping: { $ref: '#/$defs/address' }
24
- tags: { type: array, items: { type: string }, maxItems: 3 }
25
- lines:
26
- type: array
27
- items:
28
- type: object
29
- properties:
30
- product: { type: string }
31
- quantity: { type: integer, minimum: 1 }
32
- required: [ product, quantity ]
33
- blocks:
34
- type: array
35
- items:
36
- oneOf:
37
- - properties:
38
- kind: { const: paragraph }
39
- text: { type: string }
40
- required: [ kind, text ]
41
- - properties:
42
- kind: { const: quiz }
43
- question: { type: string }
44
- required: [ kind, question ]
45
- attributes:
46
- type: object
47
- additionalProperties: { type: string }
48
- description: { type: string, contentMediaType: text/markdown, title: Description }
49
- required: [ title, company, stage ]
50
- if:
51
- properties:
52
- stage: { const: won }
53
- required: [ stage ]
54
- then:
55
- required: [ amount ]
@@ -1,55 +0,0 @@
1
- $defs:
2
- address:
3
- type: object
4
- properties:
5
- city: { type: string }
6
- country: { type: string, pattern: '^[A-Z]{2}$' }
7
- required: [ city ]
8
- company:
9
- properties:
10
- name: { type: string }
11
- deal:
12
- type: object
13
- properties:
14
- title: { type: string, minLength: 1, maxLength: 40 }
15
- company: { type: string, reference: company }
16
- stage: { enum: [ lead, proposal, won, lost ], default: lead }
17
- amount: { type: integer, minimum: 0 }
18
- probability: { type: number, minimum: 0, maximum: 1 }
19
- open: { type: boolean }
20
- closes_at: { type: string, format: date-time }
21
- contact_email: { type: string, format: email }
22
- note: { type: [ string, 'null' ] }
23
- shipping: { $ref: '#/$defs/address' }
24
- tags: { type: array, items: { type: string }, maxItems: 3 }
25
- lines:
26
- type: array
27
- items:
28
- type: object
29
- properties:
30
- product: { type: string }
31
- quantity: { type: integer, minimum: 1 }
32
- required: [ product, quantity ]
33
- blocks:
34
- type: array
35
- items:
36
- oneOf:
37
- - properties:
38
- kind: { const: paragraph }
39
- text: { type: string }
40
- required: [ kind, text ]
41
- - properties:
42
- kind: { const: quiz }
43
- question: { type: string }
44
- required: [ kind, question ]
45
- attributes:
46
- type: object
47
- additionalProperties: { type: string }
48
- description: { type: string, contentMediaType: text/markdown, title: Description }
49
- required: [ title, company, stage ]
50
- if:
51
- properties:
52
- stage: { const: won }
53
- required: [ stage ]
54
- then:
55
- required: [ amount ]
@@ -1,55 +0,0 @@
1
- $defs:
2
- address:
3
- type: object
4
- properties:
5
- city: { type: string }
6
- country: { type: string, pattern: '^[A-Z]{2}$' }
7
- required: [ city ]
8
- company:
9
- properties:
10
- name: { type: string }
11
- deal:
12
- type: object
13
- properties:
14
- title: { type: string, minLength: 1, maxLength: 40 }
15
- company: { type: string, reference: company }
16
- stage: { enum: [ lead, proposal, won, lost ], default: lead }
17
- amount: { type: integer, minimum: 0 }
18
- probability: { type: number, minimum: 0, maximum: 1 }
19
- open: { type: boolean }
20
- closes_at: { type: string, format: date-time }
21
- contact_email: { type: string, format: email }
22
- note: { type: [ string, 'null' ] }
23
- shipping: { $ref: '#/$defs/address' }
24
- tags: { type: array, items: { type: string }, maxItems: 3 }
25
- lines:
26
- type: array
27
- items:
28
- type: object
29
- properties:
30
- product: { type: string }
31
- quantity: { type: integer, minimum: 1 }
32
- required: [ product, quantity ]
33
- blocks:
34
- type: array
35
- items:
36
- oneOf:
37
- - properties:
38
- kind: { const: paragraph }
39
- text: { type: string }
40
- required: [ kind, text ]
41
- - properties:
42
- kind: { const: quiz }
43
- question: { type: string }
44
- required: [ kind, question ]
45
- attributes:
46
- type: object
47
- additionalProperties: { type: string }
48
- description: { type: string, contentMediaType: text/markdown, title: Description }
49
- required: [ title, company, stage ]
50
- if:
51
- properties:
52
- stage: { const: won }
53
- required: [ stage ]
54
- then:
55
- required: [ amount ]
@@ -1,55 +0,0 @@
1
- $defs:
2
- address:
3
- type: object
4
- properties:
5
- city: { type: string }
6
- country: { type: string, pattern: '^[A-Z]{2}$' }
7
- required: [ city ]
8
- company:
9
- properties:
10
- name: { type: string }
11
- deal:
12
- type: object
13
- properties:
14
- title: { type: string, minLength: 1, maxLength: 40 }
15
- company: { type: string, reference: company }
16
- stage: { enum: [ lead, proposal, won, lost ], default: lead }
17
- amount: { type: integer, minimum: 0 }
18
- probability: { type: number, minimum: 0, maximum: 1 }
19
- open: { type: boolean }
20
- closes_at: { type: string, format: date-time }
21
- contact_email: { type: string, format: email }
22
- note: { type: [ string, 'null' ] }
23
- shipping: { $ref: '#/$defs/address' }
24
- tags: { type: array, items: { type: string }, maxItems: 3 }
25
- lines:
26
- type: array
27
- items:
28
- type: object
29
- properties:
30
- product: { type: string }
31
- quantity: { type: integer, minimum: 1 }
32
- required: [ product, quantity ]
33
- blocks:
34
- type: array
35
- items:
36
- oneOf:
37
- - properties:
38
- kind: { const: paragraph }
39
- text: { type: string }
40
- required: [ kind, text ]
41
- - properties:
42
- kind: { const: quiz }
43
- question: { type: string }
44
- required: [ kind, question ]
45
- attributes:
46
- type: object
47
- additionalProperties: { type: string }
48
- description: { type: string, contentMediaType: text/markdown, title: Description }
49
- required: [ title, company, stage ]
50
- if:
51
- properties:
52
- stage: { const: won }
53
- required: [ stage ]
54
- then:
55
- required: [ amount ]
@@ -1,5 +0,0 @@
1
- task:
2
- properties:
3
- title: { type: string }
4
- description: { type: string, contentMediaType: text/markdown, minLength: 1, title: Description }
5
- required: [ title, description ]
@@ -1,5 +0,0 @@
1
- {
2
- "verdict": "refuse",
3
- "location": "line 1",
4
- "rule": "schema-yaml"
5
- }