import type { SinonSandbox } from 'sinon'; import type { Service } from '../core/Service/Service.impl.js'; import type { Complete } from '../core/types/Complete.js'; import type { ContentType } from '../core/types/ContentType.js'; import type { DefinitionEventBridgeConsumerFailureHandling } from '../core/types/DefinitionEventBridgeConsumerFailureHandling.js'; import type { EBMessage } from '../core/types/EBMessage.js'; import type { EBMessageType } from '../core/types/EBMessageType.enum.js'; import type { InstanceId } from '../core/types/InstanceId.js'; import type { PrincipalId } from '../core/types/PrincipalId.js'; import type { SubscriptionAfterGuardHook } from '../core/types/subscription/SubscriptionAfterGuardHook.js'; import type { SubscriptionBeforeGuardHook } from '../core/types/subscription/SubscriptionBeforeGuardHook.js'; import type { SubscriptionDefinition } from '../core/types/subscription/SubscriptionDefinition.js'; import type { SubscriptionDefinitionMetadataBase } from '../core/types/subscription/SubscriptionDefinitionMetadataBase.js'; import type { SubscriptionFunction } from '../core/types/subscription/SubscriptionFunction.js'; import type { SubscriptionTransformInputHook } from '../core/types/subscription/SubscriptionTransformInputHook.js'; import type { SubscriptionTransformOutputHook } from '../core/types/subscription/SubscriptionTransformOutputHook.js'; import type { TenantId } from '../core/types/TenantId.js'; import type { NonEmptyString } from '../helper/types/NonEmptyString.js'; import type { Infer, InferIn, Schema } from '../schema/index.js'; import type { SubscriptionDefinitionBuilderTypes } from './SubscriptionDefinitionBuilderTypes.js'; /** * Subscription definition builder is a helper to create and define a subscriptions for a service. * It helps to set all needed filters. * * A working schema definition needs at least a subscription name, a short description and the subscription implementation. * * @group Subscription */ export declare class SubscriptionDefinitionBuilder { private subscriptionName; private subscriptionDescription; private messageType; private inputSchema?; private inputContentType; private inputContentEncoding; private outputSchema?; private outputContentType; private outputContentEncoding; private parameterSchema?; private hooks; private sender?; private receiver?; private fn?; private eventName?; private emitEventName?; private principalId?; private tenantId?; private durable; private shared; private autoacknowledge; private consumerFailureHandling?; private invokes; private streamInvokes; private emitList; private queueInvokes; private deprecated; constructor(subscriptionName: Exclude, subscriptionDescription: string, deprecated?: boolean); /** * Define a command which can be invoked by the current subscription * @param serviceName * @param serviceVersion * @param serviceTarget * @param outputSchema * @param payloadSchema * @param parameterSchema * @returns */ canInvoke(serviceName: SName, serviceVersion: Version, serviceTarget: Fname, outputSchema?: Output, payloadSchema?: Payload, parameterSchema?: Parameter): SubscriptionDefinitionBuilder, parameter: InferIn) => Promise>>>>, C['StreamInvokes'], C['EmitList']>>; canConsumeStream(serviceName: SName, serviceVersion: Version, serviceTarget: Fname, chunkSchema?: Chunk, payloadSchema?: Payload, parameterSchema?: Parameter, finalSchema?: Final, validateChunk?: boolean, validateFinal?: boolean): SubscriptionDefinitionBuilder, parameter: InferIn) => Promise<{ sessionId: string; cancel(reason?: string): Promise; [Symbol.asyncIterator](): AsyncIterator<{ payload: { chunk?: Infer; final?: Infer; }; }>; }>>>>, C['EmitList']>>; /** * Define which custom events the subscription can emit. * * @param eventName The custom event name * @param schema the payload schema * @returns */ canEmit(eventName: EventName, schema: T): SubscriptionDefinitionBuilder>>>; /** * Mark this subscription as deprecated * @returns SubscriptionDefinitionBuilder */ markAsDeprecated(): this; /** * Add a filter to only subscribe to messages with matching event name * @param eventName The name of event to subscribe * @param serviceVersion the version of the service that produces the event * @returns SubscriptionDefinitionBuilder */ subscribeToEvent(eventName: NonEmptyString, serviceVersion?: NonEmptyString): this; /** * Filter messages only for principalId * @param principalId the principal id to subscribe * @returns */ filterPrincipalId(principalId: NonEmptyString): this; /** * Filter messages only for tenantId * @param tenantId the principal id to subscribe * @returns */ filterTenantId(tenantId: NonEmptyString): this; /** * Instruct the event bridge message broker to autoacknowledge messages as soon as they arrive. * This means, a message will not be resent, if the subscription execution fails unexpected. * * If set to false, the message will be resent from message broker to eventbridge, if: * - the underlaying message broker supports it * - if the subscription execution fails unexpected * - if sending of optional subscription response failed * * @param acknowledge Enable (true) and disable (false) * @returns SubscriptionDefinition */ adviceAutoacknowledgeMessage(acknowledge?: boolean): this; /** * Instruct the event bridge message broker to send the matching message to every running instance. * The underlaying message broker must support this functionality. * * In serverless environments, this flag should not have any effect * * @param enforce Set to true to deliver message to every running instance * @returns SubscriptionDefinition */ receiveMessageOnEveryInstance(enforce?: boolean): this; /** * False: defines the subscription as a live-subscription, which is only able to process messages while the subscription itself is running. * * True: Advises the event bridge (like rabbitMQ) to store all messages if the subscription is not running. * As soon as the subscription is back again, all missed messages will be sent first, before it starts working like a live-subscription. */ adviceDurable(durable: boolean): this; /** * Advise retry and dead-letter handling for this subscription. * * The selected event bridge decides which parts it can honor. Production * adapters should document whether retries are broker-native, bridge-emulated, * or unsupported. */ adviceConsumerFailureHandling(config: DefinitionEventBridgeConsumerFailureHandling): this; /** * Add filter to only match messages send by given service function & version. * Set one or more parameters to undefined means "do not filter by this criteria". * For example: * * This will filter for all messages send from function testFunction of service UserService. * This will include messages from all versions of this function. * * ```typescript * sentFrom('UserService', undefined, 'testFunction') * ``` * * @param serviceName the name of the service that produces the message * @param serviceVersion the version of the service that produces the message * @param serviceTarget the command or subscription name of the service that produces the message * @param instanceId the event bridge instance id which was publishing the message * @returns */ filterSentFrom(serviceName: NonEmptyString | undefined, serviceVersion: NonEmptyString | undefined, serviceTarget: NonEmptyString | undefined, instanceId: NonEmptyString | undefined): this; /** * Add filter to only match messages received by given service function & version. * Set one or more parameters to undefined means "do not filter by this criteria". * For example: * * This will filter for all messages send to function testFunction of service UserService. * This will include messages from all versions of this function. * * ```typescript * receivedBy('UserService', undefined, 'testFunction') * ``` * * @param serviceName the name of the service that consumes the message * @param serviceVersion the version of the service that consumes the message * @param serviceTarget the command or subscription name of the service that consumes the message * @param instanceId the event bridge instance id which should receive the message * @returns */ filterReceivedBy(serviceName: NonEmptyString | undefined, serviceVersion: NonEmptyString | undefined, serviceTarget: NonEmptyString | undefined, instanceId: NonEmptyString | undefined): this; /** * Adds a filter to match specific message type. * * Common message types are `Command`, `CommandSuccessResponse` and `CommandErrorResponse`. * * See @enum EBMessageType for full available list. * * @param messageType the type of message * @returns */ filterForMessageType(messageType: EBMessageType): this; /** * Add a schema for input payload validation. * Types for payload of message and function payload input are generated from given schema. * @param inputSchema the validation schema for input payload * @param inputContentType optional the content type of payload * @param inputContentEncoding optional the content encoding * @returns SubscriptionDefinitionBuilder */ addPayloadSchema(inputSchema: PayloadSchema, inputContentType?: string, inputContentEncoding?: string): SubscriptionDefinitionBuilder>; /** * Add a schema for output payload validation. * Types for payload of message and function payload output are generated from given schema. * @param eventName the event name to be used when the subscription result is emitted as custom event * @param outputSchema the validation schema for the output payload * @param outputContentType optional the content type of payload * @param outputContentEncoding optional the content encoding * @returns SubscriptionDefinitionBuilder */ addOutputSchema(eventName: string, outputSchema: OutputSchema, outputContentType?: string, outputContentEncoding?: string): SubscriptionDefinitionBuilder>; /** * Add a schema for output parameter validation. * Types for parameter of message and function parameter output are generated from given schema. * @param parameterSchema the validation schema for output parameter * @returns SubscriptionDefinitionBuilder */ addParameterSchema(parameterSchema: ParamsSchema): SubscriptionDefinitionBuilder>; /** * Set a transform input hook which will encode or transform the input payload and parameters. * Will be executed as first step before input validation, before guard and the function itself. * This will change the type of input message payload and input message parameter. * @param transformInputSchema Input payload validation schema * @param transformParameterSchema Input parameter validation schema * @param transformFunction the transform input function * @param inputContentType optional the content type of payload * @param inputContentEncoding optional the content encoding * @returns SubscriptionDefinitionBuilder */ setTransformInput(transformInputSchema: TransformInputPayloadSchema, transformParameterSchema: TransformInputParamsSchema, transformFunction: SubscriptionTransformInputHook, Infer, InferIn, InferIn>, inputContentType?: ContentType, inputContentEncoding?: string): SubscriptionDefinitionBuilder>; /** * Return the transform input function * @returns the input transform function if defined */ getTransformInputFunction(): SubscriptionTransformInputHook, Infer, InferIn, InferIn> | undefined; /** * Set a transform output hook which will encode or transform the response payload. * Will be executed at very last step after function execution, output validation and after guard hooks. * This will change the type of output message payload. * @param transformOutputSchema The output validation schema * @param transformFunction the transform output function * @param outputContentType optional the content type of payload * @param outputContentEncoding optional the content encoding * @returns SubscriptionDefinitionBuilder */ setTransformOutput(transformOutputSchema: TransformOutputSchema, transformFunction: SubscriptionTransformOutputHook, Infer, InferIn>, outputContentType?: ContentType, outputContentEncoding?: string): SubscriptionDefinitionBuilder>; /** * Return the transform output function * @returns the transform output function if defined */ getTransformOutputFunction(): SubscriptionTransformOutputHook, Infer, InferIn> | undefined; /** * Set one or more before guard hook(s). * If there are multiple before guard hooks, they are executed in parallel * @param beforeGuards Object of key = name of guard, value = function * @returns SubscriptionDefinitionBuilder */ setBeforeGuardHooks(beforeGuards: Record, Infer, C['Resources'], C['Invokes'], C['StreamInvokes'], C['EmitList']>>): this; /** * Set one or more after guard hook(s). * If there are multiple after guard hooks, they are executed in parallel * @param afterGuards Object of key = name of guard, value = function * @returns SubscriptionDefinitionBuilder */ setAfterGuardHooks(afterGuards: Record, Infer, Infer, C['Resources'], C['Invokes'], C['StreamInvokes'], C['EmitList']>>): this; /** * Required: Set the function implementation. * The types should be automatically set as soon as schemas previously defined. * As the function will be a a function of a service class you need to implement as function declaration. * Arrow functions do not have access to the `this` scope. * * @example * ```ts * async function (context, payload, parameter) { * * return `the result output payload` * } * ``` * @param fn the function implementation * @returns SubscriptionDefinitionBuilder */ setSubscriptionFunction(fn: SubscriptionFunction, Infer, InferIn, C['Resources'], C['Invokes'], C['StreamInvokes'], C['EmitList'], C['QueueInvokes']>): this; /** * Get the function implementation including input and output validation. * Also, before and after hooks are triggered during execution. * * @returns the subscription function */ getSubscriptionFunction(): SubscriptionFunction, InferIn, InferIn, C['Resources'], C['Invokes'], C['StreamInvokes'], C['EmitList'], C['QueueInvokes']>; /** * Get the function implementation without input and output validation. * No hooks are triggered during execution. * * @returns the subscription function */ getSubscriptionFunctionPlain(): SubscriptionFunction, Infer, InferIn, C['Resources'], C['Invokes'], C['StreamInvokes'], C['EmitList'], C['QueueInvokes']>; /** * Returns the final subscription definition which will be passed into the service class. * @returns SubscriptionDefinition */ getDefinition(): Promise, Infer, Infer, Infer, InferIn, Infer, InferIn, C["Resources"], C["Invokes"], C["StreamInvokes"], C["EmitList"], SubscriptionDefinitionMetadataBase, C["QueueInvokes"]>>>; /** * Returns a mocked transform function context, which can be used in unit tests. * * @param input Options to create the transform context mock (message/resources/sandbox) * @returns a mocked transform function context */ getSubscriptionTransformContextMock(input: { message: EBMessage; resources?: C['Resources']; sandbox?: SinonSandbox; }): { mock: { logger: import("../index.js").Logger; metrics: import("../index.js").PuristaMetricContext; wrapInSpan: (name: string, opts: import("@opentelemetry/api").SpanOptions, fn: (span: import("@opentelemetry/api").Span) => Promise, context?: import("@opentelemetry/api").Context) => Promise; startActiveSpan: (name: string, opts: import("@opentelemetry/api").SpanOptions, context: import("@opentelemetry/api").Context | undefined, fn: (span: import("@opentelemetry/api").Span) => Promise) => Promise; secrets: { getSecret: import("../index.js").SecretGetterFunction; setSecret: import("../index.js").SecretSetterFunction; removeSecret: import("../index.js").SecretDeleteFunction; }; configs: { getConfig: import("../index.js").ConfigGetterFunction; setConfig: import("../index.js").ConfigSetterFunction; removeConfig: import("../index.js").ConfigDeleteFunction; }; states: { getState: import("../index.js").StateGetterFunction; setState: import("../index.js").StateSetterFunction; removeState: import("../index.js").StateDeleteFunction; }; queue: import("../index.js").QueueContext; message: Readonly; resources: import("../index.js").EmptyObject; }; stubs: { logger: { info: import("sinon").SinonStub; error: import("sinon").SinonStub; warn: import("sinon").SinonStub; debug: import("sinon").SinonStub; trace: import("sinon").SinonStub; fatal: import("sinon").SinonStub; }; wrapInSpan: import("sinon").SinonStub; startActiveSpan: import("sinon").SinonStub; getSecret: import("sinon").SinonStub; setSecret: import("sinon").SinonStub; removeSecret: import("sinon").SinonStub; getConfig: import("sinon").SinonStub; setConfig: import("sinon").SinonStub; removeConfig: import("sinon").SinonStub; getState: import("sinon").SinonStub; setState: import("sinon").SinonStub; removeState: import("sinon").SinonStub; enqueue: import("sinon").SinonStub; scheduleAt: import("sinon").SinonStub; resources: Partial; }; }; } //# sourceMappingURL=SubscriptionDefinitionBuilder.impl.d.ts.map