Skip to content

Commit

Permalink
imp(index.d.ts): add Middlewares declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0a0d committed Sep 22, 2023
1 parent 4b72d3f commit 6fb089d
Showing 1 changed file with 59 additions and 9 deletions.
68 changes: 59 additions & 9 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 { BinaryLike, CipherCCMTypes, CipherGCMTypes, CipherKey, CipherOCBTypes } from 'crypto'

declare namespace Moleculer {
/**
Expand Down Expand Up @@ -166,18 +167,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);

Expand Down Expand Up @@ -1016,8 +1017,8 @@ declare namespace Moleculer {
internalServices?:
| boolean
| {
[key: string]: Partial<ServiceSchema>;
};
[key: string]: Partial<ServiceSchema>;
};
internalMiddlewares?: boolean;

dependencyInterval?: number;
Expand Down Expand Up @@ -1834,6 +1835,55 @@ declare namespace Moleculer {
function makeDirs(path: string): void;
function parseByteString(value: string): number;
}

const Middlewares = {
Transmit: {
/**
* Encrypts the Transporter payload
* @param key The key to use for encryption
* @param [algorithm] The algorithm to use for encryption. Default is aes-256-cbc
* @param [iv] The initialization vector to use for encryption. Optional
* @example // moleculer.config.js
* const crypto = require("crypto");
* const { Middlewares } = require("moleculer");
* const initVector = crypto.randomBytes(16);
*
* module.exports = {
* middlewares: [
* Middlewares.Transmit.Encryption("secret-password", "aes-256-cbc", initVector) // "aes-256-cbc" is the default
* ]
* };
*/
Encryption: (key: CipherKey, algorithm?: CipherCCMTypes|CipherOCBTypes|CipherGCMTypes|string, iv?: BinaryLike | null)=> Middleware,
Compression: (opts?: {
/**
* @default deflate
*/
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.
* Threshold should be a number of bytes or a string like 100kb, 4mb, etc. Accepted units are:
* - kb, for kilobytes
* - mb, for megabytes
* - gb, for gigabytes
* - tb, for terabytes
* - pb, for petabytes
* @default 1kb
* @example // moleculer.config.js
* const { Middlewares } = require("moleculer");
*
* // Create broker
* module.exports = {
* middlewares: [
* Middlewares.Transmit.Compression("deflate") // or "deflateRaw" or "gzip"
* ]
* };
*/
threshold?: number | string
}) => Middleware,
},
}
}

export = Moleculer;

0 comments on commit 6fb089d

Please sign in to comment.