Meteor-files: Typescript definitions for Meteor-Files

Created on 8 Sep 2016  Â·  9Comments  Â·  Source: veliovgroup/Meteor-Files

I'm interested in using Meteor-Files together with ng2-files-upload which being an Angular 2 component is written in Typescript.

Here's my initial try if anyone is interested.

declare module 'meteor/ostrio:files' {

    import {Mongo} from 'meteor/mongo';
    import {ReactiveVar} from 'meteor/reactive-var';

    export interface FilesCollectionOptions {
        storagePath?: string;
        collection?: Mongo.Collection<any>;
        collectionName?: string;
        continueUploadTTL?: string;
        cacheControl?: string;
        responseHeaders?: {[x: string]: string} | ((responseCode?, fileRef?, versionRef?, version?) => {[x: string]: string});
        throttle?: string;
        schema?: Object;
        chunkSize?: number;
        namingFunction?: Function;
        permissions?: number;
        parentDirPermissions?: number;
        integrityCheck?: boolean;
        strict?: boolean;
        downloadCallback?: Function;
        protected?: boolean | Function;
        public?: boolean;
        onBeforeUpload?: (fileData) => boolean | string;
        onInitiateUpload?: (fileData) => void;
        onBeforeRemove?: (cursor: Mongo.Cursor<any>) => boolean;
        onAfterUpload?: (Object) => any;
        onAfterRemove?: (Object) => any;
        onbeforeunloadMessage?: string | (() => string);
        allowClientCode?: boolean;
        debug?: boolean;
        interceptDownload?: (http, fileRef, version) => any;
    }

    export interface SearchOptions {
        sort?: Mongo.SortSpecifier;
        skip?: number;
        limit?: number;
        fields?: Mongo.FieldSpecifier;
        reactive?: boolean;
        transform?: Function;
    }

    export interface InsertOptions {
        file: File | Object | string;
        isBase64?: boolean;
        meta?: {[x: string]: any};
        transport?: 'ddp' | 'http'
        onStart?: (error: Object, fileData: Object) => any;
        onUploaded?: (error: Object, fileData: Object) => any;
        onAbort?: (fileData: Object) => any;
        onError?: (error: Object, fileData: Object) => any;
        onProgress?: (progress: number, fileData: Object) => any;
        onBeforeUpload?: (fileData: Object) => any;
        chunkSize?: number | 'dynamic';
        allowWebWorkers?: boolean;
    }

    export interface LoadOptions {
        fileName: string;
        meta?: Object;
        type?: string;
        size?: number;
    }

    export class FileUpload {
        file: File;
        onPause: ReactiveVar<boolean>;
        progress: ReactiveVar<number>;
        estimateTime: ReactiveVar<number>;
        estimateSpeed: ReactiveVar<number>;
        state: ReactiveVar<'active' | 'paused' | 'aborted' | 'completed'>;

        pause();

        continue();

        toggle();

        pipe();
    }

    export class FileCursor {
        remove(callback: (err) => void);

        link(): string;

        get(property: string): any;

        fetch(): Object[];

        with(): FileCursor;
    }

    export class FilesCursor extends Mongo.Cursor<any> {

        cursor: Mongo.Cursor<any>;

        get(): Object[];

        hasNext(): boolean;

        next(): Object;

        hasPrevious(): boolean;

        previous(): Object;

        fetch(): Object[]

        first(): Object;

        last(): Object;

        count(): number;

        remove(callback: (err) => void);

        forEach(callback: (doc)=>void, context: Object);

        each(): FileCursor[];

        map(callback: (doc)=>Object, context: Object): Object[];

        current(): Object | undefined;

        observe(callbacks: Mongo.ObserveCallbacks): Meteor.LiveQueryHandle;

        observeChanges(callbacks: Mongo.ObserveChangesCallbacks): Meteor.LiveQueryHandle;
    }

    export class FilesCollection {
        collection: Mongo.Collection<any>;
        schema: any;

        constructor(config: FilesCollectionOptions)

        find(selector?: Mongo.Selector, options?: SearchOptions): FilesCursor;

        findOne(selector?: Mongo.Selector, options?: SearchOptions): FileCursor;

        insert(settings: InsertOptions, autoStart: boolean): FileUpload;

        remove(select: Mongo.Selector, callback: (error)=>any): FilesCollection;

