@rexeus/typeweaver-types 0.10.3 → 0.10.4
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.
|
@@ -20,7 +20,7 @@ export declare abstract class ResponseValidator<
|
|
|
20
20
|
TResponse extends ITypedHttpResponse = ITypedHttpResponse,
|
|
21
21
|
>
|
|
22
22
|
extends Validator
|
|
23
|
-
implements IResponseValidator
|
|
23
|
+
implements IResponseValidator<TResponse>
|
|
24
24
|
{
|
|
25
25
|
protected abstract readonly responseEntries: readonly ResponseEntry[];
|
|
26
26
|
protected abstract readonly expectedStatusCodes: readonly number[];
|
|
@@ -29,9 +29,16 @@ export class ResponseValidator extends Validator {
|
|
|
29
29
|
* @returns A result object containing either the validated response or error details
|
|
30
30
|
*/
|
|
31
31
|
safeValidate(response) {
|
|
32
|
-
const
|
|
32
|
+
const statusCode = typeof response === "object" && response !== null
|
|
33
|
+
? response.statusCode
|
|
34
|
+
: undefined;
|
|
35
|
+
const error = new ResponseValidationError(statusCode);
|
|
36
|
+
if (typeof statusCode !== "number") {
|
|
37
|
+
error.addStatusCodeIssue([...this.expectedStatusCodes]);
|
|
38
|
+
return { isValid: false, error };
|
|
39
|
+
}
|
|
33
40
|
for (const entry of this.responseEntries) {
|
|
34
|
-
if (
|
|
41
|
+
if (statusCode === entry.statusCode) {
|
|
35
42
|
const result = this.validateResponseType(entry.name, entry.headerSchema, entry.bodySchema)(response, error);
|
|
36
43
|
if (result.isValid)
|
|
37
44
|
return result;
|
package/dist/lib/Validator.js
CHANGED
|
@@ -83,7 +83,7 @@ export class Validator {
|
|
|
83
83
|
* @returns Coerced data object with proper key casing and array coercion
|
|
84
84
|
*/
|
|
85
85
|
coerceToSchema(data, shape, caseSensitive) {
|
|
86
|
-
if (typeof data !== "object" || data === null) {
|
|
86
|
+
if (typeof data !== "object" || data === null || Array.isArray(data)) {
|
|
87
87
|
return data;
|
|
88
88
|
}
|
|
89
89
|
const schemaMap = this.analyzeSchema(shape, caseSensitive);
|
|
@@ -160,6 +160,9 @@ export class Validator {
|
|
|
160
160
|
if (typeof header !== "object" || header === null) {
|
|
161
161
|
return this.coerceToSchema(header ?? {}, shape, false);
|
|
162
162
|
}
|
|
163
|
+
if (Array.isArray(header)) {
|
|
164
|
+
return header;
|
|
165
|
+
}
|
|
163
166
|
const preprocessed = this.splitCommaDelimitedValues(header, shape);
|
|
164
167
|
return this.coerceToSchema(preprocessed, shape, false);
|
|
165
168
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexeus/typeweaver-types",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
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-core": "^0.10.
|
|
51
|
-
"@rexeus/typeweaver-gen": "^0.10.
|
|
50
|
+
"@rexeus/typeweaver-core": "^0.10.4",
|
|
51
|
+
"@rexeus/typeweaver-gen": "^0.10.4"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"test-utils": "file:../test-utils",
|
|
55
|
-
"@rexeus/typeweaver-core": "^0.10.
|
|
56
|
-
"@rexeus/typeweaver-gen": "^0.10.
|
|
55
|
+
"@rexeus/typeweaver-core": "^0.10.4",
|
|
56
|
+
"@rexeus/typeweaver-gen": "^0.10.4"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"polycase": "^1.1.0",
|
|
60
|
-
"@rexeus/typeweaver-zod-to-ts": "^0.10.
|
|
60
|
+
"@rexeus/typeweaver-zod-to-ts": "^0.10.4"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"typecheck": "tsc --noEmit -p tsconfig.typecheck.json",
|