@adonisjs/core 6.1.5-8 → 6.2.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.
Files changed (135) hide show
  1. package/README.md +3 -5
  2. package/build/commands/build.d.ts +3 -5
  3. package/build/commands/build.js +5 -9
  4. package/build/commands/commands.json +1 -1
  5. package/build/commands/configure.d.ts +21 -28
  6. package/build/commands/configure.js +60 -118
  7. package/build/commands/eject.js +2 -1
  8. package/build/commands/generate_key.js +2 -2
  9. package/build/commands/inspect_rcfile.js +19 -2
  10. package/build/commands/main.d.ts +4 -0
  11. package/build/commands/make/command.d.ts +1 -1
  12. package/build/commands/make/command.js +5 -2
  13. package/build/commands/make/controller.d.ts +2 -1
  14. package/build/commands/make/controller.js +33 -10
  15. package/build/commands/make/event.d.ts +1 -1
  16. package/build/commands/make/event.js +5 -3
  17. package/build/commands/make/exception.d.ts +1 -1
  18. package/build/commands/make/exception.js +6 -4
  19. package/build/commands/make/listener.d.ts +1 -1
  20. package/build/commands/make/listener.js +9 -6
  21. package/build/commands/make/middleware.d.ts +2 -1
  22. package/build/commands/make/middleware.js +50 -4
  23. package/build/commands/make/preload.d.ts +4 -3
  24. package/build/commands/make/preload.js +34 -35
  25. package/build/commands/make/provider.d.ts +7 -1
  26. package/build/commands/make/provider.js +57 -7
  27. package/build/commands/make/service.d.ts +1 -1
  28. package/build/commands/make/service.js +5 -3
  29. package/build/commands/make/test.d.ts +1 -1
  30. package/build/commands/make/test.js +7 -5
  31. package/build/commands/make/validator.d.ts +19 -0
  32. package/build/commands/make/validator.js +53 -0
  33. package/build/commands/make/view.d.ts +14 -0
  34. package/build/commands/make/view.js +37 -0
  35. package/build/commands/serve.js +7 -4
  36. package/build/commands/test.js +2 -2
  37. package/build/factories/core/ace.d.ts +2 -2
  38. package/build/factories/core/ignitor.d.ts +2 -2
  39. package/build/factories/core/ignitor.js +9 -10
  40. package/build/factories/core/main.d.ts +0 -1
  41. package/build/factories/core/main.js +0 -1
  42. package/build/factories/core/test_utils.d.ts +2 -2
  43. package/build/factories/stubs.d.ts +2 -2
  44. package/build/factories/stubs.js +3 -2
  45. package/build/index.d.ts +11 -140
  46. package/build/index.js +5 -1
  47. package/build/modules/ace/codemods.d.ts +93 -0
  48. package/build/modules/ace/codemods.js +259 -0
  49. package/build/modules/ace/commands.d.ts +6 -81
  50. package/build/modules/ace/commands.js +12 -33
  51. package/build/modules/ace/create_kernel.d.ts +1 -1
  52. package/build/modules/ace/create_kernel.js +19 -3
  53. package/build/modules/env/editor.d.ts +1 -0
  54. package/build/modules/{http.js → env/editor.js} +1 -1
  55. package/build/modules/hash/define_config.d.ts +29 -12
  56. package/build/modules/hash/define_config.js +52 -11
  57. package/build/modules/hash/drivers/argon.d.ts +1 -0
  58. package/build/modules/hash/drivers/argon.js +9 -0
  59. package/build/modules/hash/drivers/bcrypt.d.ts +1 -0
  60. package/build/modules/hash/drivers/bcrypt.js +9 -0
  61. package/build/modules/hash/drivers/scrypt.d.ts +1 -0
  62. package/build/modules/hash/drivers/scrypt.js +9 -0
  63. package/build/modules/hash/main.d.ts +1 -2
  64. package/build/modules/hash/main.js +1 -2
  65. package/build/modules/hash/phc_formatter.d.ts +1 -0
  66. package/build/modules/hash/phc_formatter.js +9 -0
  67. package/build/modules/http/main.d.ts +7 -0
  68. package/build/modules/http/main.js +15 -0
  69. package/build/modules/http/request_validator.d.ts +34 -0
  70. package/build/modules/http/request_validator.js +66 -0
  71. package/build/providers/app_provider.d.ts +14 -0
  72. package/build/providers/app_provider.js +47 -3
  73. package/build/providers/edge_provider.d.ts +31 -0
  74. package/build/providers/edge_provider.js +70 -0
  75. package/build/providers/hash_provider.d.ts +0 -4
  76. package/build/providers/hash_provider.js +11 -11
  77. package/build/providers/repl_provider.js +83 -8
  78. package/build/providers/vinejs_provider.d.ts +43 -0
  79. package/build/providers/vinejs_provider.js +97 -0
  80. package/build/src/cli_formatters/routes_list.d.ts +1 -1
  81. package/build/src/config_provider.d.ts +9 -0
  82. package/build/src/config_provider.js +26 -0
  83. package/build/src/debug.d.ts +1 -1
  84. package/build/src/helpers/assert.d.ts +1 -0
  85. package/build/src/helpers/assert.js +9 -0
  86. package/build/src/helpers/main.d.ts +2 -2
  87. package/build/src/helpers/main.js +2 -2
  88. package/build/src/helpers/types.d.ts +109 -16
  89. package/build/src/helpers/types.js +3 -3
  90. package/build/src/ignitor/ace.js +3 -1
  91. package/build/src/ignitor/http.d.ts +2 -2
  92. package/build/src/ignitor/http.js +5 -1
  93. package/build/src/ignitor/main.d.ts +2 -2
  94. package/build/src/ignitor/main.js +1 -1
  95. package/build/src/test_utils/http.d.ts +2 -2
  96. package/build/src/test_utils/main.d.ts +3 -3
  97. package/build/src/test_utils/main.js +1 -1
  98. package/build/src/types.d.ts +18 -18
  99. package/build/stubs/make/command/main.stub +6 -4
  100. package/build/stubs/make/controller/actions.stub +14 -0
  101. package/build/stubs/make/controller/api.stub +6 -4
  102. package/build/stubs/make/controller/main.stub +6 -4
  103. package/build/stubs/make/controller/resource.stub +6 -4
  104. package/build/stubs/make/event/main.stub +5 -3
  105. package/build/stubs/make/exception/main.stub +5 -3
  106. package/build/stubs/make/listener/for_event.stub +6 -4
  107. package/build/stubs/make/listener/main.stub +5 -3
  108. package/build/stubs/make/middleware/main.stub +7 -5
  109. package/build/stubs/make/{preload_file → preload}/main.stub +5 -3
  110. package/build/stubs/make/provider/main.stub +6 -4
  111. package/build/stubs/make/service/main.stub +5 -3
  112. package/build/stubs/make/test/main.stub +5 -3
  113. package/build/stubs/make/validator/main.stub +7 -0
  114. package/build/stubs/make/validator/resource.stub +26 -0
  115. package/build/stubs/make/view/main.stub +6 -0
  116. package/build/types/bodyparser.js +1 -1
  117. package/build/types/helpers.d.ts +1 -0
  118. package/build/types/helpers.js +9 -0
  119. package/build/types/http.d.ts +7 -0
  120. package/package.json +71 -56
  121. package/build/commands/make/_base.d.ts +0 -36
  122. package/build/commands/make/_base.js +0 -27
  123. package/build/modules/ace/shell.d.ts +0 -12
  124. package/build/modules/ace/shell.js +0 -49
  125. package/build/modules/hash/drivers_collection.d.ts +0 -21
  126. package/build/modules/hash/drivers_collection.js +0 -45
  127. package/build/modules/http.d.ts +0 -1
  128. package/build/providers/http_provider.d.ts +0 -26
  129. package/build/providers/http_provider.js +0 -61
  130. package/build/src/bindings/repl.d.ts +0 -6
  131. package/build/src/bindings/repl.js +0 -78
  132. /package/build/modules/{env.d.ts → env/main.d.ts} +0 -0
  133. /package/build/modules/{env.js → env/main.js} +0 -0
  134. /package/build/stubs/{index.d.ts → main.d.ts} +0 -0
  135. /package/build/stubs/{index.js → main.js} +0 -0
