@adonisjs/core 6.19.0 → 7.0.0-next.1

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 (177) hide show
  1. package/build/commands/add.d.ts +36 -5
  2. package/build/commands/add.js +24 -60
  3. package/build/commands/build.d.ts +23 -3
  4. package/build/commands/build.js +22 -36
  5. package/build/commands/commands.json +1 -1
  6. package/build/commands/configure.d.ts +35 -12
  7. package/build/commands/configure.js +39 -12
  8. package/build/commands/eject.d.ts +28 -3
  9. package/build/commands/eject.js +24 -5
  10. package/build/commands/env/add.d.ts +41 -4
  11. package/build/commands/env/add.js +32 -5
  12. package/build/commands/generate_key.d.ts +20 -1
  13. package/build/commands/generate_key.js +14 -1
  14. package/build/commands/inspect_rcfile.d.ts +20 -2
  15. package/build/commands/inspect_rcfile.js +20 -2
  16. package/build/commands/list/routes.d.ts +33 -11
  17. package/build/commands/list/routes.js +28 -5
  18. package/build/commands/make/command.d.ts +26 -3
  19. package/build/commands/make/command.js +25 -5
  20. package/build/commands/make/controller.d.ts +35 -2
  21. package/build/commands/make/controller.js +20 -2
  22. package/build/commands/make/event.d.ts +30 -4
  23. package/build/commands/make/event.js +27 -4
  24. package/build/commands/make/exception.d.ts +30 -4
  25. package/build/commands/make/exception.js +27 -4
  26. package/build/commands/make/listener.d.ts +38 -5
  27. package/build/commands/make/listener.js +32 -5
  28. package/build/commands/make/middleware.d.ts +25 -2
  29. package/build/commands/make/middleware.js +21 -4
  30. package/build/commands/make/preload.d.ts +31 -4
  31. package/build/commands/make/preload.js +28 -8
  32. package/build/commands/make/provider.d.ts +32 -3
  33. package/build/commands/make/provider.js +29 -7
  34. package/build/commands/make/service.d.ts +21 -2
  35. package/build/commands/make/service.js +18 -2
  36. package/build/commands/make/test.d.ts +27 -4
  37. package/build/commands/make/test.js +36 -8
  38. package/build/commands/make/transformer.d.ts +43 -0
  39. package/build/commands/make/transformer.js +65 -0
  40. package/build/commands/make/validator.d.ts +36 -5
  41. package/build/commands/make/validator.js +30 -5
  42. package/build/commands/make/view.d.ts +26 -3
  43. package/build/commands/make/view.js +24 -4
  44. package/build/commands/repl.d.ts +24 -4
  45. package/build/commands/repl.js +23 -3
  46. package/build/commands/serve.d.ts +38 -4
  47. package/build/commands/serve.js +34 -43
  48. package/build/commands/test.d.ts +68 -7
  49. package/build/commands/test.js +39 -37
  50. package/build/factories/core/ace.d.ts +31 -4
  51. package/build/factories/core/ace.js +20 -4
  52. package/build/factories/core/ignitor.d.ts +80 -9
  53. package/build/factories/core/ignitor.js +84 -13
  54. package/build/factories/core/main.d.ts +3 -3
  55. package/build/factories/core/main.js +3 -3
  56. package/build/factories/core/test_utils.d.ts +32 -4
  57. package/build/factories/core/test_utils.js +21 -4
  58. package/build/factories/stubs.d.ts +54 -5
  59. package/build/factories/stubs.js +55 -6
  60. package/build/index.d.ts +5 -4
  61. package/build/index.js +13 -9
  62. package/build/modules/ace/codemods.d.ts +71 -11
  63. package/build/modules/ace/codemods.js +90 -22
  64. package/build/modules/ace/commands.d.ts +48 -13
  65. package/build/modules/ace/commands.js +45 -10
  66. package/build/modules/ace/create_kernel.d.ts +19 -8
  67. package/build/modules/ace/create_kernel.js +19 -8
  68. package/build/modules/ace/kernel.d.ts +18 -4
  69. package/build/modules/ace/kernel.js +17 -3
  70. package/build/modules/ace/main.d.ts +3 -3
  71. package/build/modules/ace/main.js +3 -3
  72. package/build/modules/dumper/define_config.d.ts +25 -4
  73. package/build/modules/dumper/define_config.js +23 -2
  74. package/build/modules/dumper/dumper.d.ts +82 -12
  75. package/build/modules/dumper/dumper.js +82 -12
  76. package/build/modules/dumper/errors.d.ts +31 -10
  77. package/build/modules/dumper/errors.js +28 -7
  78. package/build/modules/dumper/main.d.ts +3 -3
  79. package/build/modules/dumper/main.js +3 -3
  80. package/build/modules/dumper/plugins/edge.d.ts +1 -1
  81. package/build/modules/hash/define_config.d.ts +53 -8
  82. package/build/modules/hash/define_config.js +51 -6
  83. package/build/modules/hash/main.d.ts +1 -1
  84. package/build/modules/hash/main.js +1 -1
  85. package/build/modules/http/main.d.ts +1 -1
  86. package/build/modules/http/main.js +1 -1
  87. package/build/modules/http/request_validator.d.ts +36 -9
  88. package/build/modules/http/request_validator.js +32 -5
  89. package/build/modules/transformers/main.d.ts +1 -0
  90. package/build/modules/transformers/main.js +9 -0
  91. package/build/providers/app_provider.d.ts +173 -1
  92. package/build/providers/app_provider.js +204 -8
  93. package/build/providers/edge_provider.d.ts +31 -2
  94. package/build/providers/edge_provider.js +31 -2
  95. package/build/providers/hash_provider.d.ts +38 -1
  96. package/build/providers/hash_provider.js +40 -3
  97. package/build/providers/repl_provider.d.ts +40 -1
  98. package/build/providers/repl_provider.js +52 -2
  99. package/build/providers/vinejs_provider.d.ts +32 -5
  100. package/build/providers/vinejs_provider.js +31 -4
  101. package/build/services/ace.d.ts +1 -1
  102. package/build/services/ace.js +1 -1
  103. package/build/services/app.d.ts +1 -1
  104. package/build/services/config.d.ts +1 -1
  105. package/build/services/config.js +1 -1
  106. package/build/services/dumper.js +1 -1
  107. package/build/services/emitter.d.ts +1 -1
  108. package/build/services/emitter.js +1 -1
  109. package/build/services/encryption.d.ts +1 -1
  110. package/build/services/encryption.js +1 -1
  111. package/build/services/hash.d.ts +1 -1
  112. package/build/services/hash.js +1 -1
  113. package/build/services/logger.d.ts +1 -1
  114. package/build/services/logger.js +1 -1
  115. package/build/services/repl.d.ts +1 -1
  116. package/build/services/repl.js +1 -1
  117. package/build/services/router.d.ts +1 -1
  118. package/build/services/router.js +1 -1
  119. package/build/services/server.d.ts +1 -1
  120. package/build/services/server.js +1 -1
  121. package/build/services/test_utils.d.ts +1 -1
  122. package/build/services/test_utils.js +1 -1
  123. package/build/services/url_builder.d.ts +4 -0
  124. package/build/services/url_builder.js +21 -0
  125. package/build/src/assembler_hooks/index_entities.d.ts +37 -0
  126. package/build/src/assembler_hooks/index_entities.js +106 -0
  127. package/build/src/cli_formatters/routes_list.d.ts +24 -12
  128. package/build/src/cli_formatters/routes_list.js +43 -46
  129. package/build/src/config_provider.d.ts +48 -3
  130. package/build/src/config_provider.js +47 -2
  131. package/build/src/debug.d.ts +15 -0
  132. package/build/src/debug.js +15 -0
  133. package/build/src/exceptions.d.ts +41 -1
  134. package/build/src/exceptions.js +41 -1
  135. package/build/src/helpers/assert.d.ts +47 -1
  136. package/build/src/helpers/assert.js +47 -1
  137. package/build/src/helpers/is.d.ts +21 -0
  138. package/build/src/helpers/is.js +21 -0
  139. package/build/src/helpers/main.d.ts +48 -5
  140. package/build/src/helpers/main.js +48 -5
  141. package/build/src/helpers/string.d.ts +89 -9
  142. package/build/src/helpers/string.js +21 -2
  143. package/build/src/helpers/types.d.ts +97 -2
  144. package/build/src/helpers/types.js +96 -2
  145. package/build/src/helpers/verification_token.d.ts +22 -1
  146. package/build/src/helpers/verification_token.js +24 -2
  147. package/build/src/ignitor/ace.d.ts +23 -3
  148. package/build/src/ignitor/ace.js +21 -1
  149. package/build/src/ignitor/http.d.ts +16 -3
  150. package/build/src/ignitor/http.js +16 -3
  151. package/build/src/ignitor/main.d.ts +29 -6
  152. package/build/src/ignitor/main.js +30 -7
  153. package/build/src/ignitor/test.d.ts +26 -3
  154. package/build/src/ignitor/test.js +24 -1
  155. package/build/src/test_utils/http.d.ts +19 -3
  156. package/build/src/test_utils/http.js +24 -3
  157. package/build/src/test_utils/main.d.ts +22 -4
  158. package/build/src/test_utils/main.js +21 -3
  159. package/build/src/types.d.ts +283 -26
  160. package/build/src/utils.d.ts +60 -0
  161. package/build/src/utils.js +104 -0
  162. package/build/src/vine.d.ts +24 -1
  163. package/build/src/vine.js +27 -1
  164. package/build/stubs/main.js +1 -2
  165. package/build/stubs/make/transformer/main.stub +18 -0
  166. package/build/toolkit/main.js +1 -1
  167. package/build/types/common.d.ts +1 -0
  168. package/build/types/common.js +9 -0
  169. package/build/types/helpers.d.ts +2 -1
  170. package/build/types/http.d.ts +1 -0
  171. package/build/types/transformers.d.ts +1 -0
  172. package/build/types/transformers.js +9 -0
  173. package/package.json +55 -52
  174. package/build/src/helpers/parse_binding_reference.d.ts +0 -45
  175. package/build/src/helpers/parse_binding_reference.js +0 -83
  176. package/build/src/internal_helpers.d.ts +0 -15
  177. package/build/src/internal_helpers.js +0 -63
