@agentshouse/mdmodel 0.1.0-c04c0d681d2d4 → 0.1.0-c08b2adadd2fe
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.
- package/API.md +150 -110
- package/README.md +8 -6
- package/dist/definition.d.ts +3 -1
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +138 -26
- package/dist/divide.d.ts.map +1 -1
- package/dist/divide.js +5 -4
- package/dist/document.d.ts +9 -5
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +169 -67
- package/dist/event.d.ts +78 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +201 -0
- package/dist/facts.d.ts +15 -0
- package/dist/facts.d.ts.map +1 -0
- package/dist/facts.js +41 -0
- package/dist/index.d.ts +23 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -7
- package/dist/kinds.d.ts +18 -0
- package/dist/kinds.d.ts.map +1 -0
- package/dist/kinds.js +150 -0
- package/dist/markdown.d.ts +51 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +271 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +9 -2
- package/dist/pattern.d.ts +10 -0
- package/dist/pattern.d.ts.map +1 -0
- package/dist/pattern.js +356 -0
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +16 -21
- package/dist/query/language.d.ts +254 -0
- package/dist/query/language.d.ts.map +1 -0
- package/dist/query/language.js +620 -0
- package/dist/query/match.d.ts +14 -0
- package/dist/query/match.d.ts.map +1 -0
- package/dist/query/match.js +150 -0
- package/dist/query/rows.d.ts +32 -0
- package/dist/query/rows.d.ts.map +1 -0
- package/dist/query/rows.js +161 -0
- package/dist/query/sql.d.ts +39 -0
- package/dist/query/sql.d.ts.map +1 -0
- package/dist/query/sql.js +285 -0
- package/dist/reserved.d.ts +6 -0
- package/dist/reserved.d.ts.map +1 -0
- package/dist/reserved.js +21 -0
- package/dist/schema.d.ts +1 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +55 -4
- package/dist/types.d.ts +19 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +29 -5
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +327 -161
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +40 -14
- package/fixtures/README.md +25 -3
- package/fixtures/cases/conditional-section/context.json +1 -0
- package/fixtures/cases/conditional-section/expected.json +6 -0
- package/fixtures/cases/conditional-section/library/questions/hosting.md +9 -0
- package/fixtures/cases/conditional-section/library/questions/payments.md +12 -0
- package/fixtures/cases/conditional-section/schema.yaml +14 -0
- package/fixtures/cases/lazy-list-item/context.json +1 -0
- package/fixtures/cases/lazy-list-item/expected.json +3 -0
- package/fixtures/cases/lazy-list-item/library/item.md +8 -0
- package/fixtures/cases/lazy-list-item/schema.yaml +3 -0
- package/fixtures/cases/link-into-a-reserved-name/context.json +1 -0
- package/fixtures/cases/link-into-a-reserved-name/expected.json +5 -0
- package/fixtures/cases/link-into-a-reserved-name/library/notes/a.md +6 -0
- package/fixtures/cases/link-into-a-reserved-name/schema.yaml +3 -0
- package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/context.json +1 -0
- package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/expected.json +5 -0
- package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/library/notes/b.md +5 -0
- package/fixtures/cases/member-on-an-untyped-document/context.json +1 -0
- package/fixtures/cases/member-on-an-untyped-document/expected.json +6 -0
- package/fixtures/cases/member-on-an-untyped-document/library/note.md +4 -0
- package/fixtures/cases/member-on-another-type/context.json +1 -0
- package/fixtures/cases/member-on-another-type/expected.json +6 -0
- package/fixtures/cases/member-on-another-type/library/note.md +4 -0
- package/fixtures/cases/member-on-another-type/schema.yaml +7 -0
- package/fixtures/cases/reference-into-a-reserved-name/context.json +1 -0
- package/fixtures/cases/reference-into-a-reserved-name/expected.json +6 -0
- package/fixtures/cases/reference-into-a-reserved-name/library/notes/a.md +4 -0
- package/fixtures/cases/reference-into-a-reserved-name/library/settings/brief.md +1 -0
- package/fixtures/cases/reference-into-a-reserved-name/schema.yaml +3 -0
- package/fixtures/cases/room-md-declares-a-type/context.json +1 -0
- package/fixtures/cases/room-md-declares-a-type/expected.json +6 -0
- package/fixtures/cases/room-md-declares-a-type/library/ROOM.md +5 -0
- package/fixtures/cases/thematic-break-in-a-list-section/context.json +1 -0
- package/fixtures/cases/thematic-break-in-a-list-section/expected.json +6 -0
- package/fixtures/cases/thematic-break-in-a-list-section/library/item.md +7 -0
- package/fixtures/cases/thematic-break-in-a-list-section/schema.yaml +3 -0
- package/fixtures/cases/typed-path-names-another-type/context.json +11 -0
- package/fixtures/cases/typed-path-names-another-type/expected.json +6 -0
- package/fixtures/cases/typed-path-names-another-type/library/settings/prefs/one.md +3 -0
- package/fixtures/cases/typed-path-names-another-type/schema.yaml +6 -0
- package/fixtures/cases/typed-path-names-its-type/context.json +11 -0
- package/fixtures/cases/typed-path-names-its-type/expected.json +3 -0
- package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/deeper/two.md +1 -0
- package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/one.md +4 -0
- package/fixtures/cases/typed-path-names-its-type/schema.yaml +6 -0
- package/fixtures/cases/typed-path-names-no-type/context.json +11 -0
- package/fixtures/cases/typed-path-names-no-type/expected.json +6 -0
- package/fixtures/cases/typed-path-names-no-type/library/settings/prefs/one.md +1 -0
- package/fixtures/cases/typed-path-names-no-type/schema.yaml +6 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/expected.json +6 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/library/rooms/team/tasks/plan.md +4 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/schema.yaml +5 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/expected.json +6 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/library/rooms/team/tasks/plan.md +6 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/schema.yaml +5 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/expected.json +3 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/plan.md +1 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/tasks/plan.md +5 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/schema.yaml +5 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/expected.json +5 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/library/rooms/team/tasks/plan.md +5 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/schema.yaml +5 -0
- package/fixtures/division.json +47 -2
- package/fixtures/preamble.json +24 -3
- package/fixtures/projection.json +105 -2
- package/fixtures/queries.json +964 -0
- package/package.json +16 -2
- package/dist/blocks.d.ts +0 -11
- package/dist/blocks.d.ts.map +0 -1
- package/dist/blocks.js +0 -69
- package/dist/condition.d.ts +0 -162
- package/dist/condition.d.ts.map +0 -1
- package/dist/condition.js +0 -616
- package/dist/links.d.ts +0 -29
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -788
- package/dist/profile.d.ts +0 -6
- package/dist/profile.d.ts.map +0 -1
- package/dist/profile.js +0 -5
- package/dist/sections.d.ts +0 -11
- package/dist/sections.d.ts.map +0 -1
- package/dist/sections.js +0 -57
package/dist/yaml.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
export class YamlError extends Error {
|
|
2
2
|
offset;
|
|
3
3
|
constructor(offset) {
|
|
4
|
-
super(
|
|
4
|
+
super();
|
|
5
5
|
this.offset = offset;
|
|
6
6
|
this.name = 'YamlError';
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
+
const YAML_DEPTH_MAX = 64;
|
|
10
|
+
function nested(c, parse) {
|
|
11
|
+
if (c.depth >= YAML_DEPTH_MAX)
|
|
12
|
+
throw new YamlError(c.i);
|
|
13
|
+
c.depth += 1;
|
|
14
|
+
try {
|
|
15
|
+
return parse();
|
|
16
|
+
}
|
|
17
|
+
finally {
|
|
18
|
+
c.depth -= 1;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
9
21
|
function peek(c) {
|
|
10
22
|
return c.i < c.end ? c.text[c.i] : '';
|
|
11
23
|
}
|
|
@@ -70,7 +82,10 @@ function indentAt(c) {
|
|
|
70
82
|
}
|
|
71
83
|
return n;
|
|
72
84
|
}
|
|
85
|
+
const UNHELD_TEXT = /[\0\ud800-\udfff]/u;
|
|
73
86
|
function scalar(value, start, end) {
|
|
87
|
+
if (typeof value === 'string' && UNHELD_TEXT.test(value))
|
|
88
|
+
throw new YamlError(start);
|
|
74
89
|
return { kind: 'scalar', value, start, end };
|
|
75
90
|
}
|
|
76
91
|
export function interpretPlain(text) {
|
|
@@ -202,9 +217,10 @@ function parseFlowValue(c) {
|
|
|
202
217
|
return parseScalar(c, true);
|
|
203
218
|
}
|
|
204
219
|
function parseFlowMap(c) {
|
|
220
|
+
return nested(c, () => flowMap(c));
|
|
221
|
+
}
|
|
222
|
+
function flowMap(c) {
|
|
205
223
|
const start = c.i;
|
|
206
|
-
if (peek(c) !== '{')
|
|
207
|
-
throw new YamlError(c.i);
|
|
208
224
|
c.i += 1;
|
|
209
225
|
skipFlowSpace(c);
|
|
210
226
|
const entries = [];
|
|
@@ -240,9 +256,10 @@ function parseFlowMap(c) {
|
|
|
240
256
|
throw new YamlError(c.i);
|
|
241
257
|
}
|
|
242
258
|
function parseFlowSeq(c) {
|
|
259
|
+
return nested(c, () => flowSeq(c));
|
|
260
|
+
}
|
|
261
|
+
function flowSeq(c) {
|
|
243
262
|
const start = c.i;
|
|
244
|
-
if (peek(c) !== '[')
|
|
245
|
-
throw new YamlError(c.i);
|
|
246
263
|
c.i += 1;
|
|
247
264
|
skipFlowSpace(c);
|
|
248
265
|
const items = [];
|
|
@@ -314,10 +331,8 @@ function mappingAhead(c) {
|
|
|
314
331
|
const next = c.text[c.i + 1];
|
|
315
332
|
return next === ' ' || next === '\n' || next === '\r' || c.i + 1 >= c.end;
|
|
316
333
|
}
|
|
317
|
-
catch
|
|
318
|
-
|
|
319
|
-
return false;
|
|
320
|
-
throw error;
|
|
334
|
+
catch {
|
|
335
|
+
return false;
|
|
321
336
|
}
|
|
322
337
|
finally {
|
|
323
338
|
c.i = start;
|
|
@@ -336,6 +351,9 @@ function parseSeqItem(c, indent) {
|
|
|
336
351
|
return parseValue(c, indent);
|
|
337
352
|
}
|
|
338
353
|
function parseBlockSeq(c, indent) {
|
|
354
|
+
return nested(c, () => blockSeq(c, indent));
|
|
355
|
+
}
|
|
356
|
+
function blockSeq(c, indent) {
|
|
339
357
|
const start = c.i;
|
|
340
358
|
const items = [];
|
|
341
359
|
let end = start;
|
|
@@ -355,6 +373,9 @@ function parseBlockSeq(c, indent) {
|
|
|
355
373
|
return { kind: 'seq', items, start, end };
|
|
356
374
|
}
|
|
357
375
|
function parseBlockMap(c, indent, inline = false) {
|
|
376
|
+
return nested(c, () => blockMap(c, indent, inline));
|
|
377
|
+
}
|
|
378
|
+
function blockMap(c, indent, inline) {
|
|
358
379
|
const start = c.i;
|
|
359
380
|
const entries = [];
|
|
360
381
|
const seen = new Set();
|
|
@@ -387,7 +408,7 @@ function parseBlockMap(c, indent, inline = false) {
|
|
|
387
408
|
return { kind: 'map', entries, start, end };
|
|
388
409
|
}
|
|
389
410
|
export function parseYamlMapping(text, start, end) {
|
|
390
|
-
const c = { text, i: start, end };
|
|
411
|
+
const c = { text, i: start, end, depth: 0 };
|
|
391
412
|
skipBlankAndComments(c);
|
|
392
413
|
if (c.i >= end)
|
|
393
414
|
return { kind: 'map', entries: [], start, end };
|
|
@@ -439,17 +460,23 @@ function listed(value) {
|
|
|
439
460
|
return keys.length === value.length && keys.every((key, index) => key === String(index));
|
|
440
461
|
}
|
|
441
462
|
function heldWithin(value, within) {
|
|
442
|
-
if (
|
|
463
|
+
if (typeof value === 'string')
|
|
464
|
+
return !UNHELD_TEXT.test(value);
|
|
465
|
+
if (value === null || typeof value === 'boolean')
|
|
443
466
|
return true;
|
|
444
467
|
if (typeof value === 'number')
|
|
445
468
|
return Number.isFinite(value);
|
|
446
469
|
if (typeof value !== 'object' || within.includes(value))
|
|
447
470
|
return false;
|
|
471
|
+
if (within.length + 1 >= YAML_DEPTH_MAX)
|
|
472
|
+
return false;
|
|
448
473
|
const path = [...within, value];
|
|
449
474
|
const held = (item) => heldWithin(item, path);
|
|
450
475
|
if (Array.isArray(value))
|
|
451
476
|
return listed(value) && value.every(held);
|
|
452
|
-
return plain(value) &&
|
|
477
|
+
return (plain(value) &&
|
|
478
|
+
Object.keys(value).every((key) => !UNHELD_TEXT.test(key)) &&
|
|
479
|
+
Object.values(value).every(held));
|
|
453
480
|
}
|
|
454
481
|
export function frontmatterValue(value) {
|
|
455
482
|
return heldWithin(value, []);
|
|
@@ -495,7 +522,7 @@ export function extractFrontmatter(content) {
|
|
|
495
522
|
return { kind: 'unclosed' };
|
|
496
523
|
const yamlStart = firstNl + 1;
|
|
497
524
|
let i = yamlStart;
|
|
498
|
-
|
|
525
|
+
for (;;) {
|
|
499
526
|
const nl = content.indexOf('\n', i);
|
|
500
527
|
const lineEnd = nl === -1 ? content.length : nl;
|
|
501
528
|
let line = content.slice(i, lineEnd);
|
|
@@ -507,7 +534,6 @@ export function extractFrontmatter(content) {
|
|
|
507
534
|
return { kind: 'unclosed' };
|
|
508
535
|
i = nl + 1;
|
|
509
536
|
}
|
|
510
|
-
return { kind: 'unclosed' };
|
|
511
537
|
}
|
|
512
538
|
export function equalValue(left, right) {
|
|
513
539
|
if (left === right)
|
package/fixtures/README.md
CHANGED
|
@@ -18,7 +18,9 @@ the validation Libraries. Each row carries `name`, exact `source`, expected
|
|
|
18
18
|
the source, compare `Document.preamble`, apply
|
|
19
19
|
`{ kind: 'preamble', prior: preamble, value }`, and compare the serialized result.
|
|
20
20
|
These cases cover empty and heading-free Documents, frontmatter boundaries,
|
|
21
|
-
fenced headings
|
|
21
|
+
fenced headings and a heading an HTML block holds, setext, indented and empty
|
|
22
|
+
headings that open a section, newline/source preservation, and a moved-export
|
|
23
|
+
link rewrite.
|
|
22
24
|
|
|
23
25
|
## Projection
|
|
24
26
|
|
|
@@ -65,6 +67,19 @@ value one span carries part of. `start` and `end` are UTF-8 byte offsets into th
|
|
|
65
67
|
source; every source in this corpus is ASCII, so a consumer compares the
|
|
66
68
|
addressed `source` with an ordinary string slice.
|
|
67
69
|
|
|
70
|
+
## Queries
|
|
71
|
+
|
|
72
|
+
`queries.json` is the one table of cases both query evaluators answer. It carries `schema`,
|
|
73
|
+
one schema text; `documents`, each named and carrying its `path`, the `type` a collection
|
|
74
|
+
stores for it (`any` for an untyped Markdown Document, `null` for one that is not Markdown),
|
|
75
|
+
its `fileId`, the `text` the device holds or `null`, and its `fields`; and `cases`, each with a
|
|
76
|
+
`name`, a `query` of filter parts, the `document` it names and whether it `matches`. Verify
|
|
77
|
+
the schema and plan `{ ...query, select: {} }` with `planOf` against its types. Then
|
|
78
|
+
`matches(plan, candidate)` over the named Document, given its type's definition, and the
|
|
79
|
+
condition `sql.tests` writes over a collection holding every Document of the table with the
|
|
80
|
+
values `indexed` derives from it must both answer `matches`. A new operator adds its cases
|
|
81
|
+
here first.
|
|
82
|
+
|
|
68
83
|
## Verdict format
|
|
69
84
|
|
|
70
85
|
Acceptance:
|
|
@@ -107,6 +122,7 @@ schema text. The model's own rules:
|
|
|
107
122
|
| `frontmatter-fence` | A present frontmatter fence does not parse as the accepted YAML subset |
|
|
108
123
|
| `schema-yaml` | A schema text is not a mapping in the accepted YAML subset |
|
|
109
124
|
| `schema-type-name` | A type name is empty, starts with `$`, or is `any` or `attachment` |
|
|
125
|
+
| `provided-type` | A schema names a type its caller provides with a key but its two role keywords |
|
|
110
126
|
| `schema` | A type or subschema is neither a mapping nor a boolean |
|
|
111
127
|
| `schema-keyword` | A schema carries a key that is no JSON Schema 2020-12 keyword the model admits |
|
|
112
128
|
| `$defs` | `$defs` is not a mapping |
|
|
@@ -114,16 +130,22 @@ schema text. The model's own rules:
|
|
|
114
130
|
| `reference` | `reference` is not on a string or names something but a type, `any`, `attachment` |
|
|
115
131
|
| `sections` | A section is not `{ kind: text }` or `{ kind: list, items }` over one scalar |
|
|
116
132
|
| `member_document` | The mark is not a boolean, or a second type carries it |
|
|
117
|
-
| `unknown-type` | A file declares a type absent from the governing schema
|
|
133
|
+
| `unknown-type` | A file declares a type absent from the governing schema, or other than its typed path requires it to name |
|
|
118
134
|
| `undeclared-field` | A closed object carries a key it does not declare |
|
|
119
135
|
| `required-section` | A required section heading is missing |
|
|
136
|
+
| `conditional-section` | A section its type's `if` branch requires is absent or holds no text |
|
|
120
137
|
| `unresolved-reference` | A reference at any depth or a section item reaches no member it admits |
|
|
121
|
-
| `unresolved-link` | A body link is an absolute path
|
|
138
|
+
| `unresolved-link` | A body link is an absolute path, leaves the collection or, from a typed Document at a document path, reaches a reserved name |
|
|
139
|
+
| `room-md-type` | `ROOM.md` declares a type |
|
|
140
|
+
| `required-body` | A file at a typed path that requires a body has a body holding no text |
|
|
122
141
|
| `structured-section` | A declared list section is not a list of values of its item schema |
|
|
123
142
|
| `referenced-missing-file` | Remaining files still reference an absent path |
|
|
124
143
|
| `unwritable-link` | No Markdown destination form can carry a new link destination |
|
|
125
144
|
| `division-bound` | A division bound is not a whole number of at least 2 |
|
|
126
145
|
|
|
146
|
+
A `then` or `else` of an `if` on a type, in its `allOf` or in such a branch may hold
|
|
147
|
+
`sections`, naming sections the type declares as the type declares them, else `sections`.
|
|
148
|
+
|
|
127
149
|
`unwritable-link` is refused by `apply` and `division-bound` by `divide`, not
|
|
128
150
|
by `validate`, so no case under `cases/` carries either.
|
|
129
151
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "binaryTargets": [] }
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
question:
|
|
2
|
+
properties:
|
|
3
|
+
title: { type: string }
|
|
4
|
+
status: { enum: [open, answered, withdrawn] }
|
|
5
|
+
required: [title, status]
|
|
6
|
+
sections:
|
|
7
|
+
Question: { kind: text, required: true }
|
|
8
|
+
Answer: { kind: text }
|
|
9
|
+
if:
|
|
10
|
+
properties:
|
|
11
|
+
status: { enum: [answered, withdrawn] }
|
|
12
|
+
then:
|
|
13
|
+
sections:
|
|
14
|
+
Answer: { kind: text, required: true }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "binaryTargets": [] }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "binaryTargets": [] }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "binaryTargets": [] }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "binaryTargets": [] }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "binaryTargets": [] }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "binaryTargets": [] }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
The brief.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "binaryTargets": [] }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "binaryTargets": [] }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Dark.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Dark.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
A plan.
|