@agentshouse/mdmodel 0.1.0-ccb295d7b1fee → 0.1.0-ccb5d0a28eae3
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 +57 -19
- package/README.md +1 -0
- package/dist/built-in.d.ts.map +1 -1
- package/dist/built-in.js +10 -1
- package/dist/definition.d.ts +5 -1
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +79 -10
- package/dist/document.d.ts +2 -1
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +24 -1
- package/dist/event.d.ts +5 -8
- package/dist/event.d.ts.map +1 -1
- package/dist/event.js +3 -2
- package/dist/facts.d.ts.map +1 -1
- package/dist/facts.js +8 -4
- package/dist/folders.d.ts +5 -0
- package/dist/folders.d.ts.map +1 -0
- package/dist/folders.js +19 -0
- package/dist/house-model.d.ts +200 -18
- package/dist/house-model.d.ts.map +1 -1
- package/dist/house-model.js +99 -12
- package/dist/house-references/patterns.d.ts +5 -1
- package/dist/house-references/patterns.d.ts.map +1 -1
- package/dist/house-references/patterns.js +8 -1
- package/dist/index.d.ts +14 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -10
- package/dist/indexed.d.ts +1 -0
- package/dist/indexed.d.ts.map +1 -1
- package/dist/indexed.js +8 -0
- package/dist/kinds.d.ts +6 -1
- package/dist/kinds.d.ts.map +1 -1
- package/dist/kinds.js +8 -0
- package/dist/moment.d.ts +2 -0
- package/dist/moment.d.ts.map +1 -1
- package/dist/moment.js +22 -0
- package/dist/query/language.d.ts +2 -0
- package/dist/query/language.d.ts.map +1 -1
- package/dist/query/language.js +7 -6
- package/dist/query/match.d.ts.map +1 -1
- package/dist/query/match.js +3 -24
- package/dist/query/rows.d.ts +5 -0
- package/dist/query/rows.d.ts.map +1 -1
- package/dist/query/rows.js +35 -3
- package/dist/query/sql.d.ts +5 -0
- package/dist/query/sql.d.ts.map +1 -1
- package/dist/query/sql.js +19 -0
- package/dist/query/walk.d.ts +10 -0
- package/dist/query/walk.d.ts.map +1 -1
- package/dist/query/walk.js +15 -1
- package/dist/reserved.d.ts +0 -1
- package/dist/reserved.d.ts.map +1 -1
- package/dist/reserved.js +0 -2
- package/dist/room-types.d.ts +2 -1
- package/dist/room-types.d.ts.map +1 -1
- package/dist/room-types.js +16 -10
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +5 -3
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +100 -42
- package/dist/view.d.ts +5 -0
- package/dist/view.d.ts.map +1 -0
- package/dist/view.js +27 -0
- package/fixtures/README.md +25 -5
- package/fixtures/cases/absent-link-dangles/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/{boolean-field/schema.yaml → absent-optional-field/schema.md} +2 -0
- package/fixtures/cases/{duplicate-link-definition/schema.yaml → absolute-link/schema.md} +2 -0
- package/fixtures/cases/{attachment-reference-dangles/schema.yaml → attachment-reference-any-file/schema.md} +2 -0
- package/fixtures/cases/{attachment-reference-outside/schema.yaml → attachment-reference-dangles/schema.md} +2 -0
- package/fixtures/cases/{list-of-objects-reference/schema.yaml → attachment-reference-outside/schema.md} +2 -0
- package/fixtures/cases/binary-any-reference/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/binary-document-collision/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/binary-image-dangles/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/binary-link-dangles/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/binary-link-outside-collection/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/binary-prototype-reference/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/binary-typed-reference/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/{absent-optional-field/schema.yaml → boolean-field/schema.md} +2 -0
- package/fixtures/cases/{absolute-link/schema.yaml → bracketed-link-definition/schema.md} +2 -0
- package/fixtures/cases/closed-nested-object/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/composed-root-reference/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/conditional-long-text/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/cross-room-link/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/cross-room-reference/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/date-time-format/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/declared-binary-links/schema.md +3 -0
- package/fixtures/cases/default-unfilled/schema.md +57 -0
- package/fixtures/cases/defs-pattern/schema.md +57 -0
- package/fixtures/cases/dependent-rule/schema.md +57 -0
- package/fixtures/cases/{bracketed-link-definition/schema.yaml → duplicate-link-definition/schema.md} +2 -0
- package/fixtures/cases/email-format/schema.md +57 -0
- package/fixtures/cases/equal-labels/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/fenced-link-definition/schema.md +7 -0
- package/fixtures/cases/field-enum/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/folder-keeps-a-built-in-type/expected.json +1 -0
- package/fixtures/cases/folder-keeps-a-built-in-type/library/tickets/door.md +3 -0
- package/fixtures/cases/folder-keeps-a-built-in-type/library/tickets/host.md +13 -0
- package/fixtures/cases/folder-keeps-a-built-in-type/library/tickets/map.md +24 -0
- package/fixtures/cases/folder-keeps-a-built-in-type/library/tickets/open.md +13 -0
- package/fixtures/cases/folder-keeps-a-built-in-type/schema.md +9 -0
- package/fixtures/cases/folder-keeps-a-record/context.json +1 -0
- package/fixtures/cases/folder-keeps-a-record/expected.json +1 -0
- package/fixtures/cases/folder-keeps-a-record/library/tickets/2026-11-16-d_1.r.md +13 -0
- package/fixtures/cases/folder-keeps-a-record/library/tickets/door.md +3 -0
- package/fixtures/cases/folder-keeps-a-record/schema.md +9 -0
- package/fixtures/cases/folder-names-no-type-of-the-schema/context.json +1 -0
- package/fixtures/cases/folder-names-no-type-of-the-schema/expected.json +5 -0
- package/fixtures/cases/folder-names-no-type-of-the-schema/schema.md +7 -0
- package/fixtures/cases/folder-nearer-entry-types-a-document/context.json +1 -0
- package/fixtures/cases/folder-nearer-entry-types-a-document/expected.json +6 -0
- package/fixtures/cases/folder-nearer-entry-types-a-document/library/tickets/archive/2025/old.md +1 -0
- package/fixtures/cases/folder-nearer-entry-types-a-document/schema.md +15 -0
- package/fixtures/cases/folder-refuses-a-declared-any/context.json +1 -0
- package/fixtures/cases/folder-refuses-a-declared-any/expected.json +6 -0
- package/fixtures/cases/folder-refuses-a-declared-any/library/tickets/door.md +5 -0
- package/fixtures/cases/folder-refuses-a-declared-any/schema.md +9 -0
- package/fixtures/cases/folder-refuses-another-declared-type/context.json +1 -0
- package/fixtures/cases/folder-refuses-another-declared-type/expected.json +6 -0
- package/fixtures/cases/folder-refuses-another-declared-type/library/tickets/door.md +5 -0
- package/fixtures/cases/folder-refuses-another-declared-type/schema.md +12 -0
- package/fixtures/cases/folder-type-is-the-type-a-reference-reaches/context.json +1 -0
- package/fixtures/cases/folder-type-is-the-type-a-reference-reaches/expected.json +1 -0
- package/fixtures/cases/folder-type-is-the-type-a-reference-reaches/library/notes/plan.md +7 -0
- package/fixtures/cases/folder-type-is-the-type-a-reference-reaches/library/tickets/door.md +3 -0
- package/fixtures/cases/folder-type-is-the-type-a-reference-reaches/library/tickets/gate.md +7 -0
- package/fixtures/cases/folder-type-is-the-type-a-reference-reaches/schema.md +13 -0
- package/fixtures/cases/folder-types-a-document-in-a-folder-below-it/context.json +1 -0
- package/fixtures/cases/folder-types-a-document-in-a-folder-below-it/expected.json +6 -0
- package/fixtures/cases/folder-types-a-document-in-a-folder-below-it/library/tickets/2026/gate.md +1 -0
- package/fixtures/cases/folder-types-a-document-in-a-folder-below-it/schema.md +9 -0
- package/fixtures/cases/folder-types-a-document-that-names-no-type/context.json +1 -0
- package/fixtures/cases/folder-types-a-document-that-names-no-type/expected.json +7 -0
- package/fixtures/cases/folder-types-a-document-that-names-no-type/library/tickets/door.md +3 -0
- package/fixtures/cases/folder-types-a-document-that-names-no-type/schema.md +9 -0
- package/fixtures/cases/folder-under-a-reserved-name/context.json +1 -0
- package/fixtures/cases/folder-under-a-reserved-name/expected.json +5 -0
- package/fixtures/cases/folder-under-a-reserved-name/schema.md +7 -0
- package/fixtures/cases/folder-without-a-trailing-slash/context.json +1 -0
- package/fixtures/cases/folder-without-a-trailing-slash/expected.json +5 -0
- package/fixtures/cases/folder-without-a-trailing-slash/schema.md +7 -0
- package/fixtures/cases/integer-field/schema.md +57 -0
- package/fixtures/cases/interrupted-link-definition/schema.md +3 -0
- package/fixtures/cases/json-schema-constructs/schema.md +57 -0
- package/fixtures/cases/labels-in-the-rooms-language/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/lazy-list-item/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/link-into-a-reserved-name/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/list-item-enum/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/list-item-kind/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/list-items/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/list-of-objects-closed/schema.md +57 -0
- package/fixtures/cases/list-of-objects-item/schema.md +57 -0
- package/fixtures/cases/{attachment-reference-any-file/schema.yaml → list-of-objects-reference/schema.md} +2 -0
- package/fixtures/cases/list-reference-path/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/list-reference-type/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/list-size/schema.md +57 -0
- package/fixtures/cases/long-fence-link-definition/schema.md +3 -0
- package/fixtures/cases/long-value-past-six-levels/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/malformed-definition/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/malformed-list/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/member-document/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/member-on-another-type/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/missing-required-field/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/misspelled-key/schema.md +57 -0
- package/fixtures/cases/name-not-a-string/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/nested-defs/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/nested-object-reference/schema.md +34 -0
- package/fixtures/cases/nested-reference/schema.md +34 -0
- package/fixtures/cases/nested-required-field/schema.md +57 -0
- package/fixtures/cases/numeric-range/schema.md +57 -0
- package/fixtures/cases/one-key-two-labels/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/one-key-two-types/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/one-of-variant/schema.md +57 -0
- package/fixtures/cases/other-room-reference/schema.md +34 -0
- package/fixtures/cases/paragraph-link-definition/schema.md +3 -0
- package/fixtures/cases/prototype-field/schema.md +7 -0
- package/fixtures/cases/quoted-link-definition/schema.md +3 -0
- package/fixtures/cases/reference-into-a-reserved-name/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/reference-to-any-file-name/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/referenced-missing-file/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/referenced-missing-non-latin-file/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/remote-ref/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/schema-body-ignored/context.json +1 -0
- package/fixtures/cases/schema-body-ignored/expected.json +1 -0
- package/fixtures/cases/schema-body-ignored/schema.md +9 -0
- package/fixtures/cases/schema-type-named-folders/context.json +1 -0
- package/fixtures/cases/schema-type-named-folders/expected.json +5 -0
- package/fixtures/cases/schema-type-named-folders/schema.md +5 -0
- package/fixtures/cases/schema-type-named-type/context.json +1 -0
- package/fixtures/cases/schema-type-named-type/expected.json +5 -0
- package/fixtures/cases/{unknown-type/schema.yaml → schema-type-named-type/schema.md} +3 -1
- package/fixtures/cases/second-member-document/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/sections-keyword-refused/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/shortcut-reference-link/schema.md +7 -0
- package/fixtures/cases/string-length/schema.md +57 -0
- package/fixtures/cases/submission-keys/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/text-field-kind/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/thematic-break-ends-the-values/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/truncated-link-definition/schema.md +3 -0
- package/fixtures/cases/typed-path-names-another-type/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/typed-path-names-its-type/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/typed-path-names-no-type/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/types-folder-content/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/undeclared-field/schema.md +7 -0
- package/fixtures/cases/unevaluated-items-closed/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/unique-in-app-schema/context.json +1 -0
- package/fixtures/cases/unique-in-app-schema/expected.json +5 -0
- package/fixtures/cases/unique-in-app-schema/schema.yaml +7 -0
- package/fixtures/cases/unique-indexed-field/context.json +1 -0
- package/fixtures/cases/unique-indexed-field/expected.json +1 -0
- package/fixtures/cases/unique-indexed-field/library/tickets/first.md +8 -0
- package/fixtures/cases/unique-indexed-field/library/tickets/second.md +8 -0
- package/fixtures/cases/unique-indexed-field/schema.md +9 -0
- package/fixtures/cases/unique-off-indexed-field/context.json +1 -0
- package/fixtures/cases/unique-off-indexed-field/expected.json +5 -0
- package/fixtures/cases/unique-off-indexed-field/schema.md +9 -0
- package/fixtures/cases/unlisted-reference-type/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/unresolved-link/schema.md +7 -0
- package/fixtures/cases/valid-typed-document/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/wide-item-fence-link/schema.md +3 -0
- package/fixtures/queries.json +776 -1
- package/fixtures/references.json +15 -0
- package/package.json +2 -2
- package/fixtures/cases/declared-binary-links/schema.yaml +0 -1
- package/fixtures/cases/default-unfilled/schema.yaml +0 -55
- package/fixtures/cases/defs-pattern/schema.yaml +0 -55
- package/fixtures/cases/dependent-rule/schema.yaml +0 -55
- package/fixtures/cases/email-format/schema.yaml +0 -55
- package/fixtures/cases/fenced-link-definition/schema.yaml +0 -5
- package/fixtures/cases/frontmatter-schema/expected.json +0 -5
- package/fixtures/cases/integer-field/schema.yaml +0 -55
- package/fixtures/cases/interrupted-link-definition/schema.yaml +0 -1
- package/fixtures/cases/json-schema-constructs/schema.yaml +0 -55
- package/fixtures/cases/list-of-objects-closed/schema.yaml +0 -55
- package/fixtures/cases/list-of-objects-item/schema.yaml +0 -55
- package/fixtures/cases/list-size/schema.yaml +0 -55
- package/fixtures/cases/long-fence-link-definition/schema.yaml +0 -1
- package/fixtures/cases/misspelled-key/schema.yaml +0 -55
- package/fixtures/cases/nested-object-reference/schema.yaml +0 -32
- package/fixtures/cases/nested-reference/schema.yaml +0 -32
- package/fixtures/cases/nested-required-field/schema.yaml +0 -55
- package/fixtures/cases/numeric-range/schema.yaml +0 -55
- package/fixtures/cases/one-of-variant/schema.yaml +0 -55
- package/fixtures/cases/other-room-reference/schema.yaml +0 -32
- package/fixtures/cases/paragraph-link-definition/schema.yaml +0 -1
- package/fixtures/cases/prototype-field/schema.yaml +0 -5
- package/fixtures/cases/quoted-link-definition/schema.yaml +0 -1
- package/fixtures/cases/shortcut-reference-link/schema.yaml +0 -5
- package/fixtures/cases/string-length/schema.yaml +0 -55
- package/fixtures/cases/truncated-link-definition/schema.yaml +0 -1
- package/fixtures/cases/undeclared-field/schema.yaml +0 -5
- package/fixtures/cases/unresolved-link/schema.yaml +0 -5
- package/fixtures/cases/wide-item-fence-link/schema.yaml +0 -1
- /package/fixtures/cases/{frontmatter-schema → folder-keeps-a-built-in-type}/context.json +0 -0
- /package/fixtures/cases/{frontmatter-schema/schema.yaml → unknown-type/schema.md} +0 -0
package/dist/validate.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { ATTACHMENT, BUILT_IN_TYPE, readSchema, } from './definition.js';
|
|
2
2
|
import { linkDestinations, links, parse } from './document.js';
|
|
3
3
|
import { MEMBER_FIELD } from './fields.js';
|
|
4
|
+
import { RECORD_TYPE } from './house-model.js';
|
|
5
|
+
import { folderType, foldersFailure } from './folders.js';
|
|
4
6
|
import { formFailure } from './form.js';
|
|
5
|
-
import { indexedFailure } from './indexed.js';
|
|
7
|
+
import { indexedFailure, uniqueFailure } from './indexed.js';
|
|
6
8
|
import { hrefOccurrences, lineBreaks, lineNumber } from './markdown.js';
|
|
7
9
|
import { classifyHref, keyedLink, roomTarget } from './paths.js';
|
|
8
10
|
import { references } from './references.js';
|
|
9
11
|
import { isDocumentPath, ROOM_DESCRIPTION } from './reserved.js';
|
|
10
12
|
import { refusal } from './refuse.js';
|
|
11
13
|
import { schemaRefusal } from './schema.js';
|
|
14
|
+
import { viewRefusal } from './view.js';
|
|
15
|
+
import { extractFrontmatter } from './yaml.js';
|
|
12
16
|
import { openPatternBudget, PatternTooCostly } from './pattern.js';
|
|
13
17
|
function refuse(file, rule, extra) {
|
|
14
18
|
return { verdict: 'refuse', ...refusal(file, rule, extra) };
|
|
@@ -37,8 +41,9 @@ function unmarkedMember(file, document, definition) {
|
|
|
37
41
|
? refuse(file, 'undeclared-field', { location: `/${MEMBER_FIELD}` })
|
|
38
42
|
: null;
|
|
39
43
|
}
|
|
40
|
-
function reservedLink(file, document, changed) {
|
|
41
|
-
return (
|
|
44
|
+
function reservedLink(file, document, typed, changed) {
|
|
45
|
+
return (typed !== undefined &&
|
|
46
|
+
typed !== RECORD_TYPE &&
|
|
42
47
|
isDocumentPath(file) &&
|
|
43
48
|
links(document, file).some((link) => !isDocumentPath(link.target) && (changed?.has(link.target) ?? true)));
|
|
44
49
|
}
|
|
@@ -71,12 +76,28 @@ function typedPathRefusal(file, document, typedPath) {
|
|
|
71
76
|
return refuse(file, 'unknown-type', { location: '/type' });
|
|
72
77
|
return typedPath.body && !HELD_TEXT.test(document.text) ? refuse(file, 'required-body') : null;
|
|
73
78
|
}
|
|
74
|
-
function
|
|
75
|
-
return
|
|
79
|
+
function undeclared(document) {
|
|
80
|
+
return document.fields.type === undefined || document.fields.type === null;
|
|
81
|
+
}
|
|
82
|
+
function folderRefusal(file, document, folder, model) {
|
|
83
|
+
const declared = document.type;
|
|
84
|
+
if (folder === undefined || declared === undefined || declared === folder)
|
|
85
|
+
return null;
|
|
86
|
+
return Object.hasOwn(model.types, declared) && model.types[declared].builtIn === true
|
|
87
|
+
? null
|
|
88
|
+
: refuse(file, 'folder-type', { location: '/type' });
|
|
89
|
+
}
|
|
90
|
+
function kindOf(document, typedPath, folder) {
|
|
91
|
+
if (typedPath !== undefined && !typedPath.named)
|
|
92
|
+
return typedPath.type;
|
|
93
|
+
return folder !== undefined && undeclared(document) ? folder : instanceType(document);
|
|
76
94
|
}
|
|
77
95
|
export function definitionAt(model, file, typedPaths) {
|
|
78
96
|
const typedPath = typedPathOf(file, typedPaths);
|
|
79
|
-
|
|
97
|
+
const folder = folderType(model, file);
|
|
98
|
+
return (type) => definitionOf(typedPath !== undefined && !typedPath.named
|
|
99
|
+
? typedPath.type
|
|
100
|
+
: (type ?? folder ?? BUILT_IN_TYPE), model);
|
|
80
101
|
}
|
|
81
102
|
function instanceType(document) {
|
|
82
103
|
const raw = document.fields.type;
|
|
@@ -86,23 +107,23 @@ function instanceType(document) {
|
|
|
86
107
|
return null;
|
|
87
108
|
return raw;
|
|
88
109
|
}
|
|
89
|
-
function reaches(reference, typeOf,
|
|
110
|
+
function reaches(reference, typeOf, isAttachment) {
|
|
90
111
|
if (reference.target === null)
|
|
91
112
|
return false;
|
|
92
113
|
if (reference.to.includes(ATTACHMENT))
|
|
93
114
|
return true;
|
|
94
|
-
if (
|
|
115
|
+
if (isAttachment(reference.target))
|
|
95
116
|
return false;
|
|
96
117
|
const held = typeOf(reference.target);
|
|
97
118
|
return held === undefined || reference.to.includes(held);
|
|
98
119
|
}
|
|
99
|
-
function missing(reference, typeOf,
|
|
120
|
+
function missing(reference, typeOf, isAttachment) {
|
|
100
121
|
if (reference.to.includes(ATTACHMENT) || reference.target === null)
|
|
101
122
|
return false;
|
|
102
|
-
return typeOf(reference.target) === undefined && !
|
|
123
|
+
return typeOf(reference.target) === undefined && !isAttachment(reference.target);
|
|
103
124
|
}
|
|
104
|
-
export function resolves(reference, typeOf,
|
|
105
|
-
return reaches(reference, typeOf,
|
|
125
|
+
export function resolves(reference, typeOf, isAttachment) {
|
|
126
|
+
return reaches(reference, typeOf, isAttachment) && !missing(reference, typeOf, isAttachment);
|
|
106
127
|
}
|
|
107
128
|
function schemaRefused(failure) {
|
|
108
129
|
return {
|
|
@@ -111,23 +132,50 @@ function schemaRefused(failure) {
|
|
|
111
132
|
...(failure.location === undefined ? {} : { location: failure.location }),
|
|
112
133
|
};
|
|
113
134
|
}
|
|
114
|
-
|
|
115
|
-
|
|
135
|
+
const NO_FRONTMATTER = { start: 0, end: 0 };
|
|
136
|
+
function frontmatterOf(document) {
|
|
137
|
+
const fence = extractFrontmatter(document);
|
|
138
|
+
if (fence.kind === 'none')
|
|
139
|
+
return NO_FRONTMATTER;
|
|
140
|
+
if (fence.kind === 'unclosed')
|
|
141
|
+
return { rule: 'schema-yaml', location: 'line 1' };
|
|
142
|
+
return { start: fence.yamlStart, end: fence.yamlEnd };
|
|
143
|
+
}
|
|
144
|
+
function verified(text, provided, { start, end }, document) {
|
|
145
|
+
const read = readSchema(text, provided, true, start, end);
|
|
116
146
|
if (!('types' in read))
|
|
117
147
|
return schemaRefused(read);
|
|
118
|
-
const failure = formFailure(read, provided) ??
|
|
148
|
+
const failure = formFailure(read, provided) ??
|
|
149
|
+
indexedFailure(read) ??
|
|
150
|
+
(document ? undefined : (uniqueFailure(read) ?? foldersFailure(read)));
|
|
119
151
|
return failure === undefined ? { verdict: 'accept', model: read } : schemaRefused(failure);
|
|
120
152
|
}
|
|
121
|
-
|
|
122
|
-
const read = readSchema(
|
|
153
|
+
function typesRead(text, provided, { start, end }) {
|
|
154
|
+
const read = readSchema(text, provided, false, start, end);
|
|
123
155
|
if ('types' in read)
|
|
124
156
|
return read;
|
|
125
157
|
throw new Error(`the schema reads as no types: ${read.rule} ${read.location ?? ''}`.trim());
|
|
126
158
|
}
|
|
127
|
-
function
|
|
159
|
+
export function verify(schema, provided) {
|
|
160
|
+
return verified(schema, provided, { start: 0, end: schema.length }, false);
|
|
161
|
+
}
|
|
162
|
+
export function readTypes(schema, provided) {
|
|
163
|
+
return typesRead(schema, provided, { start: 0, end: schema.length });
|
|
164
|
+
}
|
|
165
|
+
export function verifySchemaDocument(document, provided) {
|
|
166
|
+
const held = frontmatterOf(document);
|
|
167
|
+
return 'rule' in held ? schemaRefused(held) : verified(document, provided, held, true);
|
|
168
|
+
}
|
|
169
|
+
export function readSchemaDocument(document, provided) {
|
|
170
|
+
const held = frontmatterOf(document);
|
|
171
|
+
if ('rule' in held)
|
|
172
|
+
throw new Error(`the schema reads as no types: ${held.rule} ${held.location}`);
|
|
173
|
+
return typesRead(document, provided, held);
|
|
174
|
+
}
|
|
175
|
+
function structure(file, document, definition, model) {
|
|
128
176
|
if (definition === undefined)
|
|
129
177
|
return refuse(file, 'unknown-type', { location: '/type' });
|
|
130
|
-
const fieldFailure = schemaRefusal(definition, document.fields);
|
|
178
|
+
const fieldFailure = schemaRefusal(definition, document.fields) ?? viewRefusal(definition, document.fields, model);
|
|
131
179
|
if (fieldFailure !== undefined)
|
|
132
180
|
return placedRefusal(file, document, fieldFailure.rule, fieldFailure.location);
|
|
133
181
|
return unmarkedMember(file, document, definition);
|
|
@@ -160,19 +208,22 @@ export function checkDocument(file, content, model, context = {}) {
|
|
|
160
208
|
if (!parsed.ok)
|
|
161
209
|
return { ok: false };
|
|
162
210
|
const document = parsed.document;
|
|
163
|
-
const
|
|
211
|
+
const folder = folderType(model, file);
|
|
212
|
+
const typed = document.type ?? folder;
|
|
213
|
+
const type = typed ?? BUILT_IN_TYPE;
|
|
164
214
|
const typedPath = typedPathOf(file, context.typedPaths);
|
|
165
215
|
if (describedRoom(file, document) !== null ||
|
|
166
216
|
typedPathRefusal(file, document, typedPath) !== null ||
|
|
167
|
-
|
|
217
|
+
folderRefusal(file, document, folder, model) !== null ||
|
|
218
|
+
reservedLink(file, document, typed))
|
|
168
219
|
return { ok: false };
|
|
169
|
-
const kind = kindOf(document, typedPath);
|
|
220
|
+
const kind = kindOf(document, typedPath, folder);
|
|
170
221
|
if (kind === BUILT_IN_TYPE)
|
|
171
222
|
return unmarkedMember(file, document, undefined) === null
|
|
172
223
|
? { ok: true, type, typed: false, references: [] }
|
|
173
224
|
: { ok: false };
|
|
174
225
|
const definition = definitionOf(kind, model);
|
|
175
|
-
if (structure(file, document, definition) !== null ||
|
|
226
|
+
if (structure(file, document, definition, model) !== null ||
|
|
176
227
|
definition === undefined ||
|
|
177
228
|
!linked(file, document))
|
|
178
229
|
return { ok: false };
|
|
@@ -223,20 +274,24 @@ function placedAt(document, reference, location) {
|
|
|
223
274
|
const line = lineAt(document, location);
|
|
224
275
|
return line === undefined ? { reference, location } : { reference, location, line };
|
|
225
276
|
}
|
|
226
|
-
export function assess(file, parsed,
|
|
277
|
+
export function assess(file, parsed, attachment, model = { types: {} }, context = {}) {
|
|
227
278
|
const unread = { file, type: undefined, targets: [], structured: null, fields: [] };
|
|
228
|
-
if (
|
|
279
|
+
if (attachment)
|
|
229
280
|
return { ...unread, read: refuse(file, 'binary-target-document'), linked: true };
|
|
230
281
|
if (!parsed.ok)
|
|
231
282
|
return { ...unread, read: { verdict: 'refuse', ...parsed.refusal }, linked: true };
|
|
232
283
|
const document = parsed.document;
|
|
233
|
-
const
|
|
284
|
+
const folder = folderType(model, file);
|
|
285
|
+
const declared = document.type ?? folder;
|
|
286
|
+
const type = declared ?? BUILT_IN_TYPE;
|
|
234
287
|
const typed = { file, type, read: null, structured: null };
|
|
235
288
|
const typedPath = typedPathOf(file, context.typedPaths);
|
|
236
|
-
const described = describedRoom(file, document) ??
|
|
289
|
+
const described = describedRoom(file, document) ??
|
|
290
|
+
typedPathRefusal(file, document, typedPath) ??
|
|
291
|
+
folderRefusal(file, document, folder, model);
|
|
237
292
|
if (described !== null)
|
|
238
293
|
return { ...typed, targets: [], structured: described, fields: [], linked: true };
|
|
239
|
-
const kind = kindOf(document, typedPath);
|
|
294
|
+
const kind = kindOf(document, typedPath, folder);
|
|
240
295
|
if (kind === BUILT_IN_TYPE) {
|
|
241
296
|
const structured = unmarkedMember(file, document, undefined);
|
|
242
297
|
return {
|
|
@@ -244,12 +299,12 @@ export function assess(file, parsed, binary, model = { types: {} }, context = {}
|
|
|
244
299
|
targets: [],
|
|
245
300
|
structured,
|
|
246
301
|
fields: [],
|
|
247
|
-
linked: !reservedLink(file, document),
|
|
302
|
+
linked: !reservedLink(file, document, declared),
|
|
248
303
|
};
|
|
249
304
|
}
|
|
250
305
|
const definition = definitionOf(kind, model);
|
|
251
306
|
try {
|
|
252
|
-
return structured(file, typed, document, definition, context);
|
|
307
|
+
return structured(file, typed, document, declared, definition, model, context);
|
|
253
308
|
}
|
|
254
309
|
catch (error) {
|
|
255
310
|
if (!(error instanceof PatternTooCostly))
|
|
@@ -263,8 +318,8 @@ export function assess(file, parsed, binary, model = { types: {} }, context = {}
|
|
|
263
318
|
};
|
|
264
319
|
}
|
|
265
320
|
}
|
|
266
|
-
function structured(file, typed, document, definition, context) {
|
|
267
|
-
const refused = structure(file, document, definition);
|
|
321
|
+
function structured(file, typed, document, declared, definition, model, context) {
|
|
322
|
+
const refused = structure(file, document, definition, model);
|
|
268
323
|
if (refused !== null || definition === undefined) {
|
|
269
324
|
return { ...typed, targets: [], structured: refused, fields: [], linked: true };
|
|
270
325
|
}
|
|
@@ -281,7 +336,8 @@ function structured(file, typed, document, definition, context) {
|
|
|
281
336
|
...typed,
|
|
282
337
|
targets: [...targets],
|
|
283
338
|
fields,
|
|
284
|
-
linked:
|
|
339
|
+
linked: declared === RECORD_TYPE ||
|
|
340
|
+
(linked(file, document) && !reservedLink(file, document, declared)),
|
|
285
341
|
};
|
|
286
342
|
}
|
|
287
343
|
export function assessReferences(file, parsed, changed, model = { types: {} }, context = {}) {
|
|
@@ -297,7 +353,9 @@ export function assessReferences(file, parsed, changed, model = { types: {} }, c
|
|
|
297
353
|
if (!parsed.ok)
|
|
298
354
|
return unread;
|
|
299
355
|
const { document } = parsed;
|
|
300
|
-
const
|
|
356
|
+
const folder = folderType(model, file);
|
|
357
|
+
const declared = document.type ?? folder;
|
|
358
|
+
const definition = definitionOf(kindOf(document, typedPathOf(file, context.typedPaths), folder), model);
|
|
301
359
|
const fields = definition === undefined
|
|
302
360
|
? []
|
|
303
361
|
: references(document, definition).flatMap(({ pointer, value, to }) => {
|
|
@@ -313,10 +371,10 @@ export function assessReferences(file, parsed, changed, model = { types: {} }, c
|
|
|
313
371
|
}
|
|
314
372
|
return {
|
|
315
373
|
...unread,
|
|
316
|
-
type:
|
|
374
|
+
type: declared ?? BUILT_IN_TYPE,
|
|
317
375
|
targets: [...targets],
|
|
318
376
|
fields,
|
|
319
|
-
linked: !reservedLink(file, document, changed),
|
|
377
|
+
linked: !reservedLink(file, document, declared, changed),
|
|
320
378
|
};
|
|
321
379
|
}
|
|
322
380
|
export function verdicts() {
|
|
@@ -325,7 +383,7 @@ export function verdicts() {
|
|
|
325
383
|
let referred;
|
|
326
384
|
let missed;
|
|
327
385
|
return {
|
|
328
|
-
add(assessment, typeOf,
|
|
386
|
+
add(assessment, typeOf, isAttachment) {
|
|
329
387
|
const { file } = assessment;
|
|
330
388
|
if (assessment.read !== null) {
|
|
331
389
|
read = least(read, file, assessment.read);
|
|
@@ -335,7 +393,7 @@ export function verdicts() {
|
|
|
335
393
|
structured = least(structured, file, assessment.structured);
|
|
336
394
|
return 0;
|
|
337
395
|
}
|
|
338
|
-
const field = assessment.fields.find(({ reference }) => !reaches(reference, typeOf,
|
|
396
|
+
const field = assessment.fields.find(({ reference }) => !reaches(reference, typeOf, isAttachment));
|
|
339
397
|
if (field !== undefined) {
|
|
340
398
|
referred = least(referred, file, refuse(file, 'unresolved-reference', {
|
|
341
399
|
location: field.location,
|
|
@@ -348,7 +406,7 @@ export function verdicts() {
|
|
|
348
406
|
return 0;
|
|
349
407
|
}
|
|
350
408
|
for (const { reference } of assessment.fields) {
|
|
351
|
-
if (!missing(reference, typeOf,
|
|
409
|
+
if (!missing(reference, typeOf, isAttachment))
|
|
352
410
|
continue;
|
|
353
411
|
const path = reference.target;
|
|
354
412
|
if (missed === undefined || path < missed.path)
|
|
@@ -380,13 +438,13 @@ export function* validating(library, context = { binaryTargets: [] }, model = {
|
|
|
380
438
|
}
|
|
381
439
|
function* judging(library, context, model) {
|
|
382
440
|
const binaryTargets = new Set(context.binaryTargets);
|
|
383
|
-
const
|
|
441
|
+
const isAttachment = (path) => binaryTargets.has(path);
|
|
384
442
|
const types = new Map();
|
|
385
443
|
const assessments = [];
|
|
386
444
|
const closeBudget = openPatternBudget();
|
|
387
445
|
try {
|
|
388
446
|
for (const [file, parsed] of library) {
|
|
389
|
-
const assessment = assess(file, parsed,
|
|
447
|
+
const assessment = assess(file, parsed, isAttachment(file), model, context);
|
|
390
448
|
if (assessment.type !== undefined)
|
|
391
449
|
types.set(file, assessment.type);
|
|
392
450
|
assessments.push(assessment);
|
|
@@ -394,7 +452,7 @@ function* judging(library, context, model) {
|
|
|
394
452
|
}
|
|
395
453
|
const judged = verdicts();
|
|
396
454
|
for (const assessment of assessments) {
|
|
397
|
-
const resolved = judged.add(assessment, (path) => types.get(path),
|
|
455
|
+
const resolved = judged.add(assessment, (path) => types.get(path), isAttachment);
|
|
398
456
|
yield { path: assessment.file, resolved };
|
|
399
457
|
}
|
|
400
458
|
return judged.verdict();
|
package/dist/view.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Definition } from './definition.js';
|
|
2
|
+
import type { SchemaRefusal } from './schema.js';
|
|
3
|
+
import type { VerifiedModel } from './types.js';
|
|
4
|
+
export declare function viewRefusal(definition: Definition, fields: Readonly<Record<string, unknown>>, model: VerifiedModel): SchemaRefusal | undefined;
|
|
5
|
+
//# sourceMappingURL=view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAShD,wBAAgB,WAAW,CACzB,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACzC,KAAK,EAAE,aAAa,GACnB,aAAa,GAAG,SAAS,CAgB3B"}
|
package/dist/view.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { escapePointer } from './definition.js';
|
|
2
|
+
import { planOf, QueryError } from './query/language.js';
|
|
3
|
+
import { VIEW_TYPE } from './room-types.js';
|
|
4
|
+
import { plain } from './yaml.js';
|
|
5
|
+
const QUERY = '/query';
|
|
6
|
+
function refused(location) {
|
|
7
|
+
return { rule: 'invalid-query', location };
|
|
8
|
+
}
|
|
9
|
+
export function viewRefusal(definition, fields, model) {
|
|
10
|
+
if (definition.name !== VIEW_TYPE)
|
|
11
|
+
return undefined;
|
|
12
|
+
const { query } = fields;
|
|
13
|
+
if (plain(query) && Object.hasOwn(query, 'rooms'))
|
|
14
|
+
return refused(`${QUERY}/rooms`);
|
|
15
|
+
try {
|
|
16
|
+
planOf(query, {
|
|
17
|
+
listed: true,
|
|
18
|
+
rooms: [{ locator: '', available: true, types: Object.values(model.types) }],
|
|
19
|
+
});
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (!(error instanceof QueryError))
|
|
24
|
+
throw error;
|
|
25
|
+
return refused(`${QUERY}${error.place.map((step) => `/${escapePointer(String(step))}`).join('')}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
package/fixtures/README.md
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
Each directory under `cases/` is one text Library, one validation context,
|
|
4
4
|
and one expected verdict. Consumers load the files under `library/` as
|
|
5
5
|
path-to-content, an absent `library/` being the empty Library, and the
|
|
6
|
-
required `context.json` as `ValidationContext`. Cases with a `schema.
|
|
7
|
-
|
|
6
|
+
required `context.json` as `ValidationContext`. Cases with a `schema.md`, a Room
|
|
7
|
+
schema Document whose frontmatter is the schema, call `verifySchemaDocument` with
|
|
8
|
+
its text and `HOUSE_ROOM_TYPES`, as every Room reads one, and cases with a `schema.yaml`, an
|
|
9
|
+
App's schema text, call `verify` with it and `HOUSE_ROOM_TYPES`; either then compares its refusal or
|
|
8
10
|
`validate(library, context, verified.model)` against `expected.json`. Other
|
|
9
11
|
cases compare `validate(library, context)` directly. Text-only cases carry
|
|
10
12
|
`{ "binaryTargets": [] }`. Binary targets are membership declarations; the
|
|
@@ -39,15 +41,22 @@ link rewrite.
|
|
|
39
41
|
## Queries
|
|
40
42
|
|
|
41
43
|
`queries.json` is the one table of cases both query evaluators answer. It carries `schema`,
|
|
42
|
-
one schema text; `
|
|
44
|
+
one schema text; `reads`, the handles of the other Rooms the reader reads; `documents`, each
|
|
45
|
+
named and carrying its `path`, the `room` handle of another Room that holds it, absent for the
|
|
46
|
+
reader's own Room, the `type` a collection
|
|
43
47
|
stores for it (`any` for an untyped Markdown Document, `null` for one that is not Markdown),
|
|
44
48
|
its `fileId`, the `text` the device holds or `null`, and its `fields`; and `cases`, each with a
|
|
45
49
|
`name`, a `query` of filter parts, the `document` it names and whether it `matches`. Verify
|
|
46
50
|
the schema and plan `{ ...query, select: {} }` with `planOf` against its types. Then
|
|
47
51
|
`matches(plan, candidate)` over the named Document, given its type's definition, and the
|
|
48
52
|
condition `sql.tests` writes over a collection holding every Document of the table with the
|
|
49
|
-
values `indexed` derives from it
|
|
50
|
-
|
|
53
|
+
values and links `indexed` derives from it, joined with `sql.hopped` for a `hop` whose targets
|
|
54
|
+
are the collection's Documents by Room and Path, a link into a Room the reader does not read
|
|
55
|
+
followed by none, must both answer `matches`. A case that tests other
|
|
56
|
+
Documents names in `refusedInMemory` the part `matches` refuses there as `invalid-query`, since
|
|
57
|
+
one Document cannot answer it, and only the SQL condition answers `matches`. A new operator
|
|
58
|
+
adds its cases here first. The `actor` type's `door` holds the MD model's `WRITE_DOORS`, each
|
|
59
|
+
matched by its own case, as a Trigger condition's `by` reads it. With `types: ["task"]`, every `task` Document both evaluators match, in each case `matches` answers but a `record`'s or an `actor`'s, lies within the
|
|
51
60
|
index plan `walkOf` takes for each case: among the keys of the equality or list it walks, and
|
|
52
61
|
within the runs of keys it walks an order by each indexed field in, a missing value's among
|
|
53
62
|
them, so a new driving test adds its cases here too. Each of `orders` carries a `name`, one `orderBy` clause on a field the `task` type
|
|
@@ -56,6 +65,14 @@ either direction. The SQL order `sql.sorted` writes over that collection, `compa
|
|
|
56
65
|
value `heldAt` reads, its instant for a date-time, and the bytes of each Document's `indexKey`,
|
|
57
66
|
a missing value and `null` placed as the clause's `nulls` asks, must each give that order.
|
|
58
67
|
|
|
68
|
+
## References
|
|
69
|
+
|
|
70
|
+
`references.json` holds House's reference forms. Each row carries `name`, one `reference` and the
|
|
71
|
+
one `pattern` that reads it, `room`, `app`, `space`, `document`, `attachment` or `revision`, or
|
|
72
|
+
`null` where none does: `ROOM_REFERENCE_PATTERN`, `APP_REFERENCE_PATTERN`,
|
|
73
|
+
`SPACE_REFERENCE_PATTERN`, `DOCUMENT_REFERENCE_PATTERN`, `ATTACHMENT_REFERENCE_PATTERN` and
|
|
74
|
+
`REVISION_REFERENCE_PATTERN` must each read exactly the rows that name it.
|
|
75
|
+
|
|
59
76
|
## Verdict format
|
|
60
77
|
|
|
61
78
|
Acceptance:
|
|
@@ -110,12 +127,15 @@ schema text. The model's own rules:
|
|
|
110
127
|
| `reference` | `reference` is not on a string or names something but a type, `any`, `attachment` |
|
|
111
128
|
| `member_document` | The mark is not a boolean, or a second type carries it |
|
|
112
129
|
| `indexed` | `indexed` names a field a type cannot index, or more than its caller's bounds |
|
|
130
|
+
| `unique` | `unique` is not `true`, sits on a field its type does not name in `indexed` or anywhere but a field of a type's own `properties`, or is in an App's schema text |
|
|
131
|
+
| `folders` | `folders` is no mapping, or an entry is no folder written from the root with a trailing `/`, sits under a reserved name, or names no type the schema declares |
|
|
113
132
|
| `duplicate-label` | Two fields of one object show one label: a field's `title`, else its key |
|
|
114
133
|
| `conflicting-label` | Declarations of one key in `anyOf`, `oneOf`, `then`, `else` or a composed shape give it two `title`s |
|
|
115
134
|
| `conflicting-type` | Such declarations give one key two JSON types, integer and number counting as one |
|
|
116
135
|
| `name-type` | A type's top-level `name` is not a string |
|
|
117
136
|
| `heading-depth` | A value written under a heading sits past `######`: `##` at the top, a level deeper per property or list item, none inside a `json` block |
|
|
118
137
|
| `unknown-type` | A file declares a type absent from the governing schema, or other than its typed path requires it to name |
|
|
138
|
+
| `folder-type` | A file in a folder `folders` types declares another type, `any` included, that is not built in |
|
|
119
139
|
| `undeclared-field` | A closed object carries a key it does not declare |
|
|
120
140
|
| `malformed-value` | A value is not written in its form, or a typed Document's frontmatter holds a key that is not House's |
|
|
121
141
|
| `repeated-value` | A value is written twice: two lines, a line and a heading, or two headings |
|