@adonisjs/core 7.0.0-next.10 → 7.0.0-next.12

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.
Files changed (181) hide show
  1. package/build/ace-DDzvaSs_.js +16 -0
  2. package/build/app-B6oge7b3.js +5 -0
  3. package/build/app-BK0PN3li.js +5 -0
  4. package/build/bodyparser_middleware-DTW0epKM.js +3 -0
  5. package/build/chunk-MjwdjG2f.js +32 -0
  6. package/build/commands/add.js +40 -110
  7. package/build/commands/build.js +51 -107
  8. package/build/commands/configure.js +82 -177
  9. package/build/commands/eject.js +17 -60
  10. package/build/commands/env/add.js +55 -134
  11. package/build/commands/generate_key.js +22 -66
  12. package/build/commands/inspect_rcfile.js +27 -55
  13. package/build/commands/list/routes.js +246 -116
  14. package/build/commands/make/command.js +15 -57
  15. package/build/commands/make/controller.js +43 -120
  16. package/build/commands/make/event.js +16 -62
  17. package/build/commands/make/exception.js +16 -62
  18. package/build/commands/make/listener.js +36 -93
  19. package/build/commands/make/middleware.js +41 -101
  20. package/build/commands/make/preload.js +47 -113
  21. package/build/commands/make/provider.js +47 -112
  22. package/build/commands/make/service.js +16 -55
  23. package/build/commands/make/test.js +47 -132
  24. package/build/commands/make/transformer.js +17 -64
  25. package/build/commands/make/validator.js +20 -80
  26. package/build/commands/make/view.js +15 -56
  27. package/build/commands/repl.js +17 -50
  28. package/build/commands/serve.js +80 -150
  29. package/build/commands/test.js +92 -202
  30. package/build/config-B2S2xfmN.js +5 -0
  31. package/build/config_provider-CY-xuo2R.js +13 -0
  32. package/build/container-ClFvcykQ.js +5 -0
  33. package/build/core-CNNCwlhc.js +95 -0
  34. package/build/create_kernel-B7zWS8Zz.js +38 -0
  35. package/build/create_kernel-CsTq0pWc.js +3 -0
  36. package/build/debug-DURPi9xn.js +3 -0
  37. package/build/decorate-DM0Sx1ye.js +7 -0
  38. package/build/dumper-C_sMcyFb.js +147 -0
  39. package/build/edge-LQdCc1L3.js +47 -0
  40. package/build/encryption-D2HGu0bU.js +5 -0
  41. package/build/events-B8hK42QT.js +5 -0
  42. package/build/factories/app.js +2 -9
  43. package/build/factories/bodyparser.js +2 -9
  44. package/build/factories/core/ace.js +15 -46
  45. package/build/factories/core/ignitor.js +12 -180
  46. package/build/factories/core/main.js +22 -11
  47. package/build/factories/core/test_utils.js +19 -43
  48. package/build/factories/encryption.js +2 -9
  49. package/build/factories/events.js +2 -9
  50. package/build/factories/hash.js +2 -9
  51. package/build/factories/http.js +2 -9
  52. package/build/factories/logger.js +2 -9
  53. package/build/factories/stubs.js +28 -91
  54. package/build/ignitor-Dil-rtCo.js +63 -0
  55. package/build/index.js +13 -46
  56. package/build/logger-Dha-0hp1.js +13 -0
  57. package/build/main-2-nm3TiB.js +72 -0
  58. package/build/main-BTUXw6He.js +171 -0
  59. package/build/main-BWftwyAK.js +81 -0
  60. package/build/main-BrJQ1VAM.js +52 -0
  61. package/build/main-CFmDHDls.js +35 -0
  62. package/build/main-D5xz2ZN1.js +5 -0
  63. package/build/main-kn40V-hF.js +2 -0
  64. package/build/main-q9TMzWUj.js +5 -0
  65. package/build/modules/ace/codemods.js +222 -477
  66. package/build/modules/ace/main.js +2 -41
  67. package/build/modules/app.js +4 -26
  68. package/build/modules/bodyparser/bodyparser_middleware.js +2 -14
  69. package/build/modules/bodyparser/main.js +4 -9
  70. package/build/modules/config.js +4 -26
  71. package/build/modules/container.js +4 -9
  72. package/build/modules/dumper/main.js +6 -32
  73. package/build/modules/dumper/plugins/edge.js +2 -62
  74. package/build/modules/encryption.js +4 -26
  75. package/build/modules/env/editor.js +2 -9
  76. package/build/modules/env/main.js +2 -28
  77. package/build/modules/events.js +4 -9
  78. package/build/modules/hash/drivers/argon.js +2 -9
  79. package/build/modules/hash/drivers/bcrypt.js +2 -20
  80. package/build/modules/hash/drivers/scrypt.js +2 -9
  81. package/build/modules/hash/main.js +6 -28
  82. package/build/modules/hash/phc_formatter.js +2 -9
  83. package/build/modules/health.js +2 -9
  84. package/build/modules/http/main.js +4 -15
  85. package/build/modules/http/url_builder_client.js +2 -9
  86. package/build/modules/logger.d.ts +30 -0
  87. package/build/modules/logger.js +4 -9
  88. package/build/modules/repl.js +4 -9
  89. package/build/modules/transformers/main.js +4 -9
  90. package/build/providers/app_provider.js +147 -359
  91. package/build/providers/edge_provider.js +97 -165
  92. package/build/providers/hash_provider.js +29 -91
  93. package/build/providers/repl_provider.js +61 -152
  94. package/build/providers/vinejs_provider.d.ts +1 -1
  95. package/build/providers/vinejs_provider.js +20 -66
  96. package/build/repl-CumYg2V_.js +5 -0
  97. package/build/services/ace.js +2 -17
  98. package/build/services/app.js +2 -21
  99. package/build/services/config.js +2 -13
  100. package/build/services/dumper.js +5 -21
  101. package/build/services/emitter.js +2 -14
  102. package/build/services/encryption.js +2 -14
  103. package/build/services/hash.js +2 -14
  104. package/build/services/logger.js +2 -14
  105. package/build/services/repl.js +2 -14
  106. package/build/services/router.js +2 -14
  107. package/build/services/server.js +2 -14
  108. package/build/services/test_utils.js +2 -17
  109. package/build/services/url_builder.js +5 -17
  110. package/build/src/exceptions.js +2 -49
  111. package/build/src/helpers/assert.js +2 -55
  112. package/build/src/helpers/http.js +2 -28
  113. package/build/src/helpers/is.js +3 -31
  114. package/build/src/helpers/main.js +5 -52
  115. package/build/src/helpers/string.js +2 -78
  116. package/build/src/helpers/types.js +26 -135
  117. package/build/src/helpers/verification_token.js +2 -120
  118. package/build/src/test_utils/main.js +5 -77
  119. package/build/src/types.js +0 -8
  120. package/build/src/vine.js +2 -105
  121. package/build/string-CJ7ewUFq.js +28 -0
  122. package/build/test_utils-c_TEaEHW.js +10 -0
  123. package/build/toolkit/main.js +19 -21
  124. package/build/types/ace.js +2 -9
  125. package/build/types/app.js +2 -9
  126. package/build/types/bodyparser.js +2 -9
  127. package/build/types/common.js +2 -9
  128. package/build/types/container.js +2 -9
  129. package/build/types/encryption.js +2 -9
  130. package/build/types/events.js +2 -9
  131. package/build/types/hash.js +2 -9
  132. package/build/types/health.js +2 -9
  133. package/build/types/helpers.js +0 -8
  134. package/build/types/http.js +2 -9
  135. package/build/types/logger.js +2 -9
  136. package/build/types/repl.js +2 -9
  137. package/build/types/transformers.js +2 -9
  138. package/build/utils-CNQ4tlGM.js +41 -0
  139. package/build/verification_token-DXsW81rl.js +46 -0
  140. package/build/vine-Bt4ymkM0.js +32 -0
  141. package/package.json +81 -31
  142. package/build/modules/ace/commands.js +0 -157
  143. package/build/modules/ace/create_kernel.js +0 -91
  144. package/build/modules/ace/kernel.js +0 -40
  145. package/build/modules/dumper/define_config.js +0 -36
  146. package/build/modules/dumper/dumper.js +0 -266
  147. package/build/modules/dumper/errors.js +0 -119
  148. package/build/modules/hash/define_config.js +0 -125
  149. package/build/modules/http/request_validator.js +0 -100
  150. package/build/src/assembler_hooks/index_entities.js +0 -112
  151. package/build/src/cli_formatters/routes_list.js +0 -397
  152. package/build/src/config_provider.js +0 -71
  153. package/build/src/debug.js +0 -25
  154. package/build/src/ignitor/ace.js +0 -102
  155. package/build/src/ignitor/http.js +0 -159
  156. package/build/src/ignitor/main.js +0 -124
  157. package/build/src/ignitor/test.js +0 -66
  158. package/build/src/test_utils/http.js +0 -82
  159. package/build/src/utils.js +0 -114
  160. package/build/stubs/main.js +0 -9
  161. package/build/toolkit/commands/index_commands.js +0 -30
  162. /package/build/{stubs/make → make}/command/main.stub +0 -0
  163. /package/build/{stubs/make → make}/controller/actions.stub +0 -0
  164. /package/build/{stubs/make → make}/controller/api.stub +0 -0
  165. /package/build/{stubs/make → make}/controller/main.stub +0 -0
  166. /package/build/{stubs/make → make}/controller/resource.stub +0 -0
  167. /package/build/{stubs/make → make}/event/main.stub +0 -0
  168. /package/build/{stubs/make → make}/exception/main.stub +0 -0
  169. /package/build/{stubs/make → make}/health/controller.stub +0 -0
  170. /package/build/{stubs/make → make}/health/main.stub +0 -0
  171. /package/build/{stubs/make → make}/listener/for_event.stub +0 -0
  172. /package/build/{stubs/make → make}/listener/main.stub +0 -0
  173. /package/build/{stubs/make → make}/middleware/main.stub +0 -0
  174. /package/build/{stubs/make → make}/preload/main.stub +0 -0
  175. /package/build/{stubs/make → make}/provider/main.stub +0 -0
  176. /package/build/{stubs/make → make}/service/main.stub +0 -0
  177. /package/build/{stubs/make → make}/test/main.stub +0 -0
  178. /package/build/{stubs/make → make}/transformer/main.stub +0 -0
  179. /package/build/{stubs/make → make}/validator/main.stub +0 -0
  180. /package/build/{stubs/make → make}/validator/resource.stub +0 -0
  181. /package/build/{stubs/make → make}/view/main.stub +0 -0
