-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Better types and handling for different FormData implementat…
…ions
- Loading branch information
1 parent
4137ca5
commit 906723a
Showing
26 changed files
with
25,508 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { Readable } from 'stream'; | ||
import { CustomFile, CustomFileData } from '../../Types'; | ||
import { AttachmentInfo, StreamValue } from '../../Types/Common/Attachments'; | ||
declare class BlobFromStream { | ||
private _stream; | ||
size: number; | ||
constructor(stream: Readable, size: number); | ||
stream(): Readable; | ||
get [Symbol.toStringTag](): string; | ||
} | ||
declare class AttachmentsHandler { | ||
private getAttachmentOptions; | ||
private getFileInfo; | ||
private getCustomFileInfo; | ||
private getBufferInfo; | ||
isStream(data: unknown): data is StreamValue; | ||
isCustomFile(obj: unknown): obj is CustomFile; | ||
isBrowserFile(obj: unknown): obj is File; | ||
isBuffer(data: unknown): data is Buffer; | ||
getAttachmentInfo(attachment: CustomFile | File | string | CustomFileData): AttachmentInfo; | ||
convertToFDexpectedShape(userProvidedValue: CustomFile | File | string | CustomFileData): string | Blob | Buffer | NodeJS.ReadableStream | (CustomFile & StreamValue); | ||
getBlobFromStream(stream: Readable, size: number): BlobFromStream; | ||
} | ||
export default AttachmentsHandler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import * as NodeFormData from 'form-data'; | ||
import { InputFormData } from '../../Types/Common'; | ||
import { FormDataInput, InputFormData } from '../../Types/Common'; | ||
import { MimeMessage } from '../../Types'; | ||
declare class FormDataBuilder { | ||
private FormDataConstructor; | ||
private fileKeys; | ||
private attachmentsHandler; | ||
constructor(FormDataConstructor: InputFormData); | ||
createFormData(data: any): NodeFormData | FormData; | ||
private isFormDataPackage; | ||
private getAttachmentOptions; | ||
createFormData(data: FormDataInput): NodeFormData | FormData; | ||
private addMimeDataToFD; | ||
isMIME(data: unknown): data is MimeMessage; | ||
private isFormDataPackage; | ||
private isMessageAttachment; | ||
private addFilesToFD; | ||
private isStream; | ||
private addCommonPropertyToFD; | ||
} | ||
export default FormDataBuilder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export type NodePipeFunction = (destination: WritableStream, options?: { | ||
end?: boolean; | ||
}) => void; | ||
export type BrowserPipeFunction = (destination: WritableStream) => void; | ||
export type StreamValue = { | ||
pipe: NodePipeFunction | BrowserPipeFunction; | ||
}; | ||
export type AttachmentInfo = { | ||
filename?: string; | ||
contentType?: string; | ||
knownLength?: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import * as NodeFormData from 'form-data'; | ||
import { FormDataInputValue } from '../Messages'; | ||
export type FormDataOptions = { | ||
[key: string]: any; | ||
[key: string]: NodeFormData; | ||
}; | ||
export type InputFormData = { | ||
new (options?: HTMLFormElement | FormDataOptions): NodeFormData | FormData; | ||
new (form?: HTMLFormElement | undefined, submitter?: HTMLElement | null | undefined): FormData; | ||
} | { | ||
new (options?: FormDataOptions): NodeFormData; | ||
}; | ||
export type FormDataInput = { | ||
[key: string]: FormDataInputValue; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.