nestjs-docfy 0.1.3 → 0.2.0

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 (40) hide show
  1. package/README.md +112 -32
  2. package/dist/cli/detect-project.d.ts +13 -0
  3. package/dist/cli/detect-project.js +318 -0
  4. package/dist/cli/detect-project.js.map +1 -0
  5. package/dist/cli/errors.d.ts +15 -0
  6. package/dist/cli/errors.js +26 -0
  7. package/dist/cli/errors.js.map +1 -0
  8. package/dist/cli/extract-methods.d.ts +34 -0
  9. package/dist/cli/extract-methods.js +171 -0
  10. package/dist/cli/extract-methods.js.map +1 -0
  11. package/dist/cli/generate-file.d.ts +11 -0
  12. package/dist/cli/generate-file.js +127 -0
  13. package/dist/cli/generate-file.js.map +1 -0
  14. package/dist/cli/index.d.ts +2 -0
  15. package/dist/cli/index.js +130 -0
  16. package/dist/cli/index.js.map +1 -0
  17. package/dist/cli/logger.d.ts +5 -0
  18. package/dist/cli/logger.js +48 -0
  19. package/dist/cli/logger.js.map +1 -0
  20. package/dist/cli/merge-docs.d.ts +19 -0
  21. package/dist/cli/merge-docs.js +87 -0
  22. package/dist/cli/merge-docs.js.map +1 -0
  23. package/dist/cli/parse-args.d.ts +42 -0
  24. package/dist/cli/parse-args.js +85 -0
  25. package/dist/cli/parse-args.js.map +1 -0
  26. package/dist/cli/project-types.d.ts +18 -0
  27. package/dist/cli/project-types.js +3 -0
  28. package/dist/cli/project-types.js.map +1 -0
  29. package/dist/cli/resolve-tsconfig.d.ts +5 -0
  30. package/dist/cli/resolve-tsconfig.js +39 -0
  31. package/dist/cli/resolve-tsconfig.js.map +1 -0
  32. package/dist/cli/scan-controllers.d.ts +24 -0
  33. package/dist/cli/scan-controllers.js +157 -0
  34. package/dist/cli/scan-controllers.js.map +1 -0
  35. package/dist/cli/writer.d.ts +25 -0
  36. package/dist/cli/writer.js +115 -0
  37. package/dist/cli/writer.js.map +1 -0
  38. package/dist/docs.d.ts +4 -4
  39. package/dist/docs.js.map +1 -1
  40. package/package.json +11 -2
package/README.md CHANGED
@@ -142,47 +142,50 @@ export class UsersController {
142
142
  }
143
143
  ```
144
144
 
145
- ### 3. Create the companion docs file
145
+ ### 3. Generate the companion docs files
146
146
 
147
- Name it exactly like the controller, replacing `.controller.ts` with `.controller.docs.ts`:
147
+ Run the CLI to scan your project and generate a pre-filled `*.controller.docs.ts` for every controller:
148
148
 
149
- ```
150
- src/users/users.controller.ts ← your controller
151
- src/users/users.controller.docs.ts ← documentation goes here
149
+ ```bash
150
+ npx nestjs-docfy generate
152
151
  ```
153
152
 
