Skip to content

Instantly share code, notes, and snippets.

@Apollon77
Last active April 5, 2023 11:55
Show Gist options
  • Save Apollon77/64224fa6c867958c90f2be2dfc495817 to your computer and use it in GitHub Desktop.
Save Apollon77/64224fa6c867958c90f2be2dfc495817 to your computer and use it in GitHub Desktop.
Move concept for node-matter -> matter.js

How to move code/classes/files?

  • Directory "codec" (with exports)
    • all "Schema" ones (PairingCode and QRCode) -> matter.js/schema
    • Rest (codecs) -> mtter.js/codec
  • Directory "crypro" (with exports)
    • make crypto a signleton
    • Move Crypto (basis) and Spake2 --> matter.js/crypto --> This adds BN and eliptic as deps to matter.js
    • Leave a "CryptoNode" in node-matter directory crypto
  • Directory "error" -> matter.js/common/ (with exports)
  • Directory "log" -> matter.js/util/log (with exports)
  • Directory "math" -> matter.js/math (no exports)
  • Directory "matter/certificate" -> matter.js "certificate" (with exports)
  • Directory "matter/cluster" -> matter.js/cluster (with exports)
  • Direcory "matter/common" -> matter.js/common (with exports)
  • Directory "matter/fabric" -> matter.js/fabric (with exports)
  • Directory "matter/interaction" -> matter.js/protocol/interaction (with exports)
  • Directory "matter/mdns" -> matter.js/mdns ... or we start a matter.js/communication/mdns (and also move net in there) (with exports)
  • Directory "Matter/session"
    • Basic session types --> matter.js/session
    • session/secure/Pase* -> matter.js/session/pase
    • session/secure/Case* -> matter.js/session/case
    • session/secure/SecureChannel* -> matter.js/protocol/securechannel
  • Directory "net"
    • basically -> matter.js/net
    • the nodejs specific parts that staay there with Filename *Node (so remove extra directory "node")
  • Directory "storage"
    • all general Files and types -> matter.js/util/storage
    • StorageBackendDisk stays
  • Directory "time" -> matter.js/util/time
  • Directory "util" -> matter.js/util
  • Files matter/MatterDevice and matter/MatterController -> root of matter.js (will be replaced pot anyway when API is updated)

After this in matter-node.js we should have structure like:

  • crypto
    • CryptoNode.ts
  • net
    • NetworkNode.ts
    • UdpChannelNode.ts
  • persistence
    • StorageNode.ts
  • time
    • TimeNode.ts
  • ControllerNode.ts
  • DeviceNode.ts

How to export all the needed things?

  • Flat export as of currently - has big downsides becausethen the naming of All exported entities in whole matter.js need to be unique (that already breaks now with StatusCode and EffectVariant)
  • We could use modules to export "by topic" and only have a very few global exports
    • This means that users do "import { AccessControlCluster } from "@project-chip/matter.js/cluster" - so we define modules "by topic" toexport ... the modules could match to our above directory structure
@vves
Copy link

vves commented Apr 4, 2023

before refactoring I recommend getting all the expected exports promoted to the @project-chip/matter-node.js index.ts so that consumers of the library don't have to rework their imports. I'll do the work and get a PR in place.

@Apollon77
Copy link
Author

@vves in fact matter-node will only export the "nodejs specific" classes. This is a handful of exports. All rest will move to matter.js together with the code. Ok, looking forward for your PR, but 9x% of the exports come from matter.js in the future!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment