@adonisjs/core 6.1.5-0 → 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.
- package/build/commands/build.d.ts +10 -0
- package/build/commands/build.js +65 -22
- package/build/commands/commands.json +1 -1
- package/build/commands/configure.d.ts +36 -0
- package/build/commands/configure.js +84 -6
- package/build/commands/eject.d.ts +4 -0
- package/build/commands/eject.js +14 -7
- package/build/commands/generate_key.d.ts +4 -0
- package/build/commands/generate_key.js +14 -7
- package/build/commands/inspect_rcfile.d.ts +9 -0
- package/build/commands/inspect_rcfile.js +20 -0
- package/build/commands/list/routes.d.ts +36 -0
- package/build/commands/list/routes.js +94 -0
- package/build/commands/make/_base.d.ts +31 -1
- package/build/commands/make/_base.js +18 -10
- package/build/commands/make/command.d.ts +6 -0
- package/build/commands/make/command.js +15 -5
- package/build/commands/make/controller.d.ts +9 -0
- package/build/commands/make/controller.js +30 -11
- package/build/commands/make/event.d.ts +6 -0
- package/build/commands/make/event.js +15 -5
- package/build/commands/make/exception.d.ts +14 -0
- package/build/commands/make/exception.js +35 -0
- package/build/commands/make/listener.d.ts +7 -0
- package/build/commands/make/listener.js +20 -7
- package/build/commands/make/middleware.d.ts +7 -0
- package/build/commands/make/middleware.js +16 -5
- package/build/commands/make/preload.d.ts +22 -0
- package/build/commands/make/preload.js +95 -0
- package/build/commands/make/provider.d.ts +6 -0
- package/build/commands/make/provider.js +22 -6
- package/build/commands/make/service.d.ts +14 -0
- package/build/commands/make/service.js +35 -0
- package/build/commands/make/test.d.ts +19 -0
- package/build/commands/make/test.js +103 -0
- package/build/commands/repl.d.ts +14 -0
- package/build/commands/repl.js +30 -0
- package/build/commands/serve.d.ts +12 -0
- package/build/commands/serve.js +78 -27
- package/build/commands/test.d.ts +32 -0
- package/build/commands/test.js +203 -0
- package/build/factories/app.js +8 -0
- package/build/factories/bodyparser.js +8 -0
- package/build/factories/core/ace.d.ts +4 -1
- package/build/factories/core/ace.js +11 -0
- package/build/factories/core/ignitor.d.ts +20 -1
- package/build/factories/core/ignitor.js +35 -1
- package/build/factories/core/main.js +8 -0
- package/build/factories/core/test_utils.d.ts +4 -1
- package/build/factories/core/test_utils.js +11 -0
- package/build/factories/encryption.js +8 -0
- package/build/factories/events.js +8 -0
- package/build/factories/hash.js +8 -0
- package/build/factories/http.js +8 -0
- package/build/factories/logger.js +8 -0
- package/build/factories/stubs.d.ts +10 -0
- package/build/factories/stubs.js +21 -0
- package/build/index.d.ts +5 -1
- package/build/index.js +13 -0
- package/build/modules/ace/commands.d.ts +123 -0
- package/build/modules/ace/commands.js +79 -0
- package/build/modules/ace/create_kernel.d.ts +9 -0
- package/build/modules/ace/create_kernel.js +31 -0
- package/build/modules/ace/kernel.d.ts +4 -0
- package/build/modules/ace/kernel.js +12 -0
- package/build/modules/ace/main.d.ts +1 -1
- package/build/modules/ace/main.js +9 -1
- package/build/modules/ace/shell.d.ts +9 -1
- package/build/modules/ace/shell.js +21 -0
- package/build/modules/app.js +8 -0
- package/build/modules/bodyparser/bodyparser_middleware.d.ts +4 -0
- package/build/modules/bodyparser/bodyparser_middleware.js +12 -0
- package/build/modules/bodyparser/main.js +8 -0
- package/build/modules/config.js +8 -0
- package/build/modules/container.js +8 -0
- package/build/modules/encryption.js +8 -0
- package/build/modules/env.js +8 -0
- package/build/modules/events.js +8 -0
- package/build/modules/hash/define_config.d.ts +3 -0
- package/build/modules/hash/define_config.js +20 -0
- package/build/modules/hash/drivers_collection.d.ts +16 -4
- package/build/modules/hash/drivers_collection.js +31 -8
- package/build/modules/hash/main.d.ts +1 -0
- package/build/modules/hash/main.js +9 -0
- package/build/modules/http/main.d.ts +2 -0
- package/build/modules/http/main.js +10 -0
- package/build/modules/http/request_validator.d.ts +44 -0
- package/build/modules/http/request_validator.js +74 -0
- package/build/modules/logger.js +8 -0
- package/build/modules/repl.d.ts +1 -0
- package/build/modules/repl.js +9 -0
- package/build/providers/app_provider.d.ts +31 -2
- package/build/providers/app_provider.js +44 -15
- package/build/providers/hash_provider.d.ts +16 -0
- package/build/providers/hash_provider.js +31 -6
- package/build/providers/http_provider.d.ts +17 -0
- package/build/providers/http_provider.js +26 -1
- package/build/providers/repl_provider.d.ts +13 -0
- package/build/providers/repl_provider.js +37 -0
- package/build/services/ace.js +15 -0
- package/build/services/app.d.ts +8 -0
- package/build/services/app.js +16 -0
- package/build/services/config.js +11 -0
- package/build/services/emitter.js +13 -2
- package/build/services/encryption.js +13 -2
- package/build/services/hash.js +13 -2
- package/build/services/logger.js +13 -2
- package/build/services/repl.d.ts +3 -0
- package/build/services/repl.js +18 -0
- package/build/services/router.js +13 -2
- package/build/services/server.js +13 -2
- package/build/services/test_utils.js +15 -0
- package/build/src/bindings/repl.d.ts +6 -0
- package/build/src/bindings/repl.js +78 -0
- package/build/src/cli_formatters/routes_list.d.ts +63 -0
- package/build/src/cli_formatters/routes_list.js +376 -0
- package/build/src/debug.d.ts +1 -1
- package/build/src/debug.js +8 -0
- package/build/src/exceptions.d.ts +1 -0
- package/build/src/exceptions.js +9 -0
- package/build/src/helpers/is.js +8 -0
- package/build/src/helpers/main.d.ts +3 -1
- package/build/src/helpers/main.js +11 -1
- package/build/src/helpers/parse_binding_reference.d.ts +45 -0
- package/build/src/helpers/parse_binding_reference.js +83 -0
- package/build/src/helpers/string.d.ts +26 -0
- package/build/src/helpers/string.js +15 -0
- package/build/src/helpers/types.d.ts +7 -2
- package/build/src/helpers/types.js +13 -0
- package/build/src/ignitor/ace.d.ts +12 -0
- package/build/src/ignitor/ace.js +50 -1
- package/build/src/ignitor/http.d.ts +9 -2
- package/build/src/ignitor/http.js +67 -0
- package/build/src/ignitor/main.d.ts +29 -1
- package/build/src/ignitor/main.js +56 -0
- package/build/src/ignitor/test.d.ts +10 -0
- package/build/src/ignitor/test.js +25 -0
- package/build/src/internal_helpers.d.ts +12 -5
- package/build/src/internal_helpers.js +35 -7
- package/build/src/test_utils/http.d.ts +10 -2
- package/build/src/test_utils/http.js +19 -0
- package/build/src/test_utils/main.d.ts +21 -3
- package/build/src/test_utils/main.js +27 -1
- package/build/src/types.d.ts +61 -3
- package/build/src/types.js +8 -0
- package/build/src/vinejs/extensions/main.d.ts +1 -0
- package/build/src/vinejs/extensions/main.js +9 -0
- package/build/src/vinejs/extensions/validates_files.d.ts +22 -0
- package/build/src/vinejs/extensions/validates_files.js +76 -0
- package/build/stubs/index.js +8 -0
- package/build/stubs/make/exception/main.stub +10 -0
- package/build/stubs/make/preload_file/main.stub +4 -0
- package/build/stubs/make/service/main.stub +4 -0
- package/build/stubs/make/test/main.stub +11 -0
- package/build/toolkit/commands/index_commands.d.ts +4 -0
- package/build/toolkit/commands/index_commands.js +13 -5
- package/build/toolkit/main.js +11 -0
- package/build/types/ace.js +8 -0
- package/build/types/app.js +8 -0
- package/build/types/bodyparser.js +8 -0
- package/build/types/container.js +8 -0
- package/build/types/encryption.js +8 -0
- package/build/types/events.js +8 -0
- package/build/types/hash.js +8 -0
- package/build/types/http.js +8 -0
- package/build/types/logger.js +8 -0
- package/build/types/repl.d.ts +1 -0
- package/build/types/repl.js +9 -0
- package/package.json +76 -123
- package/build/legacy/validator.d.ts +0 -1
- package/build/legacy/validator.js +0 -1
- package/build/modules/http.d.ts +0 -1
- package/build/modules/http.js +0 -1
- package/build/src/helpers/string_builder.d.ts +0 -23
- package/build/src/helpers/string_builder.js +0 -86
package/build/services/hash.js
CHANGED
|
@@ -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(
|
|
16
|
+
hash = await app.container.make('hash');
|
|
6
17
|
});
|
|
7
18
|
export { hash as default };
|
package/build/services/logger.js
CHANGED
|
@@ -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 =
|
|
16
|
+
logger = await app.container.make('logger');
|
|
6
17
|
});
|
|
7
18
|
export { logger 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 };
|
package/build/services/router.js
CHANGED
|
@@ -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(
|
|
16
|
+
router = await app.container.make('router');
|
|
6
17
|
});
|
|
7
18
|
export { router as default };
|
package/build/services/server.js
CHANGED
|
@@ -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(
|
|
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,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
|
+
}
|
package/build/src/debug.d.ts
CHANGED
package/build/src/debug.js
CHANGED
|
@@ -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';
|