import UppyUtils = require('@uppy/utils') declare module Uppy { // Utility types type OmitKey = Pick> // These are defined in @uppy/utils instead of core so it can be used there without creating import cycles export type UppyFile< TMeta extends IndexedObject = {}, TBody extends IndexedObject = {} > = UppyUtils.UppyFile export type Store = UppyUtils.Store export type InternalMetadata = UppyUtils.InternalMetadata interface IndexedObject { [key: string]: T [key: number]: T } interface UploadedUppyFile extends UppyFile { uploadURL: string } interface FailedUppyFile extends UppyFile { error: string } // Replace the `meta` property type with one that allows omitting internal metadata; addFile() will add that type UppyFileWithoutMeta = OmitKey< UppyFile, 'meta' > interface AddFileOptions< TMeta = IndexedObject, TBody = IndexedObject > extends Partial> { // `.data` is the only required property here. data: Blob | File meta?: Partial & TMeta } interface PluginOptions { id?: string } interface DefaultPluginOptions extends PluginOptions { [prop: string]: any } type PluginTarget = string | Element | typeof Plugin class Plugin { id: string uppy: Uppy type: string constructor(uppy: Uppy, opts?: TOptions) setOptions(update: Partial): void getPluginState(): object setPluginState(update: IndexedObject): object update(state?: object): void mount(target: PluginTarget, plugin: typeof Plugin): void render(state: object): void addTarget(plugin: TPlugin): void unmount(): void install(): void uninstall(): void } type LocaleStrings = { [K in TNames]?: string | { [n: number]: string } } interface Locale { strings: LocaleStrings pluralize?: (n: number) => number } interface Restrictions { maxFileSize?: number | null minFileSize?: number | null maxTotalFileSize?: number | null maxNumberOfFiles?: number | null minNumberOfFiles?: number | null allowedFileTypes?: string[] | null } interface UppyOptions = {}> { id?: string autoProceed?: boolean allowMultipleUploads?: boolean debug?: boolean restrictions?: Restrictions meta?: TMeta onBeforeFileAdded?: ( currentFile: UppyFile, files: { [key: string]: UppyFile } ) => UppyFile | boolean | undefined onBeforeUpload?: (files: { [key: string]: UppyFile }) => { [key: string]: UppyFile } | boolean locale?: Locale store?: Store infoTimeout?: number } interface UploadResult< TMeta extends IndexedObject = {}, TBody extends IndexedObject = {} > { successful: UploadedUppyFile[] failed: FailedUppyFile[] } interface State< TMeta extends IndexedObject = {}, TBody extends IndexedObject = {} > extends IndexedObject { capabilities?: { resumableUploads?: boolean } currentUploads: {} error?: string files: { [key: string]: | UploadedUppyFile | FailedUppyFile } info?: { isHidden: boolean type: string message: string details: string } plugins?: IndexedObject totalProgress: number } type LogLevel = 'info' | 'warning' | 'error' /** Enable the old, untyped `uppy.use()` signature. */ type LooseTypes = 'loose' /** Disable the old, untyped `uppy.use()` signature. */ type StrictTypes = 'strict' type TypeChecking = LooseTypes | StrictTypes // This hack accepts _any_ string for `Event`, but also tricks VSCode and friends into providing autocompletions // for the names listed. https://github.com/microsoft/TypeScript/issues/29729#issuecomment-505826972 type LiteralUnion = T | (U & { }); type Event = LiteralUnion<'file-added' | 'file-removed' | 'upload' | 'upload-progress' | 'upload-success' | 'complete' | 'error' | 'upload-error' | 'upload-retry' | 'info-visible' | 'info-hidden' | 'cancel-all' | 'restriction-failed' | 'reset-progress'>; type UploadHandler = (fileIDs: string[]) => Promise class Uppy { constructor(opts?: UppyOptions) on = {}>( event: 'upload-success', callback: (file: UppyFile, body: any, uploadURL: string) => void ): this on = {}>( event: 'complete', callback: (result: UploadResult) => void ): this on(event: Event, callback: (...args: any[]) => void): this off(event: Event, callback: (...args: any[]) => void): this /** * For use by plugins only. */ emit(event: Event, ...args: any[]): void updateAll(state: object): void setOptions(update: Partial): void setState(patch: object): void getState = {}>(): State readonly state: State setFileState(fileID: string, state: object): void resetProgress(): void addPreProcessor(fn: UploadHandler): void removePreProcessor(fn: UploadHandler): void addPostProcessor(fn: UploadHandler): void removePostProcessor(fn: UploadHandler): void addUploader(fn: UploadHandler): void removeUploader(fn: UploadHandler): void setMeta = {}>(data: TMeta): void setFileMeta = {}>( fileID: string, data: TMeta ): void getFile< TMeta extends IndexedObject = {}, TBody extends IndexedObject = {} >(fileID: string): UppyFile getFiles< TMeta extends IndexedObject = {}, TBody extends IndexedObject = {} >(): Array> addFile = {}>( file: AddFileOptions ): void removeFile(fileID: string): void pauseResume(fileID: string): boolean pauseAll(): void resumeAll(): void retryAll = {}>(): Promise> cancelAll(): void retryUpload = {}>(fileID: string): Promise> reset(): void getID(): string /** * Add a plugin to this Uppy instance. */ use>( pluginClass: new (uppy: this, opts: TOptions) => TInstance, opts?: TOptions ): this /** * Fallback `.use()` overload with unchecked plugin options. * * This does not validate that the options you pass in are correct. * We recommend disabling this overload by using the `Uppy` type, instead of the plain `Uppy` type, to enforce strict typechecking. * This overload will be removed in Uppy 2.0. */ use(pluginClass: TUseStrictTypes extends StrictTypes ? never : new (uppy: this, opts: any) => Plugin, opts?: object): this getPlugin(name: string): Plugin iteratePlugins(callback: (plugin: Plugin) => void): void removePlugin(instance: Plugin): void close(): void info( message: string | { message: string; details: string }, type?: LogLevel, duration?: number ): void hideInfo(): void log(msg: string, type?: LogLevel): void /** * Obsolete: do not use. This method does nothing and will be removed in a future release. */ run(): this restore = {}>( uploadID: string ): Promise> addResultData(uploadID: string, data: object): void upload = {}>(): Promise> } } /** * Create an uppy instance. * * By default, Uppy's `.use(Plugin, options)` method uses loose type checking. * In Uppy 2.0, the `.use()` method will get a stricter type signature. You can enable strict type checking of plugin classes and their options today by using: * ```ts * const uppy = Uppy() * ``` * Make sure to also declare any variables and class properties with the `StrictTypes` parameter: * ```ts * private uppy: Uppy; * ``` */ declare function Uppy(opts?: Uppy.UppyOptions): Uppy.Uppy export = Uppy