Entity

Type parameters

T: SuperConstructor

T: SuperConstructor

T: SuperConstructor

T: SuperConstructor

Hierarchy

Implements

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

+ new Entity(props: Props): Entity

Overrides Serializable.constructor

Creates an instance of Entity. Creates an instance of Entity.

Parameters:

NameTypeDescription
propsPropsProperties of the type required for construction.

Returns: Entity

Properties

id

id: string | Guid


Optional schemaVersion

schemaVersion? : number

Overrides Serializable.schemaVersion


state

state: State

Implementation of Entity.state

Overrides StatefulMixin.state


status

status: Status

Implementation of Entity.status

Overrides StatusfulMixin.status

Accessors

ableTo

get ableTo(): this

Method to enforce TypeScript compliance with Asserter and AbilityAssertion.

Returns: this


can

get can(): any

Evaluates if action can be taken on Entity. Prior to invocation of any non-assertion methods snapshot of current state is done - that will be automatically rollbacked after method execution. Proxified instance wraps the executed method and ensures that boolean is returned as result indicating if method indeed can be executed(true) - or fail with thrown error(false)

Returns: any

Proxified instance of Entity.


ensure

get ensure(): this & object

Exposes the ensure BDD assertion for Entity.

remarks The entity.ensure getter-method will return a Proxified instance of the Entity. This proxified instance listens to all get methods and catches the requested method name.

If the requested get method/property name matches exactly or partially one of registered apis on Asserter(like: is) it returns associated object assigned to that assertion. Like for example - for registered AbilityAssertion, calling entity with:

entity.ensure.is

Will result with returned object:

{ableTo: ...}

That can be called like:

entity.ensure.is.ableTo.doAction(...)

Same rules of behavior will apply to other assertions like: StatefulAssertion, StatusfulAssertion.

However, since we want to enable an expressive apis on Entities - we allow users to defined their own apis. By calling:

entity.ensure.myMethod()

A backup of the entity state will be created that will be rollbacked directly * after the invocation of the method(and that will happen automatically) (it behaves exactly like ensure.is.ableTo assertion from AbilityAssertion)

This allows for evaluation of state change on command handlers directly without writing unnecessary duplicated code that would ensure that state indeed can be changed(first method) and then actually change it(second method).

Returns: this & object

Proxified instance of Entity.


is

get is(): this & object

Method to enforce TypeScript compliance with Asserter and AbilityAssertion.

Returns: this & object

Methods

[ROLLBACK_STATE_METHOD_KEY]

[ROLLBACK_STATE_METHOD_KEY](): void

Implementation of Entity

Rollbacks entity to previous state.

throws {SavedStateNotFoundError} Thrown if rollback is done on Entity without prior saved state.

Returns: void


[SAVE_STATE_METHOD_KEY]

[SAVE_STATE_METHOD_KEY](): void

Implementation of Entity

Saves current entity state.

Returns: void


equals

equals(otherEntity: Entity): boolean

Overrides DefinableMixin.equals

Evaluates if one entity is equal to other by its constructor and identifier.

Parameters:

NameTypeDescription
otherEntityEntityOther Entity instance.

Returns: boolean

Returns true if both Entities instances are equal, else false.


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


getId

getId(): string | Guid

Implementation of Entity

Returns identifier for Entity.

Returns: string | Guid

Entities identifier as Guid instance or string.


getLegacyTransformer

getLegacyTransformer(schemaVersion: number): Hook

Implementation of Entity

Inherited from VersionableMixin.getLegacyTransformer

Overrides CreateEmployee.getLegacyTransformer

Parameters:

NameType
schemaVersionnumber

Returns: Hook


getLegacyTransformers

getLegacyTransformers(): LegacyTransformers

Implementation of Entity

Inherited from VersionableMixin.getLegacyTransformers

Overrides CreateEmployee.getLegacyTransformers

Returns: LegacyTransformers


getPropTypes

getPropTypes(): Props

Implementation of Entity

Inherited from DefinableMixin.getPropTypes

Overrides CreateEmployee.getPropTypes

Returns: Props


getPropertyInitializers

getPropertyInitializers(): Props

Implementation of Entity

Inherited from DefinableMixin.getPropertyInitializers

Overrides CreateEmployee.getPropertyInitializers

Returns: Props


getSchemaVersion

getSchemaVersion(): number | undefined

Implementation of Entity

Inherited from VersionableMixin.getSchemaVersion

Overrides CreateEmployee.getSchemaVersion

Returns: number | undefined


getSelectableStates

getSelectableStates(): Record‹string, State

Implementation of Entity

Inherited from StatefulMixin.getSelectableStates

Overrides Task.getSelectableStates

Returns: Record‹string, State


getSelectableStatuses

getSelectableStatuses(): Record‹string, Status

Implementation of Entity

