@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,112 +0,0 @@
|
|
|
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
|
-
import stringHelpers from "../helpers/string.js";
|
|
10
|
-
import { outputTransformerDataObjects } from "../utils.js";
|
|
11
|
-
/**
|
|
12
|
-
* Configures the IndexGenerator to create barrel files for "controllers", "events",
|
|
13
|
-
* and "listeners". This function is used as an assembler hook to automatically generate
|
|
14
|
-
* index files that export all modules from specified directories.
|
|
15
|
-
*
|
|
16
|
-
* @param {IndexEntitiesConfig} entities - Configuration object for entities indexing
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* // Basic usage with default configuration
|
|
20
|
-
* indexEntities({})
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* // Custom configuration for specific entities
|
|
24
|
-
* indexEntities({
|
|
25
|
-
* events: {
|
|
26
|
-
* enabled: true,
|
|
27
|
-
* source: 'app/custom-events',
|
|
28
|
-
* importAlias: '#custom-events'
|
|
29
|
-
* },
|
|
30
|
-
* controllers: {
|
|
31
|
-
* enabled: false
|
|
32
|
-
* }
|
|
33
|
-
* })
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* // Using custom glob patterns
|
|
37
|
-
* indexEntities({
|
|
38
|
-
* listeners: {
|
|
39
|
-
* source: 'app/handlers',
|
|
40
|
-
* glob: '**\/*_handler.ts'
|
|
41
|
-
* }
|
|
42
|
-
* })
|
|
43
|
-
*/
|
|
44
|
-
export function indexEntities(entities = {}) {
|
|
45
|
-
const events = Object.assign({ enabled: true, source: 'app/events', importAlias: '#events' }, entities.events);
|
|
46
|
-
const listeners = Object.assign({ enabled: true, source: 'app/listeners', importAlias: '#listeners' }, entities.listeners);
|
|
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);
|
|
54
|
-
return {
|
|
55
|
-
run(_, indexGenerator) {
|
|
56
|
-
if (events.enabled) {
|
|
57
|
-
indexGenerator.add('events', {
|
|
58
|
-
source: events.source,
|
|
59
|
-
disableLazyImports: true,
|
|
60
|
-
glob: events.glob,
|
|
61
|
-
as: 'barrelFile',
|
|
62
|
-
exportName: 'events',
|
|
63
|
-
importAlias: events.importAlias,
|
|
64
|
-
output: '.adonisjs/server/events.ts',
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
if (listeners.enabled) {
|
|
68
|
-
indexGenerator.add('listeners', {
|
|
69
|
-
source: listeners.source,
|
|
70
|
-
glob: listeners.glob,
|
|
71
|
-
as: 'barrelFile',
|
|
72
|
-
exportName: 'listeners',
|
|
73
|
-
importAlias: listeners.importAlias,
|
|
74
|
-
output: '.adonisjs/server/listeners.ts',
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
if (controllers.enabled) {
|
|
78
|
-
indexGenerator.add('controllers', {
|
|
79
|
-
source: controllers.source,
|
|
80
|
-
glob: controllers.glob,
|
|
81
|
-
as: 'barrelFile',
|
|
82
|
-
exportName: 'controllers',
|
|
83
|
-
importAlias: controllers.importAlias,
|
|
84
|
-
removeSuffix: 'controller',
|
|
85
|
-
output: '.adonisjs/server/controllers.ts',
|
|
86
|
-
});
|
|
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
|
-
}
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
}
|
|
@@ -1,397 +0,0 @@
|
|
|
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
|
-
import stringWidth from 'string-width';
|
|
10
|
-
import { cliHelpers } from "../../modules/ace/main.js";
|
|
11
|
-
import { middlewareInfo, routeInfo } from '@adonisjs/http-server/helpers';
|
|
12
|
-
/**
|
|
13
|
-
* Routes list formatter is used to format the routes to JSON or an ANSI string
|
|
14
|
-
* with pretty output.
|
|
15
|
-
*
|
|
16
|
-
* The decisions of colors, padding, alignment are all handled by the lists formatter
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* const formatter = new RoutesListFormatter(router, ui, {
|
|
20
|
-
* displayHeadRoutes: false,
|
|
21
|
-
* maxPrettyPrintWidth: 120
|
|
22
|
-
* }, {
|
|
23
|
-
* match: 'api',
|
|
24
|
-
* middleware: ['auth']
|
|
25
|
-
* })
|
|
26
|
-
*
|
|
27
|
-
* const ansiOutput = await formatter.formatAsAnsiList()
|
|
28
|
-
*/
|
|
29
|
-
export class RoutesListFormatter {
|
|
30
|
-
/**
|
|
31
|
-
* Router instance containing all registered routes
|
|
32
|
-
*/
|
|
33
|
-
#router;
|
|
34
|
-
/**
|
|
35
|
-
* Colors utility for ANSI formatting
|
|
36
|
-
*/
|
|
37
|
-
#colors;
|
|
38
|
-
/**
|
|
39
|
-
* Table utility for creating formatted tables
|
|
40
|
-
*/
|
|
41
|
-
#table;
|
|
42
|
-
/**
|
|
43
|
-
* Options for printing routes
|
|
44
|
-
*/
|
|
45
|
-
#options;
|
|
46
|
-
/**
|
|
47
|
-
* Filters to apply when finding routes
|
|
48
|
-
*/
|
|
49
|
-
#filters;
|
|
50
|
-
/**
|
|
51
|
-
* Creates a new instance of the routes list formatter
|
|
52
|
-
*
|
|
53
|
-
* @param router - Router instance containing routes to format
|
|
54
|
-
* @param ui - UI primitives for colors and table formatting
|
|
55
|
-
* @param options - Display options for route formatting
|
|
56
|
-
* @param filters - Filters to apply when displaying routes
|
|
57
|
-
*/
|
|
58
|
-
constructor(router, ui, options, filters) {
|
|
59
|
-
this.#router = router;
|
|
60
|
-
this.#colors = ui.colors;
|
|
61
|
-
this.#table = ui.table;
|
|
62
|
-
this.#filters = filters;
|
|
63
|
-
this.#options = options;
|
|
64
|
-
this.#router.commit();
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
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
|
|
70
|
-
*/
|
|
71
|
-
#isAllowedByFilters(route) {
|
|
72
|
-
let allowRoute = true;
|
|
73
|
-
/**
|
|
74
|
-
* Check if the route is allowed by applying the middleware
|
|
75
|
-
* filter
|
|
76
|
-
*/
|
|
77
|
-
if (this.#filters.middleware) {
|
|
78
|
-
allowRoute = this.#filters.middleware.every((name) => {
|
|
79
|
-
if (name === '*') {
|
|
80
|
-
return route.middleware.length > 0;
|
|
81
|
-
}
|
|
82
|
-
return route.middleware.find((middleware) => middleware.name === name);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Check if the route has any or the ignored middleware. If yes, do not
|
|
87
|
-
* display the route
|
|
88
|
-
*/
|
|
89
|
-
if (allowRoute && this.#filters.ignoreMiddleware) {
|
|
90
|
-
allowRoute = this.#filters.ignoreMiddleware.every((name) => {
|
|
91
|
-
if (name === '*') {
|
|
92
|
-
return route.middleware.length === 0;
|
|
93
|
-
}
|
|
94
|
-
return !route.middleware.find((middleware) => middleware.name === name);
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* No more filters to be applied
|
|
99
|
-
*/
|
|
100
|
-
if (!this.#filters.match) {
|
|
101
|
-
return allowRoute;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Check if the route name has the match keyword
|
|
105
|
-
*/
|
|
106
|
-
if (route.name.includes(this.#filters.match)) {
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Check if the route pattern has the match keyword
|
|
111
|
-
*/
|
|
112
|
-
if (route.pattern.includes(this.#filters.match)) {
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Check if the route handler has the match keyword
|
|
117
|
-
*/
|
|
118
|
-
if (route.handler.type === 'controller'
|
|
119
|
-
? route.handler.moduleNameOrPath.includes(this.#filters.match)
|
|
120
|
-
: route.handler.name.includes(this.#filters.match)) {
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Disallow route
|
|
125
|
-
*/
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
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
|
|
133
|
-
*/
|
|
134
|
-
async #serializeRoute(route) {
|
|
135
|
-
let methods = route.methods;
|
|
136
|
-
if (!this.#options.displayHeadRoutes) {
|
|
137
|
-
methods = methods.filter((method) => method !== 'HEAD');
|
|
138
|
-
}
|
|
139
|
-
const middlewareList = await Promise.all([...route.middleware.all()].map((middleware) => {
|
|
140
|
-
return middlewareInfo(middleware);
|
|
141
|
-
}));
|
|
142
|
-
return {
|
|
143
|
-
name: route.name || '',
|
|
144
|
-
pattern: route.pattern,
|
|
145
|
-
methods: methods,
|
|
146
|
-
handler: await routeInfo(route),
|
|
147
|
-
middleware: middlewareList.filter((info) => info.type !== 'global'),
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
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.)
|
|
154
|
-
*/
|
|
155
|
-
#formatRouteMethod(method) {
|
|
156
|
-
return this.#colors.dim(method);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
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
|
|
162
|
-
*/
|
|
163
|
-
#formatRoutePattern(route) {
|
|
164
|
-
const pattern = this.#router
|
|
165
|
-
.parsePattern(route.pattern)
|
|
166
|
-
.map((token) => {
|
|
167
|
-
if (token.type === 1) {
|
|
168
|
-
return this.#colors.yellow(`:${token.val}`);
|
|
169
|
-
}
|
|
170
|
-
if (token.type === 3) {
|
|
171
|
-
return this.#colors.yellow(`:${token.val}?`);
|
|
172
|
-
}
|
|
173
|
-
if (token.type === 2) {
|
|
174
|
-
return this.#colors.red(token.val);
|
|
175
|
-
}
|
|
176
|
-
return token.val;
|
|
177
|
-
})
|
|
178
|
-
.join('/');
|
|
179
|
-
return `${pattern === '/' ? pattern : `/${pattern}`}${route.name ? ` ${this.#colors.dim(`(${route.name})`)}` : ''} `;
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Formats controller name for the ansi list and table with cyan coloring.
|
|
183
|
-
*
|
|
184
|
-
* @param route - The serialized route containing handler information
|
|
185
|
-
*/
|
|
186
|
-
#formatControllerName(route) {
|
|
187
|
-
return route.handler.type === 'controller'
|
|
188
|
-
? ` ${this.#colors.cyan(route.handler.moduleNameOrPath)}.`
|
|
189
|
-
: '';
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
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
|
|
195
|
-
*/
|
|
196
|
-
#formatAction(route) {
|
|
197
|
-
if (route.handler.type === 'controller') {
|
|
198
|
-
return `${this.#colors.cyan(route.handler.method)}`;
|
|
199
|
-
}
|
|
200
|
-
const functionName = ` ${this.#colors.cyan(route.handler.name)}`;
|
|
201
|
-
if (route.handler.args) {
|
|
202
|
-
return ` ${functionName}${this.#colors.dim(`(${route.handler.args})`)}`;
|
|
203
|
-
}
|
|
204
|
-
return functionName;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
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
|
|
211
|
-
*/
|
|
212
|
-
#formatMiddleware(route, mode = 'normal') {
|
|
213
|
-
if (mode === 'compact' && route.middleware.length > 3) {
|
|
214
|
-
const firstMiddleware = route.middleware[0].name;
|
|
215
|
-
const secondMiddleware = route.middleware[1].name;
|
|
216
|
-
const diff = route.middleware.length - 2;
|
|
217
|
-
return this.#colors.dim(`${firstMiddleware}, ${secondMiddleware}, and ${diff} more`);
|
|
218
|
-
}
|
|
219
|
-
return this.#colors.dim(`${route.middleware
|
|
220
|
-
.map((one) => one.name)
|
|
221
|
-
.filter((one) => one)
|
|
222
|
-
.join(', ')}`);
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Formatting the domain headling to be in green color with
|
|
226
|
-
* dots around it
|
|
227
|
-
*/
|
|
228
|
-
#formatDomainHeadline(domain) {
|
|
229
|
-
if (domain !== 'root') {
|
|
230
|
-
return cliHelpers.justify([`${this.#colors.dim('..')} ${this.#colors.green(domain)} `], {
|
|
231
|
-
maxWidth: this.#options.maxPrettyPrintWidth || cliHelpers.TERMINAL_SIZE,
|
|
232
|
-
paddingChar: this.#colors.dim('.'),
|
|
233
|
-
})[0];
|
|
234
|
-
}
|
|
235
|
-
return '';
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Justify the ansi list
|
|
239
|
-
*/
|
|
240
|
-
#justifyListTables(tables) {
|
|
241
|
-
return tables.map((table) => {
|
|
242
|
-
/**
|
|
243
|
-
* Formatting methods
|
|
244
|
-
*/
|
|
245
|
-
const methods = table.rows.map((columns) => columns[0]);
|
|
246
|
-
const largestMethodsLength = Math.max(...methods.map((method) => stringWidth(method)));
|
|
247
|
-
const formattedMethods = cliHelpers.justify(methods, {
|
|
248
|
-
maxWidth: largestMethodsLength,
|
|
249
|
-
});
|
|
250
|
-
/**
|
|
251
|
-
* Formatting patterns
|
|
252
|
-
*/
|
|
253
|
-
const patterns = table.rows.map((columns) => columns[1]);
|
|
254
|
-
const largestPatternLength = Math.max(...patterns.map((pattern) => stringWidth(pattern)));
|
|
255
|
-
const formattedPatterns = cliHelpers.justify(patterns, {
|
|
256
|
-
maxWidth: largestPatternLength,
|
|
257
|
-
paddingChar: this.#colors.dim('.'),
|
|
258
|
-
});
|
|
259
|
-
/**
|
|
260
|
-
* Formatting middleware to be right aligned
|
|
261
|
-
*/
|
|
262
|
-
const middleware = table.rows.map((columns) => columns[3]);
|
|
263
|
-
const largestMiddlewareLength = Math.max(...middleware.map((one) => stringWidth(one)));
|
|
264
|
-
const formattedMiddleware = cliHelpers.justify(middleware, {
|
|
265
|
-
maxWidth: largestMiddlewareLength,
|
|
266
|
-
align: 'right',
|
|
267
|
-
paddingChar: ' ',
|
|
268
|
-
});
|
|
269
|
-
/**
|
|
270
|
-
* Formatting controllers to be right aligned and take all the remaining
|
|
271
|
-
* space after printing route method, pattern and middleware.
|
|
272
|
-
*/
|
|
273
|
-
const controllers = table.rows.map((columns) => columns[2]);
|
|
274
|
-
const largestControllerLength = (this.#options.maxPrettyPrintWidth || cliHelpers.TERMINAL_SIZE) -
|
|
275
|
-
(largestPatternLength + largestMethodsLength + largestMiddlewareLength);
|
|
276
|
-
const formattedControllers = cliHelpers.truncate(cliHelpers.justify(controllers, {
|
|
277
|
-
maxWidth: largestControllerLength,
|
|
278
|
-
align: 'right',
|
|
279
|
-
paddingChar: this.#colors.dim('.'),
|
|
280
|
-
}), {
|
|
281
|
-
maxWidth: largestControllerLength,
|
|
282
|
-
});
|
|
283
|
-
return {
|
|
284
|
-
heading: table.heading,
|
|
285
|
-
rows: formattedMethods.reduce((result, method, index) => {
|
|
286
|
-
result.push(`${method}${formattedPatterns[index]}${formattedControllers[index]}${formattedMiddleware[index]}`);
|
|
287
|
-
return result;
|
|
288
|
-
}, []),
|
|
289
|
-
};
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Formats routes as an array of objects. Routes are grouped by
|
|
294
|
-
* domain.
|
|
295
|
-
*/
|
|
296
|
-
async formatAsJSON() {
|
|
297
|
-
const routes = this.#router.toJSON();
|
|
298
|
-
const domains = Object.keys(routes);
|
|
299
|
-
let routesJSON = [];
|
|
300
|
-
for (let domain of domains) {
|
|
301
|
-
const domainRoutes = await Promise.all(routes[domain].map((route) => this.#serializeRoute(route)));
|
|
302
|
-
routesJSON.push({
|
|
303
|
-
domain,
|
|
304
|
-
routes: domainRoutes.filter((route) => this.#isAllowedByFilters(route)),
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
return routesJSON;
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Format routes to ansi list of tables. Each domain has its own table
|
|
311
|
-
* with heading and rows. Each row has colums with colors and spacing
|
|
312
|
-
* around them.
|
|
313
|
-
*/
|
|
314
|
-
async formatAsAnsiList() {
|
|
315
|
-
const routes = this.#router.toJSON();
|
|
316
|
-
const domains = Object.keys(routes);
|
|
317
|
-
const tables = [];
|
|
318
|
-
for (let domain of domains) {
|
|
319
|
-
const list = {
|
|
320
|
-
heading: this.#formatDomainHeadline(domain),
|
|
321
|
-
rows: [
|
|
322
|
-
[
|
|
323
|
-
this.#colors.dim('METHOD'),
|
|
324
|
-
` ${this.#colors.dim('ROUTE')} `,
|
|
325
|
-
` ${this.#colors.dim('HANDLER')}`,
|
|
326
|
-
` ${this.#colors.dim('MIDDLEWARE')}`,
|
|
327
|
-
],
|
|
328
|
-
],
|
|
329
|
-
};
|
|
330
|
-
/**
|
|
331
|
-
* Computing table rows. Each route+method will have its
|
|
332
|
-
* own row
|
|
333
|
-
*/
|
|
334
|
-
for (let route of routes[domain]) {
|
|
335
|
-
const serializedRoute = await this.#serializeRoute(route);
|
|
336
|
-
if (this.#isAllowedByFilters(serializedRoute)) {
|
|
337
|
-
serializedRoute.methods.forEach((method) => {
|
|
338
|
-
list.rows.push([
|
|
339
|
-
this.#formatRouteMethod(method),
|
|
340
|
-
` ${this.#formatRoutePattern(serializedRoute)}`,
|
|
341
|
-
`${this.#formatControllerName(serializedRoute)}${this.#formatAction(serializedRoute)}`,
|
|
342
|
-
` ${this.#formatMiddleware(serializedRoute, 'compact')}`,
|
|
343
|
-
]);
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
tables.push(list);
|
|
348
|
-
}
|
|
349
|
-
return this.#justifyListTables(tables);
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* Format routes to ansi tables. Each domain has its own table
|
|
353
|
-
* with heading and rows. Each row has colums with colors and spacing
|
|
354
|
-
* around them.
|
|
355
|
-
*/
|
|
356
|
-
async formatAsAnsiTable() {
|
|
357
|
-
const routes = this.#router.toJSON();
|
|
358
|
-
const domains = Object.keys(routes);
|
|
359
|
-
const tables = [];
|
|
360
|
-
for (let domain of domains) {
|
|
361
|
-
const list = {
|
|
362
|
-
heading: this.#formatDomainHeadline(domain),
|
|
363
|
-
table: this.#table()
|
|
364
|
-
.fullWidth()
|
|
365
|
-
.fluidColumnIndex(2)
|
|
366
|
-
.head([
|
|
367
|
-
this.#colors.dim('METHOD'),
|
|
368
|
-
this.#colors.dim('ROUTE'),
|
|
369
|
-
{ hAlign: 'right', content: this.#colors.dim('HANDLER') },
|
|
370
|
-
{ content: this.#colors.dim('MIDDLEWARE'), hAlign: 'right' },
|
|
371
|
-
]),
|
|
372
|
-
};
|
|
373
|
-
/**
|
|
374
|
-
* Computing table rows. Each route+method will have its
|
|
375
|
-
* own row
|
|
376
|
-
*/
|
|
377
|
-
for (let route of routes[domain]) {
|
|
378
|
-
const serializedRoute = await this.#serializeRoute(route);
|
|
379
|
-
if (this.#isAllowedByFilters(serializedRoute)) {
|
|
380
|
-
serializedRoute.methods.forEach((method) => {
|
|
381
|
-
list.table.row([
|
|
382
|
-
this.#formatRouteMethod(method),
|
|
383
|
-
this.#formatRoutePattern(serializedRoute),
|
|
384
|
-
{
|
|
385
|
-
content: `${this.#formatControllerName(serializedRoute)}${this.#formatAction(serializedRoute)}`,
|
|
386
|
-
hAlign: 'right',
|
|
387
|
-
},
|
|
388
|
-
{ content: this.#formatMiddleware(serializedRoute), hAlign: 'right' },
|
|
389
|
-
]);
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
tables.push(list);
|
|
394
|
-
}
|
|
395
|
-
return tables;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
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
|
-
* Helper utilities to create and resolve config providers. Config providers
|
|
11
|
-
* are used to defer configuration resolution until the application is booted,
|
|
12
|
-
* allowing access to environment variables and other application services.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* // Creating a database config provider
|
|
16
|
-
* const databaseConfig = configProvider.create(async (app) => ({
|
|
17
|
-
* connection: app.env.get('DB_CONNECTION', 'sqlite'),
|
|
18
|
-
* host: app.env.get('DB_HOST', 'localhost'),
|
|
19
|
-
* port: app.env.get('DB_PORT', 5432)
|
|
20
|
-
* }))
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* // Resolving a config provider
|
|
24
|
-
* const config = await configProvider.resolve(app, databaseConfig)
|
|
25
|
-
* if (config) {
|
|
26
|
-
* console.log(`Database connection: ${config.connection}`)
|
|
27
|
-
* }
|
|
28
|
-
*/
|
|
29
|
-
export const configProvider = {
|
|
30
|
-
/**
|
|
31
|
-
* Creates a new config provider that will resolve configuration
|
|
32
|
-
* when the application is booted.
|
|
33
|
-
*
|
|
34
|
-
* @param resolver - Function that receives the application service and returns the configuration
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* const mailConfig = configProvider.create(async (app) => ({
|
|
38
|
-
* driver: app.env.get('MAIL_DRIVER', 'smtp'),
|
|
39
|
-
* host: app.env.get('SMTP_HOST'),
|
|
40
|
-
* port: app.env.get('SMTP_PORT', 587)
|
|
41
|
-
* }))
|
|
42
|
-
*/
|
|
43
|
-
create(resolver) {
|
|
44
|
-
return {
|
|
45
|
-
type: 'provider',
|
|
46
|
-
resolver,
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
/**
|
|
50
|
-
* Resolves a config provider if the provided value is a valid config provider,
|
|
51
|
-
* otherwise returns null.
|
|
52
|
-
*
|
|
53
|
-
* @param app - The application service instance
|
|
54
|
-
* @param provider - The potential config provider to resolve
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* const resolved = await configProvider.resolve(app, someProvider)
|
|
58
|
-
* if (resolved) {
|
|
59
|
-
* // Use the resolved configuration
|
|
60
|
-
* console.log('Config resolved:', resolved)
|
|
61
|
-
* } else {
|
|
62
|
-
* console.log('Not a valid config provider')
|
|
63
|
-
* }
|
|
64
|
-
*/
|
|
65
|
-
async resolve(app, provider) {
|
|
66
|
-
if (provider && typeof provider === 'object' && 'type' in provider) {
|
|
67
|
-
return provider.resolver(app);
|
|
68
|
-
}
|
|
69
|
-
return null;
|
|
70
|
-
},
|
|
71
|
-
};
|
package/build/src/debug.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
import { debuglog } from 'node:util';
|
|
10
|
-
/**
|
|
11
|
-
* Debug utility for AdonisJS core. This uses Node.js built-in debuglog
|
|
12
|
-
* utility to provide debugging information when the NODE_DEBUG environment
|
|
13
|
-
* variable includes 'adonisjs:core'.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* // Enable debugging by setting environment variable
|
|
17
|
-
* // NODE_DEBUG=adonisjs:core node app.js
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* // Usage in code
|
|
21
|
-
* import debug from '@adonisjs/core/debug'
|
|
22
|
-
* debug('Application started')
|
|
23
|
-
* debug('Processing request: %s', req.url)
|
|
24
|
-
*/
|
|
25
|
-
export default debuglog('adonisjs:core');
|