@zayne-labs/callapi-plugins 4.0.31 → 4.0.32

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.
@@ -9,7 +9,7 @@ declare const fallBackRouteSchemaKey = "@default";
9
9
  type FallBackRouteSchemaKey = typeof fallBackRouteSchemaKey;
10
10
  //#endregion
11
11
  //#endregion
12
- //#region ../callapi/dist/index-DP2YeNBA.d.ts
12
+ //#region ../callapi/dist/index-BDKB03qO.d.ts
13
13
  //#region src/types/type-helpers.d.ts
14
14
  type AnyString = string & NonNullable<unknown>;
15
15
  type AnyNumber = number & NonNullable<unknown>;
@@ -102,156 +102,6 @@ type StreamProgressEvent = {
102
102
  transferredBytes: number;
103
103
  };
104
104
  //#endregion
105
- //#region src/middlewares.d.ts
106
- type FetchImpl = UnmaskType<(input: string | Request | URL, init?: RequestInit) => Promise<Response>>;
107
- interface Middlewares<TCallApiContext extends NoInfer<CallApiContext> = DefaultCallApiContext> {
108
- /**
109
- * Wraps the fetch implementation to intercept requests at the network layer.
110
- *
111
- * Takes a context object containing the current fetch function and returns a new fetch function.
112
- * Use it to cache responses, add logging, handle offline mode, or short-circuit requests etc.
113
- * Multiple middleware compose in order: plugins → base config → per-request.
114
- *
115
- * Unlike `customFetchImpl`, middleware can call through to the original fetch.
116
- *
117
- * @example
118
- * ```ts
119
- * // Cache responses
120
- * const cache = new Map();
121
- *
122
- * fetchMiddleware: (ctx) => async (input, init) => {
123
- * const key = input.toString();
124
- * if (cache.has(key)) return cache.get(key).clone();
125
- *
126
- * const response = await ctx.fetchImpl(input, init);
127
- * cache.set(key, response.clone());
128
- * return response;
129
- * }
130
- *
131
- * // Handle offline
132
- * fetchMiddleware: (ctx) => async (input, init) => {
133
- * if (!navigator.onLine) {
134
- * return new Response('{"error": "offline"}', { status: 503 });
135
- * }
136
- * return ctx.fetchImpl(input, init);
137
- * }
138
- * ```
139
- */
140
- fetchMiddleware?: (context: RequestContext<TCallApiContext> & {
141
- fetchImpl: FetchImpl;
142
- }) => FetchImpl;
143
- }
144
- //#endregion
145
- //#region src/types/conditional-types.d.ts
146
- /**
147
- * @description Makes a type partial if the output type of TSchema is not provided or has undefined in the union, otherwise makes it required
148
- */
149
- type MakeSchemaOptionRequiredIfDefined<TSchemaOption extends CallApiSchema[keyof CallApiSchema], TObject> = undefined extends InferSchemaOutput<TSchemaOption, undefined> ? TObject : Required<TObject>;
150
- type ApplyURLBasedConfig<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig["prefix"] extends string ? `${TSchemaConfig["prefix"]}${TSchemaRouteKeys}` : TSchemaConfig["baseURL"] extends string ? `${TSchemaConfig["baseURL"]}${TSchemaRouteKeys}` : TSchemaRouteKeys;
151
- type ApplyStrictConfig<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig["strict"] extends true ? TSchemaRouteKeys :
152
- // eslint-disable-next-line perfectionist/sort-union-types -- Don't sort union types
153
- TSchemaRouteKeys | Exclude<InitURLOrURLObject, RouteKeyMethodsURLUnion>;
154
- type ApplySchemaConfiguration<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, TSchemaRouteKeys>>;
155
- type InferAllRouteKeys<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TSchemaConfig extends CallApiSchemaConfig> = ApplySchemaConfiguration<TSchemaConfig, Exclude<Extract<keyof TBaseSchemaRoutes, string>, FallBackRouteSchemaKey>>;
156
- type InferInitURL<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TSchemaConfig extends CallApiSchemaConfig> = keyof TBaseSchemaRoutes extends never ? InitURLOrURLObject : InferAllRouteKeys<TBaseSchemaRoutes, TSchemaConfig>;
157
- type GetCurrentRouteSchema<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TComputedFallBackRouteSchema = TBaseSchemaRoutes[FallBackRouteSchemaKey], TComputedCurrentRouteSchema = TBaseSchemaRoutes[TCurrentRouteSchemaKey], TComputedRouteSchema extends CallApiSchema = NonNullable<Omit<TComputedFallBackRouteSchema, keyof TComputedCurrentRouteSchema> & TComputedCurrentRouteSchema>> = TComputedRouteSchema extends CallApiSchema ? Writeable<TComputedRouteSchema, "deep"> : CallApiSchema;
158
- type JsonPrimitive = boolean | number | string | null | undefined;
159
- type SerializableObject = Record<PropertyKey, unknown>;
160
- type SerializableArray = Array<JsonPrimitive | SerializableObject> | ReadonlyArray<JsonPrimitive | SerializableObject>;
161
- type Body = UnmaskType<Exclude<RequestInit["body"], undefined> | SerializableArray | SerializableObject>;
162
- type InferBodyOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["body"], {
163
- /**
164
- * Body of the request, can be a object or any other supported body type.
165
- */
166
- body?: InferSchemaOutput<TSchema["body"], Body>;
167
- }>;
168
- type MethodUnion = UnmaskType<"CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE" | AnyString>;
169
- type InferMethodFromURL<TInitURL> = string extends TInitURL ? MethodUnion : TInitURL extends `@${infer TMethod extends RouteKeyMethods}/${string}` ? Uppercase<TMethod> : MethodUnion;
170
- type InferMethodOption<TSchema extends CallApiSchema, TInitURL> = MakeSchemaOptionRequiredIfDefined<TSchema["method"], {
171
- /**
172
- * HTTP method for the request.
173
- * @default "GET"
174
- */
175
- method?: InferSchemaOutput<TSchema["method"], InferMethodFromURL<TInitURL>>;
176
- }>;
177
- type HeadersOption = UnmaskType<Record<"Authorization", CommonAuthorizationHeaders | undefined> | Record<"Content-Type", CommonContentTypes | undefined> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | Array<[string, string]>>;
178
- type InferHeadersOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["headers"], {
179
- /**
180
- * Headers to be used in the request.
181
- */
182
- headers?: InferSchemaOutput<TSchema["headers"], HeadersOption> | ((context: {
183
- baseHeaders: NonNullable<HeadersOption>;
184
- }) => InferSchemaOutput<TSchema["headers"], HeadersOption>);
185
- }>;
186
- type InferRequestOptions<TSchema extends CallApiSchema, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, CallApiSchemaConfig>> = InferBodyOption<TSchema> & InferHeadersOption<TSchema> & InferMethodOption<TSchema, TInitURL>;
187
- type InferMetaOption<TSchema extends CallApiSchema, TCallApiContext extends CallApiContext> = MakeSchemaOptionRequiredIfDefined<TSchema["meta"], {
188
- /**
189
- * - An optional field you can fill with additional information,
190
- * to associate with the request, typically used for logging or tracing.
191
- *
192
- * - A good use case for this, would be to use the info to handle specific cases in any of the shared interceptors.
193
- *
194
- * @example
195
- * ```ts
196
- * const callMainApi = callApi.create({
197
- * baseURL: "https://main-api.com",
198
- * onResponseError: ({ response, options }) => {
199
- * if (options.meta?.userId) {
200
- * console.error(`User ${options.meta.userId} made an error`);
201
- * }
202
- * },
203
- * });
204
- *
205
- * const response = await callMainApi({
206
- * url: "https://example.com/api/data",
207
- * meta: { userId: "123" },
208
- * });
209
- * ```
210
- */
211
- meta?: InferSchemaOutput<TSchema["meta"], TCallApiContext["Meta"]>;
212
- }>;
213
- type InferQueryOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["query"], {
214
- /**
215
- * Parameters to be appended to the URL (i.e: /:id)
216
- */
217
- query?: InferSchemaOutput<TSchema["query"], Query>;
218
- }>;
219
- type EmptyString = "";
220
- type EmptyTuple = readonly [];
221
- type StringTuple = readonly string[];
222
- type PossibleParamNamePatterns = `${string}:${string}` | `${string}{${string}}${"" | AnyString}`;
223
- type ExtractRouteParamNames<TCurrentRoute$1, TParamNamesAccumulator extends StringTuple = EmptyTuple> = TCurrentRoute$1 extends PossibleParamNamePatterns ? TCurrentRoute$1 extends `${infer TRoutePrefix}:${infer TParamAndRemainingRoute}` ? TParamAndRemainingRoute extends `${infer TCurrentParam}/${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamAndRemainingRoute extends `${infer TCurrentParam}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : ExtractRouteParamNames<TRoutePrefix, [...TParamNamesAccumulator, TCurrentParam]> : ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : TCurrentRoute$1 extends `${infer TRoutePrefix}{${infer TCurrentParam}}${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamNamesAccumulator : TParamNamesAccumulator;
224
- type ConvertParamNamesToRecord<TParamNames extends StringTuple> = Prettify<TParamNames extends (readonly [infer TFirstParamName extends string, ...infer TRemainingParamNames extends StringTuple]) ? Record<TFirstParamName, AllowedQueryParamValues> & ConvertParamNamesToRecord<TRemainingParamNames> : NonNullable<unknown>>;
225
- type ConvertParamNamesToTuple<TParamNames extends StringTuple> = TParamNames extends readonly [string, ...infer TRemainingParamNames extends StringTuple] ? [AllowedQueryParamValues, ...ConvertParamNamesToTuple<TRemainingParamNames>] : [];
226
- type InferParamsFromRoute<TCurrentRoute$1> = ExtractRouteParamNames<TCurrentRoute$1> extends StringTuple ? ExtractRouteParamNames<TCurrentRoute$1> extends EmptyTuple ? Params : ConvertParamNamesToRecord<ExtractRouteParamNames<TCurrentRoute$1>> | ConvertParamNamesToTuple<ExtractRouteParamNames<TCurrentRoute$1>> : Params;
227
- type MakeParamsOptionRequired<TParamsSchemaOption extends CallApiSchema["params"], TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TObject> = MakeSchemaOptionRequiredIfDefined<TParamsSchemaOption, Params extends InferParamsFromRoute<TCurrentRouteSchemaKey> ? TObject : TCurrentRouteSchemaKey extends Extract<keyof TBaseSchemaRoutes, TCurrentRouteSchemaKey> ? undefined extends InferSchemaOutput<TParamsSchemaOption, null> ? TObject : Required<TObject> : TObject>;
228
- type InferParamsOption<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = MakeParamsOptionRequired<TSchema["params"], TBaseSchemaRoutes, TCurrentRouteSchemaKey, {
229
- /**
230
- * Parameters to be appended to the URL (i.e: /:id)
231
- */
232
- params?: InferSchemaOutput<TSchema["params"], InferParamsFromRoute<TCurrentRouteSchemaKey>>;
233
- }>;
234
- type InferExtraOptions<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TCallApiContext extends CallApiContext> = InferMetaOption<TSchema, TCallApiContext> & InferParamsOption<TSchema, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferQueryOption<TSchema>;
235
- type InferPluginExtraOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<TPluginArray extends Array<infer TPlugin> ? TPlugin extends CallApiPlugin ? TPlugin["defineExtraOptions"] extends AnyFunction$1<infer TReturnedSchema> ? InferSchemaOutput<TReturnedSchema> : never : never : never>;
236
- type ResultModeOption<TErrorData, TResultMode extends ResultModeType> = TErrorData extends false ? {
237
- resultMode: "onlyData";
238
- } : TErrorData extends false | undefined ? {
239
- resultMode?: "onlyData";
240
- } : {
241
- resultMode?: TResultMode;
242
- };
243
- type ThrowOnErrorUnion = boolean;
244
- type ThrowOnErrorType<TErrorData, TThrowOnError extends ThrowOnErrorUnion> = TThrowOnError | ((context: ErrorContext<{
245
- ErrorData: TErrorData;
246
- }>) => TThrowOnError);
247
- type ThrowOnErrorOption<TErrorData, TThrowOnError extends ThrowOnErrorUnion> = TErrorData extends false ? {
248
- throwOnError: true;
249
- } : TErrorData extends false | undefined ? {
250
- throwOnError?: true;
251
- } : {
252
- throwOnError?: ThrowOnErrorType<TErrorData, TThrowOnError>;
253
- };
254
- //#endregion
255
105
  //#region src/types/standard-schema.d.ts
256
106
  /**
257
107
  * The Standard Schema interface.
@@ -557,6 +407,156 @@ interface URLOptions {
557
407
  query?: Query;
558
408
  }
559
409
  //#endregion
410
+ //#region src/types/conditional-types.d.ts
411
+ /**
412
+ * @description Makes a type partial if the output type of TSchema is not provided or has undefined in the union, otherwise makes it required
413
+ */
414
+ type MakeSchemaOptionRequiredIfDefined<TSchemaOption extends CallApiSchema[keyof CallApiSchema], TObject> = undefined extends InferSchemaOutput<TSchemaOption, undefined> ? TObject : Required<TObject>;
415
+ type ApplyURLBasedConfig<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig["prefix"] extends string ? `${TSchemaConfig["prefix"]}${TSchemaRouteKeys}` : TSchemaConfig["baseURL"] extends string ? `${TSchemaConfig["baseURL"]}${TSchemaRouteKeys}` : TSchemaRouteKeys;
416
+ type ApplyStrictConfig<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig["strict"] extends true ? TSchemaRouteKeys :
417
+ // eslint-disable-next-line perfectionist/sort-union-types -- Don't sort union types
418
+ TSchemaRouteKeys | Exclude<InitURLOrURLObject, RouteKeyMethodsURLUnion>;
419
+ type ApplySchemaConfiguration<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, TSchemaRouteKeys>>;
420
+ type InferAllRouteKeys<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TSchemaConfig extends CallApiSchemaConfig> = ApplySchemaConfiguration<TSchemaConfig, Exclude<Extract<keyof TBaseSchemaRoutes, string>, FallBackRouteSchemaKey>>;
421
+ type InferInitURL<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TSchemaConfig extends CallApiSchemaConfig> = keyof TBaseSchemaRoutes extends never ? InitURLOrURLObject : InferAllRouteKeys<TBaseSchemaRoutes, TSchemaConfig>;
422
+ type GetCurrentRouteSchema<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TComputedFallBackRouteSchema = TBaseSchemaRoutes[FallBackRouteSchemaKey], TComputedCurrentRouteSchema = TBaseSchemaRoutes[TCurrentRouteSchemaKey], TComputedRouteSchema extends CallApiSchema = NonNullable<Omit<TComputedFallBackRouteSchema, keyof TComputedCurrentRouteSchema> & TComputedCurrentRouteSchema>> = TComputedRouteSchema extends CallApiSchema ? Writeable<TComputedRouteSchema, "deep"> : CallApiSchema;
423
+ type JsonPrimitive = boolean | number | string | null | undefined;
424
+ type SerializableObject = Record<PropertyKey, unknown>;
425
+ type SerializableArray = Array<JsonPrimitive | SerializableObject> | ReadonlyArray<JsonPrimitive | SerializableObject>;
426
+ type Body = UnmaskType<Exclude<RequestInit["body"], undefined> | SerializableArray | SerializableObject>;
427
+ type InferBodyOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["body"], {
428
+ /**
429
+ * Body of the request, can be a object or any other supported body type.
430
+ */
431
+ body?: InferSchemaOutput<TSchema["body"], Body>;
432
+ }>;
433
+ type MethodUnion = UnmaskType<"CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE" | AnyString>;
434
+ type InferMethodFromURL<TInitURL> = string extends TInitURL ? MethodUnion : TInitURL extends `@${infer TMethod extends RouteKeyMethods}/${string}` ? Uppercase<TMethod> : MethodUnion;
435
+ type InferMethodOption<TSchema extends CallApiSchema, TInitURL> = MakeSchemaOptionRequiredIfDefined<TSchema["method"], {
436
+ /**
437
+ * HTTP method for the request.
438
+ * @default "GET"
439
+ */
440
+ method?: InferSchemaOutput<TSchema["method"], InferMethodFromURL<TInitURL>>;
441
+ }>;
442
+ type HeadersOption = UnmaskType<Headers | Record<"Authorization", CommonAuthorizationHeaders | undefined> | Record<"Content-Type", CommonContentTypes | undefined> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | Array<[string, string]>>;
443
+ type InferHeadersOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["headers"], {
444
+ /**
445
+ * Headers to be used in the request.
446
+ */
447
+ headers?: InferSchemaOutput<TSchema["headers"], HeadersOption> | ((context: {
448
+ baseHeaders: Extract<HeadersOption, Record<string, unknown>>;
449
+ }) => InferSchemaOutput<TSchema["headers"], HeadersOption>);
450
+ }>;
451
+ type InferRequestOptions<TSchema extends CallApiSchema, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, CallApiSchemaConfig>> = InferBodyOption<TSchema> & InferHeadersOption<TSchema> & InferMethodOption<TSchema, TInitURL>;
452
+ type InferMetaOption<TSchema extends CallApiSchema, TCallApiContext extends CallApiContext> = MakeSchemaOptionRequiredIfDefined<TSchema["meta"], {
453
+ /**
454
+ * - An optional field you can fill with additional information,
455
+ * to associate with the request, typically used for logging or tracing.
456
+ *
457
+ * - A good use case for this, would be to use the info to handle specific cases in any of the shared interceptors.
458
+ *
459
+ * @example
460
+ * ```ts
461
+ * const callMainApi = callApi.create({
462
+ * baseURL: "https://main-api.com",
463
+ * onResponseError: ({ response, options }) => {
464
+ * if (options.meta?.userId) {
465
+ * console.error(`User ${options.meta.userId} made an error`);
466
+ * }
467
+ * },
468
+ * });
469
+ *
470
+ * const response = await callMainApi({
471
+ * url: "https://example.com/api/data",
472
+ * meta: { userId: "123" },
473
+ * });
474
+ * ```
475
+ */
476
+ meta?: InferSchemaOutput<TSchema["meta"], TCallApiContext["Meta"]>;
477
+ }>;
478
+ type InferQueryOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["query"], {
479
+ /**
480
+ * Parameters to be appended to the URL (i.e: /:id)
481
+ */
482
+ query?: InferSchemaOutput<TSchema["query"], Query>;
483
+ }>;
484
+ type EmptyString = "";
485
+ type EmptyTuple = readonly [];
486
+ type StringTuple = readonly string[];
487
+ type PossibleParamNamePatterns = `${string}:${string}` | `${string}{${string}}${"" | AnyString}`;
488
+ type ExtractRouteParamNames<TCurrentRoute, TParamNamesAccumulator extends StringTuple = EmptyTuple> = TCurrentRoute extends PossibleParamNamePatterns ? TCurrentRoute extends `${infer TRoutePrefix}:${infer TParamAndRemainingRoute}` ? TParamAndRemainingRoute extends `${infer TCurrentParam}/${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamAndRemainingRoute extends `${infer TCurrentParam}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : ExtractRouteParamNames<TRoutePrefix, [...TParamNamesAccumulator, TCurrentParam]> : ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : TCurrentRoute extends `${infer TRoutePrefix}{${infer TCurrentParam}}${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamNamesAccumulator : TParamNamesAccumulator;
489
+ type ConvertParamNamesToRecord<TParamNames extends StringTuple> = Prettify<TParamNames extends (readonly [infer TFirstParamName extends string, ...infer TRemainingParamNames extends StringTuple]) ? Record<TFirstParamName, AllowedQueryParamValues> & ConvertParamNamesToRecord<TRemainingParamNames> : NonNullable<unknown>>;
490
+ type ConvertParamNamesToTuple<TParamNames extends StringTuple> = TParamNames extends readonly [string, ...infer TRemainingParamNames extends StringTuple] ? [AllowedQueryParamValues, ...ConvertParamNamesToTuple<TRemainingParamNames>] : [];
491
+ type InferParamsFromRoute<TCurrentRoute> = ExtractRouteParamNames<TCurrentRoute> extends StringTuple ? ExtractRouteParamNames<TCurrentRoute> extends EmptyTuple ? Params : ConvertParamNamesToRecord<ExtractRouteParamNames<TCurrentRoute>> | ConvertParamNamesToTuple<ExtractRouteParamNames<TCurrentRoute>> : Params;
492
+ type MakeParamsOptionRequired<TParamsSchemaOption extends CallApiSchema["params"], TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TObject> = MakeSchemaOptionRequiredIfDefined<TParamsSchemaOption, Params extends InferParamsFromRoute<TCurrentRouteSchemaKey> ? TObject : TCurrentRouteSchemaKey extends Extract<keyof TBaseSchemaRoutes, TCurrentRouteSchemaKey> ? undefined extends InferSchemaOutput<TParamsSchemaOption, null> ? TObject : Required<TObject> : TObject>;
493
+ type InferParamsOption<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = MakeParamsOptionRequired<TSchema["params"], TBaseSchemaRoutes, TCurrentRouteSchemaKey, {
494
+ /**
495
+ * Parameters to be appended to the URL (i.e: /:id)
496
+ */
497
+ params?: InferSchemaOutput<TSchema["params"], InferParamsFromRoute<TCurrentRouteSchemaKey>>;
498
+ }>;
499
+ type InferExtraOptions<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TCallApiContext extends CallApiContext> = InferMetaOption<TSchema, TCallApiContext> & InferParamsOption<TSchema, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferQueryOption<TSchema>;
500
+ type InferPluginExtraOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<TPluginArray extends Array<infer TPlugin> ? TPlugin extends CallApiPlugin ? TPlugin["defineExtraOptions"] extends AnyFunction$1<infer TReturnedSchema> ? InferSchemaOutput<TReturnedSchema> : never : never : never>;
501
+ type ResultModeOption<TErrorData, TResultMode extends ResultModeType> = TErrorData extends false ? {
502
+ resultMode: "onlyData";
503
+ } : TErrorData extends false | undefined ? {
504
+ resultMode?: "onlyData";
505
+ } : {
506
+ resultMode?: TResultMode;
507
+ };
508
+ type ThrowOnErrorUnion = boolean;
509
+ type ThrowOnErrorType<TErrorData, TThrowOnError extends ThrowOnErrorUnion> = TThrowOnError | ((context: ErrorContext<{
510
+ ErrorData: TErrorData;
511
+ }>) => TThrowOnError);
512
+ type ThrowOnErrorOption<TErrorData, TThrowOnError extends ThrowOnErrorUnion> = TErrorData extends false ? {
513
+ throwOnError: true;
514
+ } : TErrorData extends false | undefined ? {
515
+ throwOnError?: true;
516
+ } : {
517
+ throwOnError?: ThrowOnErrorType<TErrorData, TThrowOnError>;
518
+ };
519
+ //#endregion
520
+ //#region src/middlewares.d.ts
521
+ type FetchImpl = UnmaskType<(input: string | Request | URL, init?: RequestInit) => Promise<Response>>;
522
+ interface Middlewares<TCallApiContext extends NoInfer<CallApiContext> = DefaultCallApiContext> {
523
+ /**
524
+ * Wraps the fetch implementation to intercept requests at the network layer.
525
+ *
526
+ * Takes a context object containing the current fetch function and returns a new fetch function.
527
+ * Use it to cache responses, add logging, handle offline mode, or short-circuit requests etc.
528
+ * Multiple middleware compose in order: plugins → base config → per-request.
529
+ *
530
+ * Unlike `customFetchImpl`, middleware can call through to the original fetch.
531
+ *
532
+ * @example
533
+ * ```ts
534
+ * // Cache responses
535
+ * const cache = new Map();
536
+ *
537
+ * fetchMiddleware: (ctx) => async (input, init) => {
538
+ * const key = input.toString();
539
+ * if (cache.has(key)) return cache.get(key).clone();
540
+ *
541
+ * const response = await ctx.fetchImpl(input, init);
542
+ * cache.set(key, response.clone());
543
+ * return response;
544
+ * }
545
+ *
546
+ * // Handle offline
547
+ * fetchMiddleware: (ctx) => async (input, init) => {
548
+ * if (!navigator.onLine) {
549
+ * return new Response('{"error": "offline"}', { status: 503 });
550
+ * }
551
+ * return ctx.fetchImpl(input, init);
552
+ * }
553
+ * ```
554
+ */
555
+ fetchMiddleware?: (context: RequestContext<TCallApiContext> & {
556
+ fetchImpl: FetchImpl;
557
+ }) => FetchImpl;
558
+ }
559
+ //#endregion
560
560
  //#region src/plugins.d.ts
561
561
  type PluginSetupContext<TCallApiContext extends CallApiContext = DefaultCallApiContext> = RequestContext<TCallApiContext> & {
562
562
  initURL: string;
@@ -1848,4 +1848,4 @@ declare const loggerPlugin: (options?: LoggerOptions) => {
1848
1848
  };
1849
1849
  //#endregion
1850
1850
  export { defaultConsoleObject as n, loggerPlugin as r, LoggerOptions as t };
1851
- //# sourceMappingURL=index-DtZjKewM.d.ts.map
1851
+ //# sourceMappingURL=index-Do3FVEkv.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { n as defaultConsoleObject, r as loggerPlugin, t as LoggerOptions } from "./index-DtZjKewM.js";
1
+ import { n as defaultConsoleObject, r as loggerPlugin, t as LoggerOptions } from "./index-Do3FVEkv.js";
2
2
  export { LoggerOptions, defaultConsoleObject, loggerPlugin };
@@ -1,2 +1,2 @@
1
- import { n as defaultConsoleObject, r as loggerPlugin, t as LoggerOptions } from "../../index-DtZjKewM.js";
1
+ import { n as defaultConsoleObject, r as loggerPlugin, t as LoggerOptions } from "../../index-Do3FVEkv.js";
2
2
  export { LoggerOptions, defaultConsoleObject, loggerPlugin };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zayne-labs/callapi-plugins",
3
3
  "type": "module",
4
- "version": "4.0.31",
4
+ "version": "4.0.32",
5
5
  "description": "A collection of plugins for callapi",
6
6
  "author": "Ryan Zayne",
7
7
  "license": "MIT",
@@ -24,7 +24,7 @@
24
24
  "peerDependencies": {
25
25
  "@zayne-labs/toolkit-type-helpers": ">=0.11.17",
26
26
  "consola": "3.x.x",
27
- "@zayne-labs/callapi": "1.11.31"
27
+ "@zayne-labs/callapi": "1.11.32"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@arethetypeswrong/cli": "0.18.2",
@@ -38,10 +38,10 @@
38
38
  "cross-env": "^10.1.0",
39
39
  "publint": "^0.3.15",
40
40
  "size-limit": "12.0.0",
41
- "tsdown": "0.17.0-beta.5",
41
+ "tsdown": "0.17.0",
42
42
  "typescript": "5.9.3",
43
43
  "vitest": "^4.0.15",
44
- "@zayne-labs/callapi": "1.11.31"
44
+ "@zayne-labs/callapi": "1.11.32"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public",