PURISTA API / @purista/core / getSubscriptionFunctionWithValidation
Function: getSubscriptionFunctionWithValidation()
getSubscriptionFunctionWithValidation<
S
>(fn
,inputPayloadSchema
,inputParameterSchema
,outputPayloadSchema
,beforeGuards
): (this
,context
,payload
,parameter
) =>Promise
<unknown
>
Defined in: packages/core/src/SubscriptionDefinitionBuilder/getSubscriptionFunctionWithValidation.impl.ts:13
Type Parameters
• S extends Service
<ServiceClassTypes
>
Parameters
fn
SubscriptionFunction
<S
, any
, any
, any
, any
, any
, any
>
inputPayloadSchema
undefined
| SchemaObject
| Schema
<any
, any
, any
, ""
> | ZodType
<any
, ZodTypeDef
, any
>
inputParameterSchema
undefined
| SchemaObject
| Schema
<any
, any
, any
, ""
> | ZodType
<any
, ZodTypeDef
, any
>
outputPayloadSchema
undefined
| SchemaObject
| Schema
<any
, any
, any
, ""
> | ZodType
<any
, ZodTypeDef
, any
>
beforeGuards
Record
<string
, SubscriptionBeforeGuardHook
<S
, any
, any
, any
, any
, any
>> = {}
Returns
Function
Parameters
this
S
context
configs
{ getConfig
: ConfigGetterFunction
; removeConfig
: ConfigDeleteFunction
; setConfig
: ConfigSetterFunction
; }
the config store
configs.getConfig
get a config value from the config store
configs.removeConfig
delete a config value from the config store
configs.setConfig
set a config value in the config store
emit
EmitCustomMessageFunction
<EmptyObject
>
emit a custom message
logger
the logger instance
message
Readonly
<EBMessage
>
the original message
resources
Provides resources defined in service builder and set via config during service creation
secrets
{ getSecret
: SecretGetterFunction
; removeSecret
: SecretDeleteFunction
; setSecret
: SecretSetterFunction
; }
the secret store
secrets.getSecret
get a secret from the secret store
secrets.removeSecret
delete a secret from the secret store
secrets.setSecret
set a secret in the secret store
service
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)
})
startActiveSpan
<F
>(name
, opts
, context
, fn
) => Promise
<F
>
wrap given function in an opentelemetry active span
states
{ getState
: StateGetterFunction
; removeState
: StateDeleteFunction
; setState
: StateSetterFunction
; }
the state store
states.getState
get a state value from the state store
states.removeState
delete a state value from the state store
states.setState
set a state value in the state store
wrapInSpan
<F
>(name
, opts
, fn
, context
?) => Promise
<F
>
wrap given function in an opentelemetry span
payload
unknown
parameter
unknown
Returns
Promise
<unknown
>