@agentshouse/mdmodel 0.1.0-alpha.9 → 0.1.0-c0d316445d94f
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 +298 -0
- package/README.md +34 -189
- package/dist/blocks.d.ts +11 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/blocks.js +62 -0
- package/dist/condition.d.ts +149 -0
- package/dist/condition.d.ts.map +1 -0
- package/dist/condition.js +497 -0
- package/dist/definition.d.ts +55 -27
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +531 -149
- package/dist/divide.d.ts +3 -0
- package/dist/divide.d.ts.map +1 -0
- package/dist/divide.js +310 -0
- package/dist/document.d.ts +8 -1
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +200 -125
- package/dist/fields.d.ts +4 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +3 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -4
- package/dist/links.d.ts +1 -0
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +618 -224
- package/dist/paths.d.ts +5 -3
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +47 -37
- package/dist/profile.js +1 -3
- package/dist/project.d.ts +19 -1
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +77 -94
- package/dist/references.d.ts +4 -0
- package/dist/references.d.ts.map +1 -0
- package/dist/references.js +25 -0
- package/dist/refuse.d.ts.map +1 -1
- package/dist/refuse.js +2 -10
- package/dist/schema.d.ts +7 -5
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +156 -41
- package/dist/sections.d.ts +2 -1
- package/dist/sections.d.ts.map +1 -1
- package/dist/sections.js +44 -66
- package/dist/types.d.ts +47 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -3
- package/dist/validate.d.ts +3 -2
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +131 -142
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -3
- package/dist/yaml.d.ts +2 -0
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +262 -192
- package/fixtures/README.md +91 -56
- package/fixtures/cases/absent-link-dangles/library/item.md +8 -0
- package/fixtures/cases/absent-link-dangles/schema.yaml +6 -0
- package/fixtures/cases/absent-optional-field/context.json +1 -0
- package/fixtures/cases/absent-optional-field/expected.json +1 -0
- package/fixtures/cases/absent-optional-field/library/companies/acme.md +4 -0
- package/fixtures/cases/absent-optional-field/library/deals/lead.md +6 -0
- package/fixtures/cases/absent-optional-field/schema.yaml +56 -0
- package/fixtures/cases/absolute-link/context.json +1 -0
- package/fixtures/cases/absolute-link/expected.json +5 -0
- package/fixtures/cases/absolute-link/library/item.md +8 -0
- package/fixtures/cases/absolute-link/schema.yaml +6 -0
- package/fixtures/cases/attachment-reference-any-file/context.json +1 -0
- package/fixtures/cases/attachment-reference-any-file/expected.json +1 -0
- package/fixtures/cases/attachment-reference-any-file/library/companies/acme.md +4 -0
- package/fixtures/cases/attachment-reference-any-file/library/deals/renewal.md +15 -0
- package/fixtures/cases/attachment-reference-any-file/library/places/depot.md +4 -0
- package/fixtures/cases/attachment-reference-any-file/library/products/seats.md +4 -0
- package/fixtures/cases/attachment-reference-any-file/library/products/support.md +4 -0
- package/fixtures/cases/attachment-reference-any-file/schema.yaml +32 -0
- package/fixtures/cases/attachment-reference-dangles/context.json +1 -0
- package/fixtures/cases/attachment-reference-dangles/expected.json +1 -0
- package/fixtures/cases/attachment-reference-dangles/library/companies/acme.md +4 -0
- package/fixtures/cases/attachment-reference-dangles/library/deals/renewal.md +15 -0
- package/fixtures/cases/attachment-reference-dangles/library/places/depot.md +4 -0
- package/fixtures/cases/attachment-reference-dangles/library/products/seats.md +4 -0
- package/fixtures/cases/attachment-reference-dangles/library/products/support.md +4 -0
- package/fixtures/cases/attachment-reference-dangles/schema.yaml +32 -0
- package/fixtures/cases/attachment-reference-outside/context.json +1 -0
- package/fixtures/cases/attachment-reference-outside/expected.json +6 -0
- package/fixtures/cases/attachment-reference-outside/library/companies/acme.md +4 -0
- package/fixtures/cases/attachment-reference-outside/library/deals/renewal.md +15 -0
- package/fixtures/cases/attachment-reference-outside/library/places/depot.md +4 -0
- package/fixtures/cases/attachment-reference-outside/library/products/seats.md +4 -0
- package/fixtures/cases/attachment-reference-outside/library/products/support.md +4 -0
- package/fixtures/cases/attachment-reference-outside/schema.yaml +32 -0
- package/fixtures/cases/binary-any-reference/expected.json +1 -2
- package/fixtures/cases/binary-any-reference/schema.yaml +4 -0
- package/fixtures/cases/binary-document-collision/expected.json +1 -2
- package/fixtures/cases/binary-document-collision/schema.yaml +1 -0
- package/fixtures/cases/binary-image-dangles/expected.json +1 -0
- package/fixtures/cases/binary-image-dangles/schema.yaml +1 -0
- package/fixtures/cases/binary-link-dangles/expected.json +1 -0
- package/fixtures/cases/binary-link-dangles/schema.yaml +1 -0
- package/fixtures/cases/binary-link-outside-collection/expected.json +1 -2
- package/fixtures/cases/binary-link-outside-collection/schema.yaml +1 -0
- package/fixtures/cases/binary-prototype-reference/expected.json +1 -2
- package/fixtures/cases/binary-prototype-reference/schema.yaml +4 -0
- package/fixtures/cases/binary-typed-reference/expected.json +1 -2
- package/fixtures/cases/binary-typed-reference/schema.yaml +5 -0
- package/fixtures/cases/boolean-field/context.json +1 -0
- package/fixtures/cases/boolean-field/expected.json +6 -0
- package/fixtures/cases/boolean-field/library/companies/acme.md +4 -0
- package/fixtures/cases/boolean-field/library/deals/renewal.md +31 -0
- package/fixtures/cases/boolean-field/schema.yaml +56 -0
- package/fixtures/cases/bracketed-link-definition/schema.yaml +6 -0
- package/fixtures/cases/closed-nested-object/context.json +1 -0
- package/fixtures/cases/closed-nested-object/expected.json +6 -0
- package/fixtures/cases/closed-nested-object/library/companies/acme.md +4 -0
- package/fixtures/cases/closed-nested-object/library/deals/renewal.md +32 -0
- package/fixtures/cases/closed-nested-object/schema.yaml +56 -0
- package/fixtures/cases/composed-root-reference/context.json +1 -0
- package/fixtures/cases/composed-root-reference/expected.json +6 -0
- package/fixtures/cases/composed-root-reference/library/a.md +5 -0
- package/fixtures/cases/composed-root-reference/schema.yaml +13 -0
- package/fixtures/cases/date-time-format/context.json +1 -0
- package/fixtures/cases/date-time-format/expected.json +6 -0
- package/fixtures/cases/date-time-format/library/companies/acme.md +4 -0
- package/fixtures/cases/date-time-format/library/deals/renewal.md +31 -0
- package/fixtures/cases/date-time-format/schema.yaml +56 -0
- package/fixtures/cases/declared-binary-links/schema.yaml +1 -0
- package/fixtures/cases/default-unfilled/context.json +1 -0
- package/fixtures/cases/default-unfilled/expected.json +6 -0
- package/fixtures/cases/default-unfilled/library/companies/acme.md +4 -0
- package/fixtures/cases/default-unfilled/library/deals/renewal.md +29 -0
- package/fixtures/cases/default-unfilled/schema.yaml +56 -0
- package/fixtures/cases/defs-pattern/context.json +1 -0
- package/fixtures/cases/defs-pattern/expected.json +6 -0
- package/fixtures/cases/defs-pattern/library/companies/acme.md +4 -0
- package/fixtures/cases/defs-pattern/library/deals/renewal.md +31 -0
- package/fixtures/cases/defs-pattern/schema.yaml +56 -0
- package/fixtures/cases/dependent-rule/context.json +1 -0
- package/fixtures/cases/dependent-rule/expected.json +6 -0
- package/fixtures/cases/dependent-rule/library/companies/acme.md +4 -0
- package/fixtures/cases/dependent-rule/library/deals/renewal.md +30 -0
- package/fixtures/cases/dependent-rule/schema.yaml +56 -0
- package/fixtures/cases/duplicate-link-definition/schema.yaml +6 -0
- package/fixtures/cases/email-format/context.json +1 -0
- package/fixtures/cases/email-format/expected.json +6 -0
- package/fixtures/cases/email-format/library/companies/acme.md +4 -0
- package/fixtures/cases/email-format/library/deals/renewal.md +31 -0
- package/fixtures/cases/email-format/schema.yaml +56 -0
- package/fixtures/cases/fenced-link-definition/schema.yaml +6 -0
- package/fixtures/cases/field-enum/expected.json +2 -3
- package/fixtures/cases/field-enum/schema.yaml +7 -0
- package/fixtures/cases/frontmatter-schema/context.json +1 -0
- package/fixtures/cases/frontmatter-schema/expected.json +5 -0
- package/fixtures/cases/frontmatter-schema/schema.yaml +5 -0
- package/fixtures/cases/integer-field/context.json +1 -0
- package/fixtures/cases/integer-field/expected.json +6 -0
- package/fixtures/cases/integer-field/library/companies/acme.md +4 -0
- package/fixtures/cases/integer-field/library/deals/renewal.md +31 -0
- package/fixtures/cases/integer-field/schema.yaml +56 -0
- package/fixtures/cases/interrupted-link-definition/schema.yaml +1 -0
- package/fixtures/cases/json-schema-constructs/context.json +1 -0
- package/fixtures/cases/json-schema-constructs/expected.json +1 -0
- package/fixtures/cases/json-schema-constructs/library/companies/acme.md +4 -0
- package/fixtures/cases/json-schema-constructs/library/deals/renewal.md +31 -0
- package/fixtures/cases/json-schema-constructs/schema.yaml +56 -0
- package/fixtures/cases/list-of-objects-closed/context.json +1 -0
- package/fixtures/cases/list-of-objects-closed/expected.json +6 -0
- package/fixtures/cases/list-of-objects-closed/library/companies/acme.md +4 -0
- package/fixtures/cases/list-of-objects-closed/library/deals/renewal.md +32 -0
- package/fixtures/cases/list-of-objects-closed/schema.yaml +56 -0
- package/fixtures/cases/list-of-objects-item/context.json +1 -0
- package/fixtures/cases/list-of-objects-item/expected.json +6 -0
- package/fixtures/cases/list-of-objects-item/library/companies/acme.md +4 -0
- package/fixtures/cases/list-of-objects-item/library/deals/renewal.md +31 -0
- package/fixtures/cases/list-of-objects-item/schema.yaml +56 -0
- package/fixtures/cases/list-of-objects-reference/context.json +1 -0
- package/fixtures/cases/list-of-objects-reference/expected.json +6 -0
- package/fixtures/cases/list-of-objects-reference/library/companies/acme.md +4 -0
- package/fixtures/cases/list-of-objects-reference/library/deals/renewal.md +14 -0
- package/fixtures/cases/list-of-objects-reference/library/places/depot.md +4 -0
- package/fixtures/cases/list-of-objects-reference/library/products/seats.md +4 -0
- package/fixtures/cases/list-of-objects-reference/library/products/support.md +4 -0
- package/fixtures/cases/list-of-objects-reference/schema.yaml +32 -0
- package/fixtures/cases/list-size/context.json +1 -0
- package/fixtures/cases/list-size/expected.json +6 -0
- package/fixtures/cases/list-size/library/companies/acme.md +4 -0
- package/fixtures/cases/list-size/library/deals/renewal.md +31 -0
- package/fixtures/cases/list-size/schema.yaml +56 -0
- package/fixtures/cases/long-fence-link-definition/schema.yaml +1 -0
- package/fixtures/cases/malformed-definition/expected.json +2 -4
- package/fixtures/cases/malformed-definition/schema.yaml +3 -0
- package/fixtures/cases/member-document/context.json +1 -0
- package/fixtures/cases/member-document/expected.json +1 -0
- package/fixtures/cases/member-document/library/people/ana.md +5 -0
- package/fixtures/cases/member-document/schema.yaml +5 -0
- package/fixtures/cases/missing-required-field/expected.json +2 -3
- package/fixtures/cases/missing-required-field/schema.yaml +7 -0
- package/fixtures/cases/missing-section-item-kind/expected.json +2 -4
- package/fixtures/cases/missing-section-item-kind/schema.yaml +6 -0
- package/fixtures/cases/misspelled-key/context.json +1 -0
- package/fixtures/cases/misspelled-key/expected.json +6 -0
- package/fixtures/cases/misspelled-key/library/companies/acme.md +4 -0
- package/fixtures/cases/misspelled-key/library/deals/renewal.md +32 -0
- package/fixtures/cases/misspelled-key/schema.yaml +56 -0
- package/fixtures/cases/nested-defs/context.json +1 -0
- package/fixtures/cases/nested-defs/expected.json +6 -0
- package/fixtures/cases/nested-defs/library/deal.md +6 -0
- package/fixtures/cases/nested-defs/schema.yaml +11 -0
- package/fixtures/cases/nested-object-reference/context.json +1 -0
- package/fixtures/cases/nested-object-reference/expected.json +6 -0
- package/fixtures/cases/nested-object-reference/library/companies/acme.md +4 -0
- package/fixtures/cases/nested-object-reference/library/deals/renewal.md +14 -0
- package/fixtures/cases/nested-object-reference/library/places/depot.md +4 -0
- package/fixtures/cases/nested-object-reference/library/products/seats.md +4 -0
- package/fixtures/cases/nested-object-reference/library/products/support.md +4 -0
- package/fixtures/cases/nested-object-reference/schema.yaml +32 -0
- package/fixtures/cases/nested-reference/context.json +1 -0
- package/fixtures/cases/nested-reference/expected.json +1 -0
- package/fixtures/cases/nested-reference/library/companies/acme.md +4 -0
- package/fixtures/cases/nested-reference/library/deals/renewal.md +15 -0
- package/fixtures/cases/nested-reference/library/places/depot.md +4 -0
- package/fixtures/cases/nested-reference/library/products/seats.md +4 -0
- package/fixtures/cases/nested-reference/library/products/support.md +4 -0
- package/fixtures/cases/nested-reference/schema.yaml +32 -0
- package/fixtures/cases/nested-required-field/context.json +1 -0
- package/fixtures/cases/nested-required-field/expected.json +6 -0
- package/fixtures/cases/nested-required-field/library/companies/acme.md +4 -0
- package/fixtures/cases/nested-required-field/library/deals/renewal.md +30 -0
- package/fixtures/cases/nested-required-field/schema.yaml +56 -0
- package/fixtures/cases/null-refused/context.json +1 -0
- package/fixtures/cases/null-refused/expected.json +6 -0
- package/fixtures/cases/null-refused/library/companies/acme.md +4 -0
- package/fixtures/cases/null-refused/library/deals/renewal.md +31 -0
- package/fixtures/cases/null-refused/schema.yaml +56 -0
- package/fixtures/cases/numeric-range/context.json +1 -0
- package/fixtures/cases/numeric-range/expected.json +6 -0
- package/fixtures/cases/numeric-range/library/companies/acme.md +4 -0
- package/fixtures/cases/numeric-range/library/deals/renewal.md +31 -0
- package/fixtures/cases/numeric-range/schema.yaml +56 -0
- package/fixtures/cases/one-of-variant/context.json +1 -0
- package/fixtures/cases/one-of-variant/expected.json +6 -0
- package/fixtures/cases/one-of-variant/library/companies/acme.md +4 -0
- package/fixtures/cases/one-of-variant/library/deals/renewal.md +31 -0
- package/fixtures/cases/one-of-variant/schema.yaml +56 -0
- package/fixtures/cases/open-map-value/context.json +1 -0
- package/fixtures/cases/open-map-value/expected.json +6 -0
- package/fixtures/cases/open-map-value/library/companies/acme.md +4 -0
- package/fixtures/cases/open-map-value/library/deals/renewal.md +31 -0
- package/fixtures/cases/open-map-value/schema.yaml +56 -0
- package/fixtures/cases/other-room-reference/context.json +1 -0
- package/fixtures/cases/other-room-reference/expected.json +6 -0
- package/fixtures/cases/other-room-reference/library/companies/acme.md +4 -0
- package/fixtures/cases/other-room-reference/library/deals/renewal.md +14 -0
- package/fixtures/cases/other-room-reference/library/places/depot.md +4 -0
- package/fixtures/cases/other-room-reference/library/products/seats.md +4 -0
- package/fixtures/cases/other-room-reference/library/products/support.md +4 -0
- package/fixtures/cases/other-room-reference/schema.yaml +32 -0
- package/fixtures/cases/paragraph-link-definition/schema.yaml +1 -0
- package/fixtures/cases/prototype-field/expected.json +2 -3
- package/fixtures/cases/prototype-field/schema.yaml +6 -0
- package/fixtures/cases/quoted-link-definition/expected.json +1 -2
- package/fixtures/cases/quoted-link-definition/library/notes/draft.md +1 -1
- package/fixtures/cases/quoted-link-definition/schema.yaml +1 -0
- package/fixtures/cases/referenced-missing-file/expected.json +0 -1
- package/fixtures/cases/referenced-missing-file/schema.yaml +11 -0
- package/fixtures/cases/remote-ref/context.json +1 -0
- package/fixtures/cases/remote-ref/expected.json +5 -0
- package/fixtures/cases/remote-ref/schema.yaml +3 -0
- package/fixtures/cases/second-member-document/context.json +1 -0
- package/fixtures/cases/second-member-document/expected.json +5 -0
- package/fixtures/cases/second-member-document/schema.yaml +4 -0
- package/fixtures/cases/section-item-enum/context.json +1 -0
- package/fixtures/cases/section-item-enum/expected.json +6 -0
- package/fixtures/cases/section-item-enum/library/task.md +8 -0
- package/fixtures/cases/section-item-enum/schema.yaml +3 -0
- package/fixtures/cases/section-item-kind/context.json +1 -0
- package/fixtures/cases/section-item-kind/expected.json +6 -0
- package/fixtures/cases/section-item-kind/library/task.md +8 -0
- package/fixtures/cases/section-item-kind/schema.yaml +3 -0
- package/fixtures/cases/section-items/context.json +1 -0
- package/fixtures/cases/section-items/expected.json +1 -0
- package/fixtures/cases/section-items/library/other.md +3 -0
- package/fixtures/cases/section-items/library/page.md +42 -0
- package/fixtures/cases/section-items/schema.yaml +10 -0
- package/fixtures/cases/section-reference-path/context.json +1 -0
- package/fixtures/cases/section-reference-path/expected.json +6 -0
- package/fixtures/cases/section-reference-path/library/other.md +3 -0
- package/fixtures/cases/section-reference-path/library/page.md +7 -0
- package/fixtures/cases/section-reference-path/schema.yaml +3 -0
- package/fixtures/cases/section-reference-type/context.json +1 -0
- package/fixtures/cases/section-reference-type/expected.json +6 -0
- package/fixtures/cases/section-reference-type/library/note.md +1 -0
- package/fixtures/cases/section-reference-type/library/page.md +7 -0
- package/fixtures/cases/section-reference-type/schema.yaml +3 -0
- package/fixtures/cases/shortcut-reference-link/context.json +1 -0
- package/fixtures/cases/shortcut-reference-link/expected.json +5 -0
- package/fixtures/cases/shortcut-reference-link/library/item.md +10 -0
- package/fixtures/cases/shortcut-reference-link/schema.yaml +6 -0
- package/fixtures/cases/string-length/context.json +1 -0
- package/fixtures/cases/string-length/expected.json +6 -0
- package/fixtures/cases/string-length/library/companies/acme.md +4 -0
- package/fixtures/cases/string-length/library/deals/renewal.md +31 -0
- package/fixtures/cases/string-length/schema.yaml +56 -0
- package/fixtures/cases/structured-section/expected.json +1 -2
- package/fixtures/cases/structured-section/schema.yaml +7 -0
- package/fixtures/cases/submission-keys/context.json +1 -0
- package/fixtures/cases/submission-keys/expected.json +1 -0
- package/fixtures/cases/submission-keys/library/notes/visitor.md +8 -0
- package/fixtures/cases/submission-keys/schema.yaml +4 -0
- package/fixtures/cases/text-field-kind/context.json +1 -0
- package/fixtures/cases/text-field-kind/expected.json +6 -0
- package/fixtures/cases/text-field-kind/library/page.md +4 -0
- package/fixtures/cases/text-field-kind/schema.yaml +4 -0
- package/fixtures/cases/truncated-link-definition/expected.json +1 -2
- package/fixtures/cases/truncated-link-definition/library/notes/draft.md +1 -1
- package/fixtures/cases/truncated-link-definition/schema.yaml +1 -0
- package/fixtures/cases/types-folder-content/context.json +1 -0
- package/fixtures/cases/types-folder-content/expected.json +1 -0
- package/fixtures/cases/types-folder-content/library/types/task.md +4 -0
- package/fixtures/cases/types-folder-content/schema.yaml +4 -0
- package/fixtures/cases/unclosed-frontmatter/expected.json +1 -2
- package/fixtures/cases/undeclared-field/expected.json +2 -3
- package/fixtures/cases/undeclared-field/schema.yaml +6 -0
- package/fixtures/cases/unevaluated-items-closed/context.json +1 -0
- package/fixtures/cases/unevaluated-items-closed/expected.json +6 -0
- package/fixtures/cases/unevaluated-items-closed/library/trip.md +6 -0
- package/fixtures/cases/unevaluated-items-closed/schema.yaml +10 -0
- package/fixtures/cases/unknown-type/context.json +1 -0
- package/fixtures/cases/unknown-type/expected.json +6 -0
- package/fixtures/cases/unknown-type/library/item.md +3 -0
- package/fixtures/cases/unknown-type/schema.yaml +3 -0
- package/fixtures/cases/unlisted-reference-type/context.json +1 -0
- package/fixtures/cases/unlisted-reference-type/expected.json +5 -0
- package/fixtures/cases/unlisted-reference-type/schema.yaml +3 -0
- package/fixtures/cases/unresolved-link/expected.json +1 -2
- package/fixtures/cases/unresolved-link/library/item.md +1 -1
- package/fixtures/cases/unresolved-link/schema.yaml +6 -0
- package/fixtures/cases/valid-typed-document/schema.yaml +16 -0
- package/fixtures/cases/wide-item-fence-link/schema.yaml +1 -0
- package/fixtures/division.json +409 -0
- package/fixtures/projection.json +90 -21
- package/package.json +3 -12
- package/dist/definition.js.map +0 -1
- package/dist/document.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/links.js.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/profile.js.map +0 -1
- package/dist/project.js.map +0 -1
- package/dist/refuse.js.map +0 -1
- package/dist/schema.js.map +0 -1
- package/dist/sections.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/validate.js.map +0 -1
- package/dist/version.js.map +0 -1
- package/dist/yaml.js.map +0 -1
- package/fixtures/cases/binary-any-reference/library/types/note.md +0 -5
- package/fixtures/cases/binary-document-collision/library/types/note.md +0 -3
- package/fixtures/cases/binary-link-outside-collection/library/types/note.md +0 -3
- package/fixtures/cases/binary-prototype-reference/library/types/note.md +0 -5
- package/fixtures/cases/binary-typed-reference/library/types/note.md +0 -5
- package/fixtures/cases/binary-typed-reference/library/types/person.md +0 -3
- package/fixtures/cases/bracketed-link-definition/library/types/task.md +0 -7
- package/fixtures/cases/declared-binary-links/library/types/note.md +0 -3
- package/fixtures/cases/duplicate-link-definition/library/types/task.md +0 -7
- package/fixtures/cases/fenced-link-definition/library/types/task.md +0 -7
- package/fixtures/cases/field-enum/library/types/task.md +0 -8
- package/fixtures/cases/interrupted-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/long-fence-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/malformed-definition/library/types/task.md +0 -5
- package/fixtures/cases/missing-binary-image/expected.json +0 -6
- package/fixtures/cases/missing-binary-image/library/types/note.md +0 -3
- package/fixtures/cases/missing-binary-link/expected.json +0 -6
- package/fixtures/cases/missing-binary-link/library/types/note.md +0 -3
- package/fixtures/cases/missing-required-field/library/types/task.md +0 -8
- package/fixtures/cases/missing-section-item-kind/library/types/task.md +0 -7
- package/fixtures/cases/paragraph-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/prd-definition/library/types/task.md +0 -16
- package/fixtures/cases/prototype-field/library/types/task.md +0 -7
- package/fixtures/cases/quoted-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/referenced-missing-file/library/types/person.md +0 -5
- package/fixtures/cases/referenced-missing-file/library/types/task.md +0 -8
- package/fixtures/cases/structured-section/library/types/task.md +0 -8
- package/fixtures/cases/truncated-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/undeclared-field/library/types/task.md +0 -7
- package/fixtures/cases/unresolved-link/library/types/task.md +0 -7
- package/fixtures/cases/valid-typed-document/library/types/person.md +0 -5
- package/fixtures/cases/valid-typed-document/library/types/task.md +0 -13
- package/fixtures/cases/wide-item-fence-link/library/types/note.md +0 -3
- package/markdown-syntax-profile.md +0 -9
- /package/fixtures/cases/{prd-definition → absent-link-dangles}/context.json +0 -0
- /package/fixtures/cases/{prd-definition → absent-link-dangles}/expected.json +0 -0
- /package/fixtures/cases/{missing-binary-image → binary-image-dangles}/context.json +0 -0
- /package/fixtures/cases/{missing-binary-image → binary-image-dangles}/library/notes/draft.md +0 -0
- /package/fixtures/cases/{missing-binary-link → binary-link-dangles}/context.json +0 -0
- /package/fixtures/cases/{missing-binary-link → binary-link-dangles}/library/notes/draft.md +0 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { type ValueFacts } from './definition.js';
|
|
2
|
+
import type { Document, VerifiedModel } from './types.js';
|
|
3
|
+
export type ConditionValue = string | number | boolean | {
|
|
4
|
+
readonly owner: true;
|
|
5
|
+
};
|
|
6
|
+
export type ConditionTest = {
|
|
7
|
+
readonly all: readonly ConditionTest[];
|
|
8
|
+
} | {
|
|
9
|
+
readonly any: readonly ConditionTest[];
|
|
10
|
+
} | {
|
|
11
|
+
readonly not: ConditionTest;
|
|
12
|
+
} | ({
|
|
13
|
+
readonly path: string;
|
|
14
|
+
} & ({
|
|
15
|
+
readonly eq: ConditionValue;
|
|
16
|
+
} | {
|
|
17
|
+
readonly in: readonly ConditionValue[];
|
|
18
|
+
} | {
|
|
19
|
+
readonly exists: boolean;
|
|
20
|
+
} | {
|
|
21
|
+
readonly contains: ConditionValue;
|
|
22
|
+
} | {
|
|
23
|
+
readonly gt: number | string;
|
|
24
|
+
} | {
|
|
25
|
+
readonly gte: number | string;
|
|
26
|
+
} | {
|
|
27
|
+
readonly lt: number | string;
|
|
28
|
+
} | {
|
|
29
|
+
readonly lte: number | string;
|
|
30
|
+
} | {
|
|
31
|
+
readonly prefix: string;
|
|
32
|
+
}));
|
|
33
|
+
export type ConditionScope = {
|
|
34
|
+
readonly type: string;
|
|
35
|
+
} | {
|
|
36
|
+
readonly folder: string;
|
|
37
|
+
} | {
|
|
38
|
+
readonly document: string;
|
|
39
|
+
};
|
|
40
|
+
type DocumentEventBase = {
|
|
41
|
+
readonly on: 'documents';
|
|
42
|
+
readonly scope: ConditionScope;
|
|
43
|
+
readonly by?: ConditionTest;
|
|
44
|
+
};
|
|
45
|
+
export type DocumentCondition = (DocumentEventBase & {
|
|
46
|
+
readonly mode: 'starts_matching';
|
|
47
|
+
readonly new_documents: boolean;
|
|
48
|
+
readonly match: ConditionTest;
|
|
49
|
+
}) | (DocumentEventBase & {
|
|
50
|
+
readonly mode: 'field_changes';
|
|
51
|
+
readonly field: string;
|
|
52
|
+
readonly from?: readonly ConditionValue[] | 'new';
|
|
53
|
+
readonly to?: readonly ConditionValue[] | 'deleted';
|
|
54
|
+
readonly match?: ConditionTest;
|
|
55
|
+
});
|
|
56
|
+
export type ItemCondition = {
|
|
57
|
+
readonly on: 'items';
|
|
58
|
+
readonly source?: string;
|
|
59
|
+
readonly address?: string;
|
|
60
|
+
readonly match?: ConditionTest;
|
|
61
|
+
};
|
|
62
|
+
export type CronCondition = {
|
|
63
|
+
readonly on: 'clock';
|
|
64
|
+
readonly cron: string;
|
|
65
|
+
readonly time_zone: string;
|
|
66
|
+
};
|
|
67
|
+
export type DateCondition = {
|
|
68
|
+
readonly on: 'clock';
|
|
69
|
+
readonly scope: {
|
|
70
|
+
readonly type: string;
|
|
71
|
+
};
|
|
72
|
+
readonly date: string;
|
|
73
|
+
readonly days: number;
|
|
74
|
+
readonly at: string;
|
|
75
|
+
readonly time_zone: string;
|
|
76
|
+
readonly match?: ConditionTest;
|
|
77
|
+
};
|
|
78
|
+
export type Condition = DocumentCondition | ItemCondition | CronCondition | DateCondition;
|
|
79
|
+
export type FactKind = 'string' | 'number' | 'boolean' | 'date' | 'time' | 'enum' | 'reference';
|
|
80
|
+
type Scalar = string | number | boolean;
|
|
81
|
+
export type Fact = {
|
|
82
|
+
readonly kind: FactKind;
|
|
83
|
+
readonly value: Scalar;
|
|
84
|
+
readonly member?: string;
|
|
85
|
+
} | {
|
|
86
|
+
readonly kind: 'prose';
|
|
87
|
+
} | {
|
|
88
|
+
readonly kind: 'null';
|
|
89
|
+
} | {
|
|
90
|
+
readonly kind: 'unreadable';
|
|
91
|
+
} | {
|
|
92
|
+
readonly kind: 'list';
|
|
93
|
+
readonly items: readonly Fact[];
|
|
94
|
+
} | {
|
|
95
|
+
readonly kind: 'object';
|
|
96
|
+
readonly fields: Readonly<Record<string, Fact>>;
|
|
97
|
+
};
|
|
98
|
+
export type DocumentFacts = {
|
|
99
|
+
readonly id: string;
|
|
100
|
+
readonly path: string;
|
|
101
|
+
readonly type: string | null;
|
|
102
|
+
readonly fields: Readonly<Record<string, Fact>>;
|
|
103
|
+
readonly sections: readonly string[];
|
|
104
|
+
};
|
|
105
|
+
export declare const WRITE_DOORS: readonly ['browser', 'agent', 'client'];
|
|
106
|
+
export type WriteDoor = (typeof WRITE_DOORS)[number];
|
|
107
|
+
export type Actor = {
|
|
108
|
+
readonly user?: string;
|
|
109
|
+
readonly site?: string;
|
|
110
|
+
readonly door?: WriteDoor;
|
|
111
|
+
};
|
|
112
|
+
export type DocumentEvent = {
|
|
113
|
+
readonly before: DocumentFacts | null;
|
|
114
|
+
readonly after: DocumentFacts | null;
|
|
115
|
+
readonly changed: readonly string[];
|
|
116
|
+
readonly by: Actor;
|
|
117
|
+
};
|
|
118
|
+
export type ItemFacts = {
|
|
119
|
+
readonly delivery: string;
|
|
120
|
+
readonly source: string | null;
|
|
121
|
+
readonly address: string | null;
|
|
122
|
+
readonly has_attachment: boolean;
|
|
123
|
+
readonly provider: string | null;
|
|
124
|
+
readonly container: string | null;
|
|
125
|
+
readonly author: string | null;
|
|
126
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
127
|
+
readonly json: {
|
|
128
|
+
readonly value: unknown;
|
|
129
|
+
} | null;
|
|
130
|
+
};
|
|
131
|
+
export type Resolved = {
|
|
132
|
+
readonly id: string;
|
|
133
|
+
readonly member?: string;
|
|
134
|
+
};
|
|
135
|
+
type Truth = boolean | undefined;
|
|
136
|
+
export declare function factKind(facts: ValueFacts): FactKind | null;
|
|
137
|
+
export declare function facts(document: Document, at: {
|
|
138
|
+
readonly id: string;
|
|
139
|
+
readonly path: string;
|
|
140
|
+
}, model: VerifiedModel, resolve: (target: string) => Resolved | undefined): DocumentFacts;
|
|
141
|
+
export declare function prosePaths(facts: DocumentFacts): string[];
|
|
142
|
+
export declare function dated(value: unknown): value is string;
|
|
143
|
+
export declare function instant(value: unknown): bigint | undefined;
|
|
144
|
+
export declare function pointed(value: unknown, pointer: string): unknown;
|
|
145
|
+
export declare function holds(test: ConditionTest, document: DocumentFacts, owner: string): Truth;
|
|
146
|
+
export declare function fires(condition: DocumentCondition, event: DocumentEvent, owner: string): boolean;
|
|
147
|
+
export declare function itemFires(condition: ItemCondition, item: ItemFacts, owner: string): boolean;
|
|
148
|
+
export {};
|
|
149
|
+
//# sourceMappingURL=condition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../src/condition.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,UAAU,EAChB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG1D,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAA;CAAE,CAAC;AAElF,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,GAAG,EAAE,SAAS,aAAa,EAAE,CAAA;CAAE,GAC1C;IAAE,QAAQ,CAAC,GAAG,EAAE,SAAS,aAAa,EAAE,CAAA;CAAE,GAC1C;IAAE,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAA;CAAE,GAC/B,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,CACzB;IAAE,QAAQ,CAAC,EAAE,EAAE,cAAc,CAAA;CAAE,GAC/B;IAAE,QAAQ,CAAC,EAAE,EAAE,SAAS,cAAc,EAAE,CAAA;CAAE,GAC1C;IAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAA;CAAE,GACrC;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;CAA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Bf;AAMD,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,EAAE,CAYzD;AAkHD,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAIrD;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAgC1D;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAehE;AAmJD,wBAAgB,KAAK,CAAC,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,CAExF;AAqFD,wBAAgB,KAAK,CAAC,SAAS,EAAE,iBAAiB,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAehG;AAED,wBAAgB,SAAS,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAO3F"}
|
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
import { ARRAY_INDEX, escapePointer, fieldFacts, itemFacts, memberFacts, pointerSegments, } from './definition.js';
|
|
2
|
+
import { target } from './paths.js';
|
|
3
|
+
import { isRecord } from './yaml.js';
|
|
4
|
+
export const WRITE_DOORS = ['browser', 'agent', 'client'];
|
|
5
|
+
const PROSE = { kind: 'prose' };
|
|
6
|
+
const NULL = { kind: 'null' };
|
|
7
|
+
const UNREADABLE = { kind: 'unreadable' };
|
|
8
|
+
const UNREAD = { present: undefined, values: [undefined], items: [undefined] };
|
|
9
|
+
const NO_ITEM = { present: false, values: [], items: [] };
|
|
10
|
+
const DATE = /^\d{4}-\d{2}-\d{2}$/u;
|
|
11
|
+
const DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(?:[Zz]|([+-])(\d{2}):(\d{2}))$/u;
|
|
12
|
+
export function factKind(facts) {
|
|
13
|
+
if (facts.reference !== undefined)
|
|
14
|
+
return 'reference';
|
|
15
|
+
if (facts.values !== undefined)
|
|
16
|
+
return 'enum';
|
|
17
|
+
if (facts.type === 'number' || facts.type === 'integer')
|
|
18
|
+
return 'number';
|
|
19
|
+
if (facts.type === 'boolean')
|
|
20
|
+
return 'boolean';
|
|
21
|
+
if (facts.type !== 'string')
|
|
22
|
+
return null;
|
|
23
|
+
if (facts.format === 'date')
|
|
24
|
+
return 'date';
|
|
25
|
+
if (facts.format === 'date-time')
|
|
26
|
+
return 'time';
|
|
27
|
+
return 'string';
|
|
28
|
+
}
|
|
29
|
+
function fits(kind, facts, value) {
|
|
30
|
+
if (!scalar(value))
|
|
31
|
+
return false;
|
|
32
|
+
if (kind === 'enum')
|
|
33
|
+
return (facts.values ?? []).includes(value);
|
|
34
|
+
if (kind === 'number')
|
|
35
|
+
return typeof value === 'number';
|
|
36
|
+
if (kind === 'boolean')
|
|
37
|
+
return typeof value === 'boolean';
|
|
38
|
+
if (typeof value !== 'string')
|
|
39
|
+
return false;
|
|
40
|
+
if (kind === 'date')
|
|
41
|
+
return dated(value);
|
|
42
|
+
if (kind === 'time')
|
|
43
|
+
return instant(value) !== undefined;
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
function factOf(value, declared, place) {
|
|
47
|
+
if (value === null)
|
|
48
|
+
return NULL;
|
|
49
|
+
if (Array.isArray(value)) {
|
|
50
|
+
if (declared?.type !== undefined && declared.type !== 'array')
|
|
51
|
+
return UNREADABLE;
|
|
52
|
+
return {
|
|
53
|
+
kind: 'list',
|
|
54
|
+
items: value.map((item, index) => factOf(item, declared === undefined ? undefined : itemFacts(declared, index), place)),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (plain(value)) {
|
|
58
|
+
if (declared?.type !== undefined && declared.type !== 'object')
|
|
59
|
+
return UNREADABLE;
|
|
60
|
+
const fields = Object.create(null);
|
|
61
|
+
for (const [key, held] of Object.entries(value))
|
|
62
|
+
fields[key] = factOf(held, declared === undefined ? undefined : memberFacts(declared, key), place);
|
|
63
|
+
return { kind: 'object', fields };
|
|
64
|
+
}
|
|
65
|
+
if (declared?.type === 'array' || declared?.type === 'object')
|
|
66
|
+
return UNREADABLE;
|
|
67
|
+
const kind = declared === undefined || declared.prose ? null : factKind(declared);
|
|
68
|
+
if (kind === null)
|
|
69
|
+
return PROSE;
|
|
70
|
+
if (!fits(kind, declared, value))
|
|
71
|
+
return UNREADABLE;
|
|
72
|
+
if (kind !== 'reference')
|
|
73
|
+
return { kind, value };
|
|
74
|
+
const reached = target(place.path, value);
|
|
75
|
+
const resolved = reached === null ? undefined : place.resolve(reached);
|
|
76
|
+
if (resolved === undefined)
|
|
77
|
+
return UNREADABLE;
|
|
78
|
+
return resolved.member === undefined
|
|
79
|
+
? { kind, value: resolved.id }
|
|
80
|
+
: { kind, value: resolved.id, member: resolved.member };
|
|
81
|
+
}
|
|
82
|
+
export function facts(document, at, model, resolve) {
|
|
83
|
+
const type = document.type ?? null;
|
|
84
|
+
const definition = type !== null && Object.hasOwn(model.types, type) ? model.types[type] : null;
|
|
85
|
+
const fields = Object.create(null);
|
|
86
|
+
const place = { path: at.path, resolve };
|
|
87
|
+
for (const [name, value] of Object.entries(document.fields)) {
|
|
88
|
+
const declared = definition === null ? undefined : fieldFacts(definition, name);
|
|
89
|
+
if (declared !== undefined)
|
|
90
|
+
fields[name] = factOf(value, declared, place);
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
id: at.id,
|
|
94
|
+
path: `/${at.path}`,
|
|
95
|
+
type,
|
|
96
|
+
fields,
|
|
97
|
+
sections: Object.keys(document.sections).sort(),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function rootOf(facts, prefix) {
|
|
101
|
+
return { pointer: prefix, fact: { kind: 'object', fields: facts.fields } };
|
|
102
|
+
}
|
|
103
|
+
export function prosePaths(facts) {
|
|
104
|
+
const paths = facts.sections.map((heading) => `/sections/${heading}`);
|
|
105
|
+
const visit = ({ pointer, fact }) => {
|
|
106
|
+
if (fact.kind === 'prose')
|
|
107
|
+
paths.push(pointer);
|
|
108
|
+
if (fact.kind === 'list')
|
|
109
|
+
fact.items.forEach((item, index) => visit({ pointer: `${pointer}/${index}`, fact: item }));
|
|
110
|
+
if (fact.kind === 'object')
|
|
111
|
+
for (const [key, held] of Object.entries(fact.fields))
|
|
112
|
+
visit({ pointer: `${pointer}/${escapePointer(key)}`, fact: held });
|
|
113
|
+
};
|
|
114
|
+
visit(rootOf(facts, '/fields'));
|
|
115
|
+
return paths.sort();
|
|
116
|
+
}
|
|
117
|
+
function walked(start, pointer) {
|
|
118
|
+
let reached = [start];
|
|
119
|
+
let several = false;
|
|
120
|
+
let missing = false;
|
|
121
|
+
const each = (from, next) => from.flatMap((one) => {
|
|
122
|
+
const found = next(one);
|
|
123
|
+
if (found === null)
|
|
124
|
+
missing = true;
|
|
125
|
+
return found ?? [];
|
|
126
|
+
});
|
|
127
|
+
for (const token of pointerSegments(pointer)) {
|
|
128
|
+
const step = ({ pointer: at, fact }) => {
|
|
129
|
+
if (fact.kind === 'unreadable')
|
|
130
|
+
return [{ pointer: at, fact }];
|
|
131
|
+
if (fact.kind === 'object')
|
|
132
|
+
return Object.hasOwn(fact.fields, token)
|
|
133
|
+
? [{ pointer: `${at}/${escapePointer(token)}`, fact: fact.fields[token] }]
|
|
134
|
+
: null;
|
|
135
|
+
if (fact.kind !== 'list')
|
|
136
|
+
return null;
|
|
137
|
+
if (ARRAY_INDEX.test(token)) {
|
|
138
|
+
const item = fact.items[Number(token)];
|
|
139
|
+
return item === undefined ? null : [{ pointer: `${at}/${token}`, fact: item }];
|
|
140
|
+
}
|
|
141
|
+
several = true;
|
|
142
|
+
return each(fact.items.map((item, index) => ({ pointer: `${at}/${index}`, fact: item })), step);
|
|
143
|
+
};
|
|
144
|
+
reached = each(reached, step);
|
|
145
|
+
}
|
|
146
|
+
return { reached, several, missing };
|
|
147
|
+
}
|
|
148
|
+
function expand(fact) {
|
|
149
|
+
return fact.kind === 'list' ? fact.items.flatMap(expand) : [fact];
|
|
150
|
+
}
|
|
151
|
+
function fieldHeld(fact) {
|
|
152
|
+
if (fact.kind === 'unreadable')
|
|
153
|
+
return undefined;
|
|
154
|
+
if (fact.kind === 'null')
|
|
155
|
+
return { kind: 'null' };
|
|
156
|
+
return 'value' in fact ? { kind: fact.kind, value: fact.value } : { kind: 'prose' };
|
|
157
|
+
}
|
|
158
|
+
function memberHeld(fact) {
|
|
159
|
+
if (fact.kind === 'unreadable')
|
|
160
|
+
return undefined;
|
|
161
|
+
return fact.kind === 'reference' && fact.member !== undefined
|
|
162
|
+
? { kind: 'member', value: fact.member }
|
|
163
|
+
: null;
|
|
164
|
+
}
|
|
165
|
+
function single(held) {
|
|
166
|
+
return { present: true, values: [held], items: null };
|
|
167
|
+
}
|
|
168
|
+
function documentRead({ reached, several, missing }, held) {
|
|
169
|
+
if (reached.length === 0)
|
|
170
|
+
return missing ? undefined : NO_ITEM;
|
|
171
|
+
const facts = reached.map(({ fact }) => fact);
|
|
172
|
+
const kept = (all) => all.map(held).filter((value) => value !== null);
|
|
173
|
+
const unknown = missing ? [undefined] : [];
|
|
174
|
+
const values = kept(facts.filter((fact) => fact.kind !== 'list'));
|
|
175
|
+
const listed = several || facts.some((fact) => fact.kind === 'list');
|
|
176
|
+
const present = facts.some((fact) => fact.kind === 'list') || values.some(Boolean);
|
|
177
|
+
return {
|
|
178
|
+
present: present ? true : values.length > 0 ? undefined : false,
|
|
179
|
+
values: [...values, ...unknown],
|
|
180
|
+
items: listed ? [...kept(facts.flatMap(expand)), ...unknown] : null,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function readDocument(facts, path) {
|
|
184
|
+
if (path === '/path')
|
|
185
|
+
return single({ kind: 'path', value: facts.path });
|
|
186
|
+
if (path === '/type')
|
|
187
|
+
return facts.type === null ? undefined : single({ kind: 'string', value: facts.type });
|
|
188
|
+
if (path.startsWith('/sections/'))
|
|
189
|
+
return facts.sections.includes(path.slice('/sections/'.length))
|
|
190
|
+
? single({ kind: 'prose' })
|
|
191
|
+
: undefined;
|
|
192
|
+
if (path.startsWith('/fields/'))
|
|
193
|
+
return documentRead(walked(rootOf(facts, '/fields'), path.slice('/fields'.length)), fieldHeld);
|
|
194
|
+
if (path.startsWith('/members/'))
|
|
195
|
+
return documentRead(walked(rootOf(facts, '/members'), path.slice('/members'.length)), memberHeld);
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
function readActor(actor, path) {
|
|
199
|
+
const value = path === '/user'
|
|
200
|
+
? actor.user
|
|
201
|
+
: path === '/site'
|
|
202
|
+
? actor.site
|
|
203
|
+
: path === '/door'
|
|
204
|
+
? actor.door
|
|
205
|
+
: undefined;
|
|
206
|
+
return value === undefined ? undefined : single({ kind: 'actor', value });
|
|
207
|
+
}
|
|
208
|
+
function plain(value) {
|
|
209
|
+
if (!isRecord(value))
|
|
210
|
+
return false;
|
|
211
|
+
const prototype = Object.getPrototypeOf(value);
|
|
212
|
+
return prototype === Object.prototype || prototype === null;
|
|
213
|
+
}
|
|
214
|
+
export function dated(value) {
|
|
215
|
+
return (typeof value === 'string' && DATE.test(value) && instant(`${value}T00:00:00Z`) !== undefined);
|
|
216
|
+
}
|
|
217
|
+
export function instant(value) {
|
|
218
|
+
if (typeof value !== 'string')
|
|
219
|
+
return undefined;
|
|
220
|
+
const parts = DATE_TIME.exec(value);
|
|
221
|
+
if (parts === null)
|
|
222
|
+
return undefined;
|
|
223
|
+
const [year, month, day, hour, minute, second, offsetHours, offsetMinutes] = [
|
|
224
|
+
1, 2, 3, 4, 5, 6, 9, 10,
|
|
225
|
+
].map((at) => Number(parts[at] ?? 0));
|
|
226
|
+
const at = new Date(0);
|
|
227
|
+
at.setUTCFullYear(year, month - 1, day);
|
|
228
|
+
at.setUTCHours(hour, minute, second);
|
|
229
|
+
if (at.getUTCFullYear() !== year ||
|
|
230
|
+
at.getUTCMonth() !== month - 1 ||
|
|
231
|
+
at.getUTCDate() !== day ||
|
|
232
|
+
at.getUTCHours() !== hour ||
|
|
233
|
+
at.getUTCMinutes() !== minute ||
|
|
234
|
+
offsetHours > 23 ||
|
|
235
|
+
offsetMinutes > 59)
|
|
236
|
+
return undefined;
|
|
237
|
+
const offset = (parts[8] === '-' ? -1 : 1) * (offsetHours * 60 + offsetMinutes);
|
|
238
|
+
const fraction = (parts[7] ?? '').padEnd(9, '0').slice(0, 9);
|
|
239
|
+
return (BigInt(at.getTime()) - BigInt(offset) * 60000n) * 1000000n + BigInt(fraction);
|
|
240
|
+
}
|
|
241
|
+
export function pointed(value, pointer) {
|
|
242
|
+
if (pointer === '')
|
|
243
|
+
return value;
|
|
244
|
+
let reached = value;
|
|
245
|
+
for (const part of pointer.slice(1).split('/')) {
|
|
246
|
+
const token = part.replaceAll('~1', '/').replaceAll('~0', '~');
|
|
247
|
+
if (Array.isArray(reached)) {
|
|
248
|
+
if (!ARRAY_INDEX.test(token))
|
|
249
|
+
return undefined;
|
|
250
|
+
reached = reached[Number(token)];
|
|
251
|
+
}
|
|
252
|
+
else if (plain(reached) && Object.hasOwn(reached, token)) {
|
|
253
|
+
reached = reached[token];
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return reached;
|
|
260
|
+
}
|
|
261
|
+
function scalar(value) {
|
|
262
|
+
return (typeof value === 'string' ||
|
|
263
|
+
typeof value === 'boolean' ||
|
|
264
|
+
(typeof value === 'number' && Number.isFinite(value)));
|
|
265
|
+
}
|
|
266
|
+
function jsonHeld(value) {
|
|
267
|
+
if (typeof value === 'string')
|
|
268
|
+
return {
|
|
269
|
+
kind: dated(value) ? 'date' : instant(value) === undefined ? 'string' : 'time',
|
|
270
|
+
value,
|
|
271
|
+
};
|
|
272
|
+
if (typeof value === 'boolean')
|
|
273
|
+
return { kind: 'boolean', value };
|
|
274
|
+
return { kind: 'number', value };
|
|
275
|
+
}
|
|
276
|
+
function jsonRead(value) {
|
|
277
|
+
if (value === undefined)
|
|
278
|
+
return undefined;
|
|
279
|
+
if (scalar(value))
|
|
280
|
+
return single(jsonHeld(value));
|
|
281
|
+
if (!Array.isArray(value))
|
|
282
|
+
return single({ kind: 'prose' });
|
|
283
|
+
return { present: true, values: [], items: value.filter(scalar).map(jsonHeld), loose: true };
|
|
284
|
+
}
|
|
285
|
+
function readItem(item, path) {
|
|
286
|
+
if (path.startsWith('/json/')) {
|
|
287
|
+
if (item.json === null)
|
|
288
|
+
return UNREAD;
|
|
289
|
+
return jsonRead(pointed(item.json.value, path.slice('/json'.length)));
|
|
290
|
+
}
|
|
291
|
+
if (path.startsWith('/headers/')) {
|
|
292
|
+
const name = path.slice('/headers/'.length);
|
|
293
|
+
return Object.hasOwn(item.headers, name)
|
|
294
|
+
? single({ kind: 'string', value: item.headers[name] })
|
|
295
|
+
: undefined;
|
|
296
|
+
}
|
|
297
|
+
if (path === '/has_attachment')
|
|
298
|
+
return single({ kind: 'boolean', value: item.has_attachment });
|
|
299
|
+
const value = path === '/delivery'
|
|
300
|
+
? item.delivery
|
|
301
|
+
: path === '/source'
|
|
302
|
+
? item.source
|
|
303
|
+
: path === '/provider'
|
|
304
|
+
? item.provider
|
|
305
|
+
: path === '/container'
|
|
306
|
+
? item.container
|
|
307
|
+
: path === '/author'
|
|
308
|
+
? item.author
|
|
309
|
+
: null;
|
|
310
|
+
return value === null ? undefined : single({ kind: 'string', value });
|
|
311
|
+
}
|
|
312
|
+
function wanted(value, owner) {
|
|
313
|
+
return isRecord(value) && value.owner === true ? owner : value;
|
|
314
|
+
}
|
|
315
|
+
function equal(held, value, owner) {
|
|
316
|
+
if (!('value' in held))
|
|
317
|
+
return undefined;
|
|
318
|
+
const expected = wanted(value, owner);
|
|
319
|
+
if (typeof expected !== typeof held.value)
|
|
320
|
+
return undefined;
|
|
321
|
+
if (held.kind !== 'time')
|
|
322
|
+
return expected === held.value;
|
|
323
|
+
const left = instant(held.value);
|
|
324
|
+
const right = instant(expected);
|
|
325
|
+
return left === undefined || right === undefined ? undefined : left === right;
|
|
326
|
+
}
|
|
327
|
+
function sign(left, right) {
|
|
328
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
329
|
+
}
|
|
330
|
+
function ordered(held, value, compare) {
|
|
331
|
+
if (!('value' in held))
|
|
332
|
+
return undefined;
|
|
333
|
+
if (held.kind === 'number') {
|
|
334
|
+
if (typeof value !== 'number' || typeof held.value !== 'number')
|
|
335
|
+
return undefined;
|
|
336
|
+
return compare(Math.sign(held.value - value));
|
|
337
|
+
}
|
|
338
|
+
if (held.kind === 'date') {
|
|
339
|
+
if (!dated(value) || !dated(held.value))
|
|
340
|
+
return undefined;
|
|
341
|
+
return compare(sign(held.value, value));
|
|
342
|
+
}
|
|
343
|
+
if (held.kind !== 'time')
|
|
344
|
+
return undefined;
|
|
345
|
+
const at = instant(held.value);
|
|
346
|
+
const wanted = instant(value);
|
|
347
|
+
if (at === undefined || wanted === undefined)
|
|
348
|
+
return undefined;
|
|
349
|
+
return compare(sign(at, wanted));
|
|
350
|
+
}
|
|
351
|
+
function anyOf(truths) {
|
|
352
|
+
if (truths.some((truth) => truth === true))
|
|
353
|
+
return true;
|
|
354
|
+
return truths.some((truth) => truth === undefined) ? undefined : false;
|
|
355
|
+
}
|
|
356
|
+
function allOf(truths) {
|
|
357
|
+
if (truths.some((truth) => truth === false))
|
|
358
|
+
return false;
|
|
359
|
+
return truths.some((truth) => truth === undefined) ? undefined : true;
|
|
360
|
+
}
|
|
361
|
+
function compared(test, held, owner) {
|
|
362
|
+
if ('eq' in test)
|
|
363
|
+
return equal(held, test.eq, owner);
|
|
364
|
+
if ('in' in test)
|
|
365
|
+
return anyOf(test.in.map((value) => equal(held, value, owner)));
|
|
366
|
+
if ('prefix' in test) {
|
|
367
|
+
if (!('value' in held) || typeof held.value !== 'string')
|
|
368
|
+
return undefined;
|
|
369
|
+
if (held.kind === 'number' || held.kind === 'reference' || held.kind === 'member')
|
|
370
|
+
return undefined;
|
|
371
|
+
return held.value.startsWith(test.prefix);
|
|
372
|
+
}
|
|
373
|
+
if ('gt' in test)
|
|
374
|
+
return ordered(held, test.gt, (sign) => sign > 0);
|
|
375
|
+
if ('gte' in test)
|
|
376
|
+
return ordered(held, test.gte, (sign) => sign >= 0);
|
|
377
|
+
if ('lt' in test)
|
|
378
|
+
return ordered(held, test.lt, (sign) => sign < 0);
|
|
379
|
+
return ordered(held, test.lte, (sign) => sign <= 0);
|
|
380
|
+
}
|
|
381
|
+
function leaf(test, read, owner) {
|
|
382
|
+
if ('exists' in test) {
|
|
383
|
+
const present = read === undefined ? false : read.present;
|
|
384
|
+
return present === undefined ? undefined : present === test.exists;
|
|
385
|
+
}
|
|
386
|
+
if (read === undefined)
|
|
387
|
+
return undefined;
|
|
388
|
+
if ('contains' in test) {
|
|
389
|
+
if (read.items === null)
|
|
390
|
+
return undefined;
|
|
391
|
+
const truths = read.items.map((item) => item === undefined ? undefined : equal(item, test.contains, owner));
|
|
392
|
+
return read.loose === true && !truths.includes(true) ? false : anyOf(truths);
|
|
393
|
+
}
|
|
394
|
+
if (read.values.length === 0)
|
|
395
|
+
return read === NO_ITEM ? false : undefined;
|
|
396
|
+
return anyOf(read.values.map((value) => (value === undefined ? undefined : compared(test, value, owner))));
|
|
397
|
+
}
|
|
398
|
+
function evaluated(test, read, owner) {
|
|
399
|
+
if ('all' in test)
|
|
400
|
+
return allOf(test.all.map((part) => evaluated(part, read, owner)));
|
|
401
|
+
if ('any' in test)
|
|
402
|
+
return anyOf(test.any.map((part) => evaluated(part, read, owner)));
|
|
403
|
+
if ('not' in test) {
|
|
404
|
+
const truth = evaluated(test.not, read, owner);
|
|
405
|
+
return truth === undefined ? undefined : !truth;
|
|
406
|
+
}
|
|
407
|
+
return leaf(test, read(test.path), owner);
|
|
408
|
+
}
|
|
409
|
+
export function holds(test, document, owner) {
|
|
410
|
+
return evaluated(test, (path) => readDocument(document, path), owner);
|
|
411
|
+
}
|
|
412
|
+
function inScope(scope, document) {
|
|
413
|
+
if (document === null)
|
|
414
|
+
return false;
|
|
415
|
+
if ('type' in scope)
|
|
416
|
+
return document.type === scope.type;
|
|
417
|
+
if ('document' in scope)
|
|
418
|
+
return document.id === scope.document;
|
|
419
|
+
return scope.folder === '/' || document.path.startsWith(`${scope.folder}/`);
|
|
420
|
+
}
|
|
421
|
+
function matched(condition, test, document, owner) {
|
|
422
|
+
if (!inScope(condition.scope, document))
|
|
423
|
+
return false;
|
|
424
|
+
return test === undefined || holds(test, document, owner) === true;
|
|
425
|
+
}
|
|
426
|
+
function reachedAt(document, field) {
|
|
427
|
+
if (document === null)
|
|
428
|
+
return [];
|
|
429
|
+
if (field.startsWith('/sections/'))
|
|
430
|
+
return document.sections.includes(field.slice('/sections/'.length))
|
|
431
|
+
? [{ pointer: field, fact: PROSE }]
|
|
432
|
+
: [];
|
|
433
|
+
if (!field.startsWith('/fields/'))
|
|
434
|
+
return [];
|
|
435
|
+
return walked(rootOf(document, '/fields'), field.slice('/fields'.length)).reached;
|
|
436
|
+
}
|
|
437
|
+
function valueOf(fact) {
|
|
438
|
+
if (fact.kind === 'list')
|
|
439
|
+
return { kind: fact.kind, items: fact.items.map(valueOf) };
|
|
440
|
+
if (fact.kind === 'object')
|
|
441
|
+
return {
|
|
442
|
+
kind: fact.kind,
|
|
443
|
+
fields: Object.keys(fact.fields)
|
|
444
|
+
.sort()
|
|
445
|
+
.map((key) => [key, valueOf(fact.fields[key])]),
|
|
446
|
+
};
|
|
447
|
+
return 'value' in fact ? { kind: fact.kind, value: fact.value } : fact;
|
|
448
|
+
}
|
|
449
|
+
function signature(reached) {
|
|
450
|
+
return JSON.stringify(reached.map(({ fact }) => valueOf(fact)));
|
|
451
|
+
}
|
|
452
|
+
function among(values, document, field, owner) {
|
|
453
|
+
return holds({ path: field, in: values }, document, owner) === true;
|
|
454
|
+
}
|
|
455
|
+
function fieldChanged(condition, event, owner) {
|
|
456
|
+
const { field, from, to } = condition;
|
|
457
|
+
const before = reachedAt(event.before, field);
|
|
458
|
+
const after = reachedAt(event.after, field);
|
|
459
|
+
const pointers = [field, ...[...before, ...after].map(({ pointer }) => pointer)];
|
|
460
|
+
const prose = event.changed.some((changed) => pointers.some((pointer) => changed === pointer || changed.startsWith(`${pointer}/`)));
|
|
461
|
+
if (from === undefined && to === undefined && prose)
|
|
462
|
+
return true;
|
|
463
|
+
if (before.length === 0 && after.length === 0)
|
|
464
|
+
return false;
|
|
465
|
+
if (event.before !== null && event.after !== null && signature(before) === signature(after))
|
|
466
|
+
return false;
|
|
467
|
+
if (from === 'new'
|
|
468
|
+
? event.before !== null
|
|
469
|
+
: from !== undefined && (event.before === null || !among(from, event.before, field, owner)))
|
|
470
|
+
return false;
|
|
471
|
+
if (to === 'deleted'
|
|
472
|
+
? event.after !== null
|
|
473
|
+
: to !== undefined && (event.after === null || !among(to, event.after, field, owner)))
|
|
474
|
+
return false;
|
|
475
|
+
return true;
|
|
476
|
+
}
|
|
477
|
+
export function fires(condition, event, owner) {
|
|
478
|
+
if (condition.by !== undefined &&
|
|
479
|
+
evaluated(condition.by, (path) => readActor(event.by, path), owner) !== true)
|
|
480
|
+
return false;
|
|
481
|
+
if (condition.mode === 'starts_matching') {
|
|
482
|
+
if (event.before === null && !condition.new_documents)
|
|
483
|
+
return false;
|
|
484
|
+
return (matched(condition, condition.match, event.after, owner) &&
|
|
485
|
+
!matched(condition, condition.match, event.before, owner));
|
|
486
|
+
}
|
|
487
|
+
const side = event.after ?? event.before;
|
|
488
|
+
return matched(condition, condition.match, side, owner) && fieldChanged(condition, event, owner);
|
|
489
|
+
}
|
|
490
|
+
export function itemFires(condition, item, owner) {
|
|
491
|
+
if (condition.source !== undefined && item.source !== condition.source)
|
|
492
|
+
return false;
|
|
493
|
+
if (condition.address !== undefined && item.address !== condition.address)
|
|
494
|
+
return false;
|
|
495
|
+
return (condition.match === undefined ||
|
|
496
|
+
evaluated(condition.match, (path) => readItem(item, path), owner) === true);
|
|
497
|
+
}
|