@agentshouse/mdmodel 0.1.0-c37720432b75a → 0.1.0-c3c0e116a89f8

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 (143) hide show
  1. package/API.md +122 -100
  2. package/README.md +7 -5
  3. package/dist/definition.d.ts +1 -1
  4. package/dist/definition.d.ts.map +1 -1
  5. package/dist/definition.js +78 -24
  6. package/dist/divide.d.ts.map +1 -1
  7. package/dist/divide.js +5 -4
  8. package/dist/document.d.ts +5 -3
  9. package/dist/document.d.ts.map +1 -1
  10. package/dist/document.js +103 -57
  11. package/dist/event.d.ts +78 -0
  12. package/dist/event.d.ts.map +1 -0
  13. package/dist/event.js +201 -0
  14. package/dist/facts.d.ts +15 -0
  15. package/dist/facts.d.ts.map +1 -0
  16. package/dist/facts.js +41 -0
  17. package/dist/index.d.ts +21 -9
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +13 -6
  20. package/dist/kinds.d.ts +18 -0
  21. package/dist/kinds.d.ts.map +1 -0
  22. package/dist/kinds.js +150 -0
  23. package/dist/markdown.d.ts +51 -0
  24. package/dist/markdown.d.ts.map +1 -0
  25. package/dist/markdown.js +271 -0
  26. package/dist/paths.d.ts.map +1 -1
  27. package/dist/paths.js +9 -2
  28. package/dist/pattern.d.ts +10 -0
  29. package/dist/pattern.d.ts.map +1 -0
  30. package/dist/pattern.js +356 -0
  31. package/dist/project.d.ts.map +1 -1
  32. package/dist/project.js +16 -21
  33. package/dist/query/language.d.ts +254 -0
  34. package/dist/query/language.d.ts.map +1 -0
  35. package/dist/query/language.js +620 -0
  36. package/dist/query/match.d.ts +14 -0
  37. package/dist/query/match.d.ts.map +1 -0
  38. package/dist/query/match.js +150 -0
  39. package/dist/query/rows.d.ts +32 -0
  40. package/dist/query/rows.d.ts.map +1 -0
  41. package/dist/query/rows.js +161 -0
  42. package/dist/query/sql.d.ts +39 -0
  43. package/dist/query/sql.d.ts.map +1 -0
  44. package/dist/query/sql.js +285 -0
  45. package/dist/reserved.d.ts +6 -0
  46. package/dist/reserved.d.ts.map +1 -0
  47. package/dist/reserved.js +21 -0
  48. package/dist/schema.d.ts +1 -0
  49. package/dist/schema.d.ts.map +1 -1
  50. package/dist/schema.js +55 -4
  51. package/dist/types.d.ts +12 -0
  52. package/dist/types.d.ts.map +1 -1
  53. package/dist/validate.d.ts +7 -5
  54. package/dist/validate.d.ts.map +1 -1
  55. package/dist/validate.js +244 -113
  56. package/dist/yaml.d.ts.map +1 -1
  57. package/dist/yaml.js +40 -14
  58. package/fixtures/README.md +24 -3
  59. package/fixtures/cases/conditional-section/context.json +1 -0
  60. package/fixtures/cases/conditional-section/expected.json +6 -0
  61. package/fixtures/cases/conditional-section/library/questions/hosting.md +9 -0
  62. package/fixtures/cases/conditional-section/library/questions/payments.md +12 -0
  63. package/fixtures/cases/conditional-section/schema.yaml +14 -0
  64. package/fixtures/cases/lazy-list-item/context.json +1 -0
  65. package/fixtures/cases/lazy-list-item/expected.json +3 -0
  66. package/fixtures/cases/lazy-list-item/library/item.md +8 -0
  67. package/fixtures/cases/lazy-list-item/schema.yaml +3 -0
  68. package/fixtures/cases/link-into-a-reserved-name/context.json +1 -0
  69. package/fixtures/cases/link-into-a-reserved-name/expected.json +5 -0
  70. package/fixtures/cases/link-into-a-reserved-name/library/notes/a.md +6 -0
  71. package/fixtures/cases/link-into-a-reserved-name/schema.yaml +3 -0
  72. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/context.json +1 -0
  73. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/expected.json +5 -0
  74. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/library/notes/b.md +5 -0
  75. package/fixtures/cases/member-on-an-untyped-document/context.json +1 -0
  76. package/fixtures/cases/member-on-an-untyped-document/expected.json +6 -0
  77. package/fixtures/cases/member-on-an-untyped-document/library/note.md +4 -0
  78. package/fixtures/cases/member-on-another-type/context.json +1 -0
  79. package/fixtures/cases/member-on-another-type/expected.json +6 -0
  80. package/fixtures/cases/member-on-another-type/library/note.md +4 -0
  81. package/fixtures/cases/member-on-another-type/schema.yaml +7 -0
  82. package/fixtures/cases/reference-into-a-reserved-name/context.json +1 -0
  83. package/fixtures/cases/reference-into-a-reserved-name/expected.json +6 -0
  84. package/fixtures/cases/reference-into-a-reserved-name/library/notes/a.md +4 -0
  85. package/fixtures/cases/reference-into-a-reserved-name/library/settings/brief.md +1 -0
  86. package/fixtures/cases/reference-into-a-reserved-name/schema.yaml +3 -0
  87. package/fixtures/cases/room-md-declares-a-type/context.json +1 -0
  88. package/fixtures/cases/room-md-declares-a-type/expected.json +6 -0
  89. package/fixtures/cases/room-md-declares-a-type/library/ROOM.md +5 -0
  90. package/fixtures/cases/thematic-break-in-a-list-section/context.json +1 -0
  91. package/fixtures/cases/thematic-break-in-a-list-section/expected.json +6 -0
  92. package/fixtures/cases/thematic-break-in-a-list-section/library/item.md +7 -0
  93. package/fixtures/cases/thematic-break-in-a-list-section/schema.yaml +3 -0
  94. package/fixtures/cases/typed-path-names-another-type/context.json +11 -0
  95. package/fixtures/cases/typed-path-names-another-type/expected.json +6 -0
  96. package/fixtures/cases/typed-path-names-another-type/library/settings/prefs/one.md +3 -0
  97. package/fixtures/cases/typed-path-names-another-type/schema.yaml +6 -0
  98. package/fixtures/cases/typed-path-names-its-type/context.json +11 -0
  99. package/fixtures/cases/typed-path-names-its-type/expected.json +3 -0
  100. package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/deeper/two.md +1 -0
  101. package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/one.md +4 -0
  102. package/fixtures/cases/typed-path-names-its-type/schema.yaml +6 -0
  103. package/fixtures/cases/typed-path-names-no-type/context.json +11 -0
  104. package/fixtures/cases/typed-path-names-no-type/expected.json +6 -0
  105. package/fixtures/cases/typed-path-names-no-type/library/settings/prefs/one.md +1 -0
  106. package/fixtures/cases/typed-path-names-no-type/schema.yaml +6 -0
  107. package/fixtures/cases/unnamed-typed-path-checks-its-fields/context.json +11 -0
  108. package/fixtures/cases/unnamed-typed-path-checks-its-fields/expected.json +6 -0
  109. package/fixtures/cases/unnamed-typed-path-checks-its-fields/library/rooms/team/tasks/plan.md +4 -0
  110. package/fixtures/cases/unnamed-typed-path-checks-its-fields/schema.yaml +5 -0
  111. package/fixtures/cases/unnamed-typed-path-names-a-type/context.json +11 -0
  112. package/fixtures/cases/unnamed-typed-path-names-a-type/expected.json +6 -0
  113. package/fixtures/cases/unnamed-typed-path-names-a-type/library/rooms/team/tasks/plan.md +6 -0
  114. package/fixtures/cases/unnamed-typed-path-names-a-type/schema.yaml +5 -0
  115. package/fixtures/cases/unnamed-typed-path-reads-its-type/context.json +11 -0
  116. package/fixtures/cases/unnamed-typed-path-reads-its-type/expected.json +3 -0
  117. package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/plan.md +1 -0
  118. package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/tasks/plan.md +5 -0
  119. package/fixtures/cases/unnamed-typed-path-reads-its-type/schema.yaml +5 -0
  120. package/fixtures/cases/unnamed-typed-path-without-a-body/context.json +11 -0
  121. package/fixtures/cases/unnamed-typed-path-without-a-body/expected.json +5 -0
  122. package/fixtures/cases/unnamed-typed-path-without-a-body/library/rooms/team/tasks/plan.md +5 -0
  123. package/fixtures/cases/unnamed-typed-path-without-a-body/schema.yaml +5 -0
  124. package/fixtures/division.json +47 -2
  125. package/fixtures/preamble.json +24 -3
  126. package/fixtures/projection.json +105 -2
  127. package/fixtures/queries.json +964 -0
  128. package/package.json +15 -1
  129. package/dist/blocks.d.ts +0 -11
  130. package/dist/blocks.d.ts.map +0 -1
  131. package/dist/blocks.js +0 -69
  132. package/dist/condition.d.ts +0 -161
  133. package/dist/condition.d.ts.map +0 -1
  134. package/dist/condition.js +0 -615
  135. package/dist/links.d.ts +0 -29
  136. package/dist/links.d.ts.map +0 -1
  137. package/dist/links.js +0 -800
  138. package/dist/profile.d.ts +0 -6
  139. package/dist/profile.d.ts.map +0 -1
  140. package/dist/profile.js +0 -5
  141. package/dist/sections.d.ts +0 -11
  142. package/dist/sections.d.ts.map +0 -1
  143. package/dist/sections.js +0 -57
