@rexeus/typeweaver-types 0.4.2 → 0.5.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 +2 -1
- package/dist/lib/Validator.ts +34 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -36,7 +36,8 @@ This plugin is included by default and doesn't need to be explicitly specified:
|
|
|
36
36
|
npx typeweaver generate --input ./api/definition --output ./api/generated --plugins clients
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
More details on how to use the
|
|
39
|
+
More details on how to use the
|
|
40
|
+
[CLI](https://github.com/rexeus/typeweaver/tree/main/packages/cli/README.md#️-cli).
|
|
40
41
|
|
|
41
42
|
## 📂 Generated Output
|
|
42
43
|
|
package/dist/lib/Validator.ts
CHANGED
|
@@ -219,7 +219,40 @@ export abstract class Validator {
|
|
|
219
219
|
* @returns Coerced header object
|
|
220
220
|
*/
|
|
221
221
|
protected coerceHeaderToSchema(header: unknown, shape: $ZodShape): unknown {
|
|
222
|
-
|
|
222
|
+
if (typeof header !== "object" || header === null) {
|
|
223
|
+
return this.coerceToSchema(header ?? {}, shape, false);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const preprocessed = this.splitCommaDelimitedValues(header, shape);
|
|
227
|
+
return this.coerceToSchema(preprocessed, shape, false);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Splits comma-separated header strings into arrays per RFC 7230.
|
|
232
|
+
* Only applies to fields where the schema expects an array type.
|
|
233
|
+
* Values that are already arrays pass through unchanged.
|
|
234
|
+
*/
|
|
235
|
+
private splitCommaDelimitedValues(
|
|
236
|
+
header: object,
|
|
237
|
+
shape: $ZodShape
|
|
238
|
+
): Record<string, unknown> {
|
|
239
|
+
const schemaMap = this.analyzeSchema(shape, false);
|
|
240
|
+
const result: Record<string, unknown> = {};
|
|
241
|
+
|
|
242
|
+
for (const [key, value] of Object.entries(header)) {
|
|
243
|
+
const schemaInfo = schemaMap.get(key.toLowerCase());
|
|
244
|
+
|
|
245
|
+
if (schemaInfo?.isArray && typeof value === "string") {
|
|
246
|
+
result[key] = value
|
|
247
|
+
.split(",")
|
|
248
|
+
.map(v => v.trim())
|
|
249
|
+
.filter(v => v !== "");
|
|
250
|
+
} else {
|
|
251
|
+
result[key] = value;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return result;
|
|
223
256
|
}
|
|
224
257
|
|
|
225
258
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexeus/typeweaver-types",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Generates request and response types plus validators aligned with your API contract. Powered by Typeweaver 🧵✨",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -47,17 +47,17 @@
|
|
|
47
47
|
},
|
|
48
48
|
"homepage": "https://github.com/rexeus/typeweaver#readme",
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@rexeus/typeweaver-
|
|
51
|
-
"@rexeus/typeweaver-
|
|
50
|
+
"@rexeus/typeweaver-gen": "^0.5.0",
|
|
51
|
+
"@rexeus/typeweaver-core": "^0.5.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"test-utils": "file:../test-utils",
|
|
55
|
-
"@rexeus/typeweaver-core": "^0.
|
|
56
|
-
"@rexeus/typeweaver-gen": "^0.
|
|
55
|
+
"@rexeus/typeweaver-core": "^0.5.0",
|
|
56
|
+
"@rexeus/typeweaver-gen": "^0.5.0"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"case": "^1.6.3",
|
|
60
|
-
"@rexeus/typeweaver-zod-to-ts": "^0.
|
|
60
|
+
"@rexeus/typeweaver-zod-to-ts": "^0.5.0"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"typecheck": "tsc --noEmit",
|