@ts-rest/core
Advanced tools
Comparing version 3.42.0 to 3.43.0
# @ts-rest/core | ||
## 3.43.0 | ||
### Minor Changes | ||
- 308b966: `TsRestResponseError` can be thrown from any server package | ||
## 3.42.0 | ||
@@ -4,0 +10,0 @@ |
@@ -271,3 +271,3 @@ 'use strict'; | ||
const combinedHeaders = { | ||
...normalizeHeaders(clientArgs.baseHeaders), | ||
...(clientArgs.baseHeaders && normalizeHeaders(clientArgs.baseHeaders)), | ||
...normalizeHeaders(headers), | ||
@@ -439,5 +439,27 @@ }; | ||
class TsRestResponseError extends Error { | ||
constructor(route, response) { | ||
super(); | ||
this.statusCode = response.status; | ||
this.body = response.body; | ||
this.name = this.constructor.name; | ||
if (typeof response.body === 'string') { | ||
this.message = response.body; | ||
} | ||
else if (typeof response.body === 'object' && | ||
response.body !== null && | ||
'message' in response.body && | ||
typeof response.body.message === 'string') { | ||
this.message = response.body['message']; | ||
} | ||
else { | ||
this.message = 'Error'; | ||
} | ||
} | ||
} | ||
exports.ContractNoBody = ContractNoBody; | ||
exports.ContractPlainTypeRuntimeSymbol = ContractPlainTypeRuntimeSymbol; | ||
exports.ResponseValidationError = ResponseValidationError; | ||
exports.TsRestResponseError = TsRestResponseError; | ||
exports.UnknownStatusError = UnknownStatusError; | ||
@@ -444,0 +466,0 @@ exports.checkZodSchema = checkZodSchema; |
@@ -267,3 +267,3 @@ const isZodType = (obj) => { | ||
const combinedHeaders = { | ||
...normalizeHeaders(clientArgs.baseHeaders), | ||
...(clientArgs.baseHeaders && normalizeHeaders(clientArgs.baseHeaders)), | ||
...normalizeHeaders(headers), | ||
@@ -435,2 +435,23 @@ }; | ||
export { ContractNoBody, ContractPlainTypeRuntimeSymbol, ResponseValidationError, UnknownStatusError, checkZodSchema, convertQueryParamsToUrlString, encodeQueryParams, encodeQueryParamsJson, evaluateFetchApiArgs, extractZodObjectShape, fetchApi, getCompleteUrl, getRouteQuery, getRouteResponses, initClient, initContract, initTsRest, insertParamsIntoPath, isAppRoute, isAppRouteNoBody, isAppRouteOtherResponse, isAppRouteResponse, isZodObject, isZodObjectStrict, isZodType, parseJsonQueryObject, tsRestFetchApi, validateResponse, zodErrorResponse, zodMerge }; | ||
class TsRestResponseError extends Error { | ||
constructor(route, response) { | ||
super(); | ||
this.statusCode = response.status; | ||
this.body = response.body; | ||
this.name = this.constructor.name; | ||
if (typeof response.body === 'string') { | ||
this.message = response.body; | ||
} | ||
else if (typeof response.body === 'object' && | ||
response.body !== null && | ||
'message' in response.body && | ||
typeof response.body.message === 'string') { | ||
this.message = response.body['message']; | ||
} | ||
else { | ||
this.message = 'Error'; | ||
} | ||
} | ||
} | ||
export { ContractNoBody, ContractPlainTypeRuntimeSymbol, ResponseValidationError, TsRestResponseError, UnknownStatusError, checkZodSchema, convertQueryParamsToUrlString, encodeQueryParams, encodeQueryParamsJson, evaluateFetchApiArgs, extractZodObjectShape, fetchApi, getCompleteUrl, getRouteQuery, getRouteResponses, initClient, initContract, initTsRest, insertParamsIntoPath, isAppRoute, isAppRouteNoBody, isAppRouteOtherResponse, isAppRouteResponse, isZodObject, isZodObjectStrict, isZodType, parseJsonQueryObject, tsRestFetchApi, validateResponse, zodErrorResponse, zodMerge }; |
{ | ||
"name": "@ts-rest/core", | ||
"version": "3.42.0", | ||
"version": "3.43.0", | ||
"description": "RPC-like experience over a regular REST API, with type safe server implementations 🪄", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -12,1 +12,2 @@ export * from './lib/client'; | ||
export * from './lib/infer-types'; | ||
export * from './lib/response-error'; |
@@ -27,3 +27,3 @@ import { AppRoute, AppRouteMutation, AppRouter } from './dsl'; | ||
export interface ClientArgs extends OverrideableClientArgs { | ||
baseHeaders: Record<string, string>; | ||
baseHeaders?: Record<string, string>; | ||
api?: ApiFetcher; | ||
@@ -30,0 +30,0 @@ } |
@@ -46,5 +46,3 @@ import { AppRoute, AppRouteMutation, AppRouter, AppRouteStrictStatusCodes, ContractAnyType, ContractNoBodyType, ContractOtherResponse } from './dsl'; | ||
} : never; | ||
type ClientInferRequestBase<T extends AppRoute, TClientArgs extends Omit<ClientArgs, 'baseUrl'> = { | ||
baseHeaders: {}; | ||
}, THeaders = 'headers' extends keyof T ? Prettify<PartialByLooseKeys<LowercaseKeys<ZodInputOrType<T['headers']>>, keyof LowercaseKeys<TClientArgs['baseHeaders']>>> : never, TFetchOptions extends FetchOptions = FetchOptions> = Prettify<Without<{ | ||
type ClientInferRequestBase<T extends AppRoute, TClientArgs extends Omit<ClientArgs, 'baseUrl'> = {}, THeaders = 'headers' extends keyof T ? Prettify<PartialByLooseKeys<LowercaseKeys<ZodInputOrType<T['headers']>>, keyof LowercaseKeys<TClientArgs['baseHeaders']>>> : never, TFetchOptions extends FetchOptions = FetchOptions> = Prettify<Without<{ | ||
params: [keyof PathParamsWithCustomValidators<T, 'client'>] extends [ | ||
@@ -70,10 +68,6 @@ never | ||
} & ExtractExtraParametersFromClientArgs<TClientArgs>, never>>; | ||
export type ClientInferRequest<T extends AppRoute | AppRouter, TClientArgs extends Omit<ClientArgs, 'baseUrl'> = { | ||
baseHeaders: {}; | ||
}> = T extends AppRoute ? ClientInferRequestBase<T, TClientArgs> : T extends AppRouter ? { | ||
export type ClientInferRequest<T extends AppRoute | AppRouter, TClientArgs extends Omit<ClientArgs, 'baseUrl'> = {}> = T extends AppRoute ? ClientInferRequestBase<T, TClientArgs> : T extends AppRouter ? { | ||
[TKey in keyof T]: ClientInferRequest<T[TKey]>; | ||
} : never; | ||
export type PartialClientInferRequest<TRoute extends AppRoute, TClientArgs extends Omit<ClientArgs, 'baseUrl'> = { | ||
baseHeaders: {}; | ||
}> = OptionalIfAllOptional<ClientInferRequest<TRoute, TClientArgs>>; | ||
export type PartialClientInferRequest<TRoute extends AppRoute, TClientArgs extends Omit<ClientArgs, 'baseUrl'> = {}> = OptionalIfAllOptional<ClientInferRequest<TRoute, TClientArgs>>; | ||
export {}; |
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
84815
23
1495