npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@project-chip/matter.js-model

v0.11.0-alpha.0-20240911-db8f7c80

Published

Matter data model

Downloads

4

Readme

Matter Object Model

This folder contains an object model that captures Matter semantics as precisely as possible. It also includes support logic related to model manipulation and runtime validation.

Other representations of the Matter data model in matter.js offer similar representations with a different focus. The TLV models data with a focus on serialization and manipulation of instance values. The Cluster API models clusters in an operational form and in fact is partially generated from this model.

All references to Matter specification in the object model corpus refer collectively to Matter 1.1 Core Specification, Matter 1.1 Application Cluster Specification, and Matter 1.1 Device Library Specification.

Code structure

Subfolders support specific functions:

  • elements/ - types describing the data model
  • models/ - classes implementing an operational version of the data model
  • standard/ - the full data model defined by the Matter Specification
  • definitions/ - support enums and types
  • aspects/ - parsers and ASTs for fields that utilize domain specific languages
  • logic/ - various algorithms that operate on models

The datatypes in elements model Matter elements using TypeScript types. Elements are a formal component of the Matter specification that describe individual structures in the data model. Our element definitions are subtypes of BaseElement.

For each element definition, a class in models offers a concrete operational implementation. This is the API to use if you need to work with the data model beyond simple data modeling. Our models are all subtypes of Model.

MatterModel is the primary entrypoint to the API.

Usage

Obtain a working instance of the model:

import { MatterModel } from "@project-chip/matter.js/model";
const matter = new MatterModel();

Retrieve standard definitions from the model:

import { DatatypeModel, ClusterModel } from "@project-chip/matter.js/model";
const OnOffCluster = matter.get(ClusterModel, "OnOff");
const uint8 = matter.get(DatatypeModel, "uint8");

Iterate over attributes of a cluster:

for (const attribute of OnOffCluster.attributes) {
    // Do something
}

Implementation

The base model includes global datatypes defined by the Matter specification. We generate other elements of the standard model by merging models in the top-level models package.

To recreate the standard model files:

cd matter.js/codegen
npm run generate-model

Spec data model

Input model spec.ts is the data model defined by the Matter specification.

We generate spec.ts from the Matter specification documents. This ensures our definitions align with the specification and gives us detailed information unavailable elsewhere.

The spec generator is generate-spec.ts. To run:

cd matter.js/codegen
npm run generate-spec

Details we extract from the specification include standard element names, types and detailed documentation including cross references to specification documents. We also extract DSL-based definitions of Matter concepts such as conformance, constraints, etc.

CHIP data model

Input model chip.ts is the CHIP data model. CHIP is Project CHIP's connectedhomeip repository. At the time of this writing this is the most robust open-source programmatic definition of Matter elements and serves as a defacto standard for Matter definitions.

We generate chip.ts from CHIP definitions. This ensures our definitions align with CHIP's.

The CHIP generator is generate-chip. To run:

cd matter.js/codegen
npm run generate-chip

Local data model

Input model local.ts defines elements that are unavailable (or incorrect) in the other models. This partial model is the result of editorial decisions by matter.js contributors.

Standard (final) data model

Unlike above data models, the standard data model in src/model/standard is part of the matter.js public API. This represents our best attempt at a complete Matter data model.

generate-model.ts creates this model by analyzing and combining elements from the models above.

To update the standard model:

cd matter.js/codegen
npm run generate-model

Cluster generation

One of the ways we use the Matter Object Model is to generate cluster implementations.

The cluster generator is generate-cluster.ts. To run:

cd matter.js/codegen
npm run generate

Note that this will rebuild the model (above) and the clusters. If you know the model is unchanged you can also just generate the clusters:

cd matter.js/codegen
npm run generate-clusters

This is generally only useful if you are modifying the cluster generation code or if you have already generated the model.

Ensuring correctness

Many of the scripts mentioned above generate models. It is important that these models are accurate.

To this end, there is extensive validation that every generator runs before output. Validation prints detailed information about the state of every element in the model.

Each validation error is associated with an error code. If there are errors, a summary of the errors is printed at the end of validation.

The final model is also validated during testing by MatterTest.

Automatic validation can't find every semantic error but it does ensure the resulting model is functional.