@zayne-labs/callapi 1.10.1 → 1.10.3

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.
@@ -163,42 +163,6 @@ declare namespace StandardSchemaV1 {
163
163
  type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
164
164
  }
165
165
  //#endregion
166
- //#region src/error.d.ts
167
- type HTTPErrorDetails<TErrorData> = Pick<CallApiExtraOptions, "defaultHTTPErrorMessage"> & {
168
- errorData: TErrorData;
169
- response: Response;
170
- };
171
- declare class HTTPError<TErrorData = Record<string, unknown>> extends Error {
172
- errorData: HTTPErrorDetails<TErrorData>["errorData"];
173
- readonly httpErrorSymbol: symbol;
174
- name: "HTTPError";
175
- response: HTTPErrorDetails<TErrorData>["response"];
176
- constructor(errorDetails: HTTPErrorDetails<TErrorData>, errorOptions?: ErrorOptions);
177
- /**
178
- * @description Checks if the given error is an instance of HTTPError
179
- * @param error - The error to check
180
- * @returns true if the error is an instance of HTTPError, false otherwise
181
- */
182
- static isError<TErrorData>(error: unknown): error is HTTPError<TErrorData>;
183
- }
184
- type ValidationErrorDetails = {
185
- issues: readonly StandardSchemaV1.Issue[];
186
- response: Response | null;
187
- };
188
- declare class ValidationError extends Error {
189
- errorData: ValidationErrorDetails["issues"];
190
- name: "ValidationError";
191
- response: ValidationErrorDetails["response"];
192
- readonly validationErrorSymbol: symbol;
193
- constructor(details: ValidationErrorDetails, errorOptions?: ErrorOptions);
194
- /**
195
- * @description Checks if the given error is an instance of ValidationError
196
- * @param error - The error to check
197
- * @returns true if the error is an instance of ValidationError, false otherwise
198
- */
199
- static isError(error: unknown): error is ValidationError;
200
- }
201
- //#endregion
202
166
  //#region src/url.d.ts
203
167
  type AllowedQueryParamValues = UnmaskType<boolean | number | string>;
204
168
  type RecordStyleParams = UnmaskType<Record<string, AllowedQueryParamValues>>;
