import { EntitySchemaDatatype } from "../schema/entity-schema-datatype" ; import { EntitySchemaField } from "../schema/entity-schema-field" ; import { EntitySchemaService } from "../schema/entity-schema.service" ; import { EntityConstructor } from "../model/entity" ; /**
 * Datatype for the EntitySchemaService transforming values of complex objects recursively.
 *
 * (De)serialize instances of any class recognizing the normal @DatabaseField() annotations within that referenced class.
 * This is useful if your Entity type is complex and has properties that are instances of other classes
 * rather just basic value types like string or number.
 * You can then annotate some properties of that referenced class so they will be saved to the database while ignoring other properties.
 * The referenced class instance will be saved embedded into the entity's object and not as an own "stand-alone" entity.
 *
 * see the unit tests in entity-schema.service.spec.ts for an example
 *
 * Requires the class constructor as extension field in the schema field annotation:
 *
 * `@DatabaseField({ dataType: 'schema-embed', additional: MyClass })`
 */ export const schemaEmbedEntitySchemaDatatype = { name : "schema-embed" , transformToDatabaseFormat : ( value , schemaField , schemaService ) => { return schemaService . transformEntityToDatabaseFormat ( value , schemaField . additional . schema ) ; } , transformToObjectFormat : ( value , schemaField , schemaService ) => { const instance = new ( schemaField . additional as EntityConstructor < any > ) ( ) ; schemaService . loadDataIntoEntity ( instance , value ) ; return instance ; } , } ;