@zayne-labs/callapi 1.12.0 → 1.12.1

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/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { A as GetCallApiContext, B as DedupeOptions, C as CallApiExtraOptions, D as CallApiResultLoose, G as HooksOrHooksArray, H as CallApiRequestOptionsForHooks, J as ResponseContext, K as RequestContext, L as FetchImpl, N as InstanceContext, P as Register, Q as RetryOptions, R as FetchMiddlewareContext, T as CallApiRequestOptions, U as ErrorContext, V as CallApiExtraOptionsForHooks, W as Hooks, X as ResponseStreamContext, Y as ResponseErrorContext, Z as SuccessContext, _ as ResponseTypeType, a as PluginHooks, at as InferInitURL, b as BaseCallApiExtraOptions, c as CallApiResultErrorVariant, ct as URLOptions, dt as BaseSchemaRouteKeyPrefixes, ft as CallApiSchema, gt as InferSchemaOutput, h as PossibleValidationError, ht as InferSchemaInput, i as CallApiPlugin, it as InferAllMainRoutes, j as GetCallApiContextRequired, l as CallApiResultSuccessOrErrorVariant, m as PossibleJavaScriptError, nt as GetCurrentRouteSchemaKey, o as PluginMiddlewares, ot as InferParamsFromRoute, p as PossibleHTTPError, pt as CallApiSchemaConfig, q as RequestStreamContext, rt as InferAllMainRouteKeys, s as PluginSetupContext, t as DefaultCallApiContext, u as CallApiResultSuccessVariant, ut as BaseCallApiSchemaRoutes, v as ResultModeType, w as CallApiParameters, x as CallApiConfig, y as BaseCallApiConfig, z as Middlewares } from "./default-types-BUYTny8V.js";
2
- import { n as createFetchClient, r as createFetchClientWithContext, t as callApi } from "./index-D67wXPS1.js";
3
- export { BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaRoutes, BaseSchemaRouteKeyPrefixes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResultLoose as CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessOrErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultCallApiContext, ErrorContext, FetchImpl, FetchMiddlewareContext, GetCallApiContext, GetCallApiContextRequired, GetCurrentRouteSchemaKey, Hooks, HooksOrHooksArray, InferAllMainRouteKeys, InferAllMainRoutes, InferInitURL, InferParamsFromRoute, InferSchemaInput, InferSchemaOutput, InstanceContext, Middlewares, PluginHooks, PluginMiddlewares, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeType, ResultModeType, RetryOptions, SuccessContext, URLOptions, callApi, createFetchClient, createFetchClientWithContext };
1
+ import { $ as RetryOptions, A as GetCallApiContext, B as DedupeOptions, C as CallApiExtraOptions, D as CallApiResultLoose, G as HooksOrHooksArray, H as CallApiRequestOptionsForHooks, J as ResponseContext, K as RequestContext, L as FetchImpl, N as InstanceContext, P as Register, Q as RefetchOptions, R as FetchMiddlewareContext, T as CallApiRequestOptions, U as ErrorContext, V as CallApiExtraOptionsForHooks, W as Hooks, X as ResponseStreamContext, Y as ResponseErrorContext, Z as SuccessContext, _ as ResponseTypeType, _t as InferSchemaOutput, a as PluginHooks, at as InferAllMainRoutes, b as BaseCallApiExtraOptions, c as CallApiResultErrorVariant, dt as BaseCallApiSchemaRoutes, ft as BaseSchemaRouteKeyPrefixes, gt as InferSchemaInput, h as PossibleValidationError, i as CallApiPlugin, it as InferAllMainRouteKeys, j as GetCallApiContextRequired, l as CallApiResultSuccessOrErrorVariant, lt as URLOptions, m as PossibleJavaScriptError, mt as CallApiSchemaConfig, o as PluginMiddlewares, ot as InferInitURL, p as PossibleHTTPError, pt as CallApiSchema, q as RequestStreamContext, rt as GetCurrentRouteSchemaKey, s as PluginSetupContext, st as InferParamsFromRoute, t as DefaultCallApiContext, u as CallApiResultSuccessVariant, v as ResultModeType, w as CallApiParameters, x as CallApiConfig, y as BaseCallApiConfig, z as Middlewares } from "./default-types-BvfiXmWZ.js";
2
+ import { n as createFetchClient, r as createFetchClientWithContext, t as callApi } from "./index-BHNZSrAS.js";
3
+ export { BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaRoutes, BaseSchemaRouteKeyPrefixes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResultLoose as CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessOrErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultCallApiContext, ErrorContext, FetchImpl, FetchMiddlewareContext, GetCallApiContext, GetCallApiContextRequired, GetCurrentRouteSchemaKey, Hooks, HooksOrHooksArray, InferAllMainRouteKeys, InferAllMainRoutes, InferInitURL, InferParamsFromRoute, InferSchemaInput, InferSchemaOutput, InstanceContext, Middlewares, PluginHooks, PluginMiddlewares, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleValidationError, RefetchOptions, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeType, ResultModeType, RetryOptions, SuccessContext, URLOptions, callApi, createFetchClient, createFetchClientWithContext };
package/dist/index.js CHANGED
@@ -1,6 +1,4 @@
1
- import { C as isArray, E as isFunction, O as isReadableStream, T as isBoolean, _ as handleConfigValidation, a as getBody, c as getMethod, d as splitBaseConfig, f as splitConfig, h as getCurrentRouteSchemaKeyAndMainInitURL, i as createTimeoutSignal, k as isString, l as getResolvedHeaders, m as getFullAndNormalizedURL, o as getFetchImpl, p as waitFor, r as createCombinedSignal, s as getHeaders, t as extraOptionDefaults, u as omitKeys, v as handleSchemaValidation, y as HTTPError } from "./defaults-gB08KAp_.js";
2
- import { a as isValidationErrorInstance, n as isHTTPErrorInstance } from "./guards-D7k3EcVD.js";
3
-
1
+ import { A as getFullAndNormalizedURL, B as isFunction, H as isString, M as handleConfigValidation, N as handleSchemaValidation, P as HTTPError, R as isArray, V as isReadableStream, a as getBody, c as getMethod, d as splitBaseConfig, f as splitConfig, g as isHTTPErrorInstance, i as createTimeoutSignal, j as getCurrentRouteSchemaKeyAndMainInitURL, l as getResolvedHeaders, o as getFetchImpl, p as waitUntil, r as createCombinedSignal, s as getHeaders, t as extraOptionDefaults, u as omitKeys, y as isValidationErrorInstance, z as isBoolean } from "./defaults-B0Zvy-uW.js";
4
2
  //#region src/result.ts
