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