@automapper/classes
Advanced tools
Comparing version 4.1.0 to 4.2.0
{ | ||
"name": "@automapper/classes/experimental/transformer-plugin", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"sideEffects": false, | ||
@@ -29,6 +29,6 @@ "publishConfig": { | ||
"peerDependencies": { | ||
"@automapper/classes": "4.1.0", | ||
"@automapper/core": "4.1.0", | ||
"@automapper/types": "4.1.0" | ||
"@automapper/classes": "4.2.0", | ||
"@automapper/core": "4.2.0", | ||
"@automapper/types": "4.2.0" | ||
} | ||
} |
@@ -51,5 +51,3 @@ "use strict"; | ||
} | ||
return context.factory.updateSourceFile(_sourceFile, [ | ||
...ModelVisitor.importsMap.values(), | ||
].concat((_sourceFile.statements || []).filter((statement) => statement.kind !== tsserverlibrary_1.SyntaxKind.ImportDeclaration)), _sourceFile.isDeclarationFile, _sourceFile.referencedFiles, _sourceFile.typeReferenceDirectives, _sourceFile.hasNoDefaultLib, _sourceFile.libReferenceDirectives); | ||
return context.factory.updateSourceFile(_sourceFile, [...ModelVisitor.importsMap.values()].concat((_sourceFile.statements || []).filter((statement) => statement.kind !== tsserverlibrary_1.SyntaxKind.ImportDeclaration)), _sourceFile.isDeclarationFile, _sourceFile.referencedFiles, _sourceFile.typeReferenceDirectives, _sourceFile.hasNoDefaultLib, _sourceFile.libReferenceDirectives); | ||
} | ||
@@ -56,0 +54,0 @@ static addMetadataFactory(classNode, factory) { |
{ | ||
"name": "@automapper/classes/mapped-types", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"sideEffects": false, | ||
@@ -29,6 +29,6 @@ "publishConfig": { | ||
"peerDependencies": { | ||
"@automapper/classes": "4.1.0", | ||
"@automapper/core": "4.1.0", | ||
"@automapper/types": "4.1.0" | ||
"@automapper/classes": "4.2.0", | ||
"@automapper/core": "4.2.0", | ||
"@automapper/types": "4.2.0" | ||
} | ||
} |
{ | ||
"name": "@automapper/classes", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"peerDependencies": { | ||
"reflect-metadata": "~0.1.13", | ||
"@automapper/core": "4.1.0", | ||
"@automapper/types": "4.1.0" | ||
"@automapper/core": "4.2.0", | ||
"@automapper/types": "4.2.0" | ||
}, | ||
@@ -9,0 +9,0 @@ "sideEffects": false, |
@@ -42,3 +42,3 @@ "use strict"; | ||
*/ | ||
const [destinationInstance, destinationNestedConstructible,] = this.instantiate(destination); | ||
const [destinationInstance, destinationNestedConstructible] = this.instantiate(destination); | ||
const [sourceInstance, sourceNestedConstructible] = this.instantiate(source); | ||
@@ -45,0 +45,0 @@ // Get a hold of the prototype of Source (in case of inheritance with extends keyword) |
@@ -7,3 +7,3 @@ "use strict"; | ||
function AutoMap(typeFnOrConfig, depth = 0) { | ||
const { isGetterOnly, typeFn, depth: _depth = 0 } = getConfig(typeFnOrConfig, depth); | ||
const { isGetterOnly, typeFn, depth: _depth = 0, } = getConfig(typeFnOrConfig, depth); | ||
return (target, propertyKey) => { | ||
@@ -10,0 +10,0 @@ const newMetadata = { depth: _depth }; |
@@ -13,8 +13,8 @@ import type { Constructible } from '../types'; | ||
private recursiveCountStorage; | ||
getDepthAndCount(parent: Constructible, member: string): [depth?: number, count?: number]; | ||
getDepth(parent: Constructible, member: string): number | undefined; | ||
getCount(parent: Constructible, member: string): number | undefined; | ||
setDepth(parent: Constructible, member: string, depth: number): void; | ||
setCount(parent: Constructible, member: string, count: number): void; | ||
resetCount(parent: Constructible, member: string): void; | ||
getDepthAndCount(parent: Constructible, member: string[]): [depth?: number, count?: number]; | ||
getDepth(parent: Constructible, member: string[]): number | undefined; | ||
getCount(parent: Constructible, member: string[]): number | undefined; | ||
setDepth(parent: Constructible, member: string[], depth: number): void; | ||
setCount(parent: Constructible, member: string[], count: number): void; | ||
resetCount(parent: Constructible, member: string[]): void; | ||
resetAllCount(parent: Constructible): void; | ||
@@ -21,0 +21,0 @@ dispose(): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ClassInstanceStorage = void 0; | ||
const DATA_SYMBOL = Symbol('map-data'); | ||
/** | ||
@@ -47,11 +48,11 @@ * Internal ClassInstanceStorage | ||
const parentVal = storage.get(parent); | ||
return parentVal ? parentVal.get(member) : undefined; | ||
return parentVal ? arrayMapGet(parentVal, member) : undefined; | ||
} | ||
static setInternal(storage, parent, member, value) { | ||
if (!storage.has(parent)) { | ||
storage.set(parent, new Map().set(member, value)); | ||
storage.set(parent, arrayMapSet(new Map(), member, value)); | ||
return; | ||
} | ||
if (!this.hasInternal(storage, parent, member)) { | ||
storage.get(parent).set(member, value); | ||
arrayMapSet(storage.get(parent), member, value); | ||
} | ||
@@ -61,6 +62,43 @@ } | ||
const parentVal = storage.get(parent); | ||
return parentVal ? parentVal.has(member) : false; | ||
return parentVal ? arrayMapHas(parentVal, member) : false; | ||
} | ||
} | ||
exports.ClassInstanceStorage = ClassInstanceStorage; | ||
function arrayMapSet(root, path, value) { | ||
let map = root; | ||
for (const item of path) { | ||
let nextMap = map.get(item); | ||
if (!nextMap) { | ||
// Create next map if none exists | ||
nextMap = new Map(); | ||
map.set(item, nextMap); | ||
} | ||
map = nextMap; | ||
} | ||
// Reached end of path. Set the data symbol to the given value | ||
map.set(DATA_SYMBOL, value); | ||
return root; | ||
} | ||
function arrayMapHas(root, path) { | ||
let map = root; | ||
for (const item of path) { | ||
const nextMap = map.get(item); | ||
if (nextMap) { | ||
map = nextMap; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
return map.has(DATA_SYMBOL); | ||
} | ||
function arrayMapGet(root, path) { | ||
let map = root; | ||
for (const item of path) { | ||
map = map.get(item); | ||
if (!map) | ||
return undefined; | ||
} | ||
return map.get(DATA_SYMBOL); | ||
} | ||
//# sourceMappingURL=class-instance.storage.js.map |
@@ -14,3 +14,3 @@ import type { Metadata, MetadataStorage } from '@automapper/types'; | ||
getMetadata(model: Constructible): Array<Metadata<Constructible>>; | ||
getMetadataForKey(model: Constructible, key: string): Metadata<Constructible> | undefined; | ||
getMetadataForKey(model: Constructible, key: string[]): Metadata<Constructible> | undefined; | ||
addMetadata(model: Constructible, metadata: Metadata<Constructible>): void; | ||
@@ -17,0 +17,0 @@ has(metaKey: Constructible): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ClassMetadataStorage = void 0; | ||
const core_1 = require("@automapper/core"); | ||
/** | ||
@@ -19,5 +20,4 @@ * Internal ClassMetadataStorage | ||
const metadataList = (_a = this.storage.get(model)) !== null && _a !== void 0 ? _a : []; | ||
let i = metadataList.length; | ||
// empty metadata | ||
if (!i) { | ||
if (!metadataList.length) { | ||
// try to get the metadata on the prototype of the class | ||
@@ -27,6 +27,6 @@ return model.name ? this.getMetadata(Object.getPrototypeOf(model)) : []; | ||
const resultMetadataList = []; | ||
while (i--) { | ||
for (let i = 0; i < metadataList.length; i++) { | ||
const metadata = metadataList[i]; | ||
// skip existing | ||
if (resultMetadataList.some(([metaKey]) => metaKey === metadata[0])) { | ||
if (resultMetadataList.some(([metaKey]) => core_1.isSamePath(metaKey, metadata[0]))) { | ||
continue; | ||
@@ -39,3 +39,3 @@ } | ||
getMetadataForKey(model, key) { | ||
return this.getMetadata(model).find(([metaKey]) => metaKey === key); | ||
return this.getMetadata(model).find(([metaKey]) => core_1.isSamePath(metaKey, key)); | ||
} | ||
@@ -51,3 +51,3 @@ addMetadata(model, metadata) { | ||
// if already exists, break | ||
if (merged.some(([existKey]) => existKey === metadata[0])) { | ||
if (merged.some(([existKey]) => core_1.isSamePath(existKey, metadata[0]))) { | ||
return; | ||
@@ -54,0 +54,0 @@ } |
@@ -18,5 +18,9 @@ "use strict"; | ||
for (const [propertyKey, { typeFn, depth, isGetterOnly },] of metadataList) { | ||
metadataStorage.addMetadata(model, [propertyKey, typeFn, isGetterOnly]); | ||
metadataStorage.addMetadata(model, [ | ||
[propertyKey], | ||
typeFn, | ||
isGetterOnly, | ||
]); | ||
if (depth != null) { | ||
instanceStorage.setDepth(model, propertyKey, depth); | ||
instanceStorage.setDepth(model, [propertyKey], depth); | ||
} | ||
@@ -23,0 +27,0 @@ } |
@@ -26,5 +26,4 @@ "use strict"; | ||
const nestedConstructible = []; | ||
let i = metadata.length; | ||
// reversed loop | ||
while (i--) { | ||
for (let i = 0; i < metadata.length; i++) { | ||
// destructure | ||
@@ -37,3 +36,3 @@ const [key, meta, isGetterOnly] = metadata[i]; | ||
// get the value at the current key | ||
const valueAtKey = instance[key]; | ||
const valueAtKey = core_1.get(instance, key); | ||
// call the meta fn to get the metaResult of the current key | ||
@@ -44,5 +43,4 @@ const metaResult = meta(); | ||
if (core_1.isPrimitiveConstructor(metaResult) || metaResult === null) { | ||
instance[key] = core_1.isDefined(valueAtKey, true) | ||
? valueAtKey | ||
: undefined; | ||
const value = core_1.isDefined(valueAtKey, true) ? valueAtKey : undefined; | ||
core_1.setMutate(instance, key, value); | ||
continue; | ||
@@ -52,5 +50,6 @@ } | ||
if (core_1.isDateConstructor(metaResult)) { | ||
instance[key] = core_1.isDefined(valueAtKey) | ||
const value = core_1.isDefined(valueAtKey) | ||
? new Date(valueAtKey) | ||
: undefined; | ||
core_1.setMutate(instance, key, value); | ||
continue; | ||
@@ -64,6 +63,7 @@ } | ||
// loop through each value and recursively call instantiate with each value | ||
instance[key] = valueAtKey.map((val) => { | ||
const value = valueAtKey.map((val) => { | ||
const [instantiateResultItem] = instantiate(instanceStorage, metadataStorage, metaResult, val); | ||
return instantiateResultItem; | ||
}); | ||
core_1.setMutate(instance, key, value); | ||
continue; | ||
@@ -75,3 +75,3 @@ } | ||
const [definedInstantiateResult] = instantiate(instanceStorage, metadataStorage, metaResult, valueAtKey); | ||
instance[key] = definedInstantiateResult; | ||
core_1.setMutate(instance, key, definedInstantiateResult); | ||
continue; | ||
@@ -82,3 +82,3 @@ } | ||
if (core_1.isDefined(defaultValue)) { | ||
instance[key] = valueAtKey; | ||
core_1.setMutate(instance, key, valueAtKey); | ||
continue; | ||
@@ -91,3 +91,3 @@ } | ||
if (depth === 0) { | ||
instance[key] = new metaResult(); | ||
core_1.setMutate(instance, key, new metaResult()); | ||
continue; | ||
@@ -99,3 +99,3 @@ } | ||
instanceStorage.resetCount(model, key); | ||
instance[key] = new metaResult(); | ||
core_1.setMutate(instance, key, new metaResult()); | ||
continue; | ||
@@ -106,3 +106,3 @@ } | ||
const [instantiateResult] = instantiate(instanceStorage, metadataStorage, metaResult); | ||
instance[key] = instantiateResult; | ||
core_1.setMutate(instance, key, instantiateResult); | ||
} | ||
@@ -109,0 +109,0 @@ // after all, resetAllCount on the current model |
@@ -1,1 +0,1 @@ | ||
export declare function isDestinationPathOnSource(sourceProto: Record<string, unknown>): (sourceObj: any, sourcePath: string) => boolean; | ||
export declare function isDestinationPathOnSource(sourceProto: Record<string, unknown>): (sourceObj: any, sourcePath: string[]) => boolean; |
@@ -6,5 +6,6 @@ "use strict"; | ||
return (sourceObj, sourcePath) => { | ||
return !(!sourceObj.hasOwnProperty(sourcePath) && | ||
!sourceProto.hasOwnProperty(sourcePath) && | ||
!Object.getPrototypeOf(sourceObj).hasOwnProperty(sourcePath)); | ||
return (sourcePath.length === 1 && | ||
!(!sourceObj.hasOwnProperty(sourcePath[0]) && | ||
!sourceProto.hasOwnProperty(sourcePath[0]) && | ||
!Object.getPrototypeOf(sourceObj).hasOwnProperty(sourcePath[0]))); | ||
}; | ||
@@ -11,0 +12,0 @@ } |
@@ -1,1 +0,1 @@ | ||
export declare function isMultipartSourcePathsInSource(dottedSourcePaths: string[], sourceInstance: Record<string, unknown>): boolean; | ||
export declare function isMultipartSourcePathsInSource(sourcePaths: string[], sourceInstance: Record<string, unknown>): boolean; |
@@ -5,10 +5,10 @@ "use strict"; | ||
const is_class_util_1 = require("./is-class.util"); | ||
function isMultipartSourcePathsInSource(dottedSourcePaths, sourceInstance) { | ||
return !(dottedSourcePaths.length > 1 && | ||
(!sourceInstance.hasOwnProperty(dottedSourcePaths[0]) || | ||
(sourceInstance[dottedSourcePaths[0]] && | ||
function isMultipartSourcePathsInSource(sourcePaths, sourceInstance) { | ||
return !(sourcePaths.length > 1 && | ||
(!sourceInstance.hasOwnProperty(sourcePaths[0]) || | ||
(sourceInstance[sourcePaths[0]] && | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
is_class_util_1.isClass(sourceInstance[dottedSourcePaths[0]])))); | ||
is_class_util_1.isClass(sourceInstance[sourcePaths[0]])))); | ||
} | ||
exports.isMultipartSourcePathsInSource = isMultipartSourcePathsInSource; | ||
//# sourceMappingURL=is-multipart-source-paths-in-source.util.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
119558
1425