@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,91 +0,0 @@
1
- /*
2
- * @adonisjs/ace
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 { Kernel } from "./main.js";
10
- import { FsLoader, HelpCommand } from "../../modules/ace/main.js";
11
- /**
12
- * Create and configure an Ace command kernel for AdonisJS applications.
13
- * This function abstracts the kernel setup logic and can be used in different
14
- * environments with appropriate configurations.
15
- *
16
- * - In console environment, Ace manages the lifecycle of the process
17
- * - In other environments, Ace can be pulled from the container to run commands
18
- *
19
- * @param app - The AdonisJS application service instance
20
- * @param commandName - Optional specific command name for optimized loading
21
- *
22
- * @example
23
- * ```ts
24
- * const app = new Application(new URL('../', import.meta.url))
25
- * const kernel = createAceKernel(app)
26
- *
27
- * // Run a specific command
28
- * await kernel.handle(['make:controller', 'UserController'])
29
- * ```
30
- */
31
- export function createAceKernel(app, commandName) {
32
- const kernel = new Kernel(app);
33
- kernel.info.set('binary', 'node ace');
34
- /**
35
- * Lazy import commands mentioned in the "commands" array
36
- * of rcFile
37
- */
38
- app.rcFile.commands.forEach((commandModule) => {
39
- kernel.addLoader(() => typeof commandModule === 'function' ? commandModule() : app.import(commandModule));
40
- });
41
- /**
42
- * When we know the command we are running ahead of time, then we
43
- * defer loading the application commands if the command has
44
- * already been registered by other loaders.
45
- */
46
- const fsLoader = new FsLoader(app.commandsPath());
47
- kernel.addLoader({
48
- async getMetaData() {
49
- if (!commandName || !kernel.getCommand(commandName)) {
50
- return fsLoader.getMetaData();
51
- }
52
- return [];
53
- },
54
- getCommand(command) {
55
- return fsLoader.getCommand(command);
56
- },
57
- });
58
- /**
59
- * Custom global flags
60
- */
61
- kernel.defineFlag('ansi', {
62
- type: 'boolean',
63
- showNegatedVariantInHelp: true,
64
- description: 'Force enable or disable colorful output',
65
- });
66
- kernel.defineFlag('help', {
67
- type: 'boolean',
68
- description: HelpCommand.description,
69
- });
70
- /**
71
- * Flag listener to turn colors on/off
72
- */
73
- kernel.on('ansi', (_, $kernel, parsed) => {
74
- if (parsed.flags.ansi === false) {
75
- $kernel.ui.switchMode('silent');
76
- }
77
- if (parsed.flags.ansi === true) {
78
- $kernel.ui.switchMode('normal');
79
- }
80
- });
81
- /**
82
- * Flag listener to display the help
83
- */
84
- kernel.on('help', async (command, $kernel, parsed) => {
85
- parsed.args.unshift(command.commandName);
86
- const help = new HelpCommand($kernel, parsed, kernel.ui, kernel.prompt);
87
- await help.exec();
88
- return $kernel.shortcircuit();
89
- });
90
- return kernel;
91
- }
@@ -1,40 +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 { Kernel as AceKernel } from '@adonisjs/ace';
10
- import { ListCommand } from "./commands.js";
11
- /**
12
- * The Ace command kernel for AdonisJS applications. This kernel extends the base
13
- * Ace kernel with AdonisJS-specific functionality like dependency injection and
14
- * application lifecycle management.
15
- *
16
- * @example
17
- * ```ts
18
- * const app = new Application(new URL('../', import.meta.url))
19
- * const kernel = new Kernel(app)
20
- *
21
- * await kernel.handle(['make:controller', 'UserController'])
22
- * ```
23
- */
24
- export class Kernel extends AceKernel {
25
- app;
26
- /**
27
- * Create a new Ace kernel instance
28
- *
29
- * @param app - The AdonisJS application instance
30
- */
31
- constructor(app) {
32
- super(ListCommand, {
33
- create: async (command, parsedOutput, $kernel) => {
34
- return app.container.make(command, [app, $kernel, parsedOutput, $kernel.ui, $kernel.prompt]);
35
- },
36
- run: (command) => command.exec(),
37
- });
38
- this.app = app;
39
- }
40
- }
@@ -1,36 +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
- * Define configuration for the dumper service exported by the
11
- * "@adonisjs/core/services/dumper" module. This function allows
12
- * you to customize HTML and console output formatting options.
13
- *
14
- * @param dumperConfig - Configuration object with HTML and console options
15
- * @param dumperConfig.html - HTML output formatting configuration
16
- * @param dumperConfig.console - Console output formatting configuration
17
- *
18
- * @example
19
- * ```ts
20
- * export default defineConfig({
21
- * html: {
22
- * showHidden: true,
23
- * depth: 5,
24
- * colors: true
25
- * },
26
- * console: {
27
- * showHidden: false,
28
- * depth: 3,
29
- * collapse: ['Date', 'DateTime']
30
- * }
31
- * })
32
- * ```
33
- */
34
- export function defineConfig(dumperConfig) {
35
- return dumperConfig;
36
- }
@@ -1,266 +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 useColors from '@poppinss/colors';
10
- import { dump as consoleDump } from '@poppinss/dumper/console';
11
- import { createScript, createStyleSheet, dump } from '@poppinss/dumper/html';
12
- import { E_DUMP_DIE_EXCEPTION } from "./errors.js";
13
- const colors = useColors.ansi();
14
- const DUMP_TITLE_STYLES = `
15
- .adonisjs-dump-header {
16
- font-family: JetBrains Mono, monaspace argon, Menlo, Monaco, Consolas, monospace;
17
- background: #ff1639;
18
- border-radius: 4px;
19
- color: #fff;
20
- border-bottom-left-radius: 0;
21
- border-bottom-right-radius: 0;
22
- padding: 0.4rem 1.2rem;
23
- font-size: 1em;
24
- display: flex;
25
- justify-content: space-between;
26
- }
27
- .adonisjs-dump-header .adonisjs-dump-header-title {
28
- font-weight: bold;
29
- text-transform: uppercase;
30
- }
31
- .adonisjs-dump-header .adonisjs-dump-header-source {
32
- font-weight: bold;
33
- color: inherit;
34
- text-decoration: underline;
35
- }
36
- .dumper-dump pre {
37
- border-radius: 4px;
38
- border-top-left-radius: 0;
39
- border-top-right-radius: 0;
40
- }`;
41
- const IDE = process.env.ADONIS_IDE ?? process.env.EDITOR ?? '';
42
- /**
43
- * Dumper exposes the API to dump or die/dump values in your
44
- * AdonisJS application. An singleton instance of the Dumper
45
- * is shared as a service and may use it follows.
46
- *
47
- * ```ts
48
- * const dumper = container.make('dumper')
49
- *
50
- * dumper.configureHtmlOutput({
51
- * // parser + html formatter config
52
- * })
53
- *
54
- * dumper.configureAnsiOutput({
55
- * // parser + console formatter config
56
- * })
57
- *
58
- * const html = dumper.dumpToHtml(value)
59
- * const ansi = dumper.dumpToAnsi(value)
60
- *
61
- * // Returns style and script tags that must be
62
- * // injeted to the head of the HTML document
63
- *
64
- * const head = dumper.getHeadElements()
65
- * ```
66
- */
67
- export class Dumper {
68
- #app;
69
- /**
70
- * Configuration for the HTML formatter
71
- */
72
- #htmlConfig = {};
73
- /**
74
- * Configuration for the Console formatter
75
- */
76
- #consoleConfig = {
77
- collapse: ['DateTime', 'Date'],
78
- };
79
- /**
80
- * A collections of known editors to create URLs to open
81
- * them
82
- */
83
- #editors = {
84
- textmate: 'txmt://open?url=file://%f&line=%l',
85
- macvim: 'mvim://open?url=file://%f&line=%l',
86
- emacs: 'emacs://open?url=file://%f&line=%l',
87
- sublime: 'subl://open?url=file://%f&line=%l',
88
- phpstorm: 'phpstorm://open?file=%f&line=%l',
89
- atom: 'atom://core/open/file?filename=%f&line=%l',
90
- vscode: 'vscode://file/%f:%l',
91
- };
92
- /**
93
- * Creates a new Dumper instance
94
- *
95
- * @param app - The AdonisJS application instance
96
- */
97
- constructor(app) {
98
- this.#app = app;
99
- }
100
- /**
101
- * Returns the link to open the file using dd inside one
102
- * of the known code editors. Constructs a URL that can be used
103
- * to open the file at a specific line in supported editors.
104
- *
105
- * @param source - Optional source file information
106
- * @param source.location - The file path to open
107
- * @param source.line - The line number to jump to
108
- */
109
- #getEditorLink(source) {
110
- const editorURL = this.#editors[IDE] || IDE;
111
- if (!editorURL || !source) {
112
- return;
113
- }
114
- return {
115
- href: editorURL.replace('%f', source.location).replace('%l', String(source.line)),
116
- text: `${this.#app.relativePath(source.location)}:${source.line}`,
117
- };
118
- }
119
- /**
120
- * Configure the HTML formatter output options
121
- *
122
- * @param config - Configuration options for HTML dump formatting
123
- *
124
- * @example
125
- * ```ts
126
- * dumper.configureHtmlOutput({
127
- * showHidden: true,
128
- * depth: 5,
129
- * colors: false
130
- * })
131
- * ```
132
- */
133
- configureHtmlOutput(config) {
134
- this.#htmlConfig = config;
135
- return this;
136
- }
137
- /**
138
- * Configure the ANSI formatter output options for console display
139
- *
140
- * @param config - Configuration options for ANSI console formatting
141
- *
142
- * @example
143
- * ```ts
144
- * dumper.configureAnsiOutput({
145
- * showHidden: true,
146
- * depth: 3,
147
- * collapse: ['Date', 'DateTime']
148
- * })
149
- * ```
150
- */
151
- configureAnsiOutput(config) {
152
- this.#consoleConfig = config;
153
- return this;
154
- }
155
- /**
156
- * Returns the style and script elements that need to be injected into
157
- * the HTML document head for proper dump visualization
158
- *
159
- * @param cspNonce - Optional Content Security Policy nonce for inline scripts
160
- *
161
- * @example
162
- * ```ts
163
- * const headElements = dumper.getHeadElements('abc123')
164
- * // Insert into your HTML head section
165
- * ```
166
- */
167
- getHeadElements(cspNonce) {
168
- return (`<style id="dumper-styles">` +
169
- createStyleSheet() +
170
- DUMP_TITLE_STYLES +
171
- '</style>' +
172
- `<script id="dumper-script"${cspNonce ? ` nonce="${cspNonce}"` : ''}>` +
173
- createScript() +
174
- '</script>');
175
- }
176
- /**
177
- * Dump a value to formatted HTML output
178
- *
179
- * @param value - The value to dump and inspect
180
- * @param options - Options for HTML output formatting
181
- * @param options.cspNonce - Optional Content Security Policy nonce
182
- * @param options.title - Optional title to display in the dump header
183
- * @param options.source - Optional source file information for editor links
184
- *
185
- * @example
186
- * ```ts
187
- * const htmlOutput = dumper.dumpToHtml(user, {
188
- * title: 'User Object',
189
- * source: { location: '/app/controllers/user.ts', line: 42 }
190
- * })
191
- * ```
192
- */
193
- dumpToHtml(value, options = {}) {
194
- const link = this.#getEditorLink(options.source) ?? null;
195
- const title = options.title || 'DUMP';
196
- return ('<div class="adonisjs-dump-header">' +
197
- `<span class="adonisjs-dump-header-title">${title}</span>` +
198
- (link ? `<a href="${link.href}" class="adonisjs-dump-header-source">${link.text}</a>` : '') +
199
- '</div>' +
200
- dump(value, { cspNonce: options.cspNonce, ...this.#htmlConfig }));
201
- }
202
- /**
203
- * Dump a value to formatted ANSI output for console display
204
- *
205
- * @param value - The value to dump and inspect
206
- * @param options - Options for ANSI output formatting
207
- * @param options.title - Optional title to display in the dump header
208
- * @param options.source - Optional source file information for editor links
209
- *
210
- * @example
211
- * ```ts
212
- * const ansiOutput = dumper.dumpToAnsi(user, {
213
- * title: 'User Debug',
214
- * source: { location: '/app/controllers/user.ts', line: 42 }
215
- * })
216
- * console.log(ansiOutput)
217
- * ```
218
- */
219
- dumpToAnsi(value, options = {}) {
220
- const columns = process.stdout.columns;
221
- /**
222
- * Link to the source file
223
- */
224
- const link = `${this.#getEditorLink(options.source)?.text ?? ''} `;
225
- /**
226
- * Dump title
227
- */
228
- const title = ` ${options.title || 'DUMP'}`;
229
- /**
230
- * Whitespace between the title and the link to align them
231
- * on each side of x axis
232
- */
233
- const whiteSpaceLength = columns ? columns - link.length - title.length - 4 : 2;
234
- const whiteSpace = new Array(whiteSpaceLength <= 0 ? 2 : whiteSpaceLength).join(' ');
235
- /**
236
- * Styled heading with background color and bold text
237
- */
238
- const heading = colors.bgRed().bold(`${title}${whiteSpace}${link}`);
239
- return `${heading}\n${consoleDump(value, this.#consoleConfig)}`;
240
- }
241
- /**
242
- * Dump values and die. This method dumps the provided value and then
243
- * terminates the application. The output format is automatically chosen
244
- * based on the execution context.
245
- *
246
- * - During an HTTP request, HTML output will be sent to the browser
247
- * - Otherwise the value will be logged to the console in ANSI format
248
- *
249
- * @param value - The value to dump before terminating
250
- * @param traceSourceIndex - Stack trace index for source location (default: 1)
251
- *
252
- * @example
253
- * ```ts
254
- * // This will dump the user object and terminate the application
255
- * dumper.dd(user)
256
- *
257
- * // This will never execute
258
- * console.log('This line will not run')
259
- * ```
260
- */
261
- dd(value, traceSourceIndex = 1) {
262
- const error = new E_DUMP_DIE_EXCEPTION(value, this);
263
- error.setTraceSourceIndex(traceSourceIndex);
264
- throw error;
265
- }
266
- }
@@ -1,119 +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 { inspect } from 'node:util';
10
- import { parse } from 'error-stack-parser-es';
11
- import { Exception } from '@poppinss/utils/exception';
12
- /**
13
- * DumpDie exception raised by the "dd" (dump and die) function.
14
- * This special exception terminates execution while dumping the provided
15
- * value as HTML (during HTTP requests) or ANSI (in console/CLI).
16
- *
17
- * @example
18
- * ```ts
19
- * // This will dump the user object and terminate
20
- * dumper.dd(user)
21
- *
22
- * // In HTTP context: sends HTML dump to browser
23
- * // In CLI context: prints ANSI dump to console
24
- * ```
25
- */
26
- class DumpDieException extends Exception {
27
- static status = 500;
28
- static code = 'E_DUMP_DIE_EXCEPTION';
29
- #dumper;
30
- #traceSourceIndex = 1;
31
- value;
32
- constructor(value, dumper) {
33
- super('Dump and Die exception');
34
- this.#dumper = dumper;
35
- this.value = value;
36
- }
37
- /**
38
- * Returns the source file and line number location for the error
39
- */
40
- #getErrorSource() {
41
- if (this.fileName && this.lineNumber) {
42
- return {
43
- location: this.fileName,
44
- line: this.lineNumber,
45
- };
46
- }
47
- const source = parse(this)[this.#traceSourceIndex];
48
- if (!source.fileName || !source.lineNumber) {
49
- return;
50
- }
51
- return {
52
- location: source.fileName,
53
- line: source.lineNumber,
54
- };
55
- }
56
- /**
57
- * Set the stack trace index for determining the source location.
58
- * This is useful when building nested helpers on top of dump/die functionality.
59
- *
60
- * @param index - Stack trace index (0 = current function, 1 = caller, etc.)
61
- */
62
- setTraceSourceIndex(index) {
63
- this.#traceSourceIndex = index;
64
- return this;
65
- }
66
- /**
67
- * Preventing itself from getting reported by the
68
- * AdonisJS exception reporter
69
- */
70
- report() { }
71
- /**
72
- * HTTP exception handler that renders the dump as HTML output.
73
- * This method is called automatically by AdonisJS when a DumpDieException
74
- * is thrown during an HTTP request.
75
- *
76
- * @param error - The DumpDieException instance
77
- * @param ctx - HTTP context for the current request
78
- */
79
- async handle(error, ctx) {
80
- const source = this.#getErrorSource();
81
- /**
82
- * Comes from the shield package
83
- */
84
- const cspNonce = 'nonce' in ctx.response ? ctx.response.nonce : undefined;
85
- ctx.response
86
- .status(500)
87
- .send('<!DOCTYPE html>' +
88
- '<html>' +
89
- '<head>' +
90
- '<meta charset="utf-8">' +
91
- '<meta name="viewport" content="width=device-width">' +
92
- `${this.#dumper.getHeadElements(cspNonce)}` +
93
- '</head>' +
94
- '<body>' +
95
- `${this.#dumper.dumpToHtml(error.value, { cspNonce, source, title: 'DUMP DIE' })}` +
96
- '</body>' +
97
- '</html>');
98
- }
99
- /**
100
- * Ace command exception handler that renders the dump as ANSI output.
101
- * This method is called automatically by the Ace kernel when a DumpDieException
102
- * is thrown during command execution.
103
- *
104
- * @param error - The DumpDieException instance
105
- * @param kernel - Ace kernel instance
106
- */
107
- async render(error, kernel) {
108
- const source = this.#getErrorSource();
109
- kernel.ui.logger.log(this.#dumper.dumpToAnsi(error.value, { source, title: 'DUMP DIE' }));
110
- }
111
- /**
112
- * Custom output for the Node.js util inspect
113
- */
114
- [inspect.custom]() {
115
- const source = this.#getErrorSource();
116
- return this.#dumper.dumpToAnsi(this.value, { source, title: 'DUMP DIE' });
117
- }
118
- }
119
- export const E_DUMP_DIE_EXCEPTION = DumpDieException;
@@ -1,125 +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 { InvalidArgumentsException } from '@poppinss/utils/exception';
10
- import debug from "../../src/debug.js";
11
- import { configProvider } from "../../src/config_provider.js";
12
- /**
13
- * Define config for the hash service. This function creates a configuration
14
- * provider that lazily imports and resolves hash drivers when needed.
15
- *
16
- * @param config - Configuration object containing default hasher and list of hashers
17
- * @param config.default - Optional default hasher name (must exist in the list)
18
- * @param config.list - Record of hasher configurations or config providers
19
- *
20
- * @example
21
- * ```ts
22
- * const hashConfig = defineConfig({
23
- * default: 'scrypt',
24
- * list: {
25
- * scrypt: drivers.scrypt({
26
- * cost: 16384,
27
- * blockSize: 8,
28
- * parallelization: 1,
29
- * saltSize: 16,
30
- * keyLength: 64,
31
- * }),
32
- * bcrypt: drivers.bcrypt({
33
- * rounds: 10,
34
- * })
35
- * }
36
- * })
37
- * ```
38
- */
39
- export function defineConfig(config) {
40
- /**
41
- * Hashers list should always be provided
42
- */
43
- if (!config.list) {
44
- throw new InvalidArgumentsException('Missing "list" property in hash config');
45
- }
46
- /**
47
- * The default hasher should be mentioned in the list
48
- */
49
- if (config.default && !config.list[config.default]) {
50
- throw new InvalidArgumentsException(`Missing "list.${String(config.default)}" in hash config. It is referenced by the "default" property`);
51
- }
52
- /**
53
- * Config provider to lazily import drivers as they are used inside
54
- * the user application
55
- */
56
- return configProvider.create(async (app) => {
57
- debug('resolving hash config');
58
- const hashersList = Object.keys(config.list);
59
- const hashers = {};
60
- for (let hasherName of hashersList) {
61
- const hasher = config.list[hasherName];
62
- if (typeof hasher === 'function') {
63
- hashers[hasherName] = hasher;
64
- }
65
- else {
66
- hashers[hasherName] = await hasher.resolver(app);
67
- }
68
- }
69
- return {
70
- default: config.default,
71
- list: hashers,
72
- };
73
- });
74
- }
75
- /**
76
- * Helpers to configure drivers inside the config file. These functions create
77
- * configuration providers that lazily import and instantiate hash drivers.
78
- *
79
- * - Import happens when you first use the hash module
80
- * - Construction of drivers happens when you first use a driver
81
- *
82
- * @example
83
- * ```ts
84
- * const hashConfig = defineConfig({
85
- * default: 'bcrypt',
86
- * list: {
87
- * bcrypt: drivers.bcrypt({ rounds: 12 }),
88
- * argon2: drivers.argon2({
89
- * variant: 'id',
90
- * memory: 65536,
91
- * time: 3,
92
- * parallelism: 4
93
- * }),
94
- * scrypt: drivers.scrypt({
95
- * cost: 16384,
96
- * blockSize: 8,
97
- * parallelization: 1
98
- * })
99
- * }
100
- * })
101
- * ```
102
- */
103
- export const drivers = {
104
- argon2: (config) => {
105
- return configProvider.create(async () => {
106
- const { Argon } = await import('./drivers/argon.js');
107
- debug('configuring argon driver');
108
- return () => new Argon(config);
109
- });
110
- },
111
- bcrypt: (config) => {
112
- return configProvider.create(async () => {
113
- const { Bcrypt } = await import('./drivers/bcrypt.js');
114
- debug('configuring bcrypt driver');
115
- return () => new Bcrypt(config);
116
- });
117
- },
118
- scrypt: (config) => {
119
- return configProvider.create(async () => {
120
- const { Scrypt } = await import('./drivers/scrypt.js');
121
- debug('configuring scrypt driver');
122
- return () => new Scrypt(config);
123
- });
124
- },
125
- };