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

@step-nc/p21-reader

v1.0.0

Published

Reader for ISO-10303-21 (Part 21) files — load P21 data into a StepModel using an EXPRESS schema

Downloads

64

Readme

@step-nc/p21-reader

Lector de archivos P21 (ISO 10303-21 / Part 21). Carga datos P21 en un StepModel usando un esquema EXPRESS resuelto: mapea parámetros a atributos, resuelve referencias entre instancias y produce diagnósticos de lectura.

Para entender la arquitectura del reader (pipeline, conversión de parámetros, carga en dos fases), véase ARCHITECTURE.md. Para el estado y las fases del desarrollo, véase ROADMAP.md.

Uso mínimo

import { readP21 } from '@step-nc/p21-reader';
import { buildSchema } from '@step-nc/express-dictionary';
import { parseExpress } from '@step-nc/express-parser';

const expressSource = `…`; // texto EXPRESS del schema
const p21Source = `
ISO-10303-21;
HEADER;
FILE_DESCRIPTION((''), '2;1');
FILE_NAME('', '', (''), (''), '', '', '');
FILE_SCHEMA(('EXAMPLE_SCHEMA'));
ENDSEC;
DATA;
#1=POINT(1.0, 2.0, 3.0);
#2=LINE(#1, #1);
ENDSEC;
END-ISO-10303-21;
`;

const ast = parseExpress(expressSource).ast;
const { schema } = buildSchema(ast);
const { model, diagnostics } = readP21(p21Source, schema);

// model es un StepModel poblado con las instancias del DATA section
// diagnostics combina errores/advertencias del parser P21 y del reader

API principal

  • readP21(source, schema, options?) — Punto de entrada: parsea el texto P21, carga las instancias en un StepModel y devuelve el modelo junto con diagnósticos combinados (parser + reader).
  • ReadResult{ model: StepModel; diagnostics: ReadonlyArray<P21ParseDiagnostic | ReaderDiagnostic> }.
  • P21ReadOptions — Opciones de lectura:
    • continueOnParseError?: boolean — Si es true, continúa cargando entidades aunque el parser haya reportado errores. Por defecto: false.
    • strictRefs?: boolean — Si es true, referencias colgantes producen error; si es false, advertencia. Por defecto: true.

Tipos y diagnósticos

  • ReaderDiagnostic{ severity, code, message, instanceId?, entityName?, attributeName? }.
  • ReaderDiagnosticCodeUNKNOWN_ENTITY, ABSTRACT_ENTITY, PARAMETER_TYPE_MISMATCH, REQUIRED_ATTRIBUTE_MISSING, EXTRA_PARAMETER, DANGLING_ENTITY_REF, DANGLING_VALUE_REF, UNKNOWN_CONSTANT, DUPLICATE_INSTANCE_ID, INVALID_AGGREGATION.
  • HelperscreateReaderDiagnostic, errorDiag, warningDiag, infoDiag, hasReaderErrors, filterBySeverity, formatReaderDiagnostic.

Conversión y carga (uso avanzado)

  • convertParameter(param, typeDescriptor?, schema, context?) — Convierte un ParameterNode del parser P21 en un AttributeValue (primitivos, listas, refs, SELECT, etc.). Útil para integraciones o pruebas.
  • loadEntities(dataSections, schema, model, strictRefs) — Carga las entidades de las secciones DATA en el modelo (dos fases: crear instancias, luego rellenar atributos y resolver refs). Normalmente se usa desde readP21.
  • resolveRefsInValue(value, model, strictRefs, context, diagnostics) — Recorre un valor y reemplaza referencias placeholder (entityName vacío) por refs resueltas según el modelo.
  • findConstant(name, schema) — Busca una constante por nombre en el schema (sin evaluar expresiones).

Ejemplo (validar modelo tras lectura):

import { readP21, hasReaderErrors } from '@step-nc/p21-reader';
import { validateModel } from '@step-nc/step-factory';

const { model, diagnostics } = readP21(p21Source, schema);

if (hasReaderErrors(diagnostics)) {
  console.error('Errores de lectura:', diagnostics.filter(d => d.severity === 'error'));
}

const modelDiags = validateModel(model);
if (modelDiags.length > 0) {
  console.warn('Validación del modelo:', modelDiags);
}

Dependencias

  • @step-nc/p21-parser — Parsea texto P21 en un AST (header + data sections).
  • @step-nc/express-dictionary — Proporciona el ExpressSchema resuelto para mapear entidades y tipos.
  • @step-nc/step-factoryStepModel, tipos de valores (AttributeValue, InstanceRef, etc.) y validación.