@h3ravel/shared 0.17.2 → 0.17.4

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.ts CHANGED
@@ -1,7 +1,10 @@
1
- import { H3Event, Middleware, MiddlewareOptions, H3, serve } from 'h3';
2
- import { Edge } from 'edge.js';
3
- import { TypedHeaders, ResponseHeaderMap } from 'fetchdts';
1
+ import { ChalkInstance } from "chalk";
2
+ import { H3, H3Event, Middleware, MiddlewareOptions, serve } from "h3";
3
+ import { Edge } from "edge.js";
4
+ import { ResponseHeaderMap, TypedHeaders } from "fetchdts";
5
+ import { DotNestedKeys as DotNestedKeys$1, DotNestedValue as DotNestedValue$1 } from "@h3ravel/shared";
4
6
 
7
+ //#region src/Contracts/ObjContract.d.ts
5
8
  /**
6
9
  * Adds a dot prefix to nested keys
7
10
  */
@@ -9,319 +12,335 @@ type DotPrefix<T extends string, U extends string> = T extends '' ? U : `${T}.${
9
12
  /**
10
13
  * Converts a union of objects into a single merged object
11
14
  */
12
- type MergeUnion<T> = (T extends any ? (k: T) => void : never) extends (k: infer I) => void ? {
13
- [K in keyof I]: I[K];
14
- } : never;
15
+ type MergeUnion<T> = (T extends any ? (k: T) => void : never) extends ((k: infer I) => void) ? { [K in keyof I]: I[K] } : never;
15
16
  /**
16
17
  * Flattens nested objects into dotted keys
17
18
  */
18
- type DotFlatten<T, Prefix extends string = ''> = MergeUnion<{
19
- [K in keyof T & string]: T[K] extends Record<string, any> ? DotFlatten<T[K], DotPrefix<Prefix, K>> : {
20
- [P in DotPrefix<Prefix, K>]: T[K];
21
- };
22
- }[keyof T & string]>;
19
+ 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]>;
23
20
  /**
24
21
  * Builds "nested.key" paths for autocompletion
25
22
  */
26
- type DotNestedKeys<T> = {
27
- [K in keyof T & string]: T[K] extends object ? `${K}` | `${K}.${DotNestedKeys<T[K]>}` : `${K}`;
28
- }[keyof T & string];
23
+ type DotNestedKeys<T> = { [K in keyof T & string]: T[K] extends object ? `${K}` | `${K}.${DotNestedKeys<T[K]>}` : `${K}` }[keyof T & string];
29
24
  /**
30
25
  * Retrieves type at a given dot-path
31
26
  */
32
27
  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;
33
-
28
+ /**
29
+ * A generic object type that supports nullable string values
30
+ */
31
+ interface GenericWithNullableStringValues {
32
+ [name: string]: string | undefined;
33
+ }
34
+ //#endregion
35
+ //#region src/Contracts/IContainer.d.ts
34
36
  /**
35
37
  * Interface for the Container contract, defining methods for dependency injection and service resolution.
36
38
  */
37
39
  interface IContainer {
38
- /**
39
- * Binds a transient service to the container.
40
- * @param key - The key or constructor for the service.
41
- * @param factory - The factory function to create the service instance.
42
- */
43
- bind<T>(key: new (...args: any[]) => T, factory: () => T): void;
44
- bind<T extends UseKey>(key: T, factory: () => Bindings[T]): void;
45
- /**
46
- * Binds a singleton service to the container.
47
- * @param key - The key or constructor for the service.
48
- * @param factory - The factory function to create the singleton instance.
49
- */
50
- singleton<T extends UseKey>(key: T | (new (...args: any[]) => Bindings[T]), factory: () => Bindings[T]): void;
51
- /**
52
- * Resolves a service from the container.
53
- * @param key - The key or constructor for the service.
54
- * @returns The resolved service instance.
55
- */
56
- make<T extends UseKey, X = undefined>(key: T | (new (..._args: any[]) => Bindings[T])): X extends undefined ? Bindings[T] : X;
57
- /**
58
- * Checks if a service is registered in the container.
59
- * @param key - The key to check.
60
- * @returns True if the service is registered, false otherwise.
61
- */
62
- has(key: UseKey): boolean;
40
+ /**
41
+ * Binds a transient service to the container.
42
+ * @param key - The key or constructor for the service.
43
+ * @param factory - The factory function to create the service instance.
44
+ */
45
+ bind<T>(key: new (...args: any[]) => T, factory: () => T): void;
46
+ bind<T extends UseKey>(key: T, factory: () => Bindings[T]): void;
47
+ /**
48
+ * Binds a singleton service to the container.
49
+ * @param key - The key or constructor for the service.
50
+ * @param factory - The factory function to create the singleton instance.
51
+ */
52
+ singleton<T extends UseKey>(key: T | (new (...args: any[]) => Bindings[T]), factory: () => Bindings[T]): void;
53
+ /**
54
+ * Resolves a service from the container.
55
+ * @param key - The key or constructor for the service.
56
+ * @returns The resolved service instance.
57
+ */
58
+ make<T extends UseKey, X = undefined>(key: T | (new (..._args: any[]) => Bindings[T])): X extends undefined ? Bindings[T] : X;
59
+ /**
60
+ * Checks if a service is registered in the container.
61
+ * @param key - The key to check.
62
+ * @returns True if the service is registered, false otherwise.
63
+ */
64
+ has(key: UseKey): boolean;
63
65
  }
64
-
66
+ //#endregion
67
+ //#region src/Contracts/IServiceProvider.d.ts
65
68
  interface IServiceProvider {
66
- /**
67
- * Sort order
68
- */
69
- order?: `before:${string}` | `after:${string}` | string | undefined;
70
- /**
71
- * Sort priority
72
- */
73
- priority?: number;
74
- /**
75
- * Register bindings to the container.
76
- * Runs before boot().
77
- */
78
- register(): void | Promise<void>;
79
- /**
80
- * Perform post-registration booting of services.
81
- * Runs after all providers have been registered.
82
- */
83
- boot?(): void | Promise<void>;
69
+ /**
70
+ * Sort order
71
+ */
72
+ order?: `before:${string}` | `after:${string}` | string | undefined;
73
+ /**
74
+ * Sort priority
75
+ */
76
+ priority?: number;
77
+ /**
78
+ * Indicate that this service provider only runs in console
79
+ */
80
+ console?: boolean;
81
+ /**
82
+ * List of registered console commands
83
+ */
84
+ registeredCommands?: (new (app: IApplication, kernel: any) => any)[];
85
+ /**
86
+ * An array of console commands to register.
87
+ */
88
+ commands?(commands: (new (app: IApplication, kernel: any) => any)[]): void;
89
+ /**
90
+ * Register bindings to the container.
91
+ * Runs before boot().
92
+ */
93
+ register?(...app: unknown[]): void | Promise<void>;
94
+ /**
95
+ * Perform post-registration booting of services.
96
+ * Runs after all providers have been registered.
97
+ */
98
+ boot?(...app: unknown[]): void | Promise<void>;
84
99
  }
85
-
86
- type IPathName = 'views' | 'routes' | 'assets' | 'base' | 'public' | 'storage' | 'config';
100
+ //#endregion
101
+ //#region src/Contracts/IApplication.d.ts
102
+ type IPathName = 'views' | 'routes' | 'assets' | 'base' | 'public' | 'storage' | 'config' | 'database';
87
103
  interface IApplication extends IContainer {
88
- /**
89
- * Registers configured service providers.
90
- */
91
- registerConfiguredProviders(): Promise<void>;
92
- /**
93
- * Registers an array of external service provider classes.
94
- * @param providers - Array of service provider constructor functions.
95
- */
96
- registerProviders(providers: Array<new (app: IApplication) => IServiceProvider>): void;
97
- /**
98
- * Registers a single service provider.
99
- * @param provider - The service provider instance to register.
100
- */
101
- register(provider: IServiceProvider): Promise<void>;
102
- /**
103
- * Boots all registered providers.
104
- */
105
- boot(): Promise<void>;
106
- /**
107
- * Gets the base path of the application.
108
- * @returns The base path as a string.
109
- */
110
- getBasePath(): string;
111
- /**
112
- * Retrieves a path by name, optionally appending a sub-path.
113
- * @param name - The name of the path property.
114
- * @param pth - Optional sub-path to append.
115
- * @returns The resolved path as a string.
116
- */
117
- getPath(name: string, pth?: string): string;
118
- /**
119
- * Sets a path for a given name.
120
- * @param name - The name of the path property.
121
- * @param path - The path to set.
122
- * @returns
123
- */
124
- setPath(name: IPathName, path: string): void;
125
- /**
126
- * Gets the version of the application or TypeScript.
127
- * @param key - The key to retrieve ('app' or 'ts').
128
- * @returns The version string or undefined.
129
- */
130
- getVersion(key: 'app' | 'ts'): string | undefined;
104
+ /**
105
+ * Registers configured service providers.
106
+ */
107
+ registerConfiguredProviders(): Promise<void>;
108
+ /**
109
+ * Registers an array of external service provider classes.
110
+ * @param providers - Array of service provider constructor functions.
111
+ */
112
+ registerProviders(providers: Array<new (app: IApplication) => IServiceProvider>): void;
113
+ /**
114
+ * Registers a single service provider.
115
+ * @param provider - The service provider instance to register.
116
+ */
117
+ register(provider: IServiceProvider): Promise<void>;
118
+ /**
119
+ * Boots all registered providers.
120
+ */
121
+ boot(): Promise<void>;
122
+ /**
123
+ * Gets the base path of the application.
124
+ * @returns The base path as a string.
125
+ */
126
+ getBasePath(): string;
127
+ /**
128
+ * Retrieves a path by name, optionally appending a sub-path.
129
+ * @param name - The name of the path property.
130
+ * @param pth - Optional sub-path to append.
131
+ * @returns The resolved path as a string.
132
+ */
133
+ getPath(name: string, pth?: string): string;
134
+ /**
135
+ * Sets a path for a given name.
136
+ * @param name - The name of the path property.
137
+ * @param path - The path to set.
138
+ * @returns
139
+ */
140
+ setPath(name: IPathName, path: string): void;
141
+ /**
142
+ * Gets the version of the application or TypeScript.
143
+ * @param key - The key to retrieve ('app' or 'ts').
144
+ * @returns The version string or undefined.
145
+ */
146
+ getVersion(key: 'app' | 'ts'): string | undefined;
131
147
  }
132
-
148
+ //#endregion
149
+ //#region src/Contracts/IRequest.d.ts
133
150
  /**
134
151
  * Interface for the Request contract, defining methods for handling HTTP request data.
135
152
  */
136
153
  interface IRequest {
137
- /**
138
- * The current app instance
139
- */
140
- app: IApplication;
141
- /**
142
- * Gets route parameters.
143
- * @returns An object containing route parameters.
144
- */
145
- params: NonNullable<H3Event["context"]["params"]>;
146
- /**
147
- * Gets query parameters.
148
- * @returns An object containing query parameters.
149
- */
150
- query: Record<string, any>;
151
- /**
152
- * Gets the request headers.
153
- * @returns An object containing request headers.
154
- */
155
- headers: TypedHeaders<Record<keyof ResponseHeaderMap, string>>;
156
- /**
157
- * Gets all input data (query parameters, route parameters, and body).
158
- * @returns A promise resolving to an object containing all input data.
159
- */
160
- all<T = Record<string, unknown>>(): Promise<T>;
161
- /**
162
- * Gets a single input field from query or body.
163
- * @param key - The key of the input field.
164
- * @param defaultValue - Optional default value if the key is not found.
165
- * @returns A promise resolving to the value of the input field or the default value.
166
- */
167
- input<T = unknown>(key: string, defaultValue?: T): Promise<T>;
168
- /**
169
- * Gets the underlying event object or a specific property of it.
170
- * @param key - Optional key to access a nested property of the event.
171
- * @returns The entire event object or the value of the specified property.
172
- */
173
- getEvent(): H3Event;
174
- getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
154
+ /**
155
+ * The current app instance
156
+ */
157
+ app: IApplication;
158
+ /**
159
+ * Gets route parameters.
160
+ * @returns An object containing route parameters.
161
+ */
162
+ params: NonNullable<H3Event["context"]["params"]>;
163
+ /**
164
+ * Gets query parameters.
165
+ * @returns An object containing query parameters.
166
+ */
167
+ query: Record<string, any>;
168
+ /**
169
+ * Gets the request headers.
170
+ * @returns An object containing request headers.
171
+ */
172
+ headers: TypedHeaders<Record<keyof ResponseHeaderMap, string>>;
173
+ /**
174
+ * Gets all input data (query parameters, route parameters, and body).
175
+ * @returns A promise resolving to an object containing all input data.
176
+ */
177
+ all<T = Record<string, unknown>>(): Promise<T>;
178
+ /**
179
+ * Gets a single input field from query or body.
180
+ * @param key - The key of the input field.
181
+ * @param defaultValue - Optional default value if the key is not found.
182
+ * @returns A promise resolving to the value of the input field or the default value.
183
+ */
184
+ input<T = unknown>(key: string, defaultValue?: T): Promise<T>;
185
+ /**
186
+ * Gets the underlying event object or a specific property of it.
187
+ * @param key - Optional key to access a nested property of the event.
188
+ * @returns The entire event object or the value of the specified property.
189
+ */
190
+ getEvent(): H3Event;
191
+ getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
175
192
  }
176
-
193
+ //#endregion
194
+ //#region src/Contracts/IResponse.d.ts
177
195
  /**
178
196
  * Interface for the Response contract, defining methods for handling HTTP responses.
179
197
  */
180
198
  interface IResponse {
181
- /**
182
- * The current app instance
183
- */
184
- app: IApplication;
185
- /**
186
- * Sets the HTTP status code for the response.
187
- * @param code - The HTTP status code.
188
- * @returns The instance for method chaining.
189
- */
190
- setStatusCode(code: number): this;
191
- /**
192
- * Sets a response header.
193
- * @param name - The header name.
194
- * @param value - The header value.
195
- * @returns The instance for method chaining.
196
- */
197
- setHeader(name: string, value: string): this;
198
- /**
199
- * Sends an HTML response.
200
- * @param content - The HTML content to send.
201
- * @returns The HTML content.
202
- */
203
- html(content: string): string;
204
- /**
205
- * Sends a JSON response.
206
- * @param data - The data to send as JSON.
207
- * @returns The input data.
208
- */
209
- json<T = unknown>(data: T): T;
210
- /**
211
- * Sends a plain text response.
212
- * @param data - The text content to send.
213
- * @returns The text content.
214
- */
215
- text(data: string): string;
216
- /**
217
- * Redirects to another URL.
218
- * @param url - The URL to redirect to.
219
- * @param status - The HTTP status code for the redirect (default: 302).
220
- * @returns The redirect URL.
221
- */
222
- redirect(url: string, status?: number): string;
223
- /**
224
- * Gets the underlying event object or a specific property of it.
225
- * @param key - Optional key to access a nested property of the event.
226
- * @returns The entire event object or the value of the specified property.
227
- */
228
- getEvent(): H3Event;
229
- getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
199
+ /**
200
+ * The current app instance
201
+ */
202
+ app: IApplication;
203
+ /**
204
+ * Sets the HTTP status code for the response.
205
+ * @param code - The HTTP status code.
206
+ * @returns The instance for method chaining.
207
+ */
208
+ setStatusCode(code: number): this;
209
+ /**
210
+ * Sets a response header.
211
+ * @param name - The header name.
212
+ * @param value - The header value.
213
+ * @returns The instance for method chaining.
214
+ */
215
+ setHeader(name: string, value: string): this;
216
+ /**
217
+ * Sends an HTML response.
218
+ * @param content - The HTML content to send.
219
+ * @returns The HTML content.
220
+ */
221
+ html(content: string): string;
222
+ /**
223
+ * Sends a JSON response.
224
+ * @param data - The data to send as JSON.
225
+ * @returns The input data.
226
+ */
227
+ json<T = unknown>(data: T): T;
228
+ /**
229
+ * Sends a plain text response.
230
+ * @param data - The text content to send.
231
+ * @returns The text content.
232
+ */
233
+ text(data: string): string;
234
+ /**
235
+ * Redirects to another URL.
236
+ * @param url - The URL to redirect to.
237
+ * @param status - The HTTP status code for the redirect (default: 302).
238
+ * @returns The redirect URL.
239
+ */
240
+ redirect(url: string, status?: number): string;
241
+ /**
242
+ * Gets the underlying event object or a specific property of it.
243
+ * @param key - Optional key to access a nested property of the event.
244
+ * @returns The entire event object or the value of the specified property.
245
+ */
246
+ getEvent(): H3Event;
247
+ getEvent<K extends DotNestedKeys$1<H3Event>>(key: K): DotNestedValue$1<H3Event, K>;
230
248
  }
231
-
249
+ //#endregion
250
+ //#region src/Contracts/IHttp.d.ts
232
251
  type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'patch' | 'apiResource' | 'group' | 'route';
233
252
  /**
234
253
  * Interface for the Router contract, defining methods for HTTP routing.
235
254
  */
236
255
  interface IRouter {
237
- /**
238
- * Registers a GET route.
239
- * @param path - The route path.
240
- * @param definition - The handler function or [controller class, method] array.
241
- * @param name - Optional route name.
242
- * @param middleware - Optional middleware array.
243
- */
244
- get(path: string, definition: EventHandler | [(new (...args: any[]) => IController), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
245
- /**
246
- * Registers a POST route.
247
- * @param path - The route path.
248
- * @param definition - The handler function or [controller class, method] array.
249
- * @param name - Optional route name.
250
- * @param middleware - Optional middleware array.
251
- */
252
- post(path: string, definition: EventHandler | [(new (...args: any[]) => IController), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
253
- /**
254
- * Registers a PUT route.
255
- * @param path - The route path.
256
- * @param definition - The handler function or [controller class, method] array.
257
- * @param name - Optional route name.
258
- * @param middleware - Optional middleware array.
259
- */
260
- put(path: string, definition: EventHandler | [(new (...args: any[]) => IController), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
261
- /**
262
- * Registers a DELETE route.
263
- * @param path - The route path.
264
- * @param definition - The handler function or [controller class, method] array.
265
- * @param name - Optional route name.
266
- * @param middleware - Optional middleware array.
267
- */
268
- delete(path: string, definition: EventHandler | [(new (...args: any[]) => IController), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
269
- /**
270
- * Registers an API resource with standard CRUD routes.
271
- * @param path - The base path for the resource.
272
- * @param controller - The controller class handling the resource.
273
- * @param middleware - Optional middleware array.
274
- */
275
- apiResource(path: string, controller: new (app: IApplication) => IController, middleware?: IMiddleware[]): Omit<this, RouterEnd | 'name'>;
276
- /**
277
- * Generates a URL for a named route.
278
- * @param name - The name of the route.
279
- * @param params - Optional parameters to replace in the route path.
280
- * @returns The generated URL or undefined if the route is not found.
281
- */
282
- route(name: string, params?: Record<string, string>): string | undefined;
283
- /**
284
- * Set the name of the current route
285
- *
286
- * @param name
287
- */
288
- name(name: string): this;
289
- /**
290
- * Groups routes with shared prefix or middleware.
291
- * @param options - Configuration for prefix or middleware.
292
- * @param callback - Callback function defining grouped routes.
293
- */
294
- group(options: {
295
- prefix?: string;
296
- middleware?: EventHandler[];
297
- }, callback: () => this): this;
298
- /**
299
- * Registers middleware for a specific path.
300
- * @param path - The path to apply the middleware.
301
- * @param handler - The middleware handler.
302
- * @param opts - Optional middleware options.
303
- */
304
- middleware(path: string | IMiddleware[], handler: Middleware, opts?: MiddlewareOptions): this;
256
+ /**
257
+ * Registers a GET route.
258
+ * @param path - The route path.
259
+ * @param definition - The handler function or [controller class, method] array.
260
+ * @param name - Optional route name.
261
+ * @param middleware - Optional middleware array.
262
+ */
263
+ get(path: string, definition: EventHandler | [(new (...args: any[]) => IController), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
264
+ /**
265
+ * Registers a POST route.
266
+ * @param path - The route path.
267
+ * @param definition - The handler function or [controller class, method] array.
268
+ * @param name - Optional route name.
269
+ * @param middleware - Optional middleware array.
270
+ */
271
+ post(path: string, definition: EventHandler | [(new (...args: any[]) => IController), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
272
+ /**
273
+ * Registers a PUT route.
274
+ * @param path - The route path.
275
+ * @param definition - The handler function or [controller class, method] array.
276
+ * @param name - Optional route name.
277
+ * @param middleware - Optional middleware array.
278
+ */
279
+ put(path: string, definition: EventHandler | [(new (...args: any[]) => IController), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
280
+ /**
281
+ * Registers a DELETE route.
282
+ * @param path - The route path.
283
+ * @param definition - The handler function or [controller class, method] array.
284
+ * @param name - Optional route name.
285
+ * @param middleware - Optional middleware array.
286
+ */
287
+ delete(path: string, definition: EventHandler | [(new (...args: any[]) => IController), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
288
+ /**
289
+ * Registers an API resource with standard CRUD routes.
290
+ * @param path - The base path for the resource.
291
+ * @param controller - The controller class handling the resource.
292
+ * @param middleware - Optional middleware array.
293
+ */
294
+ apiResource(path: string, controller: new (app: IApplication) => IController, middleware?: IMiddleware[]): Omit<this, RouterEnd | 'name'>;
295
+ /**
296
+ * Generates a URL for a named route.
297
+ * @param name - The name of the route.
298
+ * @param params - Optional parameters to replace in the route path.
299
+ * @returns The generated URL or undefined if the route is not found.
300
+ */
301
+ route(name: string, params?: Record<string, string>): string | undefined;
302
+ /**
303
+ * Set the name of the current route
304
+ *
305
+ * @param name
306
+ */
307
+ name(name: string): this;
308
+ /**
309
+ * Groups routes with shared prefix or middleware.
310
+ * @param options - Configuration for prefix or middleware.
311
+ * @param callback - Callback function defining grouped routes.
312
+ */
313
+ group(options: {
314
+ prefix?: string;
315
+ middleware?: EventHandler[];
316
+ }, callback: () => this): this;
317
+ /**
318
+ * Registers middleware for a specific path.
319
+ * @param path - The path to apply the middleware.
320
+ * @param handler - The middleware handler.
321
+ * @param opts - Optional middleware options.
322
+ */
323
+ middleware(path: string | IMiddleware[], handler: Middleware, opts?: MiddlewareOptions): this;
305
324
  }
306
325
  /**
307
326
  * Represents the HTTP context for a single request lifecycle.
308
327
  * Encapsulates the application instance, request, and response objects.
309
328
  */
310
329
  declare class HttpContext {
330
+ app: IApplication;
331
+ request: IRequest;
332
+ response: IResponse;
333
+ constructor(app: IApplication, request: IRequest, response: IResponse);
334
+ /**
335
+ * Factory method to create a new HttpContext instance from a context object.
336
+ * @param ctx - Object containing app, request, and response
337
+ * @returns A new HttpContext instance
338
+ */
339
+ static init(ctx: {
311
340
  app: IApplication;
312
341
  request: IRequest;
313
342
  response: IResponse;
314
- constructor(app: IApplication, request: IRequest, response: IResponse);
315
- /**
316
- * Factory method to create a new HttpContext instance from a context object.
317
- * @param ctx - Object containing app, request, and response
318
- * @returns A new HttpContext instance
319
- */
320
- static init(ctx: {
321
- app: IApplication;
322
- request: IRequest;
323
- response: IResponse;
324
- }): HttpContext;
343
+ }): HttpContext;
325
344
  }
326
345
  /**
327
346
  * Type for EventHandler, representing a function that handles an H3 event.
@@ -333,66 +352,154 @@ type RouteEventHandler = (...args: any[]) => any;
333
352
  * Any controller implementing this must define these methods.
334
353
  */
335
354
  interface IController {
336
- show(...ctx: any[]): any;
337
- index(...ctx: any[]): any;
338
- store(...ctx: any[]): any;
339
- update(...ctx: any[]): any;
340
- destroy(...ctx: any[]): any;
355
+ show(...ctx: any[]): any;
356
+ index(...ctx: any[]): any;
357
+ store(...ctx: any[]): any;
358
+ update(...ctx: any[]): any;
359
+ destroy(...ctx: any[]): any;
341
360
  }
342
361
  /**
343
362
  * Defines the contract for all middlewares.
344
363
  * Any middleware implementing this must define these methods.
345
364
  */
346
365
  interface IMiddleware {
347
- handle(context: HttpContext, next: () => Promise<any>): Promise<any>;
366
+ handle(context: HttpContext, next: () => Promise<any>): Promise<any>;
348
367
  }
349
-
368
+ //#endregion
369
+ //#region src/Utils/PathLoader.d.ts
350
370
  declare class PathLoader {
351
- private paths;
352
- /**
353
- * Dynamically retrieves a path property from the class.
354
- * Any property ending with "Path" is accessible automatically.
355
- *
356
- * @param name - The base name of the path property
357
- * @param base - The base path to include to the path
358
- * @returns
359
- */
360
- getPath(name: IPathName, base?: string): string;
361
- /**
362
- * Programatically set the paths.
363
- *
364
- * @param name - The base name of the path property
365
- * @param path - The new path
366
- * @param base - The base path to include to the path
367
- */
368
- setPath(name: IPathName, path: string, base?: string): void;
371
+ private paths;
372
+ /**
373
+ * Dynamically retrieves a path property from the class.
374
+ * Any property ending with "Path" is accessible automatically.
375
+ *
376
+ * @param name - The base name of the path property
377
+ * @param prefix - The base path to prefix to the path
378
+ * @returns
379
+ */
380
+ getPath(name: IPathName, prefix?: string): string;
381
+ /**
382
+ * Programatically set the paths.
383
+ *
384
+ * @param name - The base name of the path property
385
+ * @param path - The new path
386
+ * @param base - The base path to include to the path
387
+ */
388
+ setPath(name: IPathName, path: string, base?: string): void;
369
389
  }
370
-
371
- type RemoveIndexSignature<T> = {
372
- [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
373
- };
390
+ //#endregion
391
+ //#region src/Contracts/BindingsContract.d.ts
392
+ type RemoveIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K] };
374
393
  type Bindings = {
375
- [key: string]: any;
376
- [key: `app.${string}`]: any;
377
- env(): NodeJS.ProcessEnv;
378
- env<T extends string>(key: T, def?: any): any;
379
- view(templatePath: string, state?: Record<string, any>): Promise<string>;
380
- edge: Edge;
381
- asset(key: string, def?: string): string;
382
- router: IRouter;
383
- config: {
384
- get<X extends Record<string, any>>(): X;
385
- get<X extends Record<string, any>, T extends Extract<keyof X, string>>(key: T, def?: any): X[T];
386
- set<T extends string>(key: T, value: any): void;
387
- load?(): any;
388
- };
389
- 'http.app': H3;
390
- 'path.base': string;
391
- 'load.paths': PathLoader;
392
- 'http.serve': typeof serve;
393
- 'http.request': IRequest;
394
- 'http.response': IResponse;
394
+ [key: string]: any;
395
+ [key: `app.${string}`]: any;
396
+ env(): NodeJS.ProcessEnv;
397
+ env<T extends string>(key: T, def?: any): any;
398
+ view(templatePath: string, state?: Record<string, any>): Promise<string>;
399
+ edge: Edge;
400
+ asset(key: string, def?: string): string;
401
+ router: IRouter;
402
+ config: {
403
+ get<X extends Record<string, any>>(): X;
404
+ get<X extends Record<string, any>, T extends Extract<keyof X, string>>(key: T, def?: any): X[T];
405
+ set<T extends string>(key: T, value: any): void;
406
+ load?(): any;
407
+ };
408
+ 'http.app': H3;
409
+ 'path.base': string;
410
+ 'load.paths': PathLoader;
411
+ 'http.serve': typeof serve;
412
+ 'http.request': IRequest;
413
+ 'http.response': IResponse;
395
414
  };
396
415
  type UseKey = keyof RemoveIndexSignature<Bindings>;
397
-
398
- export { type Bindings, type DotFlatten, type DotNestedKeys, type DotNestedValue, type EventHandler, HttpContext, type IApplication, type IContainer, type IController, type IMiddleware, type IPathName, type IRequest, type IResponse, type IRouter, type IServiceProvider, PathLoader, type RouteEventHandler, type RouterEnd, type UseKey };
416
+ //#endregion
417
+ //#region src/Utils/EnvParser.d.ts
418
+ declare class EnvParser {
419
+ static parse(initial: GenericWithNullableStringValues): {
420
+ [name: string]: string | undefined;
421
+ };
422
+ static parseValue(value: any): any;
423
+ }
424
+ //#endregion
425
+ //#region src/Utils/Logger.d.ts
426
+ declare class Logger {
427
+ /**
428
+ * Logs the message in two columns
429
+ * @param name
430
+ * @param value
431
+ * @param log If set to false, array of [name, dots, value] output will be returned and not logged
432
+ * @returns
433
+ */
434
+ static twoColumnLog(name: string, value: string, log?: true): void;
435
+ static twoColumnLog(name: string, value: string, log?: false): [string, string, string];
436
+ /**
437
+ * Logs the message in two columns but allways passing status
438
+ *
439
+ * @param name
440
+ * @param value
441
+ * @param status
442
+ * @param exit
443
+ * @param preserveCol
444
+ */
445
+ static split(name: string, value: string, status?: 'success' | 'info' | 'error', exit?: boolean, preserveCol?: boolean): void;
446
+ /**
447
+ * Wraps text with chalk
448
+ *
449
+ * @param txt
450
+ * @param color
451
+ * @param preserveCol
452
+ * @returns
453
+ */
454
+ static textFormat(txt: any, color: (txt: string) => string, preserveCol?: boolean): string;
455
+ /**
456
+ * Logs a success message
457
+ *
458
+ * @param msg
459
+ * @param exit
460
+ * @param preserveCol
461
+ */
462
+ static success(msg: any, exit?: boolean, preserveCol?: boolean): void;
463
+ /**
464
+ * Logs an informational message
465
+ *
466
+ * @param msg
467
+ * @param exit
468
+ * @param preserveCol
469
+ */
470
+ static info(msg: any, exit?: boolean, preserveCol?: boolean): void;
471
+ /**
472
+ * Logs an error message
473
+ *
474
+ * @param msg
475
+ * @param exit
476
+ * @param preserveCol
477
+ */
478
+ static error(msg: string | string[] | Error & {
479
+ detail?: string;
480
+ }, exit?: boolean, preserveCol?: boolean): void;
481
+ /**
482
+ * Terminates the process
483
+ */
484
+ static quiet(): void;
485
+ /**
486
+ * Parse an array formated message and logs it
487
+ *
488
+ * @param config
489
+ * @param joiner
490
+ * @param log If set to false, string output will be returned and not logged
491
+ */
492
+ static parse(config: [string, keyof ChalkInstance][], joiner?: string, log?: true): void;
493
+ static parse(config: [string, keyof ChalkInstance][], joiner?: string, log?: false): string;
494
+ /**
495
+ * Ouput formater object or format the output
496
+ *
497
+ * @returns
498
+ */
499
+ static log(): typeof Logger;
500
+ static log(config: string, joiner: keyof ChalkInstance): void;
501
+ static log(config: [string, keyof ChalkInstance][], joiner?: string): void;
502
+ }
503
+ //#endregion
504
+ export { Bindings, DotFlatten, DotNestedKeys, DotNestedValue, EnvParser, EventHandler, GenericWithNullableStringValues, HttpContext, IApplication, IContainer, IController, IMiddleware, IPathName, IRequest, IResponse, IRouter, IServiceProvider, Logger, PathLoader, RouteEventHandler, RouterEnd, UseKey };
505
+ //# sourceMappingURL=index.d.ts.map