@adonisjs/core 6.1.5-1 → 6.1.5-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.
Files changed (174) hide show
  1. package/build/commands/build.d.ts +10 -0
  2. package/build/commands/build.js +65 -22
  3. package/build/commands/commands.json +1 -1
  4. package/build/commands/configure.d.ts +36 -0
  5. package/build/commands/configure.js +84 -6
  6. package/build/commands/eject.d.ts +4 -0
  7. package/build/commands/eject.js +14 -7
  8. package/build/commands/generate_key.d.ts +4 -0
  9. package/build/commands/generate_key.js +14 -7
  10. package/build/commands/inspect_rcfile.d.ts +9 -0
  11. package/build/commands/inspect_rcfile.js +20 -0
  12. package/build/commands/list/routes.d.ts +36 -0
  13. package/build/commands/list/routes.js +94 -0
  14. package/build/commands/make/_base.d.ts +31 -1
  15. package/build/commands/make/_base.js +18 -10
  16. package/build/commands/make/command.d.ts +6 -0
  17. package/build/commands/make/command.js +15 -5
  18. package/build/commands/make/controller.d.ts +9 -0
  19. package/build/commands/make/controller.js +30 -11
  20. package/build/commands/make/event.d.ts +6 -0
  21. package/build/commands/make/event.js +15 -5
  22. package/build/commands/make/exception.d.ts +14 -0
  23. package/build/commands/make/exception.js +35 -0
  24. package/build/commands/make/listener.d.ts +7 -0
  25. package/build/commands/make/listener.js +20 -7
  26. package/build/commands/make/middleware.d.ts +7 -0
  27. package/build/commands/make/middleware.js +16 -5
  28. package/build/commands/make/preload.d.ts +22 -0
  29. package/build/commands/make/preload.js +95 -0
  30. package/build/commands/make/provider.d.ts +6 -0
  31. package/build/commands/make/provider.js +22 -6
  32. package/build/commands/make/service.d.ts +14 -0
  33. package/build/commands/make/service.js +35 -0
  34. package/build/commands/make/test.d.ts +9 -0
  35. package/build/commands/make/test.js +41 -7
  36. package/build/commands/repl.d.ts +14 -0
  37. package/build/commands/repl.js +30 -0
  38. package/build/commands/serve.d.ts +12 -0
  39. package/build/commands/serve.js +78 -27
  40. package/build/commands/test.d.ts +32 -0
  41. package/build/commands/test.js +203 -0
  42. package/build/factories/app.js +8 -0
  43. package/build/factories/bodyparser.js +8 -0
  44. package/build/factories/core/ace.d.ts +4 -1
  45. package/build/factories/core/ace.js +11 -0
  46. package/build/factories/core/ignitor.d.ts +20 -1
  47. package/build/factories/core/ignitor.js +35 -1
  48. package/build/factories/core/main.js +8 -0
  49. package/build/factories/core/test_utils.d.ts +4 -1
  50. package/build/factories/core/test_utils.js +11 -0
  51. package/build/factories/encryption.js +8 -0
  52. package/build/factories/events.js +8 -0
  53. package/build/factories/hash.js +8 -0
  54. package/build/factories/http.js +8 -0
  55. package/build/factories/logger.js +8 -0
  56. package/build/factories/stubs.d.ts +10 -0
  57. package/build/factories/stubs.js +21 -0
  58. package/build/index.d.ts +5 -1
  59. package/build/index.js +13 -0
  60. package/build/modules/ace/commands.d.ts +123 -0
  61. package/build/modules/ace/commands.js +79 -0
  62. package/build/modules/ace/create_kernel.d.ts +9 -0
  63. package/build/modules/ace/create_kernel.js +31 -0
  64. package/build/modules/ace/kernel.d.ts +4 -0
  65. package/build/modules/ace/kernel.js +12 -0
  66. package/build/modules/ace/main.d.ts +1 -1
  67. package/build/modules/ace/main.js +9 -1
  68. package/build/modules/ace/shell.d.ts +9 -1
  69. package/build/modules/ace/shell.js +21 -0
  70. package/build/modules/app.js +8 -0
  71. package/build/modules/bodyparser/bodyparser_middleware.d.ts +4 -0
  72. package/build/modules/bodyparser/bodyparser_middleware.js +12 -0
  73. package/build/modules/bodyparser/main.js +8 -0
  74. package/build/modules/config.js +8 -0
  75. package/build/modules/container.js +8 -0
  76. package/build/modules/encryption.js +8 -0
  77. package/build/modules/env.js +8 -0
  78. package/build/modules/events.js +8 -0
  79. package/build/modules/hash/define_config.d.ts +3 -0
  80. package/build/modules/hash/define_config.js +20 -0
  81. package/build/modules/hash/drivers_collection.d.ts +16 -4
  82. package/build/modules/hash/drivers_collection.js +31 -8
  83. package/build/modules/hash/main.d.ts +1 -0
  84. package/build/modules/hash/main.js +9 -0
  85. package/build/modules/http/main.d.ts +2 -0
  86. package/build/modules/http/main.js +10 -0
  87. package/build/modules/http/request_validator.d.ts +44 -0
  88. package/build/modules/http/request_validator.js +74 -0
  89. package/build/modules/logger.js +8 -0
  90. package/build/modules/repl.d.ts +1 -0
  91. package/build/modules/repl.js +9 -0
  92. package/build/providers/app_provider.d.ts +31 -2
  93. package/build/providers/app_provider.js +44 -15
  94. package/build/providers/hash_provider.d.ts +16 -0
  95. package/build/providers/hash_provider.js +31 -6
  96. package/build/providers/http_provider.d.ts +17 -0
  97. package/build/providers/http_provider.js +26 -1
  98. package/build/providers/repl_provider.d.ts +13 -0
  99. package/build/providers/repl_provider.js +37 -0
  100. package/build/services/ace.js +15 -0
  101. package/build/services/app.d.ts +8 -0
  102. package/build/services/app.js +16 -0
  103. package/build/services/config.js +11 -0
  104. package/build/services/emitter.js +13 -2
  105. package/build/services/encryption.js +13 -2
  106. package/build/services/hash.js +13 -2
  107. package/build/services/logger.js +13 -2
  108. package/build/services/repl.d.ts +3 -0
  109. package/build/services/repl.js +18 -0
  110. package/build/services/router.js +13 -2
  111. package/build/services/server.js +13 -2
  112. package/build/services/test_utils.js +15 -0
  113. package/build/src/bindings/repl.d.ts +6 -0
  114. package/build/src/bindings/repl.js +78 -0
  115. package/build/src/cli_formatters/routes_list.d.ts +63 -0
  116. package/build/src/cli_formatters/routes_list.js +376 -0
  117. package/build/src/debug.d.ts +1 -1
  118. package/build/src/debug.js +8 -0
  119. package/build/src/exceptions.d.ts +1 -0
  120. package/build/src/exceptions.js +9 -0
  121. package/build/src/helpers/is.js +8 -0
  122. package/build/src/helpers/main.d.ts +2 -0
  123. package/build/src/helpers/main.js +10 -0
  124. package/build/src/helpers/parse_binding_reference.d.ts +45 -0
  125. package/build/src/helpers/parse_binding_reference.js +83 -0
  126. package/build/src/helpers/string.d.ts +26 -0
  127. package/build/src/helpers/string.js +15 -0
  128. package/build/src/helpers/types.d.ts +7 -2
  129. package/build/src/helpers/types.js +13 -0
  130. package/build/src/ignitor/ace.d.ts +12 -0
  131. package/build/src/ignitor/ace.js +50 -1
  132. package/build/src/ignitor/http.d.ts +9 -2
  133. package/build/src/ignitor/http.js +67 -0
  134. package/build/src/ignitor/main.d.ts +29 -1
  135. package/build/src/ignitor/main.js +56 -0
  136. package/build/src/ignitor/test.d.ts +10 -0
  137. package/build/src/ignitor/test.js +25 -0
  138. package/build/src/internal_helpers.d.ts +12 -5
  139. package/build/src/internal_helpers.js +35 -7
  140. package/build/src/test_utils/http.d.ts +10 -2
  141. package/build/src/test_utils/http.js +19 -0
  142. package/build/src/test_utils/main.d.ts +21 -3
  143. package/build/src/test_utils/main.js +27 -1
  144. package/build/src/types.d.ts +61 -3
  145. package/build/src/types.js +8 -0
  146. package/build/src/vinejs/extensions/main.d.ts +1 -0
  147. package/build/src/vinejs/extensions/main.js +9 -0
  148. package/build/src/vinejs/extensions/validates_files.d.ts +22 -0
  149. package/build/src/vinejs/extensions/validates_files.js +76 -0
  150. package/build/stubs/index.js +8 -0
  151. package/build/stubs/make/exception/main.stub +10 -0
  152. package/build/stubs/make/preload_file/main.stub +4 -0
  153. package/build/stubs/make/service/main.stub +4 -0
  154. package/build/toolkit/commands/index_commands.d.ts +4 -0
  155. package/build/toolkit/commands/index_commands.js +13 -5
  156. package/build/toolkit/main.js +11 -0
  157. package/build/types/ace.js +8 -0
  158. package/build/types/app.js +8 -0
  159. package/build/types/bodyparser.js +8 -0
  160. package/build/types/container.js +8 -0
  161. package/build/types/encryption.js +8 -0
  162. package/build/types/events.js +8 -0
  163. package/build/types/hash.js +8 -0
  164. package/build/types/http.js +8 -0
  165. package/build/types/logger.js +8 -0
  166. package/build/types/repl.d.ts +1 -0
  167. package/build/types/repl.js +9 -0
  168. package/package.json +74 -121
  169. package/build/legacy/validator.d.ts +0 -1
  170. package/build/legacy/validator.js +0 -1
  171. package/build/modules/http.d.ts +0 -1
  172. package/build/modules/http.js +0 -1
  173. package/build/src/helpers/string_builder.d.ts +0 -23
  174. package/build/src/helpers/string_builder.js +0 -86
