CompleteTask

Type parameters

T: SuperConstructor

Hierarchy

Implements

  • Definable
  • Hookable
  • Ejsonable
  • Message
  • Command
  • Identifiable

Index

Constructors

Properties

Methods

Constructors

constructor

+ new CompleteTask(props: ConstructorTypeCompleteTask› & object): CompleteTask

Inherited from CreateEmployee.constructor

Overrides void

Creates an instance of Message.

Parameters:

NameTypeDescription
propsConstructorTypeCompleteTask› & objectProperties matching generic T with targetId as `Guid

Returns: CompleteTask

Properties

id

id: Guid


Optional metadata

metadata? : Record‹string, any›

Inherited from CreateEmployee.metadata

remarks Since Command & Event are frozen after construction, metadata property must be assigning on construction. This ensures that content of message is immutable; however metadata as an object will be unaffected by Object.freeze - thus allowing for additional data to be assigned later on. Exposed as optional - but always assigned with use of Message.prototype.processProps for easier interaction.


Optional schemaVersion

schemaVersion? : number

Inherited from CreateEmployee.schemaVersion

Overrides void


targetId

targetId: Guid | string

Inherited from CreateEmployee.targetId


Optional timestamp

timestamp? : Date

Inherited from CreateEmployee.timestamp

remarks Exposed as optional - but always assigned with use of Message.prototype.processProps for easier interaction.

Methods

assignMetadata

assignMetadata(props: Record‹string, any›): void

Inherited from CreateEmployee.assignMetadata

Assigns metadata to message.

Parameters:

NameTypeDescription
propsRecord‹string, any›Metadata properties object with all information related to Message.

Returns: void


equals

equals(other: any): boolean

Inherited from CreateEmployee.equals

Evaluates if value and value's type of passed other instance are equal to current one.

example

class Person extends DefinableMixin {
firstName: string;
lastName: string;
age: number;
constructor(firstName: string, lastName: string, age: number) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
}
}
const firstPerson = new Person('Jane', 'Doe', 28);
const secondPerson = new Person('Jane', 'Doe', 28);
expect(firstPerson.equals(secondPerson)).to.be.true;

example

const firstPerson = new Person('Jane', 'Doe', 28);
const secondPerson = new Person('John', 'Doe', 30);
expect(firstPerson.equals(secondPerson)).to.be.false;

example

const firstPerson = new Person('Jane', 'Doe', 28);
const secondPerson = {firstName: 'John', lastName: 'Doe', age: 30);
expect(firstPerson.equals(secondPerson)).to.be.false;

Parameters:

NameTypeDescription
otheranyOther instance of DefinableMixin.

Returns: boolean

Returns true if other instance of DefinableMixin is equal, else false.


getActions

getActions(): Actions

Inherited from CreateEmployee.getActions

Returns a collection of all available actions with matching registered hooks as nested collection.

Returns: Actions

Collection of actions(key) with matching registered hooks as nested collection(value).


getAssignment

getAssignment(): Assignment | undefined

Inherited from CreateEmployee.getAssignment

Returns scheduling assignment if present.

Returns: Assignment | undefined

Instance of Assignment, else undefined.


getCorrelationId

getCorrelationId(key: string): string | undefined

Inherited from CreateEmployee.getCorrelationId

Returns metadata correlation id for message.

Parameters:

NameTypeDescription
keystringKey under which correlation is set with support of dotted notation for nested objects.

Returns: string | undefined

String identifier of correlating element.


getHook

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

Inherited from CreateEmployee.getHook

Returns hook for action and id.

example

class MyClass extends HookableMixin {}
const hook = sinon.spy();
MyClass.prototype.registerHook('onConstruction', 'my-hook', hook);
expect(MyClass.prototype.getHook('onConstruction', 'my-hook')).to.be.equal(hook);

Parameters:

NameTypeDescription
actionstringAction for which hook is resolved.
idstringIdentifier under which hook was was registered.

Returns: Hook | undefined

Hook as a function matching declaration, else undefined.


getHookOrThrow

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

Inherited from CreateEmployee.getHookOrThrow

Returns hook for action and id or throws.

throws {HandlerNotFoundError} Thrown if there is no hook registered for action with id.

Parameters:

NameTypeDescription
actionstringAction for which hook is resolved.
idstringIdentifier under which hook was was registered.

Returns: Hook

Hook as a function matching declaration, else throws.


getHooks

getHooks(action: string): Mappings

Inherited from CreateEmployee.getHooks

Returns a collection of all available hooks registered for action.

Parameters:

NameTypeDescription
actionstringAction for which hooks are resolved.

Returns: Mappings

Collection of hooks.


getId

getId(): Guid | string

Inherited from CreateEmployee.getId

Returns command's targeted element by id.

Returns: Guid | string

Command's target identifier as a instance of Guid or string.


getLegacyTransformer

getLegacyTransformer(schemaVersion: number): Hook

Inherited from CreateEmployee.getLegacyTransformer

Returns legacy transformer for schema version.

throws {LegacyTransformerNotFoundError} Thrown if transformer for schema version can't be found.

Parameters:

NameTypeDescription
schemaVersionnumberSchema version.

Returns: Hook

Legacy transformer for schema version.


getLegacyTransformers

getLegacyTransformers(): LegacyTransformers

Inherited from CreateEmployee.getLegacyTransformers

Returns all available legacy transformers.

Returns: LegacyTransformers

Map instance of all registered legacy transformers with number version as a key and transformer function as a value.


getMetadata

getMetadata(): Record‹string, any›

Inherited from CreateEmployee.getMetadata

Returns metadata assigned to the message.

Returns: Record‹string, any›

Returns metadata assigned to the message as an object.


getPropTypes

getPropTypes(): Props

Inherited from CreateEmployee.getPropTypes

Returns class properties types from whole inheritance tree.

example

@define()
class MyClass extends DefinableMixin {
stringKey: string
constructor(props: Record<keyof any, any>) {
super()
Object.assign(this, props);
}
}
expect(new MyClass({stringKey: 'my-string'}).getPropTypes()).to.be.eql({
stringKey: PropTypes.instanceOf(String)
})

Returns: Props

Plain object representation of properties types.


getPropertyInitializers

getPropertyInitializers(): Props

Inherited from CreateEmployee.getPropertyInitializers

Returns default values metadata from property initializers conversion for whole inheritance tree.

example

@define()
class MyClass extends Struct {
stringKey = 'my-string';
numberKey = 1337;
constructor(props: Partial<MyClass>) {
super();
Object.assign(this, this.processProps(props));
}
}
expect(new MyClass().getPropertyInitializers()).to.be.eql({
stringKey: 'my-string',
numberKey: 1337
})

Returns: Props

Default values for properties.


getSchemaVersion

getSchemaVersion(): number | undefined

Inherited from CreateEmployee.getSchemaVersion

Returns current instance schema version.

Returns: number | undefined

Schema version as a number, else undefined.


getTimestamp

getTimestamp(): Date

Inherited from CreateEmployee.getTimestamp

Returns time when message was created.

Returns: Date

Returns instance of Date.


getTypeName

getTypeName(): TypeName

Inherited from CreateEmployee.getTypeName

Returns definable type name.

Returns: TypeName

Type name as a string.


hasAction

hasAction(action: string): boolean

Inherited from CreateEmployee.hasAction

Evaluates if hooks for action are registered.

Parameters:

NameTypeDescription
actionstringAction for which hook is existence is evaluated.

Returns: boolean

Returns true if hooks for action exists, else false.


hasCorrelationId

hasCorrelationId(key: string): boolean

Inherited from CreateEmployee.hasCorrelationId

Evaluates if message contains correlation id on metadata.

Parameters:

NameTypeDescription
keystringKey under which correlation is set with support of dotted notation for nested objects.

Returns: boolean

Returns true if metadata contains correlated element, else false.


hasHook

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

Inherited from CreateEmployee.hasHook

Evaluates if hook for action with id is registered.

Parameters:

NameTypeDescription
actionstringAction for which hook is existence is evaluated.
idstringIdentifier under which hook was was registered.

Returns: boolean

Returns true if hook exists, else false.


hasLegacyTransformer

hasLegacyTransformer(schemaVersion: number): boolean

Inherited from CreateEmployee.hasLegacyTransformer

Evaluates is there is registered legacy transformer for schema version.

Parameters:

NameTypeDescription
schemaVersionnumberSchema version.

Returns: boolean

Returns true if legacy transformer for schema version is registered, else false.


hasMetadata

hasMetadata(): boolean

Inherited from CreateEmployee.hasMetadata

Evaluates if there is assigned metadata to message.

Returns: boolean

Returns true if message has assigned metadata, else false.


in

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

Inherited from CreateEmployee.in

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.


isDeliverable

isDeliverable(): boolean

Inherited from CreateEmployee.isDeliverable

Evaluates if message is deliverable(i.e. is not scheduled or is past delivery time).

Returns: boolean

Returns true if command is deliverable, else false.


isScheduled

isScheduled(): boolean

Inherited from CreateEmployee.isScheduled

Evaluates if command is scheduled for delivery.

Returns: boolean

Returns true if command is scheduled, else false.


overrideHook

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

Inherited from CreateEmployee.overrideHook

Overrides registered hook by action and id or registers a new one.

throws {InvalidHookActionError} Thrown if the the action argument is not a string.

throws {InvalidHookIdError} Thrown if the the id argument is not a string.

Parameters:

NameTypeDescription
actionstringAction for which hook will be registered(like onConstruction, onSend, onPublish etc.)
idstringIdentifier under which hook will be registered for further reference.
hookHookHook as a function matching declaration for required action that will be invoked upon action.

Returns: void


overrideLegacyTransformer

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

Inherited from CreateEmployee.overrideLegacyTransformer

Overrides registered transformer by schema version or registers a new one.

throws {InvalidSchemaVersionError} Thrown if the the schema version argument is not a number.

Parameters:

NameTypeDescription
schemaVersionnumberSchema version.
transformerHookTransformer function.

Returns: void


processSerializableList

processSerializableList(props: Props): Props

Inherited from CreateEmployee.processSerializableList

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

Parameters:

NameTypeDefaultDescription
propsProps{}Properties 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

Inherited from CreateEmployee.registerHook

Registers hook by action type and id.

throws {InvalidHookActionError} Thrown if the the action argument is not a string.

throws {InvalidHookIdError} Thrown if the the id argument is not a string.

throws {HookAlreadyExistsError} Thrown if the existing hook with id would be overridden.

example

import {expect} from 'chai';
import {HookableMixin} from 'eveble'
class Document extends HookableMixin {
content: string;
version: number;
constructor(props: Record<keyof any, any>) {
super();
const processedProps = { ...props };
const hooks = this.getHooks('onConstruction');
for (const hook of Object.values(hooks)) {
hook.bind(this)(processedProps);
}
Object.assign(this, processedProps);
}
}
const versionable = (props: Record<keyof any, any>) => {
if (props.version === undefined) {
props.version = 0;
}
return props;
};
Document.prototype.registerHook('onConstruction', 'versionable', versionable);
const newDoc = new Document({ content: 'My document content' });
expect(newDoc.version).to.be.equal(0);

Parameters:

NameTypeDefaultDescription
actionstring-Action for which hook will be registered(like onConstruction, onSend, onPublish etc.)
idstring-Identifier under which hook will be registered for further reference.
hookHook-Hook as a function matching declaration for required action that will be invoked upon action.
shouldOverridebooleanfalseFlag indicating that hook should be overridden if exist.

Returns: void


registerLegacyTransformer

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

Inherited from CreateEmployee.registerLegacyTransformer

Registers legacy transformer for version.

throws {InvalidSchemaVersionError} Thrown if the the schema version argument is not a number.

throws {LegacyTransformerAlreadyExistsError} Thrown if transformer for version would overridden without explicit call.

Parameters:

NameTypeDefaultDescription
schemaVersionnumber-Schema version.
transformerHook-Transformer function.
shouldOverridebooleanfalseFlag indicating that transformer should be overridden if exist.

Returns: void


removeHook

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

Inherited from CreateEmployee.removeHook

Removes a hook by action and id.

example

class MyClass extends HookableMixin {}
const hook = sinon.spy();
MyClass.prototype.registerHook('onConstruction', 'my-hook', hook);
MyClass.prototype.removeHook('onConstruction', 'my-hook')
expect(MyClass.prototype.getHook('onConstruction', 'my-hook')).to.be.undefined;

Parameters:

NameTypeDescription
actionstringAction for which hook is removed.
idstringIdentifier under which hook was was registered.

Returns: void


schedule

schedule(assignment: Assignment): void

Inherited from CreateEmployee.schedule

Schedules command for delivery at specific time.

Parameters:

NameTypeDescription
assignmentAssignmentScheduling assignment information.

Returns: void


setCorrelationId

setCorrelationId(key: string, id: Stringifiable): void

Inherited from CreateEmployee.setCorrelationId

Sets correlation id metadata on message.

remarks Databases like MongoDB does not support object keys with dots like: my.nested.key Since for correlation key - namespaced 'type name' like MyNamespace.MyMessage can be used we utilize lodash'es 'set' method to construct nested object from such notation.

Parameters:

NameTypeDescription
keystringKey under which correlation is set with support of dotted notation for nested objects.
idStringifiableIdentifier of correlating element.

Returns: void


toJSONValue

toJSONValue(): Record‹string, any›

Inherited from CreateEmployee.toJSONValue

Serializes value into a JSON-compatible value. It preserves all custom field types, however the initial value type is not saved.

example

@define('Address')
class Address extends Serializable {
city: string;
street: string;
}
@define('Person')
class Person extends Serializable {
firstName: string;
lastName: string;
address?: Address;
}
const person = new Person({
firstName: 'Jane',
lastName: 'Doe',
address: new Address({
city: 'New York',
street: 'Wall Street',
}),
});
expect(person.toJSONValue()).to.be.eql({
firstName: 'Jane',
lastName: 'Doe',
address: {
city: 'New York',
street: 'Wall Street',
},
});
**Returns:** *Record‹string, any*
Normalized value as JSON-compatible without type identifers.
___
### toPlainObject
**toPlainObject**(): *[Props](../modules/types.md#props)*
*Inherited from [CreateEmployee](createemployee.md).[toPlainObject](createemployee.md#toplainobject)*
Converts properties to plain object.
**`remarks`**
**Loosing object references is required** since in scenarios when properties resolved
from `toPlainObject` are transformed - in such changes to the modified plain object
will cascade to original instance(**THIS** instance, since properties are **referenced**).
**`example`**
```ts
@define()
class Point extends DefinableMixin {
x: number;
y: number;
z: number;
}
const point = new Point({x: 1, y: 2, z: 3})
expect(point.toPlainObject()).to.be.eql({x: 1, y: 2, z: 3});

