@gravity-ui/data-source 0.5.1 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/core/index.d.ts +2 -2
- package/build/cjs/core/index.js.map +1 -1
- package/build/cjs/core/types/{DataManger.js → DataManager.js} +1 -1
- package/build/cjs/core/types/DataManager.js.map +1 -0
- 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/hasTag.js +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/DataManagerContext.js +1 -1
- package/build/cjs/react/DataManagerContext.js.map +1 -1
- package/build/cjs/react-query/ClientDataManager.d.ts +1 -1
- package/build/cjs/react-query/ClientDataManager.js +6 -6
- package/build/cjs/react-query/ClientDataManager.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/types.d.ts +7 -7
- 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/types.d.ts +4 -4
- 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/esm/core/index.d.ts +2 -2
- package/build/esm/core/index.js.map +1 -1
- package/build/esm/core/types/DataManager.js +2 -0
- package/build/esm/core/types/DataManager.js.map +1 -0
- 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/hasTag.js +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/DataManagerContext.js +1 -1
- package/build/esm/react/DataManagerContext.js.map +1 -1
- package/build/esm/react-query/ClientDataManager.d.ts +1 -1
- package/build/esm/react-query/ClientDataManager.js +6 -6
- package/build/esm/react-query/ClientDataManager.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/types.d.ts +7 -7
- 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/types.d.ts +4 -4
- 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/package.json +1 -1
- package/build/cjs/core/types/DataManger.js.map +0 -1
- package/build/esm/core/types/DataManger.js +0 -2
- package/build/esm/core/types/DataManger.js.map +0 -1
- /package/build/cjs/core/types/{DataManger.d.ts → DataManager.d.ts} +0 -0
- /package/build/esm/core/types/{DataManger.d.ts → DataManager.d.ts} +0 -0
|
@@ -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,EA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,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,5 +1,5 @@
|
|
|
1
|
-
export type { DataSourceKey, DataSourceTag, DataSource, AnyDataSource, DataSourceContext, DataSourceParams, DataSourceRequest, DataSourceResponse, DataSourceData, DataSourceError, DataSourceOptions, DataSourceState, DataSourceFetchContext, ActualParams, ActualData, } from './types/DataSource';
|
|
2
|
-
export type { DataManager } from './types/
|
|
1
|
+
export type { DataSourceKey, DataSourceTag, DataSource, AnyDataSource, DataSourceContext, DataSourceParams, DataSourceRequest, DataSourceResponse, DataSourceErrorResponse, DataSourceData, DataSourceError, DataSourceOptions, DataSourceState, DataSourceFetchContext, ActualParams, ActualData, ActualResponse, } from './types/DataSource';
|
|
2
|
+
export type { DataManager } from './types/DataManager';
|
|
3
3
|
export type { DataLoaderStatus } from './types/DataLoaderStatus';
|
|
4
4
|
export type { InvalidateRepeatOptions, InvalidateOptions } from './types/DataManagerOptions';
|
|
5
5
|
export { idle } from './constants';
|
|
@@ -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/
|
|
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/DataManager';\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":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["DataManager.ts"],"sourcesContent":["import type {InvalidateOptions} from './DataManagerOptions';\nimport type {AnyDataSource, DataSourceParams, DataSourceTag} from './DataSource';\n\nexport interface DataManager {\n invalidateTag(tag: DataSourceTag, invalidateOptions?: InvalidateOptions): Promise<void>;\n\n invalidateTags(tags: DataSourceTag[], invalidateOptions?: InvalidateOptions): Promise<void>;\n\n invalidateSource<TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n invalidateOptions?: InvalidateOptions,\n ): Promise<void>;\n\n resetSource<TDataSource extends AnyDataSource>(dataSource: TDataSource): Promise<void>;\n\n invalidateParams<TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n invalidateOptions?: InvalidateOptions,\n ): Promise<void>;\n\n resetParams<TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n ): Promise<void>;\n\n invalidateSourceTags<TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n invalidateOptions?: InvalidateOptions,\n ): Promise<void>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
import type { idle } from '../constants';
|
|
2
2
|
export type DataSourceKey = ReadonlyArray<unknown>;
|
|
3
3
|
export type DataSourceTag = string;
|
|
4
|
-
declare const errorHintSymbol: unique symbol;
|
|
5
4
|
declare const stateHintSymbol: unique symbol;
|
|
6
|
-
export interface DataSource<TContext, TParams, TRequest, TResponse, TData, TError, TOptions, TState, TFetchContext> {
|
|
5
|
+
export interface DataSource<TContext, TParams, TRequest, TResponse, TData, TError, TErrorResponse, TOptions, TState, TFetchContext> {
|
|
7
6
|
readonly name: string;
|
|
8
7
|
fetch: (context: TContext, fetchContext: TFetchContext, request: TRequest) => Promise<TResponse> | TResponse;
|
|
9
|
-
tags?: (params: ActualParams<TParams
|
|
10
|
-
transformParams?: (params: TParams) => TRequest
|
|
11
|
-
transformResponse?: (response: TResponse) => TData;
|
|
12
|
-
|
|
8
|
+
tags?: (params: ActualParams<NoInfer<TParams>, NoInfer<TRequest>>) => DataSourceTag[];
|
|
9
|
+
transformParams?: (params: TParams) => NoInfer<TRequest>;
|
|
10
|
+
transformResponse?: (response: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>) => TData;
|
|
11
|
+
/**
|
|
12
|
+
* When set, the `fetch` errors will be transformed into data without changing the state to error.
|
|
13
|
+
*/
|
|
14
|
+
transformError?: (error: TError) => TErrorResponse;
|
|
13
15
|
options?: Partial<TOptions>;
|
|
14
16
|
[stateHintSymbol]?: TState;
|
|
15
17
|
}
|
|
16
|
-
export type AnyDataSource = DataSource<any, any, any, any, any, any, any, any, any>;
|
|
17
|
-
export type DataSourceContext<TDataSource> = TDataSource extends DataSource<infer TContext, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer _TOptions, infer _TState, infer _TFetchContext> ? TContext : never;
|
|
18
|
-
export type DataSourceParams<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer TParams, infer TRequest, infer _TResponse, infer _TData, infer _TError, infer _TOptions, infer _TState, infer _TFetchContext> ? ActualParams<TParams, TRequest> : never;
|
|
19
|
-
export type DataSourceRequest<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer TRequest, infer _TResponse, infer _TData, infer _TError, infer _TOptions, infer _TState, infer _TFetchContext> ? TRequest : never;
|
|
20
|
-
export type DataSourceResponse<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer TResponse, infer _TData, infer _TError, infer _TOptions, infer _TState, infer _TFetchContext> ? TResponse : never;
|
|
21
|
-
export type DataSourceData<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer TResponse, infer TData, infer _TError, infer _TOptions, infer _TState, infer _TFetchContext> ? ActualData<TData,
|
|
22
|
-
export type DataSourceError<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer TError, infer _TOptions, infer _TState, infer _TFetchContext> ? TError : never;
|
|
23
|
-
export type
|
|
24
|
-
export type
|
|
25
|
-
export type
|
|
18
|
+
export type AnyDataSource = DataSource<any, any, any, any, any, any, any, any, any, any>;
|
|
19
|
+
export type DataSourceContext<TDataSource> = TDataSource extends DataSource<infer TContext, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? TContext : never;
|
|
20
|
+
export type DataSourceParams<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer TParams, infer TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? ActualParams<TParams, TRequest> : never;
|
|
21
|
+
export type DataSourceRequest<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? TRequest : never;
|
|
22
|
+
export type DataSourceResponse<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer TResponse, infer _TData, infer _TError, infer TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? ActualResponse<TResponse, TErrorResponse> : never;
|
|
23
|
+
export type DataSourceData<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer TResponse, infer TData, infer _TError, infer TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? ActualData<TResponse, TData, TErrorResponse> : never;
|
|
24
|
+
export type DataSourceError<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer TError, infer _TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? TError : never;
|
|
25
|
+
export type DataSourceErrorResponse<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? TErrorResponse : never;
|
|
26
|
+
export type DataSourceOptions<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer TOptions, infer _TState, infer _TFetchContext> ? TOptions : never;
|
|
27
|
+
export type DataSourceState<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer _TOptions, infer TState, infer _TFetchContext> ? TState : never;
|
|
28
|
+
export type DataSourceFetchContext<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer _TOptions, infer _TState, infer TFetchContext> ? TFetchContext : never;
|
|
26
29
|
export type ActualParams<TParams, TRequest> = (unknown extends TParams ? TRequest : TParams) | typeof idle;
|
|
27
|
-
export type
|
|
30
|
+
export type ActualResponse<TResponse, TErrorResponse> = unknown extends TErrorResponse ? TResponse : TResponse | TErrorResponse;
|
|
31
|
+
export type ActualData<TResponse, TData, TErrorResponse> = unknown extends TData ? ActualResponse<TResponse, TErrorResponse> : TData;
|
|
28
32
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["DataSource.ts"],"sourcesContent":["import type {idle} from '../constants';\n\nexport type DataSourceKey = ReadonlyArray<unknown>;\nexport type DataSourceTag = string;\n\ndeclare const
|
|
1
|
+
{"version":3,"names":[],"sources":["DataSource.ts"],"sourcesContent":["import type {idle} from '../constants';\n\nexport type DataSourceKey = ReadonlyArray<unknown>;\nexport type DataSourceTag = string;\n\ndeclare const stateHintSymbol: unique symbol;\n\nexport interface DataSource<\n TContext,\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n TErrorResponse,\n TOptions,\n TState,\n TFetchContext,\n> {\n readonly name: string;\n\n fetch: (\n context: TContext,\n fetchContext: TFetchContext,\n request: TRequest,\n ) => Promise<TResponse> | TResponse;\n tags?: (params: ActualParams<NoInfer<TParams>, NoInfer<TRequest>>) => DataSourceTag[];\n\n transformParams?: (params: TParams) => NoInfer<TRequest>;\n transformResponse?: (\n response: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n ) => TData;\n\n /**\n * When set, the `fetch` errors will be transformed into data without changing the state to error.\n */\n transformError?: (error: TError) => TErrorResponse;\n\n options?: Partial<TOptions>;\n [stateHintSymbol]?: TState;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyDataSource = DataSource<any, any, any, any, any, any, any, any, any, any>;\n\nexport type DataSourceContext<TDataSource> =\n TDataSource extends DataSource<\n infer TContext,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TContext\n : never;\n\nexport type DataSourceParams<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer TParams,\n infer TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? ActualParams<TParams, TRequest>\n : never;\n\nexport type DataSourceRequest<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TRequest\n : never;\n\nexport type DataSourceResponse<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer TResponse,\n infer _TData,\n infer _TError,\n infer TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? ActualResponse<TResponse, TErrorResponse>\n : never;\n\nexport type DataSourceData<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer TResponse,\n infer TData,\n infer _TError,\n infer TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? ActualData<TResponse, TData, TErrorResponse>\n : never;\n\nexport type DataSourceError<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TError\n : never;\n\nexport type DataSourceErrorResponse<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TErrorResponse\n : never;\n\nexport type DataSourceOptions<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TOptions\n : never;\n\nexport type DataSourceState<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer TState,\n infer _TFetchContext\n >\n ? TState\n : never;\n\nexport type DataSourceFetchContext<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer TFetchContext\n >\n ? TFetchContext\n : never;\n\nexport type ActualParams<TParams, TRequest> =\n | (unknown extends TParams ? TRequest : TParams)\n | typeof idle;\n\nexport type ActualResponse<TResponse, TErrorResponse> = unknown extends TErrorResponse\n ? TResponse\n : TResponse | TErrorResponse;\n\nexport type ActualData<TResponse, TData, TErrorResponse> = unknown extends TData\n ? ActualResponse<TResponse, TErrorResponse>\n : TData;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -7,6 +7,6 @@ export var hasTag = function hasTag(key, tag) {
|
|
|
7
7
|
// First element — data source name
|
|
8
8
|
// Last element — full key
|
|
9
9
|
// Skip them for consistency
|
|
10
|
-
return index > 0 && index < key.length -
|
|
10
|
+
return index > 0 && index < key.length - 1;
|
|
11
11
|
};
|
|
12
12
|
// #sourceMappingURL=hasTag.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["hasTag","key","tag","Array","isArray","index","indexOf","length"],"sources":["hasTag.ts"],"sourcesContent":["import type {DataSourceKey, DataSourceTag} from '../types/DataSource';\n\nexport const hasTag = (key: DataSourceKey, tag: DataSourceTag): boolean => {\n if (!Array.isArray(key)) {\n return false;\n }\n\n const index = key.indexOf(tag);\n\n // First element — data source name\n // Last element — full key\n // Skip them for consistency\n return index > 0 && index < key.length -
|
|
1
|
+
{"version":3,"names":["hasTag","key","tag","Array","isArray","index","indexOf","length"],"sources":["hasTag.ts"],"sourcesContent":["import type {DataSourceKey, DataSourceTag} from '../types/DataSource';\n\nexport const hasTag = (key: DataSourceKey, tag: DataSourceTag): boolean => {\n if (!Array.isArray(key)) {\n return false;\n }\n\n const index = key.indexOf(tag);\n\n // First element — data source name\n // Last element — full key\n // Skip them for consistency\n return index > 0 && index < key.length - 1;\n};\n"],"mappings":"AAEA,OAAO,IAAMA,MAAM,GAAG,SAATA,MAAMA,CAAIC,GAAkB,EAAEC,GAAkB,EAAc;EACvE,IAAI,CAACC,KAAK,CAACC,OAAO,CAACH,GAAG,CAAC,EAAE;IACrB,OAAO,KAAK;EAChB;EAEA,IAAMI,KAAK,GAAGJ,GAAG,CAACK,OAAO,CAACJ,GAAG,CAAC;;EAE9B;EACA;EACA;EACA,OAAOG,KAAK,GAAG,CAAC,IAAIA,KAAK,GAAGJ,GAAG,CAACM,MAAM,GAAG,CAAC;AAC9C,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,26 @@
|
|
|
1
1
|
import type { AnyFunction } from '../types/utils';
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
*
|
|
5
|
+
* The function is intended to be used with the `fetch` parameter of the query data source config.
|
|
6
|
+
* It is used to ignore the query data context and the query function context parameters.
|
|
7
|
+
*
|
|
8
|
+
* NOTE: When passed directly to the `fetch` parameter, typescript fails to infer the types of the `DataSource` fields.
|
|
9
|
+
* It is better to define a constant first.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* function someFetchFunction(request: TRequest) {...}
|
|
14
|
+
*
|
|
15
|
+
* const fetchData = skipContext(someFetchFunction);
|
|
16
|
+
*
|
|
17
|
+
* const dataSource = makePlainQueryDataSource({
|
|
18
|
+
* ...
|
|
19
|
+
* fetch: fetchData,
|
|
20
|
+
* ...
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* @param fetch fetch function
|
|
24
|
+
* @returns fetch function with the ignored query data source context and the query function context.
|
|
25
|
+
*/
|
|
2
26
|
export declare const skipContext: <TFunc extends AnyFunction>(fetch: TFunc) => (_0: unknown, _1: unknown, ...args: Parameters<TFunc>) => ReturnType<TFunc>;
|
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
*
|
|
4
|
+
* The function is intended to be used with the `fetch` parameter of the query data source config.
|
|
5
|
+
* It is used to ignore the query data context and the query function context parameters.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: When passed directly to the `fetch` parameter, typescript fails to infer the types of the `DataSource` fields.
|
|
8
|
+
* It is better to define a constant first.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* function someFetchFunction(request: TRequest) {...}
|
|
13
|
+
*
|
|
14
|
+
* const fetchData = skipContext(someFetchFunction);
|
|
15
|
+
*
|
|
16
|
+
* const dataSource = makePlainQueryDataSource({
|
|
17
|
+
* ...
|
|
18
|
+
* fetch: fetchData,
|
|
19
|
+
* ...
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* @param fetch fetch function
|
|
23
|
+
* @returns fetch function with the ignored query data source context and the query function context.
|
|
24
|
+
*/
|
|
1
25
|
export var skipContext = function skipContext(fetch) {
|
|
2
26
|
return function (_0, _1) {
|
|
3
27
|
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["skipContext","fetch","_0","_1","_len","arguments","length","args","Array","_key","apply"],"sources":["skipContext.ts"],"sourcesContent":["import type {AnyFunction} from '../types/utils';\n\nexport const skipContext = <TFunc extends AnyFunction>(fetch: TFunc) => {\n return (_0: unknown, _1: unknown, ...args: Parameters<TFunc>): ReturnType<TFunc> => {\n return fetch(...args);\n };\n};\n"],"mappings":"AAEA,OAAO,IAAMA,WAAW,GAAG,SAAdA,WAAWA,CAA+BC,KAAY,EAAK;EACpE,OAAO,UAACC,EAAW,EAAEC,EAAW,EAAoD;IAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAA/CC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAJF,IAAI,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;IAAA;IACrC,OAAOR,KAAK,CAAAS,KAAA,SAAIH,IAAI,CAAC;EACzB,CAAC;AACL,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["skipContext","fetch","_0","_1","_len","arguments","length","args","Array","_key","apply"],"sources":["skipContext.ts"],"sourcesContent":["import type {AnyFunction} from '../types/utils';\n\n/**\n * @description\n *\n * The function is intended to be used with the `fetch` parameter of the query data source config.\n * It is used to ignore the query data context and the query function context parameters.\n *\n * NOTE: When passed directly to the `fetch` parameter, typescript fails to infer the types of the `DataSource` fields.\n * It is better to define a constant first.\n *\n * @example\n *\n * function someFetchFunction(request: TRequest) {...}\n *\n * const fetchData = skipContext(someFetchFunction);\n *\n * const dataSource = makePlainQueryDataSource({\n * ...\n * fetch: fetchData,\n * ...\n * })\n *\n * @param fetch fetch function\n * @returns fetch function with the ignored query data source context and the query function context.\n */\nexport const skipContext = <TFunc extends AnyFunction>(fetch: TFunc) => {\n return (_0: unknown, _1: unknown, ...args: Parameters<TFunc>): ReturnType<TFunc> => {\n return fetch(...args);\n };\n};\n"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAMA,WAAW,GAAG,SAAdA,WAAWA,CAA+BC,KAAY,EAAK;EACpE,OAAO,UAACC,EAAW,EAAEC,EAAW,EAAoD;IAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAA/CC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAJF,IAAI,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;IAAA;IACrC,OAAOR,KAAK,CAAAS,KAAA,SAAIH,IAAI,CAAC;EACzB,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -3,7 +3,7 @@ export var DataManagerContext = /*#__PURE__*/createContext(null);
|
|
|
3
3
|
export var useDataManager = function useDataManager() {
|
|
4
4
|
var dataManager = useContext(DataManagerContext);
|
|
5
5
|
if (!dataManager) {
|
|
6
|
-
throw new Error('DataManager is not
|
|
6
|
+
throw new Error('DataManager is not provided by context. Use DataManagerContext.Provider to do it');
|
|
7
7
|
}
|
|
8
8
|
return dataManager;
|
|
9
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createContext","useContext","DataManagerContext","useDataManager","dataManager","Error"],"sources":["DataManagerContext.ts"],"sourcesContent":["import {createContext, useContext} from 'react';\n\nimport type {DataManager} from '../core';\n\nexport const DataManagerContext = createContext<DataManager | null>(null);\n\nexport const useDataManager = () => {\n const dataManager = useContext(DataManagerContext);\n\n if (!dataManager) {\n throw new Error(\n 'DataManager is not
|
|
1
|
+
{"version":3,"names":["createContext","useContext","DataManagerContext","useDataManager","dataManager","Error"],"sources":["DataManagerContext.ts"],"sourcesContent":["import {createContext, useContext} from 'react';\n\nimport type {DataManager} from '../core';\n\nexport const DataManagerContext = createContext<DataManager | null>(null);\n\nexport const useDataManager = () => {\n const dataManager = useContext(DataManagerContext);\n\n if (!dataManager) {\n throw new Error(\n 'DataManager is not provided by context. Use DataManagerContext.Provider to do it',\n );\n }\n\n return dataManager;\n};\n"],"mappings":"AAAA,SAAQA,aAAa,EAAEC,UAAU,QAAO,OAAO;AAI/C,OAAO,IAAMC,kBAAkB,gBAAGF,aAAa,CAAqB,IAAI,CAAC;AAEzE,OAAO,IAAMG,cAAc,GAAG,SAAjBA,cAAcA,CAAA,EAAS;EAChC,IAAMC,WAAW,GAAGH,UAAU,CAACC,kBAAkB,CAAC;EAElD,IAAI,CAACE,WAAW,EAAE;IACd,MAAM,IAAIC,KAAK,CACX,kFACJ,CAAC;EACL;EAEA,OAAOD,WAAW;AACtB,CAAC","ignoreList":[]}
|
|
@@ -5,7 +5,7 @@ import type { InvalidateOptions, InvalidateRepeatOptions } from '../core/types/D
|
|
|
5
5
|
export type ClientDataManagerConfig = QueryClientConfig;
|
|
6
6
|
export declare class ClientDataManager implements DataManager {
|
|
7
7
|
readonly queryClient: QueryClient;
|
|
8
|
-
constructor(
|
|
8
|
+
constructor(config?: ClientDataManagerConfig);
|
|
9
9
|
invalidateTag(tag: DataSourceTag, invalidateOptions?: InvalidateOptions): Promise<void>;
|
|
10
10
|
invalidateTags(tags: DataSourceTag[], invalidateOptions?: InvalidateOptions): Promise<void>;
|
|
11
11
|
invalidateSource<TDataSource extends AnyDataSource>(dataSource: TDataSource, invalidateOptions?: InvalidateOptions): Promise<void>;
|
|
@@ -5,18 +5,18 @@ import { QueryClient } from '@tanstack/react-query';
|
|
|
5
5
|
import { composeFullKey, hasTag } from '../core';
|
|
6
6
|
export var ClientDataManager = /*#__PURE__*/function () {
|
|
7
7
|
function ClientDataManager() {
|
|
8
|
-
var
|
|
9
|
-
var
|
|
8
|
+
var _config$defaultOption, _config$defaultOption2;
|
|
9
|
+
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
10
10
|
_classCallCheck(this, ClientDataManager);
|
|
11
11
|
this.queryClient = void 0;
|
|
12
|
-
this.queryClient = new QueryClient(_objectSpread(_objectSpread({},
|
|
13
|
-
defaultOptions: _objectSpread(_objectSpread({},
|
|
12
|
+
this.queryClient = new QueryClient(_objectSpread(_objectSpread({}, config), {}, {
|
|
13
|
+
defaultOptions: _objectSpread(_objectSpread({}, config.defaultOptions), {}, {
|
|
14
14
|
queries: _objectSpread({
|
|
15
15
|
networkMode: 'always'
|
|
16
|
-
}, (
|
|
16
|
+
}, (_config$defaultOption = config.defaultOptions) === null || _config$defaultOption === void 0 ? void 0 : _config$defaultOption.queries),
|
|
17
17
|
mutations: _objectSpread({
|
|
18
18
|
networkMode: 'always'
|
|
19
|
-
}, (
|
|
19
|
+
}, (_config$defaultOption2 = config.defaultOptions) === null || _config$defaultOption2 === void 0 ? void 0 : _config$defaultOption2.mutations)
|
|
20
20
|
})
|
|
21
21
|
}));
|
|
22
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["QueryClient","composeFullKey","hasTag","ClientDataManager","
|
|
1
|
+
{"version":3,"names":["QueryClient","composeFullKey","hasTag","ClientDataManager","_config$defaultOption","_config$defaultOption2","config","arguments","length","undefined","_classCallCheck","queryClient","_objectSpread","defaultOptions","queries","networkMode","mutations","_createClass","key","value","invalidateTag","tag","invalidateOptions","invalidateQueries","predicate","_ref","queryKey","invalidateTags","tags","_ref2","every","invalidateSource","dataSource","name","resetSource","resetQueries","invalidateParams","params","exact","resetParams","invalidateSourceTags","slice","filters","_this","invalidate","repeatInvalidate","repeat","i","count","setTimeout","interval"],"sources":["ClientDataManager.ts"],"sourcesContent":["import type {InvalidateQueryFilters, QueryClientConfig} from '@tanstack/react-query';\nimport {QueryClient} from '@tanstack/react-query';\n\nimport {\n type AnyDataSource,\n type DataManager,\n type DataSourceParams,\n type DataSourceTag,\n composeFullKey,\n hasTag,\n} from '../core';\nimport type {InvalidateOptions, InvalidateRepeatOptions} from '../core/types/DataManagerOptions';\n\nexport type ClientDataManagerConfig = QueryClientConfig;\n\nexport class ClientDataManager implements DataManager {\n readonly queryClient: QueryClient;\n\n constructor(config: ClientDataManagerConfig = {}) {\n this.queryClient = new QueryClient({\n ...config,\n defaultOptions: {\n ...config.defaultOptions,\n queries: {\n networkMode: 'always',\n ...config.defaultOptions?.queries,\n },\n mutations: {\n networkMode: 'always',\n ...config.defaultOptions?.mutations,\n },\n },\n });\n }\n\n invalidateTag(tag: DataSourceTag, invalidateOptions?: InvalidateOptions) {\n return this.invalidateQueries(\n {\n predicate: ({queryKey}) => hasTag(queryKey, tag),\n },\n invalidateOptions,\n );\n }\n\n invalidateTags(tags: DataSourceTag[], invalidateOptions?: InvalidateOptions) {\n return this.invalidateQueries(\n {\n predicate: ({queryKey}) => tags.every((tag) => hasTag(queryKey, tag)),\n },\n invalidateOptions,\n );\n }\n\n invalidateSource<TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n invalidateOptions?: InvalidateOptions,\n ) {\n return this.invalidateQueries(\n {\n // First element is a data source name\n queryKey: [dataSource.name],\n },\n invalidateOptions,\n );\n }\n\n resetSource<TDataSource extends AnyDataSource>(dataSource: TDataSource) {\n return this.queryClient.resetQueries({\n // First element is a data source name\n queryKey: [dataSource.name],\n });\n }\n\n invalidateParams<TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n invalidateOptions?: InvalidateOptions,\n ) {\n return this.invalidateQueries(\n {\n queryKey: composeFullKey(dataSource, params),\n exact: true,\n },\n invalidateOptions,\n );\n }\n\n resetParams<TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n ) {\n return this.queryClient.resetQueries({\n queryKey: composeFullKey(dataSource, params),\n exact: true,\n });\n }\n\n invalidateSourceTags<TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n invalidateOptions?: InvalidateOptions,\n ) {\n return this.invalidateQueries(\n {\n // Last element is a full key\n queryKey: composeFullKey(dataSource, params).slice(0, -1),\n },\n invalidateOptions,\n );\n }\n\n protected invalidateQueries(\n filters: InvalidateQueryFilters,\n invalidateOptions?: InvalidateOptions,\n ) {\n const invalidate = () => this.queryClient.invalidateQueries(filters);\n\n this.repeatInvalidate(invalidate, invalidateOptions?.repeat);\n\n return invalidate();\n }\n\n protected repeatInvalidate(invalidate: () => Promise<void>, repeat?: InvalidateRepeatOptions) {\n if (!repeat) {\n return;\n }\n\n for (let i = 1; i <= repeat.count; i++) {\n setTimeout(invalidate, repeat.interval * i);\n }\n }\n}\n"],"mappings":";;;AACA,SAAQA,WAAW,QAAO,uBAAuB;AAEjD,SAKIC,cAAc,EACdC,MAAM,QACH,SAAS;AAKhB,WAAaC,iBAAiB;EAG1B,SAAAA,kBAAA,EAAkD;IAAA,IAAAC,qBAAA,EAAAC,sBAAA;IAAA,IAAtCC,MAA+B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAAAG,eAAA,OAAAP,iBAAA;IAAA,KAFvCQ,WAAW;IAGhB,IAAI,CAACA,WAAW,GAAG,IAAIX,WAAW,CAAAY,aAAA,CAAAA,aAAA,KAC3BN,MAAM;MACTO,cAAc,EAAAD,aAAA,CAAAA,aAAA,KACPN,MAAM,CAACO,cAAc;QACxBC,OAAO,EAAAF,aAAA;UACHG,WAAW,EAAE;QAAQ,IAAAX,qBAAA,GAClBE,MAAM,CAACO,cAAc,cAAAT,qBAAA,uBAArBA,qBAAA,CAAuBU,OAAO,CACpC;QACDE,SAAS,EAAAJ,aAAA;UACLG,WAAW,EAAE;QAAQ,IAAAV,sBAAA,GAClBC,MAAM,CAACO,cAAc,cAAAR,sBAAA,uBAArBA,sBAAA,CAAuBW,SAAS;MACtC;IACJ,EACJ,CAAC;EACN;EAAC,OAAAC,YAAA,CAAAd,iBAAA;IAAAe,GAAA;IAAAC,KAAA,EAED,SAAAC,aAAaA,CAACC,GAAkB,EAAEC,iBAAqC,EAAE;MACrE,OAAO,IAAI,CAACC,iBAAiB,CACzB;QACIC,SAAS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A","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { InfiniteQueryDataSource } from './types';
|
|
2
|
-
export declare const makeInfiniteQueryDataSource: <TParams, TRequest, TResponse, TData, TError>(config: Omit<InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError>, "type">) => InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError>;
|
|
2
|
+
export declare const makeInfiniteQueryDataSource: <TParams, TRequest, TResponse, TData, TError, TErrorResponse>(config: Omit<InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>, "type">) => InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["makeInfiniteQueryDataSource","config","_objectSpread","type"],"sources":["factory.ts"],"sourcesContent":["import type {InfiniteQueryDataSource} from './types';\n\nexport const makeInfiniteQueryDataSource =
|
|
1
|
+
{"version":3,"names":["makeInfiniteQueryDataSource","config","_objectSpread","type"],"sources":["factory.ts"],"sourcesContent":["import type {InfiniteQueryDataSource} from './types';\n\nexport const makeInfiniteQueryDataSource = <\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n TErrorResponse,\n>(\n config: Omit<\n InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>,\n 'type'\n >,\n): InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> => ({\n ...config,\n type: 'infinite',\n});\n"],"mappings":";AAEA,OAAO,IAAMA,2BAA2B,GAAG,SAA9BA,2BAA2BA,CAQpCC,MAGC;EAAA,OAAAC,aAAA,CAAAA,aAAA,KAEED,MAAM;IACTE,IAAI,EAAE;EAAU;AAAA,CAClB","ignoreList":[]}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
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';
|
|
3
|
+
import type { ActualData, ActualResponse, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
4
4
|
import type { QueryDataSourceContext } from '../../types/base';
|
|
5
5
|
import type { QueryDataAdditionalOptions } from '../../types/options';
|
|
6
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> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, InfiniteQueryObserverExtendedOptions<TResponse
|
|
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>>>> & {
|
|
8
8
|
type: 'infinite';
|
|
9
|
-
next: (lastPage: TResponse
|
|
10
|
-
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;
|
|
11
11
|
};
|
|
12
|
-
export type AnyInfiniteQueryDataSource = InfiniteQueryDataSource<any, any, any, any, any>;
|
|
12
|
+
export type AnyInfiniteQueryDataSource = InfiniteQueryDataSource<any, any, any, any, any, any>;
|
|
13
13
|
export type AnyPageParam = Partial<any>;
|
|
14
|
-
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, {
|
|
15
15
|
status: DataLoaderStatus;
|
|
16
|
-
data: Array<FlatArray<Array<ActualData<TData,
|
|
16
|
+
data: Array<FlatArray<Array<ActualData<TResponse, TData, TErrorResponse>>, 1>>;
|
|
17
17
|
}> & {
|
|
18
18
|
originalStatus: TResult['status'];
|
|
19
19
|
originalData: TResult['data'];
|
|
@@ -1 +1 @@
|
|
|
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 {ActualData
|
|
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":[]}
|
|
@@ -1,25 +1,62 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
4
|
import { skipToken } from '@tanstack/react-query';
|
|
3
5
|
import { composeFullKey, idle } from '../../../core';
|
|
6
|
+
import { formatNullableValue, parseNullableValue } from '../utils';
|
|
4
7
|
var EMPTY_OBJECT = {};
|
|
5
8
|
export var composeOptions = function composeOptions(context, dataSource, params, options) {
|
|
6
9
|
var transformParams = dataSource.transformParams,
|
|
10
|
+
transformError = dataSource.transformError,
|
|
7
11
|
transformResponse = dataSource.transformResponse,
|
|
8
12
|
next = dataSource.next,
|
|
9
13
|
prev = dataSource.prev;
|
|
10
|
-
var queryFn = function
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
var queryFn = /*#__PURE__*/function () {
|
|
15
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(fetchContext) {
|
|
16
|
+
var request, paginatedRequest, response;
|
|
17
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
18
|
+
while (1) switch (_context.prev = _context.next) {
|
|
19
|
+
case 0:
|
|
20
|
+
request = transformParams ? transformParams(params) : params;
|
|
21
|
+
paginatedRequest = _objectSpread(_objectSpread({}, request), fetchContext.pageParam);
|
|
22
|
+
_context.prev = 2;
|
|
23
|
+
_context.next = 5;
|
|
24
|
+
return dataSource.fetch(context, fetchContext, paginatedRequest);
|
|
25
|
+
case 5:
|
|
26
|
+
response = _context.sent;
|
|
27
|
+
return _context.abrupt("return", formatNullableValue(response));
|
|
28
|
+
case 9:
|
|
29
|
+
_context.prev = 9;
|
|
30
|
+
_context.t0 = _context["catch"](2);
|
|
31
|
+
if (transformError) {
|
|
32
|
+
_context.next = 13;
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
throw _context.t0;
|
|
36
|
+
case 13:
|
|
37
|
+
return _context.abrupt("return", formatNullableValue(transformError(_context.t0)));
|
|
38
|
+
case 14:
|
|
39
|
+
case "end":
|
|
40
|
+
return _context.stop();
|
|
41
|
+
}
|
|
42
|
+
}, _callee, null, [[2, 9]]);
|
|
43
|
+
}));
|
|
44
|
+
return function queryFn(_x) {
|
|
45
|
+
return _ref.apply(this, arguments);
|
|
46
|
+
};
|
|
47
|
+
}();
|
|
48
|
+
var selectPage = function selectPage(response) {
|
|
49
|
+
var actualResponse = parseNullableValue(response);
|
|
50
|
+
return transformResponse ? transformResponse(actualResponse) : actualResponse;
|
|
14
51
|
};
|
|
15
52
|
return _objectSpread(_objectSpread({
|
|
16
53
|
queryKey: composeFullKey(dataSource, params),
|
|
17
54
|
queryFn: params === idle ? skipToken : queryFn,
|
|
18
|
-
select:
|
|
55
|
+
select: function select(data) {
|
|
19
56
|
return _objectSpread(_objectSpread({}, data), {}, {
|
|
20
|
-
pages: data.pages.map(
|
|
57
|
+
pages: data.pages.map(selectPage)
|
|
21
58
|
});
|
|
22
|
-
}
|
|
59
|
+
},
|
|
23
60
|
initialPageParam: EMPTY_OBJECT,
|
|
24
61
|
getNextPageParam: next,
|
|
25
62
|
getPreviousPageParam: prev
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["skipToken","composeFullKey","idle","EMPTY_OBJECT","composeOptions","context","dataSource","params","options","transformParams","transformResponse","next","prev","queryFn","fetchContext","request","paginatedRequest","_objectSpread","pageParam","fetch","queryKey","select","data","pages","map","
|
|
1
|
+
{"version":3,"names":["skipToken","composeFullKey","idle","formatNullableValue","parseNullableValue","EMPTY_OBJECT","composeOptions","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","t0","stop","_x","apply","arguments","selectPage","actualResponse","queryKey","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,SAAQA,SAAS,QAAO,uBAAuB;AAG/C,SAAQC,cAAc,EAAEC,IAAI,QAAO,eAAe;AAWlD,SAAQC,mBAAmB,EAAEC,kBAAkB,QAAO,UAAU;AAQhE,IAAMC,YAAY,GAAG,CAAC,CAAC;AAEvB,OAAO,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CACvBC,OAAuC,EAC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