@zayne-labs/callapi 1.7.2 → 1.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cjs/{error-By05WYGj.d.cts → common-BUhBcx_C.d.cts} +246 -231
- package/dist/cjs/index.cjs +223 -210
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +4 -4
- package/dist/cjs/utils/index.cjs +5 -2
- package/dist/cjs/utils/index.cjs.map +1 -1
- package/dist/cjs/utils/index.d.cts +2 -3
- package/dist/esm/{chunk-IAT2JZPC.js → chunk-G4FFGADM.js} +13 -13
- package/dist/esm/chunk-G4FFGADM.js.map +1 -0
- package/dist/esm/{error-By05WYGj.d.ts → common-BUhBcx_C.d.ts} +246 -231
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +110 -92
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/index.d.ts +2 -3
- package/dist/esm/utils/index.js +1 -1
- package/package.json +2 -2
- package/dist/esm/chunk-IAT2JZPC.js.map +0 -1
package/dist/esm/index.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import { R as ResultModeUnion, a as ResponseTypeUnion, C as CallApiPlugin, D as DefaultPluginArray, b as CallApiSchemas, I as InferSchemaResult, c as CallApiConfig, d as CallApiResult, e as DefaultDataType, f as DefaultThrowOnError, g as DefaultMoreOptions, B as BaseCallApiConfig, h as CallApiParameters } from './
|
2
|
-
export {
|
1
|
+
import { R as ResultModeUnion, a as ResponseTypeUnion, C as CallApiPlugin, D as DefaultPluginArray, b as CallApiSchemas, I as InferSchemaResult, c as CallApiConfig, d as CallApiResult, e as DefaultDataType, f as DefaultThrowOnError, g as DefaultMoreOptions, B as BaseCallApiConfig, h as CallApiParameters } from './common-BUhBcx_C.js';
|
2
|
+
export { y as BaseCallApiExtraOptions, z as CallApiExtraOptions, A as CallApiRequestOptions, F as CallApiRequestOptionsForHooks, G as CallApiResultErrorVariant, J as CallApiResultSuccessVariant, K as CombinedCallApiExtraOptions, E as ErrorContext, H as HTTPError, p as Hooks, q as HooksOrHooksArray, j as PluginHooks, k as PluginHooksWithMoreOptions, P as PluginInitContext, n as PossibleHTTPError, o as PossibleJavaScriptError, L as Register, r as RequestContext, s as RequestErrorContext, t as RequestStreamContext, u as ResponseContext, v as ResponseErrorContext, w as ResponseStreamContext, m as RetryOptions, S as SharedHookContext, x as SuccessContext, i as definePlugin, l as getDefaultOptions } from './common-BUhBcx_C.js';
|
3
3
|
|
4
|
-
declare const createFetchClient: <TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemas extends CallApiSchemas = DefaultMoreOptions>(
|
4
|
+
declare const createFetchClient: <TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemas extends CallApiSchemas = DefaultMoreOptions>(initBaseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemas>) => <TData = InferSchemaResult<TBaseSchemas["data"], TBaseData>, TErrorData = InferSchemaResult<TBaseSchemas["errorData"], TBaseErrorData>, TResultMode extends ResultModeUnion = TBaseResultMode, TThrowOnError extends boolean = TBaseThrowOnError, TResponseType extends ResponseTypeUnion = TBaseResponseType, TPluginArray extends CallApiPlugin[] = TBasePluginArray, TSchemas extends CallApiSchemas = TBaseSchemas>(initURL: InferSchemaResult<TSchemas["initURL"], string | URL>, config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas> | undefined) => CallApiResult<InferSchemaResult<TSchemas["data"], TData>, InferSchemaResult<TSchemas["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>;
|
5
5
|
declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = boolean, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TSchemas extends CallApiSchemas = {}>(initURL: InferSchemaResult<TSchemas["initURL"], string | URL>, config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas> | undefined) => CallApiResult<InferSchemaResult<TSchemas["data"], TData>, InferSchemaResult<TSchemas["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>;
|
6
6
|
|
7
7
|
declare const defineParameters: <TData = unknown, TErrorData = unknown, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TSchemas extends CallApiSchemas = DefaultMoreOptions>(...parameters: CallApiParameters<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas>) => CallApiParameters<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas>;
|
8
8
|
|
9
|
-
export { CallApiParameters, CallApiPlugin, CallApiSchemas, InferSchemaResult, ResultModeUnion, callApi, createFetchClient, defineParameters };
|
9
|
+
export { CallApiParameters, CallApiPlugin, CallApiSchemas, InferSchemaResult, ResponseTypeUnion, ResultModeUnion, callApi, createFetchClient, defineParameters };
|
package/dist/esm/index.js
CHANGED
@@ -1,5 +1,35 @@
|
|
1
|
-
import { splitConfig, isFunction, splitBaseConfig,
|
2
|
-
export { HTTPError, getDefaultOptions } from './chunk-
|
1
|
+
import { splitConfig, isFunction, splitBaseConfig, defaultExtraOptions, defaultRequestOptions, createTimeoutSignal, createCombinedSignal, mergeAndResolveHeaders, isSerializable, HTTPError, resolveErrorResult, isHTTPErrorInstance, waitUntil, omitKeys, isPlainObject, isString, isArray, toQueryString, getFetchImpl, isReadableStream, isObject } from './chunk-G4FFGADM.js';
|
2
|
+
export { HTTPError, getDefaultOptions } from './chunk-G4FFGADM.js';
|
3
|
+
|
4
|
+
// src/hooks.ts
|
5
|
+
var hookRegistries = {
|
6
|
+
onError: /* @__PURE__ */ new Set(),
|
7
|
+
onRequest: /* @__PURE__ */ new Set(),
|
8
|
+
onRequestError: /* @__PURE__ */ new Set(),
|
9
|
+
onRequestStream: /* @__PURE__ */ new Set(),
|
10
|
+
onResponse: /* @__PURE__ */ new Set(),
|
11
|
+
onResponseError: /* @__PURE__ */ new Set(),
|
12
|
+
onResponseStream: /* @__PURE__ */ new Set(),
|
13
|
+
onRetry: /* @__PURE__ */ new Set(),
|
14
|
+
onSuccess: /* @__PURE__ */ new Set()
|
15
|
+
};
|
16
|
+
var composeTwoHooks = (hooks, mergedHooksExecutionMode) => {
|
17
|
+
if (hooks.length === 0) return;
|
18
|
+
const mergedHook = async (ctx) => {
|
19
|
+
if (mergedHooksExecutionMode === "sequential") {
|
20
|
+
for (const hook of hooks) {
|
21
|
+
await hook?.(ctx);
|
22
|
+
}
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
if (mergedHooksExecutionMode === "parallel") {
|
26
|
+
const hookArray = [...hooks];
|
27
|
+
await Promise.all(hookArray.map((uniqueHook) => uniqueHook?.(ctx)));
|
28
|
+
}
|
29
|
+
};
|
30
|
+
return mergedHook;
|
31
|
+
};
|
32
|
+
var executeHooks = (...hooks) => Promise.all(hooks);
|
3
33
|
|
4
34
|
// src/stream.ts
|
5
35
|
var createProgressEvent = (options) => {
|
@@ -22,17 +52,19 @@ var calculateTotalBytesFromBody = async (requestBody, existingTotalBytes) => {
|
|
22
52
|
return totalBytes;
|
23
53
|
};
|
24
54
|
var toStreamableRequest = async (context) => {
|
25
|
-
const { options, request, requestInstance } = context;
|
55
|
+
const { baseConfig, config, options, request, requestInstance } = context;
|
26
56
|
if (!options.onRequestStream || !requestInstance.body) return;
|
27
57
|
const contentLength = requestInstance.headers.get("content-length") ?? new Headers(request.headers).get("content-length") ?? request.body?.size;
|
28
58
|
let totalBytes = Number(contentLength ?? 0);
|
29
|
-
const shouldForceContentLengthCalc = isObject(options.
|
59
|
+
const shouldForceContentLengthCalc = isObject(options.forceCalculateStreamSize) ? options.forceCalculateStreamSize.request : options.forceCalculateStreamSize;
|
30
60
|
if (!contentLength && shouldForceContentLengthCalc) {
|
31
61
|
totalBytes = await calculateTotalBytesFromBody(requestInstance.clone().body, totalBytes);
|
32
62
|
}
|
33
63
|
let transferredBytes = 0;
|
34
64
|
await executeHooks(
|
35
65
|
options.onRequestStream({
|
66
|
+
baseConfig,
|
67
|
+
config,
|
36
68
|
event: createProgressEvent({ chunk: new Uint8Array(), totalBytes, transferredBytes }),
|
37
69
|
options,
|
38
70
|
request,
|
@@ -48,6 +80,8 @@ var toStreamableRequest = async (context) => {
|
|
48
80
|
totalBytes = Math.max(totalBytes, transferredBytes);
|
49
81
|
await executeHooks(
|
50
82
|
options.onRequestStream?.({
|
83
|
+
baseConfig,
|
84
|
+
config,
|
51
85
|
event: createProgressEvent({ chunk, totalBytes, transferredBytes }),
|
52
86
|
options,
|
53
87
|
request,
|
@@ -61,19 +95,21 @@ var toStreamableRequest = async (context) => {
|
|
61
95
|
});
|
62
96
|
};
|
63
97
|
var toStreamableResponse = async (context) => {
|
64
|
-
const { options, request, response } = context;
|
98
|
+
const { baseConfig, config, options, request, response } = context;
|
65
99
|
if (!options.onResponseStream || !response.body) {
|
66
100
|
return response;
|
67
101
|
}
|
68
102
|
const contentLength = response.headers.get("content-length");
|
69
103
|
let totalBytes = Number(contentLength ?? 0);
|
70
|
-
const shouldForceContentLengthCalc = isObject(options.
|
104
|
+
const shouldForceContentLengthCalc = isObject(options.forceCalculateStreamSize) ? options.forceCalculateStreamSize.response : options.forceCalculateStreamSize;
|
71
105
|
if (!contentLength && shouldForceContentLengthCalc) {
|
72
106
|
totalBytes = await calculateTotalBytesFromBody(response.clone().body, totalBytes);
|
73
107
|
}
|
74
108
|
let transferredBytes = 0;
|
75
109
|
await executeHooks(
|
76
110
|
options.onResponseStream({
|
111
|
+
baseConfig,
|
112
|
+
config,
|
77
113
|
event: createProgressEvent({ chunk: new Uint8Array(), totalBytes, transferredBytes }),
|
78
114
|
options,
|
79
115
|
request,
|
@@ -89,6 +125,8 @@ var toStreamableResponse = async (context) => {
|
|
89
125
|
totalBytes = Math.max(totalBytes, transferredBytes);
|
90
126
|
await executeHooks(
|
91
127
|
options.onResponseStream?.({
|
128
|
+
baseConfig,
|
129
|
+
config,
|
92
130
|
event: createProgressEvent({ chunk, totalBytes, transferredBytes }),
|
93
131
|
options,
|
94
132
|
request,
|
@@ -104,16 +142,16 @@ var toStreamableResponse = async (context) => {
|
|
104
142
|
};
|
105
143
|
|
106
144
|
// src/dedupe.ts
|
145
|
+
var generateDedupeKey = (options, request) => {
|
146
|
+
const shouldHaveDedupeKey = options.dedupeStrategy === "cancel" || options.dedupeStrategy === "defer";
|
147
|
+
if (!shouldHaveDedupeKey) {
|
148
|
+
return null;
|
149
|
+
}
|
150
|
+
return `${options.fullURL}-${JSON.stringify({ options, request })}`;
|
151
|
+
};
|
107
152
|
var createDedupeStrategy = async (context) => {
|
108
|
-
const { $RequestInfoCache, newFetchController, options, request } = context;
|
109
|
-
const
|
110
|
-
const shouldHaveDedupeKey = options.dedupeStrategy === "cancel" || options.dedupeStrategy === "defer";
|
111
|
-
if (!shouldHaveDedupeKey) {
|
112
|
-
return null;
|
113
|
-
}
|
114
|
-
return `${options.fullURL}-${JSON.stringify({ options, request })}`;
|
115
|
-
};
|
116
|
-
const dedupeKey = options.dedupeKey ?? generateDedupeKey();
|
153
|
+
const { $RequestInfoCache, baseConfig, config, newFetchController, options, request } = context;
|
154
|
+
const dedupeKey = options.dedupeKey ?? generateDedupeKey(options, request);
|
117
155
|
const $RequestInfoCacheOrNull = dedupeKey !== null ? $RequestInfoCache : null;
|
118
156
|
if (dedupeKey !== null) {
|
119
157
|
await waitUntil(0.1);
|
@@ -134,24 +172,33 @@ var createDedupeStrategy = async (context) => {
|
|
134
172
|
options.fullURL,
|
135
173
|
isReadableStream(request.body) && !request.duplex ? { ...request, duplex: "half" } : request
|
136
174
|
);
|
137
|
-
|
175
|
+
await toStreamableRequest({
|
176
|
+
baseConfig,
|
177
|
+
config,
|
138
178
|
options,
|
139
179
|
request,
|
140
180
|
requestInstance: requestInstance.clone()
|
141
181
|
});
|
142
|
-
const
|
143
|
-
|
144
|
-
|
145
|
-
|
182
|
+
const getFetchApiPromise = () => {
|
183
|
+
if (isReadableStream(request.body)) {
|
184
|
+
return fetchApi(requestInstance.clone());
|
185
|
+
}
|
186
|
+
return fetchApi(options.fullURL, request);
|
187
|
+
};
|
188
|
+
const responsePromise = shouldUsePromiseFromCache ? prevRequestInfo.responsePromise : getFetchApiPromise();
|
146
189
|
$RequestInfoCacheOrNull?.set(dedupeKey, { controller: newFetchController, responsePromise });
|
147
190
|
const streamableResponse = toStreamableResponse({
|
191
|
+
baseConfig,
|
192
|
+
config,
|
148
193
|
options,
|
149
194
|
request,
|
150
195
|
response: await responsePromise
|
151
196
|
});
|
152
197
|
return streamableResponse;
|
153
198
|
};
|
154
|
-
const removeDedupeKeyFromCache = () =>
|
199
|
+
const removeDedupeKeyFromCache = () => {
|
200
|
+
$RequestInfoCacheOrNull?.delete(dedupeKey);
|
201
|
+
};
|
155
202
|
return {
|
156
203
|
handleRequestCancelStrategy,
|
157
204
|
handleRequestDeferStrategy,
|
@@ -163,61 +210,34 @@ var createDedupeStrategy = async (context) => {
|
|
163
210
|
var definePlugin = (plugin) => {
|
164
211
|
return plugin;
|
165
212
|
};
|
166
|
-
var
|
167
|
-
if (hooks.length === 0) return;
|
168
|
-
const mergedHook = async (ctx) => {
|
169
|
-
if (mergedHooksExecutionMode === "sequential") {
|
170
|
-
for (const hook of hooks) {
|
171
|
-
await hook?.(ctx);
|
172
|
-
}
|
173
|
-
return;
|
174
|
-
}
|
175
|
-
if (mergedHooksExecutionMode === "parallel") {
|
176
|
-
const hookArray = [...hooks];
|
177
|
-
await Promise.all(hookArray.map((uniqueHook) => uniqueHook?.(ctx)));
|
178
|
-
}
|
179
|
-
};
|
180
|
-
return mergedHook;
|
181
|
-
};
|
182
|
-
var hooksEnum = {
|
183
|
-
onError: /* @__PURE__ */ new Set(),
|
184
|
-
onRequest: /* @__PURE__ */ new Set(),
|
185
|
-
onRequestError: /* @__PURE__ */ new Set(),
|
186
|
-
onRequestStream: /* @__PURE__ */ new Set(),
|
187
|
-
onResponse: /* @__PURE__ */ new Set(),
|
188
|
-
onResponseError: /* @__PURE__ */ new Set(),
|
189
|
-
onResponseStream: /* @__PURE__ */ new Set(),
|
190
|
-
onRetry: /* @__PURE__ */ new Set(),
|
191
|
-
onSuccess: /* @__PURE__ */ new Set()
|
192
|
-
};
|
193
|
-
var getPluginArray = (plugins) => {
|
213
|
+
var resolvePluginArray = (plugins, basePlugins) => {
|
194
214
|
if (!plugins) {
|
195
215
|
return [];
|
196
216
|
}
|
217
|
+
if (isFunction(plugins)) {
|
218
|
+
return plugins({ basePlugins: basePlugins ?? [] });
|
219
|
+
}
|
197
220
|
return plugins;
|
198
221
|
};
|
199
222
|
var initializePlugins = async (context) => {
|
200
223
|
const { baseConfig, config, initURL, options, request } = context;
|
201
|
-
const
|
224
|
+
const clonedHookRegistries = structuredClone(hookRegistries);
|
202
225
|
const addMainHooks = () => {
|
203
|
-
for (const key of Object.keys(
|
226
|
+
for (const key of Object.keys(clonedHookRegistries)) {
|
204
227
|
const mainHook = options[key];
|
205
|
-
|
228
|
+
clonedHookRegistries[key].add(mainHook);
|
206
229
|
}
|
207
230
|
};
|
208
231
|
const addPluginHooks = (pluginHooks) => {
|
209
|
-
for (const key of Object.keys(
|
232
|
+
for (const key of Object.keys(clonedHookRegistries)) {
|
210
233
|
const pluginHook = pluginHooks[key];
|
211
|
-
|
234
|
+
clonedHookRegistries[key].add(pluginHook);
|
212
235
|
}
|
213
236
|
};
|
214
237
|
if (options.mergedHooksExecutionOrder === "mainHooksBeforePlugins") {
|
215
238
|
addMainHooks();
|
216
239
|
}
|
217
|
-
const resolvedPlugins =
|
218
|
-
...getPluginArray(options.plugins),
|
219
|
-
...getPluginArray(options.extend?.plugins)
|
220
|
-
];
|
240
|
+
const resolvedPlugins = resolvePluginArray(options.plugins, baseConfig.plugins);
|
221
241
|
let resolvedUrl = initURL;
|
222
242
|
let resolvedOptions = options;
|
223
243
|
let resolvedRequestOptions = request;
|
@@ -250,10 +270,10 @@ var initializePlugins = async (context) => {
|
|
250
270
|
addMainHooks();
|
251
271
|
}
|
252
272
|
const resolvedHooks = {};
|
253
|
-
for (const [key, hookRegistry] of Object.entries(
|
273
|
+
for (const [key, hookRegistry] of Object.entries(clonedHookRegistries)) {
|
254
274
|
const flattenedHookArray = [...hookRegistry].flat().filter(Boolean);
|
255
|
-
const
|
256
|
-
resolvedHooks[key] =
|
275
|
+
const composedHook = composeTwoHooks(flattenedHookArray, options.mergedHooksExecutionMode);
|
276
|
+
resolvedHooks[key] = composedHook;
|
257
277
|
}
|
258
278
|
return {
|
259
279
|
resolvedHooks,
|
@@ -280,6 +300,9 @@ var getResponseType = (response, parser) => ({
|
|
280
300
|
});
|
281
301
|
var resolveResponseData = async (response, responseType, parser) => {
|
282
302
|
const RESPONSE_TYPE_LOOKUP = getResponseType(response, parser);
|
303
|
+
if (!responseType) {
|
304
|
+
return RESPONSE_TYPE_LOOKUP.json();
|
305
|
+
}
|
283
306
|
if (!Object.hasOwn(RESPONSE_TYPE_LOOKUP, responseType)) {
|
284
307
|
throw new Error(`Invalid response type: ${responseType}`);
|
285
308
|
}
|
@@ -406,10 +429,6 @@ var mergeUrlWithParamsAndQuery = (url, params, query) => {
|
|
406
429
|
return mergeUrlWithQuery(urlWithMergedParams, query);
|
407
430
|
};
|
408
431
|
|
409
|
-
// src/utils/polyfills.ts
|
410
|
-
var createCombinedSignal = (...signals) => AbortSignal.any(signals.filter(Boolean));
|
411
|
-
var createTimeoutSignal = (milliseconds) => AbortSignal.timeout(milliseconds);
|
412
|
-
|
413
432
|
// src/validation.ts
|
414
433
|
var standardSchemaParser = async (schema, inputData) => {
|
415
434
|
const result = await schema["~standard"].validate(inputData);
|
@@ -418,11 +437,6 @@ var standardSchemaParser = async (schema, inputData) => {
|
|
418
437
|
}
|
419
438
|
return result.value;
|
420
439
|
};
|
421
|
-
var createExtensibleSchemasAndValidators = (options) => {
|
422
|
-
const schemas = options.schemas && { ...options.schemas, ...options.extend?.schemas };
|
423
|
-
const validators = options.validators && { ...options.validators, ...options.extend?.validators };
|
424
|
-
return { schemas, validators };
|
425
|
-
};
|
426
440
|
var handleValidation = async (responseData, schema, validator) => {
|
427
441
|
const validResponseData = validator ? validator(responseData) : responseData;
|
428
442
|
const schemaValidResponseData = schema ? await standardSchemaParser(schema, validResponseData) : validResponseData;
|
@@ -430,35 +444,27 @@ var handleValidation = async (responseData, schema, validator) => {
|
|
430
444
|
};
|
431
445
|
|
432
446
|
// src/createFetchClient.ts
|
433
|
-
var createFetchClient = (
|
447
|
+
var createFetchClient = (initBaseConfig = {}) => {
|
434
448
|
const $RequestInfoCache = /* @__PURE__ */ new Map();
|
435
449
|
const callApi2 = async (...parameters) => {
|
436
|
-
const [initURL,
|
437
|
-
const [fetchOptions, extraOptions] = splitConfig(
|
438
|
-
const resolvedBaseConfig = isFunction(
|
439
|
-
initURL: initURL.toString(),
|
440
|
-
options: extraOptions,
|
441
|
-
request: fetchOptions
|
442
|
-
}) : baseConfig;
|
450
|
+
const [initURL, initConfig = {}] = parameters;
|
451
|
+
const [fetchOptions, extraOptions] = splitConfig(initConfig);
|
452
|
+
const resolvedBaseConfig = isFunction(initBaseConfig) ? initBaseConfig({ initURL: initURL.toString(), options: extraOptions, request: fetchOptions }) : initBaseConfig;
|
443
453
|
const [baseFetchOptions, baseExtraOptions] = splitBaseConfig(resolvedBaseConfig);
|
444
|
-
for (const key of Object.keys(hooksEnum)) {
|
445
|
-
combineHooks(
|
446
|
-
baseExtraOptions[key],
|
447
|
-
extraOptions[key]
|
448
|
-
);
|
449
|
-
}
|
450
454
|
const mergedExtraOptions = {
|
451
455
|
...defaultExtraOptions,
|
452
456
|
...baseExtraOptions,
|
453
|
-
|
457
|
+
...baseExtraOptions.skipAutoMergeFor !== "all" && baseExtraOptions.skipAutoMergeFor !== "options" && extraOptions
|
454
458
|
};
|
455
459
|
const mergedRequestOptions = {
|
456
460
|
...defaultRequestOptions,
|
457
461
|
...baseFetchOptions,
|
458
|
-
...fetchOptions
|
462
|
+
...baseExtraOptions.skipAutoMergeFor !== "all" && baseExtraOptions.skipAutoMergeFor !== "request" && fetchOptions
|
459
463
|
};
|
464
|
+
const baseConfig = resolvedBaseConfig;
|
465
|
+
const config = initConfig;
|
460
466
|
const { resolvedHooks, resolvedOptions, resolvedRequestOptions, url } = await initializePlugins({
|
461
|
-
baseConfig
|
467
|
+
baseConfig,
|
462
468
|
config,
|
463
469
|
initURL,
|
464
470
|
options: mergedExtraOptions,
|
@@ -489,18 +495,26 @@ var createFetchClient = (baseConfig = {}) => {
|
|
489
495
|
}),
|
490
496
|
signal: combinedSignal
|
491
497
|
};
|
492
|
-
const { handleRequestCancelStrategy, handleRequestDeferStrategy, removeDedupeKeyFromCache } = await createDedupeStrategy({
|
498
|
+
const { handleRequestCancelStrategy, handleRequestDeferStrategy, removeDedupeKeyFromCache } = await createDedupeStrategy({
|
499
|
+
$RequestInfoCache,
|
500
|
+
baseConfig,
|
501
|
+
config,
|
502
|
+
newFetchController,
|
503
|
+
options,
|
504
|
+
request
|
505
|
+
});
|
493
506
|
await handleRequestCancelStrategy();
|
494
507
|
try {
|
495
|
-
await executeHooks(options.onRequest?.({ options, request }));
|
508
|
+
await executeHooks(options.onRequest?.({ baseConfig, config, options, request }));
|
496
509
|
request.headers = mergeAndResolveHeaders({
|
497
510
|
auth: options.auth,
|
498
511
|
body: request.body,
|
499
512
|
headers: request.headers
|
500
513
|
});
|
501
514
|
const response = await handleRequestDeferStrategy();
|
502
|
-
const { schemas, validators } = createExtensibleSchemasAndValidators(options);
|
503
515
|
const shouldCloneResponse = options.dedupeStrategy === "defer" || options.cloneResponse;
|
516
|
+
const schemas = isFunction(options.schemas) ? options.schemas({ baseSchemas: baseExtraOptions.schemas ?? {} }) : options.schemas;
|
517
|
+
const validators = isFunction(options.validators) ? options.validators({ baseValidators: baseExtraOptions.validators ?? {} }) : options.validators;
|
504
518
|
if (!response.ok) {
|
505
519
|
const errorData = await resolveResponseData(
|
506
520
|
shouldCloneResponse ? response.clone() : response,
|
@@ -525,6 +539,8 @@ var createFetchClient = (baseConfig = {}) => {
|
|
525
539
|
);
|
526
540
|
const validSuccessData = await handleValidation(successData, schemas?.data, validators?.data);
|
527
541
|
const successContext = {
|
542
|
+
baseConfig,
|
543
|
+
config,
|
528
544
|
data: validSuccessData,
|
529
545
|
options,
|
530
546
|
request,
|
@@ -547,6 +563,8 @@ var createFetchClient = (baseConfig = {}) => {
|
|
547
563
|
resultMode: options.resultMode
|
548
564
|
});
|
549
565
|
const errorContext = {
|
566
|
+
baseConfig,
|
567
|
+
config,
|
550
568
|
error: apiDetails.error,
|
551
569
|
options,
|
552
570
|
request,
|
@@ -590,9 +608,9 @@ var createFetchClient = (baseConfig = {}) => {
|
|
590
608
|
return await handleRetryOrGetResult({ message });
|
591
609
|
}
|
592
610
|
await executeHooks(
|
593
|
-
// == At this point only the request errors exist, so the request error
|
611
|
+
// == At this point only the request errors exist, so the request error hook is called
|
594
612
|
options.onRequestError?.(errorContext),
|
595
|
-
// == Also call the onError
|
613
|
+
// == Also call the onError hook
|
596
614
|
options.onError?.(errorContext)
|
597
615
|
);
|
598
616
|
return await handleRetryOrGetResult();
|