@agentshouse/mdmodel 0.1.0-c64dbada0730d → 0.1.0-c669bdbad8a03
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 +206 -202
- package/README.md +15 -18
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +7 -14
- package/dist/condition.d.ts +2 -1
- package/dist/condition.d.ts.map +1 -1
- package/dist/condition.js +30 -15
- package/dist/definition.d.ts +15 -0
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +226 -26
- package/dist/divide.d.ts.map +1 -1
- package/dist/divide.js +18 -8
- package/dist/document.d.ts +5 -2
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +315 -165
- package/dist/fields.d.ts +2 -0
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +7 -0
- package/dist/index.d.ts +12 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -5
- package/dist/links.d.ts +2 -0
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +23 -12
- package/dist/paths.d.ts +10 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +115 -12
- package/dist/project.d.ts +1 -0
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +35 -10
- package/dist/references.d.ts +2 -2
- package/dist/references.d.ts.map +1 -1
- package/dist/references.js +6 -1
- package/dist/schema.js +2 -2
- package/dist/types.d.ts +44 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +8 -1
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +205 -100
- package/dist/yaml.d.ts +7 -3
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +72 -43
- package/fixtures/README.md +1 -1
- package/fixtures/cases/cross-room-link/context.json +1 -0
- package/fixtures/cases/cross-room-link/expected.json +1 -0
- package/fixtures/cases/cross-room-link/library/clients/acme.md +6 -0
- package/fixtures/cases/cross-room-link/schema.yaml +3 -0
- package/fixtures/cases/cross-room-reference/context.json +1 -0
- package/fixtures/cases/cross-room-reference/expected.json +1 -0
- package/fixtures/cases/cross-room-reference/library/clients/acme.md +9 -0
- package/fixtures/cases/cross-room-reference/schema.yaml +9 -0
- package/package.json +4 -2
package/dist/blocks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { fenceSpans } from './links.js';
|
|
2
|
-
const HEADING = /^(#{1,6})(?!#)[ \t]+(.+?)[ \t]
|
|
1
|
+
import { fenceSpans, spanCursor } from './links.js';
|
|
2
|
+
const HEADING = /^(#{1,6})(?!#)[ \t]+(.+?)(?:[ \t]+#+)?[ \t]*$/;
|
|
3
3
|
function lineAt(content, from, to) {
|
|
4
4
|
const nl = content.indexOf('\n', from);
|
|
5
5
|
const end = nl === -1 || nl >= to ? to : nl;
|
|
@@ -7,17 +7,11 @@ function lineAt(content, from, to) {
|
|
|
7
7
|
return { text: raw.endsWith('\r') ? raw.slice(0, -1) : raw, next: end === to ? to : end + 1 };
|
|
8
8
|
}
|
|
9
9
|
function scan(content, from, to, visit) {
|
|
10
|
-
const
|
|
10
|
+
const fenced = spanCursor(fenceSpans(content.slice(from, to)));
|
|
11
11
|
let i = from;
|
|
12
12
|
while (i < to) {
|
|
13
13
|
const { text, next } = lineAt(content, i, to);
|
|
14
|
-
|
|
15
|
-
visit({
|
|
16
|
-
text,
|
|
17
|
-
start: i,
|
|
18
|
-
next,
|
|
19
|
-
fenced: fences.some(([start, end]) => at >= start && at < end),
|
|
20
|
-
});
|
|
14
|
+
visit({ text, start: i, next, fenced: fenced(i - from) !== undefined });
|
|
21
15
|
if (next === i)
|
|
22
16
|
break;
|
|
23
17
|
i = next;
|
|
@@ -26,16 +20,15 @@ function scan(content, from, to, visit) {
|
|
|
26
20
|
const HASH = 0x23;
|
|
27
21
|
export function headingLines(content, from, to) {
|
|
28
22
|
const found = [];
|
|
29
|
-
let
|
|
23
|
+
let fenced = null;
|
|
30
24
|
let i = from;
|
|
31
25
|
while (i < to) {
|
|
32
26
|
const nl = content.indexOf('\n', i);
|
|
33
27
|
const end = nl === -1 || nl >= to ? to : nl;
|
|
34
28
|
const next = end === to ? to : end + 1;
|
|
35
29
|
if (content.charCodeAt(i) === HASH) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (!fences.some(([start, stop]) => at >= start && at < stop)) {
|
|
30
|
+
fenced ??= spanCursor(fenceSpans(content.slice(from, to)));
|
|
31
|
+
if (fenced(i - from) === undefined) {
|
|
39
32
|
const { text } = lineAt(content, i, to);
|
|
40
33
|
const match = HEADING.exec(text);
|
|
41
34
|
const hashes = match?.[1];
|
package/dist/condition.d.ts
CHANGED
|
@@ -120,7 +120,6 @@ export type ItemFacts = {
|
|
|
120
120
|
readonly source: string | null;
|
|
121
121
|
readonly address: string | null;
|
|
122
122
|
readonly has_attachment: boolean;
|
|
123
|
-
readonly provider: string | null;
|
|
124
123
|
readonly container: string | null;
|
|
125
124
|
readonly author: string | null;
|
|
126
125
|
readonly headers: Readonly<Record<string, string>>;
|
|
@@ -139,9 +138,11 @@ export declare function facts(document: Document, at: {
|
|
|
139
138
|
readonly path: string;
|
|
140
139
|
}, model: VerifiedModel, resolve: (target: string) => Resolved | undefined): DocumentFacts;
|
|
141
140
|
export declare function prosePaths(facts: DocumentFacts): string[];
|
|
141
|
+
export declare function datePointers(fields: Readonly<Record<string, ValueFacts>>): string[];
|
|
142
142
|
export declare function dated(value: unknown): value is string;
|
|
143
143
|
export declare function instant(value: unknown): bigint | undefined;
|
|
144
144
|
export declare function pointed(value: unknown, pointer: string): unknown;
|
|
145
|
+
export declare function members(document: DocumentFacts, path: string): readonly string[];
|
|
145
146
|
export declare function holds(test: ConditionTest, document: DocumentFacts, owner: string): Truth;
|
|
146
147
|
export declare function fires(condition: DocumentCondition, event: DocumentEvent, owner: string): boolean;
|
|
147
148
|
export declare function itemFires(condition: ItemCondition, item: ItemFacts, owner: string): boolean;
|
package/dist/condition.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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AAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAehE;AAiJD,wBAAgB,OAAO,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAahF;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,CAExF;AAyFD,wBAAgB,KAAK,CAAC,SAAS,EAAE,iBAAiB,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAehG;AAED,wBAAgB,SAAS,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAO3F"}
|
package/dist/condition.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ARRAY_INDEX, escapePointer, fieldFacts, itemFacts, memberFacts, pointerSegments, } from './definition.js';
|
|
2
|
-
import { target } from './paths.js';
|
|
3
|
-
import { isRecord } from './yaml.js';
|
|
2
|
+
import { roomPath, target } from './paths.js';
|
|
3
|
+
import { isRecord, plain } from './yaml.js';
|
|
4
4
|
export const WRITE_DOORS = ['browser', 'agent', 'client'];
|
|
5
5
|
const PROSE = { kind: 'prose' };
|
|
6
6
|
const NULL = { kind: 'null' };
|
|
@@ -71,7 +71,8 @@ function factOf(value, declared, place) {
|
|
|
71
71
|
return UNREADABLE;
|
|
72
72
|
if (kind !== 'reference')
|
|
73
73
|
return { kind, value };
|
|
74
|
-
const reached = target(place.path, value)
|
|
74
|
+
const reached = target(place.path, value) ??
|
|
75
|
+
(declared.crossRoom === true ? roomPath(value) : null);
|
|
75
76
|
const resolved = reached === null ? undefined : place.resolve(reached);
|
|
76
77
|
if (resolved === undefined)
|
|
77
78
|
return UNREADABLE;
|
|
@@ -205,11 +206,11 @@ function readActor(actor, path) {
|
|
|
205
206
|
: undefined;
|
|
206
207
|
return value === undefined ? undefined : single({ kind: 'actor', value });
|
|
207
208
|
}
|
|
208
|
-
function
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
export function datePointers(fields) {
|
|
210
|
+
return Object.entries(fields)
|
|
211
|
+
.filter(([, facts]) => facts.type === 'string' && facts.format === 'date')
|
|
212
|
+
.map(([name]) => `/fields/${name}`)
|
|
213
|
+
.sort();
|
|
213
214
|
}
|
|
214
215
|
export function dated(value) {
|
|
215
216
|
return (typeof value === 'string' && DATE.test(value) && instant(`${value}T00:00:00Z`) !== undefined);
|
|
@@ -300,13 +301,11 @@ function readItem(item, path) {
|
|
|
300
301
|
? item.delivery
|
|
301
302
|
: path === '/source'
|
|
302
303
|
? item.source
|
|
303
|
-
: path === '/
|
|
304
|
-
? item.
|
|
305
|
-
: path === '/
|
|
306
|
-
? item.
|
|
307
|
-
:
|
|
308
|
-
? item.author
|
|
309
|
-
: null;
|
|
304
|
+
: path === '/container'
|
|
305
|
+
? item.container
|
|
306
|
+
: path === '/author'
|
|
307
|
+
? item.author
|
|
308
|
+
: null;
|
|
310
309
|
return value === null ? undefined : single({ kind: 'string', value });
|
|
311
310
|
}
|
|
312
311
|
function wanted(value, owner) {
|
|
@@ -406,6 +405,17 @@ function evaluated(test, read, owner) {
|
|
|
406
405
|
}
|
|
407
406
|
return leaf(test, read(test.path), owner);
|
|
408
407
|
}
|
|
408
|
+
export function members(document, path) {
|
|
409
|
+
if (!path.startsWith('/members/'))
|
|
410
|
+
return [];
|
|
411
|
+
const read = readDocument(document, path);
|
|
412
|
+
const values = read === undefined ? [] : [...read.values, ...(read.items ?? [])];
|
|
413
|
+
return [
|
|
414
|
+
...new Set(values.flatMap((value) => value !== undefined && value.kind === 'member' && 'value' in value
|
|
415
|
+
? [String(value.value)]
|
|
416
|
+
: [])),
|
|
417
|
+
].sort();
|
|
418
|
+
}
|
|
409
419
|
export function holds(test, document, owner) {
|
|
410
420
|
return evaluated(test, (path) => readDocument(document, path), owner);
|
|
411
421
|
}
|
|
@@ -444,6 +454,11 @@ function valueOf(fact) {
|
|
|
444
454
|
.sort()
|
|
445
455
|
.map((key) => [key, valueOf(fact.fields[key])]),
|
|
446
456
|
};
|
|
457
|
+
if (fact.kind === 'time') {
|
|
458
|
+
const at = instant(fact.value);
|
|
459
|
+
if (at !== undefined)
|
|
460
|
+
return { kind: fact.kind, at: String(at) };
|
|
461
|
+
}
|
|
447
462
|
return 'value' in fact ? { kind: fact.kind, value: fact.value } : fact;
|
|
448
463
|
}
|
|
449
464
|
function signature(reached) {
|
package/dist/definition.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export type ValueFacts = {
|
|
|
5
5
|
readonly format?: string;
|
|
6
6
|
readonly values?: readonly unknown[];
|
|
7
7
|
readonly reference?: readonly string[];
|
|
8
|
+
readonly crossRoom?: true;
|
|
8
9
|
readonly prose: boolean;
|
|
9
10
|
readonly conditional?: true;
|
|
10
11
|
readonly prefix?: readonly ValueFacts[];
|
|
@@ -29,12 +30,26 @@ export type Shape = {
|
|
|
29
30
|
readonly schema: Readonly<Record<string, unknown>>;
|
|
30
31
|
readonly defs: Readonly<Record<string, unknown>>;
|
|
31
32
|
};
|
|
33
|
+
export type RuleValue = string | number | boolean | null;
|
|
34
|
+
export type Transition = {
|
|
35
|
+
readonly from: RuleValue;
|
|
36
|
+
readonly to: RuleValue;
|
|
37
|
+
readonly roles?: readonly string[];
|
|
38
|
+
};
|
|
39
|
+
export type FieldRules = {
|
|
40
|
+
readonly changeRoles?: readonly string[];
|
|
41
|
+
readonly initialRoles?: readonly string[];
|
|
42
|
+
readonly transitions?: readonly Transition[];
|
|
43
|
+
};
|
|
32
44
|
export type Definition = {
|
|
33
45
|
readonly name: string;
|
|
34
46
|
readonly memberDocument: boolean;
|
|
35
47
|
readonly frontmatter: ValueFacts;
|
|
36
48
|
readonly fields: Readonly<Record<string, ValueFacts>>;
|
|
37
49
|
readonly sections: Readonly<Record<string, SectionSpec>>;
|
|
50
|
+
readonly rules: Readonly<Record<string, FieldRules>>;
|
|
51
|
+
readonly createRoles?: readonly string[];
|
|
52
|
+
readonly deleteRoles?: readonly string[];
|
|
38
53
|
readonly shape: Shape;
|
|
39
54
|
};
|
|
40
55
|
export type Failure = {
|
package/dist/definition.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAEjG,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;IACrC,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IACxC,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IAC3D,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAC5C,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,C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AAG,UAAU,GAAG,SAAS,CAKlF;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,EAAE,CAK5D;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAItF;AAqBD,wBAAgB,YAAY,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAc9F;AAsPD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,OAAO,CAiChE"}
|
package/dist/definition.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD } from './fields.js';
|
|
1
|
+
import { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
|
|
2
2
|
import { equalValue, isRecord, jsValue, parseYamlMapping, YamlError } from './yaml.js';
|
|
3
3
|
export const JSON_TYPES = [
|
|
4
4
|
'string',
|
|
@@ -12,11 +12,23 @@ export const JSON_TYPES = [
|
|
|
12
12
|
export const BUILT_IN_TYPE = 'any';
|
|
13
13
|
export const ATTACHMENT = 'attachment';
|
|
14
14
|
const SCALAR_TYPES = new Set(['string', 'number', 'integer', 'boolean']);
|
|
15
|
+
const COMPOSITES = ['array', 'object'];
|
|
16
|
+
const ANNOTATIONS = new Set([
|
|
17
|
+
'$comment',
|
|
18
|
+
'title',
|
|
19
|
+
'description',
|
|
20
|
+
'default',
|
|
21
|
+
'examples',
|
|
22
|
+
'deprecated',
|
|
23
|
+
'readOnly',
|
|
24
|
+
'writeOnly',
|
|
25
|
+
]);
|
|
26
|
+
const FIELD_RULES = ['change_roles', 'initial_roles', 'transitions'];
|
|
15
27
|
const DEFS_REFERENCE = '#/$defs/';
|
|
16
28
|
const UNRESOLVED = /[\u0000-\u001f\u007f%[\]\\^{|}]|\s$/u;
|
|
17
29
|
export const ARRAY_INDEX = /^(?:0|[1-9][0-9]*)$/u;
|
|
18
30
|
const HOUSE_KEYS = {
|
|
19
|
-
|
|
31
|
+
[TYPE_FIELD]: { prose: false },
|
|
20
32
|
[SITE_FIELD]: { prose: false },
|
|
21
33
|
[RECEIVED_FIELD]: { prose: false },
|
|
22
34
|
};
|
|
@@ -204,8 +216,12 @@ const KEYWORDS = {
|
|
|
204
216
|
return (Array.isArray(named) &&
|
|
205
217
|
named.length > 0 &&
|
|
206
218
|
strings(named) &&
|
|
207
|
-
named.every((name) => name === BUILT_IN_TYPE ||
|
|
219
|
+
named.every((name) => name === BUILT_IN_TYPE ||
|
|
220
|
+
name === ATTACHMENT ||
|
|
221
|
+
context.types.has(name) ||
|
|
222
|
+
node.cross_room === true));
|
|
208
223
|
},
|
|
224
|
+
cross_room: (value, _at, node) => typeof value === 'boolean' && node.reference !== undefined,
|
|
209
225
|
};
|
|
210
226
|
function sharedType(values) {
|
|
211
227
|
if (values.length === 0)
|
|
@@ -270,24 +286,45 @@ function united(left, right) {
|
|
|
270
286
|
return undefined;
|
|
271
287
|
return [...left, ...right.filter((value) => !left.some((held) => equalValue(held, value)))];
|
|
272
288
|
}
|
|
289
|
+
function both(left, right) {
|
|
290
|
+
return left !== undefined && right !== undefined ? joined(left, right) : undefined;
|
|
291
|
+
}
|
|
273
292
|
function joined(left, right) {
|
|
274
293
|
const type = left.type === right.type ? left.type : undefined;
|
|
275
294
|
const format = left.format === right.format ? left.format : undefined;
|
|
276
295
|
const values = united(left.values, right.values);
|
|
277
296
|
const reference = united(left.reference, right.reference);
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
297
|
+
const crossRoom = left.crossRoom === true || right.crossRoom === true;
|
|
298
|
+
const items = both(left.items, right.items);
|
|
299
|
+
const prefix = left.prefix === undefined && right.prefix === undefined
|
|
300
|
+
? undefined
|
|
301
|
+
: Array.from({ length: Math.max(left.prefix?.length ?? 0, right.prefix?.length ?? 0) }, (_, index) => both(itemFacts(left, index), itemFacts(right, index)) ?? { prose: false });
|
|
302
|
+
const properties = Object.create(null);
|
|
303
|
+
for (const [name, facts] of Object.entries(left.properties ?? {})) {
|
|
304
|
+
const shared = both(facts, right.properties?.[name]);
|
|
305
|
+
if (shared !== undefined)
|
|
306
|
+
properties[name] = shared;
|
|
307
|
+
}
|
|
308
|
+
const patterns = (left.patterns ?? []).flatMap(({ pattern, facts }) => {
|
|
309
|
+
const shared = both(facts, right.patterns?.find((one) => one.pattern === pattern)?.facts);
|
|
310
|
+
return shared === undefined ? [] : [{ pattern, facts: shared }];
|
|
311
|
+
});
|
|
312
|
+
const additional = both(left.additional, right.additional);
|
|
281
313
|
return {
|
|
282
314
|
...(type === undefined ? {} : { type }),
|
|
283
315
|
...(format === undefined ? {} : { format }),
|
|
284
316
|
...(values === undefined ? {} : { values }),
|
|
285
317
|
...(reference === undefined ? {} : { reference }),
|
|
318
|
+
...(reference !== undefined && crossRoom ? { crossRoom: true } : {}),
|
|
286
319
|
prose: left.prose && right.prose,
|
|
320
|
+
...(prefix === undefined ? {} : { prefix }),
|
|
287
321
|
...(items === undefined ? {} : { items }),
|
|
322
|
+
...(Object.keys(properties).length === 0 ? {} : { properties }),
|
|
323
|
+
...(patterns.length === 0 ? {} : { patterns }),
|
|
324
|
+
...(additional === undefined ? {} : { additional }),
|
|
288
325
|
};
|
|
289
326
|
}
|
|
290
|
-
function propertiesOf(held, defs, ancestry) {
|
|
327
|
+
function propertiesOf(held, variants, defs, ancestry) {
|
|
291
328
|
const declared = new Map();
|
|
292
329
|
for (const node of held) {
|
|
293
330
|
if (!isRecord(node.properties))
|
|
@@ -298,46 +335,88 @@ function propertiesOf(held, defs, ancestry) {
|
|
|
298
335
|
const properties = Object.create(null);
|
|
299
336
|
for (const [name, schemas] of declared)
|
|
300
337
|
properties[name] = factsOf(schemas, defs, ancestry);
|
|
301
|
-
const
|
|
302
|
-
for (const branch of
|
|
303
|
-
for (const [name, facts] of Object.entries(
|
|
338
|
+
const conditional = Object.create(null);
|
|
339
|
+
for (const branch of variants.values()) {
|
|
340
|
+
for (const [name, facts] of Object.entries(branch.properties ?? {})) {
|
|
304
341
|
if (Object.hasOwn(properties, name))
|
|
305
342
|
continue;
|
|
306
|
-
|
|
343
|
+
conditional[name] = Object.hasOwn(conditional, name)
|
|
344
|
+
? joined(conditional[name], facts)
|
|
345
|
+
: facts;
|
|
307
346
|
}
|
|
308
347
|
}
|
|
309
|
-
for (const [name, facts] of Object.entries(
|
|
348
|
+
for (const [name, facts] of Object.entries(conditional))
|
|
310
349
|
properties[name] = { ...facts, conditional: true };
|
|
311
350
|
return Object.keys(properties).length === 0 ? undefined : properties;
|
|
312
351
|
}
|
|
352
|
+
function nullOnly(facts) {
|
|
353
|
+
return facts.type === 'null' || (facts.values?.every((value) => value === null) ?? false);
|
|
354
|
+
}
|
|
355
|
+
function alternativesOf(held, variants) {
|
|
356
|
+
return held.flatMap((node) => [node.anyOf, node.oneOf].flatMap((branches) => {
|
|
357
|
+
if (!Array.isArray(branches))
|
|
358
|
+
return [];
|
|
359
|
+
const kept = branches
|
|
360
|
+
.flatMap((branch) => {
|
|
361
|
+
const facts = isRecord(branch) ? variants.get(branch) : undefined;
|
|
362
|
+
return facts === undefined ? [] : [facts];
|
|
363
|
+
})
|
|
364
|
+
.filter((facts) => !nullOnly(facts));
|
|
365
|
+
return kept.length === 0 ? [] : [kept];
|
|
366
|
+
}));
|
|
367
|
+
}
|
|
368
|
+
function inheritedOf(held) {
|
|
369
|
+
return held.flatMap((node) => {
|
|
370
|
+
const kept = Object.fromEntries(['type', 'items', 'prefixItems'].flatMap((key) => node[key] === undefined ? [] : [[key, node[key]]]));
|
|
371
|
+
return Object.keys(kept).length === 0 ? [] : [kept];
|
|
372
|
+
});
|
|
373
|
+
}
|
|
313
374
|
function factsOf(nodes, defs, ancestry) {
|
|
314
375
|
const { held, ancestry: reached } = conjoined(nodes, defs, ancestry);
|
|
315
|
-
const
|
|
376
|
+
const inherited = inheritedOf(held);
|
|
377
|
+
const variants = new Map(held
|
|
378
|
+
.flatMap(variantsOf)
|
|
379
|
+
.map((branch) => [branch, factsOf([branch, ...inherited], defs, reached)]));
|
|
380
|
+
const unions = alternativesOf(held, variants);
|
|
381
|
+
const alternatives = unions.map((kept) => kept.reduce(joined));
|
|
382
|
+
const listed = [
|
|
383
|
+
...held.flatMap((node) => Array.isArray(node.enum) ? [node.enum] : node.const !== undefined ? [[node.const]] : []),
|
|
384
|
+
...alternatives.flatMap((facts) => (facts.values === undefined ? [] : [facts.values])),
|
|
385
|
+
];
|
|
316
386
|
const values = listed.length === 0
|
|
317
387
|
? undefined
|
|
318
388
|
: listed.reduce((kept, list) => kept.filter((value) => list.some((other) => equalValue(other, value))));
|
|
319
389
|
const type = firstOf(held, (node) => singleType(node.type)) ??
|
|
320
|
-
(values === undefined ? undefined : sharedType(values))
|
|
390
|
+
(values === undefined ? undefined : sharedType(values)) ??
|
|
391
|
+
alternatives.find((facts) => facts.type !== undefined)?.type;
|
|
321
392
|
const reference = firstOf(held, (node) => typeof node.reference === 'string'
|
|
322
393
|
? [node.reference]
|
|
323
394
|
: Array.isArray(node.reference)
|
|
324
395
|
? node.reference
|
|
325
|
-
: undefined);
|
|
326
|
-
const
|
|
396
|
+
: undefined) ?? alternatives.find((facts) => facts.reference !== undefined)?.reference;
|
|
397
|
+
const crossRoom = firstOf(held, (node) => node.reference === undefined ? undefined : node.cross_room === true) ?? alternatives.find((facts) => facts.reference !== undefined)?.crossRoom === true;
|
|
398
|
+
const format = firstOf(held, (node) => (typeof node.format === 'string' ? node.format : undefined)) ??
|
|
399
|
+
alternatives.find((facts) => facts.format !== undefined)?.format;
|
|
327
400
|
const prose = type === 'string' &&
|
|
328
401
|
values === undefined &&
|
|
329
402
|
format === undefined &&
|
|
330
403
|
reference === undefined &&
|
|
331
|
-
held.every((node) => node.pattern === undefined)
|
|
404
|
+
held.every((node) => node.pattern === undefined) &&
|
|
405
|
+
unions.every((kept) => kept.every((facts) => facts.type !== 'string' || facts.prose));
|
|
332
406
|
const listedItems = held.flatMap((node) => (node.items === undefined ? [] : [node.items]));
|
|
333
|
-
const items = type
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
407
|
+
const items = type !== 'array'
|
|
408
|
+
? undefined
|
|
409
|
+
: (alternatives.find((facts) => facts.items !== undefined)?.items ??
|
|
410
|
+
(listedItems.length > 0 ? factsOf(listedItems, defs, reached) : undefined));
|
|
411
|
+
const tuples = held.flatMap((node) => Array.isArray(node.prefixItems) ? [node.prefixItems] : []);
|
|
412
|
+
const prefix = type !== 'array'
|
|
413
|
+
? undefined
|
|
414
|
+
: (alternatives.find((facts) => facts.prefix !== undefined)?.prefix ??
|
|
415
|
+
(tuples.length === 0
|
|
416
|
+
? undefined
|
|
417
|
+
: Array.from({ length: Math.max(...tuples.map((tuple) => tuple.length)) }, (_, index) => factsOf(tuples.flatMap((tuple) => (index < tuple.length ? [tuple[index]] : [])), defs, reached))));
|
|
339
418
|
const mapped = type === 'object' || type === undefined;
|
|
340
|
-
const properties = mapped ? propertiesOf(held, defs, reached) : undefined;
|
|
419
|
+
const properties = mapped ? propertiesOf(held, variants, defs, reached) : undefined;
|
|
341
420
|
const patterns = mapped
|
|
342
421
|
? held.flatMap((node) => Object.entries(isRecord(node.patternProperties) ? node.patternProperties : {}).map(([pattern, schema]) => ({ pattern, facts: factsOf([schema], defs, reached) })))
|
|
343
422
|
: [];
|
|
@@ -350,6 +429,7 @@ function factsOf(nodes, defs, ancestry) {
|
|
|
350
429
|
...(format === undefined ? {} : { format }),
|
|
351
430
|
...(values === undefined ? {} : { values }),
|
|
352
431
|
...(reference === undefined ? {} : { reference }),
|
|
432
|
+
...(reference !== undefined && crossRoom ? { crossRoom: true } : {}),
|
|
353
433
|
prose,
|
|
354
434
|
...(prefix === undefined ? {} : { prefix }),
|
|
355
435
|
...(items === undefined ? {} : { items }),
|
|
@@ -478,21 +558,134 @@ function deepFreeze(value) {
|
|
|
478
558
|
}
|
|
479
559
|
return value;
|
|
480
560
|
}
|
|
561
|
+
function ruleValue(value) {
|
|
562
|
+
return value === null || typeof value === 'string' || typeof value === 'boolean' || finite(value);
|
|
563
|
+
}
|
|
564
|
+
function roleNames(value) {
|
|
565
|
+
return strings(value) && value.every((name) => name !== '');
|
|
566
|
+
}
|
|
567
|
+
function compositesOf(value) {
|
|
568
|
+
return Array.isArray(value) ? ['array'] : isRecord(value) ? ['object'] : [];
|
|
569
|
+
}
|
|
570
|
+
function typed(type) {
|
|
571
|
+
const types = typeof type === 'string' ? [type] : type;
|
|
572
|
+
return Array.isArray(types) ? COMPOSITES.filter((kind) => types.includes(kind)) : undefined;
|
|
573
|
+
}
|
|
574
|
+
function admittedWhole(node) {
|
|
575
|
+
if (node === true)
|
|
576
|
+
return COMPOSITES;
|
|
577
|
+
if (!isRecord(node) || Object.keys(node).some((key) => key !== 'type' && !ANNOTATIONS.has(key)))
|
|
578
|
+
return [];
|
|
579
|
+
return typed(node.type) ?? COMPOSITES;
|
|
580
|
+
}
|
|
581
|
+
function composites(node, defs, seen) {
|
|
582
|
+
if (node === false)
|
|
583
|
+
return [];
|
|
584
|
+
if (!isRecord(node))
|
|
585
|
+
return COMPOSITES;
|
|
586
|
+
const each = (nodes) => Array.isArray(nodes) ? nodes.map((one) => composites(one, defs, seen)) : [];
|
|
587
|
+
const target = typeof node.$ref === 'string' ? refTarget(node.$ref, defs)?.node : undefined;
|
|
588
|
+
const conditioned = () => {
|
|
589
|
+
const met = composites(node.then ?? true, defs, seen);
|
|
590
|
+
return COMPOSITES.filter((kind) => (composites(node.if, defs, seen).includes(kind) && met.includes(kind)) ||
|
|
591
|
+
composites(node.else ?? true, defs, seen).includes(kind));
|
|
592
|
+
};
|
|
593
|
+
const bounds = [
|
|
594
|
+
typed(node.type),
|
|
595
|
+
Array.isArray(node.enum) ? node.enum.flatMap(compositesOf) : undefined,
|
|
596
|
+
Object.hasOwn(node, 'const') ? compositesOf(node.const) : undefined,
|
|
597
|
+
target === undefined || seen.has(target)
|
|
598
|
+
? undefined
|
|
599
|
+
: composites(target, defs, new Set([...seen, target])),
|
|
600
|
+
...each(node.allOf),
|
|
601
|
+
...[node.anyOf, node.oneOf].filter(Array.isArray).map((branches) => each(branches).flat()),
|
|
602
|
+
Object.hasOwn(node, 'if') ? conditioned() : undefined,
|
|
603
|
+
Object.hasOwn(node, 'not')
|
|
604
|
+
? COMPOSITES.filter((kind) => !admittedWhole(node.not).includes(kind))
|
|
605
|
+
: undefined,
|
|
606
|
+
];
|
|
607
|
+
return COMPOSITES.filter((kind) => bounds.every((bound) => bound?.includes(kind) ?? true));
|
|
608
|
+
}
|
|
609
|
+
function transitionOf(value) {
|
|
610
|
+
if (!isRecord(value) || !Object.hasOwn(value, 'from') || !Object.hasOwn(value, 'to'))
|
|
611
|
+
return undefined;
|
|
612
|
+
const { from, to, roles, ...rest } = value;
|
|
613
|
+
if (Object.keys(rest).length > 0 || !ruleValue(from) || !ruleValue(to))
|
|
614
|
+
return undefined;
|
|
615
|
+
if (roles === undefined)
|
|
616
|
+
return { from, to };
|
|
617
|
+
return roleNames(roles) ? { from, to, roles } : undefined;
|
|
618
|
+
}
|
|
619
|
+
function fieldRules(written, field, at, defs) {
|
|
620
|
+
const { change_roles: changeRoles, initial_roles: initialRoles, transitions } = written;
|
|
621
|
+
if (changeRoles !== undefined && !roleNames(changeRoles))
|
|
622
|
+
return refuse('change_roles', `${at}/change_roles`);
|
|
623
|
+
if (initialRoles !== undefined && !roleNames(initialRoles))
|
|
624
|
+
return refuse('initial_roles', `${at}/initial_roles`);
|
|
625
|
+
if (transitions === undefined)
|
|
626
|
+
return {
|
|
627
|
+
...(changeRoles === undefined ? {} : { changeRoles }),
|
|
628
|
+
...(initialRoles === undefined ? {} : { initialRoles }),
|
|
629
|
+
};
|
|
630
|
+
if (!Array.isArray(transitions) || composites(field, defs, new Set()).length > 0)
|
|
631
|
+
return refuse('transitions', `${at}/transitions`);
|
|
632
|
+
const listed = [];
|
|
633
|
+
for (const [index, held] of transitions.entries()) {
|
|
634
|
+
const transition = transitionOf(held);
|
|
635
|
+
if (transition === undefined)
|
|
636
|
+
return refuse('transitions', `${at}/transitions/${index}`);
|
|
637
|
+
listed.push(transition);
|
|
638
|
+
}
|
|
639
|
+
return {
|
|
640
|
+
...(changeRoles === undefined ? {} : { changeRoles }),
|
|
641
|
+
...(initialRoles === undefined ? {} : { initialRoles }),
|
|
642
|
+
transitions: listed,
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
function unruled(schema) {
|
|
646
|
+
const written = new Map();
|
|
647
|
+
if (!isRecord(schema.properties))
|
|
648
|
+
return { schema, written };
|
|
649
|
+
const properties = Object.create(null);
|
|
650
|
+
for (const [field, node] of Object.entries(schema.properties)) {
|
|
651
|
+
if (!isRecord(node) || !FIELD_RULES.some((keyword) => Object.hasOwn(node, keyword))) {
|
|
652
|
+
properties[field] = node;
|
|
653
|
+
continue;
|
|
654
|
+
}
|
|
655
|
+
written.set(field, node);
|
|
656
|
+
properties[field] = Object.fromEntries(Object.entries(node).filter(([keyword]) => !FIELD_RULES.includes(keyword)));
|
|
657
|
+
}
|
|
658
|
+
return { schema: written.size === 0 ? schema : { ...schema, properties }, written };
|
|
659
|
+
}
|
|
481
660
|
function readType(name, value, context) {
|
|
482
661
|
const at = `/${escapePointer(name)}`;
|
|
483
662
|
if (!isRecord(value))
|
|
484
663
|
return refuse('schema', at);
|
|
485
|
-
const { sections: declared, member_document: mark, ...
|
|
664
|
+
const { sections: declared, member_document: mark, create_roles: createRoles, delete_roles: deleteRoles, ...ruled } = value;
|
|
486
665
|
if (mark !== undefined && typeof mark !== 'boolean')
|
|
487
666
|
return refuse('member_document', `${at}/member_document`);
|
|
667
|
+
if (createRoles !== undefined && !roleNames(createRoles))
|
|
668
|
+
return refuse('create_roles', `${at}/create_roles`);
|
|
669
|
+
if (deleteRoles !== undefined && !roleNames(deleteRoles))
|
|
670
|
+
return refuse('delete_roles', `${at}/delete_roles`);
|
|
488
671
|
const read = declared === undefined
|
|
489
672
|
? { sections: Object.create(null) }
|
|
490
673
|
: readSections(declared, `${at}/sections`, context);
|
|
491
674
|
if ('failure' in read)
|
|
492
675
|
return read.failure;
|
|
676
|
+
const { schema, written } = unruled(ruled);
|
|
493
677
|
const failure = schemaFailure(schema, at, context);
|
|
494
678
|
if (failure !== undefined)
|
|
495
679
|
return failure;
|
|
680
|
+
const rules = Object.create(null);
|
|
681
|
+
for (const [field, keywords] of written) {
|
|
682
|
+
const properties = schema.properties;
|
|
683
|
+
const where = `${at}/properties/${escapePointer(field)}`;
|
|
684
|
+
const ruling = fieldRules(keywords, properties[field], where, context.defs);
|
|
685
|
+
if ('rule' in ruling)
|
|
686
|
+
return ruling;
|
|
687
|
+
rules[field] = ruling;
|
|
688
|
+
}
|
|
496
689
|
const memberDocument = mark === true;
|
|
497
690
|
const root = valueFacts(schema, context.defs);
|
|
498
691
|
const fields = Object.assign(Object.create(null), root.properties);
|
|
@@ -500,13 +693,20 @@ function readType(name, value, context) {
|
|
|
500
693
|
fields[MEMBER_FIELD] = { type: 'string', prose: false };
|
|
501
694
|
const defs = Object.create(null);
|
|
502
695
|
reachedDefs(value, context.defs, defs);
|
|
696
|
+
const { create_roles: _create, delete_roles: _delete, ...shaped } = value;
|
|
503
697
|
return {
|
|
504
698
|
name,
|
|
505
699
|
memberDocument,
|
|
506
700
|
frontmatter: { ...root, properties: { ...HOUSE_KEYS, ...fields } },
|
|
507
701
|
fields,
|
|
508
702
|
sections: read.sections,
|
|
509
|
-
|
|
703
|
+
rules,
|
|
704
|
+
...(createRoles === undefined ? {} : { createRoles }),
|
|
705
|
+
...(deleteRoles === undefined ? {} : { deleteRoles }),
|
|
706
|
+
shape: {
|
|
707
|
+
schema: written.size === 0 ? shaped : { ...shaped, properties: schema.properties },
|
|
708
|
+
defs,
|
|
709
|
+
},
|
|
510
710
|
};
|
|
511
711
|
}
|
|
512
712
|
function lineAt(text, offset) {
|
package/dist/divide.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"divide.d.ts","sourceRoot":"","sources":["../src/divide.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"divide.d.ts","sourceRoot":"","sources":["../src/divide.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAgB,MAAM,YAAY,CAAC;AAwXpF,wBAAgB,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,QAAQ,CAc3F"}
|
package/dist/divide.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { blockRanges, headingLines } from './blocks.js';
|
|
2
|
-
import { projectionInput, rangeText } from './project.js';
|
|
2
|
+
import { firstEditFrom, projectionInput, rangeText, } from './project.js';
|
|
3
3
|
import { refusal } from './refuse.js';
|
|
4
4
|
const SMALLEST_BUDGET = 2;
|
|
5
5
|
function node(draft) {
|
|
@@ -131,16 +131,26 @@ function textOf(state, extent) {
|
|
|
131
131
|
return rangeText(state.content, extent, state.edits);
|
|
132
132
|
}
|
|
133
133
|
function sourceCutting(state, extent) {
|
|
134
|
-
|
|
134
|
+
const source = state.content.slice(extent.start, extent.end);
|
|
135
135
|
const masks = [];
|
|
136
|
-
for (
|
|
137
|
-
|
|
136
|
+
for (let index = firstEditFrom(state.edits, extent.start); index < state.edits.length; index += 1) {
|
|
137
|
+
const edit = state.edits[index];
|
|
138
|
+
if (edit.start > extent.end)
|
|
139
|
+
break;
|
|
140
|
+
if (edit.end > extent.end)
|
|
138
141
|
continue;
|
|
139
|
-
|
|
140
|
-
const to = edit.end - extent.start;
|
|
141
|
-
text = `${text.slice(0, from)}${'x'.repeat(to - from)}${text.slice(to)}`;
|
|
142
|
-
masks.push({ start: from, end: to });
|
|
142
|
+
masks.push({ start: edit.start - extent.start, end: edit.end - extent.start });
|
|
143
143
|
}
|
|
144
|
+
let text = '';
|
|
145
|
+
let cursor = 0;
|
|
146
|
+
for (const mask of masks) {
|
|
147
|
+
if (mask.end <= cursor)
|
|
148
|
+
continue;
|
|
149
|
+
const from = Math.max(mask.start, cursor);
|
|
150
|
+
text += `${source.slice(cursor, from)}${'x'.repeat(mask.end - from)}`;
|
|
151
|
+
cursor = mask.end;
|
|
152
|
+
}
|
|
153
|
+
text += source.slice(cursor);
|
|
144
154
|
return {
|
|
145
155
|
text,
|
|
146
156
|
masks,
|