@agentshouse/mdmodel 0.1.0-cb39915954ec5 → 0.1.0-cbb41ab5ebbd2

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.
@@ -0,0 +1,63 @@
1
+ import { type Definition } from '../definition.js';
2
+ import type { VerifiedModel } from '../types.js';
3
+ import { type Direction, type QueryPlan } from './language.js';
4
+ export type KeyBound = {
5
+ readonly key: Uint8Array;
6
+ readonly inclusive: boolean;
7
+ };
8
+ export type KeyRange = {
9
+ readonly lower: KeyBound;
10
+ readonly upper: KeyBound | null;
11
+ };
12
+ export type WalkRun = {
13
+ readonly by: 'key';
14
+ readonly key: Uint8Array;
15
+ readonly after: boolean;
16
+ } | {
17
+ readonly by: 'range';
18
+ readonly range: KeyRange;
19
+ };
20
+ export type PageOrder = {
21
+ readonly by: 'path';
22
+ readonly direction: Direction;
23
+ } | {
24
+ readonly by: 'field';
25
+ readonly field: string;
26
+ readonly direction: Direction;
27
+ readonly nulls: 'first' | 'last';
28
+ readonly lexical: boolean;
29
+ readonly after: {
30
+ readonly key: Uint8Array;
31
+ readonly tie: unknown;
32
+ } | null;
33
+ };
34
+ export type Walk = {
35
+ readonly by: 'path';
36
+ readonly direction: Direction;
37
+ } | {
38
+ readonly by: 'keys';
39
+ readonly field: string;
40
+ readonly direction: Direction;
41
+ readonly types: readonly {
42
+ readonly type: string;
43
+ readonly keys: readonly Uint8Array[];
44
+ }[];
45
+ } | {
46
+ readonly by: 'order';
47
+ readonly field: string;
48
+ readonly direction: Direction;
49
+ readonly types: readonly {
50
+ readonly type: string;
51
+ readonly runs: readonly WalkRun[];
52
+ }[];
53
+ };
54
+ export type Count = {
55
+ readonly walk: Walk;
56
+ readonly fields: readonly string[];
57
+ };
58
+ export declare function pageOrder(plan: QueryPlan): PageOrder;
59
+ export declare function walkOf(plan: QueryPlan, model: VerifiedModel): Walk;
60
+ export declare function countShape(plan: QueryPlan): boolean;
61
+ export declare function countOf(plan: QueryPlan, model: VerifiedModel, where: unknown): Count | null;
62
+ export declare function walkedValue(definition: Definition, field: string, value: unknown): unknown;
63
+ //# sourceMappingURL=walk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../../src/query/walk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,UAAU,EAAmB,MAAM,kBAAkB,CAAC;AAEpG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAIL,KAAK,SAAS,EAEd,KAAK,SAAS,EAEf,MAAM,eAAe,CAAC;AAEvB,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AAEjF,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;CAAE,CAAC;AAErF,MAAM,MAAM,OAAO,GACf;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACzE;IAAE,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAA;CAAE,CAAC;AAIvD,MAAM,MAAM,SAAS,GACjB;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;CAAE,GACtD;IACE,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MA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,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAmBnD;AAwCD,wBAAgB,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,IAAI,CAqB3F;AAED,wBAAgB,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAG1F"}
@@ -0,0 +1,263 @@
1
+ import { escapePointer, pointerSegments } from '../definition.js';
2
+ import { indexKey, instantOf, sortedKey } from '../kinds.js';
3
+ import { plain } from '../yaml.js';
4
+ import { invalid, textless, } from './language.js';
5
+ function keyOrder(left, right) {
6
+ for (let at = 0; at < Math.min(left.length, right.length); at += 1) {
7
+ if (left[at] !== right[at])
8
+ return left[at] - right[at];
9
+ }
10
+ return left.length - right.length;
11
+ }
12
+ function tighter(held, bound, sign) {
13
+ if (held === null)
14
+ return bound;
15
+ const order = sign * keyOrder(bound.key, held.key);
16
+ return order > 0 || (order === 0 && !bound.inclusive) ? bound : held;
17
+ }
18
+ function everyValue(facts) {
19
+ return { lower: { key: indexKey(facts, null), inclusive: false }, upper: null };
20
+ }
21
+ function rangeOf(facts, bounds) {
22
+ let { lower } = everyValue(facts);
23
+ let upper = null;
24
+ for (const [operator, value] of bounds) {
25
+ const bound = { key: indexKey(facts, value), inclusive: operator.endsWith('e') };
26
+ if (operator.startsWith('g'))
27
+ lower = tighter(lower, bound, 1);
28
+ else
29
+ upper = tighter(upper, bound, -1);
30
+ }
31
+ return { lower, upper };
32
+ }
33
+ function distinct(keys) {
34
+ return [...new Map(keys.map((key) => [key.join(','), key])).values()];
35
+ }
36
+ function testedKeys(facts, test) {
37
+ if (test.op === 'eq')
38
+ return { keys: [indexKey(facts, test.value)] };
39
+ if (test.op === 'in')
40
+ return { keys: distinct(test.values.map((value) => indexKey(facts, value))) };
41
+ if (test.op === 'range')
42
+ return { range: rangeOf(facts, test.bounds) };
43
+ return null;
44
+ }
45
+ function conjuncts(where) {
46
+ if (where === null || 'some' in where)
47
+ return [];
48
+ return 'every' in where ? where.every.flatMap(conjuncts) : [where];
49
+ }
50
+ function named(pointer) {
51
+ const segments = pointerSegments(pointer);
52
+ return segments.length === 1 ? segments[0] : null;
53
+ }
54
+ function indexing(model, types, field) {
55
+ const definitions = types.map((type) => Object.hasOwn(model.types, type) ? model.types[type] : null);
56
+ return definitions.every((definition) => definition?.indexed?.includes(field) === true)
57
+ ? definitions
58
+ : null;
59
+ }
60
+ function afterOf(plan) {
61
+ const values = plan.after?.values ?? null;
62
+ if (values === null)
63
+ return null;
64
+ const key = sortedKey(values[0]);
65
+ if (key === null)
66
+ invalid('after', 'expects the next an earlier result of this query returned');
67
+ return { key, tie: values[1] };
68
+ }
69
+ export function pageOrder(plan) {
70
+ if (plan.shape.kind !== 'documents')
71
+ return invalid('groupBy', 'a page answers Documents');
72
+ const [term, second] = plan.shape.orderBy;
73
+ if (second !== undefined)
74
+ invalid(['orderBy', 1], 'a page orders by one term');
75
+ if (term === undefined)
76
+ return { by: 'path', direction: 'asc' };
77
+ const { key, options } = term;
78
+ if (key.of === 'path') {
79
+ if (options.stringSort !== 'lexical')
80
+ invalid(['orderBy', 0, 'stringSort'], 'a page orders Paths by code point, as lexical');
81
+ return { by: 'path', direction: options.direction };
82
+ }
83
+ const field = key.of === 'field' ? named(key.field) : null;
84
+ if (field === null)
85
+ return invalid(['orderBy', 0, 'by'], 'a page orders by Path or by a field its types index');
86
+ if (plan.root.types === null)
87
+ invalid('types', 'an order by a field names the types whose index it walks');
88
+ return {
89
+ by: 'field',
90
+ field,
91
+ direction: options.direction,
92
+ nulls: options.nulls ?? 'first',
93
+ lexical: options.stringSort === 'lexical',
94
+ after: afterOf(plan),
95
+ };
96
+ }
97
+ function keysWalk(plan, model, direction) {
98
+ const types = plan.root.types;
99
+ for (const { field: pointer, test } of conjuncts(plan.root.where)) {
100
+ const field = named(pointer);
101
+ if (types === null || field === null || (test.op !== 'eq' && test.op !== 'in'))
102
+ continue;
103
+ const definitions = indexing(model, types, field);
104
+ if (definitions === null)
105
+ continue;
106
+ return {
107
+ by: 'keys',
108
+ field,
109
+ direction,
110
+ types: definitions.map((definition) => ({
111
+ type: definition.name,
112
+ keys: testedKeys(definition.fields[field], test).keys,
113
+ })),
114
+ };
115
+ }
116
+ return { by: 'path', direction };
117
+ }
118
+ function common(types) {
119
+ const [first, ...rest] = types;
120
+ return (first?.indexed ?? [])
121
+ .filter((field) => rest.every((definition) => definition.indexed?.includes(field)))
122
+ .map((field) => `/${escapePointer(field)}`);
123
+ }
124
+ function ranged(facts, tests) {
125
+ if (tests.length === 0)
126
+ return null;
127
+ return tests
128
+ .map(({ test }) => testedKeys(facts, test).range)
129
+ .reduce((held, range) => ({
130
+ lower: tighter(held.lower, range.lower, 1),
131
+ upper: range.upper === null ? held.upper : tighter(held.upper, range.upper, -1),
132
+ }));
133
+ }
134
+ function past(range, key, direction) {
135
+ const beyond = { key, inclusive: false };
136
+ return direction === 'asc'
137
+ ? { ...range, lower: tighter(range.lower, beyond, 1) }
138
+ : { ...range, upper: tighter(range.upper, beyond, -1) };
139
+ }
140
+ function runsOf(facts, order, range) {
141
+ const missing = indexKey(facts, null);
142
+ const cursor = order.after?.key ?? null;
143
+ const amongNulls = cursor !== null && keyOrder(cursor, missing) === 0;
144
+ const nulls = range === null ? [{ by: 'key', key: missing, after: amongNulls }] : [];
145
+ const span = range ?? everyValue(facts);
146
+ if (cursor === null || amongNulls) {
147
+ if (order.nulls === 'first')
148
+ return [...nulls, { by: 'range', range: span }];
149
+ return amongNulls ? nulls : [{ by: 'range', range: span }, ...nulls];
150
+ }
151
+ const values = [
152
+ { by: 'key', key: cursor, after: true },
153
+ { by: 'range', range: past(span, cursor, order.direction) },
154
+ ];
155
+ return order.nulls === 'first' ? values : [...values, ...nulls];
156
+ }
157
+ function unindexed(model, types, at, problem) {
158
+ const declared = types.flatMap((type) => Object.hasOwn(model.types, type) ? [model.types[type]] : []);
159
+ return invalid(at, problem, declared.length === types.length ? common(declared) : []);
160
+ }
161
+ export function walkOf(plan, model) {
162
+ const order = pageOrder(plan);
163
+ if (order.by === 'path')
164
+ return keysWalk(plan, model, order.direction);
165
+ const types = plan.root.types;
166
+ const definitions = indexing(model, types, order.field);
167
+ if (definitions === null)
168
+ return unindexed(model, types, ['orderBy', 0, 'by'], 'orders by a field every type it names indexes');
169
+ if (!order.lexical &&
170
+ definitions.some((definition) => !textless(definition.fields[order.field])))
171
+ invalid(['orderBy', 0, 'stringSort'], 'a page orders text by code point, as lexical');
172
+ const bounding = conjuncts(plan.root.where).filter(({ field, test }) => test.op === 'range' && named(field) === order.field);
173
+ return {
174
+ by: 'order',
175
+ field: order.field,
176
+ direction: order.direction,
177
+ types: definitions.map((definition) => {
178
+ const facts = definition.fields[order.field];
179
+ return { type: definition.name, runs: runsOf(facts, order, ranged(facts, bounding)) };
180
+ }),
181
+ };
182
+ }
183
+ export function countShape(plan) {
184
+ const { shape } = plan;
185
+ if (shape.kind === 'documents' && !plan.total)
186
+ return false;
187
+ if (plan.root.types === null)
188
+ invalid('types', 'a count names the types whose index it reads');
189
+ if (plan.text !== null)
190
+ invalid('text', 'a count tests no text');
191
+ if (shape.kind === 'documents')
192
+ return true;
193
+ if (plan.total)
194
+ invalid('total', 'a page of groups answers no total');
195
+ const key = shape.groupBy[0];
196
+ if (shape.groupBy.length > 1)
197
+ invalid(['groupBy', 1], 'a page groups by one field');
198
+ if (key.of !== 'field' || named(key.field) === null)
199
+ invalid(['groupBy', 0], 'a page groups by a field its types index');
200
+ for (const part of ['size', 'updated', 'greatest'])
201
+ if (shape[part] !== false && shape[part] !== null)
202
+ invalid(['select', part], 'a group selects only its count');
203
+ shape.orderBy.forEach(({ by }, index) => {
204
+ if (typeof by === 'string' && by !== 'count')
205
+ invalid(['orderBy', index, 'by'], 'a page of groups orders by its count or its key');
206
+ });
207
+ return true;
208
+ }
209
+ function testedPlaces(where, at) {
210
+ if (!plain(where))
211
+ return [];
212
+ return Object.keys(where)
213
+ .sort()
214
+ .flatMap((name) => name === '$and' || name === '$or'
215
+ ? where[name].flatMap((part, index) => testedPlaces(part, [...at, name, index]))
216
+ : [{ pointer: name, place: [...at, name] }]);
217
+ }
218
+ function countWalk(plan, model) {
219
+ const keyed = keysWalk(plan, model, 'asc');
220
+ if (keyed.by !== 'path')
221
+ return keyed;
222
+ const tests = conjuncts(plan.root.where);
223
+ for (const { field: pointer, test } of tests) {
224
+ const field = named(pointer);
225
+ if (test.op !== 'range' || field === null)
226
+ continue;
227
+ const definitions = indexing(model, plan.root.types, field);
228
+ if (definitions === null)
229
+ continue;
230
+ const bounding = tests.filter((bounded) => bounded.test.op === 'range' && bounded.field === pointer);
231
+ return {
232
+ by: 'order',
233
+ field,
234
+ direction: 'asc',
235
+ types: definitions.map((definition) => ({
236
+ type: definition.name,
237
+ runs: [{ by: 'range', range: ranged(definition.fields[field], bounding) }],
238
+ })),
239
+ };
240
+ }
241
+ return keyed;
242
+ }
243
+ export function countOf(plan, model, where) {
244
+ if (!countShape(plan))
245
+ return null;
246
+ const types = plan.root.types;
247
+ const grouped = plan.shape.kind === 'groups'
248
+ ? [{ pointer: plan.shape.groupBy[0].field, place: ['groupBy', 0] }]
249
+ : [];
250
+ const fields = [...grouped, ...testedPlaces(where, ['where'])].map(({ pointer, place }) => {
251
+ const field = named(pointer);
252
+ if (field === null || indexing(model, types, field) === null)
253
+ return unindexed(model, types, place, place[0] === 'groupBy'
254
+ ? 'groups by a field every type it names indexes'
255
+ : 'a count tests only fields every type it names indexes');
256
+ return field;
257
+ });
258
+ return { walk: countWalk(plan, model), fields: [...new Set(fields)].sort() };
259
+ }
260
+ export function walkedValue(definition, field, value) {
261
+ const instant = instantOf(definition.fields[field], value);
262
+ return instant === null ? (value ?? null) : { instant };
263
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"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,EACZ,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,OAAO,EACf,KAAK,GAAE,aAA6B,EACpC,OAAO,GAAE,OAAY,GACpB,UAAU,CAoCZ;AA+BD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,EAC5B,KAAK,GAAE,aAA6B,EACpC,OAAO,GAAE,OAAY,GACpB,UAAU,CAiCZ;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,GAAG,CACD,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,EAC5C,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAChC,MAAM,CAAC;IACV,OAAO,IAAI,UAAU,CAAC;CACvB,CAAC;AAEF,wBAAgB,QAAQ,IAAI,QAAQ,CAmDnC;AAWD,wBAAiB,UAAU,CACzB,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,OAAO,GAAE,iBAAyC,EAClD,KAAK,GAAE,aAA6B,GACnC,SAAS,CAAC,cAAc,EAAE,UAAU,EAAE,IAAI,CAAC,CAE7C;AAoCD,wBAAgB,QAAQ,CACtB,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,iBAAyC,EAClD,KAAK,GAAE,aAA6B,GACnC,UAAU,CAEZ;AAED,wBAAgB,cAAc,CAC5B,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,EACzC,OAAO,GAAE,iBAAyC,EAClD,KAAK,GAAE,aAA6B,GACnC,UAAU,CAEZ"}
package/dist/validate.js CHANGED
@@ -2,6 +2,7 @@ import { ATTACHMENT, BUILT_IN_TYPE, readSchema, } from './definition.js';
2
2
  import { linkDestinations, links, parse } from './document.js';
