-
-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript definitions for Meteor-Files #226
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. 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:
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 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:
|
@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 |
Reopening as updates submitted by @OliverColeman are pending for PR |
Closed with #743, thanks to @OliverColeman |
- 🐞 Fix #742, thanks to @menelike and @jankapunkt - 🤓 Update *TypeScript* definitions, thanks to @OliverColeman PR #743, see #226 thread for details - 🤝 Compatibility with `[email protected]` - 📋 Documentation update to address issue described in #737, thanks to @menelike, @Lickshotz, @s-ol, and @jankapunkt
v1.14.2 - 🐞 Fix #742, thanks to @menelike and @jankapunkt - 🤓 Update *TypeScript* definitions, thanks to @OliverColeman PR #743, see #226 thread for details - 🤝 Compatibility with `[email protected]` - 📋 Documentation update to address issue described in #737, thanks to @menelike, @Lickshotz, @s-ol, and @jankapunkt
Shouldn't the type for |
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 |
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 optionalEdit 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.
The text was updated successfully, but these errors were encountered: