MCPcopy Index your code
hub / github.com/bpmn-io/moddle

github.com/bpmn-io/moddle @v8.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v8.1.0 ↗ · + Follow
35 symbols 84 edges 31 files 5 documented · 14%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

moddle

CI

A utility library for working with meta-model based data structures.

What is it good for?

moddle offers you a concise way to define meta models in JavaScript. You can use these models to consume documents, create model elements, and perform model validation.

Define a schema

You start by creating a moddle schema. It is a JSON file which describes types, their properties, and relationships:

{
  "$schema": "https://unpkg.com/moddle/resources/schema/moddle.json",
  "name": "Cars",
  "uri": "http://cars",
  "prefix": "c",
  "types": [
    {
      "name": "Base",
      "properties": [
        { "name": "id", "type": "String", "isAttr": true }
      ]
    },
    {
      "name": "Root",
      "superClass": [ "Base" ],
      "properties": [
        { "name": "cars", "type": "Car", "isMany": true }
      ]
    },
    {
      "name": "Car",
      "superClass": [ "Base" ],
      "properties": [
        { "name": "name", "type": "String", "isAttr": true, "default": "No Name" },
        { "name": "power", "type": "Integer", "isAttr": true },
        { "name": "similar", "type": "Car", "isMany": true, "isReference": true },
        { "name": "trunk", "type": "Element", "isMany": true }
      ]
    }
  ]
}

You may attach the provided JSON schema to get your moddle descriptor validated by code editor.

Instantiate moddle

You can instantiate a moddle instance with a set of defined schemas:

import { Moddle } from 'moddle';

var cars = new Moddle([ carsJSON ]);

Create objects

Use a moddle instance to create objects of your defined types:

var taiga = cars.create('c:Car', { name: 'Taiga' });

console.log(taiga);
// { $type: 'c:Car', name: 'Taiga' };


var cheapCar = cars.create('c:Car');

console.log(cheapCar.name);
// "No Name"


// really?
cheapCar.get('similar').push(taiga);

Introspect things

Then again, given the knowledge moddle has, you can perform deep introspection:

var carDescriptor = cheapCar.$descriptor;

console.log(carDescriptor.properties);
// [ { name: 'id', type: 'String', ... }, { name: 'name', type: 'String', ...} ... ]

Access extensions

moddle is friendly towards extensions and keeps unknown any properties around:

taiga.set('specialProperty', 'not known to moddle');

console.log(taiga.get('specialProperty'));
// 'not known to moddle'

It also allows you to create any elements for namespaces that you did not explicitly define:

var screwdriver = cars.createAny('tools:Screwdriver', 'http://tools', {
  make: 'ScrewIt!'
});

car.trunk.push(screwdriver);

There is more

Have a look at our test coverage to learn about everything that is currently supported.

Resources

Related

  • moddle-xml: read xml documents based on moddle descriptors

License

MIT

Core symbols most depended-on inside this repo

coerceType
called by 12
lib/types.js
createModel
called by 12
test/helper.js
parseName
called by 6
lib/ns.js
isBuiltIn
called by 6
lib/types.js
isSimple
called by 6
lib/types.js
createModelBuilder
called by 4
test/helper.js
stripGlobal
called by 3
lib/properties.js
readFile
called by 3
test/helper.js

Shape

Function 27
Class 8

Languages

TypeScript100%

Modules by API surface

lib/base.spec.ts6 symbols
test/helper.js5 symbols
lib/registry.js5 symbols
lib/properties.js4 symbols
lib/types.js3 symbols
test/spec/properties.js2 symbols
test/spec/moddle.js2 symbols
lib/factory.spec.ts2 symbols
lib/factory.js2 symbols
lib/ns.js1 symbols
lib/moddle.js1 symbols
lib/descriptor-builder.js1 symbols

For agents

$ claude mcp add moddle \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page