/** * @license * Copyright 2022-2026 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import { Events } from "#behavior/Events.js"; import type { Agent } from "#endpoint/Agent.js"; import { MaybePromise } from "@matter/general"; import { Schema } from "@matter/model"; import { ClusterType, type ClusterTyping } from "@matter/types"; import { Behavior } from "../Behavior.js"; import type { BehaviorBacking } from "../internal/BehaviorBacking.js"; import type { RootSupervisor } from "../supervision/RootSupervisor.js"; import { NetworkBehavior } from "../system/network/NetworkBehavior.js"; import { ExtensionInterfaceOf } from "./cluster-behavior-utils.js"; import type { ClusterEvents } from "./ClusterEvents.js"; import { ClusterInterface } from "./ClusterInterface.js"; import type { ClusterState } from "./ClusterState.js"; /** * A {@link Behavior} with specialization for a specific cluster. * * To implement cluster functionality you should use a subclass provided by {@link ClusterBehavior.for} with the * cluster namespace you are implementing. Most commonly you would use one of the predefined implementations * matter.js includes. * * Subclasses can be modified using the static builder methods or extended like a normal class. * * Behaviors should store all mutable state in their {@link Behavior.state} property. Other fields will be transient * and may not be retained across invocations. * * ClusterBehaviors may be instantiated with unsupported mandatory commands and attributes. This is currently results * in a runtime error, but it will not cause a type error during development. */ export declare class ClusterBehavior extends Behavior { static readonly schema: Schema.Cluster; /** * The ID of ClusterBehavior implementations is the uncapitalized cluster name. */ static id: Uncapitalize; /** * The cluster namespace associated with this behavior. */ get cluster(): ClusterType.Concrete; /** * Supported features as a flag object. */ get features(): Record; get type(): ClusterBehavior.Type; /** * Every cluster behavior has an associated cluster namespace defined statically. */ static readonly cluster: ClusterType.Concrete; /** * Supported features as a flag object. */ static readonly features: Record; /** * Method definitions. */ static readonly Interface: ClusterTyping; /** * All ClusterBehavior initialization currently runs as part of {@link Endpoint} initialization. */ static readonly early = true; /** * Keep networking alive until I'm destroyed. */ static readonly dependencies: (typeof NetworkBehavior)[]; /** * Automatically lock state on command invoke. */ static readonly lockOnInvoke = true; constructor(agent: Agent, backing: BehaviorBacking); /** * Create a new behavior for a specific cluster namespace. * * If you invoke directly on {@link ClusterBehavior} you will receive a new implementation that reports all commands * as unimplemented. * * If you invoke on an existing subclass, you will receive a new implementation with the cluster in the subclass * replaced. You should generally only do this with a namespace with the same cluster ID. * * Feature selection comes from {@link ns} if it designates features, otherwise it is unchanged. Use * {@link withFeatures} to select features. */ static for(this: This, ns: NS, schema?: Schema.Cluster, name?: string): ClusterBehavior.Type & { readonly id: Uncapitalize; }; /** * Create a new behavior with different cluster features. */ static withFeatures>>(this: This, ...features: FeaturesT): ClusterBehavior.Type, ClusterType.FeaturesAsFlags, FeaturesT>>>; /** * Alias for {@link withFeatures}. */ static with>>(this: This, ...features: FeaturesT): ClusterBehavior.Type, ClusterType.FeaturesAsFlags, FeaturesT>>, ClusterType.Concrete, This["Internal"], This extends { readonly id: infer S extends Uncapitalize; } ? S : Uncapitalize>; /** * Create a new behavior with modified cluster elements. */ static alter>>(this: This, alterations: AlterationsT): ClusterBehavior.Type, ClusterType.AlteredMandatoryEventKeysOf>, ClusterType.AlteredMandatoryAttributeKeysOf>>; /** * Create a new behavior with additional cluster features marked "mandatory". * * This informs matter.js that an application supports these elements. */ static enable>>(this: This, flags: FlagsT): ClusterBehavior.Type, ClusterType.EnabledEventKeysOf>, ClusterType.EnabledAttributeKeysOf>>; /** * Returns this behavior type with all cluster elements present regardless of feature selection. * * This is type-only; at runtime the deconflicted conformance mode already includes all elements. */ static get complete(): ClusterBehavior.Type; static isType(type: Behavior.Type): type is ClusterBehavior.Type; static supports(other: Behavior.Type): boolean; requireAttributeEnabled(this: This, attributeName: K): Exclude; assertAttributeEnabled(this: This, attributeName: K): void; static Events: typeof Events; } export declare namespace ClusterBehavior { /** * A ClusterBehavior specialized for a specific cluster namespace. */ interface Type, NS extends ClusterType = ClusterType.Concrete, I = B["Internal"], // inline: B["Internal"] ID extends Uncapitalize = B extends { readonly id: infer S extends Uncapitalize; } ? S : Uncapitalize> { new (agent: Agent, backing: BehaviorBacking): Instance; readonly name: string; /** * The behavior ID for ClusterBehaviors is the name of the cluster. */ readonly id: ID; /** * The cluster namespace for this behavior. */ readonly cluster: NS; /** * Supported features as a flag object. */ readonly features: ClusterType.FeaturesOf; readonly Events: ClusterEvents.Type; readonly State: new () => ClusterState.Type; readonly Internal: I; readonly Interface: N; readonly schema: Schema.Cluster; readonly early: boolean; readonly defaults: ClusterState.Type; readonly supervisor: RootSupervisor; readonly dependencies?: Iterable; readonly migrate: typeof Behavior.migrate; supports: typeof ClusterBehavior.supports; readonly ExtensionInterface: ExtensionInterfaceOf; readonly lockOnInvoke: boolean; /** * Create a new behavior for a specific cluster namespace. */ for(this: This, ns: NS, schema?: Schema, name?: string): ClusterBehavior.Type & { readonly id: Uncapitalize; }; /** * Create a new behavior with different cluster features. */ withFeatures>>(this: This, ...features: FeaturesT): ClusterBehavior.Type, ClusterType.FeaturesAsFlags, FeaturesT>>>; /** * Alias for {@link withFeatures}. */ with>>(this: This, ...features: FeaturesT): ClusterBehavior.Type, ClusterType.FeaturesAsFlags, FeaturesT>>>; /** * Create a new behavior with modified cluster elements. */ alter>>(this: This, alterations: AlterationsT): ClusterBehavior.Type, ClusterType.AlteredMandatoryEventKeysOf>, ClusterType.AlteredMandatoryAttributeKeysOf>>; set(this: This, defaults: Behavior.InputStateOf): This; enable>>(this: This, flags: FlagsT): ClusterBehavior.Type, ClusterType.EnabledEventKeysOf>, ClusterType.EnabledAttributeKeysOf>>; } /** * A fully-typed ClusterBehavior. This type is derived by combining properties of the base type with properties * contributed by the cluster. */ type Instance = ClusterBehavior & Omit, "cluster" | "state" | "events" | "initialize" | typeof Symbol.asyncDispose | keyof ClusterInterface.MethodsOf> | keyof ExtensionInterfaceOf> & ClusterInterface.MethodsOf & ExtensionInterfaceOf & { /** * The cluster namespace. */ cluster: ClusterType.Concrete; /** * State values for the behavior. */ readonly state: ClusterState; /** * Observables for cluster events and attribute changes. */ readonly events: ClusterEvents; /** * Supported features as a flag object. */ readonly features: ClusterType.FeaturesOf; [Symbol.asyncDispose](): MaybePromise; }; /** * A behavior type with all cluster elements exposed regardless of feature selection. * * Used by client behaviors to provide access to all commands, attributes, and events. */ interface Complete extends Omit, "new" | "Events" | "State"> { new (agent: Agent, backing: BehaviorBacking): CompleteInstance; readonly Events: ClusterEvents.CompleteType; readonly State: new () => ClusterState.Complete; } /** * A fully-typed instance with all cluster elements present regardless of feature selection. */ type CompleteInstance = ClusterBehavior & Omit, "cluster" | "state" | "events" | "initialize" | typeof Symbol.asyncDispose | keyof ClusterInterface.MethodsOf> | keyof ExtensionInterfaceOf> & ClusterInterface.AllMethodsOf & ExtensionInterfaceOf & { cluster: ClusterType.Concrete; readonly state: ClusterState.Complete; readonly events: ClusterEvents.Complete; readonly features: ClusterType.FeaturesOf; [Symbol.asyncDispose](): MaybePromise; }; /** * This is an unfortunate kludge required to work around https://github.com/microsoft/TypeScript/issues/27965. It * allows you to designate extension methods available on behavior instances. * * Methods designated in this way make it so you can override methods using the syntax: * * override foo() {} * * rather than: * * override foo: () => {} * * This is also required for protected properties because TypeScript doesn't include them in the mapped types our * typing system uses to define modified behaviors. * * See {@link ClusterInterface} for more details. */ const ExtensionInterface: {}; function is(type: Behavior.Type): type is ClusterBehavior.Type; /** * The cluster behaviors among {@link types}, in order. */ function typesOf(types: Iterable): Type {}, Uncapitalize>[]; } //# sourceMappingURL=ClusterBehavior.d.ts.map