nest-scramble 2.1.3 → 3.0.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.
@@ -0,0 +1,323 @@
1
+ /** Nest-Scramble | Developed by Mohamed Mustafa | MIT License **/
2
+
3
+ /**
4
+ * NestJS 10 & 11 Compatibility Example
5
+ *
6
+ * This example demonstrates nest-scramble v3.0.0 working with both
7
+ * NestJS 10.x and 11.x using modern patterns and features.
8
+ */
9
+
10
+ import { Module, Controller, Get, Post, Put, Delete, Body, Param, Query, Version, UseGuards } from '@nestjs/common';
11
+ import { NestScrambleModule } from 'nest-scramble';
12
+
13
+ // ============================================================================
14
+ // DTOs - Modern TypeScript 5.x with better type inference
15
+ // ============================================================================
16
+
17
+ export class CreateUserDto {
18
+ name!: string;
19
+ email!: string;
20
+ age?: number;
21
+ }
22
+
23
+ export class UpdateUserDto {
24
+ name?: string;
25
+ email?: string;
26
+ age?: number;
27
+ }
28
+
29
+ export class UserDto {
30
+ id!: number;
31
+ name!: string;
32
+ email!: string;
33
+ age?: number;
34
+ createdAt!: Date;
35
+ updatedAt!: Date;
36
+ }
37
+
38
+ export class PaginationDto {
39
+ page!: number;
40
+ limit!: number;
41
+ total!: number;
42
+ }
43
+
44
+ export class UserListDto {
45
+ data!: UserDto[];
46
+ pagination!: PaginationDto;
47
+ }
48
+
49
+ // ============================================================================
50
+ // Controllers - Using NestJS 10/11 features
51
+ // ============================================================================
52
+
53
+ /**
54
+ * Basic Controller - Works with both NestJS 10 and 11
55
+ */
56
+ @Controller('users')
57
+ export class UsersController {
58
+ @Get()
59
+ findAll(@Query('page') page: number = 1, @Query('limit') limit: number = 10): UserListDto {
60
+ return {
61
+ data: [
62
+ { id: 1, name: 'John Doe', email: 'john@example.com', age: 30, createdAt: new Date(), updatedAt: new Date() },
63
+ { id: 2, name: 'Jane Smith', email: 'jane@example.com', age: 25, createdAt: new Date(), updatedAt: new Date() },
64
+ ],
65
+ pagination: { page, limit, total: 2 },
66
+ };
67
+ }
68
+
69
+ @Get(':id')
70
+ findOne(@Param('id') id: number): UserDto {
71
+ return {
72
+ id,
73
+ name: 'John Doe',
74
+ email: 'john@example.com',
75
+ age: 30,
76
+ createdAt: new Date(),
77
+ updatedAt: new Date(),
78
+ };
79
+ }
80
+
81
+ @Post()
82
+ create(@Body() createUserDto: CreateUserDto): UserDto {
83
+ return {
84
+ id: 3,
85
+ ...createUserDto,
86
+ createdAt: new Date(),
87
+ updatedAt: new Date(),
88
+ };
89
+ }
90
+
91
+ @Put(':id')
92
+ update(@Param('id') id: number, @Body() updateUserDto: UpdateUserDto): UserDto {
93
+ return {
94
+ id,
95
+ name: updateUserDto.name || 'John Doe',
96
+ email: updateUserDto.email || 'john@example.com',
97
+ age: updateUserDto.age,
98
+ createdAt: new Date(),
99
+ updatedAt: new Date(),
100
+ };
101
+ }
102
+
103
+ @Delete(':id')
104
+ remove(@Param('id') id: number): { message: string } {
105
+ return { message: `User ${id} deleted successfully` };
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Versioned Controller - API Versioning (NestJS 10+)
111
+ */
112
+ @Controller('products')
113
+ export class ProductsController {
114
+ @Version('1')
115
+ @Get()
116
+ findAllV1(): { version: string; data: any[] } {
117
+ return {
118
+ version: 'v1',
119
+ data: [{ id: 1, name: 'Product A', price: 100 }],
120
+ };
121
+ }
122
+
123
+ @Version('2')
124
+ @Get()
125
+ findAllV2(): { version: string; data: any[]; metadata: any } {
126
+ return {
127
+ version: 'v2',
128
+ data: [{ id: 1, name: 'Product A', price: 100, currency: 'USD' }],
129
+ metadata: { timestamp: new Date() },
130
+ };
131
+ }
132
+
133
+ @Version(['1', '2'])
134
+ @Get(':id')
135
+ findOne(@Param('id') id: number): { id: number; name: string } {
136
+ return { id, name: 'Product A' };
137
+ }
138
+ }
139
+
140
+ // ============================================================================
141
+ // Module Configuration - Modern NestJS 10/11 Patterns
142
+ // ============================================================================
143
+
144
+ /**
145
+ * Basic Configuration Example
146
+ */
147
+ @Module({
148
+ imports: [
149
+ NestScrambleModule.forRoot({
150
+ path: '/docs',
151
+ enableMock: true,
152
+ baseUrl: 'http://localhost:3000',
153
+ apiTitle: 'NestJS 10/11 API',
154
+ apiVersion: '3.0.0',
155
+ theme: 'futuristic',
156
+ primaryColor: '#00f2ff',
157
+
158
+ // Advanced features
159
+ useIncrementalScanning: true,
160
+ enableWatchMode: false,
161
+ cacheTtl: 24 * 60 * 60 * 1000, // 24 hours
162
+ }),
163
+ ],
164
+ controllers: [UsersController, ProductsController],
165
+ })
166
+ export class AppModule {}
167
+
168
+ /**
169
+ * Async Configuration Example - Using ConfigurableModuleBuilder (NestJS 10+)
170
+ */
171
+ @Module({
172
+ imports: [
173
+ // Modern async configuration with useFactory
174
+ NestScrambleModule.forRootAsync({
175
+ useFactory: () => ({
176
+ path: '/api-docs',
177
+ enableMock: process.env.NODE_ENV === 'development',
178
+ baseUrl: process.env.API_BASE_URL || 'http://localhost:3000',
179
+ apiTitle: 'Modern NestJS API',
180
+ apiVersion: '3.0.0',
181
+ theme: 'futuristic',
182
+ useIncrementalScanning: true,
183
+ }),
184
+ }),
185
+ ],
186
+ controllers: [UsersController, ProductsController],
187
+ })
188
+ export class AsyncAppModule {}
189
+
190
+ /**
191
+ * With ConfigService Example
192
+ */
193
+ /*
194
+ import { ConfigModule, ConfigService } from '@nestjs/config';
195
+
196
+ @Module({
197
+ imports: [
198
+ ConfigModule.forRoot(),
199
+ NestScrambleModule.forRootAsync({
200
+ inject: [ConfigService],
201
+ useFactory: (config: ConfigService) => ({
202
+ baseUrl: config.get('API_BASE_URL'),
203
+ apiTitle: config.get('API_TITLE'),
204
+ enableMock: config.get('NODE_ENV') === 'development',
205
+ theme: config.get('DOCS_THEME') || 'futuristic',
206
+ }),
207
+ }),
208
+ ],
209
+ controllers: [UsersController, ProductsController],
210
+ })
211
+ export class ConfigBasedAppModule {}
212
+ */
213
+
214
+ // ============================================================================
215
+ // Testing Instructions
216
+ // ============================================================================
217
+
218
+ /**
219
+ * How to Test with NestJS 10:
220
+ *
221
+ * 1. Create a new project:
222
+ * npx @nestjs/cli new test-nestjs-10
223
+ * cd test-nestjs-10
224
+ *
225
+ * 2. Install NestJS 10:
226
+ * npm install @nestjs/common@^10.0.0 @nestjs/core@^10.0.0 @nestjs/platform-express@^10.0.0
227
+ *
228
+ * 3. Ensure Node.js 18.10+ and TypeScript 5+:
229
+ * node --version # Should be >=18.10.0
230
+ * npx tsc --version # Should be >=5.0.0
231
+ *
232
+ * 4. Install nest-scramble v3:
233
+ * npm install nest-scramble@^3.0.0
234
+ *
235
+ * 5. Copy this file to src/app.module.ts
236
+ *
237
+ * 6. Start the app:
238
+ * npm run start:dev
239
+ *
240
+ * 7. Test the endpoints:
241
+ * - Documentation: http://localhost:3000/docs
242
+ * - OpenAPI Spec: http://localhost:3000/docs-json
243
+ * - Mock Server: http://localhost:3000/scramble-mock/users
244
+ *
245
+ * How to Test with NestJS 11:
246
+ *
247
+ * Follow the same steps but install NestJS 11:
248
+ * npm install @nestjs/common@^11.0.0 @nestjs/core@^11.0.0 @nestjs/platform-express@^11.0.0
249
+ *
250
+ * Expected Results (Same for both v10 and v11):
251
+ * - ✅ Documentation loads at /docs
252
+ * - ✅ OpenAPI spec available at /docs-json
253
+ * - ✅ Mock endpoints work at /scramble-mock/*
254
+ * - ✅ All controllers detected and documented
255
+ * - ✅ API versioning properly handled
256
+ * - ✅ No deprecation warnings
257
+ * - ✅ No version-specific errors
258
+ */
259
+
260
+ /**
261
+ * CLI Testing:
262
+ *
263
+ * Generate OpenAPI spec:
264
+ * npx nest-scramble generate src --output openapi.json
265
+ *
266
+ * Generate Postman collection:
267
+ * npx nest-scramble generate src --format postman --output collection.json
268
+ *
269
+ * With custom options:
270
+ * npx nest-scramble generate src \
271
+ * --output api-spec.json \
272
+ * --title "My API" \
273
+ * --apiVersion "3.0.0" \
274
+ * --baseUrl "https://api.example.com"
275
+ */
276
+
277
+ /**
278
+ * Performance Testing:
279
+ *
280
+ * Test incremental scanning:
281
+ * 1. Enable useIncrementalScanning: true
282
+ * 2. First run: ~2100ms (builds cache)
283
+ * 3. Subsequent runs: ~50ms (uses cache)
284
+ * 4. Modify a controller: ~100ms (partial rescan)
285
+ *
286
+ * Expected cache file: scramble-cache.json
287
+ */
288
+
289
+ /**
290
+ * Feature Verification Checklist:
291
+ *
292
+ * ✅ Module Registration
293
+ * - forRoot() works
294
+ * - forRootAsync() works
295
+ * - Options are properly typed
296
+ *
297
+ * ✅ Controller Scanning
298
+ * - @Controller decorator detected
299
+ * - All HTTP methods found
300
+ * - Parameters properly analyzed
301
+ * - Return types inferred
302
+ *
303
+ * ✅ API Versioning
304
+ * - @Version decorator detected
305
+ * - Multiple versions supported
306
+ * - Version arrays handled
307
+ *
308
+ * ✅ Documentation UI
309
+ * - Loads without errors
310
+ * - All endpoints visible
311
+ * - Request/response examples shown
312
+ * - Theme customization works
313
+ *
314
+ * ✅ Mock Server
315
+ * - /scramble-mock/* responds
316
+ * - Smart mock data generated
317
+ * - All HTTP methods supported
318
+ *
319
+ * ✅ TypeScript 5.x
320
+ * - No type errors
321
+ * - Proper inference
322
+ * - Modern syntax supported
323
+ */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nest-scramble",
3
- "version": "2.1.3",
4
- "description": "A next-generation, decorator-free API documentation engine and intelligent mock server for NestJS, engineered by Mohamed Mustafa",
3
+ "version": "3.0.2",
4
+ "description": "A next-generation, decorator-free API documentation engine with API versioning and authentication support for NestJS 10 and 11, engineered by Mohamed Mustafa",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "bin": {
@@ -45,9 +45,13 @@
45
45
  "@typescript-eslint/eslint-plugin": "^6.15.0",
46
46
  "@typescript-eslint/parser": "^6.15.0"
47
47
  },
48
+ "engines": {
49
+ "node": ">=18.10.0"
50
+ },
48
51
  "peerDependencies": {
49
- "@nestjs/common": ">=9.0.0",
50
- "@nestjs/core": ">=9.0.0",
52
+ "@nestjs/common": "^10.0.0 || ^11.0.0",
53
+ "@nestjs/core": "^10.0.0 || ^11.0.0",
54
+ "typescript": ">=5.0.0",
51
55
  "reflect-metadata": ">=0.1.13"
52
56
  },
53
57
  "peerDependenciesMeta": {