@zayne-labs/callapi 1.11.24 → 1.11.26
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 +29 -11
- package/dist/defaults-C6WKIXsf.js.map +1 -1
- package/dist/guards-5Ij_loC1.js.map +1 -1
- package/dist/index.d.ts +12 -6
- package/dist/index.js +193 -189
- package/dist/index.js.map +1 -1
- package/dist/utils/external/index.d.ts +1 -1
- package/dist/{common-Bkz3oogl.d.ts → validation-BeCBQ6_6.d.ts} +234 -238
- package/package.json +7 -7
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "../../validation-Dq--Q5zC.js";
|
|
2
|
-
import {
|
|
2
|
+
import { $ as definePlugin, J as isJavascriptError, K as isHTTPError, Q as defineMainSchema, St as ValidationError, Tt as toQueryString, X as isValidationErrorInstance, Y as isValidationError, Z as defineBaseConfig, et as defineSchema, nt as defineSchemaRoutes, q as isHTTPErrorInstance, tt as defineSchemaConfig, wt as toFormData, xt as HTTPError } from "../../validation-BeCBQ6_6.js";
|
|
3
3
|
export { HTTPError, ValidationError, defineBaseConfig, defineMainSchema, definePlugin, defineSchema, defineSchemaConfig, defineSchemaRoutes, isHTTPError, isHTTPErrorInstance, isJavascriptError, isValidationError, isValidationErrorInstance, toFormData, toQueryString };
|
|
@@ -21,6 +21,7 @@ type UnmaskType<TValue$1> = {
|
|
|
21
21
|
type RemovePrefix<TPrefix extends "dedupe" | "retry", TKey extends string> = TKey extends `${TPrefix}${infer TRest}` ? Uncapitalize<TRest> : TKey;
|
|
22
22
|
type Awaitable<TValue$1> = Promise<TValue$1> | TValue$1;
|
|
23
23
|
type Satisfies<TActualObject extends TExpectedObject, TExpectedObject> = { [Key in keyof TActualObject]: Key extends keyof TExpectedObject ? TActualObject[Key] : never };
|
|
24
|
+
type DistributiveOmit<TObject, TKeysToOmit extends keyof TObject> = TObject extends unknown ? Omit<TObject, TKeysToOmit> : never;
|
|
24
25
|
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;
|
|
25
26
|
type CommonAuthorizationHeaders = `${"Basic" | "Bearer" | "Token"} ${string}`;
|
|
26
27
|
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;
|
|
@@ -70,7 +71,7 @@ type ToQueryStringFn = {
|
|
|
70
71
|
(query: Required<CallApiExtraOptions>["query"]): string;
|
|
71
72
|
};
|
|
72
73
|
declare const toQueryString: ToQueryStringFn;
|
|
73
|
-
type AllowedPrimitives = boolean | number | string | Blob;
|
|
74
|
+
type AllowedPrimitives = boolean | number | string | Blob | null | undefined;
|
|
74
75
|
type AllowedValues = AllowedPrimitives | AllowedPrimitives[] | Record<string, AllowedPrimitives>;
|
|
75
76
|
type ToFormDataFn = {
|
|
76
77
|
(data: Record<string, AllowedValues>): FormData;
|
|
@@ -228,211 +229,6 @@ declare namespace StandardSchemaV1 {
|
|
|
228
229
|
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
229
230
|
}
|
|
230
231
|
//#endregion
|
|
231
|
-
//#region src/url.d.ts
|
|
232
|
-
type AllowedQueryParamValues = UnmaskType<boolean | number | string>;
|
|
233
|
-
type RecordStyleParams = UnmaskType<Record<string, AllowedQueryParamValues>>;
|
|
234
|
-
type TupleStyleParams = UnmaskType<AllowedQueryParamValues[]>;
|
|
235
|
-
type Params = UnmaskType<RecordStyleParams | TupleStyleParams>;
|
|
236
|
-
type Query = UnmaskType<Record<string, AllowedQueryParamValues>>;
|
|
237
|
-
type InitURLOrURLObject = AnyString | RouteKeyMethodsURLUnion | URL;
|
|
238
|
-
interface URLOptions {
|
|
239
|
-
/**
|
|
240
|
-
* Base URL for all API requests. Will only be prepended to relative URLs.
|
|
241
|
-
*
|
|
242
|
-
* Absolute URLs (starting with http/https) will not be prepended by the baseURL.
|
|
243
|
-
*
|
|
244
|
-
* @example
|
|
245
|
-
* ```ts
|
|
246
|
-
* // Set base URL for all requests
|
|
247
|
-
* baseURL: "https://api.example.com/v1"
|
|
248
|
-
*
|
|
249
|
-
* // Then use relative URLs in requests
|
|
250
|
-
* callApi("/users") // → https://api.example.com/v1/users
|
|
251
|
-
* callApi("/posts/123") // → https://api.example.com/v1/posts/123
|
|
252
|
-
*
|
|
253
|
-
* // Environment-specific base URLs
|
|
254
|
-
* baseURL: process.env.NODE_ENV === "production"
|
|
255
|
-
* ? "https://api.example.com"
|
|
256
|
-
* : "http://localhost:3000/api"
|
|
257
|
-
* ```
|
|
258
|
-
*/
|
|
259
|
-
baseURL?: string;
|
|
260
|
-
/**
|
|
261
|
-
* Resolved request URL after processing baseURL, parameters, and query strings (readonly)
|
|
262
|
-
*
|
|
263
|
-
* This is the final URL that will be used for the HTTP request, computed from
|
|
264
|
-
* baseURL, initURL, params, and query parameters.
|
|
265
|
-
*
|
|
266
|
-
*/
|
|
267
|
-
readonly fullURL?: string;
|
|
268
|
-
/**
|
|
269
|
-
* The original URL string passed to the callApi instance (readonly)
|
|
270
|
-
*
|
|
271
|
-
* This preserves the original URL as provided, including any method modifiers like "@get/" or "@post/".
|
|
272
|
-
*
|
|
273
|
-
*/
|
|
274
|
-
readonly initURL?: string;
|
|
275
|
-
/**
|
|
276
|
-
* The URL string after normalization, with method modifiers removed(readonly)
|
|
277
|
-
*
|
|
278
|
-
* Method modifiers like "@get/", "@post/" are stripped to create a clean URL
|
|
279
|
-
* for parameter substitution and final URL construction.
|
|
280
|
-
*
|
|
281
|
-
*/
|
|
282
|
-
readonly initURLNormalized?: string;
|
|
283
|
-
/**
|
|
284
|
-
* Parameters to be substituted into URL path segments.
|
|
285
|
-
*
|
|
286
|
-
* Supports both object-style (named parameters) and array-style (positional parameters)
|
|
287
|
-
* for flexible URL parameter substitution.
|
|
288
|
-
*
|
|
289
|
-
* @example
|
|
290
|
-
* ```typescript
|
|
291
|
-
* // Object-style parameters (recommended)
|
|
292
|
-
* const namedParams: URLOptions = {
|
|
293
|
-
* initURL: "/users/:userId/posts/:postId",
|
|
294
|
-
* params: { userId: "123", postId: "456" }
|
|
295
|
-
* };
|
|
296
|
-
* // Results in: /users/123/posts/456
|
|
297
|
-
*
|
|
298
|
-
* // Array-style parameters (positional)
|
|
299
|
-
* const positionalParams: URLOptions = {
|
|
300
|
-
* initURL: "/users/:userId/posts/:postId",
|
|
301
|
-
* params: ["123", "456"] // Maps in order: userId=123, postId=456
|
|
302
|
-
* };
|
|
303
|
-
* // Results in: /users/123/posts/456
|
|
304
|
-
*
|
|
305
|
-
* // Single parameter
|
|
306
|
-
* const singleParam: URLOptions = {
|
|
307
|
-
* initURL: "/users/:id",
|
|
308
|
-
* params: { id: "user-123" }
|
|
309
|
-
* };
|
|
310
|
-
* // Results in: /users/user-123
|
|
311
|
-
* ```
|
|
312
|
-
*/
|
|
313
|
-
params?: Params;
|
|
314
|
-
/**
|
|
315
|
-
* Query parameters to append to the URL as search parameters.
|
|
316
|
-
*
|
|
317
|
-
* These will be serialized into the URL query string using standard
|
|
318
|
-
* URL encoding practices.
|
|
319
|
-
*
|
|
320
|
-
* @example
|
|
321
|
-
* ```typescript
|
|
322
|
-
* // Basic query parameters
|
|
323
|
-
* const queryOptions: URLOptions = {
|
|
324
|
-
* initURL: "/users",
|
|
325
|
-
* query: {
|
|
326
|
-
* page: 1,
|
|
327
|
-
* limit: 10,
|
|
328
|
-
* search: "john doe",
|
|
329
|
-
* active: true
|
|
330
|
-
* }
|
|
331
|
-
* };
|
|
332
|
-
* // Results in: /users?page=1&limit=10&search=john%20doe&active=true
|
|
333
|
-
*
|
|
334
|
-
* // Filtering and sorting
|
|
335
|
-
* const filterOptions: URLOptions = {
|
|
336
|
-
* initURL: "/products",
|
|
337
|
-
* query: {
|
|
338
|
-
* category: "electronics",
|
|
339
|
-
* minPrice: 100,
|
|
340
|
-
* maxPrice: 500,
|
|
341
|
-
* sortBy: "price",
|
|
342
|
-
* order: "asc"
|
|
343
|
-
* }
|
|
344
|
-
* };
|
|
345
|
-
* // Results in: /products?category=electronics&minPrice=100&maxPrice=500&sortBy=price&order=asc
|
|
346
|
-
* ```
|
|
347
|
-
*/
|
|
348
|
-
query?: Query;
|
|
349
|
-
}
|
|
350
|
-
//#endregion
|
|
351
|
-
//#region src/validation.d.ts
|
|
352
|
-
type ResultVariant = "infer-input" | "infer-output";
|
|
353
|
-
type InferSchemaResult<TSchema$1, TFallbackResult, TResultVariant extends ResultVariant> = undefined extends TSchema$1 ? TFallbackResult : TSchema$1 extends StandardSchemaV1 ? TResultVariant extends "infer-input" ? StandardSchemaV1.InferInput<TSchema$1> : StandardSchemaV1.InferOutput<TSchema$1> : TSchema$1 extends AnyFunction<infer TResult> ? Awaited<TResult> : TFallbackResult;
|
|
354
|
-
type InferSchemaOutput<TSchema$1, TFallbackResult = unknown> = InferSchemaResult<TSchema$1, TFallbackResult, "infer-output">;
|
|
355
|
-
type InferSchemaInput<TSchema$1, TFallbackResult = unknown> = InferSchemaResult<TSchema$1, TFallbackResult, "infer-input">;
|
|
356
|
-
interface CallApiSchemaConfig {
|
|
357
|
-
/**
|
|
358
|
-
* The base url of the schema. By default it's the baseURL of the callApi instance.
|
|
359
|
-
*/
|
|
360
|
-
baseURL?: string;
|
|
361
|
-
/**
|
|
362
|
-
* Disables runtime validation for the schema.
|
|
363
|
-
*/
|
|
364
|
-
disableRuntimeValidation?: boolean;
|
|
365
|
-
/**
|
|
366
|
-
* If `true`, the original input value will be used instead of the transformed/validated output.
|
|
367
|
-
*
|
|
368
|
-
* This is useful when you want to validate the input but don't want any transformations
|
|
369
|
-
* applied by the validation schema (e.g., type coercion, default values, etc).
|
|
370
|
-
*/
|
|
371
|
-
disableValidationOutputApplication?: boolean;
|
|
372
|
-
/**
|
|
373
|
-
* Optional url prefix that will be substituted for the `baseURL` of the schemaConfig at runtime.
|
|
374
|
-
*
|
|
375
|
-
* This allows you to reuse the same schema against different base URLs (for example,
|
|
376
|
-
* swapping between `/api/v1` and `/api/v2`) without redefining the entire schema.
|
|
377
|
-
*/
|
|
378
|
-
prefix?: string;
|
|
379
|
-
/**
|
|
380
|
-
* Controls the strictness of API route validation.
|
|
381
|
-
*
|
|
382
|
-
* When true:
|
|
383
|
-
* - Only routes explicitly defined in the schema will be considered valid to typescript and the runtime.
|
|
384
|
-
* - Attempting to call routes not defined in the schema will result in both type errors and runtime validation errors.
|
|
385
|
-
* - Useful for ensuring API calls conform exactly to your schema definition
|
|
386
|
-
*
|
|
387
|
-
* When false or undefined (default):
|
|
388
|
-
* - All routes will be allowed, whether they are defined in the schema or not
|
|
389
|
-
*/
|
|
390
|
-
strict?: boolean;
|
|
391
|
-
}
|
|
392
|
-
interface CallApiSchema {
|
|
393
|
-
/**
|
|
394
|
-
* The schema to use for validating the request body.
|
|
395
|
-
*/
|
|
396
|
-
body?: StandardSchemaV1<Body | undefined> | ((body: Body) => Awaitable<Body | undefined>);
|
|
397
|
-
/**
|
|
398
|
-
* The schema to use for validating the response data.
|
|
399
|
-
*/
|
|
400
|
-
data?: StandardSchemaV1 | ((data: unknown) => unknown);
|
|
401
|
-
/**
|
|
402
|
-
* The schema to use for validating the response error data.
|
|
403
|
-
*/
|
|
404
|
-
errorData?: StandardSchemaV1 | ((errorData: unknown) => unknown);
|
|
405
|
-
/**
|
|
406
|
-
* The schema to use for validating the request headers.
|
|
407
|
-
*/
|
|
408
|
-
headers?: StandardSchemaV1<HeadersOption | undefined> | ((headers: HeadersOption) => Awaitable<HeadersOption | undefined>);
|
|
409
|
-
/**
|
|
410
|
-
* The schema to use for validating the meta option.
|
|
411
|
-
*/
|
|
412
|
-
meta?: StandardSchemaV1<GlobalMeta | undefined> | ((meta: GlobalMeta) => Awaitable<GlobalMeta | undefined>);
|
|
413
|
-
/**
|
|
414
|
-
* The schema to use for validating the request method.
|
|
415
|
-
*/
|
|
416
|
-
method?: StandardSchemaV1<MethodUnion | undefined> | ((method: MethodUnion) => Awaitable<MethodUnion | undefined>);
|
|
417
|
-
/**
|
|
418
|
-
* The schema to use for validating the request url parameters.
|
|
419
|
-
*/
|
|
420
|
-
params?: StandardSchemaV1<Params | undefined> | ((params: Params) => Awaitable<Params | undefined>);
|
|
421
|
-
/**
|
|
422
|
-
* The schema to use for validating the request url queries.
|
|
423
|
-
*/
|
|
424
|
-
query?: StandardSchemaV1<Query | undefined> | ((query: Query) => Awaitable<Query | undefined>);
|
|
425
|
-
}
|
|
426
|
-
declare const routeKeyMethods: readonly ["delete", "get", "patch", "post", "put"];
|
|
427
|
-
type RouteKeyMethods = (typeof routeKeyMethods)[number];
|
|
428
|
-
type RouteKeyMethodsURLUnion = `@${RouteKeyMethods}/`;
|
|
429
|
-
type BaseSchemaRouteKeyPrefixes = FallBackRouteSchemaKey | RouteKeyMethodsURLUnion;
|
|
430
|
-
type BaseCallApiSchemaRoutes = Partial<Record<AnyString | BaseSchemaRouteKeyPrefixes, CallApiSchema>>;
|
|
431
|
-
type BaseCallApiSchemaAndConfig = {
|
|
432
|
-
config?: CallApiSchemaConfig;
|
|
433
|
-
routes: BaseCallApiSchemaRoutes;
|
|
434
|
-
};
|
|
435
|
-
//#endregion
|
|
436
232
|
//#region src/utils/external/error.d.ts
|
|
437
233
|
type HTTPErrorDetails<TErrorData$1> = Pick<CallApiExtraOptions, "defaultHTTPErrorMessage"> & {
|
|
438
234
|
errorData: TErrorData$1;
|
|
@@ -504,10 +300,6 @@ type CallApiResultSuccessVariant<TData$1> = {
|
|
|
504
300
|
error: null;
|
|
505
301
|
response: Response;
|
|
506
302
|
};
|
|
507
|
-
type CallApiResultSuccessVariantWithoutResponse<TData$1> = {
|
|
508
|
-
data: NoInfer<TData$1>;
|
|
509
|
-
error: null;
|
|
510
|
-
};
|
|
511
303
|
type PossibleJavaScriptError = UnmaskType<{
|
|
512
304
|
errorData: false;
|
|
513
305
|
message: string;
|
|
@@ -537,26 +329,18 @@ type CallApiResultErrorVariant<TErrorData$1> = {
|
|
|
537
329
|
error: PossibleJavaScriptOrValidationError;
|
|
538
330
|
response: Response | null;
|
|
539
331
|
};
|
|
540
|
-
type CallApiResultErrorVariantWithoutResponse<TErrorData$1> = {
|
|
541
|
-
data: null;
|
|
542
|
-
error: PossibleHTTPError<TErrorData$1>;
|
|
543
|
-
} | {
|
|
544
|
-
data: null;
|
|
545
|
-
error: PossibleJavaScriptOrValidationError;
|
|
546
|
-
};
|
|
547
332
|
type CallApiSuccessOrErrorVariant<TData$1, TError> = CallApiResultErrorVariant<TError> | CallApiResultSuccessVariant<TData$1>;
|
|
548
|
-
type CallApiSuccessOrErrorVariantWithoutResponse<TData$1, TErrorData$1> = CallApiResultErrorVariantWithoutResponse<TErrorData$1> | CallApiResultSuccessVariantWithoutResponse<TData$1>;
|
|
549
333
|
type ResultModeMapWithoutException<TData$1, TErrorData$1, TResponseType extends ResponseTypeType, TComputedData = GetResponseType<TData$1, TResponseType>, TComputedErrorData = GetResponseType<TErrorData$1, TResponseType>, TComputedResult extends CallApiSuccessOrErrorVariant<TComputedData, TComputedErrorData> = CallApiSuccessOrErrorVariant<TComputedData, TComputedErrorData>> = UnmaskType<{
|
|
550
334
|
all: TComputedResult;
|
|
551
335
|
onlyData: TComputedResult["data"];
|
|
552
336
|
onlyResponse: TComputedResult["response"];
|
|
553
|
-
withoutResponse:
|
|
337
|
+
withoutResponse: DistributiveOmit<TComputedResult, "response">;
|
|
554
338
|
}>;
|
|
555
339
|
type ResultModeMapWithException<TData$1, TResponseType extends ResponseTypeType, TComputedData = GetResponseType<TData$1, TResponseType>, TComputedResult extends CallApiResultSuccessVariant<TComputedData> = CallApiResultSuccessVariant<TComputedData>> = {
|
|
556
340
|
all: TComputedResult;
|
|
557
341
|
onlyData: TComputedResult["data"];
|
|
558
342
|
onlyResponse: TComputedResult["response"];
|
|
559
|
-
withoutResponse:
|
|
343
|
+
withoutResponse: DistributiveOmit<TComputedResult, "response">;
|
|
560
344
|
};
|
|
561
345
|
type ResultModeMap<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResponseType extends ResponseTypeType = ResponseTypeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError> = TThrowOnError extends true ? ResultModeMapWithException<TData$1, TResponseType> : ResultModeMapWithoutException<TData$1, TErrorData$1, TResponseType>;
|
|
562
346
|
type ResultModePlaceholder = null;
|
|
@@ -603,8 +387,128 @@ interface Middlewares {
|
|
|
603
387
|
}) => FetchImpl;
|
|
604
388
|
}
|
|
605
389
|
//#endregion
|
|
390
|
+
//#region src/url.d.ts
|
|
391
|
+
type AllowedQueryParamValues = UnmaskType<boolean | number | string>;
|
|
392
|
+
type RecordStyleParams = UnmaskType<Record<string, AllowedQueryParamValues>>;
|
|
393
|
+
type TupleStyleParams = UnmaskType<AllowedQueryParamValues[]>;
|
|
394
|
+
type Params = UnmaskType<RecordStyleParams | TupleStyleParams>;
|
|
395
|
+
type Query = UnmaskType<Record<string, AllowedQueryParamValues>>;
|
|
396
|
+
type InitURLOrURLObject = AnyString | RouteKeyMethodsURLUnion | URL;
|
|
397
|
+
interface URLOptions {
|
|
398
|
+
/**
|
|
399
|
+
* Base URL for all API requests. Will only be prepended to relative URLs.
|
|
400
|
+
*
|
|
401
|
+
* Absolute URLs (starting with http/https) will not be prepended by the baseURL.
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```ts
|
|
405
|
+
* // Set base URL for all requests
|
|
406
|
+
* baseURL: "https://api.example.com/v1"
|
|
407
|
+
*
|
|
408
|
+
* // Then use relative URLs in requests
|
|
409
|
+
* callApi("/users") // → https://api.example.com/v1/users
|
|
410
|
+
* callApi("/posts/123") // → https://api.example.com/v1/posts/123
|
|
411
|
+
*
|
|
412
|
+
* // Environment-specific base URLs
|
|
413
|
+
* baseURL: process.env.NODE_ENV === "production"
|
|
414
|
+
* ? "https://api.example.com"
|
|
415
|
+
* : "http://localhost:3000/api"
|
|
416
|
+
* ```
|
|
417
|
+
*/
|
|
418
|
+
baseURL?: string;
|
|
419
|
+
/**
|
|
420
|
+
* Resolved request URL after processing baseURL, parameters, and query strings (readonly)
|
|
421
|
+
*
|
|
422
|
+
* This is the final URL that will be used for the HTTP request, computed from
|
|
423
|
+
* baseURL, initURL, params, and query parameters.
|
|
424
|
+
*
|
|
425
|
+
*/
|
|
426
|
+
readonly fullURL?: string;
|
|
427
|
+
/**
|
|
428
|
+
* The original URL string passed to the callApi instance (readonly)
|
|
429
|
+
*
|
|
430
|
+
* This preserves the original URL as provided, including any method modifiers like "@get/" or "@post/".
|
|
431
|
+
*
|
|
432
|
+
*/
|
|
433
|
+
readonly initURL?: string;
|
|
434
|
+
/**
|
|
435
|
+
* The URL string after normalization, with method modifiers removed(readonly)
|
|
436
|
+
*
|
|
437
|
+
* Method modifiers like "@get/", "@post/" are stripped to create a clean URL
|
|
438
|
+
* for parameter substitution and final URL construction.
|
|
439
|
+
*
|
|
440
|
+
*/
|
|
441
|
+
readonly initURLNormalized?: string;
|
|
442
|
+
/**
|
|
443
|
+
* Parameters to be substituted into URL path segments.
|
|
444
|
+
*
|
|
445
|
+
* Supports both object-style (named parameters) and array-style (positional parameters)
|
|
446
|
+
* for flexible URL parameter substitution.
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```typescript
|
|
450
|
+
* // Object-style parameters (recommended)
|
|
451
|
+
* const namedParams: URLOptions = {
|
|
452
|
+
* initURL: "/users/:userId/posts/:postId",
|
|
453
|
+
* params: { userId: "123", postId: "456" }
|
|
454
|
+
* };
|
|
455
|
+
* // Results in: /users/123/posts/456
|
|
456
|
+
*
|
|
457
|
+
* // Array-style parameters (positional)
|
|
458
|
+
* const positionalParams: URLOptions = {
|
|
459
|
+
* initURL: "/users/:userId/posts/:postId",
|
|
460
|
+
* params: ["123", "456"] // Maps in order: userId=123, postId=456
|
|
461
|
+
* };
|
|
462
|
+
* // Results in: /users/123/posts/456
|
|
463
|
+
*
|
|
464
|
+
* // Single parameter
|
|
465
|
+
* const singleParam: URLOptions = {
|
|
466
|
+
* initURL: "/users/:id",
|
|
467
|
+
* params: { id: "user-123" }
|
|
468
|
+
* };
|
|
469
|
+
* // Results in: /users/user-123
|
|
470
|
+
* ```
|
|
471
|
+
*/
|
|
472
|
+
params?: Params;
|
|
473
|
+
/**
|
|
474
|
+
* Query parameters to append to the URL as search parameters.
|
|
475
|
+
*
|
|
476
|
+
* These will be serialized into the URL query string using standard
|
|
477
|
+
* URL encoding practices.
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* ```typescript
|
|
481
|
+
* // Basic query parameters
|
|
482
|
+
* const queryOptions: URLOptions = {
|
|
483
|
+
* initURL: "/users",
|
|
484
|
+
* query: {
|
|
485
|
+
* page: 1,
|
|
486
|
+
* limit: 10,
|
|
487
|
+
* search: "john doe",
|
|
488
|
+
* active: true
|
|
489
|
+
* }
|
|
490
|
+
* };
|
|
491
|
+
* // Results in: /users?page=1&limit=10&search=john%20doe&active=true
|
|
492
|
+
*
|
|
493
|
+
* // Filtering and sorting
|
|
494
|
+
* const filterOptions: URLOptions = {
|
|
495
|
+
* initURL: "/products",
|
|
496
|
+
* query: {
|
|
497
|
+
* category: "electronics",
|
|
498
|
+
* minPrice: 100,
|
|
499
|
+
* maxPrice: 500,
|
|
500
|
+
* sortBy: "price",
|
|
501
|
+
* order: "asc"
|
|
502
|
+
* }
|
|
503
|
+
* };
|
|
504
|
+
* // Results in: /products?category=electronics&minPrice=100&maxPrice=500&sortBy=price&order=asc
|
|
505
|
+
* ```
|
|
506
|
+
*/
|
|
507
|
+
query?: Query;
|
|
508
|
+
}
|
|
509
|
+
//#endregion
|
|
606
510
|
//#region src/plugins.d.ts
|
|
607
|
-
type PluginSetupContext<TPluginExtraOptions = unknown> =
|
|
511
|
+
type PluginSetupContext<TPluginExtraOptions = unknown> = PluginExtraOptions<TPluginExtraOptions> & RequestContext & {
|
|
608
512
|
initURL: string;
|
|
609
513
|
};
|
|
610
514
|
type PluginInitResult = Partial<Omit<PluginSetupContext, "initURL" | "request"> & {
|
|
@@ -1287,11 +1191,7 @@ type InferHeadersOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequi
|
|
|
1287
1191
|
}) => InferSchemaOutput<TSchema$1["headers"], HeadersOption>);
|
|
1288
1192
|
}>;
|
|
1289
1193
|
type InferRequestOptions<TSchema$1 extends CallApiSchema, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, CallApiSchemaConfig>> = InferBodyOption<TSchema$1> & InferHeadersOption<TSchema$1> & InferMethodOption<TSchema$1, TInitURL>;
|
|
1290
|
-
|
|
1291
|
-
type GlobalMeta = Register extends {
|
|
1292
|
-
meta?: infer TMeta extends Record<string, unknown>;
|
|
1293
|
-
} ? TMeta : never;
|
|
1294
|
-
type InferMetaOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["meta"], {
|
|
1194
|
+
type InferMetaOption<TSchema$1 extends CallApiSchema, TCallApiContext extends CallApiContext> = MakeSchemaOptionRequiredIfDefined<TSchema$1["meta"], {
|
|
1295
1195
|
/**
|
|
1296
1196
|
* - An optional field you can fill with additional information,
|
|
1297
1197
|
* to associate with the request, typically used for logging or tracing.
|
|
@@ -1315,7 +1215,7 @@ type InferMetaOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequired
|
|
|
1315
1215
|
* });
|
|
1316
1216
|
* ```
|
|
1317
1217
|
*/
|
|
1318
|
-
meta?: InferSchemaOutput<TSchema$1["meta"],
|
|
1218
|
+
meta?: InferSchemaOutput<TSchema$1["meta"], TCallApiContext["Meta"]>;
|
|
1319
1219
|
}>;
|
|
1320
1220
|
type InferQueryOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["query"], {
|
|
1321
1221
|
/**
|
|
@@ -1338,7 +1238,7 @@ type InferParamsOption<TSchema$1 extends CallApiSchema, TBaseSchemaRoutes$1 exte
|
|
|
1338
1238
|
*/
|
|
1339
1239
|
params?: InferSchemaOutput<TSchema$1["params"], InferParamsFromRoute<TCurrentRouteSchemaKey>>;
|
|
1340
1240
|
}>;
|
|
1341
|
-
type InferExtraOptions<TSchema$1 extends CallApiSchema, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = InferMetaOption<TSchema$1> & InferParamsOption<TSchema$1, TBaseSchemaRoutes$1, TCurrentRouteSchemaKey> & InferQueryOption<TSchema$1>;
|
|
1241
|
+
type InferExtraOptions<TSchema$1 extends CallApiSchema, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TCallApiContext extends CallApiContext> = InferMetaOption<TSchema$1, TCallApiContext> & InferParamsOption<TSchema$1, TBaseSchemaRoutes$1, TCurrentRouteSchemaKey> & InferQueryOption<TSchema$1>;
|
|
1342
1242
|
type InferPluginOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<TPluginArray extends Array<infer TPlugin> ? TPlugin extends CallApiPlugin ? TPlugin["defineExtraOptions"] extends AnyFunction<infer TReturnedSchema> ? InferSchemaOutput<TReturnedSchema> : never : never : never>;
|
|
1343
1243
|
type ResultModeOption<TErrorData$1, TResultMode extends ResultModeType> = TErrorData$1 extends false ? {
|
|
1344
1244
|
resultMode: "onlyData";
|
|
@@ -1358,6 +1258,17 @@ type ThrowOnErrorOption<TErrorData$1, TThrowOnError extends ThrowOnErrorUnion> =
|
|
|
1358
1258
|
};
|
|
1359
1259
|
//#endregion
|
|
1360
1260
|
//#region src/types/common.d.ts
|
|
1261
|
+
interface Register {}
|
|
1262
|
+
type MetaObjectType = Record<string, unknown>;
|
|
1263
|
+
type GlobalMeta = Register extends {
|
|
1264
|
+
meta?: infer TMeta extends MetaObjectType;
|
|
1265
|
+
} ? TMeta : never;
|
|
1266
|
+
type CallApiContext = {
|
|
1267
|
+
Meta?: MetaObjectType;
|
|
1268
|
+
};
|
|
1269
|
+
type DefaultCallApiContext = {
|
|
1270
|
+
Meta?: GlobalMeta;
|
|
1271
|
+
};
|
|
1361
1272
|
type FetchSpecificKeysUnion = Exclude<(typeof fetchSpecificKeys)[number], "body" | "headers" | "method">;
|
|
1362
1273
|
type ModifiedRequestInit = RequestInit & {
|
|
1363
1274
|
duplex?: "half";
|
|
@@ -1380,7 +1291,7 @@ type CallApiRequestOptions = Prettify<{
|
|
|
1380
1291
|
type CallApiRequestOptionsForHooks = Omit<CallApiRequestOptions, "headers"> & {
|
|
1381
1292
|
headers: Record<string, string | undefined>;
|
|
1382
1293
|
};
|
|
1383
|
-
type SharedExtraOptions<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = DedupeOptions & HookConfigOptions & HooksOrHooksArray<TData$1, TErrorData$1, Partial<InferPluginOptions<TPluginArray>>> & Middlewares & Partial<InferPluginOptions<TPluginArray>> & ResultModeOption<TErrorData$1, TResultMode> & RetryOptions<TErrorData$1> & ThrowOnErrorOption<TErrorData$1, TThrowOnError> & URLOptions & {
|
|
1294
|
+
type SharedExtraOptions<TCallApiContext extends CallApiContext = CallApiContext, TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = DedupeOptions & HookConfigOptions & HooksOrHooksArray<TData$1, TErrorData$1, Partial<InferPluginOptions<TPluginArray>>> & Middlewares & Partial<InferPluginOptions<TPluginArray>> & ResultModeOption<TErrorData$1, TResultMode> & RetryOptions<TErrorData$1> & ThrowOnErrorOption<TErrorData$1, TThrowOnError> & URLOptions & {
|
|
1384
1295
|
/**
|
|
1385
1296
|
* Automatically add an Authorization header value.
|
|
1386
1297
|
*
|
|
@@ -1558,7 +1469,7 @@ type SharedExtraOptions<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataTyp
|
|
|
1558
1469
|
* });
|
|
1559
1470
|
* ```
|
|
1560
1471
|
*/
|
|
1561
|
-
meta?:
|
|
1472
|
+
meta?: TCallApiContext["Meta"];
|
|
1562
1473
|
/**
|
|
1563
1474
|
* Custom function to parse response strings into actual value instead of the default response.json().
|
|
1564
1475
|
*
|
|
@@ -1754,7 +1665,7 @@ type SharedExtraOptions<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataTyp
|
|
|
1754
1665
|
*/
|
|
1755
1666
|
timeout?: number;
|
|
1756
1667
|
};
|
|
1757
|
-
type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig> = SharedExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray> & {
|
|
1668
|
+
type BaseCallApiExtraOptions<TBaseCallApiContext extends CallApiContext = CallApiContext, TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig> = SharedExtraOptions<TBaseCallApiContext, TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray> & {
|
|
1758
1669
|
/**
|
|
1759
1670
|
* Array of base CallApi plugins to extend library functionality.
|
|
1760
1671
|
*
|
|
@@ -1866,7 +1777,7 @@ type InferExtendSchemaConfigContext<TBaseSchemaConfig extends CallApiSchemaConfi
|
|
|
1866
1777
|
type InferExtendPluginContext<TBasePluginArray extends CallApiPlugin[]> = {
|
|
1867
1778
|
basePlugins: TBasePluginArray;
|
|
1868
1779
|
};
|
|
1869
|
-
type CallApiExtraOptions<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig$1 extends CallApiSchemaConfig = CallApiSchemaConfig, TCurrentRouteSchemaKey extends string = string, TComputedPluginContext = InferExtendPluginContext<TBasePluginArray>, TComputedSchemaContext = InferExtendSchemaContext<TBaseSchemaRoutes$1, TCurrentRouteSchemaKey>, TComputedSchemaConfigContext = InferExtendSchemaConfigContext<TBaseSchemaConfig>> = SharedExtraOptions<TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType, TPluginArray> & {
|
|
1780
|
+
type CallApiExtraOptions<TCallApiContext extends CallApiContext = CallApiContext, TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig$1 extends CallApiSchemaConfig = CallApiSchemaConfig, TCurrentRouteSchemaKey extends string = string, TComputedPluginContext = InferExtendPluginContext<TBasePluginArray>, TComputedSchemaContext = InferExtendSchemaContext<TBaseSchemaRoutes$1, TCurrentRouteSchemaKey>, TComputedSchemaConfigContext = InferExtendSchemaConfigContext<TBaseSchemaConfig>> = SharedExtraOptions<TCallApiContext, TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType, TPluginArray> & {
|
|
1870
1781
|
/**
|
|
1871
1782
|
* Array of instance-specific CallApi plugins or a function to configure plugins.
|
|
1872
1783
|
*
|
|
@@ -1894,17 +1805,102 @@ type CallApiExtraOptions<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataTy
|
|
|
1894
1805
|
*/
|
|
1895
1806
|
schemaConfig?: TSchemaConfig$1 | ((context: TComputedSchemaConfigContext) => TSchemaConfig$1);
|
|
1896
1807
|
};
|
|
1897
|
-
type CallApiExtraOptionsForHooks = Hooks & Omit<CallApiExtraOptions
|
|
1808
|
+
type CallApiExtraOptionsForHooks<TCallApiContext extends CallApiContext = CallApiContext> = Hooks & Omit<CallApiExtraOptions<TCallApiContext>, keyof Hooks>;
|
|
1898
1809
|
type InstanceContext = {
|
|
1899
1810
|
initURL: string;
|
|
1900
1811
|
options: CallApiExtraOptions;
|
|
1901
1812
|
request: CallApiRequestOptions;
|
|
1902
1813
|
};
|
|
1903
|
-
type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseConfig = BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>> = (CallApiRequestOptions & TComputedBaseConfig) | ((context: InstanceContext) => CallApiRequestOptions & TComputedBaseConfig);
|
|
1904
|
-
type CallApiConfig<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig$1 extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = InferExtraOptions<TSchema$1, TBaseSchemaRoutes$1, TCurrentRouteSchemaKey> & InferRequestOptions<TSchema$1, TInitURL> & Omit<CallApiExtraOptions<TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchemaRoutes$1, TSchema$1, TBaseSchemaConfig, TSchemaConfig$1, TCurrentRouteSchemaKey>, keyof InferExtraOptions<CallApiSchema, BaseCallApiSchemaRoutes, string>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, string>>;
|
|
1905
|
-
type CallApiParameters<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig$1 extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = [initURL: TInitURL, config?: CallApiConfig<TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType, TBaseSchemaRoutes$1, TSchema$1, TBaseSchemaConfig, TSchemaConfig$1, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>];
|
|
1814
|
+
type BaseCallApiConfig<TBaseCallApiContext extends CallApiContext = CallApiContext, TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseConfig = BaseCallApiExtraOptions<TBaseCallApiContext, TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>> = (CallApiRequestOptions & TComputedBaseConfig) | ((context: InstanceContext) => CallApiRequestOptions & TComputedBaseConfig);
|
|
1815
|
+
type CallApiConfig<TCallApiContext extends CallApiContext = CallApiContext, TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig$1 extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = InferExtraOptions<TSchema$1, TBaseSchemaRoutes$1, TCurrentRouteSchemaKey, TCallApiContext> & InferRequestOptions<TSchema$1, TInitURL> & Omit<CallApiExtraOptions<TCallApiContext, TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchemaRoutes$1, TSchema$1, TBaseSchemaConfig, TSchemaConfig$1, TCurrentRouteSchemaKey>, keyof InferExtraOptions<CallApiSchema, BaseCallApiSchemaRoutes, string, CallApiContext>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, string>>;
|
|
1816
|
+
type CallApiParameters<TCallApiContext extends CallApiContext = CallApiContext, TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig$1 extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = [initURL: TInitURL, config?: CallApiConfig<TCallApiContext, TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType, TBaseSchemaRoutes$1, TSchema$1, TBaseSchemaConfig, TSchemaConfig$1, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>];
|
|
1906
1817
|
type CallApiResult<TData$1, TErrorData$1, TResultMode extends ResultModeType, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeType> = GetCallApiResult<TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType>;
|
|
1907
1818
|
type CallApiResultLoose<TData$1, TErrorData$1, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = ThrowOnErrorUnion, TResponseType extends ResponseTypeType = ResponseTypeType> = GetCallApiResult<TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType>;
|
|
1908
1819
|
//#endregion
|
|
1909
|
-
|
|
1910
|
-
|
|
1820
|
+
//#region src/validation.d.ts
|
|
1821
|
+
type ResultVariant = "infer-input" | "infer-output";
|
|
1822
|
+
type InferSchemaResult<TSchema$1, TFallbackResult, TResultVariant extends ResultVariant> = undefined extends TSchema$1 ? TFallbackResult : TSchema$1 extends StandardSchemaV1 ? TResultVariant extends "infer-input" ? StandardSchemaV1.InferInput<TSchema$1> : StandardSchemaV1.InferOutput<TSchema$1> : TSchema$1 extends AnyFunction<infer TResult> ? Awaited<TResult> : TFallbackResult;
|
|
1823
|
+
type InferSchemaOutput<TSchema$1, TFallbackResult = unknown> = InferSchemaResult<TSchema$1, TFallbackResult, "infer-output">;
|
|
1824
|
+
type InferSchemaInput<TSchema$1, TFallbackResult = unknown> = InferSchemaResult<TSchema$1, TFallbackResult, "infer-input">;
|
|
1825
|
+
interface CallApiSchemaConfig {
|
|
1826
|
+
/**
|
|
1827
|
+
* The base url of the schema. By default it's the baseURL of the callApi instance.
|
|
1828
|
+
*/
|
|
1829
|
+
baseURL?: string;
|
|
1830
|
+
/**
|
|
1831
|
+
* Disables runtime validation for the schema.
|
|
1832
|
+
*/
|
|
1833
|
+
disableRuntimeValidation?: boolean;
|
|
1834
|
+
/**
|
|
1835
|
+
* If `true`, the original input value will be used instead of the transformed/validated output.
|
|
1836
|
+
*
|
|
1837
|
+
* This is useful when you want to validate the input but don't want any transformations
|
|
1838
|
+
* applied by the validation schema (e.g., type coercion, default values, etc).
|
|
1839
|
+
*/
|
|
1840
|
+
disableValidationOutputApplication?: boolean;
|
|
1841
|
+
/**
|
|
1842
|
+
* Optional url prefix that will be substituted for the `baseURL` of the schemaConfig at runtime.
|
|
1843
|
+
*
|
|
1844
|
+
* This allows you to reuse the same schema against different base URLs (for example,
|
|
1845
|
+
* swapping between `/api/v1` and `/api/v2`) without redefining the entire schema.
|
|
1846
|
+
*/
|
|
1847
|
+
prefix?: string;
|
|
1848
|
+
/**
|
|
1849
|
+
* Controls the strictness of API route validation.
|
|
1850
|
+
*
|
|
1851
|
+
* When true:
|
|
1852
|
+
* - Only routes explicitly defined in the schema will be considered valid to typescript and the runtime.
|
|
1853
|
+
* - Attempting to call routes not defined in the schema will result in both type errors and runtime validation errors.
|
|
1854
|
+
* - Useful for ensuring API calls conform exactly to your schema definition
|
|
1855
|
+
*
|
|
1856
|
+
* When false or undefined (default):
|
|
1857
|
+
* - All routes will be allowed, whether they are defined in the schema or not
|
|
1858
|
+
*/
|
|
1859
|
+
strict?: boolean;
|
|
1860
|
+
}
|
|
1861
|
+
interface CallApiSchema {
|
|
1862
|
+
/**
|
|
1863
|
+
* The schema to use for validating the request body.
|
|
1864
|
+
*/
|
|
1865
|
+
body?: StandardSchemaV1<Body | undefined> | ((body: Body) => Awaitable<Body | undefined>);
|
|
1866
|
+
/**
|
|
1867
|
+
* The schema to use for validating the response data.
|
|
1868
|
+
*/
|
|
1869
|
+
data?: StandardSchemaV1 | ((data: unknown) => unknown);
|
|
1870
|
+
/**
|
|
1871
|
+
* The schema to use for validating the response error data.
|
|
1872
|
+
*/
|
|
1873
|
+
errorData?: StandardSchemaV1 | ((errorData: unknown) => unknown);
|
|
1874
|
+
/**
|
|
1875
|
+
* The schema to use for validating the request headers.
|
|
1876
|
+
*/
|
|
1877
|
+
headers?: StandardSchemaV1<HeadersOption | undefined> | ((headers: HeadersOption) => Awaitable<HeadersOption | undefined>);
|
|
1878
|
+
/**
|
|
1879
|
+
* The schema to use for validating the meta option.
|
|
1880
|
+
*/
|
|
1881
|
+
meta?: StandardSchemaV1<GlobalMeta | undefined> | ((meta: GlobalMeta) => Awaitable<GlobalMeta | undefined>);
|
|
1882
|
+
/**
|
|
1883
|
+
* The schema to use for validating the request method.
|
|
1884
|
+
*/
|
|
1885
|
+
method?: StandardSchemaV1<MethodUnion | undefined> | ((method: MethodUnion) => Awaitable<MethodUnion | undefined>);
|
|
1886
|
+
/**
|
|
1887
|
+
* The schema to use for validating the request url parameters.
|
|
1888
|
+
*/
|
|
1889
|
+
params?: StandardSchemaV1<Params | undefined> | ((params: Params) => Awaitable<Params | undefined>);
|
|
1890
|
+
/**
|
|
1891
|
+
* The schema to use for validating the request url queries.
|
|
1892
|
+
*/
|
|
1893
|
+
query?: StandardSchemaV1<Query | undefined> | ((query: Query) => Awaitable<Query | undefined>);
|
|
1894
|
+
}
|
|
1895
|
+
declare const routeKeyMethods: readonly ["delete", "get", "patch", "post", "put"];
|
|
1896
|
+
type RouteKeyMethods = (typeof routeKeyMethods)[number];
|
|
1897
|
+
type RouteKeyMethodsURLUnion = `@${RouteKeyMethods}/`;
|
|
1898
|
+
type BaseSchemaRouteKeyPrefixes = FallBackRouteSchemaKey | RouteKeyMethodsURLUnion;
|
|
1899
|
+
type BaseCallApiSchemaRoutes = Partial<Record<AnyString | BaseSchemaRouteKeyPrefixes, CallApiSchema>>;
|
|
1900
|
+
type BaseCallApiSchemaAndConfig = {
|
|
1901
|
+
config?: CallApiSchemaConfig;
|
|
1902
|
+
routes: BaseCallApiSchemaRoutes;
|
|
1903
|
+
};
|
|
1904
|
+
//#endregion
|
|
1905
|
+
export { definePlugin as $, GetCurrentRouteSchemaKey as A, RequestContext as B, InferExtendSchemaConfigContext as C, DefaultPluginArray as Ct, ApplyStrictConfig as D, Writeable as Dt, Register as E, AnyString as Et, DedupeOptions as F, SuccessContext as G, ResponseContext as H, ErrorContext as I, isJavascriptError as J, isHTTPError as K, Hooks as L, InferParamsFromRoute as M, ThrowOnErrorUnion as N, ApplyURLBasedConfig as O, RetryOptions as P, defineMainSchema as Q, HooksOrHooksArray as R, GetBaseSchemaRoutes as S, ValidationError as St, InstanceContext as T, toQueryString as Tt, ResponseErrorContext as U, RequestStreamContext as V, ResponseStreamContext as W, isValidationErrorInstance as X, isValidationError as Y, defineBaseConfig as Z, CallApiRequestOptionsForHooks as _, ResponseTypeMap as _t, CallApiSchemaConfig as a, PluginHooksWithMoreOptions as at, DefaultCallApiContext as b, ResultModeType as bt, InferSchemaResult as c, CallApiResultErrorVariant as ct, CallApiConfig as d, GetCallApiResult as dt, defineSchema as et, CallApiContext as f, GetResponseType as ft, CallApiRequestOptions as g, PossibleValidationError as gt, CallApiParameters as h, PossibleJavaScriptOrValidationError as ht, CallApiSchema as i, PluginHooks as it, InferInitURL as j, GetCurrentRouteSchema as k, BaseCallApiConfig as l, CallApiResultSuccessVariant as lt, CallApiExtraOptionsForHooks as m, PossibleJavaScriptError as mt, BaseCallApiSchemaRoutes as n, defineSchemaRoutes as nt, InferSchemaInput as o, PluginSetupContext as ot, CallApiExtraOptions as p, PossibleHTTPError as pt, isHTTPErrorInstance as q, BaseSchemaRouteKeyPrefixes as r, CallApiPlugin as rt, InferSchemaOutput as s, URLOptions as st, BaseCallApiSchemaAndConfig as t, defineSchemaConfig as tt, BaseCallApiExtraOptions as u, CallApiSuccessOrErrorVariant as ut, CallApiResult as v, ResponseTypeType as vt, InferExtendSchemaContext as w, toFormData as wt, GetBaseSchemaConfig as x, HTTPError as xt, CallApiResultLoose as y, ResultModeMap as yt, PluginExtraOptions as z };
|
|
1906
|
+
//# sourceMappingURL=validation-BeCBQ6_6.d.ts.map
|