PURISTA API / @purista/core / CommandFunctionContextEnhancements
Type Alias: CommandFunctionContextEnhancements<MessagePayloadType, MessageParamsType, Resources, Invokes, EmitList>
CommandFunctionContextEnhancements<
MessagePayloadType,MessageParamsType,Resources,Invokes,EmitList> =object
Defined in: packages/core/src/core/types/commandType/CommandFunctionContext.ts:19
It provides the original command message with types for payload and parameter. Also, the methods:
emitwhich allows to emit custom events to the event bridgeinvokewhich allows to call other commands
Type Parameters
MessagePayloadType
MessagePayloadType = unknown
MessageParamsType
MessageParamsType = unknown
Resources
Resources extends Record<string, any> = EmptyObject
Invokes
Invokes extends InvokeList = EmptyObject
EmitList
EmitList extends Record<string, Schema> = EmptyObject
Properties
emit
emit:
EmitCustomMessageFunction<EmitList>
Defined in: packages/core/src/core/types/commandType/CommandFunctionContext.ts:29
emit a custom message
message
message:
Readonly<Command<MessagePayloadType,MessageParamsType>>
Defined in: packages/core/src/core/types/commandType/CommandFunctionContext.ts:27
the original message
resources
resources:
Resources
Defined in: packages/core/src/core/types/commandType/CommandFunctionContext.ts:49
Provides resources defined in service builder and set via config during service creation
service
service:
Invokes
Defined in: packages/core/src/core/types/commandType/CommandFunctionContext.ts:45
Invokes a command and returns the result. It is recommended to validate the result against a schema which only contains the data you actually need.
Example
// define your invocation in command builder
.canInvoke('ServiceA', '1', 'test', responseOutputSchema, payloadSchema, parameterSchema)
.setCommandFunction(async function (context, payload, _parameter) {
const inputPayload = { my: 'input' }
const inputParameter = { search: 'for_me' }
const result = await context.service.ServiceA[1].test(inputPayload,inputParameter)
})