@type-crafter/mcp 0.6.0 → 1.1.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.
- package/README.md +203 -221
- package/dist/docs/RULES_COMPOSITION.md +343 -0
- package/dist/docs/RULES_NULLABLE.md +293 -0
- package/dist/docs/RULES_PATTERNS.md +516 -0
- package/dist/docs/RULES_REFERENCES.md +302 -0
- package/dist/docs/RULES_STRUCTURE.md +248 -0
- package/dist/docs/RULES_TYPES.md +291 -0
- package/dist/docs/WRITING_GUIDE.md +179 -0
- package/dist/index.js +321 -345
- package/package.json +3 -5
- package/src/GUIDE.md +0 -459
- package/src/SPEC_RULES.md +0 -1755
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
# Common Patterns
|
|
2
|
+
|
|
3
|
+
## Pattern 1: API Response Wrapper
|
|
4
|
+
|
|
5
|
+
```yaml
|
|
6
|
+
info:
|
|
7
|
+
version: '1.0.0'
|
|
8
|
+
title: 'API Patterns'
|
|
9
|
+
|
|
10
|
+
types:
|
|
11
|
+
SuccessResponse:
|
|
12
|
+
type: object
|
|
13
|
+
required:
|
|
14
|
+
- success
|
|
15
|
+
- data
|
|
16
|
+
properties:
|
|
17
|
+
success:
|
|
18
|
+
type: boolean
|
|
19
|
+
data:
|
|
20
|
+
type: unknown
|
|
21
|
+
|
|
22
|
+
ErrorResponse:
|
|
23
|
+
type: object
|
|
24
|
+
required:
|
|
25
|
+
- success
|
|
26
|
+
- error
|
|
27
|
+
properties:
|
|
28
|
+
success:
|
|
29
|
+
type: boolean
|
|
30
|
+
error:
|
|
31
|
+
type: string
|
|
32
|
+
code:
|
|
33
|
+
type: number
|
|
34
|
+
|
|
35
|
+
ApiResponse:
|
|
36
|
+
oneOf:
|
|
37
|
+
- $ref: '#/types/SuccessResponse'
|
|
38
|
+
- $ref: '#/types/ErrorResponse'
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**TypeScript:**
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
export type ApiResponse =
|
|
45
|
+
| { success: boolean; data: unknown }
|
|
46
|
+
| { success: boolean; error: string; code: number | null };
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Pattern 2: Paginated Response
|
|
52
|
+
|
|
53
|
+
```yaml
|
|
54
|
+
types:
|
|
55
|
+
PaginationMeta:
|
|
56
|
+
type: object
|
|
57
|
+
required:
|
|
58
|
+
- total
|
|
59
|
+
- page
|
|
60
|
+
- perPage
|
|
61
|
+
- totalPages
|
|
62
|
+
properties:
|
|
63
|
+
total:
|
|
64
|
+
type: number
|
|
65
|
+
page:
|
|
66
|
+
type: number
|
|
67
|
+
perPage:
|
|
68
|
+
type: number
|
|
69
|
+
totalPages:
|
|
70
|
+
type: number
|
|
71
|
+
|
|
72
|
+
PaginatedUsers:
|
|
73
|
+
type: object
|
|
74
|
+
required:
|
|
75
|
+
- data
|
|
76
|
+
- meta
|
|
77
|
+
properties:
|
|
78
|
+
data:
|
|
79
|
+
type: array
|
|
80
|
+
items:
|
|
81
|
+
$ref: '#/types/User'
|
|
82
|
+
meta:
|
|
83
|
+
$ref: '#/types/PaginationMeta'
|
|
84
|
+
|
|
85
|
+
User:
|
|
86
|
+
type: object
|
|
87
|
+
required:
|
|
88
|
+
- id
|
|
89
|
+
- email
|
|
90
|
+
properties:
|
|
91
|
+
id: { type: string }
|
|
92
|
+
email: { type: string }
|
|
93
|
+
name: { type: string }
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Pattern 3: Timestamp Mixin
|
|
99
|
+
|
|
100
|
+
```yaml
|
|
101
|
+
types:
|
|
102
|
+
Timestamps:
|
|
103
|
+
type: object
|
|
104
|
+
required:
|
|
105
|
+
- createdAt
|
|
106
|
+
- updatedAt
|
|
107
|
+
properties:
|
|
108
|
+
createdAt:
|
|
109
|
+
type: string
|
|
110
|
+
format: date
|
|
111
|
+
updatedAt:
|
|
112
|
+
type: string
|
|
113
|
+
format: date
|
|
114
|
+
|
|
115
|
+
User:
|
|
116
|
+
allOf:
|
|
117
|
+
- $ref: '#/types/Timestamps'
|
|
118
|
+
- type: object
|
|
119
|
+
required:
|
|
120
|
+
- id
|
|
121
|
+
- email
|
|
122
|
+
properties:
|
|
123
|
+
id: { type: string }
|
|
124
|
+
email: { type: string }
|
|
125
|
+
name: { type: string }
|
|
126
|
+
|
|
127
|
+
Post:
|
|
128
|
+
allOf:
|
|
129
|
+
- $ref: '#/types/Timestamps'
|
|
130
|
+
- type: object
|
|
131
|
+
required:
|
|
132
|
+
- id
|
|
133
|
+
- title
|
|
134
|
+
properties:
|
|
135
|
+
id: { type: string }
|
|
136
|
+
title: { type: string }
|
|
137
|
+
content: { type: string }
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**TypeScript:**
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
export type User = Timestamps & {
|
|
144
|
+
id: string;
|
|
145
|
+
email: string;
|
|
146
|
+
name: string | null;
|
|
147
|
+
};
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Pattern 4: Status Enum with Metadata
|
|
153
|
+
|
|
154
|
+
```yaml
|
|
155
|
+
types:
|
|
156
|
+
OrderStatus:
|
|
157
|
+
type: string
|
|
158
|
+
enum:
|
|
159
|
+
- pending
|
|
160
|
+
- processing
|
|
161
|
+
- shipped
|
|
162
|
+
- delivered
|
|
163
|
+
- cancelled
|
|
164
|
+
|
|
165
|
+
Order:
|
|
166
|
+
type: object
|
|
167
|
+
required:
|
|
168
|
+
- id
|
|
169
|
+
- status
|
|
170
|
+
properties:
|
|
171
|
+
id:
|
|
172
|
+
type: string
|
|
173
|
+
status:
|
|
174
|
+
$ref: '#/types/OrderStatus'
|
|
175
|
+
statusChangedAt:
|
|
176
|
+
type: string
|
|
177
|
+
format: date
|
|
178
|
+
statusHistory:
|
|
179
|
+
type: array
|
|
180
|
+
items:
|
|
181
|
+
type: object
|
|
182
|
+
required:
|
|
183
|
+
- status
|
|
184
|
+
- changedAt
|
|
185
|
+
properties:
|
|
186
|
+
status:
|
|
187
|
+
$ref: '#/types/OrderStatus'
|
|
188
|
+
changedAt:
|
|
189
|
+
type: string
|
|
190
|
+
format: date
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## Pattern 5: Recursive/Tree Structure
|
|
196
|
+
|
|
197
|
+
```yaml
|
|
198
|
+
types:
|
|
199
|
+
MenuItem:
|
|
200
|
+
type: object
|
|
201
|
+
required:
|
|
202
|
+
- id
|
|
203
|
+
- label
|
|
204
|
+
properties:
|
|
205
|
+
id:
|
|
206
|
+
type: string
|
|
207
|
+
label:
|
|
208
|
+
type: string
|
|
209
|
+
url:
|
|
210
|
+
type: string
|
|
211
|
+
children:
|
|
212
|
+
type: array
|
|
213
|
+
items:
|
|
214
|
+
$ref: '#/types/MenuItem'
|
|
215
|
+
|
|
216
|
+
Menu:
|
|
217
|
+
type: object
|
|
218
|
+
required:
|
|
219
|
+
- items
|
|
220
|
+
properties:
|
|
221
|
+
items:
|
|
222
|
+
type: array
|
|
223
|
+
items:
|
|
224
|
+
$ref: '#/types/MenuItem'
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
**TypeScript:**
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
export type MenuItem = {
|
|
231
|
+
id: string;
|
|
232
|
+
label: string;
|
|
233
|
+
url: string | null;
|
|
234
|
+
children: MenuItem[] | null;
|
|
235
|
+
};
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## Pattern 6: Form Request/Response
|
|
241
|
+
|
|
242
|
+
```yaml
|
|
243
|
+
groupedTypes:
|
|
244
|
+
Auth:
|
|
245
|
+
LoginRequest:
|
|
246
|
+
type: object
|
|
247
|
+
required:
|
|
248
|
+
- email
|
|
249
|
+
- password
|
|
250
|
+
properties:
|
|
251
|
+
email:
|
|
252
|
+
type: string
|
|
253
|
+
password:
|
|
254
|
+
type: string
|
|
255
|
+
rememberMe:
|
|
256
|
+
type: boolean
|
|
257
|
+
|
|
258
|
+
LoginResponse:
|
|
259
|
+
type: object
|
|
260
|
+
required:
|
|
261
|
+
- token
|
|
262
|
+
- expiresAt
|
|
263
|
+
properties:
|
|
264
|
+
token:
|
|
265
|
+
type: string
|
|
266
|
+
refreshToken:
|
|
267
|
+
type: string
|
|
268
|
+
expiresAt:
|
|
269
|
+
type: string
|
|
270
|
+
format: date
|
|
271
|
+
user:
|
|
272
|
+
$ref: '#/types/User'
|
|
273
|
+
|
|
274
|
+
RegisterRequest:
|
|
275
|
+
type: object
|
|
276
|
+
required:
|
|
277
|
+
- email
|
|
278
|
+
- password
|
|
279
|
+
- confirmPassword
|
|
280
|
+
properties:
|
|
281
|
+
email:
|
|
282
|
+
type: string
|
|
283
|
+
password:
|
|
284
|
+
type: string
|
|
285
|
+
confirmPassword:
|
|
286
|
+
type: string
|
|
287
|
+
name:
|
|
288
|
+
type: string
|
|
289
|
+
|
|
290
|
+
types:
|
|
291
|
+
User:
|
|
292
|
+
type: object
|
|
293
|
+
required:
|
|
294
|
+
- id
|
|
295
|
+
- email
|
|
296
|
+
properties:
|
|
297
|
+
id: { type: string }
|
|
298
|
+
email: { type: string }
|
|
299
|
+
name: { type: string }
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## Pattern 7: Polymorphic Types (Discriminated Union)
|
|
305
|
+
|
|
306
|
+
```yaml
|
|
307
|
+
types:
|
|
308
|
+
BaseNotification:
|
|
309
|
+
type: object
|
|
310
|
+
required:
|
|
311
|
+
- id
|
|
312
|
+
- type
|
|
313
|
+
- createdAt
|
|
314
|
+
properties:
|
|
315
|
+
id: { type: string }
|
|
316
|
+
type: { type: string }
|
|
317
|
+
createdAt: { type: string, format: date }
|
|
318
|
+
read: { type: boolean }
|
|
319
|
+
|
|
320
|
+
EmailNotification:
|
|
321
|
+
allOf:
|
|
322
|
+
- $ref: '#/types/BaseNotification'
|
|
323
|
+
- type: object
|
|
324
|
+
required:
|
|
325
|
+
- subject
|
|
326
|
+
- body
|
|
327
|
+
properties:
|
|
328
|
+
type:
|
|
329
|
+
type: string
|
|
330
|
+
enum: [email]
|
|
331
|
+
subject: { type: string }
|
|
332
|
+
body: { type: string }
|
|
333
|
+
|
|
334
|
+
SmsNotification:
|
|
335
|
+
allOf:
|
|
336
|
+
- $ref: '#/types/BaseNotification'
|
|
337
|
+
- type: object
|
|
338
|
+
required:
|
|
339
|
+
- message
|
|
340
|
+
- phoneNumber
|
|
341
|
+
properties:
|
|
342
|
+
type:
|
|
343
|
+
type: string
|
|
344
|
+
enum: [sms]
|
|
345
|
+
message: { type: string }
|
|
346
|
+
phoneNumber: { type: string }
|
|
347
|
+
|
|
348
|
+
PushNotification:
|
|
349
|
+
allOf:
|
|
350
|
+
- $ref: '#/types/BaseNotification'
|
|
351
|
+
- type: object
|
|
352
|
+
required:
|
|
353
|
+
- title
|
|
354
|
+
properties:
|
|
355
|
+
type:
|
|
356
|
+
type: string
|
|
357
|
+
enum: [push]
|
|
358
|
+
title: { type: string }
|
|
359
|
+
body: { type: string }
|
|
360
|
+
|
|
361
|
+
Notification:
|
|
362
|
+
oneOf:
|
|
363
|
+
- $ref: '#/types/EmailNotification'
|
|
364
|
+
- $ref: '#/types/SmsNotification'
|
|
365
|
+
- $ref: '#/types/PushNotification'
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
## Pattern 8: Configuration Object
|
|
371
|
+
|
|
372
|
+
```yaml
|
|
373
|
+
types:
|
|
374
|
+
DatabaseConfig:
|
|
375
|
+
type: object
|
|
376
|
+
required:
|
|
377
|
+
- host
|
|
378
|
+
- port
|
|
379
|
+
- database
|
|
380
|
+
properties:
|
|
381
|
+
host: { type: string }
|
|
382
|
+
port: { type: number }
|
|
383
|
+
database: { type: string }
|
|
384
|
+
username: { type: string }
|
|
385
|
+
password: { type: string }
|
|
386
|
+
ssl: { type: boolean }
|
|
387
|
+
|
|
388
|
+
CacheConfig:
|
|
389
|
+
type: object
|
|
390
|
+
required:
|
|
391
|
+
- enabled
|
|
392
|
+
properties:
|
|
393
|
+
enabled: { type: boolean }
|
|
394
|
+
ttl: { type: number }
|
|
395
|
+
maxSize: { type: number }
|
|
396
|
+
|
|
397
|
+
AppConfig:
|
|
398
|
+
type: object
|
|
399
|
+
required:
|
|
400
|
+
- database
|
|
401
|
+
- environment
|
|
402
|
+
properties:
|
|
403
|
+
environment:
|
|
404
|
+
type: string
|
|
405
|
+
enum: [development, staging, production]
|
|
406
|
+
database:
|
|
407
|
+
$ref: '#/types/DatabaseConfig'
|
|
408
|
+
cache:
|
|
409
|
+
$ref: '#/types/CacheConfig'
|
|
410
|
+
features:
|
|
411
|
+
type: object
|
|
412
|
+
additionalProperties:
|
|
413
|
+
keyType: string
|
|
414
|
+
valueType:
|
|
415
|
+
type: boolean
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
---
|
|
419
|
+
|
|
420
|
+
## Pattern 9: Multi-File Domain Organization
|
|
421
|
+
|
|
422
|
+
**specs/api.yaml (top file):**
|
|
423
|
+
|
|
424
|
+
```yaml
|
|
425
|
+
info:
|
|
426
|
+
version: '1.0.0'
|
|
427
|
+
title: 'E-Commerce API'
|
|
428
|
+
|
|
429
|
+
groupedTypes:
|
|
430
|
+
Users:
|
|
431
|
+
$ref: './specs/users/types.yaml#/UserTypes'
|
|
432
|
+
Products:
|
|
433
|
+
$ref: './specs/products/types.yaml#/ProductTypes'
|
|
434
|
+
Orders:
|
|
435
|
+
$ref: './specs/orders/types.yaml#/OrderTypes'
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
**specs/users/types.yaml:**
|
|
439
|
+
|
|
440
|
+
```yaml
|
|
441
|
+
info:
|
|
442
|
+
version: '1.0.0'
|
|
443
|
+
title: 'User Types'
|
|
444
|
+
|
|
445
|
+
groupedTypes:
|
|
446
|
+
UserTypes:
|
|
447
|
+
User:
|
|
448
|
+
type: object
|
|
449
|
+
required: [id, email]
|
|
450
|
+
properties:
|
|
451
|
+
id: { type: string }
|
|
452
|
+
email: { type: string }
|
|
453
|
+
profile:
|
|
454
|
+
$ref: '#/groupedTypes/UserTypes/UserProfile'
|
|
455
|
+
|
|
456
|
+
UserProfile:
|
|
457
|
+
type: object
|
|
458
|
+
properties:
|
|
459
|
+
name: { type: string }
|
|
460
|
+
avatar: { type: string }
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
---
|
|
464
|
+
|
|
465
|
+
## Pattern 10: Hashmap/Dictionary
|
|
466
|
+
|
|
467
|
+
```yaml
|
|
468
|
+
types:
|
|
469
|
+
# String to string map
|
|
470
|
+
Headers:
|
|
471
|
+
type: object
|
|
472
|
+
additionalProperties:
|
|
473
|
+
keyType: string
|
|
474
|
+
valueType:
|
|
475
|
+
type: string
|
|
476
|
+
|
|
477
|
+
# String to any map
|
|
478
|
+
Metadata:
|
|
479
|
+
type: object
|
|
480
|
+
additionalProperties: true
|
|
481
|
+
|
|
482
|
+
# ID to entity map
|
|
483
|
+
UserCache:
|
|
484
|
+
type: object
|
|
485
|
+
additionalProperties:
|
|
486
|
+
keyType: string
|
|
487
|
+
valueType:
|
|
488
|
+
$ref: '#/types/User'
|
|
489
|
+
|
|
490
|
+
# Mixed: fixed properties + dynamic
|
|
491
|
+
Response:
|
|
492
|
+
type: object
|
|
493
|
+
required:
|
|
494
|
+
- status
|
|
495
|
+
properties:
|
|
496
|
+
status: { type: number }
|
|
497
|
+
additionalProperties:
|
|
498
|
+
keyType: string
|
|
499
|
+
valueType:
|
|
500
|
+
type: unknown
|
|
501
|
+
|
|
502
|
+
User:
|
|
503
|
+
type: object
|
|
504
|
+
required: [id]
|
|
505
|
+
properties:
|
|
506
|
+
id: { type: string }
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
**TypeScript:**
|
|
510
|
+
|
|
511
|
+
```typescript
|
|
512
|
+
export type Headers = { [keys: string]: string };
|
|
513
|
+
export type Metadata = { [keys: string]: unknown };
|
|
514
|
+
export type UserCache = { [keys: string]: User };
|
|
515
|
+
export type Response = { status: number; [keys: string]: unknown };
|
|
516
|
+
```
|