@@ -403,6 +367,56 @@ type BaseCallApiSchemaAndConfig = {
403
367
  declare const fallBackRouteSchemaKey = ".";
404
368
  type FallBackRouteSchemaKey = typeof fallBackRouteSchemaKey;
405
369
  //#endregion
370
+ //#region src/error.d.ts
371
+ type HTTPErrorDetails<TErrorData> = Pick<CallApiExtraOptions, "defaultHTTPErrorMessage"> & {
372
+ errorData: TErrorData;
373
+ response: Response;
374
+ };
375
+ declare class HTTPError<TErrorData = Record<string, unknown>> extends Error {
376
+ errorData: HTTPErrorDetails<TErrorData>["errorData"];
377
+ readonly httpErrorSymbol: symbol;
378
+ name: "HTTPError";
379
+ response: HTTPErrorDetails<TErrorData>["response"];
380
+ constructor(errorDetails: HTTPErrorDetails<TErrorData>, errorOptions?: ErrorOptions);
381
+ /**
382
+ * @description Checks if the given error is an instance of HTTPError
383
+ * @param error - The error to check
384
+ * @returns true if the error is an instance of HTTPError, false otherwise
385
+ */
386
+ static isError<TErrorData>(error: unknown): error is HTTPError<TErrorData>;
387
+ }
388
+ type LockedExtract<TUnion, TKey extends TUnion> = Extract<TUnion, TKey>;
389
+ type ValidationErrorDetails = {
390
+ /**
391
+ * The cause of the validation error.
392
+ *
393
+ * It's either the name the schema for which validation failed, or the name of the schema config option that led to the validation error.
394
+ */
395
+ issueCause: "unknown" | `schemaConfig-(${LockedExtract<keyof CallApiSchemaConfig, "strict">})` | keyof CallApiSchema;
396
+ /**
397
+ * The issues that caused the validation error.
398
+ */
399
+ issues: readonly StandardSchemaV1.Issue[];
400
+ /**
401
+ * The response from server, if any.
402
+ */
403
+ response: Response | null;
404
+ };
405
+ declare class ValidationError extends Error {
406
+ errorData: ValidationErrorDetails["issues"];
407
+ issueCause: ValidationErrorDetails["issueCause"];
408
+ name: "ValidationError";
409
+ response: ValidationErrorDetails["response"];
410
+ readonly validationErrorSymbol: symbol;
411
+ constructor(details: ValidationErrorDetails, errorOptions?: ErrorOptions);
412
+ /**
413
+ * @description Checks if the given error is an instance of ValidationError
414
+ * @param error - The error to check
415
+ * @returns true if the error is an instance of ValidationError, false otherwise
416
+ */
417
+ static isError(error: unknown): error is ValidationError;
418
+ }
419
+ //#endregion
406
420
  //#region src/plugins.d.ts
407
421
  type PluginSetupContext<TPluginExtraOptions = unknown> = RequestContext & PluginExtraOptions<TPluginExtraOptions> & {
408
422
  initURL: string;
@@ -486,6 +500,7 @@ type PossibleHTTPError<TErrorData> = UnmaskType<{
486
500
  }>;
487
501
  type PossibleValidationError = UnmaskType<{
488
502
  errorData: ValidationError["errorData"];
503
+ issueCause: ValidationError["issueCause"];
489
504
  message: string;
490
505
  name: "ValidationError";
491
506
  originalError: ValidationError;
@@ -500,14 +515,18 @@ type CallApiResultErrorVariant<TErrorData> = {
500
515
  error: PossibleJavaScriptOrValidationError;
501
516
  response: Response | null;
502
517
  };
503
- type ResultModeMap<TData = DefaultDataType, TErrorData = DefaultDataType, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TComputedData = GetResponseType<TData, TResponseType>, TComputedErrorData = GetResponseType<TErrorData, TResponseType>> = UnmaskType<{
504
- all: CallApiResultSuccessVariant<TComputedData> | CallApiResultErrorVariant<TComputedErrorData>;
505
- allWithException: CallApiResultSuccessVariant<TComputedData>;
506
- onlySuccess: CallApiResultErrorVariant<TComputedErrorData>["data"] | CallApiResultSuccessVariant<TComputedData>["data"];
507
- onlySuccessWithException: CallApiResultSuccessVariant<TComputedData>["data"];
518
+ type ResultModeMapWithoutException<TData, TErrorData, TResponseType extends ResponseTypeUnion, TComputedData = GetResponseType<TData, TResponseType>, TComputedErrorData = GetResponseType<TErrorData, TResponseType>> = UnmaskType<{
519
+ all: CallApiResultErrorVariant<TComputedErrorData> | CallApiResultSuccessVariant<TComputedData>;
520
+ onlyData: CallApiResultErrorVariant<TComputedErrorData>["data"] | CallApiResultSuccessVariant<TComputedData>["data"];
508
521
  }>;
509
- type ResultModeUnion = keyof ResultModeMap | null;
510
- type GetCallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeUnion> = TErrorData extends false ? ResultModeMap<TData, TErrorData, TResponseType>["onlySuccessWithException"] : TErrorData extends false | undefined ? ResultModeMap<TData, TErrorData, TResponseType>["onlySuccessWithException"] : TErrorData extends false | null ? ResultModeMap<TData, TErrorData, TResponseType>["onlySuccess"] : null extends TResultMode ? TThrowOnError extends true ? ResultModeMap<TData, TErrorData, TResponseType>["allWithException"] : ResultModeMap<TData, TErrorData, TResponseType>["all"] : TResultMode extends NonNullable<ResultModeUnion> ? ResultModeMap<TData, TErrorData, TResponseType>[TResultMode] : never;
522
+ type ResultModeMapWithException<TData, TResponseType extends ResponseTypeUnion, TComputedData = GetResponseType<TData, TResponseType>> = {
523
+ all: CallApiResultSuccessVariant<TComputedData>;
524
+ onlyData: CallApiResultSuccessVariant<TComputedData>["data"];
525
+ };
526
+ type ResultModeMap<TData = DefaultDataType, TErrorData = DefaultDataType, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError> = TThrowOnError extends true ? ResultModeMapWithException<TData, TResponseType> : ResultModeMapWithoutException<TData, TErrorData, TResponseType>;
527
+ type ResultModePlaceholder = null;
528
+ type ResultModeUnion = keyof ResultModeMap | ResultModePlaceholder;
529
+ type GetCallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeUnion> = TErrorData extends false ? ResultModeMapWithException<TData, TResponseType>["onlyData"] : TErrorData extends false | undefined ? ResultModeMapWithException<TData, TResponseType>["onlyData"] : ResultModePlaceholder extends TResultMode ? ResultModeMap<TData, TErrorData, TResponseType, TThrowOnError>["all"] : TResultMode extends Exclude<ResultModeUnion, ResultModePlaceholder> ? ResultModeMap<TData, TErrorData, TResponseType, TThrowOnError>[TResultMode] : never;
511
530
  //#endregion
512
531
  //#region src/stream.d.ts
513
532
  type StreamProgressEvent = {
@@ -803,7 +822,7 @@ type RequestContext = {
803
822
  };
804
823
  type ValidationErrorContext = UnmaskType<RequestContext & {
805
824
  /** Validation error containing details about what failed validation */
806
- error: ValidationError;
825
+ error: PossibleValidationError;
807
826
  /** HTTP response object if validation failed on response, null if on request */
808
827
  response: Response | null;
809
828
  }>;
@@ -818,7 +837,7 @@ type ResponseContext<TData, TErrorData> = UnmaskType<RequestContext & (Prettify<
818
837
  }>>)>;
819
838
  type RequestErrorContext = RequestContext & {
820
839
  /** Error that occurred during the request (network, timeout, etc.) */
821
- error: PossibleJavaScriptOrValidationError;
840
+ error: PossibleJavaScriptError;
822
841
  /** Always null for request errors since no response was received */
823
842
  response: null;
824
843
  };
@@ -1222,23 +1241,21 @@ type InferParamsOption<TSchema extends CallApiSchema, TBaseSchemaRoutes extends
1222
1241
  }>;
1223
1242
  type InferExtraOptions<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = InferMetaOption<TSchema> & InferParamsOption<TSchema, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferQueryOption<TSchema>;
1224
1243
  type InferPluginOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<TPluginArray extends Array<infer TPlugin> ? TPlugin extends CallApiPlugin ? TPlugin["defineExtraOptions"] extends AnyFunction<infer TReturnedSchema> ? InferSchemaOutputResult<TReturnedSchema> : never : never : never>;
1225
- type ExtractKeys<TUnion, TSelectedUnion extends TUnion> = Extract<TUnion, TSelectedUnion>;
1226
1244
  type ResultModeOption<TErrorData, TResultMode extends ResultModeUnion> = TErrorData extends false ? {
1227
- resultMode: "onlySuccessWithException";
1245
+ resultMode: "onlyData";
1228
1246
  } : TErrorData extends false | undefined ? {
1229
- resultMode?: "onlySuccessWithException";
1230
- } : TErrorData extends false | null ? {
1231
- resultMode?: ExtractKeys<ResultModeUnion, "onlySuccess" | "onlySuccessWithException">;
1247
+ resultMode?: "onlyData";
1232
1248
  } : {
1233
1249
  resultMode?: TResultMode;
1234
1250
  };
1235
1251
  type ThrowOnErrorUnion = boolean;
1252
+ type ThrowOnErrorType<TErrorData, TThrowOnError extends ThrowOnErrorUnion> = TThrowOnError | ((context: ErrorContext<TErrorData>) => TThrowOnError);
1236
1253
  type ThrowOnErrorOption<TErrorData, TThrowOnError extends ThrowOnErrorUnion> = TErrorData extends false ? {
1237
1254
  throwOnError: true;
1238
1255
  } : TErrorData extends false | undefined ? {
1239
1256
  throwOnError?: true;
1240
1257
  } : {
1241
- throwOnError?: TThrowOnError | ((context: ErrorContext<TErrorData>) => TThrowOnError);
1258
+ throwOnError?: ThrowOnErrorType<TErrorData, TThrowOnError>;
1242
1259
  };
1243
1260
  //#endregion
1244
1261
  //#region src/types/common.d.ts
@@ -1519,46 +1536,50 @@ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, T
1519
1536
  *
1520
1537
  * Different modes return different combinations of data, error, and response:
1521
1538
  * - **"all"**: Returns { data, error, response } - complete result information
1522
- * - **"allWithException"**: Returns { data, error, response } but throws on errors
1523
- * - **"onlySuccess"**: Returns only data (null for errors), never throws
1524
- * - **"onlySuccessWithException"**: Returns only data but throws on errors
1539
+ * - **"onlyData"**: Returns only data (null for errors)
1540
+ *
1541
+ * When combined with throwOnError: true, null/error variants are automatically removed:
1542
+ * - **"all" + throwOnError: true**: Returns { data, error: null, response } (error property is null, throws instead)
1543
+ * - **"onlyData" + throwOnError: true**: Returns data (never null, throws on error)
1525
1544
  *
1526
1545
  * @default "all"
1527
1546
  *
1528
1547
  * @example
1529
1548
  * ```ts
1530
1549
  * // Complete result with all information (default)
1531
- * resultMode: "all"
1532
- * const { data, error, response } = await callApi("/users");
1550
+ * const { data, error, response } = await callApi("/users", { resultMode: "all" });
1533
1551
  * if (error) {
1534
1552
  * console.error("Request failed:", error);
1535
1553
  * } else {
1536
1554
  * console.log("Users:", data);
1537
1555
  * }
1538
1556
  *
1539
- * // Complete result but throws on errors
1540
- * resultMode: "allWithException"
1557
+ * // Complete result but throws on errors (throwOnError removes error from type)
1541
1558
  * try {
1542
- * const { data, response } = await callApi("/users", { resultMode: "allWithException" });
1543
- * console.log("Users:", data);
1559
+ * const { data, response } = await callApi("/users", {
1560
+ * resultMode: "all",
1561
+ * throwOnError: true
1562
+ * });
1563
+ * console.log("Users:", data); // data is never null here
1544
1564
  * } catch (error) {
1545
1565
  * console.error("Request failed:", error);
1546
1566
  * }
1547
1567
  *
1548
1568
  * // Only data, returns null on errors
1549
- * resultMode: "onlySuccess"
1550
- * const users = await callApi("/users", { resultMode: "onlySuccess" });
1569
+ * const users = await callApi("/users", { resultMode: "onlyData" });
1551
1570
  * if (users) {
1552
1571
  * console.log("Users:", users);
1553
1572
  * } else {
1554
1573
  * console.log("Request failed");
1555
1574
  * }
1556
1575
  *
1557
- * // Only data with null, throws on errors
1558
- * resultMode: "onlySuccessWithException"
1576
+ * // Only data, throws on errors (throwOnError removes null from type)
1559
1577
  * try {
1560
- * const users = await callApi("/users", { resultMode: "onlySuccessWithException" });
1561
- * console.log("Users:", users);
1578
+ * const users = await callApi("/users", {
1579
+ * resultMode: "onlyData",
1580
+ * throwOnError: true
1581
+ * });
1582
+ * console.log("Users:", users); // users is never null here
1562
1583
  * } catch (error) {
1563
1584
  * console.error("Request failed:", error);
1564
1585
  * }
@@ -1609,7 +1630,7 @@ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, T
1609
1630
  * }
1610
1631
  * ```
1611
1632
  */
1612
- throwOnError?: TThrowOnError | ((context: ErrorContext<TErrorData>) => TThrowOnError);
1633
+ throwOnError?: ThrowOnErrorType<TErrorData, TThrowOnError>;
1613
1634
  /**
1614
1635
  * Request timeout in milliseconds. Request will be aborted if it takes longer.
1615
1636
  *
@@ -1771,7 +1792,7 @@ type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType,
1771
1792
  }) => TSchemaConfig);
1772
1793
  };
1773
1794
  type CallApiExtraOptionsForHooks = Hooks & Omit<CallApiExtraOptions, keyof Hooks>;
1774
- type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray> = (CallApiRequestOptions & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>) | ((context: {
1795
+ type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray> = (CallApiRequestOptions & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>) | ((instanceConfig: {
1775
1796
  initURL: string;
1776
1797
  options: CallApiExtraOptions;
1777
1798
  request: CallApiRequestOptions;
@@ -1781,4 +1802,4 @@ type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TR
1781
1802
  type CallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeUnion> = Promise<GetCallApiResult<TData, TErrorData, TResultMode, TThrowOnError, TResponseType>>;
1782
1803
  //#endregion
1783
1804
  export { AnyFunction, AnyString, ApplyStrictConfig, ApplyURLBasedConfig, BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaAndConfig, BaseCallApiSchemaRoutes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteSchema, GetCurrentRouteSchemaKey, GetResponseType, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaOutputResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeMap, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable, fallBackRouteSchemaKey };
1784
- //# sourceMappingURL=common-CO8LGZIl.d.ts.map
1805
+ //# sourceMappingURL=common-Bk1Hh1hR.d.ts.map
@@ -1,4 +1,4 @@
1
- import { AnyFunction, AnyString, ApplyStrictConfig, ApplyURLBasedConfig, BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaAndConfig, BaseCallApiSchemaRoutes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteSchema, GetCurrentRouteSchemaKey, GetResponseType, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaOutputResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeMap, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable, fallBackRouteSchemaKey } from "./common-CO8LGZIl.js";
1
+ import { AnyFunction, AnyString, ApplyStrictConfig, ApplyURLBasedConfig, BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaAndConfig, BaseCallApiSchemaRoutes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteSchema, GetCurrentRouteSchemaKey, GetResponseType, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaOutputResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeMap, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable, fallBackRouteSchemaKey } from "./common-Bk1Hh1hR.js";
2
2
 
3
3
  //#region src/createFetchClient.d.ts
4
4
 
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { HTTPError, ValidationError, createCombinedSignal, createTimeoutSignal, defineEnum, deterministicHashFn, extraOptionDefaults, getBody, getFetchImpl, getHeaders, isArray, isBoolean, isFunction, isHTTPErrorInstance, isObject, isPlainObject, isReadableStream, isString, isValidationErrorInstance, requestOptionDefaults, splitBaseConfig, splitConfig, toArray, toQueryString, waitFor } from "./utils-zvYT8TK8.js";
1
+ import { HTTPError, ValidationError, createCombinedSignal, createTimeoutSignal, defineEnum, deterministicHashFn, extraOptionDefaults, getBody, getFetchImpl, getHeaders, isArray, isBoolean, isFunction, isHTTPErrorInstance, isObject, isPlainObject, isReadableStream, isString, isValidationErrorInstance, requestOptionDefaults, splitBaseConfig, splitConfig, toArray, toQueryString, waitFor } from "./utils-BCsnh8UI.js";
2
2
 
3
3
  //#region src/result.ts
4
4
  const getResponseType = (response, parser) => ({
@@ -35,13 +35,10 @@ const resolveResponseData = (response, responseType, parser) => {
35
35
  return RESPONSE_TYPE_LOOKUP[selectedResponseType]();
36
36
  };
37
37
  const getResultModeMap = (details) => {
38
- const resultModeMap = {
38
+ return {
39
39
  all: () => details,
40
- allWithException: () => resultModeMap.all(),
41
- onlySuccess: () => details.data,
42
- onlySuccessWithException: () => resultModeMap.onlySuccess()
40
+ onlyData: () => details.data
43
41
  };
44
- return resultModeMap;
45
42
  };
46
43
  const resolveSuccessResult = (data, info) => {
47
44
  const { response, resultMode } = info;
@@ -69,6 +66,7 @@ const resolveErrorResult = (error, info) => {
69
66
  data: null,
70
67
  error: {
71
68
  errorData,
69
+ issueCause: error.issueCause,
72
70
  message,
73
71
  name: "ValidationError",
74
72
  originalError: error
@@ -344,12 +342,15 @@ const handleValidatorFunction = async (validator, inputData) => {
344
342
  };
345
343
  }
346
344
  };
347
- const standardSchemaParser = async (schema, inputData, response) => {
345
+ const standardSchemaParser = async (fullSchema, schemaName, inputData, response) => {
346
+ const schema = fullSchema?.[schemaName];
347
+ if (!schema) return inputData;
348
348
  const result = isFunction(schema) ? await handleValidatorFunction(schema, inputData) : await schema["~standard"].validate(inputData);
349
349
  if (result.issues) throw new ValidationError({
350
+ issueCause: schemaName,
350
351
  issues: result.issues,
351
352
  response: response ?? null
352
- }, { cause: result.issues });
353
+ });
353
354
  return result.value;
354
355
  };
355
356
  const routeKeyMethods = defineEnum([
@@ -359,10 +360,10 @@ const routeKeyMethods = defineEnum([
359
360
  "post",
360
361
  "put"
361
362
  ]);
362
- const handleSchemaValidation = async (schema, validationOptions) => {
363
+ const handleSchemaValidation = async (fullSchema, schemaName, validationOptions) => {
363
364
  const { inputValue, response, schemaConfig } = validationOptions;
364
- if (!schema || schemaConfig?.disableRuntimeValidation) return inputValue;
365
- return await standardSchemaParser(schema, inputValue, response);
365
+ if (schemaConfig?.disableRuntimeValidation) return inputValue;
366
+ return await standardSchemaParser(fullSchema, schemaName, inputValue, response);
366
367
  };
367
368
  const extraOptionsToBeValidated = [
368
369
  "meta",
@@ -371,15 +372,15 @@ const extraOptionsToBeValidated = [
371
372
  ];
372
373
  const handleExtraOptionsValidation = async (validationOptions) => {
373
374
  const { options, schema, schemaConfig } = validationOptions;
374
- const validationResultArray = await Promise.all(extraOptionsToBeValidated.map((propertyKey) => handleSchemaValidation(schema?.[propertyKey], {
375
- inputValue: options[propertyKey],
375
+ const validationResultArray = await Promise.all(extraOptionsToBeValidated.map((schemaName) => handleSchemaValidation(schema, schemaName, {
376
+ inputValue: options[schemaName],
376
377
  schemaConfig
377
378
  })));
378
379
  const validatedResultObject = {};
379
- for (const [index, propertyKey] of extraOptionsToBeValidated.entries()) {
380
+ for (const [index, schemaName] of extraOptionsToBeValidated.entries()) {
380
381
  const validationResult = validationResultArray[index];
381
382
  if (validationResult === void 0) continue;
382
- validatedResultObject[propertyKey] = validationResult;
383
+ validatedResultObject[schemaName] = validationResult;
383
384
  }
384
385
  return validatedResultObject;
385
386
  };
@@ -390,8 +391,8 @@ const requestOptionsToBeValidated = [
390
391
  ];
391
392
  const handleRequestOptionsValidation = async (validationOptions) => {
392
393
  const { requestOptions, schema, schemaConfig } = validationOptions;
393
- const validationResultArray = await Promise.all(requestOptionsToBeValidated.map((propertyKey) => handleSchemaValidation(schema?.[propertyKey], {
394
- inputValue: requestOptions[propertyKey],
394
+ const validationResultArray = await Promise.all(requestOptionsToBeValidated.map((schemaName) => handleSchemaValidation(schema, schemaName, {
395
+ inputValue: requestOptions[schemaName],
395
396
  schemaConfig
396
397
  })));
397
398
  const validatedResultObject = {};
@@ -413,7 +414,8 @@ const handleConfigValidation = async (validationOptions) => {
413
414
  baseExtraOptions,
414
415
  extraOptions
415
416
  });
416
- if (!currentRouteSchema && resolvedSchemaConfig?.strict === true) throw new ValidationError({
417
+ if (resolvedSchemaConfig?.strict === true && !currentRouteSchema) throw new ValidationError({
418
+ issueCause: "schemaConfig-(strict)",
417
419
  issues: [{ message: `Strict Mode - No schema found for route '${currentRouteSchemaKey}' ` }],
418
420
  response: null
419
421
  });
@@ -818,7 +820,7 @@ const createFetchClient = (initBaseConfig = {}) => {
818
820
  const shouldCloneResponse = resolvedDedupeStrategy === "defer" || options.cloneResponse;
819
821
  if (!response.ok) {
820
822
  const errorData = await resolveResponseData(shouldCloneResponse ? response.clone() : response, options.responseType, options.responseParser);
821
- const validErrorData = await handleSchemaValidation(resolvedSchema?.errorData, {
823
+ const validErrorData = await handleSchemaValidation(resolvedSchema, "errorData", {
822
824
  inputValue: errorData,
823
825
  response,
824
826
  schemaConfig: resolvedSchemaConfig
@@ -830,7 +832,7 @@ const createFetchClient = (initBaseConfig = {}) => {
830
832
  }, { cause: validErrorData });
831
833
  }
832
834
  const successData = await resolveResponseData(shouldCloneResponse ? response.clone() : response, options.responseType, options.responseParser);
833
- const validSuccessData = await handleSchemaValidation(resolvedSchema?.data, {
835
+ const validSuccessData = await handleSchemaValidation(resolvedSchema, "data", {
834
836
  inputValue: successData,
835
837
  response,
836
838
  schemaConfig: resolvedSchemaConfig
@@ -865,7 +867,7 @@ const createFetchClient = (initBaseConfig = {}) => {
865
867
  request,
866
868
  response: errorDetails.response
867
869
  };
868
- const shouldThrowOnError = isFunction(options.throwOnError) ? options.throwOnError(errorContext) : options.throwOnError;
870
+ const shouldThrowOnError = Boolean(isFunction(options.throwOnError) ? options.throwOnError(errorContext) : options.throwOnError);
869
871
  const hookInfo = {
870
872
  errorInfo,
871
873
  shouldThrowOnError
@@ -890,11 +892,7 @@ const createFetchClient = (initBaseConfig = {}) => {
890
892
  if (shouldThrowOnError) throw error;
891
893
  return generalErrorResult;
892
894
  };
893
- if (isValidationErrorInstance(error)) return await executeHooksInCatchBlock([
894
- options.onValidationError?.(errorContext),
895
- options.onRequestError?.(errorContext),
896
- options.onError?.(errorContext)
897
- ], hookInfo) ?? await handleRetryOrGetErrorResult();
895
+ if (isValidationErrorInstance(error)) return await executeHooksInCatchBlock([options.onValidationError?.(errorContext), options.onError?.(errorContext)], hookInfo) ?? await handleRetryOrGetErrorResult();
898
896
  if (isHTTPErrorInstance(error)) return await executeHooksInCatchBlock([
899
897
  options.onResponseError?.(errorContext),
900
898
  options.onError?.(errorContext),