@gravity-ui/data-source 0.5.0 → 0.5.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/types/DataManger.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/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/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 +4 -5
- package/build/cjs/react-query/impl/infinite/types.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 +3 -2
- package/build/cjs/react-query/impl/plain/types.js.map +1 -1
- 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/types/DataManger.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/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/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 +4 -5
- package/build/esm/react-query/impl/infinite/types.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 +3 -2
- package/build/esm/react-query/impl/plain/types.js.map +1 -1
- 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,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 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["DataManger.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 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
|
+
{"version":3,"names":[],"sources":["DataManger.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 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getError","states","_states$find$error","_states$find","find","_ref","error","Boolean"],"sources":["getError.ts"],"sourcesContent":["export const getError = <T>(states: {error: T | null}[]) => {\n return states.find(({error}) => Boolean(error))?.error ?? null;\n};\n"],"mappings":"AAAA,OAAO,IAAMA,QAAQ,GAAG,SAAXA,QAAQA,CAAOC,MAA2B,
|
|
1
|
+
{"version":3,"names":["getError","states","_states$find$error","_states$find","find","_ref","error","Boolean"],"sources":["getError.ts"],"sourcesContent":["export const getError = <T>(states: {error: T | null}[]): NonNullable<T> | null => {\n return states.find(({error}) => Boolean(error))?.error ?? null;\n};\n"],"mappings":"AAAA,OAAO,IAAMA,QAAQ,GAAG,SAAXA,QAAQA,CAAOC,MAA2B,EAA4B;EAAA,IAAAC,kBAAA,EAAAC,YAAA;EAC/E,QAAAD,kBAAA,IAAAC,YAAA,GAAOF,MAAM,CAACG,IAAI,CAAC,UAAAC,IAAA;IAAA,IAAEC,KAAK,GAAAD,IAAA,CAALC,KAAK;IAAA,OAAMC,OAAO,CAACD,KAAK,CAAC;EAAA,EAAC,cAAAH,YAAA,uBAAxCA,YAAA,CAA0CG,KAAK,cAAAJ,kBAAA,cAAAA,kBAAA,GAAI,IAAI;AAClE,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["mergeStatuses","getStatus","states","map","_ref","status"],"sources":["getStatus.ts"],"sourcesContent":["import type {DataLoaderStatus} from '../types/DataLoaderStatus';\n\nimport {mergeStatuses} from './mergeStatuses';\n\nexport const getStatus = (states: {status: DataLoaderStatus}[]) => {\n return mergeStatuses(states.map(({status}) => status));\n};\n"],"mappings":"AAEA,SAAQA,aAAa,QAAO,iBAAiB;AAE7C,OAAO,IAAMC,SAAS,GAAG,SAAZA,SAASA,CAAIC,MAAoC,
|
|
1
|
+
{"version":3,"names":["mergeStatuses","getStatus","states","map","_ref","status"],"sources":["getStatus.ts"],"sourcesContent":["import type {DataLoaderStatus} from '../types/DataLoaderStatus';\n\nimport {mergeStatuses} from './mergeStatuses';\n\nexport const getStatus = (states: {status: DataLoaderStatus}[]): DataLoaderStatus => {\n return mergeStatuses(states.map(({status}) => status));\n};\n"],"mappings":"AAEA,SAAQA,aAAa,QAAO,iBAAiB;AAE7C,OAAO,IAAMC,SAAS,GAAG,SAAZA,SAASA,CAAIC,MAAoC,EAAuB;EACjF,OAAOF,aAAa,CAACE,MAAM,CAACC,GAAG,CAAC,UAAAC,IAAA;IAAA,IAAEC,MAAM,GAAAD,IAAA,CAANC,MAAM;IAAA,OAAMA,MAAM;EAAA,EAAC,CAAC;AAC1D,CAAC","ignoreList":[]}
|
|
@@ -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) => {\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 - 2;\n};\n"],"mappings":"AAEA,OAAO,IAAMA,MAAM,GAAG,SAATA,MAAMA,CAAIC,GAAkB,EAAEC,GAAkB,
|
|
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 - 2;\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,7 +1,7 @@
|
|
|
1
|
-
import type { QueryClientConfig } from '@tanstack/react-query';
|
|
1
|
+
import type { InvalidateQueryFilters, QueryClientConfig } from '@tanstack/react-query';
|
|
2
2
|
import { QueryClient } from '@tanstack/react-query';
|
|
3
3
|
import { type AnyDataSource, type DataManager, type DataSourceParams, type DataSourceTag } from '../core';
|
|
4
|
-
import type { InvalidateOptions } from '../core/types/DataManagerOptions';
|
|
4
|
+
import type { InvalidateOptions, InvalidateRepeatOptions } from '../core/types/DataManagerOptions';
|
|
5
5
|
export type ClientDataManagerConfig = QueryClientConfig;
|
|
6
6
|
export declare class ClientDataManager implements DataManager {
|
|
7
7
|
readonly queryClient: QueryClient;
|
|
@@ -13,6 +13,6 @@ export declare class ClientDataManager implements DataManager {
|
|
|
13
13
|
invalidateParams<TDataSource extends AnyDataSource>(dataSource: TDataSource, params: DataSourceParams<TDataSource>, invalidateOptions?: InvalidateOptions): Promise<void>;
|
|
14
14
|
resetParams<TDataSource extends AnyDataSource>(dataSource: TDataSource, params: DataSourceParams<TDataSource>): Promise<void>;
|
|
15
15
|
invalidateSourceTags<TDataSource extends AnyDataSource>(dataSource: TDataSource, params: DataSourceParams<TDataSource>, invalidateOptions?: InvalidateOptions): Promise<void>;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
protected invalidateQueries(filters: InvalidateQueryFilters, invalidateOptions?: InvalidateOptions): Promise<void>;
|
|
17
|
+
protected repeatInvalidate(invalidate: () => Promise<void>, repeat?: InvalidateRepeatOptions): void;
|
|
18
18
|
}
|
|
@@ -86,12 +86,10 @@ export var ClientDataManager = /*#__PURE__*/function () {
|
|
|
86
86
|
key: "invalidateQueries",
|
|
87
87
|
value: function invalidateQueries(filters, invalidateOptions) {
|
|
88
88
|
var _this = this;
|
|
89
|
-
var _ref3 = invalidateOptions || {},
|
|
90
|
-
repeat = _ref3.repeat;
|
|
91
89
|
var invalidate = function invalidate() {
|
|
92
90
|
return _this.queryClient.invalidateQueries(filters);
|
|
93
91
|
};
|
|
94
|
-
this.repeatInvalidate(invalidate, repeat);
|
|
92
|
+
this.repeatInvalidate(invalidate, invalidateOptions === null || invalidateOptions === void 0 ? void 0 : invalidateOptions.repeat);
|
|
95
93
|
return invalidate();
|
|
96
94
|
}
|
|
97
95
|
}, {
|
|
@@ -100,10 +98,8 @@ export var ClientDataManager = /*#__PURE__*/function () {
|
|
|
100
98
|
if (!repeat) {
|
|
101
99
|
return;
|
|
102
100
|
}
|
|
103
|
-
var
|
|
104
|
-
|
|
105
|
-
for (var i = 1; i <= count; i++) {
|
|
106
|
-
setTimeout(invalidate, interval * i);
|
|
101
|
+
for (var i = 1; i <= repeat.count; i++) {
|
|
102
|
+
setTimeout(invalidate, repeat.interval * i);
|
|
107
103
|
}
|
|
108
104
|
}
|
|
109
105
|
}]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["QueryClient","composeFullKey","hasTag","ClientDataManager","_conifg$defaultOption","_conifg$defaultOption2","conifg","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","
|
|
1
|
+
{"version":3,"names":["QueryClient","composeFullKey","hasTag","ClientDataManager","_conifg$defaultOption","_conifg$defaultOption2","conifg","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(conifg: ClientDataManagerConfig = {}) {\n this.queryClient = new QueryClient({\n ...conifg,\n defaultOptions: {\n ...conifg.defaultOptions,\n queries: {\n networkMode: 'always',\n ...conifg.defaultOptions?.queries,\n },\n mutations: {\n networkMode: 'always',\n ...conifg.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":"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","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { QueryDataSourceContext } from '../types';
|
|
1
|
+
import type { QueryDataSourceContext } from '../types/base';
|
|
2
2
|
export declare const useQueryContext: () => QueryDataSourceContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMemo","useQueryClient","useQueryContext","queryClient","queryContext"],"sources":["useQueryContext.ts"],"sourcesContent":["import {useMemo} from 'react';\n\nimport {useQueryClient} from '@tanstack/react-query';\n\nimport type {QueryDataSourceContext} from '../types';\n\nexport const useQueryContext = (): QueryDataSourceContext => {\n const queryClient = useQueryClient();\n const queryContext = useMemo(() => ({queryClient}), [queryClient]);\n\n return queryContext;\n};\n"],"mappings":"AAAA,SAAQA,OAAO,QAAO,OAAO;AAE7B,SAAQC,cAAc,QAAO,uBAAuB;AAIpD,OAAO,IAAMC,eAAe,GAAG,SAAlBA,eAAeA,CAAA,EAAiC;EACzD,IAAMC,WAAW,GAAGF,cAAc,CAAC,CAAC;EACpC,IAAMG,YAAY,GAAGJ,OAAO,CAAC;IAAA,OAAO;MAACG,WAAW,EAAXA;IAAW,CAAC;EAAA,CAAC,EAAE,CAACA,WAAW,CAAC,CAAC;EAElE,OAAOC,YAAY;AACvB,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["useMemo","useQueryClient","useQueryContext","queryClient","queryContext"],"sources":["useQueryContext.ts"],"sourcesContent":["import {useMemo} from 'react';\n\nimport {useQueryClient} from '@tanstack/react-query';\n\nimport type {QueryDataSourceContext} from '../types/base';\n\nexport const useQueryContext = (): QueryDataSourceContext => {\n const queryClient = useQueryClient();\n const queryContext = useMemo(() => ({queryClient}), [queryClient]);\n\n return queryContext;\n};\n"],"mappings":"AAAA,SAAQA,OAAO,QAAO,OAAO;AAE7B,SAAQC,cAAc,QAAO,uBAAuB;AAIpD,OAAO,IAAMC,eAAe,GAAG,SAAlBA,eAAeA,CAAA,EAAiC;EACzD,IAAMC,WAAW,GAAGF,cAAc,CAAC,CAAC;EACpC,IAAMG,YAAY,GAAGJ,OAAO,CAAC;IAAA,OAAO;MAACG,WAAW,EAAXA;IAAW,CAAC;EAAA,CAAC,EAAE,CAACA,WAAW,CAAC,CAAC;EAElE,OAAOC,YAAY;AACvB,CAAC","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { DataSourceOptions, DataSourceParams, DataSourceState } from '../../core';
|
|
2
|
-
import type { AnyQueryDataSource } from '../types';
|
|
2
|
+
import type { AnyQueryDataSource } from '../types/base';
|
|
3
3
|
export declare const useQueryData: <TDataSource extends AnyQueryDataSource>(dataSource: TDataSource, params: DataSourceParams<TDataSource>, options?: Partial<DataSourceOptions<TDataSource>>) => DataSourceState<TDataSource>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useInfiniteQueryData","usePlainQueryData","notReachable","useQueryContext","useQueryData","dataSource","params","options","context","type","state","concat"],"sources":["useQueryData.ts"],"sourcesContent":["import type {DataSourceOptions, DataSourceParams, DataSourceState} from '../../core';\nimport {useInfiniteQueryData} from '../impl/infinite/hooks';\nimport type {AnyInfiniteQueryDataSource} from '../impl/infinite/types';\nimport {usePlainQueryData} from '../impl/plain/hooks';\nimport type {AnyPlainQueryDataSource} from '../impl/plain/types';\nimport type {AnyQueryDataSource} from '../types';\nimport {notReachable} from '../utils/notReachable';\n\nimport {useQueryContext} from './useQueryContext';\n\nexport const useQueryData = <TDataSource extends AnyQueryDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n options?: Partial<DataSourceOptions<TDataSource>>,\n): DataSourceState<TDataSource> => {\n const context = useQueryContext();\n\n const type = dataSource.type;\n let state: DataSourceState<AnyQueryDataSource> | undefined;\n\n // Do not change data source type in the same hook call\n if (type === 'plain') {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n state = usePlainQueryData(\n context,\n dataSource,\n params,\n options as Partial<DataSourceOptions<AnyPlainQueryDataSource>> | undefined,\n );\n } else if (type === 'infinite') {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n state = useInfiniteQueryData(\n context,\n dataSource,\n params,\n // TS can't calculate types in this place\n options as Partial<DataSourceOptions<AnyInfiniteQueryDataSource>> | undefined,\n );\n } else {\n return notReachable(type, `Data Source type must be plain or infinite, got: ${type}`);\n }\n\n return state as DataSourceState<TDataSource>;\n};\n"],"mappings":"AACA,SAAQA,oBAAoB,QAAO,wBAAwB;AAE3D,SAAQC,iBAAiB,QAAO,qBAAqB;AAGrD,SAAQC,YAAY,QAAO,uBAAuB;AAElD,SAAQC,eAAe,QAAO,mBAAmB;AAEjD,OAAO,IAAMC,YAAY,GAAG,SAAfA,YAAYA,CACrBC,UAAuB,EACvBC,MAAqC,EACrCC,OAAiD,EAClB;EAC/B,IAAMC,OAAO,GAAGL,eAAe,CAAC,CAAC;EAEjC,IAAMM,IAAI,GAAGJ,UAAU,CAACI,IAAI;EAC5B,IAAIC,KAAsD;;EAE1D;EACA,IAAID,IAAI,KAAK,OAAO,EAAE;IAClB;IACAC,KAAK,GAAGT,iBAAiB,CACrBO,OAAO,EACPH,UAAU,EACVC,MAAM,EACNC,OACJ,CAAC;EACL,CAAC,MAAM,IAAIE,IAAI,KAAK,UAAU,EAAE;IAC5B;IACAC,KAAK,GAAGV,oBAAoB,CACxBQ,OAAO,EACPH,UAAU,EACVC,MAAM;IACN;IACAC,OACJ,CAAC;EACL,CAAC,MAAM;IACH,OAAOL,YAAY,CAACO,IAAI,sDAAAE,MAAA,CAAsDF,IAAI,CAAE,CAAC;EACzF;EAEA,OAAOC,KAAK;AAChB,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["useInfiniteQueryData","usePlainQueryData","notReachable","useQueryContext","useQueryData","dataSource","params","options","context","type","state","concat"],"sources":["useQueryData.ts"],"sourcesContent":["import type {DataSourceOptions, DataSourceParams, DataSourceState} from '../../core';\nimport {useInfiniteQueryData} from '../impl/infinite/hooks';\nimport type {AnyInfiniteQueryDataSource} from '../impl/infinite/types';\nimport {usePlainQueryData} from '../impl/plain/hooks';\nimport type {AnyPlainQueryDataSource} from '../impl/plain/types';\nimport type {AnyQueryDataSource} from '../types/base';\nimport {notReachable} from '../utils/notReachable';\n\nimport {useQueryContext} from './useQueryContext';\n\nexport const useQueryData = <TDataSource extends AnyQueryDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n options?: Partial<DataSourceOptions<TDataSource>>,\n): DataSourceState<TDataSource> => {\n const context = useQueryContext();\n\n const type = dataSource.type;\n let state: DataSourceState<AnyQueryDataSource> | undefined;\n\n // Do not change data source type in the same hook call\n if (type === 'plain') {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n state = usePlainQueryData(\n context,\n dataSource,\n params,\n options as Partial<DataSourceOptions<AnyPlainQueryDataSource>> | undefined,\n );\n } else if (type === 'infinite') {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n state = useInfiniteQueryData(\n context,\n dataSource,\n params,\n // TS can't calculate types in this place\n options as Partial<DataSourceOptions<AnyInfiniteQueryDataSource>> | undefined,\n );\n } else {\n return notReachable(type, `Data Source type must be plain or infinite, got: ${type}`);\n }\n\n return state as DataSourceState<TDataSource>;\n};\n"],"mappings":"AACA,SAAQA,oBAAoB,QAAO,wBAAwB;AAE3D,SAAQC,iBAAiB,QAAO,qBAAqB;AAGrD,SAAQC,YAAY,QAAO,uBAAuB;AAElD,SAAQC,eAAe,QAAO,mBAAmB;AAEjD,OAAO,IAAMC,YAAY,GAAG,SAAfA,YAAYA,CACrBC,UAAuB,EACvBC,MAAqC,EACrCC,OAAiD,EAClB;EAC/B,IAAMC,OAAO,GAAGL,eAAe,CAAC,CAAC;EAEjC,IAAMM,IAAI,GAAGJ,UAAU,CAACI,IAAI;EAC5B,IAAIC,KAAsD;;EAE1D;EACA,IAAID,IAAI,KAAK,OAAO,EAAE;IAClB;IACAC,KAAK,GAAGT,iBAAiB,CACrBO,OAAO,EACPH,UAAU,EACVC,MAAM,EACNC,OACJ,CAAC;EACL,CAAC,MAAM,IAAIE,IAAI,KAAK,UAAU,EAAE;IAC5B;IACAC,KAAK,GAAGV,oBAAoB,CACxBQ,OAAO,EACPH,UAAU,EACVC,MAAM;IACN;IACAC,OACJ,CAAC;EACL,CAAC,MAAM;IACH,OAAOL,YAAY,CAACO,IAAI,sDAAAE,MAAA,CAAsDF,IAAI,CAAE,CAAC;EACzF;EAEA,OAAOC,KAAK;AAChB,CAAC","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Query, QueryFunction, SkipToken } from '@tanstack/react-query';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type { DefaultError, Query, QueryFunction, QueryKey, SkipToken } from '@tanstack/react-query';
|
|
2
|
+
import type { RefetchInterval } from '../types/refetch-interval';
|
|
3
|
+
export interface UseRefetchIntervalResult<TQueryFnData = unknown, TError = DefaultError, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = never> {
|
|
4
|
+
refetchInterval?: number | false | ((query: Query<TQueryFnData, TError, TQueryData, TQueryKey>) => number | false | undefined);
|
|
5
|
+
queryFn?: QueryFunction<TQueryFnData, TQueryKey, TPageParam> | SkipToken;
|
|
6
|
+
}
|
|
7
|
+
export declare const useRefetchInterval: <TQueryFnData = unknown, TError = Error, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = never>(refetchInterval?: RefetchInterval<TQueryFnData, TError, TQueryData, TQueryKey>, queryFn?: QueryFunction<TQueryFnData, TQueryKey, TPageParam> | SkipToken) => UseRefetchIntervalResult<TQueryFnData, TError, TQueryData, TQueryKey, TPageParam>;
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export var useRefetchInterval = function useRefetchInterval(
|
|
2
|
+
export var useRefetchInterval = function useRefetchInterval(refetchInterval, queryFn) {
|
|
3
3
|
var count = React.useRef(0);
|
|
4
|
-
var
|
|
5
|
-
if (typeof
|
|
4
|
+
var actualQueryFn = React.useMemo(function () {
|
|
5
|
+
if (typeof queryFn === 'function') {
|
|
6
6
|
return function (context) {
|
|
7
|
-
count.current
|
|
8
|
-
return
|
|
7
|
+
++count.current;
|
|
8
|
+
return queryFn(context);
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
-
return
|
|
12
|
-
}, [
|
|
13
|
-
var
|
|
14
|
-
if (typeof
|
|
11
|
+
return queryFn;
|
|
12
|
+
}, [queryFn]);
|
|
13
|
+
var actualRefetchInterval = React.useMemo(function () {
|
|
14
|
+
if (typeof refetchInterval === 'function') {
|
|
15
15
|
return function (query) {
|
|
16
|
-
return
|
|
16
|
+
return refetchInterval(query, count.current);
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
return
|
|
20
|
-
}, [
|
|
19
|
+
return refetchInterval;
|
|
20
|
+
}, [refetchInterval]);
|
|
21
21
|
return {
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
queryFn: actualQueryFn,
|
|
23
|
+
refetchInterval: actualRefetchInterval
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
// #sourceMappingURL=useRefetchInterval.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useRefetchInterval","
|
|
1
|
+
{"version":3,"names":["React","useRefetchInterval","refetchInterval","queryFn","count","useRef","actualQueryFn","useMemo","context","current","actualRefetchInterval","query"],"sources":["useRefetchInterval.ts"],"sourcesContent":["import React from 'react';\n\nimport type {DefaultError, Query, QueryFunction, QueryKey, SkipToken} from '@tanstack/react-query';\n\nimport type {RefetchInterval} from '../types/refetch-interval';\n\nexport interface UseRefetchIntervalResult<\n TQueryFnData = unknown,\n TError = DefaultError,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n> {\n refetchInterval?:\n | number\n | false\n | ((\n query: Query<TQueryFnData, TError, TQueryData, TQueryKey>,\n ) => number | false | undefined);\n queryFn?: QueryFunction<TQueryFnData, TQueryKey, TPageParam> | SkipToken;\n}\n\nexport const useRefetchInterval = <\n TQueryFnData = unknown,\n TError = DefaultError,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n>(\n refetchInterval?: RefetchInterval<TQueryFnData, TError, TQueryData, TQueryKey>,\n queryFn?: QueryFunction<TQueryFnData, TQueryKey, TPageParam> | SkipToken,\n): UseRefetchIntervalResult<TQueryFnData, TError, TQueryData, TQueryKey, TPageParam> => {\n const count = React.useRef<number>(0);\n\n const actualQueryFn = React.useMemo(() => {\n if (typeof queryFn === 'function') {\n return ((context) => {\n ++count.current;\n return queryFn(context);\n }) satisfies UseRefetchIntervalResult<\n TQueryFnData,\n TError,\n TQueryData,\n TQueryKey,\n TPageParam\n >['queryFn'];\n }\n\n return queryFn;\n }, [queryFn]);\n\n const actualRefetchInterval = React.useMemo(() => {\n if (typeof refetchInterval === 'function') {\n return ((query) => {\n return refetchInterval(query, count.current);\n }) satisfies UseRefetchIntervalResult<\n TQueryFnData,\n TError,\n TQueryData,\n TQueryKey,\n TPageParam\n >['refetchInterval'];\n }\n\n return refetchInterval;\n }, [refetchInterval]);\n\n return {queryFn: actualQueryFn, refetchInterval: actualRefetchInterval};\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAsBzB,OAAO,IAAMC,kBAAkB,GAAG,SAArBA,kBAAkBA,CAO3BC,eAA8E,EAC9EC,OAAwE,EACY;EACpF,IAAMC,KAAK,GAAGJ,KAAK,CAACK,MAAM,CAAS,CAAC,CAAC;EAErC,IAAMC,aAAa,GAAGN,KAAK,CAACO,OAAO,CAAC,YAAM;IACtC,IAAI,OAAOJ,OAAO,KAAK,UAAU,EAAE;MAC/B,OAAQ,UAACK,OAAO,EAAK;QACjB,EAAEJ,KAAK,CAACK,OAAO;QACf,OAAON,OAAO,CAACK,OAAO,CAAC;MAC3B,CAAC;IAOL;IAEA,OAAOL,OAAO;EAClB,CAAC,EAAE,CAACA,OAAO,CAAC,CAAC;EAEb,IAAMO,qBAAqB,GAAGV,KAAK,CAACO,OAAO,CAAC,YAAM;IAC9C,IAAI,OAAOL,eAAe,KAAK,UAAU,EAAE;MACvC,OAAQ,UAACS,KAAK,EAAK;QACf,OAAOT,eAAe,CAACS,KAAK,EAAEP,KAAK,CAACK,OAAO,CAAC;MAChD,CAAC;IAOL;IAEA,OAAOP,eAAe;EAC1B,CAAC,EAAE,CAACA,eAAe,CAAC,CAAC;EAErB,OAAO;IAACC,OAAO,EAAEG,aAAa;IAAEJ,eAAe,EAAEQ;EAAqB,CAAC;AAC3E,CAAC","ignoreList":[]}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { AnyInfiniteQueryDataSource, AnyPageParam, InfiniteQueryObserverExtendedOptions } from './types';
|
|
1
|
+
import type { DataSourceContext, DataSourceOptions, DataSourceParams, DataSourceState } from '../../../core';
|
|
2
|
+
import type { AnyInfiniteQueryDataSource } from './types';
|
|
4
3
|
export declare const useInfiniteQueryData: <TDataSource extends AnyInfiniteQueryDataSource>(context: DataSourceContext<TDataSource>, dataSource: TDataSource, params: DataSourceParams<TDataSource>, options?: Partial<DataSourceOptions<TDataSource>>) => DataSourceState<TDataSource>;
|
|
5
|
-
export declare function useInfiniteQueryDataOptions<TDataSource extends AnyInfiniteQueryDataSource>(composedOptions: InfiniteQueryObserverExtendedOptions<DataSourceResponse<TDataSource>, DataSourceError<TDataSource>, InfiniteData<DataSourceData<TDataSource>, AnyPageParam>, DataSourceResponse<TDataSource>, DataSourceKey, AnyPageParam>): InfiniteQueryObserverOptions<DataSourceResponse<TDataSource>, DataSourceError<TDataSource>, InfiniteData<DataSourceData<TDataSource>, AnyPageParam>, DataSourceResponse<TDataSource>, DataSourceKey, AnyPageParam>;
|
|
@@ -1,37 +1,36 @@
|
|
|
1
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
1
|
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
3
|
-
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["queryFn", "refetchInterval"];
|
|
4
4
|
import { useMemo } from 'react';
|
|
5
5
|
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
6
6
|
import { useRefetchInterval } from '../../hooks/useRefetchInterval';
|
|
7
7
|
import { normalizeStatus } from '../../utils/normalizeStatus';
|
|
8
8
|
import { composeOptions } from './utils';
|
|
9
|
+
var useInfiniteQueryDataOptions = function useInfiniteQueryDataOptions(composedOptions) {
|
|
10
|
+
var queryFnOption = composedOptions.queryFn,
|
|
11
|
+
refetchIntervalOption = composedOptions.refetchInterval,
|
|
12
|
+
restOptions = _objectWithoutProperties(composedOptions, _excluded);
|
|
13
|
+
var _useRefetchInterval = useRefetchInterval(refetchIntervalOption, queryFnOption),
|
|
14
|
+
queryFn = _useRefetchInterval.queryFn,
|
|
15
|
+
refetchInterval = _useRefetchInterval.refetchInterval;
|
|
16
|
+
return _objectSpread(_objectSpread({}, restOptions), {}, {
|
|
17
|
+
queryFn: queryFn,
|
|
18
|
+
refetchInterval: refetchInterval
|
|
19
|
+
});
|
|
20
|
+
};
|
|
9
21
|
export var useInfiniteQueryData = function useInfiniteQueryData(context, dataSource, params, options) {
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
22
|
+
var extendedOptions = composeOptions(context, dataSource, params, options);
|
|
23
|
+
var composedOptions = useInfiniteQueryDataOptions(extendedOptions);
|
|
24
|
+
var state = useInfiniteQuery(composedOptions);
|
|
13
25
|
var transformedData = useMemo(function () {
|
|
14
|
-
var
|
|
15
|
-
return (
|
|
16
|
-
}, [
|
|
17
|
-
return _objectSpread(_objectSpread({},
|
|
18
|
-
status: normalizeStatus(
|
|
26
|
+
var _state$data$pages$fla, _state$data;
|
|
27
|
+
return (_state$data$pages$fla = (_state$data = state.data) === null || _state$data === void 0 ? void 0 : _state$data.pages.flat(1)) !== null && _state$data$pages$fla !== void 0 ? _state$data$pages$fla : [];
|
|
28
|
+
}, [state.data]);
|
|
29
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
30
|
+
status: normalizeStatus(state.status, state.fetchStatus),
|
|
19
31
|
data: transformedData,
|
|
20
|
-
originalStatus:
|
|
21
|
-
originalData:
|
|
32
|
+
originalStatus: state.status,
|
|
33
|
+
originalData: state.data
|
|
22
34
|
});
|
|
23
35
|
};
|
|
24
|
-
export function useInfiniteQueryDataOptions(composedOptions) {
|
|
25
|
-
var _ref = composedOptions || {},
|
|
26
|
-
refetchIntervalOption = _ref.refetchInterval,
|
|
27
|
-
queryFnOption = _ref.queryFn,
|
|
28
|
-
restOptions = _objectWithoutProperties(_ref, _excluded);
|
|
29
|
-
var _useRefetchInterval = useRefetchInterval(refetchIntervalOption, queryFnOption),
|
|
30
|
-
refetchInterval = _useRefetchInterval.refetchInterval,
|
|
31
|
-
queryFn = _useRefetchInterval.queryFn;
|
|
32
|
-
return _objectSpread(_objectSpread({}, restOptions), {}, {
|
|
33
|
-
refetchInterval: refetchInterval,
|
|
34
|
-
queryFn: queryFn
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
36
|
// #sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMemo","useInfiniteQuery","useRefetchInterval","normalizeStatus","composeOptions","
|
|
1
|
+
{"version":3,"names":["useMemo","useInfiniteQuery","useRefetchInterval","normalizeStatus","composeOptions","useInfiniteQueryDataOptions","composedOptions","queryFnOption","queryFn","refetchIntervalOption","refetchInterval","restOptions","_objectWithoutProperties","_excluded","_useRefetchInterval","_objectSpread","useInfiniteQueryData","context","dataSource","params","options","extendedOptions","state","transformedData","_state$data$pages$fla","_state$data","data","pages","flat","status","fetchStatus","originalStatus","originalData"],"sources":["hooks.ts"],"sourcesContent":["import {useMemo} from 'react';\n\nimport {useInfiniteQuery} from '@tanstack/react-query';\nimport type {InfiniteData, InfiniteQueryObserverOptions} from '@tanstack/react-query';\n\nimport type {\n DataSourceContext,\n DataSourceData,\n DataSourceError,\n DataSourceKey,\n DataSourceOptions,\n DataSourceParams,\n DataSourceRequest,\n DataSourceResponse,\n DataSourceState,\n} from '../../../core';\nimport {useRefetchInterval} from '../../hooks/useRefetchInterval';\nimport {normalizeStatus} from '../../utils/normalizeStatus';\n\nimport type {AnyInfiniteQueryDataSource, InfiniteQueryObserverExtendedOptions} from './types';\nimport {composeOptions} from './utils';\n\nconst useInfiniteQueryDataOptions = <TDataSource extends AnyInfiniteQueryDataSource>(\n composedOptions: InfiniteQueryObserverExtendedOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n InfiniteData<DataSourceData<TDataSource>, Partial<DataSourceRequest<TDataSource>>>,\n DataSourceResponse<TDataSource>,\n DataSourceKey,\n Partial<DataSourceRequest<TDataSource>>\n >,\n): InfiniteQueryObserverOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n InfiniteData<DataSourceData<TDataSource>, Partial<DataSourceRequest<TDataSource>>>,\n DataSourceResponse<TDataSource>,\n DataSourceKey,\n Partial<DataSourceRequest<TDataSource>>\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 useInfiniteQueryData = <TDataSource extends AnyInfiniteQueryDataSource>(\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 = useInfiniteQueryDataOptions(extendedOptions);\n const state = useInfiniteQuery(composedOptions);\n\n const transformedData = useMemo<DataSourceState<TDataSource>['data']>(\n () => state.data?.pages.flat(1) ?? [],\n [state.data],\n );\n\n return {\n ...state,\n status: normalizeStatus(state.status, state.fetchStatus),\n data: transformedData,\n originalStatus: state.status,\n originalData: state.data,\n } as DataSourceState<TDataSource>;\n};\n"],"mappings":";;;AAAA,SAAQA,OAAO,QAAO,OAAO;AAE7B,SAAQC,gBAAgB,QAAO,uBAAuB;AActD,SAAQC,kBAAkB,QAAO,gCAAgC;AACjE,SAAQC,eAAe,QAAO,6BAA6B;AAG3D,SAAQC,cAAc,QAAO,SAAS;AAEtC,IAAMC,2BAA2B,GAAG,SAA9BA,2BAA2BA,CAC7BC,eAOC,EAQA;EACD,IACaC,aAAa,GAGtBD,eAAe,CAHfE,OAAO;IACUC,qBAAqB,GAEtCH,eAAe,CAFfI,eAAe;IACZC,WAAW,GAAAC,wBAAA,CACdN,eAAe,EAAAO,SAAA;EAEnB,IAAAC,mBAAA,GAAmCZ,kBAAkB,CAACO,qBAAqB,EAAEF,aAAa,CAAC;IAApFC,OAAO,GAAAM,mBAAA,CAAPN,OAAO;IAAEE,eAAe,GAAAI,mBAAA,CAAfJ,eAAe;EAE/B,OAAAK,aAAA,CAAAA,aAAA,KAAWJ,WAAW;IAAEH,OAAO,EAAPA,OAAO;IAAEE,eAAe,EAAfA;EAAe;AACpD,CAAC;AAED,OAAO,IAAMM,oBAAoB,GAAG,SAAvBA,oBAAoBA,CAC7BC,OAAuC,EACvCC,UAAuB,EACvBC,MAAqC,EACrCC,OAAiD,EAClB;EAC/B,IAAMC,eAAe,GAAGjB,cAAc,CAACa,OAAO,EAAEC,UAAU,EAAEC,MAAM,EAAEC,OAAO,CAAC;EAC5E,IAAMd,eAAe,GAAGD,2BAA2B,CAACgB,eAAe,CAAC;EACpE,IAAMC,KAAK,GAAGrB,gBAAgB,CAACK,eAAe,CAAC;EAE/C,IAAMiB,eAAe,GAAGvB,OAAO,CAC3B;IAAA,IAAAwB,qBAAA,EAAAC,WAAA;IAAA,QAAAD,qBAAA,IAAAC,WAAA,GAAMH,KAAK,CAACI,IAAI,cAAAD,WAAA,uBAAVA,WAAA,CAAYE,KAAK,CAACC,IAAI,CAAC,CAAC,CAAC,cAAAJ,qBAAA,cAAAA,qBAAA,GAAI,EAAE;EAAA,GACrC,CAACF,KAAK,CAACI,IAAI,CACf,CAAC;EAED,OAAAX,aAAA,CAAAA,aAAA,KACOO,KAAK;IACRO,MAAM,EAAE1B,eAAe,CAACmB,KAAK,CAACO,MAAM,EAAEP,KAAK,CAACQ,WAAW,CAAC;IACxDJ,IAAI,EAAEH,eAAe;IACrBQ,cAAc,EAAET,KAAK,CAACO,MAAM;IAC5BG,YAAY,EAAEV,KAAK,CAACI;EAAI;AAEhC,CAAC","ignoreList":[]}
|
|
@@ -1,10 +1,9 @@
|
|
|
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
3
|
import type { ActualData, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
4
|
-
import type { QueryDataSourceContext } from '../../types';
|
|
5
|
-
import type {
|
|
6
|
-
export
|
|
7
|
-
}
|
|
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>>;
|
|
8
7
|
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>>> & {
|
|
9
8
|
type: 'infinite';
|
|
10
9
|
next: (lastPage: TResponse, allPages: TResponse[]) => Partial<TRequest> | null | undefined;
|
|
@@ -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 {ActualData, DataLoaderStatus, DataSource, DataSourceKey} 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> = DataSource<\n QueryDataSourceContext,\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n InfiniteQueryObserverExtendedOptions<\n TResponse,\n TError,\n InfiniteData<ActualData<TData, TResponse>, Partial<TRequest>>,\n TResponse,\n DataSourceKey,\n Partial<TRequest>\n >,\n ResultWrapper<\n InfiniteQueryObserverResult<\n InfiniteData<ActualData<TData, TResponse>, Partial<TRequest>>,\n TError\n >,\n TRequest,\n TResponse,\n TData,\n TError\n >,\n QueryFunctionContext<DataSourceKey, Partial<TRequest>>\n> & {\n type: 'infinite';\n next: (lastPage: TResponse, allPages: TResponse[]) => Partial<TRequest> | null | undefined;\n prev?: (firstPage: TResponse, allPages: TResponse[]) => Partial<TRequest> | null | undefined;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyInfiniteQueryDataSource = InfiniteQueryDataSource<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> =\n TResult extends InfiniteQueryObserverResult<\n InfiniteData<ActualData<TData, TResponse>, Partial<TRequest>>,\n TError\n >\n ? Overwrite<\n TResult,\n {\n status: DataLoaderStatus;\n data: Array<FlatArray<Array<ActualData<TData, TResponse>>, 1>>;\n }\n > & {\n originalStatus: TResult['status'];\n originalData: TResult['data'];\n }\n : never;\n"],"mappings":"","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>;
|
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
1
|
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
3
|
-
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["queryFn", "refetchInterval"];
|
|
4
4
|
import { useQuery } from '@tanstack/react-query';
|
|
5
5
|
import { useRefetchInterval } from '../../hooks/useRefetchInterval';
|
|
6
6
|
import { normalizeStatus } from '../../utils/normalizeStatus';
|
|
7
7
|
import { composeOptions } from './utils';
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return _objectSpread(_objectSpread({}, result), {}, {
|
|
13
|
-
status: normalizeStatus(result.status, result.fetchStatus),
|
|
14
|
-
originalStatus: result.status
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
export function useQueryDataOptions(composedOptions) {
|
|
18
|
-
var _ref = composedOptions || {},
|
|
19
|
-
refetchIntervalOption = _ref.refetchInterval,
|
|
20
|
-
queryFnOption = _ref.queryFn,
|
|
21
|
-
restOptions = _objectWithoutProperties(_ref, _excluded);
|
|
8
|
+
var usePlainQueryDataOptions = function usePlainQueryDataOptions(composedOptions) {
|
|
9
|
+
var queryFnOption = composedOptions.queryFn,
|
|
10
|
+
refetchIntervalOption = composedOptions.refetchInterval,
|
|
11
|
+
restOptions = _objectWithoutProperties(composedOptions, _excluded);
|
|
22
12
|
var _useRefetchInterval = useRefetchInterval(refetchIntervalOption, queryFnOption),
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
queryFn = _useRefetchInterval.queryFn,
|
|
14
|
+
refetchInterval = _useRefetchInterval.refetchInterval;
|
|
25
15
|
return _objectSpread(_objectSpread({}, restOptions), {}, {
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
queryFn: queryFn,
|
|
17
|
+
refetchInterval: refetchInterval
|
|
28
18
|
});
|
|
29
|
-
}
|
|
19
|
+
};
|
|
20
|
+
export var usePlainQueryData = function usePlainQueryData(context, dataSource, params, options) {
|
|
21
|
+
var extendedOptions = composeOptions(context, dataSource, params, options);
|
|
22
|
+
var composedOptions = usePlainQueryDataOptions(extendedOptions);
|
|
23
|
+
var state = useQuery(composedOptions);
|
|
24
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
25
|
+
status: normalizeStatus(state.status, state.fetchStatus),
|
|
26
|
+
originalStatus: state.status
|
|
27
|
+
});
|
|
28
|
+
};
|
|
30
29
|
// #sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useQuery","useRefetchInterval","normalizeStatus","composeOptions","
|
|
1
|
+
{"version":3,"names":["useQuery","useRefetchInterval","normalizeStatus","composeOptions","usePlainQueryDataOptions","composedOptions","queryFnOption","queryFn","refetchIntervalOption","refetchInterval","restOptions","_objectWithoutProperties","_excluded","_useRefetchInterval","_objectSpread","usePlainQueryData","context","dataSource","params","options","extendedOptions","state","status","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,SAAmCA,QAAQ,QAAO,uBAAuB;AAYzE,SAAQC,kBAAkB,QAAO,gCAAgC;AACjE,SAAQC,eAAe,QAAO,6BAA6B;AAG3D,SAAQC,cAAc,QAAO,SAAS;AAEtC,IAAMC,wBAAwB,GAAG,SAA3BA,wBAAwBA,CAC1BC,eAMC,EAOA;EACD,IACaC,aAAa,GAGtBD,eAAe,CAHfE,OAAO;IACUC,qBAAqB,GAEtCH,eAAe,CAFfI,eAAe;IACZC,WAAW,GAAAC,wBAAA,CACdN,eAAe,EAAAO,SAAA;EAEnB,IAAAC,mBAAA,GAAmCZ,kBAAkB,CAACO,qBAAqB,EAAEF,aAAa,CAAC;IAApFC,OAAO,GAAAM,mBAAA,CAAPN,OAAO;IAAEE,eAAe,GAAAI,mBAAA,CAAfJ,eAAe;EAE/B,OAAAK,aAAA,CAAAA,aAAA,KAAWJ,WAAW;IAAEH,OAAO,EAAPA,OAAO;IAAEE,eAAe,EAAfA;EAAe;AACpD,CAAC;AAED,OAAO,IAAMM,iBAAiB,GAAG,SAApBA,iBAAiBA,CAC1BC,OAAuC,EACvCC,UAAuB,EACvBC,MAAqC,EACrCC,OAAiD,EAClB;EAC/B,IAAMC,eAAe,GAAGjB,cAAc,CAACa,OAAO,EAAEC,UAAU,EAAEC,MAAM,EAAEC,OAAO,CAAC;EAC5E,IAAMd,eAAe,GAAGD,wBAAwB,CAACgB,eAAe,CAAC;EACjE,IAAMC,KAAK,GAAGrB,QAAQ,CAACK,eAAe,CAAC;EAEvC,OAAAS,aAAA,CAAAA,aAAA,KACOO,KAAK;IACRC,MAAM,EAAEpB,eAAe,CAACmB,KAAK,CAACC,MAAM,EAAED,KAAK,CAACE,WAAW,CAAC;IACxDC,cAAc,EAAEH,KAAK,CAACC;EAAM;AAEpC,CAAC","ignoreList":[]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { DefaultError, QueryFunctionContext, QueryKey, QueryObserverOptions, QueryObserverResult } from '@tanstack/react-query';
|
|
2
2
|
import type { Overwrite } from 'utility-types';
|
|
3
3
|
import type { ActualData, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
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>>;
|
|
6
7
|
export type PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, QueryObserverExtendedOptions<TResponse, TError, ActualData<TData, TResponse>, TResponse, DataSourceKey>, ResultWrapper<QueryObserverResult<ActualData<TData, TResponse>, TError>, TResponse, TData, TError>, QueryFunctionContext<DataSourceKey>> & {
|
|
7
8
|
type: 'plain';
|
|
8
9
|
};
|
|
@@ -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, DataLoaderStatus, DataSource, DataSourceKey} from '../../../core';\nimport type {
|
|
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, DataLoaderStatus, DataSource, DataSourceKey} 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> = DataSource<\n QueryDataSourceContext,\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n QueryObserverExtendedOptions<\n TResponse,\n TError,\n ActualData<TData, TResponse>,\n TResponse,\n DataSourceKey\n >,\n ResultWrapper<\n QueryObserverResult<ActualData<TData, TResponse>, TError>,\n TResponse,\n TData,\n TError\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>;\n\ntype ResultWrapper<TResult, TResponse, TData, TError> =\n TResult extends QueryObserverResult<ActualData<TData, TResponse>, TError>\n ? Overwrite<TResult, {status: DataLoaderStatus}> & {originalStatus: TResult['status']}\n : never;\n"],"mappings":"","ignoreList":[]}
|