Mapping
Mapping protocol schemas
Base Field Mapping Protocol
Shared by: Connector
This module provides the canonical field mapping schema used across ObjectStack for data synchronization.
Use Cases:
- Integration connectors (integration/connector.zod.ts)
- (
data/external-lookup.zod.ts'sExternalFieldMappingSchemaextended this base too, until the whole external-lookup family was retired in #8075 — ADR-0049, zero consumers.)
@example Basic field mapping
const mapping: FieldMapping = {
source: 'external_user_id',
target: 'user_id',
};@example With a fallback for missing source values
const mapping: FieldMapping = {
source: 'user_name',
target: 'name',
defaultValue: 'Unknown'
};What is NOT here any more: transform (#5552, protocol 17)
This schema used to carry a transform key typed by a five-member
discriminated union — constant / cast / lookup / javascript / map.
No runtime ever executed one of the five, so the whole union was retired
under ADR-0049 enforce-or-remove; the tombstone below carries the
prescription, and the measurement behind it is written up on the
field-mapping-transform-removed conversion in src/conversions/registry.ts.
Where transforms actually run: data/mapping.zod.ts's
ImportFieldMappingSchema.transform — a flat string enum steering a params
bag, applied row by row by the REST import path and recorded live, key by
key, in packages/spec/liveness/mapping.json. Same word, opposite
disposition: that one runs, and rejects its own javascript value with a 400
rather than pretending to.
Source: packages/spec/src/shared/mapping.zod.ts
TypeScript Usage
import { FieldMappingSchema } from '@objectstack/spec/shared';
import type { FieldMapping } from '@objectstack/spec/shared';
// Validate data
const result = FieldMappingSchema.parse(data);FieldMapping
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| source | string | ✅ | Source field name |
| target | string | ✅ | Target field name |
| transform | never | optional | [REMOVED] FieldMapping.transform — authored as connector.fieldMappings[].transform and externalLookup.fieldMappings[].transform — was removed in @objectstack/spec 17.0.0 (#5552, ADR-0049), and the whole FieldMappingTransform union went with it (constant / cast / lookup / javascript / map) — no runtime ever executed any of the five, and the javascript member advertised dialect: "js", a dialect retired in #3278. Delete the key. The transform pipeline that IS enforced is the import mapping's: mapping.fieldMapping[].transform (a string enum — none/constant/map/split/join/lookup — with its settings in params), applied by the REST import path, which rejects javascript with a 400 rather than pretending to run it. Run os migrate meta --from 16 to rewrite existing sources automatically. |
| defaultValue | any | optional | Default if source is null/undefined |