@zayne-labs/callapi 1.11.5 → 1.11.7

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.
@@ -1,8 +1,8 @@
1
- import { AnyFunction, AnyString, ApplyStrictConfig, ApplyURLBasedConfig, BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaAndConfig, BaseCallApiSchemaRoutes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, CallApiSuccessOrErrorVariant, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCallApiResult, 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, ResultModeMap, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable, fallBackRouteSchemaKey } from "./common-NVdD93VW.js";
1
+ import { $ as ValidationError, A as ResponseStreamContext, B as PossibleValidationError, C as Hooks, D as RequestStreamContext, E as RequestContext, F as GetCallApiResult, G as DefaultDataType, H as ResponseTypeUnion, I as GetResponseType, J as CallApiPlugin, K as DefaultPluginArray, L as PossibleHTTPError, M as CallApiResultErrorVariant, N as CallApiResultSuccessVariant, O as ResponseContext, P as CallApiSuccessOrErrorVariant, Q as HTTPError, R as PossibleJavaScriptError, S as ErrorContext, T as PluginExtraOptions, U as ResultModeMap, V as ResponseTypeMap, W as ResultModeUnion, X as PluginHooksWithMoreOptions, Y as PluginHooks, Z as PluginSetupContext, _ as InferParamsFromRoute, a as CallApiExtraOptionsForHooks, at as fallBackRouteSchemaKey, b as RetryOptions, c as CallApiRequestOptionsForHooks, d as GetBaseSchemaRoutes, et as BaseCallApiSchemaAndConfig, f as ApplyStrictConfig, g as InferInitURL, h as GetCurrentRouteSchemaKey, i as CallApiExtraOptions, it as InferSchemaOutputResult, j as SuccessContext, k as ResponseErrorContext, l as CallApiResult, m as GetCurrentRouteSchema, n as BaseCallApiExtraOptions, nt as CallApiSchema, o as CallApiParameters, ot as URLOptions, p as ApplyURLBasedConfig, q as DefaultThrowOnError, r as CallApiConfig, rt as CallApiSchemaConfig, s as CallApiRequestOptions, st as AnyString, t as BaseCallApiConfig, tt as BaseCallApiSchemaRoutes, u as GetBaseSchemaConfig, v as Register, w as HooksOrHooksArray, x as DedupeOptions, y as ThrowOnErrorUnion, z as PossibleJavaScriptOrValidationError } from "./common-BsDcf2vu.js";
2
2
 
3
3
  //#region src/createFetchClient.d.ts
4
4
 
