diff --git a/website/content/specification/syntax/constraints.md b/website/content/specification/syntax/constraints.md index 18009e01..163f2998 100644 --- a/website/content/specification/syntax/constraints.md +++ b/website/content/specification/syntax/constraints.md @@ -18,7 +18,7 @@ The following constraint types are allowed for `` definitions. - [``](#enumerated-values) - `` -- `` +- [``](#index-has-key-constraints) - `` For each of these constraint types, use of the `@target` attribute is prohibited. This is because a flag constraint may only target the flag, since a flag has no child nodes. @@ -29,7 +29,7 @@ The following constraint types are allowed for `` definitions. - [``](#enumerated-values) - `` -- `` +- [``](#index-has-key-constraints) - `` ## `` constraints @@ -38,9 +38,9 @@ The following constraint types are allowed for `` definitions. - [``](#enumerated-values) - `` -- `` +- [``](#index-has-key-constraints) - `` -- `` +- [``](#index-constraints) - `` - `` @@ -179,6 +179,30 @@ A constraint may have an OPTIONAL [`@level`](#level) attribute and/or an OPTIONA If defined, the `` value MUST be a [Metaschema string value](/specification/datatypes#string). It MAY contain a Metapath expression templates that starts with `{`, contains a Metapath expression, and ends with `}`. When evaluating a template Metapath expression, the context of the Metapath [evaluation focus](#constraint-processing) MUST be the failing value node. +## `index` constraints + +The `index` constraint is a type of Metaschema constraint that defines an index of document instance nodes addressable by key. + +The `@name` flag of an `` constraint specifies the identity of the index. The constraint MUST define the name. + +The `@target` flag of an `` constraint defines the node(s) in a document instance to index. The index MUST define a [`@target`](#target) with a Metapath expression. The processor MUST index only The document instance node(s) resulting from its evaluation. + +The `` assembly of an `` constraint defines the flag or field value that is the key for each entry in the index. The `` field MUST define a [`@target`](#target) flag with a Metapath expression evaluated relative to [the evaluation focus](#constraint-processing) of each entry of the matches of the constraint's `@target`. + +An `index` constraint MAY define more than one `` assembly. The composite key for each entry in the index is the combination of values for the `@target` of every ``. The composite values of the key are the discriminator for the uniqueness of the index entry. + +An `index` constraint requires that each member entry be unique based upon this composite key. + +If the evaluation of the Metapath `@target` of the `` does not result in a value, its value for that key in the index is null. + +## `index-has-key` constraints + +The `index-has-key` constraint is a type of Metaschema constraint that cross-references values an existing `index` constraint` with a separate `@target` and ``. + +The `@name` flag of an `` constraint MUST specify the name of a previously defined `index` constraint. + +The `index-has-key` constraint has the same flags and assemblies as a [`index`](#index-constraints) constraint. + ## Enumerated values The `allowed-values` constraint is a type of Metaschema constraint that restricts field or flag value(s) based on an enumerated set of permitted values.