Browse Source

Split up typescript definitions.

Also add the type tests to our `npm test` script.
Renée Kooi 6 years ago
parent
commit
a0fd2d3d29

+ 2 - 2
package.json

@@ -122,8 +122,8 @@
     "test:acceptance": "./bin/endtoend-build && wdio test/endtoend/wdio.remote.conf.js",
     "test:acceptance:local": "./bin/endtoend-build && wdio test/endtoend/wdio.local.conf.js",
     "test:unit": "jest --testPathPattern=./src --coverage",
-    "test:type": "tsc -p .",
-    "test": "npm run lint && npm run test:unit",
+    "test:type": "tsc -p packages/uppy/types",
+    "test": "npm run lint && npm run test:unit && npm run test:type",
     "test:watch": "jest --watch --testPathPattern=src",
     "travis:deletecache": "travis cache --delete",
     "watch:css": "onchange 'src/scss/**/*.scss' --initial --verbose -- npm run build:css",

+ 21 - 0
packages/@uppy/aws-s3/types/index.d.ts

@@ -0,0 +1,21 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/aws-s3' {
+  export interface AwsS3UploadParameters {
+    method?: string;
+    url: string;
+    fields?: { [type: string]: string };
+    headers?: { [type: string]: string };
+  }
+
+  export interface AwsS3Options extends PluginOptions {
+    serverUrl: string;
+    getUploadParameters(file: object): Promise<AwsS3UploadParameters>;
+    timeout: number;
+    limit: number;
+  }
+
+  export default class AwsS3 extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<AwsS3Options>);
+  }
+}

+ 127 - 0
packages/@uppy/core/types/index.d.ts

@@ -0,0 +1,127 @@
+declare module '@uppy/core' {
+  // TODO actually use the properties here
+  export interface UppyFile {
+    data: Blob | File;
+    extension: string;
+    id: string;
+    isPaused: boolean;
+    isRemote: boolean;
+    meta: {
+      name: string;
+      type?: string;
+    };
+    name: string;
+    preview?: string;
+    progress?: {
+      uploadStarted: number;
+      uploadComplete: boolean;
+      percentage: number;
+      bytesUploaded: number;
+      bytesTotal: number;
+    };
+    remote?: {
+      host: string;
+      url: string;
+      body?: object;
+    };
+    size: number;
+    source?: string;
+    type?: string;
+    uploadURL?: string;
+  }
+
+  export interface PluginOptions {
+    id?: string;
+  }
+
+  export class Plugin {
+    constructor(uppy: Uppy, opts?: PluginOptions);
+    getPluginState(): object;
+    setPluginState(update: any): object;
+    update(state?: object): void;
+    mount(target: any, plugin: any): void;
+    render(state: object): void;
+    addTarget(plugin: any): void;
+    unmount(): void;
+    install(): void;
+    uninstall(): void;
+  }
+
+  export interface Store {
+    getState(): object;
+    setState(patch: object): void;
+    subscribe(listener: any): () => void;
+  }
+
+  export interface UppyOptions {
+    id: string;
+    autoProceed: boolean;
+    debug: boolean;
+    restrictions: {
+      maxFileSize: false,
+      maxNumberOfFiles: false,
+      minNumberOfFiles: false,
+      allowedFileTypes: false
+    };
+    target: string | Plugin;
+    meta: any;
+    // onBeforeFileAdded: (currentFile, files) => currentFile,
+    // onBeforeUpload: (files) => files,
+    locale: any;
+    store: Store;
+  }
+
+  export interface UploadResult {
+    successful: Array<UppyFile>;
+    failed: Array<UppyFile>;
+  }
+
+  type LogLevel = 'info' | 'warning' | 'error';
+  export class Uppy {
+    constructor(opts?: Partial<UppyOptions>);
+    on(event: 'upload-success', callback: (file: UppyFile, body: any, uploadURL: string) => any): Uppy;
+    on(event: 'complete', callback: (result: UploadResult) => void): Uppy;
+    on(event: string, callback: (...args: any[]) => any): Uppy;
+    off(event: string, callback: any): Uppy;
+    updateAll(state: object): void;
+    setState(patch: object): void;
+    getState(): object;
+    readonly state: object;
+    setFileState(fileID: string, state: object): void;
+    resetProgress(): void;
+    addPreProcessor(fn: any): void;
+    removePreProcessor(fn: any): void;
+    addPostProcessor(fn: any): void;
+    removePostProcessor(fn: any): void;
+    addUploader(fn: any): void;
+    removeUploader(fn: any): void;
+    setMeta(data: any): void;
+    setFileMeta(fileID: string, data: any): void;
+    getFile(fileID: string): UppyFile;
+    getFiles(): UppyFile[];
+    addFile(file: object): void;
+    removeFile(fileID: string): void;
+    pauseResume(fileID: string): boolean;
+    pauseAll(): void;
+    resumeAll(): void;
+    retryAll(): void;
+    cancelAll(): void;
+    retryUpload(fileID: string): any;
+    reset(): void;
+    getID(): string;
+    use(plugin: typeof Plugin, opts: any): Uppy;
+    getPlugin(name: string): Plugin;
+    iteratePlugins(method: any): 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;
+    run(): Uppy;
+    restore(uploadID: string): Promise<any>;
+    addResultData(uploadID: string, data: any): void;
+    upload(): Promise<any>;
+  }
+
+  export default function createUppy(opts?: Partial<UppyOptions>): Uppy;
+}

