ObjectStackObjectStack

Mapping

Mapping protocol schemas

Base Field Mapping Protocol

Shared by: ETL, Sync, Connector, External Lookup

This module provides the canonical field mapping schema used across

ObjectStack for data transformation and synchronization.

Use Cases:

  • ETL pipelines (data/mapping.zod.ts)

  • Data synchronization (automation/sync.zod.ts)

  • Integration connectors (integration/connector.zod.ts)

  • External lookups (data/external-lookup.zod.ts)

@example Basic field mapping


const mapping: FieldMapping = \{

source: 'external_user_id',

target: 'user_id',

\};

@example With transformation


const mapping: FieldMapping = \{

source: 'user_name',

target: 'name',

transform: \{ type: 'cast', targetType: 'string' \},

defaultValue: 'Unknown'

\};

Source: packages/spec/src/shared/mapping.zod.ts

TypeScript Usage

import { FieldMapping, TransformType } from '@objectstack/spec/shared';
import type { FieldMapping, TransformType } from '@objectstack/spec/shared';

// Validate data
const result = FieldMapping.parse(data);

FieldMapping

Properties

PropertyTypeRequiredDescription
sourcestringSource field name
targetstringTarget field name
transformObject | Object | Object | Object | ObjectoptionalTransformation to apply
defaultValueanyoptionalDefault if source is null/undefined

TransformType

Union Options

This schema accepts one of the following structures:

Option 1

Set a constant value

Type: constant

Properties

PropertyTypeRequiredDescription
typestring
valueanyConstant value to use

Option 2

Cast to a specific data type

Type: cast

Properties

PropertyTypeRequiredDescription
typestring
targetTypeEnum<'string' | 'number' | 'boolean' | 'date'>Target data type

Option 3

Lookup value from another table

Type: lookup

Properties

PropertyTypeRequiredDescription
typestring
tablestringLookup table name
keyFieldstringField to match on
valueFieldstringField to retrieve

Option 4

Custom JavaScript transformation

Type: javascript

Properties

PropertyTypeRequiredDescription
typestring
expressionstringJavaScript expression (e.g., "value.toUpperCase()")

Option 5

Map values using a dictionary

Type: map

Properties

PropertyTypeRequiredDescription
typestring
mappingsRecord<string, any>Value mappings (e.g., {"Active": "active"})


On this page