import { Type } from './Type' ; import { Utils } from '../utils' ; import type { EntityProperty } from '../typings' ; import type { Platform } from '../platforms' ; import { ValidationError } from '../errors' ; export class ArrayType < T extends string | number = string > extends Type < T [ ] | null , string | null > { constructor ( private readonly hydrate = i => i as T ) { super ( ) ; } convertToDatabaseValue ( value , platform , fromQuery ? ) { if ( ! value ) { return value as null ; } if ( Array . isArray ( value ) ) { return platform . marshallArray ( value as string [ ] ) ; } if ( fromQuery ) { return value ; } throw ValidationError . invalidType ( ArrayType , value , 'JS' ) ; } convertToJSValue ( value , platform ) { if ( ! Utils . isDefined ( value , true ) ) { return value as null ; } if ( Utils . isString ( value ) ) { value = platform . unmarshallArray ( value ) as T [ ] ; } return value . map ( i => this . hydrate ( i as string ) ) ; } compareAsType ( ) { return 'string[]' ; } toJSON ( value ) { return value ; } getColumnType ( prop , platform ) { return platform . getArrayDeclarationSQL ( ) ; } }