@adonisjs/core 7.0.0-next.10 → 7.0.0-next.11

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 (128) hide show
  1. package/build/commands/add.js +40 -110
  2. package/build/commands/build.js +51 -107
  3. package/build/commands/configure.js +82 -177
  4. package/build/commands/eject.js +17 -60
  5. package/build/commands/env/add.js +55 -134
  6. package/build/commands/generate_key.js +22 -66
  7. package/build/commands/inspect_rcfile.js +27 -55
  8. package/build/commands/list/routes.js +246 -116
  9. package/build/commands/make/command.js +15 -57
  10. package/build/commands/make/controller.js +43 -120
  11. package/build/commands/make/event.js +16 -62
  12. package/build/commands/make/exception.js +16 -62
  13. package/build/commands/make/listener.js +36 -93
  14. package/build/commands/make/middleware.js +41 -101
  15. package/build/commands/make/preload.js +47 -113
  16. package/build/commands/make/provider.js +47 -112
  17. package/build/commands/make/service.js +16 -55
  18. package/build/commands/make/test.js +47 -132
  19. package/build/commands/make/transformer.js +17 -64
  20. package/build/commands/make/validator.js +20 -80
  21. package/build/commands/make/view.js +15 -56
  22. package/build/commands/repl.js +17 -50
  23. package/build/commands/serve.js +80 -150
  24. package/build/commands/test.js +92 -202
  25. package/build/factories/app.js +2 -9
  26. package/build/factories/bodyparser.js +2 -9
  27. package/build/factories/core/ace.js +15 -46
  28. package/build/factories/core/ignitor.js +12 -180
  29. package/build/factories/core/main.js +22 -11
  30. package/build/factories/core/test_utils.js +19 -43
  31. package/build/factories/encryption.js +2 -9
  32. package/build/factories/events.js +2 -9
  33. package/build/factories/hash.js +2 -9
  34. package/build/factories/http.js +2 -9
  35. package/build/factories/logger.js +2 -9
  36. package/build/factories/stubs.js +28 -91
  37. package/build/index.js +13 -46
  38. package/build/modules/ace/codemods.js +222 -477
  39. package/build/modules/ace/main.js +2 -41
  40. package/build/modules/app.js +4 -26
  41. package/build/modules/bodyparser/bodyparser_middleware.js +2 -14
  42. package/build/modules/bodyparser/main.js +4 -9
  43. package/build/modules/config.js +4 -26
  44. package/build/modules/container.js +4 -9
  45. package/build/modules/dumper/main.js +6 -32
  46. package/build/modules/dumper/plugins/edge.js +2 -62
  47. package/build/modules/encryption.js +4 -26
  48. package/build/modules/env/editor.js +2 -9
  49. package/build/modules/env/main.js +2 -28
  50. package/build/modules/events.js +4 -9
  51. package/build/modules/hash/drivers/argon.js +2 -9
  52. package/build/modules/hash/drivers/bcrypt.js +2 -20
  53. package/build/modules/hash/drivers/scrypt.js +2 -9
  54. package/build/modules/hash/main.js +6 -28
  55. package/build/modules/hash/phc_formatter.js +2 -9
  56. package/build/modules/health.js +2 -9
  57. package/build/modules/http/main.js +4 -15
  58. package/build/modules/http/url_builder_client.js +2 -9
  59. package/build/modules/logger.d.ts +30 -0
  60. package/build/modules/logger.js +4 -9
  61. package/build/modules/repl.js +4 -9
  62. package/build/modules/transformers/main.js +4 -9
  63. package/build/providers/app_provider.js +147 -359
  64. package/build/providers/edge_provider.js +97 -165
  65. package/build/providers/hash_provider.js +29 -91
  66. package/build/providers/repl_provider.js +61 -152
  67. package/build/providers/vinejs_provider.d.ts +1 -1
  68. package/build/providers/vinejs_provider.js +20 -66
  69. package/build/services/ace.js +2 -17
  70. package/build/services/app.js +2 -21
  71. package/build/services/config.js +2 -13
  72. package/build/services/dumper.js +5 -21
  73. package/build/services/emitter.js +2 -14
  74. package/build/services/encryption.js +2 -14
  75. package/build/services/hash.js +2 -14
  76. package/build/services/logger.js +2 -14
  77. package/build/services/repl.js +2 -14
  78. package/build/services/router.js +2 -14
  79. package/build/services/server.js +2 -14
  80. package/build/services/test_utils.js +2 -17
  81. package/build/services/url_builder.js +5 -17
  82. package/build/src/exceptions.js +2 -49
  83. package/build/src/helpers/assert.js +2 -55
  84. package/build/src/helpers/http.js +2 -28
  85. package/build/src/helpers/is.js +3 -31
  86. package/build/src/helpers/main.js +5 -52
  87. package/build/src/helpers/string.js +2 -78
  88. package/build/src/helpers/types.js +26 -135
  89. package/build/src/helpers/verification_token.js +2 -120
  90. package/build/src/test_utils/main.js +5 -77
  91. package/build/src/types.js +0 -8
  92. package/build/src/vine.js +2 -105
  93. package/build/types/ace.js +2 -9
  94. package/build/types/app.js +2 -9
  95. package/build/types/bodyparser.js +2 -9
  96. package/build/types/common.js +2 -9
  97. package/build/types/container.js +2 -9
  98. package/build/types/encryption.js +2 -9
  99. package/build/types/events.js +2 -9
  100. package/build/types/hash.js +2 -9
  101. package/build/types/health.js +2 -9
  102. package/build/types/helpers.js +0 -8
  103. package/build/types/http.js +2 -9
  104. package/build/types/logger.js +2 -9
  105. package/build/types/repl.js +2 -9
  106. package/build/types/transformers.js +2 -9
  107. package/package.json +76 -19
  108. package/build/modules/ace/commands.js +0 -157
  109. package/build/modules/ace/create_kernel.js +0 -91
  110. package/build/modules/ace/kernel.js +0 -40
  111. package/build/modules/dumper/define_config.js +0 -36
  112. package/build/modules/dumper/dumper.js +0 -266
  113. package/build/modules/dumper/errors.js +0 -119
  114. package/build/modules/hash/define_config.js +0 -125
  115. package/build/modules/http/request_validator.js +0 -100
  116. package/build/src/assembler_hooks/index_entities.js +0 -112
  117. package/build/src/cli_formatters/routes_list.js +0 -397
  118. package/build/src/config_provider.js +0 -71
  119. package/build/src/debug.js +0 -25
  120. package/build/src/ignitor/ace.js +0 -102
  121. package/build/src/ignitor/http.js +0 -159
  122. package/build/src/ignitor/main.js +0 -124
  123. package/build/src/ignitor/test.js +0 -66
  124. package/build/src/test_utils/http.js +0 -82
  125. package/build/src/utils.js +0 -114
  126. package/build/stubs/main.js +0 -9
  127. package/build/toolkit/commands/index_commands.js +0 -30
  128. package/build/toolkit/main.js +0 -27