@@ -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 * from '@adonisjs/hash/drivers/scrypt';
@@ -1,3 +1,2 @@
1
1
  export * from '@adonisjs/hash';
2
- export { defineConfig } from './define_config.js';
3
- export { default as driversList } from './drivers_collection.js';
2
+ export { defineConfig, drivers } from './define_config.js';
@@ -7,5 +7,4 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  export * from '@adonisjs/hash';
10
- export { defineConfig } from './define_config.js';
11
- export { default as driversList } from './drivers_collection.js';
10
+ export { defineConfig, drivers } from './define_config.js';
@@ -0,0 +1 @@
1
+ export * from '@adonisjs/hash/phc_formatter';
@@ -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 * from '@adonisjs/hash/phc_formatter';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Bodyparser import is needed to merge types of Request
3
+ * class augmented by the bodyparser package
4
+ */
5
+ import '@adonisjs/bodyparser';
6
+ export * from '@adonisjs/http-server';
7
+ export { RequestValidator } from './request_validator.js';
@@ -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
+ * Bodyparser import is needed to merge types of Request
11
+ * class augmented by the bodyparser package
12
+ */
13
+ import '@adonisjs/bodyparser';
14
+ export * from '@adonisjs/http-server';
15
+ export { RequestValidator } from './request_validator.js';
@@ -0,0 +1,34 @@
1
+ import type { VineValidator } from '@vinejs/vine';
2
+ import type { Infer, SchemaTypes, ErrorReporterContract, MessagesProviderContact } from '@vinejs/vine/types';
3
+ import type { HttpContext } from './main.js';
4
+ import type { RequestValidationOptions } from '../../types/http.js';
5
+ /**
6
+ * Request validator is used validate HTTP request data using
7
+ * VineJS validators. You may validate the request body,
8
+ * files, cookies, and headers.
9
+ */
10
+ export declare class RequestValidator {
11
+ #private;
12
+ constructor(ctx: HttpContext);
13
+ /**
14
+ * The error reporter method returns the error reporter
15
+ * to use for reporting errors.
16
+ *
17
+ * You can use this function to pick a different error reporter
18
+ * for each HTTP request
19
+ */
20
+ static errorReporter?: (_: HttpContext) => ErrorReporterContract;
21
+ /**
22
+ * The messages provider method returns the messages provider to use
23
+ * finding custom error messages
24
+ *
25
+ * You can use this function to pick a different messages provider for
26
+ * each HTTP request
27
+ */
28
+ static messagesProvider?: (_: HttpContext) => MessagesProviderContact;
29
+ /**
30
+ * The validate method can be used to validate the request
31
+ * data for the current request using VineJS validators
32
+ */
33
+ validateUsing<Schema extends SchemaTypes, MetaData extends undefined | Record<string, any>>(validator: VineValidator<Schema, MetaData>, ...[options]: [undefined] extends MetaData ? [options?: RequestValidationOptions<MetaData> | undefined] : [options: RequestValidationOptions<MetaData>]): Promise<Infer<Schema>>;
34
+ }
@@ -0,0 +1,66 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ /**
10
+ * Request validator is used validate HTTP request data using
11
+ * VineJS validators. You may validate the request body,
12
+ * files, cookies, and headers.
13
+ */
14
+ export class RequestValidator {
15
+ #ctx;
16
+ constructor(ctx) {
17
+ this.#ctx = ctx;
18
+ }
19
+ /**
20
+ * The error reporter method returns the error reporter
21
+ * to use for reporting errors.
22
+ *
23
+ * You can use this function to pick a different error reporter
24
+ * for each HTTP request
25
+ */
26
+ static errorReporter;
27
+ /**
28
+ * The messages provider method returns the messages provider to use
29
+ * finding custom error messages
30
+ *
31
+ * You can use this function to pick a different messages provider for
32
+ * each HTTP request
33
+ */
34
+ static messagesProvider;
35
+ /**
36
+ * The validate method can be used to validate the request
37
+ * data for the current request using VineJS validators
38
+ */
39
+ validateUsing(validator, ...[options]) {
40
+ const validatorOptions = options || {};
41
+ /**
42
+ * Assign request specific error reporter
43
+ */
44
+ if (RequestValidator.errorReporter && !validatorOptions.errorReporter) {
45
+ const errorReporter = RequestValidator.errorReporter(this.#ctx);
46
+ validatorOptions.errorReporter = () => errorReporter;
47
+ }
48
+ /**
49
+ * Assign request specific messages provider
50
+ */
51
+ if (RequestValidator.messagesProvider && !validatorOptions.messagesProvider) {
52
+ validatorOptions.messagesProvider = RequestValidator.messagesProvider(this.#ctx);
53
+ }
54
+ /**
55
+ * Data to validate
56
+ */
57
+ const data = validatorOptions.data || {
58
+ ...this.#ctx.request.all(),
59
+ ...this.#ctx.request.allFiles(),
60
+ params: this.#ctx.request.params(),
61
+ headers: this.#ctx.request.headers(),
62
+ cookies: this.#ctx.request.cookiesList(),
63
+ };
64
+ return validator.validate(data, validatorOptions);
65
+ }
66
+ }
@@ -38,8 +38,22 @@ export default class AppServiceProvider {
38
38
  * Register the encryption service to the container
39
39
  */
40
40
  protected registerEncryption(): void;
41
+ /**
42
+ * Registers the HTTP server with the container as a singleton
43
+ */
44
+ protected registerServer(): void;
45
+ /**
46
+ * Registers router with the container as a singleton
47
+ */
48
+ protected registerRouter(): void;
49
+ /**
50
+ * Self construct bodyparser middleware class, since it needs
51
+ * config that cannot be resolved by the container
52
+ */
53
+ protected registerBodyParserMiddleware(): void;
41
54
  /**
42
55
  * Registers bindings
43
56
  */
44
57
  register(): void;
58
+ boot(): Promise<void>;
45
59
  }
@@ -8,7 +8,11 @@
8
8
  */
9
9
  import { Config } from '../modules/config.js';
10
10
  import { Logger } from '../modules/logger.js';
11
+ import { Application } from '../modules/app.js';
12
+ import { BaseEvent, Emitter } from '../modules/events.js';
11
13
  import { Encryption } from '../modules/encryption.js';
14
+ import { Router, Server } from '../modules/http/main.js';
15
+ import BodyParserMiddleware from '../modules/bodyparser/bodyparser_middleware.js';
12
16
  /**
13
17
  * The Application Service provider registers all the baseline
14
18
  * features required to run the framework.
@@ -40,7 +44,8 @@ export default class AppServiceProvider {
40
44
  * Registers the application to the container
41
45
  */
42
46
  registerApp() {
43
- this.app.container.singleton('app', () => this.app);
47
+ this.app.container.singleton(Application, () => this.app);
48
+ this.app.container.alias('app', Application);
44
49
  }
45
50
  /**
46
51
  * Registers the logger class to resolve the default logger
@@ -72,10 +77,10 @@ export default class AppServiceProvider {
72
77
  * Registers emitter service to the container
73
78
  */
74
79
  registerEmitter() {
75
- this.app.container.singleton('emitter', async () => {
76
- const { Emitter } = await import('../modules/events.js');
80
+ this.app.container.singleton(Emitter, async () => {
77
81
  return new Emitter(this.app);
78
82
  });
83
+ this.app.container.alias('emitter', Emitter);
79
84
  }
80
85
  /**
81
86
  * Register the encryption service to the container
@@ -87,6 +92,39 @@ export default class AppServiceProvider {
87
92
  });
88
93
  this.app.container.alias('encryption', Encryption);
89
94
  }
95
+ /**
96
+ * Registers the HTTP server with the container as a singleton
97
+ */
98
+ registerServer() {
99
+ this.app.container.singleton(Server, async (resolver) => {
100
+ const encryption = await resolver.make('encryption');
101
+ const emitter = await resolver.make('emitter');
102
+ const logger = await resolver.make('logger');
103
+ const config = this.app.config.get('app.http');
104
+ return new Server(this.app, encryption, emitter, logger, config);
105
+ });
106
+ this.app.container.alias('server', Server);
107
+ }
108
+ /**
109
+ * Registers router with the container as a singleton
110
+ */
111
+ registerRouter() {
112
+ this.app.container.singleton(Router, async (resolver) => {
113
+ const server = await resolver.make('server');
114
+ return server.getRouter();
115
+ });
116
+ this.app.container.alias('router', Router);
117
+ }
118
+ /**
119
+ * Self construct bodyparser middleware class, since it needs
120
+ * config that cannot be resolved by the container
121
+ */
122
+ registerBodyParserMiddleware() {
123
+ this.app.container.bind(BodyParserMiddleware, () => {
124
+ const config = this.app.config.get('bodyparser');
125
+ return new BodyParserMiddleware(config);
126
+ });
127
+ }
90
128
  /**
91
129
  * Registers bindings
92
130
  */
@@ -99,5 +137,11 @@ export default class AppServiceProvider {
99
137
  this.registerEmitter();
100
138
  this.registerEncryption();
101
139
  this.registerTestUtils();
140
+ this.registerServer();
141
+ this.registerRouter();
142
+ this.registerBodyParserMiddleware();
143
+ }
144
+ async boot() {
145
+ BaseEvent.useEmitter(await this.app.container.make('emitter'));
102
146
  }
103
147
  }
@@ -0,0 +1,31 @@
1
+ import { type Edge } from 'edge.js';
2
+ import type { ApplicationService } from '../src/types.js';
3
+ import { type Route } from '../modules/http/main.js';
4
+ declare module '@adonisjs/core/http' {
5
+ interface HttpContext {
6
+ /**
7
+ * Reference to the edge renderer to render templates
8
+ * during an HTTP request
9
+ */
10
+ view: ReturnType<Edge['createRenderer']>;
11
+ }
12
+ interface BriskRoute {
13
+ /**
14
+ * Render an edge template without defining an
15
+ * explicit route handler
16
+ */
17
+ render(template: string, data?: Record<string, any>): Route;
18
+ }
19
+ }
20
+ /**
21
+ * The Edge service provider configures Edge to work within
22
+ * an AdonisJS application environment
23
+ */
24
+ export default class EdgeServiceProvider {
25
+ protected app: ApplicationService;
26
+ constructor(app: ApplicationService);
27
+ /**
28
+ * Bridge AdonisJS and Edge
29
+ */
30
+ boot(): Promise<void>;
31
+ }
@@ -0,0 +1,70 @@
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 edge from 'edge.js';
10
+ import { BriskRoute, HttpContext } from '../modules/http/main.js';
11
+ /**
12
+ * The Edge service provider configures Edge to work within
13
+ * an AdonisJS application environment
14
+ */
15
+ export default class EdgeServiceProvider {
16
+ app;
17
+ constructor(app) {
18
+ this.app = app;
19
+ this.app.usingEdgeJS = true;
20
+ }
21
+ /**
22
+ * Bridge AdonisJS and Edge
23
+ */
24
+ async boot() {
25
+ const app = this.app;
26
+ const router = await this.app.container.make('router');
27
+ function edgeConfigResolver(key, defaultValue) {
28
+ return app.config.get(key, defaultValue);
29
+ }
30
+ edgeConfigResolver.has = function (key) {
31
+ return app.config.has(key);
32
+ };
33
+ /**
34
+ * Mount the default disk
35
+ */
36
+ edge.mount(app.viewsPath());
37
+ /**
38
+ * Cache templates in production
39
+ */
40
+ edge.configure({ cache: app.inProduction });
41
+ /**
42
+ * Define Edge global helpers
43
+ */
44
+ edge.global('route', function (...args) {
45
+ return router.makeUrl(...args);
46
+ });
47
+ edge.global('signedRoute', function (...args) {
48
+ return router.makeSignedUrl(...args);
49
+ });
50
+ edge.global('app', app);
51
+ edge.global('config', edgeConfigResolver);
52
+ /**
53
+ * Creating a isolated instance of edge renderer
54
+ */
55
+ HttpContext.getter('view', function () {
56
+ return edge.createRenderer().share({
57
+ request: this.request,
58
+ });
59
+ }, true);
60
+ /**
61
+ * Adding brisk route to render templates without an
62
+ * explicit handler
63
+ */
64
+ BriskRoute.macro('render', function (template, data) {
65
+ return this.setHandler(({ view }) => {
66
+ return view.render(template, data);
67
+ });
68
+ });
69
+ }
70
+ }
@@ -5,10 +5,6 @@ import type { ApplicationService } from '../src/types.js';
5
5
  export default class HashServiceProvider {
6
6
  protected app: ApplicationService;
7
7
  constructor(app: ApplicationService);
8
- /**
9
- * Registering bundled drivers with the driversList collection
10
- */
11
- protected registerHashDrivers(): void;
12
8
  /**
13
9
  * Registering the hash class to resolve an instance with the
14
10
  * default hasher.
@@ -6,7 +6,9 @@
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 { Argon, Bcrypt, Hash, Scrypt, driversList } from '../modules/hash/main.js';
9
+ import { RuntimeException } from '@poppinss/utils';
10
+ import { Hash } from '../modules/hash/main.js';
11
+ import { configProvider } from '../src/config_provider.js';
10
12
  /**
11
13
  * Registers the passwords hasher with the container
12
14
  */
@@ -15,14 +17,6 @@ export default class HashServiceProvider {
15
17
  constructor(app) {
16
18
  this.app = app;
17
19
  }
18
- /**
19
- * Registering bundled drivers with the driversList collection
20
- */
21
- registerHashDrivers() {
22
- driversList.extend('bcrypt', (config) => new Bcrypt(config));
23
- driversList.extend('scrypt', (config) => new Scrypt(config));
24
- driversList.extend('argon2', (config) => new Argon(config));
25
- }
26
20
  /**
27
21
  * Registering the hash class to resolve an instance with the
28
22
  * default hasher.
@@ -38,8 +32,15 @@ export default class HashServiceProvider {
38
32
  */
39
33
  registerHashManager() {
40
34
  this.app.container.singleton('hash', async () => {
35
+ const hashConfigProvider = this.app.config.get('hash');
36
+ /**
37
+ * Resolve config from the provider
38
+ */
39
+ const config = await configProvider.resolve(this.app, hashConfigProvider);
40
+ if (!config) {
41
+ throw new RuntimeException('Invalid "config/hash.ts" file. Make sure you are using the "defineConfig" method');
42
+ }
41
43
  const { HashManager } = await import('../modules/hash/main.js');
42
- const config = this.app.config.get('hash');
43
44
  return new HashManager(config);
44
45
  });
45
46
  }
@@ -47,7 +48,6 @@ export default class HashServiceProvider {
47
48
  * Registers bindings
48
49
  */
49
50
  register() {
50
- this.registerHashDrivers();
51
51
  this.registerHashManager();
52
52
  this.registerHash();
53
53
  }
@@ -6,6 +6,18 @@
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 { join } from 'node:path';
10
+ import { homedir } from 'node:os';
11
+ import { Repl } from '../modules/repl.js';
12
+ import { fsImportAll } from '@poppinss/utils';
13
+ /**
14
+ * Resolves a container binding and sets it on the REPL
15
+ * context
16
+ */
17
+ async function resolveBindingForRepl(app, repl, binding) {
18
+ repl.server.context[binding] = await app.container.make(binding);
19
+ repl.notify(`Loaded "${binding}" service. You can access it using the "${repl.colors.underline(binding)}" variable`);
20
+ }
9
21
  export default class ReplServiceProvider {
10
22
  app;
11
23
  constructor(app) {
@@ -15,19 +27,82 @@ export default class ReplServiceProvider {
15
27
  * Registers the REPL binding
16
28
  */
17
29
  register() {
18
- this.app.container.singleton('repl', async () => {
19
- const { Repl } = await import('../modules/repl.js');
20
- return new Repl();
30
+ this.app.container.singleton(Repl, async () => {
31
+ return new Repl({
32
+ historyFilePath: join(homedir(), '.adonisjs_v6_repl_history'),
33
+ });
21
34
  });
35
+ this.app.container.alias('repl', Repl);
22
36
  }
23
37
  /**
24
38
  * Registering REPL bindings during provider boot
25
39
  */
26
40
  async boot() {
27
- if (this.app.getEnvironment() === 'repl') {
28
- const repl = await this.app.container.make('repl');
29
- const { defineReplBindings } = await import('../src/bindings/repl.js');
30
- defineReplBindings(this.app, repl);
31
- }
41
+ this.app.container.resolving('repl', (repl) => {
42
+ repl.addMethod('importDefault', (_, modulePath) => {
43
+ return this.app.importDefault(modulePath);
44
+ }, {
45
+ description: 'Returns the default export for a module',
46
+ });
47
+ repl.addMethod('importAll', (_, dirPath) => {
48
+ return fsImportAll(this.app.makeURL(dirPath), {
49
+ ignoreMissingRoot: false,
50
+ });
51
+ }, {
52
+ description: 'Import all files from a directory and assign them to a variable',
53
+ });
54
+ repl.addMethod('make', (_, service, runtimeValues) => {
55
+ return this.app.container.make(service, runtimeValues);
56
+ }, {
57
+ description: 'Make class instance using "container.make" method',
58
+ });
59
+ repl.addMethod('loadApp', () => {
60
+ return resolveBindingForRepl(this.app, repl, 'app');
61
+ }, {
62
+ description: 'Load "app" service in the REPL context',
63
+ });
64
+ repl.addMethod('loadEncryption', () => {
65
+ return resolveBindingForRepl(this.app, repl, 'encryption');
66
+ }, {
67
+ description: 'Load "encryption" service in the REPL context',
68
+ });
69
+ repl.addMethod('loadHash', () => {
70
+ return resolveBindingForRepl(this.app, repl, 'hash');
71
+ }, {
72
+ description: 'Load "hash" service in the REPL context',
73
+ });
74
+ repl.addMethod('loadRouter', () => {
75
+ return resolveBindingForRepl(this.app, repl, 'router');
76
+ }, {
77
+ description: 'Load "router" service in the REPL context',
78
+ });
79
+ repl.addMethod('loadConfig', () => {
80
+ return resolveBindingForRepl(this.app, repl, 'config');
81
+ }, {
82
+ description: 'Load "config" service in the REPL context',
83
+ });
84
+ repl.addMethod('loadTestUtils', () => {
85
+ return resolveBindingForRepl(this.app, repl, 'testUtils');
86
+ }, {
87
+ description: 'Load "testUtils" service in the REPL context',
88
+ });
89
+ repl.addMethod('loadHelpers', async () => {
90
+ const { default: isModule } = await import('../src/helpers/is.js');
91
+ const { default: stringModule } = await import('../src/helpers/string.js');
92
+ const { base64, cuid, fsReadAll, slash, parseImports } = await import('../src/helpers/main.js');
93
+ repl.server.context.helpers = {
94
+ string: stringModule,
95
+ is: isModule,
96
+ base64,
97
+ cuid,
98
+ fsReadAll,
99
+ slash,
100
+ parseImports,
101
+ };
102
+ repl.notify(`Loaded "helpers" module. You can access it using the "${repl.colors.underline('helpers')}" variable`);
103
+ }, {
104
+ description: 'Load "helpers" module in the REPL context',
105
+ });
106
+ });
32
107
  }
33
108
  }
@@ -0,0 +1,43 @@
1
+ import { BaseLiteralType } from '@vinejs/vine';
2
+ import type { Validation, FieldContext, FieldOptions } from '@vinejs/vine/types';
3
+ import type { MultipartFile, FileValidationOptions } from '@adonisjs/bodyparser/types';
4
+ import type { ApplicationService } from '../src/types.js';
5
+ import { RequestValidator } from '../modules/http/main.js';
6
+ /**
7
+ * Validation options accepted by the "file" rule
8
+ */
9
+ export type FileRuleValidationOptions = Partial<FileValidationOptions> | ((field: FieldContext) => Partial<FileValidationOptions>);
10
+ /**
11
+ * Extend VineJS
12
+ */
13
+ declare module '@vinejs/vine' {
14
+ interface Vine {
15
+ file(options?: FileRuleValidationOptions): VineMultipartFile;
16
+ }
17
+ }
18
+ /**
19
+ * Extend HTTP request class
20
+ */
21
+ declare module '@adonisjs/core/http' {
22
+ interface Request extends RequestValidator {
23
+ }
24
+ }
25
+ /**
26
+ * Represents a multipart file uploaded via multipart/form-data HTTP
27
+ * request.
28
+ */
29
+ declare class VineMultipartFile extends BaseLiteralType<MultipartFile, MultipartFile> {
30
+ #private;
31
+ constructor(validationOptions?: FileRuleValidationOptions, options?: FieldOptions, validations?: Validation<any>[]);
32
+ clone(): this;
33
+ }
34
+ /**
35
+ * The Edge service provider configures Edge to work within
36
+ * an AdonisJS application environment
37
+ */
38
+ export default class VineJSServiceProvider {
39
+ protected app: ApplicationService;
40
+ constructor(app: ApplicationService);
41
+ boot(): void;
42
+ }
43
+ export {};