@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/README.md +13 -1
- package/dist/index.cjs +226 -98
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +443 -324
- package/dist/index.d.ts +431 -324
- package/dist/index.js +207 -71
- package/dist/index.js.map +1 -1
- package/package.json +13 -5
- package/tsconfig.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { H3Event, Middleware, MiddlewareOptions,
|
|
2
|
-
import { Edge } from
|
|
3
|
-
import {
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
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
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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
|
-
|
|
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
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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
|
-
|
|
372
|
-
|
|
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
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
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
|
-
|
|
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
|