From 701a479c76a5e8c1b016de2bcbbb712ccbfb1e0f Mon Sep 17 00:00:00 2001 From: thibaut severac Date: Sat, 3 Dec 2022 01:07:08 +0100 Subject: [PATCH 1/7] feat(types): add middlewares types --- index.d.ts | 84 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 14 deletions(-) diff --git a/index.d.ts b/index.d.ts index 63fceacdb..a7da8f511 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,5 @@ import { EventEmitter2 } from "eventemitter2"; +import type { Kleur } from "kleur"; declare namespace Moleculer { /** @@ -1340,21 +1341,23 @@ declare namespace Moleculer { sender: string | null; } + type packetType = | 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; } @@ -1666,6 +1669,59 @@ declare namespace Moleculer { } } + /** + * you can use multiple modifier with a dot + * e.g. `black.bgRed.bold` + */ + type KleurColor = keyof Kleur | string + + namespace Middlewares { + namespace Debugging { + type actionLoggerOptions = { + logger?: LoggerInstance, + logLevel?: LogLevels, + logParams?: boolean, + logResponse?: boolean, + logMeta?: boolean, + + folder?: string | null, + extension?: string, + + colors?: { + request?: KleurColor, + response?: KleurColor, + error?: KleurColor + }, + whitelist?: Array + } + const ActionLogger = (options?: actionLoggerOptions) => Middleware + type transitLoggerOptions = { + logger?: LoggerInstance, + logLevel?: LogLevels, + logPacketData?: boolean, + + folder?: string | null, + extension?: string, + + colors?: { + receive?: KleurColor, + send?: KleurColor + }, + + packetFilter?: Array + } + const TransitLogger = (options?: transitLoggerOptions) => Middleware + } + namespace Transmit { + type compressionOptions = { + method?: "deflate" | "deflateRaw" | "gzip", + threshold?: number | string + } + const Compression = (options?: compressionOptions) => Middleware + const Encryption = (password: string, algorithm: string, iv: string | Buffer) => Middleware + } + } + interface TransitRequest { action: string; nodeID: string; From f577ca27409510deea0f455a80eceb02990344ec Mon Sep 17 00:00:00 2001 From: thibaut severac Date: Sat, 3 Dec 2022 01:18:16 +0100 Subject: [PATCH 2/7] fix(TU): correct to match tests --- index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index a7da8f511..84a115e16 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1694,7 +1694,7 @@ declare namespace Moleculer { }, whitelist?: Array } - const ActionLogger = (options?: actionLoggerOptions) => Middleware + function ActionLogger(options?: actionLoggerOptions): Middleware; type transitLoggerOptions = { logger?: LoggerInstance, logLevel?: LogLevels, @@ -1710,15 +1710,15 @@ declare namespace Moleculer { packetFilter?: Array } - const TransitLogger = (options?: transitLoggerOptions) => Middleware + function TransitLogger(options?: transitLoggerOptions): Middleware } namespace Transmit { type compressionOptions = { method?: "deflate" | "deflateRaw" | "gzip", threshold?: number | string } - const Compression = (options?: compressionOptions) => Middleware - const Encryption = (password: string, algorithm: string, iv: string | Buffer) => Middleware + function Compression(options?: compressionOptions): Middleware + function Encryption(password: string, algorithm: string, iv: string | Buffer): Middleware } } From f4e0c7976f2532e74d4b3058fc2189628a451f94 Mon Sep 17 00:00:00 2001 From: thibaut severac Date: Sun, 11 Dec 2022 15:39:22 +0100 Subject: [PATCH 3/7] refacto(types): - remove namespaces - rename types as PascalCase --- index.d.ts | 125 +++++++++++++++++++++++++---------------------------- 1 file changed, 59 insertions(+), 66 deletions(-) diff --git a/index.d.ts b/index.d.ts index 84a115e16..296750271 100644 --- a/index.d.ts +++ b/index.d.ts @@ -180,12 +180,12 @@ declare namespace Moleculer { meta?: boolean | string[]; }; - type TracingSpanNameOption = string | ((ctx: Context) => string) + type TracingSpanNameOption = string | ((ctx: Context) => string); interface TracingOptions { enabled?: boolean; tags?: TracingActionTags | TracingEventTags; - spanName?: TracingSpanNameOption + spanName?: TracingSpanNameOption; safetyTags?: boolean; } @@ -780,7 +780,7 @@ declare namespace Moleculer { * @param params The event parameters * @param opts The event options */ - emitLocalEventHandler(eventName: string, params?: any, opts?: any): any + emitLocalEventHandler(eventName: string, params?: any, opts?: any): any; /** * Wait for the specified services to become available/registered with this broker. @@ -791,9 +791,9 @@ declare namespace Moleculer { * @param interval The time we will wait before once again checking if the service(s) are available (In milliseconds) */ waitForServices( - serviceNames: string | Array | Array, - timeout?: number, - interval?: number, + serviceNames: string | Array | Array, + timeout?: number, + interval?: number ): Promise; [name: string]: any; @@ -883,10 +883,7 @@ declare namespace Moleculer { * @param src Source schema property * @param target Target schema property */ - mergeSchemaLifecycleHandlers( - src: GenericObject, - target: GenericObject - ): GenericObject; + mergeSchemaLifecycleHandlers(src: GenericObject, target: GenericObject): GenericObject; /** * Merge unknown properties in schema @@ -902,7 +899,7 @@ declare namespace Moleculer { * @param name The name * @param version The version */ - static getVersionedFullName(name: string, version?: string|number): string; + static getVersionedFullName(name: string, version?: string | number): string; } type CheckRetryable = (err: Errors.MoleculerError | Error) => boolean; @@ -1090,10 +1087,10 @@ declare namespace Moleculer { type FallbackResponseHandler = (ctx: Context, err: Errors.MoleculerError) => Promise; type ContextParentSpan = { - id: string - traceID: string - sampled: boolean - } + id: string; + traceID: string; + sampled: boolean; + }; interface CallingOptions { timeout?: number; @@ -1341,7 +1338,8 @@ declare namespace Moleculer { sender: string | null; } - type packetType = | PACKET_UNKNOWN + type packetType = + | PACKET_UNKNOWN | PACKET_EVENT | PACKET_DISCONNECT | PACKET_DISCOVER @@ -1356,7 +1354,7 @@ declare namespace Moleculer { | PACKET_GOSSIP_HELLO; interface Packet { - type: packetType + type: packetType; target?: string; payload: PacketPayload; @@ -1451,8 +1449,8 @@ declare namespace Moleculer { meta: object | null, keys: Array | null ): string; - tryLock(key: string | Array, ttl?: number): Promise<() => Promise> - lock(key: string | Array, ttl?: number): Promise<() => Promise> + tryLock(key: string | Array, ttl?: number): Promise<() => Promise>; + lock(key: string | Array, ttl?: number): Promise<() => Promise>; } class Memory extends Base { @@ -1673,54 +1671,49 @@ declare namespace Moleculer { * you can use multiple modifier with a dot * e.g. `black.bgRed.bold` */ - type KleurColor = keyof Kleur | string - - namespace Middlewares { - namespace Debugging { - type actionLoggerOptions = { - logger?: LoggerInstance, - logLevel?: LogLevels, - logParams?: boolean, - logResponse?: boolean, - logMeta?: boolean, - - folder?: string | null, - extension?: string, - - colors?: { - request?: KleurColor, - response?: KleurColor, - error?: KleurColor - }, - whitelist?: Array - } - function ActionLogger(options?: actionLoggerOptions): Middleware; - type transitLoggerOptions = { - logger?: LoggerInstance, - logLevel?: LogLevels, - logPacketData?: boolean, - - folder?: string | null, - extension?: string, - - colors?: { - receive?: KleurColor, - send?: KleurColor - }, - - packetFilter?: Array - } - function TransitLogger(options?: transitLoggerOptions): Middleware - } - namespace Transmit { - type compressionOptions = { - method?: "deflate" | "deflateRaw" | "gzip", - threshold?: number | string - } - function Compression(options?: compressionOptions): Middleware - function Encryption(password: string, algorithm: string, iv: string | Buffer): Middleware + type KleurColor = keyof Kleur | string; + + type ActionLoggerOptions = { + logger?: LoggerInstance; + logLevel?: LogLevels; + logParams?: boolean; + logResponse?: boolean; + logMeta?: boolean; + folder?: string | null; + extension?: string; + colors?: { + request?: KleurColor; + response?: KleurColor; + error?: KleurColor; + }; + whitelist?: Array; + }; + type TransitLoggerOptions = { + logger?: LoggerInstance; + logLevel?: LogLevels; + logPacketData?: boolean; + folder?: string | null; + extension?: string; + colors?: { + receive?: KleurColor; + send?: KleurColor; + }; + packetFilter?: Array; + }; + type CompressionOptions = { + method?: "deflate" | "deflateRaw" | "gzip"; + threshold?: number | string; + }; + export const Middlewares = { + Debugging: { + ActionLogger(options?: ActionLoggerOptions): Middleware {}, + TransitLogger(options?: TransitLoggerOptions): Middleware {} + }, + Transmit: { + Compression(options?: CompressionOptions): Middleware {}, + Encryption(password: string, algorithm: string, iv: string | Buffer): Middleware {} } - } + }; interface TransitRequest { action: string; From 9b51de96187be163c357a937e8aebfa38bc6468e Mon Sep 17 00:00:00 2001 From: thibaut severac Date: Sun, 11 Dec 2022 16:42:50 +0100 Subject: [PATCH 4/7] fix(types): - fix TU --- index.d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/index.d.ts b/index.d.ts index 296750271..999cd6c71 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1704,15 +1704,15 @@ declare namespace Moleculer { method?: "deflate" | "deflateRaw" | "gzip"; threshold?: number | string; }; - export const Middlewares = { + export const Middlewares: { Debugging: { - ActionLogger(options?: ActionLoggerOptions): Middleware {}, - TransitLogger(options?: TransitLoggerOptions): Middleware {} - }, + ActionLogger(options?: ActionLoggerOptions): Middleware; + TransitLogger(options?: TransitLoggerOptions): Middleware; + }; Transmit: { - Compression(options?: CompressionOptions): Middleware {}, - Encryption(password: string, algorithm: string, iv: string | Buffer): Middleware {} - } + Compression(options?: CompressionOptions): Middleware; + Encryption(password: string, algorithm: string, iv: string | Buffer): Middleware; + }; }; interface TransitRequest { From dc472857a34cacaa8750ddd977f31201e6947a36 Mon Sep 17 00:00:00 2001 From: thibaut severac Date: Sun, 19 Mar 2023 18:17:56 +0100 Subject: [PATCH 5/7] refacto(types): - back to namespaces - correct PascalCase --- index.d.ts | 88 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/index.d.ts b/index.d.ts index 2031df665..8dc6a971b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1343,7 +1343,7 @@ declare namespace Moleculer { sender: string | null; } - type packetType = + type PacketType = | PACKET_UNKNOWN | PACKET_EVENT | PACKET_DISCONNECT @@ -1359,7 +1359,7 @@ declare namespace Moleculer { | PACKET_GOSSIP_HELLO; interface Packet { - type: packetType; + type: PacketType; target?: string; payload: PacketPayload; @@ -1678,47 +1678,49 @@ declare namespace Moleculer { */ type KleurColor = keyof Kleur | string; - type ActionLoggerOptions = { - logger?: LoggerInstance; - logLevel?: LogLevels; - logParams?: boolean; - logResponse?: boolean; - logMeta?: boolean; - folder?: string | null; - extension?: string; - colors?: { - request?: KleurColor; - response?: KleurColor; - error?: KleurColor; - }; - whitelist?: Array; - }; - type TransitLoggerOptions = { - logger?: LoggerInstance; - logLevel?: LogLevels; - logPacketData?: boolean; - folder?: string | null; - extension?: string; - colors?: { - receive?: KleurColor; - send?: KleurColor; - }; - packetFilter?: Array; - }; - type CompressionOptions = { - method?: "deflate" | "deflateRaw" | "gzip"; - threshold?: number | string; - }; - export const Middlewares: { - Debugging: { - ActionLogger(options?: ActionLoggerOptions): Middleware; - TransitLogger(options?: TransitLoggerOptions): Middleware; - }; - Transmit: { - Compression(options?: CompressionOptions): Middleware; - Encryption(password: string, algorithm: string, iv: string | Buffer): Middleware; - }; - }; + namespace Middlewares { + namespace Debugging { + interface ActionLoggerOptions { + logger?: LoggerInstance; + logLevel?: LogLevels; + logParams?: boolean; + logResponse?: boolean; + logMeta?: boolean; + folder?: string | null; + extension?: string; + colors?: { + request?: KleurColor; + response?: KleurColor; + error?: KleurColor; + }; + whitelist?: string[]; + } + interface TransitLoggerOptions { + logger?: LoggerInstance; + logLevel?: LogLevels; + logPacketData?: boolean; + folder?: string | null; + extension?: string; + colors?: { + receive?: KleurColor; + send?: KleurColor; + }; + packetFilter?: Packet.packetType[]; + } + + const ActionLogger = (options?: ActionLoggerOptions) => Middleware; + const TransitLogger = (options?: TransitLoggerOptions) => Middleware; + } + namespace Transmit { + interface CompressionOptions { + method?: "deflate" | "deflateRaw" | "gzip"; + threshold?: number | string; + } + const Compression = (options?: CompressionOptions) => Middleware; + const Encryption = (password: string, algorithm: string, iv: string | Buffer) => Middleware; + } + + } interface TransitRequest { action: string; From 67d0ee72aa9afb0be16a507897b24099f67f3a07 Mon Sep 17 00:00:00 2001 From: thibaut severac Date: Sun, 12 Nov 2023 22:39:49 +0100 Subject: [PATCH 6/7] remove unwanted changes --- index.d.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/index.d.ts b/index.d.ts index cd179e9c2..3911d50ab 100644 --- a/index.d.ts +++ b/index.d.ts @@ -169,18 +169,18 @@ declare namespace Moleculer { type TracingActionTags = | TracingActionTagsFuncType | { - params?: boolean | string[]; - meta?: boolean | string[]; - response?: boolean | string[]; - }; + params?: boolean | string[]; + meta?: boolean | string[]; + response?: boolean | string[]; + }; type TracingEventTagsFuncType = (ctx: Context) => GenericObject; type TracingEventTags = | TracingEventTagsFuncType | { - params?: boolean | string[]; - meta?: boolean | string[]; - }; + params?: boolean | string[]; + meta?: boolean | string[]; + }; type TracingSpanNameOption = string | ((ctx: Context) => string); @@ -1020,8 +1020,8 @@ declare namespace Moleculer { internalServices?: | boolean | { - [key: string]: Partial; - }; + [key: string]: Partial; + }; internalMiddlewares?: boolean; dependencyInterval?: number; @@ -2027,11 +2027,11 @@ declare namespace Moleculer { }; /* @private */ interface MoleculerMiddlewares { + Debugging: { + ActionLogger: (options?: ActionLoggerOptions) => Middleware; + TransitLogger: (options?: TransitLoggerOptions) => Middleware; + }; Transmit: { - Debugging: { - ActionLogger(options?: ActionLoggerOptions): Middleware; - TransitLogger(options?: TransitLoggerOptions): Middleware; - }; /** * Encrypts the Transporter payload * @param key The key to use for encryption From 0ff74937f232e521f9738451fe664fb20aa0d3a2 Mon Sep 17 00:00:00 2001 From: thibaut severac Date: Sun, 12 Nov 2023 22:47:58 +0100 Subject: [PATCH 7/7] correct merge --- index.d.ts | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/index.d.ts b/index.d.ts index 3911d50ab..832a90ed5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1334,21 +1334,23 @@ declare namespace Moleculer { sender: string | null; } + type PacketType = + | 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; } @@ -2023,7 +2025,7 @@ declare namespace Moleculer { receive?: KleurColor; send?: KleurColor; }; - packetFilter?: Array; + packetFilter?: Array; }; /* @private */ interface MoleculerMiddlewares {