@adonisjs/core 6.13.0 → 6.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/commands/generate_key.js +1 -1
- package/build/index.js +4 -0
- package/build/modules/dumper/define_config.d.ts +13 -0
- package/build/modules/dumper/define_config.js +15 -0
- package/build/modules/dumper/dumper.d.ts +75 -0
- package/build/modules/dumper/dumper.js +186 -0
- package/build/modules/dumper/errors.d.ts +43 -0
- package/build/modules/dumper/errors.js +98 -0
- package/build/modules/dumper/main.d.ts +3 -0
- package/build/modules/dumper/main.js +11 -0
- package/build/modules/dumper/plugins/edge.d.ts +7 -0
- package/build/modules/dumper/plugins/edge.js +62 -0
- package/build/providers/app_provider.d.ts +5 -0
- package/build/providers/app_provider.js +21 -1
- package/build/providers/edge_provider.js +3 -0
- package/build/services/dumper.d.ts +6 -0
- package/build/services/dumper.js +25 -0
- package/build/src/helpers/main.d.ts +1 -1
- package/build/src/helpers/main.js +1 -1
- package/build/src/helpers/parse_binding_reference.js +1 -1
- package/build/src/types.d.ts +2 -0
- package/package.json +25 -19
|
@@ -33,7 +33,7 @@ export default class GenerateKey extends BaseCommand {
|
|
|
33
33
|
const secureKey = string.random(32);
|
|
34
34
|
if (writeToFile) {
|
|
35
35
|
const editor = await EnvEditor.create(this.app.appRoot);
|
|
36
|
-
editor.add('APP_KEY', secureKey);
|
|
36
|
+
editor.add('APP_KEY', secureKey, true);
|
|
37
37
|
await editor.save();
|
|
38
38
|
this.logger.action('add APP_KEY to .env').succeeded();
|
|
39
39
|
}
|
package/build/index.js
CHANGED
|
@@ -30,6 +30,10 @@ export const errors = {
|
|
|
30
30
|
* Youch terminal
|
|
31
31
|
*/
|
|
32
32
|
export async function prettyPrintError(error) {
|
|
33
|
+
if (error && typeof error === 'object' && error.code === 'E_DUMP_DIE_EXCEPTION') {
|
|
34
|
+
console.error(error);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
33
37
|
// @ts-expect-error
|
|
34
38
|
const { default: youchTerminal } = await import('youch-terminal');
|
|
35
39
|
const { default: Youch } = await import('youch');
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ConsoleDumpConfig } from '@poppinss/dumper/console/types';
|
|
2
|
+
import { HTMLDumpConfig } from '@poppinss/dumper/html/types';
|
|
3
|
+
/**
|
|
4
|
+
* Define config for the dumper service exported by
|
|
5
|
+
* the "@adonisjs/core/services/dumper" module
|
|
6
|
+
*/
|
|
7
|
+
export declare function defineConfig(dumperConfig: Partial<{
|
|
8
|
+
html: HTMLDumpConfig;
|
|
9
|
+
console: ConsoleDumpConfig;
|
|
10
|
+
}>): Partial<{
|
|
11
|
+
html: HTMLDumpConfig;
|
|
12
|
+
console: ConsoleDumpConfig;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,15 @@
|
|
|
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 config for the dumper service exported by
|
|
11
|
+
* the "@adonisjs/core/services/dumper" module
|
|
12
|
+
*/
|
|
13
|
+
export function defineConfig(dumperConfig) {
|
|
14
|
+
return dumperConfig;
|
|
15
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { HTMLDumpConfig } from '@poppinss/dumper/html/types';
|
|
2
|
+
import type { ConsoleDumpConfig } from '@poppinss/dumper/console/types';
|
|
3
|
+
import type { Application } from '../app.js';
|
|
4
|
+
/**
|
|
5
|
+
* Dumper exposes the API to dump or die/dump values in your
|
|
6
|
+
* AdonisJS application. An singleton instance of the Dumper
|
|
7
|
+
* is shared as a service and may use it follows.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* const dumper = container.make('dumper')
|
|
11
|
+
*
|
|
12
|
+
* dumper.configureHtmlOutput({
|
|
13
|
+
* // parser + html formatter config
|
|
14
|
+
* })
|
|
15
|
+
*
|
|
16
|
+
* dumper.configureAnsiOutput({
|
|
17
|
+
* // parser + console formatter config
|
|
18
|
+
* })
|
|
19
|
+
*
|
|
20
|
+
* const html = dumper.dumpToHtml(value)
|
|
21
|
+
* const ansi = dumper.dumpToAnsi(value)
|
|
22
|
+
*
|
|
23
|
+
* // Returns style and script tags that must be
|
|
24
|
+
* // injeted to the head of the HTML document
|
|
25
|
+
*
|
|
26
|
+
* const head = dumper.getHeadElements()
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare class Dumper {
|
|
30
|
+
#private;
|
|
31
|
+
constructor(app: Application<any>);
|
|
32
|
+
/**
|
|
33
|
+
* Configure the HTML formatter output
|
|
34
|
+
*/
|
|
35
|
+
configureHtmlOutput(config: HTMLDumpConfig): this;
|
|
36
|
+
/**
|
|
37
|
+
* Configure the ANSI formatter output
|
|
38
|
+
*/
|
|
39
|
+
configureAnsiOutput(config: ConsoleDumpConfig): this;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the style and the script elements for the
|
|
42
|
+
* HTML document
|
|
43
|
+
*/
|
|
44
|
+
getHeadElements(cspNonce?: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Dump value to HTML ouput
|
|
47
|
+
*/
|
|
48
|
+
dumpToHtml(value: unknown, options?: {
|
|
49
|
+
cspNonce?: string;
|
|
50
|
+
title?: string;
|
|
51
|
+
source?: {
|
|
52
|
+
location: string;
|
|
53
|
+
line: number;
|
|
54
|
+
};
|
|
55
|
+
}): string;
|
|
56
|
+
/**
|
|
57
|
+
* Dump value to ANSI output
|
|
58
|
+
*/
|
|
59
|
+
dumpToAnsi(value: unknown, options?: {
|
|
60
|
+
title?: string;
|
|
61
|
+
source?: {
|
|
62
|
+
location: string;
|
|
63
|
+
line: number;
|
|
64
|
+
};
|
|
65
|
+
}): string;
|
|
66
|
+
/**
|
|
67
|
+
* Dump values and die. The formatter will be picked
|
|
68
|
+
* based upon where your app is running.
|
|
69
|
+
*
|
|
70
|
+
* - During an HTTP request, the HTML output will be
|
|
71
|
+
* sent to the server.
|
|
72
|
+
* - Otherwise the value will be logged in the console
|
|
73
|
+
*/
|
|
74
|
+
dd(value: unknown, traceSourceIndex?: number): void;
|
|
75
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
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
|
+
constructor(app) {
|
|
93
|
+
this.#app = app;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Returns the link to open the file using dd inside one
|
|
97
|
+
* of the known code editors
|
|
98
|
+
*/
|
|
99
|
+
#getEditorLink(source) {
|
|
100
|
+
const editorURL = this.#editors[IDE] || IDE;
|
|
101
|
+
if (!editorURL || !source) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
href: editorURL.replace('%f', source.location).replace('%l', String(source.line)),
|
|
106
|
+
text: `${this.#app.relativePath(source.location)}:${source.line}`,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Configure the HTML formatter output
|
|
111
|
+
*/
|
|
112
|
+
configureHtmlOutput(config) {
|
|
113
|
+
this.#htmlConfig = config;
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Configure the ANSI formatter output
|
|
118
|
+
*/
|
|
119
|
+
configureAnsiOutput(config) {
|
|
120
|
+
this.#consoleConfig = config;
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Returns the style and the script elements for the
|
|
125
|
+
* HTML document
|
|
126
|
+
*/
|
|
127
|
+
getHeadElements(cspNonce) {
|
|
128
|
+
return (`<style id="dumper-styles">` +
|
|
129
|
+
createStyleSheet() +
|
|
130
|
+
DUMP_TITLE_STYLES +
|
|
131
|
+
'</style>' +
|
|
132
|
+
`<script id="dumper-script"${cspNonce ? ` nonce="${cspNonce}"` : ''}>` +
|
|
133
|
+
createScript() +
|
|
134
|
+
'</script>');
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Dump value to HTML ouput
|
|
138
|
+
*/
|
|
139
|
+
dumpToHtml(value, options = {}) {
|
|
140
|
+
const link = this.#getEditorLink(options.source) ?? null;
|
|
141
|
+
const title = options.title || 'DUMP';
|
|
142
|
+
return ('<div class="adonisjs-dump-header">' +
|
|
143
|
+
`<span class="adonisjs-dump-header-title">${title}</span>` +
|
|
144
|
+
(link ? `<a href="${link.href}" class="adonisjs-dump-header-source">${link.text}</a>` : '') +
|
|
145
|
+
'</div>' +
|
|
146
|
+
dump(value, { cspNonce: options.cspNonce, ...this.#htmlConfig }));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Dump value to ANSI output
|
|
150
|
+
*/
|
|
151
|
+
dumpToAnsi(value, options = {}) {
|
|
152
|
+
const columns = process.stdout.columns;
|
|
153
|
+
/**
|
|
154
|
+
* Link to the source file
|
|
155
|
+
*/
|
|
156
|
+
const link = `${this.#getEditorLink(options.source)?.text ?? ''} `;
|
|
157
|
+
/**
|
|
158
|
+
* Dump title
|
|
159
|
+
*/
|
|
160
|
+
const title = ` ${options.title || 'DUMP'}`;
|
|
161
|
+
/**
|
|
162
|
+
* Whitespace between the title and the link to align them
|
|
163
|
+
* on each side of x axis
|
|
164
|
+
*/
|
|
165
|
+
const whiteSpaceLength = columns ? columns - link.length - title.length - 4 : 2;
|
|
166
|
+
const whiteSpace = new Array(whiteSpaceLength <= 0 ? 2 : whiteSpaceLength).join(' ');
|
|
167
|
+
/**
|
|
168
|
+
* Styled heading with background color and bold text
|
|
169
|
+
*/
|
|
170
|
+
const heading = colors.bgRed().bold(`${title}${whiteSpace}${link}`);
|
|
171
|
+
return `${heading}\n${consoleDump(value, this.#consoleConfig)}`;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Dump values and die. The formatter will be picked
|
|
175
|
+
* based upon where your app is running.
|
|
176
|
+
*
|
|
177
|
+
* - During an HTTP request, the HTML output will be
|
|
178
|
+
* sent to the server.
|
|
179
|
+
* - Otherwise the value will be logged in the console
|
|
180
|
+
*/
|
|
181
|
+
dd(value, traceSourceIndex = 1) {
|
|
182
|
+
const error = new E_DUMP_DIE_EXCEPTION(value, this);
|
|
183
|
+
error.setTraceSourceIndex(traceSourceIndex);
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
import type { Kernel } from '@adonisjs/core/ace';
|
|
3
|
+
import { Exception } from '@poppinss/utils/exception';
|
|
4
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
5
|
+
import type { Dumper } from './dumper.js';
|
|
6
|
+
/**
|
|
7
|
+
* DumpDie exception is raised by the "dd" function. It will
|
|
8
|
+
* result in dumping the value in response to an HTTP
|
|
9
|
+
* request or printing the value to the console
|
|
10
|
+
*/
|
|
11
|
+
declare class DumpDieException extends Exception {
|
|
12
|
+
#private;
|
|
13
|
+
static status: number;
|
|
14
|
+
static code: string;
|
|
15
|
+
fileName: string;
|
|
16
|
+
lineNumber: number;
|
|
17
|
+
value: unknown;
|
|
18
|
+
constructor(value: unknown, dumper: Dumper);
|
|
19
|
+
/**
|
|
20
|
+
* Set the index for the trace source. This is helpful when
|
|
21
|
+
* you build nested helpers on top of Die/Dump
|
|
22
|
+
*/
|
|
23
|
+
setTraceSourceIndex(index: number): this;
|
|
24
|
+
/**
|
|
25
|
+
* Preventing itself from getting reported by the
|
|
26
|
+
* AdonisJS exception reporter
|
|
27
|
+
*/
|
|
28
|
+
report(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Handler called by the AdonisJS HTTP exception handler
|
|
31
|
+
*/
|
|
32
|
+
handle(error: DumpDieException, ctx: HttpContext): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Handler called by the AdonisJS Ace kernel
|
|
35
|
+
*/
|
|
36
|
+
render(error: DumpDieException, kernel: Kernel): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Custom output for the Node.js util inspect
|
|
39
|
+
*/
|
|
40
|
+
[inspect.custom](): string;
|
|
41
|
+
}
|
|
42
|
+
export declare const E_DUMP_DIE_EXCEPTION: typeof DumpDieException;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
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 is raised by the "dd" function. It will
|
|
14
|
+
* result in dumping the value in response to an HTTP
|
|
15
|
+
* request or printing the value to the console
|
|
16
|
+
*/
|
|
17
|
+
class DumpDieException extends Exception {
|
|
18
|
+
static status = 500;
|
|
19
|
+
static code = 'E_DUMP_DIE_EXCEPTION';
|
|
20
|
+
#dumper;
|
|
21
|
+
#traceSourceIndex = 1;
|
|
22
|
+
value;
|
|
23
|
+
constructor(value, dumper) {
|
|
24
|
+
super('Dump and Die exception');
|
|
25
|
+
this.#dumper = dumper;
|
|
26
|
+
this.value = value;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns the source file and line number location for the error
|
|
30
|
+
*/
|
|
31
|
+
#getErrorSource() {
|
|
32
|
+
if (this.fileName && this.lineNumber) {
|
|
33
|
+
return {
|
|
34
|
+
location: this.fileName,
|
|
35
|
+
line: this.lineNumber,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const source = parse(this)[this.#traceSourceIndex];
|
|
39
|
+
if (!source.fileName || !source.lineNumber) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
location: source.fileName,
|
|
44
|
+
line: source.lineNumber,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Set the index for the trace source. This is helpful when
|
|
49
|
+
* you build nested helpers on top of Die/Dump
|
|
50
|
+
*/
|
|
51
|
+
setTraceSourceIndex(index) {
|
|
52
|
+
this.#traceSourceIndex = index;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Preventing itself from getting reported by the
|
|
57
|
+
* AdonisJS exception reporter
|
|
58
|
+
*/
|
|
59
|
+
report() { }
|
|
60
|
+
/**
|
|
61
|
+
* Handler called by the AdonisJS HTTP exception handler
|
|
62
|
+
*/
|
|
63
|
+
async handle(error, ctx) {
|
|
64
|
+
const source = this.#getErrorSource();
|
|
65
|
+
/**
|
|
66
|
+
* Comes from the shield package
|
|
67
|
+
*/
|
|
68
|
+
const cspNonce = 'nonce' in ctx.response ? ctx.response.nonce : undefined;
|
|
69
|
+
ctx.response
|
|
70
|
+
.status(500)
|
|
71
|
+
.send('<!DOCTYPE html>' +
|
|
72
|
+
'<html>' +
|
|
73
|
+
'<head>' +
|
|
74
|
+
'<meta charset="utf-8">' +
|
|
75
|
+
'<meta name="viewport" content="width=device-width">' +
|
|
76
|
+
`${this.#dumper.getHeadElements(cspNonce)}` +
|
|
77
|
+
'</head>' +
|
|
78
|
+
'<body>' +
|
|
79
|
+
`${this.#dumper.dumpToHtml(error.value, { cspNonce, source, title: 'DUMP DIE' })}` +
|
|
80
|
+
'</body>' +
|
|
81
|
+
'</html>');
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Handler called by the AdonisJS Ace kernel
|
|
85
|
+
*/
|
|
86
|
+
async render(error, kernel) {
|
|
87
|
+
const source = this.#getErrorSource();
|
|
88
|
+
kernel.ui.logger.log(this.#dumper.dumpToAnsi(error.value, { source, title: 'DUMP DIE' }));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Custom output for the Node.js util inspect
|
|
92
|
+
*/
|
|
93
|
+
[inspect.custom]() {
|
|
94
|
+
const source = this.#getErrorSource();
|
|
95
|
+
return this.#dumper.dumpToAnsi(this.value, { source, title: 'DUMP DIE' });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export const E_DUMP_DIE_EXCEPTION = DumpDieException;
|
|
@@ -0,0 +1,11 @@
|
|
|
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 * as errors from './errors.js';
|
|
10
|
+
export { Dumper } from './dumper.js';
|
|
11
|
+
export { defineConfig } from './define_config.js';
|
|
@@ -0,0 +1,62 @@
|
|
|
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 { Template } from 'edge.js';
|
|
10
|
+
/**
|
|
11
|
+
* Returns an edge plugin that integrates with a given
|
|
12
|
+
* dumper instance
|
|
13
|
+
*/
|
|
14
|
+
export function pluginEdgeDumper(dumper) {
|
|
15
|
+
Template.macro('dumper', dumper);
|
|
16
|
+
return (edge) => {
|
|
17
|
+
edge.registerTag({
|
|
18
|
+
tagName: 'dump',
|
|
19
|
+
block: false,
|
|
20
|
+
seekable: true,
|
|
21
|
+
noNewLine: true,
|
|
22
|
+
compile(parser, buffer, token) {
|
|
23
|
+
const parsed = parser.utils.transformAst(parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename), token.filename, parser);
|
|
24
|
+
buffer.writeExpression(`template.stacks.pushOnceTo('dumper', 'dumper_globals', template.dumper.getHeadElements(state.cspNonce))`, token.filename, token.loc.start.line);
|
|
25
|
+
buffer.outputExpression(`template.dumper.dumpToHtml(${parser.utils.stringify(parsed)}, { cspNonce: state.cspNonce, source: { location: $filename, line: $lineNumber } })`, token.filename, token.loc.start.line, true);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
edge.registerTag({
|
|
29
|
+
tagName: 'dd',
|
|
30
|
+
block: false,
|
|
31
|
+
seekable: true,
|
|
32
|
+
noNewLine: true,
|
|
33
|
+
compile(parser, buffer, token) {
|
|
34
|
+
const parsed = parser.utils.transformAst(parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename), token.filename, parser);
|
|
35
|
+
/**
|
|
36
|
+
* Dump/Die statement to catch error and convert it into
|
|
37
|
+
* an Edge error
|
|
38
|
+
*/
|
|
39
|
+
const ddStatement = [
|
|
40
|
+
'try {',
|
|
41
|
+
` template.dumper.dd(${parser.utils.stringify(parsed)})`,
|
|
42
|
+
'} catch (error) {',
|
|
43
|
+
` if (error.code === 'E_DUMP_DIE_EXCEPTION') {`,
|
|
44
|
+
' const edgeError = template.createError(error.message, $filename, $lineNumber)',
|
|
45
|
+
' error.fileName = $filename',
|
|
46
|
+
' error.lineNumber = $lineNumber',
|
|
47
|
+
' edgeError.handle = function (_, ctx) {',
|
|
48
|
+
' return error.handle(error, ctx)',
|
|
49
|
+
' }',
|
|
50
|
+
' edgeError.report = function () {',
|
|
51
|
+
' return error.report(error)',
|
|
52
|
+
' }',
|
|
53
|
+
' throw edgeError',
|
|
54
|
+
' }',
|
|
55
|
+
' throw error',
|
|
56
|
+
'}',
|
|
57
|
+
].join('\n');
|
|
58
|
+
buffer.writeStatement(ddStatement, token.filename, token.loc.start.line);
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -51,6 +51,11 @@ export default class AppServiceProvider {
|
|
|
51
51
|
* config that cannot be resolved by the container
|
|
52
52
|
*/
|
|
53
53
|
protected registerBodyParserMiddleware(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Registeres singleton instance of the "Dumper" module configured
|
|
56
|
+
* via the "config/app.ts" file.
|
|
57
|
+
*/
|
|
58
|
+
protected registerDumper(): void;
|
|
54
59
|
/**
|
|
55
60
|
* Registers bindings
|
|
56
61
|
*/
|
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
import { Config } from '../modules/config.js';
|
|
10
10
|
import { Logger } from '../modules/logger.js';
|
|
11
11
|
import { Application } from '../modules/app.js';
|
|
12
|
-
import {
|
|
12
|
+
import { Dumper } from '../modules/dumper/dumper.js';
|
|
13
13
|
import { Encryption } from '../modules/encryption.js';
|
|
14
14
|
import { Router, Server } from '../modules/http/main.js';
|
|
15
|
+
import { BaseEvent, Emitter } from '../modules/events.js';
|
|
15
16
|
import BodyParserMiddleware from '../modules/bodyparser/bodyparser_middleware.js';
|
|
16
17
|
/**
|
|
17
18
|
* The Application Service provider registers all the baseline
|
|
@@ -125,12 +126,31 @@ export default class AppServiceProvider {
|
|
|
125
126
|
return new BodyParserMiddleware(config);
|
|
126
127
|
});
|
|
127
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Registeres singleton instance of the "Dumper" module configured
|
|
131
|
+
* via the "config/app.ts" file.
|
|
132
|
+
*/
|
|
133
|
+
registerDumper() {
|
|
134
|
+
this.app.container.singleton(Dumper, async () => {
|
|
135
|
+
const config = this.app.config.get('app.dumper', {});
|
|
136
|
+
const dumper = new Dumper(this.app);
|
|
137
|
+
if (config.html) {
|
|
138
|
+
dumper.configureHtmlOutput(config.html);
|
|
139
|
+
}
|
|
140
|
+
if (config.console) {
|
|
141
|
+
dumper.configureAnsiOutput(config.console);
|
|
142
|
+
}
|
|
143
|
+
return dumper;
|
|
144
|
+
});
|
|
145
|
+
this.app.container.alias('dumper', Dumper);
|
|
146
|
+
}
|
|
128
147
|
/**
|
|
129
148
|
* Registers bindings
|
|
130
149
|
*/
|
|
131
150
|
register() {
|
|
132
151
|
this.registerApp();
|
|
133
152
|
this.registerAce();
|
|
153
|
+
this.registerDumper();
|
|
134
154
|
this.registerLoggerManager();
|
|
135
155
|
this.registerLogger();
|
|
136
156
|
this.registerConfig();
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import edge from 'edge.js';
|
|
10
|
+
import { pluginEdgeDumper } from '../modules/dumper/plugins/edge.js';
|
|
10
11
|
import { BriskRoute, HttpContext } from '../modules/http/main.js';
|
|
11
12
|
/**
|
|
12
13
|
* The Edge service provider configures Edge to work within
|
|
@@ -24,6 +25,7 @@ export default class EdgeServiceProvider {
|
|
|
24
25
|
async boot() {
|
|
25
26
|
const app = this.app;
|
|
26
27
|
const router = await this.app.container.make('router');
|
|
28
|
+
const dumper = await this.app.container.make('dumper');
|
|
27
29
|
function edgeConfigResolver(key, defaultValue) {
|
|
28
30
|
return app.config.get(key, defaultValue);
|
|
29
31
|
}
|
|
@@ -66,5 +68,6 @@ export default class EdgeServiceProvider {
|
|
|
66
68
|
return view.render(template, data);
|
|
67
69
|
});
|
|
68
70
|
});
|
|
71
|
+
edge.use(pluginEdgeDumper(dumper));
|
|
69
72
|
}
|
|
70
73
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 dumper;
|
|
11
|
+
/**
|
|
12
|
+
* dumper service is an instance of the "Dumper" class stored inside
|
|
13
|
+
* the "modules/dumper/dumper.ts" file
|
|
14
|
+
*/
|
|
15
|
+
await app.booted(async () => {
|
|
16
|
+
dumper = await app.container.make('dumper');
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Dump a value and die. The dumped value will be displayed
|
|
20
|
+
* using the HTML printer during an HTTP request or within
|
|
21
|
+
* the console otherwise.
|
|
22
|
+
*/
|
|
23
|
+
export const dd = (value) => {
|
|
24
|
+
dumper.dd(value, 2);
|
|
25
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { parseImports } from 'parse-imports';
|
|
2
2
|
export { createId as cuid, isCuid } from '@paralleldrive/cuid2';
|
|
3
3
|
export { slash, base64, compose, Secret, joinToURL, fsReadAll, safeEqual, getDirname, getFilename, fsImportAll, MessageBuilder, } from '@poppinss/utils';
|
|
4
4
|
export { parseBindingReference } from './parse_binding_reference.js';
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
export {
|
|
9
|
+
export { parseImports } from 'parse-imports';
|
|
10
10
|
export { createId as cuid, isCuid } from '@paralleldrive/cuid2';
|
|
11
11
|
export { slash, base64, compose, Secret, joinToURL, fsReadAll, safeEqual, getDirname, getFilename, fsImportAll, MessageBuilder, } from '@poppinss/utils';
|
|
12
12
|
export { parseBindingReference } from './parse_binding_reference.js';
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
import parseImports from 'parse-imports';
|
|
9
|
+
import { parseImports } from 'parse-imports';
|
|
10
10
|
/**
|
|
11
11
|
* The "parseBindingReference" method can be used to parse a binding references
|
|
12
12
|
* similar to route controller binding value or event listener binding value.
|
package/build/src/types.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { Kernel } from '../modules/ace/main.js';
|
|
|
5
5
|
import type { Application } from '../modules/app.js';
|
|
6
6
|
import type { TestUtils } from './test_utils/main.js';
|
|
7
7
|
import type { HttpServerEvents } from '../types/http.js';
|
|
8
|
+
import type { Dumper } from '../modules/dumper/dumper.js';
|
|
8
9
|
import type { LoggerManager } from '../modules/logger.js';
|
|
9
10
|
import type { HashManager } from '../modules/hash/main.js';
|
|
10
11
|
import type { Encryption } from '../modules/encryption.js';
|
|
@@ -109,6 +110,7 @@ export interface HashService extends HashManager<HashersList extends Record<stri
|
|
|
109
110
|
*/
|
|
110
111
|
export interface ContainerBindings {
|
|
111
112
|
ace: Kernel;
|
|
113
|
+
dumper: Dumper;
|
|
112
114
|
app: ApplicationService;
|
|
113
115
|
logger: LoggerService;
|
|
114
116
|
config: ApplicationService['config'];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/core",
|
|
3
3
|
"description": "Core of AdonisJS",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.14.0",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.6.0"
|
|
7
7
|
},
|
|
@@ -49,6 +49,8 @@
|
|
|
49
49
|
"./container": "./build/modules/container.js",
|
|
50
50
|
"./encryption": "./build/modules/encryption.js",
|
|
51
51
|
"./env": "./build/modules/env/main.js",
|
|
52
|
+
"./dumper": "./build/modules/dumper/main.js",
|
|
53
|
+
"./dumper/plugin_edge": "./build/modules/dumper/plugins/edge.js",
|
|
52
54
|
"./env/editor": "./build/modules/env/editor.js",
|
|
53
55
|
"./events": "./build/modules/events.js",
|
|
54
56
|
"./http": "./build/modules/http/main.js",
|
|
@@ -82,18 +84,19 @@
|
|
|
82
84
|
},
|
|
83
85
|
"devDependencies": {
|
|
84
86
|
"@adonisjs/assembler": "^7.8.2",
|
|
85
|
-
"@adonisjs/eslint-config": "^2.0.0-beta.
|
|
87
|
+
"@adonisjs/eslint-config": "^2.0.0-beta.7",
|
|
86
88
|
"@adonisjs/prettier-config": "^1.4.0",
|
|
87
89
|
"@adonisjs/tsconfig": "^1.4.0",
|
|
88
|
-
"@commitlint/cli": "^19.
|
|
89
|
-
"@commitlint/config-conventional": "^19.
|
|
90
|
+
"@commitlint/cli": "^19.5.0",
|
|
91
|
+
"@commitlint/config-conventional": "^19.5.0",
|
|
90
92
|
"@japa/assert": "^3.0.0",
|
|
91
93
|
"@japa/expect-type": "^2.0.2",
|
|
92
94
|
"@japa/file-system": "^2.3.0",
|
|
93
95
|
"@japa/runner": "^3.1.4",
|
|
94
|
-
"@
|
|
95
|
-
"@
|
|
96
|
-
"@
|
|
96
|
+
"@japa/snapshot": "^2.0.5",
|
|
97
|
+
"@release-it/conventional-changelog": "^8.0.2",
|
|
98
|
+
"@swc/core": "^1.7.26",
|
|
99
|
+
"@types/node": "^22.5.5",
|
|
97
100
|
"@types/pretty-hrtime": "^1.0.3",
|
|
98
101
|
"@types/sinon": "^17.0.3",
|
|
99
102
|
"@types/supertest": "^6.0.2",
|
|
@@ -105,19 +108,19 @@
|
|
|
105
108
|
"copyfiles": "^2.4.1",
|
|
106
109
|
"cross-env": "^7.0.3",
|
|
107
110
|
"del-cli": "^5.1.0",
|
|
108
|
-
"edge.js": "^6.0
|
|
109
|
-
"eslint": "^9.
|
|
110
|
-
"execa": "^9.
|
|
111
|
+
"edge.js": "^6.2.0",
|
|
112
|
+
"eslint": "^9.11.0",
|
|
113
|
+
"execa": "^9.4.0",
|
|
111
114
|
"get-port": "^7.1.0",
|
|
112
115
|
"github-label-sync": "^2.3.1",
|
|
113
|
-
"husky": "^9.1.
|
|
116
|
+
"husky": "^9.1.6",
|
|
114
117
|
"prettier": "^3.3.3",
|
|
115
118
|
"release-it": "^17.6.0",
|
|
116
|
-
"sinon": "^
|
|
119
|
+
"sinon": "^19.0.2",
|
|
117
120
|
"supertest": "^7.0.0",
|
|
118
121
|
"test-console": "^2.0.0",
|
|
119
122
|
"ts-node-maintained": "^10.9.4",
|
|
120
|
-
"typescript": "^5.
|
|
123
|
+
"typescript": "^5.6.2"
|
|
121
124
|
},
|
|
122
125
|
"dependencies": {
|
|
123
126
|
"@adonisjs/ace": "^13.2.0",
|
|
@@ -128,19 +131,22 @@
|
|
|
128
131
|
"@adonisjs/env": "^6.1.0",
|
|
129
132
|
"@adonisjs/events": "^9.0.2",
|
|
130
133
|
"@adonisjs/fold": "^10.1.2",
|
|
131
|
-
"@adonisjs/hash": "^9.0.
|
|
134
|
+
"@adonisjs/hash": "^9.0.5",
|
|
132
135
|
"@adonisjs/health": "^2.0.0",
|
|
133
136
|
"@adonisjs/http-server": "^7.2.3",
|
|
134
137
|
"@adonisjs/logger": "^6.0.3",
|
|
135
138
|
"@adonisjs/repl": "^4.0.1",
|
|
136
139
|
"@antfu/install-pkg": "^0.4.1",
|
|
137
140
|
"@paralleldrive/cuid2": "^2.2.2",
|
|
138
|
-
"@poppinss/
|
|
139
|
-
"@poppinss/
|
|
140
|
-
"@
|
|
141
|
+
"@poppinss/colors": "^4.1.3",
|
|
142
|
+
"@poppinss/dumper": "^0.4.1",
|
|
143
|
+
"@poppinss/macroable": "^1.0.3",
|
|
144
|
+
"@poppinss/utils": "^6.8.3",
|
|
145
|
+
"@sindresorhus/is": "^7.0.1",
|
|
141
146
|
"@types/he": "^1.2.3",
|
|
147
|
+
"error-stack-parser-es": "^0.1.5",
|
|
142
148
|
"he": "^1.2.0",
|
|
143
|
-
"parse-imports": "^
|
|
149
|
+
"parse-imports": "^2.2.1",
|
|
144
150
|
"pretty-hrtime": "^1.0.3",
|
|
145
151
|
"string-width": "^7.2.0",
|
|
146
152
|
"youch": "^3.3.3",
|
|
@@ -151,7 +157,7 @@
|
|
|
151
157
|
"@vinejs/vine": "^2.1.0",
|
|
152
158
|
"argon2": "^0.31.2 || ^0.41.0",
|
|
153
159
|
"bcrypt": "^5.1.1",
|
|
154
|
-
"edge.js": "^6.0
|
|
160
|
+
"edge.js": "^6.2.0"
|
|
155
161
|
},
|
|
156
162
|
"peerDependenciesMeta": {
|
|
157
163
|
"argon2": {
|