@h3ravel/contracts 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +43 -0
- package/dist/index.cjs +348 -0
- package/dist/index.d.ts +4464 -0
- package/dist/index.js +312 -0
- package/package.json +65 -0
- package/tsconfig.json +8 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4464 @@
|
|
|
1
|
+
/// <reference path="./app.globals.d.ts" />
|
|
2
|
+
import { H3, H3Event, HTTPResponse, Middleware, MiddlewareOptions, serve } from "h3";
|
|
3
|
+
import { IApplication as IApplication$1 } from "@h3ravel/contracts";
|
|
4
|
+
import { DotNestedKeys as DotNestedKeys$1, DotNestedValue as DotNestedValue$1 } from "@h3ravel/shared";
|
|
5
|
+
import { Edge } from "edge.js";
|
|
6
|
+
import { Builder, Model } from "@h3ravel/arquebus";
|
|
7
|
+
import { IQueryBuilder } from "@h3ravel/arquebus/types";
|
|
8
|
+
import { Command, Kernel } from "@h3ravel/musket";
|
|
9
|
+
import In from "simple-body-validator/lib/cjs/rules/in";
|
|
10
|
+
import NotIn from "simple-body-validator/lib/cjs/rules/notIn";
|
|
11
|
+
import Regex from "simple-body-validator/lib/cjs/rules/regex";
|
|
12
|
+
import RequiredIf from "simple-body-validator/lib/cjs/rules/requiredIf";
|
|
13
|
+
import { Rule as Rule$1 } from "simple-body-validator";
|
|
14
|
+
|
|
15
|
+
//#region src/Routing/IMiddleware.d.ts
|
|
16
|
+
/**
|
|
17
|
+
* Defines the contract for all middlewares.
|
|
18
|
+
* Any middleware implementing this must define these methods.
|
|
19
|
+
*/
|
|
20
|
+
declare abstract class IMiddleware {
|
|
21
|
+
options: {
|
|
22
|
+
only?: RouteMethod[];
|
|
23
|
+
except?: RouteMethod[];
|
|
24
|
+
};
|
|
25
|
+
abstract handle(...args: any[]): Promise<any>;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/Core/IController.d.ts
|
|
29
|
+
/**
|
|
30
|
+
* Defines the contract for all controllers.
|
|
31
|
+
*/
|
|
32
|
+
declare abstract class IController {
|
|
33
|
+
show?(...ctx: any[]): any;
|
|
34
|
+
edit?(...ctx: any[]): any;
|
|
35
|
+
index?(...ctx: any[]): any;
|
|
36
|
+
store?(...ctx: any[]): any;
|
|
37
|
+
create?(...ctx: any[]): any;
|
|
38
|
+
update?(...ctx: any[]): any;
|
|
39
|
+
destroy?(...ctx: any[]): any;
|
|
40
|
+
__invoke?(...ctx: any[]): any;
|
|
41
|
+
callAction?(method: ResourceMethod, parameters: any[]): any;
|
|
42
|
+
getMiddleware?(): IMiddleware;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/Core/IServiceProvider.d.ts
|
|
46
|
+
declare abstract class IServiceProvider {
|
|
47
|
+
/**
|
|
48
|
+
* Unique Identifier for service providers
|
|
49
|
+
*/
|
|
50
|
+
static uid?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Sort order
|
|
53
|
+
*/
|
|
54
|
+
static order?: `before:${string}` | `after:${string}` | string | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Sort priority
|
|
57
|
+
*/
|
|
58
|
+
static priority?: number;
|
|
59
|
+
/**
|
|
60
|
+
* Indicate that this service provider only runs in console
|
|
61
|
+
*/
|
|
62
|
+
static runsInConsole?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Indicate that this service provider only runs in console
|
|
65
|
+
*/
|
|
66
|
+
static console?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Indicate that this service provider only runs in console
|
|
69
|
+
*/
|
|
70
|
+
abstract console?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Indicate that this service provider only runs in console
|
|
73
|
+
*/
|
|
74
|
+
abstract runsInConsole: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* List of registered console commands
|
|
77
|
+
*/
|
|
78
|
+
abstract registeredCommands?: (new (app: any, kernel: any) => any)[];
|
|
79
|
+
/**
|
|
80
|
+
* An array of console commands to register.
|
|
81
|
+
*/
|
|
82
|
+
abstract commands?(commands: (new (app: any, kernel: any) => any)[]): void;
|
|
83
|
+
/**
|
|
84
|
+
* Register bindings to the container.
|
|
85
|
+
* Runs before boot().
|
|
86
|
+
*/
|
|
87
|
+
abstract register(...app: unknown[]): void | Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Perform post-registration booting of services.
|
|
90
|
+
* Runs after all providers have been registered.
|
|
91
|
+
*/
|
|
92
|
+
boot?(...app: unknown[]): void | Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Register a booted callback to be run after the "boot" method is called.
|
|
95
|
+
*
|
|
96
|
+
* @param callback
|
|
97
|
+
*/
|
|
98
|
+
abstract booted(callback: (...args: any[]) => void): void;
|
|
99
|
+
/**
|
|
100
|
+
* Call the registered booted callbacks.
|
|
101
|
+
*/
|
|
102
|
+
abstract callBootedCallbacks(): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Register the listed service providers.
|
|
105
|
+
*
|
|
106
|
+
* @param commands An array of console commands to register.
|
|
107
|
+
*/
|
|
108
|
+
abstract registerCommands(commands: (new (app: any, kernel: any) => any)[]): void;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/Foundation/MiddlewareContract.d.ts
|
|
112
|
+
type RedirectHandler = string | (() => string);
|
|
113
|
+
type MiddlewareIdentifier = string | IMiddleware;
|
|
114
|
+
type MiddlewareList = MiddlewareIdentifier[];
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/Foundation/IBootstraper.d.ts
|
|
117
|
+
declare abstract class IBootstraper {
|
|
118
|
+
/**
|
|
119
|
+
* Bootstrap the given application.
|
|
120
|
+
*/
|
|
121
|
+
abstract bootstrap(app: IApplication$1): void | Promise<void>;
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/Utilities/ObjContract.d.ts
|
|
125
|
+
/**
|
|
126
|
+
* Adds a dot prefix to nested keys
|
|
127
|
+
*/
|
|
128
|
+
type DotPrefix<T extends string, U extends string> = T extends '' ? U : `${T}.${U}`;
|
|
129
|
+
/**
|
|
130
|
+
* Converts a union of objects into a single merged object
|
|
131
|
+
*/
|
|
132
|
+
type MergeUnion<T> = (T extends any ? (k: T) => void : never) extends ((k: infer I) => void) ? { [K in keyof I]: I[K] } : never;
|
|
133
|
+
/**
|
|
134
|
+
* Flattens nested objects into dotted keys
|
|
135
|
+
*/
|
|
136
|
+
type DotFlatten<T, Prefix extends string = ''> = MergeUnion<{ [K in keyof T & string]: T[K] extends Record<string, any> ? DotFlatten<T[K], DotPrefix<Prefix, K>> : { [P in DotPrefix<Prefix, K>]: T[K] } }[keyof T & string]>;
|
|
137
|
+
/**
|
|
138
|
+
* Builds "nested.key" paths for autocompletion
|
|
139
|
+
*/
|
|
140
|
+
type DotNestedKeys<T> = { [K in keyof T & string]: T[K] extends object ? `${K}` | `${K}.${DotNestedKeys<T[K]>}` : `${K}` }[keyof T & string];
|
|
141
|
+
/**
|
|
142
|
+
* Retrieves type at a given dot-path
|
|
143
|
+
*/
|
|
144
|
+
type DotNestedValue<T, Path extends string> = Path extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? DotNestedValue<T[Key], Rest> : never : Path extends keyof T ? T[Path] : never;
|
|
145
|
+
/**
|
|
146
|
+
* A generic object type that supports nullable string values
|
|
147
|
+
*/
|
|
148
|
+
interface GenericWithNullableStringValues {
|
|
149
|
+
[name: string]: string | undefined;
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/Http/IHeaderBag.d.ts
|
|
153
|
+
/**
|
|
154
|
+
* HeaderBag — A container for HTTP headers
|
|
155
|
+
* for H3ravel App.
|
|
156
|
+
*/
|
|
157
|
+
declare abstract class IHeaderBag implements Iterable<[string, (string | null)[]]> {
|
|
158
|
+
/**
|
|
159
|
+
* Returns all headers as string (for debugging / toString)
|
|
160
|
+
*
|
|
161
|
+
* @returns
|
|
162
|
+
*/
|
|
163
|
+
abstract toString(): string;
|
|
164
|
+
/**
|
|
165
|
+
* Returns all headers or specific header list
|
|
166
|
+
*
|
|
167
|
+
* @param key
|
|
168
|
+
* @returns
|
|
169
|
+
*/
|
|
170
|
+
abstract all<K$1 extends string | undefined>(key?: K$1): K$1 extends string ? (string | null)[] : Record<string, (string | null)[]>;
|
|
171
|
+
/**
|
|
172
|
+
* Returns header keys
|
|
173
|
+
*
|
|
174
|
+
* @returns
|
|
175
|
+
*/
|
|
176
|
+
abstract keys(): string[];
|
|
177
|
+
/**
|
|
178
|
+
* Replace all headers with new set
|
|
179
|
+
*
|
|
180
|
+
* @param headers
|
|
181
|
+
*/
|
|
182
|
+
abstract replace(headers?: Record<string, string | string[] | null>): void;
|
|
183
|
+
/**
|
|
184
|
+
* Add multiple headers
|
|
185
|
+
*
|
|
186
|
+
* @param headers
|
|
187
|
+
*/
|
|
188
|
+
abstract add(headers: Record<string, string | string[] | null>): void;
|
|
189
|
+
/**
|
|
190
|
+
* Returns first header value by name or default
|
|
191
|
+
*
|
|
192
|
+
* @param key
|
|
193
|
+
* @param defaultValue
|
|
194
|
+
* @returns
|
|
195
|
+
*/
|
|
196
|
+
abstract get<R = undefined>(key: string, defaultValue?: string | null | undefined): R extends undefined ? string | null | undefined : R;
|
|
197
|
+
/**
|
|
198
|
+
* Sets a header by name.
|
|
199
|
+
*
|
|
200
|
+
* @param replace Whether to replace existing values (default true)
|
|
201
|
+
*/
|
|
202
|
+
abstract set(key: string, values: string | string[] | null, replace?: boolean): void;
|
|
203
|
+
/**
|
|
204
|
+
* Returns true if header exists
|
|
205
|
+
*
|
|
206
|
+
* @param key
|
|
207
|
+
* @returns
|
|
208
|
+
*/
|
|
209
|
+
abstract has(key: string): boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Returns true if header contains value
|
|
212
|
+
*
|
|
213
|
+
* @param key
|
|
214
|
+
* @param value
|
|
215
|
+
* @returns
|
|
216
|
+
*/
|
|
217
|
+
abstract contains(key: string, value: string): boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Removes a header
|
|
220
|
+
*
|
|
221
|
+
* @param key
|
|
222
|
+
*/
|
|
223
|
+
abstract remove(key: string): void;
|
|
224
|
+
/**
|
|
225
|
+
* Returns parsed date from header
|
|
226
|
+
*
|
|
227
|
+
* @param key
|
|
228
|
+
* @param defaultValue
|
|
229
|
+
* @returns
|
|
230
|
+
*/
|
|
231
|
+
abstract getDate(key: string, defaultValue?: Date | null): any;
|
|
232
|
+
/**
|
|
233
|
+
* Adds a Cache-Control directive
|
|
234
|
+
*
|
|
235
|
+
* @param key
|
|
236
|
+
* @param value
|
|
237
|
+
*/
|
|
238
|
+
abstract addCacheControlDirective(key: string, value?: string | boolean): void;
|
|
239
|
+
/**
|
|
240
|
+
* Returns true if Cache-Control directive is defined
|
|
241
|
+
*
|
|
242
|
+
* @param key
|
|
243
|
+
* @returns
|
|
244
|
+
*/
|
|
245
|
+
abstract hasCacheControlDirective(key: string): boolean;
|
|
246
|
+
/**
|
|
247
|
+
* Returns a Cache-Control directive value by name
|
|
248
|
+
*
|
|
249
|
+
* @param key
|
|
250
|
+
* @returns
|
|
251
|
+
*/
|
|
252
|
+
abstract getCacheControlDirective(key: string): string | boolean | null;
|
|
253
|
+
/**
|
|
254
|
+
* Removes a Cache-Control directive
|
|
255
|
+
*
|
|
256
|
+
* @param key
|
|
257
|
+
* @returns
|
|
258
|
+
*/
|
|
259
|
+
abstract removeCacheControlDirective(key: string): void;
|
|
260
|
+
/**
|
|
261
|
+
* Number of headers
|
|
262
|
+
*
|
|
263
|
+
* @param key
|
|
264
|
+
* @returns
|
|
265
|
+
*/
|
|
266
|
+
abstract count(): number;
|
|
267
|
+
/**
|
|
268
|
+
* Iterator support
|
|
269
|
+
* @returns
|
|
270
|
+
*/
|
|
271
|
+
abstract [Symbol.iterator](): Iterator<[string, (string | null)[]]>;
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region src/Http/IUploadedFile.d.ts
|
|
275
|
+
declare abstract class IUploadedFile {
|
|
276
|
+
abstract originalName: string;
|
|
277
|
+
abstract mimeType: string;
|
|
278
|
+
abstract size: number;
|
|
279
|
+
abstract content: File;
|
|
280
|
+
/**
|
|
281
|
+
* Save to disk (Node environment only)
|
|
282
|
+
*/
|
|
283
|
+
abstract moveTo(destination: string): Promise<void>;
|
|
284
|
+
}
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/Http/Utils.d.ts
|
|
287
|
+
type IFileInput = IUploadedFile | File | null | undefined;
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/Http/IParamBag.d.ts
|
|
290
|
+
/**
|
|
291
|
+
* ParamBag is a container for key/value pairs
|
|
292
|
+
* for H3ravel App.
|
|
293
|
+
*/
|
|
294
|
+
declare abstract class IParamBag implements Iterable<[string, any]> {
|
|
295
|
+
/**
|
|
296
|
+
* The current H3 H3Event instance
|
|
297
|
+
*/
|
|
298
|
+
abstract readonly event: H3Event;
|
|
299
|
+
/**
|
|
300
|
+
* Returns the parameters.
|
|
301
|
+
* @
|
|
302
|
+
* @param key The name of the parameter to return or null to get them all
|
|
303
|
+
*
|
|
304
|
+
* @throws BadRequestException if the value is not an array
|
|
305
|
+
*/
|
|
306
|
+
abstract all(key?: string): any;
|
|
307
|
+
abstract get(key: string, defaultValue?: any): any;
|
|
308
|
+
abstract set(key: string, value: any): void;
|
|
309
|
+
/**
|
|
310
|
+
* Returns true if the parameter is defined.
|
|
311
|
+
*
|
|
312
|
+
* @param key
|
|
313
|
+
*/
|
|
314
|
+
abstract has(key: string): boolean;
|
|
315
|
+
/**
|
|
316
|
+
* Removes a parameter.
|
|
317
|
+
*
|
|
318
|
+
* @param key
|
|
319
|
+
*/
|
|
320
|
+
abstract remove(key: string): void;
|
|
321
|
+
/**
|
|
322
|
+
*
|
|
323
|
+
* Returns the parameter as string.
|
|
324
|
+
*
|
|
325
|
+
* @param key
|
|
326
|
+
* @param defaultValue
|
|
327
|
+
* @throws UnexpectedValueException if the value cannot be converted to string
|
|
328
|
+
* @returns
|
|
329
|
+
*/
|
|
330
|
+
abstract getString(key: string, defaultValue?: string): string;
|
|
331
|
+
/**
|
|
332
|
+
* Returns the parameter value converted to integer.
|
|
333
|
+
*
|
|
334
|
+
* @param key
|
|
335
|
+
* @param defaultValue
|
|
336
|
+
* @throws UnexpectedValueException if the value cannot be converted to integer
|
|
337
|
+
*/
|
|
338
|
+
abstract getInt(key: string, defaultValue?: number): number;
|
|
339
|
+
/**
|
|
340
|
+
* Returns the parameter value converted to boolean.
|
|
341
|
+
*
|
|
342
|
+
* @param key
|
|
343
|
+
* @param defaultValue
|
|
344
|
+
* @throws UnexpectedValueException if the value cannot be converted to a boolean
|
|
345
|
+
*/
|
|
346
|
+
abstract getBoolean(key: string, defaultValue?: boolean): boolean;
|
|
347
|
+
/**
|
|
348
|
+
* Returns the alphabetic characters of the parameter value.
|
|
349
|
+
*
|
|
350
|
+
* @param key
|
|
351
|
+
* @param defaultValue
|
|
352
|
+
* @throws UnexpectedValueException if the value cannot be converted to string
|
|
353
|
+
*/
|
|
354
|
+
abstract getAlpha(key: string, defaultValue?: string): string;
|
|
355
|
+
/**
|
|
356
|
+
* Returns the alphabetic characters and digits of the parameter value.
|
|
357
|
+
*
|
|
358
|
+
* @param key
|
|
359
|
+
* @param defaultValue
|
|
360
|
+
* @throws UnexpectedValueException if the value cannot be converted to string
|
|
361
|
+
*/
|
|
362
|
+
abstract getAlnum(key: string, defaultValue?: string): string;
|
|
363
|
+
/**
|
|
364
|
+
* Returns the digits of the parameter value.
|
|
365
|
+
*
|
|
366
|
+
* @param key
|
|
367
|
+
* @param defaultValue
|
|
368
|
+
* @throws UnexpectedValueException if the value cannot be converted to string
|
|
369
|
+
* @returns
|
|
370
|
+
**/
|
|
371
|
+
abstract getDigits(key: string, defaultValue?: string): string;
|
|
372
|
+
/**
|
|
373
|
+
* Returns the parameter keys.
|
|
374
|
+
*/
|
|
375
|
+
abstract keys(): string[];
|
|
376
|
+
/**
|
|
377
|
+
* Replaces the current parameters by a new set.
|
|
378
|
+
*/
|
|
379
|
+
abstract replace(parameters?: RequestObject): void;
|
|
380
|
+
/**
|
|
381
|
+
* Adds parameters.
|
|
382
|
+
*/
|
|
383
|
+
abstract add(parameters?: RequestObject): void;
|
|
384
|
+
/**
|
|
385
|
+
* Returns the number of parameters.
|
|
386
|
+
*/
|
|
387
|
+
abstract count(): number;
|
|
388
|
+
/**
|
|
389
|
+
* Returns an iterator for parameters.
|
|
390
|
+
*
|
|
391
|
+
* @returns
|
|
392
|
+
*/
|
|
393
|
+
abstract [Symbol.iterator](): ArrayIterator<[string, any]>;
|
|
394
|
+
}
|
|
395
|
+
//#endregion
|
|
396
|
+
//#region src/Http/IFileBag.d.ts
|
|
397
|
+
/**
|
|
398
|
+
* FileBag is a container for uploaded files
|
|
399
|
+
* for H3ravel App.
|
|
400
|
+
*/
|
|
401
|
+
declare abstract class IFileBag extends IParamBag {
|
|
402
|
+
/**
|
|
403
|
+
* Replace all stored files.
|
|
404
|
+
*/
|
|
405
|
+
abstract replace(files?: Record<string, IFileInput | IFileInput[]>): void;
|
|
406
|
+
/**
|
|
407
|
+
* Set a file or array of files.
|
|
408
|
+
*/
|
|
409
|
+
abstract set(key: string, value: IFileInput | IFileInput[]): void;
|
|
410
|
+
/**
|
|
411
|
+
* Add multiple files.
|
|
412
|
+
*/
|
|
413
|
+
abstract add(files?: Record<string, IFileInput | IFileInput[]>): void;
|
|
414
|
+
/**
|
|
415
|
+
* Get all stored files.
|
|
416
|
+
*/
|
|
417
|
+
abstract all(): Record<string, IUploadedFile | IUploadedFile[] | null>;
|
|
418
|
+
}
|
|
419
|
+
//#endregion
|
|
420
|
+
//#region src/Http/IServerBag.d.ts
|
|
421
|
+
/**
|
|
422
|
+
* ServerBag — a simplified version of Symfony's ServerBag
|
|
423
|
+
* for H3ravel App.
|
|
424
|
+
*
|
|
425
|
+
* Responsible for extracting and normalizing HTTP headers
|
|
426
|
+
* from the incoming request.
|
|
427
|
+
*/
|
|
428
|
+
declare abstract class IServerBag extends IParamBag {
|
|
429
|
+
/**
|
|
430
|
+
* Returns all request headers, normalized to uppercase with underscores.
|
|
431
|
+
* Example: content-type → CONTENT_TYPE
|
|
432
|
+
*/
|
|
433
|
+
abstract getHeaders(): Record<string, string>;
|
|
434
|
+
/**
|
|
435
|
+
* Returns a specific header by name, case-insensitive.
|
|
436
|
+
*/
|
|
437
|
+
abstract get(name: string): string | undefined;
|
|
438
|
+
/**
|
|
439
|
+
* Returns true if a header exists.
|
|
440
|
+
*/
|
|
441
|
+
abstract has(name: string): boolean;
|
|
442
|
+
}
|
|
443
|
+
//#endregion
|
|
444
|
+
//#region src/Url/Utils.d.ts
|
|
445
|
+
type RouteParams<N = any> = Record<string, N>;
|
|
446
|
+
//#endregion
|
|
447
|
+
//#region src/Url/IUrl.d.ts
|
|
448
|
+
declare abstract class IUrl {
|
|
449
|
+
/**
|
|
450
|
+
* Create a URL from a full URL string
|
|
451
|
+
*/
|
|
452
|
+
static of(url: string, app?: IApplication): IUrl;
|
|
453
|
+
/**
|
|
454
|
+
* Create a URL from a path relative to the app URL
|
|
455
|
+
*/
|
|
456
|
+
static to(path: string, app?: IApplication): IUrl;
|
|
457
|
+
/**
|
|
458
|
+
* Create a URL from a named route
|
|
459
|
+
*/
|
|
460
|
+
static route<TName extends string = string, TParams extends RouteParams = RouteParams>(name: TName, params?: TParams, app?: IApplication): IUrl;
|
|
461
|
+
/**
|
|
462
|
+
* Create a signed URL from a named route
|
|
463
|
+
*/
|
|
464
|
+
static signedRoute<TName extends string = string, TParams extends RouteParams = RouteParams>(name: TName, params?: TParams, app?: IApplication): IUrl;
|
|
465
|
+
/**
|
|
466
|
+
* Create a temporary signed URL from a named route
|
|
467
|
+
*/
|
|
468
|
+
static temporarySignedRoute<TName extends string = string, TParams extends RouteParams = RouteParams>(name: TName, params: TParams | undefined, expiration: number, app?: IApplication): IUrl;
|
|
469
|
+
/**
|
|
470
|
+
* Create a URL from a controller action
|
|
471
|
+
*/
|
|
472
|
+
static action<C extends new (...args: any) => any>(controller: string | [C, methodName: ExtractClassMethods<InstanceType<C>>], params?: Record<string, any>, app?: IApplication): IUrl;
|
|
473
|
+
/**
|
|
474
|
+
* Set the scheme (protocol) of the URL
|
|
475
|
+
*/
|
|
476
|
+
abstract withScheme(scheme: string): IUrl;
|
|
477
|
+
/**
|
|
478
|
+
* Set the host of the URL
|
|
479
|
+
*/
|
|
480
|
+
abstract withHost(host: string): IUrl;
|
|
481
|
+
/**
|
|
482
|
+
* Set the port of the URL
|
|
483
|
+
*/
|
|
484
|
+
abstract withPort(port: number): IUrl;
|
|
485
|
+
/**
|
|
486
|
+
* Set the path of the URL
|
|
487
|
+
*/
|
|
488
|
+
abstract withPath(path: string): IUrl;
|
|
489
|
+
/**
|
|
490
|
+
* Set the query parameters of the URL
|
|
491
|
+
*/
|
|
492
|
+
abstract withQuery(query: Record<string, unknown>): IUrl;
|
|
493
|
+
/**
|
|
494
|
+
* Merge additional query parameters
|
|
495
|
+
*/
|
|
496
|
+
abstract withQueryParams(params: Record<string, unknown>): IUrl;
|
|
497
|
+
/**
|
|
498
|
+
* Set the fragment (hash) of the URL
|
|
499
|
+
*/
|
|
500
|
+
abstract withFragment(fragment: string): IUrl;
|
|
501
|
+
/**
|
|
502
|
+
* Add a signature to the URL for security
|
|
503
|
+
*/
|
|
504
|
+
abstract withSignature(app?: IApplication, expiration?: number): IUrl;
|
|
505
|
+
/**
|
|
506
|
+
* Verify if a URL signature is valid
|
|
507
|
+
*/
|
|
508
|
+
abstract hasValidSignature(app?: IApplication): boolean;
|
|
509
|
+
/**
|
|
510
|
+
* Convert the URL to its string representation
|
|
511
|
+
*/
|
|
512
|
+
abstract toString(): string;
|
|
513
|
+
/**
|
|
514
|
+
* Get the scheme
|
|
515
|
+
*/
|
|
516
|
+
abstract getScheme(): string | undefined;
|
|
517
|
+
/**
|
|
518
|
+
* Get the host
|
|
519
|
+
*/
|
|
520
|
+
abstract getHost(): string | undefined;
|
|
521
|
+
/**
|
|
522
|
+
* Get the port
|
|
523
|
+
*/
|
|
524
|
+
abstract getPort(): number | undefined;
|
|
525
|
+
/**
|
|
526
|
+
* Get the path
|
|
527
|
+
*/
|
|
528
|
+
abstract getPath(): string;
|
|
529
|
+
/**
|
|
530
|
+
* Get the query parameters
|
|
531
|
+
*/
|
|
532
|
+
abstract getQuery(): Record<string, unknown>;
|
|
533
|
+
/**
|
|
534
|
+
* Get the fragment
|
|
535
|
+
*/
|
|
536
|
+
abstract getFragment(): string | undefined;
|
|
537
|
+
}
|
|
538
|
+
//#endregion
|
|
539
|
+
//#region src/Http/IInputBag.d.ts
|
|
540
|
+
/**
|
|
541
|
+
* InputBag is a container for user input values
|
|
542
|
+
* (e.g., query params, body, cookies)
|
|
543
|
+
* for H3ravel App.
|
|
544
|
+
*/
|
|
545
|
+
declare abstract class InputBag extends IParamBag {
|
|
546
|
+
/**
|
|
547
|
+
* Returns a scalar input value by name.
|
|
548
|
+
*
|
|
549
|
+
* @param key
|
|
550
|
+
* @param defaultValue
|
|
551
|
+
* @throws BadRequestException if the input contains a non-scalar value
|
|
552
|
+
* @returns
|
|
553
|
+
*/
|
|
554
|
+
abstract get<T extends string | number | boolean | null>(key: string, defaultValue?: T | null): T | string | number | boolean | null;
|
|
555
|
+
/**
|
|
556
|
+
* Replaces all current input values.
|
|
557
|
+
*
|
|
558
|
+
* @param inputs
|
|
559
|
+
* @returns
|
|
560
|
+
*/
|
|
561
|
+
abstract replace(inputs?: RequestObject): void;
|
|
562
|
+
/**
|
|
563
|
+
* Adds multiple input values.
|
|
564
|
+
*
|
|
565
|
+
* @param inputs
|
|
566
|
+
* @returns
|
|
567
|
+
*/
|
|
568
|
+
abstract add(inputs?: RequestObject): void;
|
|
569
|
+
/**
|
|
570
|
+
* Sets an input by name.
|
|
571
|
+
*
|
|
572
|
+
* @param key
|
|
573
|
+
* @param value
|
|
574
|
+
* @throws TypeError if value is not scalar or array
|
|
575
|
+
* @returns
|
|
576
|
+
*/
|
|
577
|
+
abstract set(key: string, value: any): void;
|
|
578
|
+
/**
|
|
579
|
+
* Returns true if a key exists.
|
|
580
|
+
*
|
|
581
|
+
* @param key
|
|
582
|
+
* @returns
|
|
583
|
+
*/
|
|
584
|
+
abstract has(key: string): boolean;
|
|
585
|
+
/**
|
|
586
|
+
* Returns all parameters.
|
|
587
|
+
*
|
|
588
|
+
* @returns
|
|
589
|
+
*/
|
|
590
|
+
abstract all(): RequestObject;
|
|
591
|
+
/**
|
|
592
|
+
* Converts a parameter value to string.
|
|
593
|
+
*
|
|
594
|
+
* @param key
|
|
595
|
+
* @param defaultValue
|
|
596
|
+
* @throws BadRequestException if input contains a non-scalar value
|
|
597
|
+
* @returns
|
|
598
|
+
*/
|
|
599
|
+
abstract getString(key: string, defaultValue?: string): string;
|
|
600
|
+
/**
|
|
601
|
+
* Filters input value with a predicate.
|
|
602
|
+
* Mimics PHP’s filter_var() in spirit, but simpler.
|
|
603
|
+
*
|
|
604
|
+
* @param key
|
|
605
|
+
* @param defaultValue
|
|
606
|
+
* @param filterFn
|
|
607
|
+
* @throws BadRequestException if validation fails
|
|
608
|
+
* @returns
|
|
609
|
+
*/
|
|
610
|
+
abstract filter<T = any>(key: string, defaultValue?: T | null, filterFn?: (value: any) => boolean): T | null;
|
|
611
|
+
/**
|
|
612
|
+
* Returns an enum value by key.
|
|
613
|
+
*
|
|
614
|
+
* @param key
|
|
615
|
+
* @param EnumClass
|
|
616
|
+
* @param defaultValue
|
|
617
|
+
* @throws BadRequestException if conversion fails
|
|
618
|
+
* @returns
|
|
619
|
+
*/
|
|
620
|
+
abstract getEnum<T extends Record<string, string | number>>(key: string, EnumClass: T, defaultValue?: T[keyof T] | null): T[keyof T] | null;
|
|
621
|
+
/**
|
|
622
|
+
* Removes a key.
|
|
623
|
+
*
|
|
624
|
+
* @param key
|
|
625
|
+
*/
|
|
626
|
+
abstract remove(key: string): void;
|
|
627
|
+
/**
|
|
628
|
+
* Returns all keys.
|
|
629
|
+
*
|
|
630
|
+
* @returns
|
|
631
|
+
*/
|
|
632
|
+
abstract keys(): string[];
|
|
633
|
+
/**
|
|
634
|
+
* Returns number of parameters.
|
|
635
|
+
*
|
|
636
|
+
* @returns
|
|
637
|
+
*/
|
|
638
|
+
abstract count(): number;
|
|
639
|
+
}
|
|
640
|
+
//#endregion
|
|
641
|
+
//#region src/Http/IHttpRequest.d.ts
|
|
642
|
+
declare abstract class IHttpRequest {
|
|
643
|
+
/**
|
|
644
|
+
* The current app instance
|
|
645
|
+
*/
|
|
646
|
+
abstract app: IApplication;
|
|
647
|
+
/**
|
|
648
|
+
* Parsed request body
|
|
649
|
+
*/
|
|
650
|
+
abstract body: unknown;
|
|
651
|
+
/**
|
|
652
|
+
* Gets route parameters.
|
|
653
|
+
* @returns An object containing route parameters.
|
|
654
|
+
*/
|
|
655
|
+
abstract params: NonNullable<H3Event['context']['params']>;
|
|
656
|
+
/**
|
|
657
|
+
* Uploaded files (FILES).
|
|
658
|
+
*/
|
|
659
|
+
abstract files: IFileBag;
|
|
660
|
+
/**
|
|
661
|
+
* Query string parameters (GET).
|
|
662
|
+
*/
|
|
663
|
+
abstract _query: InputBag;
|
|
664
|
+
/**
|
|
665
|
+
* Server and execution environment parameters
|
|
666
|
+
*/
|
|
667
|
+
abstract _server: IServerBag;
|
|
668
|
+
/**
|
|
669
|
+
* Cookies
|
|
670
|
+
*/
|
|
671
|
+
abstract cookies: InputBag;
|
|
672
|
+
/**
|
|
673
|
+
* The current Http Context
|
|
674
|
+
*/
|
|
675
|
+
abstract context: IHttpContext;
|
|
676
|
+
/**
|
|
677
|
+
* The request attributes (parameters parsed from the PATH_INFO, ...).
|
|
678
|
+
*/
|
|
679
|
+
abstract attributes: IParamBag;
|
|
680
|
+
/**
|
|
681
|
+
* Gets the request headers.
|
|
682
|
+
* @returns An object containing request headers.
|
|
683
|
+
*/
|
|
684
|
+
abstract headers: IHeaderBag;
|
|
685
|
+
/**
|
|
686
|
+
* Sets the parameters for this request.
|
|
687
|
+
*
|
|
688
|
+
* This method also re-initializes all properties.
|
|
689
|
+
*
|
|
690
|
+
* @param attributes
|
|
691
|
+
* @param cookies The COOKIE parameters
|
|
692
|
+
* @param files The FILES parameters
|
|
693
|
+
* @param server The SERVER parameters
|
|
694
|
+
* @param content The raw body data
|
|
695
|
+
*/
|
|
696
|
+
abstract initialize(): Promise<void>;
|
|
697
|
+
/**
|
|
698
|
+
* Gets a list of content types acceptable by the client browser in preferable order.
|
|
699
|
+
* @returns {string[]}
|
|
700
|
+
*/
|
|
701
|
+
abstract getAcceptableContentTypes(): string[];
|
|
702
|
+
/**
|
|
703
|
+
* Get a URI instance for the request.
|
|
704
|
+
*/
|
|
705
|
+
abstract getUriInstance(): IUrl;
|
|
706
|
+
/**
|
|
707
|
+
* Returns the requested URI (path and query string).
|
|
708
|
+
*
|
|
709
|
+
* @return {string} The raw URI (i.e. not URI decoded)
|
|
710
|
+
*/
|
|
711
|
+
abstract getRequestUri(): string;
|
|
712
|
+
/**
|
|
713
|
+
* Gets the scheme and HTTP host.
|
|
714
|
+
*
|
|
715
|
+
* If the URL was called with basic authentication, the user
|
|
716
|
+
* and the password are not added to the generated string.
|
|
717
|
+
*/
|
|
718
|
+
abstract getSchemeAndHttpHost(): string;
|
|
719
|
+
/**
|
|
720
|
+
* Returns the HTTP host being requested.
|
|
721
|
+
*
|
|
722
|
+
* The port name will be appended to the host if it's non-standard.
|
|
723
|
+
*/
|
|
724
|
+
abstract getHttpHost(): string;
|
|
725
|
+
/**
|
|
726
|
+
* Returns the root path from which this request is executed.
|
|
727
|
+
*
|
|
728
|
+
* @returns {string} The raw path (i.e. not urldecoded)
|
|
729
|
+
*/
|
|
730
|
+
abstract getBasePath(): string;
|
|
731
|
+
/**
|
|
732
|
+
* Returns the root URL from which this request is executed.
|
|
733
|
+
*
|
|
734
|
+
* The base URL never ends with a /.
|
|
735
|
+
*
|
|
736
|
+
* This is similar to getBasePath(), except that it also includes the
|
|
737
|
+
* script filename (e.g. index.php) if one exists.
|
|
738
|
+
*
|
|
739
|
+
* @return string The raw URL (i.e. not urldecoded)
|
|
740
|
+
*/
|
|
741
|
+
abstract getBaseUrl(): string;
|
|
742
|
+
/**
|
|
743
|
+
* Gets the request's scheme.
|
|
744
|
+
*/
|
|
745
|
+
abstract getScheme(): string;
|
|
746
|
+
/**
|
|
747
|
+
* Returns the port on which the request is made.
|
|
748
|
+
*
|
|
749
|
+
* This method can read the client port from the "X-Forwarded-Port" header
|
|
750
|
+
* when trusted proxies were set via "setTrustedProxies()".
|
|
751
|
+
*
|
|
752
|
+
* The "X-Forwarded-Port" header must contain the client port.
|
|
753
|
+
*
|
|
754
|
+
* @return int|string|null Can be a string if fetched from the server bag
|
|
755
|
+
*/
|
|
756
|
+
abstract getPort(): number | string | undefined;
|
|
757
|
+
abstract getHost(): string;
|
|
758
|
+
/**
|
|
759
|
+
* Checks whether the request is secure or not.
|
|
760
|
+
*
|
|
761
|
+
* This method can read the client protocol from the "X-Forwarded-Proto" header
|
|
762
|
+
* when trusted proxies were set via "setTrustedProxies()".
|
|
763
|
+
*
|
|
764
|
+
* The "X-Forwarded-Proto" header must contain the protocol: "https" or "http".
|
|
765
|
+
*/
|
|
766
|
+
abstract isSecure(): boolean;
|
|
767
|
+
/**
|
|
768
|
+
* Returns the value of the requested header.
|
|
769
|
+
*/
|
|
770
|
+
abstract getHeader(name: string): string | undefined | null;
|
|
771
|
+
/**
|
|
772
|
+
* Checks if the request method is of specified type.
|
|
773
|
+
*
|
|
774
|
+
* @param method Uppercase request method (GET, POST etc)
|
|
775
|
+
*/
|
|
776
|
+
abstract isMethod(method: string): boolean;
|
|
777
|
+
/**
|
|
778
|
+
* Checks whether or not the method is safe.
|
|
779
|
+
*
|
|
780
|
+
* @see https://tools.ietf.org/html/rfc7231#section-4.2.1
|
|
781
|
+
*/
|
|
782
|
+
abstract isMethodSafe(): boolean;
|
|
783
|
+
/**
|
|
784
|
+
* Checks whether or not the method is idempotent.
|
|
785
|
+
*/
|
|
786
|
+
abstract isMethodIdempotent(): boolean;
|
|
787
|
+
/**
|
|
788
|
+
* Checks whether the method is cacheable or not.
|
|
789
|
+
*
|
|
790
|
+
* @see https://tools.ietf.org/html/rfc7231#section-4.2.3
|
|
791
|
+
*/
|
|
792
|
+
abstract isMethodCacheable(): boolean;
|
|
793
|
+
/**
|
|
794
|
+
* Returns true if the request is an XMLHttpRequest (AJAX).
|
|
795
|
+
*/
|
|
796
|
+
abstract isXmlHttpRequest(): boolean;
|
|
797
|
+
/**
|
|
798
|
+
* Gets the request "intended" method.
|
|
799
|
+
*
|
|
800
|
+
* If the X-HTTP-Method-Override header is set, and if the method is a POST,
|
|
801
|
+
* then it is used to determine the "real" intended HTTP method.
|
|
802
|
+
*
|
|
803
|
+
* The _method request parameter can also be used to determine the HTTP method,
|
|
804
|
+
* but only if enableHttpMethodParameterOverride() has been called.
|
|
805
|
+
*
|
|
806
|
+
* The method is always an uppercased string.
|
|
807
|
+
*
|
|
808
|
+
* @see getRealMethod()
|
|
809
|
+
*/
|
|
810
|
+
abstract getMethod(): RequestMethod;
|
|
811
|
+
/**
|
|
812
|
+
* Gets the preferred format for the response by inspecting, in the following order:
|
|
813
|
+
* * the request format set using setRequestFormat;
|
|
814
|
+
* * the values of the Accept HTTP header.
|
|
815
|
+
*
|
|
816
|
+
* Note that if you use this method, you should send the "Vary: Accept" header
|
|
817
|
+
* in the response to prevent any issues with intermediary HTTP caches.
|
|
818
|
+
*/
|
|
819
|
+
abstract getPreferredFormat(defaultValue?: string): string | undefined;
|
|
820
|
+
/**
|
|
821
|
+
* Gets the format associated with the mime type.
|
|
822
|
+
*/
|
|
823
|
+
abstract getFormat(mimeType: string): string | undefined;
|
|
824
|
+
/**
|
|
825
|
+
* Gets the request format.
|
|
826
|
+
*
|
|
827
|
+
* Here is the process to determine the format:
|
|
828
|
+
*
|
|
829
|
+
* * format defined by the user (with setRequestFormat())
|
|
830
|
+
* * _format request attribute
|
|
831
|
+
* * $default
|
|
832
|
+
*
|
|
833
|
+
* @see getPreferredFormat
|
|
834
|
+
*/
|
|
835
|
+
abstract getRequestFormat(defaultValue?: string): string | undefined;
|
|
836
|
+
/**
|
|
837
|
+
* Sets the request format.
|
|
838
|
+
*/
|
|
839
|
+
abstract setRequestFormat(format: string): void;
|
|
840
|
+
/**
|
|
841
|
+
* Gets the "real" request method.
|
|
842
|
+
*
|
|
843
|
+
* @see getMethod()
|
|
844
|
+
*/
|
|
845
|
+
abstract getRealMethod(): RequestMethod;
|
|
846
|
+
/**
|
|
847
|
+
* Gets the mime type associated with the format.
|
|
848
|
+
*/
|
|
849
|
+
abstract getMimeType(format: string): string | undefined;
|
|
850
|
+
/**
|
|
851
|
+
* Returns the request body content.
|
|
852
|
+
*
|
|
853
|
+
* @param asStream If true, returns a ReadableStream instead of the parsed string
|
|
854
|
+
* @return {string | ReadableStream | Promise<string | ReadableStream>}
|
|
855
|
+
*/
|
|
856
|
+
abstract getContent(asStream?: boolean): string | ReadableStream;
|
|
857
|
+
/**
|
|
858
|
+
* Gets a "parameter" value from any bag.
|
|
859
|
+
*
|
|
860
|
+
* This method is mainly useful for libraries that want to provide some flexibility. If you don't need the
|
|
861
|
+
* flexibility in controllers, it is better to explicitly get request parameters from the appropriate
|
|
862
|
+
* public property instead (attributes, query, request).
|
|
863
|
+
*
|
|
864
|
+
* Order of precedence: PATH (routing placeholders or custom attributes), GET, POST
|
|
865
|
+
*
|
|
866
|
+
* @internal use explicit input sources instead
|
|
867
|
+
*/
|
|
868
|
+
abstract get(key: string, defaultValue?: any): any;
|
|
869
|
+
/**
|
|
870
|
+
* Indicates whether this request originated from a trusted proxy.
|
|
871
|
+
*
|
|
872
|
+
* This can be useful to determine whether or not to trust the
|
|
873
|
+
* contents of a proxy-specific header.
|
|
874
|
+
*/
|
|
875
|
+
abstract isFromTrustedProxy(): boolean;
|
|
876
|
+
/**
|
|
877
|
+
* Returns the path being requested relative to the executed script.
|
|
878
|
+
*
|
|
879
|
+
* The path info always starts with a /.
|
|
880
|
+
*
|
|
881
|
+
* @return {string} The raw path (i.e. not urldecoded)
|
|
882
|
+
*/
|
|
883
|
+
abstract getPathInfo(): string;
|
|
884
|
+
}
|
|
885
|
+
//#endregion
|
|
886
|
+
//#region src/Routing/ICompiledRoute.d.ts
|
|
887
|
+
declare class ICompiledRoute {
|
|
888
|
+
/**
|
|
889
|
+
* Get the compiled path regex
|
|
890
|
+
*/
|
|
891
|
+
getRegex(): RegExp;
|
|
892
|
+
/**
|
|
893
|
+
* Get the compiled host regex (if any)
|
|
894
|
+
*/
|
|
895
|
+
getHostRegex(): RegExp | undefined;
|
|
896
|
+
/**
|
|
897
|
+
* Returns list of all param names (including optional)
|
|
898
|
+
*/
|
|
899
|
+
getParamNames(): string[];
|
|
900
|
+
/**
|
|
901
|
+
* Returns optional params record
|
|
902
|
+
*/
|
|
903
|
+
getOptionalParams(): Record<string, null>;
|
|
904
|
+
}
|
|
905
|
+
//#endregion
|
|
906
|
+
//#region src/Routing/IRoute.d.ts
|
|
907
|
+
declare abstract class IRoute {
|
|
908
|
+
/**
|
|
909
|
+
* The default values for the route.
|
|
910
|
+
*/
|
|
911
|
+
abstract _defaults: GenericObject;
|
|
912
|
+
/**
|
|
913
|
+
* The compiled version of the route.
|
|
914
|
+
*/
|
|
915
|
+
abstract compiled?: ICompiledRoute;
|
|
916
|
+
/**
|
|
917
|
+
* The array of matched parameters.
|
|
918
|
+
*/
|
|
919
|
+
abstract parameters?: GenericObject;
|
|
920
|
+
/**
|
|
921
|
+
* The route action array.
|
|
922
|
+
*/
|
|
923
|
+
abstract action: RouteActions;
|
|
924
|
+
/**
|
|
925
|
+
* The HTTP methods the route responds to.
|
|
926
|
+
*/
|
|
927
|
+
abstract methods: RouteMethod[];
|
|
928
|
+
/**
|
|
929
|
+
* The route path that can be handled by H3.
|
|
930
|
+
*/
|
|
931
|
+
abstract path: string;
|
|
932
|
+
/**
|
|
933
|
+
* The computed gathered middleware.
|
|
934
|
+
*/
|
|
935
|
+
abstract computedMiddleware?: MiddlewareList;
|
|
936
|
+
/**
|
|
937
|
+
* The controller instance.
|
|
938
|
+
*/
|
|
939
|
+
abstract controller?: Required<IController>;
|
|
940
|
+
/**
|
|
941
|
+
* Set the router instance on the route.
|
|
942
|
+
*
|
|
943
|
+
* @param router
|
|
944
|
+
*/
|
|
945
|
+
abstract setRouter(router: any): this;
|
|
946
|
+
/**
|
|
947
|
+
* Set the container instance on the route.
|
|
948
|
+
*
|
|
949
|
+
* @param container
|
|
950
|
+
*/
|
|
951
|
+
abstract setContainer(container: IContainer): this;
|
|
952
|
+
/**
|
|
953
|
+
* Set the URI that the route responds to.
|
|
954
|
+
*
|
|
955
|
+
* @param uri
|
|
956
|
+
*/
|
|
957
|
+
abstract setUri(uri: string): this;
|
|
958
|
+
/**
|
|
959
|
+
* Get the URI associated with the route.
|
|
960
|
+
*/
|
|
961
|
+
abstract uri(): string;
|
|
962
|
+
/**
|
|
963
|
+
* Add a prefix to the route URI.
|
|
964
|
+
*
|
|
965
|
+
* @param prefix
|
|
966
|
+
*/
|
|
967
|
+
abstract prefix(prefix: string): this;
|
|
968
|
+
/**
|
|
969
|
+
* Get the name of the route instance.
|
|
970
|
+
*/
|
|
971
|
+
abstract getName(): string | undefined;
|
|
972
|
+
/**
|
|
973
|
+
* Add or change the route name.
|
|
974
|
+
*
|
|
975
|
+
* @param name
|
|
976
|
+
*
|
|
977
|
+
* @throws {InvalidArgumentException}
|
|
978
|
+
*/
|
|
979
|
+
abstract name(name: string): this;
|
|
980
|
+
/**
|
|
981
|
+
* Determine whether the route's name matches the given patterns.
|
|
982
|
+
*
|
|
983
|
+
* @param patterns
|
|
984
|
+
*/
|
|
985
|
+
abstract named(...patterns: string[]): boolean;
|
|
986
|
+
/**
|
|
987
|
+
* Get the action name for the route.
|
|
988
|
+
*/
|
|
989
|
+
abstract getActionName(): any;
|
|
990
|
+
/**
|
|
991
|
+
* Get the method name of the route action.
|
|
992
|
+
*
|
|
993
|
+
* @return string
|
|
994
|
+
*/
|
|
995
|
+
abstract getActionMethod(): any;
|
|
996
|
+
/**
|
|
997
|
+
* Get the action array or one of its properties for the route.
|
|
998
|
+
* @param key
|
|
999
|
+
*/
|
|
1000
|
+
abstract getAction(key?: string): any;
|
|
1001
|
+
/**
|
|
1002
|
+
* Mark this route as a fallback route.
|
|
1003
|
+
*/
|
|
1004
|
+
abstract fallback(): this;
|
|
1005
|
+
/**
|
|
1006
|
+
* Set the fallback value.
|
|
1007
|
+
*
|
|
1008
|
+
* @param sFallback
|
|
1009
|
+
*/
|
|
1010
|
+
abstract setFallback(isFallback: boolean): this;
|
|
1011
|
+
/**
|
|
1012
|
+
* Get the HTTP verbs the route responds to.
|
|
1013
|
+
*/
|
|
1014
|
+
abstract getMethods(): RouteMethod[];
|
|
1015
|
+
/**
|
|
1016
|
+
* Determine if the route only responds to HTTP requests.
|
|
1017
|
+
*/
|
|
1018
|
+
abstract httpOnly(): boolean;
|
|
1019
|
+
/**
|
|
1020
|
+
* Determine if the route only responds to HTTPS requests.
|
|
1021
|
+
*/
|
|
1022
|
+
abstract httpsOnly(): boolean;
|
|
1023
|
+
/**
|
|
1024
|
+
* Get or set the middlewares attached to the route.
|
|
1025
|
+
*
|
|
1026
|
+
* @param middleware
|
|
1027
|
+
*/
|
|
1028
|
+
abstract middleware(): any[];
|
|
1029
|
+
abstract middleware(middleware?: string | string[]): this;
|
|
1030
|
+
/**
|
|
1031
|
+
* Specify that the "Authorize" / "can" middleware should be applied to the route with the given options.
|
|
1032
|
+
*
|
|
1033
|
+
* @param ability
|
|
1034
|
+
* @param models
|
|
1035
|
+
*/
|
|
1036
|
+
abstract can(ability: string, models?: string | string[]): any[] | this;
|
|
1037
|
+
/**
|
|
1038
|
+
* Set the action array for the route.
|
|
1039
|
+
*
|
|
1040
|
+
* @param action
|
|
1041
|
+
*/
|
|
1042
|
+
abstract setAction(action: RouteActions): this;
|
|
1043
|
+
/**
|
|
1044
|
+
* Determine if the route only responds to HTTPS requests.
|
|
1045
|
+
*/
|
|
1046
|
+
abstract secure(): boolean;
|
|
1047
|
+
/**
|
|
1048
|
+
* Bind the route to a given request for execution.
|
|
1049
|
+
*
|
|
1050
|
+
* @param request
|
|
1051
|
+
*/
|
|
1052
|
+
abstract bind(request: IRequest): this;
|
|
1053
|
+
/**
|
|
1054
|
+
* Get or set the domain for the route.
|
|
1055
|
+
*
|
|
1056
|
+
* @param domain
|
|
1057
|
+
*
|
|
1058
|
+
* @throws {InvalidArgumentException}
|
|
1059
|
+
*/
|
|
1060
|
+
abstract domain<D extends string | undefined = undefined>(domain?: D): D extends undefined ? string : this;
|
|
1061
|
+
/**
|
|
1062
|
+
* Get the key / value list of original parameters for the route.
|
|
1063
|
+
*
|
|
1064
|
+
* @throws {LogicException}
|
|
1065
|
+
*/
|
|
1066
|
+
abstract originalParameters(): GenericObject;
|
|
1067
|
+
/**
|
|
1068
|
+
* Get the matched parameters object.
|
|
1069
|
+
*/
|
|
1070
|
+
abstract getParameters(): GenericObject;
|
|
1071
|
+
/**
|
|
1072
|
+
* Get a given parameter from the route.
|
|
1073
|
+
*
|
|
1074
|
+
* @param name
|
|
1075
|
+
* @param defaultParam
|
|
1076
|
+
*/
|
|
1077
|
+
abstract parameter(name: string, defaultParam?: any): any;
|
|
1078
|
+
/**
|
|
1079
|
+
* Get the domain defined for the route.
|
|
1080
|
+
*/
|
|
1081
|
+
abstract getDomain(): string | undefined;
|
|
1082
|
+
/**
|
|
1083
|
+
* Get the compiled version of the route.
|
|
1084
|
+
*/
|
|
1085
|
+
abstract getCompiled(): ICompiledRoute | undefined;
|
|
1086
|
+
/**
|
|
1087
|
+
* Get the binding field for the given parameter.
|
|
1088
|
+
*
|
|
1089
|
+
* @param parameter
|
|
1090
|
+
*/
|
|
1091
|
+
abstract bindingFieldFor(parameter: string | number): string | undefined;
|
|
1092
|
+
/**
|
|
1093
|
+
* Get the binding fields for the route.
|
|
1094
|
+
*/
|
|
1095
|
+
abstract getBindingFields(): GenericObject<string>;
|
|
1096
|
+
/**
|
|
1097
|
+
* Set the binding fields for the route.
|
|
1098
|
+
*
|
|
1099
|
+
* @param bindingFields
|
|
1100
|
+
*/
|
|
1101
|
+
abstract setBindingFields(bindingFields: GenericObject<string>): this;
|
|
1102
|
+
/**
|
|
1103
|
+
* Get the parent parameter of the given parameter.
|
|
1104
|
+
*
|
|
1105
|
+
* @param parameter
|
|
1106
|
+
*/
|
|
1107
|
+
abstract parentOfParameter(parameter: string): any;
|
|
1108
|
+
/**
|
|
1109
|
+
* Determines if the route allows "trashed" models to be retrieved when resolving implicit model bindings.
|
|
1110
|
+
*/
|
|
1111
|
+
abstract allowsTrashedBindings(): boolean;
|
|
1112
|
+
/**
|
|
1113
|
+
* Set a default value for the route.
|
|
1114
|
+
*
|
|
1115
|
+
* @param key
|
|
1116
|
+
* @param value
|
|
1117
|
+
*/
|
|
1118
|
+
abstract defaults(key: string, value: any): this;
|
|
1119
|
+
/**
|
|
1120
|
+
* Set the default values for the route.
|
|
1121
|
+
*
|
|
1122
|
+
* @param defaults
|
|
1123
|
+
*/
|
|
1124
|
+
abstract setDefaults(defaults: GenericObject): this;
|
|
1125
|
+
/**
|
|
1126
|
+
* Get the optional parameter names for the route.
|
|
1127
|
+
*/
|
|
1128
|
+
abstract getOptionalParameterNames(): GenericObject;
|
|
1129
|
+
/**
|
|
1130
|
+
* Get all of the parameter names for the route.
|
|
1131
|
+
*/
|
|
1132
|
+
abstract parameterNames(): string[];
|
|
1133
|
+
/**
|
|
1134
|
+
* Flush the cached container instance on the route.
|
|
1135
|
+
*/
|
|
1136
|
+
abstract flushController(): void;
|
|
1137
|
+
/**
|
|
1138
|
+
* Get the parameters that are listed in the route / controller signature.
|
|
1139
|
+
*
|
|
1140
|
+
* @param conditions
|
|
1141
|
+
*/
|
|
1142
|
+
abstract signatureParameters(conditions: ClassConstructor | GenericObject): any[];
|
|
1143
|
+
/**
|
|
1144
|
+
* Compile the route once, cache the result, return compiled data
|
|
1145
|
+
*/
|
|
1146
|
+
abstract compileRoute(): ICompiledRoute;
|
|
1147
|
+
/**
|
|
1148
|
+
* Set a parameter to the given value.
|
|
1149
|
+
*
|
|
1150
|
+
* @param name
|
|
1151
|
+
* @param value
|
|
1152
|
+
*/
|
|
1153
|
+
abstract setParameter(name: string, value?: string | GenericObject): void;
|
|
1154
|
+
/**
|
|
1155
|
+
* Unset a parameter on the route if it is set.
|
|
1156
|
+
*
|
|
1157
|
+
* @param name
|
|
1158
|
+
*/
|
|
1159
|
+
abstract forgetParameter(name: string): void;
|
|
1160
|
+
/**
|
|
1161
|
+
* Get the value of the action that should be taken on a missing model exception.
|
|
1162
|
+
*/
|
|
1163
|
+
abstract getMissing(): CallableConstructor | undefined;
|
|
1164
|
+
/**
|
|
1165
|
+
* The route path that can be handled by H3.
|
|
1166
|
+
*/
|
|
1167
|
+
abstract getPath(): string;
|
|
1168
|
+
/**
|
|
1169
|
+
* Define the callable that should be invoked on a missing model exception.
|
|
1170
|
+
*
|
|
1171
|
+
* @param missing
|
|
1172
|
+
*/
|
|
1173
|
+
abstract missing(missing: CallableConstructor): this;
|
|
1174
|
+
/**
|
|
1175
|
+
* Specify middleware that should be removed from the given route.
|
|
1176
|
+
*
|
|
1177
|
+
* @param middleware
|
|
1178
|
+
*/
|
|
1179
|
+
abstract withoutMiddleware(middleware: any): this;
|
|
1180
|
+
/**
|
|
1181
|
+
* Get the middleware that should be removed from the route.
|
|
1182
|
+
*/
|
|
1183
|
+
abstract excludedMiddleware(): any;
|
|
1184
|
+
/**
|
|
1185
|
+
* Get all middleware, including the ones from the controller.
|
|
1186
|
+
*/
|
|
1187
|
+
abstract gatherMiddleware(): GenericObject;
|
|
1188
|
+
/**
|
|
1189
|
+
* Indicate that the route should enforce scoping of multiple implicit Eloquent bindings.
|
|
1190
|
+
*/
|
|
1191
|
+
abstract scopeBindings(): this;
|
|
1192
|
+
/**
|
|
1193
|
+
* Indicate that the route should not enforce scoping of multiple implicit Eloquent bindings.
|
|
1194
|
+
*/
|
|
1195
|
+
abstract withoutScopedBindings(): this;
|
|
1196
|
+
/**
|
|
1197
|
+
* Determine if the route should enforce scoping of multiple implicit Eloquent bindings.
|
|
1198
|
+
*/
|
|
1199
|
+
abstract enforcesScopedBindings(): boolean;
|
|
1200
|
+
/**
|
|
1201
|
+
* Determine if the route should prevent scoping of multiple implicit Eloquent bindings.
|
|
1202
|
+
*/
|
|
1203
|
+
abstract preventsScopedBindings(): boolean;
|
|
1204
|
+
}
|
|
1205
|
+
//#endregion
|
|
1206
|
+
//#region src/Session/FlashBag.d.ts
|
|
1207
|
+
declare class FlashBag {
|
|
1208
|
+
/**
|
|
1209
|
+
* Flash a value for the next request
|
|
1210
|
+
*
|
|
1211
|
+
* @param key Key to store in flash
|
|
1212
|
+
* @param value Value to be flashed
|
|
1213
|
+
*/
|
|
1214
|
+
flash(key: string, value: any): void;
|
|
1215
|
+
/**
|
|
1216
|
+
* Store a temporary value for the current request only
|
|
1217
|
+
*
|
|
1218
|
+
* @param key Key to store
|
|
1219
|
+
* @param value Value to store
|
|
1220
|
+
*/
|
|
1221
|
+
now(key: string, value: any): void;
|
|
1222
|
+
/**
|
|
1223
|
+
* Reflash all current flash data for another request cycle
|
|
1224
|
+
*/
|
|
1225
|
+
reflash(): void;
|
|
1226
|
+
/**
|
|
1227
|
+
* Keep only specific flash keys for the next request
|
|
1228
|
+
*
|
|
1229
|
+
* @param keys Keys to keep
|
|
1230
|
+
*/
|
|
1231
|
+
keep(keys: string[]): void;
|
|
1232
|
+
/**
|
|
1233
|
+
* Age flash data at the end of the request
|
|
1234
|
+
*
|
|
1235
|
+
* - Removes old flash data
|
|
1236
|
+
* - Moves new flash data to old
|
|
1237
|
+
* - Clears new flash data
|
|
1238
|
+
*/
|
|
1239
|
+
ageFlashData(): void;
|
|
1240
|
+
/**
|
|
1241
|
+
* Get a flash value
|
|
1242
|
+
*
|
|
1243
|
+
* @param key Key to retrieve
|
|
1244
|
+
* @param defaultValue Default value if key doesn't exist
|
|
1245
|
+
* @returns Flash value or default
|
|
1246
|
+
*/
|
|
1247
|
+
get(key: string, defaultValue?: any): any;
|
|
1248
|
+
/**
|
|
1249
|
+
* Check if a flash key exists
|
|
1250
|
+
*
|
|
1251
|
+
* @param key Key to check
|
|
1252
|
+
* @returns Boolean indicating existence
|
|
1253
|
+
*/
|
|
1254
|
+
has(key: string): boolean;
|
|
1255
|
+
/**
|
|
1256
|
+
* Get all flash data
|
|
1257
|
+
*
|
|
1258
|
+
* @returns Combined flash data
|
|
1259
|
+
*/
|
|
1260
|
+
all(): Record<string, any>;
|
|
1261
|
+
/**
|
|
1262
|
+
* Get all flash data keys
|
|
1263
|
+
*
|
|
1264
|
+
* @returns Combined flash data
|
|
1265
|
+
*/
|
|
1266
|
+
keys(): string[];
|
|
1267
|
+
/**
|
|
1268
|
+
* Get the raww flash data
|
|
1269
|
+
*
|
|
1270
|
+
* @returns raw flash data
|
|
1271
|
+
*/
|
|
1272
|
+
raw(): Record<string, any>;
|
|
1273
|
+
/**
|
|
1274
|
+
* Clear all flash data
|
|
1275
|
+
*/
|
|
1276
|
+
clear(): void;
|
|
1277
|
+
}
|
|
1278
|
+
//#endregion
|
|
1279
|
+
//#region src/Session/SessionContract.d.ts
|
|
1280
|
+
/**
|
|
1281
|
+
* SessionDriver Interface
|
|
1282
|
+
*
|
|
1283
|
+
* All session drivers must implement these methods to ensure
|
|
1284
|
+
* consistency across different storage mechanisms (memory, files, database, redis).
|
|
1285
|
+
*/
|
|
1286
|
+
interface SessionDriver {
|
|
1287
|
+
flashBag: FlashBag;
|
|
1288
|
+
/**
|
|
1289
|
+
* Retrieve a value from the session by key.
|
|
1290
|
+
*
|
|
1291
|
+
* @param key
|
|
1292
|
+
* @param defaultValue
|
|
1293
|
+
*/
|
|
1294
|
+
get<T = any>(key: string, defaultValue?: any): T | Promise<T>;
|
|
1295
|
+
/**
|
|
1296
|
+
* Store multiple values in the session.
|
|
1297
|
+
*
|
|
1298
|
+
* @param key
|
|
1299
|
+
* @param defaultValue
|
|
1300
|
+
*/
|
|
1301
|
+
set(value: Record<string, any>): void | Promise<void>;
|
|
1302
|
+
/**
|
|
1303
|
+
* Retrieve all data from the session including flash
|
|
1304
|
+
*
|
|
1305
|
+
* @returns
|
|
1306
|
+
*/
|
|
1307
|
+
getAll<T extends Record<string, any>>(): Promise<T> | T;
|
|
1308
|
+
/**
|
|
1309
|
+
* Store a value in the session.
|
|
1310
|
+
*
|
|
1311
|
+
* @param key
|
|
1312
|
+
* @param value
|
|
1313
|
+
*/
|
|
1314
|
+
put(key: string, value: any): void | Promise<void>;
|
|
1315
|
+
/**
|
|
1316
|
+
* Append a value to an array key
|
|
1317
|
+
*
|
|
1318
|
+
* @param key
|
|
1319
|
+
* @param value
|
|
1320
|
+
*/
|
|
1321
|
+
push(key: string, value: any): Promise<void> | void;
|
|
1322
|
+
/**
|
|
1323
|
+
* Remove a key from the session.
|
|
1324
|
+
*
|
|
1325
|
+
* @param key
|
|
1326
|
+
*/
|
|
1327
|
+
forget(key: string): Promise<void> | void;
|
|
1328
|
+
/**
|
|
1329
|
+
* Determine if a key is present in the session.
|
|
1330
|
+
*
|
|
1331
|
+
* @param key
|
|
1332
|
+
*/
|
|
1333
|
+
has(key: string): Promise<boolean> | boolean;
|
|
1334
|
+
/**
|
|
1335
|
+
* Determine if a key exists in the session (even if null).
|
|
1336
|
+
*
|
|
1337
|
+
* @param key
|
|
1338
|
+
*/
|
|
1339
|
+
exists(key: string): Promise<boolean> | boolean;
|
|
1340
|
+
/**
|
|
1341
|
+
* Get all data from the session.
|
|
1342
|
+
*/
|
|
1343
|
+
all<T extends Record<string, any>>(): Promise<T> | T;
|
|
1344
|
+
/**
|
|
1345
|
+
* Get only a subset of session keys.
|
|
1346
|
+
*
|
|
1347
|
+
* @param keys
|
|
1348
|
+
*/
|
|
1349
|
+
only<T extends Record<string, any>>(keys: string[]): Promise<T> | T;
|
|
1350
|
+
/**
|
|
1351
|
+
* Get all session data except the specified keys.
|
|
1352
|
+
*
|
|
1353
|
+
* @param keys
|
|
1354
|
+
*/
|
|
1355
|
+
except<T extends Record<string, any>>(keys: string[]): Promise<T> | T;
|
|
1356
|
+
/**
|
|
1357
|
+
* Get and remove an item from the session.
|
|
1358
|
+
*
|
|
1359
|
+
* @param key
|
|
1360
|
+
* @param defaultValue
|
|
1361
|
+
*/
|
|
1362
|
+
pull<T = any>(key: string, defaultValue?: any): Promise<T> | T;
|
|
1363
|
+
/**
|
|
1364
|
+
* Increment a numeric session value.
|
|
1365
|
+
*
|
|
1366
|
+
* @param key
|
|
1367
|
+
* @param amount
|
|
1368
|
+
*/
|
|
1369
|
+
increment(key: string, amount?: number): Promise<number> | number;
|
|
1370
|
+
/**
|
|
1371
|
+
* Decrement a numeric session value.
|
|
1372
|
+
*
|
|
1373
|
+
* @param key
|
|
1374
|
+
* @param amount
|
|
1375
|
+
*/
|
|
1376
|
+
decrement(key: string, amount?: number): Promise<number> | number;
|
|
1377
|
+
/**
|
|
1378
|
+
* Flash a key/value pair for the next request only.
|
|
1379
|
+
*
|
|
1380
|
+
* @param key
|
|
1381
|
+
* @param value
|
|
1382
|
+
*/
|
|
1383
|
+
flash(key: string, value: any): Promise<void> | void;
|
|
1384
|
+
/**
|
|
1385
|
+
* Reflash all current flash data for another request cycle.
|
|
1386
|
+
*/
|
|
1387
|
+
reflash(): Promise<void> | void;
|
|
1388
|
+
/**
|
|
1389
|
+
* Keep only specific flash data for another request.
|
|
1390
|
+
*
|
|
1391
|
+
* @param keys
|
|
1392
|
+
*/
|
|
1393
|
+
keep(keys: string[]): Promise<void> | void;
|
|
1394
|
+
/**
|
|
1395
|
+
* Store data for the current request only (not persisted).
|
|
1396
|
+
*
|
|
1397
|
+
* @param key
|
|
1398
|
+
* @param value
|
|
1399
|
+
*/
|
|
1400
|
+
now(key: string, value: any): Promise<void> | void;
|
|
1401
|
+
/**
|
|
1402
|
+
* Regenerate the session ID and optionally persist the data.
|
|
1403
|
+
*/
|
|
1404
|
+
regenerate(): Promise<void> | void;
|
|
1405
|
+
/**
|
|
1406
|
+
* Invalidate the session completely and regenerate ID.
|
|
1407
|
+
*/
|
|
1408
|
+
invalidate(): Promise<void> | void;
|
|
1409
|
+
/**
|
|
1410
|
+
* Determine if an item is not present in the session.
|
|
1411
|
+
*
|
|
1412
|
+
* @param key
|
|
1413
|
+
*/
|
|
1414
|
+
missing(key: string): Promise<boolean> | boolean;
|
|
1415
|
+
/**
|
|
1416
|
+
* Flush all session data
|
|
1417
|
+
*/
|
|
1418
|
+
flush(): Promise<void> | void;
|
|
1419
|
+
/**
|
|
1420
|
+
* Age flash data at the end of the request lifecycle.
|
|
1421
|
+
*/
|
|
1422
|
+
ageFlashData(): Promise<void> | void;
|
|
1423
|
+
}
|
|
1424
|
+
interface DriverOption {
|
|
1425
|
+
cwd?: string;
|
|
1426
|
+
dir?: string;
|
|
1427
|
+
table?: string;
|
|
1428
|
+
prefix?: string;
|
|
1429
|
+
client?: any;
|
|
1430
|
+
sessionId?: string;
|
|
1431
|
+
sessionDir?: string;
|
|
1432
|
+
}
|
|
1433
|
+
/**
|
|
1434
|
+
* A builder function that returns a SessionDriver for a given sessionId.
|
|
1435
|
+
*
|
|
1436
|
+
* The builder receives the sessionId and a driver-specific options bag.
|
|
1437
|
+
*/
|
|
1438
|
+
type DriverBuilder = (sessionId: string, options?: DriverOption) => SessionDriver;
|
|
1439
|
+
//#endregion
|
|
1440
|
+
//#region src/Session/ISessionManager.d.ts
|
|
1441
|
+
/**
|
|
1442
|
+
* SessionManager
|
|
1443
|
+
*
|
|
1444
|
+
* Handles session initialization, ID generation, and encryption.
|
|
1445
|
+
* Each request gets a unique session namespace tied to its ID.
|
|
1446
|
+
*/
|
|
1447
|
+
declare class ISessionManager {
|
|
1448
|
+
/**
|
|
1449
|
+
* @param ctx - incoming request http context
|
|
1450
|
+
* @param driverName - registered driver key ('file' | 'database' | 'memory' | 'redis')
|
|
1451
|
+
* @param driverOptions - optional bag for driver-specific options
|
|
1452
|
+
*/
|
|
1453
|
+
constructor(ctx: IHttpContext, driverName: 'file' | 'memory' | 'database' | 'redis', driverOptions: DriverOption);
|
|
1454
|
+
/**
|
|
1455
|
+
* Access the current session ID.
|
|
1456
|
+
*/
|
|
1457
|
+
id(): string;
|
|
1458
|
+
/**
|
|
1459
|
+
* Retrieve a value from the session
|
|
1460
|
+
*
|
|
1461
|
+
* @param key
|
|
1462
|
+
* @returns
|
|
1463
|
+
*/
|
|
1464
|
+
get(key: string, defaultValue?: any): Promise<any> | any;
|
|
1465
|
+
/**
|
|
1466
|
+
* Store a value in the session
|
|
1467
|
+
*
|
|
1468
|
+
* @param key
|
|
1469
|
+
* @param value
|
|
1470
|
+
*/
|
|
1471
|
+
set(value: Record<string, any>): Promise<void> | void;
|
|
1472
|
+
/**
|
|
1473
|
+
* Store multiple key/value pairs
|
|
1474
|
+
*
|
|
1475
|
+
* @param values
|
|
1476
|
+
*/
|
|
1477
|
+
put(key: string, value: any): void | Promise<void>;
|
|
1478
|
+
/**
|
|
1479
|
+
* Append a value to an array key
|
|
1480
|
+
*
|
|
1481
|
+
* @param key
|
|
1482
|
+
* @param value
|
|
1483
|
+
*/
|
|
1484
|
+
push(key: string, value: any): void | Promise<void>;
|
|
1485
|
+
/**
|
|
1486
|
+
* Remove a key from the session
|
|
1487
|
+
*
|
|
1488
|
+
* @param key
|
|
1489
|
+
*/
|
|
1490
|
+
forget(key: string): void | Promise<void>;
|
|
1491
|
+
/**
|
|
1492
|
+
* Retrieve all session data
|
|
1493
|
+
*
|
|
1494
|
+
* @returns
|
|
1495
|
+
*/
|
|
1496
|
+
all(): Record<string, any> | Promise<Record<string, any>>;
|
|
1497
|
+
/**
|
|
1498
|
+
* Determine if a key exists (even if null).
|
|
1499
|
+
*
|
|
1500
|
+
* @param key
|
|
1501
|
+
* @returns
|
|
1502
|
+
*/
|
|
1503
|
+
exists(key: string): Promise<boolean> | boolean;
|
|
1504
|
+
/**
|
|
1505
|
+
* Determine if a key has a non-null value.
|
|
1506
|
+
*
|
|
1507
|
+
* @param key
|
|
1508
|
+
* @returns
|
|
1509
|
+
*/
|
|
1510
|
+
has(key: string): Promise<boolean> | boolean;
|
|
1511
|
+
/**
|
|
1512
|
+
* Get only specific keys.
|
|
1513
|
+
*
|
|
1514
|
+
* @param keys
|
|
1515
|
+
* @returns
|
|
1516
|
+
*/
|
|
1517
|
+
only(keys: string[]): Record<string, any> | Promise<Record<string, any>>;
|
|
1518
|
+
/**
|
|
1519
|
+
* Return all keys except the specified ones.
|
|
1520
|
+
*
|
|
1521
|
+
* @param keys
|
|
1522
|
+
* @returns
|
|
1523
|
+
*/
|
|
1524
|
+
except(keys: string[]): Record<string, any> | Promise<Record<string, any>>;
|
|
1525
|
+
/**
|
|
1526
|
+
* Return and delete a key from the session.
|
|
1527
|
+
*
|
|
1528
|
+
* @param key
|
|
1529
|
+
* @param defaultValue
|
|
1530
|
+
* @returns
|
|
1531
|
+
*/
|
|
1532
|
+
pull(key: string, defaultValue?: any): any;
|
|
1533
|
+
/**
|
|
1534
|
+
* Increment a numeric value by amount (default 1).
|
|
1535
|
+
*
|
|
1536
|
+
* @param key
|
|
1537
|
+
* @param amount
|
|
1538
|
+
* @returns
|
|
1539
|
+
*/
|
|
1540
|
+
increment(key: string, amount?: number): Promise<number> | number;
|
|
1541
|
+
/**
|
|
1542
|
+
* Decrement a numeric value by amount (default 1).
|
|
1543
|
+
*
|
|
1544
|
+
* @param key
|
|
1545
|
+
* @param amount
|
|
1546
|
+
* @returns
|
|
1547
|
+
*/
|
|
1548
|
+
decrement(key: string, amount?: number): number | Promise<number>;
|
|
1549
|
+
/**
|
|
1550
|
+
* Flash a value for next request only.
|
|
1551
|
+
*
|
|
1552
|
+
* @param key
|
|
1553
|
+
* @param value
|
|
1554
|
+
*/
|
|
1555
|
+
flash(key: string, value: any): void | Promise<void>;
|
|
1556
|
+
/**
|
|
1557
|
+
* Reflash all flash data for one more cycle.
|
|
1558
|
+
*
|
|
1559
|
+
* @returns
|
|
1560
|
+
*/
|
|
1561
|
+
reflash(): void | Promise<void>;
|
|
1562
|
+
/**
|
|
1563
|
+
* Keep only selected flash data.
|
|
1564
|
+
*
|
|
1565
|
+
* @param keys
|
|
1566
|
+
* @returns
|
|
1567
|
+
*/
|
|
1568
|
+
keep(keys: string[]): void | Promise<void>;
|
|
1569
|
+
/**
|
|
1570
|
+
* Store data only for current request cycle (not persisted).
|
|
1571
|
+
*
|
|
1572
|
+
* @param key
|
|
1573
|
+
* @param value
|
|
1574
|
+
*/
|
|
1575
|
+
now(key: string, value: any): void | Promise<void>;
|
|
1576
|
+
/**
|
|
1577
|
+
* Regenerate session ID and persist data under new ID.
|
|
1578
|
+
*/
|
|
1579
|
+
regenerate(): void | Promise<void>;
|
|
1580
|
+
/**
|
|
1581
|
+
* Determine if an item is not present in the session.
|
|
1582
|
+
*
|
|
1583
|
+
* @param key
|
|
1584
|
+
* @returns
|
|
1585
|
+
*/
|
|
1586
|
+
missing(key: string): Promise<boolean> | boolean;
|
|
1587
|
+
/**
|
|
1588
|
+
* Flush all session data
|
|
1589
|
+
*/
|
|
1590
|
+
flush(): void | Promise<void>;
|
|
1591
|
+
/**
|
|
1592
|
+
* Age flash data at the end of the request lifecycle.
|
|
1593
|
+
*
|
|
1594
|
+
* @returns
|
|
1595
|
+
*/
|
|
1596
|
+
ageFlashData(): void | Promise<void>;
|
|
1597
|
+
}
|
|
1598
|
+
//#endregion
|
|
1599
|
+
//#region src/Http/IRequest.d.ts
|
|
1600
|
+
type RequestObject$1 = Record<string, any>;
|
|
1601
|
+
/**
|
|
1602
|
+
* Interface for the Request contract, defining methods for handling HTTP request data.
|
|
1603
|
+
*/
|
|
1604
|
+
declare abstract class IRequest<D extends Record<string, any> = Record<string, any>, R extends Record<string, any> = Record<string, any>, U extends Record<string, any> = Record<string, any>> extends IHttpRequest {
|
|
1605
|
+
/**
|
|
1606
|
+
* The current app instance
|
|
1607
|
+
*/
|
|
1608
|
+
abstract app: IApplication;
|
|
1609
|
+
/**
|
|
1610
|
+
* Parsed request body
|
|
1611
|
+
*/
|
|
1612
|
+
abstract body: unknown;
|
|
1613
|
+
/**
|
|
1614
|
+
* The current Http Context
|
|
1615
|
+
*/
|
|
1616
|
+
abstract context: IHttpContext;
|
|
1617
|
+
/**
|
|
1618
|
+
* Gets route parameters.
|
|
1619
|
+
* @returns An object containing route parameters.
|
|
1620
|
+
*/
|
|
1621
|
+
abstract params: NonNullable<H3Event['context']['params']>;
|
|
1622
|
+
/**
|
|
1623
|
+
* The request attributes (parameters parsed from the PATH_INFO, ...).
|
|
1624
|
+
*/
|
|
1625
|
+
abstract attributes: IParamBag;
|
|
1626
|
+
/**
|
|
1627
|
+
* Gets the request headers.
|
|
1628
|
+
* @returns An object containing request headers.
|
|
1629
|
+
*/
|
|
1630
|
+
abstract headers: IHeaderBag;
|
|
1631
|
+
/**
|
|
1632
|
+
* Factory method to create a Request instance from an H3Event.
|
|
1633
|
+
*/
|
|
1634
|
+
static create(
|
|
1635
|
+
/**
|
|
1636
|
+
* The current H3 H3Event instance
|
|
1637
|
+
*/
|
|
1638
|
+
event: H3Event,
|
|
1639
|
+
/**
|
|
1640
|
+
* The current app instance
|
|
1641
|
+
*/
|
|
1642
|
+
app: IApplication): Promise<IRequest>;
|
|
1643
|
+
/**
|
|
1644
|
+
* Sets the parameters for this request.
|
|
1645
|
+
*
|
|
1646
|
+
* This method also re-initializes all properties.
|
|
1647
|
+
*
|
|
1648
|
+
* @param attributes
|
|
1649
|
+
* @param cookies The COOKIE parameters
|
|
1650
|
+
* @param files The FILES parameters
|
|
1651
|
+
* @param server The SERVER parameters
|
|
1652
|
+
* @param content The raw body data
|
|
1653
|
+
*/
|
|
1654
|
+
abstract initialize(): Promise<void>;
|
|
1655
|
+
/**
|
|
1656
|
+
* Retrieve all data from the instance (query + body).
|
|
1657
|
+
*/
|
|
1658
|
+
abstract all<T = Record<string, any>>(keys?: string | string[]): T;
|
|
1659
|
+
/**
|
|
1660
|
+
* Retrieve an input item from the request.
|
|
1661
|
+
*
|
|
1662
|
+
* @param key
|
|
1663
|
+
* @param defaultValue
|
|
1664
|
+
* @returns
|
|
1665
|
+
*/
|
|
1666
|
+
abstract input<K$1 extends string | undefined>(key?: K$1, defaultValue?: any): K$1 extends undefined ? RequestObject$1 : any;
|
|
1667
|
+
/**
|
|
1668
|
+
* Retrieve a file from the request.
|
|
1669
|
+
*
|
|
1670
|
+
* By default a single `UploadedFile` instance will always be returned by
|
|
1671
|
+
* the method (first file in property when there are multiple), unless
|
|
1672
|
+
* the `expectArray` parameter is set to true, in which case, the method
|
|
1673
|
+
* returns an `UploadedFile[]` array.
|
|
1674
|
+
*
|
|
1675
|
+
* @param key
|
|
1676
|
+
* @param defaultValue
|
|
1677
|
+
* @param expectArray set to true to return an `UploadedFile[]` array.
|
|
1678
|
+
* @returns
|
|
1679
|
+
*/
|
|
1680
|
+
abstract file(): Record<string, IUploadedFile>;
|
|
1681
|
+
abstract file(key?: undefined, defaultValue?: any, expectArray?: true): Record<string, IUploadedFile[]>;
|
|
1682
|
+
abstract file(key: string, defaultValue?: any, expectArray?: false | undefined): IUploadedFile;
|
|
1683
|
+
abstract file(key: string, defaultValue?: any, expectArray?: true): IUploadedFile[];
|
|
1684
|
+
/**
|
|
1685
|
+
* Get the user making the request.
|
|
1686
|
+
*
|
|
1687
|
+
* @param guard
|
|
1688
|
+
*/
|
|
1689
|
+
abstract user(guard?: string): U | undefined;
|
|
1690
|
+
/**
|
|
1691
|
+
* Get the route handling the request.
|
|
1692
|
+
*
|
|
1693
|
+
* @param param
|
|
1694
|
+
* @param defaultRoute
|
|
1695
|
+
*/
|
|
1696
|
+
abstract route(): IRoute;
|
|
1697
|
+
abstract route(param?: string, defaultParam?: any): any;
|
|
1698
|
+
/**
|
|
1699
|
+
* Determine if the uploaded data contains a file.
|
|
1700
|
+
*
|
|
1701
|
+
* @param key
|
|
1702
|
+
* @return boolean
|
|
1703
|
+
*/
|
|
1704
|
+
abstract hasFile(key: string): boolean;
|
|
1705
|
+
/**
|
|
1706
|
+
* Get an object with all the files on the request.
|
|
1707
|
+
*/
|
|
1708
|
+
abstract allFiles(): Record<string, IUploadedFile | IUploadedFile[]>;
|
|
1709
|
+
/**
|
|
1710
|
+
* Extract and convert uploaded files from FormData.
|
|
1711
|
+
*/
|
|
1712
|
+
abstract convertUploadedFiles(files: Record<string, IUploadedFile | IUploadedFile[]>): Record<string, IUploadedFile | IUploadedFile[]>;
|
|
1713
|
+
/**
|
|
1714
|
+
* Determine if the data contains a given key.
|
|
1715
|
+
*
|
|
1716
|
+
* @param keys
|
|
1717
|
+
* @returns
|
|
1718
|
+
*/
|
|
1719
|
+
abstract has(keys: string[] | string): boolean;
|
|
1720
|
+
/**
|
|
1721
|
+
* Determine if the instance is missing a given key.
|
|
1722
|
+
*/
|
|
1723
|
+
abstract missing(key: string | string[]): boolean;
|
|
1724
|
+
/**
|
|
1725
|
+
* Get a subset containing the provided keys with values from the instance data.
|
|
1726
|
+
*
|
|
1727
|
+
* @param keys
|
|
1728
|
+
* @returns
|
|
1729
|
+
*/
|
|
1730
|
+
abstract only<T = Record<string, any>>(keys: string[]): T;
|
|
1731
|
+
/**
|
|
1732
|
+
* Get all of the data except for a specified array of items.
|
|
1733
|
+
*
|
|
1734
|
+
* @param keys
|
|
1735
|
+
* @returns
|
|
1736
|
+
*/
|
|
1737
|
+
abstract except<T = Record<string, any>>(keys: string[]): T;
|
|
1738
|
+
/**
|
|
1739
|
+
* Merges new input data into the current request's input source.
|
|
1740
|
+
*
|
|
1741
|
+
* @param input - An object containing key-value pairs to merge.
|
|
1742
|
+
* @returns this - For fluent chaining.
|
|
1743
|
+
*/
|
|
1744
|
+
abstract merge(input: Record<string, any>): this;
|
|
1745
|
+
/**
|
|
1746
|
+
* Merge new input into the request's input, but only when that key is missing from the request.
|
|
1747
|
+
*
|
|
1748
|
+
* @param input
|
|
1749
|
+
*/
|
|
1750
|
+
abstract mergeIfMissing(input: Record<string, any>): this;
|
|
1751
|
+
/**
|
|
1752
|
+
* Get the keys for all of the input and files.
|
|
1753
|
+
*/
|
|
1754
|
+
abstract keys(): string[];
|
|
1755
|
+
/**
|
|
1756
|
+
* Get an instance of the current session manager
|
|
1757
|
+
*
|
|
1758
|
+
* @param key
|
|
1759
|
+
* @param defaultValue
|
|
1760
|
+
* @returns an instance of the current session manager.
|
|
1761
|
+
*/
|
|
1762
|
+
abstract session<K$1 extends string | Record<string, any> | undefined = undefined>(key?: K$1, defaultValue?: any): K$1 extends undefined ? ISessionManager : K$1 extends string ? any : void | Promise<void>;
|
|
1763
|
+
/**
|
|
1764
|
+
* Determine if the request is sending JSON.
|
|
1765
|
+
*
|
|
1766
|
+
* @return bool
|
|
1767
|
+
*/
|
|
1768
|
+
abstract isJson(): boolean;
|
|
1769
|
+
/**
|
|
1770
|
+
* Determine if the current request probably expects a JSON response.
|
|
1771
|
+
*
|
|
1772
|
+
* @returns
|
|
1773
|
+
*/
|
|
1774
|
+
abstract expectsJson(): boolean;
|
|
1775
|
+
/**
|
|
1776
|
+
* Determine if the current request is asking for JSON.
|
|
1777
|
+
*
|
|
1778
|
+
* @returns
|
|
1779
|
+
*/
|
|
1780
|
+
abstract wantsJson(): boolean;
|
|
1781
|
+
/**
|
|
1782
|
+
* Gets a list of content types acceptable by the client browser in preferable order.
|
|
1783
|
+
* @returns {string[]}
|
|
1784
|
+
*/
|
|
1785
|
+
abstract getAcceptableContentTypes(): string[];
|
|
1786
|
+
/**
|
|
1787
|
+
* Determine if the request is the result of a PJAX call.
|
|
1788
|
+
*
|
|
1789
|
+
* @return bool
|
|
1790
|
+
*/
|
|
1791
|
+
abstract pjax(): boolean;
|
|
1792
|
+
/**
|
|
1793
|
+
* Returns true if the request is an XMLHttpRequest (AJAX).
|
|
1794
|
+
*
|
|
1795
|
+
* @alias isXmlHttpRequest()
|
|
1796
|
+
* @returns {boolean}
|
|
1797
|
+
*/
|
|
1798
|
+
abstract ajax(): boolean;
|
|
1799
|
+
/**
|
|
1800
|
+
* Returns true if the request is an XMLHttpRequest (AJAX).
|
|
1801
|
+
*/
|
|
1802
|
+
abstract isXmlHttpRequest(): boolean;
|
|
1803
|
+
/**
|
|
1804
|
+
* Returns the value of the requested header.
|
|
1805
|
+
*/
|
|
1806
|
+
abstract getHeader(name: string): string | undefined | null;
|
|
1807
|
+
/**
|
|
1808
|
+
* Checks if the request method is of specified type.
|
|
1809
|
+
*
|
|
1810
|
+
* @param method Uppercase request method (GET, POST etc)
|
|
1811
|
+
*/
|
|
1812
|
+
abstract isMethod(method: string): boolean;
|
|
1813
|
+
/**
|
|
1814
|
+
* Checks whether or not the method is safe.
|
|
1815
|
+
*
|
|
1816
|
+
* @see https://tools.ietf.org/html/rfc7231#section-4.2.1
|
|
1817
|
+
*/
|
|
1818
|
+
abstract isMethodSafe(): boolean;
|
|
1819
|
+
/**
|
|
1820
|
+
* Checks whether or not the method is idempotent.
|
|
1821
|
+
*/
|
|
1822
|
+
abstract isMethodIdempotent(): boolean;
|
|
1823
|
+
/**
|
|
1824
|
+
* Checks whether the method is cacheable or not.
|
|
1825
|
+
*
|
|
1826
|
+
* @see https://tools.ietf.org/html/rfc7231#section-4.2.3
|
|
1827
|
+
*/
|
|
1828
|
+
abstract isMethodCacheable(): boolean;
|
|
1829
|
+
/**
|
|
1830
|
+
* Gets the request "intended" method.
|
|
1831
|
+
*
|
|
1832
|
+
* If the X-HTTP-Method-Override header is set, and if the method is a POST,
|
|
1833
|
+
* then it is used to determine the "real" intended HTTP method.
|
|
1834
|
+
*
|
|
1835
|
+
* The _method request parameter can also be used to determine the HTTP method,
|
|
1836
|
+
* but only if enableHttpMethodParameterOverride() has been called.
|
|
1837
|
+
*
|
|
1838
|
+
* The method is always an uppercased string.
|
|
1839
|
+
*
|
|
1840
|
+
* @see getRealMethod()
|
|
1841
|
+
*/
|
|
1842
|
+
abstract getMethod(): RequestMethod;
|
|
1843
|
+
/**
|
|
1844
|
+
* Gets the "real" request method.
|
|
1845
|
+
*
|
|
1846
|
+
* @see getMethod()
|
|
1847
|
+
*/
|
|
1848
|
+
abstract getRealMethod(): RequestMethod;
|
|
1849
|
+
/**
|
|
1850
|
+
* Get the client IP address.
|
|
1851
|
+
*/
|
|
1852
|
+
abstract ip(): string | undefined;
|
|
1853
|
+
/**
|
|
1854
|
+
* Get the flashed input from previous request
|
|
1855
|
+
*
|
|
1856
|
+
* @param key
|
|
1857
|
+
* @param defaultValue
|
|
1858
|
+
* @returns
|
|
1859
|
+
*/
|
|
1860
|
+
abstract old(): Promise<Record<string, any>>;
|
|
1861
|
+
abstract old(key: string, defaultValue?: any): Promise<any>;
|
|
1862
|
+
/**
|
|
1863
|
+
* Get a URI instance for the request.
|
|
1864
|
+
*/
|
|
1865
|
+
abstract uri(): unknown;
|
|
1866
|
+
/**
|
|
1867
|
+
* Get the root URL for the application.
|
|
1868
|
+
*
|
|
1869
|
+
* @return string
|
|
1870
|
+
*/
|
|
1871
|
+
abstract root(): string;
|
|
1872
|
+
/**
|
|
1873
|
+
* Get the URL (no query string) for the request.
|
|
1874
|
+
*
|
|
1875
|
+
* @return string
|
|
1876
|
+
*/
|
|
1877
|
+
abstract url(): string;
|
|
1878
|
+
/**
|
|
1879
|
+
* Get the full URL for the request.
|
|
1880
|
+
*/
|
|
1881
|
+
abstract fullUrl(): string;
|
|
1882
|
+
/**
|
|
1883
|
+
* Get the current path info for the request.
|
|
1884
|
+
*/
|
|
1885
|
+
abstract path(): string;
|
|
1886
|
+
/**
|
|
1887
|
+
* Return the Request instance.
|
|
1888
|
+
*/
|
|
1889
|
+
abstract instance(): this;
|
|
1890
|
+
/**
|
|
1891
|
+
* Get the request method.
|
|
1892
|
+
*/
|
|
1893
|
+
abstract method(): RequestMethod;
|
|
1894
|
+
/**
|
|
1895
|
+
* Get the JSON payload for the request.
|
|
1896
|
+
*
|
|
1897
|
+
* @param key
|
|
1898
|
+
* @param defaultValue
|
|
1899
|
+
* @return {InputBag}
|
|
1900
|
+
*/
|
|
1901
|
+
abstract json<K$1 extends string | undefined = undefined>(key?: string, defaultValue?: any): K$1 extends undefined ? IParamBag : any;
|
|
1902
|
+
/**
|
|
1903
|
+
* Get the user resolver callback.
|
|
1904
|
+
*/
|
|
1905
|
+
abstract getUserResolver(): (gaurd?: string) => U | undefined;
|
|
1906
|
+
/**
|
|
1907
|
+
* Set the user resolver callback.
|
|
1908
|
+
*
|
|
1909
|
+
* @param callback
|
|
1910
|
+
*/
|
|
1911
|
+
abstract setUserResolver(callback: (gaurd?: string) => U): this;
|
|
1912
|
+
/**
|
|
1913
|
+
* Get the route resolver callback.
|
|
1914
|
+
*/
|
|
1915
|
+
abstract getRouteResolver(): () => IRoute | undefined;
|
|
1916
|
+
/**
|
|
1917
|
+
* Set the route resolver callback.
|
|
1918
|
+
*
|
|
1919
|
+
* @param callback
|
|
1920
|
+
*/
|
|
1921
|
+
abstract setRouteResolver(callback: () => IRoute): this;
|
|
1922
|
+
/**
|
|
1923
|
+
* Get the bearer token from the request headers.
|
|
1924
|
+
*/
|
|
1925
|
+
abstract bearerToken(): string | undefined;
|
|
1926
|
+
/**
|
|
1927
|
+
* Retrieve a request payload item from the request.
|
|
1928
|
+
*
|
|
1929
|
+
* @param key
|
|
1930
|
+
* @param default
|
|
1931
|
+
*/
|
|
1932
|
+
abstract post(key?: string, defaultValue?: any): any;
|
|
1933
|
+
/**
|
|
1934
|
+
* Determine if a header is set on the request.
|
|
1935
|
+
*
|
|
1936
|
+
* @param key
|
|
1937
|
+
*/
|
|
1938
|
+
abstract hasHeader(key: string): boolean;
|
|
1939
|
+
/**
|
|
1940
|
+
* Retrieve a header from the request.
|
|
1941
|
+
*
|
|
1942
|
+
* @param key
|
|
1943
|
+
* @param default
|
|
1944
|
+
*/
|
|
1945
|
+
abstract header(key?: string, defaultValue?: any): any;
|
|
1946
|
+
/**
|
|
1947
|
+
* Determine if a cookie is set on the request.
|
|
1948
|
+
*
|
|
1949
|
+
* @param string $key
|
|
1950
|
+
*/
|
|
1951
|
+
abstract hasCookie(key: string): boolean;
|
|
1952
|
+
/**
|
|
1953
|
+
* Retrieve a cookie from the request.
|
|
1954
|
+
*
|
|
1955
|
+
* @param key
|
|
1956
|
+
* @param default
|
|
1957
|
+
*/
|
|
1958
|
+
abstract cookie(key?: string, defaultValue?: any): any;
|
|
1959
|
+
/**
|
|
1960
|
+
* Retrieve a query string item from the request.
|
|
1961
|
+
*
|
|
1962
|
+
* @param key
|
|
1963
|
+
* @param default
|
|
1964
|
+
*/
|
|
1965
|
+
abstract query(key?: string, defaultValue?: any): any;
|
|
1966
|
+
/**
|
|
1967
|
+
* Retrieve a server variable from the request.
|
|
1968
|
+
*
|
|
1969
|
+
* @param key
|
|
1970
|
+
* @param default
|
|
1971
|
+
*/
|
|
1972
|
+
abstract server(key?: string, defaultValue?: any): any;
|
|
1973
|
+
/**
|
|
1974
|
+
* Returns the request body content.
|
|
1975
|
+
*
|
|
1976
|
+
* @param asStream If true, returns a ReadableStream instead of the parsed string
|
|
1977
|
+
* @return {string | ReadableStream | Promise<string | ReadableStream>}
|
|
1978
|
+
*/
|
|
1979
|
+
abstract getContent(asStream?: boolean): string | ReadableStream;
|
|
1980
|
+
/**
|
|
1981
|
+
* Gets a "parameter" value from any bag.
|
|
1982
|
+
*
|
|
1983
|
+
* This method is mainly useful for libraries that want to provide some flexibility. If you don't need the
|
|
1984
|
+
* flexibility in controllers, it is better to explicitly get request parameters from the appropriate
|
|
1985
|
+
* public property instead (attributes, query, request).
|
|
1986
|
+
*
|
|
1987
|
+
* Order of precedence: PATH (routing placeholders or custom attributes), GET, POST
|
|
1988
|
+
*
|
|
1989
|
+
* @internal use explicit input sources instead
|
|
1990
|
+
*/
|
|
1991
|
+
abstract get(key: string, defaultValue?: any): any;
|
|
1992
|
+
/**
|
|
1993
|
+
* Validate the incoming request data
|
|
1994
|
+
*
|
|
1995
|
+
* @param data
|
|
1996
|
+
* @param rules
|
|
1997
|
+
* @param messages
|
|
1998
|
+
*/
|
|
1999
|
+
abstract validate(rules: R, messages?: Partial<Record<string, string>>): Promise<D>;
|
|
2000
|
+
/**
|
|
2001
|
+
* Enables support for the _method request parameter to determine the intended HTTP method.
|
|
2002
|
+
*
|
|
2003
|
+
* Be warned that enabling this feature might lead to CSRF issues in your code.
|
|
2004
|
+
* Check that you are using CSRF tokens when required.
|
|
2005
|
+
* If the HTTP method parameter override is enabled, an html-form with method "POST" can be altered
|
|
2006
|
+
* and used to send a "PUT" or "DELETE" request via the _method request parameter.
|
|
2007
|
+
* If these methods are not protected against CSRF, this presents a possible vulnerability.
|
|
2008
|
+
*
|
|
2009
|
+
* The HTTP method can only be overridden when the real HTTP method is POST.
|
|
2010
|
+
*/
|
|
2011
|
+
static enableHttpMethodParameterOverride(): void;
|
|
2012
|
+
/**
|
|
2013
|
+
* Checks whether support for the _method request parameter is enabled.
|
|
2014
|
+
*/
|
|
2015
|
+
static getHttpMethodParameterOverride(): boolean;
|
|
2016
|
+
/**
|
|
2017
|
+
* Dump the items.
|
|
2018
|
+
*
|
|
2019
|
+
* @param keys
|
|
2020
|
+
* @return this
|
|
2021
|
+
*/
|
|
2022
|
+
abstract dump(...keys: any[]): this;
|
|
2023
|
+
/**
|
|
2024
|
+
* Get the base event
|
|
2025
|
+
*/
|
|
2026
|
+
abstract getEvent(): H3Event;
|
|
2027
|
+
abstract getEvent<K$1 extends DotNestedKeys<H3Event>>(key: K$1): DotNestedValue<H3Event, K$1>;
|
|
2028
|
+
}
|
|
2029
|
+
//#endregion
|
|
2030
|
+
//#region src/Http/IHttpResponse.d.ts
|
|
2031
|
+
/**
|
|
2032
|
+
* Interface for the Response contract, defining methods for handling HTTP responses.
|
|
2033
|
+
*/
|
|
2034
|
+
declare abstract class IHttpResponse {
|
|
2035
|
+
/**
|
|
2036
|
+
* Set HTTP status code.
|
|
2037
|
+
*/
|
|
2038
|
+
abstract setStatusCode(code: number, text?: string): this;
|
|
2039
|
+
/**
|
|
2040
|
+
* Retrieves the status code for the current web response.
|
|
2041
|
+
*/
|
|
2042
|
+
abstract getStatusCode(): number;
|
|
2043
|
+
/**
|
|
2044
|
+
* Sets the response charset.
|
|
2045
|
+
*/
|
|
2046
|
+
abstract setCharset(charset: string): this;
|
|
2047
|
+
/**
|
|
2048
|
+
* Retrieves the response charset.
|
|
2049
|
+
*/
|
|
2050
|
+
abstract getCharset(): string | undefined;
|
|
2051
|
+
/**
|
|
2052
|
+
* Returns true if the response may safely be kept in a shared (surrogate) cache.
|
|
2053
|
+
*
|
|
2054
|
+
* Responses marked "private" with an explicit Cache-Control directive are
|
|
2055
|
+
* considered uncacheable.
|
|
2056
|
+
*
|
|
2057
|
+
* Responses with neither a freshness lifetime (Expires, max-age) nor cache
|
|
2058
|
+
* validator (Last-Modified, ETag) are considered uncacheable because there is
|
|
2059
|
+
* no way to tell when or how to remove them from the cache.
|
|
2060
|
+
*
|
|
2061
|
+
* Note that RFC 7231 and RFC 7234 possibly allow for a more permissive implementation,
|
|
2062
|
+
* for example "status codes that are defined as cacheable by default [...]
|
|
2063
|
+
* can be reused by a cache with heuristic expiration unless otherwise indicated"
|
|
2064
|
+
* (https://tools.ietf.org/html/rfc7231#section-6.1)
|
|
2065
|
+
*
|
|
2066
|
+
* @final
|
|
2067
|
+
*/
|
|
2068
|
+
abstract isCacheable(): boolean;
|
|
2069
|
+
/**
|
|
2070
|
+
* Returns true if the response is "fresh".
|
|
2071
|
+
*
|
|
2072
|
+
* Fresh responses may be served from cache without any interaction with the
|
|
2073
|
+
* origin. A response is considered fresh when it includes a Cache-Control/max-age
|
|
2074
|
+
* indicator or Expires header and the calculated age is less than the freshness lifetime.
|
|
2075
|
+
*/
|
|
2076
|
+
abstract isFresh(): boolean;
|
|
2077
|
+
/**
|
|
2078
|
+
* Returns true if the response includes headers that can be used to validate
|
|
2079
|
+
* the response with the origin server using a conditional GET request.
|
|
2080
|
+
*/
|
|
2081
|
+
abstract isValidateable(): boolean;
|
|
2082
|
+
/**
|
|
2083
|
+
* Sets the response content.
|
|
2084
|
+
*/
|
|
2085
|
+
abstract setContent(content?: any): this;
|
|
2086
|
+
/**
|
|
2087
|
+
* Gets the current response content.
|
|
2088
|
+
*/
|
|
2089
|
+
abstract getContent(): any;
|
|
2090
|
+
/**
|
|
2091
|
+
* Set a header.
|
|
2092
|
+
*/
|
|
2093
|
+
abstract setHeader(name: string, value: string): this;
|
|
2094
|
+
/**
|
|
2095
|
+
* Sets the HTTP protocol version (1.0 or 1.1).
|
|
2096
|
+
*/
|
|
2097
|
+
abstract setProtocolVersion(version: string): this;
|
|
2098
|
+
/**
|
|
2099
|
+
* Gets the HTTP protocol version.
|
|
2100
|
+
*/
|
|
2101
|
+
abstract getProtocolVersion(): string;
|
|
2102
|
+
/**
|
|
2103
|
+
* Marks the response as "private".
|
|
2104
|
+
*
|
|
2105
|
+
* It makes the response ineligible for serving other clients.
|
|
2106
|
+
*/
|
|
2107
|
+
abstract setPrivate(): this;
|
|
2108
|
+
/**
|
|
2109
|
+
* Marks the response as "public".
|
|
2110
|
+
*
|
|
2111
|
+
* It makes the response eligible for serving other clients.
|
|
2112
|
+
*/
|
|
2113
|
+
abstract setPublic(): this;
|
|
2114
|
+
/**
|
|
2115
|
+
* Returns the Date header as a DateTime instance.
|
|
2116
|
+
* @throws {RuntimeException} When the header is not parseable
|
|
2117
|
+
*/
|
|
2118
|
+
abstract getDate(): any;
|
|
2119
|
+
/**
|
|
2120
|
+
* Returns the age of the response in seconds.
|
|
2121
|
+
*
|
|
2122
|
+
* @final
|
|
2123
|
+
*/
|
|
2124
|
+
abstract getAge(): number;
|
|
2125
|
+
/**
|
|
2126
|
+
* Marks the response stale by setting the Age header to be equal to the maximum age of the response.
|
|
2127
|
+
*/
|
|
2128
|
+
abstract expire(): this;
|
|
2129
|
+
/**
|
|
2130
|
+
* Returns the value of the Expires header as a DateTime instance.
|
|
2131
|
+
*
|
|
2132
|
+
* @final
|
|
2133
|
+
*/
|
|
2134
|
+
abstract getExpires(): any;
|
|
2135
|
+
/**
|
|
2136
|
+
* Returns the number of seconds after the time specified in the response's Date
|
|
2137
|
+
* header when the response should no longer be considered fresh.
|
|
2138
|
+
*
|
|
2139
|
+
* First, it checks for a s-maxage directive, then a max-age directive, and then it falls
|
|
2140
|
+
* back on an expires header. It returns null when no maximum age can be established.
|
|
2141
|
+
*/
|
|
2142
|
+
abstract getMaxAge(): number | undefined;
|
|
2143
|
+
/**
|
|
2144
|
+
* Sets the number of seconds after which the response should no longer be considered fresh.
|
|
2145
|
+
*
|
|
2146
|
+
* This method sets the Cache-Control max-age directive.
|
|
2147
|
+
*/
|
|
2148
|
+
abstract setMaxAge(value: number): this;
|
|
2149
|
+
/**
|
|
2150
|
+
* Sets the number of seconds after which the response should no longer be returned by shared caches when backend is down.
|
|
2151
|
+
*
|
|
2152
|
+
* This method sets the Cache-Control stale-if-error directive.
|
|
2153
|
+
*/
|
|
2154
|
+
abstract setStaleIfError(value: number): this;
|
|
2155
|
+
/**
|
|
2156
|
+
* Sets the number of seconds after which the response should no longer return stale content by shared caches.
|
|
2157
|
+
*
|
|
2158
|
+
* This method sets the Cache-Control stale-while-revalidate directive.
|
|
2159
|
+
*/
|
|
2160
|
+
abstract setStaleWhileRevalidate(value: number): this;
|
|
2161
|
+
/**
|
|
2162
|
+
* Returns the response's time-to-live in seconds.
|
|
2163
|
+
*
|
|
2164
|
+
* It returns null when no freshness information is present in the response.
|
|
2165
|
+
*
|
|
2166
|
+
* When the response's TTL is 0, the response may not be served from cache without first
|
|
2167
|
+
* revalidating with the origin.
|
|
2168
|
+
*
|
|
2169
|
+
* @final
|
|
2170
|
+
*/
|
|
2171
|
+
abstract getTtl(): number | undefined;
|
|
2172
|
+
/**
|
|
2173
|
+
* Sets the response's time-to-live for shared caches in seconds.
|
|
2174
|
+
*
|
|
2175
|
+
* This method adjusts the Cache-Control/s-maxage directive.
|
|
2176
|
+
*/
|
|
2177
|
+
abstract setTtl(seconds: number): this;
|
|
2178
|
+
/**
|
|
2179
|
+
* Sets the response's time-to-live for private/client caches in seconds.
|
|
2180
|
+
*
|
|
2181
|
+
* This method adjusts the Cache-Control/max-age directive.
|
|
2182
|
+
*/
|
|
2183
|
+
abstract setClientTtl(seconds: number): this;
|
|
2184
|
+
/**
|
|
2185
|
+
* Sets the number of seconds after which the response should no longer be considered fresh by shared caches.
|
|
2186
|
+
*
|
|
2187
|
+
* This method sets the Cache-Control s-maxage directive.
|
|
2188
|
+
*/
|
|
2189
|
+
abstract setSharedMaxAge(value: number): this;
|
|
2190
|
+
/**
|
|
2191
|
+
* Returns the Last-Modified HTTP header as a DateTime instance.
|
|
2192
|
+
*
|
|
2193
|
+
* @throws \RuntimeException When the HTTP header is not parseable
|
|
2194
|
+
*
|
|
2195
|
+
* @final
|
|
2196
|
+
*/
|
|
2197
|
+
abstract getLastModified(): any;
|
|
2198
|
+
/**
|
|
2199
|
+
* Sets the Last-Modified HTTP header with a DateTime instance.
|
|
2200
|
+
*
|
|
2201
|
+
* Passing null as value will remove the header.
|
|
2202
|
+
*
|
|
2203
|
+
* @return $this
|
|
2204
|
+
*
|
|
2205
|
+
* @final
|
|
2206
|
+
*/
|
|
2207
|
+
abstract setLastModified(date?: any): this;
|
|
2208
|
+
/**
|
|
2209
|
+
* Returns the literal value of the ETag HTTP header.
|
|
2210
|
+
*/
|
|
2211
|
+
abstract getEtag(): string | null;
|
|
2212
|
+
/**
|
|
2213
|
+
* Sets the ETag value.
|
|
2214
|
+
*
|
|
2215
|
+
* @param etag The ETag unique identifier or null to remove the header
|
|
2216
|
+
* @param weak Whether you want a weak ETag or not
|
|
2217
|
+
*/
|
|
2218
|
+
abstract setEtag(etag?: string, weak?: boolean): this;
|
|
2219
|
+
/**
|
|
2220
|
+
* Sets the response's cache headers (validation and/or expiration).
|
|
2221
|
+
*
|
|
2222
|
+
* Available options are: must_revalidate, no_cache, no_store, no_transform, public, private, proxy_revalidate, max_age, s_maxage, immutable, last_modified and etag.
|
|
2223
|
+
*
|
|
2224
|
+
* @throws {InvalidArgumentException}
|
|
2225
|
+
*/
|
|
2226
|
+
abstract setCache(options: any): this;
|
|
2227
|
+
/**
|
|
2228
|
+
* Modifies the response so that it conforms to the rules defined for a 304 status code.
|
|
2229
|
+
*
|
|
2230
|
+
* This sets the status, removes the body, and discards any headers
|
|
2231
|
+
* that MUST NOT be included in 304 responses.
|
|
2232
|
+
* @see https://tools.ietf.org/html/rfc2616#section-10.3.5
|
|
2233
|
+
*/
|
|
2234
|
+
abstract setNotModified(): this;
|
|
2235
|
+
/**
|
|
2236
|
+
* Add an array of headers to the response.
|
|
2237
|
+
*
|
|
2238
|
+
*/
|
|
2239
|
+
abstract withHeaders(headers: any): this;
|
|
2240
|
+
/**
|
|
2241
|
+
* Set the exception to attach to the response.
|
|
2242
|
+
*/
|
|
2243
|
+
abstract withException(e: Error): this;
|
|
2244
|
+
/**
|
|
2245
|
+
* Throws the response in a HttpResponseException instance.
|
|
2246
|
+
*
|
|
2247
|
+
* @throws {HttpResponseException}
|
|
2248
|
+
*/
|
|
2249
|
+
abstract throwResponse(): void;
|
|
2250
|
+
/**
|
|
2251
|
+
* Is response invalid?
|
|
2252
|
+
*
|
|
2253
|
+
* @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
|
|
2254
|
+
*/
|
|
2255
|
+
abstract isInvalid(): boolean;
|
|
2256
|
+
/**
|
|
2257
|
+
* Is response informative?
|
|
2258
|
+
*/
|
|
2259
|
+
abstract isInformational(): boolean;
|
|
2260
|
+
/**
|
|
2261
|
+
* Is response successful?
|
|
2262
|
+
*/
|
|
2263
|
+
abstract isSuccessful(): boolean;
|
|
2264
|
+
/**
|
|
2265
|
+
* Is the response a redirect?
|
|
2266
|
+
*/
|
|
2267
|
+
abstract isRedirection(): boolean;
|
|
2268
|
+
/**
|
|
2269
|
+
* Is there a client error?
|
|
2270
|
+
*/
|
|
2271
|
+
abstract isClientError(): boolean;
|
|
2272
|
+
/**
|
|
2273
|
+
* Was there a server side error?
|
|
2274
|
+
*/
|
|
2275
|
+
abstract isServerError(): boolean;
|
|
2276
|
+
/**
|
|
2277
|
+
* Is the response OK?
|
|
2278
|
+
*/
|
|
2279
|
+
abstract isOk(): boolean;
|
|
2280
|
+
/**
|
|
2281
|
+
* Is the response forbidden?
|
|
2282
|
+
*/
|
|
2283
|
+
abstract isForbidden(): boolean;
|
|
2284
|
+
/**
|
|
2285
|
+
* Is the response a not found error?
|
|
2286
|
+
*/
|
|
2287
|
+
abstract isNotFound(): boolean;
|
|
2288
|
+
/**
|
|
2289
|
+
* Is the response a redirect of some form?
|
|
2290
|
+
*/
|
|
2291
|
+
abstract isRedirect(location?: string | null): boolean;
|
|
2292
|
+
/**
|
|
2293
|
+
* Is the response empty?
|
|
2294
|
+
*/
|
|
2295
|
+
abstract isEmpty(): boolean;
|
|
2296
|
+
/**
|
|
2297
|
+
* Apply headers before sending response.
|
|
2298
|
+
*/
|
|
2299
|
+
abstract sendHeaders(statusCode?: number): this;
|
|
2300
|
+
/**
|
|
2301
|
+
* Prepares the Response before it is sent to the client.
|
|
2302
|
+
*
|
|
2303
|
+
* This method tweaks the Response to ensure that it is
|
|
2304
|
+
* compliant with RFC 2616. Most of the changes are based on
|
|
2305
|
+
* the Request that is "associated" with this Response.
|
|
2306
|
+
**/
|
|
2307
|
+
abstract prepare(request: IRequest): this;
|
|
2308
|
+
}
|
|
2309
|
+
//#endregion
|
|
2310
|
+
//#region src/Http/IResponse.d.ts
|
|
2311
|
+
/**
|
|
2312
|
+
* Interface for the Response contract, defining methods for handling HTTP responses.
|
|
2313
|
+
*/
|
|
2314
|
+
declare abstract class IResponse extends IHttpResponse {
|
|
2315
|
+
/**
|
|
2316
|
+
* The current app instance
|
|
2317
|
+
*/
|
|
2318
|
+
abstract app: IApplication;
|
|
2319
|
+
/**
|
|
2320
|
+
* The current Http Context
|
|
2321
|
+
*/
|
|
2322
|
+
abstract context: IHttpContext;
|
|
2323
|
+
/**
|
|
2324
|
+
* Sends content for the current web response.
|
|
2325
|
+
*/
|
|
2326
|
+
abstract sendContent(type?: 'html' | 'json' | 'text' | 'xml', parse?: boolean): IResponsable;
|
|
2327
|
+
/**
|
|
2328
|
+
* Sends content for the current web response.
|
|
2329
|
+
*/
|
|
2330
|
+
abstract send(type?: 'html' | 'json' | 'text' | 'xml'): IResponsable;
|
|
2331
|
+
/**
|
|
2332
|
+
* Use an edge view as content
|
|
2333
|
+
*
|
|
2334
|
+
* @param viewPath The path to the view file
|
|
2335
|
+
* @param send if set to true, the content will be returned, instead of the Response instance
|
|
2336
|
+
* @returns
|
|
2337
|
+
*/
|
|
2338
|
+
abstract view(viewPath: string, data?: Record<string, any> | undefined): Promise<this>;
|
|
2339
|
+
abstract view(viewPath: string, data: Record<string, any> | undefined, parse: boolean): Promise<IResponsable>;
|
|
2340
|
+
/**
|
|
2341
|
+
*
|
|
2342
|
+
* Parse content as edge view
|
|
2343
|
+
*
|
|
2344
|
+
* @param content The content to serve
|
|
2345
|
+
* @param send if set to true, the content will be returned, instead of the Response instance
|
|
2346
|
+
* @returns
|
|
2347
|
+
*/
|
|
2348
|
+
abstract viewTemplate(content: string, data?: Record<string, any> | undefined): Promise<this>;
|
|
2349
|
+
abstract viewTemplate(content: string, data: Record<string, any> | undefined, parse: boolean): Promise<IResponsable>;
|
|
2350
|
+
/**
|
|
2351
|
+
*
|
|
2352
|
+
* @param content The content to serve
|
|
2353
|
+
* @param send if set to true, the content will be returned, instead of the Response instance
|
|
2354
|
+
* @returns
|
|
2355
|
+
*/
|
|
2356
|
+
abstract html(content?: string): this;
|
|
2357
|
+
abstract html(content: string, parse: boolean): IResponsable;
|
|
2358
|
+
/**
|
|
2359
|
+
* Send a JSON response.
|
|
2360
|
+
*/
|
|
2361
|
+
abstract json<T = unknown>(data?: T): this;
|
|
2362
|
+
abstract json<T = unknown>(data: T, parse: boolean): T;
|
|
2363
|
+
/**
|
|
2364
|
+
* Send plain text.
|
|
2365
|
+
*/
|
|
2366
|
+
abstract text(content?: string): this;
|
|
2367
|
+
abstract text(content: string, parse: boolean): IResponsable;
|
|
2368
|
+
/**
|
|
2369
|
+
* Send plain xml.
|
|
2370
|
+
*/
|
|
2371
|
+
abstract xml(data?: string): this;
|
|
2372
|
+
abstract xml(data: string, parse: boolean): IResponsable;
|
|
2373
|
+
/**
|
|
2374
|
+
* Redirect to another URL.
|
|
2375
|
+
*/
|
|
2376
|
+
abstract redirect(location: string, status?: number, statusText?: string | undefined): this;
|
|
2377
|
+
/**
|
|
2378
|
+
* Dump the response.
|
|
2379
|
+
*/
|
|
2380
|
+
abstract dump(): this;
|
|
2381
|
+
/**
|
|
2382
|
+
* Get the base event
|
|
2383
|
+
*/
|
|
2384
|
+
abstract getEvent(): H3Event;
|
|
2385
|
+
abstract getEvent<K$1 extends DotNestedKeys$1<H3Event>>(key: K$1): DotNestedValue$1<H3Event, K$1>;
|
|
2386
|
+
}
|
|
2387
|
+
declare abstract class IResponsable extends HTTPResponse {
|
|
2388
|
+
abstract toResponse(request: IRequest): IResponse;
|
|
2389
|
+
abstract HTTPResponse(): HTTPResponse;
|
|
2390
|
+
}
|
|
2391
|
+
type ResponsableType<X = string> = IResponse | IResponsable | ConcreteConstructor<ClassConstructor> | string | X;
|
|
2392
|
+
//#endregion
|
|
2393
|
+
//#region src/Queue/Utils.d.ts
|
|
2394
|
+
interface JobPayload {
|
|
2395
|
+
maxTries?: number;
|
|
2396
|
+
maxExceptions?: number;
|
|
2397
|
+
failOnTimeout?: boolean;
|
|
2398
|
+
timeout?: number;
|
|
2399
|
+
retryUntil?: number;
|
|
2400
|
+
job: string;
|
|
2401
|
+
backoff?: number;
|
|
2402
|
+
delay?: number;
|
|
2403
|
+
data?: any;
|
|
2404
|
+
uuid?: string;
|
|
2405
|
+
}
|
|
2406
|
+
//#endregion
|
|
2407
|
+
//#region src/Events/IDispatcher.d.ts
|
|
2408
|
+
declare abstract class IDispatcher {
|
|
2409
|
+
/**
|
|
2410
|
+
* Register an event listener with the dispatcher.
|
|
2411
|
+
*
|
|
2412
|
+
* @param events
|
|
2413
|
+
* @param listener
|
|
2414
|
+
*/
|
|
2415
|
+
abstract listen(events: AppEvent | AppEvent[] | string | string[], listener?: AppListener | AppListener[] | string | string[]): void;
|
|
2416
|
+
/**
|
|
2417
|
+
* Determine if a given event has listeners.
|
|
2418
|
+
*
|
|
2419
|
+
* @param eventName
|
|
2420
|
+
* @return bool
|
|
2421
|
+
*/
|
|
2422
|
+
abstract hasListeners(eventName: string): any[];
|
|
2423
|
+
/**
|
|
2424
|
+
* Determine if the given event has any wildcard listeners.
|
|
2425
|
+
*
|
|
2426
|
+
* @param eventName
|
|
2427
|
+
*/
|
|
2428
|
+
abstract hasWildcardListeners(eventName: string): boolean;
|
|
2429
|
+
/**
|
|
2430
|
+
* Register an event and payload to be fired later.
|
|
2431
|
+
*
|
|
2432
|
+
* @para event
|
|
2433
|
+
* @param payload
|
|
2434
|
+
* @return void
|
|
2435
|
+
*/
|
|
2436
|
+
abstract push(event: string, payload?: Record<string, any> | any[]): void;
|
|
2437
|
+
/**
|
|
2438
|
+
* Flush a set of pushed events.
|
|
2439
|
+
*
|
|
2440
|
+
* @param event
|
|
2441
|
+
*/
|
|
2442
|
+
abstract flush(event: string): void;
|
|
2443
|
+
/**
|
|
2444
|
+
* Fire an event until the first non-null response is returned.
|
|
2445
|
+
*
|
|
2446
|
+
* @param event
|
|
2447
|
+
* @param mixed payload
|
|
2448
|
+
* @return mixed
|
|
2449
|
+
*/
|
|
2450
|
+
abstract until(event: AppEvent, payload?: JobPayload): void;
|
|
2451
|
+
/**
|
|
2452
|
+
* Fire an event and call the listeners.
|
|
2453
|
+
*
|
|
2454
|
+
* @param event
|
|
2455
|
+
* @param payload
|
|
2456
|
+
* @param halt
|
|
2457
|
+
*/
|
|
2458
|
+
abstract dispatch(event: Record<string, any> | string, payload?: Record<string, any> | any[], halt?: boolean): void;
|
|
2459
|
+
/**
|
|
2460
|
+
* Remove a set of listeners from the dispatcher.
|
|
2461
|
+
*
|
|
2462
|
+
* @param event
|
|
2463
|
+
*/
|
|
2464
|
+
abstract forget(event: string): void;
|
|
2465
|
+
/**
|
|
2466
|
+
* Forget all of the pushed listeners.
|
|
2467
|
+
*
|
|
2468
|
+
* @return void
|
|
2469
|
+
*/
|
|
2470
|
+
abstract forgetPushed(): void;
|
|
2471
|
+
/**
|
|
2472
|
+
* Set the queue resolver implementation.
|
|
2473
|
+
*
|
|
2474
|
+
* @param callable $resolver
|
|
2475
|
+
* @return this
|
|
2476
|
+
*/
|
|
2477
|
+
abstract setQueueResolver(resolver: (...a: any[]) => any): this;
|
|
2478
|
+
/**
|
|
2479
|
+
* Set the database transaction manager resolver implementation.
|
|
2480
|
+
*
|
|
2481
|
+
* @param resolver
|
|
2482
|
+
*/
|
|
2483
|
+
abstract setTransactionManagerResolver(resolver: (...a: any[]) => any): this;
|
|
2484
|
+
/**
|
|
2485
|
+
* Execute the given callback while deferring events, then dispatch all deferred events.
|
|
2486
|
+
*
|
|
2487
|
+
* @param callback
|
|
2488
|
+
* @param events
|
|
2489
|
+
*/
|
|
2490
|
+
abstract defer(callback: (...a: any[]) => any, events: AppEvent[]): any;
|
|
2491
|
+
/**
|
|
2492
|
+
* Gets the raw, unprepared listeners.
|
|
2493
|
+
*
|
|
2494
|
+
* @return array
|
|
2495
|
+
*/
|
|
2496
|
+
abstract getRawListeners(): Record<string, any[]>;
|
|
2497
|
+
}
|
|
2498
|
+
//#endregion
|
|
2499
|
+
//#region src/Routing/IAbstractRouteCollection.d.ts
|
|
2500
|
+
declare abstract class IAbstractRouteCollection {
|
|
2501
|
+
static verbs: RouteMethod[];
|
|
2502
|
+
abstract get(): IRoute[];
|
|
2503
|
+
abstract get(method: string): Record<string, IRoute>;
|
|
2504
|
+
abstract getRoutes(): IRoute[];
|
|
2505
|
+
}
|
|
2506
|
+
//#endregion
|
|
2507
|
+
//#region src/Routing/IRouteCollection.d.ts
|
|
2508
|
+
declare class IRouteCollection extends IAbstractRouteCollection {
|
|
2509
|
+
/**
|
|
2510
|
+
* Add a IRoute instance to the collection.
|
|
2511
|
+
*/
|
|
2512
|
+
add(route: IRoute): IRoute;
|
|
2513
|
+
/**
|
|
2514
|
+
* Refresh the name look-up table.
|
|
2515
|
+
*
|
|
2516
|
+
* This is done in case any names are fluently defined or if routes are overwritten.
|
|
2517
|
+
*/
|
|
2518
|
+
refreshNameLookups(): void;
|
|
2519
|
+
/**
|
|
2520
|
+
* Refresh the action look-up table.
|
|
2521
|
+
*
|
|
2522
|
+
* This is done in case any actions are overwritten with new controllers.
|
|
2523
|
+
*/
|
|
2524
|
+
refreshActionLookups(): void;
|
|
2525
|
+
/**
|
|
2526
|
+
* Find the first route matching a given request.
|
|
2527
|
+
*
|
|
2528
|
+
* May throw framework-specific exceptions (MethodNotAllowed / NotFound).
|
|
2529
|
+
*/
|
|
2530
|
+
match(request: IRequest): IRoute;
|
|
2531
|
+
/**
|
|
2532
|
+
*
|
|
2533
|
+
* Get routes from the collection by method.
|
|
2534
|
+
*
|
|
2535
|
+
* @param method
|
|
2536
|
+
*/
|
|
2537
|
+
get(): IRoute[];
|
|
2538
|
+
get(method: string): Record<string, IRoute>;
|
|
2539
|
+
/**
|
|
2540
|
+
* Determine if the route collection contains a given named route.
|
|
2541
|
+
*/
|
|
2542
|
+
hasNamedRoute(name: string): boolean;
|
|
2543
|
+
/**
|
|
2544
|
+
* Get a route instance by its name.
|
|
2545
|
+
*/
|
|
2546
|
+
getByName(name: string): IRoute | undefined;
|
|
2547
|
+
/**
|
|
2548
|
+
* Get a route instance by its controller action.
|
|
2549
|
+
*/
|
|
2550
|
+
getByAction(action: string): IRoute | undefined;
|
|
2551
|
+
/**
|
|
2552
|
+
* Get all of the routes in the collection.
|
|
2553
|
+
*/
|
|
2554
|
+
getRoutes(): IRoute[];
|
|
2555
|
+
/**
|
|
2556
|
+
* Get all of the routes keyed by their HTTP verb / method.
|
|
2557
|
+
*/
|
|
2558
|
+
getRoutesByMethod(): Record<string, Record<string, IRoute>>;
|
|
2559
|
+
/**
|
|
2560
|
+
* Get all of the routes keyed by their name.
|
|
2561
|
+
*/
|
|
2562
|
+
getRoutesByName(): Record<string, IRoute>;
|
|
2563
|
+
}
|
|
2564
|
+
//#endregion
|
|
2565
|
+
//#region src/Routing/IPendingResourceRegistration.d.ts
|
|
2566
|
+
declare abstract class IPendingResourceRegistration {
|
|
2567
|
+
/**
|
|
2568
|
+
* Set the methods the controller should apply to.
|
|
2569
|
+
*
|
|
2570
|
+
* @param methods
|
|
2571
|
+
*/
|
|
2572
|
+
abstract only(...methods: ResourceMethod[]): this;
|
|
2573
|
+
/**
|
|
2574
|
+
* Set the methods the controller should exclude.
|
|
2575
|
+
*
|
|
2576
|
+
* @param methods
|
|
2577
|
+
*/
|
|
2578
|
+
abstract except(...methods: ResourceMethod[]): this;
|
|
2579
|
+
/**
|
|
2580
|
+
* Set the route names for controller actions.
|
|
2581
|
+
*
|
|
2582
|
+
* @param names
|
|
2583
|
+
*/
|
|
2584
|
+
abstract names(names: Record<string, string>): this;
|
|
2585
|
+
/**
|
|
2586
|
+
* Set the route name for a controller action.
|
|
2587
|
+
*
|
|
2588
|
+
* @param method
|
|
2589
|
+
* @param name
|
|
2590
|
+
*/
|
|
2591
|
+
abstract setName(method: string, name: string): this;
|
|
2592
|
+
/**
|
|
2593
|
+
* Override the route parameter names.
|
|
2594
|
+
*
|
|
2595
|
+
* @param parameters
|
|
2596
|
+
*/
|
|
2597
|
+
abstract parameters(parameters: any): this;
|
|
2598
|
+
/**
|
|
2599
|
+
* Override a route parameter's name.
|
|
2600
|
+
*
|
|
2601
|
+
* @param previous
|
|
2602
|
+
* @param newValue
|
|
2603
|
+
*/
|
|
2604
|
+
abstract parameter(previous: string, newValue: any): this;
|
|
2605
|
+
/**
|
|
2606
|
+
* Add middleware to the resource routes.
|
|
2607
|
+
*
|
|
2608
|
+
* @param middleware
|
|
2609
|
+
*/
|
|
2610
|
+
abstract middleware(middleware: MiddlewareList | MiddlewareIdentifier): this;
|
|
2611
|
+
/**
|
|
2612
|
+
* Specify middleware that should be added to the specified resource routes.
|
|
2613
|
+
*
|
|
2614
|
+
* @param methods
|
|
2615
|
+
* @param middleware
|
|
2616
|
+
*/
|
|
2617
|
+
abstract middlewareFor(methods: ResourceMethod[], middleware: MiddlewareList | MiddlewareIdentifier): this;
|
|
2618
|
+
/**
|
|
2619
|
+
* Specify middleware that should be removed from the resource routes.
|
|
2620
|
+
*
|
|
2621
|
+
* @param middleware
|
|
2622
|
+
*/
|
|
2623
|
+
abstract withoutMiddleware(middleware: MiddlewareList | MiddlewareIdentifier): this;
|
|
2624
|
+
/**
|
|
2625
|
+
* Specify middleware that should be removed from the specified resource routes.
|
|
2626
|
+
*
|
|
2627
|
+
* @param methods
|
|
2628
|
+
* @param middleware
|
|
2629
|
+
*/
|
|
2630
|
+
abstract withoutMiddlewareFor(methods: ResourceMethod[], middleware: MiddlewareList | MiddlewareIdentifier): this;
|
|
2631
|
+
/**
|
|
2632
|
+
* Add "where" constraints to the resource routes.
|
|
2633
|
+
*
|
|
2634
|
+
* @param wheres
|
|
2635
|
+
*/
|
|
2636
|
+
abstract where(wheres: any): this;
|
|
2637
|
+
/**
|
|
2638
|
+
* Indicate that the resource routes should have "shallow" nesting.
|
|
2639
|
+
*
|
|
2640
|
+
* @param shallow
|
|
2641
|
+
*/
|
|
2642
|
+
abstract shallow(shallow?: boolean): this;
|
|
2643
|
+
/**
|
|
2644
|
+
* Define the callable that should be invoked on a missing model exception.
|
|
2645
|
+
*
|
|
2646
|
+
* @param callback
|
|
2647
|
+
*/
|
|
2648
|
+
abstract missing(callback: string): this;
|
|
2649
|
+
/**
|
|
2650
|
+
* Indicate that the resource routes should be scoped using the given binding fields.
|
|
2651
|
+
*
|
|
2652
|
+
* @param fields
|
|
2653
|
+
*/
|
|
2654
|
+
abstract scoped(fields?: string[]): this;
|
|
2655
|
+
/**
|
|
2656
|
+
* Define which routes should allow "trashed" models to be retrieved when resolving implicit model bindings.
|
|
2657
|
+
*
|
|
2658
|
+
* @param array methods
|
|
2659
|
+
*/
|
|
2660
|
+
abstract withTrashed(methods?: never[]): this;
|
|
2661
|
+
/**
|
|
2662
|
+
* Register the singleton resource route.
|
|
2663
|
+
*/
|
|
2664
|
+
abstract register(): IRouteCollection | undefined;
|
|
2665
|
+
}
|
|
2666
|
+
//#endregion
|
|
2667
|
+
//#region src/Routing/IPendingSingletonResourceRegistration.d.ts
|
|
2668
|
+
declare abstract class IPendingSingletonResourceRegistration {
|
|
2669
|
+
/**
|
|
2670
|
+
* Set the methods the controller should apply to.
|
|
2671
|
+
*
|
|
2672
|
+
* @param methods
|
|
2673
|
+
*/
|
|
2674
|
+
abstract only(...methods: ResourceMethod[]): this;
|
|
2675
|
+
/**
|
|
2676
|
+
* Set the methods the controller should exclude.
|
|
2677
|
+
*
|
|
2678
|
+
* @param methods
|
|
2679
|
+
*/
|
|
2680
|
+
abstract except(...methods: ResourceMethod[]): this;
|
|
2681
|
+
/**
|
|
2682
|
+
* Indicate that the resource should have creation and storage routes.
|
|
2683
|
+
*
|
|
2684
|
+
* @return this
|
|
2685
|
+
*/
|
|
2686
|
+
abstract creatable(): this;
|
|
2687
|
+
/**
|
|
2688
|
+
* Indicate that the resource should have a deletion route.
|
|
2689
|
+
*
|
|
2690
|
+
* @return this
|
|
2691
|
+
*/
|
|
2692
|
+
abstract destroyable(): this;
|
|
2693
|
+
/**
|
|
2694
|
+
* Set the route names for controller actions.
|
|
2695
|
+
*
|
|
2696
|
+
* @param names
|
|
2697
|
+
*/
|
|
2698
|
+
abstract names(names: Record<string, string>): this;
|
|
2699
|
+
/**
|
|
2700
|
+
* Set the route name for a controller action.
|
|
2701
|
+
*
|
|
2702
|
+
* @param method
|
|
2703
|
+
* @param name
|
|
2704
|
+
*/
|
|
2705
|
+
abstract setName(method: string, name: string): this;
|
|
2706
|
+
/**
|
|
2707
|
+
* Override the route parameter names.
|
|
2708
|
+
*
|
|
2709
|
+
* @param parameters
|
|
2710
|
+
*/
|
|
2711
|
+
abstract parameters(parameters: any): this;
|
|
2712
|
+
/**
|
|
2713
|
+
* Override a route parameter's name.
|
|
2714
|
+
*
|
|
2715
|
+
* @param previous
|
|
2716
|
+
* @param newValue
|
|
2717
|
+
*/
|
|
2718
|
+
abstract parameter(previous: string, newValue: any): this;
|
|
2719
|
+
/**
|
|
2720
|
+
* Add middleware to the resource routes.
|
|
2721
|
+
*
|
|
2722
|
+
* @param middleware
|
|
2723
|
+
*/
|
|
2724
|
+
abstract middleware(middleware: MiddlewareList | MiddlewareIdentifier): this;
|
|
2725
|
+
/**
|
|
2726
|
+
* Specify middleware that should be added to the specified resource routes.
|
|
2727
|
+
*
|
|
2728
|
+
* @param methods
|
|
2729
|
+
* @param middleware
|
|
2730
|
+
*/
|
|
2731
|
+
abstract middlewareFor(methods: ResourceMethod[], middleware: MiddlewareList | MiddlewareIdentifier): this;
|
|
2732
|
+
/**
|
|
2733
|
+
* Specify middleware that should be removed from the resource routes.
|
|
2734
|
+
*
|
|
2735
|
+
* @param middleware
|
|
2736
|
+
*/
|
|
2737
|
+
abstract withoutMiddleware(middleware: MiddlewareList | MiddlewareIdentifier): this;
|
|
2738
|
+
/**
|
|
2739
|
+
* Specify middleware that should be removed from the specified resource routes.
|
|
2740
|
+
*
|
|
2741
|
+
* @param methods
|
|
2742
|
+
* @param middleware
|
|
2743
|
+
*/
|
|
2744
|
+
abstract withoutMiddlewareFor(methods: ResourceMethod[], middleware: MiddlewareList | MiddlewareIdentifier): this;
|
|
2745
|
+
/**
|
|
2746
|
+
* Add "where" constraints to the resource routes.
|
|
2747
|
+
*
|
|
2748
|
+
* @param wheres
|
|
2749
|
+
*/
|
|
2750
|
+
abstract where(wheres: any): this;
|
|
2751
|
+
/**
|
|
2752
|
+
* Register the singleton resource route.
|
|
2753
|
+
*/
|
|
2754
|
+
abstract register(): IAbstractRouteCollection | undefined;
|
|
2755
|
+
}
|
|
2756
|
+
//#endregion
|
|
2757
|
+
//#region src/Routing/IRouter.d.ts
|
|
2758
|
+
/**
|
|
2759
|
+
* Interface for the Router contract, defining methods for HTTP routing.
|
|
2760
|
+
*/
|
|
2761
|
+
declare abstract class IRouter {
|
|
2762
|
+
/**
|
|
2763
|
+
* The priority-sorted list of middleware.
|
|
2764
|
+
*
|
|
2765
|
+
* Forces the listed middleware to always be in the given order.
|
|
2766
|
+
*/
|
|
2767
|
+
abstract middlewarePriority: MiddlewareList;
|
|
2768
|
+
/**
|
|
2769
|
+
* All of the verbs supported by the router.
|
|
2770
|
+
*/
|
|
2771
|
+
static verbs: RouteMethod[];
|
|
2772
|
+
/**
|
|
2773
|
+
* Get the currently dispatched route instance.
|
|
2774
|
+
*/
|
|
2775
|
+
abstract getCurrentRoute(): IRoute | undefined;
|
|
2776
|
+
/**
|
|
2777
|
+
* Check if a route with the given name exists.
|
|
2778
|
+
*
|
|
2779
|
+
* @param name
|
|
2780
|
+
*/
|
|
2781
|
+
abstract has(...name: string[]): boolean;
|
|
2782
|
+
/**
|
|
2783
|
+
* Get the current route name.
|
|
2784
|
+
*/
|
|
2785
|
+
abstract currentRouteName(): string | undefined;
|
|
2786
|
+
/**
|
|
2787
|
+
* Alias for the "currentRouteNamed" method.
|
|
2788
|
+
*
|
|
2789
|
+
* @param patterns
|
|
2790
|
+
*/
|
|
2791
|
+
abstract is(...patterns: string[]): boolean;
|
|
2792
|
+
/**
|
|
2793
|
+
* Determine if the current route matches a pattern.
|
|
2794
|
+
*
|
|
2795
|
+
* @param patterns
|
|
2796
|
+
*/
|
|
2797
|
+
abstract currentRouteNamed(...patterns: string[]): boolean;
|
|
2798
|
+
/**
|
|
2799
|
+
* Get the underlying route collection.
|
|
2800
|
+
*/
|
|
2801
|
+
abstract getRoutes(): IRouteCollection;
|
|
2802
|
+
/**
|
|
2803
|
+
* Create a new IRoute object.
|
|
2804
|
+
*
|
|
2805
|
+
* @param methods
|
|
2806
|
+
* @param uri
|
|
2807
|
+
* @param action
|
|
2808
|
+
*/
|
|
2809
|
+
abstract newRoute(methods: RouteMethod | RouteMethod[], uri: string, action: ActionInput): IRoute;
|
|
2810
|
+
/**
|
|
2811
|
+
* Dispatch the request to the application.
|
|
2812
|
+
*
|
|
2813
|
+
* @param request
|
|
2814
|
+
*/
|
|
2815
|
+
abstract dispatch(request: IRequest): Promise<IResponse>;
|
|
2816
|
+
/**
|
|
2817
|
+
* Dispatch the request to a route and return the response.
|
|
2818
|
+
*
|
|
2819
|
+
* @param request
|
|
2820
|
+
*/
|
|
2821
|
+
abstract dispatchToRoute(request: IRequest): Promise<IResponse>;
|
|
2822
|
+
/**
|
|
2823
|
+
* Registers a route that responds to HTTP GET requests.
|
|
2824
|
+
*
|
|
2825
|
+
* @param uri - The route uri.
|
|
2826
|
+
* @param action - The handler function or [controller class, method] array.
|
|
2827
|
+
* @returns
|
|
2828
|
+
*/
|
|
2829
|
+
abstract get<C extends typeof IController>(uri: string, action: ActionInput<C>): IRoute;
|
|
2830
|
+
/**
|
|
2831
|
+
* Registers a route that responds to HTTP POST requests.
|
|
2832
|
+
*
|
|
2833
|
+
* @param uri - The route uri.
|
|
2834
|
+
* @param action - The handler function or [controller class, method] array.
|
|
2835
|
+
* @returns
|
|
2836
|
+
*/
|
|
2837
|
+
abstract post<C extends typeof IController>(uri: string, action: ActionInput<C>): IRoute;
|
|
2838
|
+
/**
|
|
2839
|
+
* Registers a route that responds to HTTP PUT requests.
|
|
2840
|
+
*
|
|
2841
|
+
* @param uri - The route uri.
|
|
2842
|
+
* @param action - The handler function or [controller class, method] array.
|
|
2843
|
+
* @returns
|
|
2844
|
+
*/
|
|
2845
|
+
abstract put<C extends typeof IController>(uri: string, action: ActionInput<C>): IRoute;
|
|
2846
|
+
/**
|
|
2847
|
+
* Registers a route that responds to HTTP PATCH requests.
|
|
2848
|
+
*
|
|
2849
|
+
* @param uri - The route uri.
|
|
2850
|
+
* @param action - The handler function or [controller class, method] array.
|
|
2851
|
+
* @returns
|
|
2852
|
+
*/
|
|
2853
|
+
abstract patch<C extends typeof IController>(uri: string, action: ActionInput<C>): IRoute;
|
|
2854
|
+
/**
|
|
2855
|
+
* Registers a route that responds to HTTP DELETE requests.
|
|
2856
|
+
*
|
|
2857
|
+
* @param uri - The route uri.
|
|
2858
|
+
* @param action - The handler function or [controller class, method] array.
|
|
2859
|
+
* @returns
|
|
2860
|
+
*/
|
|
2861
|
+
abstract delete<C extends typeof IController>(uri: string, action: ActionInput<C>): IRoute;
|
|
2862
|
+
/**
|
|
2863
|
+
* Registers a route the matches the provided methods.
|
|
2864
|
+
*
|
|
2865
|
+
* @param methods - The route methods to match.
|
|
2866
|
+
* @param uri - The route uri.
|
|
2867
|
+
* @param action - The handler function or [controller class, method] array.
|
|
2868
|
+
*/
|
|
2869
|
+
abstract match<C extends typeof IController>(methods: RouteMethod | RouteMethod[], uri: string, action: ActionInput<C>): IRoute;
|
|
2870
|
+
/**
|
|
2871
|
+
* Route a resource to a controller.
|
|
2872
|
+
*
|
|
2873
|
+
* @param name
|
|
2874
|
+
* @param controller
|
|
2875
|
+
* @param options
|
|
2876
|
+
*/
|
|
2877
|
+
abstract resource<C extends typeof IController>(name: string, controller: C, options: ResourceOptions): IPendingResourceRegistration;
|
|
2878
|
+
/**
|
|
2879
|
+
* Register an array of API resource controllers.
|
|
2880
|
+
*
|
|
2881
|
+
* @param resources
|
|
2882
|
+
* @param options
|
|
2883
|
+
*/
|
|
2884
|
+
abstract apiResources(resources: GenericObject<typeof IController>, options: ResourceOptions): void;
|
|
2885
|
+
/**
|
|
2886
|
+
* API Resource support
|
|
2887
|
+
*
|
|
2888
|
+
* @param path
|
|
2889
|
+
* @param controller
|
|
2890
|
+
*/
|
|
2891
|
+
abstract apiResource<C extends typeof IController>(name: string, controller: C, options: ResourceOptions): IPendingResourceRegistration;
|
|
2892
|
+
/**
|
|
2893
|
+
* Register an array of singleton resource controllers.
|
|
2894
|
+
*
|
|
2895
|
+
* @param singletons
|
|
2896
|
+
* @param options
|
|
2897
|
+
*/
|
|
2898
|
+
abstract singletons(singletons: GenericObject<typeof IController>, options: ResourceOptions): void;
|
|
2899
|
+
/**
|
|
2900
|
+
* Route a singleton resource to a controller.
|
|
2901
|
+
*
|
|
2902
|
+
* @param name
|
|
2903
|
+
* @param controller
|
|
2904
|
+
* @param options
|
|
2905
|
+
*/
|
|
2906
|
+
abstract singleton<C extends typeof IController>(name: string, controller: C, options: ResourceOptions): IPendingSingletonResourceRegistration;
|
|
2907
|
+
/**
|
|
2908
|
+
* Register an array of API singleton resource controllers.
|
|
2909
|
+
*
|
|
2910
|
+
* @param singletons
|
|
2911
|
+
* @param options
|
|
2912
|
+
*/
|
|
2913
|
+
abstract apiSingletons(singletons: GenericObject<typeof IController>, options: ResourceOptions): void;
|
|
2914
|
+
/**
|
|
2915
|
+
* Route an API singleton resource to a controller.
|
|
2916
|
+
*
|
|
2917
|
+
* @param name
|
|
2918
|
+
* @param controller
|
|
2919
|
+
* @param options
|
|
2920
|
+
*/
|
|
2921
|
+
abstract apiSingleton<C extends typeof IController>(name: string, controller: C, options: ResourceOptions): IPendingSingletonResourceRegistration;
|
|
2922
|
+
/**
|
|
2923
|
+
* Grouping
|
|
2924
|
+
*
|
|
2925
|
+
* @param options
|
|
2926
|
+
* @param callback
|
|
2927
|
+
*/
|
|
2928
|
+
/**
|
|
2929
|
+
* Create a route group with shared attributes.
|
|
2930
|
+
*
|
|
2931
|
+
* @param attributes
|
|
2932
|
+
* @param routes
|
|
2933
|
+
*/
|
|
2934
|
+
abstract group<C extends ((_e: this) => void) | string>(attributes: RouteActions, routes: C | C[]): this;
|
|
2935
|
+
/**
|
|
2936
|
+
* Merge the given array with the last group stack.
|
|
2937
|
+
*
|
|
2938
|
+
* @param newItems
|
|
2939
|
+
* @param prependExistingPrefix
|
|
2940
|
+
*/
|
|
2941
|
+
abstract mergeWithLastGroup(newItems: RouteActions, prependExistingPrefix?: boolean): RouteActions;
|
|
2942
|
+
/**
|
|
2943
|
+
* Get the prefix from the last group on the stack.
|
|
2944
|
+
*/
|
|
2945
|
+
abstract getLastGroupPrefix(): any;
|
|
2946
|
+
/**
|
|
2947
|
+
* Determine if the router currently has a group stack.
|
|
2948
|
+
*/
|
|
2949
|
+
abstract hasGroupStack(): boolean;
|
|
2950
|
+
/**
|
|
2951
|
+
* Set the name of the current route
|
|
2952
|
+
*
|
|
2953
|
+
* @param name
|
|
2954
|
+
*/
|
|
2955
|
+
abstract name(name: string): this;
|
|
2956
|
+
/**
|
|
2957
|
+
* Registers middleware for a specific path.
|
|
2958
|
+
* @param path - The path to apply the middleware.
|
|
2959
|
+
* @param handler - The middleware handler.
|
|
2960
|
+
* @param opts - Optional middleware options.
|
|
2961
|
+
*/
|
|
2962
|
+
abstract h3middleware(path: string | IMiddleware[] | Middleware, handler?: Middleware | MiddlewareOptions, opts?: MiddlewareOptions): this;
|
|
2963
|
+
/**
|
|
2964
|
+
* Get all of the defined middleware short-hand names.
|
|
2965
|
+
*/
|
|
2966
|
+
abstract getMiddleware(): GenericObject;
|
|
2967
|
+
/**
|
|
2968
|
+
* Register a short-hand name for a middleware.
|
|
2969
|
+
*
|
|
2970
|
+
* @param name
|
|
2971
|
+
* @param class
|
|
2972
|
+
*/
|
|
2973
|
+
abstract aliasMiddleware(name: string, cls: IMiddleware): this;
|
|
2974
|
+
/**
|
|
2975
|
+
* Gather the middleware for the given route with resolved class names.
|
|
2976
|
+
*
|
|
2977
|
+
* @param route
|
|
2978
|
+
*/
|
|
2979
|
+
abstract gatherRouteMiddleware(route: IRoute): any;
|
|
2980
|
+
/**
|
|
2981
|
+
* Resolve a flat array of middleware classes from the provided array.
|
|
2982
|
+
*
|
|
2983
|
+
* @param middleware
|
|
2984
|
+
* @param excluded
|
|
2985
|
+
*/
|
|
2986
|
+
abstract resolveMiddleware(middleware: MiddlewareList, excluded: MiddlewareList): any;
|
|
2987
|
+
/**
|
|
2988
|
+
* Register a group of middleware.
|
|
2989
|
+
*
|
|
2990
|
+
* @param name
|
|
2991
|
+
* @param middleware
|
|
2992
|
+
*/
|
|
2993
|
+
abstract middlewareGroup(name: string, middleware: MiddlewareList): this;
|
|
2994
|
+
/**
|
|
2995
|
+
* Register a group of middleware.
|
|
2996
|
+
*
|
|
2997
|
+
* @param name
|
|
2998
|
+
* @param middleware
|
|
2999
|
+
*/
|
|
3000
|
+
abstract middlewareGroup(name: string, middleware: MiddlewareList): this;
|
|
3001
|
+
/**
|
|
3002
|
+
* Create a response instance from the given value.
|
|
3003
|
+
*
|
|
3004
|
+
* @param request
|
|
3005
|
+
* @param response
|
|
3006
|
+
*/
|
|
3007
|
+
abstract prepareResponse(request: IRequest, response: ResponsableType): Promise<IResponse>;
|
|
3008
|
+
/**
|
|
3009
|
+
* Substitute the route bindings onto the route.
|
|
3010
|
+
*
|
|
3011
|
+
* @param route
|
|
3012
|
+
*
|
|
3013
|
+
* @throws {ModelNotFoundException<IModel>}
|
|
3014
|
+
*/
|
|
3015
|
+
abstract substituteBindings(route: IRoute): Promise<IRoute>;
|
|
3016
|
+
/**
|
|
3017
|
+
* Substitute the implicit route bindings for the given route.
|
|
3018
|
+
*
|
|
3019
|
+
* @param route
|
|
3020
|
+
*
|
|
3021
|
+
* @throws {ModelNotFoundException<IModel>}
|
|
3022
|
+
*/
|
|
3023
|
+
abstract substituteImplicitBindings(route: IRoute): Promise<any | undefined>;
|
|
3024
|
+
/**
|
|
3025
|
+
* Register a callback to run after implicit bindings are substituted.
|
|
3026
|
+
*
|
|
3027
|
+
* @param callback
|
|
3028
|
+
*/
|
|
3029
|
+
abstract substituteImplicitBindingsUsing(callback: CallableConstructor): this;
|
|
3030
|
+
}
|
|
3031
|
+
//#endregion
|
|
3032
|
+
//#region src/Utilities/PathLoader.d.ts
|
|
3033
|
+
declare class PathLoader {
|
|
3034
|
+
/**
|
|
3035
|
+
* Dynamically retrieves a path property from the class.
|
|
3036
|
+
* Any property ending with "Path" is accessible automatically.
|
|
3037
|
+
*
|
|
3038
|
+
* @param name - The base name of the path property
|
|
3039
|
+
* @param prefix - The base path to prefix to the path
|
|
3040
|
+
* @returns
|
|
3041
|
+
*/
|
|
3042
|
+
getPath(name: IPathName, prefix?: string): string;
|
|
3043
|
+
/**
|
|
3044
|
+
* Programatically set the paths.
|
|
3045
|
+
*
|
|
3046
|
+
* @param name - The base name of the path property
|
|
3047
|
+
* @param path - The new path
|
|
3048
|
+
* @param base - The base path to include to the path
|
|
3049
|
+
*/
|
|
3050
|
+
setPath(name: IPathName, path: string, base?: string): void;
|
|
3051
|
+
}
|
|
3052
|
+
//#endregion
|
|
3053
|
+
//#region src/Utilities/BindingsContract.d.ts
|
|
3054
|
+
type RemoveIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K] };
|
|
3055
|
+
type Bindings = {
|
|
3056
|
+
[key: string]: any;
|
|
3057
|
+
[key: `app.${string}`]: any;
|
|
3058
|
+
[key: `middleware.${string}`]: any;
|
|
3059
|
+
db: any;
|
|
3060
|
+
env(): NodeJS.ProcessEnv;
|
|
3061
|
+
env<T extends string>(key: T, def?: any): any;
|
|
3062
|
+
view(viewPath: string, params?: Record<string, any>): Promise<IResponsable>;
|
|
3063
|
+
edge: Edge;
|
|
3064
|
+
asset(key: string, def?: string): string;
|
|
3065
|
+
router: IRouter;
|
|
3066
|
+
events: IDispatcher;
|
|
3067
|
+
config: {
|
|
3068
|
+
get<X extends Record<string, any>>(): X;
|
|
3069
|
+
get<X extends Record<string, any>, T extends Extract<keyof X, string>>(key: T, def?: any): X[T];
|
|
3070
|
+
set<T extends string>(key: T, value: any): void;
|
|
3071
|
+
load?(): any;
|
|
3072
|
+
};
|
|
3073
|
+
'app.events': IDispatcher;
|
|
3074
|
+
'http.app': H3;
|
|
3075
|
+
'path.base': string;
|
|
3076
|
+
'load.paths': PathLoader;
|
|
3077
|
+
'http.serve': typeof serve;
|
|
3078
|
+
'http.context': IHttpContext;
|
|
3079
|
+
'http.request': IRequest;
|
|
3080
|
+
'http.response': IResponse;
|
|
3081
|
+
};
|
|
3082
|
+
type UseKey<X extends Record<string, any> = Record<string, any>> = keyof RemoveIndexSignature<Bindings & X>;
|
|
3083
|
+
type IBinding = UseKey | (new (...args: any[]) => unknown);
|
|
3084
|
+
//#endregion
|
|
3085
|
+
//#region src/Routing/IMiddlewareHandler.d.ts
|
|
3086
|
+
declare class IMiddlewareHandler {
|
|
3087
|
+
/**
|
|
3088
|
+
* Registers a middleware instance.
|
|
3089
|
+
*
|
|
3090
|
+
* @param mw
|
|
3091
|
+
*/
|
|
3092
|
+
register(mw: IMiddleware | IMiddleware[]): this;
|
|
3093
|
+
/**
|
|
3094
|
+
* Runs the middleware chain for a given HttpContext.
|
|
3095
|
+
* Each middleware must call next() to continue the chain.
|
|
3096
|
+
*
|
|
3097
|
+
* @param context - The current HttpContext.
|
|
3098
|
+
* @param next - Callback to execute when middleware completes.
|
|
3099
|
+
* @returns A promise resolving to the final handler's result.
|
|
3100
|
+
*/
|
|
3101
|
+
run(context: IHttpContext, next: (ctx: IHttpContext) => Promise<any>): Promise<any>;
|
|
3102
|
+
}
|
|
3103
|
+
//#endregion
|
|
3104
|
+
//#region src/Core/IContainer.d.ts
|
|
3105
|
+
/**
|
|
3106
|
+
* Interface for the Container contract, defining methods for dependency injection and service resolution.
|
|
3107
|
+
*/
|
|
3108
|
+
declare abstract class IContainer {
|
|
3109
|
+
abstract middlewareHandler?: IMiddlewareHandler;
|
|
3110
|
+
/**
|
|
3111
|
+
* Check if the target has any decorators
|
|
3112
|
+
*
|
|
3113
|
+
* @param target
|
|
3114
|
+
* @returns
|
|
3115
|
+
*/
|
|
3116
|
+
static hasAnyDecorator<C extends abstract new (...args: any[]) => any>(target: C): boolean;
|
|
3117
|
+
/**
|
|
3118
|
+
* Bind a transient service to the container
|
|
3119
|
+
*
|
|
3120
|
+
* @param key
|
|
3121
|
+
* @param factory
|
|
3122
|
+
*/
|
|
3123
|
+
abstract bind<T>(key: new (...args: any[]) => T, factory: () => T): void;
|
|
3124
|
+
abstract bind<T extends UseKey>(key: T, factory: () => Bindings[T]): void;
|
|
3125
|
+
/**
|
|
3126
|
+
* Bind unregistered middlewares to the service container so we can use them later
|
|
3127
|
+
*
|
|
3128
|
+
* @param key
|
|
3129
|
+
* @param middleware
|
|
3130
|
+
*/
|
|
3131
|
+
abstract bindMiddleware(key: IMiddleware | string, middleware: ConcreteConstructor<IMiddleware>): void;
|
|
3132
|
+
/**
|
|
3133
|
+
* Get all bound and unregistered middlewares in the service container
|
|
3134
|
+
*
|
|
3135
|
+
* @param key
|
|
3136
|
+
* @param middleware
|
|
3137
|
+
*/
|
|
3138
|
+
abstract boundMiddlewares(): MapIterator<[string | IMiddleware, IMiddleware]>;
|
|
3139
|
+
abstract boundMiddlewares(key: IMiddleware | string): IMiddleware;
|
|
3140
|
+
/**
|
|
3141
|
+
* Remove one or more transient services from the container
|
|
3142
|
+
*
|
|
3143
|
+
* @param key
|
|
3144
|
+
*/
|
|
3145
|
+
abstract unbind<T extends UseKey>(key: T | T[]): void;
|
|
3146
|
+
/**
|
|
3147
|
+
* Bind a singleton service to the container
|
|
3148
|
+
*
|
|
3149
|
+
* @param key
|
|
3150
|
+
* @param factory
|
|
3151
|
+
*/
|
|
3152
|
+
abstract singleton<T extends UseKey>(key: T | (new (...args: any[]) => Bindings[T]), factory: (app: this) => Bindings[T]): void;
|
|
3153
|
+
abstract singleton<T extends UseKey>(key: T | (abstract new (...args: any[]) => Bindings[T]), factory: (app: this) => Bindings[T]): void;
|
|
3154
|
+
abstract singleton<T extends UseKey>(key: T | (new (...args: any[]) => Bindings[T]), factory: abstract new (...args: any[]) => any): void;
|
|
3155
|
+
abstract singleton<T extends UseKey>(key: T | (abstract new (...args: any[]) => Bindings[T]), factory: abstract new (...args: any[]) => any): void;
|
|
3156
|
+
/**
|
|
3157
|
+
* Read reflected param types, resolve dependencies from the container and
|
|
3158
|
+
* optionally transform them, finally invoke the specified method on a class instance
|
|
3159
|
+
*
|
|
3160
|
+
* @param instance
|
|
3161
|
+
* @param method
|
|
3162
|
+
* @param defaultArgs
|
|
3163
|
+
* @param handler
|
|
3164
|
+
* @returns
|
|
3165
|
+
*/
|
|
3166
|
+
abstract invoke<X extends InstanceType<ClassConstructor>, M extends ExtractClassMethods<X>>(instance: X, method: M, defaultArgs?: any[], handler?: CallableConstructor): Promise<any>;
|
|
3167
|
+
/**
|
|
3168
|
+
* Resolve a service from the container
|
|
3169
|
+
*
|
|
3170
|
+
* @param key
|
|
3171
|
+
*/
|
|
3172
|
+
abstract make<T extends UseKey>(key: T): Bindings[T];
|
|
3173
|
+
abstract make<C extends abstract new (...args: any[]) => any>(key: C): InstanceType<C>;
|
|
3174
|
+
abstract make<F extends (...args: any[]) => any>(key: F): ReturnType<F>;
|
|
3175
|
+
/**
|
|
3176
|
+
* Register a callback to be executed after a service is resolved
|
|
3177
|
+
*
|
|
3178
|
+
* @param key
|
|
3179
|
+
* @param callback
|
|
3180
|
+
*/
|
|
3181
|
+
abstract afterResolving<T extends UseKey>(key: T, callback: (resolved: Bindings[T], app: this) => void): void;
|
|
3182
|
+
abstract afterResolving<T extends abstract new (...args: any[]) => any>(key: T, callback: (resolved: InstanceType<T>, app: this) => void): void;
|
|
3183
|
+
/**
|
|
3184
|
+
* Register a new before resolving callback for all types.
|
|
3185
|
+
*
|
|
3186
|
+
* @param key
|
|
3187
|
+
* @param callback
|
|
3188
|
+
*/
|
|
3189
|
+
abstract beforeResolving<T extends UseKey>(key: T, callback: (app: this) => void): void;
|
|
3190
|
+
abstract beforeResolving<T extends abstract new (...args: any[]) => any>(key: T, callback: (app: this) => void): void;
|
|
3191
|
+
/**
|
|
3192
|
+
* Determine if a given string is an alias.
|
|
3193
|
+
*
|
|
3194
|
+
* @param name
|
|
3195
|
+
*/
|
|
3196
|
+
abstract isAlias(name: IBinding): boolean;
|
|
3197
|
+
/**
|
|
3198
|
+
* Get the alias for an abstract if available.
|
|
3199
|
+
*
|
|
3200
|
+
* @param abstract
|
|
3201
|
+
*/
|
|
3202
|
+
abstract getAlias(abstract: any): any;
|
|
3203
|
+
/**
|
|
3204
|
+
* Set the alias for an abstract.
|
|
3205
|
+
*
|
|
3206
|
+
* @param token
|
|
3207
|
+
* @param target
|
|
3208
|
+
*/
|
|
3209
|
+
abstract alias(key: [string | ClassConstructor, any][]): this;
|
|
3210
|
+
abstract alias(key: string | ClassConstructor, target: any): this;
|
|
3211
|
+
/**
|
|
3212
|
+
* Determine if the given abstract type has been bound.
|
|
3213
|
+
*
|
|
3214
|
+
* @param string $abstract
|
|
3215
|
+
* @returns
|
|
3216
|
+
*/
|
|
3217
|
+
abstract bound<T extends UseKey>(abstract: T): boolean;
|
|
3218
|
+
abstract bound<C extends abstract new (...args: any[]) => any>(abstract: C): boolean;
|
|
3219
|
+
abstract bound<F extends (...args: any[]) => any>(abstract: F): boolean;
|
|
3220
|
+
/**
|
|
3221
|
+
* Check if a service is registered
|
|
3222
|
+
*
|
|
3223
|
+
* @param key
|
|
3224
|
+
* @returns
|
|
3225
|
+
*/
|
|
3226
|
+
abstract has<T extends UseKey>(key: T): boolean;
|
|
3227
|
+
abstract has<C extends abstract new (...args: any[]) => any>(key: C): boolean;
|
|
3228
|
+
abstract has<F extends (...args: any[]) => any>(key: F): boolean;
|
|
3229
|
+
/**
|
|
3230
|
+
* Determine if the given abstract type has been resolved.
|
|
3231
|
+
*
|
|
3232
|
+
* @param abstract
|
|
3233
|
+
*/
|
|
3234
|
+
abstract resolved(abstract: IBinding | string): boolean;
|
|
3235
|
+
/**
|
|
3236
|
+
* Register an existing instance as shared in the container.
|
|
3237
|
+
*
|
|
3238
|
+
* @param abstract
|
|
3239
|
+
* @param instance
|
|
3240
|
+
*/
|
|
3241
|
+
abstract instance<X = any>(key: string, instance: X): X;
|
|
3242
|
+
abstract instance<K$1 extends abstract new (...args: any[]) => any, X = any>(abstract: K$1, instance: X): X;
|
|
3243
|
+
/**
|
|
3244
|
+
* Call the given method and inject its dependencies.
|
|
3245
|
+
*
|
|
3246
|
+
* @param callback
|
|
3247
|
+
*/
|
|
3248
|
+
abstract call<C extends abstract new (...args: any[]) => any>(callback: C): void | Promise<void>;
|
|
3249
|
+
abstract call<F extends (...args: any[]) => any>(callback: F): void | Promise<void>;
|
|
3250
|
+
}
|
|
3251
|
+
//#endregion
|
|
3252
|
+
//#region src/Core/IApplication.d.ts
|
|
3253
|
+
declare abstract class IApplication extends IContainer {
|
|
3254
|
+
abstract paths: PathLoader;
|
|
3255
|
+
context?: (event: H3Event) => Promise<IHttpContext>;
|
|
3256
|
+
h3Event?: H3Event;
|
|
3257
|
+
/**
|
|
3258
|
+
* List of registered console commands
|
|
3259
|
+
*/
|
|
3260
|
+
abstract registeredCommands: (new (app: any, kernel: any) => any)[];
|
|
3261
|
+
/**
|
|
3262
|
+
* Get all registered providers
|
|
3263
|
+
*/
|
|
3264
|
+
abstract getRegisteredProviders(): IServiceProvider[];
|
|
3265
|
+
/**
|
|
3266
|
+
* Configure and Dynamically register all configured service providers, then boot the app.
|
|
3267
|
+
*
|
|
3268
|
+
* @param providers All regitererable service providers
|
|
3269
|
+
* @param filtered A list of service provider name strings we do not want to register at all cost
|
|
3270
|
+
* @param autoRegisterProviders If set to false, service providers will not be auto discovered and registered.
|
|
3271
|
+
*
|
|
3272
|
+
* @returns
|
|
3273
|
+
*/
|
|
3274
|
+
abstract initialize(providers: Array<ConcreteConstructor<IServiceProvider, false>>, filtered?: string[], autoRegisterProviders?: boolean): this;
|
|
3275
|
+
/**
|
|
3276
|
+
* Dynamically register all configured providers
|
|
3277
|
+
*
|
|
3278
|
+
* @param autoRegister If set to false, service providers will not be auto discovered and registered.
|
|
3279
|
+
*/
|
|
3280
|
+
abstract registerConfiguredProviders(autoRegister?: boolean): Promise<void>;
|
|
3281
|
+
/**
|
|
3282
|
+
* Register service providers
|
|
3283
|
+
*
|
|
3284
|
+
* @param providers
|
|
3285
|
+
* @param filtered
|
|
3286
|
+
*/
|
|
3287
|
+
abstract registerProviders(providers: Array<ConcreteConstructor<IServiceProvider, false>>, filtered?: string[]): void;
|
|
3288
|
+
/**
|
|
3289
|
+
* Register a provider
|
|
3290
|
+
*/
|
|
3291
|
+
abstract register(provider: IServiceProvider): Promise<void>;
|
|
3292
|
+
/**
|
|
3293
|
+
* Register the listed service providers.
|
|
3294
|
+
*
|
|
3295
|
+
* @param commands An array of console commands to register.
|
|
3296
|
+
*/
|
|
3297
|
+
abstract withCommands(commands: (new (app: any, kernel: any) => any)[]): this;
|
|
3298
|
+
/**
|
|
3299
|
+
* checks if the application is running in CLI
|
|
3300
|
+
*/
|
|
3301
|
+
abstract runningInConsole(): boolean;
|
|
3302
|
+
/**
|
|
3303
|
+
* checks if the application is running in Unit Test
|
|
3304
|
+
*/
|
|
3305
|
+
abstract runningUnitTests(): boolean;
|
|
3306
|
+
abstract getRuntimeEnv(): 'browser' | 'node' | 'unknown';
|
|
3307
|
+
/**
|
|
3308
|
+
* Determine if the application has booted.
|
|
3309
|
+
*/
|
|
3310
|
+
abstract isBooted(): boolean;
|
|
3311
|
+
/**
|
|
3312
|
+
* Boot all service providers after registration
|
|
3313
|
+
*/
|
|
3314
|
+
abstract boot(): Promise<this>;
|
|
3315
|
+
/**
|
|
3316
|
+
* Register a new boot listener.
|
|
3317
|
+
*
|
|
3318
|
+
* @param callable $callback
|
|
3319
|
+
*/
|
|
3320
|
+
abstract booting(callback: (app: this) => void): void;
|
|
3321
|
+
/**
|
|
3322
|
+
* Register a new "booted" listener.
|
|
3323
|
+
*
|
|
3324
|
+
* @param callback
|
|
3325
|
+
*/
|
|
3326
|
+
abstract booted(callback: (app: this) => void): void;
|
|
3327
|
+
/**
|
|
3328
|
+
* Handle the incoming HTTP request and send the response to the browser.
|
|
3329
|
+
*
|
|
3330
|
+
* @param request
|
|
3331
|
+
*/
|
|
3332
|
+
abstract handleRequest(event: H3Event): Promise<void>;
|
|
3333
|
+
/**
|
|
3334
|
+
* Get the URI resolver callback.
|
|
3335
|
+
*/
|
|
3336
|
+
abstract getUriResolver(): () => typeof IUrl | undefined;
|
|
3337
|
+
/**
|
|
3338
|
+
* Set the URI resolver callback.
|
|
3339
|
+
*
|
|
3340
|
+
* @param callback
|
|
3341
|
+
*/
|
|
3342
|
+
abstract setUriResolver(callback: () => typeof IUrl): this;
|
|
3343
|
+
/**
|
|
3344
|
+
* Determine if middleware has been disabled for the application.
|
|
3345
|
+
*/
|
|
3346
|
+
abstract shouldSkipMiddleware(): boolean;
|
|
3347
|
+
/**
|
|
3348
|
+
* Provide safe overides for the app
|
|
3349
|
+
*/
|
|
3350
|
+
abstract configure(): IAppBuilder;
|
|
3351
|
+
/**
|
|
3352
|
+
* Check if the current application environment matches the one provided
|
|
3353
|
+
*
|
|
3354
|
+
* @param env
|
|
3355
|
+
*/
|
|
3356
|
+
abstract environment<E = string | undefined>(env: E): E extends undefined ? string : boolean;
|
|
3357
|
+
/**
|
|
3358
|
+
* Fire up the developement server using the user provided arguments
|
|
3359
|
+
*
|
|
3360
|
+
* Port will be auto assigned if provided one is not available
|
|
3361
|
+
*
|
|
3362
|
+
* @param h3App The current H3 app instance
|
|
3363
|
+
* @param preferedPort If provided, this will overide the port set in the evironment
|
|
3364
|
+
* @alias serve
|
|
3365
|
+
*/
|
|
3366
|
+
abstract fire(): Promise<this>;
|
|
3367
|
+
abstract fire(h3App: H3, preferredPort?: number): Promise<this>;
|
|
3368
|
+
/**
|
|
3369
|
+
* Fire up the developement server using the user provided arguments
|
|
3370
|
+
*
|
|
3371
|
+
* Port will be auto assigned if provided one is not available
|
|
3372
|
+
*
|
|
3373
|
+
* @param h3App The current H3 app instance
|
|
3374
|
+
* @param preferedPort If provided, this will overide the port set in the evironment
|
|
3375
|
+
*/
|
|
3376
|
+
abstract serve(h3App?: H3, preferredPort?: number): Promise<this>;
|
|
3377
|
+
/**
|
|
3378
|
+
* Run the given array of bootstrap classes.
|
|
3379
|
+
*
|
|
3380
|
+
* @param bootstrappers
|
|
3381
|
+
*/
|
|
3382
|
+
abstract bootstrapWith(bootstrappers: ConcreteConstructor<IBootstraper>[]): void | Promise<void>;
|
|
3383
|
+
/**
|
|
3384
|
+
* Determine if the application has been bootstrapped before.
|
|
3385
|
+
*/
|
|
3386
|
+
abstract hasBeenBootstrapped(): boolean;
|
|
3387
|
+
/**
|
|
3388
|
+
* Save the curretn H3 instance for possible future use.
|
|
3389
|
+
*
|
|
3390
|
+
* @param h3App The current H3 app instance
|
|
3391
|
+
* @returns
|
|
3392
|
+
*/
|
|
3393
|
+
abstract setH3App(h3App?: H3): this;
|
|
3394
|
+
/**
|
|
3395
|
+
* Set the HttpContext.
|
|
3396
|
+
*
|
|
3397
|
+
* @param ctx
|
|
3398
|
+
*/
|
|
3399
|
+
abstract setHttpContext(ctx: IHttpContext): this;
|
|
3400
|
+
/**
|
|
3401
|
+
* Get the HttpContext.
|
|
3402
|
+
*/
|
|
3403
|
+
abstract getHttpContext(): IHttpContext | undefined;
|
|
3404
|
+
/**
|
|
3405
|
+
* Get the base path of the app
|
|
3406
|
+
*
|
|
3407
|
+
* @returns
|
|
3408
|
+
*/
|
|
3409
|
+
abstract getBasePath(): string;
|
|
3410
|
+
/**
|
|
3411
|
+
* Dynamically retrieves a path property from the class.
|
|
3412
|
+
* Any property ending with "Path" is accessible automatically.
|
|
3413
|
+
*
|
|
3414
|
+
* @param name - The base name of the path property
|
|
3415
|
+
* @returns
|
|
3416
|
+
*/
|
|
3417
|
+
abstract getPath(name: IPathName, suffix?: string): string;
|
|
3418
|
+
/**
|
|
3419
|
+
* Programatically set the paths.
|
|
3420
|
+
*
|
|
3421
|
+
* @param name - The base name of the path property
|
|
3422
|
+
* @param path - The new path
|
|
3423
|
+
* @returns
|
|
3424
|
+
*/
|
|
3425
|
+
abstract setPath(name: IPathName, path: string): void;
|
|
3426
|
+
/**
|
|
3427
|
+
* Returns the installed version of the system core and typescript.
|
|
3428
|
+
*
|
|
3429
|
+
* @returns
|
|
3430
|
+
*/
|
|
3431
|
+
abstract getVersion(key: string): string;
|
|
3432
|
+
}
|
|
3433
|
+
//#endregion
|
|
3434
|
+
//#region src/Http/IHttpContext.d.ts
|
|
3435
|
+
declare abstract class IHttpContext {
|
|
3436
|
+
abstract app: IApplication;
|
|
3437
|
+
abstract event: H3Event;
|
|
3438
|
+
abstract request: IRequest;
|
|
3439
|
+
abstract response: IResponse;
|
|
3440
|
+
/**
|
|
3441
|
+
* Retrieve an existing HttpContext instance for an event, if any.
|
|
3442
|
+
*/
|
|
3443
|
+
static get(event: unknown): IHttpContext | undefined;
|
|
3444
|
+
/**
|
|
3445
|
+
* Delete the cached context for a given event (optional cleanup).
|
|
3446
|
+
*/
|
|
3447
|
+
static forget(event: unknown): void;
|
|
3448
|
+
}
|
|
3449
|
+
//#endregion
|
|
3450
|
+
//#region src/Utilities/Utilities.d.ts
|
|
3451
|
+
type IPathName = 'views' | 'routes' | 'assets' | 'base' | 'public' | 'storage' | 'config' | 'database' | 'commands';
|
|
3452
|
+
type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'patch' | 'apiResource' | 'group' | 'route' | 'any';
|
|
3453
|
+
type RouteMethod = 'GET' | 'HEAD' | 'PUT' | 'PATCH' | 'POST' | 'DELETE' | 'OPTIONS';
|
|
3454
|
+
type RequestMethod = 'HEAD' | 'GET' | 'PUT' | 'DELETE' | 'TRACE' | 'OPTIONS' | 'PURGE' | 'POST' | 'CONNECT' | 'PATCH';
|
|
3455
|
+
type ResourceMethod = 'index' | 'create' | 'store' | 'show' | 'edit' | 'update' | 'destroy';
|
|
3456
|
+
type GenericObject<X = any> = Record<string, X>;
|
|
3457
|
+
type RequestObject = Record<string, any>;
|
|
3458
|
+
type ResponseObject = Record<string, any>;
|
|
3459
|
+
type ExtractClassMethods<T> = { [K in keyof T]: T[K] extends ((...args: any[]) => any) ? K : never }[keyof T];
|
|
3460
|
+
/**
|
|
3461
|
+
* Type for EventHandler, representing a function that handles an H3 event.
|
|
3462
|
+
*/
|
|
3463
|
+
type EventHandler = (ctx: IHttpContext) => any;
|
|
3464
|
+
type TGeneric<V = any, K$1 extends string = string> = Record<K$1, V>;
|
|
3465
|
+
type ClassConstructor<T = any> = abstract new (...args: any[]) => T;
|
|
3466
|
+
type MixinConstructor<T = TGeneric> = ClassConstructor<T>;
|
|
3467
|
+
type RouteEventHandler = (ctx: IHttpContext, ...args: any[]) => any;
|
|
3468
|
+
type MergedConstructor<T = any> = (new (...args: any[]) => T) & Record<string, T>;
|
|
3469
|
+
type AbstractConstructor<T = any> = ClassConstructor<T> & Record<string, T>;
|
|
3470
|
+
type CallableConstructor<X = any, Y = any> = (...args: Y[]) => X;
|
|
3471
|
+
type AppEvent = CallableConstructor;
|
|
3472
|
+
type AppListener = CallableConstructor;
|
|
3473
|
+
type ConcreteConstructor<T = any, RA extends boolean = true> = new (...args: any[]) => RA extends true ? Required<T> : T;
|
|
3474
|
+
interface RouteActions {
|
|
3475
|
+
[key: string]: any;
|
|
3476
|
+
can?: [string, string][];
|
|
3477
|
+
where?: Record<string, RouteEventHandler>;
|
|
3478
|
+
domain?: string;
|
|
3479
|
+
path?: string;
|
|
3480
|
+
prefix?: string;
|
|
3481
|
+
as?: string;
|
|
3482
|
+
name?: string;
|
|
3483
|
+
controller?: RouteEventHandler | IController | string;
|
|
3484
|
+
missing?: any;
|
|
3485
|
+
uses?: any;
|
|
3486
|
+
http?: boolean;
|
|
3487
|
+
https?: boolean;
|
|
3488
|
+
middleware?: MiddlewareList;
|
|
3489
|
+
namespace?: string;
|
|
3490
|
+
excluded_middleware?: any;
|
|
3491
|
+
scopeBindings?: boolean;
|
|
3492
|
+
scope_bindings?: boolean;
|
|
3493
|
+
withoutMiddleware?: any;
|
|
3494
|
+
withoutScopedBindings?: any;
|
|
3495
|
+
}
|
|
3496
|
+
interface ResourceOptions {
|
|
3497
|
+
as?: string;
|
|
3498
|
+
missing?: string;
|
|
3499
|
+
prefix?: string;
|
|
3500
|
+
names?: Record<string, string>;
|
|
3501
|
+
middleware?: MiddlewareList;
|
|
3502
|
+
shallow?: any;
|
|
3503
|
+
only?: ResourceMethod[];
|
|
3504
|
+
except?: ResourceMethod[];
|
|
3505
|
+
parameters?: any;
|
|
3506
|
+
wheres?: any;
|
|
3507
|
+
trashed?: ResourceMethod[];
|
|
3508
|
+
creatable?: any;
|
|
3509
|
+
destroyable?: any;
|
|
3510
|
+
bindingFields?: string[];
|
|
3511
|
+
middleware_for?: GenericObject;
|
|
3512
|
+
excluded_middleware?: MiddlewareList;
|
|
3513
|
+
excluded_middleware_for?: GenericObject<MiddlewareList>;
|
|
3514
|
+
}
|
|
3515
|
+
interface ClassicRouteDefinition {
|
|
3516
|
+
method: Lowercase<RouteMethod>;
|
|
3517
|
+
path: string;
|
|
3518
|
+
name?: string | undefined;
|
|
3519
|
+
handler: EventHandler;
|
|
3520
|
+
signature: [string, string | undefined];
|
|
3521
|
+
}
|
|
3522
|
+
interface RouteAttributes {
|
|
3523
|
+
action: RouteActions;
|
|
3524
|
+
}
|
|
3525
|
+
type ActionInput<C extends typeof IController = any> = null | undefined | RouteEventHandler | IController | [C, methodName: ExtractClassMethods<InstanceType<C>>] | RouteActions;
|
|
3526
|
+
interface NormalizedAction {
|
|
3527
|
+
uses: RouteEventHandler | IController | string;
|
|
3528
|
+
controller?: RouteEventHandler | IController;
|
|
3529
|
+
methodName?: string;
|
|
3530
|
+
}
|
|
3531
|
+
type AServiceProvider = (new (app: any) => IServiceProvider) & Partial<IServiceProvider>;
|
|
3532
|
+
type OServiceProvider = (new (app: any) => Partial<IServiceProvider>) & Partial<IServiceProvider>;
|
|
3533
|
+
type ServiceProviderConstructor = (new (app: any) => IServiceProvider) & IServiceProvider;
|
|
3534
|
+
type ListenerClassConstructor = (new (...args: any) => any) & {
|
|
3535
|
+
subscribe?(...args: any[]): any;
|
|
3536
|
+
};
|
|
3537
|
+
//#endregion
|
|
3538
|
+
//#region src/Configuration/IAppBuilder.d.ts
|
|
3539
|
+
declare abstract class IAppBuilder {
|
|
3540
|
+
/**
|
|
3541
|
+
* Register the base kernel classes for the application.
|
|
3542
|
+
*/
|
|
3543
|
+
abstract withKernels(): this;
|
|
3544
|
+
/**
|
|
3545
|
+
* Register and wire up the application's exception handling layer.
|
|
3546
|
+
*
|
|
3547
|
+
* @param using
|
|
3548
|
+
**/
|
|
3549
|
+
abstract withExceptions(using: (exceptions: any) => void): this;
|
|
3550
|
+
/**
|
|
3551
|
+
* Register and wire up the application's middleware handling layer.
|
|
3552
|
+
*
|
|
3553
|
+
* @param using
|
|
3554
|
+
**/
|
|
3555
|
+
abstract withMiddleware(callback?: (mw: any) => void): this;
|
|
3556
|
+
/**
|
|
3557
|
+
* Register the routing services for the application.
|
|
3558
|
+
*/
|
|
3559
|
+
abstract withRouting({
|
|
3560
|
+
using,
|
|
3561
|
+
web,
|
|
3562
|
+
api,
|
|
3563
|
+
commands,
|
|
3564
|
+
health,
|
|
3565
|
+
channels,
|
|
3566
|
+
pages,
|
|
3567
|
+
apiPrefix,
|
|
3568
|
+
then
|
|
3569
|
+
}?: {
|
|
3570
|
+
using?: CallableConstructor;
|
|
3571
|
+
web?: string | string[];
|
|
3572
|
+
api?: string | string[];
|
|
3573
|
+
commands?: string;
|
|
3574
|
+
health?: string;
|
|
3575
|
+
channels?: string;
|
|
3576
|
+
pages?: string;
|
|
3577
|
+
apiPrefix?: string;
|
|
3578
|
+
then?: CallableConstructor;
|
|
3579
|
+
}): this;
|
|
3580
|
+
/**
|
|
3581
|
+
* create
|
|
3582
|
+
*/
|
|
3583
|
+
abstract create(): void;
|
|
3584
|
+
}
|
|
3585
|
+
//#endregion
|
|
3586
|
+
//#region src/Core/IRegisterer.d.ts
|
|
3587
|
+
declare abstract class IRegisterer {
|
|
3588
|
+
abstract bootRegister(): void;
|
|
3589
|
+
}
|
|
3590
|
+
//#endregion
|
|
3591
|
+
//#region src/Database/IModel.d.ts
|
|
3592
|
+
declare abstract class IModel<M extends Model = any> extends Model {
|
|
3593
|
+
/**
|
|
3594
|
+
* Retrieve the model for a bound value.
|
|
3595
|
+
*
|
|
3596
|
+
* @param value
|
|
3597
|
+
* @param field
|
|
3598
|
+
* @returns
|
|
3599
|
+
*/
|
|
3600
|
+
abstract resolveRouteBinding(value: any, field?: undefined | string | null): Promise<M>;
|
|
3601
|
+
/**
|
|
3602
|
+
* Retrieve the model for a bound value.
|
|
3603
|
+
*
|
|
3604
|
+
* @param query
|
|
3605
|
+
* @param value
|
|
3606
|
+
* @param field
|
|
3607
|
+
*/
|
|
3608
|
+
abstract resolveRouteBindingQuery(query: Builder, value: any, field?: undefined | string | null): IQueryBuilder<M>;
|
|
3609
|
+
/**
|
|
3610
|
+
* Get the value of the model's route key.
|
|
3611
|
+
*/
|
|
3612
|
+
abstract getRouteKey(): any;
|
|
3613
|
+
/**
|
|
3614
|
+
* Get the route key for the model.
|
|
3615
|
+
*/
|
|
3616
|
+
abstract getRouteKeyName(): string;
|
|
3617
|
+
}
|
|
3618
|
+
//#endregion
|
|
3619
|
+
//#region src/Exceptions/IExceptionHandler.d.ts
|
|
3620
|
+
type ExceptionConstructor<T = any> = new (...args: any[]) => T;
|
|
3621
|
+
type ExceptionConditionCallback = (error: any) => boolean;
|
|
3622
|
+
type RenderExceptionCallback = (error: any, request: IRequest) => IResponse | Promise<IResponse> | undefined | null;
|
|
3623
|
+
type ReportExceptionCallback = (error: any) => boolean | void | Promise<boolean | void>;
|
|
3624
|
+
type ThrottleExceptionCallback = (error: any) => LimitSpec | Unlimited | null | undefined;
|
|
3625
|
+
declare abstract class IExceptionHandler {
|
|
3626
|
+
/**
|
|
3627
|
+
* The exception handler method
|
|
3628
|
+
*
|
|
3629
|
+
* @param error
|
|
3630
|
+
* @param ctx
|
|
3631
|
+
*/
|
|
3632
|
+
abstract handle?(error: Error, ctx: IHttpContext): Promise<any>;
|
|
3633
|
+
/**
|
|
3634
|
+
* Register a reportable callback handler
|
|
3635
|
+
*
|
|
3636
|
+
* @param cb
|
|
3637
|
+
* @returns
|
|
3638
|
+
*/
|
|
3639
|
+
abstract reportable(cb: ReportExceptionCallback): this;
|
|
3640
|
+
abstract renderable(cb: RenderExceptionCallback): this;
|
|
3641
|
+
abstract dontReport(exceptions: ExceptionConstructor | ExceptionConstructor[]): this;
|
|
3642
|
+
abstract stopIgnoring(exceptions: ExceptionConstructor | ExceptionConstructor[]): this;
|
|
3643
|
+
abstract dontReportWhen(cb: ExceptionConditionCallback): this;
|
|
3644
|
+
abstract dontReportDuplicates(): this;
|
|
3645
|
+
abstract map(from: ExceptionConstructor, mapper: (error: any) => any): this;
|
|
3646
|
+
abstract throttleUsing(cb: ThrottleExceptionCallback): this;
|
|
3647
|
+
abstract buildContextUsing(cb: (e: any, current?: Record<string, any>) => Record<string, any>): this;
|
|
3648
|
+
abstract setRateLimiter(adapter: RateLimiterAdapter): this;
|
|
3649
|
+
abstract respondUsing(cb: (response: IResponse, error: any, request: IRequest) => IResponse | Promise<IResponse>): this;
|
|
3650
|
+
abstract shouldRenderJsonWhen(cb: (request: IRequest, error: any) => boolean): this;
|
|
3651
|
+
/**
|
|
3652
|
+
* Entry point to reporting an exception.
|
|
3653
|
+
*
|
|
3654
|
+
* @param error
|
|
3655
|
+
* @returns
|
|
3656
|
+
*/
|
|
3657
|
+
abstract report(error: any): Promise<void>;
|
|
3658
|
+
/**
|
|
3659
|
+
* Render an exception to the console.
|
|
3660
|
+
*
|
|
3661
|
+
* @param e
|
|
3662
|
+
*/
|
|
3663
|
+
abstract renderForConsole(e: Error): void;
|
|
3664
|
+
/**
|
|
3665
|
+
* Render an exception into an HTTP Response.
|
|
3666
|
+
*
|
|
3667
|
+
* @param ctx
|
|
3668
|
+
* @param error
|
|
3669
|
+
* @returns
|
|
3670
|
+
*/
|
|
3671
|
+
abstract render(request: IRequest, error: any): Promise<IResponse>;
|
|
3672
|
+
/**
|
|
3673
|
+
* getResponse
|
|
3674
|
+
*/
|
|
3675
|
+
abstract getResponse(request: IRequest, payload: Record<string, any>, e: any): IResponse | Promise<IResponse>;
|
|
3676
|
+
/**
|
|
3677
|
+
* Not implemented in core. Subclass can implement and call RequestException helpers.
|
|
3678
|
+
*
|
|
3679
|
+
* @param _length
|
|
3680
|
+
*/
|
|
3681
|
+
abstract truncateRequestExceptionsAt(_length: number): this;
|
|
3682
|
+
/**
|
|
3683
|
+
* Set the log level
|
|
3684
|
+
*
|
|
3685
|
+
* @param _attributes
|
|
3686
|
+
*/
|
|
3687
|
+
abstract level(type: string | Error, level: 'log' | 'debug' | 'warn' | 'info' | 'error'): this;
|
|
3688
|
+
/**
|
|
3689
|
+
* Not implemented here; applicable to validation pipeline/UI.
|
|
3690
|
+
*
|
|
3691
|
+
* @param _attributes
|
|
3692
|
+
*/
|
|
3693
|
+
abstract dontFlash(_attributes: string | string[]): this;
|
|
3694
|
+
}
|
|
3695
|
+
//#endregion
|
|
3696
|
+
//#region src/Foundation/CKernel.d.ts
|
|
3697
|
+
declare abstract class CKernel {
|
|
3698
|
+
/**
|
|
3699
|
+
* Run the console application.
|
|
3700
|
+
*/
|
|
3701
|
+
abstract handle(): Promise<number>;
|
|
3702
|
+
/**
|
|
3703
|
+
* Register a given command.
|
|
3704
|
+
*
|
|
3705
|
+
* @param command
|
|
3706
|
+
*/
|
|
3707
|
+
abstract registerCommand(command: any): void;
|
|
3708
|
+
/**
|
|
3709
|
+
* Get all the registered commands.
|
|
3710
|
+
*/
|
|
3711
|
+
abstract all(): Promise<{
|
|
3712
|
+
new (app: IApplication, kernel: Kernel<IApplication>): Command<IApplication>;
|
|
3713
|
+
}[]>;
|
|
3714
|
+
/**
|
|
3715
|
+
* Bootstrap the application for Musket commands.
|
|
3716
|
+
*
|
|
3717
|
+
* @return void
|
|
3718
|
+
*/
|
|
3719
|
+
abstract bootstrap(): Promise<void>;
|
|
3720
|
+
/**
|
|
3721
|
+
* Set the paths that should have their Musket commands automatically discovered.
|
|
3722
|
+
*
|
|
3723
|
+
* @param paths
|
|
3724
|
+
*/
|
|
3725
|
+
abstract addCommandPaths(paths: string[]): this;
|
|
3726
|
+
/**
|
|
3727
|
+
* Set the paths that should have their Artisan "routes" automatically discovered.
|
|
3728
|
+
*
|
|
3729
|
+
* @param paths
|
|
3730
|
+
*/
|
|
3731
|
+
abstract addCommandRoutePaths(paths: string[]): this;
|
|
3732
|
+
/**
|
|
3733
|
+
* Get the Musket application instance.
|
|
3734
|
+
*/
|
|
3735
|
+
abstract getConsole(): Kernel<IApplication>;
|
|
3736
|
+
/**
|
|
3737
|
+
* Terminate the app.
|
|
3738
|
+
*
|
|
3739
|
+
* @param request
|
|
3740
|
+
*/
|
|
3741
|
+
abstract terminate(status: number): void;
|
|
3742
|
+
}
|
|
3743
|
+
//#endregion
|
|
3744
|
+
//#region src/Foundation/IKernel.d.ts
|
|
3745
|
+
declare abstract class IKernel {
|
|
3746
|
+
/**
|
|
3747
|
+
* Handle an incoming HTTP request.
|
|
3748
|
+
*
|
|
3749
|
+
* @param request
|
|
3750
|
+
*/
|
|
3751
|
+
abstract handle(request: IRequest): Promise<IResponse | undefined>;
|
|
3752
|
+
/**
|
|
3753
|
+
* Bootstrap the application for HTTP requests.
|
|
3754
|
+
*
|
|
3755
|
+
* @return void
|
|
3756
|
+
*/
|
|
3757
|
+
abstract bootstrap(): void;
|
|
3758
|
+
/**
|
|
3759
|
+
* Call the terminate method on any terminable middleware.
|
|
3760
|
+
*
|
|
3761
|
+
* @param request
|
|
3762
|
+
* @param response
|
|
3763
|
+
*/
|
|
3764
|
+
abstract terminate(request: IRequest, response: IResponse): void;
|
|
3765
|
+
/**
|
|
3766
|
+
* Register a callback to be invoked when the requests lifecycle duration exceeds a given amount of time.
|
|
3767
|
+
*
|
|
3768
|
+
* @param {number | DateTime} threshold
|
|
3769
|
+
* @param handler
|
|
3770
|
+
*/
|
|
3771
|
+
abstract whenRequestLifecycleIsLongerThan(threshold: any, handler: (...args: any[]) => any): void;
|
|
3772
|
+
/**
|
|
3773
|
+
* When the request being handled started.
|
|
3774
|
+
*
|
|
3775
|
+
* @returns {DateTime}
|
|
3776
|
+
*/
|
|
3777
|
+
abstract requestStartedAt(): any;
|
|
3778
|
+
/**
|
|
3779
|
+
* Determine if the kernel has a given middleware.
|
|
3780
|
+
*
|
|
3781
|
+
* @param middleware
|
|
3782
|
+
*/
|
|
3783
|
+
abstract hasMiddleware(middleware: IMiddleware): boolean;
|
|
3784
|
+
/**
|
|
3785
|
+
* Add a new middleware to the beginning of the stack if it does not already exist.
|
|
3786
|
+
*
|
|
3787
|
+
* @param string middleware
|
|
3788
|
+
*/
|
|
3789
|
+
abstract prependMiddleware(middleware: IMiddleware): this;
|
|
3790
|
+
/**
|
|
3791
|
+
* Add a new middleware to end of the stack if it does not already exist.
|
|
3792
|
+
*
|
|
3793
|
+
* @param middleware
|
|
3794
|
+
*/
|
|
3795
|
+
abstract pushMiddleware(middleware: IMiddleware): this;
|
|
3796
|
+
/**
|
|
3797
|
+
* Prepend the given middleware to the given middleware group.
|
|
3798
|
+
*
|
|
3799
|
+
* @param group
|
|
3800
|
+
* @param middleware
|
|
3801
|
+
*
|
|
3802
|
+
* @throws {InvalidArgumentException}
|
|
3803
|
+
*/
|
|
3804
|
+
abstract prependMiddlewareToGroup(group: string, middleware: IMiddleware): this;
|
|
3805
|
+
/**
|
|
3806
|
+
* Append the given middleware to the given middleware group.
|
|
3807
|
+
*
|
|
3808
|
+
* @param group
|
|
3809
|
+
* @param middleware
|
|
3810
|
+
*
|
|
3811
|
+
* @throws {InvalidArgumentException}
|
|
3812
|
+
*/
|
|
3813
|
+
abstract appendMiddlewareToGroup(group: string, middleware: IMiddleware): this;
|
|
3814
|
+
/**
|
|
3815
|
+
* Prepend the given middleware to the middleware priority list.
|
|
3816
|
+
*
|
|
3817
|
+
* @param middleware
|
|
3818
|
+
*/
|
|
3819
|
+
abstract prependToMiddlewarePriority(middleware: IMiddleware): this;
|
|
3820
|
+
/**
|
|
3821
|
+
* Append the given middleware to the middleware priority list.
|
|
3822
|
+
*
|
|
3823
|
+
* @param string $middleware
|
|
3824
|
+
* @return $this
|
|
3825
|
+
*/
|
|
3826
|
+
abstract appendToMiddlewarePriority(middleware: IMiddleware): this;
|
|
3827
|
+
/**
|
|
3828
|
+
* Add the given middleware to the middleware priority list before other middleware.
|
|
3829
|
+
*
|
|
3830
|
+
* @param before
|
|
3831
|
+
* @param string $middleware
|
|
3832
|
+
* @return $this
|
|
3833
|
+
*/
|
|
3834
|
+
abstract addToMiddlewarePriorityBefore(before: IMiddleware | IMiddleware[], middleware: IMiddleware): this;
|
|
3835
|
+
/**
|
|
3836
|
+
* Add the given middleware to the middleware priority list after other middleware.
|
|
3837
|
+
*
|
|
3838
|
+
* @param after
|
|
3839
|
+
* @param middleware
|
|
3840
|
+
*/
|
|
3841
|
+
abstract addToMiddlewarePriorityAfter(after: IMiddleware | IMiddleware[], middleware: IMiddleware): this;
|
|
3842
|
+
/**
|
|
3843
|
+
* Get the priority-sorted list of middleware.
|
|
3844
|
+
*
|
|
3845
|
+
* @return array
|
|
3846
|
+
*/
|
|
3847
|
+
abstract getMiddlewarePriority(): MiddlewareList;
|
|
3848
|
+
/**
|
|
3849
|
+
* Get the application's global middleware.
|
|
3850
|
+
*
|
|
3851
|
+
* @return array
|
|
3852
|
+
*/
|
|
3853
|
+
abstract getGlobalMiddleware(): MiddlewareList;
|
|
3854
|
+
/**
|
|
3855
|
+
* Set the application's global middleware.
|
|
3856
|
+
*
|
|
3857
|
+
* @param middleware
|
|
3858
|
+
* @returns
|
|
3859
|
+
*/
|
|
3860
|
+
abstract setGlobalMiddleware(middleware: MiddlewareList): this;
|
|
3861
|
+
/**
|
|
3862
|
+
* Get the application's route middleware groups.
|
|
3863
|
+
*
|
|
3864
|
+
* @return array
|
|
3865
|
+
*/
|
|
3866
|
+
abstract getMiddlewareGroups(): Record<string, MiddlewareList>;
|
|
3867
|
+
/**
|
|
3868
|
+
* Set the application's middleware groups.
|
|
3869
|
+
*
|
|
3870
|
+
* @param groups
|
|
3871
|
+
* @returns
|
|
3872
|
+
*/
|
|
3873
|
+
abstract setMiddlewareGroups(groups: Record<string, MiddlewareList>): this;
|
|
3874
|
+
/**
|
|
3875
|
+
* Get the application's route middleware aliases.
|
|
3876
|
+
*
|
|
3877
|
+
* @return array
|
|
3878
|
+
*/
|
|
3879
|
+
abstract getMiddlewareAliases(): Record<string, IMiddleware>;
|
|
3880
|
+
/**
|
|
3881
|
+
* Set the application's route middleware aliases.
|
|
3882
|
+
*
|
|
3883
|
+
* @param aliases
|
|
3884
|
+
*/
|
|
3885
|
+
abstract setMiddlewareAliases(aliases: Record<string, IMiddleware>): this;
|
|
3886
|
+
/**
|
|
3887
|
+
* Set the application's middleware priority.
|
|
3888
|
+
*
|
|
3889
|
+
* @param priority
|
|
3890
|
+
*/
|
|
3891
|
+
abstract setMiddlewarePriority(priority: MiddlewareList): this;
|
|
3892
|
+
/**
|
|
3893
|
+
* Get the Laravel application instance.
|
|
3894
|
+
*/
|
|
3895
|
+
abstract getApplication(): IApplication;
|
|
3896
|
+
/**
|
|
3897
|
+
* Set the Laravel application instance.
|
|
3898
|
+
*
|
|
3899
|
+
* @param app
|
|
3900
|
+
*/
|
|
3901
|
+
abstract setApplication(app: IApplication): this;
|
|
3902
|
+
}
|
|
3903
|
+
//#endregion
|
|
3904
|
+
//#region src/Foundation/RateLimiterAdapter.d.ts
|
|
3905
|
+
type LimitSpec = {
|
|
3906
|
+
key?: string;
|
|
3907
|
+
maxAttempts: number;
|
|
3908
|
+
decaySeconds: number;
|
|
3909
|
+
};
|
|
3910
|
+
type Unlimited = {
|
|
3911
|
+
unlimited: true;
|
|
3912
|
+
};
|
|
3913
|
+
/**
|
|
3914
|
+
* Rate Limiter Adapter Interface
|
|
3915
|
+
*/
|
|
3916
|
+
interface RateLimiterAdapter {
|
|
3917
|
+
/**
|
|
3918
|
+
* Attempt a key with a maxAttempts and decaySeconds.
|
|
3919
|
+
*
|
|
3920
|
+
* Return true if this is allowed (i.e., *not* throttled),
|
|
3921
|
+
* false if the limit is reached.
|
|
3922
|
+
*/
|
|
3923
|
+
attempt(key: string, maxAttempts: number, allowCallback: () => boolean | Promise<boolean>, decaySeconds: number): Promise<boolean>;
|
|
3924
|
+
}
|
|
3925
|
+
//#endregion
|
|
3926
|
+
//#region src/Http/HttpContract.d.ts
|
|
3927
|
+
type CacheOptions = Partial<{
|
|
3928
|
+
must_revalidate: boolean;
|
|
3929
|
+
no_cache: boolean;
|
|
3930
|
+
no_store: boolean;
|
|
3931
|
+
no_transform: boolean;
|
|
3932
|
+
public: boolean;
|
|
3933
|
+
private: boolean;
|
|
3934
|
+
proxy_revalidate: boolean;
|
|
3935
|
+
max_age: number;
|
|
3936
|
+
s_maxage: number;
|
|
3937
|
+
immutable: boolean;
|
|
3938
|
+
stale_while_revalidate: number;
|
|
3939
|
+
stale_if_error: number;
|
|
3940
|
+
last_modified: string | Date;
|
|
3941
|
+
etag: string;
|
|
3942
|
+
}>;
|
|
3943
|
+
//#endregion
|
|
3944
|
+
//#region src/Queue/IJob.d.ts
|
|
3945
|
+
declare abstract class IJob {
|
|
3946
|
+
/**
|
|
3947
|
+
* Get the job identifier.
|
|
3948
|
+
*/
|
|
3949
|
+
abstract getJobId(): string | number | undefined;
|
|
3950
|
+
/**
|
|
3951
|
+
* Get the raw body of the job.
|
|
3952
|
+
*/
|
|
3953
|
+
abstract getRawBody(): string;
|
|
3954
|
+
/**
|
|
3955
|
+
* Get the UUID of the job.
|
|
3956
|
+
*
|
|
3957
|
+
* @return string|null
|
|
3958
|
+
*/
|
|
3959
|
+
abstract uuid(): string | null;
|
|
3960
|
+
/**
|
|
3961
|
+
* Fire the job.
|
|
3962
|
+
*
|
|
3963
|
+
* @return void
|
|
3964
|
+
*/
|
|
3965
|
+
abstract fire(): void;
|
|
3966
|
+
/**
|
|
3967
|
+
* Delete the job from the queue.
|
|
3968
|
+
*/
|
|
3969
|
+
abstract delete(): void;
|
|
3970
|
+
/**
|
|
3971
|
+
* Determine if the job has been deleted.
|
|
3972
|
+
*/
|
|
3973
|
+
abstract isDeleted(): boolean;
|
|
3974
|
+
/**
|
|
3975
|
+
* Release the job back into the queue after (n) seconds.
|
|
3976
|
+
*
|
|
3977
|
+
* @param delay
|
|
3978
|
+
*/
|
|
3979
|
+
abstract release(delay?: number): void;
|
|
3980
|
+
/**
|
|
3981
|
+
* Determine if the job was released back into the queue.
|
|
3982
|
+
*
|
|
3983
|
+
* @return bool
|
|
3984
|
+
*/
|
|
3985
|
+
abstract isReleased(): boolean;
|
|
3986
|
+
/**
|
|
3987
|
+
* Determine if the job has been deleted or released.
|
|
3988
|
+
*/
|
|
3989
|
+
abstract isDeletedOrReleased(): boolean;
|
|
3990
|
+
/**
|
|
3991
|
+
* Determine if the job has been marked as a failure.
|
|
3992
|
+
*/
|
|
3993
|
+
abstract hasFailed(): boolean;
|
|
3994
|
+
/**
|
|
3995
|
+
* Mark the job as "failed".
|
|
3996
|
+
*/
|
|
3997
|
+
abstract markAsFailed(): void;
|
|
3998
|
+
/**
|
|
3999
|
+
* Delete the job, call the "failed" method, and raise the failed job event.
|
|
4000
|
+
*
|
|
4001
|
+
* @param e
|
|
4002
|
+
*/
|
|
4003
|
+
abstract fail(e: Error): void;
|
|
4004
|
+
/**
|
|
4005
|
+
* Get the resolved job handler instance.
|
|
4006
|
+
*
|
|
4007
|
+
* @return mixed
|
|
4008
|
+
*/
|
|
4009
|
+
abstract getResolvedJob(): IJob;
|
|
4010
|
+
/**
|
|
4011
|
+
* Get the decoded body of the job.
|
|
4012
|
+
*/
|
|
4013
|
+
abstract payload(): JobPayload;
|
|
4014
|
+
/**
|
|
4015
|
+
* Get the number of times to attempt a job.
|
|
4016
|
+
*
|
|
4017
|
+
* @return int|null
|
|
4018
|
+
*/
|
|
4019
|
+
abstract maxTries(): number | null;
|
|
4020
|
+
/**
|
|
4021
|
+
* Get the number of times to attempt a job after an exception.
|
|
4022
|
+
*
|
|
4023
|
+
* @return int|null
|
|
4024
|
+
*/
|
|
4025
|
+
abstract maxExceptions(): number | null;
|
|
4026
|
+
/**
|
|
4027
|
+
* Determine if the job should fail when it timeouts.
|
|
4028
|
+
*
|
|
4029
|
+
* @return bool
|
|
4030
|
+
*/
|
|
4031
|
+
abstract shouldFailOnTimeout(): boolean;
|
|
4032
|
+
/**
|
|
4033
|
+
* The number of seconds to wait before retrying a job that encountered an uncaught exception.
|
|
4034
|
+
*
|
|
4035
|
+
* @return int|int[]|null
|
|
4036
|
+
*/
|
|
4037
|
+
abstract backoff(): number | null;
|
|
4038
|
+
/**
|
|
4039
|
+
* Get the number of seconds the job can run.
|
|
4040
|
+
*
|
|
4041
|
+
* @return int|null
|
|
4042
|
+
*/
|
|
4043
|
+
abstract timeout(): number | null;
|
|
4044
|
+
/**
|
|
4045
|
+
* Get the timestamp indicating when the job should timeout.
|
|
4046
|
+
*
|
|
4047
|
+
* @return int|null
|
|
4048
|
+
*/
|
|
4049
|
+
abstract retryUntil(): number | null;
|
|
4050
|
+
/**
|
|
4051
|
+
* Get the name of the queued job class.
|
|
4052
|
+
*
|
|
4053
|
+
* @return string
|
|
4054
|
+
*/
|
|
4055
|
+
abstract getName(): string;
|
|
4056
|
+
/**
|
|
4057
|
+
* Get the resolved display name of the queued job class.
|
|
4058
|
+
*
|
|
4059
|
+
* Resolves the name of "wrapped" jobs such as class-based handlers.
|
|
4060
|
+
*/
|
|
4061
|
+
abstract resolveName(): any;
|
|
4062
|
+
/**
|
|
4063
|
+
* Get the class of the queued job.
|
|
4064
|
+
*
|
|
4065
|
+
* Resolves the class of "wrapped" jobs such as class-based handlers.
|
|
4066
|
+
*
|
|
4067
|
+
* @return string
|
|
4068
|
+
*/
|
|
4069
|
+
abstract resolveQueuedJobClass(): any;
|
|
4070
|
+
/**
|
|
4071
|
+
* Get the name of the connection the job belongs to.
|
|
4072
|
+
*/
|
|
4073
|
+
abstract getConnectionName(): string;
|
|
4074
|
+
/**
|
|
4075
|
+
* Get the name of the queue the job belongs to.
|
|
4076
|
+
*/
|
|
4077
|
+
abstract getQueue(): string | undefined;
|
|
4078
|
+
/**
|
|
4079
|
+
* Get the service container instance.
|
|
4080
|
+
*/
|
|
4081
|
+
abstract getContainer(): IContainer;
|
|
4082
|
+
}
|
|
4083
|
+
//#endregion
|
|
4084
|
+
//#region src/Routing/ICallableDispatcher.d.ts
|
|
4085
|
+
declare abstract class ICallableDispatcher {}
|
|
4086
|
+
//#endregion
|
|
4087
|
+
//#region src/Routing/IControllerDispatcher.d.ts
|
|
4088
|
+
declare abstract class IControllerDispatcher {
|
|
4089
|
+
/**
|
|
4090
|
+
* Dispatch a request to a given controller and method.
|
|
4091
|
+
*
|
|
4092
|
+
* @param route
|
|
4093
|
+
* @param controller
|
|
4094
|
+
* @param method
|
|
4095
|
+
*/
|
|
4096
|
+
abstract dispatch(route: IRoute, controller: IController, method: ResourceMethod): Promise<any>;
|
|
4097
|
+
/**
|
|
4098
|
+
* Get the middleware for the controller instance.
|
|
4099
|
+
*
|
|
4100
|
+
* @param controller
|
|
4101
|
+
* @param method
|
|
4102
|
+
*/
|
|
4103
|
+
abstract getMiddleware(controller: IController, method: RouteMethod): IMiddleware[];
|
|
4104
|
+
}
|
|
4105
|
+
//#endregion
|
|
4106
|
+
//#region src/Routing/IRouteRegistrar.d.ts
|
|
4107
|
+
declare abstract class IRouteRegistrar {
|
|
4108
|
+
abstract attribute(key: string, value: any): this;
|
|
4109
|
+
abstract resource<C extends typeof IController>(name: string, controller: C, options?: ResourceOptions): IPendingResourceRegistration;
|
|
4110
|
+
abstract apiResource<C extends typeof IController>(name: string, controller: C, options?: ResourceOptions): IPendingResourceRegistration;
|
|
4111
|
+
abstract singleton<C extends typeof IController>(name: string, controller: C, options?: ResourceOptions): IPendingSingletonResourceRegistration;
|
|
4112
|
+
abstract apiSingleton<C extends typeof IController>(name: string, controller: C, options?: ResourceOptions): IPendingSingletonResourceRegistration;
|
|
4113
|
+
abstract group(callback: CallableConstructor | any[] | string): this;
|
|
4114
|
+
abstract match(methods: RouteMethod | RouteMethod[], uri: string, action?: RouteActions): IRoute;
|
|
4115
|
+
abstract middleware(): any[];
|
|
4116
|
+
abstract middleware(middleware?: string | string[]): this;
|
|
4117
|
+
abstract prefix(prefix: string): this;
|
|
4118
|
+
}
|
|
4119
|
+
//#endregion
|
|
4120
|
+
//#region src/Routing/Traits/UrlRoutable.d.ts
|
|
4121
|
+
declare abstract class UrlRoutable {
|
|
4122
|
+
/**
|
|
4123
|
+
* Get the value of the model's route key.
|
|
4124
|
+
*/
|
|
4125
|
+
abstract getRouteKey(): any;
|
|
4126
|
+
/**
|
|
4127
|
+
* Retrieve the model for a bound value.
|
|
4128
|
+
*
|
|
4129
|
+
* @param value
|
|
4130
|
+
* @param field
|
|
4131
|
+
*/
|
|
4132
|
+
abstract resolveRouteBinding(value: any, field?: string): Promise<IModel<any>>;
|
|
4133
|
+
/**
|
|
4134
|
+
* Retrieve the child model for a bound value.
|
|
4135
|
+
*
|
|
4136
|
+
* @param childType
|
|
4137
|
+
* @param value
|
|
4138
|
+
* @param field
|
|
4139
|
+
*/
|
|
4140
|
+
/**
|
|
4141
|
+
* Get the route key for the model.
|
|
4142
|
+
*/
|
|
4143
|
+
abstract getRouteKeyName(): string;
|
|
4144
|
+
}
|
|
4145
|
+
//#endregion
|
|
4146
|
+
//#region src/Url/IRequestAwareUrl.d.ts
|
|
4147
|
+
/**
|
|
4148
|
+
* Contract for request-aware URL helpers
|
|
4149
|
+
*/
|
|
4150
|
+
declare abstract class IRequestAwareUrl {
|
|
4151
|
+
/**
|
|
4152
|
+
* Get the current request URL
|
|
4153
|
+
*/
|
|
4154
|
+
abstract current(): string;
|
|
4155
|
+
/**
|
|
4156
|
+
* Get the full current URL with query string
|
|
4157
|
+
*/
|
|
4158
|
+
abstract full(): string;
|
|
4159
|
+
/**
|
|
4160
|
+
* Get the previous request URL
|
|
4161
|
+
*/
|
|
4162
|
+
abstract previous(): string;
|
|
4163
|
+
/**
|
|
4164
|
+
* Get the previous request path (without query string)
|
|
4165
|
+
*/
|
|
4166
|
+
abstract previousPath(): string;
|
|
4167
|
+
/**
|
|
4168
|
+
* Get the current query parameters
|
|
4169
|
+
*/
|
|
4170
|
+
abstract query(): Record<string, any>;
|
|
4171
|
+
}
|
|
4172
|
+
//#endregion
|
|
4173
|
+
//#region src/Url/IUrlHelpers.d.ts
|
|
4174
|
+
/**
|
|
4175
|
+
* The Url Helper Contract
|
|
4176
|
+
*/
|
|
4177
|
+
declare abstract class IUrlHelpers {
|
|
4178
|
+
/**
|
|
4179
|
+
* Create a URL from a path relative to the app URL
|
|
4180
|
+
*/
|
|
4181
|
+
abstract to: (path: string) => IUrl;
|
|
4182
|
+
/**
|
|
4183
|
+
* Create a URL from a named route
|
|
4184
|
+
*/
|
|
4185
|
+
abstract route: (name: string, params?: Record<string, any>) => string;
|
|
4186
|
+
/**
|
|
4187
|
+
* Create a signed URL from a named route
|
|
4188
|
+
*
|
|
4189
|
+
* @param name
|
|
4190
|
+
* @param params
|
|
4191
|
+
* @returns
|
|
4192
|
+
*/
|
|
4193
|
+
abstract signedRoute: (name: string, params?: Record<string, any>) => IUrl;
|
|
4194
|
+
/**
|
|
4195
|
+
* Create a temporary signed URL from a named route
|
|
4196
|
+
*
|
|
4197
|
+
* @param name
|
|
4198
|
+
* @param params
|
|
4199
|
+
* @param expiration
|
|
4200
|
+
* @returns
|
|
4201
|
+
*/
|
|
4202
|
+
abstract temporarySignedRoute: (name: string, params: Record<string, any> | undefined, expiration: number) => IUrl;
|
|
4203
|
+
/**
|
|
4204
|
+
* Create a URL from a controller action
|
|
4205
|
+
*/
|
|
4206
|
+
abstract action: <C extends new (...args: any) => any>(controller: string | [C, methodName: ExtractClassMethods<InstanceType<C>>], params?: Record<string, any>) => string;
|
|
4207
|
+
/**
|
|
4208
|
+
* Get request-aware URL helpers
|
|
4209
|
+
*/
|
|
4210
|
+
abstract url: {
|
|
4211
|
+
(): IUrlHelpers;
|
|
4212
|
+
(path: string): string;
|
|
4213
|
+
};
|
|
4214
|
+
}
|
|
4215
|
+
//#endregion
|
|
4216
|
+
//#region src/Validation/IMessageBag.d.ts
|
|
4217
|
+
declare class ValidationMessageProvider {
|
|
4218
|
+
getMessageBag(): IMessageBag;
|
|
4219
|
+
}
|
|
4220
|
+
declare class IMessageBag implements ValidationMessageProvider {
|
|
4221
|
+
/**
|
|
4222
|
+
* Create a new message bag instance.
|
|
4223
|
+
*/
|
|
4224
|
+
constructor(messages: Record<string, string[] | string>);
|
|
4225
|
+
getMessageBag(): IMessageBag;
|
|
4226
|
+
/**
|
|
4227
|
+
* Get all message keys.
|
|
4228
|
+
*/
|
|
4229
|
+
keys(): string[];
|
|
4230
|
+
/**
|
|
4231
|
+
* Add a message.
|
|
4232
|
+
*/
|
|
4233
|
+
add(key: string, message: string): this;
|
|
4234
|
+
/**
|
|
4235
|
+
* Add a message conditionally.
|
|
4236
|
+
*/
|
|
4237
|
+
addIf(condition: boolean, key: string, message: string): this;
|
|
4238
|
+
/**
|
|
4239
|
+
* Merge another message source into this one.
|
|
4240
|
+
*/
|
|
4241
|
+
merge(messages: Record<string, string[]> | ValidationMessageProvider): this;
|
|
4242
|
+
/**
|
|
4243
|
+
* Determine if messages exist for all given keys.
|
|
4244
|
+
*/
|
|
4245
|
+
has(key?: string | string[] | null): boolean;
|
|
4246
|
+
/**
|
|
4247
|
+
* Determine if messages exist for any given key.
|
|
4248
|
+
*/
|
|
4249
|
+
hasAny(keys: string | string[]): boolean;
|
|
4250
|
+
/**
|
|
4251
|
+
* Determine if messages don't exist for given keys.
|
|
4252
|
+
*/
|
|
4253
|
+
missing(key: string | string[]): boolean;
|
|
4254
|
+
/**
|
|
4255
|
+
* Get the first message for a given key.
|
|
4256
|
+
*/
|
|
4257
|
+
first(key?: string | null, format?: string | null): string;
|
|
4258
|
+
/**
|
|
4259
|
+
* Get all messages for a given key.
|
|
4260
|
+
*/
|
|
4261
|
+
get(key: string, format?: string | null): string[] | Record<string, string[]>;
|
|
4262
|
+
/**
|
|
4263
|
+
* Get all messages.
|
|
4264
|
+
*/
|
|
4265
|
+
all(format?: string): string[];
|
|
4266
|
+
/**
|
|
4267
|
+
* Get unique messages.
|
|
4268
|
+
*/
|
|
4269
|
+
unique(format?: string | null): string[];
|
|
4270
|
+
/**
|
|
4271
|
+
* Remove messages for a key.
|
|
4272
|
+
*/
|
|
4273
|
+
forget(key: string): this;
|
|
4274
|
+
/**
|
|
4275
|
+
* Get raw messages.
|
|
4276
|
+
*/
|
|
4277
|
+
messagesRaw(): Record<string, string[]>;
|
|
4278
|
+
/**
|
|
4279
|
+
* Alias for messagesRaw().
|
|
4280
|
+
*/
|
|
4281
|
+
getMessages(): Record<string, string[]>;
|
|
4282
|
+
/**
|
|
4283
|
+
* Return message bag instance.
|
|
4284
|
+
*/
|
|
4285
|
+
getMessageBag(): IMessageBag;
|
|
4286
|
+
/**
|
|
4287
|
+
* Get format string.
|
|
4288
|
+
*/
|
|
4289
|
+
getFormat(): string;
|
|
4290
|
+
/**
|
|
4291
|
+
* Set default message format.
|
|
4292
|
+
*/
|
|
4293
|
+
setFormat(format: string): this;
|
|
4294
|
+
/**
|
|
4295
|
+
* Empty checks.
|
|
4296
|
+
*/
|
|
4297
|
+
isEmpty(): boolean;
|
|
4298
|
+
isNotEmpty(): boolean;
|
|
4299
|
+
any(): boolean;
|
|
4300
|
+
/**
|
|
4301
|
+
* Count total messages.
|
|
4302
|
+
*/
|
|
4303
|
+
count(): number;
|
|
4304
|
+
/**
|
|
4305
|
+
* Array & JSON conversions.
|
|
4306
|
+
*/
|
|
4307
|
+
toArray(): Record<string, string[]>;
|
|
4308
|
+
jsonSerialize(): any;
|
|
4309
|
+
toJson(options: number): string;
|
|
4310
|
+
toPrettyJson(): string;
|
|
4311
|
+
/**
|
|
4312
|
+
* String representation.
|
|
4313
|
+
*/
|
|
4314
|
+
toString(): string;
|
|
4315
|
+
}
|
|
4316
|
+
//#endregion
|
|
4317
|
+
//#region src/Validation/RuleBuilder.d.ts
|
|
4318
|
+
interface ValidationRuleCallable {
|
|
4319
|
+
name: string;
|
|
4320
|
+
validator: (value: any, parameters?: string[], attribute?: string) => boolean | Promise<boolean>;
|
|
4321
|
+
message?: string;
|
|
4322
|
+
}
|
|
4323
|
+
type CustomValidationRules = IValidationRule | ValidationRuleCallable;
|
|
4324
|
+
declare class BaseValidationRuleClass {}
|
|
4325
|
+
//#endregion
|
|
4326
|
+
//#region src/Validation/IValidationRule.d.ts
|
|
4327
|
+
declare abstract class IValidationRule {
|
|
4328
|
+
rules: ValidationRuleCallable[];
|
|
4329
|
+
/**
|
|
4330
|
+
* Run the validation rule.
|
|
4331
|
+
*/
|
|
4332
|
+
abstract validate(attribute: string, value: any, fail: (msg: string) => any): void;
|
|
4333
|
+
/**
|
|
4334
|
+
* Set the current validator.
|
|
4335
|
+
*/
|
|
4336
|
+
/**
|
|
4337
|
+
* Set the data under validation.
|
|
4338
|
+
*/
|
|
4339
|
+
setData(_data: Record<string, any>): this;
|
|
4340
|
+
passes(value: any, attribute: string): boolean | Promise<boolean>;
|
|
4341
|
+
}
|
|
4342
|
+
//#endregion
|
|
4343
|
+
//#region src/Validation/ValidationRuleName.d.ts
|
|
4344
|
+
type ParamableValidationRuleName = 'accepted_if' | 'after' | 'after_or_equal' | 'before' | 'before_or_equal' | 'between' | 'date_equals' | 'datetime' | 'declined_if' | 'digits_between' | 'different' | 'exists' | 'ends_with' | 'gt' | 'gte' | 'in' | 'includes' | 'lt' | 'lte' | 'max' | 'min' | 'not_in' | 'not_includes' | 'required_if' | 'required_unless' | 'required_with' | 'required_with_all' | 'required_without' | 'required_without_all' | 'same' | 'size' | 'starts_with' | 'unique';
|
|
4345
|
+
type PlainRuleName = 'accepted' | 'alpha' | 'alpha_dash' | 'alpha_num' | 'array' | 'array_unique' | 'bail' | 'boolean' | 'confirmed' | 'date' | 'declined' | 'digits' | 'email' | 'integer' | 'json' | 'not_regex' | 'nullable' | 'numeric' | 'object' | 'present' | 'regex' | 'required' | 'sometimes' | 'string' | 'url' | 'hex' | 'uuid';
|
|
4346
|
+
type ValidationRuleName = ParamableValidationRuleName | PlainRuleName;
|
|
4347
|
+
type MethodRules = Regex | In | NotIn | RequiredIf;
|
|
4348
|
+
/**
|
|
4349
|
+
* Single rule value (supports autocomplete + arbitrary strings + Rule instances)
|
|
4350
|
+
*/
|
|
4351
|
+
type RuleName = ValidationRuleName | `${ParamableValidationRuleName}:${string}` | Rule$1 | MethodRules;
|
|
4352
|
+
type ValidationRuleSet = RuleName | RuleName[] | `${ValidationRuleName}${string & `|${string}`}`;
|
|
4353
|
+
//#endregion
|
|
4354
|
+
//#region src/Validation/ValidatorContracts.d.ts
|
|
4355
|
+
/**
|
|
4356
|
+
* Parse rule names from rule string or string[] definitions
|
|
4357
|
+
*/
|
|
4358
|
+
type ExtractRules<R> = R extends string ? R extends `${infer Head}|${infer Tail}` ? Head extends `${infer Rule}:${string}` ? Rule | ExtractRules<Tail> : Head | ExtractRules<Tail> : R extends `${infer Rule}:${string}` ? Rule : R : R extends string[] ? ExtractRules<R[number]> : never;
|
|
4359
|
+
/**
|
|
4360
|
+
* Flatten data structure into dot-notation keys
|
|
4361
|
+
* including wildcards (*) for arrays.
|
|
4362
|
+
*/
|
|
4363
|
+
type DotPaths<T, Prefix extends string = ''> = { [K in keyof T & string]: T[K] extends (infer A)[] ? `${Prefix}${K}` | `${Prefix}${K}.*` | (A extends Record<string, any> ? `${Prefix}${K}.*.${DotPaths<A>}` : never) : T[K] extends Record<string, any> ? `${Prefix}${K}` | `${Prefix}${K}.${DotPaths<T[K]>}` : `${Prefix}${K}` }[keyof T & string];
|
|
4364
|
+
/**
|
|
4365
|
+
* Builds message keys only for rules used on that field
|
|
4366
|
+
*/
|
|
4367
|
+
type FieldMessages<Field extends string, R> = `${Field}` | `${Field}.${ExtractRules<R> & ValidationRuleName}`;
|
|
4368
|
+
/**
|
|
4369
|
+
* Build all valid message keys for a given rules object
|
|
4370
|
+
*/
|
|
4371
|
+
type MessagesForRules<Rules extends Record<string, any>> = { [K in keyof Rules & string]: FieldMessages<K, Rules[K]> }[keyof Rules & string];
|
|
4372
|
+
/**
|
|
4373
|
+
* Make rules align with keys in the data object
|
|
4374
|
+
*/
|
|
4375
|
+
type RulesForData<D extends Record<string, any>> = Partial<Record<DotPaths<D>, ValidationRuleSet>>;
|
|
4376
|
+
//#endregion
|
|
4377
|
+
//#region src/Validation/IValidator.d.ts
|
|
4378
|
+
declare class IValidator<D extends Record<string, any> = any, R extends RulesForData<D> = RulesForData<D>> {
|
|
4379
|
+
constructor(data: D, rules: R, messages: Partial<Record<MessagesForRules<R>, string>>);
|
|
4380
|
+
/**
|
|
4381
|
+
* Validate the data and return the instance
|
|
4382
|
+
*/
|
|
4383
|
+
static make<D extends Record<string, any>, R extends RulesForData<D>>(data: D, rules: R, messages: Partial<Record<MessagesForRules<R>, string>>): IValidator<D, R>;
|
|
4384
|
+
/**
|
|
4385
|
+
* Run the validator and store results.
|
|
4386
|
+
*/
|
|
4387
|
+
passes(): Promise<boolean>;
|
|
4388
|
+
/**
|
|
4389
|
+
* Opposite of passes()
|
|
4390
|
+
*/
|
|
4391
|
+
fails(): Promise<boolean>;
|
|
4392
|
+
/**
|
|
4393
|
+
* Throw if validation fails, else return executed data
|
|
4394
|
+
*
|
|
4395
|
+
* @throws ValidationException if validation fails
|
|
4396
|
+
*/
|
|
4397
|
+
validate(): Promise<Record<string, any>>;
|
|
4398
|
+
/**
|
|
4399
|
+
* Run the validator's rules against its data.
|
|
4400
|
+
* @param bagName
|
|
4401
|
+
* @returns
|
|
4402
|
+
*/
|
|
4403
|
+
validateWithBag(bagName: string): Promise<Record<string, any>>;
|
|
4404
|
+
/**
|
|
4405
|
+
* Stop validation on first failure.
|
|
4406
|
+
*/
|
|
4407
|
+
stopOnFirstFailure(): this;
|
|
4408
|
+
/**
|
|
4409
|
+
* Get the data that passed validation.
|
|
4410
|
+
*/
|
|
4411
|
+
validatedData(): Record<string, any>;
|
|
4412
|
+
/**
|
|
4413
|
+
* Return all validated input.
|
|
4414
|
+
*/
|
|
4415
|
+
validated(): Partial<D>;
|
|
4416
|
+
/**
|
|
4417
|
+
* Return a portion of validated input
|
|
4418
|
+
*/
|
|
4419
|
+
safe(): {
|
|
4420
|
+
only: (keys: string[]) => Partial<D>;
|
|
4421
|
+
except: (keys: string[]) => Partial<D>;
|
|
4422
|
+
};
|
|
4423
|
+
/**
|
|
4424
|
+
* Get the message container for the validator.
|
|
4425
|
+
*/
|
|
4426
|
+
messages(): Promise<Partial<Record<MessagesForRules<R>, string>>>;
|
|
4427
|
+
/**
|
|
4428
|
+
* Add an after validation callback.
|
|
4429
|
+
*
|
|
4430
|
+
* @param callback
|
|
4431
|
+
*/
|
|
4432
|
+
after<C extends ((validator: IValidator<D, R>) => void) | BaseValidationRuleClass>(callback: C | C[]): this;
|
|
4433
|
+
/**
|
|
4434
|
+
* Get all errors.
|
|
4435
|
+
*/
|
|
4436
|
+
errors(): IMessageBag;
|
|
4437
|
+
errorBag(): string;
|
|
4438
|
+
/**
|
|
4439
|
+
* Reset validator with new data.
|
|
4440
|
+
*/
|
|
4441
|
+
setData(data: D): this;
|
|
4442
|
+
/**
|
|
4443
|
+
* Set validation rules.
|
|
4444
|
+
*/
|
|
4445
|
+
setRules(rules: R): this;
|
|
4446
|
+
/**
|
|
4447
|
+
* Add a single rule to existing rules.
|
|
4448
|
+
*/
|
|
4449
|
+
addRule(key: DotPaths<D>, rule: ValidationRuleSet): this;
|
|
4450
|
+
/**
|
|
4451
|
+
* Merge additional rules.
|
|
4452
|
+
*/
|
|
4453
|
+
mergeRules(rules: Record<string, string>): this;
|
|
4454
|
+
/**
|
|
4455
|
+
* Get current data.
|
|
4456
|
+
*/
|
|
4457
|
+
getData(): Record<string, any>;
|
|
4458
|
+
/**
|
|
4459
|
+
* Get current rules.
|
|
4460
|
+
*/
|
|
4461
|
+
getRules(): R;
|
|
4462
|
+
}
|
|
4463
|
+
//#endregion
|
|
4464
|
+
export { AServiceProvider, AbstractConstructor, ActionInput, AppEvent, AppListener, BaseValidationRuleClass, Bindings, CKernel, CacheOptions, CallableConstructor, ClassConstructor, ClassicRouteDefinition, ConcreteConstructor, CustomValidationRules, DotFlatten, DotNestedKeys, DotNestedValue, DotPaths, DriverBuilder, DriverOption, EventHandler, ExceptionConditionCallback, ExceptionConstructor, ExtractClassMethods, ExtractRules, FieldMessages, FlashBag, GenericObject, GenericWithNullableStringValues, IAbstractRouteCollection, IAppBuilder, IApplication, IBinding, IBootstraper, ICallableDispatcher, ICompiledRoute, IContainer, IController, IControllerDispatcher, IDispatcher, IExceptionHandler, IFileBag, IFileInput, IHeaderBag, IHttpContext, IHttpRequest, IHttpResponse, IJob, IKernel, IMessageBag, IMiddleware, IMiddlewareHandler, IModel, IParamBag, IPathName, IPendingResourceRegistration, IPendingSingletonResourceRegistration, IRegisterer, IRequest, IRequestAwareUrl, IResponsable, IResponse, IRoute, IRouteCollection, IRouteRegistrar, IRouter, IServerBag, IServiceProvider, ISessionManager, IUploadedFile, IUrl, IUrlHelpers, IValidationRule, IValidator, InputBag, JobPayload, LimitSpec, ListenerClassConstructor, MergedConstructor, MessagesForRules, MiddlewareIdentifier, MiddlewareList, MixinConstructor, NormalizedAction, OServiceProvider, ParamableValidationRuleName, PathLoader, PlainRuleName, RateLimiterAdapter, RedirectHandler, RenderExceptionCallback, ReportExceptionCallback, RequestMethod, RequestObject, ResourceMethod, ResourceOptions, ResponsableType, ResponseObject, RouteActions, RouteAttributes, RouteEventHandler, RouteMethod, RouteParams, RouterEnd, RulesForData, ServiceProviderConstructor, SessionDriver, TGeneric, ThrottleExceptionCallback, Unlimited, UrlRoutable, UseKey, ValidationMessageProvider, ValidationRuleCallable, ValidationRuleName, ValidationRuleSet };
|