+ 37 - 0
packages/@uppy/dashboard/types/index.d.ts

@@ -0,0 +1,37 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/dashboard' {
+  export interface DashboardOptions extends PluginOptions {
+    onRequestCloseModal: () => void;
+    disablePageScrollWhenModalOpen: boolean;
+    closeModalOnClickOutside: boolean;
+    trigger: string | HTMLElement;
+    inline: boolean;
+    defaultTabIcon: string;
+    hideUploadButton: boolean;
+    width: string;
+    height: string;
+    note: string;
+    showLinkToFileUploadResult: boolean;
+    proudlyDisplayPoweredByUppy: boolean;
+    metaFields: string[];
+    plugins: string[];
+    disableStatusBar: boolean;
+    showProgressDetails: boolean;
+    hideProgressAfterFinish: boolean;
+    disableInformer: boolean;
+    disableThumbnailGenerator: boolean;
+  }
+
+  export default class Dashboard extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<DashboardOptions>);
+    addTarget(plugin: Plugin): HTMLElement;
+    hideAllPanels(): void;
+    openModal(): void;
+    closeModal(): void;
+    isModalOpen(): boolean;
+    render(state: object): void;
+    install(): void;
+    uninstall(): void;
+  }
+}

+ 15 - 0
packages/@uppy/drag-drop/types/index.d.ts

@@ -0,0 +1,15 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/drag-drop' {
+  export interface DragDropOptions extends PluginOptions {
+    inputName: string;
+    allowMultipleFiles: boolean;
+    width: string;
+    height: string;
+    note: string;
+  }
+
+  export default class DragDrop extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<DragDropOptions>);
+  }
+}

+ 11 - 0
packages/@uppy/dropbox/types/index.d.ts

@@ -0,0 +1,11 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/dropbox' {
+  export interface DropboxOptions extends PluginOptions {
+    serverUrl: string;
+  }
+
+  export default class Dropbox extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<DropboxOptions>);
+  }
+}

+ 12 - 0
packages/@uppy/file-input/types/index.d.ts

@@ -0,0 +1,12 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/file-input' {
+  export interface FileInputOptions extends PluginOptions {
+    pretty: boolean;
+    inputName: string;
+  }
+
+  export default class FileInput extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<FileInputOptions>);
+  }
+}

+ 15 - 0
packages/@uppy/form/types/index.d.ts

@@ -0,0 +1,15 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/form' {
+  export interface FormOptions extends PluginOptions {
+    getMetaFromForm: boolean;
+    addResultToForm: boolean;
+    submitOnSuccess: boolean;
+    triggerUploadOnSubmit: boolean;
+    resultName: string;
+  }
+
+  export default class Form extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<FormOptions>);
+  }
+}

+ 13 - 0
packages/@uppy/golden-retriever/types/index.d.ts

@@ -0,0 +1,13 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/golden-retriever' {
+  export interface GoldenRetrieverOptions extends PluginOptions {
+    expires: number;
+    serviceWorker: boolean;
+    indexedDB: any;
+  }
+
+  export default class GoldenRetriever extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<GoldenRetrieverOptions>);
+  }
+}

+ 12 - 0
packages/@uppy/google-drive/types/index.d.ts

@@ -0,0 +1,12 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/google-drive' {
+  export interface GoogleDriveOptions extends PluginOptions {
+    serverUrl: string;
+    // TODO inherit from ProviderOptions
+  }
+
+  export default class GoogleDrive extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<GoogleDriveOptions>);
+  }
+}

+ 18 - 0
packages/@uppy/informer/types/index.d.ts

@@ -0,0 +1,18 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/informer' {
+  interface Color {
+    bg: string | number;
+    text: string | number;
+  }
+
+  export interface InformerOptions extends PluginOptions {
+    typeColors: {
+      [type: string]: Color
+    };
+  }
+
+  export default class Informer extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<InformerOptions>);
+  }
+}

