PURISTA API / @purista/core / CommandFunctionContextEnhancements
Type Alias: CommandFunctionContextEnhancements<MessagePayloadType, MessageParamsType, Resources, Invokes, StreamInvokes, EmitList, QueueInvokes, AgentInvokes>
CommandFunctionContextEnhancements<
MessagePayloadType,MessageParamsType,Resources,Invokes,StreamInvokes,EmitList,QueueInvokes,AgentInvokes> =object
Defined in: core/types/commandType/CommandFunctionContext.ts:23
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, unknown> = EmptyObject
Invokes
Invokes extends InvokeList = EmptyObject
StreamInvokes
StreamInvokes extends StreamInvokeList = EmptyObject
EmitList
EmitList extends Record<string, Schema> = EmptyObject
QueueInvokes
QueueInvokes extends QueueInvokeList = QueueInvokeList
AgentInvokes
AgentInvokes extends AgentInvokeList = EmptyObject
Properties
emit
emit:
EmitCustomMessageFunction<EmitList>
Defined in: core/types/commandType/CommandFunctionContext.ts:36
emit a custom message
invokeAgent
invokeAgent:
AgentInvokes
Defined in: core/types/commandType/CommandFunctionContext.ts:64
Invokes an agent and returns the result.
message
message:
Readonly<Command<MessagePayloadType,MessageParamsType>>
Defined in: core/types/commandType/CommandFunctionContext.ts:34
the original message
queue
queue:
QueueContext<QueueInvokes>
Defined in: core/types/commandType/CommandFunctionContext.ts:56
typed queue enqueue helpers
resources
resources:
Resources
Defined in: core/types/commandType/CommandFunctionContext.ts:60
Provides resources defined in service builder and set via config during service creation
service
service:
Invokes
Defined in: core/types/commandType/CommandFunctionContext.ts:52
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)
})stream
stream:
StreamInvokes
Defined in: core/types/commandType/CommandFunctionContext.ts:54
consumes stream responses from other service stream endpoints
