@vercube/scan 1.2.0 → 1.2.2

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 (2) hide show
  1. package/dist/index.d.mts +34 -35
  2. package/package.json +2 -2
package/dist/index.d.mts CHANGED
@@ -11,7 +11,7 @@
11
11
  * @param node - An AST node from the program body to inspect.
12
12
  * @returns An object containing the class AST node and whether it is a default export, or `null` if not a class.
13
13
  */
14
- declare function getClassNode(node: any): {
14
+ export declare function getClassNode(node: any): {
15
15
  classNode: any;
16
16
  isDefault: boolean;
17
17
  } | null;
@@ -23,7 +23,7 @@ declare function getClassNode(node: any): {
23
23
  * @param isDefault - Whether the class is a default export.
24
24
  * @returns The generated import statement string.
25
25
  */
26
- declare function buildImport(className: string, source: string, isDefault: boolean): string;
26
+ export declare function buildImport(className: string, source: string, isDefault: boolean): string;
27
27
  /**
28
28
  * Searches a list of decorators for a `CallExpression` matching the given name
29
29
  * and extracts its first string argument.
@@ -36,7 +36,7 @@ declare function buildImport(className: string, source: string, isDefault: boole
36
36
  * @param name - The decorator function name to match against (e.g. 'Controller').
37
37
  * @returns The string argument value, an empty string if no argument is provided, or `null` if the decorator is not found.
38
38
  */
39
- declare function extractDecoratorArg(decorators: any[] | undefined, name: string): string | null;
39
+ export declare function extractDecoratorArg(decorators: any[] | undefined, name: string): string | null;
40
40
  /**
41
41
  * Returns true if the given decorators array contains a decorator matching `name`.
42
42
  * Supports both `@Name` identifier and `@Name()` call expression styles.
@@ -45,7 +45,7 @@ declare function extractDecoratorArg(decorators: any[] | undefined, name: string
45
45
  * @param name - The decorator name to match.
46
46
  * @returns Whether a matching decorator exists.
47
47
  */
48
- declare function hasDecorator(decorators: any[] | undefined, name: string): boolean;
48
+ export declare function hasDecorator(decorators: any[] | undefined, name: string): boolean;
49
49
  /**
50
50
  * Returns true if the class node extends a superclass with the given name.
51
51
  *
@@ -53,7 +53,7 @@ declare function hasDecorator(decorators: any[] | undefined, name: string): bool
53
53
  * @param name - The expected superclass identifier name.
54
54
  * @returns Whether the class extends the named superclass.
55
55
  */
56
- declare function extendsSuperClass(classNode: any, name: string): boolean;
56
+ export declare function extendsSuperClass(classNode: any, name: string): boolean;
57
57
  /**
58
58
  * Normalizes a route path by removing duplicate slashes and ensuring
59
59
  * the path starts with a single leading slash.
@@ -61,7 +61,7 @@ declare function extendsSuperClass(classNode: any, name: string): boolean;
61
61
  * @param path - The raw concatenated path string to normalize.
62
62
  * @returns A cleaned path string with a leading slash and no duplicate separators.
63
63
  */
64
- declare function normalizePath(path: string): string;
64
+ export declare function normalizePath(path: string): string;
65
65
  /**
66
66
  * Extracts named route parameters from a path string.
67
67
  *
@@ -71,13 +71,13 @@ declare function normalizePath(path: string): string;
71
71
  * @param route - The normalized route path to scan for parameters.
72
72
  * @returns An array of parameter name strings, empty if none are found.
73
73
  */
74
- declare function extractParams(route: string): string[];
74
+ export declare function extractParams(route: string): string[];
75
75
  //#endregion
76
76
  //#region src/Types.d.ts
77
77
  /**
78
78
  * Basic information about a scanned source file.
79
79
  */
80
- type FileInfo = {
80
+ export type FileInfo = {
81
81
  /** The path of the file relative to the directory it was scanned from. */
82
82
  path: string;
83
83
  /** The absolute path of the file on disk. */
@@ -86,7 +86,7 @@ type FileInfo = {
86
86
  /**
87
87
  * Represents a single extracted route from a controller class.
88
88
  */
89
- interface RouteInfo extends FileInfo {
89
+ export interface RouteInfo extends FileInfo {
90
90
  /** The import statement required to load the controller class. */
91
91
  import: string;
92
92
  /** The name of the import statement. */
@@ -101,7 +101,7 @@ interface RouteInfo extends FileInfo {
101
101
  /**
102
102
  * Represents a single injectable service class discovered during scanning.
103
103
  */
104
- interface ServiceInfo extends FileInfo {
104
+ export interface ServiceInfo extends FileInfo {
105
105
  /** The import statement required to load the service class. */
106
106
  import: string;
107
107
  /** The name of the imported class. */
@@ -110,7 +110,7 @@ interface ServiceInfo extends FileInfo {
110
110
  /**
111
111
  * Represents a single middleware class discovered during scanning.
112
112
  */
113
- interface MiddlewareInfo extends FileInfo {
113
+ export interface MiddlewareInfo extends FileInfo {
114
114
  /** The import statement required to load the middleware class. */
115
115
  import: string;
116
116
  /** The name of the imported class. */
@@ -119,7 +119,7 @@ interface MiddlewareInfo extends FileInfo {
119
119
  /**
120
120
  * Minimal logger interface used to report non-fatal scanning issues.
121
121
  */
122
- interface ScanLogger {
122
+ export interface ScanLogger {
123
123
  warn(message: string): void;
124
124
  }
125
125
  //#endregion
@@ -128,15 +128,15 @@ interface ScanLogger {
128
128
  * Placeholder module specifier embedded in generated route imports.
129
129
  * Callers resolve it to the real file path once known (see {@link Transform}).
130
130
  */
131
- declare const IMPORT_SOURCE = "#internal/vercube-route-plugin";
131
+ export declare const IMPORT_SOURCE = "#internal/vercube-route-plugin";
132
132
  /**
133
133
  * Placeholder module specifier embedded in generated service imports.
134
134
  */
135
- declare const SERVICE_IMPORT_SOURCE = "#internal/vercube-service-source";
135
+ export declare const SERVICE_IMPORT_SOURCE = "#internal/vercube-service-source";
136
136
  /**
137
137
  * Placeholder module specifier embedded in generated middleware imports.
138
138
  */
139
- declare const MIDDLEWARE_IMPORT_SOURCE = "#internal/vercube-middleware-source";
139
+ export declare const MIDDLEWARE_IMPORT_SOURCE = "#internal/vercube-middleware-source";
140
140
  /**
141
141
  * Extracts all route definitions from the given TypeScript/JavaScript source code.
142
142
  *
@@ -149,7 +149,7 @@ declare const MIDDLEWARE_IMPORT_SOURCE = "#internal/vercube-middleware-source";
149
149
  * @param code - The raw TypeScript or JavaScript source code string to analyze.
150
150
  * @returns An array of {@link RouteInfo} objects representing all discovered routes.
151
151
  */
152
- declare function extractRoutes(code: string): RouteInfo[];
152
+ export declare function extractRoutes(code: string): RouteInfo[];
153
153
  /**
154
154
  * Extracts every `@Controller`-decorated class from the given source code,
155
155
  * regardless of whether it declares HTTP method routes.
@@ -162,21 +162,21 @@ declare function extractRoutes(code: string): RouteInfo[];
162
162
  * @param code - The raw TypeScript or JavaScript source code string to analyze.
163
163
  * @returns An array of {@link ServiceInfo} objects for all discovered controller classes.
164
164
  */
165
- declare function extractControllers(code: string): ServiceInfo[];
165
+ export declare function extractControllers(code: string): ServiceInfo[];
166
166
  /**
167
167
  * Extracts all `@Injectable`-decorated class definitions from the given source code.
168
168
  *
169
169
  * @param code - The raw TypeScript or JavaScript source code string to analyze.
170
170
  * @returns An array of {@link ServiceInfo} objects for all discovered injectable classes.
171
171
  */
172
- declare function extractServices(code: string): ServiceInfo[];
172
+ export declare function extractServices(code: string): ServiceInfo[];
173
173
  /**
174
174
  * Extracts all class definitions that extend `BaseMiddleware` from the given source code.
175
175
  *
176
176
  * @param code - The raw TypeScript or JavaScript source code string to analyze.
177
177
  * @returns An array of {@link MiddlewareInfo} objects for all discovered middleware classes.
178
178
  */
179
- declare function extractMiddlewares(code: string): MiddlewareInfo[];
179
+ export declare function extractMiddlewares(code: string): MiddlewareInfo[];
180
180
  //#endregion
181
181
  //#region src/Project.d.ts
182
182
  /**
@@ -185,7 +185,7 @@ declare function extractMiddlewares(code: string): MiddlewareInfo[];
185
185
  * `baseDirs` are the project source roots (e.g. `src/`). The remaining options
186
186
  * name the subdirectories scanned within each base root.
187
187
  */
188
- interface ScanProjectOptions {
188
+ export interface ScanProjectOptions {
189
189
  /** Project source roots to scan within. */
190
190
  baseDirs: string[];
191
191
  /** Subdirectory holding API controllers. Defaults to `api`. */
@@ -206,7 +206,7 @@ interface ScanProjectOptions {
206
206
  * @param options - Where to scan. See {@link ScanProjectOptions}.
207
207
  * @returns The discovered routes with resolved imports.
208
208
  */
209
- declare function getRoutes(options: ScanProjectOptions): Promise<RouteInfo[]>;
209
+ export declare function getRoutes(options: ScanProjectOptions): Promise<RouteInfo[]>;
210
210
  /**
211
211
  * Scans the configured service directories for `@Injectable` classes and returns
212
212
  * every service with its `import` resolved to the class's real file path.
@@ -214,7 +214,7 @@ declare function getRoutes(options: ScanProjectOptions): Promise<RouteInfo[]>;
214
214
  * @param options - Where to scan. See {@link ScanProjectOptions}.
215
215
  * @returns The discovered services with resolved imports.
216
216
  */
217
- declare function getServices(options: ScanProjectOptions): Promise<ServiceInfo[]>;
217
+ export declare function getServices(options: ScanProjectOptions): Promise<ServiceInfo[]>;
218
218
  /**
219
219
  * Scans the middleware directory for `BaseMiddleware` subclasses and returns
220
220
  * every middleware with its `import` resolved to the class's real file path.
@@ -222,7 +222,7 @@ declare function getServices(options: ScanProjectOptions): Promise<ServiceInfo[]
222
222
  * @param options - Where to scan. See {@link ScanProjectOptions}.
223
223
  * @returns The discovered middleware with resolved imports.
224
224
  */
225
- declare function getMiddlewares(options: ScanProjectOptions): Promise<MiddlewareInfo[]>;
225
+ export declare function getMiddlewares(options: ScanProjectOptions): Promise<MiddlewareInfo[]>;
226
226
  /**
227
227
  * Convenience wrapper that scans routes, services and middleware in one call.
228
228
  *
@@ -232,7 +232,7 @@ declare function getMiddlewares(options: ScanProjectOptions): Promise<Middleware
232
232
  * @param options - Where to scan. See {@link ScanProjectOptions}.
233
233
  * @returns The discovered routes, deduplicated services, and middleware.
234
234
  */
235
- declare function scanProject(options: ScanProjectOptions): Promise<{
235
+ export declare function scanProject(options: ScanProjectOptions): Promise<{
236
236
  routes: RouteInfo[];
237
237
  services: ServiceInfo[];
238
238
  middlewares: MiddlewareInfo[];
@@ -240,7 +240,7 @@ declare function scanProject(options: ScanProjectOptions): Promise<{
240
240
  /**
241
241
  * Options for {@link scanSource}.
242
242
  */
243
- interface ScanSourceOptions {
243
+ export interface ScanSourceOptions {
244
244
  /** Directories whose entire file tree is scanned for decorated classes. */
245
245
  dirs: string[];
246
246
  /** Optional logger forwarded to the underlying scanner. */
@@ -263,7 +263,7 @@ interface ScanSourceOptions {
263
263
  * @param options - Directories to scan. See {@link ScanSourceOptions}.
264
264
  * @returns The discovered controllers, HTTP routes, deduplicated services, and middleware, all with resolved imports.
265
265
  */
266
- declare function scanSource(options: ScanSourceOptions): Promise<{
266
+ export declare function scanSource(options: ScanSourceOptions): Promise<{
267
267
  controllers: ServiceInfo[];
268
268
  routes: RouteInfo[];
269
269
  services: ServiceInfo[];
@@ -274,7 +274,7 @@ declare function scanSource(options: ScanSourceOptions): Promise<{
274
274
  /**
275
275
  * Glob pattern matching every source file extension the scanner understands.
276
276
  */
277
- declare const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
277
+ export declare const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
278
278
  /**
279
279
  * Scans a single base directory for files inside the named subdirectory.
280
280
  *
@@ -287,7 +287,7 @@ declare const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
287
287
  * @param logger - Optional logger used to warn when `<dir>/<name>` is not a directory.
288
288
  * @returns A sorted list of discovered files.
289
289
  */
290
- declare function scanDir(dir: string, name: string, logger?: ScanLogger): Promise<FileInfo[]>;
290
+ export declare function scanDir(dir: string, name: string, logger?: ScanLogger): Promise<FileInfo[]>;
291
291
  /**
292
292
  * Scans every base directory for files inside the named subdirectory.
293
293
  *
@@ -296,7 +296,7 @@ declare function scanDir(dir: string, name: string, logger?: ScanLogger): Promis
296
296
  * @param logger - Optional logger forwarded to {@link scanDir}.
297
297
  * @returns The flattened list of discovered files across all base directories.
298
298
  */
299
- declare function scanFiles(baseDirs: string[], name: string, logger?: ScanLogger): Promise<FileInfo[]>;
299
+ export declare function scanFiles(baseDirs: string[], name: string, logger?: ScanLogger): Promise<FileInfo[]>;
300
300
  //#endregion
301
301
  //#region src/Transform.d.ts
302
302
  /**
@@ -309,21 +309,21 @@ declare function scanFiles(baseDirs: string[], name: string, logger?: ScanLogger
309
309
  * @param file - File info (path and fullPath) to analyze.
310
310
  * @returns A list of {@link RouteInfo} for every route in the file.
311
311
  */
312
- declare function transformRoute(file: FileInfo): Promise<RouteInfo[]>;
312
+ export declare function transformRoute(file: FileInfo): Promise<RouteInfo[]>;
313
313
  /**
314
314
  * Reads a file from disk and returns all `@Injectable`-decorated classes found within it.
315
315
  *
316
316
  * @param file - File info (path and fullPath) to analyze.
317
317
  * @returns A list of {@link ServiceInfo} for every injectable class in the file.
318
318
  */
319
- declare function transformService(file: FileInfo): Promise<ServiceInfo[]>;
319
+ export declare function transformService(file: FileInfo): Promise<ServiceInfo[]>;
320
320
  /**
321
321
  * Reads a file from disk and returns all classes extending `BaseMiddleware` found within it.
322
322
  *
323
323
  * @param file - File info (path and fullPath) to analyze.
324
324
  * @returns A list of {@link MiddlewareInfo} for every middleware class in the file.
325
325
  */
326
- declare function transformMiddleware(file: FileInfo): Promise<MiddlewareInfo[]>;
326
+ export declare function transformMiddleware(file: FileInfo): Promise<MiddlewareInfo[]>;
327
327
  /**
328
328
  * Replaces the placeholder import source in each entry with the entry's real
329
329
  * absolute file path, producing import statements that load the actual module.
@@ -332,9 +332,8 @@ declare function transformMiddleware(file: FileInfo): Promise<MiddlewareInfo[]>;
332
332
  * @param placeholder - The placeholder module specifier to replace.
333
333
  * @returns The entries with resolved `import` statements.
334
334
  */
335
- declare function resolveImports<T extends {
335
+ export declare function resolveImports<T extends {
336
336
  import: string;
337
337
  fullPath: string;
338
338
  }>(entries: T[], placeholder: string): T[];
339
- //#endregion
340
- export { FileInfo, GLOB_SCAN_PATTERN, IMPORT_SOURCE, MIDDLEWARE_IMPORT_SOURCE, MiddlewareInfo, RouteInfo, SERVICE_IMPORT_SOURCE, ScanLogger, ScanProjectOptions, ScanSourceOptions, ServiceInfo, buildImport, extendsSuperClass, extractControllers, extractDecoratorArg, extractMiddlewares, extractParams, extractRoutes, extractServices, getClassNode, getMiddlewares, getRoutes, getServices, hasDecorator, normalizePath, resolveImports, scanDir, scanFiles, scanProject, scanSource, transformMiddleware, transformRoute, transformService };
339
+ //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercube/scan",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Source scanning and AST extraction utilities for the Vercube framework",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,7 +28,7 @@
28
28
  "framework"
29
29
  ],
30
30
  "dependencies": {
31
- "oxc-parser": "0.144.0",
31
+ "oxc-parser": "0.151.0",
32
32
  "pathe": "2.0.3",
33
33
  "tinyglobby": "0.2.17"
34
34
  },