/** * @license * Copyright 2022-2026 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import { FieldValue } from "../common/index.js"; import { Aspect } from "./Aspect.js"; /** * An operational view of constraints as defined by the Matter specification. * * A "constraint" limits possible data values. */ export declare class Constraint extends Aspect implements Constraint.Ast { /** * Indicates that the constraint is explicitly unconstrained. This prevents inheritance of constraints from * shadow/base models via {@link extend}. */ none?: boolean; desc?: boolean; value?: Constraint.Expression; min?: Constraint.Expression; max?: Constraint.Expression; in?: FieldValue; entry?: Constraint; cpMax?: number; parts?: Constraint[]; /** * Initialize from a Constraint.Definition or the constraint DSL defined by the Matter Specification. */ constructor(definition: Constraint.Definition); extend(other: Constraint): Constraint; /** * Test a value against a constraint. Does not recurse into arrays. */ test(value: FieldValue, nameResolver?: (name: string) => unknown): boolean; toString(): string; protected freeze(): void; } export declare namespace Constraint { type NumberOrIdentifier = number | string; /** * What a constraint does with the value a name denotes. * * The position decides what may answer the name. A bound is compared against the value, so a single name in one * may denote a value of the constrained type as well as an element of the record. The operand of "in" names the * element holding the values allowed, so a value of the constrained type never answers it. * * @see {@link MatterSpecification.v161.Core} § 7.18.3 */ type NamePosition = "bound" | "set"; /** A name a constraint states, and what the constraint does with the value it denotes */ interface Reference { path: string[]; position: NamePosition; } /** * The path an expression names: the segments of a complete member access, the one segment of a bare name, or * undefined for an expression that computes a value. * * Both operands of "." name elements: the lhs names one the scope resolves and the rhs a member of it. An access * to a computed value states no path, because the rhs then names a member of whatever the expression evaluates to * and no scope resolves it. Each operand of an access is judged by this in turn, so a bare name answering it is * what lets a named operand be told from a computed one. * * @see {@link MatterSpecification.v161.Core} § 7.18.3.4 */ function accessPathOf(expression: Expression): string[] | undefined; /** * Whether the constraint states a member access no evaluation can take. * * A member access evaluates only where the value before "." is a record and the name after it a member of one. * Where either operand is computed, or the path reaches a member of a member, the access denotes nothing and the * bound holding it admits every value. The specification states no such constraint; the grammar permits one. * * The entry constraint of a list bounds the entries and is judged in the entry's own scope, so an access it holds * is not among these. * * @see {@link MatterSpecification.v161.Core} § 7.18.3.4 */ function hasUnevaluableAccess(constraint: Ast): boolean; /** * Every name a constraint states that a scope resolves, in definition order, with what the constraint does with * it. * * A name the constraint qualifies with "." states the path to a member rather than a name of the surrounding * scope, so it arrives as the segments of that path. The member an access names is not among these: it belongs * to whatever the access is taken from rather than to any scope. A path resolves only if every segment does: a bound naming * a member its type does not define states no bound, just as an unknown element does. * * The entry constraint of a list bounds the entries, so the names it states belong to the type of the entry. They * are not among these; {@link Ast.entry} states them and resolves in the entry's own scope. * * @see {@link MatterSpecification.v161.Core} § 7.18.3.4 */ function referencesOf(constraint: Ast): Reference[]; const KEYWORDS: readonly ["in", "min", "max", "to", "all", "none", "desc", "true", "false"]; const keywords: Set; /** * Parsed constraint. */ type Ast = { /** * Indicates the element is explicitly unconstrained. Prevents inheritance of constraints from shadow/base * models. */ none?: boolean; /** * Indicates constraint is defined in prose and cannot be enforced automatically. */ desc?: boolean; /** * Constant value. */ value?: Expression; /** * Lower bound on value or sequence length. */ min?: Expression; /** * Upper bound on value or sequence length. */ max?: Expression; /** * Require set membership for the value. */ in?: FieldValue; /** * Constraint on list child element. */ entry?: Ast; /** * Constraint on codepoints in a string. */ cpMax?: number; /** * List of sub-constraints in a sequence. */ parts?: Ast[]; }; /** * Parsed binary operator. */ interface BinaryOperator { type: "+" | "-" | "*" | "/" | "." | "^"; lhs: Expression; rhs: Expression; } /** * Parsed function. */ interface Function { type: "maxOf" | "minOf"; args: Expression[]; } /** * Parsed expression. */ type Expression = FieldValue | BinaryOperator | Function; /** * The number an expression computes from numbers alone, such as the "2^62" of "max 2^62" or "(2^62) - 1", or * undefined if it names a value or states a unit, which only the value it is compared with gives a number. */ function constantOf(expression: Expression | FieldValue.Open | undefined): number | bigint | undefined; /** * Whether an expression computes its value by an operator or a function rather than stating it. */ function isComputed(expression: Expression | FieldValue.Open | undefined): expression is BinaryOperator | Function; /** * These are all ways to describe a constraint. */ type Definition = (Ast & { definition?: Definition; }) | string | number | undefined; } //# sourceMappingURL=Constraint.d.ts.map