+ 12 - 0
packages/@uppy/instagram/types/index.d.ts

@@ -0,0 +1,12 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/instagram' {
+  export interface InstagramOptions extends PluginOptions {
+    serverUrl: string;
+    // TODO inherit from ProviderOptions
+  }
+
+  export default class Instagram extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<InstagramOptions>);
+  }
+}

+ 12 - 0
packages/@uppy/progress-bar/types/index.d.ts

@@ -0,0 +1,12 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/progress-bar' {
+  export interface ProgressBarOptions extends PluginOptions {
+    hideAfterFinish: boolean;
+    fixed: boolean;
+  }
+
+  export default class ProgressBar extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<ProgressBarOptions>);
+  }
+}

+ 10 - 0
packages/@uppy/redux-dev-tools/types/index.d.ts

@@ -0,0 +1,10 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/redux-dev-tools' {
+  export interface ReduxDevToolsOptions extends PluginOptions {
+  }
+
+  export default class ReduxDevTools extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<ReduxDevToolsOptions>);
+  }
+}

+ 43 - 0
packages/@uppy/server-utils/types/index.d.ts

@@ -0,0 +1,43 @@
+import { Uppy } from '@uppy/core';
+
+declare module '@uppy/server-utils' {
+  export interface RequestClientOptions {
+    serverUrl: string;
+  }
+
+  export class RequestClient {
+    constructor (uppy: Uppy, opts: RequestClientOptions);
+    get (path: string): Promise<any>;
+    post (path: string, data: object): Promise<any>;
+    delete (path: string, data: object): Promise<any>;
+  }
+
+  export interface ProviderOptions {
+    serverUrl: string;
+    provider: string;
+    authProvider?: string;
+    name?: string;
+  }
+
+  export class Provider extends RequestClient {
+    constructor (uppy: Uppy, opts: ProviderOptions);
+    checkAuth (): Promise<boolean>;
+    authUrl (): string;
+    fileUrl (id: string): string;
+    list (directory: string): Promise<any>;
+    logout (redirect?: string): Promise<any>;
+  }
+
+  export interface SocketOptions {
+    target: string;
+  }
+
+  export class Socket {
+    constructor (opts: SocketOptions);
+    close (): void;
+    send (action: string, payload: any): void;
+    on (action: string, handler: (any) => void);
+    emit (action: string, payload: (any) => void);
+    once (action: string, handler: (any) => void);
+  }
+}

+ 13 - 0
packages/@uppy/statusbar/types/index.d.ts

@@ -0,0 +1,13 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/statusbar' {
+  export interface StatusBarOptions extends PluginOptions {
+    showProgressDetails: boolean;
+    hideUploadButton: boolean;
+    hideAfterFinish: boolean;
+  }
+
+  export default class StatusBar extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<StatusBarOptions>);
+  }
+}

+ 12 - 0
packages/@uppy/store-default/types/index.d.ts

@@ -0,0 +1,12 @@
+import { Store } from '@uppy/core';
+
+declare module '@uppy/store-default' {
+  class DefaultStore implements Store {
+    constructor();
+    getState(): object;
+    setState(patch: object): void;
+    subscribe(listener: any): () => void;
+  }
+
+  export default function createDefaultStore(): DefaultStore;
+}

+ 21 - 0
packages/@uppy/store-redux/types/index.d.ts

@@ -0,0 +1,21 @@
+import { Store } from '@uppy/core';
+import { Reducer, Middleware, Store as Redux } from 'redux';
+
+declare module '@uppy/store-redux' {
+  export interface ReduxStoreOptions {
+    store: Redux<object>;
+    id?: string;
+    selector?: (state: any) => object;
+  }
+
+  class ReduxStore implements Store {
+    constructor(opts: ReduxStoreOptions);
+    getState(): object;
+    setState(patch: object): void;
+    subscribe(listener: any): () => void;
+  }
+
+  export default function createReduxStore(opts: ReduxStoreOptions): ReduxStore;
+  export const reducer: Reducer<object>;
+  export const middleware: Middleware;
+}

+ 11 - 0
packages/@uppy/thumbnail-generator/types/index.d.ts

@@ -0,0 +1,11 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/thumbnail-generator' {
+  export interface ThumbnailGeneratorOptions extends PluginOptions {
+    thumbnailWidth: number;
+  }
+
+  export default class ThumbnailGenerator extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<ThumbnailGeneratorOptions>);
+  }
+}

