Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ts-rest/core

Package Overview
Dependencies
Maintainers
1
Versions
136
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ts-rest/core - npm Package Compare versions

Comparing version 3.27.0 to 3.28.0

7

CHANGELOG.md
# @ts-rest/core
## 3.28.0
### Minor Changes
- a7755ef: Adds support for fetch cache and support for Nextjs App Dir fetch (docs coming soon), see this PR for more info: https://github.com/ts-rest/ts-rest/pull/315
- 16501dd: tsRestFetchApi should be more flexible when determining application/json content type header
## 3.27.0

@@ -4,0 +11,0 @@

15

index.js

@@ -198,3 +198,3 @@ 'use strict';

}
const tsRestFetchApi = async ({ path, method, headers, body, credentials, signal, }) => {
const tsRestFetchApi = async ({ path, method, headers, body, credentials, signal, cache, next }) => {
const result = await fetch(path, {

@@ -206,5 +206,7 @@ method,

signal,
cache,
next
});
const contentType = result.headers.get('content-type');
if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/json')) {
if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/")) && (contentType === null || contentType === void 0 ? void 0 : contentType.includes('json'))) {
return {

@@ -244,3 +246,3 @@ status: result.status,

};
const fetchApi = ({ path, clientArgs, route, body, query, extraInputArgs, headers, signal, }) => {
const fetchApi = ({ path, clientArgs, route, body, query, extraInputArgs, headers, signal, next }) => {
const apiFetcher = clientArgs.api || tsRestFetchApi;

@@ -268,2 +270,3 @@ const combinedHeaders = {

signal,
next,
...extraInputArgs,

@@ -286,2 +289,3 @@ });

signal,
next,
...extraInputArgs,

@@ -301,3 +305,5 @@ });

return async (inputArgs) => {
const { query, params, body, headers, extraHeaders, ...extraInputArgs } = inputArgs || {};
const { query, params, body, headers, extraHeaders, next, ...extraInputArgs } =
inputArgs
|| {};
const completeUrl = getCompleteUrl(query, clientArgs.baseUrl, params, route, !!clientArgs.jsonQuery);

@@ -311,2 +317,3 @@ const response = await fetchApi({

extraInputArgs,
next,
headers: {

@@ -313,0 +320,0 @@ ...extraHeaders,

{
"name": "@ts-rest/core",
"version": "3.27.0",
"version": "3.28.0",
"description": "RPC-like experience over a regular REST API, with type safe server implementations 🪄",

@@ -5,0 +5,0 @@ "license": "MIT",

import { AppRoute, AppRouteMutation, AppRouter } from './dsl';
import { AreAllPropertiesOptional, Prettify } from './type-utils';
import { ClientInferRequest, ClientInferResponses, PartialClientInferRequest } from './infer-types';
import { ClientInferRequest, ClientInferResponses, PartialClientInferRequest, NextClientArgs, Frameworks } from './infer-types';
type RecursiveProxyObj<T extends AppRouter, TClientArgs extends ClientArgs> = {

@@ -37,2 +37,8 @@ [TKey in keyof T]: T[TKey] extends AppRoute ? AppRouteFunction<T[TKey], TClientArgs> : T[TKey] extends AppRouter ? RecursiveProxyObj<T[TKey], TClientArgs> : never;

signal?: AbortSignal;
cache?: RequestCache;
/**
* Only to be used by `@ts-rest/next`.
* You can obtain a Nextjs Client by calling `initNextClient`
*/
next?: NextClientArgs['next'] | undefined;
};

@@ -52,3 +58,3 @@ export type ApiFetcher = (args: ApiFetcherArgs) => Promise<{

export declare const tsRestFetchApi: ApiFetcher;
export declare const fetchApi: ({ path, clientArgs, route, body, query, extraInputArgs, headers, signal, }: {
export declare const fetchApi: ({ path, clientArgs, route, body, query, extraInputArgs, headers, signal, next }: {
path: string;

@@ -62,2 +68,7 @@ clientArgs: ClientArgs;

signal?: AbortSignal | undefined;
/**
* only to be used by @ts-rest/next
* You can obtain a Nextjs Client by calling `initNextClient`
*/
next?: NextClientArgs['next'] | undefined;
}) => Promise<{

@@ -72,3 +83,33 @@ status: number;

export declare const getCompleteUrl: (query: unknown, baseUrl: string, params: unknown, route: AppRoute, jsonQuery: boolean) => string;
export declare const getRouteQuery: <TAppRoute extends AppRoute>(route: TAppRoute, clientArgs: InitClientArgs) => (inputArgs?: ClientInferRequest<AppRouteMutation, ClientArgs>) => Promise<{
export declare const getRouteQuery: <TAppRoute extends AppRoute, Framework extends Frameworks = "none">(route: TAppRoute, clientArgs: InitClientArgs) => (inputArgs?: (Framework extends "nextjs" ? {
headers: {
[x: Lowercase<string>]: any;
};
body: any;
cache?: RequestCache | undefined;
next?: {
revalidate?: number | false | undefined;
tags?: string[] | undefined;
} | undefined;
params: {
[x: string]: any;
};
query: any;
extraHeaders?: ({
[x: Lowercase<string> & {}]: undefined;
} & Record<string, string | undefined>) | undefined;
} : {
headers: {
[x: Lowercase<string>]: any;
};
body: any;
cache?: RequestCache | undefined;
params: {
[x: string]: any;
};
query: any;
extraHeaders?: ({
[x: Lowercase<string> & {}]: undefined;
} & Record<string, string | undefined>) | undefined;
}) | undefined) => Promise<{
status: number;

@@ -75,0 +116,0 @@ body: unknown;

@@ -6,2 +6,9 @@ import { AppRoute, AppRouteMutation, AppRouter, AppRouteStrictStatusCodes, ContractAnyType, ContractOtherResponse } from './dsl';

import { ParamsFromUrl } from './paths';
export type Frameworks = 'nextjs' | 'none';
export type NextClientArgs = {
next?: {
revalidate?: number | false;
tags?: string[];
} | undefined;
};
type ExtractExtraParametersFromClientArgs<TClientArgs extends Pick<ClientArgs, 'api'>> = TClientArgs['api'] extends ApiFetcher ? Omit<Parameters<TClientArgs['api']>[0], keyof Parameters<ApiFetcher>[0]> : {};

@@ -47,3 +54,3 @@ /**

} : never;
type ClientInferRequestBase<T extends AppRoute, TClientArgs extends Omit<ClientArgs, 'baseUrl'> = {
type ClientInferRequestBase<Framework extends Frameworks, T extends AppRoute, TClientArgs extends Omit<ClientArgs, 'baseUrl'> = {
baseHeaders: {};

@@ -60,6 +67,8 @@ }, THeaders = 'headers' extends keyof T ? Prettify<PartialByLooseKeys<LowercaseKeys<ZodInputOrType<T['headers']>>, keyof LowercaseKeys<TClientArgs['baseHeaders']>>> : never> = Prettify<Without<{

} & Record<string, string | undefined>;
cache?: RequestCache;
next?: Framework extends 'nextjs' ? NextClientArgs['next'] : 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 ? {
}, Framework extends Frameworks = 'none'> = T extends AppRoute ? ClientInferRequestBase<Framework, T, TClientArgs> : T extends AppRouter ? {
[TKey in keyof T]: ClientInferRequest<T[TKey]>;

@@ -69,3 +78,3 @@ } : never;

baseHeaders: {};
}> = OptionalIfAllOptional<ClientInferRequest<TRoute, TClientArgs>>;
}, Framework extends Frameworks = 'none'> = OptionalIfAllOptional<ClientInferRequest<TRoute, TClientArgs, Framework>>;
export {};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc