@agentshouse/mdmodel 0.1.0-c0bdbbc92d020 → 0.1.0-c107ff2190b0a
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 +349 -251
- package/README.md +29 -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 +28 -0
- package/dist/definition.d.ts +52 -11
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +566 -113
- package/dist/document.d.ts +20 -13
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +1038 -213
- package/dist/event.d.ts +74 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +201 -0
- package/dist/facts.d.ts +15 -0
- package/dist/facts.d.ts.map +1 -0
- package/dist/facts.js +45 -0
- package/dist/fields.d.ts +3 -1
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +8 -1
- package/dist/folders.d.ts +5 -0
- package/dist/folders.d.ts.map +1 -0
- package/dist/folders.js +19 -0
- 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 +1117 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +600 -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 +13 -0
- package/dist/house-references/patterns.d.ts.map +1 -0
- package/dist/house-references/patterns.js +20 -0
- package/dist/index.d.ts +46 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -9
- package/dist/indexed.d.ts +10 -0
- package/dist/indexed.d.ts.map +1 -0
- package/dist/indexed.js +63 -0
- package/dist/kinds.d.ts +26 -0
- package/dist/kinds.d.ts.map +1 -0
- package/dist/kinds.js +218 -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 +9 -0
- package/dist/moment.d.ts.map +1 -0
- package/dist/moment.js +40 -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 +257 -0
- package/dist/query/language.d.ts.map +1 -0
- package/dist/query/language.js +621 -0
- package/dist/query/match.d.ts +14 -0
- package/dist/query/match.d.ts.map +1 -0
- package/dist/query/match.js +129 -0
- package/dist/query/rows.d.ts +37 -0
- package/dist/query/rows.d.ts.map +1 -0
- package/dist/query/rows.js +190 -0
- package/dist/query/sql.d.ts +48 -0
- package/dist/query/sql.d.ts.map +1 -0
- package/dist/query/sql.js +304 -0
- package/dist/query/walk.d.ts +73 -0
- package/dist/query/walk.d.ts.map +1 -0
- package/dist/query/walk.js +277 -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 +6 -0
- package/dist/reserved.d.ts.map +1 -0
- package/dist/reserved.js +30 -0
- package/dist/room-types.d.ts +8 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +142 -0
- package/dist/schema.d.ts +1 -2
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +11 -24
- package/dist/types.d.ts +70 -21
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +38 -2
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +445 -142
- package/dist/view.d.ts +5 -0
- package/dist/view.d.ts.map +1 -0
- package/dist/view.js +27 -0
- package/dist/yaml.d.ts +10 -4
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +258 -82
- package/fixtures/README.md +112 -67
- package/fixtures/cases/absent-link-dangles/library/item.md +1 -1
- package/fixtures/cases/absent-link-dangles/schema.md +7 -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/{closed-nested-object/schema.yaml → absent-optional-field/schema.md} +12 -11
- package/fixtures/cases/absolute-link/library/item.md +1 -1
- package/fixtures/cases/absolute-link/schema.md +7 -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-any-file/{schema.yaml → schema.md} +2 -0
- 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-dangles/{schema.yaml → schema.md} +2 -0
- 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/attachment-reference-outside/{schema.yaml → schema.md} +2 -0
- 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-any-reference/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/binary-document-collision/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/binary-image-dangles/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/binary-link-dangles/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/binary-link-outside-collection/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/binary-prototype-reference/expected.json +2 -1
- package/fixtures/cases/binary-prototype-reference/library/notes/draft.md +1 -1
- package/fixtures/cases/binary-prototype-reference/{schema.yaml → schema.md} +2 -0
- 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/binary-typed-reference/{schema.yaml → schema.md} +2 -0
- 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/{absent-optional-field/schema.yaml → boolean-field/schema.md} +12 -11
- package/fixtures/cases/bracketed-link-definition/library/item.md +1 -1
- package/fixtures/cases/bracketed-link-definition/schema.md +7 -0
- 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/{date-time-format/schema.yaml → closed-nested-object/schema.md} +12 -11
- package/fixtures/cases/composed-root-reference/library/a.md +2 -2
- package/fixtures/cases/composed-root-reference/{schema.yaml → schema.md} +2 -0
- 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.md +15 -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.md +5 -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.md +10 -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/{boolean-field/schema.yaml → date-time-format/schema.md} +12 -11
- package/fixtures/cases/declared-binary-links/schema.md +3 -0
- 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.md +57 -0
- 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.md +57 -0
- 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.md +57 -0
- package/fixtures/cases/duplicate-link-definition/library/item.md +1 -1
- package/fixtures/cases/duplicate-link-definition/schema.md +7 -0
- 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.md +57 -0
- package/fixtures/cases/equal-labels/expected.json +5 -0
- package/fixtures/cases/equal-labels/schema.md +6 -0
- package/fixtures/cases/fenced-link-definition/library/item.md +1 -1
- package/fixtures/cases/fenced-link-definition/schema.md +7 -0
- 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.md +8 -0
- package/fixtures/cases/folder-keeps-a-built-in-type/expected.json +1 -0
- package/fixtures/cases/folder-keeps-a-built-in-type/library/tickets/door.md +3 -0
- package/fixtures/cases/folder-keeps-a-built-in-type/library/tickets/host.md +13 -0
- package/fixtures/cases/folder-keeps-a-built-in-type/library/tickets/map.md +24 -0
- package/fixtures/cases/folder-keeps-a-built-in-type/library/tickets/open.md +13 -0
- package/fixtures/cases/folder-keeps-a-built-in-type/schema.md +9 -0
- package/fixtures/cases/folder-keeps-a-record/expected.json +1 -0
- package/fixtures/cases/folder-keeps-a-record/library/tickets/2026-11-16-d_1.r.md +13 -0
- package/fixtures/cases/folder-keeps-a-record/library/tickets/door.md +3 -0
- package/fixtures/cases/folder-keeps-a-record/schema.md +9 -0
- package/fixtures/cases/folder-names-no-type-of-the-schema/expected.json +5 -0
- package/fixtures/cases/folder-names-no-type-of-the-schema/schema.md +7 -0
- package/fixtures/cases/folder-nearer-entry-types-a-document/expected.json +6 -0
- package/fixtures/cases/folder-nearer-entry-types-a-document/library/tickets/archive/2025/old.md +1 -0
- package/fixtures/cases/folder-nearer-entry-types-a-document/schema.md +15 -0
- package/fixtures/cases/folder-refuses-a-declared-any/expected.json +6 -0
- package/fixtures/cases/folder-refuses-a-declared-any/library/tickets/door.md +5 -0
- package/fixtures/cases/folder-refuses-a-declared-any/schema.md +9 -0
- package/fixtures/cases/folder-refuses-another-declared-type/context.json +1 -0
- package/fixtures/cases/folder-refuses-another-declared-type/expected.json +6 -0
- package/fixtures/cases/folder-refuses-another-declared-type/library/tickets/door.md +5 -0
- package/fixtures/cases/folder-refuses-another-declared-type/schema.md +12 -0
- package/fixtures/cases/folder-type-is-the-type-a-reference-reaches/context.json +1 -0
- package/fixtures/cases/folder-type-is-the-type-a-reference-reaches/expected.json +1 -0
- package/fixtures/cases/folder-type-is-the-type-a-reference-reaches/library/notes/plan.md +7 -0
- package/fixtures/cases/folder-type-is-the-type-a-reference-reaches/library/tickets/door.md +3 -0
- package/fixtures/cases/folder-type-is-the-type-a-reference-reaches/library/tickets/gate.md +7 -0
- package/fixtures/cases/folder-type-is-the-type-a-reference-reaches/schema.md +13 -0
- package/fixtures/cases/folder-types-a-document-in-a-folder-below-it/context.json +1 -0
- package/fixtures/cases/folder-types-a-document-in-a-folder-below-it/expected.json +6 -0
- package/fixtures/cases/folder-types-a-document-in-a-folder-below-it/library/tickets/2026/gate.md +1 -0
- package/fixtures/cases/folder-types-a-document-in-a-folder-below-it/schema.md +9 -0
- package/fixtures/cases/folder-types-a-document-that-names-no-type/context.json +1 -0
- package/fixtures/cases/folder-types-a-document-that-names-no-type/expected.json +7 -0
- package/fixtures/cases/folder-types-a-document-that-names-no-type/library/tickets/door.md +3 -0
- package/fixtures/cases/folder-types-a-document-that-names-no-type/schema.md +9 -0
- package/fixtures/cases/folder-under-a-reserved-name/context.json +1 -0
- package/fixtures/cases/folder-under-a-reserved-name/expected.json +5 -0
- package/fixtures/cases/folder-under-a-reserved-name/schema.md +7 -0
- package/fixtures/cases/folder-without-a-trailing-slash/context.json +1 -0
- package/fixtures/cases/folder-without-a-trailing-slash/expected.json +5 -0
- package/fixtures/cases/folder-without-a-trailing-slash/schema.md +7 -0
- package/fixtures/cases/frontmatter-construct/context.json +1 -0
- 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.md +57 -0
- package/fixtures/cases/interrupted-link-definition/schema.md +3 -0
- 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.md +57 -0
- package/fixtures/cases/labels-in-the-rooms-language/context.json +1 -0
- 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.md +11 -0
- package/fixtures/cases/lazy-list-item/context.json +1 -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.md +5 -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/{unknown-type/schema.yaml → link-into-a-reserved-name/schema.md} +3 -1
- package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/context.json +1 -0
- package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/expected.json +5 -0
- package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/library/notes/b.md +5 -0
- package/fixtures/cases/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.md +5 -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.md +5 -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.md +12 -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.md +57 -0
- 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.md +57 -0
- 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-of-objects-reference/{schema.yaml → schema.md} +2 -0
- 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.md +5 -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.md +5 -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.md +57 -0
- package/fixtures/cases/long-fence-link-definition/schema.md +3 -0
- 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.md +17 -0
- package/fixtures/cases/malformed-definition/{schema.yaml → schema.md} +2 -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.md +8 -0
- package/fixtures/cases/member-document/library/people/ana.md +2 -2
- package/fixtures/cases/member-document/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/member-on-an-untyped-document/context.json +1 -0
- package/fixtures/cases/member-on-an-untyped-document/expected.json +6 -0
- package/fixtures/cases/member-on-an-untyped-document/library/note.md +4 -0
- package/fixtures/cases/member-on-another-type/context.json +1 -0
- package/fixtures/cases/member-on-another-type/expected.json +6 -0
- package/fixtures/cases/member-on-another-type/library/note.md +4 -0
- package/fixtures/cases/member-on-another-type/schema.md +9 -0
- package/fixtures/cases/missing-required-field/library/item.md +1 -1
- package/fixtures/cases/missing-required-field/schema.md +8 -0
- 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.md +57 -0
- 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.md +7 -0
- package/fixtures/cases/nested-defs/expected.json +2 -1
- package/fixtures/cases/nested-defs/library/deal.md +3 -3
- package/fixtures/cases/nested-defs/{schema.yaml → schema.md} +2 -0
- 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-object-reference/schema.md +34 -0
- 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-reference/schema.md +34 -0
- 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.md +57 -0
- 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.md +57 -0
- 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.md +7 -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.md +6 -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.md +57 -0
- 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/other-room-reference/schema.md +34 -0
- package/fixtures/cases/paragraph-link-definition/schema.md +3 -0
- 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.md +7 -0
- package/fixtures/cases/quoted-link-definition/schema.md +3 -0
- 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.md +5 -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.md +12 -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.md +12 -0
- 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.md +12 -0
- package/fixtures/cases/remote-ref/{schema.yaml → schema.md} +2 -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/schema-body-ignored/context.json +1 -0
- package/fixtures/cases/schema-body-ignored/expected.json +1 -0
- package/fixtures/cases/schema-body-ignored/schema.md +9 -0
- package/fixtures/cases/schema-type-named-folders/context.json +1 -0
- package/fixtures/cases/schema-type-named-folders/expected.json +5 -0
- package/fixtures/cases/schema-type-named-folders/schema.md +5 -0
- package/fixtures/cases/schema-type-named-type/context.json +1 -0
- package/fixtures/cases/schema-type-named-type/expected.json +5 -0
- package/fixtures/cases/schema-type-named-type/schema.md +5 -0
- package/fixtures/cases/second-member-document/{schema.yaml → schema.md} +2 -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/schema.yaml → sections-keyword-refused/schema.md} +3 -2
- package/fixtures/cases/shortcut-reference-link/library/item.md +1 -1
- package/fixtures/cases/shortcut-reference-link/schema.md +7 -0
- 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.md +57 -0
- package/fixtures/cases/submission-keys/library/notes/visitor.md +2 -2
- package/fixtures/cases/submission-keys/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/text-field-kind/expected.json +1 -4
- package/fixtures/cases/text-field-kind/library/page.md +1 -1
- package/fixtures/cases/text-field-kind/{schema.yaml → schema.md} +2 -0
- 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.md +5 -0
- package/fixtures/cases/truncated-link-definition/schema.md +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.md +8 -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.md +8 -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.md +8 -0
- package/fixtures/cases/types-folder-content/library/types/task.md +1 -1
- package/fixtures/cases/types-folder-content/{schema.yaml → schema.md} +2 -0
- 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.md +7 -0
- package/fixtures/cases/unevaluated-items-closed/expected.json +2 -1
- package/fixtures/cases/unevaluated-items-closed/library/trip.md +13 -3
- package/fixtures/cases/unevaluated-items-closed/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/unique-in-app-schema/context.json +1 -0
- package/fixtures/cases/unique-in-app-schema/expected.json +5 -0
- package/fixtures/cases/unique-in-app-schema/schema.yaml +7 -0
- package/fixtures/cases/unique-indexed-field/context.json +1 -0
- package/fixtures/cases/unique-indexed-field/expected.json +1 -0
- package/fixtures/cases/unique-indexed-field/library/tickets/first.md +8 -0
- package/fixtures/cases/unique-indexed-field/library/tickets/second.md +8 -0
- package/fixtures/cases/unique-indexed-field/schema.md +9 -0
- package/fixtures/cases/unique-off-indexed-field/context.json +1 -0
- package/fixtures/cases/unique-off-indexed-field/expected.json +5 -0
- package/fixtures/cases/unique-off-indexed-field/schema.md +9 -0
- package/fixtures/cases/unlisted-reference-type/{schema.yaml → schema.md} +2 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/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.md +7 -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.md +7 -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.md +7 -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.md +7 -0
- package/fixtures/cases/unresolved-link/library/item.md +1 -1
- package/fixtures/cases/unresolved-link/schema.md +7 -0
- 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.md +17 -0
- package/fixtures/cases/wide-item-fence-link/schema.md +3 -0
- package/fixtures/forms.json +371 -0
- package/fixtures/preamble.json +29 -8
- package/fixtures/queries.json +2134 -0
- package/fixtures/references.json +15 -0
- package/package.json +20 -4
- 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/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/absent-link-dangles/schema.yaml +0 -6
- package/fixtures/cases/absolute-link/schema.yaml +0 -6
- package/fixtures/cases/bracketed-link-definition/schema.yaml +0 -6
- package/fixtures/cases/declared-binary-links/schema.yaml +0 -1
- package/fixtures/cases/default-unfilled/schema.yaml +0 -56
- package/fixtures/cases/defs-pattern/schema.yaml +0 -56
- package/fixtures/cases/dependent-rule/schema.yaml +0 -56
- package/fixtures/cases/duplicate-link-definition/schema.yaml +0 -6
- package/fixtures/cases/email-format/schema.yaml +0 -56
- package/fixtures/cases/fenced-link-definition/schema.yaml +0 -6
- package/fixtures/cases/field-enum/schema.yaml +0 -7
- package/fixtures/cases/frontmatter-schema/expected.json +0 -5
- package/fixtures/cases/integer-field/schema.yaml +0 -56
- package/fixtures/cases/interrupted-link-definition/schema.yaml +0 -1
- package/fixtures/cases/json-schema-constructs/schema.yaml +0 -56
- package/fixtures/cases/list-of-objects-closed/schema.yaml +0 -56
- package/fixtures/cases/list-of-objects-item/schema.yaml +0 -56
- package/fixtures/cases/list-size/schema.yaml +0 -56
- package/fixtures/cases/long-fence-link-definition/schema.yaml +0 -1
- package/fixtures/cases/missing-required-field/schema.yaml +0 -7
- 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/misspelled-key/schema.yaml +0 -56
- package/fixtures/cases/nested-object-reference/schema.yaml +0 -32
- package/fixtures/cases/nested-reference/schema.yaml +0 -32
- package/fixtures/cases/nested-required-field/schema.yaml +0 -56
- 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/numeric-range/schema.yaml +0 -56
- package/fixtures/cases/one-of-variant/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/other-room-reference/schema.yaml +0 -32
- package/fixtures/cases/paragraph-link-definition/schema.yaml +0 -1
- package/fixtures/cases/prototype-field/schema.yaml +0 -6
- package/fixtures/cases/quoted-link-definition/schema.yaml +0 -1
- package/fixtures/cases/referenced-missing-file/schema.yaml +0 -11
- 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/shortcut-reference-link/schema.yaml +0 -6
- package/fixtures/cases/string-length/schema.yaml +0 -56
- package/fixtures/cases/structured-section/expected.json +0 -6
- package/fixtures/cases/truncated-link-definition/schema.yaml +0 -1
- package/fixtures/cases/undeclared-field/schema.yaml +0 -6
- package/fixtures/cases/unresolved-link/schema.yaml +0 -6
- package/fixtures/cases/valid-typed-document/schema.yaml +0 -16
- package/fixtures/cases/wide-item-fence-link/schema.yaml +0 -1
- package/fixtures/division.json +0 -409
- package/fixtures/projection.json +0 -255
- /package/fixtures/cases/{frontmatter-schema → block-scalar-frontmatter}/context.json +0 -0
- /package/fixtures/cases/{section-items → block-scalar-frontmatter}/expected.json +0 -0
- /package/fixtures/cases/{missing-section-item-kind → conditional-long-text}/context.json +0 -0
- /package/fixtures/cases/{null-refused → cross-room-link}/context.json +0 -0
- /package/fixtures/cases/{open-map-value → cross-room-reference}/context.json +0 -0
- /package/fixtures/cases/{section-item-enum → equal-labels}/context.json +0 -0
- /package/fixtures/cases/{section-item-kind → folder-keeps-a-built-in-type}/context.json +0 -0
- /package/fixtures/cases/{section-items → folder-keeps-a-record}/context.json +0 -0
- /package/fixtures/cases/{section-reference-path → folder-names-no-type-of-the-schema}/context.json +0 -0
- /package/fixtures/cases/{section-reference-type → folder-nearer-entry-types-a-document}/context.json +0 -0
- /package/fixtures/cases/{structured-section → folder-refuses-a-declared-any}/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/fixtures/cases/{frontmatter-schema/schema.yaml → unknown-type/schema.md} +0 -0
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { instantKey } from '../kinds.js';
|
|
2
|
+
import { placedOf } from './rows.js';
|
|
3
|
+
export const VALUE_TABLE = 'CREATE TABLE replica_values (doc INTEGER NOT NULL, keys TEXT NOT NULL, places TEXT NOT NULL, item INTEGER NOT NULL, kind TEXT NOT NULL, value, size INTEGER, instant TEXT, PRIMARY KEY (doc, keys, places, item)) WITHOUT ROWID';
|
|
4
|
+
export const HOLDS_PHRASE = 'holds_phrase';
|
|
5
|
+
const BOUNDS = { gt: '>', gte: '>=', lt: '<', lte: '<=' };
|
|
6
|
+
const NUMBERS = 1;
|
|
7
|
+
const INSTANTS = 2;
|
|
8
|
+
const TEXTS = 3;
|
|
9
|
+
const LISTS = 4;
|
|
10
|
+
export function holdsPhrase(_context, text, phrase) {
|
|
11
|
+
return typeof text === 'string' &&
|
|
12
|
+
typeof phrase === 'string' &&
|
|
13
|
+
text.toLowerCase().includes(phrase)
|
|
14
|
+
? 1
|
|
15
|
+
: 0;
|
|
16
|
+
}
|
|
17
|
+
export function fragment(sql, bind = []) {
|
|
18
|
+
return { sql, bind };
|
|
19
|
+
}
|
|
20
|
+
export function joined(parts, separator) {
|
|
21
|
+
return {
|
|
22
|
+
sql: parts.map((part) => part.sql).join(separator),
|
|
23
|
+
bind: parts.flatMap((part) => part.bind),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function balanced(parts, separator) {
|
|
27
|
+
if (parts.length === 1)
|
|
28
|
+
return grouped(parts[0]);
|
|
29
|
+
const half = Math.ceil(parts.length / 2);
|
|
30
|
+
return grouped(joined([balanced(parts.slice(0, half), separator), balanced(parts.slice(half), separator)], separator));
|
|
31
|
+
}
|
|
32
|
+
export function all(parts) {
|
|
33
|
+
return parts.length === 0 ? fragment('1') : balanced(parts, ' AND ');
|
|
34
|
+
}
|
|
35
|
+
export function any(parts) {
|
|
36
|
+
return parts.length === 0 ? fragment('0') : balanced(parts, ' OR ');
|
|
37
|
+
}
|
|
38
|
+
export function grouped(part) {
|
|
39
|
+
return { sql: `(${part.sql})`, bind: part.bind };
|
|
40
|
+
}
|
|
41
|
+
export function listed(values) {
|
|
42
|
+
return fragment(`(${values.map(() => '?').join(', ')})`, values);
|
|
43
|
+
}
|
|
44
|
+
export function exists(part) {
|
|
45
|
+
return { sql: `EXISTS (${part.sql})`, bind: part.bind };
|
|
46
|
+
}
|
|
47
|
+
function not(part) {
|
|
48
|
+
return { sql: `NOT ${part.sql}`, bind: part.bind };
|
|
49
|
+
}
|
|
50
|
+
function scalarText(value) {
|
|
51
|
+
if (value === Infinity)
|
|
52
|
+
return 'Infinity';
|
|
53
|
+
if (value === -Infinity)
|
|
54
|
+
return '-Infinity';
|
|
55
|
+
return JSON.stringify(value);
|
|
56
|
+
}
|
|
57
|
+
export function insertedValues(held) {
|
|
58
|
+
const rows = held.flatMap(({ doc, values }) => values.map((value) => `[${doc},${JSON.stringify(value.keys)},${JSON.stringify(value.places)},${value.item},${JSON.stringify(value.kind)},${scalarText(value.value)},${JSON.stringify(value.size)},${JSON.stringify(value.instant)}]`));
|
|
59
|
+
return fragment('INSERT INTO replica_values (doc, keys, places, item, kind, value, size, instant) SELECT value ->> 0, value ->> 1, value ->> 2, value ->> 3, value ->> 4, value ->> 5, value ->> 6, value ->> 7 FROM json_each(?)', [`[${rows.join(',')}]`]);
|
|
60
|
+
}
|
|
61
|
+
export function placed(alias, field, reach) {
|
|
62
|
+
const { keys, places, glob } = placedOf(field, reach);
|
|
63
|
+
return fragment(`${alias}.keys = ? AND ${alias}.places ${glob ? 'GLOB' : '='} ?`, [keys, places]);
|
|
64
|
+
}
|
|
65
|
+
function plainText(alias, operator, text) {
|
|
66
|
+
return fragment(`${alias}.instant IS NULL AND ${alias}.kind = 'string' AND ${alias}.value ${operator} ?`, [text]);
|
|
67
|
+
}
|
|
68
|
+
function compares(alias, operator, value) {
|
|
69
|
+
if (typeof value !== 'string') {
|
|
70
|
+
return fragment(`${alias}.kind = ? AND ${alias}.value ${operator} ?`, [
|
|
71
|
+
typeof value,
|
|
72
|
+
typeof value === 'boolean' ? (value ? 1 : 0) : value,
|
|
73
|
+
]);
|
|
74
|
+
}
|
|
75
|
+
const key = instantKey(value);
|
|
76
|
+
if (key === null)
|
|
77
|
+
return plainText(alias, operator, value);
|
|
78
|
+
return any([
|
|
79
|
+
fragment(`${alias}.instant IS NOT NULL AND ${alias}.instant ${operator} ?`, [key]),
|
|
80
|
+
plainText(alias, operator, value),
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
function same(alias, value) {
|
|
84
|
+
return value === null ? fragment(`${alias}.kind = 'null'`) : compares(alias, '=', value);
|
|
85
|
+
}
|
|
86
|
+
function heldValues(doc, field, alias, where) {
|
|
87
|
+
return joined([
|
|
88
|
+
fragment(`SELECT 1 FROM replica_values ${alias} WHERE ${alias}.doc = ${doc}.id AND `),
|
|
89
|
+
grouped(placed(alias, field, 'value')),
|
|
90
|
+
fragment(' AND '),
|
|
91
|
+
grouped(where),
|
|
92
|
+
], '');
|
|
93
|
+
}
|
|
94
|
+
function itemOf(held, where) {
|
|
95
|
+
return exists(joined([
|
|
96
|
+
fragment(`SELECT 1 FROM replica_values i WHERE i.doc = ${held}.doc AND i.keys = ${held}.keys AND i.places = ${held}.places AND i.item >= 0 AND `),
|
|
97
|
+
grouped(where),
|
|
98
|
+
], ''));
|
|
99
|
+
}
|
|
100
|
+
function matching(held, values) {
|
|
101
|
+
return any(values.map((value) => any([
|
|
102
|
+
same(held, value),
|
|
103
|
+
all([fragment(`${held}.kind = 'array'`), itemOf(held, same('i', value))]),
|
|
104
|
+
])));
|
|
105
|
+
}
|
|
106
|
+
function tested(doc, field, test) {
|
|
107
|
+
const reached = exists(heldValues(doc, field, 'r', fragment('r.item = -1')));
|
|
108
|
+
if (test.op === 'exists')
|
|
109
|
+
return test.exists ? reached : not(reached);
|
|
110
|
+
if (test.op === 'eq' || test.op === 'in') {
|
|
111
|
+
const values = test.op === 'eq' ? [test.value] : test.values;
|
|
112
|
+
return exists(heldValues(doc, field, 'v', any(values.map((value) => same('v', value)))));
|
|
113
|
+
}
|
|
114
|
+
if (test.op === 'ne' || test.op === 'nin') {
|
|
115
|
+
const values = test.op === 'ne' ? [test.value] : test.values;
|
|
116
|
+
return any([
|
|
117
|
+
not(reached),
|
|
118
|
+
exists(heldValues(doc, field, 'h', all([fragment('h.item = -1'), not(grouped(matching('h', values)))]))),
|
|
119
|
+
]);
|
|
120
|
+
}
|
|
121
|
+
if (test.op === 'range') {
|
|
122
|
+
return exists(heldValues(doc, field, 'v', all([
|
|
123
|
+
fragment('v.item = -1'),
|
|
124
|
+
...test.bounds.map(([operator, bound]) => compares('v', BOUNDS[operator], bound)),
|
|
125
|
+
])));
|
|
126
|
+
}
|
|
127
|
+
if (test.op === 'prefix') {
|
|
128
|
+
return exists(heldValues(doc, field, 'v', fragment("v.kind = 'string' AND substr(v.value, 1, length(?)) = ?", [
|
|
129
|
+
test.prefix,
|
|
130
|
+
test.prefix,
|
|
131
|
+
])));
|
|
132
|
+
}
|
|
133
|
+
if (test.op === 'all') {
|
|
134
|
+
return exists(heldValues(doc, field, 'h', all([
|
|
135
|
+
fragment("h.item = -1 AND h.kind = 'array'"),
|
|
136
|
+
...test.values.map((value) => itemOf('h', same('i', value))),
|
|
137
|
+
])));
|
|
138
|
+
}
|
|
139
|
+
return exists(heldValues(doc, field, 'v', fragment("v.item = -1 AND v.kind = 'array' AND v.size = ?", [test.size])));
|
|
140
|
+
}
|
|
141
|
+
function conditioned(doc, condition) {
|
|
142
|
+
if ('every' in condition)
|
|
143
|
+
return all(condition.every.map((one) => conditioned(doc, one)));
|
|
144
|
+
if ('some' in condition)
|
|
145
|
+
return any(condition.some.map((one) => conditioned(doc, one)));
|
|
146
|
+
return tested(doc, condition.field, condition.test);
|
|
147
|
+
}
|
|
148
|
+
export function scoped(alias, scope, byPaths = false) {
|
|
149
|
+
const type = byPaths ? `+${alias}.type` : `${alias}.type`;
|
|
150
|
+
return all([
|
|
151
|
+
...(scope.types === null
|
|
152
|
+
? []
|
|
153
|
+
: [fragment(`${type} IN ${listed(scope.types).sql}`, scope.types)]),
|
|
154
|
+
...(scope.pathPrefix === null || scope.pathPrefix === ''
|
|
155
|
+
? []
|
|
156
|
+
: [
|
|
157
|
+
fragment(`${alias}.path >= ? AND ${alias}.path < ?`, [
|
|
158
|
+
`${scope.pathPrefix}/`,
|
|
159
|
+
`${scope.pathPrefix}0`,
|
|
160
|
+
]),
|
|
161
|
+
]),
|
|
162
|
+
...(scope.where === null ? [] : [conditioned(alias, scope.where)]),
|
|
163
|
+
]);
|
|
164
|
+
}
|
|
165
|
+
export function tests(alias, plan) {
|
|
166
|
+
return all([
|
|
167
|
+
...(plan.paths === null
|
|
168
|
+
? []
|
|
169
|
+
: [fragment(`${alias}.path IN ${listed(plan.paths).sql}`, plan.paths)]),
|
|
170
|
+
...(plan.fileIds === null
|
|
171
|
+
? []
|
|
172
|
+
: [fragment(`${alias}.file_id IN ${listed(plan.fileIds).sql}`, plan.fileIds)]),
|
|
173
|
+
...(plan.folder === null ? [] : [fragment(`${alias}.folder = ?`, [plan.folder])]),
|
|
174
|
+
...(plan.outside ?? []).map((folder) => fragment(`NOT (${alias}.path = ? OR (${alias}.path >= ? AND ${alias}.path < ?))`, [
|
|
175
|
+
folder,
|
|
176
|
+
`${folder}/`,
|
|
177
|
+
`${folder}0`,
|
|
178
|
+
])),
|
|
179
|
+
scoped(alias, plan.root, plan.paths !== null),
|
|
180
|
+
...(plan.text === null
|
|
181
|
+
? []
|
|
182
|
+
: [fragment(`${HOLDS_PHRASE}(${alias}.content, ?)`, [plan.text.toLowerCase()])]),
|
|
183
|
+
]);
|
|
184
|
+
}
|
|
185
|
+
export function hopped(alias, hop, followed) {
|
|
186
|
+
const linked = exists(joined([
|
|
187
|
+
fragment('SELECT 1 FROM replica_links l JOIN '),
|
|
188
|
+
followed.targets('l', 'm'),
|
|
189
|
+
fragment(` WHERE l.doc = ${alias}.id AND l.kind = 'field' AND `),
|
|
190
|
+
grouped(placed('l', hop.field, 'link')),
|
|
191
|
+
fragment(' AND '),
|
|
192
|
+
grouped(scoped('m', hop)),
|
|
193
|
+
], ''));
|
|
194
|
+
if (!hop.none)
|
|
195
|
+
return linked;
|
|
196
|
+
const blind = exists(joined([
|
|
197
|
+
fragment(`SELECT 1 FROM replica_links l WHERE l.doc = ${alias}.id AND l.kind = 'field' AND `),
|
|
198
|
+
grouped(placed('l', hop.field, 'link')),
|
|
199
|
+
fragment(' AND '),
|
|
200
|
+
grouped(followed.unfollowed('l')),
|
|
201
|
+
], ''));
|
|
202
|
+
return all([not(linked), not(blind)]);
|
|
203
|
+
}
|
|
204
|
+
function instantMark(value) {
|
|
205
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
206
|
+
return null;
|
|
207
|
+
const { instant } = value;
|
|
208
|
+
return typeof instant === 'string' && Object.keys(value).length === 1 ? instant : null;
|
|
209
|
+
}
|
|
210
|
+
export function sortValue(kind, value, instant) {
|
|
211
|
+
return typeof instant === 'string' && kind === 'string' ? { instant } : value;
|
|
212
|
+
}
|
|
213
|
+
function classOf(value, ordering) {
|
|
214
|
+
if (value === null || value === undefined) {
|
|
215
|
+
return { placement: ordering.nulls === 'first' ? 0 : 2, klass: 0, scalar: null };
|
|
216
|
+
}
|
|
217
|
+
const mark = instantMark(value);
|
|
218
|
+
if (mark !== null)
|
|
219
|
+
return { placement: 1, klass: INSTANTS, scalar: mark };
|
|
220
|
+
if (typeof value === 'boolean')
|
|
221
|
+
return { placement: 1, klass: NUMBERS, scalar: value ? 1 : 0 };
|
|
222
|
+
if (typeof value === 'number')
|
|
223
|
+
return { placement: 1, klass: NUMBERS, scalar: value };
|
|
224
|
+
if (typeof value === 'string')
|
|
225
|
+
return { placement: 1, klass: TEXTS, scalar: value };
|
|
226
|
+
return { placement: 1, klass: LISTS, scalar: JSON.stringify(value) };
|
|
227
|
+
}
|
|
228
|
+
function placement(term) {
|
|
229
|
+
const nulls = term.ordering.nulls === 'first' ? 0 : 2;
|
|
230
|
+
return fragment(`CASE WHEN ${term.kind.sql} IS NULL OR ${term.kind.sql} = 'null' THEN ${nulls} ELSE 1 END`, [...term.kind.bind, ...term.kind.bind]);
|
|
231
|
+
}
|
|
232
|
+
function klass(term) {
|
|
233
|
+
const kinds = fragment(`CASE ${term.kind.sql} WHEN 'boolean' THEN ${NUMBERS} WHEN 'number' THEN ${NUMBERS} WHEN 'string' THEN ${TEXTS} WHEN 'array' THEN ${LISTS} ELSE 5 END`, term.kind.bind);
|
|
234
|
+
if (term.instant === undefined)
|
|
235
|
+
return kinds;
|
|
236
|
+
return fragment(`CASE WHEN ${term.instant.sql} IS NOT NULL THEN ${INSTANTS} ELSE ${kinds.sql} END`, [...term.instant.bind, ...kinds.bind]);
|
|
237
|
+
}
|
|
238
|
+
function classed(term, which) {
|
|
239
|
+
if (which === INSTANTS)
|
|
240
|
+
return term.instant ?? fragment('NULL');
|
|
241
|
+
const kinds = which === NUMBERS ? "('boolean', 'number')" : which === TEXTS ? "('string')" : "('array')";
|
|
242
|
+
const plain = which === TEXTS && term.instant !== undefined
|
|
243
|
+
? fragment(` AND ${term.instant.sql} IS NULL`, term.instant.bind)
|
|
244
|
+
: fragment('');
|
|
245
|
+
return fragment(`(CASE WHEN ${term.kind.sql} IN ${kinds}${plain.sql} THEN ${term.value.sql} END)`, [...term.kind.bind, ...plain.bind, ...term.value.bind]);
|
|
246
|
+
}
|
|
247
|
+
function collated(collate, term, which) {
|
|
248
|
+
if (which === NUMBERS || which === INSTANTS)
|
|
249
|
+
return '';
|
|
250
|
+
const name = collate(term.ordering, which === LISTS, term.total === true);
|
|
251
|
+
return name === null ? '' : ` COLLATE ${name}`;
|
|
252
|
+
}
|
|
253
|
+
export function sorted(collate, term) {
|
|
254
|
+
const direction = term.ordering.direction === 'desc' ? 'DESC' : 'ASC';
|
|
255
|
+
const group = klass(term);
|
|
256
|
+
return joined([
|
|
257
|
+
placement(term),
|
|
258
|
+
fragment(`${group.sql} ${direction}`, group.bind),
|
|
259
|
+
...[NUMBERS, INSTANTS, TEXTS, LISTS].map((which) => {
|
|
260
|
+
const value = classed(term, which);
|
|
261
|
+
return fragment(`${value.sql}${collated(collate, term, which)} ${direction}`, value.bind);
|
|
262
|
+
}),
|
|
263
|
+
], ', ');
|
|
264
|
+
}
|
|
265
|
+
export function beyond(collate, term, value) {
|
|
266
|
+
const held = classOf(value, term.ordering);
|
|
267
|
+
const place = placement(term);
|
|
268
|
+
if (held.placement !== 1) {
|
|
269
|
+
return {
|
|
270
|
+
beyond: fragment(`${place.sql} > ${held.placement}`, place.bind),
|
|
271
|
+
equal: fragment(`${place.sql} = ${held.placement}`, place.bind),
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
const after = term.ordering.direction === 'desc' ? '<' : '>';
|
|
275
|
+
const kind = klass(term);
|
|
276
|
+
const scalar = classed(term, held.klass);
|
|
277
|
+
const collation = collated(collate, term, held.klass);
|
|
278
|
+
return {
|
|
279
|
+
beyond: any([
|
|
280
|
+
fragment(`${place.sql} > 1`, place.bind),
|
|
281
|
+
all([
|
|
282
|
+
fragment(`${place.sql} = 1`, place.bind),
|
|
283
|
+
any([
|
|
284
|
+
fragment(`${kind.sql} ${after} ${held.klass}`, kind.bind),
|
|
285
|
+
all([
|
|
286
|
+
fragment(`${kind.sql} = ${held.klass}`, kind.bind),
|
|
287
|
+
fragment(`${scalar.sql} ${after} ?${collation}`, [...scalar.bind, held.scalar]),
|
|
288
|
+
]),
|
|
289
|
+
]),
|
|
290
|
+
]),
|
|
291
|
+
]),
|
|
292
|
+
equal: all([
|
|
293
|
+
fragment(`${place.sql} = 1 AND ${kind.sql} = ${held.klass}`, [...place.bind, ...kind.bind]),
|
|
294
|
+
fragment(`${scalar.sql} = ?${collation}`, [...scalar.bind, held.scalar]),
|
|
295
|
+
]),
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
export function following(parts, tie) {
|
|
299
|
+
let condition = tie;
|
|
300
|
+
for (const part of [...parts].reverse()) {
|
|
301
|
+
condition = any([part.beyond, all([part.equal, condition])]);
|
|
302
|
+
}
|
|
303
|
+
return condition;
|
|
304
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type Definition } from '../definition.js';
|
|
2
|
+
import type { VerifiedModel } from '../types.js';
|
|
3
|
+
import { type Direction, type QueryPlan } from './language.js';
|
|
4
|
+
export type KeyBound = {
|
|
5
|
+
readonly key: Uint8Array;
|
|
6
|
+
readonly inclusive: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type KeyRange = {
|
|
9
|
+
readonly lower: KeyBound;
|
|
10
|
+
readonly upper: KeyBound | null;
|
|
11
|
+
};
|
|
12
|
+
export type WalkRun = {
|
|
13
|
+
readonly by: 'key';
|
|
14
|
+
readonly key: Uint8Array;
|
|
15
|
+
readonly after: boolean;
|
|
16
|
+
} | {
|
|
17
|
+
readonly by: 'range';
|
|
18
|
+
readonly range: KeyRange;
|
|
19
|
+
};
|
|
20
|
+
export type PageOrder = {
|
|
21
|
+
readonly by: 'path';
|
|
22
|
+
readonly direction: Direction;
|
|
23
|
+
} | {
|
|
24
|
+
readonly by: 'field';
|
|
25
|
+
readonly field: string;
|
|
26
|
+
readonly direction: Direction;
|
|
27
|
+
readonly nulls: 'first' | 'last';
|
|
28
|
+
readonly lexical: boolean;
|
|
29
|
+
readonly after: {
|
|
30
|
+
readonly key: Uint8Array;
|
|
31
|
+
readonly tie: unknown;
|
|
32
|
+
} | null;
|
|
33
|
+
};
|
|
34
|
+
export type Walk = {
|
|
35
|
+
readonly by: 'path';
|
|
36
|
+
readonly direction: Direction;
|
|
37
|
+
} | {
|
|
38
|
+
readonly by: 'keys';
|
|
39
|
+
readonly field: string;
|
|
40
|
+
readonly direction: Direction;
|
|
41
|
+
readonly types: readonly {
|
|
42
|
+
readonly type: string;
|
|
43
|
+
readonly keys: readonly Uint8Array[];
|
|
44
|
+
}[];
|
|
45
|
+
} | {
|
|
46
|
+
readonly by: 'order';
|
|
47
|
+
readonly field: string;
|
|
48
|
+
readonly direction: Direction;
|
|
49
|
+
readonly types: readonly {
|
|
50
|
+
readonly type: string;
|
|
51
|
+
readonly runs: readonly WalkRun[];
|
|
52
|
+
}[];
|
|
53
|
+
};
|
|
54
|
+
export type Count = {
|
|
55
|
+
readonly walk: Walk;
|
|
56
|
+
readonly fields: readonly string[];
|
|
57
|
+
};
|
|
58
|
+
export type WalkedFacts = {
|
|
59
|
+
readonly path: string;
|
|
60
|
+
readonly type: string | null;
|
|
61
|
+
readonly fields: Readonly<Record<string, unknown>> | null;
|
|
62
|
+
};
|
|
63
|
+
export declare function pageOrder(plan: QueryPlan): PageOrder;
|
|
64
|
+
export declare function walkOf(plan: QueryPlan, model: VerifiedModel): Walk;
|
|
65
|
+
export declare function countShape(plan: QueryPlan): boolean;
|
|
66
|
+
export declare function countOf(plan: QueryPlan, model: VerifiedModel, where: unknown): Count | null;
|
|
67
|
+
export declare function walkedValue(definition: Definition, field: string, value: unknown): unknown;
|
|
68
|
+
export type HopTarget = {
|
|
69
|
+
readonly handle: string | null;
|
|
70
|
+
readonly path: string;
|
|
71
|
+
};
|
|
72
|
+
export declare function hopTargets(plan: QueryPlan, model: VerifiedModel, row: WalkedFacts): HopTarget[];
|
|
73
|
+
//# sourceMappingURL=walk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../../src/query/walk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,UAAU,EAAmB,MAAM,kBAAkB,CAAC;AAEpG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,OAAO,EAIL,KAAK,SAAS,EAEd,KAAK,SAAS,EAEf,MAAM,eAAe,CAAC;AAGvB,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AAEjF,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;CAAE,CAAC;AAErF,MAAM,MAAM,OAAO,GACf;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACzE;IAAE,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAA;CAAE,CAAC;AAIvD,MAAM,MAAM,SAAS,GACjB;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;CAAE,GACtD;IACE,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;QAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CAC5E,CAAC;AAEN,MAAM,MAAM,IAAI,GACZ;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;CAAE,GACtD;IACE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,SAAS;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,UAAU,EAAE,CAAA;KAAE,EAAE,CAAC;CAC5F,GACD;IACE,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,SAAS;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,CAAA;KAAE,EAAE,CAAC;CACzF,CAAC;AAEN,MAAM,MAAM,KAAK,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAEhF,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;CAC3D,CAAC;AA6EF,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,CAwBpD;AA2ED,wBAAgB,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI,CA6BlE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAoBnD;AAwCD,wBAAgB,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,IAAI,CAqB3F;AAED,wBAAgB,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAG1F;AAED,MAAM,MAAM,SAAS,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAElF,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,WAAW,GAAG,SAAS,EAAE,CAQ/F"}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { escapePointer, pointerSegments } from '../definition.js';
|
|
2
|
+
import { byCodePoint, indexKey, instantOf, sortedKey } from '../kinds.js';
|
|
3
|
+
import { definitionAt } from '../validate.js';
|
|
4
|
+
import { plain } from '../yaml.js';
|
|
5
|
+
import { invalid, textless, } from './language.js';
|
|
6
|
+
import { indexed, placedIn } from './rows.js';
|
|
7
|
+
function keyOrder(left, right) {
|
|
8
|
+
for (let at = 0; at < Math.min(left.length, right.length); at += 1) {
|
|
9
|
+
if (left[at] !== right[at])
|
|
10
|
+
return left[at] - right[at];
|
|
11
|
+
}
|
|
12
|
+
return left.length - right.length;
|
|
13
|
+
}
|
|
14
|
+
function tighter(held, bound, sign) {
|
|
15
|
+
if (held === null)
|
|
16
|
+
return bound;
|
|
17
|
+
const order = sign * keyOrder(bound.key, held.key);
|
|
18
|
+
return order > 0 || (order === 0 && !bound.inclusive) ? bound : held;
|
|
19
|
+
}
|
|
20
|
+
function everyValue(facts) {
|
|
21
|
+
return { lower: { key: indexKey(facts, null), inclusive: false }, upper: null };
|
|
22
|
+
}
|
|
23
|
+
function rangeOf(facts, bounds) {
|
|
24
|
+
let { lower } = everyValue(facts);
|
|
25
|
+
let upper = null;
|
|
26
|
+
for (const [operator, value] of bounds) {
|
|
27
|
+
const bound = { key: indexKey(facts, value), inclusive: operator.endsWith('e') };
|
|
28
|
+
if (operator.startsWith('g'))
|
|
29
|
+
lower = tighter(lower, bound, 1);
|
|
30
|
+
else
|
|
31
|
+
upper = tighter(upper, bound, -1);
|
|
32
|
+
}
|
|
33
|
+
return { lower, upper };
|
|
34
|
+
}
|
|
35
|
+
function distinct(keys) {
|
|
36
|
+
return [...new Map(keys.map((key) => [key.join(','), key])).values()];
|
|
37
|
+
}
|
|
38
|
+
function testedKeys(facts, test) {
|
|
39
|
+
if (test.op === 'eq')
|
|
40
|
+
return { keys: [indexKey(facts, test.value)] };
|
|
41
|
+
if (test.op === 'in')
|
|
42
|
+
return { keys: distinct(test.values.map((value) => indexKey(facts, value))) };
|
|
43
|
+
if (test.op === 'range')
|
|
44
|
+
return { range: rangeOf(facts, test.bounds) };
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
function conjuncts(where) {
|
|
48
|
+
if (where === null || 'some' in where)
|
|
49
|
+
return [];
|
|
50
|
+
return 'every' in where ? where.every.flatMap(conjuncts) : [where];
|
|
51
|
+
}
|
|
52
|
+
function named(pointer) {
|
|
53
|
+
const segments = pointerSegments(pointer);
|
|
54
|
+
return segments.length === 1 ? segments[0] : null;
|
|
55
|
+
}
|
|
56
|
+
function indexing(model, types, field) {
|
|
57
|
+
const definitions = types.map((type) => Object.hasOwn(model.types, type) ? model.types[type] : null);
|
|
58
|
+
return definitions.every((definition) => definition?.indexed?.includes(field) === true)
|
|
59
|
+
? definitions
|
|
60
|
+
: null;
|
|
61
|
+
}
|
|
62
|
+
function afterOf(plan) {
|
|
63
|
+
const values = plan.after?.values ?? null;
|
|
64
|
+
if (values === null)
|
|
65
|
+
return null;
|
|
66
|
+
const key = sortedKey(values[0]);
|
|
67
|
+
if (key === null)
|
|
68
|
+
invalid('after', 'expects the next an earlier result of this query returned');
|
|
69
|
+
return { key, tie: values[1] };
|
|
70
|
+
}
|
|
71
|
+
export function pageOrder(plan) {
|
|
72
|
+
if (plan.shape.kind !== 'documents')
|
|
73
|
+
return invalid('groupBy', 'a page answers Documents');
|
|
74
|
+
const [term, second] = plan.shape.orderBy;
|
|
75
|
+
if (second !== undefined)
|
|
76
|
+
invalid(['orderBy', 1], 'a page orders by one term');
|
|
77
|
+
if (term === undefined)
|
|
78
|
+
return { by: 'path', direction: 'asc' };
|
|
79
|
+
const { key, options } = term;
|
|
80
|
+
if (key.of === 'path') {
|
|
81
|
+
if (options.stringSort !== 'lexical')
|
|
82
|
+
invalid(['orderBy', 0, 'stringSort'], 'a page orders Paths by code point, as lexical');
|
|
83
|
+
return { by: 'path', direction: options.direction };
|
|
84
|
+
}
|
|
85
|
+
const field = key.of === 'field' ? named(key.field) : null;
|
|
86
|
+
if (field === null)
|
|
87
|
+
return invalid(['orderBy', 0, 'by'], 'a page orders by Path or by a field its types index');
|
|
88
|
+
if (plan.root.types === null)
|
|
89
|
+
invalid('types', 'an order by a field names the types whose index it walks');
|
|
90
|
+
return {
|
|
91
|
+
by: 'field',
|
|
92
|
+
field,
|
|
93
|
+
direction: options.direction,
|
|
94
|
+
nulls: options.nulls ?? 'first',
|
|
95
|
+
lexical: options.stringSort === 'lexical',
|
|
96
|
+
after: afterOf(plan),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function keysWalk(plan, model, direction) {
|
|
100
|
+
const types = plan.root.types;
|
|
101
|
+
for (const { field: pointer, test } of conjuncts(plan.root.where)) {
|
|
102
|
+
const field = named(pointer);
|
|
103
|
+
if (types === null || field === null || (test.op !== 'eq' && test.op !== 'in'))
|
|
104
|
+
continue;
|
|
105
|
+
const definitions = indexing(model, types, field);
|
|
106
|
+
if (definitions === null)
|
|
107
|
+
continue;
|
|
108
|
+
return {
|
|
109
|
+
by: 'keys',
|
|
110
|
+
field,
|
|
111
|
+
direction,
|
|
112
|
+
types: definitions.map((definition) => ({
|
|
113
|
+
type: definition.name,
|
|
114
|
+
keys: testedKeys(definition.fields[field], test).keys,
|
|
115
|
+
})),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return { by: 'path', direction };
|
|
119
|
+
}
|
|
120
|
+
function common(types) {
|
|
121
|
+
const [first, ...rest] = types;
|
|
122
|
+
return (first?.indexed ?? [])
|
|
123
|
+
.filter((field) => rest.every((definition) => definition.indexed?.includes(field)))
|
|
124
|
+
.map((field) => `/${escapePointer(field)}`);
|
|
125
|
+
}
|
|
126
|
+
function ranged(facts, tests) {
|
|
127
|
+
if (tests.length === 0)
|
|
128
|
+
return null;
|
|
129
|
+
return tests
|
|
130
|
+
.map(({ test }) => testedKeys(facts, test).range)
|
|
131
|
+
.reduce((held, range) => ({
|
|
132
|
+
lower: tighter(held.lower, range.lower, 1),
|
|
133
|
+
upper: range.upper === null ? held.upper : tighter(held.upper, range.upper, -1),
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
function past(range, key, direction) {
|
|
137
|
+
const beyond = { key, inclusive: false };
|
|
138
|
+
return direction === 'asc'
|
|
139
|
+
? { ...range, lower: tighter(range.lower, beyond, 1) }
|
|
140
|
+
: { ...range, upper: tighter(range.upper, beyond, -1) };
|
|
141
|
+
}
|
|
142
|
+
function runsOf(facts, order, range) {
|
|
143
|
+
const missing = indexKey(facts, null);
|
|
144
|
+
const cursor = order.after?.key ?? null;
|
|
145
|
+
const amongNulls = cursor !== null && keyOrder(cursor, missing) === 0;
|
|
146
|
+
const nulls = range === null ? [{ by: 'key', key: missing, after: amongNulls }] : [];
|
|
147
|
+
const span = range ?? everyValue(facts);
|
|
148
|
+
if (cursor === null || amongNulls) {
|
|
149
|
+
if (order.nulls === 'first')
|
|
150
|
+
return [...nulls, { by: 'range', range: span }];
|
|
151
|
+
return amongNulls ? nulls : [{ by: 'range', range: span }, ...nulls];
|
|
152
|
+
}
|
|
153
|
+
const values = [
|
|
154
|
+
{ by: 'key', key: cursor, after: true },
|
|
155
|
+
{ by: 'range', range: past(span, cursor, order.direction) },
|
|
156
|
+
];
|
|
157
|
+
return order.nulls === 'first' ? values : [...values, ...nulls];
|
|
158
|
+
}
|
|
159
|
+
function unindexed(model, types, at, problem) {
|
|
160
|
+
const declared = types.flatMap((type) => Object.hasOwn(model.types, type) ? [model.types[type]] : []);
|
|
161
|
+
return invalid(at, problem, declared.length === types.length ? common(declared) : []);
|
|
162
|
+
}
|
|
163
|
+
export function walkOf(plan, model) {
|
|
164
|
+
const order = pageOrder(plan);
|
|
165
|
+
if (order.by === 'path')
|
|
166
|
+
return keysWalk(plan, model, order.direction);
|
|
167
|
+
const types = plan.root.types;
|
|
168
|
+
const definitions = indexing(model, types, order.field);
|
|
169
|
+
if (definitions === null)
|
|
170
|
+
return unindexed(model, types, ['orderBy', 0, 'by'], 'orders by a field every type it names indexes');
|
|
171
|
+
if (!order.lexical &&
|
|
172
|
+
definitions.some((definition) => !textless(definition.fields[order.field])))
|
|
173
|
+
invalid(['orderBy', 0, 'stringSort'], 'a page orders text by code point, as lexical');
|
|
174
|
+
const bounding = conjuncts(plan.root.where).filter(({ field, test }) => test.op === 'range' && named(field) === order.field);
|
|
175
|
+
return {
|
|
176
|
+
by: 'order',
|
|
177
|
+
field: order.field,
|
|
178
|
+
direction: order.direction,
|
|
179
|
+
types: definitions.map((definition) => {
|
|
180
|
+
const facts = definition.fields[order.field];
|
|
181
|
+
return { type: definition.name, runs: runsOf(facts, order, ranged(facts, bounding)) };
|
|
182
|
+
}),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
export function countShape(plan) {
|
|
186
|
+
const { shape } = plan;
|
|
187
|
+
if (shape.kind === 'documents' && !plan.total)
|
|
188
|
+
return false;
|
|
189
|
+
if (plan.root.types === null)
|
|
190
|
+
invalid('types', 'a count names the types whose index it reads');
|
|
191
|
+
if (plan.text !== null)
|
|
192
|
+
invalid('text', 'a count tests no text');
|
|
193
|
+
if (plan.hop !== null)
|
|
194
|
+
invalid('hop', 'a count tests no hop');
|
|
195
|
+
if (shape.kind === 'documents')
|
|
196
|
+
return true;
|
|
197
|
+
if (plan.total)
|
|
198
|
+
invalid('total', 'a page of groups answers no total');
|
|
199
|
+
const key = shape.groupBy[0];
|
|
200
|
+
if (shape.groupBy.length > 1)
|
|
201
|
+
invalid(['groupBy', 1], 'a page groups by one field');
|
|
202
|
+
if (key.of !== 'field' || named(key.field) === null)
|
|
203
|
+
invalid(['groupBy', 0], 'a page groups by a field its types index');
|
|
204
|
+
for (const part of ['size', 'updated', 'greatest'])
|
|
205
|
+
if (shape[part] !== false && shape[part] !== null)
|
|
206
|
+
invalid(['select', part], 'a group selects only its count');
|
|
207
|
+
shape.orderBy.forEach(({ by }, index) => {
|
|
208
|
+
if (typeof by === 'string' && by !== 'count')
|
|
209
|
+
invalid(['orderBy', index, 'by'], 'a page of groups orders by its count or its key');
|
|
210
|
+
});
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
function testedPlaces(where, at) {
|
|
214
|
+
if (!plain(where))
|
|
215
|
+
return [];
|
|
216
|
+
return Object.keys(where)
|
|
217
|
+
.sort()
|
|
218
|
+
.flatMap((name) => name === '$and' || name === '$or'
|
|
219
|
+
? where[name].flatMap((part, index) => testedPlaces(part, [...at, name, index]))
|
|
220
|
+
: [{ pointer: name, place: [...at, name] }]);
|
|
221
|
+
}
|
|
222
|
+
function countWalk(plan, model) {
|
|
223
|
+
const keyed = keysWalk(plan, model, 'asc');
|
|
224
|
+
if (keyed.by !== 'path')
|
|
225
|
+
return keyed;
|
|
226
|
+
const tests = conjuncts(plan.root.where);
|
|
227
|
+
for (const { field: pointer, test } of tests) {
|
|
228
|
+
const field = named(pointer);
|
|
229
|
+
if (test.op !== 'range' || field === null)
|
|
230
|
+
continue;
|
|
231
|
+
const definitions = indexing(model, plan.root.types, field);
|
|
232
|
+
if (definitions === null)
|
|
233
|
+
continue;
|
|
234
|
+
const bounding = tests.filter((bounded) => bounded.test.op === 'range' && bounded.field === pointer);
|
|
235
|
+
return {
|
|
236
|
+
by: 'order',
|
|
237
|
+
field,
|
|
238
|
+
direction: 'asc',
|
|
239
|
+
types: definitions.map((definition) => ({
|
|
240
|
+
type: definition.name,
|
|
241
|
+
runs: [{ by: 'range', range: ranged(definition.fields[field], bounding) }],
|
|
242
|
+
})),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
return keyed;
|
|
246
|
+
}
|
|
247
|
+
export function countOf(plan, model, where) {
|
|
248
|
+
if (!countShape(plan))
|
|
249
|
+
return null;
|
|
250
|
+
const types = plan.root.types;
|
|
251
|
+
const grouped = plan.shape.kind === 'groups'
|
|
252
|
+
? [{ pointer: plan.shape.groupBy[0].field, place: ['groupBy', 0] }]
|
|
253
|
+
: [];
|
|
254
|
+
const fields = [...grouped, ...testedPlaces(where, ['where'])].map(({ pointer, place }) => {
|
|
255
|
+
const field = named(pointer);
|
|
256
|
+
if (field === null || indexing(model, types, field) === null)
|
|
257
|
+
return unindexed(model, types, place, place[0] === 'groupBy'
|
|
258
|
+
? 'groups by a field every type it names indexes'
|
|
259
|
+
: 'a count tests only fields every type it names indexes');
|
|
260
|
+
return field;
|
|
261
|
+
});
|
|
262
|
+
return { walk: countWalk(plan, model), fields: [...new Set(fields)].sort() };
|
|
263
|
+
}
|
|
264
|
+
export function walkedValue(definition, field, value) {
|
|
265
|
+
const instant = instantOf(definition.fields[field], value);
|
|
266
|
+
return instant === null ? (value ?? null) : { instant };
|
|
267
|
+
}
|
|
268
|
+
export function hopTargets(plan, model, row) {
|
|
269
|
+
if (plan.hop === null || row.type === null || row.fields === null)
|
|
270
|
+
return [];
|
|
271
|
+
const definition = definitionAt(model, row.path)(row.type);
|
|
272
|
+
const { links } = indexed(row.path, row.fields, definition);
|
|
273
|
+
const named = new Map();
|
|
274
|
+
for (const { handle, target } of placedIn(links, plan.hop.field, 'link'))
|
|
275
|
+
named.set(`${handle ?? ''}\u0000${target}`, { handle, path: target });
|
|
276
|
+
return [...named].sort(([left], [right]) => byCodePoint(left, right)).map(([, target]) => target);
|
|
277
|
+
}
|
package/dist/references.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type Definition } from './definition.js';
|
|
2
2
|
import type { Document, Reference } from './types.js';
|
|
3
|
-
export declare function references(document: Document, definition: Definition): readonly Reference[];
|
|
3
|
+
export declare function references(document: Pick<Document, 'fields'>, definition: Definition): readonly Reference[];
|
|
4
4
|
//# sourceMappingURL=references.d.ts.map
|
package/dist/references.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,UAAU,EAEhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,UAAU,EAEhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA8BtD,wBAAgB,UAAU,CACxB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAClC,UAAU,EAAE,UAAU,GACrB,SAAS,SAAS,EAAE,CAItB"}
|