@ts-rest/core
Advanced tools
Comparing version 3.13.1 to 3.14.0
10
index.js
@@ -183,10 +183,2 @@ const isAppRoute = (obj) => { | ||
function getValue(data, path, defaultValue) { | ||
const value = path | ||
.split(/[.[\]]/) | ||
.filter(Boolean) | ||
.reduce((value, key) => value === null || value === void 0 ? void 0 : value[key], data); | ||
return value !== undefined ? value : defaultValue; | ||
} | ||
const isZodObject = (body) => { | ||
@@ -217,2 +209,2 @@ return (body === null || body === void 0 ? void 0 : body.safeParse) !== undefined; | ||
export { checkZodSchema, convertQueryParamsToUrlString, defaultApi, encodeQueryParams, encodeQueryParamsJson, fetchApi, getCompleteUrl, getRouteQuery, getRouteResponses, getValue, initClient, initContract, initTsRest, insertParamsIntoPath, isAppRoute, isZodObject, parseJsonQueryObject }; | ||
export { checkZodSchema, convertQueryParamsToUrlString, defaultApi, encodeQueryParams, encodeQueryParamsJson, fetchApi, getCompleteUrl, getRouteQuery, getRouteResponses, initClient, initContract, initTsRest, insertParamsIntoPath, isAppRoute, isZodObject, parseJsonQueryObject }; |
{ | ||
"name": "@ts-rest/core", | ||
"version": "3.13.1", | ||
"version": "3.14.0", | ||
"description": "RPC-like experience over a regular REST API, with type safe server implementations 🪄", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -1,2 +0,1 @@ | ||
import { Narrow } from './type-utils'; | ||
/** | ||
@@ -37,2 +36,10 @@ * The path with colon-prefixed parameters | ||
/** | ||
* Recursively process a router, allowing for you to define nested routers. | ||
* | ||
* The main purpose of this is to convert all path strings into string constants so we can infer the path | ||
*/ | ||
type RecursivelyProcessAppRouter<T extends AppRouter> = { | ||
[K in keyof T]: T[K] extends AppRoute ? T[K] : T[K] extends AppRouter ? RecursivelyProcessAppRouter<T[K]> : T[K]; | ||
}; | ||
/** | ||
* A union of all possible endpoint types. | ||
@@ -62,3 +69,3 @@ */ | ||
*/ | ||
router: <T extends AppRouter>(endpoints: Narrow<T>) => T; | ||
router: <T extends AppRouter>(endpoints: RecursivelyProcessAppRouter<T>) => T; | ||
/** | ||
@@ -68,3 +75,3 @@ * A single query route, should exist within | ||
*/ | ||
query: <T extends AppRouteQuery>(query: Narrow<T>) => T; | ||
query: <T extends AppRouteQuery>(query: T) => T; | ||
/** | ||
@@ -74,3 +81,3 @@ * A single mutation route, should exist within | ||
*/ | ||
mutation: <T extends AppRouteMutation>(mutation: Narrow<T>) => T; | ||
mutation: <T extends AppRouteMutation>(mutation: T) => T; | ||
/** | ||
@@ -77,0 +84,0 @@ * Exists to allow storing a Type in the contract (at compile time only) |
@@ -1,2 +0,2 @@ | ||
import { z, ZodType, ZodTypeAny } from 'zod'; | ||
import { z, ZodTypeAny } from 'zod'; | ||
type GetIndexedField<T, K> = K extends keyof T ? T[K] : K extends `${number}` ? '0' extends keyof T ? undefined : number extends keyof T ? T[number] : undefined : undefined; | ||
@@ -6,3 +6,2 @@ type FieldWithPossiblyUndefined<T, Key> = GetFieldType<Exclude<T, undefined>, Key> | Extract<T, undefined>; | ||
export type GetFieldType<T, P> = P extends `${infer Left}.${infer Right}` ? Left extends keyof T ? FieldWithPossiblyUndefined<T[Left], Right> : Left extends `${infer FieldKey}[${infer IndexKey}]` ? FieldKey extends keyof T ? FieldWithPossiblyUndefined<IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey>, Right> : undefined : undefined : P extends keyof T ? T[P] : P extends `${infer FieldKey}[${infer IndexKey}]` ? FieldKey extends keyof T ? IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey> : undefined : undefined; | ||
export declare function getValue<TData, TPath extends string, TDefault = GetFieldType<TData, TPath>>(data: TData, path: TPath, defaultValue?: TDefault): GetFieldType<TData, TPath> | TDefault; | ||
type ExcludeKeysWithTypeOf<T, V> = { | ||
@@ -18,8 +17,2 @@ [K in keyof T]: Exclude<T[K], undefined> extends V ? never : K; | ||
export type Merge<T, U> = Omit<T, keyof U> & U; | ||
type Try<A, B, C> = A extends B ? A : C; | ||
type NarrowRaw<T> = (T extends Function ? T : never) | (T extends string | number | bigint | boolean ? T : never) | (T extends [] ? [] : never) | { | ||
[K in keyof T]: K extends 'description' ? T[K] : NarrowNotZod<T[K]>; | ||
}; | ||
type NarrowNotZod<T> = Try<T, ZodType, NarrowRaw<T>>; | ||
export type Narrow<T> = Try<T, [], NarrowNotZod<T>>; | ||
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; | ||
@@ -26,0 +19,0 @@ type OptionalKeys<T> = T extends unknown ? { |
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
32462
695