3
3
  import { MEMBER_FIELD } from './fields.js';
4
4
  import { formFailure } from './form.js';
5
+ import { indexedFailure } from './indexed.js';
5
6
  import { hrefOccurrences, lineBreaks, lineNumber } from './markdown.js';
6
7
  import { classifyHref, keyedLink, roomTarget } from './paths.js';
7
8
  import { references } from './references.js';
@@ -114,7 +115,7 @@ export function verify(schema, provided) {
114
115
  const read = readSchema(schema, provided);
115
116
  if (!('types' in read))
116
117
  return schemaRefused(read);
117
- const failure = formFailure(read, provided);
118
+ const failure = formFailure(read, provided) ?? indexedFailure(read);
118
119
  return failure === undefined ? { verdict: 'accept', model: read } : schemaRefused(failure);
119
120
  }
120
121
  export function readTypes(schema, provided) {
@@ -90,7 +90,14 @@ the schema and plan `{ ...query, select: {} }` with `planOf` against its types.
90
90
  `matches(plan, candidate)` over the named Document, given its type's definition, and the
91
91
  condition `sql.tests` writes over a collection holding every Document of the table with the
92
92
  values `indexed` derives from it must both answer `matches`. A new operator adds its cases
93
- here first.
93
+ here first. With `types: ["task"]`, every `task` Document both evaluators match lies within the
94
+ index plan `walkOf` takes for each case: among the keys of the equality or list it walks, and
95
+ within the runs of keys it walks an order by each indexed field in, a missing value's among
96
+ them, so a new driving test adds its cases here too. Each of `orders` carries a `name`, one `orderBy` clause on a field the `task` type
97
+ names `indexed` and the `order` of every `task` Document, ties by Path in code-point order in
98
+ either direction. The SQL order `sql.sorted` writes over that collection, `compared` over the
99
+ value `heldAt` reads, its instant for a date-time, and the bytes of each Document's `indexKey`,
100
+ a missing value and `null` placed as the clause's `nulls` asks, must each give that order.
94
101
 
95
102
  ## Verdict format
96
103
 
@@ -142,6 +149,7 @@ schema text. The model's own rules:
142
149
  | `$ref` | A `$ref` reaches no subschema under `#/$defs/` of the same file |
143
150
  | `reference` | `reference` is not on a string or names something but a type, `any`, `attachment` |
144
151
  | `member_document` | The mark is not a boolean, or a second type carries it |
152
+ | `indexed` | `indexed` names a field a type cannot index, or more than its caller's bounds |
145
153
  | `duplicate-label` | Two fields of one object show one label: a field's `title`, else its key |
146
154
  | `conflicting-label` | Declarations of one key in `anyOf`, `oneOf`, `then`, `else` or a composed shape give it two `title`s |
147
155
  | `conflicting-type` | Such declarations give one key two JSON types, integer and number counting as one |
@@ -60,14 +60,14 @@
60
60
  "source": "```md\n## Example\n```\n\n## Body\nKept.\n",
61
61
  "preamble": "```md\n## Example\n```\n\n",
62
62
  "value": "Example removed.\n",
63
- "expected": "Example removed.\n## Body\nKept.\n"
63
+ "expected": "Example removed.\n\n## Body\nKept.\n"
64
64
  },
