@message-queue-toolkit/core
Advanced tools
Comparing version 10.1.1 to 11.0.0
@@ -9,3 +9,3 @@ export type { QueueConsumer, AsyncPublisher, SyncPublisher, TransactionObservabilityManager, Logger, LogFn, SchemaMap, ExtraParams, } from './lib/types/MessageQueueTypes'; | ||
export { HandlerContainer, MessageHandlerConfig, MessageHandlerConfigBuilder, } from './lib/queues/HandlerContainer'; | ||
export type { BarrierCallback, BarrierResult, BarrierResultPositive, BarrierResultNegative, HandlerContainerOptions, Handler, Prehandler, PrehandlingOutputs, } from './lib/queues/HandlerContainer'; | ||
export type { BarrierCallback, BarrierResult, BarrierResultPositive, BarrierResultNegative, HandlerContainerOptions, Handler, Prehandler, PreHandlingOutputs, } from './lib/queues/HandlerContainer'; | ||
export { HandlerSpy } from './lib/queues/HandlerSpy'; | ||
@@ -12,0 +12,0 @@ export type { SpyResult, HandlerSpyParams, PublicHandlerSpy } from './lib/queues/HandlerSpy'; |
@@ -6,3 +6,3 @@ import type { ErrorReporter, ErrorResolver, Either } from '@lokalise/node-core'; | ||
import type { DeletionConfig, QueueDependencies, QueueOptions } from '../types/queueOptionsTypes'; | ||
import type { BarrierCallback, BarrierResult, Prehandler, PrehandlerResult, PrehandlingOutputs } from './HandlerContainer'; | ||
import type { BarrierCallback, BarrierResult, Prehandler, PrehandlerResult, PreHandlingOutputs } from './HandlerContainer'; | ||
import type { HandlerSpy, PublicHandlerSpy } from './HandlerSpy'; | ||
@@ -38,11 +38,11 @@ export type Deserializer<MessagePayloadType extends object> = (message: unknown, type: ZodType<MessagePayloadType>, errorProcessor: ErrorResolver) => Either<MessageInvalidFormatError | MessageValidationError, MessagePayloadType>; | ||
protected handleMessageProcessed(message: MessagePayloadSchemas | null, processingResult: MessageProcessingResult, messageId?: string): void; | ||
protected processPrehandlersInternal(prehandlers: Prehandler<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput>[], message: MessagePayloadSchemas): Promise<PrehandlerOutput>; | ||
protected preHandlerBarrierInternal<BarrierOutput>(barrier: BarrierCallback<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput, BarrierOutput> | undefined, message: MessagePayloadSchemas, executionContext: ExecutionContext, prehandlerOutput: PrehandlerOutput): Promise<BarrierResult<BarrierOutput>>; | ||
protected abstract resolveNextFunction(prehandlers: Prehandler<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput>[], message: MessagePayloadSchemas, index: number, prehandlerOutput: PrehandlerOutput, resolve: (value: PrehandlerOutput | PromiseLike<PrehandlerOutput>) => void, reject: (err: Error) => void): (prehandlerResult: PrehandlerResult) => void; | ||
protected resolveNextPreHandlerFunctionInternal(prehandlers: Prehandler<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput>[], executionContext: ExecutionContext, message: MessagePayloadSchemas, index: number, prehandlerOutput: PrehandlerOutput, resolve: (value: PrehandlerOutput | PromiseLike<PrehandlerOutput>) => void, reject: (err: Error) => void): (prehandlerResult: PrehandlerResult) => void; | ||
protected processPrehandlersInternal(preHandlers: Prehandler<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput>[], message: MessagePayloadSchemas): Promise<PrehandlerOutput>; | ||
protected preHandlerBarrierInternal<BarrierOutput>(barrier: BarrierCallback<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput, BarrierOutput> | undefined, message: MessagePayloadSchemas, executionContext: ExecutionContext, preHandlerOutput: PrehandlerOutput): Promise<BarrierResult<BarrierOutput>>; | ||
protected abstract resolveNextFunction(preHandlers: Prehandler<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput>[], message: MessagePayloadSchemas, index: number, preHandlerOutput: PrehandlerOutput, resolve: (value: PrehandlerOutput | PromiseLike<PrehandlerOutput>) => void, reject: (err: Error) => void): (preHandlerResult: PrehandlerResult) => void; | ||
protected resolveNextPreHandlerFunctionInternal(preHandlers: Prehandler<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput>[], executionContext: ExecutionContext, message: MessagePayloadSchemas, index: number, preHandlerOutput: PrehandlerOutput, resolve: (value: PrehandlerOutput | PromiseLike<PrehandlerOutput>) => void, reject: (err: Error) => void): (preHandlerResult: PrehandlerResult) => void; | ||
protected abstract processPrehandlers(message: MessagePayloadSchemas, messageType: string): Promise<PrehandlerOutput>; | ||
protected abstract preHandlerBarrier<BarrierOutput>(message: MessagePayloadSchemas, messageType: string, prehandlerOutput: PrehandlerOutput): Promise<BarrierResult<BarrierOutput>>; | ||
protected abstract processMessage(message: MessagePayloadSchemas, messageType: string, prehandlingOutputs: PrehandlingOutputs<PrehandlerOutput, any>): Promise<Either<'retryLater', 'success'>>; | ||
protected abstract preHandlerBarrier<BarrierOutput>(message: MessagePayloadSchemas, messageType: string, preHandlerOutput: PrehandlerOutput): Promise<BarrierResult<BarrierOutput>>; | ||
protected abstract processMessage(message: MessagePayloadSchemas, messageType: string, preHandlingOutputs: PreHandlingOutputs<PrehandlerOutput, any>): Promise<Either<'retryLater', 'success'>>; | ||
abstract close(): Promise<unknown>; | ||
} | ||
export {}; |
@@ -80,4 +80,4 @@ "use strict"; | ||
} | ||
processPrehandlersInternal(prehandlers, message) { | ||
if (prehandlers.length === 0) { | ||
processPrehandlersInternal(preHandlers, message) { | ||
if (preHandlers.length === 0) { | ||
return Promise.resolve({}); | ||
@@ -87,4 +87,4 @@ } | ||
try { | ||
const prehandlerOutput = {}; | ||
const next = this.resolveNextFunction(prehandlers, message, 0, prehandlerOutput, resolve, reject); | ||
const preHandlerOutput = {}; | ||
const next = this.resolveNextFunction(preHandlers, message, 0, preHandlerOutput, resolve, reject); | ||
next({ result: 'success' }); | ||
@@ -97,3 +97,3 @@ } | ||
} | ||
async preHandlerBarrierInternal(barrier, message, executionContext, prehandlerOutput) { | ||
async preHandlerBarrierInternal(barrier, message, executionContext, preHandlerOutput) { | ||
if (!barrier) { | ||
@@ -107,18 +107,18 @@ // @ts-ignore | ||
// @ts-ignore | ||
return await barrier(message, executionContext, prehandlerOutput); | ||
return await barrier(message, executionContext, preHandlerOutput); | ||
} | ||
// eslint-disable-next-line max-params | ||
resolveNextPreHandlerFunctionInternal(prehandlers, executionContext, message, index, prehandlerOutput, resolve, reject) { | ||
return (prehandlerResult) => { | ||
if (prehandlerResult.error) { | ||
reject(prehandlerResult.error); | ||
resolveNextPreHandlerFunctionInternal(preHandlers, executionContext, message, index, preHandlerOutput, resolve, reject) { | ||
return (preHandlerResult) => { | ||
if (preHandlerResult.error) { | ||
reject(preHandlerResult.error); | ||
} | ||
if (prehandlers.length < index + 1) { | ||
resolve(prehandlerOutput); | ||
if (preHandlers.length < index + 1) { | ||
resolve(preHandlerOutput); | ||
} | ||
else { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
prehandlers[index](message, executionContext, | ||
preHandlers[index](message, executionContext, | ||
// @ts-ignore | ||
prehandlerOutput, this.resolveNextPreHandlerFunctionInternal(prehandlers, executionContext, message, index + 1, prehandlerOutput, resolve, reject)); | ||
preHandlerOutput, this.resolveNextPreHandlerFunctionInternal(preHandlers, executionContext, message, index + 1, preHandlerOutput, resolve, reject)); | ||
} | ||
@@ -125,0 +125,0 @@ }; |
@@ -5,4 +5,4 @@ import type { Either } from '@lokalise/node-core'; | ||
import type { RetryMessageLaterError } from '../errors/RetryMessageLaterError'; | ||
export type PrehandlingOutputs<PrehandlerOutput = undefined, BarrierOutput = undefined> = { | ||
prehandlerOutput: PrehandlerOutput; | ||
export type PreHandlingOutputs<PrehandlerOutput = undefined, BarrierOutput = undefined> = { | ||
preHandlerOutput: PrehandlerOutput; | ||
barrierOutput: BarrierOutput; | ||
@@ -21,4 +21,4 @@ }; | ||
export type PrehandlerResult = Either<DoNotProcessMessageError | RetryMessageLaterError, 'success'>; | ||
export type BarrierCallback<MessagePayloadSchema extends object, ExecutionContext, PrehandlerOutput, BarrierOutput> = (message: MessagePayloadSchema, context: ExecutionContext, prehandlerOutput: PrehandlerOutput) => Promise<BarrierResult<BarrierOutput>>; | ||
export type Prehandler<MessagePayloadSchema extends object, ExecutionContext, PrehandlerOutput> = (message: MessagePayloadSchema, context: ExecutionContext, prehandlerOutput: Partial<PrehandlerOutput>, next: (result: PrehandlerResult) => void) => void; | ||
export type BarrierCallback<MessagePayloadSchema extends object, ExecutionContext, PrehandlerOutput, BarrierOutput> = (message: MessagePayloadSchema, context: ExecutionContext, preHandlerOutput: PrehandlerOutput) => Promise<BarrierResult<BarrierOutput>>; | ||
export type Prehandler<MessagePayloadSchema extends object, ExecutionContext, PrehandlerOutput> = (message: MessagePayloadSchema, context: ExecutionContext, preHandlerOutput: Partial<PrehandlerOutput>, next: (result: PrehandlerResult) => void) => void; | ||
export declare const defaultLogFormatter: <MessagePayloadSchema>(message: MessagePayloadSchema) => MessagePayloadSchema; | ||
@@ -28,3 +28,3 @@ export type HandlerConfigOptions<MessagePayloadSchema extends object, ExecutionContext, PrehandlerOutput, BarrierOutput> = { | ||
preHandlerBarrier?: BarrierCallback<MessagePayloadSchema, ExecutionContext, PrehandlerOutput, BarrierOutput>; | ||
prehandlers?: Prehandler<MessagePayloadSchema, ExecutionContext, PrehandlerOutput>[]; | ||
preHandlers?: Prehandler<MessagePayloadSchema, ExecutionContext, PrehandlerOutput>[]; | ||
}; | ||
@@ -36,3 +36,3 @@ export declare class MessageHandlerConfig<const MessagePayloadSchema extends object, const ExecutionContext, const PrehandlerOutput = undefined, const BarrierOutput = unknown> { | ||
readonly preHandlerBarrier?: BarrierCallback<MessagePayloadSchema, ExecutionContext, PrehandlerOutput, BarrierOutput>; | ||
readonly prehandlers: Prehandler<MessagePayloadSchema, ExecutionContext, PrehandlerOutput>[]; | ||
readonly preHandlers: Prehandler<MessagePayloadSchema, ExecutionContext, PrehandlerOutput>[]; | ||
constructor(schema: ZodSchema<MessagePayloadSchema>, handler: Handler<MessagePayloadSchema, ExecutionContext, PrehandlerOutput, BarrierOutput>, options?: HandlerConfigOptions<MessagePayloadSchema, ExecutionContext, PrehandlerOutput, BarrierOutput>); | ||
@@ -46,3 +46,3 @@ } | ||
} | ||
export type Handler<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput = undefined, BarrierOutput = undefined> = (message: MessagePayloadSchemas, context: ExecutionContext, prehandlingOutputs: PrehandlingOutputs<PrehandlerOutput, BarrierOutput>) => Promise<Either<'retryLater', 'success'>>; | ||
export type Handler<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput = undefined, BarrierOutput = undefined> = (message: MessagePayloadSchemas, context: ExecutionContext, preHandlingOutputs: PreHandlingOutputs<PrehandlerOutput, BarrierOutput>) => Promise<Either<'retryLater', 'success'>>; | ||
export type HandlerContainerOptions<MessagePayloadSchemas extends object, ExecutionContext, PrehandlerOutput = undefined> = { | ||
@@ -49,0 +49,0 @@ messageHandlers: MessageHandlerConfig<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput>[]; |
@@ -11,3 +11,3 @@ "use strict"; | ||
preHandlerBarrier; | ||
prehandlers; | ||
preHandlers; | ||
constructor(schema, handler, options) { | ||
@@ -18,3 +18,3 @@ this.schema = schema; | ||
this.preHandlerBarrier = options?.preHandlerBarrier; | ||
this.prehandlers = options?.prehandlers ?? []; | ||
this.preHandlers = options?.preHandlers ?? []; | ||
} | ||
@@ -21,0 +21,0 @@ } |
{ | ||
"name": "@message-queue-toolkit/core", | ||
"version": "10.1.1", | ||
"version": "11.0.0", | ||
"private": false, | ||
@@ -28,3 +28,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@lokalise/node-core": "^9.10.1", | ||
"@lokalise/node-core": "^9.14.0", | ||
"fast-equals": "^5.0.1", | ||
@@ -35,13 +35,12 @@ "toad-cache": "^3.7.0" | ||
"@types/node": "^20.11.25", | ||
"@typescript-eslint/eslint-plugin": "^7.1.1", | ||
"@typescript-eslint/parser": "^7.1.1", | ||
"@vitest/coverage-v8": "^1.4.0", | ||
"@typescript-eslint/eslint-plugin": "^7.7.1", | ||
"@typescript-eslint/parser": "^7.7.1", | ||
"@vitest/coverage-v8": "^1.5.0", | ||
"del-cli": "^5.1.0", | ||
"eslint": "^8.57.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"eslint-plugin-vitest": "0.4.1", | ||
"prettier": "^3.2.5", | ||
"typescript": "^5.4.2", | ||
"vitest": "^1.4.0" | ||
"typescript": "^5.4.5", | ||
"vitest": "^1.5.0" | ||
}, | ||
@@ -48,0 +47,0 @@ "homepage": "https://github.com/kibertoad/message-queue-toolkit", |
11
59131
Updated@lokalise/node-core@^9.14.0