@agentshouse/mdmodel 0.1.0-c375119e5613a → 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 +131 -109
  2. package/README.md +8 -6
  3. package/dist/definition.d.ts +2 -1
  4. package/dist/definition.d.ts.map +1 -1
  5. package/dist/definition.js +107 -26
  6. package/dist/divide.d.ts.map +1 -1
  7. package/dist/divide.js +5 -4
  8. package/dist/document.d.ts +5 -5
  9. package/dist/document.d.ts.map +1 -1
  10. package/dist/document.js +114 -79
  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 +23 -10
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +14 -7
  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 -3
  52. package/dist/types.d.ts.map +1 -1
  53. package/dist/validate.d.ts +28 -5
  54. package/dist/validate.d.ts.map +1 -1
  55. package/dist/validate.js +325 -160
  56. package/dist/yaml.d.ts.map +1 -1
  57. package/dist/yaml.js +40 -14
  58. package/fixtures/README.md +25 -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 +16 -2
  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 -162
  133. package/dist/condition.d.ts.map +0 -1
  134. package/dist/condition.js +0 -616
  135. package/dist/links.d.ts +0 -29
  136. package/dist/links.d.ts.map +0 -1
  137. package/dist/links.js +0 -788
  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
@@ -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))
@@ -0,0 +1,254 @@
1
+ import { type Definition } from '../definition.js';
2
+ export type Value = string | number | boolean | null;
3
+ export type Predicate = Value | {
4
+ $eq: Value;
5
+ } | {
6
+ $ne: Value;
7
+ } | {
8
+ $in: readonly Value[];
9
+ } | {
10
+ $nin: readonly Value[];
11
+ } | {
12
+ $gt?: Value;
13
+ $gte?: Value;
14
+ $lt?: Value;
15
+ $lte?: Value;
16
+ } | {
17
+ $all: readonly Value[];
18
+ } | {
19
+ $size: number;
20
+ } | {
21
+ $exists: boolean;
22
+ } | {
23
+ $prefix: string;
24
+ };
25
+ export type Where = {
26
+ $and?: readonly Where[];
27
+ $or?: readonly Where[];
28
+ [field: string]: Predicate | readonly Where[] | undefined;
29
+ };
30
+ export type Related = {
31
+ types?: readonly string[];
32
+ where?: Where;
33
+ pathPrefix?: string;
34
+ };
35
+ export type Filter = {
36
+ rooms?: readonly string[];
37
+ types?: readonly string[];
38
+ where?: Where;
39
+ pathPrefix?: string;
40
+ outside?: readonly string[];
41
+ folder?: string;
42
+ paths?: readonly string[];
43
+ fileIds?: readonly string[];
44
+ hop?: Related & {
45
+ field: string;
46
+ };
47
+ backlinks?: Related & {
48
+ field?: string;
49
+ };
50
+ text?: string;
51
+ };
52
+ export type Key = 'room' | 'path' | 'type' | 'folder' | 'size' | 'created' | 'updated' | {
53
+ field: string;
54
+ };
55
+ export type GroupKey = 'room' | 'type' | 'folder' | 'subfolder' | {
56
+ field: string;
57
+ };
58
+ export type Select = 'all' | {
59
+ fields?: 'all' | readonly string[];
60
+ sections?: 'all' | readonly string[];
61
+ preamble?: true;
62
+ markdown?: true;
63
+ backlinks?: true;
64
+ change?: true;
65
+ fileId?: true;
66
+ revision?: true;
67
+ size?: true;
68
+ created?: true;
69
+ };
70
+ export type GroupSelect = {
71
+ size?: true;
72
+ updated?: true;
73
+ greatest?: {
74
+ field: string;
75
+ };
76
+ };
77
+ export type GroupOrder = 'count' | 'size' | 'updated' | 'greatest';
78
+ export type OrderOptions = {
79
+ nulls?: 'first' | 'last';
80
+ stringSort?: 'lexical' | 'locale';
81
+ locale?: string;
82
+ localeOptions?: Readonly<Record<string, unknown>>;
83
+ };
84
+ export type Direction = 'asc' | 'desc';
85
+ export type DocumentQuery = Filter & {
86
+ select: Select;
87
+ orderBy?: readonly ({
88
+ by: Key;
89
+ direction?: Direction;
90
+ } & OrderOptions)[];
91
+ limit?: number;
92
+ after?: string;
93
+ total?: true;
94
+ };
95
+ export type GroupQuery = Filter & {
96
+ groupBy: readonly GroupKey[];
97
+ select?: GroupSelect;
98
+ orderBy?: readonly {
99
+ by: GroupOrder | GroupKey;
100
+ direction?: Direction;
101
+ nulls?: 'first' | 'last';
102
+ }[];
103
+ limit?: number;
104
+ after?: string;
105
+ total?: true;
106
+ };
107
+ export type LocalQuery = DocumentQuery | GroupQuery;
108
+ export type QueryErrorCode = 'invalid-query' | 'unknown-type' | 'unknown-field' | 'wrong-kind';
109
+ export type RoomFacts = {
110
+ locator: string;
111
+ available: boolean;
112
+ types: readonly Definition[];
113
+ };
114
+ export type HeldRooms = {
115
+ listed: boolean;
116
+ rooms: readonly RoomFacts[];
117
+ };
118
+ export type Test = {
119
+ op: 'eq';
120
+ value: Value;
121
+ } | {
122
+ op: 'ne';
123
+ value: Value;
124
+ } | {
125
+ op: 'in';
126
+ values: readonly Value[];
127
+ } | {
128
+ op: 'nin';
129
+ values: readonly Value[];
130
+ } | {
131
+ op: 'range';
132
+ bounds: readonly (readonly ['gt' | 'gte' | 'lt' | 'lte', Value])[];
133
+ } | {
134
+ op: 'all';
135
+ values: readonly Value[];
136
+ } | {
137
+ op: 'size';
138
+ size: number;
139
+ } | {
140
+ op: 'exists';
141
+ exists: boolean;
142
+ } | {
143
+ op: 'prefix';
144
+ prefix: string;
145
+ };
146
+ export type Clause = {
147
+ every: readonly Clause[];
148
+ } | {
149
+ some: readonly Clause[];
150
+ } | {
151
+ field: string;
152
+ test: Test;
153
+ };
154
+ export type Scope = {
155
+ types: readonly string[] | null;
156
+ where: Clause | null;
157
+ pathPrefix: string | null;
158
+ };
159
+ export type KeyPlan = {
160
+ of: 'room';
161
+ } | {
162
+ of: 'path';
163
+ } | {
164
+ of: 'type';
165
+ } | {
166
+ of: 'folder';
167
+ } | {
168
+ of: 'subfolder';
169
+ } | {
170
+ of: 'size';
171
+ } | {
172
+ of: 'created';
173
+ } | {
174
+ of: 'updated';
175
+ } | {
176
+ of: 'field';
177
+ field: string;
178
+ };
179
+ export type DocumentShape = {
180
+ kind: 'documents';
181
+ fields: 'all' | readonly string[] | null;
182
+ sections: 'all' | readonly string[] | null;
183
+ preamble: boolean;
184
+ markdown: boolean;
185
+ backlinks: boolean;
186
+ change: boolean;
187
+ fileId: boolean;
188
+ revision: boolean;
189
+ size: boolean;
190
+ created: boolean;
191
+ orderBy: readonly {
192
+ key: KeyPlan;
193
+ options: OrderOptions & {
194
+ direction: Direction;
195
+ };
196
+ }[];
197
+ };
198
+ export type GroupShape = {
199
+ kind: 'groups';
200
+ groupBy: readonly KeyPlan[];
201
+ size: boolean;
202
+ updated: boolean;
203
+ greatest: string | null;
204
+ orderBy: readonly {
205
+ by: GroupOrder | number;
206
+ direction: Direction;
207
+ nulls: 'first' | 'last' | null;
208
+ }[];
209
+ };
210
+ export type Continuation = {
211
+ text: string;
212
+ values: readonly unknown[] | null;
213
+ };
214
+ export type QueryPlan = {
215
+ key: string;
216
+ rooms: readonly string[] | null;
217
+ root: Scope;
218
+ outside: readonly string[] | null;
219
+ folder: string | null;
220
+ paths: readonly string[] | null;
221
+ fileIds: readonly string[] | null;
222
+ hop: (Scope & {
223
+ field: string;
224
+ }) | null;
225
+ backlinks: (Scope & {
226
+ field: string | null;
227
+ }) | null;
228
+ text: string | null;
229
+ shape: DocumentShape | GroupShape;
230
+ limit: number | null;
231
+ after: Continuation | null;
232
+ total: boolean;
233
+ };
234
+ export type Place = readonly (string | number)[];
235
+ type At = Place | string;
236
+ export declare class QueryError extends Error {
237
+ readonly code: QueryErrorCode;
238
+ readonly place: Place;
239
+ readonly accepts: readonly string[];
240
+ readonly retryable = false;
241
+ constructor(code: QueryErrorCode, at: At, problem: string, accepts?: readonly string[]);
242
+ }
243
+ type Entries = Readonly<Record<string, unknown>>;
244
+ export declare function bodied(shape: DocumentShape): boolean;
245
+ export declare function invalid(at: At, problem: string, accepts?: readonly string[]): never;
246
+ export declare function placeText(at: Place): string;
247
+ export declare function known(value: Entries, allowed: readonly string[], at: At): void;
248
+ export declare function planOf(input: unknown, facts: HeldRooms): QueryPlan;
249
+ export declare function cursorOf(values: readonly unknown[]): string;
250
+ export declare function decodedCursor(text: string): readonly unknown[] | null;
251
+ export declare function queryKey(query: unknown): string;
252
+ export declare function identityOf(plan: QueryPlan): string;
253
+ export {};
254
+ //# sourceMappingURL=language.d.ts.map