@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.cjs +220 -250
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +433 -397
- package/dist/index.d.ts +421 -397
- package/dist/index.js +201 -221
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { H3Event, Middleware, MiddlewareOptions,
|
|
2
|
-
import { Edge } from
|
|
3
|
-
import {
|
|
4
|
-
import { ChalkInstance } from
|
|
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
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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
|
-
|
|
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
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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
|
-
|
|
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
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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
|
-
|
|
379
|
-
|
|
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
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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 {
|
|
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
|