65
65
  {
66
66
  "name": "tilde fence hides a heading",
67
67
  "source": " ~~~md\n## Example\n ~~~\n\n## Body\nKept.",
68
68
  "preamble": " ~~~md\n## Example\n ~~~\n\n",
69
69
  "value": "Example removed.\n",
70
- "expected": "Example removed.\n## Body\nKept."
70
+ "expected": "Example removed.\n\n## Body\nKept."
71
71
  },
72
72
  {
73
73
  "name": "unclosed fence carries the entire body",
@@ -81,7 +81,7 @@
81
81
  "source": "# Title\n### Subheading\n> ## Quoted\n ## Indented\n\n## Actual ##\nKept.\n",
82
82
  "preamble": "# Title\n### Subheading\n> ## Quoted\n ## Indented\n\n",
83
83
  "value": "Intro.\n",
84
- "expected": "Intro.\n## Actual ##\nKept.\n"
84
+ "expected": "Intro.\n\n## Actual ##\nKept.\n"
85
85
  },
86
86
  {
87
87
  "name": "a setext heading opens a section",
@@ -102,7 +102,7 @@
102
102
  "source": "<!--\n## Hidden\n-->\n\n## Body\nKept.\n",
103
103
  "preamble": "<!--\n## Hidden\n-->\n\n",
104
104
  "value": "Intro.\n",
105
- "expected": "Intro.\n## Body\nKept.\n"
105
+ "expected": "Intro.\n\n## Body\nKept.\n"
106
106
  },
107
107
  {
108
108
  "name": "Unicode and mixed newlines",