@h3ravel/shared 0.26.0 → 0.26.1

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/dist/index.d.cts DELETED
@@ -1,1161 +0,0 @@
1
- /// <reference path="./app.globals.d.ts" />
2
- import { H3, H3Event, HTTPResponse, Middleware, MiddlewareOptions, serve } from "h3";
3
- import { Edge } from "edge.js";
4
- import { DotNestedKeys as DotNestedKeys$1, DotNestedValue as DotNestedValue$1 } from "@h3ravel/shared";
5
- import { Separator } from "@inquirer/prompts";
6
- import { ChoiceOrSeparatorArray, ChoiceOrSeparatorArray as ChoiceOrSeparatorArray$1 } from "inquirer-autocomplete-standalone";
7
- import { ChalkInstance } from "chalk";
8
-
9
- //#region src/Contracts/ObjContract.d.ts
10
- /**
11
- * Adds a dot prefix to nested keys
12
- */
13
- type DotPrefix<T$1 extends string, U extends string> = T$1 extends '' ? U : `${T$1}.${U}`;
14
- /**
15
- * Converts a union of objects into a single merged object
16
- */
17
- type MergeUnion<T$1> = (T$1 extends any ? (k: T$1) => void : never) extends ((k: infer I) => void) ? { [K in keyof I]: I[K] } : never;
18
- /**
19
- * Flattens nested objects into dotted keys
20
- */
21
- type DotFlatten<T$1, Prefix extends string = ''> = MergeUnion<{ [K in keyof T$1 & string]: T$1[K] extends Record<string, any> ? DotFlatten<T$1[K], DotPrefix<Prefix, K>> : { [P in DotPrefix<Prefix, K>]: T$1[K] } }[keyof T$1 & string]>;
22
- /**
23
- * Builds "nested.key" paths for autocompletion
24
- */
25
- type DotNestedKeys<T$1> = { [K in keyof T$1 & string]: T$1[K] extends object ? `${K}` | `${K}.${DotNestedKeys<T$1[K]>}` : `${K}` }[keyof T$1 & string];
26
- /**
27
- * Retrieves type at a given dot-path
28
- */
29
- type DotNestedValue<T$1, Path extends string> = Path extends `${infer Key}.${infer Rest}` ? Key extends keyof T$1 ? DotNestedValue<T$1[Key], Rest> : never : Path extends keyof T$1 ? T$1[Path] : never;
30
- /**
31
- * A generic object type that supports nullable string values
32
- */
33
- interface GenericWithNullableStringValues {
34
- [name: string]: string | undefined;
35
- }
36
- //#endregion
37
- //#region src/Contracts/IContainer.d.ts
38
- /**
39
- * Interface for the Container contract, defining methods for dependency injection and service resolution.
40
- */
41
- interface IContainer {
42
- /**
43
- * Binds a transient service to the container.
44
- * @param key - The key or constructor for the service.
45
- * @param factory - The factory function to create the service instance.
46
- */
47
- bind<T>(key: new (...args: any[]) => T, factory: () => T): void;
48
- bind<T extends UseKey>(key: T, factory: () => Bindings[T]): void;
49
- /**
50
- * Binds a singleton service to the container.
51
- * @param key - The key or constructor for the service.
52
- * @param factory - The factory function to create the singleton instance.
53
- */
54
- singleton<T extends UseKey>(key: T | (new (...args: any[]) => Bindings[T]), factory: () => Bindings[T]): void;
55
- /**
56
- * Resolves a service from the container.
57
- * @param key - The key or constructor for the service.
58
- * @returns The resolved service instance.
59
- */
60
- make<T extends UseKey, X = undefined>(key: T | (new (..._args: any[]) => Bindings[T])): X extends undefined ? Bindings[T] : X;
61
- /**
62
- * Checks if a service is registered in the container.
63
- * @param key - The key to check.
64
- * @returns True if the service is registered, false otherwise.
65
- */
66
- has(key: UseKey): boolean;
67
- }
68
- //#endregion
69
- //#region src/Contracts/IServiceProvider.d.ts
70
- interface IServiceProvider {
71
- /**
72
- * Unique Identifier for service providers
73
- */
74
- uid?: number;
75
- /**
76
- * Sort order
77
- */
78
- order?: `before:${string}` | `after:${string}` | string | undefined;
79
- /**
80
- * Sort priority
81
- */
82
- priority?: number;
83
- /**
84
- * Indicate that this service provider only runs in console
85
- */
86
- runsInConsole?: boolean;
87
- /**
88
- * List of registered console commands
89
- */
90
- registeredCommands?: (new (app: IApplication, kernel: any) => any)[];
91
- /**
92
- * An array of console commands to register.
93
- */
94
- commands?(commands: (new (app: IApplication, kernel: any) => any)[]): void;
95
- /**
96
- * Register bindings to the container.
97
- * Runs before boot().
98
- */
99
- register?(...app: unknown[]): void | Promise<void>;
100
- /**
101
- * Perform post-registration booting of services.
102
- * Runs after all providers have been registered.
103
- */
104
- boot?(...app: unknown[]): void | Promise<void>;
105
- }
106
- //#endregion
107
- //#region src/Contracts/IApplication.d.ts
108
- type IPathName = 'views' | 'routes' | 'assets' | 'base' | 'public' | 'storage' | 'config' | 'database';
109
- interface IApplication extends IContainer {
110
- /**
111
- * Registers configured service providers.
112
- */
113
- registerConfiguredProviders(): Promise<void>;
114
- /**
115
- * Registers an array of external service provider classes.
116
- * @param providers - Array of service provider constructor functions.
117
- */
118
- registerProviders(providers: Array<(new <A = IApplication, S = IServiceProvider>(app: A) => S)>): void;
119
- /**
120
- * Registers a single service provider.
121
- * @param provider - The service provider instance to register.
122
- */
123
- /**
124
- * Boots all registered providers.
125
- */
126
- boot(): Promise<this>;
127
- /**
128
- * Gets the base path of the application.
129
- * @returns The base path as a string.
130
- */
131
- getBasePath(): string;
132
- /**
133
- * Retrieves a path by name, optionally appending a sub-path.
134
- * @param name - The name of the path property.
135
- * @param pth - Optional sub-path to append.
136
- * @returns The resolved path as a string.
137
- */
138
- getPath(name: string, pth?: string): string;
139
- /**
140
- * Sets a path for a given name.
141
- * @param name - The name of the path property.
142
- * @param path - The path to set.
143
- * @returns
144
- */
145
- setPath(name: IPathName, path: string): void;
146
- /**
147
- * Gets the version of the application or TypeScript.
148
- * @param key - The key to retrieve ('app' or 'ts').
149
- * @returns The version string or undefined.
150
- */
151
- getVersion(key: string): string | undefined;
152
- }
153
- //#endregion
154
- //#region src/Contracts/IResponse.d.ts
155
- /**
156
- * Interface for the Response contract, defining methods for handling HTTP responses.
157
- */
158
- interface IResponse {
159
- /**
160
- * The current app instance
161
- */
162
- app: IApplication;
163
- /**
164
- * Sets the HTTP status code for the response.
165
- * @param code - The HTTP status code.
166
- * @returns The instance for method chaining.
167
- */
168
- setStatusCode(code: number): this;
169
- /**
170
- * Sets a response header.
171
- * @param name - The header name.
172
- * @param value - The header value.
173
- * @returns The instance for method chaining.
174
- */
175
- setHeader(name: string, value: string): this;
176
- /**
177
- * Sends an HTML response.
178
- * @param content - The HTML content to send.
179
- * @returns The HTML content.
180
- */
181
- html(content: string): HTTPResponse;
182
- /**
183
- * Sends a JSON response.
184
- * @param data - The data to send as JSON.
185
- * @returns The input data.
186
- */
187
- json<T = unknown>(data: T): T;
188
- /**
189
- * Sends a plain text response.
190
- * @param data - The text content to send.
191
- * @returns The text content.
192
- */
193
- text(data: string): string;
194
- /**
195
- * Redirects to another URL.
196
- * @param url - The URL to redirect to.
197
- * @param status - The HTTP status code for the redirect (default: 302).
198
- * @returns The redirect URL.
199
- */
200
- redirect(url: string, status?: number): HTTPResponse;
201
- /**
202
- * Gets the underlying event object or a specific property of it.
203
- * @param key - Optional key to access a nested property of the event.
204
- * @returns The entire event object or the value of the specified property.
205
- */
206
- getEvent(): H3Event;
207
- getEvent<K extends DotNestedKeys$1<H3Event>>(key: K): DotNestedValue$1<H3Event, K>;
208
- }
209
- //#endregion
210
- //#region src/Contracts/IHttp.d.ts
211
- type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'patch' | 'apiResource' | 'group' | 'route';
212
- type RequestMethod = 'HEAD' | 'GET' | 'PUT' | 'DELETE' | 'TRACE' | 'OPTIONS' | 'PURGE' | 'POST' | 'CONNECT' | 'PATCH';
213
- type RequestObject = Record<string, any>;
214
- type ExtractControllerMethods<T$1> = { [K in keyof T$1]: T$1[K] extends ((...args: any[]) => any) ? K : never }[keyof T$1];
215
- /**
216
- * Interface for the Router contract, defining methods for HTTP routing.
217
- */
218
- declare class IRouter {
219
- /**
220
- * Registers a GET route.
221
- * @param path - The route path.
222
- * @param definition - The handler function or [controller class, method] array.
223
- * @param name - Optional route name.
224
- * @param middleware - Optional middleware array.
225
- */
226
- get<C extends new (...args: any) => any>(path: string, definition: EventHandler | [C, methodName: ExtractControllerMethods<InstanceType<C>>], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
227
- /**
228
- * Registers a POST route.
229
- * @param path - The route path.
230
- * @param definition - The handler function or [controller class, method] array.
231
- * @param name - Optional route name.
232
- * @param middleware - Optional middleware array.
233
- */
234
- post<C extends new (...args: any) => any>(path: string, definition: EventHandler | [C, methodName: ExtractControllerMethods<InstanceType<C>>], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
235
- /**
236
- * Registers a PUT route.
237
- * @param path - The route path.
238
- * @param definition - The handler function or [controller class, method] array.
239
- * @param name - Optional route name.
240
- * @param middleware - Optional middleware array.
241
- */
242
- put<C extends new (...args: any) => any>(path: string, definition: EventHandler | [C, methodName: ExtractControllerMethods<InstanceType<C>>], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
243
- /**
244
- * Registers a route that responds to HTTP PATCH requests.
245
- *
246
- * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
247
- * @param definition Either:
248
- * - An EventHandler function
249
- * - A tuple: [ControllerClass, methodName]
250
- * @param name Optional route name (for URL generation or referencing).
251
- * @param middleware Optional array of middleware functions to execute before the handler.
252
- */
253
- patch<C extends new (...args: any) => any>(path: string, definition: EventHandler | [C, methodName: ExtractControllerMethods<InstanceType<C>>], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
254
- /**
255
- * Registers a DELETE route.
256
- * @param path - The route path.
257
- * @param definition - The handler function or [controller class, method] array.
258
- * @param name - Optional route name.
259
- * @param middleware - Optional middleware array.
260
- */
261
- delete<C extends new (...args: any) => any>(path: string, definition: EventHandler | [C, methodName: ExtractControllerMethods<InstanceType<C>>], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
262
- /**
263
- * Registers an API resource with standard CRUD routes.
264
- * @param path - The base path for the resource.
265
- * @param controller - The controller class handling the resource.
266
- * @param middleware - Optional middleware array.
267
- */
268
- apiResource(path: string, controller: new (app: IApplication) => IController, middleware?: IMiddleware[]): Omit<this, RouterEnd | 'name'>;
269
- /**
270
- * Generates a URL for a named route.
271
- * @param name - The name of the route.
272
- * @param params - Optional parameters to replace in the route path.
273
- * @returns The generated URL or undefined if the route is not found.
274
- */
275
- route(name: string, params?: Record<string, string>): string | undefined;
276
- /**
277
- * Set the name of the current route
278
- *
279
- * @param name
280
- */
281
- name(name: string): this;
282
- /**
283
- * Groups routes with shared prefix or middleware.
284
- * @param options - Configuration for prefix or middleware.
285
- * @param callback - Callback function defining grouped routes.
286
- */
287
- group(options: {
288
- prefix?: string;
289
- middleware?: EventHandler[];
290
- }, callback: () => this): this;
291
- /**
292
- * Registers middleware for a specific path.
293
- * @param path - The path to apply the middleware.
294
- * @param handler - The middleware handler.
295
- * @param opts - Optional middleware options.
296
- */
297
- middleware(path: Middleware, opts?: Middleware | MiddlewareOptions): this;
298
- middleware(path: string | IMiddleware[] | Middleware, handler: Middleware | MiddlewareOptions, opts?: MiddlewareOptions): this;
299
- }
300
- /**
301
- * Represents the HTTP context for a single request lifecycle.
302
- * Encapsulates the application instance, request, and response objects.
303
- */
304
- declare class HttpContext {
305
- app: IApplication;
306
- request: IRequest;
307
- response: IResponse;
308
- private static contexts;
309
- constructor(app: IApplication, request: IRequest, response: IResponse);
310
- /**
311
- * Factory method to create a new HttpContext instance from a context object.
312
- * @param ctx - Object containing app, request, and response
313
- * @returns A new HttpContext instance
314
- */
315
- static init(ctx: {
316
- app: IApplication;
317
- request: IRequest;
318
- response: IResponse;
319
- }, event?: unknown): HttpContext;
320
- /**
321
- * Retrieve an existing HttpContext instance for an event, if any.
322
- */
323
- static get(event: unknown): HttpContext | undefined;
324
- /**
325
- * Delete the cached context for a given event (optional cleanup).
326
- */
327
- static forget(event: unknown): void;
328
- }
329
- /**
330
- * Type for EventHandler, representing a function that handles an H3 event.
331
- */
332
- type EventHandler = (ctx: HttpContext) => any;
333
- type RouteEventHandler = (...args: any[]) => any;
334
- /**
335
- * Defines the contract for all controllers.
336
- * Any controller implementing this must define these methods.
337
- */
338
- declare class IController {
339
- show?(...ctx: any[]): any;
340
- index?(...ctx: any[]): any;
341
- store?(...ctx: any[]): any;
342
- update?(...ctx: any[]): any;
343
- destroy?(...ctx: any[]): any;
344
- }
345
- /**
346
- * Defines the contract for all middlewares.
347
- * Any middleware implementing this must define these methods.
348
- */
349
- declare class IMiddleware {
350
- handle(context: HttpContext, next: () => Promise<any>): Promise<any>;
351
- }
352
- //#endregion
353
- //#region src/Contracts/IParamBag.d.ts
354
- declare class IParamBag implements Iterable<[string, any]> {
355
- /**
356
- * The current H3 H3Event instance
357
- */
358
- readonly event: H3Event;
359
- constructor(parameters: RequestObject | undefined,
360
- /**
361
- * The current H3 H3Event instance
362
- */
363
- event: H3Event);
364
- /**
365
- * Returns the parameters.
366
- * @
367
- * @param key The name of the parameter to return or null to get them all
368
- *
369
- * @throws BadRequestException if the value is not an array
370
- */
371
- all(key?: string): any;
372
- get(key: string, defaultValue?: any): any;
373
- set(key: string, value: any): void;
374
- /**
375
- * Returns true if the parameter is defined.
376
- *
377
- * @param key
378
- */
379
- has(key: string): boolean;
380
- /**
381
- * Removes a parameter.
382
- *
383
- * @param key
384
- */
385
- remove(key: string): void;
386
- /**
387
- *
388
- * Returns the parameter as string.
389
- *
390
- * @param key
391
- * @param defaultValue
392
- * @throws UnexpectedValueException if the value cannot be converted to string
393
- * @returns
394
- */
395
- getString(key: string, defaultValue?: string): string;
396
- /**
397
- * Returns the parameter value converted to integer.
398
- *
399
- * @param key
400
- * @param defaultValue
401
- * @throws UnexpectedValueException if the value cannot be converted to integer
402
- */
403
- getInt(key: string, defaultValue?: number): number;
404
- /**
405
- * Returns the parameter value converted to boolean.
406
- *
407
- * @param key
408
- * @param defaultValue
409
- * @throws UnexpectedValueException if the value cannot be converted to a boolean
410
- */
411
- getBoolean(key: string, defaultValue?: boolean): boolean;
412
- /**
413
- * Returns the alphabetic characters of the parameter value.
414
- *
415
- * @param key
416
- * @param defaultValue
417
- * @throws UnexpectedValueException if the value cannot be converted to string
418
- */
419
- getAlpha(key: string, defaultValue?: string): string;
420
- /**
421
- * Returns the alphabetic characters and digits of the parameter value.
422
- *
423
- * @param key
424
- * @param defaultValue
425
- * @throws UnexpectedValueException if the value cannot be converted to string
426
- */
427
- getAlnum(key: string, defaultValue?: string): string;
428
- /**
429
- * Returns the digits of the parameter value.
430
- *
431
- * @param key
432
- * @param defaultValue
433
- * @throws UnexpectedValueException if the value cannot be converted to string
434
- * @returns
435
- **/
436
- getDigits(key: string, defaultValue?: string): string;
437
- /**
438
- * Returns the parameter keys.
439
- */
440
- keys(): string[];
441
- /**
442
- * Replaces the current parameters by a new set.
443
- */
444
- replace(parameters?: RequestObject): void;
445
- /**
446
- * Adds parameters.
447
- */
448
- add(parameters?: RequestObject): void;
449
- /**
450
- * Returns the number of parameters.
451
- */
452
- count(): number;
453
- /**
454
- * Returns an iterator for parameters.
455
- *
456
- * @returns
457
- */
458
- [Symbol.iterator](): ArrayIterator<[string, any]>;
459
- }
460
- //#endregion
461
- //#region src/Contracts/IUploadedFile.d.ts
462
- declare class IUploadedFile {
463
- originalName: string;
464
- mimeType: string;
465
- size: number;
466
- content: File;
467
- constructor(originalName: string, mimeType: string, size: number, content: File);
468
- static createFromBase(file: File): IUploadedFile;
469
- /**
470
- * Save to disk (Node environment only)
471
- */
472
- moveTo(destination: string): Promise<void>;
473
- }
474
- //#endregion
475
- //#region src/Contracts/IRequest.d.ts
476
- type RequestObject$1 = Record<string, any>;
477
- /**
478
- * Interface for the Request contract, defining methods for handling HTTP request data.
479
- */
480
- declare class IRequest {
481
- /**
482
- * The current app instance
483
- */
484
- app: IApplication;
485
- /**
486
- * Parsed request body
487
- */
488
- body: unknown;
489
- /**
490
- * Gets route parameters.
491
- * @returns An object containing route parameters.
492
- */
493
- params: NonNullable<H3Event['context']['params']>;
494
- /**
495
- * Uploaded files (FILES).
496
- */
497
- constructor(
498
- /**
499
- * The current H3 H3Event instance
500
- */
501
- event: H3Event,
502
- /**
503
- * The current app instance
504
- */
505
- app: IApplication);
506
- /**
507
- * Factory method to create a Request instance from an H3Event.
508
- */
509
- static create(
510
- /**
511
- * The current H3 H3Event instance
512
- */
513
- event: H3Event,
514
- /**
515
- * The current app instance
516
- */
517
- app: IApplication): Promise<Request>;
518
- /**
519
- * Sets the parameters for this request.
520
- *
521
- * This method also re-initializes all properties.
522
- *
523
- * @param attributes
524
- * @param cookies The COOKIE parameters
525
- * @param files The FILES parameters
526
- * @param server The SERVER parameters
527
- * @param content The raw body data
528
- */
529
- initialize(): Promise<void>;
530
- /**
531
- * Retrieve all data from the instance (query + body).
532
- */
533
- all<T = Record<string, any>>(keys?: string | string[]): T;
534
- /**
535
- * Retrieve an input item from the request.
536
- *
537
- * @param key
538
- * @param defaultValue
539
- * @returns
540
- */
541
- input<K extends string | undefined>(key?: K, defaultValue?: any): K extends undefined ? RequestObject$1 : any;
542
- /**
543
- * Retrieve a file from the request.
544
- *
545
- * By default a single `UploadedFile` instance will always be returned by
546
- * the method (first file in property when there are multiple), unless
547
- * the `expectArray` parameter is set to true, in which case, the method
548
- * returns an `UploadedFile[]` array.
549
- *
550
- * @param key
551
- * @param defaultValue
552
- * @param expectArray set to true to return an `UploadedFile[]` array.
553
- * @returns
554
- */
555
- file<K extends string | undefined = undefined, E extends boolean | undefined = undefined>(key?: K, defaultValue?: any, expectArray?: E): K extends undefined ? Record<string, E extends true ? IUploadedFile[] : IUploadedFile> : E extends true ? IUploadedFile[] : IUploadedFile;
556
- /**
557
- * Determine if the uploaded data contains a file.
558
- *
559
- * @param key
560
- * @return boolean
561
- */
562
- hasFile(key: string): boolean;
563
- /**
564
- * Get an object with all the files on the request.
565
- */
566
- allFiles(): Record<string, IUploadedFile | IUploadedFile[]>;
567
- /**
568
- * Extract and convert uploaded files from FormData.
569
- */
570
- convertUploadedFiles(files: Record<string, IUploadedFile | IUploadedFile[]>): Record<string, IUploadedFile | IUploadedFile[]>;
571
- /**
572
- * Determine if the data contains a given key.
573
- *
574
- * @param keys
575
- * @returns
576
- */
577
- has(keys: string[] | string): boolean;
578
- /**
579
- * Determine if the instance is missing a given key.
580
- */
581
- missing(key: string | string[]): boolean;
582
- /**
583
- * Get a subset containing the provided keys with values from the instance data.
584
- *
585
- * @param keys
586
- * @returns
587
- */
588
- only<T = Record<string, any>>(keys: string[]): T;
589
- /**
590
- * Get all of the data except for a specified array of items.
591
- *
592
- * @param keys
593
- * @returns
594
- */
595
- except<T = Record<string, any>>(keys: string[]): T;
596
- /**
597
- * Merges new input data into the current request's input source.
598
- *
599
- * @param input - An object containing key-value pairs to merge.
600
- * @returns this - For fluent chaining.
601
- */
602
- merge(input: Record<string, any>): this;
603
- /**
604
- * Merge new input into the request's input, but only when that key is missing from the request.
605
- *
606
- * @param input
607
- */
608
- mergeIfMissing(input: Record<string, any>): this;
609
- /**
610
- * Get the keys for all of the input and files.
611
- */
612
- keys(): string[];
613
- /**
614
- * Determine if the request is sending JSON.
615
- *
616
- * @return bool
617
- */
618
- isJson(): boolean;
619
- /**
620
- * Determine if the current request probably expects a JSON response.
621
- *
622
- * @returns
623
- */
624
- expectsJson(): boolean;
625
- /**
626
- * Determine if the current request is asking for JSON.
627
- *
628
- * @returns
629
- */
630
- wantsJson(): boolean;
631
- /**
632
- * Gets a list of content types acceptable by the client browser in preferable order.
633
- * @returns {string[]}
634
- */
635
- getAcceptableContentTypes(): string[];
636
- /**
637
- * Determine if the request is the result of a PJAX call.
638
- *
639
- * @return bool
640
- */
641
- pjax(): boolean;
642
- /**
643
- * Returns true if the request is an XMLHttpRequest (AJAX).
644
- *
645
- * @alias isXmlHttpRequest()
646
- * @returns {boolean}
647
- */
648
- ajax(): boolean;
649
- /**
650
- * Returns true if the request is an XMLHttpRequest (AJAX).
651
- */
652
- isXmlHttpRequest(): boolean;
653
- /**
654
- * Returns the value of the requested header.
655
- */
656
- getHeader(name: string): string | undefined | null;
657
- /**
658
- * Checks if the request method is of specified type.
659
- *
660
- * @param method Uppercase request method (GET, POST etc)
661
- */
662
- isMethod(method: string): boolean;
663
- /**
664
- * Checks whether or not the method is safe.
665
- *
666
- * @see https://tools.ietf.org/html/rfc7231#section-4.2.1
667
- */
668
- isMethodSafe(): boolean;
669
- /**
670
- * Checks whether or not the method is idempotent.
671
- */
672
- isMethodIdempotent(): boolean;
673
- /**
674
- * Checks whether the method is cacheable or not.
675
- *
676
- * @see https://tools.ietf.org/html/rfc7231#section-4.2.3
677
- */
678
- isMethodCacheable(): boolean;
679
- /**
680
- * Gets the request "intended" method.
681
- *
682
- * If the X-HTTP-Method-Override header is set, and if the method is a POST,
683
- * then it is used to determine the "real" intended HTTP method.
684
- *
685
- * The _method request parameter can also be used to determine the HTTP method,
686
- * but only if enableHttpMethodParameterOverride() has been called.
687
- *
688
- * The method is always an uppercased string.
689
- *
690
- * @see getRealMethod()
691
- */
692
- getMethod(): RequestMethod;
693
- /**
694
- * Gets the "real" request method.
695
- *
696
- * @see getMethod()
697
- */
698
- getRealMethod(): RequestMethod;
699
- /**
700
- * Get the client IP address.
701
- */
702
- ip(): string | undefined;
703
- /**
704
- * Get a URI instance for the request.
705
- */
706
- uri(): unknown;
707
- /**
708
- * Get the full URL for the request.
709
- */
710
- fullUrl(): string;
711
- /**
712
- * Return the Request instance.
713
- */
714
- instance(): this;
715
- /**
716
- * Get the request method.
717
- */
718
- method(): RequestMethod;
719
- /**
720
- * Get the JSON payload for the request.
721
- *
722
- * @param key
723
- * @param defaultValue
724
- * @return {InputBag}
725
- */
726
- json<K extends string | undefined = undefined>(key?: string, defaultValue?: any): K extends undefined ? IParamBag : any;
727
- /**
728
- * Returns the request body content.
729
- *
730
- * @param asStream If true, returns a ReadableStream instead of the parsed string
731
- * @return {string | ReadableStream | Promise<string | ReadableStream>}
732
- */
733
- getContent(asStream?: boolean): string | ReadableStream;
734
- /**
735
- * Gets a "parameter" value from any bag.
736
- *
737
- * This method is mainly useful for libraries that want to provide some flexibility. If you don't need the
738
- * flexibility in controllers, it is better to explicitly get request parameters from the appropriate
739
- * public property instead (attributes, query, request).
740
- *
741
- * Order of precedence: PATH (routing placeholders or custom attributes), GET, POST
742
- *
743
- * @internal use explicit input sources instead
744
- */
745
- get(key: string, defaultValue?: any): any;
746
- /**
747
- * Enables support for the _method request parameter to determine the intended HTTP method.
748
- *
749
- * Be warned that enabling this feature might lead to CSRF issues in your code.
750
- * Check that you are using CSRF tokens when required.
751
- * If the HTTP method parameter override is enabled, an html-form with method "POST" can be altered
752
- * and used to send a "PUT" or "DELETE" request via the _method request parameter.
753
- * If these methods are not protected against CSRF, this presents a possible vulnerability.
754
- *
755
- * The HTTP method can only be overridden when the real HTTP method is POST.
756
- */
757
- static enableHttpMethodParameterOverride(): void;
758
- /**
759
- * Checks whether support for the _method request parameter is enabled.
760
- */
761
- static getHttpMethodParameterOverride(): boolean;
762
- /**
763
- * Dump the items.
764
- *
765
- * @param keys
766
- * @return this
767
- */
768
- dump(...keys: any[]): this;
769
- /**
770
- * Get the base event
771
- */
772
- getEvent(): H3Event;
773
- getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
774
- }
775
- //#endregion
776
- //#region src/Utils/PathLoader.d.ts
777
- declare class PathLoader {
778
- private paths;
779
- /**
780
- * Dynamically retrieves a path property from the class.
781
- * Any property ending with "Path" is accessible automatically.
782
- *
783
- * @param name - The base name of the path property
784
- * @param prefix - The base path to prefix to the path
785
- * @returns
786
- */
787
- getPath(name: IPathName, prefix?: string): string;
788
- /**
789
- * Programatically set the paths.
790
- *
791
- * @param name - The base name of the path property
792
- * @param path - The new path
793
- * @param base - The base path to include to the path
794
- */
795
- setPath(name: IPathName, path: string, base?: string): void;
796
- }
797
- //#endregion
798
- //#region src/Contracts/BindingsContract.d.ts
799
- type RemoveIndexSignature<T$1> = { [K in keyof T$1 as string extends K ? never : number extends K ? never : K]: T$1[K] };
800
- type Bindings = {
801
- [key: string]: any;
802
- [key: `app.${string}`]: any;
803
- env(): NodeJS.ProcessEnv;
804
- env<T extends string>(key: T, def?: any): any;
805
- view(viewPath: string, params?: Record<string, any>): Promise<HTTPResponse>;
806
- edge: Edge;
807
- asset(key: string, def?: string): string;
808
- router: IRouter;
809
- config: {
810
- get<X extends Record<string, any>>(): X;
811
- get<X extends Record<string, any>, T extends Extract<keyof X, string>>(key: T, def?: any): X[T];
812
- set<T extends string>(key: T, value: any): void;
813
- load?(): any;
814
- };
815
- 'http.app': H3;
816
- 'path.base': string;
817
- 'load.paths': PathLoader;
818
- 'http.serve': typeof serve;
819
- 'http.request': IRequest;
820
- 'http.response': IResponse;
821
- };
822
- type UseKey = keyof RemoveIndexSignature<Bindings>;
823
- //#endregion
824
- //#region src/Contracts/PromptsContract.d.ts
825
- type Choice<Value> = {
826
- value: Value;
827
- name?: string;
828
- description?: string;
829
- short?: string;
830
- disabled?: boolean | string;
831
- type?: never;
832
- };
833
- type ISeparator = Separator;
834
- type Choices = readonly (string | Separator)[] | readonly (Separator | Choice<string>)[];
835
- //#endregion
836
- //#region src/Contracts/Router.d.ts
837
- type RouteMethod = 'get' | 'head' | 'put' | 'patch' | 'post' | 'delete';
838
- interface RouteDefinition {
839
- method: RouteMethod;
840
- path: string;
841
- name?: string | undefined;
842
- handler: EventHandler;
843
- signature: [string, string | undefined];
844
- }
845
- //#endregion
846
- //#region src/Utils/Logger.d.ts
847
- declare class Logger {
848
- /**
849
- * Global verbosity configuration
850
- */
851
- private static verbosity;
852
- private static isQuiet;
853
- private static isSilent;
854
- /**
855
- * Configure global verbosity levels
856
- */
857
- static configure(options?: {
858
- verbosity?: number;
859
- quiet?: boolean;
860
- silent?: boolean;
861
- }): void;
862
- /**
863
- * Check if output should be suppressed
864
- */
865
- private static shouldSuppressOutput;
866
- /**
867
- * Logs the message in two columns
868
- *
869
- * @param name
870
- * @param value
871
- * @param log If set to false, array of [name, dots, value] output will be returned and not logged
872
- * @returns
873
- */
874
- static twoColumnDetail(name: string, value: string, log?: true, spacer?: string): void;
875
- static twoColumnDetail(name: string, value: string, log?: false, spacer?: string): [string, string, string];
876
- /**
877
- * Logs the message in two columns
878
- *
879
- * @param name
880
- * @param desc
881
- * @param width
882
- * @param log If set to false, array of [name, dots, value] output will be returned and not logged
883
- * @returns
884
- */
885
- static describe(name: string, desc: string, width?: number, log?: true): void;
886
- static describe(name: string, desc: string, width?: number, log?: false): [string, string, string];
887
- /**
888
- * Logs the message in two columns but allways passing status
889
- *
890
- * @param name
891
- * @param value
892
- * @param status
893
- * @param exit
894
- * @param preserveCol
895
- */
896
- static split(name: string, value: string, status?: 'success' | 'info' | 'error', exit?: boolean, preserveCol?: boolean): void;
897
- /**
898
- * Wraps text with chalk
899
- *
900
- * @param txt
901
- * @param color
902
- * @param preserveCol
903
- * @returns
904
- */
905
- static textFormat(txt: unknown, color: (txt: string) => string, preserveCol?: boolean): string;
906
- /**
907
- * Logs a success message
908
- *
909
- * @param msg
910
- * @param exit
911
- * @param preserveCol
912
- */
913
- static success(msg: any, exit?: boolean, preserveCol?: boolean): void;
914
- /**
915
- * Logs an informational message
916
- *
917
- * @param msg
918
- * @param exit
919
- * @param preserveCol
920
- */
921
- static info(msg: any, exit?: boolean, preserveCol?: boolean): void;
922
- /**
923
- * Logs an error message
924
- *
925
- * @param msg
926
- * @param exit
927
- * @param preserveCol
928
- */
929
- static error(msg: string | string[] | Error & {
930
- detail?: string;
931
- }, exit?: boolean, preserveCol?: boolean): void;
932
- /**
933
- * Logs a warning message
934
- *
935
- * @param msg
936
- * @param exit
937
- * @param preserveCol
938
- */
939
- static warn(msg: any, exit?: boolean, preserveCol?: boolean): void;
940
- /**
941
- * Logs a debug message (only shown with verbosity >= 3)
942
- *
943
- * @param msg
944
- * @param exit
945
- * @param preserveCol
946
- */
947
- static debug<M = any>(msg: M | M[], exit?: boolean, preserveCol?: boolean): void;
948
- /**
949
- * Terminates the process
950
- */
951
- static quiet(): void;
952
- static chalker(styles: LoggerChalk[]): (input: any) => string;
953
- /**
954
- * Parse an array formated message and logs it
955
- *
956
- * @param config
957
- * @param joiner
958
- * @param log If set to false, string output will be returned and not logged
959
- * @param sc color to use ue on split text if : is found
960
- */
961
- static parse(config: LoggerParseSignature, joiner?: string, log?: true, sc?: LoggerChalk): void;
962
- static parse(config: LoggerParseSignature, joiner?: string, log?: false, sc?: LoggerChalk): string;
963
- /**
964
- * Ouput formater object or format the output
965
- *
966
- * @returns
967
- */
968
- static log: LoggerLog;
969
- }
970
- //#endregion
971
- //#region src/Contracts/Utils.d.ts
972
- type LoggerChalk = keyof ChalkInstance | ChalkInstance | (keyof ChalkInstance)[];
973
- type LoggerParseSignature = [string, LoggerChalk][];
974
- /**
975
- * Ouput formater object or format the output
976
- *
977
- * @param config
978
- * @param joiner
979
- * @param log If set to false, string output will be returned and not logged
980
- * @param sc color to use ue on split text if : is found
981
- *
982
- * @returns
983
- */
984
- interface LoggerLog {
985
- (): typeof Logger;
986
- <L extends boolean>(config: string, joiner: LoggerChalk, log?: L, sc?: LoggerChalk): L extends true ? void : string;
987
- <L extends boolean>(config: LoggerParseSignature, joiner?: string, log?: L, sc?: LoggerChalk): L extends true ? void : string;
988
- <L extends boolean>(config?: LoggerParseSignature, joiner?: string, log?: L, sc?: LoggerChalk): L extends true ? void : string | Logger;
989
- }
990
- //#endregion
991
- //#region src/Utils/EnvParser.d.ts
992
- declare class EnvParser {
993
- static parse(initial: GenericWithNullableStringValues): {
994
- [name: string]: string | undefined;
995
- };
996
- static parseValue(value: any): any;
997
- }
998
- //#endregion
999
- //#region src/Utils/FileSystem.d.ts
1000
- declare class FileSystem {
1001
- static findModulePkg(moduleId: string, cwd?: string): string | undefined;
1002
- /**
1003
- * Check if file exists
1004
- *
1005
- * @param path
1006
- * @returns
1007
- */
1008
- static fileExists(path: string): Promise<boolean>;
1009
- /**
1010
- * Recursively find files starting from given cwd
1011
- *
1012
- * @param name
1013
- * @param extensions
1014
- * @param cwd
1015
- *
1016
- * @returns
1017
- */
1018
- static resolveFileUp(name: string, extensions: string[] | ((dir: string, filesNames: string[]) => string | false), cwd?: string): string | undefined;
1019
- }
1020
- //#endregion
1021
- //#region src/Utils/Prompts.d.ts
1022
- declare class Prompts extends Logger {
1023
- /**
1024
- * Allows users to pick from a predefined set of choices when asked a question.
1025
- */
1026
- static choice(
1027
- /**
1028
- * Message to dislpay
1029
- */
1030
- message: string,
1031
- /**
1032
- * The choices available to the user
1033
- */
1034
- choices: Choices,
1035
- /**
1036
- * Item index front of which the cursor will initially appear
1037
- */
1038
- defaultIndex?: number): Promise<string>;
1039
- /**
1040
- * Ask the user for a simple "yes or no" confirmation.
1041
- * By default, this method returns `false`. However, if the user enters y or yes
1042
- * in response to the prompt, the method would return `true`.
1043
- */
1044
- static confirm(
1045
- /**
1046
- * Message to dislpay
1047
- */
1048
- message: string,
1049
- /**
1050
- * The default value
1051
- */
1052
- def?: boolean | undefined): Promise<boolean>;
1053
- /**
1054
- * Prompt the user with the given question, accept their input,
1055
- * and then return the user's input back to your command.
1056
- */
1057
- static ask(
1058
- /**
1059
- * Message to dislpay
1060
- */
1061
- message: string,
1062
- /**
1063
- * The default value
1064
- */
1065
- def?: string | undefined): Promise<string>;
1066
- /**
1067
- * Prompt the user with the given question, accept their input which
1068
- * will not be visible to them as they type in the console,
1069
- * and then return the user's input back to your command.
1070
- */
1071
- static secret(
1072
- /**
1073
- * Message to dislpay
1074
- */
1075
- message: string,
1076
- /**
1077
- * Mask the user input
1078
- *
1079
- * @default true
1080
- */
1081
- mask?: string | boolean): Promise<string>;
1082
- /**
1083
- * Provide auto-completion for possible choices.
1084
- * The user can still provide any answer, regardless of the auto-completion hints.
1085
- */
1086
- static anticipate(
1087
- /**
1088
- * Message to dislpay
1089
- */
1090
- message: string,
1091
- /**
1092
- * The source of completions
1093
- */
1094
- source: string[] | ((input?: string | undefined) => Promise<ChoiceOrSeparatorArray$1<any>>),
1095
- /**
1096
- * Set a default value
1097
- */
1098
- def?: string): Promise<any>;
1099
- }
1100
- //#endregion
1101
- //#region src/Utils/Resolver.d.ts
1102
- declare class Resolver {
1103
- static getPakageInstallCommand(pkg?: string): Promise<string>;
1104
- static getInstallCommand(pkg: string): Promise<string>;
1105
- /**
1106
- * Create a hash for a function or an object
1107
- *
1108
- * @param provider
1109
- * @returns
1110
- */
1111
- static hashObjectOrFunction(provider: object | ((..._: any[]) => any)): string;
1112
- }
1113
- //#endregion
1114
- //#region src/Utils/scripts.d.ts
1115
- declare const mainTsconfig: {
1116
- extends: string;
1117
- compilerOptions: {
1118
- baseUrl: string;
1119
- outDir: string;
1120
- paths: {
1121
- 'src/*': string[];
1122
- 'App/*': string[];
1123
- 'root/*': string[];
1124
- 'routes/*': string[];
1125
- 'config/*': string[];
1126
- 'resources/*': string[];
1127
- };
1128
- target: string;
1129
- module: string;
1130
- moduleResolution: string;
1131
- esModuleInterop: boolean;
1132
- strict: boolean;
1133
- allowJs: boolean;
1134
- skipLibCheck: boolean;
1135
- resolveJsonModule: boolean;
1136
- noEmit: boolean;
1137
- experimentalDecorators: boolean;
1138
- emitDecoratorMetadata: boolean;
1139
- };
1140
- include: string[];
1141
- exclude: string[];
1142
- };
1143
- declare const baseTsconfig: {
1144
- extends: string;
1145
- };
1146
- declare const packageJsonScript: {
1147
- build: string;
1148
- dev: string;
1149
- start: string;
1150
- lint: string;
1151
- test: string;
1152
- postinstall: string;
1153
- };
1154
- //#endregion
1155
- //#region src/Utils/TaskManager.d.ts
1156
- declare class TaskManager {
1157
- static taskRunner(description: string, task: (() => Promise<any>) | (() => any)): Promise<void>;
1158
- static advancedTaskRunner<R = any>(info: [[string, string], [string, string]] | [[string, string]], task: (() => Promise<R>) | (() => R)): Promise<R | undefined>;
1159
- }
1160
- //#endregion
1161
- export { Bindings, Choice, type ChoiceOrSeparatorArray, Choices, DotFlatten, DotNestedKeys, DotNestedValue, EnvParser, EventHandler, ExtractControllerMethods, FileSystem, GenericWithNullableStringValues, HttpContext, IApplication, IContainer, IController, IMiddleware, IParamBag, IPathName, IRequest, IResponse, IRouter, ISeparator, IServiceProvider, IUploadedFile, Logger, LoggerChalk, LoggerLog, LoggerParseSignature, PathLoader, Prompts, RequestMethod, RequestObject, Resolver, RouteDefinition, RouteEventHandler, RouteMethod, RouterEnd, TaskManager, UseKey, baseTsconfig, mainTsconfig, packageJsonScript };