@@ -1,100 +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
- * 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
- * ```
21
- */
22
- export class RequestValidator {
23
- #ctx;
24
- #experimentalFlags;
25
- constructor(ctx, experimentalFlags) {
26
- this.#ctx = ctx;
27
- this.#experimentalFlags = experimentalFlags;
28
- }
29
- /**
30
- * The error reporter method returns the error reporter
31
- * to use for reporting errors.
32
- *
33
- * You can use this function to pick a different error reporter
34
- * for each HTTP request
35
- */
36
- static errorReporter;
37
- /**
38
- * The messages provider method returns the messages provider to use
39
- * finding custom error messages
40
- *
41
- * You can use this function to pick a different messages provider for
42
- * each HTTP request
43
- */
44
- static messagesProvider;
45
- /**
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
- * ```
67
- */
68
- validateUsing(validator, ...[options]) {
69
- const validatorOptions = options || {};
70
- /**
71
- * Assign request specific error reporter
72
- */
73
- if (RequestValidator.errorReporter && !validatorOptions.errorReporter) {
74
- const errorReporter = RequestValidator.errorReporter(this.#ctx);
75
- validatorOptions.errorReporter = () => errorReporter;
76
- }
77
- /**
78
- * Assign request specific messages provider
79
- */
80
- if (RequestValidator.messagesProvider && !validatorOptions.messagesProvider) {
81
- validatorOptions.messagesProvider = RequestValidator.messagesProvider(this.#ctx);
82
- }
83
- const requestBody = this.#experimentalFlags?.enabled('mergeMultipartFieldsAndFiles')
84
- ? this.#ctx.request.all()
85
- : {
86
- ...this.#ctx.request.all(),
87
- ...this.#ctx.request.allFiles(),
88
- };
89
- /**
90
- * Data to validate
91
- */
92
- const data = validatorOptions.data || {
93
- ...requestBody,
94
- params: this.#ctx.request.params(),
95
- headers: this.#ctx.request.headers(),
96
- cookies: this.#ctx.request.cookiesList(),
97
- };
98
- return validator.validate(data, validatorOptions);
99
- }
100
- }
@@ -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
- };