/** * @license * Copyright 2022-2026 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import { Bytes, Duration, UnexpectedDataError } from "@matter/general"; export declare class UnsupportedCastError extends UnexpectedDataError { } /** * General groupings of Matter types. */ export declare enum Metatype { any = "any", boolean = "boolean", bitmap = "bitmap", enum = "enum", integer = "integer", float = "float", bytes = "bytes", array = "array", object = "object", string = "string", date = "date", duration = "duration" } export declare namespace Metatype { /** * Does the specific type have children? */ export function hasChildren(type: Metatype | undefined): boolean; /** * What a constraint on a value of a metatype states. * * @see {@link MatterSpecification.v161.Core} § 7.18.3 */ export enum BoundKind { /** A range or exact value the number the value encodes to must fall in */ magnitude = "magnitude", /** A range or exact count of the elements the value holds */ length = "length", /** The one value it may take */ value = "value", /** Nothing: the type has neither a magnitude nor a length, so a bound on it states no bound at all */ none = "none" } /** * What a constraint on a value of this metatype states, or undefined where the type is unknown and so states * nothing either way. * * This is what the specification may say about the value, which is not the same as what a comparison can check: * a bitmap and a date both take a bound the specification states, such as the "max 15" of a window covering's * mode, while neither is held as a number a bound compares against. {@link holdsNumber} answers that. * * @see {@link MatterSpecification.v161.Core} § 7.18.3 */ export function boundKind(type: Metatype | undefined): BoundKind | undefined; /** * Whether a value of this metatype is held as a number, so a comparison against one has a numeric meaning. * * A bitmap encodes to a number but is held as the record of its flags, as {@link native} states, so a bound * comparing against one compares * a number against a record, which is false whatever the value. A date is held as a {@link Date}, which a * comparison coerces to a timestamp — a number of a different scale from anything a constraint states, so a bound * naming one states no bound worth judging. A duration is held as a number of milliseconds. */ export function holdsNumber(type: Metatype | undefined): boolean; /** * Whether a value of this metatype is held as a record, so a member access may take a member of one. * * This is not the same as defining members: an enumerated type defines its values, but a value of one is held as * the number it encodes to, so an access takes nothing from it. */ export function holdsRecord(type: Metatype | undefined): boolean; /** * Determine the JS type for a metatype. */ export function native(type: Metatype | undefined): ArrayConstructor | BigIntConstructor | BooleanConstructor | DateConstructor | NumberConstructor | ObjectConstructor | StringConstructor | Uint8ArrayConstructor | typeof Duration | undefined; /** * Map metatype value to JS type. */ export type Native = T extends "boolean" ? boolean : T extends "integer" | "float" ? number : T extends "string" ? string : T extends "bitmap" | "object" ? Record : T extends "array" ? unknown[] : T extends "bytes" ? Uint8Array : T extends "date" ? Date : T extends "any" ? unknown : T extends "duration" ? number : never; /** * Shape of {@link cast}: a generic call signature for dispatch + per-metatype converters. */ interface Cast { (type: T, value: unknown): Native; any: (value: unknown) => unknown; boolean: (value: unknown) => boolean | null | undefined; bitmap: (value: any) => number | bigint | Record | null | undefined; enum: (value: any) => number | string | null | undefined; integer: (value: any) => number | bigint | null | undefined; float: (value: any) => number | null | undefined; bytes: (value: any) => Bytes | null | undefined; array: (value: any) => Array | null | undefined; object: (value: any) => Record | null | undefined; string: (value: any) => string | null | undefined; date: (value: any) => Date | null | undefined; duration: (value: any) => Duration | null | undefined; } /** * Functions that perform conversion of arbitrary values to a metatype. * * This is a "best effort" that ensures the value is an appropriate JS type but cannot ensure semantic validity in * all cases. * * @throws {@link UnsupportedCastError} if the cast is deemed impossible */ export const cast: Cast; /** * These are the native types used by this module. */ export type NativeType = typeof Boolean | typeof BigInt | typeof Number | typeof Bytes | typeof Array | typeof Object | typeof String | typeof Date; export {}; } //# sourceMappingURL=Metatype.d.ts.map