        link(fileRef: Object): string;

        allow(options: Mongo.AllowDenyOptions): void;

        deny(options: Mongo.AllowDenyOptions): void;

        denyClient(): void;

        on(event: string, callback: (fileRef) => void);

        unlink(fileRef: Object, version: string): FilesCollection;

        addFile(path: string, opts: LoadOptions, callback: (err: any, fileRef: Object) => any, proceedAfterUpload: boolean);

        load(url: string, opts: LoadOptions, callback: (err: any, fileRef: Object) => any, proceedAfterUpload: boolean);

        write(buffer: Buffer, opts: LoadOptions, callback: (err: any, fileRef: Object) => any, proceedAfterUpload: boolean);
    }
}

Edit: allowWebWorkers should be optional
Edit 2: I've made a few more changes. This will be my last update as while this package does have some good features it doesn't really fit into my app.

Angular help wanted

Most helpful comment

Hi dr.dimitru,

Thanks for pointing me here. I am trying to update and further complete the definitions file

, however I still have a few questions:

  • In your docs you refer to FileObj, FileRef and FileData, which are all different objects. I think I have distinguished them all correctly, however I am confused about FileCursor. Is it correct to say that FileCursor extends FileObj with extra methods?

  • FilesCursor seems to extend Mongo.Cursor. Why is there still a 'cursor' member in there and what does it refer to : to the base Mongo.Cursor? What's the reason behind that?

Attached is a first attempt of my updated version. Would you or anyone else be able to roughly verify if this is more or less correct, and I don't make any wrong assumptions?

Thanks!

Avijobo

declare module "meteor/ostrio:files" {

    import { Mongo } from 'meteor/mongo';
    import { ReactiveVar } from 'meteor/reactive-var';

    class FileObj {
        size: number;
        name: string;
        type: string;
        path: string;
        isVideo: boolean;
        isAudio: boolean;
        isImage: boolean;
        isText: boolean;
        isJSON: boolean;
        isPDF: boolean;
        extension?: string;
        _storagePath: string;
        _downloadRoute: string;
        _collectionName: string;
        public?: boolean;
        meta?: Object;
        userid?: string;
        updatedAt?: Date;
        versions: Object;
    }

    type FileRef = any; // File record from Mongo DB... don't know the details yet

    interface FileData {
        size: number;
        type: string;
        mime: string;
        "mime-type": string;
        ext: string;
        extension: string;
        name: string;
    }

    interface FilesCollectionConfig {
        storagePath?: string;
        collection?: Mongo.Collection<any>;
        collectionName?: string;
        continueUploadTTL?: string;
        ddp?: Object;
        cacheControl?: string;
        responseHeaders?: { [x: string]: string } | ((responseCode?, fileRef?, versionRef?, version?) => { [x: string]: string });
        throttle?: number | boolean;
        downloadRoute?: string;
        schema?: Object;
        chunkSize?: number;
        namingFunction?: () => string;
        permissions?: number;
        parentDirPermissions?: number;
        integrityCheck?: boolean;
        strict?: boolean;
        downloadCallback?: (fileObj: FileObj) => boolean;
        protected?: boolean | ((fileObj: FileObj) => boolean | number);
        public?: boolean;
        onBeforeUpload?: (fileData: FileData) => boolean | string;
        onBeforeRemove?: (cursor: Mongo.Cursor<any>) => boolean;
        onInitiateUpload?: (fileData: FileData) => void;
        onAfterUpload?: (fileRef: FileRef) => any;
        onAfterRemove?: (files: Object[]) => any;
        onbeforeunloadMessage?: string | (() => string);
        allowClientCode?: boolean;
        debug?: boolean;
        interceptDownload?: (http: any, fileRef: any, version: string) => boolean;
    }

    export interface SearchOptions {
        sort?: Mongo.SortSpecifier;
        skip?: number;
        limit?: number;
        fields?: Mongo.FieldSpecifier;
        reactive?: boolean;
        transform?: Function;
    }

    export interface InsertOptions {
        file: File | Object | string;
        isBase64?: boolean;
        meta?: { [x: string]: any };
        transport?: 'ddp' | 'http'
        onStart?: (error: Object, fileData: Object) => any;
        onUploaded?: (error: Object, fileData: Object) => any;
        onAbort?: (fileData: Object) => any;
        onError?: (error: Object, fileData: Object) => any;
        onProgress?: (progress: number, fileData: Object) => any;
        onBeforeUpload?: (fileData: Object) => any;
        streams?: number | 'dynamic';
        chunkSize?: number | 'dynamic';
        allowWebWorkers?: boolean;
    }

