@adonisjs/assembler 8.0.0-next.3 → 8.0.0-next.30

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 (39) hide show
  1. package/README.md +87 -59
  2. package/build/codemod_exception-vyN1VXuX.js +137 -0
  3. package/build/helpers-DDurYRsZ.js +72 -0
  4. package/build/index.d.ts +4 -0
  5. package/build/index.js +925 -1319
  6. package/build/main-BeV45LeF.js +246 -0
  7. package/build/main-CknPN3rJ.js +188 -0
  8. package/build/src/bundler.d.ts +44 -3
  9. package/build/src/code_scanners/routes_scanner/main.d.ts +63 -11
  10. package/build/src/code_scanners/routes_scanner/main.js +4 -0
  11. package/build/src/code_scanners/routes_scanner/validator_extractor.d.ts +12 -4
  12. package/build/src/code_transformer/main.d.ts +53 -43
  13. package/build/src/code_transformer/main.js +354 -599
  14. package/build/src/code_transformer/rc_file_transformer.d.ts +83 -5
  15. package/build/src/debug.d.ts +13 -1
  16. package/build/src/dev_server.d.ts +92 -17
  17. package/build/src/exceptions/codemod_exception.d.ts +178 -0
  18. package/build/src/file_buffer.d.ts +87 -0
  19. package/build/src/file_system.d.ts +46 -8
  20. package/build/src/helpers.d.ts +79 -4
  21. package/build/src/helpers.js +2 -0
  22. package/build/src/index_generator/main.d.ts +68 -0
  23. package/build/src/index_generator/main.js +3 -0
  24. package/build/src/index_generator/source.d.ts +60 -0
  25. package/build/src/paths_resolver.d.ts +29 -3
  26. package/build/src/shortcuts_manager.d.ts +42 -4
  27. package/build/src/test_runner.d.ts +57 -12
  28. package/build/src/types/code_scanners.d.ts +160 -30
  29. package/build/src/types/code_transformer.d.ts +69 -19
  30. package/build/src/types/common.d.ts +233 -55
  31. package/build/src/types/hooks.d.ts +238 -22
  32. package/build/src/types/main.d.ts +15 -1
  33. package/build/src/types/main.js +1 -0
  34. package/build/src/utils.d.ts +96 -15
  35. package/build/src/virtual_file_system.d.ts +112 -0
  36. package/build/virtual_file_system-bGeoWsK-.js +285 -0
  37. package/package.json +46 -36
  38. package/build/chunk-RR4HCA4M.js +0 -7
  39. package/build/src/ast_file_system.d.ts +0 -17
@@ -1,45 +1,115 @@
1
+ /**
2
+ * Represents a controller that has been scanned and analyzed by the routes scanner.
3
+ * Contains metadata about the controller class and the specific method being called.
4
+ *
5
+ * @example
6
+ * const controller: ScannedController = {
7
+ * name: 'UsersController',
8
+ * path: '/project/app/controllers/users_controller.ts',
9
+ * method: 'index',
10
+ * import: {
11
+ * type: 'default',
12
+ * specifier: '#controllers/users_controller',
13
+ * value: 'UsersController'
14
+ * }
15
+ * }
16
+ */
1
17
  export type ScannedController = {
18
+ /** The name of the controller class */
2
19
  name: string;
20
+ /** Absolute file path to the controller */
3
21
  path: string;
22
+ /** The method name being called on the controller */
4
23
  method: string;
24
+ /** Import information for the controller */
5
25
  import: {
26
+ /** Import type (always 'default' for controllers) */
6
27
  type: 'default';
28
+ /** Import specifier used to import the controller */
7
29
  specifier: string;
30
+ /** The imported value name */
8
31
  value: string;
9
32
  };
10
33
  };
34
+ /**
35
+ * Represents a validator that has been extracted from controller methods.
36
+ * Contains information about how the validator is imported and used.
37
+ *
38
+ * @example
39
+ * const validator: ScannedValidator = {
40
+ * name: 'createUserValidator',
41
+ * import: {
42
+ * type: 'named',
43
+ * specifier: '#validators/user_validators',
44
+ * value: 'createUserValidator'
45
+ * }
46
+ * }
47
+ */
11
48
  export type ScannedValidator = {
49
+ /** The name/identifier of the validator */
12
50
  name: string;
51
+ /** Import information for the validator */
13
52
  import: {
53
+ /** The type of import (namespace, default, or named) */
14
54
  type: 'namespace' | 'default' | 'named';
55
+ /** The module specifier being imported from */
15
56
  specifier: string;
57
+ /** The imported value name */
16
58
  value: string;
17
59
  };
18
60
  };