153
+ This produces files like:
154
+
154
155
  ```ts
155
- // users.controller.docs.ts
156
- import { HttpStatus } from '@nestjs/common';
157
- import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
158
- import { UsersController } from './users.controller';
159
- import { UserEntity } from './user.entity';
160
- import { CreateUserDto } from './dto/create-user.dto';
156
+ // users.controller.docs.ts (generated — fill in the arrays)
161
157
  import { docs } from 'nestjs-docfy';
158
+ import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
159
+ import { UsersController } from './users.controller';
162
160
 
163
161
  docs(UsersController, {
164
- classDecorators: [ApiTags('users')],
162
+ classDecorators: [
163
+ // ApiTags('users'),
164
+ ],
165
165
  methods: {
166
+ // GET /users → async findAll(): Promise<UserEntity[]>
166
167
  findAll: [
167
- ApiOperation({ summary: 'List all users' }),
168
- ApiResponse({ status: HttpStatus.OK, type: [UserEntity] }),
168
+ // ApiOperation({ summary: '' }),
169
+ // ApiResponse({ status: 200, type: [UserEntity] }),
169
170
  ],
171
+
172
+ // GET /:id → async findOne(id: string): Promise<UserEntity>
170
173
  findOne: [
171
- ApiOperation({ summary: 'Get a user by ID' }),
172
- ApiParam({ name: 'id', description: 'User UUID' }),
173
- ApiResponse({ status: HttpStatus.OK, type: UserEntity }),
174
- ApiResponse({ status: HttpStatus.NOT_FOUND, description: 'User not found' }),
175
- ],
176
- create: [
177
- ApiOperation({ summary: 'Create a user' }),
178
- ApiBody({ type: CreateUserDto }),
179
- ApiResponse({ status: HttpStatus.CREATED, type: UserEntity }),
180
- ApiResponse({ status: HttpStatus.BAD_REQUEST, description: 'Invalid input' }),
174
+ // ApiOperation({ summary: '' }),
175
+ // ApiResponse({ status: 200, type: UserEntity }),
176
+ // ApiResponse({ status: 404 }),
181
177
  ],
182
178
  },
183
179
  });
184
180
  ```
185
181
 
182
+ Or create the file manually following the same convention:
183
+
184
+ ```text
185
+ src/users/users.controller.ts ← your controller
186
+ src/users/users.controller.docs.ts ← documentation goes here
187
+ ```
188
+
186
189
  ### 4. Keep `main.ts` unchanged
187
190
 
188
191
  `DocfyModule` applies documentation metadata synchronously during module initialization, before `SwaggerModule.createDocument` is called. No changes to your bootstrap function are needed.
@@ -198,14 +201,77 @@ async function bootstrap() {
198
201
  }