    export interface LoadOptions {
        fileName: string;
        meta?: Object;
        type?: string;
        size?: number;
    }

    export class FileUpload {
        file: File;
        onPause: ReactiveVar<boolean>;
        progress: ReactiveVar<number>;
        estimateTime: ReactiveVar<number>;
        estimateSpeed: ReactiveVar<number>;
        state: ReactiveVar<'active' | 'paused' | 'aborted' | 'completed'>;

        pause();
        continue();
        toggle();
        pipe();
        start();
        on(event: string, callback: Function): void;
    }

    export class FileCursor extends FileObj { // Is it correct to say that it extends FileObj?
        remove(callback: (err) => void): void;
        link(): string;
        get(property: string): Object | any;
        fetch(): Object[];
        with(): ReactiveVar<FileCursor>;
    }

    export class FilesCursor extends Mongo.Cursor<FileObj> {
        cursor: Mongo.Cursor<FileObj>; // Refers to base cursor? Why is this existing?

        get(): Object[];
        hasNext(): boolean;
        next(): Object;
        hasPrevious(): boolean;
        previous(): Object;
        first(): Object;
        last(): Object;
        remove(callback: (err) => void): void;
        each(): FileCursor[];
        current(): Object | undefined;
    }

    export class FilesCollection {
        collection: Mongo.Collection<FileObj>;
        schema: any;

        constructor(config: FilesCollectionConfig)

        find(selector?: Mongo.Selector, options?: SearchOptions): FilesCursor;
        findOne(selector?: Mongo.Selector, options?: SearchOptions): FileCursor;
        insert(settings: InsertOptions, autoStart?: boolean): FileUpload;
        remove(select: Mongo.Selector, callback: (error) => any): FilesCollection;
        link(fileRef: FileRef, version?: string): string;
        allow(options: Mongo.AllowDenyOptions): void;
        deny(options: Mongo.AllowDenyOptions): void;
        denyClient(): void;
        on(event: string, callback: (fileRef: FileRef) => void): void;
        unlink(fileRef: FileRef, version?: string): FilesCollection;
        addFile(path: string, opts: LoadOptions, callback: (err: any, fileRef: FileRef) => any, proceedAfterUpload: boolean);
        load(url: string, opts: LoadOptions, callback: (err: any, fileRef: FileRef) => any, proceedAfterUpload: boolean);
        write(buffer: Buffer, opts: LoadOptions, callback: (err: any, fileRef: FileRef) => any, proceedAfterUpload: boolean);
    }
}

All 9 comments

Hi @Lavan ,

Is there any chance make a docs, like "TS definition" from your snippet?

@dr-dimitru what do you mean by docs like?

As I mentioned in my edit, I'm not using this package any more and I really don't have time to work on it anymore.

@Lavan sad to hear that.
I saw some developers already young your definitions within theirs TS apps.

Okay, hope someone who uses TS will make docs from it.

Hi dr.dimitru,

Thanks for pointing me here. I am trying to update and further complete the definitions file

, however I still have a few questions:

  • In your docs you refer to FileObj, FileRef and FileData, which are all different objects. I think I have distinguished them all correctly, however I am confused about FileCursor. Is it correct to say that FileCursor extends FileObj with extra methods?

  • FilesCursor seems to extend Mongo.Cursor. Why is there still a 'cursor' member in there and what does it refer to : to the base Mongo.Cursor? What's the reason behind that?

Attached is a first attempt of my updated version. Would you or anyone else be able to roughly verify if this is more or less correct, and I don't make any wrong assumptions?

Thanks!

Avijobo

declare module "meteor/ostrio:files" {

    import { Mongo } from 'meteor/mongo';
    import { ReactiveVar } from 'meteor/reactive-var';

    class FileObj {
        size: number;
        name: string;
        type: string;
        path: string;
        isVideo: boolean;
        isAudio: boolean;
        isImage: boolean;
        isText: boolean;
        isJSON: boolean;
        isPDF: boolean;
        extension?: string;
        _storagePath: string;
        _downloadRoute: string;
        _collectionName: string;
        public?: boolean;
        meta?: Object;
        userid?: string;
        updatedAt?: Date;
        versions: Object;
    }