Inherited from StatusfulMixin.getSelectableStatuses

Overrides Task.getSelectableStatuses

Returns: Record‹string, Status


getState

getState(): State

Implementation of Entity

Inherited from StatefulMixin.getState

Overrides Task.getState

Returns: State


getStatus

getStatus(): Status

Implementation of Entity

Inherited from StatusfulMixin.getStatus

Overrides Task.getStatus

Returns: Status


getTypeName

getTypeName(): TypeName

Implementation of Entity

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 Entity

Inherited from VersionableMixin.hasLegacyTransformer

Overrides CreateEmployee.hasLegacyTransformer

Parameters:

NameType
schemaVersionnumber

Returns: boolean


hasState

hasState(): boolean

Implementation of Entity

Inherited from StatefulMixin.hasState

Overrides Task.hasState

Returns: boolean


hasStatus

hasStatus(): boolean

Implementation of Entity

Inherited from StatusfulMixin.hasStatus

Overrides Task.hasStatus

Returns: boolean


in

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

Inherited from Serializable.in

Overrides CreateEmployee.in

Type parameters:

T

Parameters:

NameType
listNamestring

Returns: List‹T›


isInOneOfStates

isInOneOfStates(states: State | State[]): boolean

Implementation of Entity

Inherited from StatefulMixin.isInOneOfStates

Overrides Task.isInOneOfStates

Parameters:

NameType
statesState | State[]

Returns: boolean


isInOneOfStatuses

isInOneOfStatuses(status: Status | Status[]): boolean

Implementation of Entity

Inherited from StatusfulMixin.isInOneOfStatuses

Overrides Task.isInOneOfStatuses

Parameters:

NameType
statusStatus | Status[]

Returns: boolean


isInState

isInState(state: State | State[]): boolean

Implementation of Entity

Inherited from StatefulMixin.isInState

Overrides Task.isInState

Parameters:

NameType
stateState | State[]

Returns: boolean


isInStatus

isInStatus(status: Status | Status[]): boolean

Implementation of Entity

Inherited from StatusfulMixin.isInStatus

Overrides Task.isInStatus

Parameters:

NameType
statusStatus | Status[]

Returns: boolean


isStateSaved

isStateSaved(): boolean

Implementation of Entity

Evaluates if state of entity is saved.

Returns: boolean

Returns true if state of entity is saved, else false.


on

on(action: string | Stringifiable): this

Implementation of Entity

Sets current action for asserting state of Entity.

Parameters:

NameTypeDescription
actionstring | StringifiableName of action to be taken or Command that is handled.

Returns: this

Instance implementing Asserter interface.


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 Entity

Inherited from VersionableMixin.overrideLegacyTransformer

Overrides CreateEmployee.overrideLegacyTransformer

Parameters:

NameType
schemaVersionnumber
transformerHook

Returns: void


processSerializableList

processSerializableList(props?: Props): Props

Inherited from Serializable.processSerializableList

Overrides CreateEmployee.processSerializableList

Parameters:

NameType
props?Props

Returns: Props


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 Entity

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


setState

setState(state: State): void

Implementation of Entity

Inherited from StatefulMixin.setState

Overrides Task.setState

Parameters:

NameType
stateState

Returns: void


setStatus

setStatus(status: Status): void

Implementation of Entity

Inherited from StatusfulMixin.setStatus

Overrides Task.setStatus

Parameters:

NameType
statusStatus

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 Entity

Inherited from DefinableMixin.toPlainObject

Overrides CreateEmployee.toPlainObject

Returns: Props


toString

toString(): TypeName

Implementation of Entity

Inherited from SerializableMixin.toString

Overrides CreateEmployee.toString

Returns: TypeName


transformLegacyProps

transformLegacyProps(props: Props): Props

Implementation of Entity

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


validateState

validateState(stateOrStates: State | State[], error?: Error): boolean

Implementation of Entity

Inherited from StatefulMixin.validateState

Overrides Task.validateState

Parameters:

NameType
stateOrStatesState | State[]
error?Error

Returns: boolean


validateStatus

validateStatus(statusOrStatuses: Status | Status[], error?: Error): boolean

Implementation of Entity

Inherited from StatusfulMixin.validateStatus

Overrides Task.validateStatus

Parameters:

NameType
statusOrStatusesStatus | Status[]
error?Error

Returns: boolean


Static disableSerializableLists

disableSerializableLists(): void

Inherited from Serializable.disableSerializableLists

Overrides CreateEmployee.disableSerializableLists

Returns: void


Static enableSerializableLists

enableSerializableLists(): void

Inherited from Serializable.enableSerializableLists

Overrides CreateEmployee.enableSerializableLists

Returns: void


Static from

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

Inherited from Serializable.from

Overrides CreateEmployee.from

Parameters:

NameType
...sourcesRecord‹string, any›[]

Returns: any


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