PURISTA API / @purista/core / SubscriptionFunctionContextEnhancements
Type Alias: SubscriptionFunctionContextEnhancements<Resources, Invokes, EmitList>
SubscriptionFunctionContextEnhancements<
Resources
,Invokes
,EmitList
> =object
Defined in: packages/core/src/core/types/subscription/SubscriptionFunctionContext.ts:18
It provides the original command message. Also, the methods:
emit
which allows to emit custom events to the event bridgeinvoke
which allows to call other commands
Type Parameters
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/subscription/SubscriptionFunctionContext.ts:26
emit a custom message
message
message:
Readonly
<EBMessage
>
Defined in: packages/core/src/core/types/subscription/SubscriptionFunctionContext.ts:24
the original message
resources
resources:
Resources
Defined in: packages/core/src/core/types/subscription/SubscriptionFunctionContext.ts:46
Provides resources defined in service builder and set via config during service creation
service
service:
Invokes
Defined in: packages/core/src/core/types/subscription/SubscriptionFunctionContext.ts:42
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 subscription builder
.canInvoke<{ response: string }>('ServiceA', '1', 'test', 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)
})