    type FileRef = any; // File record from Mongo DB... don't know the details yet

    interface FileData {
        size: number;
        type: string;
        mime: string;
        "mime-type": string;
        ext: string;
        extension: string;
        name: string;
    }

    interface FilesCollectionConfig {
        storagePath?: string;
        collection?: Mongo.Collection<any>;
        collectionName?: string;
        continueUploadTTL?: string;
        ddp?: Object;
        cacheControl?: string;
        responseHeaders?: { [x: string]: string } | ((responseCode?, fileRef?, versionRef?, version?) => { [x: string]: string });
        throttle?: number | boolean;
        downloadRoute?: string;
        schema?: Object;
        chunkSize?: number;
        namingFunction?: () => string;
        permissions?: number;
        parentDirPermissions?: number;
        integrityCheck?: boolean;
        strict?: boolean;
        downloadCallback?: (fileObj: FileObj) => boolean;
        protected?: boolean | ((fileObj: FileObj) => boolean | number);
        public?: boolean;
        onBeforeUpload?: (fileData: FileData) => boolean | string;
        onBeforeRemove?: (cursor: Mongo.Cursor<any>) => boolean;
        onInitiateUpload?: (fileData: FileData) => void;
        onAfterUpload?: (fileRef: FileRef) => any;
        onAfterRemove?: (files: Object[]) => any;
        onbeforeunloadMessage?: string | (() => string);
        allowClientCode?: boolean;
        debug?: boolean;
        interceptDownload?: (http: any, fileRef: any, version: string) => boolean;
    }

    export interface SearchOptions {
        sort?: Mongo.SortSpecifier;
        skip?: number;
        limit?: number;
        fields?: Mongo.FieldSpecifier;
        reactive?: boolean;
        transform?: Function;
    }

    export interface InsertOptions {
        file: File | Object | string;
        isBase64?: boolean;
        meta?: { [x: string]: any };
        transport?: 'ddp' | 'http'
        onStart?: (error: Object, fileData: Object) => any;
        onUploaded?: (error: Object, fileData: Object) => any;
        onAbort?: (fileData: Object) => any;
        onError?: (error: Object, fileData: Object) => any;
        onProgress?: (progress: number, fileData: Object) => any;
        onBeforeUpload?: (fileData: Object) => any;
        streams?: number | 'dynamic';
        chunkSize?: number | 'dynamic';
        allowWebWorkers?: boolean;
    }

    export interface LoadOptions {
        fileName: string;
        meta?: Object;
        type?: string;
        size?: number;
    }

    export class FileUpload {
        file: File;
        onPause: ReactiveVar<boolean>;
        progress: ReactiveVar<number>;
        estimateTime: ReactiveVar<number>;
        estimateSpeed: ReactiveVar<number>;
        state: ReactiveVar<'active' | 'paused' | 'aborted' | 'completed'>;

        pause();
        continue();
        toggle();
        pipe();
        start();
        on(event: string, callback: Function): void;
    }

    export class FileCursor extends FileObj { // Is it correct to say that it extends FileObj?
        remove(callback: (err) => void): void;
        link(): string;
        get(property: string): Object | any;
        fetch(): Object[];
        with(): ReactiveVar<FileCursor>;
    }

    export class FilesCursor extends Mongo.Cursor<FileObj> {
        cursor: Mongo.Cursor<FileObj>; // Refers to base cursor? Why is this existing?

        get(): Object[];
        hasNext(): boolean;
        next(): Object;
        hasPrevious(): boolean;
        previous(): Object;
        first(): Object;
        last(): Object;
        remove(callback: (err) => void): void;
        each(): FileCursor[];
        current(): Object | undefined;
    }

    export class FilesCollection {
        collection: Mongo.Collection<FileObj>;
        schema: any;

        constructor(config: FilesCollectionConfig)

