@spoosh/core 0.2.1 → 0.2.2
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.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +18 -1
- package/dist/index.mjs +18 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1253,6 +1253,7 @@ declare function buildUrl(baseUrl: string, path: string[], query?: Record<string
|
|
|
1253
1253
|
*/
|
|
1254
1254
|
declare function generateTags(path: string[]): string[];
|
|
1255
1255
|
|
|
1256
|
+
declare function containsFile(value: unknown): boolean;
|
|
1256
1257
|
declare function isJsonBody(body: unknown): body is Record<string, unknown> | unknown[];
|
|
1257
1258
|
|
|
1258
1259
|
/**
|
|
@@ -1519,4 +1520,4 @@ type CreateInfiniteReadOptions<TData, TItem, TError, TRequest> = {
|
|
|
1519
1520
|
};
|
|
1520
1521
|
declare function createInfiniteReadController<TData, TItem, TError, TRequest extends InfiniteRequestOptions = InfiniteRequestOptions>(options: CreateInfiniteReadOptions<TData, TItem, TError, TRequest>): InfiniteReadController<TData, TItem, TError>;
|
|
1521
1522
|
|
|
1522
|
-
export { type AnyRequestOptions, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type SpooshClientConfig as ClientConfig, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type DataAwareCallback, type DataAwareTransform, type Endpoint, type EventEmitter, type ExtractBody, type ExtractData, type ExtractError, type ExtractFormData, type ExtractMethodDef, type ExtractMethodOptions, type ExtractQuery, type ExtractUrlEncoded, type FetchDirection, type FetchExecutor, HTTP_METHODS, type HasMethod, type HasQueryMethods, type HasRequiredOptions, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InstanceApiContext, type InstanceApiResolvers, type InstancePluginExecutor, type LifecyclePhase, type MergePluginInstanceApi, type MergePluginOptions, type MergePluginResults, type MethodFn, type MethodOptionsMap, type MiddlewareContext, type MiddlewareHandler, type MiddlewarePhase, type MutationOnlyClient, type NormalizeEndpoint, type OperationController, type OperationState, type OperationType, type PageContext, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextInput, type PluginExecutor, type PluginExportsRegistry, type PluginFactory, type PluginHandler, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type QueryOnlyClient, type QuerySchemaHelper, type RefetchEvent, type RequestOptions, type ResolveInstanceApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type RetryConfig, type SchemaMethod, type SelectedEndpoint, type SelectorFunction, type SelectorResult, Spoosh, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshMiddleware, type SpooshOptions, type SpooshOptionsExtra, type SpooshPlugin, type SpooshResponse, type StateManager, type StaticPathKeys, type TagOptions, applyMiddlewares, buildUrl, composeMiddlewares, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createMiddleware, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createSelectorProxy, createStateManager, executeFetch, extractMethodFromSelector, extractPathFromSelector, generateTags, isJsonBody, mergeHeaders, objectToFormData, objectToUrlEncoded, resolveHeadersToRecord, resolvePath, resolveTags, setHeaders, sortObjectKeys };
|
|
1523
|
+
export { type AnyRequestOptions, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type SpooshClientConfig as ClientConfig, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type DataAwareCallback, type DataAwareTransform, type Endpoint, type EventEmitter, type ExtractBody, type ExtractData, type ExtractError, type ExtractFormData, type ExtractMethodDef, type ExtractMethodOptions, type ExtractQuery, type ExtractUrlEncoded, type FetchDirection, type FetchExecutor, HTTP_METHODS, type HasMethod, type HasQueryMethods, type HasRequiredOptions, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InstanceApiContext, type InstanceApiResolvers, type InstancePluginExecutor, type LifecyclePhase, type MergePluginInstanceApi, type MergePluginOptions, type MergePluginResults, type MethodFn, type MethodOptionsMap, type MiddlewareContext, type MiddlewareHandler, type MiddlewarePhase, type MutationOnlyClient, type NormalizeEndpoint, type OperationController, type OperationState, type OperationType, type PageContext, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextInput, type PluginExecutor, type PluginExportsRegistry, type PluginFactory, type PluginHandler, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type QueryOnlyClient, type QuerySchemaHelper, type RefetchEvent, type RequestOptions, type ResolveInstanceApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type RetryConfig, type SchemaMethod, type SelectedEndpoint, type SelectorFunction, type SelectorResult, Spoosh, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshMiddleware, type SpooshOptions, type SpooshOptionsExtra, type SpooshPlugin, type SpooshResponse, type StateManager, type StaticPathKeys, type TagOptions, applyMiddlewares, buildUrl, composeMiddlewares, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createMiddleware, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createSelectorProxy, createStateManager, executeFetch, extractMethodFromSelector, extractPathFromSelector, generateTags, isJsonBody, mergeHeaders, objectToFormData, objectToUrlEncoded, resolveHeadersToRecord, resolvePath, resolveTags, setHeaders, sortObjectKeys };
|
package/dist/index.d.ts
CHANGED
|
@@ -1253,6 +1253,7 @@ declare function buildUrl(baseUrl: string, path: string[], query?: Record<string
|
|
|
1253
1253
|
*/
|
|
1254
1254
|
declare function generateTags(path: string[]): string[];
|
|
1255
1255
|
|
|
1256
|
+
declare function containsFile(value: unknown): boolean;
|
|
1256
1257
|
declare function isJsonBody(body: unknown): body is Record<string, unknown> | unknown[];
|
|
1257
1258
|
|
|
1258
1259
|
/**
|
|
@@ -1519,4 +1520,4 @@ type CreateInfiniteReadOptions<TData, TItem, TError, TRequest> = {
|
|
|
1519
1520
|
};
|
|
1520
1521
|
declare function createInfiniteReadController<TData, TItem, TError, TRequest extends InfiniteRequestOptions = InfiniteRequestOptions>(options: CreateInfiniteReadOptions<TData, TItem, TError, TRequest>): InfiniteReadController<TData, TItem, TError>;
|
|
1521
1522
|
|
|
1522
|
-
export { type AnyRequestOptions, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type SpooshClientConfig as ClientConfig, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type DataAwareCallback, type DataAwareTransform, type Endpoint, type EventEmitter, type ExtractBody, type ExtractData, type ExtractError, type ExtractFormData, type ExtractMethodDef, type ExtractMethodOptions, type ExtractQuery, type ExtractUrlEncoded, type FetchDirection, type FetchExecutor, HTTP_METHODS, type HasMethod, type HasQueryMethods, type HasRequiredOptions, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InstanceApiContext, type InstanceApiResolvers, type InstancePluginExecutor, type LifecyclePhase, type MergePluginInstanceApi, type MergePluginOptions, type MergePluginResults, type MethodFn, type MethodOptionsMap, type MiddlewareContext, type MiddlewareHandler, type MiddlewarePhase, type MutationOnlyClient, type NormalizeEndpoint, type OperationController, type OperationState, type OperationType, type PageContext, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextInput, type PluginExecutor, type PluginExportsRegistry, type PluginFactory, type PluginHandler, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type QueryOnlyClient, type QuerySchemaHelper, type RefetchEvent, type RequestOptions, type ResolveInstanceApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type RetryConfig, type SchemaMethod, type SelectedEndpoint, type SelectorFunction, type SelectorResult, Spoosh, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshMiddleware, type SpooshOptions, type SpooshOptionsExtra, type SpooshPlugin, type SpooshResponse, type StateManager, type StaticPathKeys, type TagOptions, applyMiddlewares, buildUrl, composeMiddlewares, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createMiddleware, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createSelectorProxy, createStateManager, executeFetch, extractMethodFromSelector, extractPathFromSelector, generateTags, isJsonBody, mergeHeaders, objectToFormData, objectToUrlEncoded, resolveHeadersToRecord, resolvePath, resolveTags, setHeaders, sortObjectKeys };
|
|
1523
|
+
export { type AnyRequestOptions, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type SpooshClientConfig as ClientConfig, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type DataAwareCallback, type DataAwareTransform, type Endpoint, type EventEmitter, type ExtractBody, type ExtractData, type ExtractError, type ExtractFormData, type ExtractMethodDef, type ExtractMethodOptions, type ExtractQuery, type ExtractUrlEncoded, type FetchDirection, type FetchExecutor, HTTP_METHODS, type HasMethod, type HasQueryMethods, type HasRequiredOptions, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InstanceApiContext, type InstanceApiResolvers, type InstancePluginExecutor, type LifecyclePhase, type MergePluginInstanceApi, type MergePluginOptions, type MergePluginResults, type MethodFn, type MethodOptionsMap, type MiddlewareContext, type MiddlewareHandler, type MiddlewarePhase, type MutationOnlyClient, type NormalizeEndpoint, type OperationController, type OperationState, type OperationType, type PageContext, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextInput, type PluginExecutor, type PluginExportsRegistry, type PluginFactory, type PluginHandler, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type QueryOnlyClient, type QuerySchemaHelper, type RefetchEvent, type RequestOptions, type ResolveInstanceApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type RetryConfig, type SchemaMethod, type SelectedEndpoint, type SelectorFunction, type SelectorResult, Spoosh, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshMiddleware, type SpooshOptions, type SpooshOptionsExtra, type SpooshPlugin, type SpooshResponse, type StateManager, type StaticPathKeys, type TagOptions, applyMiddlewares, buildUrl, composeMiddlewares, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createMiddleware, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createSelectorProxy, createStateManager, executeFetch, extractMethodFromSelector, extractPathFromSelector, generateTags, isJsonBody, mergeHeaders, objectToFormData, objectToUrlEncoded, resolveHeadersToRecord, resolvePath, resolveTags, setHeaders, sortObjectKeys };
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __export(src_exports, {
|
|
|
25
25
|
applyMiddlewares: () => applyMiddlewares,
|
|
26
26
|
buildUrl: () => buildUrl,
|
|
27
27
|
composeMiddlewares: () => composeMiddlewares,
|
|
28
|
+
containsFile: () => containsFile,
|
|
28
29
|
createClient: () => createClient,
|
|
29
30
|
createEventEmitter: () => createEventEmitter,
|
|
30
31
|
createInfiniteReadController: () => createInfiniteReadController,
|
|
@@ -103,6 +104,14 @@ function generateTags(path) {
|
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
// src/utils/isJsonBody.ts
|
|
107
|
+
function containsFile(value) {
|
|
108
|
+
if (value instanceof File || value instanceof Blob) return true;
|
|
109
|
+
if (Array.isArray(value)) return value.some(containsFile);
|
|
110
|
+
if (value && typeof value === "object") {
|
|
111
|
+
return Object.values(value).some(containsFile);
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
106
115
|
function isJsonBody(body) {
|
|
107
116
|
if (body === null || body === void 0) return false;
|
|
108
117
|
if (body instanceof FormData) return false;
|
|
@@ -111,7 +120,11 @@ function isJsonBody(body) {
|
|
|
111
120
|
if (body instanceof URLSearchParams) return false;
|
|
112
121
|
if (body instanceof ReadableStream) return false;
|
|
113
122
|
if (typeof body === "string") return false;
|
|
114
|
-
|
|
123
|
+
if (typeof body === "object") {
|
|
124
|
+
if (containsFile(body)) return false;
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
return false;
|
|
115
128
|
}
|
|
116
129
|
|
|
117
130
|
// src/utils/mergeHeaders.ts
|
|
@@ -370,6 +383,10 @@ async function executeCoreFetch(config) {
|
|
|
370
383
|
if (headers) {
|
|
371
384
|
fetchInit.headers = headers;
|
|
372
385
|
}
|
|
386
|
+
} else if (containsFile(requestOptions.body)) {
|
|
387
|
+
fetchInit.body = objectToFormData(
|
|
388
|
+
requestOptions.body
|
|
389
|
+
);
|
|
373
390
|
} else {
|
|
374
391
|
fetchInit.body = requestOptions.body;
|
|
375
392
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -49,6 +49,14 @@ function generateTags(path) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
// src/utils/isJsonBody.ts
|
|
52
|
+
function containsFile(value) {
|
|
53
|
+
if (value instanceof File || value instanceof Blob) return true;
|
|
54
|
+
if (Array.isArray(value)) return value.some(containsFile);
|
|
55
|
+
if (value && typeof value === "object") {
|
|
56
|
+
return Object.values(value).some(containsFile);
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
52
60
|
function isJsonBody(body) {
|
|
53
61
|
if (body === null || body === void 0) return false;
|
|
54
62
|
if (body instanceof FormData) return false;
|
|
@@ -57,7 +65,11 @@ function isJsonBody(body) {
|
|
|
57
65
|
if (body instanceof URLSearchParams) return false;
|
|
58
66
|
if (body instanceof ReadableStream) return false;
|
|
59
67
|
if (typeof body === "string") return false;
|
|
60
|
-
|
|
68
|
+
if (typeof body === "object") {
|
|
69
|
+
if (containsFile(body)) return false;
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
61
73
|
}
|
|
62
74
|
|
|
63
75
|
// src/utils/mergeHeaders.ts
|
|
@@ -316,6 +328,10 @@ async function executeCoreFetch(config) {
|
|
|
316
328
|
if (headers) {
|
|
317
329
|
fetchInit.headers = headers;
|
|
318
330
|
}
|
|
331
|
+
} else if (containsFile(requestOptions.body)) {
|
|
332
|
+
fetchInit.body = objectToFormData(
|
|
333
|
+
requestOptions.body
|
|
334
|
+
);
|
|
319
335
|
} else {
|
|
320
336
|
fetchInit.body = requestOptions.body;
|
|
321
337
|
}
|
|
@@ -1576,6 +1592,7 @@ export {
|
|
|
1576
1592
|
applyMiddlewares,
|
|
1577
1593
|
buildUrl,
|
|
1578
1594
|
composeMiddlewares,
|
|
1595
|
+
containsFile,
|
|
1579
1596
|
createClient,
|
|
1580
1597
|
createEventEmitter,
|
|
1581
1598
|
createInfiniteReadController,
|