Entity
Type parameters
▪ T: SuperConstructor
▪ T: SuperConstructor
▪ T: SuperConstructor
▪ T: SuperConstructor
Hierarchy
SuperPrototypeSelector‹StatefulMixin | Serializable | StatusfulMixin, this› & StatefulMixin‹this› & Serializable‹this› & StatusfulMixin‹this›
SuperPrototypeSelector‹Serializable | StatefulMixin | StatusfulMixin, this› & StatefulMixin‹this› & Serializable‹this› & StatusfulMixin‹this›
↳ Entity
Implements
Index
Constructors
Properties
Accessors
Methods
- [ROLLBACK_STATE_METHOD_KEY]
- [SAVE_STATE_METHOD_KEY]
- equals
- getActions
- getHook
- getHookOrThrow
- getHooks
- getId
- getLegacyTransformer
- getLegacyTransformers
- getPropTypes
- getPropertyInitializers
- getSchemaVersion
- getSelectableStates
- getSelectableStatuses
- getState
- getStatus
- getTypeName
- hasAction
- hasHook
- hasLegacyTransformer
- hasState
- hasStatus
- in
- isInOneOfStates
- isInOneOfStatuses
- isInState
- isInStatus
- isStateSaved
- on
- overrideHook
- overrideLegacyTransformer
- processSerializableList
- registerHook
- registerLegacyTransformer
- removeHook
- setState
- setStatus
- toJSONValue
- toPlainObject
- toString
- transformLegacyProps
- typeName
- validateProps
- validateState
- validateStatus
- disableSerializableLists
- enableSerializableLists
- from
- getPropTypes
- getPropertyInitializers
- getTypeName
- toString
- typeName
Constructors
constructor
+ new Entity(props
: Props): Entity
Overrides Serializable.constructor
Creates an instance of Entity
.
Creates an instance of Entity
.
Parameters:
Name | Type | Description |
---|---|---|
props | Props | Properties 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:
Will result with returned object:
That can be called like:
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:
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:
Name | Type | Description |
---|---|---|
otherEntity | Entity | Other 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:
Name | Type |
---|---|
action | string |
id | string |
Returns: Hook | undefined
getHookOrThrow
▸ getHookOrThrow(action
: string, id
: string): Hook
Implementation of Hookable
Inherited from HookableMixin.getHookOrThrow
Overrides CreateEmployee.getHookOrThrow
Parameters:
Name | Type |
---|---|
action | string |
id | string |
Returns: Hook
getHooks
▸ getHooks(action
: string): Mappings
Implementation of Hookable
Inherited from HookableMixin.getHooks
Overrides CreateEmployee.getHooks
Parameters:
Name | Type |
---|---|
action | string |
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:
Name | Type |
---|---|
schemaVersion | number |
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
Returns: State
getStatus
▸ getStatus(): Status
Implementation of Entity
Inherited from StatusfulMixin.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:
Name | Type |
---|---|
action | string |
Returns: boolean
hasHook
▸ hasHook(action
: string, id
: string): boolean
Implementation of Hookable
Inherited from HookableMixin.hasHook
Overrides CreateEmployee.hasHook
Parameters:
Name | Type |
---|---|
action | string |
id | string |
Returns: boolean
hasLegacyTransformer
▸ hasLegacyTransformer(schemaVersion
: number): boolean
Implementation of Entity
Inherited from VersionableMixin.hasLegacyTransformer
Overrides CreateEmployee.hasLegacyTransformer
Parameters:
Name | Type |
---|---|
schemaVersion | number |
Returns: boolean
hasState
▸ hasState(): boolean
Implementation of Entity
Inherited from StatefulMixin.hasState
Returns: boolean
hasStatus
▸ hasStatus(): boolean
Implementation of Entity
Inherited from StatusfulMixin.hasStatus
Returns: boolean
in
▸ in‹T›(listName
: string): List‹T›
Inherited from Serializable.in
Overrides CreateEmployee.in
Type parameters:
▪ T
Parameters:
Name | Type |
---|---|
listName | string |
Returns: List‹T›
isInOneOfStates
▸ isInOneOfStates(states
: State | State[]): boolean
Implementation of Entity
Inherited from StatefulMixin.isInOneOfStates
Overrides Task.isInOneOfStates
Parameters:
Name | Type |
---|---|
states | State | State[] |
Returns: boolean
isInOneOfStatuses
▸ isInOneOfStatuses(status
: Status | Status[]): boolean
Implementation of Entity
Inherited from StatusfulMixin.isInOneOfStatuses
Overrides Task.isInOneOfStatuses
Parameters:
Name | Type |
---|---|
status | Status | Status[] |
Returns: boolean
isInState
▸ isInState(state
: State | State[]): boolean
Implementation of Entity
Inherited from StatefulMixin.isInState
Parameters:
Name | Type |
---|---|
state | State | State[] |
Returns: boolean
isInStatus
▸ isInStatus(status
: Status | Status[]): boolean
Implementation of Entity
Inherited from StatusfulMixin.isInStatus
Overrides Task.isInStatus
Parameters:
Name | Type |
---|---|
status | Status | 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:
Name | Type | Description |
---|---|---|
action | string | Stringifiable | Name 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:
Name | Type |
---|---|
action | string |
id | string |
hook | Hook |
Returns: void
overrideLegacyTransformer
▸ overrideLegacyTransformer(schemaVersion
: number, transformer
: Hook): void
Implementation of Entity
Inherited from VersionableMixin.overrideLegacyTransformer
Overrides CreateEmployee.overrideLegacyTransformer
Parameters:
Name | Type |
---|---|
schemaVersion | number |
transformer | Hook |
Returns: void
processSerializableList
▸ processSerializableList(props?
: Props): Props
Inherited from Serializable.processSerializableList
Overrides CreateEmployee.processSerializableList
Parameters:
Name | Type |
---|---|
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:
Name | Type |
---|---|
action | string |
id | string |
hook | Hook |
shouldOverride? | boolean |
Returns: void
registerLegacyTransformer
▸ registerLegacyTransformer(schemaVersion
: number, transformer
: Hook, shouldOverride?
: boolean): void
Implementation of Entity
Inherited from VersionableMixin.registerLegacyTransformer
Overrides CreateEmployee.registerLegacyTransformer
Parameters:
Name | Type |
---|---|
schemaVersion | number |
transformer | Hook |
shouldOverride? | boolean |
Returns: void
removeHook
▸ removeHook(action
: string, id
: string): void
Implementation of Hookable
Inherited from HookableMixin.removeHook
Overrides CreateEmployee.removeHook
Parameters:
Name | Type |
---|---|
action | string |
id | string |
Returns: void
setState
▸ setState(state
: State): void
Implementation of Entity
Inherited from StatefulMixin.setState
Parameters:
Name | Type |
---|---|
state | State |
Returns: void
setStatus
▸ setStatus(status
: Status): void
Implementation of Entity
Inherited from StatusfulMixin.setStatus
Parameters:
Name | Type |
---|---|
status | Status |
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:
Name | Type |
---|---|
props | Props |
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:
Name | Type |
---|---|
props | Record‹string | number | symbol, any› | undefined |
propTypes | PropTypes |
isStrict? | boolean |
Returns: boolean
validateState
▸ validateState(stateOrStates
: State | State[], error?
: Error): boolean
Implementation of Entity
Inherited from StatefulMixin.validateState
Overrides Task.validateState
Parameters:
Name | Type |
---|---|
stateOrStates | State | State[] |
error? | Error |
Returns: boolean
validateStatus
▸ validateStatus(statusOrStatuses
: Status | Status[], error?
: Error): boolean
Implementation of Entity
Inherited from StatusfulMixin.validateStatus
Overrides Task.validateStatus
Parameters:
Name | Type |
---|---|
statusOrStatuses | Status | 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:
Name | Type |
---|---|
...sources | Record‹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