Declarative JSON mappings runtime for ProcessEngine.
@processengine/mappings is the transformation and normalization boundary in the ProcessEngine family. It turns a declarative mapping source into a prepared runtime artifact and executes that artifact against runtime input.
mappings is a small runtime for simple, explicit, declarative data transformation.
It is intended for tasks such as:
- normalizing raw input into a stable structure;
- building a payload for the next step in a process;
- deriving small sets of normalized facts from source data;
- keeping transformation logic outside of surrounding service code.
Inside the broader ProcessEngine family, mappings sits between raw data and the next layer that consumes normalized output.
mappings is not:
- a general-purpose programming language;
- a runtime for stateful processing;
- a place for complex algorithmic logic;
- a mechanism for external I/O, network calls, or side effects.
If a task requires loops with arbitrary control flow, stateful orchestration, external calls, or substantial procedural logic, that task belongs in code or another explicit runtime boundary rather than in mapping DSL.
The canonical public API is:
validateMappings(source, options?)prepareMappings(source, options?)executeMappings(artifact, input, options?)MappingsCompileErrorMappingsRuntimeErrorformatMappingsDiagnostics(...)formatMappingsRuntimeError(...)
Roles:
validateMappings(...)performs soft validation and returns{ ok, diagnostics }without throwing on invalid source.prepareMappings(...)validates and prepares a runtime artifact. Invalid source causesMappingsCompileError.executeMappings(...)executes only a prepared artifact. It does not perform hidden compile/prepare work.
Legacy engine-style entrypoints such as MappingEngine and public compile() are not part of the public package API.
npm install @processengine/mappingsNode.js requirement: >=20.19.0.
import {
validateMappings,
prepareMappings,
executeMappings,
} from '@processengine/mappings';
const source = {
mappingId: 'profile.normalize.v1',
sources: {
raw: 'object',
},
output: {
'profile.displayName': { normalizeSpaces: 'sources.raw.fullName' },
'profile.email': { lowercase: 'sources.raw.email' },
'profile.country': {
mapValue: {
from: 'sources.raw.countryCode',
map: {
DE: 'DE',
DEU: 'DE',
FR: 'FR',
FRA: 'FR',
},
fallback: 'passthrough',
},
},
'profile.hasTags': { exists: 'sources.raw.tags' },
},
};
const validation = validateMappings(source);
if (!validation.ok) {
console.error(validation.diagnostics);
process.exit(1);
}
const artifact = prepareMappings(source);
const result = executeMappings(
artifact,
{
raw: {
fullName: ' Ada Lovelace ',
email: 'ADA@EXAMPLE.COM',
countryCode: 'DEU',
tags: ['math', 'notes'],
},
},
{ trace: 'basic' },
);
console.log(result.output);
// {
// profile: {
// displayName: 'Ada Lovelace',
// email: 'ada@example.com',
// country: 'DE',
// hasTags: true
// }
// }Supported trace levels:
false'basic''verbose'
Trace is disabled by default.
falsereturns no trace.'basic'returns compact execution events suitable for routine diagnostics.'verbose'may include additional redacted input and output fragments for debugging and local inspection.
Use the redact option to control masking of trace values.
executeMappings(...) returns a success result with this shape:
{
output: { ... },
trace: [ ... ] // optional
}This is not a success/error status envelope.
Failures are surfaced through typed errors:
MappingsCompileErrorMappingsRuntimeError
Current source definitions support these operators:
fromliteralexistsequalscoalescetrimlowercaseuppercasenormalizeSpacesremoveNonDigitsmapValuetransform
See the specification for source shape, operator constraints, runtime semantics, and limitations.
Repository examples are intentionally small but complete. They show source, validation, preparation, execution, output, and trace where relevant.
examples/README.mdexamples/basic-transform.mjsexamples/validate-diagnostics.mjsexamples/runtime-error.mjsexamples/trace-basic.mjsexamples/trace-verbose.mjsexamples/prepared-artifact.mjsexamples/process-boundary.mjsexamples/limitations.md
2.x is the canonical public release line of @processengine/mappings.