@@ -9,14 +9,25 @@
9
9
  import { Socket } from 'node:net';
10
10
  import Macroable from '@poppinss/macroable';
11
11
  import { IncomingMessage, ServerResponse } from 'node:http';
12
- import { HttpServerUtils } from './http.js';
13
- import { CookieClient } from '../../modules/http/main.js';
12
+ import { HttpServerUtils } from "./http.js";
13
+ import { CookieClient } from "../../modules/http/main.js";
14
14
  /**
15
15
  * Test utils has a collection of helper methods to make testing
16
- * experience great for AdonisJS applications
16
+ * experience great for AdonisJS applications. It provides utilities
17
+ * for HTTP testing, context creation, and cookie handling.
18
+ *
19
+ * @example
20
+ * const testUtils = new TestUtils(app)
21
+ * await testUtils.boot()
22
+ *
23
+ * const ctx = await testUtils.createHttpContext()
24
+ * const httpUtils = testUtils.httpServer()
17
25
  */
18
26
  export class TestUtils extends Macroable {
19
27
  app;
28
+ /**
29
+ * Flag to track if test utils have been booted
30
+ */
20
31
  #booted = false;
21
32
  /**
22
33
  * Check if utils have been booted
@@ -24,6 +35,11 @@ export class TestUtils extends Macroable {
24
35
  get isBooted() {
25
36
  return this.#booted;
26
37
  }
38
+ /**
39
+ * Creates a new TestUtils instance
40
+ *
41
+ * @param app - The application service instance
42
+ */
27
43
  constructor(app) {
28
44
  super();
29
45
  this.app = app;
@@ -47,6 +63,8 @@ export class TestUtils extends Macroable {
47
63
  }
48
64
  /**
49
65
  * Create an instance of HTTP context for testing
66
+ *
67
+ * @param options - Options for creating HTTP context with custom req/res objects
50
68
  */
51
69
  async createHttpContext(options = {}) {
52
70
  const req = options.req || new IncomingMessage(new Socket());
@@ -1,40 +1,72 @@
1
- import type { Repl } from '../modules/repl.js';
2
- import type { Importer } from '../types/app.js';
3
- import type { Emitter } from '../modules/events.js';
4
- import type { Kernel } from '../modules/ace/main.js';
5
- import type { Application } from '../modules/app.js';
6
- import type { TestUtils } from './test_utils/main.js';
7
- import type { HttpServerEvents } from '../types/http.js';
8
- import type { Dumper } from '../modules/dumper/dumper.js';
9
- import type { LoggerManager } from '../modules/logger.js';
10
- import type { HashManager } from '../modules/hash/main.js';
11
- import type { Encryption } from '../modules/encryption.js';
12
- import type { ManagerDriverFactory } from '../types/hash.js';
13
- import type { Router, Server } from '../modules/http/main.js';
14
- import type { ContainerResolveEventData } from '../types/container.js';
15
- import type { LoggerConfig, LoggerManagerConfig } from '../types/logger.js';
1
+ import type { Repl } from '../modules/repl.ts';
2
+ import type { Importer } from '../types/app.ts';
3
+ import type { Emitter } from '../modules/events.ts';
4
+ import type { Kernel } from '../modules/ace/main.ts';
5
+ import type { Application } from '../modules/app.ts';
6
+ import type { TestUtils } from './test_utils/main.ts';
7
+ import type { HttpServerEvents, LookupList, RoutesList, SignedURLOptions, UrlFor, URLOptions } from '../types/http.ts';
8
+ import type { Dumper } from '../modules/dumper/dumper.ts';
9
+ import type { LoggerManager } from '../modules/logger.ts';
10
+ import type { HashManager } from '../modules/hash/main.ts';
11
+ import type { Encryption } from '../modules/encryption.ts';
12
+ import type { ManagerDriverFactory } from '../types/hash.ts';
13
+ import type { Router, Server } from '../modules/http/main.ts';
14
+ import type { ContainerResolveEventData } from '../types/container.ts';
15
+ import type { LoggerConfig, LoggerManagerConfig } from '../types/logger.ts';
16
16
  /**
17
17
  * A config provider waits for the application to get booted
18
18
  * and then resolves the config. It receives an instance
19
19
  * of the application service.
20
+ *
21
+ * @template T - The type of configuration object that the provider resolves
22
+ *
23
+ * @example
24
+ * const databaseProvider: ConfigProvider<DatabaseConfig> = {
25
+ * type: 'provider',
26
+ * resolver: async (app) => {
27
+ * return {
28
+ * connection: app.env.get('DB_CONNECTION', 'sqlite'),
29
+ * host: app.env.get('DB_HOST', 'localhost')
30
+ * }
31
+ * }
32
+ * }
20
33
  */
21
34
  export type ConfigProvider<T> = {
35
+ /** Identifies this as a config provider */
22
36
  type: 'provider';
37
+ /** Function that resolves the configuration using the application service */
23
38
  resolver: (app: ApplicationService) => Promise<T>;
24
39
  };
25
40
  /**
26
- * Options accepted by ignitor
41
+ * Options accepted by ignitor for configuring the application bootstrap process.
42
+ *
43
+ * @example
44
+ * const options: IgnitorOptions = {
45
+ * importer: (filePath) => import(filePath)
46
+ * }
27
47
  */
28
48
  export type IgnitorOptions = {
49
+ /** Optional custom importer function for loading modules */
29
50
  importer?: Importer;
30
51
  };
31
52
  /**
32
53
  * A list of known events. The interface must be extended in
33
54
  * user land code or packages to register events and their
34
55
  * types.
56
+ *
57
+ * @example
58
+ * // Extending EventsList in user code
59
+ * declare module '@adonisjs/core' {
60
+ * interface EventsList {
61
+ * 'user:created': { user: User }
62
+ * 'order:placed': { orderId: string, amount: number }
63
+ * }
64
+ * }
35
65
  */
36
66
  export interface EventsList extends HttpServerEvents {
67
+ /** Event fired when a container binding is resolved */
37
68
  'container_binding:resolved': ContainerResolveEventData<ContainerBindings>;
69
+ /** Event fired when the HTTP server is ready and listening */
38
70
  'http:server_ready': {
39
71
  port: number;
40
72
  host: string;
@@ -43,16 +75,47 @@ export interface EventsList extends HttpServerEvents {
43
75
  }
44
76
  /**
45
77
  * The loggers list inferred from the user application
46
- * config
78
+ * config. This interface should be extended in user code
79
+ * to register custom loggers.
80
+ *
81
+ * @example
82
+ * // Extending LoggersList in user code
83
+ * declare module '@adonisjs/core' {
84
+ * interface LoggersList {
85
+ * default: LoggerConfig
86
+ * file: LoggerConfig
87
+ * }
88
+ * }
47
89
  */
48
90
  export interface LoggersList {
49
91
  }
92
+ /**
93
+ * Utility type to infer logger configurations from a LoggerManagerConfig.
94
+ *
95
+ * @template T - The logger manager configuration type
96
+ */
50
97
  export type InferLoggers<T extends LoggerManagerConfig<any>> = T['loggers'];
51
98
  /**
52
- * A list of known hashers inferred from the user config
99
+ * A list of known hashers inferred from the user config.
100
+ * This interface should be extended in user code to register
101
+ * custom hashers.
102
+ *
103
+ * @example
104
+ * // Extending HashersList in user code
105
+ * declare module '@adonisjs/core' {
106
+ * interface HashersList {
107
+ * scrypt: ManagerDriverFactory
108
+ * argon: ManagerDriverFactory
109
+ * }
110
+ * }
53
111
  */
54
112
  export interface HashersList {
55
113
  }
114
+ /**
115
+ * Utility type to infer hasher configurations from a config provider.
116
+ *
117
+ * @template T - The config provider type that resolves to an object with a 'list' property
118
+ */
56
119
  export type InferHashers<T extends ConfigProvider<{
57
120
  list: Record<string, ManagerDriverFactory>;
58
121
  }>> = Awaited<ReturnType<T['resolver']>>['list'];
@@ -67,58 +130,252 @@ export type InferHashers<T extends ConfigProvider<{
67
130
  */
68
131
  /**
69
132
  * Application service is a singleton resolved from
70
- * the container
133
+ * the container. It provides access to the core application
134
+ * instance with all registered bindings.
135
+ *
136
+ * @example
137
+ * // Accessing application service in a controller
138
+ * export default class HomeController {
139
+ * async index({ app }: { app: ApplicationService }) {
140
+ * const version = app.version
141
+ * const env = app.env.get('NODE_ENV')
142
+ * }
143
+ * }
71
144
  */
72
145
  export interface ApplicationService extends Application<ContainerBindings extends Record<any, any> ? ContainerBindings : never> {
73
146
  }
74
147
  /**
75
148
  * Logger service is a singleton logger instance registered
76
- * to the container.
149
+ * to the container. It provides access to configured loggers.
150
+ *
151
+ * @example
152
+ * // Using logger service in a controller
153
+ * export default class UserController {
154
+ * async store({ logger }: { logger: LoggerService }) {
155
+ * logger.info('Creating new user')
156
+ * logger.use('file').error('Failed to create user')
157
+ * }
158
+ * }
77
159
  */
78
160
  export interface LoggerService extends LoggerManager<LoggersList extends Record<string, LoggerConfig> ? LoggersList : never> {
79
161
  }
80
162
  /**
81
163
  * Emitter service is a singleton emitter instance registered
82
- * to the container.
164
+ * to the container. It provides type-safe event emission and listening.
165
+ *
166
+ * @example
167
+ * // Using emitter service to emit events
168
+ * export default class UserController {
169
+ * async store({ emitter }: { emitter: EmitterService }) {
170
+ * const user = await User.create(data)
171
+ * emitter.emit('user:created', { user })
172
+ * }
173
+ * }
83
174
  */
84
175
  export interface EmitterService extends Emitter<EventsList> {
85
176
  }
86
177
  /**
87
178
  * Encryption service is a singleton Encryption class instance
88
- * registered to the container.
179
+ * registered to the container. It provides encryption and decryption
180
+ * functionality using the application's secret key.
181
+ *
182
+ * @example
183
+ * // Using encryption service
184
+ * export default class PaymentController {
185
+ * async process({ encryption }: { encryption: EncryptionService }) {
186
+ * const encrypted = encryption.encrypt('sensitive-data')
187
+ * const decrypted = encryption.decrypt(encrypted)
188
+ * }
189
+ * }
89
190
  */
90
191
  export interface EncryptionService extends Encryption {
91
192
  }
92
193
  /**
93
- * Http server service added to the container as a singleton
194
+ * Http server service added to the container as a singleton.
195
+ * It provides access to the HTTP server instance for handling
196
+ * requests and responses.
197
+ *
198
+ * @example
199
+ * // Accessing server service in middleware
200
+ * export default class CustomMiddleware {
201
+ * async handle({ server }: { server: HttpServerService }, next: NextFn) {
202
+ * console.log('Server listening on:', server.getPort())
203
+ * return next()
204
+ * }
205
+ * }
94
206
  */
95
207
  export interface HttpServerService extends Server {
96
208
  }
97
209
  /**
98
- * Http server service added to the container as a singleton
210
+ * Http router service added to the container as a singleton.
211
+ * It provides access to the application's router for defining
212
+ * and managing routes.
213
+ *
214
+ * @example
215
+ * // Using router service to define routes programmatically
216
+ * export default class RouteProvider {
217
+ * boot({ router }: { router: HttpRouterService }) {
218
+ * router.get('/api/health', () => ({ status: 'ok' }))
219
+ * }
220
+ * }
99
221
  */
100
222
  export interface HttpRouterService extends Router {
101
223
  }
224
+ /**
225
+ * Url builder service offers a type-safe API for creating URLs
226
+ * for pre-registered routes. It ensures type safety when building
227
+ * URLs with parameters.
228
+ *
229
+ * @example
230
+ * // Using URL builder service
231
+ * export default class PostController {
232
+ * async show({ urlBuilder }: { urlBuilder: UrlBuilderService }) {
233
+ * const postUrl = urlBuilder.make('posts.show', { id: 1 })
234
+ * const userUrl = urlBuilder.make('users.profile', { username: 'john' })
235
+ * }
236
+ * }
237
+ */
238
+ export interface UrlBuilderService extends UrlFor<RoutesList extends LookupList ? RoutesList : never, URLOptions> {
239
+ }
240
+ /**
241
+ * Url builder service offers a type-safe API for creating signed URLs
242
+ * for pre-registered routes. Signed URLs include a signature that prevents
243
+ * tampering and can have expiration times.
244
+ *
245
+ * @example
246
+ * // Using signed URL builder service
247
+ * export default class FileController {
248
+ * async getDownloadUrl({ signedUrlBuilder }: { signedUrlBuilder: SignedUrlBuilderService }) {
249
+ * const signedUrl = signedUrlBuilder.make('files.download',
250
+ * { id: 1 },
251
+ * { expiresIn: '1h' }
252
+ * )
253
+ * }
254
+ * }
255
+ */
256
+ export interface SignedUrlBuilderService extends UrlFor<RoutesList extends LookupList ? RoutesList : never, SignedURLOptions> {
257
+ }
102
258
  /**
103
259
  * Hash service is a singleton instance of the HashManager
104
- * registered in the container
260
+ * registered in the container. It provides password hashing
261
+ * and verification functionality.
262
+ *
263
+ * @example
264
+ * // Using hash service for password management
265
+ * export default class AuthController {
266
+ * async register({ hash }: { hash: HashService }) {
267
+ * const hashedPassword = await hash.make('user-password')
268
+ * const isValid = await hash.verify(hashedPassword, 'user-password')
269
+ * }
270
+ * }
105
271
  */
106
272
  export interface HashService extends HashManager<HashersList extends Record<string, ManagerDriverFactory> ? HashersList : never> {
107
273
  }
108
274
  /**
109
- * A list of known container bindings.
275
+ * A list of known container bindings. This interface defines
276
+ * all the services that are registered in the IoC container
277
+ * and available for dependency injection.
278
+ *
279
+ * @example
280
+ * // Accessing container bindings in a service
281
+ * export default class UserService {
282
+ * constructor(
283
+ * private logger: LoggerService,
284
+ * private hash: HashService,
285
+ * private emitter: EmitterService
286
+ * ) {}
287
+ * }
110
288
  */
111
289
  export interface ContainerBindings {
290
+ /** Ace command-line kernel */
112
291
  ace: Kernel;
292
+ /** Database query dumper */
113
293
  dumper: Dumper;
294
+ /** Main application instance */
114
295
  app: ApplicationService;
296
+ /** Logger manager instance */
115
297
  logger: LoggerService;
298
+ /** Application configuration */
116
299
  config: ApplicationService['config'];
300
+ /** Event emitter instance */
117
301
  emitter: EmitterService;
302
+ /** Encryption service */
118
303
  encryption: EncryptionService;
304
+ /** Hash manager for password hashing */
119
305
  hash: HashService;
306
+ /** HTTP server instance */
120
307
  server: HttpServerService;
308
+ /** HTTP router instance */
121
309
  router: HttpRouterService;
310
+ /** Test utilities */
122
311
  testUtils: TestUtils;
312
+ /** REPL instance */
123
313
  repl: Repl;
124
314
  }
315
+ /**
316
+ * Configuration options for the IndexEntities assembler hook.
317
+ * This type defines the settings for automatically generating
318
+ * barrel files for controllers, listeners, and events.
319
+ *
320
+ * @example
321
+ * // Basic configuration
322
+ * const config: IndexEntitiesConfig = {
323
+ * controllers: { enabled: true },
324
+ * events: { source: 'app/custom-events' }
325
+ * }
326
+ *
327
+ * @example
328
+ * // Detailed configuration with custom paths
329
+ * const config: IndexEntitiesConfig = {
330
+ * controllers: {
331
+ * enabled: true,
332
+ * source: 'app/http/controllers',
333
+ * importAlias: '#controllers',
334
+ * glob: ['**\/*_controller.ts']
335
+ * },
336
+ * listeners: {
337
+ * enabled: false
338
+ * }
339
+ * }
340
+ */
341
+ export type IndexEntitiesConfig = {
342
+ /** Configuration for controllers indexing */
343
+ controllers?: {
344
+ /** Whether to enable controllers indexing */
345
+ enabled?: boolean;
346
+ /** Source directory for controllers */
347
+ source?: string;
348
+ /** Import alias for controllers */
349
+ importAlias?: string;
350
+ /** Glob patterns for matching controller files */
351
+ glob?: string[];
352
+ };
353
+ /** Configuration for listeners indexing */
354
+ listeners?: {
355
+ /** Whether to enable listeners indexing */
356
+ enabled?: boolean;
357
+ /** Source directory for listeners */
358
+ source?: string;
359
+ /** Import alias for listeners */
360
+ importAlias?: string;
361
+ /** Glob patterns for matching listener files */
362
+ glob?: string[];
363
+ };
364
+ /** Configuration for events indexing */
365
+ events?: {
366
+ /** Whether to enable events indexing */
367
+ enabled?: boolean;
368
+ /** Source directory for events */
369
+ source?: string;
370
+ /** Import alias for events */
371
+ importAlias?: string;
372
+ /** Glob patterns for matching event files */
373
+ glob?: string[];
374
+ };
375
+ transformers?: {
376
+ enabled?: boolean;
377
+ source?: string;
378
+ importAlias?: string;
379
+ glob?: string[];
380
+ };
381
+ };
@@ -0,0 +1,60 @@
1
+ import type typescript from 'typescript';
2
+ import type * as Assembler from '@adonisjs/assembler';
3
+ import { type RecursiveFileTree } from '@adonisjs/assembler/types';
4
+ import { type ApplicationService } from './types.ts';
5
+ /**
6
+ * Imports the AdonisJS assembler package optionally. This function attempts
7
+ * to import the assembler and returns undefined if it's not available,
8
+ * making it safe to use in environments where the assembler might not be installed.
9
+ *
10
+ * @param app - The application service instance used for importing the assembler
11
+ *
12
+ * @example
13
+ * const assembler = await importAssembler(app)
14
+ * if (assembler) {
15
+ * // Use assembler functionality
16
+ * const generator = new assembler.IndexGenerator()
17
+ * }
18
+ */
19
+ export declare function importAssembler(app: ApplicationService): Promise<typeof Assembler | undefined>;
20
+ /**
21
+ * Imports the TypeScript compiler package optionally. This function attempts
22
+ * to import TypeScript and returns undefined if it's not available,
23
+ * making it safe to use in environments where TypeScript might not be installed.
24
+ *
25
+ * @param app - The application service instance used for importing TypeScript
26
+ *
27
+ * @example
28
+ * const ts = await importTypeScript(app)
29
+ * if (ts) {
30
+ * // Use TypeScript compiler API
31
+ * const program = ts.createProgram(['file.ts'], {})
32
+ * const sourceFile = program.getSourceFile('file.ts')
33
+ * }
34
+ */
35
+ export declare function importTypeScript(app: ApplicationService): Promise<typeof typescript | undefined>;
36
+ /**
37
+ * Outputs transformer data objects by generating TypeScript type definitions
38
+ * for all transformers in the provided file tree. This function creates
39
+ * InferData types for each transformer and organizes them in namespaces.
40
+ *
41
+ * @param transformersList - A recursive file tree containing transformer file paths
42
+ * @param buffer - The file buffer to write the generated types to
43
+ *
44
+ * @example
45
+ * const transformersList = {
46
+ * User: '#app/transformers/user_transformer',
47
+ * Auth: {
48
+ * Login: '#app/transformers/auth/login_transformer'
49
+ * }
50
+ * }
51
+ * await outputTransformerDataObjects(transformersList, buffer)
52
+ * // Generates:
53
+ * // export namespace Data {
54
+ * // export type User = InferData<UserTransformer>
55
+ * // export namespace Auth {
56
+ * // export type Login = InferData<AuthLoginTransformer>
57
+ * // }
58
+ * // }
59
+ */
60
+ export declare function outputTransformerDataObjects(transformersList: RecursiveFileTree, buffer: Assembler.FileBuffer): Promise<void>;
@@ -0,0 +1,104 @@
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) {
75
+ const importsBuffer = buffer.create();
76
+ importsBuffer.write(`import { InferData } from '@adonisjs/core/types/transformers'`);
77
+ buffer.writeLine(importsBuffer);
78
+ buffer.write('export namespace Data {').indent();
79
+ /**
80
+ * Recursively generates namespace tree structure for transformers.
81
+ * Creates nested namespaces for directory structures and type exports
82
+ * for individual transformer files.
83
+ *
84
+ * @param input - The current level of the file tree to process
85
+ * @param parents - Array of parent namespace names for import naming
86
+ */
87
+ function generateNamespaceTree(input, parents) {
88
+ Object.keys(input).forEach((key) => {
89
+ const value = input[key];
90
+ if (typeof value === 'string') {
91
+ const importName = `${parents.join()}${key}Transformer`;
92
+ importsBuffer.write(`import ${importName} from '${value}'`);
93
+ buffer.write(`export type ${key} = InferData<${importName}>`);
94
+ }
95
+ else {
96
+ buffer.write(`export namespace ${key} {`).indent();
97
+ generateNamespaceTree(value, [...parents, key]);
98
+ buffer.dedent().write(`}`);
99
+ }
100
+ });
101
+ }
102
+ generateNamespaceTree(transformersList, []);
103
+ buffer.dedent().write('}');
104
+ }
@@ -8,12 +8,35 @@ declare const MULTIPART_FILE: typeof symbols.SUBTYPE;
8
8
  export type FileRuleValidationOptions = Partial<FileValidationOptions> | ((field: FieldContext) => Partial<FileValidationOptions>);
9
9
  /**
10
10
  * Represents a multipart file uploaded via multipart/form-data HTTP
11
- * request.
11
+ * request. This class extends VineJS's BaseLiteralType to provide
12
+ * specialized validation for uploaded files.
13
+ *
14
+ * @example
15
+ * const fileSchema = vine.object({
16
+ * avatar: vine.file({
17
+ * size: '2mb',
18
+ * extnames: ['jpg', 'png']
19
+ * })
20
+ * })
12
21
  */
13
22
  export declare class VineMultipartFile extends BaseLiteralType<MultipartFile, MultipartFile, MultipartFile> {
14
23
  #private;
24
+ /**
25
+ * Symbol identifier for multipart file subtype
26
+ */
15
27
  [MULTIPART_FILE]: string;
28
+ /**
29
+ * Creates a new VineMultipartFile instance
30
+ *
31
+ * @param validationOptions - File validation options like size limits and allowed extensions
32
+ * @param options - Field options from VineJS
33
+ * @param validations - Array of validation functions to apply
34
+ */
16
35
  constructor(validationOptions?: FileRuleValidationOptions, options?: FieldOptions, validations?: Validation<any>[]);
36
+ /**
37
+ * Creates a clone of the current VineMultipartFile instance
38
+ * with the same validation options and configurations
39
+ */
17
40
  clone(): this;
18
41
  }
19
42
  export {};
package/build/src/vine.js CHANGED
@@ -56,15 +56,41 @@ const isMultipartFile = vine.createRule((file, options, field) => {
56
56
  });
57
57
  /**
58
58
  * Represents a multipart file uploaded via multipart/form-data HTTP
59
- * request.
59
+ * request. This class extends VineJS's BaseLiteralType to provide
60
+ * specialized validation for uploaded files.
61
+ *
62
+ * @example
63
+ * const fileSchema = vine.object({
64
+ * avatar: vine.file({
65
+ * size: '2mb',
66
+ * extnames: ['jpg', 'png']
67
+ * })
68
+ * })
60
69
  */
61
70
  export class VineMultipartFile extends BaseLiteralType {
71
+ /**
72
+ * Private validation options for file validation
73
+ */
62
74
  #validationOptions;
75
+ /**
76
+ * Symbol identifier for multipart file subtype
77
+ */
63
78
  [MULTIPART_FILE] = 'multipartFile';
79
+ /**
80
+ * Creates a new VineMultipartFile instance
81
+ *
82
+ * @param validationOptions - File validation options like size limits and allowed extensions
83
+ * @param options - Field options from VineJS
84
+ * @param validations - Array of validation functions to apply
85
+ */
64
86
  constructor(validationOptions, options, validations) {
65
87
  super(options, validations || [isMultipartFile(validationOptions || {})]);
66
88
  this.#validationOptions = validationOptions;
67
89
  }
90
+ /**
91
+ * Creates a clone of the current VineMultipartFile instance
92
+ * with the same validation options and configurations
93
+ */
68
94
  clone() {
69
95
  return new VineMultipartFile(this.#validationOptions, this.cloneOptions(), this.cloneValidations());
70
96
  }