@adonisjs/assembler 8.0.0-next.25 → 8.0.0-next.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as loadHooks, c as readTsConfig, d as runNode, f as throttle, m as debug_default, n as copyFiles, o as memoize, p as watch, r as getPort, s as parseConfig, t as VirtualFileSystem, u as run } from "./virtual_file_system-bGeoWsK-.js";
|
|
2
2
|
import { n as FileBuffer, t as IndexGenerator } from "./main-XUXlmlEy.js";
|
|
3
|
-
import { t as RoutesScanner } from "./main-
|
|
3
|
+
import { t as RoutesScanner } from "./main-BeV45LeF.js";
|
|
4
4
|
import "./helpers-DDurYRsZ.js";
|
|
5
5
|
import dedent from "dedent";
|
|
6
6
|
import fs, { readFile, unlink } from "node:fs/promises";
|
|
@@ -79,7 +79,7 @@ async function extractValidators(appRoot, vfs, controller) {
|
|
|
79
79
|
}))).filter((value) => !!value);
|
|
80
80
|
}
|
|
81
81
|
var RoutesScanner = class {
|
|
82
|
-
#filter
|
|
82
|
+
#filter;
|
|
83
83
|
#appRoot;
|
|
84
84
|
#controllerRoutes = {};
|
|
85
85
|
#scannedRoutes = [];
|
|
@@ -100,6 +100,10 @@ var RoutesScanner = class {
|
|
|
100
100
|
Object.assign(this.rules.response, rules.response);
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
|
+
#shouldSkipRoute(route) {
|
|
104
|
+
if (this.#filter) return !this.#filter(route);
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
103
107
|
#prepareRequestTypes(route) {
|
|
104
108
|
if (!route.validators) return;
|
|
105
109
|
return {
|
|
@@ -107,10 +111,10 @@ var RoutesScanner = class {
|
|
|
107
111
|
const validatorExport = validator.import.type === "default" ? ".default" : validator.import.type === "named" ? `.${validator.import.value}` : "";
|
|
108
112
|
const [, ...segments] = validator.name.split(".");
|
|
109
113
|
const namespace = segments.map((segment) => `['${segment}']`).join("");
|
|
110
|
-
result.push(`
|
|
114
|
+
result.push(`InferInput<(typeof import('${validator.import.specifier}')${validatorExport})${namespace}>`);
|
|
111
115
|
return result;
|
|
112
116
|
}, []).join("|"),
|
|
113
|
-
imports: [`import {
|
|
117
|
+
imports: [`import { InferInput } from '@vinejs/vine/types'`]
|
|
114
118
|
};
|
|
115
119
|
}
|
|
116
120
|
async #inspectControllerSpecifier(importExpression, method) {
|
|
@@ -165,7 +169,7 @@ var RoutesScanner = class {
|
|
|
165
169
|
if (!controller) return this.#processRouteWithoutController(route);
|
|
166
170
|
debug_default("processing route \"%s\" with inspected controller %O", route.name, controller);
|
|
167
171
|
route.name = route.name ?? new StringBuilder(controller.name).removeSuffix("Controller").snakeCase().suffix(`.${string.snakeCase(controller.method)}`).toString();
|
|
168
|
-
if (this.#
|
|
172
|
+
if (this.#shouldSkipRoute(route)) return;
|
|
169
173
|
const scannedRoute = {
|
|
170
174
|
name: route.name,
|
|
171
175
|
domain: route.domain,
|
|
@@ -187,7 +191,7 @@ var RoutesScanner = class {
|
|
|
187
191
|
}
|
|
188
192
|
}
|
|
189
193
|
async #processRoute(route, vfs) {
|
|
190
|
-
if (route.name && this.#
|
|
194
|
+
if (route.name && this.#shouldSkipRoute(route)) {
|
|
191
195
|
debug_default("route skipped route: %O, rules: %O", route, this.rules);
|
|
192
196
|
return;
|
|
193
197
|
}
|
|
@@ -229,6 +233,10 @@ var RoutesScanner = class {
|
|
|
229
233
|
}
|
|
230
234
|
return true;
|
|
231
235
|
}
|
|
236
|
+
filter(filterFn) {
|
|
237
|
+
this.#filter = filterFn;
|
|
238
|
+
return this;
|
|
239
|
+
}
|
|
232
240
|
async scan(routes) {
|
|
233
241
|
const vfs = new VirtualFileSystem(this.#appRoot);
|
|
234
242
|
for (const route of routes) await this.#processRoute(route, vfs);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AsyncOrSync } from '@poppinss/utils/types';
|
|
2
2
|
import { PathsResolver } from '../../paths_resolver.ts';
|
|
3
|
-
import { type ScannedRoute, type RoutesListItem, type ScannedController, type RoutesScannerRules } from '../../types/code_scanners.ts';
|
|
3
|
+
import { type ScannedRoute, type RoutesListItem, type ScannedController, type RoutesScannerRules, type RoutesScannerFilterFn } from '../../types/code_scanners.ts';
|
|
4
4
|
/**
|
|
5
5
|
* RoutesScanner is responsible for scanning application routes,
|
|
6
6
|
* extracting their controllers, validators, request and response types.
|
|
@@ -106,6 +106,18 @@ export declare class RoutesScanner {
|
|
|
106
106
|
* @param controllerPath - Path to the controller file to invalidate
|
|
107
107
|
*/
|
|
108
108
|
invalidate(controllerPath: string): Promise<boolean>;
|
|
109
|
+
/**
|
|
110
|
+
* Sets a filter function to selectively include routes during scanning.
|
|
111
|
+
*
|
|
112
|
+
* @param filterFn - Function that returns true for routes to include
|
|
113
|
+
* @returns This RoutesScanner instance for method chaining
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* scanner.filter((route) => {
|
|
117
|
+
* return route.pattern.startsWith('/api')
|
|
118
|
+
* })
|
|
119
|
+
*/
|
|
120
|
+
filter(filterFn: RoutesScannerFilterFn): this;
|
|
109
121
|
/**
|
|
110
122
|
* Scans an array of Route list items and fetches their validators,
|
|
111
123
|
* controllers, and request/response types.
|
|
@@ -70,8 +70,8 @@ export type ScannedValidator = {
|
|
|
70
70
|
* pattern: '/users',
|
|
71
71
|
* tokens: [{ val: '/users', old: '/users', type: 0, end: '' }],
|
|
72
72
|
* request: {
|
|
73
|
-
* type: '
|
|
74
|
-
* imports: ['import {
|
|
73
|
+
* type: 'InferInput<typeof createUserValidator>',
|
|
74
|
+
* imports: ['import { InferInput } from "@vinejs/vine/types"']
|
|
75
75
|
* },
|
|
76
76
|
* response: {
|
|
77
77
|
* type: 'ReturnType<UsersController["store"]>',
|
|
@@ -174,8 +174,11 @@ export type RoutesListItem = {
|
|
|
174
174
|
domain: string;
|
|
175
175
|
/** HTTP methods accepted by this route */
|
|
176
176
|
methods: string[];
|
|
177
|
+
/** Handler information for controller-based routes */
|
|
177
178
|
handler?: {
|
|
179
|
+
/** The method name to be called on the controller */
|
|
178
180
|
method: string;
|
|
181
|
+
/** Dynamic import expression that loads the controller module */
|
|
179
182
|
importExpression: string | null;
|
|
180
183
|
};
|
|
181
184
|
/** Parsed route tokens for URI construction */
|
|
@@ -187,8 +190,24 @@ export type RoutesListItem = {
|
|
|
187
190
|
}[];
|
|
188
191
|
};
|
|
189
192
|
/**
|
|
190
|
-
*
|
|
191
|
-
* to filter out (
|
|
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
|
+
* }
|
|
192
211
|
*/
|
|
193
212
|
export type RoutesScannerFilterFn = (route: RoutesListItem) => boolean;
|
|
194
213
|
/**
|
package/package.json
CHANGED