19
61
  /**
20
- * Output of scanned route
62
+ * Output of a scanned route containing all extracted metadata including
63
+ * controller information, validators, request/response types, and route patterns.
64
+ *
65
+ * @example
66
+ * const scannedRoute: ScannedRoute = {
67
+ * name: 'users.store',
68
+ * methods: ['POST'],
69
+ * domain: 'root',
70
+ * pattern: '/users',
71
+ * tokens: [{ val: '/users', old: '/users', type: 0, end: '' }],
72
+ * request: {
73
+ * type: 'InferInput<typeof createUserValidator>',
74
+ * imports: ['import { InferInput } from "@vinejs/vine/types"']
75
+ * },
76
+ * response: {
77
+ * type: 'ReturnType<UsersController["store"]>',
78
+ * imports: []
79
+ * },
80
+ * validators: [{
81
+ * name: 'createUserValidator',
82
+ * import: { type: 'named', specifier: '#validators/user', value: 'createUserValidator' }
83
+ * }],
84
+ * controller: {
85
+ * name: 'UsersController',
86
+ * method: 'store',
87
+ * path: '/app/controllers/users_controller.ts',
88
+ * import: { type: 'default', specifier: '#controllers/users_controller', value: 'UsersController' }
89
+ * }
90
+ * }
21
91
  */
