Skip to content

Commit

Permalink
Multipart.d.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNorthMemory committed May 20, 2021
1 parent 3727ede commit 7cc2d00
Showing 1 changed file with 134 additions and 12 deletions.
146 changes: 134 additions & 12 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference types="node" />
import { ReadStream } from "fs";
import { Readable } from "stream";
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";

Expand Down Expand Up @@ -380,6 +381,48 @@ export namespace WechatpayAxiosPlugin {
* .getBuffer();
*/
class Multipart extends Readable {
/**
* @protected
* @memberof Multipart#
* @prop {object<string,string>} mimeTypes - Built-in mime-type mapping
*/
protected mimeTypes: object;
/**
* @readonly
* @memberof Multipart#
* @prop {buffer} dashDash - Double `dash` buffer
*/
readonly dashDash: Buffer;
/**
* @readonly
* @memberof Multipart#
* @prop {buffer} boundary - The boundary buffer.
*/
readonly boundary: Buffer;
/**
* @readonly
* @memberof Multipart#
* @prop {buffer} EMPTY - An empty buffer
*/
readonly EMPTY: Buffer;
/**
* @readonly
* @memberof Multipart#
* @prop {buffer} CRLF - Double `dash` buffer
*/
readonly CRLF: Buffer;
/**
* @protected
* @memberof Multipart#
* @prop {buffer[]} data - The Multipart's data storage
*/
protected data: Buffer[] | ReadStream[];
/**
* @protected
* @memberof Multipart#
* @prop {Array<string, number>} indices - The entities' value indices whose were in {@link Multipart#data}
*/
protected indices: any;
/**
* To retrieve the {@link Miltipart#data} buffer
*
Expand All @@ -403,7 +446,7 @@ export namespace WechatpayAxiosPlugin {
*
* @returns {Multipart} - The `Multipart` class instance self
*/
appendMimeTypes(things: any): this;
appendMimeTypes(things: object): this;
/**
* Append data wrapped by {@link Multipart#boundary}
*
Expand All @@ -413,15 +456,77 @@ export namespace WechatpayAxiosPlugin {
*
* @returns {Multipart} - The `Multipart` class instance self
*/
append(field: string, value: string | any, filename?: string): this;
entries(): void;
set(): void;
get(): void;
getAll(): void;
has(): void;
delete(): void;
keys(): void;
values(): void;
append(field: string, value: string | Buffer | ReadStream, filename?: string): this;
/**
* Formed a named value, a filename reported to the server, when a Buffer or FileStream is passed as the second parameter.
*
* @param {string} name - The field name
* @param {string|Buffer|ReadStream} value - The value
* @param {string} [filename] - Optional filename, when provided, then append the `Content-Type` after of the `Content-Disposition`
*
* @returns {array<Buffer[]>} - The part of data
*/
formed(name: string, value: string | Buffer | ReadStream, filename?: string): Buffer[];
/**
* To go through all key/value pairs contained in this {@link Multipart#data} instance
*
* @return {Array<string, Buffer|ReadStream>} - An IteratorLike key/value pairs.
*/
entries(): Array<Buffer[]>;
/**
* Sets a new value for an existing key inside a {@link Multipart#data} instance, or adds the key/value if it does not already exist.
*
* @param {string} name - The field name
* @param {string|Buffer|ReadStream} value - The value
* @param {string} [filename] - Optional filename, when provided, then append the `Content-Type` after of the `Content-Disposition`
*
* @returns {this} - The Multipart instance
*/
set(name: string, value: string | Buffer | ReadStream, filename?: string): this;
/**
* Returns the first value associated with a given key from within a {@link Multipart#data} instance
*
* @param {string} name - The field name
*
* @return {Buffer|ReadStream} value - The value
*/
get(name: string): Buffer | ReadStream;
/**
* Returns all values associated with a given key from within a {@link Multipart#data} instance
*
* @param {string} name - The field name
*
* @return {Buffer|ReadStream} value(s) - The value(s)
*/
getAll(name: string): Buffer[] | ReadStream[];
/**
* Returns a boolean stating whether a {@link Multipart#data} instance contains a certain key.
*
* @param {string} name - The field name
*
* @return {boolean} - True for contains
*/
has(name: string): boolean;
/**
* Deletes a key and its value(s) from a {@link Multipart#data} instance
*
* @param {string} name - The field name
*
* @returns {this} - The Multipart instance
*/
delete(name: string): this;
/**
* To go through all keys contained in {@link Multipart#data} instance
*
* @return {Array<string>} - An IteratorLike key array.
*/
keys(): string[];
/**
* To go through all values contained in {@link Multipart#data} instance
*
* @return {Array<Buffer|ReadStream>} - An IteratorLike value array.
*/
values(): Buffer[] | ReadStream[];
/**
* @returns {string} - FormData string
*/
Expand All @@ -435,10 +540,27 @@ export namespace WechatpayAxiosPlugin {
*/
toString(): string;
/**
* To fetch data from the underlying resource.
* @private
* The WeChatPay APIv3' specific, the `meta` JSON
*
* @return {object<string, string>|null} - The `meta{filename,sha1}` information.
*/
toJSON(): object | null;
_read(): void;
/**
* Pushing {@link Multipart#data} into the readable BufferList
*
* @returns {Promise<this>} - The Multipart instance
*/
flowing(): Promise<this>;
/**
* Attaches a Writable stream to the {@link Multipart} instance
*
* @param {NodeJS.WritableStream} destination - The destination for writing data
* @param {object} [options] - Pipe options
* @param {boolean} [options.end = true] - End the writer when the reader ends. Default: true.
* @returns {stream.Writable} - The destination, allowing for a chain of pipes
*/
pipe<T extends NodeJS.WritableStream>(destination: T, options?: {end?: boolean}): T;
}

/**
Expand Down

0 comments on commit 7cc2d00

Please sign in to comment.