Returns: Props

Public properties with assigned values as plain object.


toString

toString(): TypeName

Inherited from CreateEmployee.toString

Returns definable type name

Returns: TypeName

Type name as a string.


transformLegacyProps

transformLegacyProps(props: Props): Props

Inherited from CreateEmployee.transformLegacyProps

Registrable hook for transforming legacy schema.

Parameters:

NameTypeDescription
propsPropsProperties object to be transformed.

Returns: Props

Transformed legacy properties or their unchanged state if up to date.


typeName

typeName(): TypeName

Inherited from CreateEmployee.typeName

alias getTypeName

remarks Compatibility for EJSON serializer: @eveble/ejson

Returns: TypeName


validateProps

validateProps(props: Props, propTypes: PropTypes, isStrict: boolean): boolean

Inherited from CreateEmployee.validateProps

Validates if provided properties matches prop types.

throws {ValidationError} Thrown if the passed properties do not match prop types.

remarks Disabling of runtime validation is possible via Kernel's configuration(and by that env flags also) or by annotating class with @validable(false).

This is useful when there is external layer(like transportation) that does all the heavy lifting of validation and there are no other sources of incoming data beside points that is handled by layer.

Use env EVEBLE_VALIDATION_TYPE set to manual to disable validation on initialization. You ca re-enable it again on your application configuration via path validation.type set to runtime before staring application.