5
- declare const createFetchClient: <TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, const TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, const TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseSchemaConfig extends CallApiSchemaConfig = NonNullable<Writeable<TBaseSchemaAndConfig["config"], "deep">>, TComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = Writeable<TBaseSchemaAndConfig["routes"], "deep">>(initBaseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBaseSchemaAndConfig, TBasePluginArray>) => <TData = TBaseData, TErrorData = TBaseErrorData, TResultMode extends ResultModeUnion = TBaseResultMode, TThrowOnError extends ThrowOnErrorUnion = TBaseThrowOnError, TResponseType extends ResponseTypeUnion = TBaseResponseType, const TSchemaConfig extends CallApiSchemaConfig = TComputedBaseSchemaConfig, TInitURL extends InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig> = InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<TComputedBaseSchemaRoutes, TCurrentRouteSchemaKey>, const TPluginArray extends CallApiPlugin[] = TBasePluginArray, TComputedResult = CallApiResult<InferSchemaOutputResult<TSchema["data"], TData>, InferSchemaOutputResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>>(initURL: TInitURL, config?: CallApiConfig<InferSchemaOutputResult<TSchema["data"], GetResponseType<TData, TResponseType>>, InferSchemaOutputResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType>>, TResultMode, TThrowOnError, TResponseType, TComputedBaseSchemaRoutes, TSchema, TComputedBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray> | undefined) => Promise<TComputedResult>;
5
+ declare const createFetchClient: <TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, const TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, const TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseSchemaConfig extends CallApiSchemaConfig = GetBaseSchemaConfig<TBaseSchemaAndConfig>, TComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = GetBaseSchemaRoutes<TBaseSchemaAndConfig>>(initBaseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBaseSchemaAndConfig, TBasePluginArray>) => <TData = TBaseData, TErrorData = TBaseErrorData, TResultMode extends ResultModeUnion = TBaseResultMode, TThrowOnError extends ThrowOnErrorUnion = TBaseThrowOnError, TResponseType extends ResponseTypeUnion = TBaseResponseType, const TSchemaConfig extends CallApiSchemaConfig = TComputedBaseSchemaConfig, TInitURL extends InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig> = InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<TComputedBaseSchemaRoutes, TCurrentRouteSchemaKey>, const TPluginArray extends CallApiPlugin[] = TBasePluginArray, TComputedResult = CallApiResult<InferSchemaOutputResult<TSchema["data"], TData>, InferSchemaOutputResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>>(initURL: TInitURL, initConfig?: CallApiConfig<InferSchemaOutputResult<TSchema["data"], GetResponseType<TData, TResponseType>>, InferSchemaOutputResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType>>, TResultMode, TThrowOnError, TResponseType, TComputedBaseSchemaRoutes, TSchema, TComputedBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>) => Promise<TComputedResult>;
6
6
  declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = boolean, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, const TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, AnyString | "@delete/" | "@get/" | "@patch/" | "@post/" | "@put/">> = ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, AnyString | "@delete/" | "@get/" | "@patch/" | "@post/" | "@put/">>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<{
7
7
  [x: AnyString]: CallApiSchema | undefined;
8
8
  "@delete/"?: CallApiSchema | undefined;
@@ -10,21 +10,14 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
10
10
  "@patch/"?: CallApiSchema | undefined;
11
11
  "@post/"?: CallApiSchema | undefined;
12
12
  "@put/"?: CallApiSchema | undefined;
13
- }, TCurrentRouteSchemaKey, Omit<CallApiSchema | undefined, keyof {
13
+ }, TCurrentRouteSchemaKey, CallApiSchema | undefined, {
14
14
  [x: AnyString]: CallApiSchema | undefined;
15
15
  "@delete/"?: CallApiSchema | undefined;
16
16
  "@get/"?: CallApiSchema | undefined;
17
17
  "@patch/"?: CallApiSchema | undefined;
18
18
  "@post/"?: CallApiSchema | undefined;
19
19
  "@put/"?: CallApiSchema | undefined;
20
- }[TCurrentRouteSchemaKey]> & {
21
- [x: AnyString]: CallApiSchema | undefined;
22
- "@delete/"?: CallApiSchema | undefined;
23
- "@get/"?: CallApiSchema | undefined;
24
- "@patch/"?: CallApiSchema | undefined;
25
- "@post/"?: CallApiSchema | undefined;
26
- "@put/"?: CallApiSchema | undefined;
27
- }[TCurrentRouteSchemaKey], NonNullable<Writeable<Omit<CallApiSchema | undefined, keyof {
20
+ }[TCurrentRouteSchemaKey], NonNullable<Omit<CallApiSchema | undefined, keyof {
28
21
  [x: AnyString]: CallApiSchema | undefined;
29
22
  "@delete/"?: CallApiSchema | undefined;
30
23
  "@get/"?: CallApiSchema | undefined;
@@ -38,29 +31,18 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
38
31
  "@patch/"?: CallApiSchema | undefined;
39
32
  "@post/"?: CallApiSchema | undefined;
40
33
  "@put/"?: CallApiSchema | undefined;
41
- }[TCurrentRouteSchemaKey], "deep">>>, const TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedResult = GetCallApiResult<InferSchemaOutputResult<TSchema["data"], TData>, InferSchemaOutputResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType, {
34
+ }[TCurrentRouteSchemaKey]>>, const TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedResult = GetCallApiResult<InferSchemaOutputResult<TSchema["data"], TData>, InferSchemaOutputResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType, {
42
35
  all: CallApiResultSuccessVariant<GetResponseType<InferSchemaOutputResult<TSchema["data"], TData>, TResponseType, ResponseTypeMap<InferSchemaOutputResult<TSchema["data"], TData>>>>;
43
36
  onlyData: NoInfer<GetResponseType<InferSchemaOutputResult<TSchema["data"], TData>, TResponseType, ResponseTypeMap<InferSchemaOutputResult<TSchema["data"], TData>>>>;
44
37
  onlyResponse: Response;
45
- }, ResultModeMap<InferSchemaOutputResult<TSchema["data"], TData>, InferSchemaOutputResult<TSchema["errorData"], TErrorData>, TResponseType, TThrowOnError>>>(initURL: TInitURL, config?: CallApiConfig<InferSchemaOutputResult<TSchema["data"], GetResponseType<TData, TResponseType, ResponseTypeMap<TData>>>, InferSchemaOutputResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType, ResponseTypeMap<TErrorData>>>, TResultMode, TThrowOnError, TResponseType, {
38
+ }, ResultModeMap<InferSchemaOutputResult<TSchema["data"], TData>, InferSchemaOutputResult<TSchema["errorData"], TErrorData>, TResponseType, TThrowOnError>>>(initURL: TInitURL, initConfig?: CallApiConfig<InferSchemaOutputResult<TSchema["data"], GetResponseType<TData, TResponseType, ResponseTypeMap<TData>>>, InferSchemaOutputResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType, ResponseTypeMap<TErrorData>>>, TResultMode, TThrowOnError, TResponseType, {
46
39
  [x: AnyString]: CallApiSchema | undefined;
47
40
  "@delete/"?: CallApiSchema | undefined;
48
41
  "@get/"?: CallApiSchema | undefined;
49
42
  "@patch/"?: CallApiSchema | undefined;
50
43
  "@post/"?: CallApiSchema | undefined;
51
44
  "@put/"?: CallApiSchema | undefined;
52
- }, TSchema, CallApiSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, DefaultPluginArray, TPluginArray> | undefined) => Promise<TComputedResult>;
53
- //#endregion
54
- //#region src/defineHelpers.d.ts
55
- declare const defineSchema: <const TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, const TSchemaConfig extends CallApiSchemaConfig>(routes: TBaseSchemaRoutes, config?: TSchemaConfig) => {
56
- config: Writeable<TSchemaConfig, "deep"> & {};
57
- routes: Writeable<TBaseSchemaRoutes, "deep">;
58
- };
59
- declare const defineSchemaConfig: <const TConfig extends CallApiExtraOptions["schemaConfig"]>(config: TConfig) => NonNullable<Writeable<typeof config, "deep">>;
60
- declare const defineSchemaRoutes: <const TBaseSchemaRoutes extends BaseCallApiSchemaRoutes>(routes: TBaseSchemaRoutes) => Writeable<typeof routes, "deep">;
61
- declare const definePlugin: <const TPlugin extends CallApiPlugin | AnyFunction<CallApiPlugin>>(plugin: TPlugin) => Writeable<TPlugin, "deep">;
62
- declare const defineBaseConfig: <const TBaseConfig extends BaseCallApiConfig>(baseConfig: TBaseConfig) => Writeable<typeof baseConfig, "deep">;
63
- declare const defineParameters: <TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, TSchemaConfig> = InferInitURL<BaseCallApiSchemaRoutes, TSchemaConfig>, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray>(...parameters: CallApiParameters<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>) => CallApiParameters<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>;
45
+ }, TSchema, CallApiSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, DefaultPluginArray, TPluginArray>) => Promise<TComputedResult>;
64
46
  //#endregion
