@zayne-labs/callapi 1.11.24 → 1.11.25
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/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-BXtphXvQ.d.ts} +224 -231
- 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-BXtphXvQ.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;
|
|
@@ -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,6 +387,126 @@ 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
511
|
type PluginSetupContext<TPluginExtraOptions = unknown> = RequestContext & PluginExtraOptions<TPluginExtraOptions> & {
|
|
608
512
|
initURL: string;
|
|
@@ -1291,7 +1195,7 @@ interface Register {}
|
|
|
1291
1195
|
type GlobalMeta = Register extends {
|
|
1292
1196
|
meta?: infer TMeta extends Record<string, unknown>;
|
|
1293
1197
|
} ? TMeta : never;
|
|
1294
|
-
type InferMetaOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["meta"], {
|
|
1198
|
+
type InferMetaOption<TSchema$1 extends CallApiSchema, TCallApiEnv extends CallApiEnv> = MakeSchemaOptionRequiredIfDefined<TSchema$1["meta"], {
|
|
1295
1199
|
/**
|
|
1296
1200
|
* - An optional field you can fill with additional information,
|
|
1297
1201
|
* to associate with the request, typically used for logging or tracing.
|
|
@@ -1315,7 +1219,7 @@ type InferMetaOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequired
|
|
|
1315
1219
|
* });
|
|
1316
1220
|
* ```
|
|
1317
1221
|
*/
|
|
1318
|
-
meta?: InferSchemaOutput<TSchema$1["meta"],
|
|
1222
|
+
meta?: InferSchemaOutput<TSchema$1["meta"], TCallApiEnv["Meta"]>;
|
|
1319
1223
|
}>;
|
|
1320
1224
|
type InferQueryOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["query"], {
|
|
1321
1225
|
/**
|
|
@@ -1338,7 +1242,7 @@ type InferParamsOption<TSchema$1 extends CallApiSchema, TBaseSchemaRoutes$1 exte
|
|
|
1338
1242
|
*/
|
|
1339
1243
|
params?: InferSchemaOutput<TSchema$1["params"], InferParamsFromRoute<TCurrentRouteSchemaKey>>;
|
|
1340
1244
|
}>;
|
|
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>;
|
|
1245
|
+
type InferExtraOptions<TSchema$1 extends CallApiSchema, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TCallApiEnv extends CallApiEnv> = InferMetaOption<TSchema$1, TCallApiEnv> & InferParamsOption<TSchema$1, TBaseSchemaRoutes$1, TCurrentRouteSchemaKey> & InferQueryOption<TSchema$1>;
|
|
1342
1246
|
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
1247
|
type ResultModeOption<TErrorData$1, TResultMode extends ResultModeType> = TErrorData$1 extends false ? {
|
|
1344
1248
|
resultMode: "onlyData";
|
|
@@ -1358,6 +1262,10 @@ type ThrowOnErrorOption<TErrorData$1, TThrowOnError extends ThrowOnErrorUnion> =
|
|
|
1358
1262
|
};
|
|
1359
1263
|
//#endregion
|
|
1360
1264
|
//#region src/types/common.d.ts
|
|
1265
|
+
type BlankCallApiEnv = {};
|
|
1266
|
+
type CallApiEnv = {
|
|
1267
|
+
Meta?: GlobalMeta;
|
|
1268
|
+
};
|
|
1361
1269
|
type FetchSpecificKeysUnion = Exclude<(typeof fetchSpecificKeys)[number], "body" | "headers" | "method">;
|
|
1362
1270
|
type ModifiedRequestInit = RequestInit & {
|
|
1363
1271
|
duplex?: "half";
|
|
@@ -1380,7 +1288,7 @@ type CallApiRequestOptions = Prettify<{
|
|
|
1380
1288
|
type CallApiRequestOptionsForHooks = Omit<CallApiRequestOptions, "headers"> & {
|
|
1381
1289
|
headers: Record<string, string | undefined>;
|
|
1382
1290
|
};
|
|
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 & {
|
|
1291
|
+
type SharedExtraOptions<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TCallApiEnv extends CallApiEnv = CallApiEnv, 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
1292
|
/**
|
|
1385
1293
|
* Automatically add an Authorization header value.
|
|
1386
1294
|
*
|
|
@@ -1558,7 +1466,7 @@ type SharedExtraOptions<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataTyp
|
|
|
1558
1466
|
* });
|
|
1559
1467
|
* ```
|
|
1560
1468
|
*/
|
|
1561
|
-
meta?:
|
|
1469
|
+
meta?: TCallApiEnv["Meta"];
|
|
1562
1470
|
/**
|
|
1563
1471
|
* Custom function to parse response strings into actual value instead of the default response.json().
|
|
1564
1472
|
*
|
|
@@ -1754,7 +1662,7 @@ type SharedExtraOptions<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataTyp
|
|
|
1754
1662
|
*/
|
|
1755
1663
|
timeout?: number;
|
|
1756
1664
|
};
|
|
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> & {
|
|
1665
|
+
type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseCallApiEnv extends CallApiEnv = CallApiEnv, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig> = SharedExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseCallApiEnv, TBaseThrowOnError, TBaseResponseType, TBasePluginArray> & {
|
|
1758
1666
|
/**
|
|
1759
1667
|
* Array of base CallApi plugins to extend library functionality.
|
|
1760
1668
|
*
|
|
@@ -1866,7 +1774,7 @@ type InferExtendSchemaConfigContext<TBaseSchemaConfig extends CallApiSchemaConfi
|
|
|
1866
1774
|
type InferExtendPluginContext<TBasePluginArray extends CallApiPlugin[]> = {
|
|
1867
1775
|
basePlugins: TBasePluginArray;
|
|
1868
1776
|
};
|
|
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> & {
|
|
1777
|
+
type CallApiExtraOptions<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TCallApiEnv extends CallApiEnv = CallApiEnv, 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, TCallApiEnv, TThrowOnError, TResponseType, TPluginArray> & {
|
|
1870
1778
|
/**
|
|
1871
1779
|
* Array of instance-specific CallApi plugins or a function to configure plugins.
|
|
1872
1780
|
*
|
|
@@ -1900,11 +1808,96 @@ type InstanceContext = {
|
|
|
1900
1808
|
options: CallApiExtraOptions;
|
|
1901
1809
|
request: CallApiRequestOptions;
|
|
1902
1810
|
};
|
|
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>];
|
|
1811
|
+
type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseCallApiEnv extends CallApiEnv = CallApiEnv, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseConfig = BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseCallApiEnv, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>> = (CallApiRequestOptions & TComputedBaseConfig) | ((context: InstanceContext) => CallApiRequestOptions & TComputedBaseConfig);
|
|
1812
|
+
type CallApiConfig<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TCallApiEnv extends CallApiEnv = CallApiEnv, 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, TCallApiEnv> & InferRequestOptions<TSchema$1, TInitURL> & Omit<CallApiExtraOptions<TData$1, TErrorData$1, TResultMode, TCallApiEnv, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchemaRoutes$1, TSchema$1, TBaseSchemaConfig, TSchemaConfig$1, TCurrentRouteSchemaKey>, keyof InferExtraOptions<CallApiSchema, BaseCallApiSchemaRoutes, string, CallApiEnv>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, string>>;
|
|
1813
|
+
type CallApiParameters<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TCallApiEnv extends CallApiEnv = CallApiEnv, 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, TCallApiEnv, TThrowOnError, TResponseType, TBaseSchemaRoutes$1, TSchema$1, TBaseSchemaConfig, TSchemaConfig$1, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>];
|
|
1906
1814
|
type CallApiResult<TData$1, TErrorData$1, TResultMode extends ResultModeType, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeType> = GetCallApiResult<TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType>;
|
|
1907
1815
|
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
1816
|
//#endregion
|
|
1909
|
-
|
|
1910
|
-
|
|
1817
|
+
//#region src/validation.d.ts
|
|
1818
|
+
type ResultVariant = "infer-input" | "infer-output";
|
|
1819
|
+
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;
|
|
1820
|
+
type InferSchemaOutput<TSchema$1, TFallbackResult = unknown> = InferSchemaResult<TSchema$1, TFallbackResult, "infer-output">;
|
|
1821
|
+
type InferSchemaInput<TSchema$1, TFallbackResult = unknown> = InferSchemaResult<TSchema$1, TFallbackResult, "infer-input">;
|
|
1822
|
+
interface CallApiSchemaConfig {
|
|
1823
|
+
/**
|
|
1824
|
+
* The base url of the schema. By default it's the baseURL of the callApi instance.
|
|
1825
|
+
*/
|
|
1826
|
+
baseURL?: string;
|
|
1827
|
+
/**
|
|
1828
|
+
* Disables runtime validation for the schema.
|
|
1829
|
+
*/
|
|
1830
|
+
disableRuntimeValidation?: boolean;
|
|
1831
|
+
/**
|
|
1832
|
+
* If `true`, the original input value will be used instead of the transformed/validated output.
|
|
1833
|
+
*
|
|
1834
|
+
* This is useful when you want to validate the input but don't want any transformations
|
|
1835
|
+
* applied by the validation schema (e.g., type coercion, default values, etc).
|
|
1836
|
+
*/
|
|
1837
|
+
disableValidationOutputApplication?: boolean;
|
|
1838
|
+
/**
|
|
1839
|
+
* Optional url prefix that will be substituted for the `baseURL` of the schemaConfig at runtime.
|
|
1840
|
+
*
|
|
1841
|
+
* This allows you to reuse the same schema against different base URLs (for example,
|
|
1842
|
+
* swapping between `/api/v1` and `/api/v2`) without redefining the entire schema.
|
|
1843
|
+
*/
|
|
1844
|
+
prefix?: string;
|
|
1845
|
+
/**
|
|
1846
|
+
* Controls the strictness of API route validation.
|
|
1847
|
+
*
|
|
1848
|
+
* When true:
|
|
1849
|
+
* - Only routes explicitly defined in the schema will be considered valid to typescript and the runtime.
|
|
1850
|
+
* - Attempting to call routes not defined in the schema will result in both type errors and runtime validation errors.
|
|
1851
|
+
* - Useful for ensuring API calls conform exactly to your schema definition
|
|
1852
|
+
*
|
|
1853
|
+
* When false or undefined (default):
|
|
1854
|
+
* - All routes will be allowed, whether they are defined in the schema or not
|
|
1855
|
+
*/
|
|
1856
|
+
strict?: boolean;
|
|
1857
|
+
}
|
|
1858
|
+
interface CallApiSchema {
|
|
1859
|
+
/**
|
|
1860
|
+
* The schema to use for validating the request body.
|
|
1861
|
+
*/
|
|
1862
|
+
body?: StandardSchemaV1<Body | undefined> | ((body: Body) => Awaitable<Body | undefined>);
|
|
1863
|
+
/**
|
|
1864
|
+
* The schema to use for validating the response data.
|
|
1865
|
+
*/
|
|
1866
|
+
data?: StandardSchemaV1 | ((data: unknown) => unknown);
|
|
1867
|
+
/**
|
|
1868
|
+
* The schema to use for validating the response error data.
|
|
1869
|
+
*/
|
|
1870
|
+
errorData?: StandardSchemaV1 | ((errorData: unknown) => unknown);
|
|
1871
|
+
/**
|
|
1872
|
+
* The schema to use for validating the request headers.
|
|
1873
|
+
*/
|
|
1874
|
+
headers?: StandardSchemaV1<HeadersOption | undefined> | ((headers: HeadersOption) => Awaitable<HeadersOption | undefined>);
|
|
1875
|
+
/**
|
|
1876
|
+
* The schema to use for validating the meta option.
|
|
1877
|
+
*/
|
|
1878
|
+
meta?: StandardSchemaV1<GlobalMeta | undefined> | ((meta: GlobalMeta) => Awaitable<GlobalMeta | undefined>);
|
|
1879
|
+
/**
|
|
1880
|
+
* The schema to use for validating the request method.
|
|
1881
|
+
*/
|
|
1882
|
+
method?: StandardSchemaV1<MethodUnion | undefined> | ((method: MethodUnion) => Awaitable<MethodUnion | undefined>);
|
|
1883
|
+
/**
|
|
1884
|
+
* The schema to use for validating the request url parameters.
|
|
1885
|
+
*/
|
|
1886
|
+
params?: StandardSchemaV1<Params | undefined> | ((params: Params) => Awaitable<Params | undefined>);
|
|
1887
|
+
/**
|
|
1888
|
+
* The schema to use for validating the request url queries.
|
|
1889
|
+
*/
|
|
1890
|
+
query?: StandardSchemaV1<Query | undefined> | ((query: Query) => Awaitable<Query | undefined>);
|
|
1891
|
+
}
|
|
1892
|
+
declare const routeKeyMethods: readonly ["delete", "get", "patch", "post", "put"];
|
|
1893
|
+
type RouteKeyMethods = (typeof routeKeyMethods)[number];
|
|
1894
|
+
type RouteKeyMethodsURLUnion = `@${RouteKeyMethods}/`;
|
|
1895
|
+
type BaseSchemaRouteKeyPrefixes = FallBackRouteSchemaKey | RouteKeyMethodsURLUnion;
|
|
1896
|
+
type BaseCallApiSchemaRoutes = Partial<Record<AnyString | BaseSchemaRouteKeyPrefixes, CallApiSchema>>;
|
|
1897
|
+
type BaseCallApiSchemaAndConfig = {
|
|
1898
|
+
config?: CallApiSchemaConfig;
|
|
1899
|
+
routes: BaseCallApiSchemaRoutes;
|
|
1900
|
+
};
|
|
1901
|
+
//#endregion
|
|
1902
|
+
export { definePlugin as $, InferInitURL as A, RequestContext as B, InferExtendSchemaConfigContext as C, DefaultPluginArray as Ct, ApplyURLBasedConfig as D, Writeable as Dt, ApplyStrictConfig 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, Register as M, ThrowOnErrorUnion as N, GetCurrentRouteSchema 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, CallApiRequestOptions as _, ResponseTypeMap as _t, CallApiSchemaConfig as a, PluginHooksWithMoreOptions as at, CallApiResultLoose as b, ResultModeType as bt, InferSchemaResult as c, CallApiResultErrorVariant as ct, BlankCallApiEnv as d, GetCallApiResult as dt, defineSchema as et, CallApiConfig as f, GetResponseType as ft, CallApiParameters as g, PossibleValidationError as gt, CallApiExtraOptionsForHooks as h, PossibleJavaScriptOrValidationError as ht, CallApiSchema as i, PluginHooks as it, InferParamsFromRoute as j, GetCurrentRouteSchemaKey as k, BaseCallApiConfig as l, CallApiResultSuccessVariant as lt, CallApiExtraOptions as m, PossibleJavaScriptError as mt, BaseCallApiSchemaRoutes as n, defineSchemaRoutes as nt, InferSchemaInput as o, PluginSetupContext as ot, CallApiEnv 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, CallApiRequestOptionsForHooks as v, ResponseTypeType as vt, InferExtendSchemaContext as w, toFormData as wt, GetBaseSchemaConfig as x, HTTPError as xt, CallApiResult as y, ResultModeMap as yt, PluginExtraOptions as z };
|
|
1903
|
+
//# sourceMappingURL=validation-BXtphXvQ.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zayne-labs/callapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.11.
|
|
4
|
+
"version": "1.11.25",
|
|
5
5
|
"description": "A lightweight wrapper over fetch with quality of life improvements like built-in request cancellation, retries, interceptors and more",
|
|
6
6
|
"author": "Ryan Zayne",
|
|
7
7
|
"license": "MIT",
|
|
@@ -39,20 +39,20 @@
|
|
|
39
39
|
"@size-limit/esbuild-why": "11.2.0",
|
|
40
40
|
"@size-limit/preset-small-lib": "11.2.0",
|
|
41
41
|
"@total-typescript/ts-reset": "0.6.1",
|
|
42
|
-
"@vitest/browser": "4.0.
|
|
43
|
-
"@vitest/browser-playwright": "4.0.
|
|
44
|
-
"@vitest/coverage-v8": "4.0.
|
|
42
|
+
"@vitest/browser": "4.0.14",
|
|
43
|
+
"@vitest/browser-playwright": "4.0.14",
|
|
44
|
+
"@vitest/coverage-v8": "4.0.14",
|
|
45
45
|
"@zayne-labs/prettier-config": "^0.11.5",
|
|
46
46
|
"@zayne-labs/tsconfig": "0.11.5",
|
|
47
47
|
"concurrently": "^9.2.1",
|
|
48
48
|
"cross-env": "^10.1.0",
|
|
49
|
-
"playwright": "^1.
|
|
49
|
+
"playwright": "^1.57.0",
|
|
50
50
|
"publint": "^0.3.15",
|
|
51
51
|
"size-limit": "11.2.0",
|
|
52
52
|
"tsdown": "0.15.9",
|
|
53
53
|
"typescript": "5.9.3",
|
|
54
|
-
"vitest": "^4.0.
|
|
55
|
-
"zod": "^4.1.
|
|
54
|
+
"vitest": "^4.0.14",
|
|
55
|
+
"zod": "^4.1.13"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public",
|