@adonisjs/core 7.0.0-next.10 → 7.0.0-next.11
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.js +40 -110
- package/build/commands/build.js +51 -107
- package/build/commands/configure.js +82 -177
- package/build/commands/eject.js +17 -60
- package/build/commands/env/add.js +55 -134
- package/build/commands/generate_key.js +22 -66
- package/build/commands/inspect_rcfile.js +27 -55
- package/build/commands/list/routes.js +246 -116
- package/build/commands/make/command.js +15 -57
- package/build/commands/make/controller.js +43 -120
- package/build/commands/make/event.js +16 -62
- package/build/commands/make/exception.js +16 -62
- package/build/commands/make/listener.js +36 -93
- package/build/commands/make/middleware.js +41 -101
- package/build/commands/make/preload.js +47 -113
- package/build/commands/make/provider.js +47 -112
- package/build/commands/make/service.js +16 -55
- package/build/commands/make/test.js +47 -132
- package/build/commands/make/transformer.js +17 -64
- package/build/commands/make/validator.js +20 -80
- package/build/commands/make/view.js +15 -56
- package/build/commands/repl.js +17 -50
- package/build/commands/serve.js +80 -150
- package/build/commands/test.js +92 -202
- package/build/factories/app.js +2 -9
- package/build/factories/bodyparser.js +2 -9
- package/build/factories/core/ace.js +15 -46
- package/build/factories/core/ignitor.js +12 -180
- package/build/factories/core/main.js +22 -11
- package/build/factories/core/test_utils.js +19 -43
- package/build/factories/encryption.js +2 -9
- package/build/factories/events.js +2 -9
- package/build/factories/hash.js +2 -9
- package/build/factories/http.js +2 -9
- package/build/factories/logger.js +2 -9
- package/build/factories/stubs.js +28 -91
- package/build/index.js +13 -46
- package/build/modules/ace/codemods.js +222 -477
- package/build/modules/ace/main.js +2 -41
- package/build/modules/app.js +4 -26
- package/build/modules/bodyparser/bodyparser_middleware.js +2 -14
- package/build/modules/bodyparser/main.js +4 -9
- package/build/modules/config.js +4 -26
- package/build/modules/container.js +4 -9
- package/build/modules/dumper/main.js +6 -32
- package/build/modules/dumper/plugins/edge.js +2 -62
- package/build/modules/encryption.js +4 -26
- package/build/modules/env/editor.js +2 -9
- package/build/modules/env/main.js +2 -28
- package/build/modules/events.js +4 -9
- package/build/modules/hash/drivers/argon.js +2 -9
- package/build/modules/hash/drivers/bcrypt.js +2 -20
- package/build/modules/hash/drivers/scrypt.js +2 -9
- package/build/modules/hash/main.js +6 -28
- package/build/modules/hash/phc_formatter.js +2 -9
- package/build/modules/health.js +2 -9
- package/build/modules/http/main.js +4 -15
- package/build/modules/http/url_builder_client.js +2 -9
- package/build/modules/logger.d.ts +30 -0
- package/build/modules/logger.js +4 -9
- package/build/modules/repl.js +4 -9
- package/build/modules/transformers/main.js +4 -9
- package/build/providers/app_provider.js +147 -359
- package/build/providers/edge_provider.js +97 -165
- package/build/providers/hash_provider.js +29 -91
- package/build/providers/repl_provider.js +61 -152
- package/build/providers/vinejs_provider.d.ts +1 -1
- package/build/providers/vinejs_provider.js +20 -66
- package/build/services/ace.js +2 -17
- package/build/services/app.js +2 -21
- package/build/services/config.js +2 -13
- package/build/services/dumper.js +5 -21
- package/build/services/emitter.js +2 -14
- package/build/services/encryption.js +2 -14
- package/build/services/hash.js +2 -14
- package/build/services/logger.js +2 -14
- package/build/services/repl.js +2 -14
- package/build/services/router.js +2 -14
- package/build/services/server.js +2 -14
- package/build/services/test_utils.js +2 -17
- package/build/services/url_builder.js +5 -17
- package/build/src/exceptions.js +2 -49
- package/build/src/helpers/assert.js +2 -55
- package/build/src/helpers/http.js +2 -28
- package/build/src/helpers/is.js +3 -31
- package/build/src/helpers/main.js +5 -52
- package/build/src/helpers/string.js +2 -78
- package/build/src/helpers/types.js +26 -135
- package/build/src/helpers/verification_token.js +2 -120
- package/build/src/test_utils/main.js +5 -77
- package/build/src/types.js +0 -8
- package/build/src/vine.js +2 -105
- package/build/types/ace.js +2 -9
- package/build/types/app.js +2 -9
- package/build/types/bodyparser.js +2 -9
- package/build/types/common.js +2 -9
- package/build/types/container.js +2 -9
- package/build/types/encryption.js +2 -9
- package/build/types/events.js +2 -9
- package/build/types/hash.js +2 -9
- package/build/types/health.js +2 -9
- package/build/types/helpers.js +0 -8
- package/build/types/http.js +2 -9
- package/build/types/logger.js +2 -9
- package/build/types/repl.js +2 -9
- package/build/types/transformers.js +2 -9
- package/package.json +76 -19
- package/build/modules/ace/commands.js +0 -157
- package/build/modules/ace/create_kernel.js +0 -91
- package/build/modules/ace/kernel.js +0 -40
- package/build/modules/dumper/define_config.js +0 -36
- package/build/modules/dumper/dumper.js +0 -266
- package/build/modules/dumper/errors.js +0 -119
- package/build/modules/hash/define_config.js +0 -125
- package/build/modules/http/request_validator.js +0 -100
- package/build/src/assembler_hooks/index_entities.js +0 -112
- package/build/src/cli_formatters/routes_list.js +0 -397
- package/build/src/config_provider.js +0 -71
- package/build/src/debug.js +0 -25
- package/build/src/ignitor/ace.js +0 -102
- package/build/src/ignitor/http.js +0 -159
- package/build/src/ignitor/main.js +0 -124
- package/build/src/ignitor/test.js +0 -66
- package/build/src/test_utils/http.js +0 -82
- package/build/src/utils.js +0 -114
- package/build/stubs/main.js +0 -9
- package/build/toolkit/commands/index_commands.js +0 -30
- package/build/toolkit/main.js +0 -27
|
@@ -1,359 +1,147 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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 })
|
|
154
|
-
*/
|
|
155
|
-
registerEmitter() {
|
|
156
|
-
this.app.container.singleton(Emitter, async () => {
|
|
157
|
-
return new Emitter(this.app);
|
|
158
|
-
});
|
|
159
|
-
this.app.container.alias('emitter', Emitter);
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
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')
|
|
170
|
-
*/
|
|
171
|
-
registerEncryption() {
|
|
172
|
-
this.app.container.singleton(Encryption, () => {
|
|
173
|
-
const appKey = this.app.config.get('app.appKey');
|
|
174
|
-
return new Encryption({ secret: appKey });
|
|
175
|
-
});
|
|
176
|
-
this.app.container.alias('encryption', Encryption);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
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()
|
|
188
|
-
*/
|
|
189
|
-
registerServer() {
|
|
190
|
-
this.app.container.singleton(Server, async (resolver) => {
|
|
191
|
-
const encryption = await resolver.make('encryption');
|
|
192
|
-
const emitter = await resolver.make('emitter');
|
|
193
|
-
const logger = await resolver.make('logger');
|
|
194
|
-
const config = this.app.config.get('app.http');
|
|
195
|
-
return new Server(this.app, encryption, emitter, logger, config);
|
|
196
|
-
});
|
|
197
|
-
this.app.container.alias('server', Server);
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
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'))
|
|
208
|
-
*/
|
|
209
|
-
registerRouter() {
|
|
210
|
-
this.app.container.singleton(Router, async (resolver) => {
|
|
211
|
-
const server = await resolver.make('server');
|
|
212
|
-
return server.getRouter();
|
|
213
|
-
});
|
|
214
|
-
this.app.container.alias('router', Router);
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Self construct bodyparser middleware class, since it needs
|
|
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)
|
|
226
|
-
*/
|
|
227
|
-
registerBodyParserMiddleware() {
|
|
228
|
-
this.app.container.singleton(BodyParserMiddleware, () => {
|
|
229
|
-
const config = this.app.config.get('bodyparser');
|
|
230
|
-
return new BodyParserMiddleware(config, this.app.experimentalFlags);
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Registeres singleton instance of the "Dumper" module configured
|
|
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' } })
|
|
243
|
-
*/
|
|
244
|
-
registerDumper() {
|
|
245
|
-
this.app.container.singleton(Dumper, async () => {
|
|
246
|
-
const config = this.app.config.get('app.dumper', {});
|
|
247
|
-
const dumper = new Dumper(this.app);
|
|
248
|
-
if (config.html) {
|
|
249
|
-
dumper.configureHtmlOutput(config.html);
|
|
250
|
-
}
|
|
251
|
-
if (config.console) {
|
|
252
|
-
dumper.configureAnsiOutput(config.console);
|
|
253
|
-
}
|
|
254
|
-
return dumper;
|
|
255
|
-
});
|
|
256
|
-
this.app.container.alias('dumper', Dumper);
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Generates TypeScript type definitions and JSON representation of routes
|
|
260
|
-
*
|
|
261
|
-
* Creates route type definitions for better IDE support and a JSON file
|
|
262
|
-
* containing all registered routes. This is used in development mode for
|
|
263
|
-
* tooling integration and type-safety.
|
|
264
|
-
*
|
|
265
|
-
* @param router - The router instance containing registered routes
|
|
266
|
-
*
|
|
267
|
-
* @example
|
|
268
|
-
* const router = await container.make('router')
|
|
269
|
-
* await this.emitRoutes(router)
|
|
270
|
-
* // Generates .adonisjs/server/routes.d.ts and routes.json
|
|
271
|
-
*/
|
|
272
|
-
async emitRoutes(router) {
|
|
273
|
-
try {
|
|
274
|
-
const { routes, imports, types } = router.generateTypes(2);
|
|
275
|
-
const routesTypesPath = this.app.generatedServerPath('routes.d.ts');
|
|
276
|
-
const routesJsonPath = this.app.generatedServerPath('routes.json');
|
|
277
|
-
await mkdir(dirname(routesTypesPath), { recursive: true });
|
|
278
|
-
await Promise.all([
|
|
279
|
-
writeFile(routesTypesPath, [
|
|
280
|
-
`import '@adonisjs/core/types/http'`,
|
|
281
|
-
...imports,
|
|
282
|
-
'',
|
|
283
|
-
...types,
|
|
284
|
-
'',
|
|
285
|
-
'export type ScannedRoutes = {',
|
|
286
|
-
routes,
|
|
287
|
-
'}',
|
|
288
|
-
`declare module '@adonisjs/core/types/http' {`,
|
|
289
|
-
' export interface RoutesList extends ScannedRoutes {}',
|
|
290
|
-
'}',
|
|
291
|
-
].join('\n')),
|
|
292
|
-
writeFile(routesJsonPath, JSON.stringify(router.toJSON())),
|
|
293
|
-
]);
|
|
294
|
-
this.app.notify({ isAdonisJS: true, routesFileLocation: routesJsonPath });
|
|
295
|
-
}
|
|
296
|
-
catch (error) {
|
|
297
|
-
console.error("Unable to generate routes types file due to the following error. This won't impact the dev-server");
|
|
298
|
-
console.error(error);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Registers bindings
|
|
303
|
-
*
|
|
304
|
-
* Called during the application bootstrap phase to register
|
|
305
|
-
* all core service bindings with the IoC container.
|
|
306
|
-
*
|
|
307
|
-
* @example
|
|
308
|
-
* const provider = new AppServiceProvider(app)
|
|
309
|
-
* provider.register() // Registers all core services
|
|
310
|
-
*/
|
|
311
|
-
register() {
|
|
312
|
-
this.registerApp();
|
|
313
|
-
this.registerAce();
|
|
314
|
-
this.registerDumper();
|
|
315
|
-
this.registerLoggerManager();
|
|
316
|
-
this.registerLogger();
|
|
317
|
-
this.registerConfig();
|
|
318
|
-
this.registerEmitter();
|
|
319
|
-
this.registerEncryption();
|
|
320
|
-
this.registerTestUtils();
|
|
321
|
-
this.registerServer();
|
|
322
|
-
this.registerRouter();
|
|
323
|
-
this.registerBodyParserMiddleware();
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Boot the service provider
|
|
327
|
-
*
|
|
328
|
-
* Called after all providers have been registered. Sets up
|
|
329
|
-
* event emitter for BaseEvent and adds transform macro to HttpContext.
|
|
330
|
-
*
|
|
331
|
-
* @example
|
|
332
|
-
* await provider.boot()
|
|
333
|
-
* // Now HttpContext has transform method available
|
|
334
|
-
*/
|
|
335
|
-
async boot() {
|
|
336
|
-
BaseEvent.useEmitter(await this.app.container.make('emitter'));
|
|
337
|
-
HttpContext.instanceProperty('serialize', function (value, container) {
|
|
338
|
-
return serialize(value, container ?? this.containerResolver);
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Called when the application is ready
|
|
343
|
-
*
|
|
344
|
-
* In non-production environments, generates route types and
|
|
345
|
-
* JSON files for development tooling when router is committed.
|
|
346
|
-
*
|
|
347
|
-
* @example
|
|
348
|
-
* await provider.ready()
|
|
349
|
-
* // Route types and JSON generated in development
|
|
350
|
-
*/
|
|
351
|
-
async ready() {
|
|
352
|
-
if (!this.app.inProduction) {
|
|
353
|
-
const router = await this.app.container.make('router');
|
|
354
|
-
if (router.commited) {
|
|
355
|
-
await this.emitRoutes(router);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
1
|
+
import "../chunk-MjwdjG2f.js";
|
|
2
|
+
import { t as app_exports } from "../app-BK0PN3li.js";
|
|
3
|
+
import { t as config_exports } from "../config-B2S2xfmN.js";
|
|
4
|
+
import { t as encryption_exports } from "../encryption-D2HGu0bU.js";
|
|
5
|
+
import { t as events_exports } from "../events-B8hK42QT.js";
|
|
6
|
+
import { t as logger_exports } from "../logger-Dha-0hp1.js";
|
|
7
|
+
import { t as Dumper } from "../dumper-C_sMcyFb.js";
|
|
8
|
+
import { t as main_exports } from "../main-CFmDHDls.js";
|
|
9
|
+
import { t as main_exports$1 } from "../main-D5xz2ZN1.js";
|
|
10
|
+
import { t as bodyparser_middleware_default } from "../bodyparser_middleware-DTW0epKM.js";
|
|
11
|
+
import { dirname } from "node:path";
|
|
12
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
13
|
+
var AppServiceProvider = class {
|
|
14
|
+
constructor(app) {
|
|
15
|
+
this.app = app;
|
|
16
|
+
}
|
|
17
|
+
registerTestUtils() {
|
|
18
|
+
this.app.container.singleton("testUtils", async () => {
|
|
19
|
+
const { TestUtils } = await import("../src/test_utils/main.js");
|
|
20
|
+
return new TestUtils(this.app);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
registerAce() {
|
|
24
|
+
this.app.container.singleton("ace", async () => {
|
|
25
|
+
const { createAceKernel } = await import("../create_kernel-B4MzSE2_.js");
|
|
26
|
+
return createAceKernel(this.app);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
registerApp() {
|
|
30
|
+
this.app.container.singleton(app_exports.Application, () => this.app);
|
|
31
|
+
this.app.container.alias("app", app_exports.Application);
|
|
32
|
+
}
|
|
33
|
+
registerLogger() {
|
|
34
|
+
this.app.container.singleton(logger_exports.Logger, async (resolver) => {
|
|
35
|
+
return (await resolver.make("logger")).use();
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
registerLoggerManager() {
|
|
39
|
+
this.app.container.singleton("logger", async () => {
|
|
40
|
+
const { LoggerManager } = await import("../modules/logger.js");
|
|
41
|
+
return new LoggerManager(this.app.config.get("logger"));
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
registerConfig() {
|
|
45
|
+
this.app.container.singleton(config_exports.Config, () => this.app.config);
|
|
46
|
+
this.app.container.alias("config", config_exports.Config);
|
|
47
|
+
}
|
|
48
|
+
registerEmitter() {
|
|
49
|
+
this.app.container.singleton(events_exports.Emitter, async () => {
|
|
50
|
+
return new events_exports.Emitter(this.app);
|
|
51
|
+
});
|
|
52
|
+
this.app.container.alias("emitter", events_exports.Emitter);
|
|
53
|
+
}
|
|
54
|
+
registerEncryption() {
|
|
55
|
+
this.app.container.singleton(encryption_exports.Encryption, () => {
|
|
56
|
+
const appKey = this.app.config.get("app.appKey");
|
|
57
|
+
return new encryption_exports.Encryption({ secret: appKey });
|
|
58
|
+
});
|
|
59
|
+
this.app.container.alias("encryption", encryption_exports.Encryption);
|
|
60
|
+
}
|
|
61
|
+
registerServer() {
|
|
62
|
+
this.app.container.singleton(main_exports.Server, async (resolver) => {
|
|
63
|
+
const encryption = await resolver.make("encryption");
|
|
64
|
+
const emitter = await resolver.make("emitter");
|
|
65
|
+
const logger = await resolver.make("logger");
|
|
66
|
+
const config = this.app.config.get("app.http");
|
|
67
|
+
return new main_exports.Server(this.app, encryption, emitter, logger, config);
|
|
68
|
+
});
|
|
69
|
+
this.app.container.alias("server", main_exports.Server);
|
|
70
|
+
}
|
|
71
|
+
registerRouter() {
|
|
72
|
+
this.app.container.singleton(main_exports.Router, async (resolver) => {
|
|
73
|
+
return (await resolver.make("server")).getRouter();
|
|
74
|
+
});
|
|
75
|
+
this.app.container.alias("router", main_exports.Router);
|
|
76
|
+
}
|
|
77
|
+
registerBodyParserMiddleware() {
|
|
78
|
+
this.app.container.singleton(bodyparser_middleware_default, () => {
|
|
79
|
+
return new bodyparser_middleware_default(this.app.config.get("bodyparser"), this.app.experimentalFlags);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
registerDumper() {
|
|
83
|
+
this.app.container.singleton(Dumper, async () => {
|
|
84
|
+
const config = this.app.config.get("app.dumper", {});
|
|
85
|
+
const dumper = new Dumper(this.app);
|
|
86
|
+
if (config.html) dumper.configureHtmlOutput(config.html);
|
|
87
|
+
if (config.console) dumper.configureAnsiOutput(config.console);
|
|
88
|
+
return dumper;
|
|
89
|
+
});
|
|
90
|
+
this.app.container.alias("dumper", Dumper);
|
|
91
|
+
}
|
|
92
|
+
async emitRoutes(router) {
|
|
93
|
+
try {
|
|
94
|
+
const { routes, imports, types } = router.generateTypes(2);
|
|
95
|
+
const routesTypesPath = this.app.generatedServerPath("routes.d.ts");
|
|
96
|
+
const routesJsonPath = this.app.generatedServerPath("routes.json");
|
|
97
|
+
await mkdir(dirname(routesTypesPath), { recursive: true });
|
|
98
|
+
await Promise.all([writeFile(routesTypesPath, [
|
|
99
|
+
`import '@adonisjs/core/types/http'`,
|
|
100
|
+
...imports,
|
|
101
|
+
"",
|
|
102
|
+
...types,
|
|
103
|
+
"",
|
|
104
|
+
"export type ScannedRoutes = {",
|
|
105
|
+
routes,
|
|
106
|
+
"}",
|
|
107
|
+
`declare module '@adonisjs/core/types/http' {`,
|
|
108
|
+
" export interface RoutesList extends ScannedRoutes {}",
|
|
109
|
+
"}"
|
|
110
|
+
].join("\n")), writeFile(routesJsonPath, JSON.stringify(router.toJSON()))]);
|
|
111
|
+
this.app.notify({
|
|
112
|
+
isAdonisJS: true,
|
|
113
|
+
routesFileLocation: routesJsonPath
|
|
114
|
+
});
|
|
115
|
+
} catch (error) {
|
|
116
|
+
console.error("Unable to generate routes types file due to the following error. This won't impact the dev-server");
|
|
117
|
+
console.error(error);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
register() {
|
|
121
|
+
this.registerApp();
|
|
122
|
+
this.registerAce();
|
|
123
|
+
this.registerDumper();
|
|
124
|
+
this.registerLoggerManager();
|
|
125
|
+
this.registerLogger();
|
|
126
|
+
this.registerConfig();
|
|
127
|
+
this.registerEmitter();
|
|
128
|
+
this.registerEncryption();
|
|
129
|
+
this.registerTestUtils();
|
|
130
|
+
this.registerServer();
|
|
131
|
+
this.registerRouter();
|
|
132
|
+
this.registerBodyParserMiddleware();
|
|
133
|
+
}
|
|
134
|
+
async boot() {
|
|
135
|
+
events_exports.BaseEvent.useEmitter(await this.app.container.make("emitter"));
|
|
136
|
+
main_exports.HttpContext.instanceProperty("serialize", function(value, container) {
|
|
137
|
+
return (0, main_exports$1.serialize)(value, container ?? this.containerResolver);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
async ready() {
|
|
141
|
+
if (!this.app.inProduction) {
|
|
142
|
+
const router = await this.app.container.make("router");
|
|
143
|
+
if (router.commited) await this.emitRoutes(router);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
export { AppServiceProvider as default };
|