@zayne-labs/callapi 1.11.4 → 1.11.6
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.
- package/README.md +35 -27
- package/dist/esm/{common-BdFk9r_h.d.ts → common-ClytspsT.d.ts} +38 -38
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +430 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/index.d.ts +57 -6
- package/dist/esm/utils/index.js +2 -2
- package/dist/esm/utils-DOVvfarH.js +225 -0
- package/dist/esm/utils-DOVvfarH.js.map +1 -0
- package/package.json +11 -11
- package/dist/esm/common-CfCB_X1k.js +0 -580
- package/dist/esm/common-CfCB_X1k.js.map +0 -1
package/README.md
CHANGED
|
@@ -10,18 +10,18 @@
|
|
|
10
10
|
<a href="https://github.com/zayne-labs/callapi/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/@zayne-labs/callapi?style=flat&color=EFBA5F" alt="license"></a>
|
|
11
11
|
<a href="https://www.npmjs.com/package/@zayne-labs/callapi"><img src="https://img.shields.io/npm/dm/@zayne-labs/callapi?style=flat&color=EFBA5F" alt="downloads per month"></a>
|
|
12
12
|
<a href="https://github.com/zayne-labs/callapi/graphs/commit-activity"><img src="https://img.shields.io/github/commit-activity/m/zayne-labs/callapi?style=flat&color=EFBA5F" alt="commit activity"></a>
|
|
13
|
-
<a href="https://deepwiki.com/zayne-labs/callapi"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
|
|
14
13
|
<a href="https://code2tutorial.com/tutorial/f77cfbd0-3c37-4c37-9608-b3c977e46f00/index.md"><img src="https://img.shields.io/badge/Code2Tutorial-blue?color=blue&logo=victoriametrics" alt="Code2Tutorial"></a>
|
|
14
|
+
<a href="https://deepwiki.com/zayne-labs/callapi"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
|
|
15
15
|
</p>
|
|
16
16
|
|
|
17
17
|
<p align="center">
|
|
18
|
-
<
|
|
18
|
+
<b>An advanced fetch library that actually solves real problems.</b>
|
|
19
19
|
</p>
|
|
20
20
|
|
|
21
21
|
<p align="center">
|
|
22
|
-
<a href="https://zayne-labs-callapi.netlify.app"><
|
|
23
|
-
<a href="https://zayne-labs-callapi.netlify.app/docs/getting-started"><
|
|
24
|
-
<a href="https://github.com/zayne-labs/callapi/tree/main/packages/callapi-plugins"><
|
|
22
|
+
<a href="https://zayne-labs-callapi.netlify.app"><b>Documentation</b></a> ·
|
|
23
|
+
<a href="https://zayne-labs-callapi.netlify.app/docs/getting-started"><b>Getting Started</b></a> ·
|
|
24
|
+
<a href="https://github.com/zayne-labs/callapi/tree/main/packages/callapi-plugins"><b>Plugins</b></a>
|
|
25
25
|
</p>
|
|
26
26
|
|
|
27
27
|
---
|
|
@@ -57,6 +57,7 @@ const { data } = await callApi("/api/data"); // JSON? Parsed.
|
|
|
57
57
|
|
|
58
58
|
```js
|
|
59
59
|
const { data, error } = await callApi("/api/users");
|
|
60
|
+
|
|
60
61
|
if (error) {
|
|
61
62
|
console.log(error.name); // "HTTPError", "ValidationError"
|
|
62
63
|
console.log(error.errorData); // Actual API response
|
|
@@ -79,7 +80,7 @@ await callApi("/api/data", {
|
|
|
79
80
|
import { z } from "zod";
|
|
80
81
|
import { defineSchema, createFetchClient } from "@zayne-labs/callapi";
|
|
81
82
|
|
|
82
|
-
const
|
|
83
|
+
const callMainApi = createFetchClient({
|
|
83
84
|
schema: defineSchema({
|
|
84
85
|
"/users/:id": {
|
|
85
86
|
data: z.object({
|
|
@@ -90,7 +91,7 @@ const api = createFetchClient({
|
|
|
90
91
|
}),
|
|
91
92
|
});
|
|
92
93
|
|
|
93
|
-
const user = await
|
|
94
|
+
const user = await callMainApi("/users/123"); // Fully typed + validated
|
|
94
95
|
```
|
|
95
96
|
|
|
96
97
|
**Hooks** - Intercept at any point.
|
|
@@ -109,35 +110,42 @@ const api = createFetchClient({
|
|
|
109
110
|
});
|
|
110
111
|
```
|
|
111
112
|
|
|
112
|
-
**Plugins** - Extend with middleware.
|
|
113
|
+
**Plugins** - Extend with setup, hooks, and middleware.
|
|
113
114
|
|
|
114
115
|
```js
|
|
115
|
-
const
|
|
116
|
-
id: "
|
|
117
|
-
name: "
|
|
116
|
+
const metricsPlugin = definePlugin({
|
|
117
|
+
id: "metrics",
|
|
118
|
+
name: "Metrics Plugin",
|
|
119
|
+
|
|
120
|
+
setup: ({ options }) => ({
|
|
121
|
+
options: {
|
|
122
|
+
...options,
|
|
123
|
+
meta: { startTime: Date.now() },
|
|
124
|
+
},
|
|
125
|
+
}),
|
|
118
126
|
|
|
119
|
-
|
|
120
|
-
|
|
127
|
+
hooks: {
|
|
128
|
+
onSuccess: ({ options }) => {
|
|
129
|
+
const duration = Date.now() - options.meta.startTime;
|
|
121
130
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
131
|
+
console.info(`Request took ${duration}ms`);
|
|
132
|
+
},
|
|
133
|
+
},
|
|
125
134
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
135
|
+
middlewares: {
|
|
136
|
+
fetchMiddleware: (ctx) => async (input, init) => {
|
|
137
|
+
console.info("→", input);
|
|
129
138
|
|
|
130
|
-
|
|
131
|
-
cache.set(key, response.clone());
|
|
139
|
+
const response = await ctx.fetchImpl(input, init);
|
|
132
140
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
141
|
+
console.info("←", response.status);
|
|
142
|
+
return response;
|
|
143
|
+
},
|
|
136
144
|
},
|
|
137
145
|
});
|
|
138
146
|
|
|
139
|
-
const
|
|
140
|
-
plugins: [
|
|
147
|
+
const api = createFetchClient({
|
|
148
|
+
plugins: [metricsPlugin],
|
|
141
149
|
});
|
|
142
150
|
```
|
|
143
151
|
|
|
@@ -149,7 +157,7 @@ await callApi("/search", { query: { q: "test" } });
|
|
|
149
157
|
await callApi("@delete/users/123");
|
|
150
158
|
```
|
|
151
159
|
|
|
152
|
-
|
|
160
|
+
**See the [full documentation](https://zayne-labs-callapi.netlify.app/docs) for all features.**
|
|
153
161
|
|
|
154
162
|
## Installation
|
|
155
163
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/types/type-helpers.d.ts
|
|
2
2
|
type AnyString = string & NonNullable<unknown>;
|
|
3
3
|
type AnyNumber = number & NonNullable<unknown>;
|
|
4
|
-
type AnyFunction<TResult = unknown> = (...args: any[]) => TResult;
|
|
4
|
+
type AnyFunction<TResult$1 = unknown> = (...args: any[]) => TResult$1;
|
|
5
5
|
type Prettify<TObject> = NonNullable<unknown> & { [Key in keyof TObject]: TObject[Key] };
|
|
6
6
|
type WriteableLevel = "deep" | "shallow";
|
|
7
7
|
/**
|
|
@@ -13,11 +13,11 @@ type WriteableLevel = "deep" | "shallow";
|
|
|
13
13
|
type ArrayOrObject = Record<number | string | symbol, unknown> | unknown[];
|
|
14
14
|
type Writeable<TObject, TLevel extends WriteableLevel = "shallow"> = TObject extends readonly [...infer TTupleItems] ? [...{ [Index in keyof TTupleItems]: TLevel extends "deep" ? Writeable<TTupleItems[Index], "deep"> : TTupleItems[Index] }] : TObject extends ArrayOrObject ? { -readonly [Key in keyof TObject]: TLevel extends "deep" ? Writeable<TObject[Key], "deep"> : TObject[Key] } : TObject;
|
|
15
15
|
type UnionToIntersection<TUnion> = (TUnion extends unknown ? (param: TUnion) => void : never) extends ((param: infer TParam) => void) ? TParam : never;
|
|
16
|
-
type UnmaskType<TValue> = {
|
|
17
|
-
_: TValue;
|
|
16
|
+
type UnmaskType<TValue$1> = {
|
|
17
|
+
_: TValue$1;
|
|
18
18
|
}["_"];
|
|
19
19
|
type RemovePrefix<TPrefix extends "dedupe" | "retry", TKey extends string> = TKey extends `${TPrefix}${infer TRest}` ? Uncapitalize<TRest> : TKey;
|
|
20
|
-
type Awaitable<TValue> = Promise<TValue> | TValue;
|
|
20
|
+
type Awaitable<TValue$1> = Promise<TValue$1> | TValue$1;
|
|
21
21
|
type CommonRequestHeaders = "Access-Control-Allow-Credentials" | "Access-Control-Allow-Headers" | "Access-Control-Allow-Methods" | "Access-Control-Allow-Origin" | "Access-Control-Expose-Headers" | "Access-Control-Max-Age" | "Age" | "Allow" | "Cache-Control" | "Clear-Site-Data" | "Content-Disposition" | "Content-Encoding" | "Content-Language" | "Content-Length" | "Content-Location" | "Content-Range" | "Content-Security-Policy-Report-Only" | "Content-Security-Policy" | "Cookie" | "Cross-Origin-Embedder-Policy" | "Cross-Origin-Opener-Policy" | "Cross-Origin-Resource-Policy" | "Date" | "ETag" | "Expires" | "Last-Modified" | "Location" | "Permissions-Policy" | "Pragma" | "Retry-After" | "Save-Data" | "Sec-CH-Prefers-Color-Scheme" | "Sec-CH-Prefers-Reduced-Motion" | "Sec-CH-UA-Arch" | "Sec-CH-UA-Bitness" | "Sec-CH-UA-Form-Factor" | "Sec-CH-UA-Full-Version-List" | "Sec-CH-UA-Full-Version" | "Sec-CH-UA-Mobile" | "Sec-CH-UA-Model" | "Sec-CH-UA-Platform-Version" | "Sec-CH-UA-Platform" | "Sec-CH-UA-WoW64" | "Sec-CH-UA" | "Sec-Fetch-Dest" | "Sec-Fetch-Mode" | "Sec-Fetch-Site" | "Sec-Fetch-User" | "Sec-GPC" | "Server-Timing" | "Server" | "Service-Worker-Navigation-Preload" | "Set-Cookie" | "Strict-Transport-Security" | "Timing-Allow-Origin" | "Trailer" | "Transfer-Encoding" | "Upgrade" | "Vary" | "Warning" | "WWW-Authenticate" | "X-Content-Type-Options" | "X-DNS-Prefetch-Control" | "X-Frame-Options" | "X-Permitted-Cross-Domain-Policies" | "X-Powered-By" | "X-Robots-Tag" | "X-XSS-Protection" | AnyString;
|
|
22
22
|
type CommonAuthorizationHeaders = `${"Basic" | "Bearer" | "Token"} ${string}`;
|
|
23
23
|
type CommonContentTypes = "application/epub+zip" | "application/gzip" | "application/json" | "application/ld+json" | "application/octet-stream" | "application/ogg" | "application/pdf" | "application/rtf" | "application/vnd.ms-fontobject" | "application/wasm" | "application/xhtml+xml" | "application/xml" | "application/zip" | "audio/aac" | "audio/mpeg" | "audio/ogg" | "audio/opus" | "audio/webm" | "audio/x-midi" | "font/otf" | "font/ttf" | "font/woff" | "font/woff2" | "image/avif" | "image/bmp" | "image/gif" | "image/jpeg" | "image/png" | "image/svg+xml" | "image/tiff" | "image/webp" | "image/x-icon" | "model/gltf-binary" | "model/gltf+json" | "text/calendar" | "text/css" | "text/csv" | "text/html" | "text/javascript" | "text/plain" | "video/3gpp" | "video/3gpp2" | "video/av1" | "video/mp2t" | "video/mp4" | "video/mpeg" | "video/ogg" | "video/webm" | "video/x-msvideo" | AnyString;
|
|
@@ -69,11 +69,11 @@ declare const fetchSpecificKeys: readonly (keyof RequestInit | "duplex")[];
|
|
|
69
69
|
* The Standard Schema interface.
|
|
70
70
|
* @see https://github.com/standard-schema/standard-schema
|
|
71
71
|
*/
|
|
72
|
-
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
72
|
+
interface StandardSchemaV1<Input$1 = unknown, Output$1 = Input$1> {
|
|
73
73
|
/**
|
|
74
74
|
* The Standard Schema properties.
|
|
75
75
|
*/
|
|
76
|
-
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
76
|
+
readonly "~standard": StandardSchemaV1.Props<Input$1, Output$1>;
|
|
77
77
|
}
|
|
78
78
|
declare namespace StandardSchemaV1 {
|
|
79
79
|
/**
|
|
@@ -285,8 +285,8 @@ interface URLOptions {
|
|
|
285
285
|
}
|
|
286
286
|
//#endregion
|
|
287
287
|
//#region src/validation.d.ts
|
|
288
|
-
type InferSchemaOutputResult<TSchema, TFallbackResult = unknown> = undefined extends TSchema ? TFallbackResult : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TSchema extends AnyFunction<infer TResult> ? Awaited<TResult> : TFallbackResult;
|
|
289
|
-
type InferSchemaInputResult<TSchema, TFallbackResult = unknown> = undefined extends TSchema ? TFallbackResult : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TSchema extends AnyFunction<infer TResult> ? Awaited<TResult> : TFallbackResult;
|
|
288
|
+
type InferSchemaOutputResult<TSchema$1, TFallbackResult = unknown> = undefined extends TSchema$1 ? TFallbackResult : TSchema$1 extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema$1> : TSchema$1 extends AnyFunction<infer TResult> ? Awaited<TResult> : TFallbackResult;
|
|
289
|
+
type InferSchemaInputResult<TSchema$1, TFallbackResult = unknown> = undefined extends TSchema$1 ? TFallbackResult : TSchema$1 extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema$1> : TSchema$1 extends AnyFunction<infer TResult> ? Awaited<TResult> : TFallbackResult;
|
|
290
290
|
interface CallApiSchemaConfig {
|
|
291
291
|
/**
|
|
292
292
|
* The base url of the schema. By default it's the baseURL of the callApi instance.
|
|
@@ -521,10 +521,10 @@ declare const getResponseType: <TResponse>(response: Response, parser: Parser<TR
|
|
|
521
521
|
stream: () => ReadableStream<Uint8Array<ArrayBuffer>> | null;
|
|
522
522
|
text: () => Promise<string>;
|
|
523
523
|
};
|
|
524
|
-
type InitResponseTypeMap<TResponse = unknown> = ReturnType<typeof getResponseType<TResponse>>;
|
|
524
|
+
type InitResponseTypeMap<TResponse$1 = unknown> = ReturnType<typeof getResponseType<TResponse$1>>;
|
|
525
525
|
type ResponseTypeUnion = keyof InitResponseTypeMap | null;
|
|
526
|
-
type ResponseTypeMap<TResponse> = { [Key in keyof InitResponseTypeMap<TResponse>]: Awaited<ReturnType<InitResponseTypeMap<TResponse>[Key]>> };
|
|
527
|
-
type GetResponseType<TResponse, TResponseType extends ResponseTypeUnion, TComputedResponseTypeMap extends ResponseTypeMap<TResponse> = ResponseTypeMap<TResponse>> = null extends TResponseType ? TComputedResponseTypeMap["json"] : TResponseType extends NonNullable<ResponseTypeUnion> ? TComputedResponseTypeMap[TResponseType] : never;
|
|
526
|
+
type ResponseTypeMap<TResponse$1> = { [Key in keyof InitResponseTypeMap<TResponse$1>]: Awaited<ReturnType<InitResponseTypeMap<TResponse$1>[Key]>> };
|
|
527
|
+
type GetResponseType<TResponse$1, TResponseType extends ResponseTypeUnion, TComputedResponseTypeMap extends ResponseTypeMap<TResponse$1> = ResponseTypeMap<TResponse$1>> = null extends TResponseType ? TComputedResponseTypeMap["json"] : TResponseType extends NonNullable<ResponseTypeUnion> ? TComputedResponseTypeMap[TResponseType] : never;
|
|
528
528
|
type CallApiResultSuccessVariant<TData> = {
|
|
529
529
|
data: NoInfer<TData>;
|
|
530
530
|
error: null;
|
|
@@ -958,7 +958,7 @@ type DedupeOptions = {
|
|
|
958
958
|
*
|
|
959
959
|
* @default "default"
|
|
960
960
|
*/
|
|
961
|
-
dedupeCacheScopeKey?: "default" | AnyString | ((context: RequestContext) => string);
|
|
961
|
+
dedupeCacheScopeKey?: "default" | AnyString | ((context: RequestContext) => string | undefined);
|
|
962
962
|
/**
|
|
963
963
|
* Custom key generator for request deduplication.
|
|
964
964
|
*
|
|
@@ -1028,7 +1028,7 @@ type DedupeOptions = {
|
|
|
1028
1028
|
*
|
|
1029
1029
|
* @default Auto-generated from request details
|
|
1030
1030
|
*/
|
|
1031
|
-
dedupeKey?: string | ((context: RequestContext) => string);
|
|
1031
|
+
dedupeKey?: string | ((context: RequestContext) => string | undefined);
|
|
1032
1032
|
/**
|
|
1033
1033
|
* Strategy for handling duplicate requests. Can be a static string or callback function.
|
|
1034
1034
|
*
|
|
@@ -1100,7 +1100,7 @@ type InnerRetryOptions<TErrorData> = { [Key in RetryOptionKeys<TErrorData> as Re
|
|
|
1100
1100
|
interface RetryOptions<TErrorData> {
|
|
1101
1101
|
/**
|
|
1102
1102
|
* Keeps track of the number of times the request has already been retried
|
|
1103
|
-
*
|
|
1103
|
+
* @internal
|
|
1104
1104
|
* @deprecated **NOTE**: This property is used internally to track retries. Please abstain from modifying it.
|
|
1105
1105
|
*/
|
|
1106
1106
|
readonly ["~retryAttemptCount"]?: number;
|
|
@@ -1161,36 +1161,36 @@ type JsonPrimitive = boolean | number | string | null | undefined;
|
|
|
1161
1161
|
type SerializableObject = Record<keyof object, unknown>;
|
|
1162
1162
|
type SerializableArray = Array<JsonPrimitive | SerializableArray | SerializableObject> | ReadonlyArray<JsonPrimitive | SerializableArray | SerializableObject>;
|
|
1163
1163
|
type Body = UnmaskType<RequestInit["body"] | SerializableArray | SerializableObject>;
|
|
1164
|
-
type InferBodyOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["body"], {
|
|
1164
|
+
type InferBodyOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["body"], {
|
|
1165
1165
|
/**
|
|
1166
1166
|
* Body of the request, can be a object or any other supported body type.
|
|
1167
1167
|
*/
|
|
1168
|
-
body?: InferSchemaInputResult<TSchema["body"], Body>;
|
|
1168
|
+
body?: InferSchemaInputResult<TSchema$1["body"], Body>;
|
|
1169
1169
|
}>;
|
|
1170
1170
|
type MethodUnion = UnmaskType<"CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE" | AnyString>;
|
|
1171
1171
|
type InferMethodFromURL<TInitURL> = string extends TInitURL ? MethodUnion : TInitURL extends `@${infer TMethod extends RouteKeyMethods}/${string}` ? Uppercase<TMethod> : MethodUnion;
|
|
1172
|
-
type InferMethodOption<TSchema extends CallApiSchema, TInitURL> = MakeSchemaOptionRequiredIfDefined<TSchema["method"], {
|
|
1172
|
+
type InferMethodOption<TSchema$1 extends CallApiSchema, TInitURL> = MakeSchemaOptionRequiredIfDefined<TSchema$1["method"], {
|
|
1173
1173
|
/**
|
|
1174
1174
|
* HTTP method for the request.
|
|
1175
1175
|
* @default "GET"
|
|
1176
1176
|
*/
|
|
1177
|
-
method?: InferSchemaInputResult<TSchema["method"], InferMethodFromURL<TInitURL>>;
|
|
1177
|
+
method?: InferSchemaInputResult<TSchema$1["method"], InferMethodFromURL<TInitURL>>;
|
|
1178
1178
|
}>;
|
|
1179
1179
|
type HeadersOption = UnmaskType<Record<"Authorization", CommonAuthorizationHeaders | undefined> | Record<"Content-Type", CommonContentTypes | undefined> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | Array<[string, string]>>;
|
|
1180
|
-
type InferHeadersOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["headers"], {
|
|
1180
|
+
type InferHeadersOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["headers"], {
|
|
1181
1181
|
/**
|
|
1182
1182
|
* Headers to be used in the request.
|
|
1183
1183
|
*/
|
|
1184
|
-
headers?: InferSchemaInputResult<TSchema["headers"], HeadersOption> | ((context: {
|
|
1184
|
+
headers?: InferSchemaInputResult<TSchema$1["headers"], HeadersOption> | ((context: {
|
|
1185
1185
|
baseHeaders: NonNullable<HeadersOption>;
|
|
1186
|
-
}) => InferSchemaInputResult<TSchema["headers"], HeadersOption>);
|
|
1186
|
+
}) => InferSchemaInputResult<TSchema$1["headers"], HeadersOption>);
|
|
1187
1187
|
}>;
|
|
1188
|
-
type InferRequestOptions<TSchema extends CallApiSchema, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, CallApiSchemaConfig>> = InferBodyOption<TSchema> & InferHeadersOption<TSchema> & InferMethodOption<TSchema, TInitURL>;
|
|
1188
|
+
type InferRequestOptions<TSchema$1 extends CallApiSchema, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, CallApiSchemaConfig>> = InferBodyOption<TSchema$1> & InferHeadersOption<TSchema$1> & InferMethodOption<TSchema$1, TInitURL>;
|
|
1189
1189
|
interface Register {}
|
|
1190
1190
|
type GlobalMeta = Register extends {
|
|
1191
1191
|
meta?: infer TMeta extends Record<string, unknown>;
|
|
1192
1192
|
} ? TMeta : never;
|
|
1193
|
-
type InferMetaOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["meta"], {
|
|
1193
|
+
type InferMetaOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["meta"], {
|
|
1194
1194
|
/**
|
|
1195
1195
|
* - An optional field you can fill with additional information,
|
|
1196
1196
|
* to associate with the request, typically used for logging or tracing.
|
|
@@ -1214,30 +1214,30 @@ type InferMetaOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIf
|
|
|
1214
1214
|
* });
|
|
1215
1215
|
* ```
|
|
1216
1216
|
*/
|
|
1217
|
-
meta?: InferSchemaInputResult<TSchema["meta"], GlobalMeta>;
|
|
1217
|
+
meta?: InferSchemaInputResult<TSchema$1["meta"], GlobalMeta>;
|
|
1218
1218
|
}>;
|
|
1219
|
-
type InferQueryOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["query"], {
|
|
1219
|
+
type InferQueryOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["query"], {
|
|
1220
1220
|
/**
|
|
1221
1221
|
* Parameters to be appended to the URL (i.e: /:id)
|
|
1222
1222
|
*/
|
|
1223
|
-
query?: InferSchemaInputResult<TSchema["query"], Query>;
|
|
1223
|
+
query?: InferSchemaInputResult<TSchema$1["query"], Query>;
|
|
1224
1224
|
}>;
|
|
1225
1225
|
type EmptyString = "";
|
|
1226
1226
|
type EmptyTuple = readonly [];
|
|
1227
1227
|
type StringTuple = readonly string[];
|
|
1228
1228
|
type PossibleParamNamePatterns = `${string}:${string}` | `${string}{${string}}${"" | AnyString}`;
|
|
1229
|
-
type ExtractRouteParamNames<TCurrentRoute, TParamNamesAccumulator extends StringTuple = EmptyTuple> = TCurrentRoute extends PossibleParamNamePatterns ? TCurrentRoute extends `${infer TRoutePrefix}:${infer TParamAndRemainingRoute}` ? TParamAndRemainingRoute extends `${infer TCurrentParam}/${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamAndRemainingRoute extends `${infer TCurrentParam}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : ExtractRouteParamNames<TRoutePrefix, [...TParamNamesAccumulator, TCurrentParam]> : ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : TCurrentRoute extends `${infer TRoutePrefix}{${infer TCurrentParam}}${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamNamesAccumulator : TParamNamesAccumulator;
|
|
1229
|
+
type ExtractRouteParamNames<TCurrentRoute$1, TParamNamesAccumulator extends StringTuple = EmptyTuple> = TCurrentRoute$1 extends PossibleParamNamePatterns ? TCurrentRoute$1 extends `${infer TRoutePrefix}:${infer TParamAndRemainingRoute}` ? TParamAndRemainingRoute extends `${infer TCurrentParam}/${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamAndRemainingRoute extends `${infer TCurrentParam}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : ExtractRouteParamNames<TRoutePrefix, [...TParamNamesAccumulator, TCurrentParam]> : ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : TCurrentRoute$1 extends `${infer TRoutePrefix}{${infer TCurrentParam}}${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamNamesAccumulator : TParamNamesAccumulator;
|
|
1230
1230
|
type ConvertParamNamesToRecord<TParamNames extends StringTuple> = Prettify<TParamNames extends (readonly [infer TFirstParamName extends string, ...infer TRemainingParamNames extends StringTuple]) ? Record<TFirstParamName, AllowedQueryParamValues> & ConvertParamNamesToRecord<TRemainingParamNames> : NonNullable<unknown>>;
|
|
1231
1231
|
type ConvertParamNamesToTuple<TParamNames extends StringTuple> = TParamNames extends readonly [string, ...infer TRemainingParamNames extends StringTuple] ? [AllowedQueryParamValues, ...ConvertParamNamesToTuple<TRemainingParamNames>] : [];
|
|
1232
|
-
type InferParamsFromRoute<TCurrentRoute> = ExtractRouteParamNames<TCurrentRoute> extends StringTuple ? ExtractRouteParamNames<TCurrentRoute> extends EmptyTuple ? Params : ConvertParamNamesToRecord<ExtractRouteParamNames<TCurrentRoute>> | ConvertParamNamesToTuple<ExtractRouteParamNames<TCurrentRoute>> : Params;
|
|
1232
|
+
type InferParamsFromRoute<TCurrentRoute$1> = ExtractRouteParamNames<TCurrentRoute$1> extends StringTuple ? ExtractRouteParamNames<TCurrentRoute$1> extends EmptyTuple ? Params : ConvertParamNamesToRecord<ExtractRouteParamNames<TCurrentRoute$1>> | ConvertParamNamesToTuple<ExtractRouteParamNames<TCurrentRoute$1>> : Params;
|
|
1233
1233
|
type MakeParamsOptionRequired<TParamsSchemaOption extends CallApiSchema["params"], TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TObject> = MakeSchemaOptionRequiredIfDefined<TParamsSchemaOption, Params extends InferParamsFromRoute<TCurrentRouteSchemaKey> ? TObject : TCurrentRouteSchemaKey extends Extract<keyof TBaseSchemaRoutes, TCurrentRouteSchemaKey> ? undefined extends InferSchemaInputResult<TParamsSchemaOption, null> ? TObject : Required<TObject> : TObject>;
|
|
1234
|
-
type InferParamsOption<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = MakeParamsOptionRequired<TSchema["params"], TBaseSchemaRoutes, TCurrentRouteSchemaKey, {
|
|
1234
|
+
type InferParamsOption<TSchema$1 extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = MakeParamsOptionRequired<TSchema$1["params"], TBaseSchemaRoutes, TCurrentRouteSchemaKey, {
|
|
1235
1235
|
/**
|
|
1236
1236
|
* Parameters to be appended to the URL (i.e: /:id)
|
|
1237
1237
|
*/
|
|
1238
|
-
params?: InferSchemaInputResult<TSchema["params"], InferParamsFromRoute<TCurrentRouteSchemaKey>>;
|
|
1238
|
+
params?: InferSchemaInputResult<TSchema$1["params"], InferParamsFromRoute<TCurrentRouteSchemaKey>>;
|
|
1239
1239
|
}>;
|
|
1240
|
-
type InferExtraOptions<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = InferMetaOption<TSchema> & InferParamsOption<TSchema, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferQueryOption<TSchema>;
|
|
1240
|
+
type InferExtraOptions<TSchema$1 extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = InferMetaOption<TSchema$1> & InferParamsOption<TSchema$1, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferQueryOption<TSchema$1>;
|
|
1241
1241
|
type InferPluginOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<TPluginArray extends Array<infer TPlugin> ? TPlugin extends CallApiPlugin ? TPlugin["defineExtraOptions"] extends AnyFunction<infer TReturnedSchema> ? InferSchemaOutputResult<TReturnedSchema> : never : never : never>;
|
|
1242
1242
|
type ResultModeOption<TErrorData, TResultMode extends ResultModeUnion> = TErrorData extends false ? {
|
|
1243
1243
|
resultMode: "onlyData";
|
|
@@ -1753,7 +1753,7 @@ type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = Defau
|
|
|
1753
1753
|
*/
|
|
1754
1754
|
skipAutoMergeFor?: "all" | "options" | "request";
|
|
1755
1755
|
};
|
|
1756
|
-
type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TCurrentRouteSchemaKey extends string = string> = SharedExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray> & {
|
|
1756
|
+
type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TCurrentRouteSchemaKey extends string = string> = SharedExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray> & {
|
|
1757
1757
|
/**
|
|
1758
1758
|
* Array of instance-specific CallApi plugins or a function to configure plugins.
|
|
1759
1759
|
*
|
|
@@ -1773,10 +1773,10 @@ type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType,
|
|
|
1773
1773
|
* Can be a static schema object or a function that receives base schema context and returns instance schemas.
|
|
1774
1774
|
*
|
|
1775
1775
|
*/
|
|
1776
|
-
schema?: TSchema | ((context: {
|
|
1776
|
+
schema?: TSchema$1 | ((context: {
|
|
1777
1777
|
baseSchemaRoutes: Writeable<TBaseSchemaRoutes, "deep">;
|
|
1778
1778
|
currentRouteSchema: GetCurrentRouteSchema<TBaseSchemaRoutes, TCurrentRouteSchemaKey>;
|
|
1779
|
-
}) => TSchema);
|
|
1779
|
+
}) => TSchema$1);
|
|
1780
1780
|
/**
|
|
1781
1781
|
* Instance-specific schema configuration or a function to configure schema behavior.
|
|
1782
1782
|
*
|
|
@@ -1794,9 +1794,9 @@ type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultData
|
|
|
1794
1794
|
options: CallApiExtraOptions;
|
|
1795
1795
|
request: CallApiRequestOptions;
|
|
1796
1796
|
}) => CallApiRequestOptions & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>);
|
|
1797
|
-
type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = InferExtraOptions<TSchema, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferRequestOptions<TSchema, TInitURL> & Omit<CallApiExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TCurrentRouteSchemaKey>, keyof InferExtraOptions<CallApiSchema, BaseCallApiSchemaRoutes, string>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, string>>;
|
|
1798
|
-
type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = [initURL: TInitURL, config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>];
|
|
1797
|
+
type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = InferExtraOptions<TSchema$1, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferRequestOptions<TSchema$1, TInitURL> & Omit<CallApiExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchemaRoutes, TSchema$1, TBaseSchemaConfig, TSchemaConfig, TCurrentRouteSchemaKey>, keyof InferExtraOptions<CallApiSchema, BaseCallApiSchemaRoutes, string>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, string>>;
|
|
1798
|
+
type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = [initURL: TInitURL, config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBaseSchemaRoutes, TSchema$1, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>];
|
|
1799
1799
|
type CallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeUnion> = GetCallApiResult<TData, TErrorData, TResultMode, TThrowOnError, TResponseType>;
|
|
1800
1800
|
//#endregion
|
|
1801
|
-
export {
|
|
1802
|
-
//# sourceMappingURL=common-
|
|
1801
|
+
export { BaseCallApiSchemaRoutes as $, CallApiResultErrorVariant as A, ResponseTypeUnion as B, PluginExtraOptions as C, ResponseErrorContext as D, ResponseContext as E, PossibleHTTPError as F, DefaultThrowOnError as G, ResultModeUnion as H, PossibleJavaScriptError as I, PluginHooksWithMoreOptions as J, CallApiPlugin as K, PossibleJavaScriptOrValidationError as L, CallApiSuccessOrErrorVariant as M, GetCallApiResult as N, ResponseStreamContext as O, GetResponseType as P, BaseCallApiSchemaAndConfig as Q, PossibleValidationError as R, HooksOrHooksArray as S, RequestStreamContext as T, DefaultDataType as U, ResultModeMap as V, DefaultPluginArray as W, HTTPError as X, PluginSetupContext as Y, ValidationError as Z, ThrowOnErrorUnion as _, CallApiExtraOptionsForHooks as a, AnyFunction as at, ErrorContext as b, CallApiRequestOptionsForHooks as c, ApplyURLBasedConfig as d, CallApiSchema as et, GetCurrentRouteSchema as f, Register as g, InferParamsFromRoute as h, CallApiExtraOptions as i, URLOptions as it, CallApiResultSuccessVariant as j, SuccessContext as k, CallApiResult as l, InferInitURL as m, BaseCallApiExtraOptions as n, InferSchemaOutputResult as nt, CallApiParameters as o, AnyString as ot, GetCurrentRouteSchemaKey as p, PluginHooks as q, CallApiConfig as r, fallBackRouteSchemaKey as rt, CallApiRequestOptions as s, Writeable as st, BaseCallApiConfig as t, CallApiSchemaConfig as tt, ApplyStrictConfig as u, RetryOptions as v, RequestContext as w, Hooks as x, DedupeOptions as y, ResponseTypeMap as z };
|
|
1802
|
+
//# sourceMappingURL=common-ClytspsT.d.ts.map
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as BaseCallApiSchemaRoutes, A as CallApiResultErrorVariant, B as ResponseTypeUnion, C as PluginExtraOptions, D as ResponseErrorContext, E as ResponseContext, F as PossibleHTTPError, G as DefaultThrowOnError, H as ResultModeUnion, I as PossibleJavaScriptError, J as PluginHooksWithMoreOptions, K as CallApiPlugin, L as PossibleJavaScriptOrValidationError, M as CallApiSuccessOrErrorVariant, N as GetCallApiResult, O as ResponseStreamContext, P as GetResponseType, Q as BaseCallApiSchemaAndConfig, R as PossibleValidationError, S as HooksOrHooksArray, T as RequestStreamContext, U as DefaultDataType, V as ResultModeMap, W as DefaultPluginArray, X as HTTPError, Y as PluginSetupContext, Z as ValidationError, _ as ThrowOnErrorUnion, a as CallApiExtraOptionsForHooks, at as AnyFunction, b as ErrorContext, c as CallApiRequestOptionsForHooks, d as ApplyURLBasedConfig, et as CallApiSchema, f as GetCurrentRouteSchema, g as Register, h as InferParamsFromRoute, i as CallApiExtraOptions, it as URLOptions, j as CallApiResultSuccessVariant, k as SuccessContext, l as CallApiResult, m as InferInitURL, n as BaseCallApiExtraOptions, nt as InferSchemaOutputResult, o as CallApiParameters, ot as AnyString, p as GetCurrentRouteSchemaKey, q as PluginHooks, r as CallApiConfig, rt as fallBackRouteSchemaKey, s as CallApiRequestOptions, st as Writeable, t as BaseCallApiConfig, tt as CallApiSchemaConfig, u as ApplyStrictConfig, v as RetryOptions, w as RequestContext, x as Hooks, y as DedupeOptions, z as ResponseTypeMap } from "./common-ClytspsT.js";
|
|
2
2
|
|
|
3
3
|
//#region src/createFetchClient.d.ts
|
|
4
4
|
|