example

@define()
class MyClass extends DefinableMixin {
stringKey: string
constructor(props: Record<keyof any, any>) {
super()
Object.assign(this, props);
}
}
const instance = new MyClass({stringKey: 'my-string'});
expect(
() => instance.validateProps({stringKey: 1337}, this.getPropTypes())
).to.throw(ValidationError)

Parameters:

NameTypeDefaultDescription
propsProps{}Properties to validate.
propTypesPropTypes-Properties types.
isStrictbooleantrueFlag indicating that validation should be done in strict mode.

Returns: boolean

Returns true if properties are valid, else throws.


Static disableSerializableLists

disableSerializableLists(): void

Inherited from CreateEmployee.disableSerializableLists

Disables conversion of serializable lists to List instances.

Returns: void


Static enableSerializableLists

enableSerializableLists(): void

Inherited from CreateEmployee.enableSerializableLists

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

Inherited from CreateEmployee.from

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 CreateEmployee.getPropTypes

Returns class properties types from whole inheritance tree.

example

@define()
class MyClass extends DefinableMixin {
stringKey: string
constructor(props: Record<keyof any, any>) {
super()
Object.assign(this, props);
}
}
expect(MyClass.getPropTypes()).to.be.eql({
stringKey: PropTypes.instanceOf(String)
})

Returns: Props

Plain object representation of properties types.


Static getPropertyInitializers

getPropertyInitializers(): Props

Inherited from CreateEmployee.getPropertyInitializers

Returns class property initializers for whole inheritance tree.

example

@define()
class MyClass extends Struct {
stringKey = 'my-string';
numberKey = 1337;
constructor(props: Partial<MyClass>) {
super();
Object.assign(this, this.processProps(props));
}
}
expect(MyClass.getPropertyInitializers()).to.be.eql({
stringKey: 'my-string',
numberKey: 1337
})

Returns: Props

Plain object representation of property initializers.


Static getTypeName

getTypeName(): TypeName

Inherited from CreateEmployee.getTypeName

Returns definable type name.

Returns: TypeName

Type name as a string.


Static toString

toString(): TypeName

Inherited from CreateEmployee.toString

Returns definable type name

Returns: TypeName

Type name as a string.


Static typeName

typeName(): TypeName

Inherited from CreateEmployee.typeName

alias getTypeName

remarks Compatibility for EJSON serializer: @eveble/ejson

Returns: TypeName