        find(selector?: Mongo.Selector, options?: SearchOptions): FilesCursor;
        findOne(selector?: Mongo.Selector, options?: SearchOptions): FileCursor;
        insert(settings: InsertOptions, autoStart?: boolean): FileUpload;
        remove(select: Mongo.Selector, callback: (error) => any): FilesCollection;
        link(fileRef: FileRef, version?: string): string;
        allow(options: Mongo.AllowDenyOptions): void;
        deny(options: Mongo.AllowDenyOptions): void;
        denyClient(): void;
        on(event: string, callback: (fileRef: FileRef) => void): void;
        unlink(fileRef: FileRef, version?: string): FilesCollection;
        addFile(path: string, opts: LoadOptions, callback: (err: any, fileRef: FileRef) => any, proceedAfterUpload: boolean);
        load(url: string, opts: LoadOptions, callback: (err: any, fileRef: FileRef) => any, proceedAfterUpload: boolean);
        write(buffer: Buffer, opts: LoadOptions, callback: (err: any, fileRef: FileRef) => any, proceedAfterUpload: boolean);
    }
}

I have updated @Avijobo version, there was a typo on fileObj userId

declare module "meteor/ostrio:files" {

    import { Mongo } from 'meteor/mongo';
    import { ReactiveVar } from 'meteor/reactive-var';

    class FileObj {
        size: number;
        name: string;
        type: string;
        path: string;
        isVideo: boolean;
        isAudio: boolean;
        isImage: boolean;
        isText: boolean;
        isJSON: boolean;
        isPDF: boolean;
        extension?: string;
        _storagePath: string;
        _downloadRoute: string;
        _collectionName: string;
        public?: boolean;
        meta?: Object;
        userId?: string;
        updatedAt?: Date;
        versions: Object;
    }

    type FileRef = any; // File record from Mongo DB... don't know the details yet

    interface FileData {
        size: number;
        type: string;
        mime: string;
        "mime-type": string;
        ext: string;
        extension: string;
        name: string;
    }

    interface FilesCollectionConfig {
        storagePath?: string;
        collection?: Mongo.Collection<any>;
        collectionName?: string;
        continueUploadTTL?: string;
        ddp?: Object;
        cacheControl?: string;
        responseHeaders?: { [x: string]: string } | ((responseCode?, fileRef?, versionRef?, version?) => { [x: string]: string });
        throttle?: number | boolean;
        downloadRoute?: string;
        schema?: Object;
        chunkSize?: number;
        namingFunction?: () => string;
        permissions?: number;
        parentDirPermissions?: number;
        integrityCheck?: boolean;
        strict?: boolean;
        downloadCallback?: (fileObj: FileObj) => boolean;
        protected?: boolean | ((fileObj: FileObj) => boolean | number);
        public?: boolean;
        onBeforeUpload?: (fileData: FileData) => boolean | string;
        onBeforeRemove?: (cursor: Mongo.Cursor<any>) => boolean;
        onInitiateUpload?: (fileData: FileData) => void;
        onAfterUpload?: (fileRef: FileRef) => any;
        onAfterRemove?: (files: Object[]) => any;
        onbeforeunloadMessage?: string | (() => string);
        allowClientCode?: boolean;
        debug?: boolean;
        interceptDownload?: (http: any, fileRef: any, version: string) => boolean;
    }

    export interface SearchOptions {
        sort?: Mongo.SortSpecifier;
        skip?: number;
        limit?: number;
        fields?: Mongo.FieldSpecifier;
        reactive?: boolean;
        transform?: Function;
    }

    export interface InsertOptions {
        file: File | Object | string;
        isBase64?: boolean;
        meta?: { [x: string]: any };
        transport?: 'ddp' | 'http'
        onStart?: (error: Object, fileData: Object) => any;
        onUploaded?: (error: Object, fileData: Object) => any;
        onAbort?: (fileData: Object) => any;
        onError?: (error: Object, fileData: Object) => any;
        onProgress?: (progress: number, fileData: Object) => any;
        onBeforeUpload?: (fileData: Object) => any;
        streams?: number | 'dynamic';
        chunkSize?: number | 'dynamic';
        allowWebWorkers?: boolean;
    }

    export interface LoadOptions {
        fileName: string;
        meta?: Object;
        type?: string;
        size?: number;
    }

    export class FileUpload {
        file: File;
        onPause: ReactiveVar<boolean>;
        progress: ReactiveVar<number>;
        estimateTime: ReactiveVar<number>;
        estimateSpeed: ReactiveVar<number>;
        state: ReactiveVar<'active' | 'paused' | 'aborted' | 'completed'>;