@@ -1,102 +0,0 @@
1
- /*
2
- * @adonisjs/core
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- /**
10
- * The Ace process is used to start the application in the
11
- * console environment. It manages the Ace kernel lifecycle
12
- * and command execution.
13
- *
14
- * @example
15
- * const ignitor = new Ignitor()
16
- * const aceProcess = new AceProcess(ignitor)
17
- *
18
- * await aceProcess
19
- * .configure((app) => {
20
- * // Configure ace kernel
21
- * })
22
- * .handle(['make:controller', 'UserController'])
23
- */
24
- export class AceProcess {
25
- /**
26
- * Ignitor reference
27
- */
28
- #ignitor;
29
- /**
30
- * The callback that configures the ace instance before the
31
- * handle method is called
32
- */
33
- #configureCallback = () => { };
34
- /**
35
- * Creates a new Ace process instance
36
- *
37
- * @param ignitor - The ignitor instance used to create and manage the app
38
- */
39
- constructor(ignitor) {
40
- this.#ignitor = ignitor;
41
- }
42
- /**
43
- * Register a callback that can be used to configure the ace
44
- * kernel before the handle method is called
45
- *
46
- * @param callback - Configuration callback function
47
- */
48
- configure(callback) {
49
- this.#configureCallback = callback;
50
- return this;
51
- }
52
- /**
53
- * Handles the command line arguments and executes
54
- * the matching ace commands
55
- *
56
- * @param argv - Command line arguments array
57
- */
58
- async handle(argv) {
59
- const app = this.#ignitor.createApp('console');
60
- await app.init();
61
- const { createAceKernel } = await import('../../modules/ace/create_kernel.js');
62
- const commandNameIndex = argv.findIndex((value) => !value.startsWith('-'));
63
- const commandName = argv[commandNameIndex];
64
- const kernel = createAceKernel(app, commandName);
65
- app.container.bindValue('ace', kernel);
66
- /**
67
- * Hook into kernel and start the app when the
68
- * command needs the app.
69
- *
70
- * Since multiple commands can be executed in a single process,
71
- * we add a check to only start the app only once.
72
- */
73
- kernel.loading(async (metaData) => {
74
- if (metaData.options.startApp && !app.isReady) {
75
- if (metaData.commandName === 'repl') {
76
- app.setEnvironment('repl');
77
- }
78
- await app.boot();
79
- await app.start(() => { });
80
- }
81
- });
82
- await this.#configureCallback(app);
83
- /**
84
- * Handle command line args
85
- */
86
- await kernel.handle(argv);
87
- /**
88
- * Terminate the app when the command does not want to
89
- * hold a long running process
90
- */
91
- const mainCommand = kernel.getMainCommand();
92
- if (!mainCommand || !mainCommand.staysAlive) {
93
- process.exitCode = kernel.exitCode;
94
- await app.terminate();
95
- }
96
- else {
97
- app.terminating(() => {
98
- process.exitCode = mainCommand.exitCode;
99
- });
100
- }
101
- }
102
- }
@@ -1,159 +0,0 @@
1
- /*
2
- * @adonisjs/core
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import { createServer, } from 'node:http';
10
- import debug from "../debug.js";
11
- /**
12
- * The HTTP server process is used to start the application in the
13
- * web environment. It creates and manages the Node.js HTTP server
14
- * instance, handling lifecycle events and monitoring.
15
- *
16
- * @example
17
- * const ignitor = new Ignitor()
18
- * const httpProcess = new HttpServerProcess(ignitor)
19
- * await httpProcess.start()
20
- */
21
- export class HttpServerProcess {
22
- /**
23
- * Ignitor reference
24
- */
25
- #ignitor;
26
- /**
27
- * Creates a new HTTP server process instance
28
- *
29
- * @param ignitor - The ignitor instance used to create and manage the app
30
- */
31
- constructor(ignitor) {
32
- this.#ignitor = ignitor;
33
- }
34
- /**
35
- * Calling this method closes the underlying HTTP server gracefully.
36
- *
37
- * @param nodeHttpServer - The Node.js HTTP or HTTPS server instance to close
38
- */
39
- #close(nodeHttpServer) {
40
- return new Promise((resolve) => {
41
- debug('closing http server process');
42
- nodeHttpServer.close(() => resolve());
43
- });
44
- }
45
- /**
46
- * Monitors the app and the server to close the HTTP server when
47
- * either one of them goes down. Sets up event listeners for graceful shutdown.
48
- *
49
- * @param nodeHttpServer - The Node.js HTTP or HTTPS server instance to monitor
50
- * @param app - The application service instance
51
- * @param logger - The logger service for error reporting
52
- */
53
- #monitorAppAndServer(nodeHttpServer, app, logger) {
54
- /**
55
- * Close the HTTP server when the application begins to
56
- * terminate
57
- */
58
- app.terminating(async () => {
59
- debug('terminating signal received');
60
- await this.#close(nodeHttpServer);
61
- });
62
- /**
63
- * Terminate the app when the HTTP server crashes
64
- */
65
- nodeHttpServer.once('error', (error) => {
66
- debug('http server crashed with error "%O"', error);
67
- logger.fatal({ err: error }, error.message);
68
- process.exitCode = 1;
69
- app.terminate();
70
- });
71
- }
72
- /**
73
- * Starts the HTTP server on a given host and port using environment variables.
74
- *
75
- * @param nodeHttpServer - The Node.js HTTP or HTTPS server instance to start listening
76
- */
77
- #listen(nodeHttpServer) {
78
- return new Promise((resolve, reject) => {
79
- const host = process.env.HOST || '0.0.0.0';
80
- const port = Number(process.env.PORT || '3333');
81
- nodeHttpServer.listen(port, host);
82
- nodeHttpServer.once('listening', () => {
83
- debug('listening to http server, host :%s, port: %s', host, port);
84
- resolve({ port, host });
85
- });
86
- nodeHttpServer.once('error', (error) => {
87
- reject(error);
88
- });
89
- });
90
- }
91
- /**
92
- * Notifies the app and the parent process that the HTTP server is ready.
93
- * Sends notifications through multiple channels: parent process, logger, and event emitter.
94
- *
95
- * @param app - The application service instance for parent process notification
96
- * @param logger - The logger service for console output
97
- * @param emitter - The event emitter for app-level notifications
98
- * @param payload - Server startup information including host, port, and duration
99
- */
100
- #notifyServerHasStarted(app, logger, emitter, payload) {
101
- /**
102
- * Notify parent process
103
- */
104
- app.notify({ isAdonisJS: true, environment: 'web', ...payload });
105
- /**
106
- * Visual notification
107
- */
108
- logger.info('started HTTP server on %s:%s', payload.host, payload.port);
109
- /**
110
- * Notify app
111
- */
112
- emitter.emit('http:server_ready', payload);
113
- }
114
- /**
115
- * Start the HTTP server by wiring up the application
116
- *
117
- * @param serverCallback - Optional callback to create custom HTTP server instance
118
- */
119
- async start(serverCallback) {
120
- const startTime = process.hrtime();
121
- /**
122
- * Method to create the HTTP server
123
- */
124
- const createHTTPServer = serverCallback || createServer;
125
- const app = this.#ignitor.createApp('web');
126
- await app.init();
127
- await app.boot();
128
- await app.start(async () => {
129
- /**
130
- * Resolve and boot the AdonisJS HTTP server
131
- */
132
- const server = await app.container.make('server');
133
- await server.boot();
134
- /**
135
- * Create Node.js HTTP server instance and share it with the
136
- * AdonisJS HTTP server
137
- */
138
- const httpServer = createHTTPServer(server.handle.bind(server));
139
- server.setNodeServer(httpServer);
140
- const logger = await app.container.make('logger');
141
- const emitter = await app.container.make('emitter');
142
- /**
143
- * Start the server by listening on a port of host
144
- */
145
- const payload = await this.#listen(httpServer);
146
- /**
147
- * Notify
148
- */
149
- this.#notifyServerHasStarted(app, logger, emitter, {
150
- ...payload,
151
- duration: process.hrtime(startTime),
152
- });
153
- /**
154
- * Monitor app and the server (after the server is listening)
155
- */
156
- this.#monitorAppAndServer(httpServer, app, logger);
157
- });
158
- }
159
- }
@@ -1,124 +0,0 @@
1
- /*
2
- * @adonisjs/core
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import debug from "../debug.js";
10
- import { AceProcess } from "./ace.js";
11
- import { TestRunnerProcess } from "./test.js";
12
- import { HttpServerProcess } from "./http.js";
13
- import { setApp } from "../../services/app.js";
14
- import { Application } from "../../modules/app.js";
15
- /**
16
- * Ignitor is used to instantiate an AdonisJS application in different
17
- * known environments. It serves as the main entry point for creating
18
- * and managing application processes.
19
- *
20
- * @example
21
- * const ignitor = new Ignitor(new URL(import.meta.url))
22
- *
23
- * // For HTTP server
24
- * await ignitor.httpServer().start()
25
- *
26
- * // For CLI commands
27
- * await ignitor.ace().handle(process.argv.slice(2))
28
- *
29
- * // For tests
30
- * await ignitor.testRunner().run(() => {})
31
- */
32
- export class Ignitor {
33
- /**
34
- * Ignitor options
35
- */
36
- #options;
37
- /**
38
- * Application root URL
39
- */
40
- #appRoot;
41
- /**
42
- * Reference to the application instance created using
43
- * the "createApp" method.
44
- *
45
- * We store the output of the last call made to "createApp" method
46
- * and assume that in one process only one entrypoint will
47
- * call this method.
48
- */
49
- #app;
50
- /**
51
- * Reference to the created application
52
- */
53
- #tapCallbacks = new Set();
54
- /**
55
- * Creates a new Ignitor instance
56
- *
57
- * @param appRoot - The root URL of the application
58
- * @param options - Configuration options for the ignitor
59
- */
60
- constructor(appRoot, options = {}) {
61
- this.#appRoot = appRoot;
62
- this.#options = options;
63
- }
64
- /**
65
- * Runs all the tap callbacks
66
- */
67
- #runTapCallbacks(app) {
68
- this.#tapCallbacks.forEach((tapCallback) => tapCallback(app));
69
- }
70
- /**
71
- * Get access to the application instance created
72
- * by either the http server process or the ace
73
- * process
74
- */
75
- getApp() {
76
- return this.#app;
77
- }
78
- /**
79
- * Create an instance of AdonisJS application
80
- *
81
- * @param environment - The environment in which to create the app (web, console, test, repl)
82
- */
83
- createApp(environment) {
84
- debug('creating application instance');
85
- this.#app = new Application(this.#appRoot, { environment, importer: this.#options.importer });
86
- setApp(this.#app);
87
- this.#runTapCallbacks(this.#app);
88
- return this.#app;
89
- }
90
- /**
91
- * Tap to access the application class instance.
92
- *
93
- * @param callback - Callback function to execute when app is created
94
- */
95
- tap(callback) {
96
- this.#tapCallbacks.add(callback);
97
- return this;
98
- }
99
- /**
100
- * Get instance of the HTTPServerProcess
101
- */
102
- httpServer() {
103
- return new HttpServerProcess(this);
104
- }
105
- /**
106
- * Get an instance of the AceProcess class
107
- */
108
- ace() {
109
- return new AceProcess(this);
110
- }
111
- /**
112
- * Get an instance of the TestRunnerProcess class
113
- */
114
- testRunner() {
115
- return new TestRunnerProcess(this);
116
- }
117
- /**
118
- * Terminates the app by calling the "app.terminate"
119
- * method
120
- */
121
- async terminate() {
122
- await this.#app?.terminate();
123
- }
124
- }
@@ -1,66 +0,0 @@
1
- /*
2
- * @adonisjs/core
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- /**
10
- * The Test runner process is used to start the tests runner process.
11
- * It provides lifecycle hooks for configuring the test environment
12
- * and running tests within the AdonisJS application context.
13
- *
14
- * @example
15
- * const ignitor = new Ignitor()
16
- * const testProcess = new TestRunnerProcess(ignitor)
17
- *
18
- * await testProcess
19
- * .configure((app) => {
20
- * // Configure test environment
21
- * })
22
- * .run(async (app) => {
23
- * // Run your tests
24
- * })
25
- */
26
- export class TestRunnerProcess {
27
- /**
28
- * Ignitor reference
29
- */
30
- #ignitor;
31
- /**
32
- * The callback that configures the tests runner. This callback
33
- * runs at the time of starting the app.
34
- */
35
- #configureCallback = () => { };
36
- /**
37
- * Creates a new test runner process instance
38
- *
39
- * @param ignitor - The ignitor instance used to create and manage the app
40
- */
41
- constructor(ignitor) {
42
- this.#ignitor = ignitor;
43
- }
44
- /**
45
- * Register a callback that runs after booting the AdonisJS app
46
- * and just before the provider's ready hook
47
- *
48
- * @param callback - Configuration callback function
49
- */
50
- configure(callback) {
51
- this.#configureCallback = callback;
52
- return this;
53
- }
54
- /**
55
- * Runs a callback after starting the app
56
- *
57
- * @param callback - Test execution callback function
58
- */
59
- async run(callback) {
60
- const app = this.#ignitor.createApp('test');
61
- await app.init();
62
- await app.boot();
63
- await app.start(this.#configureCallback);
64
- await callback(app);
65
- }
66
- }
@@ -1,82 +0,0 @@
1
- /*
2
- * @adonisjs/core
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import debug from "../debug.js";
10
- import { createServer, } from 'node:http';
11
- /**
12
- * Http server utils are used to start the AdonisJS HTTP server
13
- * during testing. It provides methods to start and stop the server
14
- * for integration testing.
15
- *
16
- * @example
17
- * const testUtils = new TestUtils(app)
18
- * const httpUtils = testUtils.httpServer()
19
- *
20
- * const closeServer = await httpUtils.start()
21
- * // Make HTTP requests to test endpoints
22
- * await closeServer() // Clean up
23
- */
24
- export class HttpServerUtils {
25
- /**
26
- * Reference to the test utils instance
27
- */
28
- #utils;
29
- /**
30
- * Creates a new HttpServerUtils instance
31
- *
32
- * @param utils - The test utils instance
33
- */
34
- constructor(utils) {
35
- this.#utils = utils;
36
- }
37
- /**
38
- * Starts the http server a given host and port
39
- *
40
- * @param nodeHttpServer - The Node.js HTTP server instance
41
- */
42
- #listen(nodeHttpServer) {
43
- return new Promise((resolve, reject) => {
44
- const host = process.env.HOST || '0.0.0.0';
45
- const port = Number(process.env.PORT || '3333');
46
- nodeHttpServer.listen(port, host);
47
- nodeHttpServer.once('listening', () => {
48
- debug('listening to utils http server, host :%s, port: %s', host, port);
49
- resolve({ port, host });
50
- });
51
- nodeHttpServer.once('error', (error) => {
52
- reject(error);
53
- });
54
- });
55
- }
56
- /**
57
- * Testing hook to start the HTTP server to listen for new request.
58
- * The return value is a function to close the HTTP server.
59
- *
60
- * @param serverCallback - Optional callback to create custom HTTP server instance
61
- */
62
- async start(serverCallback) {
63
- const createHTTPServer = serverCallback || createServer;
64
- const server = await this.#utils.app.container.make('server');
65
- await server.boot();
66
- const httpServer = createHTTPServer(server.handle.bind(server));
67
- server.setNodeServer(httpServer);
68
- await this.#listen(httpServer);
69
- return () => {
70
- return new Promise((resolve, reject) => {
71
- httpServer.close((error) => {
72
- if (error) {
73
- reject(error);
74
- }
75
- else {
76
- resolve();
77
- }
78
- });
79
- });
80
- };
81
- }
82
- }
@@ -1,114 +0,0 @@
1
- /*
2
- * @adonisjs/core
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- /**
10
- * Imports the AdonisJS assembler package optionally. This function attempts
11
- * to import the assembler and returns undefined if it's not available,
12
- * making it safe to use in environments where the assembler might not be installed.
13
- *
14
- * @param app - The application service instance used for importing the assembler
15
- *
16
- * @example
17
- * const assembler = await importAssembler(app)
18
- * if (assembler) {
19
- * // Use assembler functionality
20
- * const generator = new assembler.IndexGenerator()
21
- * }
22
- */
23
- export async function importAssembler(app) {
24
- try {
25
- return await app.import('@adonisjs/assembler');
26
- }
27
- catch { }
28
- }
29
- /**
30
- * Imports the TypeScript compiler package optionally. This function attempts
31
- * to import TypeScript and returns undefined if it's not available,
32
- * making it safe to use in environments where TypeScript might not be installed.
33
- *
34
- * @param app - The application service instance used for importing TypeScript
35
- *
36
- * @example
37
- * const ts = await importTypeScript(app)
38
- * if (ts) {
39
- * // Use TypeScript compiler API
40
- * const program = ts.createProgram(['file.ts'], {})
41
- * const sourceFile = program.getSourceFile('file.ts')
42
- * }
43
- */
44
- export async function importTypeScript(app) {
45
- try {
46
- return await app.importDefault('typescript');
47
- }
48
- catch { }
49
- }
50
- /**
51
- * Outputs transformer data objects by generating TypeScript type definitions
52
- * for all transformers in the provided file tree. This function creates
53
- * InferData types for each transformer and organizes them in namespaces.
54
- *
55
- * @param transformersList - A recursive file tree containing transformer file paths
56
- * @param buffer - The file buffer to write the generated types to
57
- *
58
- * @example
59
- * const transformersList = {
60
- * User: '#app/transformers/user_transformer',
61
- * Auth: {
62
- * Login: '#app/transformers/auth/login_transformer'
63
- * }
64
- * }
65
- * await outputTransformerDataObjects(transformersList, buffer)
66
- * // Generates:
67
- * // export namespace Data {
68
- * // export type User = InferData<UserTransformer>
69
- * // export namespace Auth {
70
- * // export type Login = InferData<AuthLoginTransformer>
71
- * // }
72
- * // }
73
- */
74
- export async function outputTransformerDataObjects(transformersList, buffer, withSharedProps) {
75
- const importsBuffer = buffer.create();
76
- importsBuffer.write(`import type { InferData, InferVariants } from '@adonisjs/core/types/transformers'`);
77
- if (withSharedProps) {
78
- importsBuffer.write(`import type { InferSharedProps } from '@adonisjs/inertia/types'`);
79
- }
80
- buffer.writeLine(importsBuffer);
81
- buffer.write('export namespace Data {').indent();
82
- /**
83
- * Recursively generates namespace tree structure for transformers.
84
- * Creates nested namespaces for directory structures and type exports
85
- * for individual transformer files.
86
- *
87
- * @param input - The current level of the file tree to process
88
- * @param parents - Array of parent namespace names for import naming
89
- */
90
- function generateNamespaceTree(input, parents) {
91
- Object.keys(input).forEach((key) => {
92
- const value = input[key];
93
- if (typeof value === 'string') {
94
- const importName = `${parents.join()}${key}Transformer`;
95
- importsBuffer.write(`import type ${importName} from '${value}'`);
96
- buffer.write(`export type ${key} = InferData<${importName}>`);
97
- buffer.write(`export namespace ${key} {`).indent();
98
- buffer.write(`export type Variants = InferVariants<${importName}>`);
99
- buffer.dedent().write('}');
100
- }
101
- else {
102
- buffer.write(`export namespace ${key} {`).indent();
103
- generateNamespaceTree(value, [...parents, key]);
104
- buffer.dedent().write(`}`);
105
- }
106
- });
107
- }
108
- generateNamespaceTree(transformersList, []);
109
- if (withSharedProps) {
110
- importsBuffer.write(`import type InertiaMiddleware from '#middleware/inertia_middleware'`);
111
- buffer.write('export type SharedProps = InferSharedProps<InertiaMiddleware>');
112
- }
113
- buffer.dedent().write('}');
114
- }
@@ -1,9 +0,0 @@
1
- /*
2
- * @adonisjs/core
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- export const stubsRoot = import.meta.dirname;
@@ -1,30 +0,0 @@
1
- /*
2
- * @adonisjs/core
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
10
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
12
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
13
- return c > 3 && r && Object.defineProperty(target, key, r), r;
14
- };
15
- import { join } from 'node:path';
16
- import { args, BaseCommand, IndexGenerator } from '@adonisjs/ace';
17
- /**
18
- * Generates index of commands with a loader. Must be called against
19
- * the TypeScript compiled output.
20
- */
21
- export default class IndexCommand extends BaseCommand {
22
- static commandName = 'index';
23
- static description = 'Create an index of commands along with a lazy loader';
24
- async run() {
25
- await new IndexGenerator(join(process.cwd(), this.commandsDir)).generate();
26
- }
27
- }
28
- __decorate([
29
- args.string({ description: 'Relative path from cwd to the commands directory' })
30
- ], IndexCommand.prototype, "commandsDir", void 0);