65
- export { type BaseCallApiConfig, type BaseCallApiExtraOptions, type BaseCallApiSchemaRoutes, type CallApiConfig, type CallApiExtraOptions, type CallApiExtraOptionsForHooks, type CallApiParameters, type CallApiPlugin, type CallApiRequestOptions, type CallApiRequestOptionsForHooks, type CallApiResult, type CallApiResultErrorVariant, type CallApiResultSuccessVariant, type CallApiSchema, type CallApiSchemaConfig, type CallApiSuccessOrErrorVariant, type DedupeOptions, type ErrorContext, HTTPError, type Hooks, type HooksOrHooksArray, type InferParamsFromRoute, type InferSchemaOutputResult, type PluginExtraOptions, type PluginHooks, type PluginHooksWithMoreOptions, type PluginSetupContext, type PossibleHTTPError, type PossibleJavaScriptError, type PossibleJavaScriptOrValidationError, type PossibleValidationError, type Register, type RequestContext, type RequestStreamContext, type ResponseContext, type ResponseErrorContext, type ResponseStreamContext, type ResponseTypeUnion, type ResultModeUnion, type RetryOptions, type SuccessContext, type URLOptions, ValidationError, callApi, createFetchClient, defineBaseConfig, defineParameters, definePlugin, defineSchema, defineSchemaConfig, defineSchemaRoutes, fallBackRouteSchemaKey };
47
+ export { type BaseCallApiConfig, type BaseCallApiExtraOptions, type BaseCallApiSchemaRoutes, type CallApiConfig, type CallApiExtraOptions, type CallApiExtraOptionsForHooks, type CallApiParameters, type CallApiPlugin, type CallApiRequestOptions, type CallApiRequestOptionsForHooks, type CallApiResult, type CallApiResultErrorVariant, type CallApiResultSuccessVariant, type CallApiSchema, type CallApiSchemaConfig, type CallApiSuccessOrErrorVariant, type DedupeOptions, type ErrorContext, HTTPError, type Hooks, type HooksOrHooksArray, type InferParamsFromRoute, type InferSchemaOutputResult, type PluginExtraOptions, type PluginHooks, type PluginHooksWithMoreOptions, type PluginSetupContext, type PossibleHTTPError, type PossibleJavaScriptError, type PossibleJavaScriptOrValidationError, type PossibleValidationError, type Register, type RequestContext, type RequestStreamContext, type ResponseContext, type ResponseErrorContext, type ResponseStreamContext, type ResponseTypeUnion, type ResultModeUnion, type RetryOptions, type SuccessContext, type URLOptions, ValidationError, callApi, createFetchClient, fallBackRouteSchemaKey };
66
48
  //# sourceMappingURL=index.d.ts.map
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { HTTPError, ValidationError, createCombinedSignal, createTimeoutSignal, deterministicHashFn, extraOptionDefaults, fallBackRouteSchemaKey, getBody, getCurrentRouteSchemaKeyAndMainInitURL, getFetchImpl, getFullAndNormalizedURL, getHeaders, getMethod, handleConfigValidation, handleSchemaValidation, isArray, isBoolean, isFunction, isHTTPErrorInstance, isObject, isPlainObject, isReadableStream, isString, isValidationErrorInstance, splitBaseConfig, splitConfig, waitFor } from "./common-CfCB_X1k.js";
1
+ import { C as defineEnum, S as requestOptionDefaults, _ as isReadableStream, b as isValidJsonString, c as HTTPError, d as isBoolean, f as isFunction, g as isQueryString, h as isPromise, i as isHTTPErrorInstance, l as ValidationError, m as isPlainObject, n as toQueryString, p as isObject, s as isValidationErrorInstance, u as isArray, v as isSerializable, x as extraOptionDefaults, y as isString } from "./body-BVMFJoeo.js";
2
2
 
3
3
  //#region src/result.ts
