@agentshouse/mdmodel 0.1.0-c2987f5d89720 → 0.1.0-c2e6f0cf254e0
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 +354 -234
- package/README.md +28 -29
- package/dist/body.d.ts +85 -0
- package/dist/body.d.ts.map +1 -0
- package/dist/body.js +1083 -0
- package/dist/built-in.d.ts +4 -0
- package/dist/built-in.d.ts.map +1 -0
- package/dist/built-in.js +19 -0
- package/dist/definition.d.ts +44 -10
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +480 -104
- package/dist/divide.d.ts.map +1 -1
- package/dist/divide.js +32 -21
- package/dist/document.d.ts +19 -13
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +993 -210
- package/dist/event.d.ts +77 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +200 -0
- package/dist/facts.d.ts +15 -0
- package/dist/facts.d.ts.map +1 -0
- package/dist/facts.js +41 -0
- package/dist/fields.d.ts +3 -1
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +8 -1
- package/dist/form.d.ts +4 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +153 -0
- package/dist/house-model.d.ts +831 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +462 -0
- package/dist/house-references/crockford.d.ts +4 -0
- package/dist/house-references/crockford.d.ts.map +1 -0
- package/dist/house-references/crockford.js +3 -0
- package/dist/house-references/patterns.d.ts +9 -0
- package/dist/house-references/patterns.d.ts.map +1 -0
- package/dist/house-references/patterns.js +13 -0
- package/dist/index.d.ts +38 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -7
- package/dist/kinds.d.ts +18 -0
- package/dist/kinds.d.ts.map +1 -0
- package/dist/kinds.js +150 -0
- package/dist/markdown.d.ts +75 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +265 -0
- package/dist/media-type.d.ts +72 -0
- package/dist/media-type.d.ts.map +1 -0
- package/dist/media-type.js +157 -0
- package/dist/paths.d.ts +20 -2
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +177 -16
- package/dist/pattern.d.ts +10 -0
- package/dist/pattern.d.ts.map +1 -0
- package/dist/pattern.js +356 -0
- package/dist/project.d.ts +1 -0
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +61 -65
- 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 +150 -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 +285 -0
- package/dist/references.d.ts +2 -2
- package/dist/references.d.ts.map +1 -1
- package/dist/references.js +6 -1
- package/dist/refuse.d.ts +1 -0
- package/dist/refuse.d.ts.map +1 -1
- package/dist/refuse.js +1 -0
- package/dist/reserved.d.ts +6 -0
- package/dist/reserved.d.ts.map +1 -0
- package/dist/reserved.js +21 -0
- package/dist/room-types.d.ts +7 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +137 -0
- package/dist/schema.d.ts +0 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +10 -22
- package/dist/types.d.ts +72 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +34 -2
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +383 -140
- package/dist/yaml.d.ts +7 -3
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +110 -55
- package/fixtures/README.md +62 -25
- package/fixtures/cases/absent-link-dangles/library/item.md +8 -0
- package/fixtures/cases/absent-link-dangles/schema.yaml +5 -0
- package/fixtures/cases/absent-optional-field/library/companies/acme.md +1 -1
- package/fixtures/cases/absent-optional-field/library/deals/lead.md +3 -3
- package/fixtures/cases/absent-optional-field/schema.yaml +10 -11
- package/fixtures/cases/{missing-binary-image → absolute-link}/expected.json +1 -1
- package/fixtures/cases/absolute-link/library/item.md +8 -0
- package/fixtures/cases/absolute-link/schema.yaml +5 -0
- package/fixtures/cases/attachment-reference-any-file/library/companies/acme.md +1 -1
- package/fixtures/cases/attachment-reference-any-file/library/deals/renewal.md +13 -10
- package/fixtures/cases/attachment-reference-any-file/library/places/depot.md +1 -1
- package/fixtures/cases/attachment-reference-any-file/library/products/seats.md +1 -1
- package/fixtures/cases/attachment-reference-any-file/library/products/support.md +1 -1
- package/fixtures/cases/attachment-reference-dangles/library/companies/acme.md +1 -1
- package/fixtures/cases/attachment-reference-dangles/library/deals/renewal.md +13 -10
- package/fixtures/cases/attachment-reference-dangles/library/places/depot.md +1 -1
- package/fixtures/cases/attachment-reference-dangles/library/products/seats.md +1 -1
- package/fixtures/cases/attachment-reference-dangles/library/products/support.md +1 -1
- package/fixtures/cases/attachment-reference-outside/expected.json +2 -1
- package/fixtures/cases/attachment-reference-outside/library/companies/acme.md +1 -1
- package/fixtures/cases/attachment-reference-outside/library/deals/renewal.md +13 -10
- package/fixtures/cases/attachment-reference-outside/library/places/depot.md +1 -1
- package/fixtures/cases/attachment-reference-outside/library/products/seats.md +1 -1
- package/fixtures/cases/attachment-reference-outside/library/products/support.md +1 -1
- package/fixtures/cases/binary-any-reference/expected.json +2 -1
- package/fixtures/cases/binary-any-reference/library/notes/draft.md +1 -1
- package/fixtures/cases/binary-image-dangles/expected.json +1 -0
- package/fixtures/cases/binary-link-dangles/expected.json +1 -0
- package/fixtures/cases/binary-prototype-reference/expected.json +2 -1
- package/fixtures/cases/binary-prototype-reference/library/notes/draft.md +1 -1
- package/fixtures/cases/binary-typed-reference/expected.json +2 -1
- package/fixtures/cases/binary-typed-reference/library/notes/draft.md +1 -1
- package/fixtures/cases/boolean-field/expected.json +2 -1
- package/fixtures/cases/boolean-field/library/companies/acme.md +1 -1
- package/fixtures/cases/boolean-field/library/deals/renewal.md +49 -24
- package/fixtures/cases/boolean-field/schema.yaml +10 -11
- package/fixtures/cases/bracketed-link-definition/library/item.md +1 -1
- package/fixtures/cases/bracketed-link-definition/schema.yaml +2 -3
- package/fixtures/cases/closed-nested-object/expected.json +2 -1
- package/fixtures/cases/closed-nested-object/library/companies/acme.md +1 -1
- package/fixtures/cases/closed-nested-object/library/deals/renewal.md +50 -25
- package/fixtures/cases/closed-nested-object/schema.yaml +10 -11
- package/fixtures/cases/composed-root-reference/library/a.md +2 -2
- package/fixtures/cases/conditional-long-text/expected.json +7 -0
- package/fixtures/cases/conditional-long-text/library/questions/hosting.md +9 -0
- package/fixtures/cases/conditional-long-text/library/questions/payments.md +12 -0
- package/fixtures/cases/conditional-long-text/schema.yaml +13 -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/expected.json +1 -0
- package/fixtures/cases/cross-room-reference/library/clients/acme.md +9 -0
- package/fixtures/cases/cross-room-reference/schema.yaml +8 -0
- package/fixtures/cases/date-time-format/expected.json +2 -1
- package/fixtures/cases/date-time-format/library/companies/acme.md +1 -1
- package/fixtures/cases/date-time-format/library/deals/renewal.md +49 -24
- package/fixtures/cases/date-time-format/schema.yaml +10 -11
- package/fixtures/cases/default-unfilled/library/companies/acme.md +1 -1
- package/fixtures/cases/default-unfilled/library/deals/renewal.md +47 -22
- package/fixtures/cases/default-unfilled/schema.yaml +10 -11
- package/fixtures/cases/defs-pattern/expected.json +2 -1
- package/fixtures/cases/defs-pattern/library/companies/acme.md +1 -1
- package/fixtures/cases/defs-pattern/library/deals/renewal.md +49 -24
- package/fixtures/cases/defs-pattern/schema.yaml +10 -11
- package/fixtures/cases/dependent-rule/library/companies/acme.md +1 -1
- package/fixtures/cases/dependent-rule/library/deals/renewal.md +48 -23
- package/fixtures/cases/dependent-rule/schema.yaml +10 -11
- package/fixtures/cases/duplicate-link-definition/library/item.md +1 -1
- package/fixtures/cases/duplicate-link-definition/schema.yaml +2 -3
- package/fixtures/cases/email-format/expected.json +2 -1
- package/fixtures/cases/email-format/library/companies/acme.md +1 -1
- package/fixtures/cases/email-format/library/deals/renewal.md +49 -24
- package/fixtures/cases/email-format/schema.yaml +10 -11
- package/fixtures/cases/equal-labels/expected.json +5 -0
- package/fixtures/cases/equal-labels/schema.yaml +4 -0
- package/fixtures/cases/fenced-link-definition/library/item.md +1 -1
- package/fixtures/cases/fenced-link-definition/schema.yaml +2 -3
- package/fixtures/cases/field-enum/expected.json +2 -1
- package/fixtures/cases/field-enum/library/item.md +2 -2
- package/fixtures/cases/field-enum/schema.yaml +3 -4
- package/fixtures/cases/integer-field/expected.json +2 -1
- package/fixtures/cases/integer-field/library/companies/acme.md +1 -1
- package/fixtures/cases/integer-field/library/deals/renewal.md +49 -24
- package/fixtures/cases/integer-field/schema.yaml +10 -11
- package/fixtures/cases/json-schema-constructs/library/companies/acme.md +1 -1
- package/fixtures/cases/json-schema-constructs/library/deals/renewal.md +49 -24
- package/fixtures/cases/json-schema-constructs/schema.yaml +10 -11
- package/fixtures/cases/labels-in-the-rooms-language/expected.json +1 -0
- package/fixtures/cases/labels-in-the-rooms-language/library/deals/atlas.md +7 -0
- package/fixtures/cases/labels-in-the-rooms-language/schema.yaml +9 -0
- package/fixtures/cases/lazy-list-item/expected.json +3 -0
- package/fixtures/cases/lazy-list-item/library/item.md +10 -0
- package/fixtures/cases/lazy-list-item/schema.yaml +3 -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/{missing-binary-link → link-into-a-reserved-name-from-an-untyped-document}/expected.json +1 -1
- package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/library/notes/b.md +5 -0
- package/fixtures/cases/list-item-enum/context.json +1 -0
- package/fixtures/cases/list-item-enum/expected.json +7 -0
- package/fixtures/cases/list-item-enum/library/task.md +7 -0
- package/fixtures/cases/list-item-enum/schema.yaml +3 -0
- package/fixtures/cases/list-item-kind/context.json +1 -0
- package/fixtures/cases/list-item-kind/expected.json +7 -0
- package/fixtures/cases/list-item-kind/library/task.md +6 -0
- package/fixtures/cases/list-item-kind/schema.yaml +3 -0
- package/fixtures/cases/list-items/context.json +1 -0
- package/fixtures/cases/list-items/expected.json +1 -0
- package/fixtures/cases/list-items/library/page.md +26 -0
- package/fixtures/cases/list-items/schema.yaml +10 -0
- package/fixtures/cases/list-of-objects-closed/expected.json +2 -1
- package/fixtures/cases/list-of-objects-closed/library/companies/acme.md +1 -1
- package/fixtures/cases/list-of-objects-closed/library/deals/renewal.md +49 -25
- package/fixtures/cases/list-of-objects-closed/schema.yaml +10 -11
- package/fixtures/cases/list-of-objects-item/expected.json +2 -1
- package/fixtures/cases/list-of-objects-item/library/companies/acme.md +1 -1
- package/fixtures/cases/list-of-objects-item/library/deals/renewal.md +49 -24
- package/fixtures/cases/list-of-objects-item/schema.yaml +10 -11
- package/fixtures/cases/list-of-objects-reference/expected.json +2 -1
- package/fixtures/cases/list-of-objects-reference/library/companies/acme.md +1 -1
- package/fixtures/cases/list-of-objects-reference/library/deals/renewal.md +12 -9
- package/fixtures/cases/list-of-objects-reference/library/places/depot.md +1 -1
- package/fixtures/cases/list-of-objects-reference/library/products/seats.md +1 -1
- package/fixtures/cases/list-of-objects-reference/library/products/support.md +1 -1
- package/fixtures/cases/list-reference-path/context.json +1 -0
- package/fixtures/cases/list-reference-path/expected.json +7 -0
- package/fixtures/cases/list-reference-path/library/page.md +5 -0
- package/fixtures/cases/list-reference-path/schema.yaml +3 -0
- package/fixtures/cases/list-reference-type/context.json +1 -0
- package/fixtures/cases/list-reference-type/expected.json +7 -0
- package/fixtures/cases/list-reference-type/library/page.md +6 -0
- package/fixtures/cases/list-reference-type/schema.yaml +3 -0
- package/fixtures/cases/list-size/expected.json +2 -1
- package/fixtures/cases/list-size/library/companies/acme.md +1 -1
- package/fixtures/cases/list-size/library/deals/renewal.md +51 -24
- package/fixtures/cases/list-size/schema.yaml +10 -11
- package/fixtures/cases/long-value-past-six-levels/context.json +1 -0
- package/fixtures/cases/long-value-past-six-levels/expected.json +5 -0
- package/fixtures/cases/long-value-past-six-levels/schema.yaml +15 -0
- package/fixtures/cases/malformed-list/context.json +1 -0
- package/fixtures/cases/malformed-list/expected.json +7 -0
- package/fixtures/cases/{structured-section → malformed-list}/library/item.md +1 -1
- package/fixtures/cases/malformed-list/schema.yaml +6 -0
- package/fixtures/cases/member-document/library/people/ana.md +2 -2
- 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/missing-required-field/library/item.md +1 -1
- package/fixtures/cases/missing-required-field/schema.yaml +3 -4
- package/fixtures/cases/misspelled-key/expected.json +2 -1
- package/fixtures/cases/misspelled-key/library/companies/acme.md +1 -1
- package/fixtures/cases/misspelled-key/library/deals/renewal.md +50 -25
- package/fixtures/cases/misspelled-key/schema.yaml +10 -11
- package/fixtures/cases/name-not-a-string/context.json +1 -0
- package/fixtures/cases/name-not-a-string/expected.json +5 -0
- package/fixtures/cases/name-not-a-string/schema.yaml +5 -0
- package/fixtures/cases/nested-defs/expected.json +2 -1
- package/fixtures/cases/nested-defs/library/deal.md +3 -3
- package/fixtures/cases/nested-object-reference/expected.json +2 -1
- package/fixtures/cases/nested-object-reference/library/companies/acme.md +1 -1
- package/fixtures/cases/nested-object-reference/library/deals/renewal.md +12 -9
- package/fixtures/cases/nested-object-reference/library/places/depot.md +1 -1
- package/fixtures/cases/nested-object-reference/library/products/seats.md +1 -1
- package/fixtures/cases/nested-object-reference/library/products/support.md +1 -1
- package/fixtures/cases/nested-reference/library/companies/acme.md +1 -1
- package/fixtures/cases/nested-reference/library/deals/renewal.md +13 -10
- package/fixtures/cases/nested-reference/library/places/depot.md +1 -1
- package/fixtures/cases/nested-reference/library/products/seats.md +1 -1
- package/fixtures/cases/nested-reference/library/products/support.md +1 -1
- package/fixtures/cases/nested-required-field/expected.json +2 -1
- package/fixtures/cases/nested-required-field/library/companies/acme.md +1 -1
- package/fixtures/cases/nested-required-field/library/deals/renewal.md +48 -23
- package/fixtures/cases/nested-required-field/schema.yaml +10 -11
- package/fixtures/cases/numeric-range/expected.json +2 -1
- package/fixtures/cases/numeric-range/library/companies/acme.md +1 -1
- package/fixtures/cases/numeric-range/library/deals/renewal.md +49 -24
- package/fixtures/cases/numeric-range/schema.yaml +10 -11
- package/fixtures/cases/one-key-two-labels/context.json +1 -0
- package/fixtures/cases/one-key-two-labels/expected.json +5 -0
- package/fixtures/cases/one-key-two-labels/schema.yaml +5 -0
- package/fixtures/cases/one-key-two-types/context.json +1 -0
- package/fixtures/cases/one-key-two-types/expected.json +5 -0
- package/fixtures/cases/one-key-two-types/schema.yaml +4 -0
- package/fixtures/cases/one-of-variant/expected.json +2 -1
- package/fixtures/cases/one-of-variant/library/companies/acme.md +1 -1
- package/fixtures/cases/one-of-variant/library/deals/renewal.md +49 -24
- package/fixtures/cases/one-of-variant/schema.yaml +10 -11
- package/fixtures/cases/other-room-reference/expected.json +2 -1
- package/fixtures/cases/other-room-reference/library/companies/acme.md +1 -1
- package/fixtures/cases/other-room-reference/library/deals/renewal.md +12 -9
- package/fixtures/cases/other-room-reference/library/places/depot.md +1 -1
- package/fixtures/cases/other-room-reference/library/products/seats.md +1 -1
- package/fixtures/cases/other-room-reference/library/products/support.md +1 -1
- package/fixtures/cases/prototype-field/expected.json +2 -1
- package/fixtures/cases/prototype-field/library/item.md +2 -2
- package/fixtures/cases/prototype-field/schema.yaml +2 -3
- package/fixtures/cases/quoted-link-definition/library/notes/draft.md +1 -1
- package/fixtures/cases/reference-into-a-reserved-name/context.json +1 -0
- package/fixtures/cases/reference-into-a-reserved-name/expected.json +7 -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/referenced-missing-file/library/a.md +2 -2
- package/fixtures/cases/referenced-missing-file/library/b.md +2 -2
- package/fixtures/cases/referenced-missing-file/schema.yaml +3 -4
- 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/sections-keyword-refused/context.json +1 -0
- package/fixtures/cases/sections-keyword-refused/expected.json +5 -0
- package/fixtures/cases/{structured-section → sections-keyword-refused}/schema.yaml +1 -2
- package/fixtures/cases/shortcut-reference-link/library/item.md +2 -2
- package/fixtures/cases/shortcut-reference-link/schema.yaml +2 -3
- package/fixtures/cases/string-length/expected.json +2 -1
- package/fixtures/cases/string-length/library/companies/acme.md +1 -1
- package/fixtures/cases/string-length/library/deals/renewal.md +49 -24
- package/fixtures/cases/string-length/schema.yaml +10 -11
- package/fixtures/cases/submission-keys/library/notes/visitor.md +2 -2
- package/fixtures/cases/text-field-kind/expected.json +1 -4
- package/fixtures/cases/text-field-kind/library/page.md +1 -1
- package/fixtures/cases/thematic-break-ends-the-values/context.json +1 -0
- package/fixtures/cases/thematic-break-ends-the-values/expected.json +1 -0
- package/fixtures/cases/thematic-break-ends-the-values/library/item.md +10 -0
- package/fixtures/cases/thematic-break-ends-the-values/schema.yaml +3 -0
- package/fixtures/cases/truncated-link-definition/library/notes/draft.md +1 -1
- 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/types-folder-content/library/types/task.md +1 -1
- package/fixtures/cases/undeclared-field/expected.json +2 -1
- package/fixtures/cases/undeclared-field/library/item.md +2 -2
- package/fixtures/cases/undeclared-field/schema.yaml +2 -3
- package/fixtures/cases/unevaluated-items-closed/expected.json +2 -1
- package/fixtures/cases/unevaluated-items-closed/library/trip.md +13 -3
- 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 +5 -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 +7 -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 +6 -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/cases/unresolved-link/library/item.md +2 -2
- package/fixtures/cases/unresolved-link/schema.yaml +2 -3
- package/fixtures/cases/valid-typed-document/library/people/ada.md +1 -1
- package/fixtures/cases/valid-typed-document/library/tasks/one.md +11 -11
- package/fixtures/cases/valid-typed-document/schema.yaml +5 -6
- package/fixtures/division.json +111 -66
- package/fixtures/forms.json +347 -0
- package/fixtures/preamble.json +26 -5
- package/fixtures/projection.json +121 -18
- package/fixtures/queries.json +964 -0
- package/package.json +19 -3
- package/dist/blocks.d.ts +0 -11
- package/dist/blocks.d.ts.map +0 -1
- package/dist/blocks.js +0 -62
- package/dist/condition.d.ts +0 -137
- package/dist/condition.d.ts.map +0 -1
- package/dist/condition.js +0 -394
- package/dist/links.d.ts +0 -26
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -774
- package/dist/profile.d.ts +0 -6
- package/dist/profile.d.ts.map +0 -1
- package/dist/profile.js +0 -5
- package/dist/sections.d.ts +0 -11
- package/dist/sections.d.ts.map +0 -1
- package/dist/sections.js +0 -57
- package/fixtures/cases/missing-section-item-kind/expected.json +0 -5
- package/fixtures/cases/missing-section-item-kind/schema.yaml +0 -6
- package/fixtures/cases/null-refused/expected.json +0 -6
- package/fixtures/cases/null-refused/library/companies/acme.md +0 -4
- package/fixtures/cases/null-refused/library/deals/renewal.md +0 -31
- package/fixtures/cases/null-refused/schema.yaml +0 -56
- package/fixtures/cases/open-map-value/expected.json +0 -6
- package/fixtures/cases/open-map-value/library/companies/acme.md +0 -4
- package/fixtures/cases/open-map-value/library/deals/renewal.md +0 -31
- package/fixtures/cases/open-map-value/schema.yaml +0 -56
- package/fixtures/cases/section-item-enum/expected.json +0 -6
- package/fixtures/cases/section-item-enum/library/task.md +0 -8
- package/fixtures/cases/section-item-enum/schema.yaml +0 -3
- package/fixtures/cases/section-item-kind/expected.json +0 -6
- package/fixtures/cases/section-item-kind/library/task.md +0 -8
- package/fixtures/cases/section-item-kind/schema.yaml +0 -3
- package/fixtures/cases/section-items/library/page.md +0 -42
- package/fixtures/cases/section-items/schema.yaml +0 -10
- package/fixtures/cases/section-reference-path/expected.json +0 -6
- package/fixtures/cases/section-reference-path/library/page.md +0 -7
- package/fixtures/cases/section-reference-path/schema.yaml +0 -3
- package/fixtures/cases/section-reference-type/expected.json +0 -6
- package/fixtures/cases/section-reference-type/library/page.md +0 -7
- package/fixtures/cases/section-reference-type/schema.yaml +0 -3
- package/fixtures/cases/structured-section/expected.json +0 -6
- /package/fixtures/cases/{missing-section-item-kind → absent-link-dangles}/context.json +0 -0
- /package/fixtures/cases/{section-items → absent-link-dangles}/expected.json +0 -0
- /package/fixtures/cases/{null-refused → absolute-link}/context.json +0 -0
- /package/fixtures/cases/{missing-binary-image → binary-image-dangles}/context.json +0 -0
- /package/fixtures/cases/{missing-binary-image → binary-image-dangles}/library/notes/draft.md +0 -0
- /package/fixtures/cases/{missing-binary-image → binary-image-dangles}/schema.yaml +0 -0
- /package/fixtures/cases/{missing-binary-link → binary-link-dangles}/context.json +0 -0
- /package/fixtures/cases/{missing-binary-link → binary-link-dangles}/library/notes/draft.md +0 -0
- /package/fixtures/cases/{missing-binary-link → binary-link-dangles}/schema.yaml +0 -0
- /package/fixtures/cases/{open-map-value → conditional-long-text}/context.json +0 -0
- /package/fixtures/cases/{section-item-enum → cross-room-link}/context.json +0 -0
- /package/fixtures/cases/{section-item-kind → cross-room-reference}/context.json +0 -0
- /package/fixtures/cases/{section-items → equal-labels}/context.json +0 -0
- /package/fixtures/cases/{section-reference-path → labels-in-the-rooms-language}/context.json +0 -0
- /package/fixtures/cases/{section-reference-type → lazy-list-item}/context.json +0 -0
- /package/fixtures/cases/{structured-section → link-into-a-reserved-name-from-an-untyped-document}/context.json +0 -0
- /package/fixtures/cases/{section-items → list-items}/library/other.md +0 -0
- /package/fixtures/cases/{section-reference-path → list-reference-path}/library/other.md +0 -0
- /package/fixtures/cases/{section-reference-type → list-reference-type}/library/note.md +0 -0
package/dist/definition.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD } from './fields.js';
|
|
1
|
+
import { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
|
|
2
|
+
import { MEDIA_TYPES } from './media-type.js';
|
|
3
|
+
import { linearPattern } from './pattern.js';
|
|
2
4
|
import { equalValue, isRecord, jsValue, parseYamlMapping, YamlError } from './yaml.js';
|
|
3
5
|
export const JSON_TYPES = [
|
|
4
6
|
'string',
|
|
@@ -11,17 +13,34 @@ export const JSON_TYPES = [
|
|
|
11
13
|
];
|
|
12
14
|
export const BUILT_IN_TYPE = 'any';
|
|
13
15
|
export const ATTACHMENT = 'attachment';
|
|
14
|
-
const
|
|
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
|
+
export const OPENING = ['additionalProperties', 'unevaluatedProperties'];
|
|
28
|
+
const FIELD_RULES = ['change_roles', 'initial_roles', 'transitions'];
|
|
29
|
+
const PROVIDED_KEYWORDS = ['create_roles', 'delete_roles'];
|
|
30
|
+
const NO_TYPES = Object.freeze({ types: Object.freeze({}) });
|
|
15
31
|
const DEFS_REFERENCE = '#/$defs/';
|
|
32
|
+
const UNBOUNDED_FORMAT = 'url';
|
|
33
|
+
const UNIONS = ['anyOf', 'oneOf'];
|
|
16
34
|
const UNRESOLVED = /[\u0000-\u001f\u007f%[\]\\^{|}]|\s$/u;
|
|
17
35
|
export const ARRAY_INDEX = /^(?:0|[1-9][0-9]*)$/u;
|
|
36
|
+
export const JSON_POINTER = /^(?:\/(?:[^~/]|~[01])*)*$/u;
|
|
18
37
|
const HOUSE_KEYS = {
|
|
19
|
-
|
|
38
|
+
[TYPE_FIELD]: { prose: false },
|
|
20
39
|
[SITE_FIELD]: { prose: false },
|
|
21
40
|
[RECEIVED_FIELD]: { prose: false },
|
|
22
41
|
};
|
|
23
|
-
function refuse(rule, location) {
|
|
24
|
-
return
|
|
42
|
+
export function refuse(rule, location) {
|
|
43
|
+
return { rule, location };
|
|
25
44
|
}
|
|
26
45
|
export function escapePointer(key) {
|
|
27
46
|
return key.replaceAll('~', '~0').replaceAll('/', '~1');
|
|
@@ -33,12 +52,12 @@ export function pointerSegments(pointer) {
|
|
|
33
52
|
return pointer.split('/').slice(1).map(unescapePointer);
|
|
34
53
|
}
|
|
35
54
|
export function refTarget(reference, defs) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (segments.some((segment) => escapePointer(unescapePointer(segment)) !== segment))
|
|
55
|
+
const pointer = reference.slice('#'.length);
|
|
56
|
+
if (!reference.startsWith(DEFS_REFERENCE) ||
|
|
57
|
+
UNRESOLVED.test(reference) ||
|
|
58
|
+
!JSON_POINTER.test(pointer))
|
|
41
59
|
return undefined;
|
|
60
|
+
const [, name = '', ...rest] = pointerSegments(pointer);
|
|
42
61
|
if (!Object.hasOwn(defs, name))
|
|
43
62
|
return undefined;
|
|
44
63
|
let node = defs[name];
|
|
@@ -69,15 +88,7 @@ export function refTarget(reference, defs) {
|
|
|
69
88
|
return { name, node };
|
|
70
89
|
}
|
|
71
90
|
function compiles(pattern) {
|
|
72
|
-
|
|
73
|
-
return false;
|
|
74
|
-
try {
|
|
75
|
-
new RegExp(pattern, 'u');
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
catch {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
91
|
+
return typeof pattern === 'string' && linearPattern(pattern) !== null;
|
|
81
92
|
}
|
|
82
93
|
function finite(value) {
|
|
83
94
|
return typeof value === 'number' && Number.isFinite(value);
|
|
@@ -91,7 +102,7 @@ function strings(value) {
|
|
|
91
102
|
new Set(value).size === value.length);
|
|
92
103
|
}
|
|
93
104
|
function schemaFailure(value, at, context) {
|
|
94
|
-
if (typeof value === 'boolean')
|
|
105
|
+
if (!context.checked || typeof value === 'boolean')
|
|
95
106
|
return undefined;
|
|
96
107
|
if (!isRecord(value))
|
|
97
108
|
return refuse('schema', at);
|
|
@@ -187,7 +198,7 @@ const KEYWORDS = {
|
|
|
187
198
|
uniqueItems: FLAG,
|
|
188
199
|
required: strings,
|
|
189
200
|
dependentRequired: (value) => isRecord(value) && Object.values(value).every(strings),
|
|
190
|
-
format:
|
|
201
|
+
format: (value) => typeof value === 'string' && value !== UNBOUNDED_FORMAT,
|
|
191
202
|
contentEncoding: TEXT,
|
|
192
203
|
contentMediaType: TEXT,
|
|
193
204
|
title: TEXT,
|
|
@@ -204,8 +215,12 @@ const KEYWORDS = {
|
|
|
204
215
|
return (Array.isArray(named) &&
|
|
205
216
|
named.length > 0 &&
|
|
206
217
|
strings(named) &&
|
|
207
|
-
named.every((name) => name === BUILT_IN_TYPE ||
|
|
218
|
+
named.every((name) => name === BUILT_IN_TYPE ||
|
|
219
|
+
name === ATTACHMENT ||
|
|
220
|
+
context.types.has(name) ||
|
|
221
|
+
node.cross_room === true));
|
|
208
222
|
},
|
|
223
|
+
cross_room: (value, _at, node) => typeof value === 'boolean' && node.reference !== undefined,
|
|
209
224
|
};
|
|
210
225
|
function sharedType(values) {
|
|
211
226
|
if (values.length === 0)
|
|
@@ -234,60 +249,90 @@ function firstOf(held, read) {
|
|
|
234
249
|
}
|
|
235
250
|
return undefined;
|
|
236
251
|
}
|
|
237
|
-
function conjoined(
|
|
252
|
+
export function conjoined(declared, defs, ancestry) {
|
|
238
253
|
const held = [];
|
|
239
254
|
const reached = new Set(ancestry);
|
|
240
|
-
const visit = (node) => {
|
|
241
|
-
if (!isRecord(node) || held.
|
|
255
|
+
const visit = (node, at) => {
|
|
256
|
+
if (!isRecord(node) || held.some((one) => one.node === node))
|
|
242
257
|
return;
|
|
243
|
-
held.push(node);
|
|
258
|
+
held.push({ node, at });
|
|
244
259
|
if (typeof node.$ref === 'string') {
|
|
245
260
|
const target = refTarget(node.$ref, defs)?.node;
|
|
246
261
|
if (target !== undefined && !reached.has(target)) {
|
|
247
262
|
reached.add(target);
|
|
248
|
-
visit(target);
|
|
263
|
+
visit(target, node.$ref.slice('#'.length));
|
|
249
264
|
}
|
|
250
265
|
}
|
|
251
266
|
if (Array.isArray(node.allOf))
|
|
252
|
-
|
|
253
|
-
visit(one);
|
|
267
|
+
node.allOf.forEach((one, index) => visit(one, `${at}/allOf/${index}`));
|
|
254
268
|
};
|
|
255
|
-
for (const node of
|
|
256
|
-
visit(node);
|
|
269
|
+
for (const { node, at } of declared)
|
|
270
|
+
visit(node, at);
|
|
257
271
|
return { held, ancestry: reached };
|
|
258
272
|
}
|
|
259
|
-
function variantsOf(node) {
|
|
273
|
+
export function variantsOf({ node, at }) {
|
|
274
|
+
const listed = (keyword) => {
|
|
275
|
+
const branches = node[keyword];
|
|
276
|
+
return Array.isArray(branches)
|
|
277
|
+
? branches.map((branch, index) => ({ node: branch, at: `${at}/${keyword}/${index}` }))
|
|
278
|
+
: [];
|
|
279
|
+
};
|
|
260
280
|
return [
|
|
261
|
-
...(
|
|
262
|
-
...(
|
|
263
|
-
node.then,
|
|
264
|
-
node.else,
|
|
265
|
-
...(isRecord(node.dependentSchemas) ?
|
|
266
|
-
].filter(isRecord);
|
|
281
|
+
...listed('anyOf'),
|
|
282
|
+
...listed('oneOf'),
|
|
283
|
+
{ node: node.then, at: `${at}/then` },
|
|
284
|
+
{ node: node.else, at: `${at}/else` },
|
|
285
|
+
...Object.entries(isRecord(node.dependentSchemas) ? node.dependentSchemas : {}).map(([key, branch]) => ({ node: branch, at: `${at}/dependentSchemas/${escapePointer(key)}` })),
|
|
286
|
+
].filter((one) => isRecord(one.node));
|
|
267
287
|
}
|
|
268
288
|
function united(left, right) {
|
|
269
289
|
if (left === undefined || right === undefined)
|
|
270
290
|
return undefined;
|
|
271
291
|
return [...left, ...right.filter((value) => !left.some((held) => equalValue(held, value)))];
|
|
272
292
|
}
|
|
293
|
+
function both(left, right) {
|
|
294
|
+
return left !== undefined && right !== undefined ? joined(left, right) : undefined;
|
|
295
|
+
}
|
|
273
296
|
function joined(left, right) {
|
|
274
297
|
const type = left.type === right.type ? left.type : undefined;
|
|
275
298
|
const format = left.format === right.format ? left.format : undefined;
|
|
276
299
|
const values = united(left.values, right.values);
|
|
277
300
|
const reference = united(left.reference, right.reference);
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
301
|
+
const crossRoom = left.crossRoom === true || right.crossRoom === true;
|
|
302
|
+
const items = both(left.items, right.items);
|
|
303
|
+
const prefix = left.prefix === undefined && right.prefix === undefined
|
|
304
|
+
? undefined
|
|
305
|
+
: Array.from({ length: Math.max(left.prefix?.length ?? 0, right.prefix?.length ?? 0) }, (_, index) => both(itemFacts(left, index), itemFacts(right, index)) ?? { prose: false });
|
|
306
|
+
const properties = Object.create(null);
|
|
307
|
+
for (const [name, facts] of Object.entries(left.properties ?? {})) {
|
|
308
|
+
const shared = both(facts, right.properties?.[name]);
|
|
309
|
+
if (shared !== undefined)
|
|
310
|
+
properties[name] = shared;
|
|
311
|
+
}
|
|
312
|
+
const patterns = (left.patterns ?? []).flatMap(({ pattern, facts }) => {
|
|
313
|
+
const shared = both(facts, right.patterns?.find((one) => one.pattern === pattern)?.facts);
|
|
314
|
+
return shared === undefined ? [] : [{ pattern, facts: shared }];
|
|
315
|
+
});
|
|
316
|
+
const additional = both(left.additional, right.additional);
|
|
317
|
+
const title = left.title ?? right.title;
|
|
281
318
|
return {
|
|
282
319
|
...(type === undefined ? {} : { type }),
|
|
283
320
|
...(format === undefined ? {} : { format }),
|
|
284
321
|
...(values === undefined ? {} : { values }),
|
|
285
322
|
...(reference === undefined ? {} : { reference }),
|
|
323
|
+
...(reference !== undefined && crossRoom ? { crossRoom: true } : {}),
|
|
286
324
|
prose: left.prose && right.prose,
|
|
325
|
+
...(title === undefined ? {} : { title }),
|
|
326
|
+
...(left.markdown === true || right.markdown === true ? { markdown: true } : {}),
|
|
327
|
+
...(left.json === true || right.json === true ? { json: true } : {}),
|
|
328
|
+
...(prefix === undefined ? {} : { prefix }),
|
|
287
329
|
...(items === undefined ? {} : { items }),
|
|
330
|
+
...(Object.keys(properties).length === 0 ? {} : { properties }),
|
|
331
|
+
...(patterns.length === 0 ? {} : { patterns }),
|
|
332
|
+
...(additional === undefined ? {} : { additional }),
|
|
288
333
|
};
|
|
289
334
|
}
|
|
290
|
-
function propertiesOf(held, defs, ancestry) {
|
|
335
|
+
function propertiesOf(held, variants, defs, ancestry) {
|
|
291
336
|
const declared = new Map();
|
|
292
337
|
for (const node of held) {
|
|
293
338
|
if (!isRecord(node.properties))
|
|
@@ -298,58 +343,173 @@ function propertiesOf(held, defs, ancestry) {
|
|
|
298
343
|
const properties = Object.create(null);
|
|
299
344
|
for (const [name, schemas] of declared)
|
|
300
345
|
properties[name] = factsOf(schemas, defs, ancestry);
|
|
301
|
-
const
|
|
302
|
-
for (const branch of
|
|
303
|
-
for (const [name, facts] of Object.entries(
|
|
346
|
+
const conditional = Object.create(null);
|
|
347
|
+
for (const branch of variants.values()) {
|
|
348
|
+
for (const [name, facts] of Object.entries(branch.properties ?? {})) {
|
|
304
349
|
if (Object.hasOwn(properties, name))
|
|
305
350
|
continue;
|
|
306
|
-
|
|
351
|
+
conditional[name] = Object.hasOwn(conditional, name)
|
|
352
|
+
? joined(conditional[name], facts)
|
|
353
|
+
: facts;
|
|
307
354
|
}
|
|
308
355
|
}
|
|
309
|
-
Object.
|
|
356
|
+
for (const [name, facts] of Object.entries(conditional))
|
|
357
|
+
properties[name] = { ...facts, conditional: true };
|
|
310
358
|
return Object.keys(properties).length === 0 ? undefined : properties;
|
|
311
359
|
}
|
|
360
|
+
function nullOnly(facts) {
|
|
361
|
+
return facts.type === 'null' || (facts.values?.every((value) => value === null) ?? false);
|
|
362
|
+
}
|
|
363
|
+
function alternativesOf(held, variants) {
|
|
364
|
+
return held.flatMap((node) => [node.anyOf, node.oneOf].flatMap((branches) => {
|
|
365
|
+
if (!Array.isArray(branches))
|
|
366
|
+
return [];
|
|
367
|
+
const kept = branches
|
|
368
|
+
.flatMap((branch) => {
|
|
369
|
+
const facts = isRecord(branch) ? variants.get(branch) : undefined;
|
|
370
|
+
return facts === undefined ? [] : [facts];
|
|
371
|
+
})
|
|
372
|
+
.filter((facts) => !nullOnly(facts));
|
|
373
|
+
return kept.length === 0 ? [] : [kept];
|
|
374
|
+
}));
|
|
375
|
+
}
|
|
376
|
+
function inheritedOf(held) {
|
|
377
|
+
return held.flatMap((node) => {
|
|
378
|
+
const kept = Object.fromEntries(['type', 'items', 'prefixItems'].flatMap((key) => node[key] === undefined ? [] : [[key, node[key]]]));
|
|
379
|
+
return Object.keys(kept).length === 0 ? [] : [kept];
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
function typeSet(type) {
|
|
383
|
+
const listed = typeof type === 'string' ? [type] : Array.isArray(type) ? type : null;
|
|
384
|
+
return listed === null
|
|
385
|
+
? null
|
|
386
|
+
: new Set(listed.map((one) => (one === 'integer' ? 'number' : String(one))));
|
|
387
|
+
}
|
|
388
|
+
function valueType(value) {
|
|
389
|
+
if (value === null)
|
|
390
|
+
return 'null';
|
|
391
|
+
if (Array.isArray(value))
|
|
392
|
+
return 'array';
|
|
393
|
+
return typeof value;
|
|
394
|
+
}
|
|
395
|
+
function narrowed(left, right) {
|
|
396
|
+
if (left === null)
|
|
397
|
+
return right;
|
|
398
|
+
if (right === null)
|
|
399
|
+
return left;
|
|
400
|
+
return new Set([...left].filter((one) => right.has(one)));
|
|
401
|
+
}
|
|
402
|
+
function admitted(nodes, defs, ancestry) {
|
|
403
|
+
const conjunction = conjoined(nodes.map((node) => ({ node, at: '' })), defs, ancestry);
|
|
404
|
+
let kept = null;
|
|
405
|
+
for (const { node } of conjunction.held) {
|
|
406
|
+
kept = narrowed(kept, typeSet(node.type));
|
|
407
|
+
if (Array.isArray(node.enum))
|
|
408
|
+
kept = narrowed(kept, new Set(node.enum.map(valueType)));
|
|
409
|
+
if (Object.hasOwn(node, 'const'))
|
|
410
|
+
kept = narrowed(kept, new Set([valueType(node.const)]));
|
|
411
|
+
for (const keyword of UNIONS) {
|
|
412
|
+
const branches = node[keyword];
|
|
413
|
+
if (!Array.isArray(branches))
|
|
414
|
+
continue;
|
|
415
|
+
let union = new Set();
|
|
416
|
+
for (const branch of branches) {
|
|
417
|
+
const one = admitted([branch], defs, conjunction.ancestry);
|
|
418
|
+
if (one === null) {
|
|
419
|
+
union = null;
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
for (const type of one)
|
|
423
|
+
union.add(type);
|
|
424
|
+
}
|
|
425
|
+
kept = narrowed(kept, union);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return kept;
|
|
429
|
+
}
|
|
430
|
+
function structuredUnion(held, defs, ancestry) {
|
|
431
|
+
return held.some((node) => UNIONS.some((keyword) => Array.isArray(node[keyword]) &&
|
|
432
|
+
node[keyword].some((branch) => {
|
|
433
|
+
const types = admitted([branch], defs, ancestry);
|
|
434
|
+
return types === null || types.has('object') || types.has('array');
|
|
435
|
+
})));
|
|
436
|
+
}
|
|
437
|
+
function openWhole(held) {
|
|
438
|
+
return held.some((node) => OPENING.some((keyword) => node[keyword] === true));
|
|
439
|
+
}
|
|
440
|
+
function writtenAsJson(held, defs, ancestry) {
|
|
441
|
+
const types = admitted(held, defs, ancestry);
|
|
442
|
+
if (types === null || types.size !== 1)
|
|
443
|
+
return true;
|
|
444
|
+
return structuredUnion(held, defs, ancestry) || (types.has('object') && openWhole(held));
|
|
445
|
+
}
|
|
312
446
|
function factsOf(nodes, defs, ancestry) {
|
|
313
|
-
const {
|
|
314
|
-
const
|
|
447
|
+
const conjunction = conjoined(nodes.map((node) => ({ node, at: '' })), defs, ancestry);
|
|
448
|
+
const reached = conjunction.ancestry;
|
|
449
|
+
const held = conjunction.held.map(({ node }) => node);
|
|
450
|
+
const inherited = inheritedOf(held);
|
|
451
|
+
const variants = new Map(conjunction.held
|
|
452
|
+
.flatMap(variantsOf)
|
|
453
|
+
.map(({ node: branch }) => [branch, factsOf([branch, ...inherited], defs, reached)]));
|
|
454
|
+
const unions = alternativesOf(held, variants);
|
|
455
|
+
const alternatives = unions.map((kept) => kept.reduce(joined));
|
|
456
|
+
const listed = [
|
|
457
|
+
...held.flatMap((node) => Array.isArray(node.enum) ? [node.enum] : node.const !== undefined ? [[node.const]] : []),
|
|
458
|
+
...alternatives.flatMap((facts) => (facts.values === undefined ? [] : [facts.values])),
|
|
459
|
+
];
|
|
315
460
|
const values = listed.length === 0
|
|
316
461
|
? undefined
|
|
317
462
|
: listed.reduce((kept, list) => kept.filter((value) => list.some((other) => equalValue(other, value))));
|
|
318
463
|
const type = firstOf(held, (node) => singleType(node.type)) ??
|
|
319
|
-
(values === undefined ? undefined : sharedType(values))
|
|
464
|
+
(values === undefined ? undefined : sharedType(values)) ??
|
|
465
|
+
alternatives.find((facts) => facts.type !== undefined)?.type;
|
|
320
466
|
const reference = firstOf(held, (node) => typeof node.reference === 'string'
|
|
321
467
|
? [node.reference]
|
|
322
468
|
: Array.isArray(node.reference)
|
|
323
469
|
? node.reference
|
|
324
|
-
: undefined);
|
|
325
|
-
const
|
|
470
|
+
: undefined) ?? alternatives.find((facts) => facts.reference !== undefined)?.reference;
|
|
471
|
+
const crossRoom = firstOf(held, (node) => node.reference === undefined ? undefined : node.cross_room === true) ?? alternatives.find((facts) => facts.reference !== undefined)?.crossRoom === true;
|
|
472
|
+
const format = firstOf(held, (node) => (typeof node.format === 'string' ? node.format : undefined)) ??
|
|
473
|
+
alternatives.find((facts) => facts.format !== undefined)?.format;
|
|
326
474
|
const prose = type === 'string' &&
|
|
327
475
|
values === undefined &&
|
|
328
476
|
format === undefined &&
|
|
329
477
|
reference === undefined &&
|
|
330
|
-
held.every((node) => node.pattern === undefined)
|
|
478
|
+
held.every((node) => node.pattern === undefined) &&
|
|
479
|
+
unions.every((kept) => kept.every((facts) => facts.type !== 'string' || facts.prose));
|
|
331
480
|
const listedItems = held.flatMap((node) => (node.items === undefined ? [] : [node.items]));
|
|
332
|
-
const items = type
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
481
|
+
const items = type !== 'array'
|
|
482
|
+
? undefined
|
|
483
|
+
: (alternatives.find((facts) => facts.items !== undefined)?.items ??
|
|
484
|
+
(listedItems.length > 0 ? factsOf(listedItems, defs, reached) : undefined));
|
|
485
|
+
const tuples = held.flatMap((node) => Array.isArray(node.prefixItems) ? [node.prefixItems] : []);
|
|
486
|
+
const prefix = type !== 'array'
|
|
487
|
+
? undefined
|
|
488
|
+
: (alternatives.find((facts) => facts.prefix !== undefined)?.prefix ??
|
|
489
|
+
(tuples.length === 0
|
|
490
|
+
? undefined
|
|
491
|
+
: Array.from({ length: Math.max(...tuples.map((tuple) => tuple.length)) }, (_, index) => factsOf(tuples.flatMap((tuple) => (index < tuple.length ? [tuple[index]] : [])), defs, reached))));
|
|
338
492
|
const mapped = type === 'object' || type === undefined;
|
|
339
|
-
const properties = mapped ? propertiesOf(held, defs, reached) : undefined;
|
|
493
|
+
const properties = mapped ? propertiesOf(held, variants, defs, reached) : undefined;
|
|
340
494
|
const patterns = mapped
|
|
341
495
|
? held.flatMap((node) => Object.entries(isRecord(node.patternProperties) ? node.patternProperties : {}).map(([pattern, schema]) => ({ pattern, facts: factsOf([schema], defs, reached) })))
|
|
342
496
|
: [];
|
|
343
497
|
const opened = mapped
|
|
344
|
-
? held.flatMap((node) =>
|
|
498
|
+
? held.flatMap((node) => OPENING.map((keyword) => (node[keyword] === true ? {} : node[keyword])).filter(isRecord))
|
|
345
499
|
: [];
|
|
346
500
|
const additional = opened.length === 0 ? undefined : factsOf(opened, defs, reached);
|
|
501
|
+
const title = firstOf(nodes.filter(isRecord), (node) => typeof node.title === 'string' ? node.title : undefined);
|
|
502
|
+
const markdown = held.some((node) => node.contentMediaType === MEDIA_TYPES.markdown);
|
|
347
503
|
return {
|
|
348
504
|
...(type === undefined ? {} : { type }),
|
|
349
505
|
...(format === undefined ? {} : { format }),
|
|
350
506
|
...(values === undefined ? {} : { values }),
|
|
351
507
|
...(reference === undefined ? {} : { reference }),
|
|
508
|
+
...(reference !== undefined && crossRoom ? { crossRoom: true } : {}),
|
|
352
509
|
prose,
|
|
510
|
+
...(title === undefined ? {} : { title }),
|
|
511
|
+
...(markdown ? { markdown: true } : {}),
|
|
512
|
+
...(writtenAsJson(held, defs, ancestry) ? { json: true } : {}),
|
|
353
513
|
...(prefix === undefined ? {} : { prefix }),
|
|
354
514
|
...(items === undefined ? {} : { items }),
|
|
355
515
|
...(properties === undefined ? {} : { properties }),
|
|
@@ -366,9 +526,57 @@ export function itemFacts(facts, index) {
|
|
|
366
526
|
export function memberFacts(facts, key) {
|
|
367
527
|
if (facts.properties !== undefined && Object.hasOwn(facts.properties, key))
|
|
368
528
|
return facts.properties[key];
|
|
369
|
-
const pattern = facts.patterns?.find((one) =>
|
|
529
|
+
const pattern = facts.patterns?.find((one) => linearPattern(one.pattern).test(key));
|
|
370
530
|
return pattern === undefined ? facts.additional : pattern.facts;
|
|
371
531
|
}
|
|
532
|
+
export function crossedFacts(facts) {
|
|
533
|
+
if (facts.type !== 'array')
|
|
534
|
+
return [facts];
|
|
535
|
+
return [...(facts.prefix ?? []), ...(facts.items === undefined ? [] : [facts.items])].flatMap(crossedFacts);
|
|
536
|
+
}
|
|
537
|
+
export function fieldFacts(definition, key) {
|
|
538
|
+
if (Object.hasOwn(definition.fields, key))
|
|
539
|
+
return definition.fields[key];
|
|
540
|
+
if (Object.hasOwn(HOUSE_KEYS, key))
|
|
541
|
+
return undefined;
|
|
542
|
+
return memberFacts(definition.frontmatter, key);
|
|
543
|
+
}
|
|
544
|
+
function stepped({ facts, through, conditional }, token) {
|
|
545
|
+
if (facts.type === 'array' && ARRAY_INDEX.test(token)) {
|
|
546
|
+
const item = itemFacts(facts, Number(token));
|
|
547
|
+
return item === undefined ? [] : [{ facts: item, through, conditional }];
|
|
548
|
+
}
|
|
549
|
+
return crossedFacts(facts).flatMap((crossed) => {
|
|
550
|
+
const member = memberFacts(crossed, token);
|
|
551
|
+
return member === undefined
|
|
552
|
+
? []
|
|
553
|
+
: [
|
|
554
|
+
{
|
|
555
|
+
facts: member,
|
|
556
|
+
through: through || facts.type === 'array',
|
|
557
|
+
conditional: conditional || member.conditional === true,
|
|
558
|
+
},
|
|
559
|
+
];
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
export function pointerFacts(definition, pointer) {
|
|
563
|
+
const [field, ...rest] = pointerSegments(pointer);
|
|
564
|
+
const declared = field === undefined ? undefined : fieldFacts(definition, field);
|
|
565
|
+
if (declared === undefined)
|
|
566
|
+
return undefined;
|
|
567
|
+
let reached = [
|
|
568
|
+
{ facts: declared, through: false, conditional: declared.conditional === true },
|
|
569
|
+
];
|
|
570
|
+
for (const token of rest)
|
|
571
|
+
reached = reached.flatMap((held) => stepped(held, token));
|
|
572
|
+
if (reached.length === 0)
|
|
573
|
+
return undefined;
|
|
574
|
+
return reached.reduce((kept, held) => ({
|
|
575
|
+
facts: joined(kept.facts, held.facts),
|
|
576
|
+
through: kept.through || held.through,
|
|
577
|
+
conditional: kept.conditional || held.conditional,
|
|
578
|
+
}));
|
|
579
|
+
}
|
|
372
580
|
function reachedDefs(value, defs, reached) {
|
|
373
581
|
if (Array.isArray(value)) {
|
|
374
582
|
for (const item of value)
|
|
@@ -389,37 +597,60 @@ function reachedDefs(value, defs, reached) {
|
|
|
389
597
|
reachedDefs(held, defs, reached);
|
|
390
598
|
}
|
|
391
599
|
}
|
|
392
|
-
function
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
const where = `${at}/${escapePointer(name)}`;
|
|
399
|
-
if (!isRecord(spec) || (spec.kind !== 'text' && spec.kind !== 'list'))
|
|
400
|
-
return failed('sections', where);
|
|
401
|
-
const allowed = spec.kind === 'list' ? ['kind', 'required', 'items'] : ['kind', 'required'];
|
|
402
|
-
const extra = Object.keys(spec).find((key) => !allowed.includes(key));
|
|
403
|
-
if (extra !== undefined)
|
|
404
|
-
return failed('sections', `${where}/${escapePointer(extra)}`);
|
|
405
|
-
if (spec.required !== undefined && typeof spec.required !== 'boolean')
|
|
406
|
-
return failed('sections', `${where}/required`);
|
|
407
|
-
const required = spec.required === true;
|
|
408
|
-
if (spec.kind === 'text') {
|
|
409
|
-
sections[name] = { kind: 'text', required };
|
|
600
|
+
function untitledSchema(node) {
|
|
601
|
+
if (!isRecord(node))
|
|
602
|
+
return node;
|
|
603
|
+
const kept = {};
|
|
604
|
+
for (const [key, held] of Object.entries(node)) {
|
|
605
|
+
if (key === 'title' && typeof held === 'string')
|
|
410
606
|
continue;
|
|
411
|
-
|
|
412
|
-
if (
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
sections[name] = { kind: 'list', required, items };
|
|
607
|
+
const check = Object.hasOwn(KEYWORDS, key) ? KEYWORDS[key] : undefined;
|
|
608
|
+
if (check === SCHEMA)
|
|
609
|
+
kept[key] = untitledSchema(held);
|
|
610
|
+
else if (check === SCHEMA_LIST && Array.isArray(held))
|
|
611
|
+
kept[key] = held.map(untitledSchema);
|
|
612
|
+
else if (check === SCHEMA_MAP && isRecord(held))
|
|
613
|
+
kept[key] = untitledMap(held);
|
|
614
|
+
else
|
|
615
|
+
kept[key] = held;
|
|
421
616
|
}
|
|
422
|
-
return
|
|
617
|
+
return kept;
|
|
618
|
+
}
|
|
619
|
+
function untitledMap(map) {
|
|
620
|
+
return Object.fromEntries(Object.entries(map).map(([key, held]) => [key, untitledSchema(held)]));
|
|
621
|
+
}
|
|
622
|
+
function untitledFacts(facts) {
|
|
623
|
+
const { title: _title, prefix, items, properties, patterns, additional, ...kept } = facts;
|
|
624
|
+
return {
|
|
625
|
+
...kept,
|
|
626
|
+
...(prefix === undefined ? {} : { prefix: prefix.map(untitledFacts) }),
|
|
627
|
+
...(items === undefined ? {} : { items: untitledFacts(items) }),
|
|
628
|
+
...(properties === undefined
|
|
629
|
+
? {}
|
|
630
|
+
: {
|
|
631
|
+
properties: Object.fromEntries(Object.entries(properties).map(([key, held]) => [key, untitledFacts(held)])),
|
|
632
|
+
}),
|
|
633
|
+
...(patterns === undefined
|
|
634
|
+
? {}
|
|
635
|
+
: {
|
|
636
|
+
patterns: patterns.map(({ pattern, facts: held }) => ({
|
|
637
|
+
pattern,
|
|
638
|
+
facts: untitledFacts(held),
|
|
639
|
+
})),
|
|
640
|
+
}),
|
|
641
|
+
...(additional === undefined ? {} : { additional: untitledFacts(additional) }),
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
export function untitled(definition) {
|
|
645
|
+
return {
|
|
646
|
+
...definition,
|
|
647
|
+
frontmatter: untitledFacts(definition.frontmatter),
|
|
648
|
+
fields: Object.fromEntries(Object.entries(definition.fields).map(([key, held]) => [key, untitledFacts(held)])),
|
|
649
|
+
shape: {
|
|
650
|
+
schema: untitledSchema(definition.shape.schema),
|
|
651
|
+
defs: untitledMap(definition.shape.defs),
|
|
652
|
+
},
|
|
653
|
+
};
|
|
423
654
|
}
|
|
424
655
|
function deepFreeze(value) {
|
|
425
656
|
if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
|
|
@@ -429,21 +660,150 @@ function deepFreeze(value) {
|
|
|
429
660
|
}
|
|
430
661
|
return value;
|
|
431
662
|
}
|
|
663
|
+
function ruleValue(value) {
|
|
664
|
+
return value === null || typeof value === 'string' || typeof value === 'boolean' || finite(value);
|
|
665
|
+
}
|
|
666
|
+
function roleNames(value) {
|
|
667
|
+
return strings(value) && value.every((name) => name !== '');
|
|
668
|
+
}
|
|
669
|
+
function compositesOf(value) {
|
|
670
|
+
return Array.isArray(value) ? ['array'] : isRecord(value) ? ['object'] : [];
|
|
671
|
+
}
|
|
672
|
+
function typed(type) {
|
|
673
|
+
const types = typeof type === 'string' ? [type] : type;
|
|
674
|
+
return Array.isArray(types) ? COMPOSITES.filter((kind) => types.includes(kind)) : undefined;
|
|
675
|
+
}
|
|
676
|
+
function admittedWhole(node) {
|
|
677
|
+
if (node === true)
|
|
678
|
+
return COMPOSITES;
|
|
679
|
+
if (!isRecord(node) || Object.keys(node).some((key) => key !== 'type' && !ANNOTATIONS.has(key)))
|
|
680
|
+
return [];
|
|
681
|
+
return typed(node.type) ?? COMPOSITES;
|
|
682
|
+
}
|
|
683
|
+
function composites(node, defs, seen) {
|
|
684
|
+
if (node === false)
|
|
685
|
+
return [];
|
|
686
|
+
if (!isRecord(node))
|
|
687
|
+
return COMPOSITES;
|
|
688
|
+
const each = (nodes) => Array.isArray(nodes) ? nodes.map((one) => composites(one, defs, seen)) : [];
|
|
689
|
+
const target = typeof node.$ref === 'string' ? refTarget(node.$ref, defs)?.node : undefined;
|
|
690
|
+
const conditioned = () => {
|
|
691
|
+
const met = composites(node.then ?? true, defs, seen);
|
|
692
|
+
const condition = composites(node.if, defs, seen);
|
|
693
|
+
const otherwise = composites(node.else ?? true, defs, seen);
|
|
694
|
+
return COMPOSITES.filter((kind) => (condition.includes(kind) && met.includes(kind)) || otherwise.includes(kind));
|
|
695
|
+
};
|
|
696
|
+
const bounds = [
|
|
697
|
+
typed(node.type),
|
|
698
|
+
Array.isArray(node.enum) ? node.enum.flatMap(compositesOf) : undefined,
|
|
699
|
+
Object.hasOwn(node, 'const') ? compositesOf(node.const) : undefined,
|
|
700
|
+
target === undefined || seen.has(target)
|
|
701
|
+
? undefined
|
|
702
|
+
: composites(target, defs, new Set([...seen, target])),
|
|
703
|
+
...each(node.allOf),
|
|
704
|
+
...[node.anyOf, node.oneOf].filter(Array.isArray).map((branches) => each(branches).flat()),
|
|
705
|
+
Object.hasOwn(node, 'if') ? conditioned() : undefined,
|
|
706
|
+
Object.hasOwn(node, 'not')
|
|
707
|
+
? COMPOSITES.filter((kind) => !admittedWhole(node.not).includes(kind))
|
|
708
|
+
: undefined,
|
|
709
|
+
];
|
|
710
|
+
return COMPOSITES.filter((kind) => bounds.every((bound) => bound?.includes(kind) ?? true));
|
|
711
|
+
}
|
|
712
|
+
function transitionOf(value) {
|
|
713
|
+
if (!isRecord(value) || !Object.hasOwn(value, 'from') || !Object.hasOwn(value, 'to'))
|
|
714
|
+
return undefined;
|
|
715
|
+
const { from, to, roles, ...rest } = value;
|
|
716
|
+
if (Object.keys(rest).length > 0 || !ruleValue(from) || !ruleValue(to))
|
|
717
|
+
return undefined;
|
|
718
|
+
if (roles === undefined)
|
|
719
|
+
return { from, to };
|
|
720
|
+
return roleNames(roles) ? { from, to, roles } : undefined;
|
|
721
|
+
}
|
|
722
|
+
function fieldRules(written, field, at, defs) {
|
|
723
|
+
const { change_roles: changeRoles, initial_roles: initialRoles, transitions } = written;
|
|
724
|
+
if (changeRoles !== undefined && !roleNames(changeRoles))
|
|
725
|
+
return refuse('change_roles', `${at}/change_roles`);
|
|
726
|
+
if (initialRoles !== undefined && !roleNames(initialRoles))
|
|
727
|
+
return refuse('initial_roles', `${at}/initial_roles`);
|
|
728
|
+
if (transitions === undefined)
|
|
729
|
+
return {
|
|
730
|
+
...(changeRoles === undefined ? {} : { changeRoles }),
|
|
731
|
+
...(initialRoles === undefined ? {} : { initialRoles }),
|
|
732
|
+
};
|
|
733
|
+
if (!Array.isArray(transitions) || composites(field, defs, new Set()).length > 0)
|
|
734
|
+
return refuse('transitions', `${at}/transitions`);
|
|
735
|
+
const listed = [];
|
|
736
|
+
for (const [index, held] of transitions.entries()) {
|
|
737
|
+
const transition = transitionOf(held);
|
|
738
|
+
if (transition === undefined)
|
|
739
|
+
return refuse('transitions', `${at}/transitions/${index}`);
|
|
740
|
+
listed.push(transition);
|
|
741
|
+
}
|
|
742
|
+
return {
|
|
743
|
+
...(changeRoles === undefined ? {} : { changeRoles }),
|
|
744
|
+
...(initialRoles === undefined ? {} : { initialRoles }),
|
|
745
|
+
transitions: listed,
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
function unruled(schema) {
|
|
749
|
+
const written = new Map();
|
|
750
|
+
if (!isRecord(schema.properties))
|
|
751
|
+
return { schema, written };
|
|
752
|
+
const properties = Object.create(null);
|
|
753
|
+
for (const [field, node] of Object.entries(schema.properties)) {
|
|
754
|
+
if (!isRecord(node) || !FIELD_RULES.some((keyword) => Object.hasOwn(node, keyword))) {
|
|
755
|
+
properties[field] = node;
|
|
756
|
+
continue;
|
|
757
|
+
}
|
|
758
|
+
written.set(field, node);
|
|
759
|
+
properties[field] = Object.fromEntries(Object.entries(node).filter(([keyword]) => !FIELD_RULES.includes(keyword)));
|
|
760
|
+
}
|
|
761
|
+
return { schema: written.size === 0 ? schema : { ...schema, properties }, written };
|
|
762
|
+
}
|
|
763
|
+
function providedType(name, value, provided, checked) {
|
|
764
|
+
const at = `/${escapePointer(name)}`;
|
|
765
|
+
if (checked && provided.nameable?.includes(name) !== true)
|
|
766
|
+
return refuse('provided-type', at);
|
|
767
|
+
if (!isRecord(value))
|
|
768
|
+
return refuse('schema', at);
|
|
769
|
+
const declared = Object.keys(value).find((key) => !PROVIDED_KEYWORDS.includes(key));
|
|
770
|
+
if (checked && declared !== undefined)
|
|
771
|
+
return refuse('provided-type', `${at}/${escapePointer(declared)}`);
|
|
772
|
+
const { create_roles: createRoles, delete_roles: deleteRoles } = value;
|
|
773
|
+
if (createRoles !== undefined && !roleNames(createRoles))
|
|
774
|
+
return refuse('create_roles', `${at}/create_roles`);
|
|
775
|
+
if (deleteRoles !== undefined && !roleNames(deleteRoles))
|
|
776
|
+
return refuse('delete_roles', `${at}/delete_roles`);
|
|
777
|
+
return {
|
|
778
|
+
...provided.types[name],
|
|
779
|
+
...(createRoles === undefined ? {} : { createRoles }),
|
|
780
|
+
...(deleteRoles === undefined ? {} : { deleteRoles }),
|
|
781
|
+
};
|
|
782
|
+
}
|
|
432
783
|
function readType(name, value, context) {
|
|
433
784
|
const at = `/${escapePointer(name)}`;
|
|
434
785
|
if (!isRecord(value))
|
|
435
786
|
return refuse('schema', at);
|
|
436
|
-
const {
|
|
787
|
+
const { member_document: mark, create_roles: createRoles, delete_roles: deleteRoles, ...ruled } = value;
|
|
437
788
|
if (mark !== undefined && typeof mark !== 'boolean')
|
|
438
789
|
return refuse('member_document', `${at}/member_document`);
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
790
|
+
if (createRoles !== undefined && !roleNames(createRoles))
|
|
791
|
+
return refuse('create_roles', `${at}/create_roles`);
|
|
792
|
+
if (deleteRoles !== undefined && !roleNames(deleteRoles))
|
|
793
|
+
return refuse('delete_roles', `${at}/delete_roles`);
|
|
794
|
+
const { schema, written } = unruled(ruled);
|
|
444
795
|
const failure = schemaFailure(schema, at, context);
|
|
445
796
|
if (failure !== undefined)
|
|
446
797
|
return failure;
|
|
798
|
+
const rules = Object.create(null);
|
|
799
|
+
for (const [field, keywords] of written) {
|
|
800
|
+
const properties = schema.properties;
|
|
801
|
+
const where = `${at}/properties/${escapePointer(field)}`;
|
|
802
|
+
const ruling = fieldRules(keywords, properties[field], where, context.defs);
|
|
803
|
+
if ('rule' in ruling)
|
|
804
|
+
return ruling;
|
|
805
|
+
rules[field] = ruling;
|
|
806
|
+
}
|
|
447
807
|
const memberDocument = mark === true;
|
|
448
808
|
const root = valueFacts(schema, context.defs);
|
|
449
809
|
const fields = Object.assign(Object.create(null), root.properties);
|
|
@@ -451,19 +811,25 @@ function readType(name, value, context) {
|
|
|
451
811
|
fields[MEMBER_FIELD] = { type: 'string', prose: false };
|
|
452
812
|
const defs = Object.create(null);
|
|
453
813
|
reachedDefs(value, context.defs, defs);
|
|
814
|
+
const { create_roles: _create, delete_roles: _delete, ...shaped } = value;
|
|
454
815
|
return {
|
|
455
816
|
name,
|
|
456
817
|
memberDocument,
|
|
457
818
|
frontmatter: { ...root, properties: { ...HOUSE_KEYS, ...fields } },
|
|
458
819
|
fields,
|
|
459
|
-
|
|
460
|
-
|
|
820
|
+
rules,
|
|
821
|
+
...(createRoles === undefined ? {} : { createRoles }),
|
|
822
|
+
...(deleteRoles === undefined ? {} : { deleteRoles }),
|
|
823
|
+
shape: {
|
|
824
|
+
schema: written.size === 0 ? shaped : { ...shaped, properties: schema.properties },
|
|
825
|
+
defs,
|
|
826
|
+
},
|
|
461
827
|
};
|
|
462
828
|
}
|
|
463
829
|
function lineAt(text, offset) {
|
|
464
830
|
return text.slice(0, offset).split(/\r\n|\r|\n/).length;
|
|
465
831
|
}
|
|
466
|
-
export function readSchema(text) {
|
|
832
|
+
export function readSchema(text, provided = NO_TYPES, checked = true) {
|
|
467
833
|
let root;
|
|
468
834
|
try {
|
|
469
835
|
root = jsValue(parseYamlMapping(text, 0, text.length));
|
|
@@ -477,11 +843,15 @@ export function readSchema(text) {
|
|
|
477
843
|
if (!isRecord(defs))
|
|
478
844
|
return refuse('$defs', '/$defs');
|
|
479
845
|
const names = Object.keys(root).filter((key) => key !== '$defs');
|
|
480
|
-
for (const name of names) {
|
|
846
|
+
for (const name of checked ? names : []) {
|
|
481
847
|
if (name === '' || name.startsWith('$') || name === BUILT_IN_TYPE || name === ATTACHMENT)
|
|
482
848
|
return refuse('schema-type-name', `/${escapePointer(name)}`);
|
|
483
849
|
}
|
|
484
|
-
const context = {
|
|
850
|
+
const context = {
|
|
851
|
+
defs,
|
|
852
|
+
types: new Set([...names, ...Object.keys(provided.types)]),
|
|
853
|
+
checked,
|
|
854
|
+
};
|
|
485
855
|
for (const [name, def] of Object.entries(defs)) {
|
|
486
856
|
const failure = schemaFailure(def, `/$defs/${escapePointer(name)}`, context);
|
|
487
857
|
if (failure !== undefined)
|
|
@@ -490,15 +860,21 @@ export function readSchema(text) {
|
|
|
490
860
|
const types = Object.create(null);
|
|
491
861
|
let marked = false;
|
|
492
862
|
for (const name of names) {
|
|
493
|
-
const definition =
|
|
863
|
+
const definition = Object.hasOwn(provided.types, name)
|
|
864
|
+
? providedType(name, root[name], provided, checked)
|
|
865
|
+
: readType(name, root[name], context);
|
|
494
866
|
if ('rule' in definition)
|
|
495
867
|
return definition;
|
|
496
|
-
if (definition.memberDocument) {
|
|
868
|
+
if (checked && definition.memberDocument) {
|
|
497
869
|
if (marked)
|
|
498
870
|
return refuse('member_document', `/${escapePointer(name)}/member_document`);
|
|
499
871
|
marked = true;
|
|
500
872
|
}
|
|
501
873
|
types[name] = deepFreeze(definition);
|
|
502
874
|
}
|
|
875
|
+
for (const [name, definition] of Object.entries(provided.types)) {
|
|
876
|
+
if (!Object.hasOwn(types, name))
|
|
877
|
+
types[name] = definition;
|
|
878
|
+
}
|
|
503
879
|
return Object.freeze({ types: Object.freeze(types) });
|
|
504
880
|
}
|