forked from xxzefgh/adonisjs-types
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
353 lines (322 loc) · 13.5 KB
/
index.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
declare namespace Adonis {
type WorkInProgress = any
class Config {
syncWithFileSystem(): void
get(key: string, defaultValue?: any): any
merge(key: string, defaultValues: Object, customizer?: Function): Object
set(key: string, value: any): void
}
class Env {
load(filePath: string, overwrite?: true, encoding?: 'utf-8'): void
getEnvPath(): string
get(key: string, defaultValue?: any): any
set(key: string, value: any): void
}
type EventListeners = string | string[] | Function
class Event {
getListeners(event: string): Array<string | Function>
getListenersAny(): Array<string | Function>
hasListeners(event: string): boolean
listenersCount(event: string): number
times(number: number): Event
on(event: string, listeners: EventListeners): void
when(event: string, listeners: EventListeners): void
once(event: string, listeners: EventListeners): void
any(listeners: EventListeners): void
onAny(listeners: EventListeners): void
emit(event: string, ...args: any[]): void
fire(event: string, ...args: any[]): void
off(event: string, listeners: EventListeners): void
offAny(listeners: EventListeners): void
removeListener(event: string, listeners: EventListeners): void
removeAllListeners(event: string): void
setMaxListeners(number: number): void
fake(): void
restore(): void
}
class Encryption {
encrypt(input: string | number | Object): string
decrypt(cipherText: string): string | number | Object
base64Encode(input: string): string
base64Decode(encodedText: string): string
// base64Decode(encodedText: NodeBuffer): string
}
type ExceptionHandler = (error: any, ctx: Http.Context) => void
class Exception {
clear(): void
getHandler(name: string): Function | undefined
getReporter(name: string): Function | undefined
handle(name: string, callback: ExceptionHandler): Exception
handle(name: string, callback: ExceptionHandler): Exception
}
class Hash {
make(value: string, rounds: number): Promise<string>
verify(value: string, hash: string): Promise<boolean>
}
class Helpers {
configPath(): string
appRoot(toFile?: ''): string
publicPath(toFile?: ''): string
resourcesPath(toFile?: ''): string
viewsPath(toFile?: ''): string
databasePath(toFile?: ''): string
migrationsPath(toFile?: ''): string
seedsPath(toFile?: ''): string
tmpPath(toFile?: ''): string
promisify(fn: Function, options: Object): Promise<any>
isAceCommand(): boolean
}
type LogLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
class Logger {
level: LogLevel
log(level: LogLevel, message: string, ...options: any[]): void
debug(message: string, ...options: any[]): void
info(message: string, ...options: any[]): void
notice(message: string, ...options: any[]): void
warning(message: string, ...options: any[]): void
error(message: string, ...options: any[]): void
crit(message: string, ...options: any[]): void
alert(message: string, ...options: any[]): void
emerg(message: string, ...options: any[]): void
}
namespace Lucid {
interface ConstructableModel<t> extends Model{
new(): t
}
interface Model {
new(): Model
save(): Object
all(): Object
boot(): any
addHook(action: string, callback: string): any
hasMany(path: string): Object
}
}
namespace Http {
class Request {
body: Object
get(): Object
post(): Object
all(): Object
raw(): Object
collect(keys: string[]): Object[]
input(key: string, defaultValue?: any): any
except(keys: string[]): Object
only(keys: string[]): Object
method(): string
intended(): string
headers(): Object
header(key: string, defaultValue?: any): any
ip(trust?: boolean): string
ips(trust?: boolean): string[]
protocol(trust?: boolean): string
secure(): boolean
subdomains(trust?: boolean, offset?: number): string[]
ajax(): boolean
pjax(): boolean
hostname(trust?: boolean): string
url(): string
originalUrl(): string
is(types: string[]): string
accepts(types: string[]): string | string[]
types(): string[]
language(acceptedLanguages: string[]): string
languages(): string[]
encoding(acceptedEncodings: string[]): string
encodings(): string[]
charset(acceptedCharsets: string[]): string
charsets(): string[]
hasBody(): boolean
cookies(): { [key: string]: string }
plainCookies(): { [key: string]: string }
cookie(key: string, defaultValue?: any): any
plainCookie(key: string, defaultValue?: any): any
match(routes: string[]): boolean
fresh(): boolean
stale(): boolean
format(): string
}
class Response {
finished: boolean
headersSent: boolean
isPending: boolean
status(): number
header(key: string, value: string): Response
safeHeader(key: string, value: string): Response
removeHeader(key: string): Response
getHeader(key: string): string | void
download(filePath: string, options?: {}): void
attachment(filePath: string, name?: string, disposition?: string, options?: {}): void
location(url: string): Response
redirect(url: string, sendParams?: false, status?: 302): void
route(routeNameOrHandler: string, data?: {}, domain?: string, sendParams?: false, status?: 302): void
vary(field: string): Response
type(type: string, charset?: string): Response
send(body: any, generateEtag?: boolean): void
json(body: Object, generateEtag?: boolean): void
jsonp(body: Object, callbackFn?: Function, generateEtag?: boolean): void
end(): void
cookie(key: string, value: any, options?: {}): void
plainCookie(key: string, value: any, options?: {}): void
clearCookie(key: string): void
abortIf(expression: any, status: number, body: any): void
abortUnless(expression: any, status: number, body: any): void
}
class Context {
auth: WorkInProgress
request: Adonis.Http.Request
response: Adonis.Http.Response
view: Adonis.View
session: Adonis.Session
}
type Handler = (ctx: Context) => any
}
class Route {
domain(domain: string): Route
formats(formats: string[], strict: false): Route
as(name: string): Route
middleware(middleware: string | string[]): Route
middleware(...middleware: Function[]): Route
prependMiddleware(middleware: string | string[]): Route
prependMiddleware(...middleware: Function[]): Route
prefix(prefix: string): Route
resolve(url: string, verb: 'string', host?: string): { url: string; params: string[]; subdomains: {} } | null
toJSON(): {
route: Route
verbs: string[]
handler: string | Http.Handler
middleware: Array<string | Function>
name: string
domain?: RegExp
}
}
namespace Route {
class Brisk {
setHandler(handler: Function | string, verbs: string[]): Route
render(template: string, data?: {}): Route
}
class Group {
middleware(middleware: string | string[]): Group
middleware(...middleware: Function[]): Group
formats(formats: string[], strict: false): Group
prefix(prefix: string): Group
domain(domain: string): Group
}
class Resource {
only(names: string[]): Resource
except(names: string[]): Resource
apiOnly(): Resource
middleware(middleware: string | string[]): Resource
middleware(middleware: Map<string[], string>): Resource
formats(formats: string[], strict: false): Resource
}
class Manager {
route(route: string, handler: string | Http.Handler, verbs: string[]): Route
get(route: string, handler: string | Http.Handler): Route
post(route: string, handler: string | Http.Handler): Route
put(route: string, handler: string | Http.Handler): Route
patch(route: string, handler: string | Http.Handler): Route
delete(route: string, handler: string | Http.Handler): Route
any(route: string, handler: string | Http.Handler): Route
on(route: string): Brisk
match(url: string, verb: string, host?: string): Object | null
group(callback: Function): Group
group(name: string, callback: Function): Group
resource(resouce: string, controller: string): Resource
list(): Route[]
url(routeNameOrHandler: string, data?: {}, options?: string): string | null
}
}
type HttpServer = any // node Server instance
class Server {
registerGlobal(middleware: string[]): Server
use(middleware: string[]): Server
registerNamed(middleware: string[]): Server
getInstance(): HttpServer
setInstance(httpInstance: HttpServer): void
handle(req: any, res: any): void
listen(host?: 'localhost', port?: 3333, callback?: Function): HttpServer
close(callback?: Function): void
}
class Session {
// TODO
}
class View {
engine: View.Engine
global(name: string, value: any): void
share(locals: Object): View.Engine
render(view: string, data?: {}): string
renderString(statement: string, data?: {}): string
presenter(presenter: string): View.Engine
tag(tag: View.Tag): void
}
namespace View {
class Engine {
new(): Template
tag(tag: Tag): void
configure(options: Object): void
global(name: string, value: any): void
registerViews(location: string): void
registerPresenters(location: string): void
renderString(statement: string, data?: {}): string
compileString(statement: string, asFunction?: true): string
render(view: string, data?: {}): string
compile(view: string, asFunction?: true): string
presenter(presenter: string): Engine
share(locals: Object): Engine
}
class Template {
// TODO
}
interface Tag {
tagName: string
compile(
compiler: Object,
lexer: Object,
buffer: Object,
options: {
body: string
childs: any[]
lineno: number
}
): void
run(): void
}
}
}
declare namespace AdonisNamespaces {
type Config = 'Config' | 'Adonis/Src/Config'
type Database = 'Database' | 'Adonis/Src/Database'
type Env = 'Env' | 'Adonis/Src/Env'
type Event = 'Event' | 'Adonis/Src/Event'
type Encryption = 'Encryption' | 'Adonis/Src/Encryption'
type Exception = 'Exception' | 'Adonis/Src/Exception'
type Factory = 'Factory' | 'Adonis/Src/Factory'
type Hash = 'Hash' | 'Adonis/Src/Hash'
type Helpers = 'Helpers' | 'Adonis/Src/Helpers'
type Logger = 'Logger' | 'Adonis/Src/Logger'
type Lucid = 'Lucid' | 'Adonis/Src/Lucid'
type Route = 'Route' | 'Adonis/Src/Route'
type Schema = 'Schema' | 'Adonis/Src/Schema'
type Server = 'Server' | 'Adonis/Src/Server'
type View = 'View' | 'Adonis/Src/View'
type Ws = 'Ws' | 'Adonis/Addons/Ws'
type Model = 'Model'
}
declare function use(namespace: AdonisNamespaces.Config): Adonis.Config
declare function use(namespace: AdonisNamespaces.Database): Adonis.WorkInProgress
declare function use(namespace: AdonisNamespaces.Env): Adonis.Env
declare function use(namespace: AdonisNamespaces.Event): Adonis.Event
declare function use(namespace: AdonisNamespaces.Encryption): Adonis.Encryption
declare function use(namespace: AdonisNamespaces.Exception): Adonis.Exception
declare function use(namespace: AdonisNamespaces.Factory): Adonis.WorkInProgress
declare function use(namespace: AdonisNamespaces.Hash): Adonis.Hash
declare function use(namespace: AdonisNamespaces.Helpers): Adonis.Helpers
declare function use(namespace: AdonisNamespaces.Logger): Adonis.WorkInProgress
declare function use(namespace: AdonisNamespaces.Lucid): Adonis.WorkInProgress
declare function use(namespace: AdonisNamespaces.Model): Adonis.Lucid.Model
declare function use(namespace: AdonisNamespaces.Route): Adonis.Route.Manager
declare function use(namespace: AdonisNamespaces.Schema): Adonis.WorkInProgress
declare function use(namespace: AdonisNamespaces.Server): Adonis.Server
declare function use(namespace: AdonisNamespaces.View): Adonis.View
declare function use(namespace: AdonisNamespaces.Ws): Adonis.WorkInProgress