4
4
  const getResponseType = (response, parser) => ({
@@ -262,6 +262,427 @@ const toStreamableResponse = async (context) => {
262
262
  return new Response(stream, response);
263
263
  };
264
264
 
265
+ //#endregion
266
+ //#region src/auth.ts
267
+ const resolveAuthValue = (value) => isFunction(value) ? value() : value;
268
+ const getAuthHeader = async (auth) => {
269
+ if (auth === void 0) return;
270
+ if (isPromise(auth) || isFunction(auth) || !isObject(auth)) {
271
+ const authValue = await resolveAuthValue(auth);
272
+ if (authValue === void 0) return;
273
+ return { Authorization: `Bearer ${authValue}` };
274
+ }
275
+ switch (auth.type) {
276
+ case "Basic": {
277
+ const [username, password] = await Promise.all([resolveAuthValue(auth.username), resolveAuthValue(auth.password)]);
278
+ if (username === void 0 || password === void 0) return;
279
+ return { Authorization: `Basic ${globalThis.btoa(`${username}:${password}`)}` };
280
+ }
281
+ case "Custom": {
282
+ const [prefix, value] = await Promise.all([resolveAuthValue(auth.prefix), resolveAuthValue(auth.value)]);
283
+ if (value === void 0) return;
284
+ return { Authorization: `${prefix} ${value}` };
285
+ }
286
+ default: {
287
+ const [bearer, token] = await Promise.all([resolveAuthValue(auth.bearer), resolveAuthValue(auth.token)]);
288
+ if (bearer !== void 0) return { Authorization: `Bearer ${bearer}` };
289
+ if (token === void 0) return;
290
+ return { Authorization: `Token ${token}` };
291
+ }
292
+ }
293
+ };
294
+
295
+ //#endregion
296
+ //#region src/constants/common.ts
297
+ const fetchSpecificKeys = defineEnum([
298
+ "body",
299
+ "integrity",
300
+ "duplex",
301
+ "method",
302
+ "headers",
303
+ "signal",
304
+ "cache",
305
+ "redirect",
306
+ "window",
307
+ "credentials",
308
+ "keepalive",
309
+ "referrer",
310
+ "priority",
311
+ "mode",
312
+ "referrerPolicy"
313
+ ]);
314
+
315
+ //#endregion
316
+ //#region src/validation.ts
317
+ const handleValidatorFunction = async (validator, inputData) => {
318
+ try {
319
+ return {
320
+ issues: void 0,
321
+ value: await validator(inputData)
322
+ };
323
+ } catch (error) {
324
+ return {
325
+ issues: toArray(error),
326
+ value: void 0
327
+ };
328
+ }
329
+ };
330
+ const standardSchemaParser = async (fullSchema, schemaName, inputData, response) => {
331
+ const schema = fullSchema?.[schemaName];
332
+ if (!schema) return inputData;
333
+ const result = isFunction(schema) ? await handleValidatorFunction(schema, inputData) : await schema["~standard"].validate(inputData);
334
+ if (result.issues) throw new ValidationError({
335
+ issueCause: schemaName,
336
+ issues: result.issues,
337
+ response: response ?? null
338
+ });
339
+ return result.value;
340
+ };
341
+ const routeKeyMethods = defineEnum([
342
+ "delete",
343
+ "get",
344
+ "patch",
345
+ "post",
346
+ "put"
347
+ ]);
348
+ const handleSchemaValidation = async (fullSchema, schemaName, validationOptions) => {
349
+ const { inputValue, response, schemaConfig } = validationOptions;
350
+ if (schemaConfig?.disableRuntimeValidation) return inputValue;
351
+ return await standardSchemaParser(fullSchema, schemaName, inputValue, response);
352
+ };
353
+ const extraOptionsToBeValidated = [
354
+ "meta",
355
+ "params",
356
+ "query"
357
+ ];
358
+ const handleExtraOptionsValidation = async (validationOptions) => {
359
+ const { options, schema, schemaConfig } = validationOptions;
360
+ const validationResultArray = await Promise.all(extraOptionsToBeValidated.map((schemaName) => handleSchemaValidation(schema, schemaName, {
361
+ inputValue: options[schemaName],
362
+ schemaConfig
363
+ })));
364
+ const validatedResultObject = {};
365
+ for (const [index, schemaName] of extraOptionsToBeValidated.entries()) {
366
+ const validationResult = validationResultArray[index];
367
+ if (validationResult === void 0) continue;
368
+ validatedResultObject[schemaName] = validationResult;
369
+ }
370
+ return validatedResultObject;
371
+ };
372
+ const requestOptionsToBeValidated = [
373
+ "body",
374
+ "headers",
375
+ "method"
376
+ ];
377
+ const handleRequestOptionsValidation = async (validationOptions) => {
378
+ const { requestOptions, schema, schemaConfig } = validationOptions;
379
+ const validationResultArray = await Promise.all(requestOptionsToBeValidated.map((schemaName) => handleSchemaValidation(schema, schemaName, {
380
+ inputValue: requestOptions[schemaName],
381
+ schemaConfig
382
+ })));
383
+ const validatedResultObject = {};
384
+ for (const [index, propertyKey] of requestOptionsToBeValidated.entries()) {
385
+ const validationResult = validationResultArray[index];
386
+ if (validationResult === void 0) continue;
387
+ validatedResultObject[propertyKey] = validationResult;
388
+ }
389
+ return validatedResultObject;
390
+ };
391
+ const handleConfigValidation = async (validationOptions) => {
392
+ const { baseExtraOptions, currentRouteSchemaKey, extraOptions, options, requestOptions } = validationOptions;
393
+ const { currentRouteSchema, resolvedSchema } = getResolvedSchema({
394
+ baseExtraOptions,
395
+ currentRouteSchemaKey,
396
+ extraOptions
397
+ });
398
+ const resolvedSchemaConfig = getResolvedSchemaConfig({
399
+ baseExtraOptions,
400
+ extraOptions
401
+ });
402
+ if (resolvedSchemaConfig?.strict === true && !currentRouteSchema) throw new ValidationError({
403
+ issueCause: "schemaConfig-(strict)",
404
+ issues: [{ message: `Strict Mode - No schema found for route '${currentRouteSchemaKey}' ` }],
405
+ response: null
406
+ });
407
+ if (resolvedSchemaConfig?.disableRuntimeValidation) return {
408
+ extraOptionsValidationResult: null,
409
+ requestOptionsValidationResult: null,
410
+ resolvedSchema,
411
+ resolvedSchemaConfig,
412
+ shouldApplySchemaOutput: false
413
+ };
414
+ const [extraOptionsValidationResult, requestOptionsValidationResult] = await Promise.all([handleExtraOptionsValidation({
415
+ options,
416
+ schema: resolvedSchema,
417
+ schemaConfig: resolvedSchemaConfig
418
+ }), handleRequestOptionsValidation({
419
+ requestOptions,
420
+ schema: resolvedSchema,
421
+ schemaConfig: resolvedSchemaConfig
422
+ })]);
423
+ return {
424
+ extraOptionsValidationResult,
425
+ requestOptionsValidationResult,
426
+ resolvedSchema,
427
+ resolvedSchemaConfig,
428
+ shouldApplySchemaOutput: (Boolean(extraOptionsValidationResult) || Boolean(requestOptionsValidationResult)) && !resolvedSchemaConfig?.disableValidationOutputApplication
429
+ };
430
+ };
431
+ const fallBackRouteSchemaKey = ".";
432
+ const getResolvedSchema = (context) => {
433
+ const { baseExtraOptions, currentRouteSchemaKey, extraOptions } = context;
434
+ const fallbackRouteSchema = baseExtraOptions.schema?.routes[fallBackRouteSchemaKey];
435
+ const currentRouteSchema = baseExtraOptions.schema?.routes[currentRouteSchemaKey];
436
+ const resolvedRouteSchema = {
437
+ ...fallbackRouteSchema,
438
+ ...currentRouteSchema
439
+ };
440
+ return {
441
+ currentRouteSchema,
442
+ resolvedSchema: isFunction(extraOptions.schema) ? extraOptions.schema({
443
+ baseSchemaRoutes: baseExtraOptions.schema?.routes ?? {},
444
+ currentRouteSchema: resolvedRouteSchema ?? {}
445
+ }) : extraOptions.schema ?? resolvedRouteSchema
446
+ };
447
+ };
448
+ const getResolvedSchemaConfig = (context) => {
449
+ const { baseExtraOptions, extraOptions } = context;
450
+ return isFunction(extraOptions.schemaConfig) ? extraOptions.schemaConfig({ baseSchemaConfig: baseExtraOptions.schema?.config ?? {} }) : extraOptions.schemaConfig ?? baseExtraOptions.schema?.config;
451
+ };
452
+ const getCurrentRouteSchemaKeyAndMainInitURL = (context) => {
453
+ const { baseExtraOptions, extraOptions, initURL } = context;
454
+ const schemaConfig = getResolvedSchemaConfig({
455
+ baseExtraOptions,
456
+ extraOptions
457
+ });
458
+ let currentRouteSchemaKey = initURL;
459
+ let mainInitURL = initURL;
460
+ if (schemaConfig?.prefix && currentRouteSchemaKey.startsWith(schemaConfig.prefix)) {
461
+ currentRouteSchemaKey = currentRouteSchemaKey.replace(schemaConfig.prefix, "");
462
+ mainInitURL = mainInitURL.replace(schemaConfig.prefix, schemaConfig.baseURL ?? "");
463
+ }
464
+ if (schemaConfig?.baseURL && currentRouteSchemaKey.startsWith(schemaConfig.baseURL)) currentRouteSchemaKey = currentRouteSchemaKey.replace(schemaConfig.baseURL, "");
465
+ return {
466
+ currentRouteSchemaKey,
467
+ mainInitURL
468
+ };
469
+ };
470
+
471
+ //#endregion
472
+ //#region src/url.ts
473
+ const slash = "/";
474
+ const colon = ":";
475
+ const openBrace = "{";
476
+ const closeBrace = "}";
477
+ const mergeUrlWithParams = (url, params) => {
478
+ if (!params) return url;
479
+ let newUrl = url;
480
+ if (isArray(params)) {
481
+ const matchedParamsArray = newUrl.split(slash).filter((part) => part.startsWith(colon) || part.startsWith(openBrace) && part.endsWith(closeBrace));
482
+ for (const [paramIndex, matchedParam] of matchedParamsArray.entries()) {
483
+ const stringParamValue = String(params[paramIndex]);
484
+ newUrl = newUrl.replace(matchedParam, stringParamValue);
485
+ }
486
+ return newUrl;
487
+ }
488
+ for (const [paramKey, paramValue] of Object.entries(params)) {
489
+ const colonPattern = `${colon}${paramKey}`;
490
+ const bracePattern = `${openBrace}${paramKey}${closeBrace}`;
491
+ const stringValue = String(paramValue);
492
+ newUrl = newUrl.replace(colonPattern, stringValue);
493
+ newUrl = newUrl.replace(bracePattern, stringValue);
494
+ }
495
+ return newUrl;
496
+ };
497
+ const questionMark = "?";
498
+ const ampersand = "&";
499
+ const mergeUrlWithQuery = (url, query) => {
500
+ if (!query) return url;
501
+ const queryString = toQueryString(query);
502
+ if (queryString?.length === 0) return url;
503
+ if (url.endsWith(questionMark)) return `${url}${queryString}`;
504
+ if (url.includes(questionMark)) return `${url}${ampersand}${queryString}`;
505
+ return `${url}${questionMark}${queryString}`;
506
+ };
507
+ /**
508
+ * @description Extracts the HTTP method from method-prefixed route patterns.
509
+ *
510
+ * Analyzes URLs that start with method modifiers (e.g., "@get/", "@post/") and extracts
511
+ * the HTTP method for use in API requests. This enables method specification directly
512
+ * in route definitions.
513
+ *
514
+ * @param initURL - The URL string to analyze for method modifiers
515
+ * @returns The extracted HTTP method (lowercase) if found, otherwise undefined
516
+ *
517
+ * @example
518
+ * ```typescript
519
+ * // Method extraction from prefixed routes
520
+ * extractMethodFromURL("@get/users"); // Returns: "get"
521
+ * extractMethodFromURL("@post/users"); // Returns: "post"
522
+ * extractMethodFromURL("@put/users/:id"); // Returns: "put"
523
+ * extractMethodFromURL("@delete/users/:id"); // Returns: "delete"
524
+ * extractMethodFromURL("@patch/users/:id"); // Returns: "patch"
525
+ *
526
+ * // No method modifier
527
+ * extractMethodFromURL("/users"); // Returns: undefined
528
+ * extractMethodFromURL("users"); // Returns: undefined
529
+ *
530
+ * // Invalid or unsupported methods
531
+ * extractMethodFromURL("@invalid/users"); // Returns: undefined
532
+ * extractMethodFromURL("@/users"); // Returns: undefined
533
+ *
534
+ * // Edge cases
535
+ * extractMethodFromURL(undefined); // Returns: undefined
536
+ * extractMethodFromURL(""); // Returns: undefined
537
+ * ```
538
+ */
539
+ const extractMethodFromURL = (initURL) => {
540
+ if (!initURL?.startsWith("@")) return;
541
+ const method = initURL.split("@")[1]?.split("/")[0];
542
+ if (!method || !routeKeyMethods.includes(method)) return;
543
+ return method;
544
+ };
545
+ const normalizeURL = (initURL) => {
546
+ const methodFromURL = extractMethodFromURL(initURL);
547
+ if (!methodFromURL) return initURL;
548
+ return initURL.replace(`@${methodFromURL}/`, "/");
549
+ };
550
+ const getFullAndNormalizedURL = (options) => {
551
+ const { baseURL, initURL, params, query } = options;
552
+ const normalizedInitURL = normalizeURL(initURL);
553
+ const urlWithMergedQueryAndParams = mergeUrlWithQuery(mergeUrlWithParams(normalizedInitURL, params), query);
554
+ return {
555
+ fullURL: !urlWithMergedQueryAndParams.startsWith("http") && baseURL ? `${baseURL}${urlWithMergedQueryAndParams}` : urlWithMergedQueryAndParams,
556
+ normalizedInitURL
557
+ };
558
+ };
559
+
560
+ //#endregion
561
+ //#region src/utils/polyfills/combinedSignal.ts
562
+ const createCombinedSignalPolyfill = (signals) => {
563
+ const controller = new AbortController();
564
+ const handleAbort = (actualSignal) => {
565
+ if (controller.signal.aborted) return;
566
+ controller.abort(actualSignal.reason);
567
+ };
568
+ for (const actualSignal of signals) {
569
+ if (actualSignal.aborted) {
570
+ handleAbort(actualSignal);
571
+ break;
572
+ }
573
+ actualSignal.addEventListener("abort", () => handleAbort(actualSignal), { signal: controller.signal });
574
+ }
575
+ return controller.signal;
576
+ };
577
+
578
+ //#endregion
579
+ //#region src/utils/polyfills/timeoutSignal.ts
580
+ const createTimeoutSignalPolyfill = (milliseconds) => {
581
+ const controller = new AbortController();
582
+ const reason = new DOMException("Request timed out", "TimeoutError");
583
+ const timeout = setTimeout(() => controller.abort(reason), milliseconds);
584
+ controller.signal.addEventListener("abort", () => clearTimeout(timeout));
585
+ return controller.signal;
586
+ };
587
+
588
+ //#endregion
589
+ //#region src/utils/common.ts
590
+ const omitKeys = (initialObject, keysToOmit) => {
591
+ const updatedObject = {};
592
+ const keysToOmitSet = new Set(keysToOmit);
593
+ for (const [key, value] of Object.entries(initialObject)) if (!keysToOmitSet.has(key)) updatedObject[key] = value;
594
+ return updatedObject;
595
+ };
596
+ const pickKeys = (initialObject, keysToPick) => {
597
+ const updatedObject = {};
598
+ const keysToPickSet = new Set(keysToPick);
599
+ for (const [key, value] of Object.entries(initialObject)) if (keysToPickSet.has(key)) updatedObject[key] = value;
600
+ return updatedObject;
601
+ };
602
+ const splitBaseConfig = (baseConfig) => [pickKeys(baseConfig, fetchSpecificKeys), omitKeys(baseConfig, fetchSpecificKeys)];
603
+ const splitConfig = (config) => [pickKeys(config, fetchSpecificKeys), omitKeys(config, fetchSpecificKeys)];
604
+ const objectifyHeaders = (headers) => {
605
+ if (!headers || isPlainObject(headers)) return headers;
606
+ return Object.fromEntries(headers);
607
+ };
608
+ const getHeaders = async (options) => {
609
+ const { auth, body, headers } = options;
610
+ if (!(Boolean(headers) || Boolean(body) || Boolean(auth))) return;
611
+ const headersObject = {
612
+ ...await getAuthHeader(auth),
613
+ ...objectifyHeaders(headers)
614
+ };
615
+ if (isQueryString(body)) {
616
+ headersObject["Content-Type"] = "application/x-www-form-urlencoded";
617
+ return headersObject;
618
+ }
619
+ if (isSerializable(body) || isValidJsonString(body)) {
620
+ headersObject["Content-Type"] = "application/json";
621
+ headersObject.Accept = "application/json";
622
+ }
623
+ return headersObject;
624
+ };
625
+ const getMethod = (ctx) => {
626
+ const { initURL, method } = ctx;
627
+ return method?.toUpperCase() ?? extractMethodFromURL(initURL)?.toUpperCase() ?? requestOptionDefaults.method;
628
+ };
629
+ const getBody = (options) => {
630
+ const { body, bodySerializer } = options;
631
+ if (isSerializable(body)) return (bodySerializer ?? extraOptionDefaults.bodySerializer)(body);
632
+ return body;
633
+ };
634
+ const getInitFetchImpl = (customFetchImpl) => {
635
+ if (customFetchImpl) return customFetchImpl;
636
+ if (typeof globalThis !== "undefined" && isFunction(globalThis.fetch)) return globalThis.fetch;
637
+ throw new Error("No fetch implementation found");
638
+ };
639
+ const getFetchImpl = (context) => {
640
+ const { customFetchImpl, fetchMiddleware, requestContext } = context;
641
+ const initFetchImpl = getInitFetchImpl(customFetchImpl);
642
+ return fetchMiddleware ? fetchMiddleware({
643
+ ...requestContext,
644
+ fetchImpl: initFetchImpl
645
+ }) : initFetchImpl;
646
+ };
647
+ const PromiseWithResolvers = () => {
648
+ let reject;
649
+ let resolve;
650
+ return {
651
+ promise: new Promise((res, rej) => {
652
+ resolve = res;
653
+ reject = rej;
654
+ }),
655
+ reject,
656
+ resolve
657
+ };
658
+ };
659
+ const waitFor = (delay) => {
660
+ if (delay === 0) return;
661
+ const { promise, resolve } = PromiseWithResolvers();
662
+ setTimeout(resolve, delay);
663
+ return promise;
664
+ };
665
+ const createCombinedSignal = (...signals) => {
666
+ const cleanedSignals = signals.filter((signal) => signal != null);
667
+ if (!("any" in AbortSignal)) return createCombinedSignalPolyfill(cleanedSignals);
668
+ return AbortSignal.any(cleanedSignals);
669
+ };
670
+ const createTimeoutSignal = (milliseconds) => {
671
+ if (milliseconds == null) return null;
672
+ if (!("timeout" in AbortSignal)) return createTimeoutSignalPolyfill(milliseconds);
673
+ return AbortSignal.timeout(milliseconds);
674
+ };
675
+ const deterministicHashFn = (value) => {
676
+ return JSON.stringify(value, (_, val) => {
677
+ if (!isPlainObject(val)) return val;
678
+ const sortedKeys = Object.keys(val).toSorted();
679
+ const result = {};
680
+ for (const key of sortedKeys) result[key] = val[key];
681
+ return result;
682
+ });
683
+ };
684
+ const toArray = (value) => isArray(value) ? value : [value];
685
+
265
686
  //#endregion
266
687
  //#region src/dedupe.ts
267
688
  const createDedupeStrategy = async (context) => {
@@ -272,16 +693,16 @@ const createDedupeStrategy = async (context) => {
272
693
  if (!(resolvedDedupeStrategy === "cancel" || resolvedDedupeStrategy === "defer")) return null;
273
694
  const dedupeKey$1 = globalOptions.dedupeKey ?? globalOptions.dedupe?.key;
274
695
  const resolvedDedupeKey = isFunction(dedupeKey$1) ? dedupeKey$1(context) : dedupeKey$1;
275
- if (resolvedDedupeKey !== void 0) return resolvedDedupeKey;
276
- return `${globalOptions.fullURL}-${deterministicHashFn({
696
+ if (resolvedDedupeKey === void 0) return `${globalOptions.fullURL}-${deterministicHashFn({
277
697
  options: globalOptions,
278
698
  request: globalRequest
279
699
  })}`;
700
+ return resolvedDedupeKey;
280
701
  };
281
702
  const getDedupeCacheScopeKey = () => {
282
- const dedupeCacheScopeKey$1 = globalOptions.dedupeCacheScopeKey ?? globalOptions.dedupe?.cacheScopeKey ?? extraOptionDefaults.dedupeCacheScopeKey;
703
+ const dedupeCacheScopeKey$1 = globalOptions.dedupeCacheScopeKey ?? globalOptions.dedupe?.cacheScopeKey;
283
704
  const resolvedDedupeCacheScopeKey = isFunction(dedupeCacheScopeKey$1) ? dedupeCacheScopeKey$1(context) : dedupeCacheScopeKey$1;
284
- if (resolvedDedupeCacheScopeKey !== void 0) return resolvedDedupeCacheScopeKey;
705
+ if (resolvedDedupeCacheScopeKey === void 0) return extraOptionDefaults.dedupeCacheScopeKey;
285
706
  return resolvedDedupeCacheScopeKey;
286
707
  };
287
708
  const dedupeKey = getDedupeKey();
@@ -552,11 +973,10 @@ const createRetryStrategy = (ctx) => {
552
973
  const $GlobalRequestInfoCache = /* @__PURE__ */ new Map();
553
974
  const createFetchClient = (initBaseConfig = {}) => {
554
975
  const $LocalRequestInfoCache = /* @__PURE__ */ new Map();
555
- const callApi$1 = async (...parameters) => {
556
- const [initURLOrURLObject, initConfig = {}] = parameters;
976
+ const callApi$1 = async (initURL, initConfig = {}) => {
557
977
  const [fetchOptions, extraOptions] = splitConfig(initConfig);
558
978
  const baseConfig = isFunction(initBaseConfig) ? initBaseConfig({
559
- initURL: initURLOrURLObject.toString(),
979
+ initURL: initURL.toString(),
560
980
  options: extraOptions,
561
981
  request: fetchOptions
562
982
  }) : initBaseConfig;
@@ -576,7 +996,7 @@ const createFetchClient = (initBaseConfig = {}) => {
576
996
  const { resolvedCurrentRouteSchemaKey, resolvedHooks, resolvedInitURL, resolvedMiddlewares, resolvedOptions, resolvedRequestOptions } = await initializePlugins({
577
997
  baseConfig,
578
998
  config,
579
- initURL: initURLOrURLObject.toString(),
999
+ initURL: initURL.toString(),
580
1000
  options: mergedExtraOptions,
581
1001
  request: mergedRequestOptions
582
1002
  });
@@ -595,8 +1015,7 @@ const createFetchClient = (initBaseConfig = {}) => {
595
1015
  initURLNormalized: normalizedInitURL
596
1016
  };
597
1017
  const newFetchController = new AbortController();
598
- const timeoutSignal = options.timeout != null ? createTimeoutSignal(options.timeout) : null;
599
- const combinedSignal = createCombinedSignal(resolvedRequestOptions.signal, timeoutSignal, newFetchController.signal);
1018
+ const combinedSignal = createCombinedSignal(createTimeoutSignal(options.timeout), resolvedRequestOptions.signal, newFetchController.signal);
600
1019
  const initMethod = getMethod({
601
1020
  initURL: resolvedInitURL,
602
1021
  method: resolvedRequestOptions.method
@@ -728,7 +1147,7 @@ const createFetchClient = (initBaseConfig = {}) => {
728
1147
  const hookError = await executeHooksInCatchBlock([options.onRetry?.(retryContext)], hookInfo);
729
1148
  if (hookError) return hookError;
730
1149
  await waitFor(getDelay());
731
- return callApi$1(initURLOrURLObject, {
1150
+ return callApi$1(initURL, {
732
1151
  ...config,
733
1152
  "~retryAttemptCount": currentAttemptCount + 1
734
1153
  });
@@ -764,29 +1183,5 @@ const createFetchClient = (initBaseConfig = {}) => {
764
1183
  const callApi = createFetchClient();
765
1184
 
766
1185
  //#endregion
767
- //#region src/defineHelpers.ts
768
- const defineSchema = (routes, config) => {
769
- return {
770
- config: defineSchemaConfig(config),
771
- routes: defineSchemaRoutes(routes)
772
- };
773
- };
774
- const defineSchemaConfig = (config) => {
775
- return config;
776
- };
777
- const defineSchemaRoutes = (routes) => {
778
- return routes;
779
- };
780
- const definePlugin = (plugin) => {
781
- return plugin;
782
- };
783
- const defineBaseConfig = (baseConfig) => {
784
- return baseConfig;
785
- };
786
- const defineParameters = (...parameters) => {
787
- return parameters;
788
- };
789
-
790
- //#endregion
791
- export { HTTPError, ValidationError, callApi, createFetchClient, defineBaseConfig, defineParameters, definePlugin, defineSchema, defineSchemaConfig, defineSchemaRoutes, fallBackRouteSchemaKey };
1186
+ export { HTTPError, ValidationError, callApi, createFetchClient, fallBackRouteSchemaKey };
792
1187
  //# sourceMappingURL=index.js.map