@agentshouse/mdmodel 0.1.0-c0d316445d94f → 0.1.0-c2224db91aaa3
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 +129 -68
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +31 -17
- package/dist/condition.d.ts +1 -0
- package/dist/condition.d.ts.map +1 -1
- package/dist/condition.js +11 -6
- package/dist/definition.js +2 -2
- package/dist/document.d.ts +3 -1
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +53 -25
- 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 +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/links.d.ts +1 -0
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +1 -1
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +92 -12
- package/dist/schema.js +2 -2
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +19 -25
- 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/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
export { dated, factKind, facts, fires, holds, instant, itemFires, pointed, prosePaths, WRITE_DOORS, } from './condition.js';
|
|
1
|
+
export { dated, datePointers, factKind, facts, fires, holds, instant, itemFires, pointed, prosePaths, WRITE_DOORS, } from './condition.js';
|
|
2
2
|
export type { Actor, Condition, ConditionScope, ConditionTest, ConditionValue, CronCondition, DateCondition, DocumentCondition, DocumentEvent, DocumentFacts, Fact, FactKind, ItemCondition, ItemFacts, Resolved, WriteDoor, } from './condition.js';
|
|
3
3
|
export { divide } from './divide.js';
|
|
4
|
-
export { apply, bodyLinks, links, parse, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
|
|
5
|
-
export { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD } from './fields.js';
|
|
4
|
+
export { apply, bodyLinks, fieldStart, linkOccurrences, links, parse, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
|
|
5
|
+
export { HOUSE_FIELDS, MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
|
|
6
6
|
export { relative, retarget, target } from './paths.js';
|
|
7
7
|
export { MARKDOWN_SYNTAX_PROFILE } from './profile.js';
|
|
8
8
|
export { project } from './project.js';
|
|
9
9
|
export { references } from './references.js';
|
|
10
10
|
export { ARRAY_INDEX, ATTACHMENT, crossedFacts, escapePointer, itemFacts, memberFacts, pointerFacts, pointerSegments, } from './definition.js';
|
|
11
11
|
export type { Definition, JsonType, PatternFacts, PointerFacts, SectionSpec, Shape, ValueFacts, } from './definition.js';
|
|
12
|
-
export type { ApplyResult, BodyResult, Change, Division, DivisionContext, Document, Library, ModelVerification, Link, ParseResult, Projection, ProjectionContext, Reference, Refusal, Span, Validation, ValidationContext, VerifiedModel, } from './types.js';
|
|
12
|
+
export type { ApplyResult, BodyResult, Change, Division, DivisionContext, Document, Library, ModelVerification, Link, LinkOccurrence, ParseResult, Projection, ProjectionContext, Reference, Refusal, Span, Validation, ValidationContext, VerifiedModel, } from './types.js';
|
|
13
13
|
export { validate, verify } from './validate.js';
|
|
14
14
|
export { VERSION } from './version.js';
|
|
15
|
+
export { equalValue, frontmatterValue } from './yaml.js';
|
|
16
|
+
export type { FrontmatterValue } from './yaml.js';
|
|
15
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,QAAQ,EACR,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,SAAS,EACT,OAAO,EACP,UAAU,EACV,WAAW,GACZ,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,KAAK,EACL,SAAS,EACT,cAAc,EACd,aAAa,EACb,cAAc,EACd,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,SAAS,EACT,QAAQ,EACR,SAAS,GACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,KAAK,EACL,SAAS,EACT,KAAK,EACL,KAAK,EACL,UAAU,EACV,cAAc,EACd,UAAU,EACV,SAAS,GACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,YAAY,EACZ,QAAQ,EACR,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,SAAS,EACT,OAAO,EACP,UAAU,EACV,WAAW,GACZ,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,KAAK,EACL,SAAS,EACT,cAAc,EACd,aAAa,EACb,cAAc,EACd,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,SAAS,EACT,QAAQ,EACR,SAAS,GACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,KAAK,EACL,SAAS,EACT,UAAU,EACV,eAAe,EACf,KAAK,EACL,KAAK,EACL,UAAU,EACV,cAAc,EACd,UAAU,EACV,SAAS,GACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACjG,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,WAAW,EACX,UAAU,EACV,YAAY,EACZ,aAAa,EACb,SAAS,EACT,WAAW,EACX,YAAY,EACZ,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,KAAK,EACL,UAAU,GACX,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,OAAO,EACP,iBAAiB,EACjB,IAAI,EACJ,cAAc,EACd,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,OAAO,EACP,IAAI,EACJ,UAAU,EACV,iBAAiB,EACjB,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AACzD,YAAY,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { dated, factKind, facts, fires, holds, instant, itemFires, pointed, prosePaths, WRITE_DOORS, } from './condition.js';
|
|
1
|
+
export { dated, datePointers, factKind, facts, fires, holds, instant, itemFires, pointed, prosePaths, WRITE_DOORS, } from './condition.js';
|
|
2
2
|
export { divide } from './divide.js';
|
|
3
|
-
export { apply, bodyLinks, links, parse, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
|
|
4
|
-
export { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD } from './fields.js';
|
|
3
|
+
export { apply, bodyLinks, fieldStart, linkOccurrences, links, parse, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
|
|
4
|
+
export { HOUSE_FIELDS, MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
|
|
5
5
|
export { relative, retarget, target } from './paths.js';
|
|
6
6
|
export { MARKDOWN_SYNTAX_PROFILE } from './profile.js';
|
|
7
7
|
export { project } from './project.js';
|
|
@@ -9,3 +9,4 @@ export { references } from './references.js';
|
|
|
9
9
|
export { ARRAY_INDEX, ATTACHMENT, crossedFacts, escapePointer, itemFacts, memberFacts, pointerFacts, pointerSegments, } from './definition.js';
|
|
10
10
|
export { validate, verify } from './validate.js';
|
|
11
11
|
export { VERSION } from './version.js';
|
|
12
|
+
export { equalValue, frontmatterValue } from './yaml.js';
|
package/dist/links.d.ts
CHANGED
package/dist/links.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAsgBA,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAE5D;AAkMD,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;CAC7C,CAAC;AAEF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAe/E;AAYD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CA2DzD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,cAAc,EAAE,CAIvE"}
|
package/dist/links.js
CHANGED
|
@@ -504,7 +504,7 @@ function structure(text) {
|
|
|
504
504
|
}
|
|
505
505
|
return { joins, raw };
|
|
506
506
|
}
|
|
507
|
-
function escapes(text, index) {
|
|
507
|
+
export function escapes(text, index) {
|
|
508
508
|
return text[index] === '\\' && PUNCTUATION.test(text[index + 1] ?? '');
|
|
509
509
|
}
|
|
510
510
|
function referenceEnd(text, start, joins) {
|
package/dist/paths.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare function dirname(path: string): string;
|
|
2
2
|
export declare function join(base: string, relative: string): string;
|
|
3
3
|
export declare function normalize(path: string): string | null;
|
|
4
|
+
export declare function destinationPath(href: string): string | null;
|
|
4
5
|
export declare function classifyHref(from: string, href: string): {
|
|
5
6
|
kind: 'skip';
|
|
6
7
|
} | {
|
package/dist/paths.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAIA,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG5C;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG3D;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYrD;AAoDD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAW3D;AAgBD,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CASzE;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGhE;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAGzD;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAW7D;AAED,eAAO,MAAM,WAAW,YAAY,CAAC;AAErC,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMvE"}
|
package/dist/paths.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { decodeNamedCharacterReference } from 'decode-named-character-reference';
|
|
2
|
+
import { decodeNumericCharacterReference } from 'micromark-util-decode-numeric-character-reference';
|
|
3
|
+
import { escapes } from './links.js';
|
|
1
4
|
export function dirname(path) {
|
|
2
5
|
const index = path.lastIndexOf('/');
|
|
3
6
|
return index === -1 ? '' : path.slice(0, index);
|
|
@@ -22,18 +25,95 @@ export function normalize(path) {
|
|
|
22
25
|
}
|
|
23
26
|
return parts.join('/');
|
|
24
27
|
}
|
|
28
|
+
const REFERENCE = /&(?:#[xX]([0-9a-fA-F]{1,6})|#([0-9]{1,7})|([A-Za-z][A-Za-z0-9]{0,31}));/y;
|
|
29
|
+
const PERCENT = /^%[0-9a-fA-F]{2}/;
|
|
30
|
+
function referenceAt(text, at) {
|
|
31
|
+
REFERENCE.lastIndex = at;
|
|
32
|
+
const match = REFERENCE.exec(text);
|
|
33
|
+
if (match === null)
|
|
34
|
+
return null;
|
|
35
|
+
const [whole, hex, decimal, name] = match;
|
|
36
|
+
const end = at + whole.length;
|
|
37
|
+
if (name !== undefined) {
|
|
38
|
+
const decoded = decodeNamedCharacterReference(name);
|
|
39
|
+
return decoded === false ? null : { text: decoded, end };
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
text: decodeNumericCharacterReference(hex ?? decimal, hex === undefined ? 10 : 16),
|
|
43
|
+
end,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function unescaped(written) {
|
|
47
|
+
let base = '';
|
|
48
|
+
let i = 0;
|
|
49
|
+
while (i < written.length) {
|
|
50
|
+
const escaped = escapes(written, i);
|
|
51
|
+
const reference = escaped || written[i] !== '&' ? null : referenceAt(written, i);
|
|
52
|
+
const text = escaped ? written[i + 1] : (reference?.text ?? written[i]);
|
|
53
|
+
if (text.startsWith('?') || text.startsWith('#'))
|
|
54
|
+
return { base, suffix: i };
|
|
55
|
+
base += text;
|
|
56
|
+
i = escaped ? i + 2 : (reference?.end ?? i + 1);
|
|
57
|
+
}
|
|
58
|
+
return { base, suffix: written.length };
|
|
59
|
+
}
|
|
60
|
+
function located(href) {
|
|
61
|
+
const written = href.trim();
|
|
62
|
+
const { base, suffix } = unescaped(written);
|
|
63
|
+
const url = base.replace(/[\t\n\r]/g, '').replace(/^[\u0000-\u0020]+/, '');
|
|
64
|
+
return { base: suffix === written.length ? url.replace(/[\u0000-\u0020]+$/, '') : url, suffix };
|
|
65
|
+
}
|
|
66
|
+
const ENCODED = /(?:%[0-9a-fA-F]{2})+/g;
|
|
67
|
+
function decodedRun(run) {
|
|
68
|
+
try {
|
|
69
|
+
return decodeURIComponent(run);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export function destinationPath(href) {
|
|
76
|
+
const base = located(href).base;
|
|
77
|
+
let path = '';
|
|
78
|
+
let cursor = 0;
|
|
79
|
+
for (const match of base.matchAll(ENCODED)) {
|
|
80
|
+
const decoded = decodedRun(match[0]);
|
|
81
|
+
if (decoded === null)
|
|
82
|
+
return null;
|
|
83
|
+
path += base.slice(cursor, match.index) + decoded;
|
|
84
|
+
cursor = match.index + match[0].length;
|
|
85
|
+
}
|
|
86
|
+
return path + base.slice(cursor);
|
|
87
|
+
}
|
|
88
|
+
function written(path) {
|
|
89
|
+
let text = '';
|
|
90
|
+
for (let i = 0; i < path.length; i += 1) {
|
|
91
|
+
const char = path[i];
|
|
92
|
+
if (char === '?' || char === '#' || char < ' ')
|
|
93
|
+
text += encodeURIComponent(char);
|
|
94
|
+
else if (char === ' ' && (i === 0 || i === path.length - 1))
|
|
95
|
+
text += '%20';
|
|
96
|
+
else if (char === '%' && PERCENT.test(path.slice(i)))
|
|
97
|
+
text += '%25';
|
|
98
|
+
else if (escapes(path, i))
|
|
99
|
+
text += '%5C';
|
|
100
|
+
else if (char === '&' && referenceAt(path, i) !== null)
|
|
101
|
+
text += '%26';
|
|
102
|
+
else
|
|
103
|
+
text += char;
|
|
104
|
+
}
|
|
105
|
+
return text;
|
|
106
|
+
}
|
|
25
107
|
export function classifyHref(from, href) {
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
108
|
+
const base = located(href).base;
|
|
109
|
+
if (base === '')
|
|
28
110
|
return { kind: 'skip' };
|
|
29
|
-
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(
|
|
111
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(base))
|
|
30
112
|
return { kind: 'skip' };
|
|
31
|
-
|
|
113
|
+
const path = destinationPath(href);
|
|
114
|
+
if (path === null || path.startsWith('/'))
|
|
32
115
|
return { kind: 'invalid' };
|
|
33
|
-
const
|
|
34
|
-
if (bare === '')
|
|
35
|
-
return { kind: 'skip' };
|
|
36
|
-
const resolved = normalize(join(dirname(from), bare));
|
|
116
|
+
const resolved = normalize(join(dirname(from), path));
|
|
37
117
|
if (resolved === null || resolved === '')
|
|
38
118
|
return { kind: 'invalid' };
|
|
39
119
|
return { kind: 'path', path: resolved };
|
|
@@ -44,8 +124,7 @@ export function target(from, href) {
|
|
|
44
124
|
}
|
|
45
125
|
export function retarget(href, to) {
|
|
46
126
|
const trimmed = href.trim();
|
|
47
|
-
|
|
48
|
-
return match === null ? to : to + trimmed.slice(match.index);
|
|
127
|
+
return written(to) + trimmed.slice(unescaped(trimmed).suffix);
|
|
49
128
|
}
|
|
50
129
|
export function relative(from, target) {
|
|
51
130
|
const base = dirname(from)
|
|
@@ -62,8 +141,9 @@ export function relative(from, target) {
|
|
|
62
141
|
export const SHELL_ROOMS = '/rooms/';
|
|
63
142
|
export function shellTarget(href, handle) {
|
|
64
143
|
const prefix = `${SHELL_ROOMS}${handle}/`;
|
|
65
|
-
|
|
144
|
+
const decoded = destinationPath(href);
|
|
145
|
+
if (decoded === null || !decoded.startsWith(prefix))
|
|
66
146
|
return null;
|
|
67
|
-
const path = normalize(
|
|
147
|
+
const path = normalize(decoded.slice(prefix.length));
|
|
68
148
|
return path === null || path === '' ? null : path;
|
|
69
149
|
}
|
package/dist/schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Validator } from '@cfworker/json-schema';
|
|
2
2
|
import { escapePointer, refTarget } from './definition.js';
|
|
3
|
-
import { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD } from './fields.js';
|
|
3
|
+
import { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
|
|
4
4
|
import { interpretPlain, isRecord } from './yaml.js';
|
|
5
5
|
const STANDING_MAPS = ['properties', 'patternProperties'];
|
|
6
6
|
const STANDING = [
|
|
@@ -101,7 +101,7 @@ function compile(definition) {
|
|
|
101
101
|
const closedDefs = mapped(defs, (held) => closed(held, true, defs));
|
|
102
102
|
const declared = isRecord(root.properties) ? root.properties : {};
|
|
103
103
|
const properties = {
|
|
104
|
-
|
|
104
|
+
[TYPE_FIELD]: true,
|
|
105
105
|
[SITE_FIELD]: true,
|
|
106
106
|
[RECEIVED_FIELD]: true,
|
|
107
107
|
...(definition.memberDocument ? { [MEMBER_FIELD]: { type: 'string' } } : {}),
|
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEvD,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;CACtD,CAAC;AAEF,MAAM,MAAM,iBAAiB,GACzB;IAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAA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d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAGV,OAAO,EACP,iBAAiB,
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAGV,OAAO,EACP,iBAAiB,EACjB,UAAU,EACV,iBAAiB,EACjB,aAAa,EACd,MAAM,YAAY,CAAC;AAwDpB,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAQxD;AAED,wBAAgB,QAAQ,CACtB,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,iBAAyC,EAClD,KAAK,GAAE,aAA6B,GACnC,UAAU,CAqGZ"}
|
package/dist/validate.js
CHANGED
|
@@ -18,7 +18,7 @@ function instanceType(document) {
|
|
|
18
18
|
return null;
|
|
19
19
|
return raw;
|
|
20
20
|
}
|
|
21
|
-
function reaches(file, href, to,
|
|
21
|
+
function reaches(file, href, to, types, binaryTargets) {
|
|
22
22
|
const resolved = classifyHref(file, href);
|
|
23
23
|
if (resolved.kind !== 'path')
|
|
24
24
|
return false;
|
|
@@ -26,8 +26,8 @@ function reaches(file, href, to, documents, binaryTargets) {
|
|
|
26
26
|
return true;
|
|
27
27
|
if (binaryTargets.has(resolved.path))
|
|
28
28
|
return false;
|
|
29
|
-
const held =
|
|
30
|
-
return held === undefined ||
|
|
29
|
+
const held = types.get(resolved.path);
|
|
30
|
+
return held === undefined || to.includes(held);
|
|
31
31
|
}
|
|
32
32
|
function itemHrefs(content, items) {
|
|
33
33
|
const bodyStart = bodyStartOf(content);
|
|
@@ -56,28 +56,28 @@ export function verify(schema) {
|
|
|
56
56
|
export function validate(library, context = { binaryTargets: [] }, model = { types: {} }) {
|
|
57
57
|
const binaryTargets = new Set(context.binaryTargets);
|
|
58
58
|
const files = Object.keys(library).sort();
|
|
59
|
+
const types = new Map();
|
|
59
60
|
const documents = new Map();
|
|
60
61
|
for (const file of files) {
|
|
61
62
|
if (binaryTargets.has(file))
|
|
62
63
|
return refuse(file, 'binary-target-document');
|
|
63
64
|
const parsed = parse(library[file], file);
|
|
64
|
-
documents.set(file, parsed);
|
|
65
65
|
if (!parsed.ok)
|
|
66
66
|
return { verdict: 'refuse', ...parsed.refusal };
|
|
67
|
+
types.set(file, parsed.document.type ?? BUILT_IN_TYPE);
|
|
68
|
+
if (instanceType(parsed.document) !== BUILT_IN_TYPE)
|
|
69
|
+
documents.set(file, parsed.document);
|
|
67
70
|
}
|
|
68
71
|
const definitions = new Map(Object.entries(model.types));
|
|
69
72
|
const sectionReferences = new Map();
|
|
70
|
-
for (const file of
|
|
71
|
-
const
|
|
72
|
-
if (parsed === undefined || !parsed.ok)
|
|
73
|
-
continue;
|
|
74
|
-
const kind = instanceType(parsed.document);
|
|
73
|
+
for (const [file, document] of documents) {
|
|
74
|
+
const kind = instanceType(document);
|
|
75
75
|
if (kind === BUILT_IN_TYPE)
|
|
76
76
|
continue;
|
|
77
77
|
const definition = kind === null ? undefined : definitions.get(kind);
|
|
78
78
|
if (definition === undefined)
|
|
79
79
|
return refuse(file, 'unknown-type', { location: '/type' });
|
|
80
|
-
const fieldFailure = frontmatterRefusal(definition,
|
|
80
|
+
const fieldFailure = frontmatterRefusal(definition, document.fields);
|
|
81
81
|
if (fieldFailure !== undefined) {
|
|
82
82
|
return refuse(file, fieldFailure.rule, { location: fieldFailure.location });
|
|
83
83
|
}
|
|
@@ -105,18 +105,15 @@ export function validate(library, context = { binaryTargets: [] }, model = { typ
|
|
|
105
105
|
}
|
|
106
106
|
sectionReferences.set(file, references);
|
|
107
107
|
}
|
|
108
|
-
for (const file of
|
|
109
|
-
const
|
|
110
|
-
if (parsed === undefined || !parsed.ok)
|
|
111
|
-
continue;
|
|
112
|
-
const kind = instanceType(parsed.document);
|
|
108
|
+
for (const [file, document] of documents) {
|
|
109
|
+
const kind = instanceType(document);
|
|
113
110
|
if (kind === null || kind === BUILT_IN_TYPE)
|
|
114
111
|
continue;
|
|
115
112
|
const definition = definitions.get(kind);
|
|
116
113
|
if (definition === undefined)
|
|
117
114
|
continue;
|
|
118
|
-
for (const { pointer, to, value } of references(
|
|
119
|
-
if (!reaches(file, value, to,
|
|
115
|
+
for (const { pointer, to, value } of references(document, definition)) {
|
|
116
|
+
if (!reaches(file, value, to, types, binaryTargets))
|
|
120
117
|
return refuse(file, 'unresolved-reference', { location: pointer });
|
|
121
118
|
}
|
|
122
119
|
const body = bodyAfterFrontmatter(library[file]);
|
|
@@ -127,24 +124,21 @@ export function validate(library, context = { binaryTargets: [] }, model = { typ
|
|
|
127
124
|
}
|
|
128
125
|
for (const { section, to, hrefs } of sectionReferences.get(file)) {
|
|
129
126
|
for (const href of hrefs) {
|
|
130
|
-
if (!reaches(file, href, to,
|
|
127
|
+
if (!reaches(file, href, to, types, binaryTargets))
|
|
131
128
|
return refuse(file, 'unresolved-reference', { location: section });
|
|
132
129
|
}
|
|
133
130
|
}
|
|
134
131
|
}
|
|
135
132
|
const missing = new Map();
|
|
136
|
-
for (const file of
|
|
137
|
-
const
|
|
138
|
-
if (parsed === undefined || !parsed.ok)
|
|
139
|
-
continue;
|
|
140
|
-
const kind = instanceType(parsed.document);
|
|
133
|
+
for (const [file, document] of documents) {
|
|
134
|
+
const kind = instanceType(document);
|
|
141
135
|
if (kind === null || kind === BUILT_IN_TYPE)
|
|
142
136
|
continue;
|
|
143
137
|
const definition = definitions.get(kind);
|
|
144
138
|
if (definition === undefined)
|
|
145
139
|
continue;
|
|
146
140
|
const named = [
|
|
147
|
-
...references(
|
|
141
|
+
...references(document, definition),
|
|
148
142
|
...sectionReferences
|
|
149
143
|
.get(file)
|
|
150
144
|
.flatMap(({ to, hrefs }) => hrefs.map((value) => ({ value, to }))),
|
|
@@ -155,7 +149,7 @@ export function validate(library, context = { binaryTargets: [] }, model = { typ
|
|
|
155
149
|
const resolved = classifyHref(file, value);
|
|
156
150
|
if (resolved.kind !== 'path')
|
|
157
151
|
continue;
|
|
158
|
-
if (
|
|
152
|
+
if (types.has(resolved.path) || binaryTargets.has(resolved.path))
|
|
159
153
|
continue;
|
|
160
154
|
const referrers = missing.get(resolved.path) ?? [];
|
|
161
155
|
referrers.push(file);
|
package/dist/yaml.d.ts
CHANGED
|
@@ -16,8 +16,7 @@ export type YamlSeq = {
|
|
|
16
16
|
};
|
|
17
17
|
export type YamlEntry = {
|
|
18
18
|
readonly key: string;
|
|
19
|
-
readonly
|
|
20
|
-
readonly keyEnd: number;
|
|
19
|
+
readonly after: number;
|
|
21
20
|
readonly value: YamlNode;
|
|
22
21
|
};
|
|
23
22
|
export type YamlMap = {
|
|
@@ -32,7 +31,12 @@ export declare function parseYamlMapping(text: string, start: number, end: numbe
|
|
|
32
31
|
export declare function jsValue(node: YamlNode): unknown;
|
|
33
32
|
export declare function mapEntry(map: YamlMap, key: string): YamlEntry | undefined;
|
|
34
33
|
export declare function isPlainSafe(text: string): boolean;
|
|
35
|
-
export
|
|
34
|
+
export type FrontmatterValue = string | number | boolean | null | readonly FrontmatterValue[] | {
|
|
35
|
+
readonly [name: string]: FrontmatterValue;
|
|
36
|
+
};
|
|
37
|
+
export declare function plain(value: unknown): value is Record<string, unknown>;
|
|
38
|
+
export declare function frontmatterValue(value: unknown): value is FrontmatterValue;
|
|
39
|
+
export declare function serializeJs(value: FrontmatterValue): string;
|
|
36
40
|
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
37
41
|
export declare function serializeKey(name: string): string;
|
|
38
42
|
export declare function bodyStartAfterYaml(content: string, yamlEnd: number): number;
|
package/dist/yaml.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../src/yaml.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAU,SAAQ,KAAK;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM;IAAnC,YAAqB,MAAM,EAAE,MAAM,EAGlC;CACF;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ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AAgB,CAE1E;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAO3D;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAG3E;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGnD;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,GACd;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAqB9F;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAgBjE;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAEzD"}
|
package/dist/yaml.js
CHANGED
|
@@ -84,6 +84,30 @@ export function interpretPlain(text) {
|
|
|
84
84
|
return Number(text);
|
|
85
85
|
return text;
|
|
86
86
|
}
|
|
87
|
+
const ESCAPES = {
|
|
88
|
+
b: '\b',
|
|
89
|
+
f: '\f',
|
|
90
|
+
n: '\n',
|
|
91
|
+
r: '\r',
|
|
92
|
+
t: '\t',
|
|
93
|
+
'"': '"',
|
|
94
|
+
'/': '/',
|
|
95
|
+
'\\': '\\',
|
|
96
|
+
};
|
|
97
|
+
function parseEscape(c) {
|
|
98
|
+
c.i += 1;
|
|
99
|
+
const escaped = peek(c);
|
|
100
|
+
const held = ESCAPES[escaped];
|
|
101
|
+
if (held !== undefined) {
|
|
102
|
+
c.i += 1;
|
|
103
|
+
return held;
|
|
104
|
+
}
|
|
105
|
+
const hex = c.text.slice(c.i + 1, c.i + 5);
|
|
106
|
+
if (escaped !== 'u' || c.i + 5 > c.end || !/^[0-9A-Fa-f]{4}$/.test(hex))
|
|
107
|
+
throw new YamlError(c.i);
|
|
108
|
+
c.i += 5;
|
|
109
|
+
return String.fromCharCode(Number.parseInt(hex, 16));
|
|
110
|
+
}
|
|
87
111
|
function parseQuoted(c) {
|
|
88
112
|
const quote = peek(c);
|
|
89
113
|
const start = c.i;
|
|
@@ -91,31 +115,19 @@ function parseQuoted(c) {
|
|
|
91
115
|
let out = '';
|
|
92
116
|
while (c.i < c.end) {
|
|
93
117
|
const ch = peek(c);
|
|
118
|
+
if (quote === "'" && ch === "'" && c.i + 1 < c.end && c.text[c.i + 1] === "'") {
|
|
119
|
+
out += "'";
|
|
120
|
+
c.i += 2;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
94
123
|
if (ch === quote) {
|
|
95
124
|
c.i += 1;
|
|
96
125
|
return scalar(out, start, c.i);
|
|
97
126
|
}
|
|
98
127
|
if (ch === '\n' || ch === '\r')
|
|
99
128
|
throw new YamlError(c.i);
|
|
100
|
-
if (quote === "'" && ch === "'" && c.text[c.i + 1] === "'") {
|
|
101
|
-
out += "'";
|
|
102
|
-
c.i += 2;
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
129
|
if (quote === '"' && ch === '\\') {
|
|
106
|
-
|
|
107
|
-
const escaped = peek(c);
|
|
108
|
-
if (escaped === 'n')
|
|
109
|
-
out += '\n';
|
|
110
|
-
else if (escaped === 't')
|
|
111
|
-
out += '\t';
|
|
112
|
-
else if (escaped === '"')
|
|
113
|
-
out += '"';
|
|
114
|
-
else if (escaped === '\\')
|
|
115
|
-
out += '\\';
|
|
116
|
-
else
|
|
117
|
-
throw new YamlError(c.i);
|
|
118
|
-
c.i += 1;
|
|
130
|
+
out += parseEscape(c);
|
|
119
131
|
continue;
|
|
120
132
|
}
|
|
121
133
|
out += ch;
|
|
@@ -208,11 +220,12 @@ function parseFlowMap(c) {
|
|
|
208
220
|
if (peek(c) !== ':')
|
|
209
221
|
throw new YamlError(c.i);
|
|
210
222
|
c.i += 1;
|
|
223
|
+
const after = c.i;
|
|
211
224
|
const value = parseFlowValue(c);
|
|
212
225
|
if (seen.has(key.name))
|
|
213
226
|
throw new YamlError(key.start);
|
|
214
227
|
seen.add(key.name);
|
|
215
|
-
entries.push({ key: key.name,
|
|
228
|
+
entries.push({ key: key.name, after, value });
|
|
216
229
|
skipFlowSpace(c);
|
|
217
230
|
if (peek(c) === ',') {
|
|
218
231
|
c.i += 1;
|
|
@@ -254,6 +267,7 @@ function parseFlowSeq(c) {
|
|
|
254
267
|
throw new YamlError(c.i);
|
|
255
268
|
}
|
|
256
269
|
function parseValue(c, parentKeyIndent) {
|
|
270
|
+
const at = c.i;
|
|
257
271
|
skipSpaces(c);
|
|
258
272
|
if (peek(c) === '#')
|
|
259
273
|
skipToEol(c);
|
|
@@ -262,12 +276,12 @@ function parseValue(c, parentKeyIndent) {
|
|
|
262
276
|
skipEol(c);
|
|
263
277
|
skipBlankAndComments(c);
|
|
264
278
|
if (c.i >= c.end)
|
|
265
|
-
return scalar(null,
|
|
279
|
+
return scalar(null, at, at);
|
|
266
280
|
const nextIndent = indentAt(c);
|
|
267
281
|
if (nextIndent === parentKeyIndent && seqAhead(c))
|
|
268
282
|
return parseBlockSeq(c, nextIndent);
|
|
269
283
|
if (nextIndent <= parentKeyIndent)
|
|
270
|
-
return scalar(null,
|
|
284
|
+
return scalar(null, at, at);
|
|
271
285
|
if (peek(c) === '-')
|
|
272
286
|
return parseBlockSeq(c, nextIndent);
|
|
273
287
|
if (peek(c) === '[')
|
|
@@ -315,9 +329,6 @@ function lineStartOf(c) {
|
|
|
315
329
|
j -= 1;
|
|
316
330
|
return j;
|
|
317
331
|
}
|
|
318
|
-
function valueEnd(value, marked) {
|
|
319
|
-
return value.kind === 'scalar' && value.start === value.end ? marked : value.end;
|
|
320
|
-
}
|
|
321
332
|
function parseSeqItem(c, indent) {
|
|
322
333
|
skipSpaces(c);
|
|
323
334
|
if (peek(c) !== '#' && peek(c) !== '\n' && peek(c) !== '\r' && c.i < c.end && mappingAhead(c))
|
|
@@ -337,10 +348,9 @@ function parseBlockSeq(c, indent) {
|
|
|
337
348
|
if (peek(c) !== '-')
|
|
338
349
|
break;
|
|
339
350
|
c.i += 1;
|
|
340
|
-
const marked = c.i;
|
|
341
351
|
const item = parseSeqItem(c, indent);
|
|
342
352
|
items.push(item);
|
|
343
|
-
end =
|
|
353
|
+
end = item.end;
|
|
344
354
|
}
|
|
345
355
|
return { kind: 'seq', items, start, end };
|
|
346
356
|
}
|
|
@@ -366,13 +376,13 @@ function parseBlockMap(c, indent, inline = false) {
|
|
|
366
376
|
if (peek(c) !== ':')
|
|
367
377
|
throw new YamlError(c.i);
|
|
368
378
|
c.i += 1;
|
|
369
|
-
const
|
|
379
|
+
const after = c.i;
|
|
370
380
|
const value = parseValue(c, indent);
|
|
371
381
|
if (seen.has(key.name))
|
|
372
382
|
throw new YamlError(key.start);
|
|
373
383
|
seen.add(key.name);
|
|
374
|
-
entries.push({ key: key.name,
|
|
375
|
-
end =
|
|
384
|
+
entries.push({ key: key.name, after, value });
|
|
385
|
+
end = value.end;
|
|
376
386
|
}
|
|
377
387
|
return { kind: 'map', entries, start, end };
|
|
378
388
|
}
|
|
@@ -418,24 +428,42 @@ export function isPlainSafe(text) {
|
|
|
418
428
|
return false;
|
|
419
429
|
return true;
|
|
420
430
|
}
|
|
431
|
+
export function plain(value) {
|
|
432
|
+
if (!isRecord(value))
|
|
433
|
+
return false;
|
|
434
|
+
const prototype = Object.getPrototypeOf(value);
|
|
435
|
+
return prototype === Object.prototype || prototype === null;
|
|
436
|
+
}
|
|
437
|
+
function listed(value) {
|
|
438
|
+
const keys = Object.keys(value);
|
|
439
|
+
return keys.length === value.length && keys.every((key, index) => key === String(index));
|
|
440
|
+
}
|
|
441
|
+
function heldWithin(value, within) {
|
|
442
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean')
|
|
443
|
+
return true;
|
|
444
|
+
if (typeof value === 'number')
|
|
445
|
+
return Number.isFinite(value);
|
|
446
|
+
if (typeof value !== 'object' || within.includes(value))
|
|
447
|
+
return false;
|
|
448
|
+
const path = [...within, value];
|
|
449
|
+
const held = (item) => heldWithin(item, path);
|
|
450
|
+
if (Array.isArray(value))
|
|
451
|
+
return listed(value) && value.every(held);
|
|
452
|
+
return plain(value) && Object.values(value).every(held);
|
|
453
|
+
}
|
|
454
|
+
export function frontmatterValue(value) {
|
|
455
|
+
return heldWithin(value, []);
|
|
456
|
+
}
|
|
421
457
|
export function serializeJs(value) {
|
|
422
|
-
if (value === null)
|
|
423
|
-
return 'null';
|
|
424
|
-
if (value === true)
|
|
425
|
-
return 'true';
|
|
426
|
-
if (value === false)
|
|
427
|
-
return 'false';
|
|
428
|
-
if (typeof value === 'number' && Number.isFinite(value))
|
|
429
|
-
return JSON.stringify(value);
|
|
430
458
|
if (typeof value === 'string')
|
|
431
459
|
return isPlainSafe(value) ? value : JSON.stringify(value);
|
|
460
|
+
if (value === null || typeof value !== 'object')
|
|
461
|
+
return JSON.stringify(value);
|
|
432
462
|
if (Array.isArray(value))
|
|
433
463
|
return `[${value.map(serializeJs).join(', ')}]`;
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
.join(', ')}}`;
|
|
438
|
-
throw new YamlError(0);
|
|
464
|
+
return `{${Object.entries(value)
|
|
465
|
+
.map(([key, held]) => `${serializeKey(key)}: ${serializeJs(held)}`)
|
|
466
|
+
.join(', ')}}`;
|
|
439
467
|
}
|
|
440
468
|
export function isRecord(value) {
|
|
441
469
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -485,7 +513,8 @@ export function equalValue(left, right) {
|
|
|
485
513
|
if (left === right)
|
|
486
514
|
return true;
|
|
487
515
|
if (Array.isArray(left) && Array.isArray(right)) {
|
|
488
|
-
return (left.length === right.length &&
|
|
516
|
+
return (left.length === right.length &&
|
|
517
|
+
Array.from(left).every((item, index) => equalValue(item, right[index])));
|
|
489
518
|
}
|
|
490
519
|
if (isRecord(left) && isRecord(right)) {
|
|
491
520
|
const keys = Object.keys(left);
|
package/fixtures/README.md
CHANGED
|
@@ -136,6 +136,6 @@ Library is accepted too, so `unresolved-link` never names it and
|
|
|
136
136
|
## YAML subset
|
|
137
137
|
|
|
138
138
|
Frontmatter and a schema text are each a mapping in a closed YAML subset: block and flow mappings,
|
|
139
|
-
block and flow sequences, a block sequence item that opens a mapping, plain and quoted scalars, `true`, `false`, `null`,
|
|
139
|
+
block and flow sequences, a block sequence item that opens a mapping, plain and quoted scalars (a single-quoted scalar doubles its apostrophe, a double-quoted one takes JSON's escapes), `true`, `false`, `null`,
|
|
140
140
|
and decimal numbers. It does not take YAML 1.1 boolean or timestamp aliases,
|
|
141
141
|
octal numbers, anchors, tags, or block scalars. A mapping carries each key once.
|