@gravity-ui/data-source 0.5.0 → 0.6.0
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/build/cjs/core/index.d.ts +1 -1
- package/build/cjs/core/index.js.map +1 -1
- package/build/cjs/core/types/DataManger.js.map +1 -1
- package/build/cjs/core/types/DataSource.d.ts +21 -17
- package/build/cjs/core/types/DataSource.js.map +1 -1
- package/build/cjs/core/utils/getError.js.map +1 -1
- package/build/cjs/core/utils/getStatus.js.map +1 -1
- package/build/cjs/core/utils/hasTag.js.map +1 -1
- package/build/cjs/core/utils/skipContext.d.ts +24 -0
- package/build/cjs/core/utils/skipContext.js +24 -0
- package/build/cjs/core/utils/skipContext.js.map +1 -1
- package/build/cjs/react-query/ClientDataManager.d.ts +4 -4
- package/build/cjs/react-query/ClientDataManager.js +3 -7
- package/build/cjs/react-query/ClientDataManager.js.map +1 -1
- package/build/cjs/react-query/hooks/useQueryContext.d.ts +1 -1
- package/build/cjs/react-query/hooks/useQueryContext.js.map +1 -1
- package/build/cjs/react-query/hooks/useQueryData.d.ts +1 -1
- package/build/cjs/react-query/hooks/useQueryData.js.map +1 -1
- package/build/cjs/react-query/hooks/useRefetchInterval.d.ts +7 -7
- package/build/cjs/react-query/hooks/useRefetchInterval.js +14 -14
- package/build/cjs/react-query/hooks/useRefetchInterval.js.map +1 -1
- package/build/cjs/react-query/impl/infinite/factory.d.ts +1 -1
- package/build/cjs/react-query/impl/infinite/factory.js.map +1 -1
- package/build/cjs/react-query/impl/infinite/hooks.d.ts +2 -4
- package/build/cjs/react-query/impl/infinite/hooks.js +24 -26
- package/build/cjs/react-query/impl/infinite/hooks.js.map +1 -1
- package/build/cjs/react-query/impl/infinite/types.d.ts +11 -12
- package/build/cjs/react-query/impl/infinite/types.js.map +1 -1
- package/build/cjs/react-query/impl/infinite/utils.js +44 -7
- package/build/cjs/react-query/impl/infinite/utils.js.map +1 -1
- package/build/cjs/react-query/impl/plain/factory.d.ts +1 -1
- package/build/cjs/react-query/impl/plain/factory.js.map +1 -1
- package/build/cjs/react-query/impl/plain/hooks.d.ts +2 -5
- package/build/cjs/react-query/impl/plain/hooks.js +20 -22
- package/build/cjs/react-query/impl/plain/hooks.js.map +1 -1
- package/build/cjs/react-query/impl/plain/types.d.ts +7 -6
- package/build/cjs/react-query/impl/plain/types.js.map +1 -1
- package/build/cjs/react-query/impl/plain/utils.js +42 -4
- package/build/cjs/react-query/impl/plain/utils.js.map +1 -1
- package/build/cjs/react-query/impl/utils.d.ts +4 -0
- package/build/cjs/react-query/impl/utils.js +27 -0
- package/build/cjs/react-query/impl/utils.js.map +1 -0
- package/build/cjs/react-query/index.d.ts +3 -1
- package/build/cjs/react-query/index.js.map +1 -1
- package/build/cjs/react-query/types/options.d.ts +5 -0
- package/build/cjs/react-query/types/options.js +6 -0
- package/build/cjs/react-query/types/options.js.map +1 -0
- package/build/cjs/react-query/types/refetch-interval.d.ts +0 -7
- package/build/cjs/react-query/types/refetch-interval.js.map +1 -1
- package/build/cjs/react-query/utils/getProgressiveRefetch.d.ts +7 -2
- package/build/cjs/react-query/utils/getProgressiveRefetch.js +5 -4
- package/build/cjs/react-query/utils/getProgressiveRefetch.js.map +1 -1
- package/build/esm/core/index.d.ts +1 -1
- package/build/esm/core/index.js.map +1 -1
- package/build/esm/core/types/DataManger.js.map +1 -1
- package/build/esm/core/types/DataSource.d.ts +21 -17
- package/build/esm/core/types/DataSource.js.map +1 -1
- package/build/esm/core/utils/getError.js.map +1 -1
- package/build/esm/core/utils/getStatus.js.map +1 -1
- package/build/esm/core/utils/hasTag.js.map +1 -1
- package/build/esm/core/utils/skipContext.d.ts +24 -0
- package/build/esm/core/utils/skipContext.js +24 -0
- package/build/esm/core/utils/skipContext.js.map +1 -1
- package/build/esm/react-query/ClientDataManager.d.ts +4 -4
- package/build/esm/react-query/ClientDataManager.js +3 -7
- package/build/esm/react-query/ClientDataManager.js.map +1 -1
- package/build/esm/react-query/hooks/useQueryContext.d.ts +1 -1
- package/build/esm/react-query/hooks/useQueryContext.js.map +1 -1
- package/build/esm/react-query/hooks/useQueryData.d.ts +1 -1
- package/build/esm/react-query/hooks/useQueryData.js.map +1 -1
- package/build/esm/react-query/hooks/useRefetchInterval.d.ts +7 -7
- package/build/esm/react-query/hooks/useRefetchInterval.js +14 -14
- package/build/esm/react-query/hooks/useRefetchInterval.js.map +1 -1
- package/build/esm/react-query/impl/infinite/factory.d.ts +1 -1
- package/build/esm/react-query/impl/infinite/factory.js.map +1 -1
- package/build/esm/react-query/impl/infinite/hooks.d.ts +2 -4
- package/build/esm/react-query/impl/infinite/hooks.js +24 -25
- package/build/esm/react-query/impl/infinite/hooks.js.map +1 -1
- package/build/esm/react-query/impl/infinite/types.d.ts +11 -12
- package/build/esm/react-query/impl/infinite/types.js.map +1 -1
- package/build/esm/react-query/impl/infinite/utils.js +44 -7
- package/build/esm/react-query/impl/infinite/utils.js.map +1 -1
- package/build/esm/react-query/impl/plain/factory.d.ts +1 -1
- package/build/esm/react-query/impl/plain/factory.js.map +1 -1
- package/build/esm/react-query/impl/plain/hooks.d.ts +2 -5
- package/build/esm/react-query/impl/plain/hooks.js +20 -21
- package/build/esm/react-query/impl/plain/hooks.js.map +1 -1
- package/build/esm/react-query/impl/plain/types.d.ts +7 -6
- package/build/esm/react-query/impl/plain/types.js.map +1 -1
- package/build/esm/react-query/impl/plain/utils.js +42 -4
- package/build/esm/react-query/impl/plain/utils.js.map +1 -1
- package/build/esm/react-query/impl/utils.d.ts +4 -0
- package/build/esm/react-query/impl/utils.js +21 -0
- package/build/esm/react-query/impl/utils.js.map +1 -0
- package/build/esm/react-query/index.d.ts +3 -1
- package/build/esm/react-query/index.js.map +1 -1
- package/build/esm/react-query/types/options.d.ts +5 -0
- package/build/esm/react-query/types/options.js +2 -0
- package/build/esm/react-query/types/options.js.map +1 -0
- package/build/esm/react-query/types/refetch-interval.d.ts +0 -7
- package/build/esm/react-query/types/refetch-interval.js.map +1 -1
- package/build/esm/react-query/utils/getProgressiveRefetch.d.ts +7 -2
- package/build/esm/react-query/utils/getProgressiveRefetch.js +5 -4
- package/build/esm/react-query/utils/getProgressiveRefetch.js.map +1 -1
- package/package.json +1 -1
- package/build/cjs/react-query/types/index.d.ts +0 -2
- package/build/cjs/react-query/types/index.js +0 -28
- package/build/cjs/react-query/types/index.js.map +0 -1
- package/build/esm/react-query/types/index.d.ts +0 -2
- package/build/esm/react-query/types/index.js +0 -3
- package/build/esm/react-query/types/index.js.map +0 -1
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import type { DefaultError, InfiniteData,
|
|
1
|
+
import type { DefaultError, InfiniteData, InfiniteQueryObserverOptions, InfiniteQueryObserverResult, QueryFunctionContext, QueryKey } from '@tanstack/react-query';
|
|
2
2
|
import type { Overwrite } from 'utility-types';
|
|
3
|
-
import type { ActualData, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
4
|
-
import type { QueryDataSourceContext } from '../../types';
|
|
5
|
-
import type {
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
export type InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, InfiniteQueryObserverExtendedOptions<TResponse, TError, InfiniteData<ActualData<TData, TResponse>, Partial<TRequest>>, TResponse, DataSourceKey, Partial<TRequest>>, ResultWrapper<InfiniteQueryObserverResult<InfiniteData<ActualData<TData, TResponse>, Partial<TRequest>>, TError>, TRequest, TResponse, TData, TError>, QueryFunctionContext<DataSourceKey, Partial<TRequest>>> & {
|
|
3
|
+
import type { ActualData, ActualResponse, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
4
|
+
import type { QueryDataSourceContext } from '../../types/base';
|
|
5
|
+
import type { QueryDataAdditionalOptions } from '../../types/options';
|
|
6
|
+
export type InfiniteQueryObserverExtendedOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = Overwrite<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, QueryDataAdditionalOptions<TQueryFnData, TError, InfiniteData<TQueryData, TPageParam>, TQueryKey>>;
|
|
7
|
+
export type InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, TErrorResponse, InfiniteQueryObserverExtendedOptions<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, NoInfer<TError>, InfiniteData<ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>, Partial<NoInfer<TRequest>>>, ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, DataSourceKey, Partial<NoInfer<TRequest>>>, ResultWrapper<InfiniteQueryObserverResult<InfiniteData<ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>, Partial<NoInfer<TRequest>>>, NoInfer<TError>>, NoInfer<TRequest>, NoInfer<TResponse>, NoInfer<TData>, NoInfer<TError>, NoInfer<TErrorResponse>>, QueryFunctionContext<DataSourceKey, Partial<NoInfer<TRequest>>>> & {
|
|
9
8
|
type: 'infinite';
|
|
10
|
-
next: (lastPage: TResponse
|
|
11
|
-
prev?: (firstPage: TResponse
|
|
9
|
+
next: (lastPage: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, allPages: Array<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>>) => Partial<NoInfer<TRequest>> | undefined | null;
|
|
10
|
+
prev?: (firstPage: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, allPages: Array<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>>) => Partial<NoInfer<TRequest>> | undefined | null;
|
|
12
11
|
};
|
|
13
|
-
export type AnyInfiniteQueryDataSource = InfiniteQueryDataSource<any, any, any, any, any>;
|
|
12
|
+
export type AnyInfiniteQueryDataSource = InfiniteQueryDataSource<any, any, any, any, any, any>;
|
|
14
13
|
export type AnyPageParam = Partial<any>;
|
|
15
|
-
type ResultWrapper<TResult, TRequest, TResponse, TData, TError> = TResult extends InfiniteQueryObserverResult<InfiniteData<ActualData<TData,
|
|
14
|
+
type ResultWrapper<TResult, TRequest, TResponse, TData, TError, TErrorResponse> = TResult extends InfiniteQueryObserverResult<InfiniteData<ActualData<TResponse, TData, TErrorResponse>, Partial<TRequest>>, TError> ? Overwrite<TResult, {
|
|
16
15
|
status: DataLoaderStatus;
|
|
17
|
-
data: Array<FlatArray<Array<ActualData<TData,
|
|
16
|
+
data: Array<FlatArray<Array<ActualData<TResponse, TData, TErrorResponse>>, 1>>;
|
|
18
17
|
}> & {
|
|
19
18
|
originalStatus: TResult['status'];
|
|
20
19
|
originalData: TResult['data'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n DefaultError,\n InfiniteData,\n
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryFunctionContext,\n QueryKey,\n} from '@tanstack/react-query';\nimport type {Overwrite} from 'utility-types';\n\nimport type {\n ActualData,\n ActualResponse,\n DataLoaderStatus,\n DataSource,\n DataSourceKey,\n} from '../../../core';\nimport type {QueryDataSourceContext} from '../../types/base';\nimport type {QueryDataAdditionalOptions} from '../../types/options';\n\nexport type InfiniteQueryObserverExtendedOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = Overwrite<\n InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>,\n QueryDataAdditionalOptions<\n TQueryFnData,\n TError,\n InfiniteData<TQueryData, TPageParam>,\n TQueryKey\n >\n>;\n\nexport type InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> =\n DataSource<\n QueryDataSourceContext,\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n TErrorResponse,\n InfiniteQueryObserverExtendedOptions<\n ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n NoInfer<TError>,\n InfiniteData<\n ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>,\n Partial<NoInfer<TRequest>>\n >,\n ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n DataSourceKey,\n Partial<NoInfer<TRequest>>\n >,\n ResultWrapper<\n InfiniteQueryObserverResult<\n InfiniteData<\n ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>,\n Partial<NoInfer<TRequest>>\n >,\n NoInfer<TError>\n >,\n NoInfer<TRequest>,\n NoInfer<TResponse>,\n NoInfer<TData>,\n NoInfer<TError>,\n NoInfer<TErrorResponse>\n >,\n QueryFunctionContext<DataSourceKey, Partial<NoInfer<TRequest>>>\n > & {\n type: 'infinite';\n next: (\n lastPage: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n allPages: Array<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>>,\n ) => Partial<NoInfer<TRequest>> | undefined | null;\n prev?: (\n firstPage: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n allPages: Array<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>>,\n ) => Partial<NoInfer<TRequest>> | undefined | null;\n };\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyInfiniteQueryDataSource = InfiniteQueryDataSource<any, any, any, any, any, any>;\n\n// It is used instead of `Partial<DataSourceRequest<TDataSource>>` because TS can't calculate type\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyPageParam = Partial<any>;\n\ntype ResultWrapper<TResult, TRequest, TResponse, TData, TError, TErrorResponse> =\n TResult extends InfiniteQueryObserverResult<\n InfiniteData<ActualData<TResponse, TData, TErrorResponse>, Partial<TRequest>>,\n TError\n >\n ? Overwrite<\n TResult,\n {\n status: DataLoaderStatus;\n data: Array<FlatArray<Array<ActualData<TResponse, TData, TErrorResponse>>, 1>>;\n }\n > & {\n originalStatus: TResult['status'];\n originalData: TResult['data'];\n }\n : never;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -5,28 +5,65 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.composeOptions = void 0;
|
|
7
7
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
8
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
9
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
8
10
|
var _reactQuery = require("@tanstack/react-query");
|
|
9
11
|
var _core = require("../../../core");
|
|
12
|
+
var _utils = require("../utils");
|
|
10
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
14
|
var EMPTY_OBJECT = {};
|
|
12
15
|
var composeOptions = exports.composeOptions = function composeOptions(context, dataSource, params, options) {
|
|
13
16
|
var transformParams = dataSource.transformParams,
|
|
17
|
+
transformError = dataSource.transformError,
|
|
14
18
|
transformResponse = dataSource.transformResponse,
|
|
15
19
|
next = dataSource.next,
|
|
16
20
|
prev = dataSource.prev;
|
|
17
|
-
var queryFn = function
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
var queryFn = /*#__PURE__*/function () {
|
|
22
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(fetchContext) {
|
|
23
|
+
var request, paginatedRequest, response;
|
|
24
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
25
|
+
while (1) switch (_context.prev = _context.next) {
|
|
26
|
+
case 0:
|
|
27
|
+
request = transformParams ? transformParams(params) : params;
|
|
28
|
+
paginatedRequest = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, request), fetchContext.pageParam);
|
|
29
|
+
_context.prev = 2;
|
|
30
|
+
_context.next = 5;
|
|
31
|
+
return dataSource.fetch(context, fetchContext, paginatedRequest);
|
|
32
|
+
case 5:
|
|
33
|
+
response = _context.sent;
|
|
34
|
+
return _context.abrupt("return", (0, _utils.formatNullableValue)(response));
|
|
35
|
+
case 9:
|
|
36
|
+
_context.prev = 9;
|
|
37
|
+
_context.t0 = _context["catch"](2);
|
|
38
|
+
if (transformError) {
|
|
39
|
+
_context.next = 13;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
throw _context.t0;
|
|
43
|
+
case 13:
|
|
44
|
+
return _context.abrupt("return", (0, _utils.formatNullableValue)(transformError(_context.t0)));
|
|
45
|
+
case 14:
|
|
46
|
+
case "end":
|
|
47
|
+
return _context.stop();
|
|
48
|
+
}
|
|
49
|
+
}, _callee, null, [[2, 9]]);
|
|
50
|
+
}));
|
|
51
|
+
return function queryFn(_x) {
|
|
52
|
+
return _ref.apply(this, arguments);
|
|
53
|
+
};
|
|
54
|
+
}();
|
|
55
|
+
var selectPage = function selectPage(response) {
|
|
56
|
+
var actualResponse = (0, _utils.parseNullableValue)(response);
|
|
57
|
+
return transformResponse ? transformResponse(actualResponse) : actualResponse;
|
|
21
58
|
};
|
|
22
59
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
23
60
|
queryKey: (0, _core.composeFullKey)(dataSource, params),
|
|
24
61
|
queryFn: params === _core.idle ? _reactQuery.skipToken : queryFn,
|
|
25
|
-
select:
|
|
62
|
+
select: function select(data) {
|
|
26
63
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, data), {}, {
|
|
27
|
-
pages: data.pages.map(
|
|
64
|
+
pages: data.pages.map(selectPage)
|
|
28
65
|
});
|
|
29
|
-
}
|
|
66
|
+
},
|
|
30
67
|
initialPageParam: EMPTY_OBJECT,
|
|
31
68
|
getNextPageParam: next,
|
|
32
69
|
getPreviousPageParam: prev
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactQuery","require","_core","_interopRequireDefault","e","__esModule","default","EMPTY_OBJECT","composeOptions","exports","context","dataSource","params","options","transformParams","transformResponse","next","prev","queryFn","fetchContext","request","paginatedRequest","_objectSpread","pageParam","fetch","queryKey","composeFullKey","idle","skipToken","select","data","pages","map","
|
|
1
|
+
{"version":3,"names":["_reactQuery","require","_core","_utils","_interopRequireDefault","e","__esModule","default","EMPTY_OBJECT","composeOptions","exports","context","dataSource","params","options","transformParams","transformError","transformResponse","next","prev","queryFn","_ref","_asyncToGenerator","_regeneratorRuntime","mark","_callee","fetchContext","request","paginatedRequest","response","wrap","_callee$","_context","_objectSpread","pageParam","fetch","sent","abrupt","formatNullableValue","t0","stop","_x","apply","arguments","selectPage","actualResponse","parseNullableValue","queryKey","composeFullKey","idle","skipToken","select","data","pages","map","initialPageParam","getNextPageParam","getPreviousPageParam"],"sources":["utils.ts"],"sourcesContent":["import {skipToken} from '@tanstack/react-query';\nimport type {InfiniteData, QueryFunctionContext} from '@tanstack/react-query';\n\nimport {composeFullKey, idle} from '../../../core';\nimport type {\n DataSourceContext,\n DataSourceData,\n DataSourceError,\n DataSourceKey,\n DataSourceOptions,\n DataSourceParams,\n DataSourceResponse,\n} from '../../../core';\nimport type {nullSymbol, undefinedSymbol} from '../utils';\nimport {formatNullableValue, parseNullableValue} from '../utils';\n\nimport type {\n AnyInfiniteQueryDataSource,\n AnyPageParam,\n InfiniteQueryObserverExtendedOptions,\n} from './types';\n\nconst EMPTY_OBJECT = {};\n\nexport const composeOptions = <TDataSource extends AnyInfiniteQueryDataSource>(\n context: DataSourceContext<TDataSource>,\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n options?: Partial<DataSourceOptions<TDataSource>>,\n): InfiniteQueryObserverExtendedOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n InfiniteData<DataSourceData<TDataSource>, AnyPageParam>,\n DataSourceResponse<TDataSource>,\n DataSourceKey,\n AnyPageParam\n> => {\n const {transformParams, transformError, transformResponse, next, prev} = dataSource;\n\n const queryFn = async (\n fetchContext: QueryFunctionContext<DataSourceKey, AnyPageParam>,\n ): Promise<DataSourceResponse<TDataSource> | typeof undefinedSymbol | typeof nullSymbol> => {\n const request = transformParams ? transformParams(params) : params;\n const paginatedRequest = {...request, ...fetchContext.pageParam};\n\n try {\n const response = await dataSource.fetch(context, fetchContext, paginatedRequest);\n\n return formatNullableValue(response);\n } catch (error) {\n if (!transformError) {\n throw error;\n }\n\n return formatNullableValue(transformError(error));\n }\n };\n\n const selectPage = (\n response: DataSourceResponse<TDataSource> | typeof undefinedSymbol | typeof nullSymbol,\n ): DataSourceData<TDataSource> => {\n const actualResponse = parseNullableValue(response);\n\n return transformResponse ? transformResponse(actualResponse) : actualResponse;\n };\n\n return {\n queryKey: composeFullKey(dataSource, params),\n queryFn: params === idle ? skipToken : queryFn,\n select: (data) => ({...data, pages: data.pages.map(selectPage)}),\n initialPageParam: EMPTY_OBJECT,\n getNextPageParam: next,\n getPreviousPageParam: prev,\n ...dataSource.options,\n ...options,\n };\n};\n"],"mappings":";;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAGA,IAAAC,KAAA,GAAAD,OAAA;AAWA,IAAAE,MAAA,GAAAF,OAAA;AAAgE,SAAAG,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAQhE,IAAMG,YAAY,GAAG,CAAC,CAAC;AAEhB,IAAMC,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,SAAjBA,cAAcA,CACvBE,OAAuC,EACvCC,UAAuB,EACvBC,MAAqC,EACrCC,OAAiD,EAQhD;EACD,IAAOC,eAAe,GAAmDH,UAAU,CAA5EG,eAAe;IAAEC,cAAc,GAAmCJ,UAAU,CAA3DI,cAAc;IAAEC,iBAAiB,GAAgBL,UAAU,CAA3CK,iBAAiB;IAAEC,IAAI,GAAUN,UAAU,CAAxBM,IAAI;IAAEC,IAAI,GAAIP,UAAU,CAAlBO,IAAI;EAErE,IAAMC,OAAO;IAAA,IAAAC,IAAA,OAAAC,0BAAA,gBAAAC,oBAAA,CAAAC,IAAA,CAAG,SAAAC,QACZC,YAA+D;MAAA,IAAAC,OAAA,EAAAC,gBAAA,EAAAC,QAAA;MAAA,OAAAN,oBAAA,CAAAO,IAAA,UAAAC,SAAAC,QAAA;QAAA,kBAAAA,QAAA,CAAAb,IAAA,GAAAa,QAAA,CAAAd,IAAA;UAAA;YAEzDS,OAAO,GAAGZ,eAAe,GAAGA,eAAe,CAACF,MAAM,CAAC,GAAGA,MAAM;YAC5De,gBAAgB,OAAAK,sBAAA,MAAAA,sBAAA,MAAON,OAAO,GAAKD,YAAY,CAACQ,SAAS;YAAAF,QAAA,CAAAb,IAAA;YAAAa,QAAA,CAAAd,IAAA;YAAA,OAGpCN,UAAU,CAACuB,KAAK,CAACxB,OAAO,EAAEe,YAAY,EAAEE,gBAAgB,CAAC;UAAA;YAA1EC,QAAQ,GAAAG,QAAA,CAAAI,IAAA;YAAA,OAAAJ,QAAA,CAAAK,MAAA,WAEP,IAAAC,0BAAmB,EAACT,QAAQ,CAAC;UAAA;YAAAG,QAAA,CAAAb,IAAA;YAAAa,QAAA,CAAAO,EAAA,GAAAP,QAAA;YAAA,IAE/BhB,cAAc;cAAAgB,QAAA,CAAAd,IAAA;cAAA;YAAA;YAAA,MAAAc,QAAA,CAAAO,EAAA;UAAA;YAAA,OAAAP,QAAA,CAAAK,MAAA,WAIZ,IAAAC,0BAAmB,EAACtB,cAAc,CAAAgB,QAAA,CAAAO,EAAM,CAAC,CAAC;UAAA;UAAA;YAAA,OAAAP,QAAA,CAAAQ,IAAA;QAAA;MAAA,GAAAf,OAAA;IAAA,CAExD;IAAA,gBAjBKL,OAAOA,CAAAqB,EAAA;MAAA,OAAApB,IAAA,CAAAqB,KAAA,OAAAC,SAAA;IAAA;EAAA,GAiBZ;EAED,IAAMC,UAAU,GAAG,SAAbA,UAAUA,CACZf,QAAsF,EACxD;IAC9B,IAAMgB,cAAc,GAAG,IAAAC,yBAAkB,EAACjB,QAAQ,CAAC;IAEnD,OAAOZ,iBAAiB,GAAGA,iBAAiB,CAAC4B,cAAc,CAAC,GAAGA,cAAc;EACjF,CAAC;EAED,WAAAZ,sBAAA,MAAAA,sBAAA;IACIc,QAAQ,EAAE,IAAAC,oBAAc,EAACpC,UAAU,EAAEC,MAAM,CAAC;IAC5CO,OAAO,EAAEP,MAAM,KAAKoC,UAAI,GAAGC,qBAAS,GAAG9B,OAAO;IAC9C+B,MAAM,EAAE,SAARA,MAAMA,CAAGC,IAAI;MAAA,WAAAnB,sBAAA,MAAAA,sBAAA,MAAUmB,IAAI;QAAEC,KAAK,EAAED,IAAI,CAACC,KAAK,CAACC,GAAG,CAACV,UAAU;MAAC;IAAA,CAAE;IAChEW,gBAAgB,EAAE/C,YAAY;IAC9BgD,gBAAgB,EAAEtC,IAAI;IACtBuC,oBAAoB,EAAEtC;EAAI,GACvBP,UAAU,CAACE,OAAO,GAClBA,OAAO;AAElB,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { PlainQueryDataSource } from './types';
|
|
2
|
-
export declare const makePlainQueryDataSource: <TParams, TRequest, TResponse, TData, TError>(config: Omit<PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError>, "type">) => PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError>;
|
|
2
|
+
export declare const makePlainQueryDataSource: <TParams, TRequest, TResponse, TData, TError, TErrorResponse>(config: Omit<PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>, "type">) => PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["makePlainQueryDataSource","exports","config","_objectSpread","type"],"sources":["factory.ts"],"sourcesContent":["import type {PlainQueryDataSource} from './types';\n\nexport const makePlainQueryDataSource =
|
|
1
|
+
{"version":3,"names":["makePlainQueryDataSource","exports","config","_objectSpread","type"],"sources":["factory.ts"],"sourcesContent":["import type {PlainQueryDataSource} from './types';\n\nexport const makePlainQueryDataSource = <\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n TErrorResponse,\n>(\n config: Omit<\n PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>,\n 'type'\n >,\n): PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> => ({\n ...config,\n type: 'plain',\n});\n"],"mappings":";;;;;;;;AAEO,IAAMA,wBAAwB,GAAAC,OAAA,CAAAD,wBAAA,GAAG,SAA3BA,wBAAwBA,CAQjCE,MAGC;EAAA,WAAAC,sBAAA,MAAAA,sBAAA,MAEED,MAAM;IACTE,IAAI,EAAE;EAAO;AAAA,CACf","ignoreList":[]}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import type { AnyQueryDataSource } from '../../types';
|
|
4
|
-
import type { AnyPlainQueryDataSource, QueryObserverExtendedOptions } from './types';
|
|
1
|
+
import type { DataSourceContext, DataSourceOptions, DataSourceParams, DataSourceState } from '../../../core';
|
|
2
|
+
import type { AnyPlainQueryDataSource } from './types';
|
|
5
3
|
export declare const usePlainQueryData: <TDataSource extends AnyPlainQueryDataSource>(context: DataSourceContext<TDataSource>, dataSource: TDataSource, params: DataSourceParams<TDataSource>, options?: Partial<DataSourceOptions<TDataSource>>) => DataSourceState<TDataSource>;
|
|
6
|
-
export declare function useQueryDataOptions<TDataSource extends AnyQueryDataSource>(composedOptions: QueryObserverExtendedOptions<DataSourceResponse<TDataSource>, DataSourceError<TDataSource>, DataSourceData<TDataSource>, DataSourceResponse<TDataSource>, DataSourceKey>): QueryObserverOptions<DataSourceResponse<TDataSource>, DataSourceError<TDataSource>, DataSourceData<TDataSource>, DataSourceResponse<TDataSource>, DataSourceKey>;
|
|
@@ -4,35 +4,33 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.usePlainQueryData = void 0;
|
|
7
|
-
exports.useQueryDataOptions = useQueryDataOptions;
|
|
8
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
9
7
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
8
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
9
|
var _reactQuery = require("@tanstack/react-query");
|
|
11
10
|
var _useRefetchInterval2 = require("../../hooks/useRefetchInterval");
|
|
12
11
|
var _normalizeStatus = require("../../utils/normalizeStatus");
|
|
13
12
|
var _utils = require("./utils");
|
|
14
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
var _excluded = ["
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, result), {}, {
|
|
21
|
-
status: (0, _normalizeStatus.normalizeStatus)(result.status, result.fetchStatus),
|
|
22
|
-
originalStatus: result.status
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
function useQueryDataOptions(composedOptions) {
|
|
26
|
-
var _ref = composedOptions || {},
|
|
27
|
-
refetchIntervalOption = _ref.refetchInterval,
|
|
28
|
-
queryFnOption = _ref.queryFn,
|
|
29
|
-
restOptions = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
14
|
+
var _excluded = ["queryFn", "refetchInterval"];
|
|
15
|
+
var usePlainQueryDataOptions = function usePlainQueryDataOptions(composedOptions) {
|
|
16
|
+
var queryFnOption = composedOptions.queryFn,
|
|
17
|
+
refetchIntervalOption = composedOptions.refetchInterval,
|
|
18
|
+
restOptions = (0, _objectWithoutProperties2.default)(composedOptions, _excluded);
|
|
30
19
|
var _useRefetchInterval = (0, _useRefetchInterval2.useRefetchInterval)(refetchIntervalOption, queryFnOption),
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
queryFn = _useRefetchInterval.queryFn,
|
|
21
|
+
refetchInterval = _useRefetchInterval.refetchInterval;
|
|
33
22
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, restOptions), {}, {
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
queryFn: queryFn,
|
|
24
|
+
refetchInterval: refetchInterval
|
|
36
25
|
});
|
|
37
|
-
}
|
|
26
|
+
};
|
|
27
|
+
var usePlainQueryData = exports.usePlainQueryData = function usePlainQueryData(context, dataSource, params, options) {
|
|
28
|
+
var extendedOptions = (0, _utils.composeOptions)(context, dataSource, params, options);
|
|
29
|
+
var composedOptions = usePlainQueryDataOptions(extendedOptions);
|
|
30
|
+
var state = (0, _reactQuery.useQuery)(composedOptions);
|
|
31
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, state), {}, {
|
|
32
|
+
status: (0, _normalizeStatus.normalizeStatus)(state.status, state.fetchStatus),
|
|
33
|
+
originalStatus: state.status
|
|
34
|
+
});
|
|
35
|
+
};
|
|
38
36
|
// #sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactQuery","require","_useRefetchInterval2","_normalizeStatus","_utils","_interopRequireDefault","e","__esModule","default","
|
|
1
|
+
{"version":3,"names":["_reactQuery","require","_useRefetchInterval2","_normalizeStatus","_utils","_interopRequireDefault","e","__esModule","default","usePlainQueryDataOptions","composedOptions","queryFnOption","queryFn","refetchIntervalOption","refetchInterval","restOptions","_objectWithoutProperties","_excluded","_useRefetchInterval","useRefetchInterval","_objectSpread","usePlainQueryData","exports","context","dataSource","params","options","extendedOptions","composeOptions","state","useQuery","status","normalizeStatus","fetchStatus","originalStatus"],"sources":["hooks.ts"],"sourcesContent":["import {type QueryObserverOptions, useQuery} from '@tanstack/react-query';\n\nimport type {\n DataSourceContext,\n DataSourceData,\n DataSourceError,\n DataSourceKey,\n DataSourceOptions,\n DataSourceParams,\n DataSourceResponse,\n DataSourceState,\n} from '../../../core';\nimport {useRefetchInterval} from '../../hooks/useRefetchInterval';\nimport {normalizeStatus} from '../../utils/normalizeStatus';\n\nimport type {AnyPlainQueryDataSource, QueryObserverExtendedOptions} from './types';\nimport {composeOptions} from './utils';\n\nconst usePlainQueryDataOptions = <TDataSource extends AnyPlainQueryDataSource>(\n composedOptions: QueryObserverExtendedOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n DataSourceData<TDataSource>,\n DataSourceResponse<TDataSource>,\n DataSourceKey\n >,\n): QueryObserverOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n DataSourceData<TDataSource>,\n DataSourceResponse<TDataSource>,\n DataSourceKey\n> => {\n const {\n queryFn: queryFnOption,\n refetchInterval: refetchIntervalOption,\n ...restOptions\n } = composedOptions;\n\n const {queryFn, refetchInterval} = useRefetchInterval(refetchIntervalOption, queryFnOption);\n\n return {...restOptions, queryFn, refetchInterval};\n};\n\nexport const usePlainQueryData = <TDataSource extends AnyPlainQueryDataSource>(\n context: DataSourceContext<TDataSource>,\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n options?: Partial<DataSourceOptions<TDataSource>>,\n): DataSourceState<TDataSource> => {\n const extendedOptions = composeOptions(context, dataSource, params, options);\n const composedOptions = usePlainQueryDataOptions(extendedOptions);\n const state = useQuery(composedOptions);\n\n return {\n ...state,\n status: normalizeStatus(state.status, state.fetchStatus),\n originalStatus: state.status,\n } as DataSourceState<TDataSource>;\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAYA,IAAAC,oBAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AAGA,IAAAG,MAAA,GAAAH,OAAA;AAAsC,SAAAI,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;;AAEtC,IAAMG,wBAAwB,GAAG,SAA3BA,wBAAwBA,CAC1BC,eAMC,EAOA;EACD,IACaC,aAAa,GAGtBD,eAAe,CAHfE,OAAO;IACUC,qBAAqB,GAEtCH,eAAe,CAFfI,eAAe;IACZC,WAAW,OAAAC,iCAAA,EACdN,eAAe,EAAAO,SAAA;EAEnB,IAAAC,mBAAA,GAAmC,IAAAC,uCAAkB,EAACN,qBAAqB,EAAEF,aAAa,CAAC;IAApFC,OAAO,GAAAM,mBAAA,CAAPN,OAAO;IAAEE,eAAe,GAAAI,mBAAA,CAAfJ,eAAe;EAE/B,WAAAM,sBAAA,MAAAA,sBAAA,MAAWL,WAAW;IAAEH,OAAO,EAAPA,OAAO;IAAEE,eAAe,EAAfA;EAAe;AACpD,CAAC;AAEM,IAAMO,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAAG,SAApBA,iBAAiBA,CAC1BE,OAAuC,EACvCC,UAAuB,EACvBC,MAAqC,EACrCC,OAAiD,EAClB;EAC/B,IAAMC,eAAe,GAAG,IAAAC,qBAAc,EAACL,OAAO,EAAEC,UAAU,EAAEC,MAAM,EAAEC,OAAO,CAAC;EAC5E,IAAMhB,eAAe,GAAGD,wBAAwB,CAACkB,eAAe,CAAC;EACjE,IAAME,KAAK,GAAG,IAAAC,oBAAQ,EAACpB,eAAe,CAAC;EAEvC,WAAAU,sBAAA,MAAAA,sBAAA,MACOS,KAAK;IACRE,MAAM,EAAE,IAAAC,gCAAe,EAACH,KAAK,CAACE,MAAM,EAAEF,KAAK,CAACI,WAAW,CAAC;IACxDC,cAAc,EAAEL,KAAK,CAACE;EAAM;AAEpC,CAAC","ignoreList":[]}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { DefaultError, QueryFunctionContext, QueryKey, QueryObserverOptions, QueryObserverResult } from '@tanstack/react-query';
|
|
2
2
|
import type { Overwrite } from 'utility-types';
|
|
3
|
-
import type { ActualData, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
export type
|
|
3
|
+
import type { ActualData, ActualResponse, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
4
|
+
import type { QueryDataSourceContext } from '../../types/base';
|
|
5
|
+
import type { QueryDataAdditionalOptions } from '../../types/options';
|
|
6
|
+
export type QueryObserverExtendedOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = never> = Overwrite<QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, QueryDataAdditionalOptions<TQueryFnData, TError, TQueryData, TQueryKey>>;
|
|
7
|
+
export type PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, TErrorResponse, QueryObserverExtendedOptions<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, NoInfer<TError>, ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>, ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, DataSourceKey>, ResultWrapper<QueryObserverResult<ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>, NoInfer<TError>>, NoInfer<TResponse>, NoInfer<TData>, NoInfer<TError>, NoInfer<TErrorResponse>>, QueryFunctionContext<DataSourceKey>> & {
|
|
7
8
|
type: 'plain';
|
|
8
9
|
};
|
|
9
|
-
export type AnyPlainQueryDataSource = PlainQueryDataSource<any, any, any, any, any>;
|
|
10
|
-
type ResultWrapper<TResult, TResponse, TData, TError> = TResult extends QueryObserverResult<ActualData<TData,
|
|
10
|
+
export type AnyPlainQueryDataSource = PlainQueryDataSource<any, any, any, any, any, any>;
|
|
11
|
+
type ResultWrapper<TResult, TResponse, TData, TError, TErrorResponse> = TResult extends QueryObserverResult<ActualData<TResponse, TData, TErrorResponse>, TError> ? Overwrite<TResult, {
|
|
11
12
|
status: DataLoaderStatus;
|
|
12
13
|
}> & {
|
|
13
14
|
originalStatus: TResult['status'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n DefaultError,\n QueryFunctionContext,\n QueryKey,\n QueryObserverOptions,\n QueryObserverResult,\n} from '@tanstack/react-query';\nimport type {Overwrite} from 'utility-types';\n\nimport type {ActualData
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n DefaultError,\n QueryFunctionContext,\n QueryKey,\n QueryObserverOptions,\n QueryObserverResult,\n} from '@tanstack/react-query';\nimport type {Overwrite} from 'utility-types';\n\nimport type {\n ActualData,\n ActualResponse,\n DataLoaderStatus,\n DataSource,\n DataSourceKey,\n} from '../../../core';\nimport type {QueryDataSourceContext} from '../../types/base';\nimport type {QueryDataAdditionalOptions} from '../../types/options';\n\nexport type QueryObserverExtendedOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n> = Overwrite<\n QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>,\n QueryDataAdditionalOptions<TQueryFnData, TError, TQueryData, TQueryKey>\n>;\n\nexport type PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> =\n DataSource<\n QueryDataSourceContext,\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n TErrorResponse,\n QueryObserverExtendedOptions<\n ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n NoInfer<TError>,\n ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>,\n ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n DataSourceKey\n >,\n ResultWrapper<\n QueryObserverResult<\n ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>,\n NoInfer<TError>\n >,\n NoInfer<TResponse>,\n NoInfer<TData>,\n NoInfer<TError>,\n NoInfer<TErrorResponse>\n >,\n QueryFunctionContext<DataSourceKey>\n > & {\n type: 'plain';\n };\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyPlainQueryDataSource = PlainQueryDataSource<any, any, any, any, any, any>;\n\ntype ResultWrapper<TResult, TResponse, TData, TError, TErrorResponse> =\n TResult extends QueryObserverResult<ActualData<TResponse, TData, TErrorResponse>, TError>\n ? Overwrite<TResult, {status: DataLoaderStatus}> & {originalStatus: TResult['status']}\n : never;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -5,18 +5,56 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.composeOptions = void 0;
|
|
7
7
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
8
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
9
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
8
10
|
var _reactQuery = require("@tanstack/react-query");
|
|
9
11
|
var _core = require("../../../core");
|
|
12
|
+
var _utils = require("../utils");
|
|
10
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
14
|
var composeOptions = exports.composeOptions = function composeOptions(context, dataSource, params, options) {
|
|
12
|
-
var transformParams = dataSource.transformParams
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
var transformParams = dataSource.transformParams,
|
|
16
|
+
transformResponse = dataSource.transformResponse,
|
|
17
|
+
transformError = dataSource.transformError;
|
|
18
|
+
var queryFn = /*#__PURE__*/function () {
|
|
19
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(fetchContext) {
|
|
20
|
+
var response;
|
|
21
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
22
|
+
while (1) switch (_context.prev = _context.next) {
|
|
23
|
+
case 0:
|
|
24
|
+
_context.prev = 0;
|
|
25
|
+
_context.next = 3;
|
|
26
|
+
return dataSource.fetch(context, fetchContext, transformParams ? transformParams(params) : params);
|
|
27
|
+
case 3:
|
|
28
|
+
response = _context.sent;
|
|
29
|
+
return _context.abrupt("return", (0, _utils.formatNullableValue)(response));
|
|
30
|
+
case 7:
|
|
31
|
+
_context.prev = 7;
|
|
32
|
+
_context.t0 = _context["catch"](0);
|
|
33
|
+
if (transformError) {
|
|
34
|
+
_context.next = 11;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
throw _context.t0;
|
|
38
|
+
case 11:
|
|
39
|
+
return _context.abrupt("return", (0, _utils.formatNullableValue)(transformError(_context.t0)));
|
|
40
|
+
case 12:
|
|
41
|
+
case "end":
|
|
42
|
+
return _context.stop();
|
|
43
|
+
}
|
|
44
|
+
}, _callee, null, [[0, 7]]);
|
|
45
|
+
}));
|
|
46
|
+
return function queryFn(_x) {
|
|
47
|
+
return _ref.apply(this, arguments);
|
|
48
|
+
};
|
|
49
|
+
}();
|
|
50
|
+
var select = function select(response) {
|
|
51
|
+
var actualResponse = (0, _utils.parseNullableValue)(response);
|
|
52
|
+
return transformResponse ? transformResponse(actualResponse) : actualResponse;
|
|
15
53
|
};
|
|
16
54
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
17
55
|
queryKey: (0, _core.composeFullKey)(dataSource, params),
|
|
18
56
|
queryFn: params === _core.idle ? _reactQuery.skipToken : queryFn,
|
|
19
|
-
select:
|
|
57
|
+
select: select
|
|
20
58
|
}, dataSource.options), options);
|
|
21
59
|
};
|
|
22
60
|
// #sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactQuery","require","_core","_interopRequireDefault","e","__esModule","default","composeOptions","exports","context","dataSource","params","options","transformParams","queryFn","fetchContext","fetch","
|
|
1
|
+
{"version":3,"names":["_reactQuery","require","_core","_utils","_interopRequireDefault","e","__esModule","default","composeOptions","exports","context","dataSource","params","options","transformParams","transformResponse","transformError","queryFn","_ref","_asyncToGenerator","_regeneratorRuntime","mark","_callee","fetchContext","response","wrap","_callee$","_context","prev","next","fetch","sent","abrupt","formatNullableValue","t0","stop","_x","apply","arguments","select","actualResponse","parseNullableValue","_objectSpread","queryKey","composeFullKey","idle","skipToken"],"sources":["utils.ts"],"sourcesContent":["import {type QueryFunctionContext, skipToken} from '@tanstack/react-query';\n\nimport {composeFullKey, idle} from '../../../core';\nimport type {\n DataSourceContext,\n DataSourceData,\n DataSourceError,\n DataSourceKey,\n DataSourceOptions,\n DataSourceParams,\n DataSourceResponse,\n} from '../../../core';\nimport type {nullSymbol, undefinedSymbol} from '../utils';\nimport {formatNullableValue, parseNullableValue} from '../utils';\n\nimport type {AnyPlainQueryDataSource, QueryObserverExtendedOptions} from './types';\n\nexport const composeOptions = <TDataSource extends AnyPlainQueryDataSource>(\n context: DataSourceContext<TDataSource>,\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n options?: Partial<DataSourceOptions<TDataSource>>,\n): QueryObserverExtendedOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n DataSourceData<TDataSource>,\n DataSourceResponse<TDataSource>,\n DataSourceKey\n> => {\n const {transformParams, transformResponse, transformError} = dataSource;\n\n const queryFn = async (\n fetchContext: QueryFunctionContext<DataSourceKey>,\n ): Promise<DataSourceResponse<TDataSource> | typeof undefinedSymbol | typeof nullSymbol> => {\n try {\n const response = await dataSource.fetch(\n context,\n fetchContext,\n transformParams ? transformParams(params) : params,\n );\n\n return formatNullableValue(response);\n } catch (error) {\n if (!transformError) {\n throw error;\n }\n\n return formatNullableValue(transformError(error));\n }\n };\n\n const select = (\n response: DataSourceResponse<TDataSource> | typeof undefinedSymbol | typeof nullSymbol,\n ): DataSourceData<TDataSource> => {\n const actualResponse = parseNullableValue(response);\n\n return transformResponse ? transformResponse(actualResponse) : actualResponse;\n };\n\n return {\n queryKey: composeFullKey(dataSource, params),\n queryFn: params === idle ? skipToken : queryFn,\n select,\n ...dataSource.options,\n ...options,\n };\n};\n"],"mappings":";;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AAWA,IAAAE,MAAA,GAAAF,OAAA;AAAgE,SAAAG,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAIzD,IAAMG,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,SAAjBA,cAAcA,CACvBE,OAAuC,EACvCC,UAAuB,EACvBC,MAAqC,EACrCC,OAAiD,EAOhD;EACD,IAAOC,eAAe,GAAuCH,UAAU,CAAhEG,eAAe;IAAEC,iBAAiB,GAAoBJ,UAAU,CAA/CI,iBAAiB;IAAEC,cAAc,GAAIL,UAAU,CAA5BK,cAAc;EAEzD,IAAMC,OAAO;IAAA,IAAAC,IAAA,OAAAC,0BAAA,gBAAAC,oBAAA,CAAAC,IAAA,CAAG,SAAAC,QACZC,YAAiD;MAAA,IAAAC,QAAA;MAAA,OAAAJ,oBAAA,CAAAK,IAAA,UAAAC,SAAAC,QAAA;QAAA,kBAAAA,QAAA,CAAAC,IAAA,GAAAD,QAAA,CAAAE,IAAA;UAAA;YAAAF,QAAA,CAAAC,IAAA;YAAAD,QAAA,CAAAE,IAAA;YAAA,OAGtBlB,UAAU,CAACmB,KAAK,CACnCpB,OAAO,EACPa,YAAY,EACZT,eAAe,GAAGA,eAAe,CAACF,MAAM,CAAC,GAAGA,MAChD,CAAC;UAAA;YAJKY,QAAQ,GAAAG,QAAA,CAAAI,IAAA;YAAA,OAAAJ,QAAA,CAAAK,MAAA,WAMP,IAAAC,0BAAmB,EAACT,QAAQ,CAAC;UAAA;YAAAG,QAAA,CAAAC,IAAA;YAAAD,QAAA,CAAAO,EAAA,GAAAP,QAAA;YAAA,IAE/BX,cAAc;cAAAW,QAAA,CAAAE,IAAA;cAAA;YAAA;YAAA,MAAAF,QAAA,CAAAO,EAAA;UAAA;YAAA,OAAAP,QAAA,CAAAK,MAAA,WAIZ,IAAAC,0BAAmB,EAACjB,cAAc,CAAAW,QAAA,CAAAO,EAAM,CAAC,CAAC;UAAA;UAAA;YAAA,OAAAP,QAAA,CAAAQ,IAAA;QAAA;MAAA,GAAAb,OAAA;IAAA,CAExD;IAAA,gBAlBKL,OAAOA,CAAAmB,EAAA;MAAA,OAAAlB,IAAA,CAAAmB,KAAA,OAAAC,SAAA;IAAA;EAAA,GAkBZ;EAED,IAAMC,MAAM,GAAG,SAATA,MAAMA,CACRf,QAAsF,EACxD;IAC9B,IAAMgB,cAAc,GAAG,IAAAC,yBAAkB,EAACjB,QAAQ,CAAC;IAEnD,OAAOT,iBAAiB,GAAGA,iBAAiB,CAACyB,cAAc,CAAC,GAAGA,cAAc;EACjF,CAAC;EAED,WAAAE,sBAAA,MAAAA,sBAAA;IACIC,QAAQ,EAAE,IAAAC,oBAAc,EAACjC,UAAU,EAAEC,MAAM,CAAC;IAC5CK,OAAO,EAAEL,MAAM,KAAKiC,UAAI,GAAGC,qBAAS,GAAG7B,OAAO;IAC9CsB,MAAM,EAANA;EAAM,GACH5B,UAAU,CAACE,OAAO,GAClBA,OAAO;AAElB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const undefinedSymbol: unique symbol;
|
|
2
|
+
export declare const nullSymbol: unique symbol;
|
|
3
|
+
export declare const formatNullableValue: <T>(value: T | undefined | null) => T | typeof undefinedSymbol | typeof nullSymbol;
|
|
4
|
+
export declare const parseNullableValue: <T>(value: T | typeof undefinedSymbol | typeof nullSymbol) => T | undefined | null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.undefinedSymbol = exports.parseNullableValue = exports.nullSymbol = exports.formatNullableValue = void 0;
|
|
7
|
+
var undefinedSymbol = exports.undefinedSymbol = Symbol('undefined');
|
|
8
|
+
var nullSymbol = exports.nullSymbol = Symbol('null');
|
|
9
|
+
var formatNullableValue = exports.formatNullableValue = function formatNullableValue(value) {
|
|
10
|
+
if (value === undefined) {
|
|
11
|
+
return undefinedSymbol;
|
|
12
|
+
}
|
|
13
|
+
if (value === null) {
|
|
14
|
+
return nullSymbol;
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
};
|
|
18
|
+
var parseNullableValue = exports.parseNullableValue = function parseNullableValue(value) {
|
|
19
|
+
if (value === undefinedSymbol) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
if (value === nullSymbol) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
};
|
|
27
|
+
// #sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["undefinedSymbol","exports","Symbol","nullSymbol","formatNullableValue","value","undefined","parseNullableValue"],"sources":["utils.ts"],"sourcesContent":["export const undefinedSymbol = Symbol('undefined');\nexport const nullSymbol = Symbol('null');\n\nexport const formatNullableValue = <T>(\n value: T | undefined | null,\n): T | typeof undefinedSymbol | typeof nullSymbol => {\n if (value === undefined) {\n return undefinedSymbol;\n }\n\n if (value === null) {\n return nullSymbol;\n }\n\n return value;\n};\n\nexport const parseNullableValue = <T>(\n value: T | typeof undefinedSymbol | typeof nullSymbol,\n): T | undefined | null => {\n if (value === undefinedSymbol) {\n return undefined;\n }\n\n if (value === nullSymbol) {\n return null;\n }\n\n return value;\n};\n"],"mappings":";;;;;;AAAO,IAAMA,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAAGE,MAAM,CAAC,WAAW,CAAC;AAC3C,IAAMC,UAAU,GAAAF,OAAA,CAAAE,UAAA,GAAGD,MAAM,CAAC,MAAM,CAAC;AAEjC,IAAME,mBAAmB,GAAAH,OAAA,CAAAG,mBAAA,GAAG,SAAtBA,mBAAmBA,CAC5BC,KAA2B,EACsB;EACjD,IAAIA,KAAK,KAAKC,SAAS,EAAE;IACrB,OAAON,eAAe;EAC1B;EAEA,IAAIK,KAAK,KAAK,IAAI,EAAE;IAChB,OAAOF,UAAU;EACrB;EAEA,OAAOE,KAAK;AAChB,CAAC;AAEM,IAAME,kBAAkB,GAAAN,OAAA,CAAAM,kBAAA,GAAG,SAArBA,kBAAkBA,CAC3BF,KAAqD,EAC9B;EACvB,IAAIA,KAAK,KAAKL,eAAe,EAAE;IAC3B,OAAOM,SAAS;EACpB;EAEA,IAAID,KAAK,KAAKF,UAAU,EAAE;IACtB,OAAO,IAAI;EACf;EAEA,OAAOE,KAAK;AAChB,CAAC","ignoreList":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export type { QueryDataSourceContext, AnyQueryDataSource
|
|
1
|
+
export type { QueryDataSourceContext, AnyQueryDataSource } from './types/base';
|
|
2
|
+
export type { RefetchIntervalFunction, RefetchInterval } from './types/refetch-interval';
|
|
2
3
|
export { useQueryContext } from './hooks/useQueryContext';
|
|
3
4
|
export { useQueryData } from './hooks/useQueryData';
|
|
4
5
|
export { useQueryResponses } from './hooks/useQueryResponses';
|
|
@@ -11,6 +12,7 @@ export type { PlainQueryDataSource, AnyPlainQueryDataSource } from './impl/plain
|
|
|
11
12
|
export { makePlainQueryDataSource } from './impl/plain/factory';
|
|
12
13
|
export { composeOptions as composePlainQueryOptions } from './impl/plain/utils';
|
|
13
14
|
export { normalizeStatus } from './utils/normalizeStatus';
|
|
15
|
+
export type { ProgressiveRefetchOptions } from './utils/getProgressiveRefetch';
|
|
14
16
|
export { getProgressiveRefetch } from './utils/getProgressiveRefetch';
|
|
15
17
|
export type { ClientDataManagerConfig } from './ClientDataManager';
|
|
16
18
|
export { ClientDataManager } from './ClientDataManager';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_useQueryContext","require","_useQueryData","_useQueryResponses","_useRefetchAll","_useRefetchErrored","_factory","_utils","_factory2","_utils2","_normalizeStatus","_getProgressiveRefetch","_ClientDataManager"],"sources":["index.ts"],"sourcesContent":["export type {
|
|
1
|
+
{"version":3,"names":["_useQueryContext","require","_useQueryData","_useQueryResponses","_useRefetchAll","_useRefetchErrored","_factory","_utils","_factory2","_utils2","_normalizeStatus","_getProgressiveRefetch","_ClientDataManager"],"sources":["index.ts"],"sourcesContent":["export type {QueryDataSourceContext, AnyQueryDataSource} from './types/base';\nexport type {RefetchIntervalFunction, RefetchInterval} from './types/refetch-interval';\n\nexport {useQueryContext} from './hooks/useQueryContext';\nexport {useQueryData} from './hooks/useQueryData';\nexport {useQueryResponses} from './hooks/useQueryResponses';\nexport {useRefetchAll} from './hooks/useRefetchAll';\nexport {useRefetchErrored} from './hooks/useRefetchErrored';\n\nexport type {InfiniteQueryDataSource, AnyInfiniteQueryDataSource} from './impl/infinite/types';\nexport {makeInfiniteQueryDataSource} from './impl/infinite/factory';\nexport {composeOptions as composeInfiniteQueryOptions} from './impl/infinite/utils';\n\nexport type {PlainQueryDataSource, AnyPlainQueryDataSource} from './impl/plain/types';\nexport {makePlainQueryDataSource} from './impl/plain/factory';\nexport {composeOptions as composePlainQueryOptions} from './impl/plain/utils';\n\nexport {normalizeStatus} from './utils/normalizeStatus';\nexport type {ProgressiveRefetchOptions} from './utils/getProgressiveRefetch';\nexport {getProgressiveRefetch} from './utils/getProgressiveRefetch';\n\nexport type {ClientDataManagerConfig} from './ClientDataManager';\nexport {ClientDataManager} from './ClientDataManager';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAAA,gBAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,kBAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AAGA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAGA,IAAAO,SAAA,GAAAP,OAAA;AACA,IAAAQ,OAAA,GAAAR,OAAA;AAEA,IAAAS,gBAAA,GAAAT,OAAA;AAEA,IAAAU,sBAAA,GAAAV,OAAA;AAGA,IAAAW,kBAAA,GAAAX,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DefaultError, QueryKey } from '@tanstack/react-query';
|
|
2
|
+
import type { RefetchInterval } from './refetch-interval';
|
|
3
|
+
export interface QueryDataAdditionalOptions<TQueryFnData = unknown, TError = DefaultError, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> {
|
|
4
|
+
refetchInterval?: RefetchInterval<TQueryFnData, TError, TQueryData, TQueryKey>;
|
|
5
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["options.ts"],"sourcesContent":["import type {DefaultError, QueryKey} from '@tanstack/react-query';\n\nimport type {RefetchInterval} from './refetch-interval';\n\nexport interface QueryDataAdditionalOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> {\n refetchInterval?: RefetchInterval<TQueryFnData, TError, TQueryData, TQueryKey>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,10 +1,3 @@
|
|
|
1
1
|
import type { DefaultError, Query, QueryKey } from '@tanstack/react-query';
|
|
2
2
|
export type RefetchIntervalFunction<TQueryFnData = unknown, TError = DefaultError, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = (query: Query<TQueryFnData, TError, TQueryData, TQueryKey>, count: number) => number | false | undefined;
|
|
3
3
|
export type RefetchInterval<TQueryFnData = unknown, TError = DefaultError, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = number | false | RefetchIntervalFunction<TQueryFnData, TError, TQueryData, TQueryKey>;
|
|
4
|
-
export interface ProgressiveRefetchInterval {
|
|
5
|
-
minInterval: number;
|
|
6
|
-
maxInterval: number;
|
|
7
|
-
}
|
|
8
|
-
export interface QueryDataExtendedOptions<TQueryFnData = unknown, TError = DefaultError, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> {
|
|
9
|
-
refetchInterval?: RefetchInterval<TQueryFnData, TError, TQueryData, TQueryKey>;
|
|
10
|
-
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["refetch-interval.ts"],"sourcesContent":["import type {DefaultError, Query, QueryKey} from '@tanstack/react-query';\n\nexport type RefetchIntervalFunction<\n TQueryFnData = unknown,\n TError = DefaultError,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = (\n query: Query<TQueryFnData, TError, TQueryData, TQueryKey>,\n count: number,\n) => number | false | undefined;\n\nexport type RefetchInterval<\n TQueryFnData = unknown,\n TError = DefaultError,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = number | false | RefetchIntervalFunction<TQueryFnData, TError, TQueryData, TQueryKey>;\n
|
|
1
|
+
{"version":3,"names":[],"sources":["refetch-interval.ts"],"sourcesContent":["import type {DefaultError, Query, QueryKey} from '@tanstack/react-query';\n\nexport type RefetchIntervalFunction<\n TQueryFnData = unknown,\n TError = DefaultError,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = (\n query: Query<TQueryFnData, TError, TQueryData, TQueryKey>,\n count: number,\n) => number | false | undefined;\n\nexport type RefetchInterval<\n TQueryFnData = unknown,\n TError = DefaultError,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = number | false | RefetchIntervalFunction<TQueryFnData, TError, TQueryData, TQueryKey>;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { QueryKey } from '@tanstack/react-query';
|
|
2
|
-
import type {
|
|
3
|
-
export
|
|
2
|
+
import type { RefetchIntervalFunction } from '../types/refetch-interval';
|
|
3
|
+
export interface ProgressiveRefetchOptions {
|
|
4
|
+
minInterval: number;
|
|
5
|
+
maxInterval: number;
|
|
6
|
+
multiplier?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare const getProgressiveRefetch: <TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>({ minInterval, maxInterval, multiplier, }: ProgressiveRefetchOptions) => RefetchIntervalFunction<TQueryFnData, TError, TData, TQueryKey>;
|
|
@@ -4,12 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getProgressiveRefetch = void 0;
|
|
7
|
-
var BASE = 2;
|
|
8
7
|
var getProgressiveRefetch = exports.getProgressiveRefetch = function getProgressiveRefetch(_ref) {
|
|
9
8
|
var minInterval = _ref.minInterval,
|
|
10
|
-
maxInterval = _ref.maxInterval
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
maxInterval = _ref.maxInterval,
|
|
10
|
+
_ref$multiplier = _ref.multiplier,
|
|
11
|
+
multiplier = _ref$multiplier === void 0 ? 2 : _ref$multiplier;
|
|
12
|
+
return function (_query, count) {
|
|
13
|
+
return Math.min(minInterval * Math.pow(multiplier, count), maxInterval);
|
|
13
14
|
};
|
|
14
15
|
};
|
|
15
16
|
// #sourceMappingURL=getProgressiveRefetch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["getProgressiveRefetch","exports","_ref","minInterval","maxInterval","_ref$multiplier","multiplier","_query","count","Math","min","pow"],"sources":["getProgressiveRefetch.ts"],"sourcesContent":["import type {DefaultError, QueryKey} from '@tanstack/react-query';\n\nimport type {RefetchIntervalFunction} from '../types/refetch-interval';\n\nexport interface ProgressiveRefetchOptions {\n minInterval: number;\n maxInterval: number;\n multiplier?: number;\n}\n\nexport const getProgressiveRefetch = <\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>({\n minInterval,\n maxInterval,\n multiplier = 2,\n}: ProgressiveRefetchOptions): RefetchIntervalFunction<TQueryFnData, TError, TData, TQueryKey> => {\n return (_query, count) => {\n return Math.min(minInterval * multiplier ** count, maxInterval);\n };\n};\n"],"mappings":";;;;;;AAUO,IAAMA,qBAAqB,GAAAC,OAAA,CAAAD,qBAAA,GAAG,SAAxBA,qBAAqBA,CAAAE,IAAA,EASgE;EAAA,IAH9FC,WAAW,GAAAD,IAAA,CAAXC,WAAW;IACXC,WAAW,GAAAF,IAAA,CAAXE,WAAW;IAAAC,eAAA,GAAAH,IAAA,CACXI,UAAU;IAAVA,UAAU,GAAAD,eAAA,cAAG,CAAC,GAAAA,eAAA;EAEd,OAAO,UAACE,MAAM,EAAEC,KAAK,EAAK;IACtB,OAAOC,IAAI,CAACC,GAAG,CAACP,WAAW,GAAAM,IAAA,CAAAE,GAAA,CAAGL,UAAU,EAAIE,KAAK,GAAEJ,WAAW,CAAC;EACnE,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { DataSourceKey, DataSourceTag, DataSource, AnyDataSource, DataSourceContext, DataSourceParams, DataSourceRequest, DataSourceResponse, DataSourceData, DataSourceError, DataSourceOptions, DataSourceState, DataSourceFetchContext, ActualParams, ActualData, } from './types/DataSource';
|
|
1
|
+
export type { DataSourceKey, DataSourceTag, DataSource, AnyDataSource, DataSourceContext, DataSourceParams, DataSourceRequest, DataSourceResponse, DataSourceErrorResponse, DataSourceData, DataSourceError, DataSourceOptions, DataSourceState, DataSourceFetchContext, ActualParams, ActualData, ActualResponse, } from './types/DataSource';
|
|
2
2
|
export type { DataManager } from './types/DataManger';
|
|
3
3
|
export type { DataLoaderStatus } from './types/DataLoaderStatus';
|
|
4
4
|
export type { InvalidateRepeatOptions, InvalidateOptions } from './types/DataManagerOptions';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["idle","composeKey","composeFullKey","getError","getStatus","hasTag","mergeStatuses","skipContext","isCancellable","isAbortable","withCancellation"],"sources":["index.ts"],"sourcesContent":["export type {\n DataSourceKey,\n DataSourceTag,\n DataSource,\n AnyDataSource,\n DataSourceContext,\n DataSourceParams,\n DataSourceRequest,\n DataSourceResponse,\n DataSourceData,\n DataSourceError,\n DataSourceOptions,\n DataSourceState,\n DataSourceFetchContext,\n ActualParams,\n ActualData,\n} from './types/DataSource';\nexport type {DataManager} from './types/DataManger';\nexport type {DataLoaderStatus} from './types/DataLoaderStatus';\nexport type {InvalidateRepeatOptions, InvalidateOptions} from './types/DataManagerOptions';\n\nexport {idle} from './constants';\n\nexport {composeKey} from './utils/composeKey';\nexport {composeFullKey} from './utils/composeFullKey';\nexport {getError} from './utils/getError';\nexport {getStatus} from './utils/getStatus';\nexport {hasTag} from './utils/hasTag';\nexport {mergeStatuses} from './utils/mergeStatuses';\nexport {skipContext} from './utils/skipContext';\nexport type {Cancellable} from './utils/withCancellation';\nexport {isCancellable, isAbortable, withCancellation} from './utils/withCancellation';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["idle","composeKey","composeFullKey","getError","getStatus","hasTag","mergeStatuses","skipContext","isCancellable","isAbortable","withCancellation"],"sources":["index.ts"],"sourcesContent":["export type {\n DataSourceKey,\n DataSourceTag,\n DataSource,\n AnyDataSource,\n DataSourceContext,\n DataSourceParams,\n DataSourceRequest,\n DataSourceResponse,\n DataSourceErrorResponse,\n DataSourceData,\n DataSourceError,\n DataSourceOptions,\n DataSourceState,\n DataSourceFetchContext,\n ActualParams,\n ActualData,\n ActualResponse,\n} from './types/DataSource';\nexport type {DataManager} from './types/DataManger';\nexport type {DataLoaderStatus} from './types/DataLoaderStatus';\nexport type {InvalidateRepeatOptions, InvalidateOptions} from './types/DataManagerOptions';\n\nexport {idle} from './constants';\n\nexport {composeKey} from './utils/composeKey';\nexport {composeFullKey} from './utils/composeFullKey';\nexport {getError} from './utils/getError';\nexport {getStatus} from './utils/getStatus';\nexport {hasTag} from './utils/hasTag';\nexport {mergeStatuses} from './utils/mergeStatuses';\nexport {skipContext} from './utils/skipContext';\nexport type {Cancellable} from './utils/withCancellation';\nexport {isCancellable, isAbortable, withCancellation} from './utils/withCancellation';\n"],"mappings":"AAuBA,SAAQA,IAAI,QAAO,aAAa;AAEhC,SAAQC,UAAU,QAAO,oBAAoB;AAC7C,SAAQC,cAAc,QAAO,wBAAwB;AACrD,SAAQC,QAAQ,QAAO,kBAAkB;AACzC,SAAQC,SAAS,QAAO,mBAAmB;AAC3C,SAAQC,MAAM,QAAO,gBAAgB;AACrC,SAAQC,aAAa,QAAO,uBAAuB;AACnD,SAAQC,WAAW,QAAO,qBAAqB;AAE/C,SAAQC,aAAa,EAAEC,WAAW,EAAEC,gBAAgB,QAAO,0BAA0B","ignoreList":[]}
|