/** * @license * Copyright 2022-2026 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import { Namespace, Semtag, VendorId } from "@matter/types"; /** * A Matter "semantic namespace" is a discrete set of {@link Semtag} definitions. */ export type SemanticNamespace = Record; /** * Define a new semantic namespace. */ export function SemanticNamespace(definition: T) { const result = {} as Record; const { tags } = definition; const namespaceId = definition.id; const mfgCode = definition.mfgCode ? VendorId(definition.mfgCode) : null; for (const key in tags) { const { id: tag, label } = definition.tags[key]; result[key] = { namespaceId, mfgCode, tag, label, }; } return result as SemanticNamespace.Of; } export namespace SemanticNamespace { export interface Definition { id: Namespace; mfgCode?: number; tags: { [name: string]: { id: number; label: string }; }; } export type Of = { [name in keyof T["tags"]]: Semtag; }; }