Skip to content

Commit

Permalink
Merge pull request moleculerjs#1286 from shawnmcknight/improve-error-…
Browse files Browse the repository at this point in the history
…handler-types

Improve broker error handler types
  • Loading branch information
icebob authored Jun 13, 2024
2 parents ab3372d + 2294b96 commit 4f7787a
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { EventEmitter2 } from "eventemitter2";
import type { BinaryLike, CipherCCMTypes, CipherGCMTypes, CipherKey, CipherOCBTypes } from 'crypto'
import type { BinaryLike, CipherCCMTypes, CipherGCMTypes, CipherKey, CipherOCBTypes } from "crypto";
import type { Worker } from "cluster";

declare namespace Moleculer {
Expand Down Expand Up @@ -720,9 +720,7 @@ declare namespace Moleculer {
version?: string | number;
}

type ServiceSyncLifecycleHandler<S = ServiceSettingSchema, T = Service<S>> = (
this: T
) => void;
type ServiceSyncLifecycleHandler<S = ServiceSettingSchema, T = Service<S>> = (this: T) => void;
type ServiceAsyncLifecycleHandler<S = ServiceSettingSchema, T = Service<S>> = (
this: T
) => void | Promise<void>;
Expand Down Expand Up @@ -975,6 +973,24 @@ declare namespace Moleculer {
options?: GenericObject;
}

interface BrokerErrorHandlerInfoAction {
ctx: Context;
service: Context["service"];
action: Context["action"];
}
interface BrokerErrorHandlerInfoBroker {
actionName: string;
params: unknown;
opts: CallingOptions;
nodeId?: string;
}
type BrokerErrorHandlerInfo = BrokerErrorHandlerInfoAction | BrokerErrorHandlerInfoBroker;
type BrokerErrorHandler = (
this: ServiceBroker,
err: Error,
info: BrokerErrorHandlerInfo
) => void;

type BrokerSyncLifecycleHandler = (broker: ServiceBroker) => void;
type BrokerAsyncLifecycleHandler = (broker: ServiceBroker) => void | Promise<void>;

Expand Down Expand Up @@ -1008,7 +1024,7 @@ declare namespace Moleculer {

uidGenerator?: () => string;

errorHandler?: ((err: Error, info: any) => void) | null;
errorHandler?: BrokerErrorHandler;

cacher?: boolean | Cacher | string | GenericObject | null;
serializer?: Serializer | string | GenericObject | null;
Expand Down Expand Up @@ -1201,7 +1217,7 @@ declare namespace Moleculer {
start(): Promise<void>;
stop(): Promise<void>;

errorHandler(err: Error, info: GenericObject): void;
errorHandler(err: Error, info: BrokerErrorHandlerInfo): void;

wrapMethod(
method: string,
Expand Down Expand Up @@ -1844,7 +1860,6 @@ declare namespace Moleculer {
* Parsed CLI flags
*/
interface RunnerFlags {

/**
* Path to load configuration from a file
*/
Expand Down Expand Up @@ -1884,7 +1899,6 @@ declare namespace Moleculer {
* File mask for loading services
*/
mask?: string;

}

/**
Expand Down Expand Up @@ -2011,12 +2025,16 @@ declare namespace Moleculer {
* ]
* };
*/
Encryption: (key: CipherKey, algorithm?: CipherCCMTypes|CipherOCBTypes|CipherGCMTypes|string, iv?: BinaryLike | null)=> Middleware,
Encryption: (
key: CipherKey,
algorithm?: CipherCCMTypes | CipherOCBTypes | CipherGCMTypes | string,
iv?: BinaryLike | null
) => Middleware;
Compression: (opts?: {
/**
* @default deflate
*/
method?: 'gzip' | 'deflate' | 'deflateRaw'
method?: "gzip" | "deflate" | "deflateRaw";
/**
* Compression middleware reduces the size of the messages that go through the transporter module.
* This middleware uses built-in Node zlib lib.
Expand All @@ -2037,11 +2055,11 @@ declare namespace Moleculer {
* ]
* };
*/
threshold?: number | string
}) => Middleware,
}
threshold?: number | string;
}) => Middleware;
};
}
const Middlewares: MoleculerMiddlewares
const Middlewares: MoleculerMiddlewares;
}

export = Moleculer;

0 comments on commit 4f7787a

Please sign in to comment.