@@ -1,7 +1,18 @@
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
+ */
1
9
  import app from './app.js';
2
- import { HashManager } from '../modules/hash/main.js';
3
10
  let hash;
11
+ /**
12
+ * Returns a singleton instance of the Hash manager from the
13
+ * container
14
+ */
4
15
  await app.booted(async () => {
5
- hash = await app.container.make(HashManager);
16
+ hash = await app.container.make('hash');
6
17
  });
7
18
  export { hash as default };
@@ -1,7 +1,18 @@
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
+ */
1
9
  import app from './app.js';
2
- import { LoggerManager } from '@adonisjs/logger';
3
10
  let logger;
11
+ /**
12
+ * Returns a singleton instance of the logger class
13
+ * from the container
14
+ */
4
15
  await app.booted(async () => {
5
- logger = (await app.container.make(LoggerManager));
16
+ logger = await app.container.make('logger');
6
17
  });
7
18
  export { logger as default };
@@ -0,0 +1,3 @@
1
+ import type { Repl } from '../modules/repl.js';
2
+ declare let repl: Repl;
3
+ export { repl as default };
@@ -0,0 +1,18 @@
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 app from './app.js';
10
+ let repl;
11
+ /**
12
+ * Returns a singleton instance of the Repl class from
13
+ * the container
14
+ */
15
+ await app.booted(async () => {
16
+ repl = await app.container.make('repl');
17
+ });
18
+ export { repl as default };
@@ -1,7 +1,18 @@
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
+ */
1
9
  import app from './app.js';
