@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.cts CHANGED
@@ -1,7 +1,9 @@
1
- import { H3Event, Middleware, MiddlewareOptions, H3, serve } from 'h3';
2
- import { Edge } from 'edge.js';
3
- import { TypedHeaders, ResponseHeaderMap } from 'fetchdts';
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";
4
5
 
6
+ //#region src/Contracts/ObjContract.d.ts
5
7
  /**
6
8
  * Adds a dot prefix to nested keys
7
9
  */
@@ -9,319 +11,348 @@ type DotPrefix<T extends string, U extends string> = T extends '' ? U : `${T}.${
9
11
  /**
10
12
  * Converts a union of objects into a single merged object
11
13
  */
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;
14
+ type MergeUnion<T> = (T extends any ? (k: T) => void : never) extends ((k: infer I) => void) ? { [K in keyof I]: I[K] } : never;
15
15
  /**
16
16
  * Flattens nested objects into dotted keys
17
17
  */
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]>;
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]>;
23
19
  /**
24
20
  * Builds "nested.key" paths for autocompletion
25
21
  */
26
- type DotNestedKeys<T> = {
27
- [K in keyof T & string]: T[K] extends object ? `${K}` | `${K}.${DotNestedKeys<T[K]>}` : `${K}`;
28
- }[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];
29
23
  /**
30
24
  * Retrieves type at a given dot-path
31
25
  */
32
26
  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
-
27
+ /**
28
+ * A generic object type that supports nullable string values
29
+ */
30
+ interface GenericWithNullableStringValues {
31
+ [name: string]: string | undefined;
32
+ }
33
+ //#endregion
34
+ //#region src/Contracts/IContainer.d.ts
34
35
  /**
35
36
  * Interface for the Container contract, defining methods for dependency injection and service resolution.
36
37
  */
37
38
  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;
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;
63
64
  }
64
-
65
+ //#endregion
66
+ //#region src/Contracts/IServiceProvider.d.ts
65
67
  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>;
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>;
84
98
  }
85
-
86
- type IPathName = 'views' | 'routes' | 'assets' | 'base' | 'public' | 'storage' | 'config';
99
+ //#endregion
100
+ //#region src/Contracts/IApplication.d.ts
101
+ type IPathName = 'views' | 'routes' | 'assets' | 'base' | 'public' | 'storage' | 'config' | 'database';
87
102
  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;
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;
131
146
  }
132
-
147
+ //#endregion
148
+ //#region src/Contracts/IRequest.d.ts
133
149
  /**
134
150
  * Interface for the Request contract, defining methods for handling HTTP request data.
135
151
  */
136
152
  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>;
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>;
175
191
  }
176
-
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
177
207
  /**
178
208
  * Interface for the Response contract, defining methods for handling HTTP responses.
179
209
  */
180
210
  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>;
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>;
230
260
  }
231
-
261
+ //#endregion
262
+ //#region src/Contracts/IHttp.d.ts
232
263
  type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'patch' | 'apiResource' | 'group' | 'route';
233
264
  /**
234
265
  * Interface for the Router contract, defining methods for HTTP routing.
235
266
  */
236
267
  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;
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;
305
336
  }
306
337
  /**
307
338
  * Represents the HTTP context for a single request lifecycle.
308
339
  * Encapsulates the application instance, request, and response objects.
309
340
  */
310
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: {
311
352
  app: IApplication;
312
353
  request: IRequest;
313
354
  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;
355
+ }): HttpContext;
325
356
  }
326
357
  /**
327
358
  * Type for EventHandler, representing a function that handles an H3 event.
@@ -333,66 +364,154 @@ type RouteEventHandler = (...args: any[]) => any;
333
364
  * Any controller implementing this must define these methods.
334
365
  */
335
366
  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;
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;
341
372
  }
342
373
  /**
343
374
  * Defines the contract for all middlewares.
344
375
  * Any middleware implementing this must define these methods.
345
376
  */
346
377
  interface IMiddleware {
347
- handle(context: HttpContext, next: () => Promise<any>): Promise<any>;
378
+ handle(context: HttpContext, next: () => Promise<any>): Promise<any>;
348
379
  }
349
-
380
+ //#endregion
381
+ //#region src/Utils/PathLoader.d.ts
350
382
  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;
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;
369
401
  }
370
-
371
- type RemoveIndexSignature<T> = {
372
- [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
373
- };
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] };
374
405
  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;
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;
395
426
  };
396
427
  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 };
428
+ //#endregion
429
+ //#region src/Utils/EnvParser.d.ts
430
+ declare class EnvParser {
431
+ static parse(initial: GenericWithNullableStringValues): {
432
+ [name: string]: string | undefined;
433
+ };
434
+ static parseValue(value: any): any;
435
+ }
436
+ //#endregion
437
+ //#region src/Utils/Logger.d.ts
438
+ declare class Logger {
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;
514
+ }
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