@h3ravel/core 1.7.4 → 1.9.0
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/app.globals.d.ts +63 -0
- package/dist/index.cjs +672 -543
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +305 -167
- package/dist/index.d.ts +306 -167
- package/dist/index.js +624 -409
- package/dist/index.js.map +1 -1
- package/package.json +14 -10
- package/dist/globals.d.ts +0 -16
package/dist/index.d.ts
CHANGED
|
@@ -1,125 +1,232 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { Bindings, HttpContext, IApplication, IContainer, IController, IMiddleware, IPathName, IServiceProvider, PathLoader, UseKey } from "@h3ravel/shared";
|
|
3
|
+
import { XGeneric } from "@h3ravel/support";
|
|
4
|
+
import { H3, H3Event } from "h3";
|
|
5
|
+
import { Argument, Command } from "commander";
|
|
3
6
|
|
|
7
|
+
//#region src/Container.d.ts
|
|
4
8
|
declare class Container implements IContainer {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
9
|
+
private bindings;
|
|
10
|
+
private singletons;
|
|
11
|
+
/**
|
|
12
|
+
* Check if the target has any decorators
|
|
13
|
+
*
|
|
14
|
+
* @param target
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
static hasAnyDecorator(target: Function): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Bind a transient service to the container
|
|
20
|
+
*/
|
|
21
|
+
bind<T>(key: new (...args: any[]) => T, factory: () => T): void;
|
|
22
|
+
bind<T extends UseKey>(key: T, factory: () => Bindings[T]): void;
|
|
23
|
+
/**
|
|
24
|
+
* Bind a singleton service to the container
|
|
25
|
+
*/
|
|
26
|
+
singleton<T extends UseKey>(key: T | (new (..._args: any[]) => Bindings[T]), factory: () => Bindings[T]): void;
|
|
27
|
+
/**
|
|
28
|
+
* Resolve a service from the container
|
|
29
|
+
*/
|
|
30
|
+
make<T extends UseKey, X = undefined>(key: T | (new (..._args: any[]) => Bindings[T])): X extends undefined ? Bindings[T] : X;
|
|
31
|
+
/**
|
|
32
|
+
* Automatically build a class with constructor dependency injection
|
|
33
|
+
*/
|
|
34
|
+
private build;
|
|
35
|
+
/**
|
|
36
|
+
* Check if a service is registered
|
|
37
|
+
*/
|
|
38
|
+
has(key: UseKey): boolean;
|
|
35
39
|
}
|
|
36
|
-
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/Application.d.ts
|
|
42
|
+
type AServiceProvider = (new (_app: Application) => IServiceProvider) & IServiceProvider;
|
|
37
43
|
declare class Application extends Container implements IApplication {
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
44
|
+
paths: PathLoader;
|
|
45
|
+
private tries;
|
|
46
|
+
private booted;
|
|
47
|
+
private versions;
|
|
48
|
+
private basePath;
|
|
49
|
+
private providers;
|
|
50
|
+
protected externalProviders: Array<new (_app: Application) => IServiceProvider>;
|
|
51
|
+
/**
|
|
52
|
+
* List of registered console commands
|
|
53
|
+
*/
|
|
54
|
+
registeredCommands: (new (app: any, kernel: any) => any)[];
|
|
55
|
+
constructor(basePath: string);
|
|
56
|
+
/**
|
|
57
|
+
* Register core bindings into the container
|
|
58
|
+
*/
|
|
59
|
+
protected registerBaseBindings(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Dynamically register all configured providers
|
|
62
|
+
*/
|
|
63
|
+
registerConfiguredProviders(): Promise<void>;
|
|
64
|
+
protected loadOptions(): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Get all registered providers
|
|
67
|
+
*/
|
|
68
|
+
getRegisteredProviders(): IServiceProvider[];
|
|
69
|
+
/**
|
|
70
|
+
* Load default and optional providers dynamically
|
|
71
|
+
*
|
|
72
|
+
* Auto-Registration Behavior
|
|
73
|
+
*
|
|
74
|
+
* Minimal App: Loads only core, config, http, router by default.
|
|
75
|
+
* Full-Stack App: Installs database, mail, queue, cache → they self-register via their providers.
|
|
76
|
+
*/
|
|
77
|
+
protected getConfiguredProviders(): Promise<Array<AServiceProvider>>;
|
|
78
|
+
protected getAllProviders(): Promise<Array<AServiceProvider>>;
|
|
79
|
+
private sortProviders;
|
|
80
|
+
registerProviders(providers: Array<AServiceProvider>): void;
|
|
81
|
+
/**
|
|
82
|
+
* Register a provider
|
|
83
|
+
*/
|
|
84
|
+
register(provider: IServiceProvider): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* checks if the application is running in CLI
|
|
87
|
+
*/
|
|
88
|
+
runningInConsole(): boolean;
|
|
89
|
+
getRuntimeEnv(): 'browser' | 'node' | 'unknown';
|
|
90
|
+
/**
|
|
91
|
+
* Boot all service providers after registration
|
|
92
|
+
*/
|
|
93
|
+
boot(): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Fire up the developement server using the user provided arguments
|
|
96
|
+
*
|
|
97
|
+
* Port will be auto assigned if provided one is not available
|
|
98
|
+
*
|
|
99
|
+
* @param h3App The current H3 app instance
|
|
100
|
+
* @param preferedPort If provided, this will overide the port set in the evironment
|
|
101
|
+
*/
|
|
102
|
+
fire(h3App: H3, preferedPort?: number): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Attempt to dynamically import an optional module
|
|
105
|
+
*/
|
|
106
|
+
private safeImport;
|
|
107
|
+
/**
|
|
108
|
+
* Get the base path of the app
|
|
109
|
+
*
|
|
110
|
+
* @returns
|
|
111
|
+
*/
|
|
112
|
+
getBasePath(): string;
|
|
113
|
+
/**
|
|
114
|
+
* Dynamically retrieves a path property from the class.
|
|
115
|
+
* Any property ending with "Path" is accessible automatically.
|
|
116
|
+
*
|
|
117
|
+
* @param name - The base name of the path property
|
|
118
|
+
* @returns
|
|
119
|
+
*/
|
|
120
|
+
getPath(name: IPathName, suffix?: string): string;
|
|
121
|
+
/**
|
|
122
|
+
* Programatically set the paths.
|
|
123
|
+
*
|
|
124
|
+
* @param name - The base name of the path property
|
|
125
|
+
* @param path - The new path
|
|
126
|
+
* @returns
|
|
127
|
+
*/
|
|
128
|
+
setPath(name: IPathName, path: string): void;
|
|
129
|
+
/**
|
|
130
|
+
* Returns the installed version of the system core and typescript.
|
|
131
|
+
*
|
|
132
|
+
* @returns
|
|
133
|
+
*/
|
|
134
|
+
getVersion(key: 'app' | 'ts'): string;
|
|
106
135
|
}
|
|
107
|
-
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/Console/ConsoleKernel.d.ts
|
|
138
|
+
declare class ConsoleKernel {
|
|
139
|
+
app: Application;
|
|
140
|
+
cwd: string;
|
|
141
|
+
output: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
|
|
142
|
+
basePath: string;
|
|
143
|
+
modulePath: string;
|
|
144
|
+
consolePath: string;
|
|
145
|
+
modulePackage: XGeneric<{
|
|
146
|
+
version: string;
|
|
147
|
+
}>;
|
|
148
|
+
consolePackage: XGeneric<{
|
|
149
|
+
version: string;
|
|
150
|
+
}>;
|
|
151
|
+
constructor(app: Application);
|
|
152
|
+
ensureDirectoryExists(dir: string): Promise<void>;
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/Console/ConsoleCommand.d.ts
|
|
156
|
+
declare class ConsoleCommand {
|
|
157
|
+
protected app: Application;
|
|
158
|
+
protected kernel: ConsoleKernel;
|
|
159
|
+
constructor(app: Application, kernel: ConsoleKernel);
|
|
160
|
+
/**
|
|
161
|
+
* The underlying commander instance.
|
|
162
|
+
*
|
|
163
|
+
* @var Command
|
|
164
|
+
*/
|
|
165
|
+
program: Command;
|
|
166
|
+
/**
|
|
167
|
+
* The name and signature of the console command.
|
|
168
|
+
*
|
|
169
|
+
* @var string
|
|
170
|
+
*/
|
|
171
|
+
protected signature: string;
|
|
172
|
+
/**
|
|
173
|
+
* A dictionary of signatures or what not.
|
|
174
|
+
*
|
|
175
|
+
* @var object
|
|
176
|
+
*/
|
|
177
|
+
protected dictionary: Record<string, any>;
|
|
178
|
+
/**
|
|
179
|
+
* The console command description.
|
|
180
|
+
*
|
|
181
|
+
* @var string
|
|
182
|
+
*/
|
|
183
|
+
protected description?: string;
|
|
184
|
+
/**
|
|
185
|
+
* The console command input.
|
|
186
|
+
*
|
|
187
|
+
* @var object
|
|
188
|
+
*/
|
|
189
|
+
private input;
|
|
190
|
+
/**
|
|
191
|
+
* Execute the console command.
|
|
192
|
+
*/
|
|
193
|
+
handle(..._args: any[]): Promise<void>;
|
|
194
|
+
setApplication(app: Application): void;
|
|
195
|
+
setInput(options: XGeneric, args: string[], regArgs: readonly Argument[], dictionary: Record<string, any>, program: Command): void;
|
|
196
|
+
getSignature(): string;
|
|
197
|
+
getDescription(): string | undefined;
|
|
198
|
+
option(key: string, def?: any): any;
|
|
199
|
+
options(key?: string): any;
|
|
200
|
+
argument(key: string, def?: any): any;
|
|
201
|
+
arguments(): Record<string, any>;
|
|
202
|
+
}
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/Contracts/ServiceProviderConstructor.d.ts
|
|
108
205
|
type ServiceProviderConstructor = (new (app: Application) => ServiceProvider) & IServiceProvider;
|
|
109
|
-
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/Controller.d.ts
|
|
110
208
|
/**
|
|
111
209
|
* Base controller class
|
|
112
210
|
*/
|
|
113
211
|
declare abstract class Controller implements IController {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
212
|
+
protected app: Application;
|
|
213
|
+
constructor(app: Application);
|
|
214
|
+
show(..._ctx: any[]): any;
|
|
215
|
+
index(..._ctx: any[]): any;
|
|
216
|
+
store(..._ctx: any[]): any;
|
|
217
|
+
update(..._ctx: any[]): any;
|
|
218
|
+
destroy(..._ctx: any[]): any;
|
|
121
219
|
}
|
|
122
|
-
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/Di/ContainerResolver.d.ts
|
|
222
|
+
declare class ContainerResolver {
|
|
223
|
+
private app;
|
|
224
|
+
constructor(app: Application);
|
|
225
|
+
resolveMethodParams<I extends Record<string, any>>(instance: I, method: keyof I, _default?: any): Promise<I>;
|
|
226
|
+
static isClass(C: any): boolean;
|
|
227
|
+
}
|
|
228
|
+
//#endregion
|
|
229
|
+
//#region src/Di/Inject.d.ts
|
|
123
230
|
declare function Inject(...dependencies: string[]): (target: any) => void;
|
|
124
231
|
/**
|
|
125
232
|
* Allows binding dependencies to both class and class methods
|
|
@@ -127,61 +234,82 @@ declare function Inject(...dependencies: string[]): (target: any) => void;
|
|
|
127
234
|
* @returns
|
|
128
235
|
*/
|
|
129
236
|
declare function Injectable(): ClassDecorator & MethodDecorator;
|
|
130
|
-
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region src/Http/Kernel.d.ts
|
|
131
239
|
/**
|
|
132
240
|
* Kernel class handles middleware execution and response transformations.
|
|
133
241
|
* It acts as the core middleware pipeline for HTTP requests.
|
|
134
242
|
*/
|
|
135
243
|
declare class Kernel {
|
|
136
|
-
|
|
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
|
-
|
|
244
|
+
protected context: (event: H3Event) => HttpContext;
|
|
245
|
+
protected middleware: IMiddleware[];
|
|
246
|
+
/**
|
|
247
|
+
* @param context - A factory function that converts an H3Event into an HttpContext.
|
|
248
|
+
* @param middleware - An array of middleware classes that will be executed in sequence.
|
|
249
|
+
*/
|
|
250
|
+
constructor(context: (event: H3Event) => HttpContext, middleware?: IMiddleware[]);
|
|
251
|
+
/**
|
|
252
|
+
* Handles an incoming request and passes it through middleware before invoking the next handler.
|
|
253
|
+
*
|
|
254
|
+
* @param event - The raw H3 event object.
|
|
255
|
+
* @param next - A callback function that represents the next layer (usually the controller or final handler).
|
|
256
|
+
* @returns A promise resolving to the result of the request pipeline.
|
|
257
|
+
*/
|
|
258
|
+
handle(event: H3Event, next: (ctx: HttpContext) => Promise<unknown>): Promise<unknown>;
|
|
259
|
+
/**
|
|
260
|
+
* Sequentially runs middleware in the order they were registered.
|
|
261
|
+
*
|
|
262
|
+
* @param context - The standardized HttpContext.
|
|
263
|
+
* @param next - Callback to execute when middleware completes.
|
|
264
|
+
* @returns A promise resolving to the final handler's result.
|
|
265
|
+
*/
|
|
266
|
+
private runMiddleware;
|
|
267
|
+
/**
|
|
268
|
+
* Utility function to determine if a value is a plain object or array.
|
|
269
|
+
*
|
|
270
|
+
* @param value - The value to check.
|
|
271
|
+
* @returns True if the value is a plain object or array, otherwise false.
|
|
272
|
+
*/
|
|
273
|
+
private isPlainObject;
|
|
166
274
|
}
|
|
167
|
-
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/ServiceProvider.d.ts
|
|
168
277
|
declare abstract class ServiceProvider implements IServiceProvider {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
278
|
+
/**
|
|
279
|
+
* Sort order
|
|
280
|
+
*/
|
|
281
|
+
static order?: `before:${string}` | `after:${string}` | string | undefined;
|
|
282
|
+
/**
|
|
283
|
+
* Sort priority
|
|
284
|
+
*/
|
|
285
|
+
static priority: number;
|
|
286
|
+
/**
|
|
287
|
+
* Indicate that this service provider only runs in console
|
|
288
|
+
*/
|
|
289
|
+
static console: boolean;
|
|
290
|
+
/**
|
|
291
|
+
* List of registered console commands
|
|
292
|
+
*/
|
|
293
|
+
registeredCommands?: (new (app: any, kernel: any) => any)[];
|
|
294
|
+
protected app: Application;
|
|
295
|
+
constructor(app: Application);
|
|
296
|
+
/**
|
|
297
|
+
* Register bindings to the container.
|
|
298
|
+
* Runs before boot().
|
|
299
|
+
*/
|
|
300
|
+
abstract register(...app: unknown[]): void | Promise<void>;
|
|
301
|
+
/**
|
|
302
|
+
* Perform post-registration booting of services.
|
|
303
|
+
* Runs after all providers have been registered.
|
|
304
|
+
*/
|
|
305
|
+
boot?(...app: unknown[]): void | Promise<void>;
|
|
306
|
+
/**
|
|
307
|
+
* An array of console commands to register.
|
|
308
|
+
*/
|
|
309
|
+
commands(commands: (new (app: any, kernel: any) => any)[]): void;
|
|
183
310
|
}
|
|
184
|
-
|
|
311
|
+
//#endregion
|
|
312
|
+
//#region src/Providers/CoreServiceProvider.d.ts
|
|
185
313
|
/**
|
|
186
314
|
* Bootstraps core services and bindings.
|
|
187
315
|
*
|
|
@@ -192,17 +320,28 @@ declare abstract class ServiceProvider implements IServiceProvider {
|
|
|
192
320
|
* Auto-Registered
|
|
193
321
|
*/
|
|
194
322
|
declare class CoreServiceProvider extends ServiceProvider {
|
|
195
|
-
|
|
196
|
-
|
|
323
|
+
static priority: number;
|
|
324
|
+
register(): void;
|
|
197
325
|
}
|
|
198
|
-
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region src/Providers/ViewServiceProvider.d.ts
|
|
199
328
|
declare class ViewServiceProvider extends ServiceProvider {
|
|
200
|
-
|
|
201
|
-
|
|
329
|
+
static priority: number;
|
|
330
|
+
register(): void;
|
|
202
331
|
}
|
|
203
|
-
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region src/Registerer.d.ts
|
|
204
334
|
declare class Registerer {
|
|
205
|
-
|
|
335
|
+
private app;
|
|
336
|
+
constructor(app: Application);
|
|
337
|
+
static register(app: Application): void;
|
|
338
|
+
bootRegister(): void;
|
|
339
|
+
private appPath;
|
|
340
|
+
private basePath;
|
|
341
|
+
private publicPath;
|
|
342
|
+
private storagePath;
|
|
343
|
+
private databasePath;
|
|
206
344
|
}
|
|
207
|
-
|
|
208
|
-
export { Application, Container, Controller, CoreServiceProvider, Inject, Injectable, Kernel, Registerer, ServiceProvider,
|
|
345
|
+
//#endregion
|
|
346
|
+
export { Application, ConsoleCommand, ConsoleKernel, Container, ContainerResolver, Controller, CoreServiceProvider, Inject, Injectable, Kernel, Registerer, ServiceProvider, ServiceProviderConstructor, ViewServiceProvider };
|
|
347
|
+
//# sourceMappingURL=index.d.ts.map
|