Serializable

Type parameters

T: SuperConstructor

T: SuperConstructor

T: SuperConstructor

T: SuperConstructor

Hierarchy

Implements

Index

Constructors

Properties

Methods

Constructors

constructor

+ new Serializable(props?: Props): Serializable

Overrides Struct.constructor

Creates an instance of Serializable. Creates an instance of Serializable.

remarks Since were dealing with special cases, mixins and limits of TypeScript, we use of "invoking multiple base constructors" from polytype to pass props to Struct's constructor: https://www.npmjs.com/package/polytype#invoking-multiple-base-constructors

remarks Since were dealing with special cases, mixins and limits of TypeScript, we use of "invoking multiple base constructors" from polytype to pass props to Struct's constructor: https://www.npmjs.com/package/polytype#invoking-multiple-base-constructors

Parameters:

NameTypeDescription
props?PropsProperties of the type required for construction.

Returns: Serializable

Properties

Optional schemaVersion

schemaVersion? : number

Overrides VersionableMixin.schemaVersion

Methods

equals

equals(other: any): boolean

Implementation of Ejsonable

Inherited from DefinableMixin.equals

Overrides CreateEmployee.equals

Parameters:

NameType
otherany

Returns: boolean


getActions

getActions(): Actions

Implementation of Hookable

Inherited from HookableMixin.getActions

Overrides CreateEmployee.getActions

Returns: Actions


getHook

getHook(action: string, id: string): Hook | undefined

Implementation of Hookable

Inherited from HookableMixin.getHook

Overrides CreateEmployee.getHook

Parameters:

NameType
actionstring
idstring

Returns: Hook | undefined


getHookOrThrow

getHookOrThrow(action: string, id: string): Hook

Implementation of Hookable

Inherited from HookableMixin.getHookOrThrow

Overrides CreateEmployee.getHookOrThrow

Parameters:

NameType
actionstring
idstring

Returns: Hook


getHooks

getHooks(action: string): Mappings

Implementation of Hookable

Inherited from HookableMixin.getHooks

Overrides CreateEmployee.getHooks

Parameters:

NameType
actionstring

Returns: Mappings


getLegacyTransformer

getLegacyTransformer(schemaVersion: number): Hook

Implementation of Ejsonable

Inherited from VersionableMixin.getLegacyTransformer

Overrides CreateEmployee.getLegacyTransformer

Parameters:

NameType
schemaVersionnumber

Returns: Hook


getLegacyTransformers

getLegacyTransformers(): LegacyTransformers

Implementation of Ejsonable

Inherited from VersionableMixin.getLegacyTransformers

Overrides CreateEmployee.getLegacyTransformers

Returns: LegacyTransformers


getPropTypes

getPropTypes(): Props

Implementation of Ejsonable

Inherited from DefinableMixin.getPropTypes

Overrides CreateEmployee.getPropTypes

Returns: Props


getPropertyInitializers

getPropertyInitializers(): Props

Implementation of Ejsonable

Inherited from DefinableMixin.getPropertyInitializers

Overrides CreateEmployee.getPropertyInitializers

Returns: Props


getSchemaVersion

getSchemaVersion(): number | undefined

Implementation of Ejsonable

Inherited from VersionableMixin.getSchemaVersion

Overrides CreateEmployee.getSchemaVersion

Returns: number | undefined


getTypeName

getTypeName(): TypeName

Implementation of Ejsonable

Inherited from SerializableMixin.getTypeName

Overrides CreateEmployee.getTypeName

Returns: TypeName


hasAction

hasAction(action: string): boolean

Implementation of Hookable

Inherited from HookableMixin.hasAction

Overrides CreateEmployee.hasAction

Parameters:

NameType
actionstring

Returns: boolean


hasHook

hasHook(action: string, id: string): boolean

Implementation of Hookable

Inherited from HookableMixin.hasHook

Overrides CreateEmployee.hasHook

Parameters:

NameType
actionstring
idstring

Returns: boolean


hasLegacyTransformer

hasLegacyTransformer(schemaVersion: number): boolean

Implementation of Ejsonable

Inherited from VersionableMixin.hasLegacyTransformer

Overrides CreateEmployee.hasLegacyTransformer

Parameters:

NameType
schemaVersionnumber

Returns: boolean


in

inT›(listName: string): List‹T›

Returns List for Serializable array.

throws {InvalidListError} Thrown if the provided container name does not point to list of supported Serializables.

example

@define('Employee')
class Employee extends Serializable {
id: string;
}
@define('Company')
class Company extends Serializable {
employees: Employee[];
}
const employees = [
new Employee({ id: 'first' }),
new Employee({ id: 'second' }),
];
const company = new Company({ employees });
expect(company.in<Employee>('employees')).to.be.instanceof(List);
expect(company.in<Employee>('employees')).to.have.length(2);
expect(company.in<Employee>('employees')).to.have.members(employees);

Type parameters:

T

Parameters:

NameTypeDescription
listNamestringProperty name of the Serializable list on this instance.

Returns: List‹T›

Instance of List implementation.


overrideHook

overrideHook(action: string, id: string, hook: Hook): void

