@rexeus/typeweaver-types 0.2.0 → 0.3.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/dist/index.cjs +14275 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.js +5996 -4534
- package/dist/lib/ResponseValidator.ts +1 -4
- package/dist/lib/Validator.ts +28 -0
- package/package.json +17 -10
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* @generated by @rexeus/typeweaver
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { z } from "zod";
|
|
9
8
|
import type {
|
|
10
9
|
HttpBodySchema,
|
|
11
10
|
HttpHeaderSchema,
|
|
@@ -94,9 +93,7 @@ export abstract class ResponseValidator
|
|
|
94
93
|
if (headerSchema) {
|
|
95
94
|
const coercedHeader = this.coerceHeaderToSchema(
|
|
96
95
|
response.header,
|
|
97
|
-
headerSchema
|
|
98
|
-
? headerSchema.shape
|
|
99
|
-
: headerSchema.unwrap().shape
|
|
96
|
+
this.getSchema(headerSchema)
|
|
100
97
|
);
|
|
101
98
|
const validateHeaderResult = headerSchema.safeParse(
|
|
102
99
|
coercedHeader
|
package/dist/lib/Validator.ts
CHANGED
|
@@ -5,7 +5,12 @@
|
|
|
5
5
|
* @generated by @rexeus/typeweaver
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import z from "zod";
|
|
8
9
|
import { $ZodArray, $ZodOptional } from "zod/v4/core";
|
|
10
|
+
import type {
|
|
11
|
+
HttpHeaderSchema,
|
|
12
|
+
HttpQuerySchema,
|
|
13
|
+
} from "@rexeus/typeweaver-core";
|
|
9
14
|
import type { $ZodShape } from "zod/v4/core";
|
|
10
15
|
|
|
11
16
|
type SchemaInfo = { readonly originalKey: string; readonly isArray: boolean };
|
|
@@ -52,6 +57,29 @@ export abstract class Validator {
|
|
|
52
57
|
return schemaMap;
|
|
53
58
|
}
|
|
54
59
|
|
|
60
|
+
/**
|
|
61
|
+
*
|
|
62
|
+
* Extracts a Zod schema shape from header or query schemas.
|
|
63
|
+
* This is used to support schema coercion and analysis.
|
|
64
|
+
*
|
|
65
|
+
* @param headerSchema
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
68
|
+
protected getSchema(
|
|
69
|
+
headerSchema: HttpHeaderSchema | HttpQuerySchema
|
|
70
|
+
): $ZodShape {
|
|
71
|
+
if (headerSchema instanceof z.ZodObject) {
|
|
72
|
+
return headerSchema.shape;
|
|
73
|
+
}
|
|
74
|
+
if (headerSchema instanceof z.ZodOptional) {
|
|
75
|
+
const unwrapped = headerSchema.unwrap();
|
|
76
|
+
if (unwrapped instanceof z.ZodObject) {
|
|
77
|
+
return unwrapped.shape;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return {};
|
|
81
|
+
}
|
|
82
|
+
|
|
55
83
|
/**
|
|
56
84
|
* Builds a schema map by analyzing the Zod shape structure.
|
|
57
85
|
* Extracts type information for each field to support proper coercion.
|
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexeus/typeweaver-types",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Generates request and response types plus validators aligned with your API contract. Powered by Typeweaver 🧵✨",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/index.
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
7
8
|
"types": "dist/index.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
|
-
"import":
|
|
11
|
-
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
12
19
|
}
|
|
13
20
|
},
|
|
14
21
|
"files": [
|
|
@@ -39,22 +46,22 @@
|
|
|
39
46
|
},
|
|
40
47
|
"homepage": "https://github.com/rexeus/typeweaver#readme",
|
|
41
48
|
"peerDependencies": {
|
|
42
|
-
"@rexeus/typeweaver-core": "^0.
|
|
43
|
-
"@rexeus/typeweaver-gen": "^0.
|
|
49
|
+
"@rexeus/typeweaver-core": "^0.3.0",
|
|
50
|
+
"@rexeus/typeweaver-gen": "^0.3.0"
|
|
44
51
|
},
|
|
45
52
|
"devDependencies": {
|
|
46
53
|
"test-utils": "file:../test-utils",
|
|
47
|
-
"@rexeus/typeweaver-
|
|
48
|
-
"@rexeus/typeweaver-
|
|
54
|
+
"@rexeus/typeweaver-gen": "^0.3.0",
|
|
55
|
+
"@rexeus/typeweaver-core": "^0.3.0"
|
|
49
56
|
},
|
|
50
57
|
"dependencies": {
|
|
51
58
|
"case": "^1.6.3",
|
|
52
|
-
"@rexeus/typeweaver-zod-to-ts": "^0.
|
|
59
|
+
"@rexeus/typeweaver-zod-to-ts": "^0.3.0"
|
|
53
60
|
},
|
|
54
61
|
"scripts": {
|
|
55
62
|
"typecheck": "tsc --noEmit",
|
|
56
63
|
"format": "prettier --write .",
|
|
57
|
-
"build": "
|
|
64
|
+
"build": "tsup && mkdir -p ./dist/templates ./dist/lib && cp -r ./src/templates/* ./dist/templates/ && cp -r ./src/lib/* ./dist/lib/ && cp ../../LICENSE ../../NOTICE ./dist/",
|
|
58
65
|
"test": "vitest --run",
|
|
59
66
|
"preversion": "npm run build"
|
|
60
67
|
}
|