2
- import { Router } from '../modules/http.js';
3
10
  let router;
11
+ /**
12
+ * Returns a singleton instance of the router class from
13
+ * the container
14
+ */
4
15
  await app.booted(async () => {
5
- router = await app.container.make(Router);
16
+ router = await app.container.make('router');
6
17
  });
7
18
  export { router as default };
@@ -1,7 +1,18 @@
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
+ */
1
9
  import app from './app.js';
2
- import { Server } from '../modules/http.js';
3
10
  let server;
11
+ /**
12
+ * Returns a singleton instance of the HTTP server
13
+ * from the container
14
+ */
4
15
  await app.booted(async () => {
5
- server = await app.container.make(Server);
16
+ server = await app.container.make('server');
6
17
  });
7
18
  export { server as default };
@@ -1,5 +1,20 @@
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
+ */
1
9
  import app from './app.js';
2
10
  let testUtils;
11
+ /**
12
+ * Returns a singleton instance of the TestUtils class
13
+ * from the container.
14
+ *
15
+ * testUtils service is an instance of the "TestUtils" exported from
16
+ * the "src/test_utils/main.ts" file.
17
+ */
3
18
  await app.booted(async () => {
4
19
  testUtils = await app.container.make('testUtils');
5
20
  });
@@ -0,0 +1,6 @@
1
+ import type { Repl } from '../../modules/repl.js';
2
+ import { ApplicationService } from '../types.js';
3
+ /**
4
+ * Registers REPL methods
5
+ */
6
+ export declare function defineReplBindings(app: ApplicationService, repl: Repl): void;
@@ -0,0 +1,78 @@
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
+ * Resolves a container binding and sets it on the REPL
11
+ * context
12
+ */
13
+ async function resolveBindingForRepl(app, repl, binding) {
14
+ repl.server.context[binding] = await app.container.make(binding);
15
+ repl.notify(`Loaded "${binding}" service. You can access it using the "${repl.colors.underline(binding)}" variable`);
16
+ }
17
+ /**
18
+ * Registers REPL methods
19
+ */
20
+ export function defineReplBindings(app, repl) {
21
+ repl.addMethod('importDefault', (_, modulePath) => {
22
+ return app.importDefault(modulePath);
23
+ }, {
24
+ description: 'Returns the default export for a module',
25
+ });
26
+ repl.addMethod('make', (_, service, runtimeValues) => {
27
+ return app.container.make(service, runtimeValues);
28
+ }, {
29
+ description: 'Make class instance using "container.make" method',
30
+ });
31
+ repl.addMethod('loadApp', () => {
32
+ return resolveBindingForRepl(app, repl, 'app');
33
+ }, {
34
+ description: 'Load "app" service in the REPL context',
35
+ });
36
+ repl.addMethod('loadEncryption', () => {
37
+ return resolveBindingForRepl(app, repl, 'encryption');
38
+ }, {
39
+ description: 'Load "encryption" service in the REPL context',
40
+ });
41
+ repl.addMethod('loadHash', () => {
42
+ return resolveBindingForRepl(app, repl, 'hash');
43
+ }, {
44
+ description: 'Load "hash" service in the REPL context',
45
+ });
46
+ repl.addMethod('loadRouter', () => {
47
+ return resolveBindingForRepl(app, repl, 'router');
48
+ }, {
49
+ description: 'Load "router" service in the REPL context',
50
+ });
51
+ repl.addMethod('loadConfig', () => {
52
+ return resolveBindingForRepl(app, repl, 'config');
53
+ }, {
54
+ description: 'Load "config" service in the REPL context',
55
+ });
56
+ repl.addMethod('loadTestUtils', () => {
57
+ return resolveBindingForRepl(app, repl, 'testUtils');
58
+ }, {
59
+ description: 'Load "testUtils" service in the REPL context',
60
+ });
61
+ repl.addMethod('loadHelpers', async () => {
62
+ const { default: isModule } = await import('../helpers/is.js');
63
+ const { default: stringModule } = await import('../helpers/string.js');
64
+ const { base64, cuid, fsReadAll, slash, parseImports } = await import('../helpers/main.js');
65
+ repl.server.context.helpers = {
66
+ string: stringModule,
67
+ is: isModule,
68
+ base64,
69
+ cuid,
70
+ fsReadAll,
71
+ slash,
72
+ parseImports,
73
+ };
74
+ repl.notify(`Loaded "helpers" module. You can access it using the "${repl.colors.underline('helpers')}" variable`);
75
+ }, {
76
+ description: 'Load "helpers" module in the REPL context',
77
+ });
78
+ }
@@ -0,0 +1,63 @@
1
+ import type { UIPrimitives } from '../../types/ace.js';
2
+ import { type Router } from '../../modules/http/main.js';
3
+ /**
4
+ * Shape of the serialized route specific to the formatter
5
+ */
6
+ type SerializedRoute = {
7
+ name: string;
8
+ pattern: string;
9
+ methods: string[];
10
+ middleware: string[];
11
+ handler: {
12
+ type: 'closure';
13
+ name: string;
14
+ } | {
15
+ type: 'controller';
16
+ moduleNameOrPath: string;
17
+ method: string;
18
+ };
19
+ };
20
+ /**
21
+ * Routes list formatter is used to format the routes to JSON or an ANSI string
22
+ * with pretty output.
23
+ *
24
+ * The decisions of colors, padding, alignment are all handled by the lists formatter
25
+ */
26
+ export declare class RoutesListFormatter {
27
+ #private;
28
+ constructor(router: Router, ui: UIPrimitives, options: {
29
+ displayHeadRoutes?: boolean;
30
+ maxPrettyPrintWidth?: number;
31
+ }, filters: {
32
+ match?: string;
33
+ middleware?: string[];
34
+ ignoreMiddleware?: string[];
35
+ });
36
+ /**
37
+ * Formats routes as an array of objects. Routes are grouped by
38
+ * domain.
39
+ */
40
+ formatAsJSON(): Promise<{
41
+ domain: string;
42
+ routes: SerializedRoute[];
43
+ }[]>;
44
+ /**
45
+ * Format routes to ansi list of tables. Each domain has its own table
46
+ * with heading and rows. Each row has colums with colors and spacing
47
+ * around them.
48
+ */
49
+ formatAsAnsiList(): Promise<{
50
+ heading: string;
51
+ rows: string[];
52
+ }[]>;
53
+ /**
54
+ * Format routes to ansi tables. Each domain has its own table
55
+ * with heading and rows. Each row has colums with colors and spacing
56
+ * around them.
57
+ */
58
+ formatAsAnsiTable(): Promise<{
59
+ heading: string;
60
+ table: ReturnType<UIPrimitives['table']>;
61
+ }[]>;
62
+ }
63
+ export {};
@@ -0,0 +1,376 @@
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 { parseBindingReference } from '../../src/helpers/main.js';
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
+ export class RoutesListFormatter {
19
+ #router;
20
+ #colors;
21
+ #table;
22
+ /**
23
+ * Options for printing routes
24
+ */
25
+ #options;
26
+ /**
27
+ * Filters to apply when finding routes
28
+ */
29
+ #filters;
30
+ constructor(router, ui, options, filters) {
31
+ this.#router = router;
32
+ this.#colors = ui.colors;
33
+ this.#table = ui.table;
34
+ this.#filters = filters;
35
+ this.#options = options;
36
+ this.#router.commit();
37
+ }
38
+ /**
39
+ * Test if a route clears the applied filters
40
+ */
41
+ #isAllowedByFilters(route) {
42
+ let allowRoute = true;
43
+ /**
44
+ * Check if the route is allowed by applying the middleware
45
+ * filter
46
+ */
47
+ if (this.#filters.middleware) {
48
+ allowRoute = this.#filters.middleware.every((name) => {
49
+ if (name === '*') {
50
+ return route.middleware.length > 0;
51
+ }
52
+ return route.middleware.includes(name);
53
+ });
54
+ }
55
+ /**
56
+ * Check if the route has any or the ignored middleware. If yes, do not
57
+ * display the route
58
+ */
59
+ if (allowRoute && this.#filters.ignoreMiddleware) {
60
+ allowRoute = this.#filters.ignoreMiddleware.every((name) => {
61
+ if (name === '*') {
62
+ return route.middleware.length === 0;
63
+ }
64
+ return !route.middleware.includes(name);
65
+ });
66
+ }
67
+ /**
68
+ * No more filters to be applied
69
+ */
70
+ if (!this.#filters.match) {
71
+ return allowRoute;
72
+ }
73
+ /**
74
+ * Check if the route name has the match keyword
75
+ */
76
+ if (route.name.includes(this.#filters.match)) {
77
+ return true;
78
+ }
79
+ /**
80
+ * Check if the route pattern has the match keyword
81
+ */
82
+ if (route.pattern.includes(this.#filters.match)) {
83
+ return true;
84
+ }
85
+ /**
86
+ * Check if the route handler has the match keyword
87
+ */
88
+ if (route.handler.type === 'controller'
89
+ ? route.handler.moduleNameOrPath.includes(this.#filters.match)
90
+ : route.handler.name.includes(this.#filters.match)) {
91
+ return true;
92
+ }
93
+ /**
94
+ * Disallow route
95
+ */
96
+ return false;
97
+ }
98
+ /**
99
+ * Serialize route middleware to an array of names
100
+ */
101
+ #serializeMiddleware(middleware) {
102
+ return [...middleware.all()].reduce((result, one) => {
103
+ if (typeof one === 'function') {
104
+ result.push(one.name || 'closure');
105
+ return result;
106
+ }
107
+ if ('name' in one && one.name) {
108
+ result.push(one.name);
109
+ }
110
+ return result;
111
+ }, []);
112
+ }
113
+ /**
114
+ * Serialize route handler reference to display object
115
+ */
116
+ async #serializeHandler(handler) {
117
+ /**
118
+ * Value is a controller reference
119
+ */
120
+ if ('reference' in handler) {
121
+ return {
122
+ type: 'controller',
123
+ ...(await parseBindingReference(handler.reference)),
124
+ };
125
+ }
126
+ /**
127
+ * Value is an inline closure
128
+ */
129
+ return {
130
+ type: 'closure',
131
+ name: handler.name || 'closure',
132
+ };
133
+ }
134
+ /**
135
+ * Serializes routes JSON to an object that can be used for pretty printing
136
+ */
137
+ async #serializeRoute(route) {
138
+ let methods = route.methods;
139
+ if (!this.#options.displayHeadRoutes) {
140
+ methods = methods.filter((method) => method !== 'HEAD');
141
+ }
142
+ return {
143
+ name: route.name || '',
144
+ pattern: route.pattern,
145
+ methods: methods,
146
+ handler: await this.#serializeHandler(route.handler),
147
+ middleware: this.#serializeMiddleware(route.middleware),
148
+ };
149
+ }
150
+ /**
151
+ * Formats the route method for the ansi list and table
152
+ */
153
+ #formatRouteMethod(method) {
154
+ return this.#colors.dim(method);
155
+ }
156
+ /**
157
+ * Formats route pattern for the ansi list and table
158
+ */
159
+ #formatRoutePattern(route) {
160
+ const pattern = this.#router
161
+ .parsePattern(route.pattern)
162
+ .map((token) => {
163
+ if (token.type === 1) {
164
+ return this.#colors.yellow(`:${token.val}`);
165
+ }
166
+ if (token.type === 3) {
167
+ return this.#colors.yellow(`:${token.val}?`);
168
+ }
169
+ if (token.type === 2) {
170
+ return this.#colors.red(token.val);
171
+ }
172
+ return token.val;
173
+ })
174
+ .join('/');
175
+ return `${pattern === '/' ? pattern : `/${pattern}`}${route.name ? ` ${this.#colors.dim(`(${route.name})`)}` : ''} `;
176
+ }
177
+ /**
178
+ * Formats controller name for the ansi list and table
179
+ */
180
+ #formatControllerName(route) {
181
+ return route.handler.type === 'controller' ? ` ${route.handler.moduleNameOrPath}.` : '';
182
+ }
183
+ /**
184
+ * Formats action name for the ansi list and table
185
+ */
186
+ #formatAction(route) {
187
+ return route.handler.type === 'controller'
188
+ ? `${this.#colors.cyan(route.handler.method)}`
189
+ : ` ${this.#colors.cyan(route.handler.name)}`;
190
+ }
191
+ /**
192
+ * Formats route middleware for the ansi list and table
193
+ */
194
+ #formatMiddleware(route, mode = 'normal') {
195
+ if (mode === 'compact' && route.middleware.length > 3) {
196
+ const firstMiddleware = route.middleware[0];
197
+ const secondMiddleware = route.middleware[1];
198
+ const diff = route.middleware.length - 2;
199
+ return this.#colors.dim(`${firstMiddleware}, ${secondMiddleware}, and ${diff} more`);
200
+ }
201
+ return this.#colors.dim(`${route.middleware.filter((one) => one).join(', ')}`);
202
+ }
203
+ /**
204
+ * Formatting the domain headling to be in green color with
205
+ * dots around it
206
+ */
207
+ #formatDomainHeadline(domain) {
208
+ if (domain !== 'root') {
209
+ return cliHelpers.justify([`${this.#colors.dim('..')} ${this.#colors.green(domain)} `], {
210
+ maxWidth: this.#options.maxPrettyPrintWidth || cliHelpers.TERMINAL_SIZE,
211
+ paddingChar: this.#colors.dim('.'),
212
+ })[0];
213
+ }
214
+ return '';
215
+ }
216
+ /**
217
+ * Justify the ansi list
218
+ */
219
+ #justifyListTables(tables) {
220
+ return tables.map((table) => {
221
+ /**
222
+ * Formatting methods
223
+ */
224
+ const methods = table.rows.map((columns) => columns[0]);
225
+ const largestMethodsLength = Math.max(...methods.map((method) => stringWidth(method)));
226
+ const formattedMethods = cliHelpers.justify(methods, {
227
+ maxWidth: largestMethodsLength,
228
+ });
229
+ /**
230
+ * Formatting patterns
231
+ */
232
+ const patterns = table.rows.map((columns) => columns[1]);
233
+ const largestPatternLength = Math.max(...patterns.map((pattern) => stringWidth(pattern)));
234
+ const formattedPatterns = cliHelpers.justify(patterns, {
235
+ maxWidth: largestPatternLength,
236
+ paddingChar: this.#colors.dim('.'),
237
+ });
238
+ /**
239
+ * Formatting middleware to be right aligned
240
+ */
241
+ const middleware = table.rows.map((columns) => columns[3]);
242
+ const largestMiddlewareLength = Math.max(...middleware.map((one) => stringWidth(one)));
243
+ const formattedMiddleware = cliHelpers.justify(middleware, {
244
+ maxWidth: largestMiddlewareLength,
245
+ align: 'right',
246
+ paddingChar: ' ',
247
+ });
248
+ /**
249
+ * Formatting controllers to be right aligned and take all the remaining
250
+ * space after printing route method, pattern and middleware.
251
+ */
252
+ const controllers = table.rows.map((columns) => columns[2]);
253
+ const largestControllerLength = (this.#options.maxPrettyPrintWidth || cliHelpers.TERMINAL_SIZE) -
254
+ (largestPatternLength + largestMethodsLength + largestMiddlewareLength);
255
+ const formattedControllers = cliHelpers.truncate(cliHelpers.justify(controllers, {
256
+ maxWidth: largestControllerLength,
257
+ align: 'right',
258
+ paddingChar: this.#colors.dim('.'),
259
+ }), {
260
+ maxWidth: largestControllerLength,
261
+ });
262
+ return {
263
+ heading: table.heading,
264
+ rows: formattedMethods.reduce((result, method, index) => {
265
+ result.push(`${method}${formattedPatterns[index]}${formattedControllers[index]}${formattedMiddleware[index]}`);
266
+ return result;
267
+ }, []),
268
+ };
269
+ });
270
+ }
271
+ /**
272
+ * Formats routes as an array of objects. Routes are grouped by
273
+ * domain.
274
+ */
275
+ async formatAsJSON() {
276
+ const routes = this.#router.toJSON();
277
+ const domains = Object.keys(routes);
278
+ let routesJSON = [];
279
+ for (let domain of domains) {
280
+ const domainRoutes = await Promise.all(routes[domain].map((route) => this.#serializeRoute(route)));
281
+ routesJSON.push({
282
+ domain,
283
+ routes: domainRoutes.filter((route) => this.#isAllowedByFilters(route)),
284
+ });
285
+ }
286
+ return routesJSON;
287
+ }
288
+ /**
289
+ * Format routes to ansi list of tables. Each domain has its own table
290
+ * with heading and rows. Each row has colums with colors and spacing
291
+ * around them.
292
+ */
293
+ async formatAsAnsiList() {
294
+ const routes = this.#router.toJSON();
295
+ const domains = Object.keys(routes);
296
+ const tables = [];
297
+ for (let domain of domains) {
298
+ const list = {
299
+ heading: this.#formatDomainHeadline(domain),
300
+ rows: [
301
+ [
302
+ this.#colors.dim('METHOD'),
303
+ ` ${this.#colors.dim('ROUTE')} `,
304
+ ` ${this.#colors.dim('HANDLER')}`,
305
+ ` ${this.#colors.dim('MIDDLEWARE')}`,
306
+ ],
307
+ ],
308
+ };
309
+ /**
310
+ * Computing table rows. Each route+method will have its
311
+ * own row
312
+ */
313
+ for (let route of routes[domain]) {
314
+ const serializedRoute = await this.#serializeRoute(route);
315
+ if (this.#isAllowedByFilters(serializedRoute)) {
316
+ serializedRoute.methods.forEach((method) => {
317
+ list.rows.push([
318
+ this.#formatRouteMethod(method),
319
+ ` ${this.#formatRoutePattern(serializedRoute)}`,
320
+ `${this.#formatControllerName(serializedRoute)}${this.#formatAction(serializedRoute)}`,
321
+ ` ${this.#formatMiddleware(serializedRoute, 'compact')}`,
322
+ ]);
323
+ });
324
+ }
325
+ }
326
+ tables.push(list);
327
+ }
328
+ return this.#justifyListTables(tables);
329
+ }
330
+ /**
331
+ * Format routes to ansi tables. Each domain has its own table
332
+ * with heading and rows. Each row has colums with colors and spacing
333
+ * around them.
334
+ */
335
+ async formatAsAnsiTable() {
336
+ const routes = this.#router.toJSON();
337
+ const domains = Object.keys(routes);
338
+ const tables = [];
339
+ for (let domain of domains) {
340
+ const list = {
341
+ heading: this.#formatDomainHeadline(domain),
342
+ table: this.#table()
343
+ .fullWidth()
344
+ .fluidColumnIndex(2)
345
+ .head([
346
+ this.#colors.dim('METHOD'),
347
+ this.#colors.dim('ROUTE'),
348
+ { hAlign: 'right', content: this.#colors.dim('HANDLER') },
349
+ { content: this.#colors.dim('MIDDLEWARE'), hAlign: 'right' },
350
+ ]),
351
+ };
352
+ /**
353
+ * Computing table rows. Each route+method will have its
354
+ * own row
355
+ */
356
+ for (let route of routes[domain]) {
357
+ const serializedRoute = await this.#serializeRoute(route);
358
+ if (this.#isAllowedByFilters(serializedRoute)) {
359
+ serializedRoute.methods.forEach((method) => {
360
+ list.table.row([
361
+ this.#formatRouteMethod(method),
362
+ this.#formatRoutePattern(serializedRoute),
363
+ {
364
+ content: `${this.#formatControllerName(serializedRoute)}${this.#formatAction(serializedRoute)}`,
365
+ hAlign: 'right',
366
+ },
367
+ { content: this.#formatMiddleware(serializedRoute), hAlign: 'right' },
368
+ ]);
369
+ });
370
+ }
371
+ }
372
+ tables.push(list);
373
+ }
374
+ return tables;
375
+ }
376
+ }
@@ -1,3 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
1
+ /// <reference types="@types/node" resolution-mode="require"/>
2
2
  declare const _default: import("util").DebugLogger;
3
3
  export default _default;
@@ -1,2 +1,10 @@
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
+ */
1
9
  import { debuglog } from 'node:util';
2
10
  export default debuglog('adonisjs:core');
@@ -0,0 +1 @@
1
+ export { Exception, createError, RuntimeException, InvalidArgumentsException, } from '@poppinss/utils';
@@ -0,0 +1,9 @@
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
+ export { Exception, createError, RuntimeException, InvalidArgumentsException, } from '@poppinss/utils';