@adonisjs/core 6.19.0 → 7.0.0-next.1
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/build/commands/add.d.ts +36 -5
- package/build/commands/add.js +24 -60
- package/build/commands/build.d.ts +23 -3
- package/build/commands/build.js +22 -36
- package/build/commands/commands.json +1 -1
- package/build/commands/configure.d.ts +35 -12
- package/build/commands/configure.js +39 -12
- package/build/commands/eject.d.ts +28 -3
- package/build/commands/eject.js +24 -5
- package/build/commands/env/add.d.ts +41 -4
- package/build/commands/env/add.js +32 -5
- package/build/commands/generate_key.d.ts +20 -1
- package/build/commands/generate_key.js +14 -1
- package/build/commands/inspect_rcfile.d.ts +20 -2
- package/build/commands/inspect_rcfile.js +20 -2
- package/build/commands/list/routes.d.ts +33 -11
- package/build/commands/list/routes.js +28 -5
- package/build/commands/make/command.d.ts +26 -3
- package/build/commands/make/command.js +25 -5
- package/build/commands/make/controller.d.ts +35 -2
- package/build/commands/make/controller.js +20 -2
- package/build/commands/make/event.d.ts +30 -4
- package/build/commands/make/event.js +27 -4
- package/build/commands/make/exception.d.ts +30 -4
- package/build/commands/make/exception.js +27 -4
- package/build/commands/make/listener.d.ts +38 -5
- package/build/commands/make/listener.js +32 -5
- package/build/commands/make/middleware.d.ts +25 -2
- package/build/commands/make/middleware.js +21 -4
- package/build/commands/make/preload.d.ts +31 -4
- package/build/commands/make/preload.js +28 -8
- package/build/commands/make/provider.d.ts +32 -3
- package/build/commands/make/provider.js +29 -7
- package/build/commands/make/service.d.ts +21 -2
- package/build/commands/make/service.js +18 -2
- package/build/commands/make/test.d.ts +27 -4
- package/build/commands/make/test.js +36 -8
- package/build/commands/make/transformer.d.ts +43 -0
- package/build/commands/make/transformer.js +65 -0
- package/build/commands/make/validator.d.ts +36 -5
- package/build/commands/make/validator.js +30 -5
- package/build/commands/make/view.d.ts +26 -3
- package/build/commands/make/view.js +24 -4
- package/build/commands/repl.d.ts +24 -4
- package/build/commands/repl.js +23 -3
- package/build/commands/serve.d.ts +38 -4
- package/build/commands/serve.js +34 -43
- package/build/commands/test.d.ts +68 -7
- package/build/commands/test.js +39 -37
- package/build/factories/core/ace.d.ts +31 -4
- package/build/factories/core/ace.js +20 -4
- package/build/factories/core/ignitor.d.ts +80 -9
- package/build/factories/core/ignitor.js +84 -13
- package/build/factories/core/main.d.ts +3 -3
- package/build/factories/core/main.js +3 -3
- package/build/factories/core/test_utils.d.ts +32 -4
- package/build/factories/core/test_utils.js +21 -4
- package/build/factories/stubs.d.ts +54 -5
- package/build/factories/stubs.js +55 -6
- package/build/index.d.ts +5 -4
- package/build/index.js +13 -9
- package/build/modules/ace/codemods.d.ts +71 -11
- package/build/modules/ace/codemods.js +90 -22
- package/build/modules/ace/commands.d.ts +48 -13
- package/build/modules/ace/commands.js +45 -10
- package/build/modules/ace/create_kernel.d.ts +19 -8
- package/build/modules/ace/create_kernel.js +19 -8
- package/build/modules/ace/kernel.d.ts +18 -4
- package/build/modules/ace/kernel.js +17 -3
- package/build/modules/ace/main.d.ts +3 -3
- package/build/modules/ace/main.js +3 -3
- package/build/modules/dumper/define_config.d.ts +25 -4
- package/build/modules/dumper/define_config.js +23 -2
- package/build/modules/dumper/dumper.d.ts +82 -12
- package/build/modules/dumper/dumper.js +82 -12
- package/build/modules/dumper/errors.d.ts +31 -10
- package/build/modules/dumper/errors.js +28 -7
- package/build/modules/dumper/main.d.ts +3 -3
- package/build/modules/dumper/main.js +3 -3
- package/build/modules/dumper/plugins/edge.d.ts +1 -1
- package/build/modules/hash/define_config.d.ts +53 -8
- package/build/modules/hash/define_config.js +51 -6
- package/build/modules/hash/main.d.ts +1 -1
- package/build/modules/hash/main.js +1 -1
- package/build/modules/http/main.d.ts +1 -1
- package/build/modules/http/main.js +1 -1
- package/build/modules/http/request_validator.d.ts +36 -9
- package/build/modules/http/request_validator.js +32 -5
- package/build/modules/transformers/main.d.ts +1 -0
- package/build/modules/transformers/main.js +9 -0
- package/build/providers/app_provider.d.ts +173 -1
- package/build/providers/app_provider.js +204 -8
- package/build/providers/edge_provider.d.ts +31 -2
- package/build/providers/edge_provider.js +31 -2
- package/build/providers/hash_provider.d.ts +38 -1
- package/build/providers/hash_provider.js +40 -3
- package/build/providers/repl_provider.d.ts +40 -1
- package/build/providers/repl_provider.js +52 -2
- package/build/providers/vinejs_provider.d.ts +32 -5
- package/build/providers/vinejs_provider.js +31 -4
- package/build/services/ace.d.ts +1 -1
- package/build/services/ace.js +1 -1
- package/build/services/app.d.ts +1 -1
- package/build/services/config.d.ts +1 -1
- package/build/services/config.js +1 -1
- package/build/services/dumper.js +1 -1
- package/build/services/emitter.d.ts +1 -1
- package/build/services/emitter.js +1 -1
- package/build/services/encryption.d.ts +1 -1
- package/build/services/encryption.js +1 -1
- package/build/services/hash.d.ts +1 -1
- package/build/services/hash.js +1 -1
- package/build/services/logger.d.ts +1 -1
- package/build/services/logger.js +1 -1
- package/build/services/repl.d.ts +1 -1
- package/build/services/repl.js +1 -1
- package/build/services/router.d.ts +1 -1
- package/build/services/router.js +1 -1
- package/build/services/server.d.ts +1 -1
- package/build/services/server.js +1 -1
- package/build/services/test_utils.d.ts +1 -1
- package/build/services/test_utils.js +1 -1
- package/build/services/url_builder.d.ts +4 -0
- package/build/services/url_builder.js +21 -0
- package/build/src/assembler_hooks/index_entities.d.ts +37 -0
- package/build/src/assembler_hooks/index_entities.js +106 -0
- package/build/src/cli_formatters/routes_list.d.ts +24 -12
- package/build/src/cli_formatters/routes_list.js +43 -46
- package/build/src/config_provider.d.ts +48 -3
- package/build/src/config_provider.js +47 -2
- package/build/src/debug.d.ts +15 -0
- package/build/src/debug.js +15 -0
- package/build/src/exceptions.d.ts +41 -1
- package/build/src/exceptions.js +41 -1
- package/build/src/helpers/assert.d.ts +47 -1
- package/build/src/helpers/assert.js +47 -1
- package/build/src/helpers/is.d.ts +21 -0
- package/build/src/helpers/is.js +21 -0
- package/build/src/helpers/main.d.ts +48 -5
- package/build/src/helpers/main.js +48 -5
- package/build/src/helpers/string.d.ts +89 -9
- package/build/src/helpers/string.js +21 -2
- package/build/src/helpers/types.d.ts +97 -2
- package/build/src/helpers/types.js +96 -2
- package/build/src/helpers/verification_token.d.ts +22 -1
- package/build/src/helpers/verification_token.js +24 -2
- package/build/src/ignitor/ace.d.ts +23 -3
- package/build/src/ignitor/ace.js +21 -1
- package/build/src/ignitor/http.d.ts +16 -3
- package/build/src/ignitor/http.js +16 -3
- package/build/src/ignitor/main.d.ts +29 -6
- package/build/src/ignitor/main.js +30 -7
- package/build/src/ignitor/test.d.ts +26 -3
- package/build/src/ignitor/test.js +24 -1
- package/build/src/test_utils/http.d.ts +19 -3
- package/build/src/test_utils/http.js +24 -3
- package/build/src/test_utils/main.d.ts +22 -4
- package/build/src/test_utils/main.js +21 -3
- package/build/src/types.d.ts +283 -26
- package/build/src/utils.d.ts +60 -0
- package/build/src/utils.js +104 -0
- package/build/src/vine.d.ts +24 -1
- package/build/src/vine.js +27 -1
- package/build/stubs/main.js +1 -2
- package/build/stubs/make/transformer/main.stub +18 -0
- package/build/toolkit/main.js +1 -1
- package/build/types/common.d.ts +1 -0
- package/build/types/common.js +9 -0
- package/build/types/helpers.d.ts +2 -1
- package/build/types/http.d.ts +1 -0
- package/build/types/transformers.d.ts +1 -0
- package/build/types/transformers.js +9 -0
- package/package.json +55 -52
- package/build/src/helpers/parse_binding_reference.d.ts +0 -45
- package/build/src/helpers/parse_binding_reference.js +0 -83
- package/build/src/internal_helpers.d.ts +0 -15
- package/build/src/internal_helpers.js +0 -63
|
@@ -7,9 +7,17 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
/**
|
|
10
|
-
* Request validator
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* Request validator for validating HTTP request data using VineJS validators.
|
|
11
|
+
* This class provides a convenient way to validate request body, files, cookies,
|
|
12
|
+
* headers, and URL parameters in AdonisJS applications.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // Inside a controller method
|
|
17
|
+
* const data = await request.validateUsing(createUserValidator, {
|
|
18
|
+
* messagesProvider: customMessages
|
|
19
|
+
* })
|
|
20
|
+
* ```
|
|
13
21
|
*/
|
|
14
22
|
export class RequestValidator {
|
|
15
23
|
#ctx;
|
|
@@ -35,8 +43,27 @@ export class RequestValidator {
|
|
|
35
43
|
*/
|
|
36
44
|
static messagesProvider;
|
|
37
45
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
46
|
+
* Validate the current HTTP request data using a VineJS validator.
|
|
47
|
+
* This method automatically includes request body, files, URL parameters,
|
|
48
|
+
* headers, and cookies in the validation data.
|
|
49
|
+
*
|
|
50
|
+
* @param validator - VineJS validator instance
|
|
51
|
+
* @param options - Optional validation options including custom error reporters and messages
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const createUserValidator = vine.compile(
|
|
56
|
+
* vine.object({
|
|
57
|
+
* email: vine.string().email(),
|
|
58
|
+
* name: vine.string().minLength(3)
|
|
59
|
+
* })
|
|
60
|
+
* )
|
|
61
|
+
*
|
|
62
|
+
* const data = await request.validateUsing(createUserValidator, {
|
|
63
|
+
* errorReporter: () => vine.errors.SimpleErrorReporter,
|
|
64
|
+
* messagesProvider: customMessages
|
|
65
|
+
* })
|
|
66
|
+
* ```
|
|
40
67
|
*/
|
|
41
68
|
validateUsing(validator, ...[options]) {
|
|
42
69
|
const validatorOptions = options || {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@adonisjs/http-transformers';
|
|
@@ -1,64 +1,236 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Router } from '../modules/http/main.ts';
|
|
2
|
+
import { type SerializeFn } from '../types/transformers.ts';
|
|
3
|
+
import type { ApplicationService } from '../src/types.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Extend HTTP request class with the transform method
|
|
6
|
+
*/
|
|
7
|
+
declare module '@adonisjs/core/http' {
|
|
8
|
+
interface HttpContext {
|
|
9
|
+
serialize: SerializeFn;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
2
12
|
/**
|
|
3
13
|
* The Application Service provider registers all the baseline
|
|
4
14
|
* features required to run the framework.
|
|
15
|
+
*
|
|
16
|
+
* This provider handles the registration of core services including:
|
|
17
|
+
* - Application instance
|
|
18
|
+
* - Logger and logger manager
|
|
19
|
+
* - Configuration
|
|
20
|
+
* - Event emitter
|
|
21
|
+
* - Encryption service
|
|
22
|
+
* - HTTP server and router
|
|
23
|
+
* - Body parser middleware
|
|
24
|
+
* - Dumper for debugging
|
|
25
|
+
* - Test utilities and ACE kernel
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* const provider = new AppServiceProvider(app)
|
|
29
|
+
* provider.register()
|
|
30
|
+
* await provider.boot()
|
|
31
|
+
* await provider.ready()
|
|
5
32
|
*/
|
|
6
33
|
export default class AppServiceProvider {
|
|
7
34
|
protected app: ApplicationService;
|
|
35
|
+
/**
|
|
36
|
+
* Application service provider constructor
|
|
37
|
+
*
|
|
38
|
+
* @param app - The application service instance
|
|
39
|
+
*/
|
|
8
40
|
constructor(app: ApplicationService);
|
|
9
41
|
/**
|
|
10
42
|
* Registers test utils with the container
|
|
43
|
+
*
|
|
44
|
+
* Creates a singleton binding for 'testUtils' that lazily imports
|
|
45
|
+
* and instantiates the TestUtils class when first accessed.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const testUtils = await app.container.make('testUtils')
|
|
49
|
+
* testUtils.createHttpContext()
|
|
11
50
|
*/
|
|
12
51
|
protected registerTestUtils(): void;
|
|
13
52
|
/**
|
|
14
53
|
* Registers ace with the container
|
|
54
|
+
*
|
|
55
|
+
* Creates a singleton binding for 'ace' that lazily creates
|
|
56
|
+
* the ACE kernel for command-line interface functionality.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const ace = await app.container.make('ace')
|
|
60
|
+
* await ace.exec('make:controller', ['UserController'])
|
|
15
61
|
*/
|
|
16
62
|
protected registerAce(): void;
|
|
17
63
|
/**
|
|
18
64
|
* Registers the application to the container
|
|
65
|
+
*
|
|
66
|
+
* Binds the application instance as both a class binding and an alias.
|
|
67
|
+
* This allows access to the app instance throughout the container.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* const app = await container.make('app')
|
|
71
|
+
* const appPath = app.makePath('tmp')
|
|
19
72
|
*/
|
|
20
73
|
protected registerApp(): void;
|
|
21
74
|
/**
|
|
22
75
|
* Registers the logger class to resolve the default logger
|
|
76
|
+
*
|
|
77
|
+
* Creates a singleton binding for the Logger class that resolves
|
|
78
|
+
* the default logger instance from the logger manager.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* const logger = await container.make(Logger)
|
|
82
|
+
* logger.info('Application started')
|
|
23
83
|
*/
|
|
24
84
|
protected registerLogger(): void;
|
|
25
85
|
/**
|
|
26
86
|
* Registers the logger manager to the container
|
|
87
|
+
*
|
|
88
|
+
* Creates a singleton binding for 'logger' that instantiates
|
|
89
|
+
* the LoggerManager with configuration from config/logger.ts
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* const loggerManager = await container.make('logger')
|
|
93
|
+
* const fileLogger = loggerManager.use('file')
|
|
27
94
|
*/
|
|
28
95
|
protected registerLoggerManager(): void;
|
|
29
96
|
/**
|
|
30
97
|
* Registers the config to the container
|
|
98
|
+
*
|
|
99
|
+
* Binds the application's config instance as both a class binding
|
|
100
|
+
* and an alias, allowing access to configuration values.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* const config = await container.make('config')
|
|
104
|
+
* const appKey = config.get('app.appKey')
|
|
31
105
|
*/
|
|
32
106
|
protected registerConfig(): void;
|
|
33
107
|
/**
|
|
34
108
|
* Registers emitter service to the container
|
|
109
|
+
*
|
|
110
|
+
* Creates a singleton binding for the event emitter that handles
|
|
111
|
+
* application-wide event dispatching and listening.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* const emitter = await container.make('emitter')
|
|
115
|
+
* emitter.emit('user:created', { userId: 123 })
|
|
35
116
|
*/
|
|
36
117
|
protected registerEmitter(): void;
|
|
37
118
|
/**
|
|
38
119
|
* Register the encryption service to the container
|
|
120
|
+
*
|
|
121
|
+
* Creates a singleton binding for the encryption service using
|
|
122
|
+
* the app key from configuration for encryption/decryption operations.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* const encryption = await container.make('encryption')
|
|
126
|
+
* const encrypted = encryption.encrypt('sensitive data')
|
|
39
127
|
*/
|
|
40
128
|
protected registerEncryption(): void;
|
|
41
129
|
/**
|
|
42
130
|
* Registers the HTTP server with the container as a singleton
|
|
131
|
+
*
|
|
132
|
+
* Creates a singleton binding for the HTTP server that handles
|
|
133
|
+
* incoming requests, with dependencies on encryption, emitter,
|
|
134
|
+
* logger, and HTTP configuration.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* const server = await container.make('server')
|
|
138
|
+
* server.start()
|
|
43
139
|
*/
|
|
44
140
|
protected registerServer(): void;
|
|
45
141
|
/**
|
|
46
142
|
* Registers router with the container as a singleton
|
|
143
|
+
*
|
|
144
|
+
* Creates a singleton binding for the router by getting it from
|
|
145
|
+
* the HTTP server instance. The router handles URL routing.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* const router = await container.make('router')
|
|
149
|
+
* router.get('/', ({ response }) => response.send('Hello'))
|
|
47
150
|
*/
|
|
48
151
|
protected registerRouter(): void;
|
|
49
152
|
/**
|
|
50
153
|
* Self construct bodyparser middleware class, since it needs
|
|
51
154
|
* config that cannot be resolved by the container
|
|
155
|
+
*
|
|
156
|
+
* Binds the BodyParserMiddleware with bodyparser configuration
|
|
157
|
+
* and experimental flags for parsing request bodies.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* const middleware = await container.make(BodyParserMiddleware)
|
|
161
|
+
* await middleware.handle(ctx, next)
|
|
52
162
|
*/
|
|
53
163
|
protected registerBodyParserMiddleware(): void;
|
|
54
164
|
/**
|
|
55
165
|
* Registeres singleton instance of the "Dumper" module configured
|
|
56
166
|
* via the "config/app.ts" file.
|
|
167
|
+
*
|
|
168
|
+
* The dumper is used for debugging and variable inspection with
|
|
169
|
+
* configurable HTML and console output formats.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* const dumper = await container.make('dumper')
|
|
173
|
+
* dumper.dump({ user: { name: 'John' } })
|
|
57
174
|
*/
|
|
58
175
|
protected registerDumper(): void;
|
|
176
|
+
/**
|
|
177
|
+
* Generates the types needed by the URL builder and writes
|
|
178
|
+
* them to the ".adonisjs/server/routes.d.ts" file
|
|
179
|
+
*
|
|
180
|
+
* This method scans registered routes and generates TypeScript
|
|
181
|
+
* types for type-safe URL generation in development.
|
|
182
|
+
*
|
|
183
|
+
* @param router - The router instance to generate types from
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* await generateRoutesTypes(router)
|
|
187
|
+
* // Creates .adonisjs/server/routes.d.ts with route types
|
|
188
|
+
*/
|
|
189
|
+
protected generateRoutesTypes(router: Router): Promise<void>;
|
|
190
|
+
/**
|
|
191
|
+
* Generates the routes JSON needed by the client integration
|
|
192
|
+
*
|
|
193
|
+
* Exports all registered routes as JSON for client-side
|
|
194
|
+
* applications that need route information.
|
|
195
|
+
*
|
|
196
|
+
* @param router - The router instance to export routes from
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* await generateRoutesJSONFile(router)
|
|
200
|
+
* // Creates .adonisjs/client/routes.json
|
|
201
|
+
*/
|
|
202
|
+
protected generateRoutesJSONFile(router: Router): Promise<void>;
|
|
59
203
|
/**
|
|
60
204
|
* Registers bindings
|
|
205
|
+
*
|
|
206
|
+
* Called during the application bootstrap phase to register
|
|
207
|
+
* all core service bindings with the IoC container.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* const provider = new AppServiceProvider(app)
|
|
211
|
+
* provider.register() // Registers all core services
|
|
61
212
|
*/
|
|
62
213
|
register(): void;
|
|
214
|
+
/**
|
|
215
|
+
* Boot the service provider
|
|
216
|
+
*
|
|
217
|
+
* Called after all providers have been registered. Sets up
|
|
218
|
+
* event emitter for BaseEvent and adds transform macro to HttpContext.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* await provider.boot()
|
|
222
|
+
* // Now HttpContext has transform method available
|
|
223
|
+
*/
|
|
63
224
|
boot(): Promise<void>;
|
|
225
|
+
/**
|
|
226
|
+
* Called when the application is ready
|
|
227
|
+
*
|
|
228
|
+
* In non-production environments, generates route types and
|
|
229
|
+
* JSON files for development tooling when router is committed.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* await provider.ready()
|
|
233
|
+
* // Route types and JSON generated in development
|
|
234
|
+
*/
|
|
235
|
+
ready(): Promise<void>;
|
|
64
236
|
}
|
|
@@ -6,25 +6,58 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import
|
|
9
|
+
import { dirname } from 'node:path';
|
|
10
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
11
|
+
import { Config } from "../modules/config.js";
|
|
12
|
+
import { Logger } from "../modules/logger.js";
|
|
13
|
+
import { Application } from "../modules/app.js";
|
|
14
|
+
import { Dumper } from "../modules/dumper/dumper.js";
|
|
15
|
+
import { HttpContext } from "../modules/http/main.js";
|
|
16
|
+
import { Encryption } from "../modules/encryption.js";
|
|
17
|
+
import { Router, Server } from "../modules/http/main.js";
|
|
18
|
+
import { BaseEvent, Emitter } from "../modules/events.js";
|
|
19
|
+
import { serialize } from "../modules/transformers/main.js";
|
|
20
|
+
import BodyParserMiddleware from "../modules/bodyparser/bodyparser_middleware.js";
|
|
17
21
|
/**
|
|
18
22
|
* The Application Service provider registers all the baseline
|
|
19
23
|
* features required to run the framework.
|
|
24
|
+
*
|
|
25
|
+
* This provider handles the registration of core services including:
|
|
26
|
+
* - Application instance
|
|
27
|
+
* - Logger and logger manager
|
|
28
|
+
* - Configuration
|
|
29
|
+
* - Event emitter
|
|
30
|
+
* - Encryption service
|
|
31
|
+
* - HTTP server and router
|
|
32
|
+
* - Body parser middleware
|
|
33
|
+
* - Dumper for debugging
|
|
34
|
+
* - Test utilities and ACE kernel
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const provider = new AppServiceProvider(app)
|
|
38
|
+
* provider.register()
|
|
39
|
+
* await provider.boot()
|
|
40
|
+
* await provider.ready()
|
|
20
41
|
*/
|
|
21
42
|
export default class AppServiceProvider {
|
|
22
43
|
app;
|
|
44
|
+
/**
|
|
45
|
+
* Application service provider constructor
|
|
46
|
+
*
|
|
47
|
+
* @param app - The application service instance
|
|
48
|
+
*/
|
|
23
49
|
constructor(app) {
|
|
24
50
|
this.app = app;
|
|
25
51
|
}
|
|
26
52
|
/**
|
|
27
53
|
* Registers test utils with the container
|
|
54
|
+
*
|
|
55
|
+
* Creates a singleton binding for 'testUtils' that lazily imports
|
|
56
|
+
* and instantiates the TestUtils class when first accessed.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const testUtils = await app.container.make('testUtils')
|
|
60
|
+
* testUtils.createHttpContext()
|
|
28
61
|
*/
|
|
29
62
|
registerTestUtils() {
|
|
30
63
|
this.app.container.singleton('testUtils', async () => {
|
|
@@ -34,6 +67,13 @@ export default class AppServiceProvider {
|
|
|
34
67
|
}
|
|
35
68
|
/**
|
|
36
69
|
* Registers ace with the container
|
|
70
|
+
*
|
|
71
|
+
* Creates a singleton binding for 'ace' that lazily creates
|
|
72
|
+
* the ACE kernel for command-line interface functionality.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* const ace = await app.container.make('ace')
|
|
76
|
+
* await ace.exec('make:controller', ['UserController'])
|
|
37
77
|
*/
|
|
38
78
|
registerAce() {
|
|
39
79
|
this.app.container.singleton('ace', async () => {
|
|
@@ -43,6 +83,13 @@ export default class AppServiceProvider {
|
|
|
43
83
|
}
|
|
44
84
|
/**
|
|
45
85
|
* Registers the application to the container
|
|
86
|
+
*
|
|
87
|
+
* Binds the application instance as both a class binding and an alias.
|
|
88
|
+
* This allows access to the app instance throughout the container.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* const app = await container.make('app')
|
|
92
|
+
* const appPath = app.makePath('tmp')
|
|
46
93
|
*/
|
|
47
94
|
registerApp() {
|
|
48
95
|
this.app.container.singleton(Application, () => this.app);
|
|
@@ -50,6 +97,13 @@ export default class AppServiceProvider {
|
|
|
50
97
|
}
|
|
51
98
|
/**
|
|
52
99
|
* Registers the logger class to resolve the default logger
|
|
100
|
+
*
|
|
101
|
+
* Creates a singleton binding for the Logger class that resolves
|
|
102
|
+
* the default logger instance from the logger manager.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* const logger = await container.make(Logger)
|
|
106
|
+
* logger.info('Application started')
|
|
53
107
|
*/
|
|
54
108
|
registerLogger() {
|
|
55
109
|
this.app.container.singleton(Logger, async (resolver) => {
|
|
@@ -59,6 +113,13 @@ export default class AppServiceProvider {
|
|
|
59
113
|
}
|
|
60
114
|
/**
|
|
61
115
|
* Registers the logger manager to the container
|
|
116
|
+
*
|
|
117
|
+
* Creates a singleton binding for 'logger' that instantiates
|
|
118
|
+
* the LoggerManager with configuration from config/logger.ts
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* const loggerManager = await container.make('logger')
|
|
122
|
+
* const fileLogger = loggerManager.use('file')
|
|
62
123
|
*/
|
|
63
124
|
registerLoggerManager() {
|
|
64
125
|
this.app.container.singleton('logger', async () => {
|
|
@@ -69,6 +130,13 @@ export default class AppServiceProvider {
|
|
|
69
130
|
}
|
|
70
131
|
/**
|
|
71
132
|
* Registers the config to the container
|
|
133
|
+
*
|
|
134
|
+
* Binds the application's config instance as both a class binding
|
|
135
|
+
* and an alias, allowing access to configuration values.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* const config = await container.make('config')
|
|
139
|
+
* const appKey = config.get('app.appKey')
|
|
72
140
|
*/
|
|
73
141
|
registerConfig() {
|
|
74
142
|
this.app.container.singleton(Config, () => this.app.config);
|
|
@@ -76,6 +144,13 @@ export default class AppServiceProvider {
|
|
|
76
144
|
}
|
|
77
145
|
/**
|
|
78
146
|
* Registers emitter service to the container
|
|
147
|
+
*
|
|
148
|
+
* Creates a singleton binding for the event emitter that handles
|
|
149
|
+
* application-wide event dispatching and listening.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* const emitter = await container.make('emitter')
|
|
153
|
+
* emitter.emit('user:created', { userId: 123 })
|
|
79
154
|
*/
|
|
80
155
|
registerEmitter() {
|
|
81
156
|
this.app.container.singleton(Emitter, async () => {
|
|
@@ -85,6 +160,13 @@ export default class AppServiceProvider {
|
|
|
85
160
|
}
|
|
86
161
|
/**
|
|
87
162
|
* Register the encryption service to the container
|
|
163
|
+
*
|
|
164
|
+
* Creates a singleton binding for the encryption service using
|
|
165
|
+
* the app key from configuration for encryption/decryption operations.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* const encryption = await container.make('encryption')
|
|
169
|
+
* const encrypted = encryption.encrypt('sensitive data')
|
|
88
170
|
*/
|
|
89
171
|
registerEncryption() {
|
|
90
172
|
this.app.container.singleton(Encryption, () => {
|
|
@@ -95,6 +177,14 @@ export default class AppServiceProvider {
|
|
|
95
177
|
}
|
|
96
178
|
/**
|
|
97
179
|
* Registers the HTTP server with the container as a singleton
|
|
180
|
+
*
|
|
181
|
+
* Creates a singleton binding for the HTTP server that handles
|
|
182
|
+
* incoming requests, with dependencies on encryption, emitter,
|
|
183
|
+
* logger, and HTTP configuration.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* const server = await container.make('server')
|
|
187
|
+
* server.start()
|
|
98
188
|
*/
|
|
99
189
|
registerServer() {
|
|
100
190
|
this.app.container.singleton(Server, async (resolver) => {
|
|
@@ -108,6 +198,13 @@ export default class AppServiceProvider {
|
|
|
108
198
|
}
|
|
109
199
|
/**
|
|
110
200
|
* Registers router with the container as a singleton
|
|
201
|
+
*
|
|
202
|
+
* Creates a singleton binding for the router by getting it from
|
|
203
|
+
* the HTTP server instance. The router handles URL routing.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* const router = await container.make('router')
|
|
207
|
+
* router.get('/', ({ response }) => response.send('Hello'))
|
|
111
208
|
*/
|
|
112
209
|
registerRouter() {
|
|
113
210
|
this.app.container.singleton(Router, async (resolver) => {
|
|
@@ -119,6 +216,13 @@ export default class AppServiceProvider {
|
|
|
119
216
|
/**
|
|
120
217
|
* Self construct bodyparser middleware class, since it needs
|
|
121
218
|
* config that cannot be resolved by the container
|
|
219
|
+
*
|
|
220
|
+
* Binds the BodyParserMiddleware with bodyparser configuration
|
|
221
|
+
* and experimental flags for parsing request bodies.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* const middleware = await container.make(BodyParserMiddleware)
|
|
225
|
+
* await middleware.handle(ctx, next)
|
|
122
226
|
*/
|
|
123
227
|
registerBodyParserMiddleware() {
|
|
124
228
|
this.app.container.bind(BodyParserMiddleware, () => {
|
|
@@ -129,6 +233,13 @@ export default class AppServiceProvider {
|
|
|
129
233
|
/**
|
|
130
234
|
* Registeres singleton instance of the "Dumper" module configured
|
|
131
235
|
* via the "config/app.ts" file.
|
|
236
|
+
*
|
|
237
|
+
* The dumper is used for debugging and variable inspection with
|
|
238
|
+
* configurable HTML and console output formats.
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* const dumper = await container.make('dumper')
|
|
242
|
+
* dumper.dump({ user: { name: 'John' } })
|
|
132
243
|
*/
|
|
133
244
|
registerDumper() {
|
|
134
245
|
this.app.container.singleton(Dumper, async () => {
|
|
@@ -144,8 +255,61 @@ export default class AppServiceProvider {
|
|
|
144
255
|
});
|
|
145
256
|
this.app.container.alias('dumper', Dumper);
|
|
146
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Generates the types needed by the URL builder and writes
|
|
260
|
+
* them to the ".adonisjs/server/routes.d.ts" file
|
|
261
|
+
*
|
|
262
|
+
* This method scans registered routes and generates TypeScript
|
|
263
|
+
* types for type-safe URL generation in development.
|
|
264
|
+
*
|
|
265
|
+
* @param router - The router instance to generate types from
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* await generateRoutesTypes(router)
|
|
269
|
+
* // Creates .adonisjs/server/routes.d.ts with route types
|
|
270
|
+
*/
|
|
271
|
+
async generateRoutesTypes(router) {
|
|
272
|
+
const types = router.generateTypes(4);
|
|
273
|
+
const outputPath = this.app.generatedServerPath('routes.d.ts');
|
|
274
|
+
await mkdir(dirname(outputPath), { recursive: true });
|
|
275
|
+
await writeFile(outputPath, [
|
|
276
|
+
`import '@adonisjs/core/types/http'`,
|
|
277
|
+
'',
|
|
278
|
+
`declare module '@adonisjs/core/types/http' {`,
|
|
279
|
+
' type ScannedRoutes = {',
|
|
280
|
+
types,
|
|
281
|
+
' }',
|
|
282
|
+
'export interface RoutesList extends ScannedRoutes {}',
|
|
283
|
+
'}',
|
|
284
|
+
].join('\n'));
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Generates the routes JSON needed by the client integration
|
|
288
|
+
*
|
|
289
|
+
* Exports all registered routes as JSON for client-side
|
|
290
|
+
* applications that need route information.
|
|
291
|
+
*
|
|
292
|
+
* @param router - The router instance to export routes from
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* await generateRoutesJSONFile(router)
|
|
296
|
+
* // Creates .adonisjs/client/routes.json
|
|
297
|
+
*/
|
|
298
|
+
async generateRoutesJSONFile(router) {
|
|
299
|
+
const routes = router.toJSON();
|
|
300
|
+
const outputPath = this.app.makePath('.adonisjs/client/routes.json');
|
|
301
|
+
await mkdir(dirname(outputPath), { recursive: true });
|
|
302
|
+
await writeFile(outputPath, JSON.stringify(routes, null, 2));
|
|
303
|
+
}
|
|
147
304
|
/**
|
|
148
305
|
* Registers bindings
|
|
306
|
+
*
|
|
307
|
+
* Called during the application bootstrap phase to register
|
|
308
|
+
* all core service bindings with the IoC container.
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* const provider = new AppServiceProvider(app)
|
|
312
|
+
* provider.register() // Registers all core services
|
|
149
313
|
*/
|
|
150
314
|
register() {
|
|
151
315
|
this.registerApp();
|
|
@@ -161,7 +325,39 @@ export default class AppServiceProvider {
|
|
|
161
325
|
this.registerRouter();
|
|
162
326
|
this.registerBodyParserMiddleware();
|
|
163
327
|
}
|
|
328
|
+
/**
|
|
329
|
+
* Boot the service provider
|
|
330
|
+
*
|
|
331
|
+
* Called after all providers have been registered. Sets up
|
|
332
|
+
* event emitter for BaseEvent and adds transform macro to HttpContext.
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* await provider.boot()
|
|
336
|
+
* // Now HttpContext has transform method available
|
|
337
|
+
*/
|
|
164
338
|
async boot() {
|
|
165
339
|
BaseEvent.useEmitter(await this.app.container.make('emitter'));
|
|
340
|
+
HttpContext.instanceProperty('serialize', function (...args) {
|
|
341
|
+
return serialize(...args);
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Called when the application is ready
|
|
346
|
+
*
|
|
347
|
+
* In non-production environments, generates route types and
|
|
348
|
+
* JSON files for development tooling when router is committed.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* await provider.ready()
|
|
352
|
+
* // Route types and JSON generated in development
|
|
353
|
+
*/
|
|
354
|
+
async ready() {
|
|
355
|
+
if (!this.app.inProduction) {
|
|
356
|
+
const router = await this.app.container.make('router');
|
|
357
|
+
if (router.commited) {
|
|
358
|
+
await this.generateRoutesJSONFile(router);
|
|
359
|
+
await this.generateRoutesTypes(router);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
166
362
|
}
|
|
167
363
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Edge } from 'edge.js';
|
|
2
|
-
import type { ApplicationService } from '../src/types.
|
|
3
|
-
import { type Route } from '../modules/http/main.
|
|
2
|
+
import type { ApplicationService } from '../src/types.ts';
|
|
3
|
+
import { type Route } from '../modules/http/main.ts';
|
|
4
4
|
declare module '@adonisjs/core/http' {
|
|
5
5
|
interface HttpContext {
|
|
6
6
|
/**
|
|
@@ -20,12 +20,41 @@ declare module '@adonisjs/core/http' {
|
|
|
20
20
|
/**
|
|
21
21
|
* The Edge service provider configures Edge to work within
|
|
22
22
|
* an AdonisJS application environment
|
|
23
|
+
*
|
|
24
|
+
* This provider integrates EdgeJS template engine with AdonisJS by:
|
|
25
|
+
* - Mounting the views directory
|
|
26
|
+
* - Configuring template caching for production
|
|
27
|
+
* - Adding global helpers for route generation
|
|
28
|
+
* - Creating isolated renderer instances for HTTP contexts
|
|
29
|
+
* - Adding render macro to BriskRoute for template rendering
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const provider = new EdgeServiceProvider(app)
|
|
33
|
+
* await provider.boot()
|
|
23
34
|
*/
|
|
24
35
|
export default class EdgeServiceProvider {
|
|
25
36
|
protected app: ApplicationService;
|
|
37
|
+
/**
|
|
38
|
+
* Edge service provider constructor
|
|
39
|
+
*
|
|
40
|
+
* Sets the usingEdgeJS flag to true to indicate EdgeJS is being used.
|
|
41
|
+
*
|
|
42
|
+
* @param app - The application service instance
|
|
43
|
+
*/
|
|
26
44
|
constructor(app: ApplicationService);
|
|
27
45
|
/**
|
|
28
46
|
* Bridge AdonisJS and Edge
|
|
47
|
+
*
|
|
48
|
+
* Configures EdgeJS integration by:
|
|
49
|
+
* - Setting up template mounting and caching
|
|
50
|
+
* - Defining global helpers (route, signedRoute, app, config)
|
|
51
|
+
* - Adding view getter to HttpContext for isolated rendering
|
|
52
|
+
* - Adding render macro to BriskRoute
|
|
53
|
+
* - Registering dumper plugin
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* await provider.boot()
|
|
57
|
+
* // Now edge templates can use {{ route('home') }} helper
|
|
29
58
|
*/
|
|
30
59
|
boot(): Promise<void>;
|
|
31
60
|
}
|