Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(types): add middlewares types #1161

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
80 changes: 66 additions & 14 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { EventEmitter2 } from "eventemitter2";
import type { Kleur } from "kleur";

declare namespace Moleculer {
/**
Expand Down Expand Up @@ -1342,21 +1343,24 @@ declare namespace Moleculer {
sender: string | null;
}

type packetType =
thib3113 marked this conversation as resolved.
Show resolved Hide resolved
| PACKET_UNKNOWN
| PACKET_EVENT
| PACKET_DISCONNECT
| PACKET_DISCOVER
| PACKET_INFO
| PACKET_HEARTBEAT
| PACKET_REQUEST
| PACKET_PING
| PACKET_PONG
| PACKET_RESPONSE
| PACKET_GOSSIP_REQ
| PACKET_GOSSIP_RES
| PACKET_GOSSIP_HELLO;

interface Packet {
type:
| PACKET_UNKNOWN
| PACKET_EVENT
| PACKET_DISCONNECT
| PACKET_DISCOVER
| PACKET_INFO
| PACKET_HEARTBEAT
| PACKET_REQUEST
| PACKET_PING
| PACKET_PONG
| PACKET_RESPONSE
| PACKET_GOSSIP_REQ
| PACKET_GOSSIP_RES
| PACKET_GOSSIP_HELLO;
type: packetType;

target?: string;
payload: PacketPayload;
}
Expand Down Expand Up @@ -1668,6 +1672,54 @@ declare namespace Moleculer {
}
}

/**
* you can use multiple modifier with a dot
* e.g. `black.bgRed.bold`
*/
type KleurColor = keyof Kleur | string;
thib3113 marked this conversation as resolved.
Show resolved Hide resolved

type ActionLoggerOptions = {
thib3113 marked this conversation as resolved.
Show resolved Hide resolved
logger?: LoggerInstance;
logLevel?: LogLevels;
logParams?: boolean;
logResponse?: boolean;
logMeta?: boolean;
folder?: string | null;
extension?: string;
colors?: {
request?: KleurColor;
response?: KleurColor;
error?: KleurColor;
};
whitelist?: Array<string>;
thib3113 marked this conversation as resolved.
Show resolved Hide resolved
};
type TransitLoggerOptions = {
logger?: LoggerInstance;
logLevel?: LogLevels;
logPacketData?: boolean;
folder?: string | null;
extension?: string;
colors?: {
receive?: KleurColor;
send?: KleurColor;
};
packetFilter?: Array<Packets.packetType>;
thib3113 marked this conversation as resolved.
Show resolved Hide resolved
};
type CompressionOptions = {
method?: "deflate" | "deflateRaw" | "gzip";
threshold?: number | string;
};
export const Middlewares: {
thib3113 marked this conversation as resolved.
Show resolved Hide resolved
Debugging: {
ActionLogger(options?: ActionLoggerOptions): Middleware;
TransitLogger(options?: TransitLoggerOptions): Middleware;
};
Transmit: {
Compression(options?: CompressionOptions): Middleware;
Encryption(password: string, algorithm: string, iv: string | Buffer): Middleware;
thib3113 marked this conversation as resolved.
Show resolved Hide resolved
};
};

interface TransitRequest {
action: string;
nodeID: string;
Expand Down