+ 24 - 0
packages/@uppy/transloadit/types/index.d.ts

@@ -0,0 +1,24 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/transloadit' {
+  export interface AssemblyOptions {
+    params: object;
+    fields: object;
+    signature: string;
+  }
+
+  export interface TransloaditOptions extends PluginOptions {
+    params: any;
+    signature: string;
+    service: string;
+    waitForEncoding: boolean;
+    waitForMetadata: boolean;
+    importFromUploadURLs: boolean;
+    alwaysRunAssembly: boolean;
+    getAssemblyOptions: (file: object) => AssemblyOptions | Promise<AssemblyOptions>;
+  }
+
+  export default class Transloadit extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<TransloaditOptions>);
+  }
+}

+ 16 - 0
packages/@uppy/tus/types/index.d.ts

@@ -0,0 +1,16 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/tus' {
+  export interface TusOptions extends PluginOptions {
+    limit: number;
+    endpoint: string;
+    uploadUrl: string;
+    useFastRemoteRetry: boolean;
+    resume: boolean;
+    autoRetry: boolean;
+  }
+
+  export default class Tus extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<TusOptions>);
+  }
+}

+ 12 - 0
packages/@uppy/url/types/index.d.ts

@@ -0,0 +1,12 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/url' {
+  export interface UrlOptions extends PluginOptions {
+    serverUrl: string;
+    // TODO inherit from ProviderOptions
+  }
+
+  export default class Url extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<UrlOptions>);
+  }
+}

+ 3 - 0
packages/@uppy/utils/types/index.d.ts

@@ -0,0 +1,3 @@
+declare module '@uppy/utils' {
+  // TODO ?
+}

+ 15 - 0
packages/@uppy/webcam/types/index.d.ts

@@ -0,0 +1,15 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/webcam' {
+  export interface WebcamOptions extends PluginOptions {
+    onBeforeSnapshot?: () => Promise<void>;
+    countdown?: number | boolean;
+    mirror?: boolean;
+    facingMode?: string;
+    modes: Array<'video-audio' | 'video-only' | 'audio-only' | 'picturee'>;
+  }
+
+  export default class Webcam extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<WebcamOptions>);
+  }
+}

+ 20 - 0
packages/@uppy/xhrupload/types/index.d.ts

@@ -0,0 +1,20 @@
+import { Plugin, PluginOptions, Uppy } from '@uppy/core';
+
+declare module '@uppy/xhrupload' {
+  export interface XHRUploadOptions extends PluginOptions {
+    limit: string;
+    bundle: boolean;
+    formData: FormData;
+    headers: any;
+    metaFields: string[];
+    fieldName: string;
+    timeout: number;
+    responseUrlFieldName: string;
+    endpoint: string;
+    method: 'GET' | 'POST' | 'HEAD';
+  }
+
+  export default class XHRUpload extends Plugin {
+    constructor(uppy: Uppy, opts: Partial<XHRUploadOptions>);
+  }
+}

+ 35 - 0
packages/uppy/types/index.d.ts

@@ -0,0 +1,35 @@
+declare module 'uppy' {
+  // Core
+  export { default as Core } from '@uppy/core';
+
+  // Stores
+  export { default as DefaultStore } from '@uppy/store-default';
+  export { default as ReduxStore } from '@uppy/store-redux';
+
+  // UI plugins
+  export { default as Dashboard } from '@uppy/dashboard';
+  export { default as DragDrop } from '@uppy/drag-drop';
+  export { default as FileInput } from '@uppy/file-input';
+  export { default as Informer } from '@uppy/informer';
+  export { default as ProgressBar } from '@uppy/progress-bar';
+  export { default as StatusBar } from '@uppy/statusbar';
+
+  // Acquirers
+  export { default as Dropbox } from '@uppy/dropbox';
+  export { default as GoogleDrive } from '@uppy/google-drive';
+  export { default as Instagram } from '@uppy/instagram';
+  export { default as Url } from '@uppy/url';
+  export { default as Webcam } from '@uppy/webcam';
+
+  // Uploaders
+  export { default as AwsS3 } from '@uppy/aws-s3';
+  export { default as Transloadit } from '@uppy/transloadit';
+  export { default as Tus } from '@uppy/tus';
+  export { default as XHRUpload } from '@uppy/xhrupload';
+
+  // Miscellaneous
+  export { default as Form } from '@uppy/form';
+  export { default as GoldenRetriever } from '@uppy/golden-retriever';
+  export { default as ReduxDevTools } from '@uppy/redux-dev-tools';
+  export { default as ThumbnailGenerator } from '@uppy/thumbnail-generator';
+}