199
202
  ```
200
203
 
204
+ ## CLI — `nestjs-docfy generate`
205
+
206
+ Scans your project for NestJS controllers using **static analysis only** (no code execution) and generates companion `*.controller.docs.ts` files with every method pre-filled and ready to annotate.
207
+
208
+ ### Basic usage
209
+
210
+ ```bash
211
+ # Auto-detect project type and generate all docs files
212
+ npx nestjs-docfy generate
213
+
214
+ # Preview what would be generated without writing anything
215
+ npx nestjs-docfy generate --dry-run
216
+
217
+ # Add new methods to existing docs files without touching decorated ones
218
+ npx nestjs-docfy generate --force
219
+ ```
220
+
221
+ ### Options
222
+
223
+ | Option | Default | Description |
224
+ | ------------------- | ------------------------- | ----------------------------------------------------------------- |
225
+ | `--root <path>` | `.` | Project root directory |
226
+ | `--tsconfig <path>` | auto-detected | Path to `tsconfig.json` |
227
+ | `--pattern <glob>` | `**/*.controller.ts` | Glob pattern to find controllers |
228
+ | `--out <path>` | alongside each controller | Output directory for generated files |
229
+ | `--force` | `false` | Merge new methods into existing docs files (preserves user edits) |
230
+ | `--dry-run` | `false` | Print what would be generated without writing files |
231
+ | `--quiet` | `false` | Suppress all output except errors (CI-friendly) |
232
+ | `--format` | `ts` | Output format: `ts` or `js` |
233
+
234
+ ### Project types supported
235
+
236
+ The CLI auto-detects your project layout — no configuration needed:
237
+
238
+ | Layout | Detected when |
239
+ | ----------------- | ------------------------------------------------------ |
240
+ | Simple project | `tsconfig.json` at root, no monorepo markers |
241
+ | NX Monorepo | `nx.json` present |
242
+ | Nest CLI Monorepo | `nest-cli.json` with `"monorepo": true` |
243
+ | Generic Monorepo | `packages/` or `apps/` with sub-`package.json` files |
244
+
245
+ ### Recommended script
246
+
247
+ Add to your `package.json`:
248
+
249
+ ```json
250
+ "scripts": {
251
+ "docs:generate": "nestjs-docfy generate"
252
+ }
253
+ ```
254
+
255
+ Then run:
256
+
257
+ ```bash
258
+ npm run docs:generate
259
+ ```
260
+
261
+ ### Idempotency and `--force`
262
+
263
+ Without `--force`: running `generate` twice is safe — existing docs files are skipped entirely.
264
+
265
+ With `--force`: the CLI merges only **new** methods (methods added to the controller since the docs file was last generated). User-edited decorator arrays are preserved. This makes `--force` safe to run after adding endpoints.
266
+
201
267
  ## API reference
202
268
 
203
269
  ### `DocfyModule.forRoot(options?)`
204
270
 
205
271
  Registers the module and loads all companion docs files for controllers marked with `@WithDocs()`.
206
272
 
207
- | Option | Type | Default | Description |
208
- |---|---|---|---|
273
+ | Option | Type | Default | Description |
274
+ | -------- | --------- | ------- | ----------------------------------------------------------------------------------------------------------- |
209
275
  | `strict` | `boolean` | `false` | Throw at startup if a controller has `@WithDocs()` but no companion docs file is found. Recommended for CI. |
210
276
 
211
277
  ```ts
@@ -243,18 +309,30 @@ const hasDocs = Reflect.getMetadata(DOCFY_MARKER, ProductsController) === true;
243
309
  Applies Swagger decorators to a controller class from outside its file.
244
310
  Call this at the top level of a `*.controller.docs.ts` file — it runs as a side effect on import.
245
311
 
312
+ The function is fully type-safe: `config.methods` only accepts keys that exist on the controller class. Typos are caught at compile time.
313
+
314
+ ```ts
315
+ docs(UsersController, {
316
+ classDecorators: [ApiTags('users')],
317
+ methods: {
318
+ findAll: [...], // ✔ exists on UsersController
319
+ typoMethod: [...] // ✖ TypeScript error
320
+ },
321
+ });
322
+ ```
323
+
246
324
  **`config.classDecorators`** — `ClassDecorator[]` — decorators applied to the class constructor (e.g. `ApiTags`).
247
325
 
248
- **`config.methods`** — `Record<string, MethodDecorator[]>` — decorators per method name. Each decorator is called exactly as TypeScript would call it if it were written inline.
326
+ **`config.methods`** — `Partial<Record<keyof T, MethodDecorator[]>>` — decorators per method name. Each decorator is called exactly as TypeScript would call it if it were written inline.
249
327
 
250
- If a method name in `config.methods` does not exist on the controller, a warning is logged and that entry is skipped — the rest of the docs file still applies.
328
+ If a method name in `config.methods` does not exist on the controller at runtime, a warning is logged and that entry is skipped — the rest of the docs file still applies.
251
329
 
252
330
  ## File naming convention
253
331
 
254
- | Controller file | Companion docs file |
255
- |---|---|
256
- | `users.controller.ts` | `users.controller.docs.ts` |
257
- | `users.controller.js` (compiled) | `users.controller.docs.js` |
332
+ | Controller file | Companion docs file |
333
+ | --------------------------------- | ---------------------------- |
334
+ | `users.controller.ts` | `users.controller.docs.ts` |
335
+ | `users.controller.js` (compiled) | `users.controller.docs.js` |
258
336
 
259
337
  Discovery is automatic. `DocfyModule` locates each controller's source file via Node's module cache (`require.cache`) and resolves the companion path. This works identically in both `ts-node` (development) and compiled `dist/` (production).
260
338
 
@@ -278,6 +356,8 @@ NestJS calls `NestFactory.create()` to build the dependency graph and module ins
278
356
 
279
357
  By the time `SwaggerModule.createDocument()` scans for metadata, all of it is already in place.
280
358
 
359
+ The `generate` CLI uses **static analysis only** (`ts-morph`) — it reads TypeScript AST without executing any project code. All user-supplied paths and values are validated and sanitised before use.
360
+
281
361
  ## License
282
362
 
283
363
  MIT
@@ -0,0 +1,13 @@
1
+ import type { ProjectContext } from './project-types';
2
+ /**
3
+ * Detects the project type and returns a ProjectContext with one entry per
4
+ * compilable unit. All paths in the result are absolute and validated to
5
+ * stay within `root`.
6
+ *
7
+ * Detection order (first match wins):
8
+ * 1. nx.json present → NX monorepo
9
+ * 2. nest-cli.json with monorepo:true → Nest CLI monorepo
10
+ * 3. packages/ or apps/ with sub-package.json → generic monorepo
11
+ * 4. fallback → simple project
12
+ */
13
+ export declare function detectProject(root: string, tsconfigOverride?: string): ProjectContext;
@@ -0,0 +1,318 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.detectProject = detectProject;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const parse_args_1 = require("./parse-args");
10
+ const errors_1 = require("./errors");
11
+ // ---------------------------------------------------------------------------
12
+ // Safe JSON reader — never throws on missing file, always validates path
13
+ // ---------------------------------------------------------------------------
14
+ function safeReadJson(filePath, root) {
15
+ try {
16
+ (0, parse_args_1.assertWithinRoot)(filePath, root);
17
+ }
18
+ catch {
19
+ return null;
20
+ }
21
+ try {
22
+ const raw = fs_1.default.readFileSync(filePath, 'utf8');
23
+ return JSON.parse(raw);
24
+ }
25
+ catch {
26
+ return null;
27
+ }
28
+ }
29
+ function exists(filePath) {
30
+ try {
31
+ fs_1.default.accessSync(filePath);
32
+ return true;
33
+ }
34
+ catch {
35
+ return false;
36
+ }
37
+ }
38
+ // ---------------------------------------------------------------------------
39
+ // Tsconfig candidate resolution (project-type-agnostic helper)
40
+ // ---------------------------------------------------------------------------
41
+ const TSCONFIG_CANDIDATES = [
42
+ 'tsconfig.build.json',
43
+ 'tsconfig.app.json',
44
+ 'tsconfig.json',
45
+ ];
46
+ function findTsconfig(appRoot, projectRoot) {
47
+ for (const candidate of TSCONFIG_CANDIDATES) {
48
+ const resolved = path_1.default.join(appRoot, candidate);
49
+ try {
50
+ (0, parse_args_1.assertWithinRoot)(resolved, projectRoot);
51
+ if (exists(resolved))
52
+ return resolved;
53
+ }
54
+ catch {
55
+ continue;
56
+ }
57
+ }
58
+ throw new errors_1.ConfigNotFoundError(`No tsconfig found in "${appRoot}". Tried: ${TSCONFIG_CANDIDATES.join(', ')}`);
59
+ }
60
+ // ---------------------------------------------------------------------------
61
+ // Strategy: simple project
62
+ // ---------------------------------------------------------------------------
63
+ function detectSimple(root, tsconfigOverride) {
64
+ const tsconfig = tsconfigOverride ?? findTsconfig(root, root);
65
+ return {
66
+ kind: 'simple',
67
+ root,
68
+ apps: [
69
+ {
70
+ name: path_1.default.basename(root),
71
+ root,
72
+ tsconfig,
73
+ controllerGlob: '**/*.controller.ts',
74
+ },
75
+ ],
76
+ };
77
+ }
78
+ function detectNx(root, tsconfigOverride) {
79
+ // nx.json signals an NX workspace; project roots come from project.json files
80
+ // or workspace.json / nx.json projects map (NX >=14 uses project.json per-project)
81
+ const apps = [];
82
+ // Walk known app/lib dirs: apps/, libs/, packages/
83
+ const scanDirs = ['apps', 'libs', 'packages'].map((d) => path_1.default.join(root, d));
84
+ for (const scanDir of scanDirs) {
85
+ if (!exists(scanDir))
86
+ continue;
87
+ let entries;
88
+ try {
89
+ entries = fs_1.default.readdirSync(scanDir);
90
+ }
91
+ catch {
92
+ continue;
93
+ }
94
+ for (const entry of entries) {
95
+ const appRoot = path_1.default.join(scanDir, entry);
96
+ // Validate each resolved path stays within project root
97
+ try {
98
+ (0, parse_args_1.assertWithinRoot)(appRoot, root);
99
+ }
100
+ catch {
101
+ continue;
102
+ }
103
+ let stat;
104
+ try {
105
+ stat = fs_1.default.statSync(appRoot);
106
+ }
107
+ catch {
108
+ continue;
109
+ }
110
+ if (!stat.isDirectory())
111
+ continue;
112
+ const projectJson = safeReadJson(path_1.default.join(appRoot, 'project.json'), root);
113
+ if (!projectJson)
114
+ continue;
115
+ // Resolve tsconfig: prefer build target tsConfig, then fallback candidates
116
+ let tsconfig;
117
+ const buildTsConfig = projectJson.targets?.build?.options?.tsConfig;
118
+ if (buildTsConfig) {
119
+ const resolved = path_1.default.resolve(root, buildTsConfig);
120
+ try {
121
+ (0, parse_args_1.assertWithinRoot)(resolved, root);
122
+ if (exists(resolved))
123
+ tsconfig = resolved;
124
+ }
125
+ catch {
126
+ // untrusted path — fall through to candidates
127
+ }
128
+ }
129
+ if (!tsconfig) {
130
+ try {
131
+ tsconfig = tsconfigOverride ?? findTsconfig(appRoot, root);
132
+ }
133
+ catch {
134
+ continue; // skip apps without any tsconfig
135
+ }
136
+ }
137
+ apps.push({
138
+ name: projectJson.name ?? entry,
139
+ root: appRoot,
140
+ tsconfig,
141
+ controllerGlob: '**/*.controller.ts',
142
+ });
143
+ }
144
+ }
145
+ // Also check workspace.json for older NX layouts
146
+ if (apps.length === 0) {
147
+ const workspaceJson = safeReadJson(path_1.default.join(root, 'workspace.json'), root);
148
+ if (workspaceJson?.projects) {
149
+ for (const [name, value] of Object.entries(workspaceJson.projects)) {
150
+ const appRelRoot = typeof value === 'string' ? value : value.root;
151
+ const appRoot = path_1.default.resolve(root, appRelRoot);
152
+ try {
153
+ (0, parse_args_1.assertWithinRoot)(appRoot, root);
154
+ }
155
+ catch {
156
+ continue;
157
+ }
158
+ let tsconfig;
159
+ try {
160
+ tsconfig = tsconfigOverride ?? findTsconfig(appRoot, root);
161
+ }
162
+ catch {
163
+ continue;
164
+ }
165
+ apps.push({ name, root: appRoot, tsconfig, controllerGlob: '**/*.controller.ts' });
166
+ }
167
+ }
168
+ }
169
+ if (apps.length === 0) {
170
+ // Fallback: treat as simple if NX layout is non-standard
171
+ return detectSimple(root, tsconfigOverride);
172
+ }
173
+ return { kind: 'nx', root, apps };
174
+ }
175
+ function detectNestCliMonorepo(root, nestCliJson, tsconfigOverride) {
176
+ const apps = [];
177
+ for (const [name, config] of Object.entries(nestCliJson.projects ?? {})) {
178
+ const appRelRoot = config.root ?? name;
179
+ const appRoot = path_1.default.resolve(root, appRelRoot);
180
+ try {
181
+ (0, parse_args_1.assertWithinRoot)(appRoot, root);
182
+ }
183
+ catch {
184
+ continue;
185
+ }
186
+ let tsconfig;
187
+ const tsConfigPath = config.compilerOptions?.tsConfigPath;
188
+ if (tsConfigPath) {
189
+ const resolved = path_1.default.resolve(root, tsConfigPath);
190
+ try {
191
+ (0, parse_args_1.assertWithinRoot)(resolved, root);
192
+ if (exists(resolved))
193
+ tsconfig = resolved;
194
+ }
195
+ catch {
196
+ // untrusted — fall through
197
+ }
198
+ }
199
+ if (!tsconfig) {
200
+ try {
201
+ tsconfig = tsconfigOverride ?? findTsconfig(appRoot, root);
202
+ }
203
+ catch {
204
+ continue;
205
+ }
206
+ }
207
+ apps.push({
208
+ name,
209
+ root: appRoot,
210
+ tsconfig,
211
+ controllerGlob: '**/*.controller.ts',
212
+ });
213
+ }
214
+ if (apps.length === 0) {
215
+ return detectSimple(root, tsconfigOverride);
216
+ }
217
+ return { kind: 'nest-cli-monorepo', root, apps };
218
+ }
219
+ // ---------------------------------------------------------------------------
220
+ // Strategy: generic monorepo (packages/ with sub-package.json)
221
+ // ---------------------------------------------------------------------------
222
+ function detectGenericMonorepo(root, tsconfigOverride) {
223
+ const apps = [];
224
+ const scanDirs = ['packages', 'apps', 'services'].map((d) => path_1.default.join(root, d));
225
+ for (const scanDir of scanDirs) {
226
+ if (!exists(scanDir))
227
+ continue;
228
+ let entries;
229
+ try {
230
+ entries = fs_1.default.readdirSync(scanDir);
231
+ }
232
+ catch {
233
+ continue;
234
+ }
235
+ for (const entry of entries) {
236
+ const appRoot = path_1.default.join(scanDir, entry);
237
+ try {
238
+ (0, parse_args_1.assertWithinRoot)(appRoot, root);
239
+ }
240
+ catch {
241
+ continue;
242
+ }
243
+ let stat;
244
+ try {
245
+ stat = fs_1.default.statSync(appRoot);
246
+ }
247
+ catch {
248
+ continue;
249
+ }
250
+ if (!stat.isDirectory())
251
+ continue;
252
+ // Only treat as an app if it has its own package.json
253
+ if (!exists(path_1.default.join(appRoot, 'package.json')))
254
+ continue;
255
+ let tsconfig;
256
+ try {
257
+ tsconfig = tsconfigOverride ?? findTsconfig(appRoot, root);
258
+ }
259
+ catch {
260
+ continue;
261
+ }
262
+ apps.push({
263
+ name: entry,
264
+ root: appRoot,
265
+ tsconfig,
266
+ controllerGlob: '**/*.controller.ts',
267
+ });
268
+ }
269
+ }
270
+ if (apps.length === 0) {
271
+ return detectSimple(root, tsconfigOverride);
272
+ }
273
+ return { kind: 'generic-monorepo', root, apps };
274
+ }
275
+ // ---------------------------------------------------------------------------
276
+ // Public entry point
277
+ // ---------------------------------------------------------------------------
278
+ /**
279
+ * Detects the project type and returns a ProjectContext with one entry per
280
+ * compilable unit. All paths in the result are absolute and validated to
281
+ * stay within `root`.
282
+ *
283
+ * Detection order (first match wins):
284
+ * 1. nx.json present → NX monorepo
285
+ * 2. nest-cli.json with monorepo:true → Nest CLI monorepo
286
+ * 3. packages/ or apps/ with sub-package.json → generic monorepo
287
+ * 4. fallback → simple project
288
+ */
289
+ function detectProject(root, tsconfigOverride) {
290
+ const absRoot = path_1.default.resolve(root);
291
+ // 1. NX
292
+ if (exists(path_1.default.join(absRoot, 'nx.json'))) {
293
+ return detectNx(absRoot, tsconfigOverride);
294
+ }
295
+ // 2. Nest CLI monorepo
296
+ const nestCli = safeReadJson(path_1.default.join(absRoot, 'nest-cli.json'), absRoot);
297
+ if (nestCli?.monorepo === true && nestCli.projects) {
298
+ return detectNestCliMonorepo(absRoot, nestCli, tsconfigOverride);
299
+ }
300
+ // 3. Generic monorepo
301
+ const hasSubPackages = ['packages', 'apps', 'services'].some((dir) => {
302
+ const d = path_1.default.join(absRoot, dir);
303
+ if (!exists(d))
304
+ return false;
305
+ try {
306
+ return fs_1.default.readdirSync(d).some((entry) => exists(path_1.default.join(d, entry, 'package.json')));
307
+ }
308
+ catch {
309
+ return false;
310
+ }
311
+ });
312
+ if (hasSubPackages) {
313
+ return detectGenericMonorepo(absRoot, tsconfigOverride);
314
+ }
315
+ // 4. Simple
316
+ return detectSimple(absRoot, tsconfigOverride);
317
+ }
318
+ //# sourceMappingURL=detect-project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect-project.js","sourceRoot":"","sources":["../../src/cli/detect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O,CACR,CAAC;IACF,IAAI,OAAO,EAAE,QAAQ,KAAK,IAAI,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACnD,OAAO,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC;IACnE,CAAC;IAED,sBAAsB;IACtB,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;QACnE,MAAM,CAAC,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QAC7B,IAAI,CAAC;YACH,OAAO,YAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CACtC,MAAM,CAAC,cAAI,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAC5C,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC,CAAC,CAAC;IACH,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAC1D,CAAC;IAED,YAAY;IACZ,OAAO,YAAY,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,15 @@
1
+ export declare const enum CliExitCode {
2
+ Ok = 0,
3
+ PartialError = 1,
4
+ Fatal = 2
5
+ }
6
+ export declare class CliError extends Error {
7
+ readonly exitCode: CliExitCode;
8
+ constructor(message: string, exitCode?: CliExitCode);
9
+ }
10
+ export declare class PathTraversalError extends CliError {
11
+ constructor(offendingPath: string);
12
+ }
13
+ export declare class ConfigNotFoundError extends CliError {
14
+ constructor(detail: string);
15
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigNotFoundError = exports.PathTraversalError = exports.CliError = void 0;
4
+ class CliError extends Error {
5
+ constructor(message, exitCode = 2 /* CliExitCode.Fatal */) {
6
+ super(message);
7
+ this.exitCode = exitCode;
8
+ this.name = 'CliError';
9
+ }
10
+ }
11
+ exports.CliError = CliError;
12
+ class PathTraversalError extends CliError {
13
+ constructor(offendingPath) {
14
+ super(`Path traversal detected: "${offendingPath}" resolves outside the project root.`, 2 /* CliExitCode.Fatal */);
15
+ this.name = 'PathTraversalError';
16
+ }
17
+ }
18
+ exports.PathTraversalError = PathTraversalError;
19
+ class ConfigNotFoundError extends CliError {
20
+ constructor(detail) {
21
+ super(`Could not resolve tsconfig: ${detail}`, 2 /* CliExitCode.Fatal */);
22
+ this.name = 'ConfigNotFoundError';
23
+ }
24
+ }
25
+ exports.ConfigNotFoundError = ConfigNotFoundError;
26
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/cli/errors.ts"],"names":[],"mappings":";;;AAMA,MAAa,QAAS,SAAQ,KAAK;IACjC,YACE,OAAe,EACC,oCAAyC;QAEzD,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,aAAQ,GAAR,QAAQ,CAAiC;QAGzD,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AARD,4BAQC;AAED,MAAa,kBAAmB,SAAQ,QAAQ;IAC9C,YAAY,aAAqB;QAC/B,KAAK,CACH,6BAA6B,aAAa,sCAAsC,4BAEjF,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AARD,gDAQC;AAED,MAAa,mBAAoB,SAAQ,QAAQ;IAC/C,YAAY,MAAc;QACxB,KAAK,CAAC,+BAA+B,MAAM,EAAE,4BAAoB,CAAC;QAClE,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AALD,kDAKC"}
@@ -0,0 +1,34 @@
1
+ import { ClassDeclaration } from 'ts-morph';
2
+ export interface ParamInfo {
3
+ name: string;
4
+ type: string;
5
+ nestDecorator: string | null;
6
+ }
7
+ export interface MethodInfo {
8
+ name: string;
9
+ httpDecorator: string | null;
10
+ httpPath: string | null;
11
+ params: ParamInfo[];
12
+ returnType: string;
13
+ isAsync: boolean;
14
+ isInherited: boolean;
15
+ inheritedFrom: string | null;
16
+ }
17
+ export interface ControllerInfo {
18
+ className: string;
19
+ filePath: string;
20
+ controllerPath: string | null;
21
+ methods: MethodInfo[];
22
+ hasDocsFile: boolean;
23
+ }
24
+ /**
25
+ * Extracts public, non-static methods from a controller class declaration.
26
+ * Marks inherited methods (from base classes) but still includes them.
27
+ * Private and protected methods are ignored.
28
+ */
29
+ export declare function extractMethods(cls: ClassDeclaration): MethodInfo[];
30
+ /**
31
+ * Extracts the path argument from @Controller('path').
32
+ * Returns null if the decorator is absent or has no string argument.
33
+ */
34
+ export declare function extractControllerPath(cls: ClassDeclaration): string | null;