forked from jbaroudi/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q-io.d.ts
257 lines (214 loc) · 7.72 KB
/
Q-io.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
// Type definitions for Q-io
// Project: https://github.com/kriskowal/q-io
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
///<reference path="../node/node.d.ts" />
///<reference path="../q/Q.d.ts" />
//TODO add support for q-io/http-apps
//TODO add verified support for q-io/fs-mock
//TODO fix Readers/Writers properly
//TODO find solution for overloaded return types (QioFS.open/QioFS.read)
// for some ideas see https://typescript.codeplex.com/discussions/461587#post1105930
declare module QioFS {
//TODO how to define the multiple return types? use any for now?
export function open(path:string, options?:any):Q.Promise<any>;
//export function open(path:string, options?:any):Q.Promise<Qio.Reader>;
//export function open(path:string, options?:any):Q.Promise<Qio.Writer>;
//export function open(path:string, options?:any):Q.Promise<Buffer>;
//TODO how to define the multiple return types? use any for now?
export function read(path:string, options?:any):Q.Promise<any>;
//export function read(path:string, options?:any):Q.Promise<string>;
//export function read(path:string, options?:any):Q.Promise<Buffer>;
export function write(path:string, content:Buffer, options?:any):Q.Promise<void>;
export function write(path:string, content:string, options?:any):Q.Promise<void>;
export function append(path:string, content:Buffer, options?:any):Q.Promise<void>;
export function append(path:string, content:string, options?:any):Q.Promise<void>;
export function copy(source:string, target:string):Q.Promise<void>;
export function copyTree(source:string, target:string):Q.Promise<void>;
export function list(path:string):Q.Promise<string[]>;
export function listTree(path:string, guard?:(path:string, stat:any) => boolean):Q.Promise<string[]>;
export function listDirectoryTree(path:string):Q.Promise<string[]>;
export function makeDirectory(path:string, mode?:string):Q.Promise<void>;
export function makeDirectory(path:string, mode?:number):Q.Promise<void>;
export function makeTree(path:string, mode?:string):Q.Promise<void>;
export function makeTree(path:string, mode?:number):Q.Promise<void>;
export function remove(path:string):Q.Promise<void>;
export function removeTree(path:string):Q.Promise<void>;
export function rename(source:string, target:string):Q.Promise<void>;
export function move(source:string, target:string):Q.Promise<void>;
export function link(source:string, target:any):Q.Promise<void>;
export function symbolicCopy(source:string, target:string, type:string):Q.Promise<void>;
export function symbolicLink(target:string, link:string, type:string):Q.Promise<void>;
export function chown(path:string, uid:number, gid:number):Q.Promise<void>;
export function chmod(path:string, mode?:string):Q.Promise<void>;
export function chmod(path:string, mode?:number):Q.Promise<void>;
export function stat(path:string):Q.Promise<Stats>;
export function statLink(path:string):Q.Promise<Stats>;
export function statFd(fd:number):Q.Promise<Stats>;
export function exists(path:string):Q.Promise<boolean>;
export function isFile(path:string):Q.Promise<boolean>;
export function isDirectory(path:string):Q.Promise<boolean>;
export function isSymbolicLink(path:string):Q.Promise<boolean>;
export function lastModified(path:string):Q.Promise<Date>;
export function lastAccessed(path:string):Q.Promise<Date>;
export function split(path:string):string[];
export function join(...paths:string[]):string;
export function join(paths:string[]):string;
export function resolve(...path:string[]):string;
export function resolve(paths:string[]):string;
export function normal(...path:string[]):string;
export function normal(paths:string[]):string;
export function absolute(path:string):string;
export function canonical(path:string):Q.Promise<string>;
export function readLink(path:string):Q.Promise<string>;
export function contains(parent:string, child:string):boolean;
export function relative(source:string, target:string):Q.Promise<string>;
export function relativeFromFile(source:string, target:string):string;
export function relativeFromDirectory(source:string, target:string):string;
export function isAbsolute(path:string):boolean;
export function isRelative(path:string):boolean;
export function isRoot(path:string):boolean;
export function root(path:string):string;
export function directory(path:string):string;
export function base(path:string, extension:string):string;
export function extension(path:string):string;
//this should return a q-io/fs-mock MockFS
export function reroot(path:string):typeof QioFS;
export function toObject(path:string):{[path:string]:Buffer};
//listed but not implemented by Q-io
//export function glob(pattern):Q.Promise<string[]>;
//export function match(pattern, path:string):Q.Promise<string[]>;
//TODO link this to node.js FS module (no lazy clones)
interface Stats {
node:NodeStats;
size:number;
}
interface NodeStats {
isFile():boolean;
isDirectory():boolean;
isBlockDevice():boolean;
isCharacterDevice():boolean;
isSymbolicLink():boolean;
isFIFO():boolean;
isSocket():boolean;
node:NodeStats;
dev:number;
ino:number;
mode:number;
nlink:number;
uid:number;
gid:number;
rdev:number;
size:number;
blksize:number;
blocks:number;
atime:Date;
mtime:Date;
ctime:Date;
}
}
declare module QioHTTP {
export function request(request:Request):Q.Promise<Response>;
export function request(url:string):Q.Promise<Response>;
export function read(request:Request):Q.Promise<string>;
export function read(url:string):Q.Promise<string >;
export function normalizeRequest(request:Request):Request;
export function normalizeRequest(url:string):Request;
export function normalizeResponse(response:Response):Response;
interface Request {
url:string;
path:string;
scriptName:string;
pathInfo:string;
version:string[];
method:string;
scheme:string;
host:string;
port:number;
remoteHost:string;
remotePort:number;
headers:Headers;
agent:any;
body:any;
node:any;
}
interface Response {
status:number;
headers:Headers;
body:Qio.Reader
onclose:() => void;
node:any;
}
interface Headers {
[name:string]:any;
// [name:string]:any[];
}
interface Body extends Qio.Stream {
}
interface Application {
(req:Request):Q.Promise<any>;
}
}
declare module Qio {
interface ForEachCallback {
(chunk:Buffer):Q.Promise<any>;
(chunk:string):Q.Promise<any>;
}
interface ForEach {
forEach(callback:ForEachCallback):Q.Promise<void>;
}
interface Reader extends ForEach {
read(charset:string):Q.Promise<string>;
read():Q.Promise<Buffer>;
close():void;
node: NodeJS.ReadableStream;
}
interface Writer {
write(content:string):void;
write(content:Buffer):void;
flush():Q.Promise<void>;
close():void;
destroy():void;
node: NodeJS.WritableStream;
}
interface Stream {
read(charset:string):Q.Promise<string>;
read():Q.Promise<Buffer>;
write(content:string):void;
write(content:Buffer):void;
flush():Q.Promise<void>;
close():void;
destroy():void;
node:any;
}
interface BufferReader extends QioBufferReader {
}
}
interface QioBufferReader {
new ():Qio.Reader;
read(stream:Qio.Reader, charset:string):string;
read(stream:Qio.Reader):Buffer;
join(buffers:Buffer[]):Buffer;
}
interface QioBufferWriter {
(writer:Buffer):Qio.Writer;
Writer:Qio.Writer;
}
interface QioBufferStream {
(buffer:Buffer, encoding:string):Qio.Stream
}
declare module "q-io/http" {
export = QioHTTP;
}
declare module "q-io/fs" {
export = QioFS;
}
declare module "q-io/reader" {
export = QioBufferReader;
}
declare module "q-io/writer" {
export = QioBufferWriter;
}
declare module "q-io/buffer-stream" {
export = QioBufferStream;
}