You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lib/src/support/bus/serial/decorators.ts

22 lines
1.0 KiB

import {ContainerBlueprint, Instantiable, isInstantiableOf} from '../../../di'
import {JSONState, logIfDebugging} from '../../../util'
import {BaseSerializer} from './BaseSerializer'
import {Serialization} from './Serialization'
import {Serializer} from '../types'
/**
* Register a class as an object serializer with the Serialization service.
* @constructor
*/
export const ObjectSerializer = (): <TFunction extends Instantiable<Serializer<unknown, JSONState>>>(target: TFunction) => TFunction | void => {
return (target: Instantiable<Serializer<unknown, JSONState>>) => {
if ( isInstantiableOf(target, BaseSerializer) ) {
logIfDebugging('extollo.bus.serial.decorators', 'Registering ObjectSerializer blueprint:', target)
ContainerBlueprint.getContainerBlueprint()
.onResolve<Serialization>(Serialization, serial => serial.register(target))
} else {
logIfDebugging('extollo.bus.serial.decorators', 'Skipping ObjectSerializer blueprint:', target)
}
}
}