5
3
  const getResponseType = (response, responseParser) => ({
6
4
  arrayBuffer: () => response.arrayBuffer(),
@@ -109,7 +107,6 @@ const getCustomizedErrorResult = (errorResult, customErrorInfo) => {
109
107
  }
110
108
  };
111
109
  };
112
-
113
110
  //#endregion
114
111
  //#region src/hooks.ts
115
112
  const getHookRegistriesAndKeys = () => {
@@ -159,7 +156,6 @@ const executeHooksInCatchBlock = async (hookResultsOrPromise, hookInfo) => {
159
156
  return errorResult;
160
157
  }
161
158
  };
162
-
163
159
  //#endregion
164
160
  //#region src/stream.ts
165
161
  const createProgressEvent = (options) => {
@@ -263,7 +259,6 @@ const toStreamableResponse = (context) => {
263
259
  } });
264
260
  return new Response(stream, response);
265
261
  };
266
-
267
262
  //#endregion
268
263
  //#region src/dedupe.ts
269
264
  const createDedupeStrategy = async (context) => {
@@ -284,8 +279,7 @@ const createDedupeStrategy = async (context) => {
284
279
  if (!dedupeKey) return;
285
280
  const dedupeCacheScope = globalOptions.dedupeCacheScope ?? extraOptionDefaults.dedupeCacheScope;
286
281
  const dedupeCacheScopeKey = getDedupeCacheScopeKey();
287
- if (dedupeCacheScope === "global" && !$GlobalRequestInfoCache.has(dedupeCacheScopeKey)) $GlobalRequestInfoCache.set(dedupeCacheScopeKey, /* @__PURE__ */ new Map());
288
- const $RequestInfoCache = dedupeCacheScope === "global" ? $GlobalRequestInfoCache.get(dedupeCacheScopeKey) : $LocalRequestInfoCache;
282
+ const $RequestInfoCache = dedupeCacheScope === "global" ? $GlobalRequestInfoCache.get(dedupeCacheScopeKey) ?? $GlobalRequestInfoCache.set(dedupeCacheScopeKey, /* @__PURE__ */ new Map()).get(dedupeCacheScopeKey) : $LocalRequestInfoCache;
289
283
  return {
290
284
  delete: () => $RequestInfoCache?.delete(dedupeKey),
291
285
  get: () => $RequestInfoCache?.get(dedupeKey),
@@ -317,7 +311,7 @@ const createDedupeStrategy = async (context) => {
317
311
  * simultaneously (same problem as microtasks). Any non-zero value (even 0.0000000001) forces
318
312
  * proper sequential task queue scheduling, ensuring each request gets its own task slot.
319
313
  */
320
- if (dedupeKey !== null) await waitFor(.001);
314
+ if (dedupeKey !== null) await waitUntil(.01);
321
315
  const prevRequestInfo = $RequestInfoCache?.get();
322
316
  const getAbortErrorMessage = () => {
323
317
  if (globalOptions.dedupeKey) return `Duplicate request detected - Aborted previous request with key '${dedupeKey}'`;
@@ -360,7 +354,6 @@ const createDedupeStrategy = async (context) => {
360
354
  resolvedDedupeStrategy
361
355
  };
362
356
  };
363
-
364
357
  //#endregion
365
358
  //#region src/middlewares.ts
366
359
  const getMiddlewareRegistriesAndKeys = () => {
@@ -389,7 +382,6 @@ const composeMiddlewaresFromArray = (middlewareArray) => {
389
382
  }
390
383
  return composedMiddleware;
391
384
  };
392
-
393
385
  //#endregion
394
386
  //#region src/plugins.ts
395
387
  const getResolvedPlugins = (context) => {
@@ -397,30 +389,16 @@ const getResolvedPlugins = (context) => {
397
389
  return isFunction(options.plugins) ? options.plugins({ basePlugins: baseConfig.plugins ?? [] }) : options.plugins ?? [];
398
390
  };
399
391
  const initializePlugins = async (setupContext) => {
400
- const { baseConfig, config, initURL, options, request } = setupContext;
392
+ const { baseConfig, config, currentRouteSchemaKey, mainInitURL, options, request } = setupContext;
401
393
  const { addMainHooks, addMainMiddlewares, addPluginHooks, addPluginMiddlewares, getResolvedHooks, getResolvedMiddlewares } = setupHooksAndMiddlewares({
402
394
  baseConfig,
403
395
  config,
404
396
  options
405
397
  });
406
- const initURLResult = getCurrentRouteSchemaKeyAndMainInitURL({
407
- baseExtraOptions: baseConfig,
408
- extraOptions: config,
409
- initURL
410
- });
411
- let resolvedCurrentRouteSchemaKey = initURLResult.currentRouteSchemaKey;
412
- let resolvedInitURL = initURLResult.mainInitURL;
398
+ let resolvedCurrentRouteSchemaKey = currentRouteSchemaKey;
399
+ let resolvedInitURL = mainInitURL;
413
400
  const resolvedOptions = options;
414
- const resolvedRequest = Object.assign(request, {
415
- headers: getResolvedHeaders({
416
- baseHeaders: baseConfig.headers,
417
- headers: config.headers
418
- }),
419
- method: getMethod({
420
- initURL: resolvedInitURL,
421
- method: request.method
422
- })
423
- });
401
+ const resolvedRequest = request;
424
402
  const executePluginSetupFn = async (pluginSetup) => {
425
403
  if (!pluginSetup) return;
426
404
  const initResult = await pluginSetup(setupContext);
@@ -527,18 +505,17 @@ const setupHooksAndMiddlewares = (context) => {
527
505
  getResolvedMiddlewares
528
506
  };
529
507
  };
530
-
531
508
  //#endregion
532
509
  //#region src/refetch.ts
533
510
  const createRefetchManager = (ctx) => {
534
511
  const { callApi, callApiArgs, options } = ctx;
535
512
  const currentRefetchCount = options["~refetchCount"] ?? 1;
536
- const refetch = (refetchOptionOverrides) => {
513
+ const refetch = async (refetchOptionOverrides) => {
537
514
  const maxRefetchAttempts = refetchOptionOverrides?.refetchAttempts ?? options.refetchAttempts ?? extraOptionDefaults.refetchAttempts;
538
515
  if (!(currentRefetchCount <= maxRefetchAttempts)) {
539
516
  const message = `Maximum refetch attempts (${maxRefetchAttempts}) exceeded. This prevents infinite loops. Increase 'maxRefetchAttempts' if needed.`;
540
517
  console.error(message);
541
- return Promise.resolve(null);
518
+ return null;
542
519
  }
543
520
  const updatedConfig = {
544
521
  ...callApiArgs.config,
@@ -549,7 +526,6 @@ const createRefetchManager = (ctx) => {
549
526
  };
550
527
  return { refetch };
551
528
  };
552
-
553
529
  //#endregion
554
530
  //#region src/retry.ts
555
531
  const getLinearDelay = (currentAttemptCount, options) => {
@@ -594,7 +570,7 @@ const createRetryManager = (ctx) => {
594
570
  };
595
571
  const hookError = await executeHooksInCatchBlock([options.onRetry?.(retryContext)], hookInfo);
596
572
  if (hookError) return hookError;
597
- await waitFor(getDelay());
573
+ await waitUntil(getDelay());
598
574
  const updatedConfig = {
599
575
  ...callApiArgs.config,
600
576
  "~retryAttemptCount": currentAttemptCount + 1
@@ -608,7 +584,6 @@ const createRetryManager = (ctx) => {
608
584
  };
609
585
  return { handleRetryOrGetErrorResult };
610
586
  };
611
-
612
587
  //#endregion
613
588
  //#region src/createFetchClient.ts
614
589
  const $GlobalRequestInfoCache = /* @__PURE__ */ new Map();
@@ -634,12 +609,27 @@ const createFetchClientWithContext = () => {
634
609
  ...baseFetchOptions,
635
610
  ...!shouldSkipAutoMergeForRequest && fetchOptions
636
611
  };
612
+ const initURLResult = getCurrentRouteSchemaKeyAndMainInitURL({
613
+ baseExtraOptions: baseConfig,
614
+ extraOptions: config,
615
+ initURL: initURL.toString()
616
+ });
637
617
  const { resolvedCurrentRouteSchemaKey, resolvedHooks, resolvedInitURL, resolvedMiddlewares, resolvedOptions, resolvedRequest } = await initializePlugins({
638
618
  baseConfig,
639
619
  config,
640
- initURL: initURL.toString(),
620
+ ...initURLResult,
641
621
  options: mergedExtraOptions,
642
- request: mergedRequestOptions
622
+ request: {
623
+ ...mergedRequestOptions,
624
+ headers: getResolvedHeaders({
625
+ baseHeaders: baseConfig.headers,
626
+ headers: config.headers
627
+ }),
628
+ method: getMethod({
629
+ initURL: initURLResult.initURL,
630
+ method: mergedRequestOptions.method
631
+ })
632
+ }
643
633
  });
644
634
  const { fullURL, normalizedInitURL } = getFullAndNormalizedURL({
645
635
  baseURL: resolvedOptions.baseURL,
@@ -647,7 +637,7 @@ const createFetchClientWithContext = () => {
647
637
  params: resolvedOptions.params,
648
638
  query: resolvedOptions.query
649
639
  });
650
- const options = {
640
+ const initOptions = {
651
641
  ...resolvedOptions,
652
642
  ...resolvedHooks,
653
643
  ...resolvedMiddlewares,
@@ -661,9 +651,12 @@ const createFetchClientWithContext = () => {
661
651
  config,
662
652
  initURL
663
653
  },
664
- options
654
+ options: initOptions
665
655
  });
666
- options.refetch = refetch;
656
+ const options = {
657
+ ...initOptions,
658
+ refetch
659
+ };
667
660
  const newFetchController = new AbortController();
668
661
  const combinedSignal = createCombinedSignal(createTimeoutSignal(options.timeout), resolvedRequest.signal, newFetchController.signal);
669
662
  const request = {
@@ -695,7 +688,7 @@ const createFetchClientWithContext = () => {
695
688
  request
696
689
  });
697
690
  Object.assign(options, extraOptionsValidationResult);
698
- Object.assign(request, {
691
+ const modifiedRequestOptionsValidationResult = {
699
692
  body: getBody({
700
693
  body: requestOptionsValidationResult.body,
701
694
  bodySerializer: options.bodySerializer,
@@ -710,7 +703,8 @@ const createFetchClientWithContext = () => {
710
703
  initURL: resolvedInitURL,
711
704
  method: requestOptionsValidationResult.method
712
705
  })
713
- });
706
+ };
707
+ Object.assign(request, modifiedRequestOptionsValidationResult);
714
708
  const readyRequestContext = {
715
709
  baseConfig,
716
710
  config,
@@ -835,7 +829,7 @@ const createFetchClientWithContext = () => {
835
829
  };
836
830
  const createFetchClient = createFetchClientWithContext();
837
831
  const callApi = createFetchClient();
838
-
839
832
  //#endregion
840
833
  export { callApi, createFetchClient, createFetchClientWithContext };
834
+
841
835
  //# sourceMappingURL=index.js.map