From 0eafe059f236b748b00fa30845c697d41dec15d5 Mon Sep 17 00:00:00 2001 From: Chau Tran Date: Wed, 10 Nov 2021 15:10:28 -0600 Subject: [PATCH] feat(pojos): support File as a metadata constructor --- packages/pojos/src/lib/create-metadata-map.ts | 4 ++++ packages/pojos/src/lib/utils/instantiate.util.ts | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/packages/pojos/src/lib/create-metadata-map.ts b/packages/pojos/src/lib/create-metadata-map.ts index 6e662a93c..853bff0c5 100644 --- a/packages/pojos/src/lib/create-metadata-map.ts +++ b/packages/pojos/src/lib/create-metadata-map.ts @@ -21,6 +21,7 @@ export function createMetadataMap = any>( | DateConstructor | NumberConstructor | BooleanConstructor + | typeof File.prototype.constructor | string | null; } @@ -34,6 +35,7 @@ export function createMetadataMap = any>( | DateConstructor | NumberConstructor | BooleanConstructor + | typeof File.prototype.constructor | string | null | false; @@ -49,6 +51,7 @@ export function createMetadataMap = any>( | DateConstructor | NumberConstructor | BooleanConstructor + | typeof File.prototype.constructor | string | null; }, @@ -58,6 +61,7 @@ export function createMetadataMap = any>( | DateConstructor | NumberConstructor | BooleanConstructor + | typeof File.prototype.constructor | string | null | false; diff --git a/packages/pojos/src/lib/utils/instantiate.util.ts b/packages/pojos/src/lib/utils/instantiate.util.ts index 16d234bc0..c339112c4 100644 --- a/packages/pojos/src/lib/utils/instantiate.util.ts +++ b/packages/pojos/src/lib/utils/instantiate.util.ts @@ -4,6 +4,7 @@ import { isDateConstructor, isDefined, isEmpty, + isFileConstructor, isPrimitiveConstructor, setMutate, } from '@automapper/core'; @@ -34,6 +35,7 @@ export function instantiate>( setMutate(obj as Record, key, value); continue; } + if (isDateConstructor(metaResult)) { const value = isDefined(valueAtKey) ? new Date(valueAtKey as number) @@ -42,6 +44,12 @@ export function instantiate>( continue; } + if (isFileConstructor(metaResult)) { + const value = isDefined(valueAtKey) ? valueAtKey : undefined; + setMutate(obj as Record, key, value); + continue; + } + if (typeof metaResult !== 'string') { continue; }