metacoding 1.0.0 → 1.1.1
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/CHANGELOG.md +79 -42
- package/LICENSE +1 -1
- package/lib/commands/init.d.ts.map +1 -1
- package/lib/commands/init.js +1 -1
- package/lib/commands/init.js.map +1 -1
- package/lib/services/template-manager.d.ts +4 -1
- package/lib/services/template-manager.d.ts.map +1 -1
- package/lib/services/template-manager.js +129 -10
- package/lib/services/template-manager.js.map +1 -1
- package/lib/services/vscode.js +1 -1
- package/lib/services/vscode.js.map +1 -1
- package/package.json +12 -4
- package/templates/general/code-review.instructions.md +265 -0
- package/templates/general/{files/copilot-instructions.md.template → copilot-instructions.md} +97 -140
- package/templates/{python/files → general}/docs-update.instructions.md +45 -32
- package/templates/general/release.instructions.md +242 -0
- package/templates/general/test-runner.instructions.md +188 -0
- package/templates/node/nodejs.coding.instructions.md +249 -0
- package/templates/node/nodejs.docs.instructions.md +234 -0
- package/templates/node/nodejs.testing.instructions.md +373 -0
- package/templates/python/python.coding.instructions.md +339 -0
- package/templates/python/python.docs.instructions.md +1147 -0
- package/templates/python/python.testing.instructions.md +1074 -0
- package/templates/react/react.coding.instructions.md +695 -0
- package/templates/react/react.docs.instructions.md +427 -0
- package/templates/react/react.testing.instructions.md +193 -0
- package/templates/react/test-runner.instructions.md +135 -0
- package/templates/typescript/template.json +16 -0
- package/templates/typescript/typescript.coding.instructions.md +368 -0
- package/templates/typescript/typescript.docs.instructions.md +734 -0
- package/templates/typescript/typescript.testing.instructions.md +740 -0
- package/templates/general/files/code-review.instructions.md +0 -111
- package/templates/general/files/docs-update.instructions.md +0 -203
- package/templates/general/files/release.instructions.md +0 -72
- package/templates/general/files/test-runner.instructions.md +0 -107
- package/templates/node/files/code-review.instructions.md +0 -222
- package/templates/node/files/copilot-instructions.md.template +0 -391
- package/templates/node/files/docs-update.instructions.md +0 -203
- package/templates/node/files/release.instructions.md +0 -72
- package/templates/node/files/test-runner.instructions.md +0 -108
- package/templates/python/files/code-review.instructions.md +0 -215
- package/templates/python/files/copilot-instructions.md.template +0 -418
- package/templates/python/files/release.instructions.md +0 -72
- package/templates/python/files/test-runner.instructions.md +0 -108
- package/templates/react/files/code-review.instructions.md +0 -160
- package/templates/react/files/copilot-instructions.md.template +0 -472
- package/templates/react/files/docs-update.instructions.md +0 -203
- package/templates/react/files/release.instructions.md +0 -72
- package/templates/react/files/test-runner.instructions.md +0 -108
|
@@ -0,0 +1,734 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 'TypeScript/Node.js-specific documentation standards and JSDoc patterns'
|
|
3
|
+
applyTo: '**/*.{ts,js}'
|
|
4
|
+
language: 'typescript'
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# TypeScript/Node.js Documentation Standards
|
|
8
|
+
|
|
9
|
+
## JSDoc Documentation Standards
|
|
10
|
+
|
|
11
|
+
### Function Documentation
|
|
12
|
+
|
|
13
|
+
````typescript
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves user information by ID with caching support.
|
|
16
|
+
*
|
|
17
|
+
* This function first checks the cache for existing user data before
|
|
18
|
+
* making a database query. If the user is not found in cache, it queries
|
|
19
|
+
* the database and stores the result in cache for future requests.
|
|
20
|
+
*
|
|
21
|
+
* @param userId - The unique identifier for the user
|
|
22
|
+
* @param options - Configuration options for the retrieval
|
|
23
|
+
* @param options.useCache - Whether to use cached data if available (default: true)
|
|
24
|
+
* @param options.cacheTimeout - Cache timeout in milliseconds (default: 300000)
|
|
25
|
+
* @returns Promise that resolves to user data or null if not found
|
|
26
|
+
*
|
|
27
|
+
* @throws {ValidationError} When userId format is invalid
|
|
28
|
+
* @throws {DatabaseConnectionError} When database connection fails
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // Basic usage
|
|
33
|
+
* const user = await getUserById('123');
|
|
34
|
+
*
|
|
35
|
+
* // With options
|
|
36
|
+
* const user = await getUserById('123', {
|
|
37
|
+
* useCache: false,
|
|
38
|
+
* cacheTimeout: 600000
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // Error handling
|
|
42
|
+
* try {
|
|
43
|
+
* const user = await getUserById('invalid-id');
|
|
44
|
+
* } catch (error) {
|
|
45
|
+
* if (error instanceof ValidationError) {
|
|
46
|
+
* console.log('Invalid user ID format');
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @since 1.2.0
|
|
52
|
+
* @see {@link User} for user data structure
|
|
53
|
+
* @see {@link UserRepository.findById} for underlying database query
|
|
54
|
+
*/
|
|
55
|
+
async function getUserById(
|
|
56
|
+
userId: string,
|
|
57
|
+
options: GetUserOptions = {}
|
|
58
|
+
): Promise<User | null> {
|
|
59
|
+
// Implementation here
|
|
60
|
+
}
|
|
61
|
+
````
|
|
62
|
+
|
|
63
|
+
### Class Documentation
|
|
64
|
+
|
|
65
|
+
````typescript
|
|
66
|
+
/**
|
|
67
|
+
* Service for managing user data with caching and validation.
|
|
68
|
+
*
|
|
69
|
+
* The UserService provides a high-level interface for user operations,
|
|
70
|
+
* including automatic caching, input validation, and error handling.
|
|
71
|
+
* All operations are logged for debugging and monitoring purposes.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const userService = new UserService({
|
|
76
|
+
* repository: new UserRepository(database),
|
|
77
|
+
* cache: new RedisCache(),
|
|
78
|
+
* logger: new Logger('UserService')
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* // Create a new user
|
|
82
|
+
* const user = await userService.createUser({
|
|
83
|
+
* name: 'John Doe',
|
|
84
|
+
* email: 'john@example.com'
|
|
85
|
+
* });
|
|
86
|
+
*
|
|
87
|
+
* // Retrieve user with caching
|
|
88
|
+
* const foundUser = await userService.getUserById(user.id);
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @public
|
|
92
|
+
* @since 1.0.0
|
|
93
|
+
*/
|
|
94
|
+
export class UserService {
|
|
95
|
+
/**
|
|
96
|
+
* User repository for database operations.
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
private readonly repository: UserRepository;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Cache instance for storing frequently accessed user data.
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
private readonly cache: CacheService;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Logger instance for service operations.
|
|
109
|
+
* @private
|
|
110
|
+
*/
|
|
111
|
+
private readonly logger: Logger;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Creates a new UserService instance.
|
|
115
|
+
*
|
|
116
|
+
* @param dependencies - Service dependencies
|
|
117
|
+
* @param dependencies.repository - Repository for user data persistence
|
|
118
|
+
* @param dependencies.cache - Cache service for performance optimization
|
|
119
|
+
* @param dependencies.logger - Logger for operation tracking
|
|
120
|
+
*
|
|
121
|
+
* @throws {Error} When required dependencies are not provided
|
|
122
|
+
*/
|
|
123
|
+
constructor(dependencies: UserServiceDependencies) {
|
|
124
|
+
if (!dependencies.repository) {
|
|
125
|
+
throw new Error('UserRepository is required');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
this.repository = dependencies.repository;
|
|
129
|
+
this.cache = dependencies.cache;
|
|
130
|
+
this.logger = dependencies.logger || new NullLogger();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Creates a new user with validation and duplicate checking.
|
|
135
|
+
*
|
|
136
|
+
* @param userData - Data for the new user
|
|
137
|
+
* @returns Promise resolving to the created user with generated ID
|
|
138
|
+
*
|
|
139
|
+
* @throws {ValidationError} When user data is invalid
|
|
140
|
+
* @throws {DuplicateEmailError} When email already exists
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* const newUser = await userService.createUser({
|
|
145
|
+
* name: 'Jane Doe',
|
|
146
|
+
* email: 'jane@example.com',
|
|
147
|
+
* preferences: { theme: 'dark' }
|
|
148
|
+
* });
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
async createUser(userData: CreateUserData): Promise<User> {
|
|
152
|
+
// Implementation here
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
````
|
|
156
|
+
|
|
157
|
+
### Interface and Type Documentation
|
|
158
|
+
|
|
159
|
+
````typescript
|
|
160
|
+
/**
|
|
161
|
+
* Configuration options for user retrieval operations.
|
|
162
|
+
*
|
|
163
|
+
* @public
|
|
164
|
+
*/
|
|
165
|
+
export interface GetUserOptions {
|
|
166
|
+
/**
|
|
167
|
+
* Whether to use cached data if available.
|
|
168
|
+
* @defaultValue true
|
|
169
|
+
*/
|
|
170
|
+
useCache?: boolean;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Cache timeout in milliseconds.
|
|
174
|
+
* @defaultValue 300000 (5 minutes)
|
|
175
|
+
*/
|
|
176
|
+
cacheTimeout?: number;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Additional fields to include in the response.
|
|
180
|
+
* @defaultValue []
|
|
181
|
+
*/
|
|
182
|
+
includeFields?: Array<'preferences' | 'metadata' | 'lastLogin'>;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* User data structure returned by the API.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* const user: User = {
|
|
191
|
+
* id: '123e4567-e89b-12d3-a456-426614174000',
|
|
192
|
+
* name: 'John Doe',
|
|
193
|
+
* email: 'john@example.com',
|
|
194
|
+
* createdAt: new Date('2023-01-01T00:00:00Z'),
|
|
195
|
+
* updatedAt: new Date('2023-06-01T12:00:00Z'),
|
|
196
|
+
* isActive: true,
|
|
197
|
+
* preferences: {
|
|
198
|
+
* theme: 'dark',
|
|
199
|
+
* notifications: true
|
|
200
|
+
* }
|
|
201
|
+
* };
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* @public
|
|
205
|
+
*/
|
|
206
|
+
export interface User {
|
|
207
|
+
/** Unique identifier for the user (UUID v4 format) */
|
|
208
|
+
id: string;
|
|
209
|
+
|
|
210
|
+
/** Full name of the user */
|
|
211
|
+
name: string;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Email address (unique across all users)
|
|
215
|
+
* @format email
|
|
216
|
+
*/
|
|
217
|
+
email: string;
|
|
218
|
+
|
|
219
|
+
/** Timestamp when the user was created */
|
|
220
|
+
createdAt: Date;
|
|
221
|
+
|
|
222
|
+
/** Timestamp when the user was last updated */
|
|
223
|
+
updatedAt: Date;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Whether the user account is active
|
|
227
|
+
* @defaultValue true
|
|
228
|
+
*/
|
|
229
|
+
isActive: boolean;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* User preferences and settings
|
|
233
|
+
* @optional
|
|
234
|
+
*/
|
|
235
|
+
preferences?: UserPreferences;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Discriminated union type for different user roles.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```typescript
|
|
243
|
+
* function handleUser(user: UserRole) {
|
|
244
|
+
* switch (user.type) {
|
|
245
|
+
* case 'admin':
|
|
246
|
+
* // user.permissions is available here
|
|
247
|
+
* console.log('Admin permissions:', user.permissions);
|
|
248
|
+
* break;
|
|
249
|
+
* case 'member':
|
|
250
|
+
* // user.membershipLevel is available here
|
|
251
|
+
* console.log('Membership level:', user.membershipLevel);
|
|
252
|
+
* break;
|
|
253
|
+
* case 'guest':
|
|
254
|
+
* // user.expiresAt is available here
|
|
255
|
+
* console.log('Guest expires at:', user.expiresAt);
|
|
256
|
+
* break;
|
|
257
|
+
* }
|
|
258
|
+
* }
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
export type UserRole =
|
|
262
|
+
| { type: 'admin'; permissions: string[] }
|
|
263
|
+
| { type: 'member'; membershipLevel: 'basic' | 'premium' }
|
|
264
|
+
| { type: 'guest'; expiresAt: Date };
|
|
265
|
+
````
|
|
266
|
+
|
|
267
|
+
### Error Class Documentation
|
|
268
|
+
|
|
269
|
+
````typescript
|
|
270
|
+
/**
|
|
271
|
+
* Error thrown when user validation fails.
|
|
272
|
+
*
|
|
273
|
+
* This error includes detailed information about which validation
|
|
274
|
+
* rules failed and can be used to provide specific feedback to users.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```typescript
|
|
278
|
+
* try {
|
|
279
|
+
* await userService.createUser(invalidData);
|
|
280
|
+
* } catch (error) {
|
|
281
|
+
* if (error instanceof ValidationError) {
|
|
282
|
+
* console.log('Validation failed:', error.details);
|
|
283
|
+
* error.details.forEach(detail => {
|
|
284
|
+
* console.log(`${detail.field}: ${detail.message}`);
|
|
285
|
+
* });
|
|
286
|
+
* }
|
|
287
|
+
* }
|
|
288
|
+
* ```
|
|
289
|
+
*
|
|
290
|
+
* @public
|
|
291
|
+
*/
|
|
292
|
+
export class ValidationError extends Error {
|
|
293
|
+
/**
|
|
294
|
+
* Detailed information about validation failures.
|
|
295
|
+
* Each entry contains the field name and specific error message.
|
|
296
|
+
*/
|
|
297
|
+
public readonly details: ValidationDetail[];
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Error code for programmatic handling.
|
|
301
|
+
* @defaultValue 'VALIDATION_ERROR'
|
|
302
|
+
*/
|
|
303
|
+
public readonly code: string = 'VALIDATION_ERROR';
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Creates a new ValidationError.
|
|
307
|
+
*
|
|
308
|
+
* @param message - High-level error message
|
|
309
|
+
* @param details - Specific validation failure details
|
|
310
|
+
*/
|
|
311
|
+
constructor(message: string, details: ValidationDetail[]) {
|
|
312
|
+
super(message);
|
|
313
|
+
this.name = 'ValidationError';
|
|
314
|
+
this.details = details;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Returns a formatted string of all validation errors.
|
|
319
|
+
*
|
|
320
|
+
* @returns Multi-line string with each validation error on a separate line
|
|
321
|
+
*/
|
|
322
|
+
getFormattedDetails(): string {
|
|
323
|
+
return this.details
|
|
324
|
+
.map((detail) => `${detail.field}: ${detail.message}`)
|
|
325
|
+
.join('\n');
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
````
|
|
329
|
+
|
|
330
|
+
### Module and Namespace Documentation
|
|
331
|
+
|
|
332
|
+
````typescript
|
|
333
|
+
/**
|
|
334
|
+
* @fileoverview User management utilities and services.
|
|
335
|
+
*
|
|
336
|
+
* This module provides a comprehensive set of tools for managing user data,
|
|
337
|
+
* including validation, caching, and database operations. It follows the
|
|
338
|
+
* repository pattern for data access and includes extensive error handling.
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```typescript
|
|
342
|
+
* import { UserService, ValidationError } from './user-module';
|
|
343
|
+
*
|
|
344
|
+
* const userService = new UserService(dependencies);
|
|
345
|
+
*
|
|
346
|
+
* try {
|
|
347
|
+
* const user = await userService.createUser(userData);
|
|
348
|
+
* console.log('User created:', user.id);
|
|
349
|
+
* } catch (error) {
|
|
350
|
+
* if (error instanceof ValidationError) {
|
|
351
|
+
* console.error('Validation failed:', error.getFormattedDetails());
|
|
352
|
+
* }
|
|
353
|
+
* }
|
|
354
|
+
* ```
|
|
355
|
+
*
|
|
356
|
+
* @author Development Team <dev@example.com>
|
|
357
|
+
* @since 1.0.0
|
|
358
|
+
* @version 2.1.0
|
|
359
|
+
*/
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Namespace containing user-related utility functions.
|
|
363
|
+
*
|
|
364
|
+
* @namespace UserUtils
|
|
365
|
+
*/
|
|
366
|
+
export namespace UserUtils {
|
|
367
|
+
/**
|
|
368
|
+
* Validates email format using RFC 5322 compliant regex.
|
|
369
|
+
*
|
|
370
|
+
* @param email - Email address to validate
|
|
371
|
+
* @returns True if email format is valid
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```typescript
|
|
375
|
+
* if (UserUtils.isValidEmail('user@example.com')) {
|
|
376
|
+
* console.log('Valid email format');
|
|
377
|
+
* }
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
export function isValidEmail(email: string): boolean {
|
|
381
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
382
|
+
return emailRegex.test(email);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Generates a display name from user data.
|
|
387
|
+
*
|
|
388
|
+
* @param user - User object
|
|
389
|
+
* @returns Formatted display name
|
|
390
|
+
*
|
|
391
|
+
* @internal
|
|
392
|
+
*/
|
|
393
|
+
export function getDisplayName(user: Pick<User, 'name' | 'email'>): string {
|
|
394
|
+
return user.name || user.email.split('@')[0];
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
````
|
|
398
|
+
|
|
399
|
+
### API Route Documentation
|
|
400
|
+
|
|
401
|
+
````typescript
|
|
402
|
+
/**
|
|
403
|
+
* @fileoverview User API routes and handlers.
|
|
404
|
+
*
|
|
405
|
+
* This module defines REST API endpoints for user management operations.
|
|
406
|
+
* All endpoints require authentication except for user registration.
|
|
407
|
+
*
|
|
408
|
+
* @version 2.0.0
|
|
409
|
+
*/
|
|
410
|
+
|
|
411
|
+
import { Router, Request, Response } from 'express';
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* User-related API endpoints.
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```typescript
|
|
418
|
+
* import express from 'express';
|
|
419
|
+
* import { userRoutes } from './routes/user-routes';
|
|
420
|
+
*
|
|
421
|
+
* const app = express();
|
|
422
|
+
* app.use('/api/users', userRoutes);
|
|
423
|
+
* ```
|
|
424
|
+
*/
|
|
425
|
+
export const userRoutes = Router();
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* GET /api/users/:id - Retrieve user by ID.
|
|
429
|
+
*
|
|
430
|
+
* @route GET /api/users/:id
|
|
431
|
+
* @param {string} id - User ID (UUID format)
|
|
432
|
+
* @returns {User} User object if found
|
|
433
|
+
* @returns {404} Not found if user doesn't exist
|
|
434
|
+
* @returns {400} Bad request if ID format is invalid
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* ```bash
|
|
438
|
+
* curl -X GET /api/users/123e4567-e89b-12d3-a456-426614174000 \
|
|
439
|
+
* -H "Authorization: Bearer YOUR_TOKEN"
|
|
440
|
+
* ```
|
|
441
|
+
*
|
|
442
|
+
* @example Response
|
|
443
|
+
* ```json
|
|
444
|
+
* {
|
|
445
|
+
* "id": "123e4567-e89b-12d3-a456-426614174000",
|
|
446
|
+
* "name": "John Doe",
|
|
447
|
+
* "email": "john@example.com",
|
|
448
|
+
* "createdAt": "2023-01-01T00:00:00.000Z",
|
|
449
|
+
* "isActive": true
|
|
450
|
+
* }
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
userRoutes.get('/:id', async (req: Request, res: Response) => {
|
|
454
|
+
// Implementation here
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* POST /api/users - Create a new user.
|
|
459
|
+
*
|
|
460
|
+
* @route POST /api/users
|
|
461
|
+
* @param {CreateUserData} body - User data for creation
|
|
462
|
+
* @returns {User} Created user object with generated ID
|
|
463
|
+
* @returns {400} Bad request if validation fails
|
|
464
|
+
* @returns {409} Conflict if email already exists
|
|
465
|
+
*
|
|
466
|
+
* @example Request Body
|
|
467
|
+
* ```json
|
|
468
|
+
* {
|
|
469
|
+
* "name": "Jane Doe",
|
|
470
|
+
* "email": "jane@example.com",
|
|
471
|
+
* "preferences": {
|
|
472
|
+
* "theme": "dark",
|
|
473
|
+
* "notifications": true
|
|
474
|
+
* }
|
|
475
|
+
* }
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
userRoutes.post('/', async (req: Request, res: Response) => {
|
|
479
|
+
// Implementation here
|
|
480
|
+
});
|
|
481
|
+
````
|
|
482
|
+
|
|
483
|
+
### Configuration and Constants Documentation
|
|
484
|
+
|
|
485
|
+
````typescript
|
|
486
|
+
/**
|
|
487
|
+
* @fileoverview Application configuration and constants.
|
|
488
|
+
*
|
|
489
|
+
* This module contains all configuration values and constants used
|
|
490
|
+
* throughout the application. Values are loaded from environment
|
|
491
|
+
* variables with sensible defaults for development.
|
|
492
|
+
*/
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Database configuration settings.
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
* ```typescript
|
|
499
|
+
* import { DatabaseConfig } from './config';
|
|
500
|
+
*
|
|
501
|
+
* const connection = new DatabaseConnection(DatabaseConfig);
|
|
502
|
+
* ```
|
|
503
|
+
*/
|
|
504
|
+
export const DatabaseConfig = {
|
|
505
|
+
/**
|
|
506
|
+
* Database connection URL.
|
|
507
|
+
* @env DATABASE_URL
|
|
508
|
+
* @defaultValue 'postgresql://localhost:5432/myapp_dev'
|
|
509
|
+
*/
|
|
510
|
+
url: process.env.DATABASE_URL || 'postgresql://localhost:5432/myapp_dev',
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Maximum number of database connections in pool.
|
|
514
|
+
* @env DB_POOL_SIZE
|
|
515
|
+
* @defaultValue 10
|
|
516
|
+
*/
|
|
517
|
+
poolSize: parseInt(process.env.DB_POOL_SIZE || '10', 10),
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Connection timeout in milliseconds.
|
|
521
|
+
* @env DB_TIMEOUT
|
|
522
|
+
* @defaultValue 30000
|
|
523
|
+
*/
|
|
524
|
+
timeout: parseInt(process.env.DB_TIMEOUT || '30000', 10),
|
|
525
|
+
} as const;
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* User validation constants.
|
|
529
|
+
*
|
|
530
|
+
* These constants define the validation rules for user data
|
|
531
|
+
* and are used throughout the application for consistency.
|
|
532
|
+
*/
|
|
533
|
+
export const UserValidation = {
|
|
534
|
+
/** Minimum length for user names */
|
|
535
|
+
NAME_MIN_LENGTH: 2,
|
|
536
|
+
|
|
537
|
+
/** Maximum length for user names */
|
|
538
|
+
NAME_MAX_LENGTH: 100,
|
|
539
|
+
|
|
540
|
+
/** Maximum length for email addresses */
|
|
541
|
+
EMAIL_MAX_LENGTH: 254,
|
|
542
|
+
|
|
543
|
+
/** Regex pattern for valid email format */
|
|
544
|
+
EMAIL_PATTERN: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
|
545
|
+
|
|
546
|
+
/** List of reserved usernames that cannot be used */
|
|
547
|
+
RESERVED_NAMES: ['admin', 'root', 'system', 'api'] as const,
|
|
548
|
+
} as const;
|
|
549
|
+
````
|
|
550
|
+
|
|
551
|
+
## Node.js Specific Documentation
|
|
552
|
+
|
|
553
|
+
### Process and Environment Documentation
|
|
554
|
+
|
|
555
|
+
````typescript
|
|
556
|
+
/**
|
|
557
|
+
* @fileoverview Process management and graceful shutdown handling.
|
|
558
|
+
*
|
|
559
|
+
* This module handles process lifecycle events and ensures graceful
|
|
560
|
+
* shutdown of the application with proper cleanup of resources.
|
|
561
|
+
*/
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Graceful shutdown manager for Node.js applications.
|
|
565
|
+
*
|
|
566
|
+
* Handles SIGINT and SIGTERM signals to ensure clean shutdown
|
|
567
|
+
* with proper cleanup of database connections, file handles, and
|
|
568
|
+
* other resources.
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
* ```typescript
|
|
572
|
+
* const shutdownManager = new GracefulShutdown();
|
|
573
|
+
*
|
|
574
|
+
* shutdownManager.addHandler('database', async () => {
|
|
575
|
+
* await database.disconnect();
|
|
576
|
+
* });
|
|
577
|
+
*
|
|
578
|
+
* shutdownManager.addHandler('server', async () => {
|
|
579
|
+
* await server.close();
|
|
580
|
+
* });
|
|
581
|
+
*
|
|
582
|
+
* shutdownManager.start();
|
|
583
|
+
* ```
|
|
584
|
+
*/
|
|
585
|
+
export class GracefulShutdown {
|
|
586
|
+
/**
|
|
587
|
+
* Map of cleanup handlers by name.
|
|
588
|
+
* @private
|
|
589
|
+
*/
|
|
590
|
+
private handlers = new Map<string, () => Promise<void>>();
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Whether shutdown process has started.
|
|
594
|
+
* @private
|
|
595
|
+
*/
|
|
596
|
+
private isShuttingDown = false;
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Adds a cleanup handler for a named resource.
|
|
600
|
+
*
|
|
601
|
+
* @param name - Unique name for the handler
|
|
602
|
+
* @param handler - Async function to clean up the resource
|
|
603
|
+
*
|
|
604
|
+
* @throws {Error} If handler name already exists
|
|
605
|
+
*/
|
|
606
|
+
addHandler(name: string, handler: () => Promise<void>): void {
|
|
607
|
+
if (this.handlers.has(name)) {
|
|
608
|
+
throw new Error(`Handler '${name}' already exists`);
|
|
609
|
+
}
|
|
610
|
+
this.handlers.set(name, handler);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
````
|
|
614
|
+
|
|
615
|
+
### Stream Documentation
|
|
616
|
+
|
|
617
|
+
````typescript
|
|
618
|
+
/**
|
|
619
|
+
* Custom transform stream for processing large datasets.
|
|
620
|
+
*
|
|
621
|
+
* This stream processes data in chunks to handle large files
|
|
622
|
+
* efficiently without loading everything into memory at once.
|
|
623
|
+
*
|
|
624
|
+
* @example
|
|
625
|
+
* ```typescript
|
|
626
|
+
* import fs from 'fs';
|
|
627
|
+
* import { DataProcessor } from './data-processor';
|
|
628
|
+
*
|
|
629
|
+
* const processor = new DataProcessor({
|
|
630
|
+
* batchSize: 1000,
|
|
631
|
+
* transform: (chunk) => chunk.toUpperCase()
|
|
632
|
+
* });
|
|
633
|
+
*
|
|
634
|
+
* fs.createReadStream('input.txt')
|
|
635
|
+
* .pipe(processor)
|
|
636
|
+
* .pipe(fs.createWriteStream('output.txt'));
|
|
637
|
+
* ```
|
|
638
|
+
*/
|
|
639
|
+
export class DataProcessor extends Transform {
|
|
640
|
+
/**
|
|
641
|
+
* Number of items to process in each batch.
|
|
642
|
+
* @private
|
|
643
|
+
*/
|
|
644
|
+
private readonly batchSize: number;
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Function to transform each data chunk.
|
|
648
|
+
* @private
|
|
649
|
+
*/
|
|
650
|
+
private readonly transformFn: (chunk: string) => string;
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Creates a new DataProcessor stream.
|
|
654
|
+
*
|
|
655
|
+
* @param options - Processor configuration
|
|
656
|
+
* @param options.batchSize - Number of items per batch
|
|
657
|
+
* @param options.transform - Function to transform each chunk
|
|
658
|
+
*/
|
|
659
|
+
constructor(options: DataProcessorOptions) {
|
|
660
|
+
super({ objectMode: true });
|
|
661
|
+
this.batchSize = options.batchSize || 100;
|
|
662
|
+
this.transformFn = options.transform || ((x) => x);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
````
|
|
666
|
+
|
|
667
|
+
## README and Package Documentation
|
|
668
|
+
|
|
669
|
+
### Package.json Documentation Guidelines
|
|
670
|
+
|
|
671
|
+
```json
|
|
672
|
+
{
|
|
673
|
+
"name": "user-management-service",
|
|
674
|
+
"version": "2.1.0",
|
|
675
|
+
"description": "Comprehensive user management service with caching, validation, and REST API",
|
|
676
|
+
"main": "dist/index.js",
|
|
677
|
+
"types": "dist/index.d.ts",
|
|
678
|
+
"scripts": {
|
|
679
|
+
"build": "tsc",
|
|
680
|
+
"test": "jest",
|
|
681
|
+
"test:coverage": "jest --coverage",
|
|
682
|
+
"test:watch": "jest --watch",
|
|
683
|
+
"lint": "eslint src/**/*.ts",
|
|
684
|
+
"lint:fix": "eslint src/**/*.ts --fix",
|
|
685
|
+
"start": "node dist/index.js",
|
|
686
|
+
"dev": "ts-node src/index.ts",
|
|
687
|
+
"docs": "typedoc src --out docs"
|
|
688
|
+
},
|
|
689
|
+
"keywords": [
|
|
690
|
+
"user-management",
|
|
691
|
+
"authentication",
|
|
692
|
+
"rest-api",
|
|
693
|
+
"typescript",
|
|
694
|
+
"caching"
|
|
695
|
+
],
|
|
696
|
+
"author": "Your Name <your.email@example.com>",
|
|
697
|
+
"license": "MIT",
|
|
698
|
+
"repository": {
|
|
699
|
+
"type": "git",
|
|
700
|
+
"url": "https://github.com/username/user-management-service.git"
|
|
701
|
+
},
|
|
702
|
+
"bugs": {
|
|
703
|
+
"url": "https://github.com/username/user-management-service/issues"
|
|
704
|
+
},
|
|
705
|
+
"homepage": "https://github.com/username/user-management-service#readme"
|
|
706
|
+
}
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
### TypeDoc Configuration
|
|
710
|
+
|
|
711
|
+
```javascript
|
|
712
|
+
// typedoc.json
|
|
713
|
+
{
|
|
714
|
+
"entryPoints": ["src/index.ts"],
|
|
715
|
+
"out": "docs",
|
|
716
|
+
"excludePrivate": true,
|
|
717
|
+
"excludeProtected": false,
|
|
718
|
+
"excludeInternal": false,
|
|
719
|
+
"categorizeByGroup": true,
|
|
720
|
+
"sort": ["source-order"],
|
|
721
|
+
"kindSortOrder": [
|
|
722
|
+
"Module",
|
|
723
|
+
"Namespace",
|
|
724
|
+
"Enum",
|
|
725
|
+
"Class",
|
|
726
|
+
"Interface",
|
|
727
|
+
"Function",
|
|
728
|
+
"Variable"
|
|
729
|
+
],
|
|
730
|
+
"theme": "default",
|
|
731
|
+
"readme": "README.md",
|
|
732
|
+
"includeVersion": true
|
|
733
|
+
}
|
|
734
|
+
```
|