Implementation of Hookable

Inherited from HookableMixin.overrideHook

Overrides CreateEmployee.overrideHook

Parameters:

NameType
actionstring
idstring
hookHook

Returns: void


overrideLegacyTransformer

overrideLegacyTransformer(schemaVersion: number, transformer: Hook): void

Implementation of Ejsonable

Inherited from VersionableMixin.overrideLegacyTransformer

Overrides CreateEmployee.overrideLegacyTransformer

Parameters:

NameType
schemaVersionnumber
transformerHook

Returns: void


processSerializableList

processSerializableList(props?: Props): Props

Processes properties for Serializable by wrapping each serializable list property with List .

Parameters:

NameTypeDescription
props?PropsProperties of the type required for construction.

Returns: Props

Processed properties with any registered onConstruction hooks and validates them against prop types.


registerHook

registerHook(action: string, id: string, hook: Hook, shouldOverride?: boolean): void

Implementation of Hookable

Inherited from HookableMixin.registerHook

Overrides CreateEmployee.registerHook

Parameters:

NameType
actionstring
idstring
hookHook
shouldOverride?boolean

Returns: void


registerLegacyTransformer

registerLegacyTransformer(schemaVersion: number, transformer: Hook, shouldOverride?: boolean): void

Implementation of Ejsonable

Inherited from VersionableMixin.registerLegacyTransformer

Overrides CreateEmployee.registerLegacyTransformer

Parameters:

NameType
schemaVersionnumber
transformerHook
shouldOverride?boolean

Returns: void


removeHook

removeHook(action: string, id: string): void

Implementation of Hookable

Inherited from HookableMixin.removeHook

Overrides CreateEmployee.removeHook

Parameters:

NameType
actionstring
idstring

Returns: void


toJSONValue

toJSONValue(): Record‹string, any›

Implementation of Ejsonable

Inherited from SerializableMixin.toJSONValue

Overrides CreateEmployee.toJSONValue

Returns: Record‹string, any›


toPlainObject

toPlainObject(): Props

Implementation of Ejsonable

Inherited from DefinableMixin.toPlainObject

Overrides CreateEmployee.toPlainObject

Returns: Props


toString

toString(): TypeName

Implementation of Ejsonable

Inherited from SerializableMixin.toString

Overrides CreateEmployee.toString

Returns: TypeName


transformLegacyProps

transformLegacyProps(props: Props): Props

Implementation of Ejsonable

Inherited from VersionableMixin.transformLegacyProps

Overrides CreateEmployee.transformLegacyProps

Parameters:

NameType
propsProps

Returns: Props


typeName

typeName(): TypeName

Implementation of Ejsonable

Inherited from EjsonableMixin.typeName

Overrides CreateEmployee.typeName

Returns: TypeName


validateProps

validateProps(props: Record‹string | number | symbol, any› | undefined, propTypes: PropTypes, isStrict?: boolean): boolean

Inherited from DefinableMixin.validateProps

Overrides CreateEmployee.validateProps

Parameters:

NameType
propsRecord‹string | number | symbol, any› | undefined
propTypesPropTypes
isStrict?boolean

Returns: boolean


Static disableSerializableLists

disableSerializableLists(): void

Disables conversion of serializable lists to List instances.

Returns: void


Static enableSerializableLists

enableSerializableLists(): void

Enables conversion of serializable lists to List instances.

remarks Since using mixins with polytype on extendable classes like: Serializable, Entity, EventSourceable, ValueObject will result in loosing all registered hooks on metadata

  • this ensures that hook can be easily re-applied.

Returns: void


Static from

from(...sources: Record‹string, any›[]): any

Create an Serializable from multiple property sources. Have similar api like Object.assign.

throws {ValidationError} Thrown if the passed properties does not match serializeble's property types.

example

const props1 = {
firstName: 'Jane',
age: 28,
};
const props2 = {
lastName: 'Doe',
favoriteColor: 'black',
};
const props3 = {
hobby: 'martial arts',
};
const person = Person.from(props1, props2, props3);
expect(person).to.be.instanceof(Person);
expect(person).to.be.eql({
firstName: 'Jane',
lastName: 'Doe',
});

Parameters:

NameTypeDescription
...sourcesRecord‹string, any›[]One or more source of properties.

Returns: any

New instance of Serializable with assigned properties.


Static getPropTypes

getPropTypes(): Props

Inherited from DefinableMixin.getPropTypes

Overrides CreateEmployee.getPropTypes

Returns: Props


Static getPropertyInitializers

getPropertyInitializers(): Props

Inherited from DefinableMixin.getPropertyInitializers

Overrides CreateEmployee.getPropertyInitializers

Returns: Props


Static getTypeName

getTypeName(): TypeName

Inherited from SerializableMixin.getTypeName

Overrides CreateEmployee.getTypeName

Returns: TypeName


Static toString

toString(): TypeName

Inherited from SerializableMixin.toString

Overrides CreateEmployee.toString

Returns: TypeName


Static typeName

typeName(): TypeName

Inherited from EjsonableMixin.typeName

Overrides CreateEmployee.typeName

Returns: TypeName