/** * @license * Copyright 2022-2026 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import { Callable } from "@matter/general"; import { Model } from "../models/Model.js"; /** * A collection of models with support for efficient lookup by name and ID. * * Callable as a function to look up models by key: * * clusters("OnOff") // equivalent to clusters.for("OnOff") * * Name search uses canonical camel case, so "FooBar", "fooBar" and "foo-bar" are considered equivalent. */ export interface ModelIndex { /** * Look up a model by ID or name. * * If `key` is `undefined`, returns `undefined`. */ (key: number | string | undefined): T | undefined; /** * Retrieve a model for the given ID or name. * * If `key` is `undefined`, returns `undefined`. * * Use the two-parameter version for indices that contain multiple model types. * * @deprecated Use the call signature instead: `index(key)` rather than `index.for(key)`. */ for(key: undefined): undefined; for(key: number | string): T | undefined; for(key: number | string | undefined): T | undefined; /** * Retrieve a model of the specific type for the given ID or name. * * Name search uses canonical camel case. * * @deprecated Use the call signature instead: `index(key)` rather than `index.for(key)`. */ for(key: number | string, type: Model.Type): M | undefined; /** * Retrieve a model for the given ID or name, throwing if not found. * * If `key` is `undefined`, returns `undefined` without throwing. */ require(key: undefined): undefined; require(key: number | string): T; require(key: number | string | undefined): T | undefined; /** * Retrieve a model of the specific type for the given ID or name, throwing if not found. */ require(key: number | string, type: Model.Type): M; /** * Retrieve a model by key and create an operational extension of it. * * Shorthand for `index.require(key).extend(properties, ...children)`. */ extend(key: number | string, properties?: Partial>, ...children: Model.ChildDefinition[]): T; /** * Filter to a specific model subtype. */ ofType(type: Model.Type): M[]; /** * Iterate over all models. */ [Symbol.iterator](): IterableIterator; /** * Execute a function for each model. */ forEach(fn: (model: T, index: number) => void): void; /** * Map models to a new array. */ map(fn: (model: T, index: number) => U): U[]; /** * Filter models. */ filter(fn: (model: T, index: number) => boolean): T[]; /** * Find the first model matching a predicate. */ find(fn: (model: T, index: number) => boolean): T | undefined; /** * Test whether any model matches a predicate. */ some(fn: (model: T, index: number) => boolean): boolean; /** * Test whether all models match a predicate. */ every(fn: (model: T, index: number) => boolean): boolean; /** * Reduce models to a single value. */ reduce(fn: (accumulator: U, model: T, index: number) => U, initialValue: U): U; /** * The number of models in this index. */ readonly length: number; /** * Access a model by position. */ at(index: number): T | undefined; } /** * Implementation of {@link ModelIndex} used for initial creation. */ export declare class MutableModelIndex extends Callable<[key: number | string | undefined], T | undefined> implements ModelIndex { #private; constructor(items?: T[]); /** * Add items. Used during construction only. */ push(...items: T[]): void; get length(): number; at(index: number): T | undefined; [Symbol.iterator](): IterableIterator; forEach(fn: (model: T, index: number) => void): void; map(fn: (model: T, index: number) => U): U[]; filter(fn: (model: T, index: number) => boolean): T[]; find(fn: (model: T, index: number) => boolean): T | undefined; some(fn: (model: T, index: number) => boolean): boolean; every(fn: (model: T, index: number) => boolean): boolean; reduce(fn: (accumulator: U, model: T, index: number) => U, initialValue: U): U; for(key: undefined): undefined; for(key: number | string): T; for(key: number | string, type: Model.Type): M; require(key: undefined): undefined; require(key: number | string): T; require(key: number | string, type: Model.Type): M; extend(key: number | string, properties?: Partial>, ...children: Model.ChildDefinition[]): T; ofType(type: T): InstanceType[]; } //# sourceMappingURL=ModelIndex.d.ts.map