@adonisjs/core 7.0.0-next.0 → 7.0.0-next.10
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 +32 -0
- package/build/commands/add.js +17 -0
- package/build/commands/build.d.ts +22 -0
- package/build/commands/build.js +18 -0
- package/build/commands/commands.json +1 -1
- package/build/commands/configure.d.ts +32 -9
- package/build/commands/configure.js +36 -9
- package/build/commands/eject.d.ts +27 -2
- package/build/commands/eject.js +21 -2
- package/build/commands/env/add.d.ts +39 -2
- package/build/commands/env/add.js +30 -3
- package/build/commands/generate_key.d.ts +19 -0
- package/build/commands/generate_key.js +13 -0
- package/build/commands/inspect_rcfile.d.ts +19 -1
- package/build/commands/inspect_rcfile.js +19 -1
- package/build/commands/list/routes.d.ts +31 -9
- package/build/commands/list/routes.js +26 -3
- package/build/commands/make/command.d.ts +25 -2
- package/build/commands/make/command.js +22 -2
- package/build/commands/make/controller.d.ts +33 -0
- package/build/commands/make/controller.js +18 -0
- package/build/commands/make/event.d.ts +28 -2
- package/build/commands/make/event.js +25 -2
- package/build/commands/make/exception.d.ts +28 -2
- package/build/commands/make/exception.js +25 -2
- package/build/commands/make/listener.d.ts +36 -3
- package/build/commands/make/listener.js +30 -3
- package/build/commands/make/middleware.d.ts +23 -0
- package/build/commands/make/middleware.js +17 -0
- package/build/commands/make/preload.d.ts +30 -3
- package/build/commands/make/preload.js +24 -4
- package/build/commands/make/provider.d.ts +31 -2
- package/build/commands/make/provider.js +25 -3
- package/build/commands/make/service.d.ts +19 -0
- package/build/commands/make/service.js +16 -0
- package/build/commands/make/test.d.ts +26 -3
- package/build/commands/make/test.js +34 -6
- package/build/commands/make/transformer.d.ts +43 -0
- package/build/commands/make/transformer.js +65 -0
- package/build/commands/make/validator.d.ts +34 -3
- package/build/commands/make/validator.js +28 -3
- package/build/commands/make/view.d.ts +25 -2
- package/build/commands/make/view.js +22 -2
- package/build/commands/repl.d.ts +22 -2
- package/build/commands/repl.js +22 -2
- package/build/commands/serve.d.ts +36 -0
- package/build/commands/serve.js +26 -9
- package/build/commands/test.d.ts +66 -3
- package/build/commands/test.js +37 -13
- package/build/modules/ace/codemods.d.ts +109 -14
- package/build/modules/ace/codemods.js +119 -16
- package/build/modules/ace/commands.d.ts +0 -1
- package/build/modules/ace/commands.js +0 -3
- package/build/modules/ace/main.d.ts +30 -0
- package/build/modules/ace/main.js +30 -0
- package/build/modules/app.d.ts +17 -0
- package/build/modules/app.js +17 -0
- package/build/modules/config.d.ts +17 -0
- package/build/modules/config.js +17 -0
- package/build/modules/dumper/dumper.d.ts +5 -0
- package/build/modules/dumper/dumper.js +11 -1
- package/build/modules/dumper/main.d.ts +21 -0
- package/build/modules/dumper/main.js +21 -0
- package/build/modules/encryption.d.ts +17 -0
- package/build/modules/encryption.js +17 -0
- package/build/modules/env/main.d.ts +19 -0
- package/build/modules/env/main.js +19 -0
- package/build/modules/hash/drivers/bcrypt.d.ts +11 -0
- package/build/modules/hash/drivers/bcrypt.js +11 -0
- package/build/modules/hash/main.d.ts +18 -0
- package/build/modules/hash/main.js +18 -0
- package/build/modules/http/url_builder_client.d.ts +1 -0
- package/build/modules/http/url_builder_client.js +9 -0
- package/build/providers/app_provider.d.ts +11 -23
- package/build/providers/app_provider.js +41 -45
- package/build/providers/edge_provider.js +62 -1
- package/build/src/assembler_hooks/index_entities.d.ts +3 -17
- package/build/src/assembler_hooks/index_entities.js +31 -15
- package/build/src/cli_formatters/routes_list.js +23 -7
- package/build/src/helpers/http.d.ts +20 -0
- package/build/src/helpers/http.js +28 -0
- package/build/src/helpers/main.d.ts +1 -5
- package/build/src/helpers/main.js +1 -5
- package/build/src/helpers/string.js +24 -0
- package/build/src/helpers/types.d.ts +1 -0
- package/build/src/ignitor/http.js +18 -5
- package/build/src/types.d.ts +7 -0
- package/build/src/utils.d.ts +26 -0
- package/build/src/utils.js +65 -0
- package/build/src/vine.js +14 -6
- package/build/stubs/make/transformer/main.stub +18 -0
- package/build/types/common.d.ts +1 -0
- package/build/types/common.js +9 -0
- package/build/types/helpers.d.ts +20 -0
- package/build/types/http.d.ts +1 -0
- package/package.json +26 -23
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Router } from '../modules/http/main.ts';
|
|
2
|
-
import { type
|
|
2
|
+
import { type SerializeFn } from '../types/transformers.ts';
|
|
3
3
|
import type { ApplicationService } from '../src/types.ts';
|
|
4
4
|
/**
|
|
5
5
|
* Extend HTTP request class with the transform method
|
|
6
6
|
*/
|
|
7
7
|
declare module '@adonisjs/core/http' {
|
|
8
8
|
interface HttpContext {
|
|
9
|
-
|
|
9
|
+
serialize: SerializeFn;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
@@ -174,32 +174,20 @@ export default class AppServiceProvider {
|
|
|
174
174
|
*/
|
|
175
175
|
protected registerDumper(): void;
|
|
176
176
|
/**
|
|
177
|
-
* Generates
|
|
178
|
-
* them to the ".adonisjs/server/routes.d.ts" file
|
|
177
|
+
* Generates TypeScript type definitions and JSON representation of routes
|
|
179
178
|
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
179
|
+
* Creates route type definitions for better IDE support and a JSON file
|
|
180
|
+
* containing all registered routes. This is used in development mode for
|
|
181
|
+
* tooling integration and type-safety.
|
|
182
182
|
*
|
|
183
|
-
* @param router - The router instance
|
|
183
|
+
* @param router - The router instance containing registered routes
|
|
184
184
|
*
|
|
185
185
|
* @example
|
|
186
|
-
* await
|
|
187
|
-
*
|
|
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
|
|
186
|
+
* const router = await container.make('router')
|
|
187
|
+
* await this.emitRoutes(router)
|
|
188
|
+
* // Generates .adonisjs/server/routes.d.ts and routes.json
|
|
201
189
|
*/
|
|
202
|
-
protected
|
|
190
|
+
protected emitRoutes(router: Router): Promise<void>;
|
|
203
191
|
/**
|
|
204
192
|
* Registers bindings
|
|
205
193
|
*
|
|
@@ -16,7 +16,7 @@ import { HttpContext } from "../modules/http/main.js";
|
|
|
16
16
|
import { Encryption } from "../modules/encryption.js";
|
|
17
17
|
import { Router, Server } from "../modules/http/main.js";
|
|
18
18
|
import { BaseEvent, Emitter } from "../modules/events.js";
|
|
19
|
-
import {
|
|
19
|
+
import { serialize } from "../modules/transformers/main.js";
|
|
20
20
|
import BodyParserMiddleware from "../modules/bodyparser/bodyparser_middleware.js";
|
|
21
21
|
/**
|
|
22
22
|
* The Application Service provider registers all the baseline
|
|
@@ -225,7 +225,7 @@ export default class AppServiceProvider {
|
|
|
225
225
|
* await middleware.handle(ctx, next)
|
|
226
226
|
*/
|
|
227
227
|
registerBodyParserMiddleware() {
|
|
228
|
-
this.app.container.
|
|
228
|
+
this.app.container.singleton(BodyParserMiddleware, () => {
|
|
229
229
|
const config = this.app.config.get('bodyparser');
|
|
230
230
|
return new BodyParserMiddleware(config, this.app.experimentalFlags);
|
|
231
231
|
});
|
|
@@ -256,50 +256,47 @@ export default class AppServiceProvider {
|
|
|
256
256
|
this.app.container.alias('dumper', Dumper);
|
|
257
257
|
}
|
|
258
258
|
/**
|
|
259
|
-
* Generates
|
|
260
|
-
* them to the ".adonisjs/server/routes.d.ts" file
|
|
259
|
+
* Generates TypeScript type definitions and JSON representation of routes
|
|
261
260
|
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
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
264
|
*
|
|
265
|
-
* @param router - The router instance
|
|
265
|
+
* @param router - The router instance containing registered routes
|
|
266
266
|
*
|
|
267
267
|
* @example
|
|
268
|
-
* await
|
|
269
|
-
*
|
|
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
|
|
268
|
+
* const router = await container.make('router')
|
|
269
|
+
* await this.emitRoutes(router)
|
|
270
|
+
* // Generates .adonisjs/server/routes.d.ts and routes.json
|
|
297
271
|
*/
|
|
298
|
-
async
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
+
}
|
|
303
300
|
}
|
|
304
301
|
/**
|
|
305
302
|
* Registers bindings
|
|
@@ -337,8 +334,8 @@ export default class AppServiceProvider {
|
|
|
337
334
|
*/
|
|
338
335
|
async boot() {
|
|
339
336
|
BaseEvent.useEmitter(await this.app.container.make('emitter'));
|
|
340
|
-
HttpContext.
|
|
341
|
-
return
|
|
337
|
+
HttpContext.instanceProperty('serialize', function (value, container) {
|
|
338
|
+
return serialize(value, container ?? this.containerResolver);
|
|
342
339
|
});
|
|
343
340
|
}
|
|
344
341
|
/**
|
|
@@ -355,8 +352,7 @@ export default class AppServiceProvider {
|
|
|
355
352
|
if (!this.app.inProduction) {
|
|
356
353
|
const router = await this.app.container.make('router');
|
|
357
354
|
if (router.commited) {
|
|
358
|
-
await this.
|
|
359
|
-
await this.generateRoutesTypes(router);
|
|
355
|
+
await this.emitRoutes(router);
|
|
360
356
|
}
|
|
361
357
|
}
|
|
362
358
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import edge from 'edge.js';
|
|
10
10
|
import { pluginEdgeDumper } from "../modules/dumper/plugins/edge.js";
|
|
11
|
-
import { BriskRoute, HttpContext } from "../modules/http/main.js";
|
|
11
|
+
import { BriskRoute, HttpContext, Qs } from "../modules/http/main.js";
|
|
12
12
|
/**
|
|
13
13
|
* The Edge service provider configures Edge to work within
|
|
14
14
|
* an AdonisJS application environment
|
|
@@ -53,6 +53,7 @@ export default class EdgeServiceProvider {
|
|
|
53
53
|
*/
|
|
54
54
|
async boot() {
|
|
55
55
|
const app = this.app;
|
|
56
|
+
const qs = new Qs(app.config.get('app.http.qs', {}));
|
|
56
57
|
const router = await this.app.container.make('router');
|
|
57
58
|
const dumper = await this.app.container.make('dumper');
|
|
58
59
|
function edgeConfigResolver(key, defaultValue) {
|
|
@@ -61,6 +62,25 @@ export default class EdgeServiceProvider {
|
|
|
61
62
|
edgeConfigResolver.has = function (key) {
|
|
62
63
|
return app.config.has(key);
|
|
63
64
|
};
|
|
65
|
+
function clientRoutes() {
|
|
66
|
+
const routes = router.toJSON();
|
|
67
|
+
return Object.keys(routes).reduce((result, domain) => {
|
|
68
|
+
result[domain] = routes[domain].reduce((routesResult, route) => {
|
|
69
|
+
if (!route.name) {
|
|
70
|
+
return routesResult;
|
|
71
|
+
}
|
|
72
|
+
routesResult.push({
|
|
73
|
+
domain: route.domain,
|
|
74
|
+
methods: route.methods,
|
|
75
|
+
pattern: route.pattern,
|
|
76
|
+
tokens: route.tokens,
|
|
77
|
+
name: route.name,
|
|
78
|
+
});
|
|
79
|
+
return routesResult;
|
|
80
|
+
}, []);
|
|
81
|
+
return result;
|
|
82
|
+
}, {});
|
|
83
|
+
}
|
|
64
84
|
/**
|
|
65
85
|
* Mount the default disk
|
|
66
86
|
*/
|
|
@@ -71,6 +91,7 @@ export default class EdgeServiceProvider {
|
|
|
71
91
|
edge.configure({ cache: app.inProduction });
|
|
72
92
|
/**
|
|
73
93
|
* Define Edge global helpers
|
|
94
|
+
* @deprecated
|
|
74
95
|
*/
|
|
75
96
|
edge.global('route', function (...args) {
|
|
76
97
|
return router.makeUrl(...args);
|
|
@@ -80,6 +101,46 @@ export default class EdgeServiceProvider {
|
|
|
80
101
|
});
|
|
81
102
|
edge.global('app', app);
|
|
82
103
|
edge.global('config', edgeConfigResolver);
|
|
104
|
+
edge.global('routes', function () {
|
|
105
|
+
return clientRoutes();
|
|
106
|
+
});
|
|
107
|
+
edge.global('routesJSON', function () {
|
|
108
|
+
return JSON.stringify(clientRoutes());
|
|
109
|
+
});
|
|
110
|
+
/**
|
|
111
|
+
* Route helpers
|
|
112
|
+
*/
|
|
113
|
+
edge.global('urlFor', function (...args) {
|
|
114
|
+
return router.urlBuilder.urlFor(...args);
|
|
115
|
+
});
|
|
116
|
+
edge.global('signedUrlFor', function (...args) {
|
|
117
|
+
return router.urlBuilder.signedUrlFor(...args);
|
|
118
|
+
});
|
|
119
|
+
/**
|
|
120
|
+
* Sharing qs parser with templates
|
|
121
|
+
*/
|
|
122
|
+
edge.global('qs', qs);
|
|
123
|
+
edge.global('formAttributes', function (route, method, params, options) {
|
|
124
|
+
/**
|
|
125
|
+
* Normalize method and keep a reference to the original method
|
|
126
|
+
*/
|
|
127
|
+
options = options ?? {};
|
|
128
|
+
method = method.toUpperCase();
|
|
129
|
+
const original = method;
|
|
130
|
+
/**
|
|
131
|
+
* If method if not GET and POST, then use the querystring _method
|
|
132
|
+
* to and force update the method to "POST"
|
|
133
|
+
*/
|
|
134
|
+
if (method !== 'GET' && method !== 'POST') {
|
|
135
|
+
method = 'POST';
|
|
136
|
+
options = { ...options, qs: { _method: original, ...options.qs } };
|
|
137
|
+
}
|
|
138
|
+
const { action } = router.urlBuilder.urlFor.method(original, route, params, options).form;
|
|
139
|
+
return {
|
|
140
|
+
action,
|
|
141
|
+
method,
|
|
142
|
+
};
|
|
143
|
+
});
|
|
83
144
|
/**
|
|
84
145
|
* Creating a isolated instance of edge renderer
|
|
85
146
|
*/
|
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
import { type IndexEntitiesConfig } from '../types.ts';
|
|
2
|
-
import { type CommonHooks } from '@adonisjs/assembler/types';
|
|
3
2
|
/**
|
|
4
3
|
* Configures the IndexGenerator to create barrel files for "controllers", "events",
|
|
5
4
|
* and "listeners". This function is used as an assembler hook to automatically generate
|
|
6
5
|
* index files that export all modules from specified directories.
|
|
7
6
|
*
|
|
8
7
|
* @param {IndexEntitiesConfig} entities - Configuration object for entities indexing
|
|
9
|
-
* @param {object} [entities.events] - Configuration for events indexing
|
|
10
|
-
* @param {boolean} [entities.events.enabled=true] - Whether to enable events indexing
|
|
11
|
-
* @param {string} [entities.events.source='app/events'] - Source directory for events
|
|
12
|
-
* @param {string} [entities.events.importAlias='#events'] - Import alias for events
|
|
13
|
-
* @param {string} [entities.events.glob] - Glob pattern for matching event files
|
|
14
|
-
* @param {object} [entities.listeners] - Configuration for listeners indexing
|
|
15
|
-
* @param {boolean} [entities.listeners.enabled=true] - Whether to enable listeners indexing
|
|
16
|
-
* @param {string} [entities.listeners.source='app/listeners'] - Source directory for listeners
|
|
17
|
-
* @param {string} [entities.listeners.importAlias='#listeners'] - Import alias for listeners
|
|
18
|
-
* @param {string} [entities.listeners.glob] - Glob pattern for matching listener files
|
|
19
|
-
* @param {object} [entities.controllers] - Configuration for controllers indexing
|
|
20
|
-
* @param {boolean} [entities.controllers.enabled=true] - Whether to enable controllers indexing
|
|
21
|
-
* @param {string} [entities.controllers.source='app/controllers'] - Source directory for controllers
|
|
22
|
-
* @param {string} [entities.controllers.importAlias='#controllers'] - Import alias for controllers
|
|
23
|
-
* @param {string} [entities.controllers.glob] - Glob pattern for matching controller files
|
|
24
8
|
*
|
|
25
9
|
* @example
|
|
26
10
|
* // Basic usage with default configuration
|
|
@@ -48,4 +32,6 @@ import { type CommonHooks } from '@adonisjs/assembler/types';
|
|
|
48
32
|
* }
|
|
49
33
|
* })
|
|
50
34
|
*/
|
|
51
|
-
export declare function indexEntities(entities?: IndexEntitiesConfig):
|
|
35
|
+
export declare function indexEntities(entities?: IndexEntitiesConfig): {
|
|
36
|
+
run(_: import("@adonisjs/assembler").DevServer | import("@adonisjs/assembler").TestRunner | import("@adonisjs/assembler").Bundler, indexGenerator: import("@adonisjs/assembler/index_generator").IndexGenerator): void;
|
|
37
|
+
};
|
|
@@ -6,27 +6,14 @@
|
|
|
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 stringHelpers from "../helpers/string.js";
|
|
10
|
+
import { outputTransformerDataObjects } from "../utils.js";
|
|
9
11
|
/**
|
|
10
12
|
* Configures the IndexGenerator to create barrel files for "controllers", "events",
|
|
11
13
|
* and "listeners". This function is used as an assembler hook to automatically generate
|
|
12
14
|
* index files that export all modules from specified directories.
|
|
13
15
|
*
|
|
14
16
|
* @param {IndexEntitiesConfig} entities - Configuration object for entities indexing
|
|
15
|
-
* @param {object} [entities.events] - Configuration for events indexing
|
|
16
|
-
* @param {boolean} [entities.events.enabled=true] - Whether to enable events indexing
|
|
17
|
-
* @param {string} [entities.events.source='app/events'] - Source directory for events
|
|
18
|
-
* @param {string} [entities.events.importAlias='#events'] - Import alias for events
|
|
19
|
-
* @param {string} [entities.events.glob] - Glob pattern for matching event files
|
|
20
|
-
* @param {object} [entities.listeners] - Configuration for listeners indexing
|
|
21
|
-
* @param {boolean} [entities.listeners.enabled=true] - Whether to enable listeners indexing
|
|
22
|
-
* @param {string} [entities.listeners.source='app/listeners'] - Source directory for listeners
|
|
23
|
-
* @param {string} [entities.listeners.importAlias='#listeners'] - Import alias for listeners
|
|
24
|
-
* @param {string} [entities.listeners.glob] - Glob pattern for matching listener files
|
|
25
|
-
* @param {object} [entities.controllers] - Configuration for controllers indexing
|
|
26
|
-
* @param {boolean} [entities.controllers.enabled=true] - Whether to enable controllers indexing
|
|
27
|
-
* @param {string} [entities.controllers.source='app/controllers'] - Source directory for controllers
|
|
28
|
-
* @param {string} [entities.controllers.importAlias='#controllers'] - Import alias for controllers
|
|
29
|
-
* @param {string} [entities.controllers.glob] - Glob pattern for matching controller files
|
|
30
17
|
*
|
|
31
18
|
* @example
|
|
32
19
|
* // Basic usage with default configuration
|
|
@@ -58,11 +45,18 @@ export function indexEntities(entities = {}) {
|
|
|
58
45
|
const events = Object.assign({ enabled: true, source: 'app/events', importAlias: '#events' }, entities.events);
|
|
59
46
|
const listeners = Object.assign({ enabled: true, source: 'app/listeners', importAlias: '#listeners' }, entities.listeners);
|
|
60
47
|
const controllers = Object.assign({ enabled: true, source: 'app/controllers', importAlias: '#controllers' }, entities.controllers);
|
|
48
|
+
const transformers = Object.assign({
|
|
49
|
+
enabled: false,
|
|
50
|
+
source: 'app/transformers',
|
|
51
|
+
importAlias: '#transformers',
|
|
52
|
+
withSharedProps: false,
|
|
53
|
+
}, entities.transformers);
|
|
61
54
|
return {
|
|
62
55
|
run(_, indexGenerator) {
|
|
63
56
|
if (events.enabled) {
|
|
64
57
|
indexGenerator.add('events', {
|
|
65
58
|
source: events.source,
|
|
59
|
+
disableLazyImports: true,
|
|
66
60
|
glob: events.glob,
|
|
67
61
|
as: 'barrelFile',
|
|
68
62
|
exportName: 'events',
|
|
@@ -91,6 +85,28 @@ export function indexEntities(entities = {}) {
|
|
|
91
85
|
output: '.adonisjs/server/controllers.ts',
|
|
92
86
|
});
|
|
93
87
|
}
|
|
88
|
+
if (transformers.enabled) {
|
|
89
|
+
indexGenerator.add('transformers', {
|
|
90
|
+
source: transformers.source,
|
|
91
|
+
glob: transformers.glob,
|
|
92
|
+
as(vfs, buffer, __, helpers) {
|
|
93
|
+
const transformersList = vfs.asTree({
|
|
94
|
+
transformKey(key) {
|
|
95
|
+
const segments = key.split('/');
|
|
96
|
+
const baseName = segments.pop();
|
|
97
|
+
return [
|
|
98
|
+
...segments.map((segment) => stringHelpers.pascalCase(segment)),
|
|
99
|
+
stringHelpers.create(baseName).removeSuffix('transformer').pascalCase(),
|
|
100
|
+
].join('/');
|
|
101
|
+
},
|
|
102
|
+
transformValue: helpers.toImportPath,
|
|
103
|
+
});
|
|
104
|
+
outputTransformerDataObjects(transformersList, buffer, transformers.withSharedProps);
|
|
105
|
+
},
|
|
106
|
+
importAlias: transformers.importAlias,
|
|
107
|
+
output: '.adonisjs/client/data.d.ts',
|
|
108
|
+
});
|
|
109
|
+
}
|
|
94
110
|
},
|
|
95
111
|
};
|
|
96
112
|
}
|
|
@@ -64,7 +64,9 @@ export class RoutesListFormatter {
|
|
|
64
64
|
this.#router.commit();
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
* Test if a route clears the applied filters
|
|
67
|
+
* Test if a route clears the applied filters based on middleware, name, pattern, and handler.
|
|
68
|
+
*
|
|
69
|
+
* @param route - The serialized route to test against filters
|
|
68
70
|
*/
|
|
69
71
|
#isAllowedByFilters(route) {
|
|
70
72
|
let allowRoute = true;
|
|
@@ -124,7 +126,10 @@ export class RoutesListFormatter {
|
|
|
124
126
|
return false;
|
|
125
127
|
}
|
|
126
128
|
/**
|
|
127
|
-
* Serializes routes JSON to an object that can be used for pretty printing
|
|
129
|
+
* Serializes routes JSON to an object that can be used for pretty printing.
|
|
130
|
+
* Converts RouteJSON into a format suitable for display and filtering.
|
|
131
|
+
*
|
|
132
|
+
* @param route - The route JSON object to serialize
|
|
128
133
|
*/
|
|
129
134
|
async #serializeRoute(route) {
|
|
130
135
|
let methods = route.methods;
|
|
@@ -143,13 +148,17 @@ export class RoutesListFormatter {
|
|
|
143
148
|
};
|
|
144
149
|
}
|
|
145
150
|
/**
|
|
146
|
-
* Formats the route method for the ansi list and table
|
|
151
|
+
* Formats the route method for the ansi list and table with dim styling.
|
|
152
|
+
*
|
|
153
|
+
* @param method - The HTTP method to format (GET, POST, etc.)
|
|
147
154
|
*/
|
|
148
155
|
#formatRouteMethod(method) {
|
|
149
156
|
return this.#colors.dim(method);
|
|
150
157
|
}
|
|
151
158
|
/**
|
|
152
|
-
* Formats route pattern for the ansi list and table
|
|
159
|
+
* Formats route pattern for the ansi list and table with colored parameters and route name.
|
|
160
|
+
*
|
|
161
|
+
* @param route - The serialized route containing pattern and name information
|
|
153
162
|
*/
|
|
154
163
|
#formatRoutePattern(route) {
|
|
155
164
|
const pattern = this.#router
|
|
@@ -170,7 +179,9 @@ export class RoutesListFormatter {
|
|
|
170
179
|
return `${pattern === '/' ? pattern : `/${pattern}`}${route.name ? ` ${this.#colors.dim(`(${route.name})`)}` : ''} `;
|
|
171
180
|
}
|
|
172
181
|
/**
|
|
173
|
-
* Formats controller name for the ansi list and table
|
|
182
|
+
* Formats controller name for the ansi list and table with cyan coloring.
|
|
183
|
+
*
|
|
184
|
+
* @param route - The serialized route containing handler information
|
|
174
185
|
*/
|
|
175
186
|
#formatControllerName(route) {
|
|
176
187
|
return route.handler.type === 'controller'
|
|
@@ -178,7 +189,9 @@ export class RoutesListFormatter {
|
|
|
178
189
|
: '';
|
|
179
190
|
}
|
|
180
191
|
/**
|
|
181
|
-
* Formats action name for the ansi list and table
|
|
192
|
+
* Formats action name for the ansi list and table with cyan coloring and arguments.
|
|
193
|
+
*
|
|
194
|
+
* @param route - The serialized route containing handler information
|
|
182
195
|
*/
|
|
183
196
|
#formatAction(route) {
|
|
184
197
|
if (route.handler.type === 'controller') {
|
|
@@ -191,7 +204,10 @@ export class RoutesListFormatter {
|
|
|
191
204
|
return functionName;
|
|
192
205
|
}
|
|
193
206
|
/**
|
|
194
|
-
* Formats route middleware for the ansi list and table
|
|
207
|
+
* Formats route middleware for the ansi list and table with optional compacting.
|
|
208
|
+
*
|
|
209
|
+
* @param route - The serialized route containing middleware information
|
|
210
|
+
* @param mode - Display mode: 'normal' shows all middleware, 'compact' truncates long lists
|
|
195
211
|
*/
|
|
196
212
|
#formatMiddleware(route, mode = 'normal') {
|
|
197
213
|
if (mode === 'compact' && route.middleware.length > 3) {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP helper utilities re-exported from @adonisjs/http-server. This module
|
|
3
|
+
* provides a convenient entry point for accessing all HTTP-related utilities
|
|
4
|
+
* including route helpers, middleware utilities, and request/response helpers.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Import specific HTTP helpers
|
|
8
|
+
* import { middlewareInfo, routeInfo } from '@adonisjs/core/helpers'
|
|
9
|
+
*
|
|
10
|
+
* const middleware = middlewareInfo('cors', CorsMiddleware)
|
|
11
|
+
* const route = routeInfo('users.show', '/users/:id')
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Access all HTTP helpers
|
|
15
|
+
* import * as httpHelpers from '@adonisjs/core/helpers/http'
|
|
16
|
+
*
|
|
17
|
+
* // Use any helper from the http-server package
|
|
18
|
+
* const routeData = httpHelpers.routeInfo('api.posts', '/api/posts')
|
|
19
|
+
*/
|
|
20
|
+
export * from '@adonisjs/http-server/helpers';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @adonisjs/core
|
|
3
|
+
*
|
|
4
|
+
* (c) AdonisJS
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* HTTP helper utilities re-exported from @adonisjs/http-server. This module
|
|
11
|
+
* provides a convenient entry point for accessing all HTTP-related utilities
|
|
12
|
+
* including route helpers, middleware utilities, and request/response helpers.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Import specific HTTP helpers
|
|
16
|
+
* import { middlewareInfo, routeInfo } from '@adonisjs/core/helpers'
|
|
17
|
+
*
|
|
18
|
+
* const middleware = middlewareInfo('cors', CorsMiddleware)
|
|
19
|
+
* const route = routeInfo('users.show', '/users/:id')
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Access all HTTP helpers
|
|
23
|
+
* import * as httpHelpers from '@adonisjs/core/helpers/http'
|
|
24
|
+
*
|
|
25
|
+
* // Use any helper from the http-server package
|
|
26
|
+
* const routeData = httpHelpers.routeInfo('api.posts', '/api/posts')
|
|
27
|
+
*/
|
|
28
|
+
export * from '@adonisjs/http-server/helpers';
|
|
@@ -37,12 +37,8 @@ export { default as base64 } from '@poppinss/utils/base64';
|
|
|
37
37
|
* Core utilities including function composition, secret management,
|
|
38
38
|
* safe equality comparison, and message building.
|
|
39
39
|
*/
|
|
40
|
-
export { compose, Secret, safeEqual, MessageBuilder } from '@poppinss/utils';
|
|
40
|
+
export { compose, Secret, safeEqual, MessageBuilder, defineStaticProperty } from '@poppinss/utils';
|
|
41
41
|
/**
|
|
42
42
|
* Verification token utility for creating secure tokens.
|
|
43
43
|
*/
|
|
44
44
|
export { VerificationToken } from './verification_token.ts';
|
|
45
|
-
/**
|
|
46
|
-
* HTTP server helper functions for middleware and route information.
|
|
47
|
-
*/
|
|
48
|
-
export { middlewareInfo, routeInfo } from '@adonisjs/http-server/helpers';
|
|
@@ -45,12 +45,8 @@ export { default as base64 } from '@poppinss/utils/base64';
|
|
|
45
45
|
* Core utilities including function composition, secret management,
|
|
46
46
|
* safe equality comparison, and message building.
|
|
47
47
|
*/
|
|
48
|
-
export { compose, Secret, safeEqual, MessageBuilder } from '@poppinss/utils';
|
|
48
|
+
export { compose, Secret, safeEqual, MessageBuilder, defineStaticProperty } from '@poppinss/utils';
|
|
49
49
|
/**
|
|
50
50
|
* Verification token utility for creating secure tokens.
|
|
51
51
|
*/
|
|
52
52
|
export { VerificationToken } from "./verification_token.js";
|
|
53
|
-
/**
|
|
54
|
-
* HTTP server helper functions for middleware and route information.
|
|
55
|
-
*/
|
|
56
|
-
export { middlewareInfo, routeInfo } from '@adonisjs/http-server/helpers';
|
|
@@ -34,12 +34,30 @@ const stringHelpers = {
|
|
|
34
34
|
create(value) {
|
|
35
35
|
return new StringBuilder(value);
|
|
36
36
|
},
|
|
37
|
+
/**
|
|
38
|
+
* Formats Node.js hrtime output into a human-readable string.
|
|
39
|
+
*
|
|
40
|
+
* @param time - Tuple of [seconds, nanoseconds] from process.hrtime()
|
|
41
|
+
* @param options - Formatting options for output style and precision
|
|
42
|
+
*/
|
|
37
43
|
prettyHrTime(time, options) {
|
|
38
44
|
return prettyHrTime(time, options);
|
|
39
45
|
},
|
|
46
|
+
/**
|
|
47
|
+
* Check if a string is empty or contains only whitespace characters.
|
|
48
|
+
*
|
|
49
|
+
* @param value - The string to check for emptiness
|
|
50
|
+
*/
|
|
40
51
|
isEmpty(value) {
|
|
41
52
|
return value.trim().length === 0;
|
|
42
53
|
},
|
|
54
|
+
/**
|
|
55
|
+
* Escape HTML entities to prevent XSS attacks and display HTML safely.
|
|
56
|
+
*
|
|
57
|
+
* @param value - The string containing HTML to escape
|
|
58
|
+
* @param options - Optional configuration for escaping behavior
|
|
59
|
+
* @param options.encodeSymbols - Whether to also encode Unicode symbols as HTML entities
|
|
60
|
+
*/
|
|
43
61
|
escapeHTML(value, options) {
|
|
44
62
|
value = he.escape(value);
|
|
45
63
|
if (options && options.encodeSymbols) {
|
|
@@ -47,6 +65,12 @@ const stringHelpers = {
|
|
|
47
65
|
}
|
|
48
66
|
return value;
|
|
49
67
|
},
|
|
68
|
+
/**
|
|
69
|
+
* Encode Unicode symbols and special characters as HTML entities.
|
|
70
|
+
*
|
|
71
|
+
* @param value - The string containing symbols to encode
|
|
72
|
+
* @param options - Encoding options from the 'he' library
|
|
73
|
+
*/
|
|
50
74
|
encodeSymbols(value, options) {
|
|
51
75
|
return he.encode(value, options);
|
|
52
76
|
},
|
|
@@ -104,6 +104,7 @@ declare const types: {
|
|
|
104
104
|
urlInstance: typeof import("@sindresorhus/is").isUrlInstance;
|
|
105
105
|
urlSearchParams: typeof import("@sindresorhus/is").isUrlSearchParams;
|
|
106
106
|
urlString: typeof import("@sindresorhus/is").isUrlString;
|
|
107
|
+
optional: typeof import("@sindresorhus/is").isOptional;
|
|
107
108
|
validDate: typeof import("@sindresorhus/is").isValidDate;
|
|
108
109
|
validLength: typeof import("@sindresorhus/is").isValidLength;
|
|
109
110
|
weakMap: typeof import("@sindresorhus/is").isWeakMap;
|
|
@@ -32,7 +32,9 @@ export class HttpServerProcess {
|
|
|
32
32
|
this.#ignitor = ignitor;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* Calling this method closes the underlying HTTP server
|
|
35
|
+
* Calling this method closes the underlying HTTP server gracefully.
|
|
36
|
+
*
|
|
37
|
+
* @param nodeHttpServer - The Node.js HTTP or HTTPS server instance to close
|
|
36
38
|
*/
|
|
37
39
|
#close(nodeHttpServer) {
|
|
38
40
|
return new Promise((resolve) => {
|
|
@@ -42,7 +44,11 @@ export class HttpServerProcess {
|
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
44
46
|
* Monitors the app and the server to close the HTTP server when
|
|
45
|
-
* either one of them goes down
|
|
47
|
+
* either one of them goes down. Sets up event listeners for graceful shutdown.
|
|
48
|
+
*
|
|
49
|
+
* @param nodeHttpServer - The Node.js HTTP or HTTPS server instance to monitor
|
|
50
|
+
* @param app - The application service instance
|
|
51
|
+
* @param logger - The logger service for error reporting
|
|
46
52
|
*/
|
|
47
53
|
#monitorAppAndServer(nodeHttpServer, app, logger) {
|
|
48
54
|
/**
|
|
@@ -64,7 +70,9 @@ export class HttpServerProcess {
|
|
|
64
70
|
});
|
|
65
71
|
}
|
|
66
72
|
/**
|
|
67
|
-
* Starts the
|
|
73
|
+
* Starts the HTTP server on a given host and port using environment variables.
|
|
74
|
+
*
|
|
75
|
+
* @param nodeHttpServer - The Node.js HTTP or HTTPS server instance to start listening
|
|
68
76
|
*/
|
|
69
77
|
#listen(nodeHttpServer) {
|
|
70
78
|
return new Promise((resolve, reject) => {
|
|
@@ -81,8 +89,13 @@ export class HttpServerProcess {
|
|
|
81
89
|
});
|
|
82
90
|
}
|
|
83
91
|
/**
|
|
84
|
-
* Notifies the app and the parent process that the
|
|
85
|
-
*
|
|
92
|
+
* Notifies the app and the parent process that the HTTP server is ready.
|
|
93
|
+
* Sends notifications through multiple channels: parent process, logger, and event emitter.
|
|
94
|
+
*
|
|
95
|
+
* @param app - The application service instance for parent process notification
|
|
96
|
+
* @param logger - The logger service for console output
|
|
97
|
+
* @param emitter - The event emitter for app-level notifications
|
|
98
|
+
* @param payload - Server startup information including host, port, and duration
|
|
86
99
|
*/
|
|
87
100
|
#notifyServerHasStarted(app, logger, emitter, payload) {
|
|
88
101
|
/**
|