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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@judo/model-parser

v0.1.1

Published

XMI/XML parser for JUDO UI models

Readme

@judo/model-parser

XMI/XML parser for JUDO UI models

Purpose

Parses ECore-based XMI/XML model files into typed TypeScript objects (Application and its subtree), applying EMF default values, type discrimination, boolean/numeric coercion, and containment tree building. This is a pure data-processing layer with zero React dependencies.

Architecture Layer

Layer 1 (Foundation) — converts raw XML into the typed model objects consumed by all higher layers.

Dependencies

  • @judo/model-api — TypeScript type definitions
  • fast-xml-parser — XML parsing engine

File Structure

src/
├── index.ts                        # Public barrel exports
├── parser.ts                       # Core XML→Application[] parser
├── containment-builder.ts          # Visual element tree builder + parent refs
├── emf-defaults.ts                 # EMF default value constants & applicators
├── reference-resolver.ts           # XMI cross-reference indexer/resolver
├── type-discriminator.ts           # xsi:type → @type mapping
├── parser.test.ts
├── parser.performance.test.ts
├── containment-builder.test.ts
├── emf-defaults.test.ts
├── reference-resolver.test.ts
└── type-discriminator.test.ts

Exports Summary

Core Parser

| Export | Kind | Description | | -------------------------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | parseModel(xml) | function | Main entry point. Parses an XMI/XML string into Application[]. Handles both multi-actor (<xmi:XMI> wrapper) and single-actor (direct <ui:Application> root) formats. | | parseModelWithOptions(xml, options?) | function | Advanced parse. Returns ParseResult with element index and optional reference validation errors. | | ModelParseError | class | Error thrown when XML structure is invalid. Includes a path field. | | ModelReferenceError | class | Error thrown when a cross-reference cannot be resolved. Carries sourceId and targetRef. | | ParseOptions | interface | Options for parseModelWithOptions (validateReferences, preserveRawAttributes). | | ParseResult | interface | Extended parse result: applications, element index map, and validation errors. | | ParseError | interface | Describes a parse/validation error (type, message, elementId, referencedId, path). |

Reference Resolver

| Export | Kind | Description | | ------------------- | ----- | -------------------------------------------------------------------------------------------------------------------------------------------------- | | ReferenceResolver | class | Indexes parsed elements by xmi:id and resolves cross-references. Methods: indexElement(), resolve(), getIndex(), clear(), indexTree(). |

Containment Builder

| Export | Kind | Description | | --------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | | buildContainmentTree(container) | function | Recursively builds a visual element containment tree from a parsed container. Processes Flex, TabController, Table, Link, ButtonGroup, and all input types. | | attachParentReferences(root, parent?) | function | Mutates a visual tree by attaching __parent back-references for upward navigation. | | getParent(element) | function | Retrieves the __parent reference from a visual element. Returns undefined if none attached. |

Type Discriminator

| Export | Kind | Description | | --------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- | | TYPE_MAP | constant | Maps ~85 fully-qualified XMI xsi:type values to simplified @type strings. | | discriminateType(element) | function | Looks up xsi:type in TYPE_MAP. Falls back to stripping the namespace prefix. Returns string \| undefined. | | inferTypeFromTag(tagName) | function | Infers a type from an XML tag name when xsi:type is absent. |

EMF Defaults (~30 default constant objects)

Default value constants for all visual element types, inputs, structural elements, and data types:

| Category | Examples | | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Visual elements | VISUAL_ELEMENT_DEFAULTS, FLEX_DEFAULTS, PAGE_CONTAINER_DEFAULTS, TABLE_DEFAULTS, LINK_DEFAULTS | | Inputs | INPUT_DEFAULTS, TEXT_INPUT_DEFAULTS, TEXT_AREA_DEFAULTS, NUMERIC_INPUT_DEFAULTS, DATE_TIME_INPUT_DEFAULTS, TIME_INPUT_DEFAULTS, CHECKBOX_DEFAULTS, SWITCH_DEFAULTS | | Structural | PAGE_DEFINITION_DEFAULTS, APPLICATION_DEFAULTS, ACTION_DEFAULTS, ACTION_DEFINITION_DEFAULTS, CONFIRMATION_DEFAULTS, OPTION_DEFAULTS | | Data | CLASS_TYPE_DEFAULTS, RELATION_TYPE_DEFAULTS, ATTRIBUTE_TYPE_DEFAULTS, OPERATION_TYPE_DEFAULTS, REFERENCE_TYPE_DEFAULTS, BINARY_TYPE_DEFAULTS | | Sub-elements | SIZE_DEFAULTS, SIZE_CONSTRAINT_DEFAULTS, FRAME_DEFAULTS |

Applicator functions:

| Function | Description | | ---------------------------------------------- | ---------------------------------------------------------------------- | | applyTypeDefaults(element, type) | Applies EMF defaults based on @type. Only sets undefined properties. | | applyPropertyDefaults(element, propertyName) | Applies defaults to contained objects based on property name. | | applyActionDefinitionDefaults(element) | Applies defaults to any action definition element. | | applyPageDefinitionDefaults(element) | Applies defaults to page definition elements. | | applyActionDefaults(element) | Applies defaults to action elements. |

Mapping constants:

| Constant | Description | | ----------------------- | ------------------------------------------------------------------- | | TYPE_DEFAULTS_MAP | Maps @type discriminators to their default objects (~42 entries). | | PROPERTY_DEFAULTS_MAP | Maps property names to their default objects. |

Key Patterns

  • Two-pass parsing: XML is first parsed by fast-xml-parser, then a second pass adds @type discriminators, applies EMF defaults, coerces types, and sets eContainer back-references
  • In-place mutation for performance: All default application and coercion functions mutate objects in place (safe because they're freshly parsed transients)
  • EMF default inheritance chain: Default constants use spread inheritance mirroring the ECore type hierarchy (VISUAL_ELEMENT_DEFAULTSFLEX_DEFAULTSPAGE_CONTAINER_DEFAULTS)
  • Explicit boolean/numeric property sets: Curated sets of property names drive targeted coercion from "true"/"false"boolean and numeric strings → number
  • eContainer back-references: During transformElement, every nested child gets an eContainer property pointing to its parent, enabling EMF-style upward containment navigation. Additionally, attachParentReferences sets __parent for explicit parent navigation via getParent()
  • Dual format support: Handles both <xmi:XMI> wrapper (multi-actor) and bare <ui:Application> root (single-actor) model formats
  • Tag-name-driven array coercion: Ensures collection properties are always arrays even when the XML contains a single child element