@agentshouse/mdmodel 0.1.0-cc9fa0498a7f7 → 0.1.0-ccb295d7b1fee
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 +305 -305
- 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 +40 -11
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +442 -106
- package/dist/document.d.ts +16 -6
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +1000 -221
- 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 +1 -1
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +2 -2
- 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 +930 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +511 -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 +45 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -10
- package/dist/indexed.d.ts +9 -0
- package/dist/indexed.d.ts.map +1 -0
- package/dist/indexed.js +55 -0
- package/dist/kinds.d.ts +21 -0
- package/dist/kinds.d.ts.map +1 -0
- package/dist/kinds.js +210 -0
- package/dist/markdown.d.ts +71 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +232 -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/moment.d.ts +7 -0
- package/dist/moment.d.ts.map +1 -0
- package/dist/moment.js +18 -0
- package/dist/not-ready.d.ts +2 -0
- package/dist/not-ready.d.ts.map +1 -0
- package/dist/not-ready.js +5 -0
- package/dist/paths.d.ts +26 -2
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +207 -16
- package/dist/pattern.d.ts +10 -0
- package/dist/pattern.d.ts.map +1 -0
- package/dist/pattern.js +356 -0
- package/dist/query/language.d.ts +255 -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 +158 -0
- package/dist/query/sql.d.ts +43 -0
- package/dist/query/sql.d.ts.map +1 -0
- package/dist/query/sql.js +285 -0
- package/dist/query/walk.d.ts +63 -0
- package/dist/query/walk.d.ts.map +1 -0
- package/dist/query/walk.js +263 -0
- package/dist/references.d.ts +1 -1
- package/dist/references.d.ts.map +1 -1
- package/dist/references.js +7 -2
- 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 +7 -0
- package/dist/reserved.d.ts.map +1 -0
- package/dist/reserved.js +32 -0
- package/dist/room-types.d.ts +7 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +136 -0
- package/dist/schema.d.ts +1 -2
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +10 -23
- package/dist/types.d.ts +53 -21
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +36 -2
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +387 -136
- package/dist/yaml.d.ts +7 -5
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +219 -60
- package/fixtures/README.md +90 -65
- package/fixtures/cases/absent-link-dangles/library/item.md +1 -1
- package/fixtures/cases/absent-link-dangles/schema.yaml +2 -3
- 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/absolute-link/library/item.md +1 -1
- package/fixtures/cases/absolute-link/schema.yaml +2 -3
- 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-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/block-scalar-frontmatter/library/notes/literal.md +17 -0
- package/fixtures/cases/block-scalar-frontmatter/library/skills/notes/SKILL.md +10 -0
- 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/frontmatter-construct/expected.json +7 -0
- package/fixtures/cases/frontmatter-construct/library/note.md +6 -0
- 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/link-into-a-reserved-name-from-an-untyped-document/expected.json +5 -0
- package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/library/notes/b.md +5 -0
- package/fixtures/cases/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/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/reference-to-any-file-name/context.json +1 -0
- package/fixtures/cases/reference-to-any-file-name/expected.json +1 -0
- package/fixtures/cases/reference-to-any-file-name/library/people/100%.md +4 -0
- package/fixtures/cases/reference-to-any-file-name/library/people/C#.md +4 -0
- package/fixtures/cases/reference-to-any-file-name/library/people/My notes.md +4 -0
- package/fixtures/cases/reference-to-any-file-name/library/people/[draft].md +4 -0
- package/fixtures/cases/reference-to-any-file-name/library/people/c (d).md +4 -0
- package/fixtures/cases/reference-to-any-file-name/library/people/caf/303/251.md +4 -0
- package/fixtures/cases/reference-to-any-file-name/library/people//320/236/321/202/321/207/321/221/321/202.md +4 -0
- package/fixtures/cases/reference-to-any-file-name/library/tasks/bracket.md +9 -0
- package/fixtures/cases/reference-to-any-file-name/library/tasks/cyrillic.md +9 -0
- package/fixtures/cases/reference-to-any-file-name/library/tasks/decomposed.md +9 -0
- package/fixtures/cases/reference-to-any-file-name/library/tasks/hash.md +9 -0
- package/fixtures/cases/reference-to-any-file-name/library/tasks/parenthesis.md +9 -0
- package/fixtures/cases/reference-to-any-file-name/library/tasks/percent.md +9 -0
- package/fixtures/cases/reference-to-any-file-name/library/tasks/spaced.md +9 -0
- package/fixtures/cases/reference-to-any-file-name/schema.yaml +10 -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/referenced-missing-non-latin-file/context.json +1 -0
- package/fixtures/cases/referenced-missing-non-latin-file/expected.json +6 -0
- package/fixtures/cases/referenced-missing-non-latin-file/library/tasks/a.md +9 -0
- package/fixtures/cases/referenced-missing-non-latin-file/library/tasks/b.md +9 -0
- package/fixtures/cases/referenced-missing-non-latin-file/schema.yaml +10 -0
- package/fixtures/cases/room-md-declares-a-type/context.json +1 -0
- package/fixtures/cases/room-md-declares-a-type/expected.json +6 -0
- package/fixtures/cases/room-md-declares-a-type/library/ROOM.md +5 -0
- package/fixtures/cases/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 +1 -1
- 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/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 +1 -1
- 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/forms.json +371 -0
- package/fixtures/preamble.json +29 -8
- package/fixtures/queries.json +1359 -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 -76
- package/dist/condition.d.ts +0 -150
- package/dist/condition.d.ts.map +0 -1
- package/dist/condition.js +0 -497
- package/dist/divide.d.ts +0 -3
- package/dist/divide.d.ts.map +0 -1
- package/dist/divide.js +0 -310
- 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/project.d.ts +0 -21
- package/dist/project.d.ts.map +0 -1
- package/dist/project.js +0 -105
- 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/division.json +0 -409
- package/fixtures/projection.json +0 -255
- /package/fixtures/cases/{missing-section-item-kind → block-scalar-frontmatter}/context.json +0 -0
- /package/fixtures/cases/{section-items → block-scalar-frontmatter}/expected.json +0 -0
- /package/fixtures/cases/{null-refused → conditional-long-text}/context.json +0 -0
- /package/fixtures/cases/{open-map-value → cross-room-link}/context.json +0 -0
- /package/fixtures/cases/{section-item-enum → cross-room-reference}/context.json +0 -0
- /package/fixtures/cases/{section-item-kind → equal-labels}/context.json +0 -0
- /package/fixtures/cases/{section-items → frontmatter-construct}/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,
|
|
1
|
+
import { MEMBER_FIELD, SITE_FIELD, SUBMITTED_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
|
+
export 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
|
+
[SUBMITTED_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,92 @@ 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 required = (left.required ?? []).filter((name) => right.required?.includes(name) === true);
|
|
318
|
+
const title = left.title ?? right.title;
|
|
281
319
|
return {
|
|
282
320
|
...(type === undefined ? {} : { type }),
|
|
283
321
|
...(format === undefined ? {} : { format }),
|
|
284
322
|
...(values === undefined ? {} : { values }),
|
|
285
323
|
...(reference === undefined ? {} : { reference }),
|
|
324
|
+
...(reference !== undefined && crossRoom ? { crossRoom: true } : {}),
|
|
286
325
|
prose: left.prose && right.prose,
|
|
326
|
+
...(title === undefined ? {} : { title }),
|
|
327
|
+
...(left.markdown === true || right.markdown === true ? { markdown: true } : {}),
|
|
328
|
+
...(left.json === true || right.json === true ? { json: true } : {}),
|
|
329
|
+
...(prefix === undefined ? {} : { prefix }),
|
|
287
330
|
...(items === undefined ? {} : { items }),
|
|
331
|
+
...(Object.keys(properties).length === 0 ? {} : { properties }),
|
|
332
|
+
...(required.length === 0 ? {} : { required }),
|
|
333
|
+
...(patterns.length === 0 ? {} : { patterns }),
|
|
334
|
+
...(additional === undefined ? {} : { additional }),
|
|
288
335
|
};
|
|
289
336
|
}
|
|
290
|
-
function propertiesOf(held, defs, ancestry) {
|
|
337
|
+
function propertiesOf(held, variants, defs, ancestry) {
|
|
291
338
|
const declared = new Map();
|
|
292
339
|
for (const node of held) {
|
|
293
340
|
if (!isRecord(node.properties))
|
|
@@ -298,62 +345,180 @@ function propertiesOf(held, defs, ancestry) {
|
|
|
298
345
|
const properties = Object.create(null);
|
|
299
346
|
for (const [name, schemas] of declared)
|
|
300
347
|
properties[name] = factsOf(schemas, defs, ancestry);
|
|
301
|
-
const
|
|
302
|
-
for (const branch of
|
|
303
|
-
for (const [name, facts] of Object.entries(
|
|
348
|
+
const conditional = Object.create(null);
|
|
349
|
+
for (const branch of variants.values()) {
|
|
350
|
+
for (const [name, facts] of Object.entries(branch.properties ?? {})) {
|
|
304
351
|
if (Object.hasOwn(properties, name))
|
|
305
352
|
continue;
|
|
306
|
-
|
|
353
|
+
conditional[name] = Object.hasOwn(conditional, name)
|
|
354
|
+
? joined(conditional[name], facts)
|
|
355
|
+
: facts;
|
|
307
356
|
}
|
|
308
357
|
}
|
|
309
|
-
for (const [name, facts] of Object.entries(
|
|
358
|
+
for (const [name, facts] of Object.entries(conditional))
|
|
310
359
|
properties[name] = { ...facts, conditional: true };
|
|
311
360
|
return Object.keys(properties).length === 0 ? undefined : properties;
|
|
312
361
|
}
|
|
362
|
+
function nullOnly(facts) {
|
|
363
|
+
return facts.type === 'null' || (facts.values?.every((value) => value === null) ?? false);
|
|
364
|
+
}
|
|
365
|
+
function alternativesOf(held, variants) {
|
|
366
|
+
return held.flatMap((node) => [node.anyOf, node.oneOf].flatMap((branches) => {
|
|
367
|
+
if (!Array.isArray(branches))
|
|
368
|
+
return [];
|
|
369
|
+
const kept = branches
|
|
370
|
+
.flatMap((branch) => {
|
|
371
|
+
const facts = isRecord(branch) ? variants.get(branch) : undefined;
|
|
372
|
+
return facts === undefined ? [] : [facts];
|
|
373
|
+
})
|
|
374
|
+
.filter((facts) => !nullOnly(facts));
|
|
375
|
+
return kept.length === 0 ? [] : [kept];
|
|
376
|
+
}));
|
|
377
|
+
}
|
|
378
|
+
function inheritedOf(held) {
|
|
379
|
+
return held.flatMap((node) => {
|
|
380
|
+
const kept = Object.fromEntries(['type', 'items', 'prefixItems'].flatMap((key) => node[key] === undefined ? [] : [[key, node[key]]]));
|
|
381
|
+
return Object.keys(kept).length === 0 ? [] : [kept];
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
function typeSet(type) {
|
|
385
|
+
const listed = typeof type === 'string' ? [type] : Array.isArray(type) ? type : null;
|
|
386
|
+
return listed === null
|
|
387
|
+
? null
|
|
388
|
+
: new Set(listed.map((one) => (one === 'integer' ? 'number' : String(one))));
|
|
389
|
+
}
|
|
390
|
+
function valueType(value) {
|
|
391
|
+
if (value === null)
|
|
392
|
+
return 'null';
|
|
393
|
+
if (Array.isArray(value))
|
|
394
|
+
return 'array';
|
|
395
|
+
return typeof value;
|
|
396
|
+
}
|
|
397
|
+
function narrowed(left, right) {
|
|
398
|
+
if (left === null)
|
|
399
|
+
return right;
|
|
400
|
+
if (right === null)
|
|
401
|
+
return left;
|
|
402
|
+
return new Set([...left].filter((one) => right.has(one)));
|
|
403
|
+
}
|
|
404
|
+
export function admitted(nodes, defs, ancestry) {
|
|
405
|
+
const conjunction = conjoined(nodes.map((node) => ({ node, at: '' })), defs, ancestry);
|
|
406
|
+
let kept = null;
|
|
407
|
+
for (const { node } of conjunction.held) {
|
|
408
|
+
kept = narrowed(kept, typeSet(node.type));
|
|
409
|
+
if (Array.isArray(node.enum))
|
|
410
|
+
kept = narrowed(kept, new Set(node.enum.map(valueType)));
|
|
411
|
+
if (Object.hasOwn(node, 'const'))
|
|
412
|
+
kept = narrowed(kept, new Set([valueType(node.const)]));
|
|
413
|
+
for (const keyword of UNIONS) {
|
|
414
|
+
const branches = node[keyword];
|
|
415
|
+
if (!Array.isArray(branches))
|
|
416
|
+
continue;
|
|
417
|
+
let union = new Set();
|
|
418
|
+
for (const branch of branches) {
|
|
419
|
+
const one = admitted([branch], defs, conjunction.ancestry);
|
|
420
|
+
if (one === null) {
|
|
421
|
+
union = null;
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
for (const type of one)
|
|
425
|
+
union.add(type);
|
|
426
|
+
}
|
|
427
|
+
kept = narrowed(kept, union);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return kept;
|
|
431
|
+
}
|
|
432
|
+
function structuredUnion(held, defs, ancestry) {
|
|
433
|
+
return held.some((node) => UNIONS.some((keyword) => Array.isArray(node[keyword]) &&
|
|
434
|
+
node[keyword].some((branch) => {
|
|
435
|
+
const types = admitted([branch], defs, ancestry);
|
|
436
|
+
return types === null || types.has('object') || types.has('array');
|
|
437
|
+
})));
|
|
438
|
+
}
|
|
439
|
+
function openWhole(held) {
|
|
440
|
+
return held.some((node) => OPENING.some((keyword) => node[keyword] === true));
|
|
441
|
+
}
|
|
442
|
+
function writtenAsJson(held, defs, ancestry) {
|
|
443
|
+
const types = admitted(held, defs, ancestry);
|
|
444
|
+
if (types === null || types.size !== 1)
|
|
445
|
+
return true;
|
|
446
|
+
return structuredUnion(held, defs, ancestry) || (types.has('object') && openWhole(held));
|
|
447
|
+
}
|
|
313
448
|
function factsOf(nodes, defs, ancestry) {
|
|
314
|
-
const {
|
|
315
|
-
const
|
|
449
|
+
const conjunction = conjoined(nodes.map((node) => ({ node, at: '' })), defs, ancestry);
|
|
450
|
+
const reached = conjunction.ancestry;
|
|
451
|
+
const held = conjunction.held.map(({ node }) => node);
|
|
452
|
+
const inherited = inheritedOf(held);
|
|
453
|
+
const variants = new Map(conjunction.held
|
|
454
|
+
.flatMap(variantsOf)
|
|
455
|
+
.map(({ node: branch }) => [branch, factsOf([branch, ...inherited], defs, reached)]));
|
|
456
|
+
const unions = alternativesOf(held, variants);
|
|
457
|
+
const alternatives = unions.map((kept) => kept.reduce(joined));
|
|
458
|
+
const listed = [
|
|
459
|
+
...held.flatMap((node) => Array.isArray(node.enum) ? [node.enum] : node.const !== undefined ? [[node.const]] : []),
|
|
460
|
+
...alternatives.flatMap((facts) => (facts.values === undefined ? [] : [facts.values])),
|
|
461
|
+
];
|
|
316
462
|
const values = listed.length === 0
|
|
317
463
|
? undefined
|
|
318
464
|
: listed.reduce((kept, list) => kept.filter((value) => list.some((other) => equalValue(other, value))));
|
|
319
465
|
const type = firstOf(held, (node) => singleType(node.type)) ??
|
|
320
|
-
(values === undefined ? undefined : sharedType(values))
|
|
466
|
+
(values === undefined ? undefined : sharedType(values)) ??
|
|
467
|
+
alternatives.find((facts) => facts.type !== undefined)?.type;
|
|
321
468
|
const reference = firstOf(held, (node) => typeof node.reference === 'string'
|
|
322
469
|
? [node.reference]
|
|
323
470
|
: Array.isArray(node.reference)
|
|
324
471
|
? node.reference
|
|
325
|
-
: undefined);
|
|
326
|
-
const
|
|
472
|
+
: undefined) ?? alternatives.find((facts) => facts.reference !== undefined)?.reference;
|
|
473
|
+
const crossRoom = firstOf(held, (node) => node.reference === undefined ? undefined : node.cross_room === true) ?? alternatives.find((facts) => facts.reference !== undefined)?.crossRoom === true;
|
|
474
|
+
const format = firstOf(held, (node) => (typeof node.format === 'string' ? node.format : undefined)) ??
|
|
475
|
+
alternatives.find((facts) => facts.format !== undefined)?.format;
|
|
327
476
|
const prose = type === 'string' &&
|
|
328
477
|
values === undefined &&
|
|
329
478
|
format === undefined &&
|
|
330
479
|
reference === undefined &&
|
|
331
|
-
held.every((node) => node.pattern === undefined)
|
|
480
|
+
held.every((node) => node.pattern === undefined) &&
|
|
481
|
+
unions.every((kept) => kept.every((facts) => facts.type !== 'string' || facts.prose));
|
|
332
482
|
const listedItems = held.flatMap((node) => (node.items === undefined ? [] : [node.items]));
|
|
333
|
-
const items = type
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
483
|
+
const items = type !== 'array'
|
|
484
|
+
? undefined
|
|
485
|
+
: (alternatives.find((facts) => facts.items !== undefined)?.items ??
|
|
486
|
+
(listedItems.length > 0 ? factsOf(listedItems, defs, reached) : undefined));
|
|
487
|
+
const tuples = held.flatMap((node) => Array.isArray(node.prefixItems) ? [node.prefixItems] : []);
|
|
488
|
+
const prefix = type !== 'array'
|
|
489
|
+
? undefined
|
|
490
|
+
: (alternatives.find((facts) => facts.prefix !== undefined)?.prefix ??
|
|
491
|
+
(tuples.length === 0
|
|
492
|
+
? undefined
|
|
493
|
+
: Array.from({ length: Math.max(...tuples.map((tuple) => tuple.length)) }, (_, index) => factsOf(tuples.flatMap((tuple) => (index < tuple.length ? [tuple[index]] : [])), defs, reached))));
|
|
339
494
|
const mapped = type === 'object' || type === undefined;
|
|
340
|
-
const properties = mapped ? propertiesOf(held, defs, reached) : undefined;
|
|
495
|
+
const properties = mapped ? propertiesOf(held, variants, defs, reached) : undefined;
|
|
496
|
+
const required = mapped
|
|
497
|
+
? [...new Set(held.flatMap((node) => (Array.isArray(node.required) ? node.required : [])))]
|
|
498
|
+
: [];
|
|
341
499
|
const patterns = mapped
|
|
342
500
|
? held.flatMap((node) => Object.entries(isRecord(node.patternProperties) ? node.patternProperties : {}).map(([pattern, schema]) => ({ pattern, facts: factsOf([schema], defs, reached) })))
|
|
343
501
|
: [];
|
|
344
502
|
const opened = mapped
|
|
345
|
-
? held.flatMap((node) =>
|
|
503
|
+
? held.flatMap((node) => OPENING.map((keyword) => (node[keyword] === true ? {} : node[keyword])).filter(isRecord))
|
|
346
504
|
: [];
|
|
347
505
|
const additional = opened.length === 0 ? undefined : factsOf(opened, defs, reached);
|
|
506
|
+
const title = firstOf(nodes.filter(isRecord), (node) => typeof node.title === 'string' ? node.title : undefined);
|
|
507
|
+
const markdown = held.some((node) => node.contentMediaType === MEDIA_TYPES.markdown);
|
|
348
508
|
return {
|
|
349
509
|
...(type === undefined ? {} : { type }),
|
|
350
510
|
...(format === undefined ? {} : { format }),
|
|
351
511
|
...(values === undefined ? {} : { values }),
|
|
352
512
|
...(reference === undefined ? {} : { reference }),
|
|
513
|
+
...(reference !== undefined && crossRoom ? { crossRoom: true } : {}),
|
|
353
514
|
prose,
|
|
515
|
+
...(title === undefined ? {} : { title }),
|
|
516
|
+
...(markdown ? { markdown: true } : {}),
|
|
517
|
+
...(writtenAsJson(held, defs, ancestry) ? { json: true } : {}),
|
|
354
518
|
...(prefix === undefined ? {} : { prefix }),
|
|
355
519
|
...(items === undefined ? {} : { items }),
|
|
356
520
|
...(properties === undefined ? {} : { properties }),
|
|
521
|
+
...(required.length === 0 ? {} : { required }),
|
|
357
522
|
...(patterns.length === 0 ? {} : { patterns }),
|
|
358
523
|
...(additional === undefined ? {} : { additional }),
|
|
359
524
|
};
|
|
@@ -367,7 +532,7 @@ export function itemFacts(facts, index) {
|
|
|
367
532
|
export function memberFacts(facts, key) {
|
|
368
533
|
if (facts.properties !== undefined && Object.hasOwn(facts.properties, key))
|
|
369
534
|
return facts.properties[key];
|
|
370
|
-
const pattern = facts.patterns?.find((one) =>
|
|
535
|
+
const pattern = facts.patterns?.find((one) => linearPattern(one.pattern).test(key));
|
|
371
536
|
return pattern === undefined ? facts.additional : pattern.facts;
|
|
372
537
|
}
|
|
373
538
|
export function crossedFacts(facts) {
|
|
@@ -380,7 +545,7 @@ export function fieldFacts(definition, key) {
|
|
|
380
545
|
return definition.fields[key];
|
|
381
546
|
if (Object.hasOwn(HOUSE_KEYS, key))
|
|
382
547
|
return undefined;
|
|
383
|
-
return memberFacts(definition.
|
|
548
|
+
return memberFacts(definition.root, key);
|
|
384
549
|
}
|
|
385
550
|
function stepped({ facts, through, conditional }, token) {
|
|
386
551
|
if (facts.type === 'array' && ARRAY_INDEX.test(token)) {
|
|
@@ -438,37 +603,60 @@ function reachedDefs(value, defs, reached) {
|
|
|
438
603
|
reachedDefs(held, defs, reached);
|
|
439
604
|
}
|
|
440
605
|
}
|
|
441
|
-
function
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
const
|
|
446
|
-
|
|
447
|
-
const where = `${at}/${escapePointer(name)}`;
|
|
448
|
-
if (!isRecord(spec) || (spec.kind !== 'text' && spec.kind !== 'list'))
|
|
449
|
-
return failed('sections', where);
|
|
450
|
-
const allowed = spec.kind === 'list' ? ['kind', 'required', 'items'] : ['kind', 'required'];
|
|
451
|
-
const extra = Object.keys(spec).find((key) => !allowed.includes(key));
|
|
452
|
-
if (extra !== undefined)
|
|
453
|
-
return failed('sections', `${where}/${escapePointer(extra)}`);
|
|
454
|
-
if (spec.required !== undefined && typeof spec.required !== 'boolean')
|
|
455
|
-
return failed('sections', `${where}/required`);
|
|
456
|
-
const required = spec.required === true;
|
|
457
|
-
if (spec.kind === 'text') {
|
|
458
|
-
sections[name] = { kind: 'text', required };
|
|
606
|
+
function untitledSchema(node) {
|
|
607
|
+
if (!isRecord(node))
|
|
608
|
+
return node;
|
|
609
|
+
const kept = {};
|
|
610
|
+
for (const [key, held] of Object.entries(node)) {
|
|
611
|
+
if (key === 'title' && typeof held === 'string')
|
|
459
612
|
continue;
|
|
460
|
-
|
|
461
|
-
if (
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
sections[name] = { kind: 'list', required, items };
|
|
613
|
+
const check = Object.hasOwn(KEYWORDS, key) ? KEYWORDS[key] : undefined;
|
|
614
|
+
if (check === SCHEMA)
|
|
615
|
+
kept[key] = untitledSchema(held);
|
|
616
|
+
else if (check === SCHEMA_LIST && Array.isArray(held))
|
|
617
|
+
kept[key] = held.map(untitledSchema);
|
|
618
|
+
else if (check === SCHEMA_MAP && isRecord(held))
|
|
619
|
+
kept[key] = untitledMap(held);
|
|
620
|
+
else
|
|
621
|
+
kept[key] = held;
|
|
470
622
|
}
|
|
471
|
-
return
|
|
623
|
+
return kept;
|
|
624
|
+
}
|
|
625
|
+
function untitledMap(map) {
|
|
626
|
+
return Object.fromEntries(Object.entries(map).map(([key, held]) => [key, untitledSchema(held)]));
|
|
627
|
+
}
|
|
628
|
+
function untitledFacts(facts) {
|
|
629
|
+
const { title: _title, prefix, items, properties, patterns, additional, ...kept } = facts;
|
|
630
|
+
return {
|
|
631
|
+
...kept,
|
|
632
|
+
...(prefix === undefined ? {} : { prefix: prefix.map(untitledFacts) }),
|
|
633
|
+
...(items === undefined ? {} : { items: untitledFacts(items) }),
|
|
634
|
+
...(properties === undefined
|
|
635
|
+
? {}
|
|
636
|
+
: {
|
|
637
|
+
properties: Object.fromEntries(Object.entries(properties).map(([key, held]) => [key, untitledFacts(held)])),
|
|
638
|
+
}),
|
|
639
|
+
...(patterns === undefined
|
|
640
|
+
? {}
|
|
641
|
+
: {
|
|
642
|
+
patterns: patterns.map(({ pattern, facts: held }) => ({
|
|
643
|
+
pattern,
|
|
644
|
+
facts: untitledFacts(held),
|
|
645
|
+
})),
|
|
646
|
+
}),
|
|
647
|
+
...(additional === undefined ? {} : { additional: untitledFacts(additional) }),
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
export function untitled(definition) {
|
|
651
|
+
return {
|
|
652
|
+
...definition,
|
|
653
|
+
root: untitledFacts(definition.root),
|
|
654
|
+
fields: Object.fromEntries(Object.entries(definition.fields).map(([key, held]) => [key, untitledFacts(held)])),
|
|
655
|
+
shape: {
|
|
656
|
+
schema: untitledSchema(definition.shape.schema),
|
|
657
|
+
defs: untitledMap(definition.shape.defs),
|
|
658
|
+
},
|
|
659
|
+
};
|
|
472
660
|
}
|
|
473
661
|
function deepFreeze(value) {
|
|
474
662
|
if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
|
|
@@ -478,21 +666,152 @@ function deepFreeze(value) {
|
|
|
478
666
|
}
|
|
479
667
|
return value;
|
|
480
668
|
}
|
|
669
|
+
function ruleValue(value) {
|
|
670
|
+
return value === null || typeof value === 'string' || typeof value === 'boolean' || finite(value);
|
|
671
|
+
}
|
|
672
|
+
function roleNames(value) {
|
|
673
|
+
return strings(value) && value.every((name) => name !== '');
|
|
674
|
+
}
|
|
675
|
+
function compositesOf(value) {
|
|
676
|
+
return Array.isArray(value) ? ['array'] : isRecord(value) ? ['object'] : [];
|
|
677
|
+
}
|
|
678
|
+
function typed(type) {
|
|
679
|
+
const types = typeof type === 'string' ? [type] : type;
|
|
680
|
+
return Array.isArray(types) ? COMPOSITES.filter((kind) => types.includes(kind)) : undefined;
|
|
681
|
+
}
|
|
682
|
+
function admittedWhole(node) {
|
|
683
|
+
if (node === true)
|
|
684
|
+
return COMPOSITES;
|
|
685
|
+
if (!isRecord(node) || Object.keys(node).some((key) => key !== 'type' && !ANNOTATIONS.has(key)))
|
|
686
|
+
return [];
|
|
687
|
+
return typed(node.type) ?? COMPOSITES;
|
|
688
|
+
}
|
|
689
|
+
function composites(node, defs, seen) {
|
|
690
|
+
if (node === false)
|
|
691
|
+
return [];
|
|
692
|
+
if (!isRecord(node))
|
|
693
|
+
return COMPOSITES;
|
|
694
|
+
const each = (nodes) => Array.isArray(nodes) ? nodes.map((one) => composites(one, defs, seen)) : [];
|
|
695
|
+
const target = typeof node.$ref === 'string' ? refTarget(node.$ref, defs)?.node : undefined;
|
|
696
|
+
const conditioned = () => {
|
|
697
|
+
const met = composites(node.then ?? true, defs, seen);
|
|
698
|
+
const condition = composites(node.if, defs, seen);
|
|
699
|
+
const otherwise = composites(node.else ?? true, defs, seen);
|
|
700
|
+
return COMPOSITES.filter((kind) => (condition.includes(kind) && met.includes(kind)) || otherwise.includes(kind));
|
|
701
|
+
};
|
|
702
|
+
const bounds = [
|
|
703
|
+
typed(node.type),
|
|
704
|
+
Array.isArray(node.enum) ? node.enum.flatMap(compositesOf) : undefined,
|
|
705
|
+
Object.hasOwn(node, 'const') ? compositesOf(node.const) : undefined,
|
|
706
|
+
target === undefined || seen.has(target)
|
|
707
|
+
? undefined
|
|
708
|
+
: composites(target, defs, new Set([...seen, target])),
|
|
709
|
+
...each(node.allOf),
|
|
710
|
+
...[node.anyOf, node.oneOf].filter(Array.isArray).map((branches) => each(branches).flat()),
|
|
711
|
+
Object.hasOwn(node, 'if') ? conditioned() : undefined,
|
|
712
|
+
Object.hasOwn(node, 'not')
|
|
713
|
+
? COMPOSITES.filter((kind) => !admittedWhole(node.not).includes(kind))
|
|
714
|
+
: undefined,
|
|
715
|
+
];
|
|
716
|
+
return COMPOSITES.filter((kind) => bounds.every((bound) => bound?.includes(kind) ?? true));
|
|
717
|
+
}
|
|
718
|
+
function transitionOf(value) {
|
|
719
|
+
if (!isRecord(value) || !Object.hasOwn(value, 'from') || !Object.hasOwn(value, 'to'))
|
|
720
|
+
return undefined;
|
|
721
|
+
const { from, to, roles, ...rest } = value;
|
|
722
|
+
if (Object.keys(rest).length > 0 || !ruleValue(from) || !ruleValue(to))
|
|
723
|
+
return undefined;
|
|
724
|
+
if (roles === undefined)
|
|
725
|
+
return { from, to };
|
|
726
|
+
return roleNames(roles) ? { from, to, roles } : undefined;
|
|
727
|
+
}
|
|
728
|
+
function fieldRules(written, field, at, defs) {
|
|
729
|
+
const { change_roles: changeRoles, initial_roles: initialRoles, transitions } = written;
|
|
730
|
+
if (changeRoles !== undefined && !roleNames(changeRoles))
|
|
731
|
+
return refuse('change_roles', `${at}/change_roles`);
|
|
732
|
+
if (initialRoles !== undefined && !roleNames(initialRoles))
|
|
733
|
+
return refuse('initial_roles', `${at}/initial_roles`);
|
|
734
|
+
if (transitions === undefined)
|
|
735
|
+
return {
|
|
736
|
+
...(changeRoles === undefined ? {} : { changeRoles }),
|
|
737
|
+
...(initialRoles === undefined ? {} : { initialRoles }),
|
|
738
|
+
};
|
|
739
|
+
if (!Array.isArray(transitions) || composites(field, defs, new Set()).length > 0)
|
|
740
|
+
return refuse('transitions', `${at}/transitions`);
|
|
741
|
+
const listed = [];
|
|
742
|
+
for (const [index, held] of transitions.entries()) {
|
|
743
|
+
const transition = transitionOf(held);
|
|
744
|
+
if (transition === undefined)
|
|
745
|
+
return refuse('transitions', `${at}/transitions/${index}`);
|
|
746
|
+
listed.push(transition);
|
|
747
|
+
}
|
|
748
|
+
return {
|
|
749
|
+
...(changeRoles === undefined ? {} : { changeRoles }),
|
|
750
|
+
...(initialRoles === undefined ? {} : { initialRoles }),
|
|
751
|
+
transitions: listed,
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
function unruled(schema) {
|
|
755
|
+
const written = new Map();
|
|
756
|
+
if (!isRecord(schema.properties))
|
|
757
|
+
return { schema, written };
|
|
758
|
+
const properties = Object.create(null);
|
|
759
|
+
for (const [field, node] of Object.entries(schema.properties)) {
|
|
760
|
+
if (!isRecord(node) || !FIELD_RULES.some((keyword) => Object.hasOwn(node, keyword))) {
|
|
761
|
+
properties[field] = node;
|
|
762
|
+
continue;
|
|
763
|
+
}
|
|
764
|
+
written.set(field, node);
|
|
765
|
+
properties[field] = Object.fromEntries(Object.entries(node).filter(([keyword]) => !FIELD_RULES.includes(keyword)));
|
|
766
|
+
}
|
|
767
|
+
return { schema: written.size === 0 ? schema : { ...schema, properties }, written };
|
|
768
|
+
}
|
|
769
|
+
function providedType(name, value, provided, checked) {
|
|
770
|
+
const at = `/${escapePointer(name)}`;
|
|
771
|
+
if (checked && provided.nameable?.includes(name) !== true)
|
|
772
|
+
return refuse('provided-type', at);
|
|
773
|
+
if (!isRecord(value))
|
|
774
|
+
return refuse('schema', at);
|
|
775
|
+
const declared = Object.keys(value).find((key) => !PROVIDED_KEYWORDS.includes(key));
|
|
776
|
+
if (checked && declared !== undefined)
|
|
777
|
+
return refuse('provided-type', `${at}/${escapePointer(declared)}`);
|
|
778
|
+
const { create_roles: createRoles, delete_roles: deleteRoles } = value;
|
|
779
|
+
if (createRoles !== undefined && !roleNames(createRoles))
|
|
780
|
+
return refuse('create_roles', `${at}/create_roles`);
|
|
781
|
+
if (deleteRoles !== undefined && !roleNames(deleteRoles))
|
|
782
|
+
return refuse('delete_roles', `${at}/delete_roles`);
|
|
783
|
+
return {
|
|
784
|
+
...provided.types[name],
|
|
785
|
+
...(createRoles === undefined ? {} : { createRoles }),
|
|
786
|
+
...(deleteRoles === undefined ? {} : { deleteRoles }),
|
|
787
|
+
};
|
|
788
|
+
}
|
|
481
789
|
function readType(name, value, context) {
|
|
482
790
|
const at = `/${escapePointer(name)}`;
|
|
483
791
|
if (!isRecord(value))
|
|
484
792
|
return refuse('schema', at);
|
|
485
|
-
const {
|
|
793
|
+
const { member_document: mark, create_roles: createRoles, delete_roles: deleteRoles, indexed, ...ruled } = value;
|
|
486
794
|
if (mark !== undefined && typeof mark !== 'boolean')
|
|
487
795
|
return refuse('member_document', `${at}/member_document`);
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
796
|
+
if (createRoles !== undefined && !roleNames(createRoles))
|
|
797
|
+
return refuse('create_roles', `${at}/create_roles`);
|
|
798
|
+
if (deleteRoles !== undefined && !roleNames(deleteRoles))
|
|
799
|
+
return refuse('delete_roles', `${at}/delete_roles`);
|
|
800
|
+
if (indexed !== undefined && !strings(indexed))
|
|
801
|
+
return refuse('indexed', `${at}/indexed`);
|
|
802
|
+
const { schema, written } = unruled(ruled);
|
|
493
803
|
const failure = schemaFailure(schema, at, context);
|
|
494
804
|
if (failure !== undefined)
|
|
495
805
|
return failure;
|
|
806
|
+
const rules = Object.create(null);
|
|
807
|
+
for (const [field, keywords] of written) {
|
|
808
|
+
const properties = schema.properties;
|
|
809
|
+
const where = `${at}/properties/${escapePointer(field)}`;
|
|
810
|
+
const ruling = fieldRules(keywords, properties[field], where, context.defs);
|
|
811
|
+
if ('rule' in ruling)
|
|
812
|
+
return ruling;
|
|
813
|
+
rules[field] = ruling;
|
|
814
|
+
}
|
|
496
815
|
const memberDocument = mark === true;
|
|
497
816
|
const root = valueFacts(schema, context.defs);
|
|
498
817
|
const fields = Object.assign(Object.create(null), root.properties);
|
|
@@ -500,19 +819,26 @@ function readType(name, value, context) {
|
|
|
500
819
|
fields[MEMBER_FIELD] = { type: 'string', prose: false };
|
|
501
820
|
const defs = Object.create(null);
|
|
502
821
|
reachedDefs(value, context.defs, defs);
|
|
822
|
+
const { create_roles: _create, delete_roles: _delete, indexed: _indexed, ...shaped } = value;
|
|
503
823
|
return {
|
|
504
824
|
name,
|
|
505
825
|
memberDocument,
|
|
506
|
-
|
|
826
|
+
root: { ...root, properties: { ...HOUSE_KEYS, ...fields } },
|
|
507
827
|
fields,
|
|
508
|
-
|
|
509
|
-
|
|
828
|
+
rules,
|
|
829
|
+
...(createRoles === undefined ? {} : { createRoles }),
|
|
830
|
+
...(deleteRoles === undefined ? {} : { deleteRoles }),
|
|
831
|
+
...(indexed === undefined ? {} : { indexed }),
|
|
832
|
+
shape: {
|
|
833
|
+
schema: written.size === 0 ? shaped : { ...shaped, properties: schema.properties },
|
|
834
|
+
defs,
|
|
835
|
+
},
|
|
510
836
|
};
|
|
511
837
|
}
|
|
512
838
|
function lineAt(text, offset) {
|
|
513
839
|
return text.slice(0, offset).split(/\r\n|\r|\n/).length;
|
|
514
840
|
}
|
|
515
|
-
export function readSchema(text) {
|
|
841
|
+
export function readSchema(text, provided = NO_TYPES, checked = true) {
|
|
516
842
|
let root;
|
|
517
843
|
try {
|
|
518
844
|
root = jsValue(parseYamlMapping(text, 0, text.length));
|
|
@@ -526,11 +852,15 @@ export function readSchema(text) {
|
|
|
526
852
|
if (!isRecord(defs))
|
|
527
853
|
return refuse('$defs', '/$defs');
|
|
528
854
|
const names = Object.keys(root).filter((key) => key !== '$defs');
|
|
529
|
-
for (const name of names) {
|
|
855
|
+
for (const name of checked ? names : []) {
|
|
530
856
|
if (name === '' || name.startsWith('$') || name === BUILT_IN_TYPE || name === ATTACHMENT)
|
|
531
857
|
return refuse('schema-type-name', `/${escapePointer(name)}`);
|
|
532
858
|
}
|
|
533
|
-
const context = {
|
|
859
|
+
const context = {
|
|
860
|
+
defs,
|
|
861
|
+
types: new Set([...names, ...Object.keys(provided.types)]),
|
|
862
|
+
checked,
|
|
863
|
+
};
|
|
534
864
|
for (const [name, def] of Object.entries(defs)) {
|
|
535
865
|
const failure = schemaFailure(def, `/$defs/${escapePointer(name)}`, context);
|
|
536
866
|
if (failure !== undefined)
|
|
@@ -539,15 +869,21 @@ export function readSchema(text) {
|
|
|
539
869
|
const types = Object.create(null);
|
|
540
870
|
let marked = false;
|
|
541
871
|
for (const name of names) {
|
|
542
|
-
const definition =
|
|
872
|
+
const definition = Object.hasOwn(provided.types, name)
|
|
873
|
+
? providedType(name, root[name], provided, checked)
|
|
874
|
+
: readType(name, root[name], context);
|
|
543
875
|
if ('rule' in definition)
|
|
544
876
|
return definition;
|
|
545
|
-
if (definition.memberDocument) {
|
|
877
|
+
if (checked && definition.memberDocument) {
|
|
546
878
|
if (marked)
|
|
547
879
|
return refuse('member_document', `/${escapePointer(name)}/member_document`);
|
|
548
880
|
marked = true;
|
|
549
881
|
}
|
|
550
882
|
types[name] = deepFreeze(definition);
|
|
551
883
|
}
|
|
884
|
+
for (const [name, definition] of Object.entries(provided.types)) {
|
|
885
|
+
if (!Object.hasOwn(types, name))
|
|
886
|
+
types[name] = definition;
|
|
887
|
+
}
|
|
552
888
|
return Object.freeze({ types: Object.freeze(types) });
|
|
553
889
|
}
|