        pause();
        continue();
        toggle();
        pipe();
        start();
        on(event: string, callback: Function): void;
    }

    export class FileCursor extends FileObj { // Is it correct to say that it extends FileObj?
        remove(callback: (err) => void): void;
        link(): string;
        get(property: string): Object | any;
        fetch(): Object[];
        with(): ReactiveVar<FileCursor>;
    }

    export class FilesCursor extends Mongo.Cursor<FileObj> {
        cursor: Mongo.Cursor<FileObj>; // Refers to base cursor? Why is this existing?

        get(): Object[];
        hasNext(): boolean;
        next(): Object;
        hasPrevious(): boolean;
        previous(): Object;
        first(): Object;
        last(): Object;
        remove(callback: (err) => void): void;
        each(): FileCursor[];
        current(): Object | undefined;
    }

    export class FilesCollection {
        collection: Mongo.Collection<FileObj>;
        schema: any;

        constructor(config: FilesCollectionConfig)

        find(selector?: Mongo.Selector, options?: SearchOptions): FilesCursor;
        findOne(selector?: Mongo.Selector, options?: SearchOptions): FileCursor;
        insert(settings: InsertOptions, autoStart?: boolean): FileUpload;
        remove(select: Mongo.Selector, callback: (error) => any): FilesCollection;
        link(fileRef: FileRef, version?: string): string;
        allow(options: Mongo.AllowDenyOptions): void;
        deny(options: Mongo.AllowDenyOptions): void;
        denyClient(): void;
        on(event: string, callback: (fileRef: FileRef) => void): void;
        unlink(fileRef: FileRef, version?: string): FilesCollection;
        addFile(path: string, opts: LoadOptions, callback: (err: any, fileRef: FileRef) => any, proceedAfterUpload: boolean);
        load(url: string, opts: LoadOptions, callback: (err: any, fileRef: FileRef) => any, proceedAfterUpload: boolean);
        write(buffer: Buffer, opts: LoadOptions, callback: (err: any, fileRef: FileRef) => any, proceedAfterUpload: boolean);
    }
}

Here's yet more changes:

  • fixes a couple of bugs (eg FilesCollectionConfig.storagePath should also accept a function); and
  • adds a generic parameter, M, to set the type of the meta field.
// defs for meteor/ostrio:files, adapted from https://github.com/VeliovGroup/Meteor-Files/issues/226#issuecomment-603940729

declare module "meteor/ostrio:files" {

    import { Mongo } from 'meteor/mongo';
    import { ReactiveVar } from 'meteor/reactive-var';

    class FileObj<M> {
        size: number;
        name: string;
        type: string;
        path: string;
        isVideo: boolean;
        isAudio: boolean;
        isImage: boolean;
        isText: boolean;
        isJSON: boolean;
        isPDF: boolean;
        extension?: string;
        _storagePath: string;
        _downloadRoute: string;
        _collectionName: string;
        public?: boolean;
        meta?: M;
        userId?: string;
        updatedAt?: Date;
        versions: Object;
    }

    type FileRef = any; // File record from Mongo DB... don't know the details yet

    interface FileData<M> {
        size: number;
        type: string;
        mime: string;
        "mime-type": string;
        ext: string;
        extension: string;
    name: string;
    meta: M;
    }

    interface FilesCollectionConfig<M> {
        storagePath?: string | ((fileObj: FileObj<M>) => string);
        collection?: Mongo.Collection<any>;
        collectionName?: string;
        continueUploadTTL?: string;
        ddp?: Object;
        cacheControl?: string;
        responseHeaders?: { [x: string]: string } | ((responseCode?, fileRef?, versionRef?, version?) => { [x: string]: string });
        throttle?: number | boolean;
        downloadRoute?: string;
        schema?: Object;
        chunkSize?: number;
        namingFunction?: (fileObj: FileObj<M>) => string;
        permissions?: number;
        parentDirPermissions?: number;
        integrityCheck?: boolean;
        strict?: boolean;
        downloadCallback?: (fileObj: FileObj<M>) => boolean;
        protected?: boolean | ((fileObj: FileObj<M>) => boolean | number);
        public?: boolean;
        onBeforeUpload?: (fileData: FileData<M>) => boolean | string;
        onBeforeRemove?: (cursor: Mongo.Cursor<any>) => boolean;
        onInitiateUpload?: (fileData: FileData<M>) => void;
        onAfterUpload?: (fileRef: FileRef) => any;
        onAfterRemove?: (files: Object[]) => any;
        onbeforeunloadMessage?: string | (() => string);
        allowClientCode?: boolean;
        debug?: boolean;
        interceptDownload?: (http: any, fileRef: any, version: string) => boolean;
    }

