@agentshouse/mdmodel 0.1.0-cad192ab63d5f → 0.1.0-cae8e240cefab
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 +241 -211
- package/README.md +21 -22
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +35 -20
- package/dist/definition.d.ts +17 -1
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +245 -25
- package/dist/divide.d.ts.map +1 -1
- package/dist/divide.js +27 -17
- package/dist/document.d.ts +5 -5
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +304 -187
- package/dist/event.d.ts +78 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +230 -0
- package/dist/facts.d.ts +15 -0
- package/dist/facts.d.ts.map +1 -0
- package/dist/facts.js +38 -0
- package/dist/index.d.ts +24 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -6
- package/dist/kinds.d.ts +19 -0
- package/dist/kinds.d.ts.map +1 -0
- package/dist/kinds.js +161 -0
- package/dist/links.d.ts +2 -0
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +107 -50
- package/dist/paths.d.ts +9 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +28 -2
- package/dist/pattern.d.ts +10 -0
- package/dist/pattern.d.ts.map +1 -0
- package/dist/pattern.js +355 -0
- package/dist/project.d.ts +1 -0
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +38 -15
- 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 +147 -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 +284 -0
- package/dist/references.d.ts.map +1 -1
- package/dist/references.js +6 -1
- package/dist/reserved.d.ts +5 -0
- package/dist/reserved.d.ts.map +1 -0
- package/dist/reserved.js +20 -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 +35 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +30 -4
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +365 -101
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +36 -3
- package/fixtures/README.md +26 -6
- 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/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/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/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 +26 -26
- package/fixtures/queries.json +964 -0
- package/package.json +7 -2
- package/dist/condition.d.ts +0 -150
- package/dist/condition.d.ts.map +0 -1
- package/dist/condition.js +0 -502
package/README.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# `@agentshouse/mdmodel`
|
|
2
2
|
|
|
3
|
-
Typed Markdown documents: MD Types declared in JSON Schema, a parser, a validator,
|
|
4
|
-
deterministic application of one structured change to a Document,
|
|
5
|
-
|
|
3
|
+
Typed Markdown documents: MD Types declared in JSON Schema, a parser, a validator, the
|
|
4
|
+
deterministic application of one structured change to a Document, and one query language
|
|
5
|
+
answered in SQL over a collection or in memory over one Document, plus a conformance
|
|
6
|
+
fixture corpus.
|
|
6
7
|
|
|
7
8
|
It runs in the browser and in Node, makes no network call, and reads no
|
|
8
|
-
filesystem on its own. It ships one ESM artifact that Node 24.
|
|
9
|
+
filesystem on its own. It ships one ESM artifact that Node 24.22.1 and later
|
|
9
10
|
loads through `import` or `require`.
|
|
10
11
|
|
|
11
12
|
## Install
|
|
@@ -26,30 +27,28 @@ if (checked.verdict === 'accept') {
|
|
|
26
27
|
|
|
27
28
|
const parsed = parse('---\ntype: note\ntitle: Hello\n---\n');
|
|
28
29
|
if (parsed.ok) {
|
|
29
|
-
const next = apply(parsed.document,
|
|
30
|
-
kind: 'field',
|
|
31
|
-
|
|
32
|
-
value: 'World',
|
|
33
|
-
prior: 'Hello',
|
|
34
|
-
});
|
|
30
|
+
const next = apply(parsed.document, [
|
|
31
|
+
{ kind: 'field', name: 'title', value: 'World', prior: 'Hello' },
|
|
32
|
+
]);
|
|
35
33
|
if (next.outcome === 'applied') serialize(next.document);
|
|
36
34
|
}
|
|
37
35
|
```
|
|
38
36
|
|
|
39
37
|
## API
|
|
40
38
|
|
|
41
|
-
| Export | Purpose
|
|
42
|
-
| ---------------------------------------------- |
|
|
43
|
-
| `verify` | Verify one schema text into a model of MD Types
|
|
44
|
-
| `validate` | Validate a text Library; returns acceptance or one refusal
|
|
45
|
-
| `parse`, `serialize` | Read and write one Document
|
|
46
|
-
| `apply` | Apply
|
|
47
|
-
| `links`, `target`, `retarget` | Inventory and rewrite link destinations
|
|
48
|
-
| `escapePointer` | Write one key as a JSON Pointer token
|
|
49
|
-
| `project`, `divide` | Embedding projection input and its division into Spans
|
|
50
|
-
| `facts`, `
|
|
51
|
-
| `
|
|
52
|
-
| `
|
|
39
|
+
| Export | Purpose |
|
|
40
|
+
| ---------------------------------------------- | ------------------------------------------------------------------ |
|
|
41
|
+
| `verify` | Verify one schema text into a model of MD Types |
|
|
42
|
+
| `validate` | Validate a text Library; returns acceptance or one refusal |
|
|
43
|
+
| `parse`, `serialize` | Read and write one Document |
|
|
44
|
+
| `apply` | Apply field, section, preamble, link and reference changes at once |
|
|
45
|
+
| `links`, `target`, `retarget` | Inventory and rewrite link destinations |
|
|
46
|
+
| `escapePointer` | Write one key as a JSON Pointer token |
|
|
47
|
+
| `project`, `divide` | Embedding projection input and its division into Spans |
|
|
48
|
+
| `facts`, `candidateOf` | A Document as one change saw it, matched as one query candidate |
|
|
49
|
+
| `planOf`, `matches`, `sql` | Check a query, answer it over one Document or compile it to SQL |
|
|
50
|
+
| `MARKDOWN_SYNTAX_PROFILE`, `VERSION` | The pinned Markdown profile (GFM 0.29) and MD model version |
|
|
51
|
+
| `MEMBER_FIELD`, `SITE_FIELD`, `RECEIVED_FIELD` | The field names validation counts as declared beyond a type's own |
|
|
53
52
|
|
|
54
53
|
The full reference is in [`API.md`](API.md). The conformance corpus and its
|
|
55
54
|
verdict format and rule ids are described in [`fixtures/README.md`](fixtures/README.md).
|
package/dist/blocks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;
|
|
1
|
+
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAoDF,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,WAAW,EAAE,CA4BrF;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAe/E"}
|
package/dist/blocks.js
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
|
-
import { fenceSpans } from './links.js';
|
|
2
|
-
const
|
|
1
|
+
import { fenceSpans, spanCursor } from './links.js';
|
|
2
|
+
const HEADING_OPEN = /^(#{1,6})(?!#)([ \t]+)/;
|
|
3
|
+
const LINE_BREAK = /[\n\r\u2028\u2029]/;
|
|
4
|
+
function blank(character) {
|
|
5
|
+
return character === ' ' || character === '\t';
|
|
6
|
+
}
|
|
7
|
+
function heading(text) {
|
|
8
|
+
const open = HEADING_OPEN.exec(text);
|
|
9
|
+
if (open === null || LINE_BREAK.test(text))
|
|
10
|
+
return null;
|
|
11
|
+
const level = open[1].length;
|
|
12
|
+
const rest = text.slice(open[0].length);
|
|
13
|
+
if (rest === '')
|
|
14
|
+
return open[2].length > 1 ? { level, name: '' } : null;
|
|
15
|
+
let end = rest.length;
|
|
16
|
+
while (blank(rest[end - 1]))
|
|
17
|
+
end -= 1;
|
|
18
|
+
let hashes = end;
|
|
19
|
+
while (rest[hashes - 1] === '#')
|
|
20
|
+
hashes -= 1;
|
|
21
|
+
let spaced = hashes;
|
|
22
|
+
while (blank(rest[spaced - 1]))
|
|
23
|
+
spaced -= 1;
|
|
24
|
+
const closed = hashes < end && spaced < hashes && spaced > 0;
|
|
25
|
+
return { level, name: rest.slice(0, closed ? spaced : end).trim() };
|
|
26
|
+
}
|
|
3
27
|
function lineAt(content, from, to) {
|
|
4
28
|
const nl = content.indexOf('\n', from);
|
|
5
29
|
const end = nl === -1 || nl >= to ? to : nl;
|
|
@@ -7,17 +31,11 @@ function lineAt(content, from, to) {
|
|
|
7
31
|
return { text: raw.endsWith('\r') ? raw.slice(0, -1) : raw, next: end === to ? to : end + 1 };
|
|
8
32
|
}
|
|
9
33
|
function scan(content, from, to, visit) {
|
|
10
|
-
const
|
|
34
|
+
const fenced = spanCursor(fenceSpans(content.slice(from, to)));
|
|
11
35
|
let i = from;
|
|
12
36
|
while (i < to) {
|
|
13
37
|
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
|
-
});
|
|
38
|
+
visit({ text, start: i, next, fenced: fenced(i - from) !== undefined });
|
|
21
39
|
if (next === i)
|
|
22
40
|
break;
|
|
23
41
|
i = next;
|
|
@@ -26,24 +44,21 @@ function scan(content, from, to, visit) {
|
|
|
26
44
|
const HASH = 0x23;
|
|
27
45
|
export function headingLines(content, from, to) {
|
|
28
46
|
const found = [];
|
|
29
|
-
let
|
|
47
|
+
let fenced = null;
|
|
30
48
|
let i = from;
|
|
31
49
|
while (i < to) {
|
|
32
50
|
const nl = content.indexOf('\n', i);
|
|
33
51
|
const end = nl === -1 || nl >= to ? to : nl;
|
|
34
52
|
const next = end === to ? to : end + 1;
|
|
35
53
|
if (content.charCodeAt(i) === HASH) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (!fences.some(([start, stop]) => at >= start && at < stop)) {
|
|
54
|
+
fenced ??= spanCursor(fenceSpans(content.slice(from, to)));
|
|
55
|
+
if (fenced(i - from) === undefined) {
|
|
39
56
|
const { text } = lineAt(content, i, to);
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const name = match?.[2];
|
|
43
|
-
if (hashes !== undefined && name !== undefined) {
|
|
57
|
+
const read = heading(text);
|
|
58
|
+
if (read !== null) {
|
|
44
59
|
found.push({
|
|
45
|
-
level:
|
|
46
|
-
name: name
|
|
60
|
+
level: read.level,
|
|
61
|
+
name: read.name,
|
|
47
62
|
start: i,
|
|
48
63
|
textEnd: i + text.length,
|
|
49
64
|
next,
|
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 = {
|
|
@@ -45,6 +60,7 @@ export declare const JSON_TYPES: readonly JsonType[];
|
|
|
45
60
|
export declare const BUILT_IN_TYPE = "any";
|
|
46
61
|
export declare const ATTACHMENT = "attachment";
|
|
47
62
|
export declare const ARRAY_INDEX: RegExp;
|
|
63
|
+
export declare const JSON_POINTER: RegExp;
|
|
48
64
|
export declare function escapePointer(key: string): string;
|
|
49
65
|
export declare function pointerSegments(pointer: string): string[];
|
|
50
66
|
export declare function refTarget(reference: string, defs: Readonly<Record<string, unknown>>): {
|
|
@@ -62,5 +78,5 @@ export type PointerFacts = {
|
|
|
62
78
|
export declare function crossedFacts(facts: ValueFacts): ValueFacts[];
|
|
63
79
|
export declare function fieldFacts(definition: Definition, key: string): ValueFacts | undefined;
|
|
64
80
|
export declare function pointerFacts(definition: Definition, pointer: string): PointerFacts | undefined;
|
|
65
|
-
export declare function readSchema(text: string): VerifiedModel | Failure;
|
|
81
|
+
export declare function readSchema(text: string, provided?: VerifiedModel, checked?: boolean): VerifiedModel | Failure;
|
|
66
82
|
//# sourceMappingURL=definition.d.ts.map
|
package/dist/definition.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"AAEA,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,SAAS,CAAC,EAAE,I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B,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,aAAwB,EAClC,OAAO,UAAO,GACb,aAAa,GAAG,OAAO,CA0CzB"}
|
package/dist/definition.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
|
|
2
|
+
import { linearPattern } from './pattern.js';
|
|
2
3
|
import { equalValue, isRecord, jsValue, parseYamlMapping, YamlError } from './yaml.js';
|
|
3
4
|
export const JSON_TYPES = [
|
|
4
5
|
'string',
|
|
@@ -12,9 +13,25 @@ export const JSON_TYPES = [
|
|
|
12
13
|
export const BUILT_IN_TYPE = 'any';
|
|
13
14
|
export const ATTACHMENT = 'attachment';
|
|
14
15
|
const SCALAR_TYPES = new Set(['string', 'number', 'integer', 'boolean']);
|
|
16
|
+
const COMPOSITES = ['array', 'object'];
|
|
17
|
+
const ANNOTATIONS = new Set([
|
|
18
|
+
'$comment',
|
|
19
|
+
'title',
|
|
20
|
+
'description',
|
|
21
|
+
'default',
|
|
22
|
+
'examples',
|
|
23
|
+
'deprecated',
|
|
24
|
+
'readOnly',
|
|
25
|
+
'writeOnly',
|
|
26
|
+
]);
|
|
27
|
+
const FIELD_RULES = ['change_roles', 'initial_roles', 'transitions'];
|
|
28
|
+
const PROVIDED_KEYWORDS = ['create_roles', 'delete_roles'];
|
|
29
|
+
const NO_TYPES = Object.freeze({ types: Object.freeze({}) });
|
|
15
30
|
const DEFS_REFERENCE = '#/$defs/';
|
|
31
|
+
const UNBOUNDED_FORMAT = 'url';
|
|
16
32
|
const UNRESOLVED = /[\u0000-\u001f\u007f%[\]\\^{|}]|\s$/u;
|
|
17
33
|
export const ARRAY_INDEX = /^(?:0|[1-9][0-9]*)$/u;
|
|
34
|
+
export const JSON_POINTER = /^(?:\/(?:[^~/]|~[01])*)*$/u;
|
|
18
35
|
const HOUSE_KEYS = {
|
|
19
36
|
[TYPE_FIELD]: { prose: false },
|
|
20
37
|
[SITE_FIELD]: { prose: false },
|
|
@@ -33,12 +50,12 @@ export function pointerSegments(pointer) {
|
|
|
33
50
|
return pointer.split('/').slice(1).map(unescapePointer);
|
|
34
51
|
}
|
|
35
52
|
export function refTarget(reference, defs) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (segments.some((segment) => escapePointer(unescapePointer(segment)) !== segment))
|
|
53
|
+
const pointer = reference.slice('#'.length);
|
|
54
|
+
if (!reference.startsWith(DEFS_REFERENCE) ||
|
|
55
|
+
UNRESOLVED.test(reference) ||
|
|
56
|
+
!JSON_POINTER.test(pointer))
|
|
41
57
|
return undefined;
|
|
58
|
+
const [, name = '', ...rest] = pointerSegments(pointer);
|
|
42
59
|
if (!Object.hasOwn(defs, name))
|
|
43
60
|
return undefined;
|
|
44
61
|
let node = defs[name];
|
|
@@ -69,15 +86,7 @@ export function refTarget(reference, defs) {
|
|
|
69
86
|
return { name, node };
|
|
70
87
|
}
|
|
71
88
|
function compiles(pattern) {
|
|
72
|
-
|
|
73
|
-
return false;
|
|
74
|
-
try {
|
|
75
|
-
new RegExp(pattern, 'u');
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
catch {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
89
|
+
return typeof pattern === 'string' && linearPattern(pattern) !== null;
|
|
81
90
|
}
|
|
82
91
|
function finite(value) {
|
|
83
92
|
return typeof value === 'number' && Number.isFinite(value);
|
|
@@ -91,7 +100,7 @@ function strings(value) {
|
|
|
91
100
|
new Set(value).size === value.length);
|
|
92
101
|
}
|
|
93
102
|
function schemaFailure(value, at, context) {
|
|
94
|
-
if (typeof value === 'boolean')
|
|
103
|
+
if (!context.checked || typeof value === 'boolean')
|
|
95
104
|
return undefined;
|
|
96
105
|
if (!isRecord(value))
|
|
97
106
|
return refuse('schema', at);
|
|
@@ -187,7 +196,7 @@ const KEYWORDS = {
|
|
|
187
196
|
uniqueItems: FLAG,
|
|
188
197
|
required: strings,
|
|
189
198
|
dependentRequired: (value) => isRecord(value) && Object.values(value).every(strings),
|
|
190
|
-
format:
|
|
199
|
+
format: (value) => typeof value === 'string' && value !== UNBOUNDED_FORMAT,
|
|
191
200
|
contentEncoding: TEXT,
|
|
192
201
|
contentMediaType: TEXT,
|
|
193
202
|
title: TEXT,
|
|
@@ -204,8 +213,12 @@ const KEYWORDS = {
|
|
|
204
213
|
return (Array.isArray(named) &&
|
|
205
214
|
named.length > 0 &&
|
|
206
215
|
strings(named) &&
|
|
207
|
-
named.every((name) => name === BUILT_IN_TYPE ||
|
|
216
|
+
named.every((name) => name === BUILT_IN_TYPE ||
|
|
217
|
+
name === ATTACHMENT ||
|
|
218
|
+
context.types.has(name) ||
|
|
219
|
+
node.cross_room === true));
|
|
208
220
|
},
|
|
221
|
+
cross_room: (value, _at, node) => typeof value === 'boolean' && node.reference !== undefined,
|
|
209
222
|
};
|
|
210
223
|
function sharedType(values) {
|
|
211
224
|
if (values.length === 0)
|
|
@@ -278,6 +291,7 @@ function joined(left, right) {
|
|
|
278
291
|
const format = left.format === right.format ? left.format : undefined;
|
|
279
292
|
const values = united(left.values, right.values);
|
|
280
293
|
const reference = united(left.reference, right.reference);
|
|
294
|
+
const crossRoom = left.crossRoom === true || right.crossRoom === true;
|
|
281
295
|
const items = both(left.items, right.items);
|
|
282
296
|
const prefix = left.prefix === undefined && right.prefix === undefined
|
|
283
297
|
? undefined
|
|
@@ -298,6 +312,7 @@ function joined(left, right) {
|
|
|
298
312
|
...(format === undefined ? {} : { format }),
|
|
299
313
|
...(values === undefined ? {} : { values }),
|
|
300
314
|
...(reference === undefined ? {} : { reference }),
|
|
315
|
+
...(reference !== undefined && crossRoom ? { crossRoom: true } : {}),
|
|
301
316
|
prose: left.prose && right.prose,
|
|
302
317
|
...(prefix === undefined ? {} : { prefix }),
|
|
303
318
|
...(items === undefined ? {} : { items }),
|
|
@@ -376,6 +391,7 @@ function factsOf(nodes, defs, ancestry) {
|
|
|
376
391
|
: Array.isArray(node.reference)
|
|
377
392
|
? node.reference
|
|
378
393
|
: undefined) ?? alternatives.find((facts) => facts.reference !== undefined)?.reference;
|
|
394
|
+
const crossRoom = firstOf(held, (node) => node.reference === undefined ? undefined : node.cross_room === true) ?? alternatives.find((facts) => facts.reference !== undefined)?.crossRoom === true;
|
|
379
395
|
const format = firstOf(held, (node) => (typeof node.format === 'string' ? node.format : undefined)) ??
|
|
380
396
|
alternatives.find((facts) => facts.format !== undefined)?.format;
|
|
381
397
|
const prose = type === 'string' &&
|
|
@@ -410,6 +426,7 @@ function factsOf(nodes, defs, ancestry) {
|
|
|
410
426
|
...(format === undefined ? {} : { format }),
|
|
411
427
|
...(values === undefined ? {} : { values }),
|
|
412
428
|
...(reference === undefined ? {} : { reference }),
|
|
429
|
+
...(reference !== undefined && crossRoom ? { crossRoom: true } : {}),
|
|
413
430
|
prose,
|
|
414
431
|
...(prefix === undefined ? {} : { prefix }),
|
|
415
432
|
...(items === undefined ? {} : { items }),
|
|
@@ -427,7 +444,7 @@ export function itemFacts(facts, index) {
|
|
|
427
444
|
export function memberFacts(facts, key) {
|
|
428
445
|
if (facts.properties !== undefined && Object.hasOwn(facts.properties, key))
|
|
429
446
|
return facts.properties[key];
|
|
430
|
-
const pattern = facts.patterns?.find((one) =>
|
|
447
|
+
const pattern = facts.patterns?.find((one) => linearPattern(one.pattern).test(key));
|
|
431
448
|
return pattern === undefined ? facts.additional : pattern.facts;
|
|
432
449
|
}
|
|
433
450
|
export function crossedFacts(facts) {
|
|
@@ -530,6 +547,56 @@ function readSections(value, at, context) {
|
|
|
530
547
|
}
|
|
531
548
|
return { sections };
|
|
532
549
|
}
|
|
550
|
+
function branchSectionsFailure(sections, declared, where) {
|
|
551
|
+
if (!isRecord(sections))
|
|
552
|
+
return refuse('sections', where);
|
|
553
|
+
for (const [name, spec] of Object.entries(sections)) {
|
|
554
|
+
const place = `${where}/${escapePointer(name)}`;
|
|
555
|
+
const own = isRecord(declared) && Object.hasOwn(declared, name) ? declared[name] : undefined;
|
|
556
|
+
if (!isRecord(spec) || !isRecord(own))
|
|
557
|
+
return refuse('sections', place);
|
|
558
|
+
const { required, ...kind } = spec;
|
|
559
|
+
const { required: _required, ...ownKind } = own;
|
|
560
|
+
if (required !== undefined && typeof required !== 'boolean')
|
|
561
|
+
return refuse('sections', `${place}/required`);
|
|
562
|
+
if (!equalValue(kind, ownKind))
|
|
563
|
+
return refuse('sections', place);
|
|
564
|
+
}
|
|
565
|
+
return undefined;
|
|
566
|
+
}
|
|
567
|
+
function withoutBranchSections(schema, declared, at) {
|
|
568
|
+
const kept = { ...schema };
|
|
569
|
+
if (Array.isArray(schema.allOf)) {
|
|
570
|
+
const entries = [];
|
|
571
|
+
for (const [index, entry] of schema.allOf.entries()) {
|
|
572
|
+
const read = isRecord(entry)
|
|
573
|
+
? withoutBranchSections(entry, declared, `${at}/allOf/${index}`)
|
|
574
|
+
: { schema: entry };
|
|
575
|
+
if ('failure' in read)
|
|
576
|
+
return read;
|
|
577
|
+
entries.push(read.schema);
|
|
578
|
+
}
|
|
579
|
+
kept.allOf = entries;
|
|
580
|
+
}
|
|
581
|
+
if (schema.if === undefined)
|
|
582
|
+
return { schema: kept };
|
|
583
|
+
for (const branch of ['then', 'else']) {
|
|
584
|
+
const held = schema[branch];
|
|
585
|
+
if (!isRecord(held))
|
|
586
|
+
continue;
|
|
587
|
+
const { sections, ...rest } = held;
|
|
588
|
+
const failure = sections === undefined
|
|
589
|
+
? undefined
|
|
590
|
+
: branchSectionsFailure(sections, declared, `${at}/${branch}/sections`);
|
|
591
|
+
if (failure !== undefined)
|
|
592
|
+
return { failure };
|
|
593
|
+
const read = withoutBranchSections(rest, declared, `${at}/${branch}`);
|
|
594
|
+
if ('failure' in read)
|
|
595
|
+
return read;
|
|
596
|
+
kept[branch] = read.schema;
|
|
597
|
+
}
|
|
598
|
+
return { schema: kept };
|
|
599
|
+
}
|
|
533
600
|
function deepFreeze(value) {
|
|
534
601
|
if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
|
|
535
602
|
Object.freeze(value);
|
|
@@ -538,21 +605,157 @@ function deepFreeze(value) {
|
|
|
538
605
|
}
|
|
539
606
|
return value;
|
|
540
607
|
}
|
|
608
|
+
function ruleValue(value) {
|
|
609
|
+
return value === null || typeof value === 'string' || typeof value === 'boolean' || finite(value);
|
|
610
|
+
}
|
|
611
|
+
function roleNames(value) {
|
|
612
|
+
return strings(value) && value.every((name) => name !== '');
|
|
613
|
+
}
|
|
614
|
+
function compositesOf(value) {
|
|
615
|
+
return Array.isArray(value) ? ['array'] : isRecord(value) ? ['object'] : [];
|
|
616
|
+
}
|
|
617
|
+
function typed(type) {
|
|
618
|
+
const types = typeof type === 'string' ? [type] : type;
|
|
619
|
+
return Array.isArray(types) ? COMPOSITES.filter((kind) => types.includes(kind)) : undefined;
|
|
620
|
+
}
|
|
621
|
+
function admittedWhole(node) {
|
|
622
|
+
if (node === true)
|
|
623
|
+
return COMPOSITES;
|
|
624
|
+
if (!isRecord(node) || Object.keys(node).some((key) => key !== 'type' && !ANNOTATIONS.has(key)))
|
|
625
|
+
return [];
|
|
626
|
+
return typed(node.type) ?? COMPOSITES;
|
|
627
|
+
}
|
|
628
|
+
function composites(node, defs, seen) {
|
|
629
|
+
if (node === false)
|
|
630
|
+
return [];
|
|
631
|
+
if (!isRecord(node))
|
|
632
|
+
return COMPOSITES;
|
|
633
|
+
const each = (nodes) => Array.isArray(nodes) ? nodes.map((one) => composites(one, defs, seen)) : [];
|
|
634
|
+
const target = typeof node.$ref === 'string' ? refTarget(node.$ref, defs)?.node : undefined;
|
|
635
|
+
const conditioned = () => {
|
|
636
|
+
const met = composites(node.then ?? true, defs, seen);
|
|
637
|
+
return COMPOSITES.filter((kind) => (composites(node.if, defs, seen).includes(kind) && met.includes(kind)) ||
|
|
638
|
+
composites(node.else ?? true, defs, seen).includes(kind));
|
|
639
|
+
};
|
|
640
|
+
const bounds = [
|
|
641
|
+
typed(node.type),
|
|
642
|
+
Array.isArray(node.enum) ? node.enum.flatMap(compositesOf) : undefined,
|
|
643
|
+
Object.hasOwn(node, 'const') ? compositesOf(node.const) : undefined,
|
|
644
|
+
target === undefined || seen.has(target)
|
|
645
|
+
? undefined
|
|
646
|
+
: composites(target, defs, new Set([...seen, target])),
|
|
647
|
+
...each(node.allOf),
|
|
648
|
+
...[node.anyOf, node.oneOf].filter(Array.isArray).map((branches) => each(branches).flat()),
|
|
649
|
+
Object.hasOwn(node, 'if') ? conditioned() : undefined,
|
|
650
|
+
Object.hasOwn(node, 'not')
|
|
651
|
+
? COMPOSITES.filter((kind) => !admittedWhole(node.not).includes(kind))
|
|
652
|
+
: undefined,
|
|
653
|
+
];
|
|
654
|
+
return COMPOSITES.filter((kind) => bounds.every((bound) => bound?.includes(kind) ?? true));
|
|
655
|
+
}
|
|
656
|
+
function transitionOf(value) {
|
|
657
|
+
if (!isRecord(value) || !Object.hasOwn(value, 'from') || !Object.hasOwn(value, 'to'))
|
|
658
|
+
return undefined;
|
|
659
|
+
const { from, to, roles, ...rest } = value;
|
|
660
|
+
if (Object.keys(rest).length > 0 || !ruleValue(from) || !ruleValue(to))
|
|
661
|
+
return undefined;
|
|
662
|
+
if (roles === undefined)
|
|
663
|
+
return { from, to };
|
|
664
|
+
return roleNames(roles) ? { from, to, roles } : undefined;
|
|
665
|
+
}
|
|
666
|
+
function fieldRules(written, field, at, defs) {
|
|
667
|
+
const { change_roles: changeRoles, initial_roles: initialRoles, transitions } = written;
|
|
668
|
+
if (changeRoles !== undefined && !roleNames(changeRoles))
|
|
669
|
+
return refuse('change_roles', `${at}/change_roles`);
|
|
670
|
+
if (initialRoles !== undefined && !roleNames(initialRoles))
|
|
671
|
+
return refuse('initial_roles', `${at}/initial_roles`);
|
|
672
|
+
if (transitions === undefined)
|
|
673
|
+
return {
|
|
674
|
+
...(changeRoles === undefined ? {} : { changeRoles }),
|
|
675
|
+
...(initialRoles === undefined ? {} : { initialRoles }),
|
|
676
|
+
};
|
|
677
|
+
if (!Array.isArray(transitions) || composites(field, defs, new Set()).length > 0)
|
|
678
|
+
return refuse('transitions', `${at}/transitions`);
|
|
679
|
+
const listed = [];
|
|
680
|
+
for (const [index, held] of transitions.entries()) {
|
|
681
|
+
const transition = transitionOf(held);
|
|
682
|
+
if (transition === undefined)
|
|
683
|
+
return refuse('transitions', `${at}/transitions/${index}`);
|
|
684
|
+
listed.push(transition);
|
|
685
|
+
}
|
|
686
|
+
return {
|
|
687
|
+
...(changeRoles === undefined ? {} : { changeRoles }),
|
|
688
|
+
...(initialRoles === undefined ? {} : { initialRoles }),
|
|
689
|
+
transitions: listed,
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
function unruled(schema) {
|
|
693
|
+
const written = new Map();
|
|
694
|
+
if (!isRecord(schema.properties))
|
|
695
|
+
return { schema, written };
|
|
696
|
+
const properties = Object.create(null);
|
|
697
|
+
for (const [field, node] of Object.entries(schema.properties)) {
|
|
698
|
+
if (!isRecord(node) || !FIELD_RULES.some((keyword) => Object.hasOwn(node, keyword))) {
|
|
699
|
+
properties[field] = node;
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
written.set(field, node);
|
|
703
|
+
properties[field] = Object.fromEntries(Object.entries(node).filter(([keyword]) => !FIELD_RULES.includes(keyword)));
|
|
704
|
+
}
|
|
705
|
+
return { schema: written.size === 0 ? schema : { ...schema, properties }, written };
|
|
706
|
+
}
|
|
707
|
+
function providedType(name, value, provided, checked) {
|
|
708
|
+
const at = `/${escapePointer(name)}`;
|
|
709
|
+
if (checked && provided.nameable?.includes(name) !== true)
|
|
710
|
+
return refuse('provided-type', at);
|
|
711
|
+
if (!isRecord(value))
|
|
712
|
+
return refuse('schema', at);
|
|
713
|
+
const declared = Object.keys(value).find((key) => !PROVIDED_KEYWORDS.includes(key));
|
|
714
|
+
if (checked && declared !== undefined)
|
|
715
|
+
return refuse('provided-type', `${at}/${escapePointer(declared)}`);
|
|
716
|
+
const { create_roles: createRoles, delete_roles: deleteRoles } = value;
|
|
717
|
+
if (createRoles !== undefined && !roleNames(createRoles))
|
|
718
|
+
return refuse('create_roles', `${at}/create_roles`);
|
|
719
|
+
if (deleteRoles !== undefined && !roleNames(deleteRoles))
|
|
720
|
+
return refuse('delete_roles', `${at}/delete_roles`);
|
|
721
|
+
return {
|
|
722
|
+
...provided.types[name],
|
|
723
|
+
...(createRoles === undefined ? {} : { createRoles }),
|
|
724
|
+
...(deleteRoles === undefined ? {} : { deleteRoles }),
|
|
725
|
+
};
|
|
726
|
+
}
|
|
541
727
|
function readType(name, value, context) {
|
|
542
728
|
const at = `/${escapePointer(name)}`;
|
|
543
729
|
if (!isRecord(value))
|
|
544
730
|
return refuse('schema', at);
|
|
545
|
-
const { sections: declared, member_document: mark, ...
|
|
731
|
+
const { sections: declared, member_document: mark, create_roles: createRoles, delete_roles: deleteRoles, ...ruled } = value;
|
|
546
732
|
if (mark !== undefined && typeof mark !== 'boolean')
|
|
547
733
|
return refuse('member_document', `${at}/member_document`);
|
|
734
|
+
if (createRoles !== undefined && !roleNames(createRoles))
|
|
735
|
+
return refuse('create_roles', `${at}/create_roles`);
|
|
736
|
+
if (deleteRoles !== undefined && !roleNames(deleteRoles))
|
|
737
|
+
return refuse('delete_roles', `${at}/delete_roles`);
|
|
548
738
|
const read = declared === undefined
|
|
549
739
|
? { sections: Object.create(null) }
|
|
550
740
|
: readSections(declared, `${at}/sections`, context);
|
|
551
741
|
if ('failure' in read)
|
|
552
742
|
return read.failure;
|
|
743
|
+
const unbranched = withoutBranchSections(ruled, declared, at);
|
|
744
|
+
if ('failure' in unbranched)
|
|
745
|
+
return unbranched.failure;
|
|
746
|
+
const { schema, written } = unruled(unbranched.schema);
|
|
553
747
|
const failure = schemaFailure(schema, at, context);
|
|
554
748
|
if (failure !== undefined)
|
|
555
749
|
return failure;
|
|
750
|
+
const rules = Object.create(null);
|
|
751
|
+
for (const [field, keywords] of written) {
|
|
752
|
+
const properties = schema.properties;
|
|
753
|
+
const where = `${at}/properties/${escapePointer(field)}`;
|
|
754
|
+
const ruling = fieldRules(keywords, properties[field], where, context.defs);
|
|
755
|
+
if ('rule' in ruling)
|
|
756
|
+
return ruling;
|
|
757
|
+
rules[field] = ruling;
|
|
758
|
+
}
|
|
556
759
|
const memberDocument = mark === true;
|
|
557
760
|
const root = valueFacts(schema, context.defs);
|
|
558
761
|
const fields = Object.assign(Object.create(null), root.properties);
|
|
@@ -560,19 +763,26 @@ function readType(name, value, context) {
|
|
|
560
763
|
fields[MEMBER_FIELD] = { type: 'string', prose: false };
|
|
561
764
|
const defs = Object.create(null);
|
|
562
765
|
reachedDefs(value, context.defs, defs);
|
|
766
|
+
const { create_roles: _create, delete_roles: _delete, ...shaped } = value;
|
|
563
767
|
return {
|
|
564
768
|
name,
|
|
565
769
|
memberDocument,
|
|
566
770
|
frontmatter: { ...root, properties: { ...HOUSE_KEYS, ...fields } },
|
|
567
771
|
fields,
|
|
568
772
|
sections: read.sections,
|
|
569
|
-
|
|
773
|
+
rules,
|
|
774
|
+
...(createRoles === undefined ? {} : { createRoles }),
|
|
775
|
+
...(deleteRoles === undefined ? {} : { deleteRoles }),
|
|
776
|
+
shape: {
|
|
777
|
+
schema: written.size === 0 ? shaped : { ...shaped, properties: schema.properties },
|
|
778
|
+
defs,
|
|
779
|
+
},
|
|
570
780
|
};
|
|
571
781
|
}
|
|
572
782
|
function lineAt(text, offset) {
|
|
573
783
|
return text.slice(0, offset).split(/\r\n|\r|\n/).length;
|
|
574
784
|
}
|
|
575
|
-
export function readSchema(text) {
|
|
785
|
+
export function readSchema(text, provided = NO_TYPES, checked = true) {
|
|
576
786
|
let root;
|
|
577
787
|
try {
|
|
578
788
|
root = jsValue(parseYamlMapping(text, 0, text.length));
|
|
@@ -586,11 +796,15 @@ export function readSchema(text) {
|
|
|
586
796
|
if (!isRecord(defs))
|
|
587
797
|
return refuse('$defs', '/$defs');
|
|
588
798
|
const names = Object.keys(root).filter((key) => key !== '$defs');
|
|
589
|
-
for (const name of names) {
|
|
799
|
+
for (const name of checked ? names : []) {
|
|
590
800
|
if (name === '' || name.startsWith('$') || name === BUILT_IN_TYPE || name === ATTACHMENT)
|
|
591
801
|
return refuse('schema-type-name', `/${escapePointer(name)}`);
|
|
592
802
|
}
|
|
593
|
-
const context = {
|
|
803
|
+
const context = {
|
|
804
|
+
defs,
|
|
805
|
+
types: new Set([...names, ...Object.keys(provided.types)]),
|
|
806
|
+
checked,
|
|
807
|
+
};
|
|
594
808
|
for (const [name, def] of Object.entries(defs)) {
|
|
595
809
|
const failure = schemaFailure(def, `/$defs/${escapePointer(name)}`, context);
|
|
596
810
|
if (failure !== undefined)
|
|
@@ -599,15 +813,21 @@ export function readSchema(text) {
|
|
|
599
813
|
const types = Object.create(null);
|
|
600
814
|
let marked = false;
|
|
601
815
|
for (const name of names) {
|
|
602
|
-
const definition =
|
|
816
|
+
const definition = Object.hasOwn(provided.types, name)
|
|
817
|
+
? providedType(name, root[name], provided, checked)
|
|
818
|
+
: readType(name, root[name], context);
|
|
603
819
|
if ('rule' in definition)
|
|
604
820
|
return definition;
|
|
605
|
-
if (definition.memberDocument) {
|
|
821
|
+
if (checked && definition.memberDocument) {
|
|
606
822
|
if (marked)
|
|
607
823
|
return refuse('member_document', `/${escapePointer(name)}/member_document`);
|
|
608
824
|
marked = true;
|
|
609
825
|
}
|
|
610
826
|
types[name] = deepFreeze(definition);
|
|
611
827
|
}
|
|
828
|
+
for (const [name, definition] of Object.entries(provided.types)) {
|
|
829
|
+
if (!Object.hasOwn(types, name))
|
|
830
|
+
types[name] = definition;
|
|
831
|
+
}
|
|
612
832
|
return Object.freeze({ types: Object.freeze(types) });
|
|
613
833
|
}
|
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"}
|