@ts-rest/core
Advanced tools
Comparing version 3.26.0 to 3.26.1
# @ts-rest/core | ||
## 3.26.1 | ||
## 3.26.0 | ||
@@ -4,0 +6,0 @@ |
14
index.js
@@ -331,4 +331,5 @@ 'use strict'; | ||
class ResponseValidationError extends Error { | ||
constructor(cause) { | ||
super('Response validation failed'); | ||
constructor(appRoute, cause) { | ||
super(`[ts-rest] Response validation failed for ${appRoute.method} ${appRoute.path}: ${cause.message}`); | ||
this.appRoute = appRoute; | ||
this.cause = cause; | ||
@@ -349,12 +350,11 @@ } | ||
}; | ||
const validateResponse = ({ responseType, response, }) => { | ||
const validateResponse = ({ appRoute, response, }) => { | ||
if (isAppRouteResponse(response)) { | ||
const { body } = response; | ||
const responseType = appRoute.responses[response.status]; | ||
const responseSchema = isAppRouteOtherResponse(responseType) | ||
? responseType.body | ||
: responseType; | ||
const responseValidation = checkZodSchema(body, responseSchema); | ||
const responseValidation = checkZodSchema(response.body, responseSchema); | ||
if (!responseValidation.success) { | ||
const { error } = responseValidation; | ||
throw new ResponseValidationError(error); | ||
throw new ResponseValidationError(appRoute, responseValidation.error); | ||
} | ||
@@ -361,0 +361,0 @@ return { |
{ | ||
"name": "@ts-rest/core", | ||
"version": "3.26.0", | ||
"version": "3.26.1", | ||
"description": "RPC-like experience over a regular REST API, with type safe server implementations ๐ช", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -10,16 +10,8 @@ # ts-rest | ||
<p align="center"> | ||
<a href="https://www.npmjs.com/package/@ts-rest/core"> | ||
<img src="https://img.shields.io/npm/v/@ts-rest/core.svg" alt="langue typescript"/> | ||
</a> | ||
<a href="https://www.npmjs.com/package/@ts-rest/core"><img src="https://img.shields.io/npm/v/@ts-rest/core.svg" alt="langue typescript"/></a> | ||
<img alt="Github Workflow Status" src="https://img.shields.io/github/actions/workflow/status/ts-rest/ts-rest/release.yml?branch=main"/> | ||
<a href="https://www.npmjs.com/package/@ts-rest/core"> | ||
<img alt="npm" src="https://img.shields.io/npm/dw/@ts-rest/core"/> | ||
</a> | ||
<a href="https://github.com/ts-rest/ts-rest/blob/main/LICENSE"> | ||
<img alt="License" src="https://img.shields.io/github/license/ts-rest/ts-rest"/> | ||
</a> | ||
<a href="https://www.npmjs.com/package/@ts-rest/core"><img alt="npm" src="https://img.shields.io/npm/dw/@ts-rest/core"/></a> | ||
<a href="https://github.com/ts-rest/ts-rest/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/github/license/ts-rest/ts-rest"/></a> | ||
<img alt="Bundle Size" src="https://img.shields.io/bundlephobia/minzip/@ts-rest/core?label=%40ts-rest%2Fcore"/> | ||
<a href="https://discord.com/invite/2Megk85k5a"> | ||
<img alt="Discord" src="https://img.shields.io/discord/1055855205960392724"/> | ||
</a> | ||
<a href="https://discord.com/invite/2Megk85k5a"><img alt="Discord" src="https://img.shields.io/discord/1055855205960392724"/></a> | ||
</p> | ||
@@ -55,3 +47,3 @@ | ||
responses: { | ||
200: c.response<Post[]>(), // <-- OR normal TS types | ||
200: c.type<Post[]>(), // <-- OR normal TS types | ||
}, | ||
@@ -58,0 +50,0 @@ headers: z.object({ |
import { z } from 'zod'; | ||
import { AppRoute } from './dsl'; | ||
export declare class ResponseValidationError extends Error { | ||
appRoute: AppRoute; | ||
cause: z.ZodError; | ||
constructor(cause: z.ZodError); | ||
constructor(appRoute: AppRoute, cause: z.ZodError); | ||
} |
import { HTTPStatusCode } from './status-codes'; | ||
import { ContractAnyType, ContractOtherResponse } from './dsl'; | ||
import { AppRoute, ContractAnyType, ContractOtherResponse } from './dsl'; | ||
export declare const isAppRouteResponse: (value: unknown) => value is { | ||
@@ -8,4 +8,4 @@ status: HTTPStatusCode; | ||
export declare const isAppRouteOtherResponse: (response: ContractAnyType | ContractOtherResponse<ContractAnyType>) => response is ContractOtherResponse<ContractAnyType>; | ||
export declare const validateResponse: ({ responseType, response, }: { | ||
responseType: ContractAnyType | ContractOtherResponse<ContractAnyType>; | ||
export declare const validateResponse: ({ appRoute, response, }: { | ||
appRoute: AppRoute; | ||
response: { | ||
@@ -12,0 +12,0 @@ status: number; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67855
1239
148