2
2
3
3
``` ts
4
4
declare module " meteor/ostrio:files" {
5
-
6
5
import { Mongo } from ' meteor/mongo' ;
7
6
import { ReactiveVar } from ' meteor/reactive-var' ;
7
+ import { SimpleSchemaDefinition } from ' simpl-schema' ;
8
+
9
+
10
+ interface Version <MetadataType > {
11
+ extension: string ;
12
+ meta: MetadataType ;
13
+ path: string ;
14
+ size: number ;
15
+ type: string ;
16
+ }
17
+
8
18
9
- class FileObj {
19
+ class FileObj <MetadataType > {
20
+ _id: string ;
10
21
size: number ;
11
22
name: string ;
12
23
type: string ;
@@ -17,92 +28,112 @@ declare module "meteor/ostrio:files" {
17
28
isText: boolean ;
18
29
isJSON: boolean ;
19
30
isPDF: boolean ;
31
+ ext? : string ;
20
32
extension? : string ;
33
+ extensionWithDot: string ;
21
34
_storagePath: string ;
22
35
_downloadRoute: string ;
23
36
_collectionName: string ;
24
37
public? : boolean ;
25
- meta? : Object ;
38
+ meta? : MetadataType ;
26
39
userId? : string ;
27
40
updatedAt? : Date ;
28
- versions: Object ;
41
+ versions: {
42
+ [propName : string ]: Version <MetadataType >;
43
+ };
44
+ mime: string ;
45
+ " mime-type" : string ;
29
46
}
30
47
31
- type FileRef = any ; // File record from Mongo DB... don't know the details yet
32
48
33
- interface FileData {
49
+ type FileRef <MetadataType > = FileObj <MetadataType > & {
50
+ remove: (callback : (error : any ) => void ) => void ;
51
+ link: (version ? : string , location ? : string ) => string ;
52
+ get: (property ? : string ) => FileObj <MetadataType > | any ;
53
+ fetch: () => FileObj <MetadataType >[]
54
+ with: () => FileCursor <MetadataType >
55
+ }
56
+
57
+
58
+ interface FileData <MetadataType > {
34
59
size: number ;
35
60
type: string ;
36
61
mime: string ;
37
62
" mime-type" : string ;
38
63
ext: string ;
39
64
extension: string ;
40
65
name: string ;
66
+ meta: MetadataType ;
41
67
}
42
68
43
- interface FilesCollectionConfig {
44
- storagePath? : string ;
45
- collection? : Mongo .Collection <any >;
69
+
70
+ interface FilesCollectionConfig <MetadataType > {
71
+ storagePath? : string | ((fileObj : FileObj <MetadataType >) => string );
72
+ collection? : Mongo .Collection <FileObj <MetadataType >>;
46
73
collectionName? : string ;
47
74
continueUploadTTL? : string ;
48
75
ddp? : Object ;
49
76
cacheControl? : string ;
50
- responseHeaders? : { [x : string ]: string } | ((responseCode ? , fileRef ? , versionRef ? , version ? ) => { [x : string ]: string });
77
+ responseHeaders? : { [x : string ]: string } | ((responseCode ? : string , fileRef ? : FileRef < MetadataType > , versionRef ? : Version < MetadataType > , version ? : string ) => { [x : string ]: string });
51
78
throttle? : number | boolean ;
52
79
downloadRoute? : string ;
53
- schema? : Object ;
80
+ schema? : SimpleSchemaDefinition ;
54
81
chunkSize? : number ;
55
- namingFunction? : () => string ;
82
+ namingFunction? : (fileObj : FileObj < MetadataType > ) => string ;
56
83
permissions? : number ;
57
84
parentDirPermissions? : number ;
58
85
integrityCheck? : boolean ;
59
86
strict? : boolean ;
60
- downloadCallback? : (fileObj : FileObj ) => boolean ;
61
- protected? : boolean | ((fileObj : FileObj ) => boolean | number );
87
+ downloadCallback? : (fileObj : FileObj < MetadataType > ) => boolean ;
88
+ protected? : boolean | ((fileObj : FileObj < MetadataType > ) => boolean | number );
62
89
public? : boolean ;
63
- onBeforeUpload? : (fileData : FileData ) => boolean | string ;
64
- onBeforeRemove? : (cursor : Mongo .Cursor <any >) => boolean ;
65
- onInitiateUpload? : (fileData : FileData ) => void ;
66
- onAfterUpload? : (fileRef : FileRef ) => any ;
67
- onAfterRemove? : (files : Object []) => any ;
90
+ onBeforeUpload? : (fileData : FileData < MetadataType > ) => boolean | string ;
91
+ onBeforeRemove? : (cursor : Mongo .Cursor <FileObj < MetadataType > >) => boolean ;
92
+ onInitiateUpload? : (fileData : FileData < MetadataType > ) => void ;
93
+ onAfterUpload? : (fileRef : FileRef < MetadataType > ) => any ;
94
+ onAfterRemove? : (files : FileObj < MetadataType > []) => any ;
68
95
onbeforeunloadMessage? : string | (() => string );
69
96
allowClientCode? : boolean ;
70
97
debug? : boolean ;
71
- interceptDownload? : (http : any , fileRef : any , version : string ) => boolean ;
98
+ interceptDownload? : (http : Object , fileRef : FileRef < MetadataType > , version : string ) => boolean ;
72
99
}
100
+
73
101
74
- export interface SearchOptions {
102
+ export interface SearchOptions < MetadataType , TransformedType > {
75
103
sort? : Mongo .SortSpecifier ;
76
104
skip? : number ;
77
105
limit? : number ;
78
106
fields? : Mongo .FieldSpecifier ;
79
107
reactive? : boolean ;
80
- transform? : Function ;
108
+ transform? : ( fileObj : FileObj < MetadataType >) => FileObj < TransformedType > ;
81
109
}
110
+
82
111
83
- export interface InsertOptions {
112
+ export interface InsertOptions < MetadataType > {
84
113
file: File | Object | string ;
85
114
isBase64? : boolean ;
86
- meta? : { [ x : string ] : any } ;
115
+ meta? : MetadataType ;
87
116
transport? : ' ddp' | ' http'
88
- onStart? : (error : Object , fileData : Object ) => any ;
89
- onUploaded? : (error : Object , fileData : Object ) => any ;
90
- onAbort? : (fileData : Object ) => any ;
91
- onError? : (error : Object , fileData : Object ) => any ;
92
- onProgress? : (progress : number , fileData : Object ) => any ;
93
- onBeforeUpload? : (fileData : Object ) => any ;
117
+ onStart? : (error : Object , fileData : FileData < MetadataType > ) => any ;
118
+ onUploaded? : (error : Object , fileRef : FileRef < MetadataType > ) => any ;
119
+ onAbort? : (fileData : FileData < MetadataType > ) => any ;
120
+ onError? : (error : Object , fileData : FileData < MetadataType > ) => any ;
121
+ onProgress? : (progress : number , fileData : FileData < MetadataType > ) => any ;
122
+ onBeforeUpload? : (fileData : FileData < MetadataType > ) => any ;
94
123
streams? : number | ' dynamic' ;
95
124
chunkSize? : number | ' dynamic' ;
96
125
allowWebWorkers? : boolean ;
97
126
}
98
127
99
- export interface LoadOptions {
128
+
129
+ export interface LoadOptions <MetadataType > {
100
130
fileName: string ;
101
- meta? : Object ;
131
+ meta? : MetadataType ;
102
132
type? : string ;
103
133
size? : number ;
104
134
}
105
135
136
+
106
137
export class FileUpload {
107
138
file: File ;
108
139
onPause: ReactiveVar <boolean >;
@@ -119,16 +150,18 @@ declare module "meteor/ostrio:files" {
119
150
on(event : string , callback : Function ): void ;
120
151
}
121
152
122
- export class FileCursor extends FileObj { // Is it correct to say that it extends FileObj?
153
+
154
+ export class FileCursor <MetadataType > extends FileObj <MetadataType > { // Is it correct to say that it extends FileObj?
123
155
remove(callback : (err ) => void ): void ;
124
156
link(): string ;
125
157
get(property : string ): Object | any ;
126
158
fetch(): Object [];
127
- with(): ReactiveVar <FileCursor >;
159
+ with(): ReactiveVar <FileCursor < MetadataType > >;
128
160
}
129
161
130
- export class FilesCursor extends Mongo .Cursor <FileObj > {
131
- cursor: Mongo .Cursor <FileObj >; // Refers to base cursor? Why is this existing?
162
+
163
+ export class FilesCursor <MetadataType > extends Mongo .Cursor <FileObj <MetadataType >> {
164
+ cursor: Mongo .Cursor <FileObj <MetadataType >>; // Refers to base cursor? Why is this existing?
132
165
133
166
get(): Object [];
134
167
hasNext(): boolean ;
@@ -138,29 +171,46 @@ declare module "meteor/ostrio:files" {
138
171
first(): Object ;
139
172
last(): Object ;
140
173
remove(callback : (err ) => void ): void ;
141
- each(): FileCursor [];
174
+ each(): FileCursor < MetadataType > [];
142
175
current(): Object | undefined ;
143
176
}
144
177
145
- export class FilesCollection {
146
- collection: Mongo .Collection <FileObj >;
147
- schema: any ;
148
-
149
- constructor (config : FilesCollectionConfig )
150
178
151
- find(selector ? : Mongo .Selector , options ? : SearchOptions ): FilesCursor ;
152
- findOne(selector ? : Mongo .Selector , options ? : SearchOptions ): FileCursor ;
153
- insert(settings : InsertOptions , autoStart ? : boolean ): FileUpload ;
154
- remove(select : Mongo .Selector , callback : (error ) => any ): FilesCollection ;
155
- link(fileRef : FileRef , version ? : string ): string ;
179
+ export class FilesCollection <MetadataType = { [x : string ]: any }> {
180
+ collection: Mongo .Collection <FileObj <MetadataType >>;
181
+ schema: SimpleSchemaDefinition ;
182
+
183
+ constructor (config : FilesCollectionConfig <MetadataType >)
184
+
185
+ /**
186
+ * Find and return Cursor for matching documents.
187
+ *
188
+ * @param selector [[http://docs.meteor.com/api/collections.html#selectors | Mongo-Style selector]]
189
+ * @param options [[http://docs.meteor.com/api/collections.html#sortspecifiers | Mongo-Style selector Options]]
190
+
191
+ * @typeParam TransformedType The result of transforming a document with options.tranform().
192
+ */
193
+ find<TransformedType = FileRef <MetadataType >>(selector ? : Mongo .Selector <Partial <FileObj <MetadataType >>>, options ? : SearchOptions <MetadataType , TransformedType >): FilesCursor <TransformedType >;
194
+ /**
195
+ * Finds the first document that matches the selector, as ordered by sort and skip options.
196
+ *
197
+ * @param selector [[http://docs.meteor.com/api/collections.html#selectors | Mongo-Style selector]]
198
+ * @param options [[http://docs.meteor.com/api/collections.html#sortspecifiers | Mongo-Style selector Options]]
199
+
200
+ * @typeParam TransformedType The result of transforming a document with options.tranform().
201
+ */
202
+ findOne<TransformedType = FileRef <MetadataType >>(selector ? : Mongo .Selector <Partial <FileObj <MetadataType >>> | string , options ? : SearchOptions <MetadataType , TransformedType >): FileCursor <TransformedType >;
203
+ insert(settings : InsertOptions <MetadataType >, autoStart ? : boolean ): FileUpload ;
204
+ remove(select : Mongo .Selector <FileObj <MetadataType >> | string , callback ? : (error : Object ) => Object ): FilesCollection <MetadataType >;
205
+ link(fileRef : FileRef <MetadataType >, version ? : string ): string ;
156
206
allow(options : Mongo .AllowDenyOptions ): void ;
157
207
deny(options : Mongo .AllowDenyOptions ): void ;
158
208
denyClient(): void ;
159
- on(event : string , callback : (fileRef : FileRef ) => void ): void ;
160
- unlink(fileRef : FileRef , version ? : string ): FilesCollection ;
161
- addFile(path : string , opts : LoadOptions , callback : (err : any , fileRef : FileRef ) => any , proceedAfterUpload : boolean );
162
- load(url : string , opts : LoadOptions , callback : (err : any , fileRef : FileRef ) => any , proceedAfterUpload : boolean );
163
- write(buffer : Buffer , opts : LoadOptions , callback : (err : any , fileRef : FileRef ) => any , proceedAfterUpload : boolean );
209
+ on(event : string , callback : (fileRef : FileRef < MetadataType > ) => void ): void ;
210
+ unlink(fileRef : FileRef < MetadataType > , version ? : string ): FilesCollection < MetadataType > ;
211
+ addFile(path : string , opts : LoadOptions < MetadataType > , callback : (err : any , fileRef : FileRef < MetadataType > ) => any , proceedAfterUpload : boolean ): FilesCollection < MetadataType > ;
212
+ load(url : string , opts : LoadOptions < MetadataType > , callback : (err : Object , fileRef : FileRef < MetadataType > ) => any , proceedAfterUpload : boolean ): FilesCollection < MetadataType > ;
213
+ write(buffer : Buffer , opts : LoadOptions < MetadataType > , callback : (err : Object , fileRef : FileRef < MetadataType > ) => any , proceedAfterUpload : boolean ): FilesCollection < MetadataType > ;
164
214
}
165
215
}
166
216
```
0 commit comments