MappedType
Package: @opra/common
MappedType is the runtime class that represents a derived object type created by applying field transformations to an existing ComplexType, MixinType, or another MappedType. It is the runtime counterpart of the OmitType, PickType, PartialType, and RequiredType factory functions.
A MappedType shares the full field API of ComplexTypeBase — you can iterate its fields, look up individual fields, and generate codecs, just like with ComplexType.
Inheritance
DocumentElement
└── DataType
└── ComplexTypeBase ← shared field API (fields, findField, getField, …)
└── MappedType
Properties
Properties inherited from DataType:
| Property | Type | Description |
|---|---|---|
kind | 'MappedType' | Always 'MappedType'. |
name | string | undefined | Registry name. undefined for anonymous mapped types. |
description | string | undefined | Human-readable description. |
abstract | boolean | undefined | Whether the type is abstract. |
embedded | boolean | true when the type has no name. |
Properties inherited from ComplexTypeBase:
| Property | Type | Description |
|---|---|---|
keyField | string | undefined | Primary key field name (inherited from base if the key field was not omitted). |
additionalFields | boolean | DataType | ['error'] | ['error', string] | undefined | Inherited from base (suppressed when pick is set). |
ctor | Type | undefined | TypeScript class constructor (inherited from base). |
Properties on MappedType:
| Property | Type | Description |
|---|---|---|
base | ComplexType | MappedType | MixinType | The source type this MappedType was derived from. |
pick | string[] | undefined | Field names retained from base (set when created via PickType). |
omit | string[] | undefined | Field names removed from base (set when created via OmitType). |
partial | string[] | boolean | undefined | Fields made optional — array of names, or true for all (set via PartialType). |
required | string[] | boolean | undefined | Fields made required — array of names, or true for all (set via RequiredType). |
discriminatorField | string | undefined | Inherited from base. |
discriminatorValue | string | undefined | Inherited from base. |
Field methods
All field methods are inherited from ComplexTypeBase and behave identically to ComplexType. See ComplexType — Field methods.
| Method | Description |
|---|---|
findField(nameOrPath, scope?) | Returns the ApiField at the given name/path, or undefined. |
getField(nameOrPath, scope?) | Same as findField but throws if not found. |
fields(scope?) | Iterator over all ApiField instances visible in scope. |
fieldNames(scope?) | Iterator over field names. |
fieldEntries(scope?) | Iterator over [name, ApiField] pairs. |
fieldCount(scope?) | Count of fields visible in scope. |
parseFieldPath(path, options?) | Resolves a dot-separated path to an array of ParsedFieldPath items. |
normalizeFieldPath(path, options?) | Resolves a path and returns its canonical dot-separated form. |
Methods
extendsFrom(baseType)
Returns true if this mapped type's base (or its base chain) extends from the given type.
extendsFrom(baseType: DataType | string | Type | object): boolean
const updateDto = document.node.getDataType('UpdateCustomerDto');
if (updateDto instanceof MappedType) {
updateDto.extendsFrom('Customer'); // true if derived from Customer
}
generateCodec(codec, options?)
Inherited from ComplexTypeBase. Compiles a codec that validates/transforms the fields of this mapped type (respecting pick/omit and partial/required transformations).
generateCodec(
codec: 'encode' | 'decode',
options?: DataType.GenerateCodecOptions
): Validator
toJSON(options?)
Returns an OpraSchema.MappedType plain object for schema export, including base, pick/omit, and partial/required.
toJSON(options?: ApiDocument.ExportOptions): OpraSchema.MappedType
Obtaining a MappedType instance
Mapped types appear in a document when a controller or operation registers a type produced by OmitType, PickType, PartialType, or RequiredType.
import { MappedType } from '@opra/common';
const type = document.node.getDataType('UpdateCustomerDto');
if (type instanceof MappedType) {
console.log(type.kind); // 'MappedType'
console.log(type.base.name); // 'Customer'
console.log(type.omit); // ['_id'] or undefined
console.log(type.partial); // true or string[]
}
→ ApiDocument · MappedType · ComplexType