package/dist/paths.js CHANGED
@@ -1,6 +1,10 @@
1
1
  import { decodeNamedCharacterReference } from 'decode-named-character-reference';
2
2
  import { decodeNumericCharacterReference } from 'micromark-util-decode-numeric-character-reference';
3
- import { escapes } from './links.js';
3
+ const BACKSLASH = 0x5c;
4
+ const PUNCTUATION = /^[!-/:-@[-`{-~]$/;
5
+ function escapes(text, index) {
6
+ return text.charCodeAt(index) === BACKSLASH && PUNCTUATION.test(text[index + 1] ?? '');
7
+ }
4
8
  export function dirname(path) {
5
9
  const index = path.lastIndexOf('/');
6
10
  return index === -1 ? '' : path.slice(0, index);
@@ -61,7 +65,10 @@ function located(href) {
61
65
  const written = href.trim();
62
66
  const { base, suffix } = unescaped(written);
63
67
  const url = base.replace(/[\t\n\r]/g, '').replace(/^[\u0000-\u0020]+/, '');
64
- return { base: suffix === written.length ? url.replace(/[\u0000-\u0020]+$/, '') : url, suffix };
68
+ return {
69
+ base: suffix === written.length ? url.replace(/(?<![\u0000-\u0020])[\u0000-\u0020]+$/, '') : url,
70
+ suffix,
71
+ };
65
72
  }
66
73
  const ENCODED = /(?:%[0-9a-fA-F]{2})+/g;
67
74
  function decodedRun(run) {
@@ -0,0 +1,10 @@
1
+ export declare const PATTERN_STATES = 1000;
2
+ export declare class PatternTooCostly extends Error {
3
+ }
4
+ export type Pattern = {
5
+ readonly test: (text: string) => boolean;
6
+ };
7
+ export declare function linearPattern(source: string): Pattern | null;
8
+ export declare function withLinearRegExp<T>(run: () => T): T;
9
+ export declare function openPatternBudget(): () => void;
10
+ //# sourceMappingURL=pattern.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pattern.d.ts","sourceRoot":"","sources":["../src/pattern.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,OAAQ,CAAC;AAMpC,qBAAa,gBAAiB,SAAQ,KAAK;CAAG;AAQ9C,MAAM,MAAM,OAAO,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAA;CAAE,CAAC;AAkUnE,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAM5D;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CAkBnD;AAED,wBAAgB,iBAAiB,IAAI,MAAM,IAAI,CAM9C"}
@@ -0,0 +1,356 @@
1
+ const NativeRegExp = RegExp;
2
+ export const PATTERN_STATES = 1_000;
3
+ const VISIT_BUDGET = 100_000_000;
4
+ const HELD_PATTERNS = 512;
5
+ export class PatternTooCostly extends Error {
6
+ }
7
+ let scope = null;
8
+ const ASCII = 128;
9
+ class Unsupported extends Error {
10
+ }
11
+ const ATOM = 0;
12
+ const SPLIT = 1;
13
+ const ASSERT = 2;
14
+ const MATCH = 3;
15
+ class Atom {
16
+ literal;
17
+ ascii = new Int8Array(ASCII);
18
+ matcher;
19
+ constructor(source, literal) {
20
+ this.literal = literal;
21
+ this.matcher = new NativeRegExp(`^(?:${source})$`, 'u');
22
+ }
23
+ holds(point) {
24
+ if (this.literal !== null)
25
+ return point === this.literal;
26
+ if (point >= ASCII)
27
+ return this.matcher.test(String.fromCodePoint(point));
28
+ const known = this.ascii[point];
29
+ if (known !== 0)
30
+ return known > 0;
31
+ const held = this.matcher.test(String.fromCharCode(point));
32
+ this.ascii[point] = held ? 1 : -1;
33
+ return held;
34
+ }
35
+ }
36
+ class Reader {
37
+ source;
38
+ at = 0;
39
+ constructor(source) {
40
+ this.source = source;
41
+ }
42
+ peek(offset = 0) {
43
+ return this.source[this.at + offset];
44
+ }
45
+ starts(text) {
46
+ return this.source.startsWith(text, this.at);
47
+ }
48
+ }
49
+ function digits(reader) {
50
+ const from = reader.at;
51
+ while (/[0-9]/.test(reader.peek() ?? ''))
52
+ reader.at += 1;
53
+ return reader.at === from ? null : Number(reader.source.slice(from, reader.at));
54
+ }
55
+ function escapeEnd(source, at) {
56
+ const next = source[at + 1];
57
+ if (next === 'c')
58
+ return at + 3;
59
+ if (next === 'x')
60
+ return at + 4;
61
+ if ((next === 'u' && source[at + 2] === '{') || next === 'p' || next === 'P')
62
+ return source.indexOf('}', at + 2) + 1;
63
+ if (next !== 'u')
64
+ return at + 2;
65
+ const end = at + 6;
66
+ const lead = Number.parseInt(source.slice(at + 2, end), 16);
67
+ const trail = /^\\u([0-9a-fA-F]{4})$/.exec(source.slice(end, end + 6))?.[1];
68
+ const paired = lead >= 0xd800 &&
69
+ lead <= 0xdbff &&
70
+ trail !== undefined &&
71
+ Number.parseInt(trail, 16) >= 0xdc00 &&
72
+ Number.parseInt(trail, 16) <= 0xdfff;
73
+ return paired ? end + 6 : end;
74
+ }
75
+ function classEnd(source, at) {
76
+ let i = at + 1;
77
+ while (source[i] !== ']')
78
+ i += source[i] === '\\' ? 2 : 1;
79
+ return i + 1;
80
+ }
81
+ function escaped(reader) {
82
+ const next = reader.peek(1);
83
+ if (next === 'b' || next === 'B') {
84
+ reader.at += 2;
85
+ return { kind: 'assert', assertion: next === 'b' ? 'boundary' : 'inside' };
86
+ }
87
+ if (/[1-9k]/.test(next))
88
+ throw new Unsupported();
89
+ const end = escapeEnd(reader.source, reader.at);
90
+ const source = reader.source.slice(reader.at, end);
91
+ reader.at = end;
92
+ return { kind: 'atom', source, literal: false };
93
+ }
94
+ function group(reader) {
95
+ reader.at += 1;
96
+ if (reader.starts('?:'))
97
+ reader.at += 2;
98
+ else if (reader.starts('?<') && !reader.starts('?<=') && !reader.starts('?<!'))
99
+ reader.at = reader.source.indexOf('>', reader.at) + 1;
100
+ else if (reader.peek() === '?')
101
+ throw new Unsupported();
102
+ const alternatives = disjunction(reader);
103
+ reader.at += 1;
104
+ return { kind: 'group', alternatives };
105
+ }
106
+ function atom(reader) {
107
+ const character = reader.peek();
108
+ if (character === '^' || character === '$') {
109
+ reader.at += 1;
110
+ return { kind: 'assert', assertion: character === '^' ? 'start' : 'end' };
111
+ }
112
+ if (character === '\\')
113
+ return escaped(reader);
114
+ if (character === '(')
115
+ return group(reader);
116
+ if (character === '[' || character === '.') {
117
+ const end = character === '[' ? classEnd(reader.source, reader.at) : reader.at + 1;
118
+ const source = reader.source.slice(reader.at, end);
119
+ reader.at = end;
120
+ return { kind: 'atom', source, literal: false };
121
+ }
122
+ const source = String.fromCodePoint(reader.source.codePointAt(reader.at));
123
+ reader.at += source.length;
124
+ return { kind: 'atom', source, literal: true };
125
+ }
126
+ function quantified(reader, node) {
127
+ const sign = reader.peek();
128
+ let least = 1;
129
+ let most = 1;
130
+ if (sign === '*' || sign === '+' || sign === '?') {
131
+ reader.at += 1;
132
+ least = sign === '+' ? 1 : 0;
133
+ most = sign === '?' ? 1 : Infinity;
134
+ }
135
+ else if (sign === '{') {
136
+ reader.at += 1;
137
+ least = digits(reader);
138
+ most = least;
139
+ if (reader.peek() === ',') {
140
+ reader.at += 1;
141
+ most = digits(reader) ?? Infinity;
142
+ }
143
+ reader.at += 1;
144
+ }
145
+ else
146
+ return { node, least, most };
147
+ if (reader.peek() === '?')
148
+ reader.at += 1;
149
+ if (least > PATTERN_STATES || (Number.isFinite(most) && most > PATTERN_STATES))
150
+ throw new Unsupported();
151
+ return { node, least, most };
152
+ }
153
+ function disjunction(reader) {
154
+ const alternatives = [[]];
155
+ while (reader.at < reader.source.length && reader.peek() !== ')') {
156
+ if (reader.peek() === '|') {
157
+ reader.at += 1;
158
+ alternatives.push([]);
159
+ continue;
160
+ }
161
+ alternatives.at(-1).push(quantified(reader, atom(reader)));
162
+ }
163
+ return alternatives;
164
+ }
165
+ class Machine {
166
+ kinds = [];
167
+ outs = [];
168
+ alternates = [];
169
+ atoms = [];
170
+ assertions = [];
171
+ atomed = new Map();
172
+ state(kind, out, alternate = -1) {
173
+ if (this.kinds.length >= PATTERN_STATES)
174
+ throw new Unsupported();
175
+ this.kinds.push(kind);
176
+ this.outs.push(out);
177
+ this.alternates.push(alternate);
178
+ return this.kinds.length - 1;
179
+ }
180
+ atom(source, literal) {
181
+ const known = this.atomed.get(source);
182
+ if (known !== undefined)
183
+ return known;
184
+ this.atoms.push(new Atom(source, literal ? source.codePointAt(0) : null));
185
+ this.atomed.set(source, this.atoms.length - 1);
186
+ return this.atoms.length - 1;
187
+ }
188
+ node(node, next) {
189
+ if (node.kind === 'atom')
190
+ return this.state(ATOM, next, this.atom(node.source, node.literal));
191
+ if (node.kind === 'assert') {
192
+ this.assertions.push(node.assertion);
193
+ return this.state(ASSERT, next, this.assertions.length - 1);
194
+ }
195
+ return this.alternatives(node.alternatives, next);
196
+ }
197
+ alternatives(alternatives, next) {
198
+ let entry = this.sequence(alternatives.at(-1), next);
199
+ for (let index = alternatives.length - 2; index >= 0; index -= 1)
200
+ entry = this.state(SPLIT, this.sequence(alternatives[index], next), entry);
201
+ return entry;
202
+ }
203
+ sequence(terms, next) {
204
+ let entry = next;
205
+ for (let index = terms.length - 1; index >= 0; index -= 1)
206
+ entry = this.term(terms[index], entry);
207
+ return entry;
208
+ }
209
+ term({ node, least, most }, next) {
210
+ if (least === 1 && most === 1)
211
+ return this.node(node, next);
212
+ let entry = next;
213
+ if (most === Infinity) {
214
+ const loop = this.state(SPLIT, -1, next);
215
+ const body = this.node(node, loop);
216
+ if (body === loop)
217
+ return next;
218
+ this.outs[loop] = body;
219
+ entry = loop;
220
+ }
221
+ else
222
+ for (let copy = least; copy < most; copy += 1) {
223
+ const body = this.node(node, entry);
224
+ if (body === entry)
225
+ return next;
226
+ entry = this.state(SPLIT, body, entry);
227
+ }
228
+ for (let copy = 0; copy < least; copy += 1) {
229
+ const body = this.node(node, entry);
230
+ if (body === entry)
231
+ return next;
232
+ entry = body;
233
+ }
234
+ return entry;
235
+ }
236
+ }
237
+ function word(point) {
238
+ return ((point >= 0x30 && point <= 0x39) ||
239
+ (point >= 0x41 && point <= 0x5a) ||
240
+ (point >= 0x61 && point <= 0x7a) ||
241
+ point === 0x5f);
242
+ }
243
+ function holds(assertion, at, point, across) {
244
+ if (assertion === 'start')
245
+ return at === 0;
246
+ if (assertion === 'end')
247
+ return point === -1;
248
+ return assertion === 'boundary' ? across : !across;
249
+ }
250
+ class Linear {
251
+ machine;
252
+ start;
253
+ marks;
254
+ generation = 0;
255
+ constructor(machine, start) {
256
+ this.machine = machine;
257
+ this.start = start;
258
+ this.marks = new Float64Array(machine.kinds.length);
259
+ }
260
+ test(text) {
261
+ const { kinds, outs, alternates, atoms, assertions } = this.machine;
262
+ const marks = this.marks;
263
+ const budget = scope ?? { left: VISIT_BUDGET };
264
+ let seeds = [];
265
+ let wordBefore = false;
266
+ for (let at = 0;;) {
267
+ const point = at < text.length ? text.codePointAt(at) : -1;
268
+ const wordAt = word(point);
269
+ const across = wordBefore !== wordAt;
270
+ const generation = (this.generation += 1);
271
+ const active = [];
272
+ seeds.push(this.start);
273
+ while (seeds.length > 0) {
274
+ const state = seeds.pop();
275
+ if (marks[state] === generation)
276
+ continue;
277
+ marks[state] = generation;
278
+ if ((budget.left -= 1) < 0)
279
+ throw new PatternTooCostly();
280
+ const kind = kinds[state];
281
+ if (kind === MATCH)
282
+ return true;
283
+ if (kind === ATOM)
284
+ active.push(state);
285
+ else if (kind === SPLIT)
286
+ seeds.push(alternates[state], outs[state]);
287
+ else if (holds(assertions[alternates[state]], at, point, across))
288
+ seeds.push(outs[state]);
289
+ }
290
+ if (point === -1)
291
+ return false;
292
+ for (const state of active)
293
+ if (atoms[alternates[state]].holds(point))
294
+ seeds.push(outs[state]);
295
+ wordBefore = wordAt;
296
+ at += point > 0xffff ? 2 : 1;
297
+ }
298
+ }
299
+ }
300
+ function compiled(source) {
301
+ try {
302
+ new NativeRegExp(source, 'u');
303
+ }
304
+ catch {
305
+ return null;
306
+ }
307
+ try {
308
+ const alternatives = disjunction(new Reader(source));
309
+ const machine = new Machine();
310
+ const start = machine.alternatives(alternatives, machine.state(MATCH, -1));
311
+ return new Linear(machine, start);
312
+ }
313
+ catch (error) {
314
+ if (error instanceof Unsupported)
315
+ return null;
316
+ throw error;
317
+ }
318
+ }
319
+ const held = new Map();
320
+ export function linearPattern(source) {
321
+ if (held.has(source))
322
+ return held.get(source);
323
+ const made = compiled(source);
324
+ if (held.size >= HELD_PATTERNS)
325
+ held.delete(held.keys().next().value);
326
+ held.set(source, made);
327
+ return made;
328
+ }
329
+ export function withLinearRegExp(run) {
330
+ const native = globalThis.RegExp;
331
+ function LinearRegExp(source) {
332
+ new NativeRegExp(source, 'u');
333
+ return {
334
+ test(text) {
335
+ const pattern = linearPattern(source);
336
+ if (pattern === null)
337
+ throw new SyntaxError(`the pattern ${source} is not linear`);
338
+ return pattern.test(text);
339
+ },
340
+ };
341
+ }
342
+ globalThis.RegExp = LinearRegExp;
343
+ try {
344
+ return run();
345
+ }
346
+ finally {
347
+ globalThis.RegExp = native;
348
+ }
349
+ }
350
+ export function openPatternBudget() {
351
+ const outer = scope;
352
+ scope = outer ?? { left: VISIT_BUDGET };
353
+ return () => {
354
+ scope = outer;
355
+ };
356
+ }
@@ -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;AA0CtD,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;AA4BD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,GACzB,WAAW,CA+Bb;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":"AAKA,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;AA4BD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,GACzB,WAAW,CA0Bb;AAED,wBAAgB,OAAO,CACrB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,iBAA2C,GACnD,UAAU,CAMZ"}
package/dist/project.js CHANGED
@@ -1,42 +1,36 @@
1
1
  import { memberFacts } from './definition.js';
2
- import { frontmatter, inventoryOf } from './document.js';
3
- import { roomTarget, target } from './paths.js';
2
+ import { frontmatter, readingOf } from './document.js';
3
+ import { sectionSpans } from './markdown.js';
4
+ import { classifyHref } from './paths.js';
4
5
  import { refusal } from './refuse.js';
5
- import { headingSpans } from './sections.js';
6
6
  import { bodyStartOf } from './yaml.js';
7
- function internalEdits(content, inventory, bodyStart, file, documentTargets) {
7
+ function internalEdits(content, reading, file, documentTargets) {
8
8
  const internal = new Set();
9
- const uses = inventory.uses
9
+ const uses = reading.uses
10
10
  .filter((use) => {
11
- const resolved = target(file, use.destination.href);
12
- return resolved === null
13
- ? roomTarget(use.destination.href) !== null
14
- : documentTargets.has(resolved);
11
+ const resolved = classifyHref(file, use.destination.href);
12
+ return (resolved.kind === 'room' || (resolved.kind === 'path' && documentTargets.has(resolved.path)));
15
13
  })
16
14
  .sort((left, right) => left.start - right.start);
17
15
  const edits = [];
18
16
  for (let index = uses.length - 1; index >= 0; index -= 1) {
19
17
  const use = uses[index];
20
18
  internal.add(use.destination.start);
21
- const label = { start: bodyStart + use.labelStart, end: bodyStart + use.labelEnd };
19
+ const label = { start: use.labelStart, end: use.labelEnd };
22
20
  const inner = [];
23
21
  for (let nested = index + 1; nested < uses.length; nested += 1) {
24
22
  const edit = edits[uses.length - 1 - nested];
25
23
  if (edit.start >= label.end)
26
24
  break;
27
- if (edit.start >= label.start && edit.end <= label.end)
25
+ if (edit.end <= label.end)
28
26
  inner.push(edit);
29
27
  }
30
- edits.push({
31
- start: bodyStart + use.start,
32
- end: bodyStart + use.end,
33
- text: rangeText(content, label, inner),
34
- });
28
+ edits.push({ start: use.start, end: use.end, text: rangeText(content, label, inner) });
35
29
  }
36
- for (const block of inventory.blocks) {
30
+ for (const block of reading.definitions) {
37
31
  if (!internal.has(block.destination.start))
38
32
  continue;
39
- edits.push({ start: bodyStart + block.start, end: bodyStart + block.end, text: '' });
33
+ edits.push({ start: block.start, end: block.end, text: '' });
40
34
  }
41
35
  return edits.sort((left, right) => left.start - right.start);
42
36
  }
@@ -96,7 +90,8 @@ function freeTextValues(definition, document) {
96
90
  export function projectionInput(document, file, context) {
97
91
  const content = document.content;
98
92
  const bodyStart = bodyStartOf(content);
99
- const edits = internalEdits(content, inventoryOf(document), bodyStart, file, new Set(context.documentTargets));
93
+ const reading = readingOf(document);
94
+ const edits = internalEdits(content, reading, file, new Set(context.documentTargets));
100
95
  const declared = document.type;
101
96
  if (declared === undefined || declared === 'any') {
102
97
  return {
@@ -106,10 +101,10 @@ export function projectionInput(document, file, context) {
106
101
  }
107
102
  const definition = context.definition;
108
103
  if (definition === undefined) {
109
- return { ok: false, refusal: refusal(file, 'unknown-type', { location: 'type' }) };
104
+ return { ok: false, refusal: refusal(file, 'unknown-type') };
110
105
  }
111
106
  const structure = new Set(Object.entries(definition.sections).flatMap(([name, spec]) => (structural(spec) ? [name] : [])));
112
- const headings = headingSpans(content, bodyStart);
107
+ const headings = sectionSpans(reading, content.length);
113
108
  const ranges = [{ start: bodyStart, end: headings[0]?.headingStart ?? content.length }];
114
109
  for (const heading of headings) {
115
110
  if (structure.has(heading.name))