    export interface SearchOptions {
        sort?: Mongo.SortSpecifier;
        skip?: number;
        limit?: number;
        fields?: Mongo.FieldSpecifier;
        reactive?: boolean;
        transform?: Function;
    }

    export interface InsertOptions {
        file: File | Object | string;
        isBase64?: boolean;
        meta?: { [x: string]: any };
        transport?: 'ddp' | 'http'
        onStart?: (error: Object, fileData: Object) => any;
        onUploaded?: (error: Object, fileData: Object) => any;
        onAbort?: (fileData: Object) => any;
        onError?: (error: Object, fileData: Object) => any;
        onProgress?: (progress: number, fileData: Object) => any;
        onBeforeUpload?: (fileData: Object) => any;
        streams?: number | 'dynamic';
        chunkSize?: number | 'dynamic';
        allowWebWorkers?: boolean;
    }

    export interface LoadOptions<M> {
        fileName: string;
        meta?: M;
        type?: string;
        size?: number;
    }

    export class FileUpload {
        file: File;
        onPause: ReactiveVar<boolean>;
        progress: ReactiveVar<number>;
        estimateTime: ReactiveVar<number>;
        estimateSpeed: ReactiveVar<number>;
        state: ReactiveVar<'active' | 'paused' | 'aborted' | 'completed'>;

        pause();
        continue();
        toggle();
        pipe();
        start();
        on(event: string, callback: Function): void;
    }

    export class FileCursor<M> extends FileObj<M> { // Is it correct to say that it extends FileObj?
        remove(callback: (err) => void): void;
        link(): string;
        get(property: string): Object | any;
        fetch(): Object[];
        with(): ReactiveVar<FileCursor<M>>;
    }

    export class FilesCursor<M> extends Mongo.Cursor<FileObj<M>> {
        cursor: Mongo.Cursor<FileObj<M>>; // Refers to base cursor? Why is this existing?

        get(): Object[];
        hasNext(): boolean;
        next(): Object;
        hasPrevious(): boolean;
        previous(): Object;
        first(): Object;
        last(): Object;
        remove(callback: (err) => void): void;
        each(): FileCursor<M>[];
        current(): Object | undefined;
    }

    export class FilesCollection<M> {
        collection: Mongo.Collection<FileObj<M>>;
        schema: any;

        constructor(config: FilesCollectionConfig<M>)

        find(selector?: Mongo.Selector<FileObj<M>>, options?: SearchOptions): FilesCursor<M>;
        findOne(selector?: Mongo.Selector<FileObj<M>>, options?: SearchOptions): FileCursor<M>;
        insert(settings: InsertOptions, autoStart?: boolean): FileUpload;
        remove(select: Mongo.Selector<FileObj<M>>, callback: (error) => any): FilesCollection<M>;
        link(fileRef: FileRef, version?: string): string;
        allow(options: Mongo.AllowDenyOptions): void;
        deny(options: Mongo.AllowDenyOptions): void;
        denyClient(): void;
        on(event: string, callback: (fileRef: FileRef) => void): void;
        unlink(fileRef: FileRef, version?: string): FilesCollection<M>;
        addFile(path: string, opts: LoadOptions<M>, callback: (err: any, fileRef: FileRef) => any, proceedAfterUpload: boolean);
        load(url: string, opts: LoadOptions<M>, callback: (err: any, fileRef: FileRef) => any, proceedAfterUpload: boolean);
        write(buffer: Buffer, opts: LoadOptions<M>, callback: (err: any, fileRef: FileRef) => any, proceedAfterUpload: boolean);
    }
}

@OliverColeman thank you for contribution!

Feel free to send a PR to the docs, here's original file — https://github.com/VeliovGroup/Meteor-Files/blob/dev/docs/typescript-definitions.md

Please, make sure you're pushing to dev branch;

Reopening as updates submitted by @OliverColeman are pending for PR

Closed with #743, thanks to @OliverColeman

Was this page helpful?
0 / 5 - 0 ratings