Skip to content

Commit

Permalink
Document index and index-has-key constraint (#494)
Browse files Browse the repository at this point in the history
* Document index, index-has-key constraint for #490.

* Fix typo and key-field notation

1. Fix uniqueness para from the each member to that each member to make
the sentence grammatical.
1. Make all key-field references consistent to be `<key-field/>`, not
just `<key-field/>` to imply this child element can have children and is
different from a top-level `index` or `index-has-key` constraint.

* PR feedback edits: use Metaschema terms

* Woops, add in-page anchors to constraint listings
  • Loading branch information
aj-stein-nist authored Feb 6, 2024
1 parent af3690d commit b429ed0
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions website/content/specification/syntax/constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The following constraint types are allowed for `<define-flag>` definitions.

- [`<allowed-values>`](#enumerated-values)
- `<matches>`
- `<index-has-key>`
- [`<index-has-key>`](#index-has-key-constraints)
- `<expect>`

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.
Expand All @@ -29,7 +29,7 @@ The following constraint types are allowed for `<define-field>` definitions.

- [`<allowed-values>`](#enumerated-values)
- `<matches>`
- `<index-has-key>`
- [`<index-has-key>`](#index-has-key-constraints)
- `<expect>`

## `<define-assembly>` constraints
Expand All @@ -38,9 +38,9 @@ The following constraint types are allowed for `<define-assembly>` definitions.

- [`<allowed-values>`](#enumerated-values)
- `<matches>`
- `<index-has-key>`
- [`<index-has-key>`](#index-has-key-constraints)
- `<expect>`
- `<index>`
- [`<index>`](#index-constraints)
- `<is-unique>`
- `<has-cardinality>`

Expand Down Expand Up @@ -179,6 +179,30 @@ A constraint may have an OPTIONAL [`@level`](#level) attribute and/or an OPTIONA

If defined, the `<message>` 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 `<index>` constraint specifies the identity of the index. The constraint MUST define the name.

The `@target` flag of an `<index>` 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 `<key-field>` assembly of an `<index>` constraint defines the flag or field value that is the key for each entry in the index. The `<key-field>` 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 `<key-field>` assembly. The composite key for each entry in the index is the combination of values for the `@target` of every `<key-field/>`. 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 `<key-field/>` 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 `<key-field/>`.

The `@name` flag of an `<index>` 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.
Expand Down

0 comments on commit b429ed0

Please sign in to comment.