chore: add jsdoc comments

This commit is contained in:
Zack Schuster 2022-05-06 17:37:02 -07:00
parent 8b33fed186
commit 87b51595dc
3 changed files with 67 additions and 3 deletions

View File

@ -179,8 +179,16 @@ export class SMTPClient {
* @returns {void}
*/
protected _connect(stack: MessageStack) {
/**
* @param {Error | null} err callback error
* @returns {void}
*/
const connect = (err: Error | null) => {
if (!err) {
/**
* @param {Error | null} err callback error
* @returns {void}
*/
const begin = (err: Error | null) => {
if (!err) {
this.ready = true;

View File

@ -101,6 +101,7 @@ export class SMTPConnection extends EventEmitter {
AUTH_METHODS.XOAUTH2,
];
/** @type {SMTPState} */
protected _state: 0 | 1 | 2 = SMTPState.NOTCONNECTED;
protected _secure = false;
protected loggedin = false;
@ -198,7 +199,7 @@ export class SMTPConnection extends EventEmitter {
/**
* @public
* @returns {0 | 1 | 2} the current state
* @returns {SMTPState} the current state
*/
public state() {
return this._state;
@ -716,6 +717,11 @@ export class SMTPConnection extends EventEmitter {
const domain = options?.domain || this.domain;
/**
* @param {Error | null} err err
* @param {unknown} data data
* @returns {void}
*/
const initiate = (err: Error | null | undefined, data: unknown) => {
if (err) {
callback(err);
@ -793,6 +799,15 @@ export class SMTPConnection extends EventEmitter {
);
};
/**
* @param {Error | SMTPError | null} err err
* @param {(
* string |
* { code: (string | number), data: string, message: string } |
* null
* )} [data] data
* @returns {void}
*/
const response: SMTPCommandCallback = (err, data) => {
if (err) {
failed(err, data);
@ -802,6 +817,16 @@ export class SMTPConnection extends EventEmitter {
}
};
/**
* @param {Error | SMTPError | null} err err
* @param {(
* string |
* { code: (string | number), data: string, message: string } |
* null
* )} data data
* @param {string} msg message
* @returns {void}
*/
const attempt: SMTPCommandCallback = (err, data, msg) => {
if (err) {
failed(err, data);
@ -818,6 +843,15 @@ export class SMTPConnection extends EventEmitter {
}
};
/**
* @param {Error | SMTPError | null} err err
* @param {(
* string |
* { code: (string | number), data: string, message: string } |
* null
* )} [data] data
* @returns {void}
*/
const attemptUser: SMTPCommandCallback = (err, data) => {
if (err) {
failed(err, data);

View File

@ -268,6 +268,10 @@ export class Message {
str.on('error', (err) => callback(err, buffer));
}
/**
* @public
* @returns {Promise<string>} promise that resolves to the read result
*/
public readAsync() {
return new Promise<string>((resolve, reject) => {
this.read((err, buffer) => {
@ -282,10 +286,11 @@ export class Message {
}
class MessageStream extends Stream {
readable = true;
paused = false;
/** @type {Buffer | null} */
buffer: Buffer | null = Buffer.alloc(MIMECHUNK * 24 * 7);
bufferIndex = 0;
paused = false;
readable = true;
/**
* @param {Message} message the message to stream
@ -400,6 +405,11 @@ class MessageStream extends Stream {
}
};
/**
* @param {MessageAttachment} attachment attachment
* @param {function((NodeJS.ErrnoException | null)): void} next next
* @returns {void}
*/
const outputFile = (
attachment: MessageAttachment,
next: (err: NodeJS.ErrnoException | null) => void
@ -505,6 +515,11 @@ class MessageStream extends Stream {
}
};
/**
* @param {MessageAttachment} attachment attachment
* @param {function(): void} callback the function to call
* @returns {void}
*/
const outputAttachment = (
attachment: MessageAttachment,
callback: () => void
@ -548,6 +563,9 @@ class MessageStream extends Stream {
}
};
/**
* @returns {void}
*/
const outputMixed = () => {
const boundary = generateBoundary();
output(
@ -656,6 +674,10 @@ class MessageStream extends Stream {
}
};
/**
* @param {Error} [err] err
* @returns {void}
*/
const close = (err?: Error) => {
if (err) {
this.emit('error', err);