22
92
  export type ScannedRoute = {
23
93
  /**
24
- * A unique name for the route provided by AdonisJS http-server. It
25
- * could be duplicate across domains.
94
+ * A unique name for the route provided by AdonisJS http-server.
95
+ * May be duplicate across different domains.
26
96
  */
27
97
  name: string;
28
98
  /**
29
- * HTTP methods for which the route is defined
99
+ * HTTP methods for which the route is defined (GET, POST, PUT, etc.)
30
100
  */
31
101
  methods: string[];
32
102
  /**
33
- * HTTP method for which the route is defined
103
+ * The domain on which the route is registered (typically 'root')
34
104
  */
35
105
  domain: string;
36
106
  /**
37
- * The route pattern
107
+ * The route pattern with parameter placeholders (e.g., '/users/:id')
38
108
  */
39
109
  pattern: string;
40
110
  /**
41
- * Route tokens could be used for constructing a URI for
42
- * the route without parsing the pattern
111
+ * Route tokens that can be used for constructing URIs without parsing the pattern.
112
+ * Contains information about static and dynamic segments.
43
113
  */
44
114
  tokens: {
45
115
  val: string;
@@ -48,44 +118,70 @@ export type ScannedRoute = {
48
118
  end: string;
49
119
  }[];
50
120
  /**
51
- * Inferred request data accepted by the route. By default, the request
52
- * data type is inferred when route is using a controller with a
53
- * validator
121
+ * Inferred request data type accepted by the route.
122
+ * Generated when the route uses a controller with validators.
54
123
  */
55
124
  request?: {
125
+ /** TypeScript type definition for the request data */
56
126
  type: string;
127
+ /** Import statements needed for the type definition */
57
128
  imports: string[];
58
129
  };
59
130
  /**
60
- * Inferred response for the route. By default, the response is only
61
- * inferred when the route is using a controller.
131
+ * Inferred response type returned by the route.
132
+ * Generated when the route uses a controller method.
62
133
  */
63
134
  response?: {
135
+ /** TypeScript type definition for the response data */
64
136
  type: string;
137
+ /** Import statements needed for the type definition */
65
138
  imports: string[];
66
139
  };
67
140
  /**
68
- * Extracted validators info, only when using the controller.
141
+ * Extracted validator information from the controller method.
142
+ * Only present when using controller-based routes with validation.
69
143
  */
70
144
  validators?: ScannedValidator[];
71
145
  /**
72
- * Extracted controller info, only when using the controller.
146
+ * Extracted controller information including class and method details.
147
+ * Only present when using controller-based routes.
73
148
  */
74
149
  controller?: ScannedController;
75
150
  };
76
151
  /**
77
- * The route accepted by the routes scanner when initiating
78
- * the scanning process.
152
+ * The route data structure accepted by the routes scanner when initiating
153
+ * the scanning process. This represents the raw route definition before analysis.
154
+ *
155
+ * @example
156
+ * const routeItem: RoutesListItem = {
157
+ * name: 'users.store',
158
+ * pattern: '/users',
159
+ * domain: 'root',
160
+ * methods: ['POST'],
161
+ * controllerReference: {
162
+ * importExpression: "() => import('#controllers/users_controller')",
163
+ * method: 'store'
164
+ * },
165
+ * tokens: [{ val: '/users', old: '/users', type: 0, end: '' }]
166
+ * }
79
167
  */
80
168
  export type RoutesListItem = {
169
+ /** Optional unique name for the route */
81
170
  name?: string;
171
+ /** Route pattern with parameter placeholders */
82
172
  pattern: string;
173
+ /** Domain on which the route is registered */
83
174
  domain: string;
175
+ /** HTTP methods accepted by this route */
84
176
  methods: string[];
85
- controllerReference?: {
86
- importExpression: string;
87
- method?: string;
177
+ /** Handler information for controller-based routes */
178
+ handler?: {
179
+ /** The method name to be called on the controller */
180
+ method: string;
181
+ /** Dynamic import expression that loads the controller module */
182
+ importExpression: string | null;
88
183
  };
184
+ /** Parsed route tokens for URI construction */
89
185
  tokens: {
90
186
  val: string;
91
187
  old: string;
@@ -94,22 +190,56 @@ export type RoutesListItem = {
94
190
  }[];
95
191
  };
96
192
  /**
97
- * Rules accepted by the route scanner.
193
+ * A filter function to exclude routes from being processed by the routes scanner.
194
+ * Return false to filter out (exclude) the route, or true to include it.
195
+ *
196
+ * @example
197
+ * const filterFn: RoutesScannerFilterFn = (route) => {
198
+ * // Exclude all admin routes
199
+ * if (route.pattern.startsWith('/admin')) {
200
+ * return false
201
+ * }
202
+ *
203
+ * // Exclude health check routes
204
+ * if (route.name === 'health.check') {
205
+ * return false
206
+ * }
207
+ *
208
+ * // Include all other routes
209
+ * return true
210
+ * }
211
+ */
212
+ export type RoutesScannerFilterFn = (route: RoutesListItem) => boolean;
213
+ /**
214
+ * Configuration rules accepted by the routes scanner to customize
215
+ * the scanning behavior and override type inference.
216
+ *
217
+ * @example
218
+ * const rules: RoutesScannerRules = {
219
+ * skip: ['admin.dashboard', 'health.check'],
220
+ * response: {
221
+ * 'users.index': {
222
+ * type: 'PaginatedResponse<User[]>',
223
+ * imports: ['import { User } from "#models/user"']
224
+ * }
225
+ * },
226
+ * request: {
227
+ * 'users.store': {
228
+ * type: 'CreateUserRequest',
229
+ * imports: ['import { CreateUserRequest } from "#types/requests"']
230
+ * }
231
+ * }
232
+ * }
98
233
  */
99
234
  export type RoutesScannerRules = {
100
235
  /**
101
- * An array of route names or controller+method paths to skip from
102
- * the processing
103
- */
104
- skip: string[];
105
- /**
106
- * Define custom response type for a route by its name or the
107
- * controller+method path
236
+ * Define custom response types for specific routes by their name
237
+ * or controller+method path. Overrides automatic type inference.
108
238
  */
109
239
  response: Record<string, ScannedRoute['response']>;
110
240
  /**
111
- * Define custom request data type for a route by its name
112
- * or the controller+method path
241
+ * Define custom request data types for specific routes by their name
242
+ * or controller+method path. Overrides automatic type inference.
113
243
  */
114
244
  request: Record<string, ScannedRoute['response']>;
115
245
  };
@@ -1,61 +1,111 @@
1
1
  /**
2
- * Entry to add a middleware to a given middleware stack
3
- * via the CodeTransformer
2
+ * Entry to add a middleware to a given middleware stack via the CodeTransformer.
3
+ * Represents middleware configuration for server, router, or named middleware stacks.
4
+ *
5
+ * @example
6
+ * const corsMiddleware: MiddlewareNode = {
7
+ * path: '@adonisjs/cors/cors_middleware',
8
+ * position: 'before'
9
+ * }
10
+ *
11
+ * const namedMiddleware: MiddlewareNode = {
12
+ * name: 'auth',
13
+ * path: '#middleware/auth_middleware',
14
+ * position: 'after'
15
+ * }
4
16
  */
5
17
  export type MiddlewareNode = {
6
18
  /**
7
- * If you are adding a named middleware, then you must
8
- * define the name.
19
+ * Required for named middleware. The key name under which the middleware
20
+ * will be registered in the named middleware collection.
9
21
  */
10
22
  name?: string;
11
23
  /**
12
- * The path to the middleware file
24
+ * The import path to the middleware file. Can be a package import,
25
+ * subpath import, or relative path.
13
26
  *
14
27
  * @example
15
- * `@adonisjs/static/static_middleware`
16
- * `#middlewares/silent_auth.js`
28
+ * '@adonisjs/static/static_middleware'
29
+ * '#middlewares/silent_auth'
30
+ * './middleware/custom_middleware.js'
17
31
  */
18
32
  path: string;
19
33
  /**
20
- * The position to add the middleware. If `before`
21
- * middleware will be added at the first position and
22
- * therefore will be run before all others
34
+ * The position to add the middleware in the stack.
35
+ * 'before' adds at the beginning (runs first), 'after' adds at the end (runs last).
23
36
  *
24
37
  * @default 'after'
25
38
  */
26
39
  position?: 'before' | 'after';
27
40
  };
28
41
  /**
29
- * Policy node to be added to the list of policies.
42
+ * Policy node to be added to the list of Bouncer authorization policies.
43
+ * Used for registering policies in the application's policy registry.
44
+ *
45
+ * @example
46
+ * const userPolicy: BouncerPolicyNode = {
47
+ * name: 'UserPolicy',
48
+ * path: '#policies/user_policy'
49
+ * }
30
50
  */
31
51
  export type BouncerPolicyNode = {
32
52
  /**
33
- * Policy name
53
+ * The name of the policy class (should match the exported class name)
34
54
  */
35
55
  name: string;
36
56
  /**
37
- * Policy import path
57
+ * The import path to the policy file
38
58
  */
39
59
  path: string;
40
60
  };
41
61
  /**
42
- * Defines the structure of an environment variable validation
43
- * definition
62
+ * Defines the structure of an environment variable validation definition.
63
+ * Used to add new environment variable validations to the start/env.ts file.
64
+ *
65
+ * @example
66
+ * const envValidation: EnvValidationNode = {
67
+ * leadingComment: 'Database configuration',
68
+ * variables: {
69
+ * DB_HOST: 'Env.schema.string()',
70
+ * DB_PORT: 'Env.schema.number.optional({ port: 5432 })',
71
+ * DB_PASSWORD: 'Env.schema.string.optional()'
72
+ * }
73
+ * }
44
74
  */
45
75
  export type EnvValidationNode = {
46
76
  /**
47
- * Write a leading comment on top of your variables
77
+ * Optional leading comment to write above the variable definitions.
78
+ * Helps group related environment variables together.
48
79
  */
49
80
  leadingComment?: string;
50
81
  /**
51
- * A key-value pair of env variables and their validation
82
+ * A key-value pair of environment variables and their validation schemas.
83
+ * The key is the environment variable name, the value is the validation code.
52
84
  *
53
85
  * @example
54
- * MY_VAR: 'Env.schema.string.optional()'
86
+ * {
87
+ * MY_VAR: 'Env.schema.string.optional()',
88
+ * API_KEY: 'Env.schema.string()'
89
+ * }
55
90
  */
56
91
  variables: Record<string, string>;
57
92
  };
93
+ export type HookNode = {
94
+ type: 'thunk';
95
+ path: string;
96
+ } | {
97
+ type: 'import';
98
+ path: string;
99
+ name?: string;
100
+ };
58
101
  /**
59
- * The supported package managers for installing packages
102
+ * The supported package managers for installing packages and managing lockfiles.
103
+ * Each package manager has specific lockfiles and install commands.
104
+ *
105
+ * @example
106
+ * const packageManager: SupportedPackageManager = 'pnpm'
107
+ *
108
+ * // Used in bundler configuration
109
+ * const bundler = new Bundler(cwd, ts, { packageManager: 'yarn@berry' })
60
110
  */
61
111
  export type SupportedPackageManager = 'npm' | 'yarn' | 'yarn@berry' | 'pnpm' | 'bun';