@type-crafter/mcp 0.5.0 → 0.6.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 +0 -14
- package/package.json +1 -1
- package/src/SPEC_RULES.md +276 -48
package/README.md
CHANGED
|
@@ -268,20 +268,6 @@ npm run build
|
|
|
268
268
|
npm run dev
|
|
269
269
|
```
|
|
270
270
|
|
|
271
|
-
## Development
|
|
272
|
-
|
|
273
|
-
### Building from Source
|
|
274
|
-
|
|
275
|
-
```bash
|
|
276
|
-
npm run build
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
### Watch Mode
|
|
280
|
-
|
|
281
|
-
```bash
|
|
282
|
-
npm run dev
|
|
283
|
-
```
|
|
284
|
-
|
|
285
271
|
### Linting
|
|
286
272
|
|
|
287
273
|
```bash
|
package/package.json
CHANGED
package/src/SPEC_RULES.md
CHANGED
|
@@ -63,6 +63,29 @@ User:
|
|
|
63
63
|
properties:
|
|
64
64
|
profile:
|
|
65
65
|
$ref: './profile.yaml#/Profile' # ❌ WRONG! Not relative to current file
|
|
66
|
+
|
|
67
|
+
# ❌ WRONG: Using # reference in non-top file (file without info section)
|
|
68
|
+
# File: docs/cart.yaml (NON-TOP FILE - no info section)
|
|
69
|
+
Cart:
|
|
70
|
+
SCart:
|
|
71
|
+
type: object
|
|
72
|
+
properties:
|
|
73
|
+
items:
|
|
74
|
+
type: array
|
|
75
|
+
items:
|
|
76
|
+
$ref: '#/Cart/SCartItem' # ❌ WRONG! Must use full path in non-top files
|
|
77
|
+
|
|
78
|
+
# ❌ WRONG: Using full path in top file for same-file reference
|
|
79
|
+
# File: types.yaml (TOP FILE - has info section)
|
|
80
|
+
info:
|
|
81
|
+
version: '1.0.0'
|
|
82
|
+
title: 'Types'
|
|
83
|
+
types:
|
|
84
|
+
User:
|
|
85
|
+
type: object
|
|
86
|
+
properties:
|
|
87
|
+
profile:
|
|
88
|
+
$ref: './types.yaml#/types/Profile' # ❌ WRONG! Use # in top files for same-file refs
|
|
66
89
|
```
|
|
67
90
|
|
|
68
91
|
### ✅ CORRECT Ways
|
|
@@ -96,6 +119,37 @@ User:
|
|
|
96
119
|
properties:
|
|
97
120
|
profile:
|
|
98
121
|
$ref: './src/api/profile.yaml#/Profile' # ✅ From project root
|
|
122
|
+
|
|
123
|
+
# ✅ CORRECT: Top file using # for same-file references
|
|
124
|
+
# File: types.yaml (TOP FILE - has info section)
|
|
125
|
+
info:
|
|
126
|
+
version: '1.0.0'
|
|
127
|
+
title: 'API Types'
|
|
128
|
+
types:
|
|
129
|
+
User:
|
|
130
|
+
type: object
|
|
131
|
+
properties:
|
|
132
|
+
profile:
|
|
133
|
+
$ref: '#/types/Profile' # ✅ Use # in top files for same-file refs
|
|
134
|
+
Profile:
|
|
135
|
+
type: object
|
|
136
|
+
properties:
|
|
137
|
+
bio: { type: string }
|
|
138
|
+
|
|
139
|
+
# ✅ CORRECT: Non-top file using full path for all references
|
|
140
|
+
# File: docs/cart.yaml (NON-TOP FILE - no info section)
|
|
141
|
+
Cart:
|
|
142
|
+
SCart:
|
|
143
|
+
type: object
|
|
144
|
+
properties:
|
|
145
|
+
items:
|
|
146
|
+
type: array
|
|
147
|
+
items:
|
|
148
|
+
$ref: './docs/cart.yaml#/Cart/SCartItem' # ✅ Full path in non-top files
|
|
149
|
+
SCartItem:
|
|
150
|
+
type: object
|
|
151
|
+
properties:
|
|
152
|
+
id: { type: number }
|
|
99
153
|
```
|
|
100
154
|
|
|
101
155
|
### 🔑 Key Rules to Remember
|
|
@@ -113,9 +167,14 @@ User:
|
|
|
113
167
|
- NOT relative to current YAML file
|
|
114
168
|
- Always use `./path/from/root/file.yaml#/Type`
|
|
115
169
|
|
|
116
|
-
4. **
|
|
117
|
-
-
|
|
118
|
-
-
|
|
170
|
+
4. **Referencing depends on file type**
|
|
171
|
+
- **Top file** (has `info:` at root): Use `#/types/TypeName` for same-file refs
|
|
172
|
+
- **Non-top file** (no `info:` at root): MUST use `'./path/from/root/file.yaml#/TypeName'` for ALL refs
|
|
173
|
+
- Identify top files by presence of `info` section at root level
|
|
174
|
+
|
|
175
|
+
5. **Top file is required for generation**
|
|
176
|
+
- Only files with `info:` section can be used with `type-crafter generate`
|
|
177
|
+
- Non-top files must be referenced from a top file
|
|
119
178
|
|
|
120
179
|
---
|
|
121
180
|
|
|
@@ -966,69 +1025,238 @@ export type UserWithMeta = {
|
|
|
966
1025
|
|
|
967
1026
|
## References
|
|
968
1027
|
|
|
969
|
-
###
|
|
1028
|
+
### Understanding Top Files vs Non-Top Files
|
|
1029
|
+
|
|
1030
|
+
**CRITICAL:** Referencing rules differ based on whether you're in a top file or non-top file.
|
|
1031
|
+
|
|
1032
|
+
#### What is a Top File?
|
|
970
1033
|
|
|
1034
|
+
A **top file** is the root specification file that contains the `info` section at the root level.
|
|
1035
|
+
|
|
1036
|
+
**Identifying a top file:**
|
|
971
1037
|
```yaml
|
|
972
|
-
#
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
author:
|
|
977
|
-
$ref: '#/types/User'
|
|
1038
|
+
# ✅ This is a TOP FILE
|
|
1039
|
+
info:
|
|
1040
|
+
version: '1.0.0' # Has info section at root
|
|
1041
|
+
title: 'My API Types'
|
|
978
1042
|
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
1043
|
+
types:
|
|
1044
|
+
User: { ... }
|
|
1045
|
+
```
|
|
1046
|
+
|
|
1047
|
+
**Characteristics:**
|
|
1048
|
+
- Contains `info:` section with `version` and `title` at the root level
|
|
1049
|
+
- Is the root of all schemas
|
|
1050
|
+
- Can be directly used with `type-crafter generate` command
|
|
1051
|
+
- Typically referenced by other files
|
|
1052
|
+
|
|
1053
|
+
#### What is a Non-Top File?
|
|
1054
|
+
|
|
1055
|
+
A **non-top file** is any YAML file that does NOT have `info:` at the root level. These files are used to organize types into domain-specific files.
|
|
1056
|
+
|
|
1057
|
+
**Identifying a non-top file:**
|
|
1058
|
+
```yaml
|
|
1059
|
+
# ✅ This is a NON-TOP FILE (no info section at root)
|
|
1060
|
+
Cart:
|
|
1061
|
+
SCart:
|
|
1062
|
+
type: object
|
|
1063
|
+
properties:
|
|
1064
|
+
items: { ... }
|
|
1065
|
+
|
|
1066
|
+
SCartItem:
|
|
1067
|
+
type: object
|
|
1068
|
+
properties:
|
|
1069
|
+
id: { ... }
|
|
985
1070
|
```
|
|
986
1071
|
|
|
987
|
-
**
|
|
1072
|
+
**Characteristics:**
|
|
1073
|
+
- Does NOT have `info:` section at the root level
|
|
1074
|
+
- Must be referenced from a top file or another file
|
|
1075
|
+
- Used for better organization of types in domain-specific files
|
|
1076
|
+
- Cannot be used directly with `type-crafter generate` command
|
|
988
1077
|
|
|
989
|
-
|
|
990
|
-
- Grouped: `#/groupedTypes/GroupName/TypeName`
|
|
1078
|
+
### Referencing Rules
|
|
991
1079
|
|
|
992
|
-
|
|
1080
|
+
#### Rule 1: References in TOP Files
|
|
993
1081
|
|
|
994
|
-
|
|
1082
|
+
**In top files, you can reference types using `#` without specifying the file path.**
|
|
1083
|
+
|
|
1084
|
+
**Example:**
|
|
995
1085
|
|
|
996
1086
|
```yaml
|
|
997
|
-
#
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
author:
|
|
1002
|
-
$ref: './src/types/users.yaml#/User'
|
|
1087
|
+
# File: types.yaml (TOP FILE - has info section)
|
|
1088
|
+
info:
|
|
1089
|
+
version: '0.0.0'
|
|
1090
|
+
title: 'Sample Typing Spec'
|
|
1003
1091
|
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1092
|
+
types:
|
|
1093
|
+
TypeObjectTwo:
|
|
1094
|
+
type: object
|
|
1095
|
+
properties:
|
|
1096
|
+
propOne:
|
|
1097
|
+
$ref: '#/types/TypeObjectOne' # ✅ Direct reference (no file path needed)
|
|
1010
1098
|
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1099
|
+
TypeObjectOne:
|
|
1100
|
+
type: object
|
|
1101
|
+
properties:
|
|
1102
|
+
name:
|
|
1103
|
+
type: string
|
|
1104
|
+
```
|
|
1105
|
+
|
|
1106
|
+
**Valid reference formats in top files:**
|
|
1107
|
+
- Same file, top-level type: `#/types/TypeName`
|
|
1108
|
+
- Same file, grouped type: `#/groupedTypes/GroupName/TypeName`
|
|
1109
|
+
- External file: `'./path/from/root/file.yaml#/TypeName'` (when referencing another file)
|
|
1110
|
+
|
|
1111
|
+
#### Rule 2: References in NON-TOP Files
|
|
1112
|
+
|
|
1113
|
+
**In non-top files, you MUST specify the complete file path (from project root) when referencing ANY type, even types in the same file.**
|
|
1114
|
+
|
|
1115
|
+
**Example:**
|
|
1116
|
+
|
|
1117
|
+
```yaml
|
|
1118
|
+
# File: docs/cart.yaml (NON-TOP FILE - no info section)
|
|
1119
|
+
Cart:
|
|
1120
|
+
SCart:
|
|
1121
|
+
description: 'Shopify cart object'
|
|
1122
|
+
type: object
|
|
1123
|
+
properties:
|
|
1017
1124
|
items:
|
|
1018
|
-
|
|
1125
|
+
type: array
|
|
1126
|
+
items:
|
|
1127
|
+
$ref: './docs/cart.yaml#/Cart/SCartItem' # ✅ MUST include full file path
|
|
1128
|
+
|
|
1129
|
+
SCartItem:
|
|
1130
|
+
description: 'Individual cart item'
|
|
1131
|
+
type: object
|
|
1132
|
+
properties:
|
|
1133
|
+
id:
|
|
1134
|
+
type: number
|
|
1019
1135
|
```
|
|
1020
1136
|
|
|
1021
|
-
**
|
|
1137
|
+
**Why the full path?** Non-top files don't have an `info` section, so they don't have a root context. You must always specify where the type is located.
|
|
1138
|
+
|
|
1139
|
+
### Complete Examples
|
|
1140
|
+
|
|
1141
|
+
#### Example 1: Top File with Local References
|
|
1022
1142
|
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1143
|
+
```yaml
|
|
1144
|
+
# File: types.yaml (TOP FILE)
|
|
1145
|
+
info:
|
|
1146
|
+
version: '1.0.0'
|
|
1147
|
+
title: 'API Types'
|
|
1148
|
+
|
|
1149
|
+
types:
|
|
1150
|
+
Post:
|
|
1151
|
+
type: object
|
|
1152
|
+
properties:
|
|
1153
|
+
author:
|
|
1154
|
+
$ref: '#/types/User' # ✅ Local reference in top file (no path)
|
|
1155
|
+
comments:
|
|
1156
|
+
type: array
|
|
1157
|
+
items:
|
|
1158
|
+
$ref: '#/types/Comment' # ✅ Local reference in top file (no path)
|
|
1159
|
+
|
|
1160
|
+
User:
|
|
1161
|
+
type: object
|
|
1162
|
+
properties:
|
|
1163
|
+
id: { type: string }
|
|
1164
|
+
name: { type: string }
|
|
1026
1165
|
|
|
1027
|
-
|
|
1166
|
+
Comment:
|
|
1167
|
+
type: object
|
|
1168
|
+
properties:
|
|
1169
|
+
text: { type: string }
|
|
1170
|
+
```
|
|
1171
|
+
|
|
1172
|
+
#### Example 2: Top File Referencing Non-Top Files
|
|
1173
|
+
|
|
1174
|
+
```yaml
|
|
1175
|
+
# File: types.yaml (TOP FILE)
|
|
1176
|
+
info:
|
|
1177
|
+
version: '0.0.0'
|
|
1178
|
+
title: 'Sample Typing Spec'
|
|
1179
|
+
|
|
1180
|
+
groupedTypes:
|
|
1181
|
+
Cart:
|
|
1182
|
+
$ref: './docs/cart.yaml#/Cart' # ✅ Importing entire Cart group from non-top file
|
|
1183
|
+
|
|
1184
|
+
# Project structure:
|
|
1185
|
+
# .
|
|
1186
|
+
# ├── types.yaml (this file - top file)
|
|
1187
|
+
# └── docs/
|
|
1188
|
+
# └── cart.yaml (non-top file)
|
|
1189
|
+
```
|
|
1190
|
+
|
|
1191
|
+
```yaml
|
|
1192
|
+
# File: docs/cart.yaml (NON-TOP FILE)
|
|
1193
|
+
Cart:
|
|
1194
|
+
SCart:
|
|
1195
|
+
description: 'Shopify cart object'
|
|
1196
|
+
type: object
|
|
1197
|
+
required:
|
|
1198
|
+
- items
|
|
1199
|
+
properties:
|
|
1200
|
+
items:
|
|
1201
|
+
type: array
|
|
1202
|
+
items:
|
|
1203
|
+
$ref: './docs/cart.yaml#/Cart/SCartItem' # ✅ Full path required in non-top file
|
|
1204
|
+
|
|
1205
|
+
SCartItem:
|
|
1206
|
+
description: 'Individual item in the cart'
|
|
1207
|
+
type: object
|
|
1208
|
+
required:
|
|
1209
|
+
- id
|
|
1210
|
+
properties:
|
|
1211
|
+
id:
|
|
1212
|
+
type: number
|
|
1213
|
+
description: 'Unique item identifier'
|
|
1214
|
+
quantity:
|
|
1215
|
+
type: number
|
|
1216
|
+
```
|
|
1217
|
+
|
|
1218
|
+
#### Example 3: Non-Top File Referencing Another Non-Top File
|
|
1219
|
+
|
|
1220
|
+
```yaml
|
|
1221
|
+
# File: docs/order.yaml (NON-TOP FILE)
|
|
1222
|
+
Order:
|
|
1223
|
+
SOrder:
|
|
1224
|
+
type: object
|
|
1225
|
+
properties:
|
|
1226
|
+
items:
|
|
1227
|
+
type: array
|
|
1228
|
+
items:
|
|
1229
|
+
$ref: './docs/cart.yaml#/Cart/SCartItem' # ✅ Full path to another non-top file
|
|
1230
|
+
customer:
|
|
1231
|
+
$ref: './docs/user.yaml#/User/SCustomer' # ✅ Full path to another non-top file
|
|
1232
|
+
```
|
|
1233
|
+
|
|
1234
|
+
### Reference Format Summary
|
|
1235
|
+
|
|
1236
|
+
| File Type | Referencing Same File | Referencing Another File |
|
|
1237
|
+
|-----------|----------------------|--------------------------|
|
|
1238
|
+
| **Top File** | `#/types/TypeName`<br>`#/groupedTypes/Group/TypeName` | `'./path/from/root/file.yaml#/TypeName'` |
|
|
1239
|
+
| **Non-Top File** | `'./path/from/root/current-file.yaml#/TypeName'`<br>(full path required) | `'./path/from/root/other-file.yaml#/TypeName'` |
|
|
1240
|
+
|
|
1241
|
+
### Path Rules (All Files)
|
|
1242
|
+
|
|
1243
|
+
1. **Paths are from project root** (where you run `type-crafter` command), NOT relative to current file
|
|
1244
|
+
2. **Always start with `./`** for file paths
|
|
1245
|
+
3. **Never use `../`** for relative navigation
|
|
1246
|
+
4. **Case matters** - file paths are case-sensitive on some systems
|
|
1247
|
+
|
|
1248
|
+
**Example project structure:**
|
|
1249
|
+
```
|
|
1250
|
+
project-root/
|
|
1251
|
+
├── types.yaml (top file)
|
|
1252
|
+
└── docs/
|
|
1253
|
+
├── cart.yaml (non-top file)
|
|
1254
|
+
└── user.yaml (non-top file)
|
|
1255
|
+
```
|
|
1028
1256
|
|
|
1029
|
-
|
|
1030
|
-
-
|
|
1031
|
-
-
|
|
1257
|
+
If running `type-crafter generate typescript ./types.yaml ./output` from `project-root/`:
|
|
1258
|
+
- Path to cart.yaml: `'./docs/cart.yaml#/...'`
|
|
1259
|
+
- Path to user.yaml: `'./docs/user.yaml#/...'`
|
|
1032
1260
|
|
|
1033
1261
|
### Group References (Entire Group)
|
|
1034
1262
|
|