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

Update index.d.ts with Middlewares.Transmit type definitions #1246

Merged
merged 3 commits into from
Sep 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 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'
import type { Worker } from "cluster";

declare namespace Moleculer {
Expand Down Expand Up @@ -1987,6 +1988,57 @@ declare namespace Moleculer {
*/
start(args: string[]): Promise<void>;
}

/* @private */
interface MoleculerMiddlewares {
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,
}
}
const Middlewares: MoleculerMiddlewares
}

export = Moleculer;
Loading