UNPKG

@dipscope/type-manager

Version:

Transform JSON strings or plain objects into JS class instances.

735 lines 33.5 kB
import { DEFAULT_VALUE_RESOLVER } from './constants/default-value-resolver'; import { EMPTY_ARRAY } from './constants/empty-array'; import { EMPTY_MAP } from './constants/empty-map'; import { NULL_VALUE_RESOLVER } from './constants/null-value-resolver'; import { getOwnReflectMetadata } from './functions/get-own-reflect-metadata'; import { nameOf } from './functions/name-of'; import { InjectMetadata } from './inject-metadata'; import { Metadata } from './metadata'; import { PropertyMetadata } from './property-metadata'; import { TYPE_EXTENSION_METADATA_CTOR_SET_KEY } from './type-extension-metadata-ctor-set-key'; import { ResolvedTypeState } from './type-states/resolved-type-state'; import { UnresolvedTypeState } from './type-states/unresolved-type-state'; export class TypeMetadata extends Metadata { constructor(typeManager, typeFnMap, typeMetadataSet, typeFn, typeOptions, parentTypeMetadata) { super(typeManager, typeFnMap); this.typeName = nameOf(typeFn); this.typeFn = typeFn; this.parentTypeMetadata = parentTypeMetadata; this.typeOptionsBase = typeManager.typeOptionsBase; this.typeOptions = this.constructTypeOptions(typeOptions); this.typeMetadataSet = typeMetadataSet; this.currentTypeFnMap = typeFnMap; this.currentChildTypeMetadataMap = new Map(); this.currentPropertyMetadataMap = new Map(); this.currentInjectMetadataMap = new Map(); this.currentTypeState = new UnresolvedTypeState(this); this.extendParentTypeMetadata(); this.configure(typeOptions); return; } get typeState() { return this.currentTypeState; } get injectMetadataMap() { return this.currentTypeState.injectMetadataMap; } get propertyMetadataMap() { return this.currentTypeState.propertyMetadataMap; } get alias() { return this.currentTypeState.alias; } get customValueMap() { return this.currentTypeState.customValueMap; } get serializedNullValue() { return this.currentTypeState.serializedNullValueResolver(); } get serializedDefaultValue() { return this.currentTypeState.serializedDefaultValueResolver(); } get deserializedNullValue() { return this.currentTypeState.deserializedNullValueResolver(); } get deserializedDefaultValue() { return this.currentTypeState.deserializedDefaultValueResolver(); } get beforeSerializeCallback() { return this.currentTypeState.beforeSerializeCallback; } get afterDeserializeCallback() { return this.currentTypeState.afterDeserializeCallback; } get discriminant() { return this.currentTypeState.discriminant; } get discriminator() { return this.currentTypeState.discriminator; } get factory() { return this.currentTypeState.factory; } get injectable() { return this.currentTypeState.injectable; } get injector() { return this.currentTypeState.injector; } get logger() { return this.currentTypeState.logger; } get namingConvention() { return this.currentTypeState.namingConvention; } get polymorphic() { return this.currentTypeState.polymorphic; } get preserveDiscriminator() { return this.currentTypeState.preserveDiscriminator; } get referenceHandler() { return this.currentTypeState.referenceHandler; } get serializer() { return this.currentTypeState.serializer; } get preserveNull() { return this.currentTypeState.preserveNull; } get useDefaultValue() { return this.currentTypeState.useDefaultValue; } get useImplicitConversion() { return this.currentTypeState.useImplicitConversion; } get propertySorter() { return this.currentTypeState.propertySorter; } get sortedPropertyMetadatas() { return this.currentTypeState.sortedPropertyMetadatas; } get injectSorter() { return this.currentTypeState.injectSorter; } get sortedInjectMetadatas() { return this.currentTypeState.sortedInjectMetadatas; } get parentTypeArguments() { return this.currentTypeState.parentTypeArguments; } get propertyOptionsMap() { return this.currentTypeState.propertyOptionsMap; } get injectOptionsMap() { return this.currentTypeState.injectOptionsMap; } constructTypeOptions(typeOptions) { if (typeOptions.customValueMap === undefined) { typeOptions.customValueMap = new Map(); } if (typeOptions.propertyOptionsMap === undefined) { typeOptions.propertyOptionsMap = new Map(); } if (typeOptions.injectOptionsMap === undefined) { typeOptions.injectOptionsMap = new Map(); } return typeOptions; } configureTypeExtensionMetadata(typeExtensionMetadataCtor, typeExtensionOptions) { const typeExtensionMetadataCtorSet = this.extractTypeExtensionMetadataCtorSet(); if (!typeExtensionMetadataCtorSet.has(typeExtensionMetadataCtor)) { typeExtensionMetadataCtorSet.add(typeExtensionMetadataCtor); } const initialTypeExtensionOptions = typeExtensionOptions !== null && typeExtensionOptions !== void 0 ? typeExtensionOptions : {}; const typeExtensionMetadata = new typeExtensionMetadataCtor(this, initialTypeExtensionOptions); return typeExtensionMetadata; } extractTypeExtensionMetadata(typeExtensionMetadataCtor) { const typeExtensionMetadataCtorSet = this.extractTypeExtensionMetadataCtorSet(); if (!typeExtensionMetadataCtorSet.has(typeExtensionMetadataCtor)) { return undefined; } const initialTypeExtensionOptions = {}; const typeExtensionMetadata = new typeExtensionMetadataCtor(this, initialTypeExtensionOptions); return typeExtensionMetadata; } extractTypeExtensionMetadataCtorSet() { let customValueMap = this.typeOptions.customValueMap; if (customValueMap === undefined) { customValueMap = new Map(); this.typeOptions.customValueMap = customValueMap; } let typeExtensionMetadataCtorSet = customValueMap.get(TYPE_EXTENSION_METADATA_CTOR_SET_KEY); if (typeExtensionMetadataCtorSet === undefined) { typeExtensionMetadataCtorSet = new Set(); customValueMap.set(TYPE_EXTENSION_METADATA_CTOR_SET_KEY, typeExtensionMetadataCtorSet); } return typeExtensionMetadataCtorSet; } resolveTypeState() { const typeOptionsBase = this.typeOptionsBase; const typeOptions = this.typeOptions; const typeName = this.typeName; const alias = typeOptions.alias; const beforeSerializeCallback = typeOptions.beforeSerializeCallback; const afterDeserializeCallback = typeOptions.afterDeserializeCallback; const customValueMap = this.resolveCustomValueMap(); const preserveNull = typeOptions.preserveNull === undefined ? typeOptionsBase.preserveNull : typeOptions.preserveNull; const useDefaultValue = typeOptions.useDefaultValue === undefined ? typeOptionsBase.useDefaultValue : typeOptions.useDefaultValue; const useImplicitConversion = typeOptions.useImplicitConversion === undefined ? typeOptionsBase.useImplicitConversion : typeOptions.useImplicitConversion; const serializedDefaultValue = typeOptions.defaultValue === undefined ? typeOptions.serializedDefaultValue : typeOptions.defaultValue; const serializedDefaultValueResolver = useDefaultValue ? (typeof serializedDefaultValue === 'function' ? serializedDefaultValue : () => serializedDefaultValue) : DEFAULT_VALUE_RESOLVER; const serializedNullValueResolver = preserveNull ? NULL_VALUE_RESOLVER : serializedDefaultValueResolver; const deserializedDefaultValue = typeOptions.defaultValue === undefined ? typeOptions.deserializedDefaultValue : typeOptions.defaultValue; const deserializedDefaultValueResolver = useDefaultValue ? (typeof deserializedDefaultValue === 'function' ? deserializedDefaultValue : () => deserializedDefaultValue) : DEFAULT_VALUE_RESOLVER; const deserializedNullValueResolver = preserveNull ? NULL_VALUE_RESOLVER : deserializedDefaultValueResolver; const discriminant = typeOptions.discriminant === undefined ? typeName : typeOptions.discriminant; const discriminator = typeOptions.discriminator === undefined ? typeOptionsBase.discriminator : typeOptions.discriminator; const factory = typeOptions.factory === undefined ? typeOptionsBase.factory : typeOptions.factory; const injectable = typeOptions.injectable === true; const injector = typeOptions.injector === undefined ? typeOptionsBase.injector : typeOptions.injector; const logger = typeOptions.logger === undefined ? typeOptionsBase.logger : typeOptions.logger; const namingConvention = typeOptions.namingConvention === undefined ? typeOptionsBase.namingConvention : typeOptions.namingConvention; const parentTypeArguments = typeOptions.parentTypeArguments === undefined ? EMPTY_ARRAY : typeOptions.parentTypeArguments; const ownParentTypeMetadatas = this.resolveOwnParentTypeMetadatas(parentTypeArguments); const ownChildTypeMetadatas = this.resolveOwnChildTypeMetadatas(); const parentTypeMetadataSet = this.resolveParentTypeMetadataSet(this); const parentTypeMetadatas = Array.from(parentTypeMetadataSet); const childTypeMetadataSet = this.resolveChildTypeMetadataSet(this); const childTypeMetadatas = Array.from(childTypeMetadataSet); const typeMetadataMap = new Map(); const polymorphic = childTypeMetadatas.length > 1; for (let i = 0; i < childTypeMetadatas.length; i++) { const childTypeMetadata = childTypeMetadatas[i]; typeMetadataMap.set(childTypeMetadata.typeFn, childTypeMetadata); } const preserveDiscriminator = typeOptions.preserveDiscriminator === undefined ? typeOptionsBase.preserveDiscriminator : typeOptions.preserveDiscriminator; const referenceHandler = typeOptions.referenceHandler === undefined ? typeOptionsBase.referenceHandler : typeOptions.referenceHandler; const serializer = typeOptions.serializer === undefined ? typeOptionsBase.serializer : typeOptions.serializer; const propertySorter = typeOptions.propertySorter === undefined ? typeOptionsBase.propertySorter : typeOptions.propertySorter; const ownPropertyMetadataMap = this.currentPropertyMetadataMap; const propertyMetadataMap = this.resolvePropertyMetadataMap(parentTypeMetadatas); const sortedPropertyMetadatas = propertySorter === undefined ? Array.from(propertyMetadataMap.values()) : Array.from(propertyMetadataMap.values()).sort(propertySorter.sort); const injectMetadataMap = this.currentInjectMetadataMap; const injectSorter = typeOptions.injectSorter === undefined ? typeOptionsBase.injectSorter : typeOptions.injectSorter; const sortedInjectMetadatas = injectSorter === undefined ? Array.from(injectMetadataMap.values()) : Array.from(injectMetadataMap.values()).sort(injectSorter.sort); const propertyOptionsMap = typeOptions.propertyOptionsMap === undefined ? EMPTY_MAP : typeOptions.propertyOptionsMap; const injectOptionsMap = typeOptions.injectOptionsMap === undefined ? EMPTY_MAP : typeOptions.injectOptionsMap; const resolvedTypeState = new ResolvedTypeState(this, alias, customValueMap, serializedNullValueResolver, serializedDefaultValue, serializedDefaultValueResolver, deserializedNullValueResolver, deserializedDefaultValue, deserializedDefaultValueResolver, beforeSerializeCallback, afterDeserializeCallback, discriminant, discriminator, factory, injectable, injector, logger, namingConvention, polymorphic, typeMetadataMap, preserveDiscriminator, referenceHandler, serializer, preserveNull, useDefaultValue, useImplicitConversion, propertySorter, sortedPropertyMetadatas, injectSorter, sortedInjectMetadatas, parentTypeArguments, parentTypeMetadatas, ownParentTypeMetadatas, childTypeMetadatas, ownChildTypeMetadatas, propertyOptionsMap, propertyMetadataMap, ownPropertyMetadataMap, injectOptionsMap, injectMetadataMap); this.currentTypeState = resolvedTypeState; return resolvedTypeState; } unresolveTypeState() { const unresolvedTypeState = new UnresolvedTypeState(this); this.currentTypeState = unresolvedTypeState; return unresolvedTypeState; } resolveCustomValueMap() { const typeOptionsBase = this.typeOptionsBase; const typeOptions = this.typeOptions; const customValueMap = new Map(); if (typeOptions.customValueMap === undefined) { return customValueMap; } const baseCustomValueMap = typeOptionsBase.customValueMap === undefined ? EMPTY_MAP : typeOptionsBase.customValueMap; for (const [customKey, customValue] of typeOptions.customValueMap) { if (customValue === undefined) { customValueMap.set(customKey, baseCustomValueMap.get(customKey)); continue; } customValueMap.set(customKey, customValue); } return customValueMap; } resolveOwnParentTypeMetadatas(parentTypeArguments) { const ownParentTypeMetadatas = new Array(); const parentTypeMetadatas = this.resolveTypeMetadatas(parentTypeArguments); for (let i = parentTypeMetadatas.length - 1; i >= 0; i--) { ownParentTypeMetadatas.push(parentTypeMetadatas[i]); } if (this.parentTypeMetadata !== undefined) { ownParentTypeMetadatas.push(this.parentTypeMetadata); } return ownParentTypeMetadatas; } resolveOwnChildTypeMetadatas() { const ownChildTypeMetadatas = new Array(); for (const childTypeMetadata of this.currentChildTypeMetadataMap.values()) { ownChildTypeMetadatas.push(childTypeMetadata); } for (const setTypeMetadata of this.typeMetadataSet) { const typeOptions = setTypeMetadata.typeOptions; const parentTypeArguments = typeOptions.parentTypeArguments === undefined ? EMPTY_ARRAY : typeOptions.parentTypeArguments; const parentTypeMetadatas = this.resolveTypeMetadatas(parentTypeArguments); for (let i = 0; i < parentTypeMetadatas.length; i++) { if (parentTypeMetadatas[i] === this) { ownChildTypeMetadatas.push(setTypeMetadata); break; } } } return ownChildTypeMetadatas; } resolveParentTypeMetadataSet(typeMetadata, parentTypeMetadataSet = new Set()) { if (parentTypeMetadataSet.has(typeMetadata)) { return parentTypeMetadataSet; } parentTypeMetadataSet.add(typeMetadata); const typeOptions = typeMetadata.typeOptions; const parentTypeArguments = typeOptions.parentTypeArguments === undefined ? EMPTY_ARRAY : typeOptions.parentTypeArguments; const parentTypeMetadatas = this.resolveTypeMetadatas(parentTypeArguments); for (let i = parentTypeMetadatas.length - 1; i >= 0; i--) { this.resolveParentTypeMetadataSet(parentTypeMetadatas[i], parentTypeMetadataSet); } if (typeMetadata.parentTypeMetadata !== undefined) { this.resolveParentTypeMetadataSet(typeMetadata.parentTypeMetadata, parentTypeMetadataSet); } return parentTypeMetadataSet; } resolveChildTypeMetadataSet(typeMetadata, childTypeMetadataSet = new Set()) { if (childTypeMetadataSet.has(typeMetadata)) { return childTypeMetadataSet; } childTypeMetadataSet.add(typeMetadata); for (const childTypeMetadata of typeMetadata.currentChildTypeMetadataMap.values()) { this.resolveChildTypeMetadataSet(childTypeMetadata, childTypeMetadataSet); childTypeMetadata.unresolveTypeState(); } for (const setTypeMetadata of this.typeMetadataSet) { const typeOptions = setTypeMetadata.typeOptions; const parentTypeArguments = typeOptions.parentTypeArguments === undefined ? EMPTY_ARRAY : typeOptions.parentTypeArguments; const parentTypeMetadatas = this.resolveTypeMetadatas(parentTypeArguments); for (let i = 0; i < parentTypeMetadatas.length; i++) { if (parentTypeMetadatas[i] === typeMetadata) { this.resolveChildTypeMetadataSet(setTypeMetadata, childTypeMetadataSet); setTypeMetadata.unresolveTypeState(); break; } } } return childTypeMetadataSet; } resolvePropertyMetadataMap(parentTypeMetadatas) { const propertyMetadataMap = new Map(); for (let i = parentTypeMetadatas.length - 1; i >= 0; i--) { for (const [propertyName, propertyMetadata] of parentTypeMetadatas[i].currentPropertyMetadataMap) { propertyMetadataMap.set(propertyName, propertyMetadata); } } for (const propertyMetadata of this.currentPropertyMetadataMap.values()) { propertyMetadata.unresolvePropertyState(); } return propertyMetadataMap; } extendParentTypeMetadata() { const parentTypeMetadata = this.parentTypeMetadata; if (parentTypeMetadata !== undefined) { parentTypeMetadata.currentChildTypeMetadataMap.set(this.typeFn, this); } return this; } reflectInjectMetadata() { var _a; if (this.typeFn.length === 0) { return this; } const injectTypeFns = ((_a = getOwnReflectMetadata('design:paramtypes', this.typeFn)) !== null && _a !== void 0 ? _a : new Array()); for (let injectIndex = 0; injectIndex < injectTypeFns.length; injectIndex++) { if (!this.currentInjectMetadataMap.has(injectIndex)) { this.configureInjectMetadata(injectIndex, { typeArgument: injectTypeFns[injectIndex] }); } } return this; } hasAlias(alias) { this.releaseAlias(); this.typeOptions.alias = alias; if (alias !== undefined) { this.currentTypeFnMap.set(alias, this.typeFn); } this.currentTypeState = new UnresolvedTypeState(this); return this; } releaseAlias() { const alias = this.typeOptions.alias; if (alias !== undefined && this.currentTypeFnMap.has(alias)) { this.currentTypeFnMap.delete(alias); } return this; } hasCustomValueMap(customValueMap) { let currentCustomValueMap = this.typeOptions.customValueMap; if (currentCustomValueMap === undefined) { currentCustomValueMap = new Map(); this.typeOptions.customValueMap = currentCustomValueMap; } if (customValueMap !== undefined) { if (currentCustomValueMap !== customValueMap) { currentCustomValueMap.clear(); } for (const [customKey, customValue] of customValueMap) { currentCustomValueMap.set(customKey, customValue); } } this.currentTypeState = new UnresolvedTypeState(this); return this; } hasCustomValue(customKey, customValue) { let customValueMap = this.typeOptions.customValueMap; if (customValueMap === undefined) { customValueMap = new Map(); this.typeOptions.customValueMap = customValueMap; } customValueMap.set(customKey, customValue); this.currentTypeState = new UnresolvedTypeState(this); return this; } extractCustomValue(customKey) { let customValue = this.typeState.customValueMap.get(customKey); if (customValue === undefined && customKey.customValueResolver !== undefined) { customValue = customKey.customValueResolver(); } return customValue; } hasCustomOptions(customOptions) { let customValueMap = this.typeOptions.customValueMap; if (customValueMap === undefined) { customValueMap = new Map(); this.typeOptions.customValueMap = customValueMap; } for (let i = 0; i < customOptions.length; i++) { customValueMap.set(customOptions[i][0], customOptions[i][1]); } this.currentTypeState = new UnresolvedTypeState(this); return this; } hasDefaultValue(defaultValue) { this.typeOptions.defaultValue = defaultValue; this.currentTypeState = new UnresolvedTypeState(this); return this; } hasSerializedDefaultValue(serializedDefaultValue) { this.typeOptions.serializedDefaultValue = serializedDefaultValue; this.currentTypeState = new UnresolvedTypeState(this); return this; } hasDeserializedDefaultValue(deserializedDefaultValue) { this.typeOptions.deserializedDefaultValue = deserializedDefaultValue; this.currentTypeState = new UnresolvedTypeState(this); return this; } hasBeforeSerializeCallback(beforeSerializeCallback) { this.typeOptions.beforeSerializeCallback = beforeSerializeCallback; this.currentTypeState = new UnresolvedTypeState(this); return this; } hasAfterDeserializeCallback(afterDeserializeCallback) { this.typeOptions.afterDeserializeCallback = afterDeserializeCallback; this.currentTypeState = new UnresolvedTypeState(this); return this; } hasDiscriminator(discriminator) { this.typeOptions.discriminator = discriminator; this.currentTypeState = new UnresolvedTypeState(this); return this; } hasDiscriminant(discriminant) { this.typeOptions.discriminant = discriminant; this.currentTypeState = new UnresolvedTypeState(this); return this; } hasFactory(factory) { this.typeOptions.factory = factory; this.currentTypeState = new UnresolvedTypeState(this); return this; } isInjectable(injectable = true) { this.typeOptions.injectable = injectable; this.currentTypeState = new UnresolvedTypeState(this); return this; } hasInjector(injector) { this.typeOptions.injector = injector; this.currentTypeState = new UnresolvedTypeState(this); return this; } hasLogger(logger) { this.typeOptions.logger = logger; this.currentTypeState = new UnresolvedTypeState(this); return this; } hasNamingConvention(namingConvention) { this.typeOptions.namingConvention = namingConvention; this.currentTypeState = new UnresolvedTypeState(this); return this; } shouldPreserveDiscriminator(preserveDiscriminator = true) { this.typeOptions.preserveDiscriminator = preserveDiscriminator; this.currentTypeState = new UnresolvedTypeState(this); return this; } hasReferenceHandler(referenceHandler) { this.typeOptions.referenceHandler = referenceHandler; this.currentTypeState = new UnresolvedTypeState(this); return this; } hasSerializer(serializer) { this.typeOptions.serializer = serializer; this.currentTypeState = new UnresolvedTypeState(this); return this; } shouldPreserveNull(preserveNull = true) { this.typeOptions.preserveNull = preserveNull; this.currentTypeState = new UnresolvedTypeState(this); return this; } shouldUseDefaultValue(useDefaultValue = true) { this.typeOptions.useDefaultValue = useDefaultValue; this.currentTypeState = new UnresolvedTypeState(this); return this; } shouldUseImplicitConversion(useImplicitConversion = true) { this.typeOptions.useImplicitConversion = useImplicitConversion; this.currentTypeState = new UnresolvedTypeState(this); return this; } hasPropertySorter(propertySorter) { this.typeOptions.propertySorter = propertySorter; this.currentTypeState = new UnresolvedTypeState(this); return this; } hasInjectSorter(injectSorter) { this.typeOptions.injectSorter = injectSorter; this.currentTypeState = new UnresolvedTypeState(this); return this; } hasParentTypeArguments(parentTypeArguments) { this.typeOptions.parentTypeArguments = parentTypeArguments; this.currentTypeState = new UnresolvedTypeState(this); return this; } configurePropertyMetadata(propertyName, propertyOptions) { let propertyOptionsMap = this.typeOptions.propertyOptionsMap; if (propertyOptionsMap === undefined) { propertyOptionsMap = new Map(); this.typeOptions.propertyOptionsMap = propertyOptionsMap; } let propertyMetadata = this.currentPropertyMetadataMap.get(propertyName); if (propertyMetadata === undefined) { propertyOptions = propertyOptions !== null && propertyOptions !== void 0 ? propertyOptions : {}; propertyMetadata = new PropertyMetadata(this.typeManager, this.currentTypeFnMap, this, propertyName, propertyOptions); this.currentPropertyMetadataMap.set(propertyName, propertyMetadata); propertyOptionsMap.set(propertyName, propertyOptions); this.currentTypeState = new UnresolvedTypeState(this); return propertyMetadata; } if (propertyOptions !== undefined) { propertyMetadata.configure(propertyOptions); } this.currentTypeState = new UnresolvedTypeState(this); return propertyMetadata; } configureInjectMetadata(injectIndex, injectOptions) { let injectOptionsMap = this.typeOptions.injectOptionsMap; if (injectOptionsMap === undefined) { injectOptionsMap = new Map(); this.typeOptions.injectOptionsMap = injectOptionsMap; } let injectMetadata = this.currentInjectMetadataMap.get(injectIndex); if (injectMetadata === undefined) { injectOptions = injectOptions !== null && injectOptions !== void 0 ? injectOptions : {}; injectMetadata = new InjectMetadata(this.typeManager, this.currentTypeFnMap, this, injectIndex, injectOptions); this.currentInjectMetadataMap.set(injectIndex, injectMetadata); injectOptionsMap.set(injectIndex, injectOptions); this.currentTypeState = new UnresolvedTypeState(this); return injectMetadata; } if (injectOptions !== undefined) { injectMetadata.configure(injectOptions); } this.currentTypeState = new UnresolvedTypeState(this); return injectMetadata; } hasPropertyMetadataMap(propertyOptionsMap) { const currentPropertyOptionsMap = this.clearPropertyOptionsMap(propertyOptionsMap); for (const [propertyName, propertyOptions] of propertyOptionsMap) { const propertyMetadata = new PropertyMetadata(this.typeManager, this.currentTypeFnMap, this, propertyName, propertyOptions); this.currentPropertyMetadataMap.set(propertyName, propertyMetadata); currentPropertyOptionsMap.set(propertyName, propertyOptions); } this.currentTypeState = new UnresolvedTypeState(this); return this; } clearPropertyOptionsMap(propertyOptionsMap) { let currentPropertyOptionsMap = this.typeOptions.propertyOptionsMap; if (currentPropertyOptionsMap === undefined) { currentPropertyOptionsMap = new Map(); this.typeOptions.propertyOptionsMap = currentPropertyOptionsMap; } if (currentPropertyOptionsMap !== propertyOptionsMap) { currentPropertyOptionsMap.clear(); this.currentPropertyMetadataMap.clear(); } return currentPropertyOptionsMap; } hasInjectMetadataMap(injectOptionsMap) { const currentInjectOptionsMap = this.clearInjectOptionsMap(injectOptionsMap); for (const [injectIndex, injectOptions] of injectOptionsMap) { const injectMetadata = new InjectMetadata(this.typeManager, this.currentTypeFnMap, this, injectIndex, injectOptions); this.currentInjectMetadataMap.set(injectIndex, injectMetadata); currentInjectOptionsMap.set(injectIndex, injectOptions); } this.currentTypeState = new UnresolvedTypeState(this); return this; } clearInjectOptionsMap(injectOptionsMap) { let currentInjectOptionsMap = this.typeOptions.injectOptionsMap; if (currentInjectOptionsMap === undefined) { currentInjectOptionsMap = new Map(); this.typeOptions.injectOptionsMap = currentInjectOptionsMap; } if (currentInjectOptionsMap !== injectOptionsMap) { currentInjectOptionsMap.clear(); this.currentInjectMetadataMap.clear(); } return currentInjectOptionsMap; } configure(typeOptions) { if (typeOptions.alias !== undefined) { this.hasAlias(typeOptions.alias); } if (typeOptions.customValueMap !== undefined) { this.hasCustomValueMap(typeOptions.customValueMap); } if (typeOptions.defaultValue !== undefined) { this.hasDefaultValue(typeOptions.defaultValue); } if (typeOptions.serializedDefaultValue !== undefined) { this.hasSerializedDefaultValue(typeOptions.serializedDefaultValue); } if (typeOptions.deserializedDefaultValue !== undefined) { this.hasDeserializedDefaultValue(typeOptions.deserializedDefaultValue); } if (typeOptions.beforeSerializeCallback !== undefined) { this.hasBeforeSerializeCallback(typeOptions.beforeSerializeCallback); } if (typeOptions.afterDeserializeCallback !== undefined) { this.hasAfterDeserializeCallback(typeOptions.afterDeserializeCallback); } if (typeOptions.discriminator !== undefined) { this.hasDiscriminator(typeOptions.discriminator); } if (typeOptions.discriminant !== undefined) { this.hasDiscriminant(typeOptions.discriminant); } if (typeOptions.factory !== undefined) { this.hasFactory(typeOptions.factory); } if (typeOptions.injectable !== undefined) { this.isInjectable(typeOptions.injectable); } if (typeOptions.injector !== undefined) { this.hasInjector(typeOptions.injector); } if (typeOptions.logger !== undefined) { this.hasLogger(typeOptions.logger); } if (typeOptions.namingConvention !== undefined) { this.hasNamingConvention(typeOptions.namingConvention); } if (typeOptions.preserveDiscriminator !== undefined) { this.shouldPreserveDiscriminator(typeOptions.preserveDiscriminator); } if (typeOptions.referenceHandler !== undefined) { this.hasReferenceHandler(typeOptions.referenceHandler); } if (typeOptions.serializer !== undefined) { this.hasSerializer(typeOptions.serializer); } if (typeOptions.preserveNull !== undefined) { this.shouldPreserveNull(typeOptions.preserveNull); } if (typeOptions.useDefaultValue !== undefined) { this.shouldUseDefaultValue(typeOptions.useDefaultValue); } if (typeOptions.useImplicitConversion !== undefined) { this.shouldUseImplicitConversion(typeOptions.useImplicitConversion); } if (typeOptions.propertyOptionsMap !== undefined) { this.hasPropertyMetadataMap(typeOptions.propertyOptionsMap); } if (typeOptions.injectOptionsMap !== undefined) { this.hasInjectMetadataMap(typeOptions.injectOptionsMap); } if (typeOptions.propertySorter !== undefined) { this.hasPropertySorter(typeOptions.propertySorter); } if (typeOptions.injectSorter !== undefined) { this.hasInjectSorter(typeOptions.injectSorter); } if (typeOptions.parentTypeArguments !== undefined) { this.hasParentTypeArguments(typeOptions.parentTypeArguments); } return this; } } //# sourceMappingURL=type-metadata.js.map