Closed Lavan closed 4 years ago
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:
FilesCollectionConfig.storagePath
should also accept a function); and 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
Shouldn't the type for FileUpload
's on
member be on(event: string, callback(error: unknown, obj: FileObj<MetadataType>) => void): void
? With perhaps a proper type for error
rather than unknown
, I'm not sure what that should be right now.
@Delph thank you for the addition @Lavan can you check on the suggestion over your PR, please?
I now have;
type FileUploadCallback<MetadataType> = ((error: unknown, obj: FileObj<MetadataType>) => void) |
((progress: number, obj: FileObj<MetadataType>) => void)
class FileUpload<MetadataType> {
file: File;
onPause: ReactiveVar<boolean>;
progress: ReactiveVar<number>;
estimateTime: ReactiveVar<number>;
estimateSpeed: ReactiveVar<number>;
state: ReactiveVar<'active' | 'paused' | 'aborted' | 'completed'>;
pause(): void;
continue(): void;
toggle(): void;
pipe(): void;
start(): void;
on(event: string, callback: FileUploadCallback<MetadataType>): void;
}
@Delph do you wish to PR into typescript-definitions.md
?
I have no comment at all regarding this. I haven't used meteor at all these last 4-5 years.
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.
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.