Skip to content

Commit 84f12c0

Browse files
Add Metadata to types and run it through prettier (#203)
1 parent aa6cf11 commit 84f12c0

File tree

1 file changed

+44
-32
lines changed

1 file changed

+44
-32
lines changed

index.d.ts

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,99 @@
11
import { EventEmitter } from "events";
2-
import http from 'http';
2+
import * as fs from "fs";
3+
import http from "http";
34

45
/**
56
* arguments of constructor which in class extend DataStore
67
*/
7-
declare interface DataStoreOptions{
8+
declare interface DataStoreOptions {
89
path: string;
9-
namingFunction?: (req : http.IncomingMessage) => string;
10+
namingFunction?: (req: http.IncomingMessage) => string;
1011
relativeLocation?: string;
1112
}
1213

13-
declare interface FileStoreOptions extends DataStoreOptions{
14+
declare interface FileStoreOptions extends DataStoreOptions {
1415
directory?: string;
1516
}
1617

17-
declare interface GCStoreOptions extends DataStoreOptions{
18+
declare interface GCStoreOptions extends DataStoreOptions {
1819
bucket: string;
1920
projectId: string;
2021
keyFilename: string;
2122
}
2223

23-
declare interface S3StoreOptions extends DataStoreOptions{
24+
declare interface S3StoreOptions extends DataStoreOptions {
2425
accessKeyId: string;
2526
secretAccessKey: string;
2627
bucket: string;
2728
tmpDirPrefix: string;
2829
partSize: number;
2930
}
3031

31-
declare class File{
32+
declare class File {
3233
id: string;
3334
upload_length: any;
3435
upload_defer_length: any;
3536
upload_metadata: any;
36-
constructor(file_id: string, upload_length: any, upload_defer_length: any, upload_metadata: any);
37+
constructor(
38+
file_id: string,
39+
upload_length: any,
40+
upload_defer_length: any,
41+
upload_metadata: any
42+
);
3743
}
3844

3945
/**
4046
* Based store for all DataStore classes.
4147
*/
42-
export declare class DataStore extends EventEmitter{
43-
constructor(options : DataStoreOptions);
44-
get extensions() : any;
45-
set extensions(extensions_array : any);
46-
create(req: http.IncomingMessage): Promise<any>;
47-
write(req: http.IncomingMessage, file_id?: string, offset?: number): Promise<any>;
48-
getOffset(id: string): Promise<any>;
48+
export declare class DataStore extends EventEmitter {
49+
constructor(options: DataStoreOptions);
50+
get extensions(): any;
51+
set extensions(extensions_array: any);
52+
create(req: Partial<http.IncomingMessage>): Promise<any>;
53+
write(
54+
req: http.IncomingMessage,
55+
file_id?: string,
56+
offset?: number
57+
): Promise<any>;
58+
getOffset(file_id: string): Promise<any>;
4959
}
5060

5161
/**
5262
* file store in local storage
5363
*/
54-
export declare class FileStore extends DataStore{
55-
constructor(options : FileStoreOptions);
56-
create(req: http.IncomingMessage): Promise<any>;
57-
write(req: http.IncomingMessage, file_id?: string, offset?: number): Promise<any>;
58-
getOffset(file_id: string): Promise<any>;
64+
export declare class FileStore extends DataStore {
65+
constructor(options: FileStoreOptions);
66+
read(file_id: string): fs.ReadStream;
67+
getOffset(file_id: string): Promise<fs.Stats & File>;
5968
}
6069

6170
/**
6271
* file store in Google Cloud
6372
*/
64-
export declare class GCSDataStore extends DataStore{
73+
export declare class GCSDataStore extends DataStore {
6574
constructor(options: GCStoreOptions);
66-
create(req: http.IncomingMessage): Promise<any>;
67-
write(req: http.IncomingMessage, file_id?: string, offset?: number): Promise<any>;
68-
getOffset(file_id: string): Promise<any>;
6975
}
7076

7177
/**
7278
* file store in AWS S3
7379
*/
7480
export declare class S3Store extends DataStore {
75-
constructor(options : S3StoreOptions);
76-
create(req: http.IncomingMessage): Promise<any>;
77-
write(req: http.IncomingMessage, file_id?: string, offset?: number): Promise<any>;
78-
getOffset(file_id: string, with_parts?: boolean): Promise<any>;
81+
constructor(options: S3StoreOptions);
82+
getOffset(file_id: string, with_parts?: boolean): Promise<any>;
7983
}
8084

8185
/**
8286
* Tus protocol server implements
8387
*/
84-
export declare class Server extends EventEmitter{
88+
export declare class Server extends EventEmitter {
8589
constructor();
86-
get datastore() : DataStore;
90+
get datastore(): DataStore;
8791
set datastore(store: DataStore);
88-
get(path: string, callback: Function): any;
89-
handle(req: http.IncomingMessage, res: http.ServerResponse): http.ServerResponse;
92+
get(path: string, callback: (...args) => any): any;
93+
handle(
94+
req: http.IncomingMessage,
95+
res: http.ServerResponse
96+
): http.ServerResponse;
9097
listen(): http.Server;
9198
}
9299

@@ -130,3 +137,8 @@ export declare const ERRORS: {
130137
body: string;
131138
};
132139
};
140+
141+
export declare class Metadata {
142+
static parse(str: string): Record<string, string>;
143+
static stringify(metadata: Record<string, string>): string;
144+
}

0 commit comments

Comments
 (0)