@gravity-ui/data-source 0.2.1 → 0.3.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/core/types/DataSource.d.ts +3 -3
- package/build/cjs/core/types/DataSource.js.map +1 -1
- package/build/cjs/core/utils/composeFullKey.d.ts +1 -1
- package/build/cjs/core/utils/composeFullKey.js.map +1 -1
- package/build/cjs/core/utils/composeKey.js +1 -1
- package/build/cjs/core/utils/composeKey.js.map +1 -1
- package/build/cjs/react/components/DataInfiniteLoader/types.d.ts +1 -1
- package/build/cjs/react/components/DataInfiniteLoader/types.js.map +1 -1
- package/build/cjs/react/components/DataLoader/types.d.ts +1 -1
- package/build/cjs/react/components/DataLoader/types.js.map +1 -1
- package/build/cjs/react-query/hooks/useQueryData.d.ts +1 -1
- package/build/cjs/react-query/hooks/useQueryData.js +8 -4
- package/build/cjs/react-query/hooks/useQueryData.js.map +1 -1
- package/build/cjs/react-query/impl/infinite/factory.d.ts +1 -1
- package/build/cjs/react-query/impl/infinite/factory.js.map +1 -1
- package/build/cjs/react-query/impl/infinite/hooks.d.ts +2 -2
- package/build/cjs/react-query/impl/infinite/hooks.js +1 -4
- package/build/cjs/react-query/impl/infinite/hooks.js.map +1 -1
- package/build/cjs/react-query/impl/infinite/types.d.ts +10 -8
- package/build/cjs/react-query/impl/infinite/types.js.map +1 -1
- package/build/cjs/react-query/impl/infinite/utils.d.ts +5 -5
- package/build/cjs/react-query/impl/infinite/utils.js +12 -10
- package/build/cjs/react-query/impl/infinite/utils.js.map +1 -1
- package/build/cjs/react-query/impl/plain/factory.d.ts +1 -1
- package/build/cjs/react-query/impl/plain/factory.js.map +1 -1
- package/build/cjs/react-query/impl/plain/hooks.d.ts +2 -2
- package/build/cjs/react-query/impl/plain/hooks.js +1 -4
- package/build/cjs/react-query/impl/plain/hooks.js.map +1 -1
- package/build/cjs/react-query/impl/plain/types.d.ts +3 -3
- package/build/cjs/react-query/impl/plain/types.js.map +1 -1
- package/build/cjs/react-query/impl/plain/utils.d.ts +3 -3
- package/build/cjs/react-query/impl/plain/utils.js +7 -6
- package/build/cjs/react-query/impl/plain/utils.js.map +1 -1
- package/build/cjs/react-query/utils/normalizeStatus.js +4 -1
- package/build/cjs/react-query/utils/normalizeStatus.js.map +1 -1
- package/build/cjs/react-query/utils/notReachable.d.ts +1 -0
- package/build/cjs/react-query/utils/notReachable.js +10 -0
- package/build/cjs/react-query/utils/notReachable.js.map +1 -0
- package/build/esm/core/types/DataSource.d.ts +3 -3
- package/build/esm/core/types/DataSource.js.map +1 -1
- package/build/esm/core/utils/composeFullKey.d.ts +1 -1
- package/build/esm/core/utils/composeFullKey.js.map +1 -1
- package/build/esm/core/utils/composeKey.js +2 -2
- package/build/esm/core/utils/composeKey.js.map +1 -1
- package/build/esm/react/components/DataInfiniteLoader/types.d.ts +1 -1
- package/build/esm/react/components/DataInfiniteLoader/types.js.map +1 -1
- package/build/esm/react/components/DataLoader/types.d.ts +1 -1
- package/build/esm/react/components/DataLoader/types.js.map +1 -1
- package/build/esm/react-query/hooks/useQueryData.d.ts +1 -1
- package/build/esm/react-query/hooks/useQueryData.js +8 -4
- package/build/esm/react-query/hooks/useQueryData.js.map +1 -1
- package/build/esm/react-query/impl/infinite/factory.d.ts +1 -1
- package/build/esm/react-query/impl/infinite/factory.js.map +1 -1
- package/build/esm/react-query/impl/infinite/hooks.d.ts +2 -2
- package/build/esm/react-query/impl/infinite/hooks.js +1 -4
- package/build/esm/react-query/impl/infinite/hooks.js.map +1 -1
- package/build/esm/react-query/impl/infinite/types.d.ts +10 -8
- package/build/esm/react-query/impl/infinite/types.js.map +1 -1
- package/build/esm/react-query/impl/infinite/utils.d.ts +5 -5
- package/build/esm/react-query/impl/infinite/utils.js +12 -10
- package/build/esm/react-query/impl/infinite/utils.js.map +1 -1
- package/build/esm/react-query/impl/plain/factory.d.ts +1 -1
- package/build/esm/react-query/impl/plain/factory.js.map +1 -1
- package/build/esm/react-query/impl/plain/hooks.d.ts +2 -2
- package/build/esm/react-query/impl/plain/hooks.js +1 -4
- package/build/esm/react-query/impl/plain/hooks.js.map +1 -1
- package/build/esm/react-query/impl/plain/types.d.ts +3 -3
- package/build/esm/react-query/impl/plain/types.js.map +1 -1
- package/build/esm/react-query/impl/plain/utils.d.ts +3 -3
- package/build/esm/react-query/impl/plain/utils.js +7 -6
- package/build/esm/react-query/impl/plain/utils.js.map +1 -1
- package/build/esm/react-query/utils/normalizeStatus.js +4 -1
- package/build/esm/react-query/utils/normalizeStatus.js.map +1 -1
- package/build/esm/react-query/utils/notReachable.d.ts +1 -0
- package/build/esm/react-query/utils/notReachable.js +4 -0
- package/build/esm/react-query/utils/notReachable.js.map +1 -0
- package/package.json +4 -4
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { idle } from '../constants';
|
|
2
|
-
export type DataSourceKey =
|
|
2
|
+
export type DataSourceKey = ReadonlyArray<unknown>;
|
|
3
3
|
export type DataSourceTag = string;
|
|
4
4
|
declare const errorHintSymbol: unique symbol;
|
|
5
5
|
declare const stateHintSymbol: unique symbol;
|
|
6
|
-
export interface DataSource<TContext, TParams, TRequest, TResponse, TData, TError, TOptions, TState, TFetchContext> {
|
|
6
|
+
export interface DataSource<TContext, TParams, TRequest extends object, TResponse, TData, TError, TOptions extends object, TState, TFetchContext> {
|
|
7
7
|
readonly name: string;
|
|
8
8
|
fetch: (context: TContext, fetchContext: TFetchContext, request: TRequest) => Promise<TResponse> | TResponse;
|
|
9
9
|
tags?: (params: ActualParams<TParams, TRequest>) => DataSourceTag[];
|
|
10
10
|
transformParams?: (params: TParams) => TRequest;
|
|
11
11
|
transformResponse?: (response: TResponse) => TData;
|
|
12
12
|
[errorHintSymbol]?: TError;
|
|
13
|
-
options?: TOptions
|
|
13
|
+
options?: Partial<TOptions>;
|
|
14
14
|
[stateHintSymbol]?: TState;
|
|
15
15
|
}
|
|
16
16
|
export type AnyDataSource = DataSource<any, any, any, any, any, any, any, any, any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["DataSource.ts"],"sourcesContent":["import type {idle} from '../constants';\n\nexport type DataSourceKey =
|
|
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 errorHintSymbol: unique symbol;\ndeclare const stateHintSymbol: unique symbol;\n\nexport interface DataSource<\n TContext,\n TParams,\n TRequest extends object,\n TResponse,\n TData,\n TError,\n TOptions extends object,\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<TParams, TRequest>) => DataSourceTag[];\n\n transformParams?: (params: TParams) => TRequest;\n transformResponse?: (response: TResponse) => TData;\n\n [errorHintSymbol]?: TError;\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>;\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 _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 _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 _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 _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TResponse\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 _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? ActualData<TData, TResponse>\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 _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TError\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 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 _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 _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 ActualData<TData, TResponse> = unknown extends TData ? TResponse : TData;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { AnyDataSource, DataSourceParams } from '../types/DataSource';
|
|
2
|
-
export declare const composeFullKey: <TDataSource extends AnyDataSource>(dataSource: TDataSource, params: DataSourceParams<TDataSource>) =>
|
|
2
|
+
export declare const composeFullKey: <TDataSource extends AnyDataSource>(dataSource: TDataSource, params: DataSourceParams<TDataSource>) => ReadonlyArray<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["composeKey","composeFullKey","dataSource","params","_dataSource$tags","_dataSource$tags2","tags","call","name","concat","_toConsumableArray"],"sources":["composeFullKey.ts"],"sourcesContent":["import type {AnyDataSource, DataSourceParams} from '../types/DataSource';\n\nimport {composeKey} from './composeKey';\n\nexport const composeFullKey = <TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n):
|
|
1
|
+
{"version":3,"names":["composeKey","composeFullKey","dataSource","params","_dataSource$tags","_dataSource$tags2","tags","call","name","concat","_toConsumableArray"],"sources":["composeFullKey.ts"],"sourcesContent":["import type {AnyDataSource, DataSourceParams} from '../types/DataSource';\n\nimport {composeKey} from './composeKey';\n\nexport const composeFullKey = <TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n): ReadonlyArray<string> => {\n const tags = dataSource.tags?.(params) ?? [];\n\n return [dataSource.name, ...tags, composeKey(dataSource, params)];\n};\n"],"mappings":";AAEA,SAAQA,UAAU,QAAO,cAAc;AAEvC,OAAO,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CACvBC,UAAuB,EACvBC,MAAqC,EACb;EAAA,IAAAC,gBAAA,EAAAC,iBAAA;EACxB,IAAMC,IAAI,IAAAF,gBAAA,IAAAC,iBAAA,GAAGH,UAAU,CAACI,IAAI,cAAAD,iBAAA,uBAAfA,iBAAA,CAAAE,IAAA,CAAAL,UAAU,EAAQC,MAAM,CAAC,cAAAC,gBAAA,cAAAA,gBAAA,GAAI,EAAE;EAE5C,QAAQF,UAAU,CAACM,IAAI,EAAAC,MAAA,CAAAC,kBAAA,CAAKJ,IAAI,IAAEN,UAAU,CAACE,UAAU,EAAEC,MAAM,CAAC;AACpE,CAAC","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// TODO(DakEnviy): Do not use react-query in core
|
|
2
|
-
import {
|
|
2
|
+
import { hashKey } from '@tanstack/react-query';
|
|
3
3
|
import { idle } from '../constants';
|
|
4
4
|
export var composeKey = function composeKey(dataSource, params) {
|
|
5
|
-
return params === idle ? "".concat(dataSource.name, ":idle") : "".concat(dataSource.name, "(").concat(
|
|
5
|
+
return params === idle ? "".concat(dataSource.name, ":idle") : "".concat(dataSource.name, "(").concat(hashKey(params), ")");
|
|
6
6
|
};
|
|
7
7
|
// #sourceMappingURL=composeKey.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["hashKey","idle","composeKey","dataSource","params","concat","name"],"sources":["composeKey.ts"],"sourcesContent":["// TODO(DakEnviy): Do not use react-query in core\nimport {hashKey} from '@tanstack/react-query';\n\nimport {idle} from '../constants';\nimport type {AnyDataSource, DataSourceParams} from '../types/DataSource';\n\nexport const composeKey = <TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n): string =>\n params === idle ? `${dataSource.name}:idle` : `${dataSource.name}(${hashKey(params)})`;\n"],"mappings":"AAAA;AACA,SAAQA,OAAO,QAAO,uBAAuB;AAE7C,SAAQC,IAAI,QAAO,cAAc;AAGjC,OAAO,IAAMC,UAAU,GAAG,SAAbA,UAAUA,CACnBC,UAAuB,EACvBC,MAAqC;EAAA,OAErCA,MAAM,KAAKH,IAAI,MAAAI,MAAA,CAAMF,UAAU,CAACG,IAAI,gBAAAD,MAAA,CAAaF,UAAU,CAACG,IAAI,OAAAD,MAAA,CAAIL,OAAO,CAACI,MAAM,CAAC,MAAG;AAAA","ignoreList":[]}
|
|
@@ -5,7 +5,7 @@ export interface MoreViewProps {
|
|
|
5
5
|
isLoading: boolean;
|
|
6
6
|
onClick: () => void;
|
|
7
7
|
}
|
|
8
|
-
export interface DataInfiniteLoaderProps<TError, TLoadingViewProps extends
|
|
8
|
+
export interface DataInfiniteLoaderProps<TError, TLoadingViewProps extends object = {}, TErrorViewProps extends ErrorViewProps<TError> = ErrorViewProps<TError>, TMoreViewProps extends MoreViewProps = MoreViewProps> {
|
|
9
9
|
status: DataLoaderStatus;
|
|
10
10
|
error: TError | null;
|
|
11
11
|
errorAction?: ErrorAction | ErrorAction['handler'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {ComponentType, ReactNode} from 'react';\n\nimport type {DataLoaderStatus} from '../../../core';\nimport type {ErrorAction, ErrorViewProps} from '../types';\n\nexport interface MoreViewProps {\n isLoading: boolean;\n onClick: () => void;\n}\n\nexport interface DataInfiniteLoaderProps<\n TError,\n TLoadingViewProps extends
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {ComponentType, ReactNode} from 'react';\n\nimport type {DataLoaderStatus} from '../../../core';\nimport type {ErrorAction, ErrorViewProps} from '../types';\n\nexport interface MoreViewProps {\n isLoading: boolean;\n onClick: () => void;\n}\n\nexport interface DataInfiniteLoaderProps<\n TError,\n TLoadingViewProps extends object = {},\n TErrorViewProps extends ErrorViewProps<TError> = ErrorViewProps<TError>,\n TMoreViewProps extends MoreViewProps = MoreViewProps,\n> {\n status: DataLoaderStatus;\n error: TError | null;\n errorAction?: ErrorAction | ErrorAction['handler'];\n hasNextPage: boolean;\n fetchNextPage: () => unknown;\n isFetchingNextPage: boolean;\n LoadingView: ComponentType<TLoadingViewProps>;\n ErrorView: ComponentType<TErrorViewProps>;\n MoreView: ComponentType<TMoreViewProps>;\n loadingViewProps?: TLoadingViewProps;\n errorViewProps?: Omit<TErrorViewProps, keyof ErrorViewProps<TError>>;\n moreViewProps?: Omit<TMoreViewProps, keyof MoreViewProps>;\n children: ReactNode;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ComponentType, ReactNode } from 'react';
|
|
2
2
|
import type { DataLoaderStatus } from '../../../core';
|
|
3
3
|
import type { ErrorAction, ErrorViewProps } from '../types';
|
|
4
|
-
export interface DataLoaderProps<TError, TLoadingViewProps extends
|
|
4
|
+
export interface DataLoaderProps<TError, TLoadingViewProps extends object = {}, TErrorViewProps extends ErrorViewProps<TError> = ErrorViewProps<TError>> {
|
|
5
5
|
status: DataLoaderStatus;
|
|
6
6
|
error: TError | null;
|
|
7
7
|
errorAction?: ErrorAction | ErrorAction['handler'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {ComponentType, ReactNode} from 'react';\n\nimport type {DataLoaderStatus} from '../../../core';\nimport type {ErrorAction, ErrorViewProps} from '../types';\n\nexport interface DataLoaderProps<\n TError,\n TLoadingViewProps extends
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {ComponentType, ReactNode} from 'react';\n\nimport type {DataLoaderStatus} from '../../../core';\nimport type {ErrorAction, ErrorViewProps} from '../types';\n\nexport interface DataLoaderProps<\n TError,\n TLoadingViewProps extends object = {},\n TErrorViewProps extends ErrorViewProps<TError> = ErrorViewProps<TError>,\n> {\n status: DataLoaderStatus;\n error: TError | null;\n errorAction?: ErrorAction | ErrorAction['handler'];\n LoadingView: ComponentType<TLoadingViewProps>;\n ErrorView: ComponentType<TErrorViewProps>;\n loadingViewProps?: TLoadingViewProps;\n errorViewProps?: Omit<TErrorViewProps, keyof ErrorViewProps<TError>>;\n children: ReactNode;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { DataSourceOptions, DataSourceParams, DataSourceState } from '../../core';
|
|
2
2
|
import type { AnyQueryDataSource } from '../types';
|
|
3
|
-
export declare const useQueryData: <TDataSource extends AnyQueryDataSource>(dataSource: TDataSource, params: DataSourceParams<TDataSource>, options?: DataSourceOptions<TDataSource
|
|
3
|
+
export declare const useQueryData: <TDataSource extends AnyQueryDataSource>(dataSource: TDataSource, params: DataSourceParams<TDataSource>, options?: Partial<DataSourceOptions<TDataSource>>) => DataSourceState<TDataSource>;
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { useInfiniteQueryData } from '../impl/infinite/hooks';
|
|
2
2
|
import { usePlainQueryData } from '../impl/plain/hooks';
|
|
3
|
+
import { notReachable } from '../utils/notReachable';
|
|
3
4
|
import { useQueryContext } from './useQueryContext';
|
|
4
5
|
export var useQueryData = function useQueryData(dataSource, params, options) {
|
|
5
6
|
var context = useQueryContext();
|
|
7
|
+
var type = dataSource.type;
|
|
6
8
|
var state;
|
|
7
9
|
|
|
8
10
|
// Do not change data source type in the same hook call
|
|
9
|
-
if (
|
|
11
|
+
if (type === 'plain') {
|
|
10
12
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
11
13
|
state = usePlainQueryData(context, dataSource, params, options);
|
|
12
|
-
} else if (
|
|
14
|
+
} else if (type === 'infinite') {
|
|
13
15
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
14
|
-
state = useInfiniteQueryData(context, dataSource, params,
|
|
16
|
+
state = useInfiniteQueryData(context, dataSource, params,
|
|
17
|
+
// TS can't calculate types in this place
|
|
18
|
+
options);
|
|
15
19
|
} else {
|
|
16
|
-
|
|
20
|
+
return notReachable(type, "Data Source type must be plain or infinite, got: ".concat(type));
|
|
17
21
|
}
|
|
18
22
|
return state;
|
|
19
23
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useInfiniteQueryData","usePlainQueryData","useQueryContext","useQueryData","dataSource","params","options","context","
|
|
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 {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(context, dataSource, params, options);\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;AAErD,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,CAACO,OAAO,EAAEH,UAAU,EAAEC,MAAM,EAAEC,OAAO,CAAC;EACnE,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,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 extends object, TResponse, TData, TError>(config: Omit<InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError>, "type">) => InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError>;
|
|
@@ -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 extends object,\n TResponse,\n TData,\n TError,\n>(\n config: Omit<InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError>, 'type'>,\n): InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError> => ({\n ...config,\n type: 'infinite',\n});\n"],"mappings":";AAEA,OAAO,IAAMA,2BAA2B,GAAG,SAA9BA,2BAA2BA,CAOpCC,MAA0F;EAAA,OAAAC,aAAA,CAAAA,aAAA,KAEvFD,MAAM;IACTE,IAAI,EAAE;EAAU;AAAA,CAClB","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { DataSourceContext, DataSourceOptions, DataSourceParams } from '../../../core';
|
|
1
|
+
import type { DataSourceContext, DataSourceOptions, DataSourceParams, DataSourceState } from '../../../core';
|
|
2
2
|
import type { AnyInfiniteQueryDataSource } from './types';
|
|
3
|
-
export declare const useInfiniteQueryData: <TDataSource extends AnyInfiniteQueryDataSource>(context: DataSourceContext<TDataSource>, dataSource: TDataSource, params: DataSourceParams<TDataSource>, options?: DataSourceOptions<TDataSource
|
|
3
|
+
export declare const useInfiniteQueryData: <TDataSource extends AnyInfiniteQueryDataSource>(context: DataSourceContext<TDataSource>, dataSource: TDataSource, params: DataSourceParams<TDataSource>, options?: Partial<DataSourceOptions<TDataSource>>) => DataSourceState<TDataSource>;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
1
|
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
3
2
|
import { composeOptions, transformResult } from './utils';
|
|
4
3
|
export var useInfiniteQueryData = function useInfiniteQueryData(context, dataSource, params, options) {
|
|
5
4
|
var composedOptions = composeOptions(context, dataSource, params, options);
|
|
6
5
|
var result = useInfiniteQuery(composedOptions);
|
|
7
|
-
return
|
|
8
|
-
return transformResult(result);
|
|
9
|
-
}, [result]);
|
|
6
|
+
return transformResult(result);
|
|
10
7
|
};
|
|
11
8
|
// #sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["useInfiniteQuery","composeOptions","transformResult","useInfiniteQueryData","context","dataSource","params","options","composedOptions","result"],"sources":["hooks.ts"],"sourcesContent":["import {useInfiniteQuery} from '@tanstack/react-query';\n\nimport type {\n DataSourceContext,\n DataSourceOptions,\n DataSourceParams,\n DataSourceState,\n} from '../../../core';\n\nimport type {AnyInfiniteQueryDataSource} from './types';\nimport {composeOptions, transformResult} from './utils';\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 composedOptions = composeOptions(context, dataSource, params, options);\n const result = useInfiniteQuery(composedOptions);\n\n return transformResult(result);\n};\n"],"mappings":"AAAA,SAAQA,gBAAgB,QAAO,uBAAuB;AAUtD,SAAQC,cAAc,EAAEC,eAAe,QAAO,SAAS;AAEvD,OAAO,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAoBA,CAC7BC,OAAuC,EACvCC,UAAuB,EACvBC,MAAqC,EACrCC,OAAiD,EAClB;EAC/B,IAAMC,eAAe,GAAGP,cAAc,CAACG,OAAO,EAAEC,UAAU,EAAEC,MAAM,EAAEC,OAAO,CAAC;EAC5E,IAAME,MAAM,GAAGT,gBAAgB,CAACQ,eAAe,CAAC;EAEhD,OAAON,eAAe,CAACO,MAAM,CAAC;AAClC,CAAC","ignoreList":[]}
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import type { InfiniteQueryObserverOptions, InfiniteQueryObserverResult, QueryFunctionContext } from '@tanstack/react-query';
|
|
1
|
+
import type { InfiniteData, InfiniteQueryObserverOptions, InfiniteQueryObserverResult, QueryFunctionContext } from '@tanstack/react-query';
|
|
2
2
|
import type { Overwrite } from 'utility-types';
|
|
3
3
|
import type { ActualData, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
4
4
|
import type { QueryDataSourceContext } from '../../types';
|
|
5
|
-
export type InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, InfiniteQueryObserverOptions<TResponse, TError, ActualData<TData, TResponse>, TResponse
|
|
5
|
+
export type InfiniteQueryDataSource<TParams, TRequest extends object, TResponse, TData, TError> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, InfiniteQueryObserverOptions<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>>> & {
|
|
6
6
|
type: 'infinite';
|
|
7
|
-
next: (lastPage: TResponse, allPages: TResponse[]) => Partial<TRequest> | undefined;
|
|
8
|
-
prev?: (firstPage: TResponse, allPages: TResponse[]) => Partial<TRequest> | undefined;
|
|
7
|
+
next: (lastPage: TResponse, allPages: TResponse[]) => Partial<TRequest> | null | undefined;
|
|
8
|
+
prev?: (firstPage: TResponse, allPages: TResponse[]) => Partial<TRequest> | null | undefined;
|
|
9
9
|
};
|
|
10
10
|
export type AnyInfiniteQueryDataSource = InfiniteQueryDataSource<any, any, any, any, any>;
|
|
11
|
-
type
|
|
11
|
+
export type AnyPageParam = Partial<any>;
|
|
12
|
+
type ResultWrapper<TResult, TRequest, TResponse, TData, TError> = TResult extends InfiniteQueryObserverResult<InfiniteData<ActualData<TData, TResponse>, Partial<TRequest>>, TError> ? Overwrite<TResult, {
|
|
12
13
|
status: DataLoaderStatus;
|
|
13
|
-
data: TData
|
|
14
|
+
data: DataWrapper<ActualData<TData, TResponse>>;
|
|
14
15
|
}> & {
|
|
15
|
-
originalStatus:
|
|
16
|
-
originalData:
|
|
16
|
+
originalStatus: TResult['status'];
|
|
17
|
+
originalData: TResult['data'];
|
|
17
18
|
} : never;
|
|
19
|
+
type DataWrapper<TActualData> = TActualData extends any[] ? TActualData : TActualData[];
|
|
18
20
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryFunctionContext,\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';\n\nexport type InfiniteQueryDataSource
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryFunctionContext,\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';\n\nexport type InfiniteQueryDataSource<\n TParams,\n TRequest extends object,\n TResponse,\n TData,\n TError,\n> = DataSource<\n QueryDataSourceContext,\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n InfiniteQueryObserverOptions<\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 {status: DataLoaderStatus; data: DataWrapper<ActualData<TData, TResponse>>}\n > & {\n originalStatus: TResult['status'];\n originalData: TResult['data'];\n }\n : never;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype DataWrapper<TActualData> = TActualData extends any[] ? TActualData : TActualData[];\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { InfiniteQueryObserverOptions, InfiniteQueryObserverResult } from '@tanstack/react-query';
|
|
2
|
-
import type { DataSourceContext, DataSourceData, DataSourceError, DataSourceOptions, DataSourceParams, DataSourceResponse, DataSourceState } from '../../../core';
|
|
3
|
-
import type { AnyInfiniteQueryDataSource } from './types';
|
|
4
|
-
export declare const composeOptions: <TDataSource extends AnyInfiniteQueryDataSource>(context: DataSourceContext<TDataSource>, dataSource: TDataSource, params: DataSourceParams<TDataSource>, options?: DataSourceOptions<TDataSource
|
|
5
|
-
export declare const transformResult: <TDataSource extends AnyInfiniteQueryDataSource>(result: InfiniteQueryObserverResult<DataSourceData<TDataSource>, DataSourceError<TDataSource>>) => DataSourceState<TDataSource>;
|
|
1
|
+
import type { InfiniteData, InfiniteQueryObserverOptions, InfiniteQueryObserverResult } from '@tanstack/react-query';
|
|
2
|
+
import type { DataSourceContext, DataSourceData, DataSourceError, DataSourceKey, DataSourceOptions, DataSourceParams, DataSourceResponse, DataSourceState } from '../../../core';
|
|
3
|
+
import type { AnyInfiniteQueryDataSource, AnyPageParam } from './types';
|
|
4
|
+
export declare const composeOptions: <TDataSource extends AnyInfiniteQueryDataSource>(context: DataSourceContext<TDataSource>, dataSource: TDataSource, params: DataSourceParams<TDataSource>, options?: Partial<DataSourceOptions<TDataSource>>) => InfiniteQueryObserverOptions<DataSourceResponse<TDataSource>, DataSourceError<TDataSource>, InfiniteData<DataSourceData<TDataSource>, AnyPageParam>, DataSourceResponse<TDataSource>, DataSourceKey, AnyPageParam>;
|
|
5
|
+
export declare const transformResult: <TDataSource extends AnyInfiniteQueryDataSource>(result: InfiniteQueryObserverResult<InfiniteData<DataSourceData<TDataSource>, AnyPageParam>, DataSourceError<TDataSource>>) => DataSourceState<TDataSource>;
|
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
1
|
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
2
|
+
import { skipToken } from '@tanstack/react-query';
|
|
3
3
|
import { composeFullKey, idle } from '../../../core';
|
|
4
4
|
import { normalizeStatus } from '../../utils/normalizeStatus';
|
|
5
5
|
var EMPTY_ARRAY = [];
|
|
6
|
+
var EMPTY_OBJECT = {};
|
|
6
7
|
export var composeOptions = function composeOptions(context, dataSource, params, options) {
|
|
7
8
|
var transformParams = dataSource.transformParams,
|
|
8
9
|
transformResponse = dataSource.transformResponse,
|
|
9
10
|
next = dataSource.next,
|
|
10
11
|
prev = dataSource.prev;
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
var queryFn = function queryFn(fetchContext) {
|
|
13
|
+
var request = transformParams ? transformParams(params) : params;
|
|
14
|
+
var paginatedRequest = _objectSpread(_objectSpread({}, request), fetchContext.pageParam);
|
|
15
|
+
return dataSource.fetch(context, fetchContext, paginatedRequest);
|
|
16
|
+
};
|
|
17
|
+
return _objectSpread(_objectSpread({
|
|
13
18
|
queryKey: composeFullKey(dataSource, params),
|
|
14
|
-
queryFn:
|
|
15
|
-
var actualParams = transformParams ? transformParams(params) : params;
|
|
16
|
-
var request = _typeof(actualParams) === 'object' ? _objectSpread(_objectSpread({}, actualParams), fetchContext.pageParam) : actualParams;
|
|
17
|
-
return dataSource.fetch(context, fetchContext, request);
|
|
18
|
-
},
|
|
19
|
+
queryFn: params === idle ? skipToken : queryFn,
|
|
19
20
|
select: transformResponse ? function (data) {
|
|
20
21
|
return _objectSpread(_objectSpread({}, data), {}, {
|
|
21
22
|
pages: data.pages.map(transformResponse)
|
|
22
23
|
});
|
|
23
24
|
} : undefined,
|
|
25
|
+
initialPageParam: EMPTY_OBJECT,
|
|
24
26
|
getNextPageParam: next,
|
|
25
27
|
getPreviousPageParam: prev
|
|
26
|
-
}, options);
|
|
28
|
+
}, dataSource.options), options);
|
|
27
29
|
};
|
|
28
30
|
export var transformResult = function transformResult(result) {
|
|
29
31
|
var _result$data$pages$fl, _result$data;
|
|
30
32
|
return _objectSpread(_objectSpread({}, result), {}, {
|
|
31
33
|
status: normalizeStatus(result.status, result.fetchStatus),
|
|
32
|
-
data: (_result$data$pages$fl = (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.pages.flat()) !== null && _result$data$pages$fl !== void 0 ? _result$data$pages$fl : EMPTY_ARRAY,
|
|
34
|
+
data: (_result$data$pages$fl = (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.pages.flat(1)) !== null && _result$data$pages$fl !== void 0 ? _result$data$pages$fl : EMPTY_ARRAY,
|
|
33
35
|
originalStatus: result.status,
|
|
34
36
|
originalData: result.data
|
|
35
37
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["composeFullKey","idle","normalizeStatus","EMPTY_ARRAY","composeOptions","context","dataSource","params","options","transformParams","transformResponse","next","prev","
|
|
1
|
+
{"version":3,"names":["skipToken","composeFullKey","idle","normalizeStatus","EMPTY_ARRAY","EMPTY_OBJECT","composeOptions","context","dataSource","params","options","transformParams","transformResponse","next","prev","queryFn","fetchContext","request","paginatedRequest","_objectSpread","pageParam","fetch","queryKey","select","data","pages","map","undefined","initialPageParam","getNextPageParam","getPreviousPageParam","transformResult","result","_result$data$pages$fl","_result$data","status","fetchStatus","flat","originalStatus","originalData"],"sources":["utils.ts"],"sourcesContent":["import {skipToken} from '@tanstack/react-query';\nimport type {\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryFunctionContext,\n} 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 DataSourceState,\n} from '../../../core';\nimport {normalizeStatus} from '../../utils/normalizeStatus';\n\nimport type {AnyInfiniteQueryDataSource, AnyPageParam} from './types';\n\nconst EMPTY_ARRAY: unknown[] = [];\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): InfiniteQueryObserverOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n InfiniteData<DataSourceData<TDataSource>, AnyPageParam>,\n DataSourceResponse<TDataSource>,\n DataSourceKey,\n AnyPageParam\n> => {\n const {transformParams, transformResponse, next, prev} = dataSource;\n\n const queryFn = (\n fetchContext: QueryFunctionContext<DataSourceKey, AnyPageParam>,\n ): DataSourceResponse<TDataSource> | Promise<DataSourceResponse<TDataSource>> => {\n const request = transformParams ? transformParams(params) : params;\n const paginatedRequest = {...request, ...fetchContext.pageParam};\n\n return dataSource.fetch(context, fetchContext, paginatedRequest);\n };\n\n return {\n queryKey: composeFullKey(dataSource, params),\n queryFn: params === idle ? skipToken : queryFn,\n select: transformResponse\n ? (data) => ({...data, pages: data.pages.map(transformResponse)})\n : undefined,\n initialPageParam: EMPTY_OBJECT,\n getNextPageParam: next,\n getPreviousPageParam: prev,\n ...dataSource.options,\n ...options,\n };\n};\n\nexport const transformResult = <TDataSource extends AnyInfiniteQueryDataSource>(\n result: InfiniteQueryObserverResult<\n InfiniteData<DataSourceData<TDataSource>, AnyPageParam>,\n DataSourceError<TDataSource>\n >,\n): DataSourceState<TDataSource> => {\n return {\n ...result,\n status: normalizeStatus(result.status, result.fetchStatus),\n data: result.data?.pages.flat(1) ?? EMPTY_ARRAY,\n originalStatus: result.status,\n originalData: result.data,\n } as DataSourceState<TDataSource>;\n};\n"],"mappings":";AAAA,SAAQA,SAAS,QAAO,uBAAuB;AAQ/C,SAAQC,cAAc,EAAEC,IAAI,QAAO,eAAe;AAWlD,SAAQC,eAAe,QAAO,6BAA6B;AAI3D,IAAMC,WAAsB,GAAG,EAAE;AACjC,IAAMC,YAAY,GAAG,CAAC,CAAC;AAEvB,OAAO,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CACvBC,OAAuC,EACvCC,UAAuB,EACvBC,MAAqC,EACrCC,OAAiD,EAQhD;EACD,IAAOC,eAAe,GAAmCH,UAAU,CAA5DG,eAAe;IAAEC,iBAAiB,GAAgBJ,UAAU,CAA3CI,iBAAiB;IAAEC,IAAI,GAAUL,UAAU,CAAxBK,IAAI;IAAEC,IAAI,GAAIN,UAAU,CAAlBM,IAAI;EAErD,IAAMC,OAAO,GAAG,SAAVA,OAAOA,CACTC,YAA+D,EACc;IAC7E,IAAMC,OAAO,GAAGN,eAAe,GAAGA,eAAe,CAACF,MAAM,CAAC,GAAGA,MAAM;IAClE,IAAMS,gBAAgB,GAAAC,aAAA,CAAAA,aAAA,KAAOF,OAAO,GAAKD,YAAY,CAACI,SAAS,CAAC;IAEhE,OAAOZ,UAAU,CAACa,KAAK,CAACd,OAAO,EAAES,YAAY,EAAEE,gBAAgB,CAAC;EACpE,CAAC;EAED,OAAAC,aAAA,CAAAA,aAAA;IACIG,QAAQ,EAAErB,cAAc,CAACO,UAAU,EAAEC,MAAM,CAAC;IAC5CM,OAAO,EAAEN,MAAM,KAAKP,IAAI,GAAGF,SAAS,GAAGe,OAAO;IAC9CQ,MAAM,EAAEX,iBAAiB,GACnB,UAACY,IAAI;MAAA,OAAAL,aAAA,CAAAA,aAAA,KAAUK,IAAI;QAAEC,KAAK,EAAED,IAAI,CAACC,KAAK,CAACC,GAAG,CAACd,iBAAiB;MAAC;IAAA,CAAE,GAC/De,SAAS;IACfC,gBAAgB,EAAEvB,YAAY;IAC9BwB,gBAAgB,EAAEhB,IAAI;IACtBiB,oBAAoB,EAAEhB;EAAI,GACvBN,UAAU,CAACE,OAAO,GAClBA,OAAO;AAElB,CAAC;AAED,OAAO,IAAMqB,eAAe,GAAG,SAAlBA,eAAeA,CACxBC,MAGC,EAC8B;EAAA,IAAAC,qBAAA,EAAAC,YAAA;EAC/B,OAAAf,aAAA,CAAAA,aAAA,KACOa,MAAM;IACTG,MAAM,EAAEhC,eAAe,CAAC6B,MAAM,CAACG,MAAM,EAAEH,MAAM,CAACI,WAAW,CAAC;IAC1DZ,IAAI,GAAAS,qBAAA,IAAAC,YAAA,GAAEF,MAAM,CAACR,IAAI,cAAAU,YAAA,uBAAXA,YAAA,CAAaT,KAAK,CAACY,IAAI,CAAC,CAAC,CAAC,cAAAJ,qBAAA,cAAAA,qBAAA,GAAI7B,WAAW;IAC/CkC,cAAc,EAAEN,MAAM,CAACG,MAAM;IAC7BI,YAAY,EAAEP,MAAM,CAACR;EAAI;AAEjC,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { PlainQueryDataSource } from './types';
|
|
2
|
-
export declare const makePlainQueryDataSource: <TParams, TRequest, TResponse, TData, TError>(config: Omit<PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError>, "type">) => PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError>;
|
|
2
|
+
export declare const makePlainQueryDataSource: <TParams, TRequest extends object, TResponse, TData, TError>(config: Omit<PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError>, "type">) => PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["makePlainQueryDataSource","config","_objectSpread","type"],"sources":["factory.ts"],"sourcesContent":["import type {PlainQueryDataSource} from './types';\n\nexport const makePlainQueryDataSource =
|
|
1
|
+
{"version":3,"names":["makePlainQueryDataSource","config","_objectSpread","type"],"sources":["factory.ts"],"sourcesContent":["import type {PlainQueryDataSource} from './types';\n\nexport const makePlainQueryDataSource = <\n TParams,\n TRequest extends object,\n TResponse,\n TData,\n TError,\n>(\n config: Omit<PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError>, 'type'>,\n): PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError> => ({\n ...config,\n type: 'plain',\n});\n"],"mappings":";AAEA,OAAO,IAAMA,wBAAwB,GAAG,SAA3BA,wBAAwBA,CAOjCC,MAAuF;EAAA,OAAAC,aAAA,CAAAA,aAAA,KAEpFD,MAAM;IACTE,IAAI,EAAE;EAAO;AAAA,CACf","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { DataSourceContext, DataSourceOptions, DataSourceParams } from '../../../core';
|
|
1
|
+
import type { DataSourceContext, DataSourceOptions, DataSourceParams, DataSourceState } from '../../../core';
|
|
2
2
|
import type { AnyPlainQueryDataSource } from './types';
|
|
3
|
-
export declare const usePlainQueryData: <TDataSource extends AnyPlainQueryDataSource>(context: DataSourceContext<TDataSource>, dataSource: TDataSource, params: DataSourceParams<TDataSource>, options?: DataSourceOptions<TDataSource
|
|
3
|
+
export declare const usePlainQueryData: <TDataSource extends AnyPlainQueryDataSource>(context: DataSourceContext<TDataSource>, dataSource: TDataSource, params: DataSourceParams<TDataSource>, options?: Partial<DataSourceOptions<TDataSource>>) => DataSourceState<TDataSource>;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
1
|
import { useQuery } from '@tanstack/react-query';
|
|
3
2
|
import { composeOptions, transformResult } from './utils';
|
|
4
3
|
export var usePlainQueryData = function usePlainQueryData(context, dataSource, params, options) {
|
|
5
4
|
var composedOptions = composeOptions(context, dataSource, params, options);
|
|
6
5
|
var result = useQuery(composedOptions);
|
|
7
|
-
return
|
|
8
|
-
return transformResult(result);
|
|
9
|
-
}, [result]);
|
|
6
|
+
return transformResult(result);
|
|
10
7
|
};
|
|
11
8
|
// #sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["useQuery","composeOptions","transformResult","usePlainQueryData","context","dataSource","params","options","composedOptions","result"],"sources":["hooks.ts"],"sourcesContent":["import {useQuery} from '@tanstack/react-query';\n\nimport type {\n DataSourceContext,\n DataSourceOptions,\n DataSourceParams,\n DataSourceState,\n} from '../../../core';\n\nimport type {AnyPlainQueryDataSource} from './types';\nimport {composeOptions, transformResult} from './utils';\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 composedOptions = composeOptions(context, dataSource, params, options);\n const result = useQuery(composedOptions);\n\n return transformResult(result);\n};\n"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,uBAAuB;AAU9C,SAAQC,cAAc,EAAEC,eAAe,QAAO,SAAS;AAEvD,OAAO,IAAMC,iBAAiB,GAAG,SAApBA,iBAAiBA,CAC1BC,OAAuC,EACvCC,UAAuB,EACvBC,MAAqC,EACrCC,OAAiD,EAClB;EAC/B,IAAMC,eAAe,GAAGP,cAAc,CAACG,OAAO,EAAEC,UAAU,EAAEC,MAAM,EAAEC,OAAO,CAAC;EAC5E,IAAME,MAAM,GAAGT,QAAQ,CAACQ,eAAe,CAAC;EAExC,OAAON,eAAe,CAACO,MAAM,CAAC;AAClC,CAAC","ignoreList":[]}
|
|
@@ -2,13 +2,13 @@ import type { QueryFunctionContext, QueryObserverOptions, QueryObserverResult }
|
|
|
2
2
|
import type { Overwrite } from 'utility-types';
|
|
3
3
|
import type { ActualData, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
4
4
|
import type { QueryDataSourceContext } from '../../types';
|
|
5
|
-
export type PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, QueryObserverOptions<TResponse, TError, ActualData<TData, TResponse>, TResponse>, ResultWrapper<QueryObserverResult<ActualData<TData, TResponse>, TError>>, QueryFunctionContext<DataSourceKey
|
|
5
|
+
export type PlainQueryDataSource<TParams, TRequest extends object, TResponse, TData, TError> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, QueryObserverOptions<TResponse, TError, ActualData<TData, TResponse>, TResponse, DataSourceKey>, ResultWrapper<QueryObserverResult<ActualData<TData, TResponse>, TError>>, QueryFunctionContext<DataSourceKey>> & {
|
|
6
6
|
type: 'plain';
|
|
7
7
|
};
|
|
8
8
|
export type AnyPlainQueryDataSource = PlainQueryDataSource<any, any, any, any, any>;
|
|
9
|
-
type ResultWrapper<
|
|
9
|
+
type ResultWrapper<TResult> = TResult extends QueryObserverResult ? Overwrite<TResult, {
|
|
10
10
|
status: DataLoaderStatus;
|
|
11
11
|
}> & {
|
|
12
|
-
originalStatus:
|
|
12
|
+
originalStatus: TResult['status'];
|
|
13
13
|
} : never;
|
|
14
14
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n QueryFunctionContext,\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';\n\nexport type PlainQueryDataSource
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n QueryFunctionContext,\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';\n\nexport type PlainQueryDataSource<\n TParams,\n TRequest extends object,\n TResponse,\n TData,\n TError,\n> = DataSource<\n QueryDataSourceContext,\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n QueryObserverOptions<TResponse, TError, ActualData<TData, TResponse>, TResponse, DataSourceKey>,\n ResultWrapper<QueryObserverResult<ActualData<TData, TResponse>, TError>>,\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> = TResult extends QueryObserverResult\n ? Overwrite<TResult, {status: DataLoaderStatus}> & {originalStatus: TResult['status']}\n : never;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { DataSourceContext, DataSourceData, DataSourceError, DataSourceOptions, DataSourceParams, DataSourceResponse, DataSourceState } from '../../../core';
|
|
1
|
+
import { type QueryObserverOptions, type QueryObserverResult } from '@tanstack/react-query';
|
|
2
|
+
import type { DataSourceContext, DataSourceData, DataSourceError, DataSourceKey, DataSourceOptions, DataSourceParams, DataSourceResponse, DataSourceState } from '../../../core';
|
|
3
3
|
import type { AnyPlainQueryDataSource } from './types';
|
|
4
|
-
export declare const composeOptions: <TDataSource extends AnyPlainQueryDataSource>(context: DataSourceContext<TDataSource>, dataSource: TDataSource, params: DataSourceParams<TDataSource>, options?: DataSourceOptions<TDataSource
|
|
4
|
+
export declare const composeOptions: <TDataSource extends AnyPlainQueryDataSource>(context: DataSourceContext<TDataSource>, dataSource: TDataSource, params: DataSourceParams<TDataSource>, options?: Partial<DataSourceOptions<TDataSource>>) => QueryObserverOptions<DataSourceResponse<TDataSource>, DataSourceError<TDataSource>, DataSourceData<TDataSource>, DataSourceResponse<TDataSource>, DataSourceKey>;
|
|
5
5
|
export declare const transformResult: <TDataSource extends AnyPlainQueryDataSource>(result: QueryObserverResult<DataSourceData<TDataSource>, DataSourceError<TDataSource>>) => DataSourceState<TDataSource>;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
2
|
+
import { skipToken } from '@tanstack/react-query';
|
|
2
3
|
import { composeFullKey, idle } from '../../../core';
|
|
3
4
|
import { normalizeStatus } from '../../utils/normalizeStatus';
|
|
4
5
|
export var composeOptions = function composeOptions(context, dataSource, params, options) {
|
|
5
6
|
var transformParams = dataSource.transformParams;
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
var queryFn = function queryFn(fetchContext) {
|
|
8
|
+
return dataSource.fetch(context, fetchContext, transformParams ? transformParams(params) : params);
|
|
9
|
+
};
|
|
10
|
+
return _objectSpread(_objectSpread({
|
|
8
11
|
queryKey: composeFullKey(dataSource, params),
|
|
9
|
-
queryFn:
|
|
10
|
-
return dataSource.fetch(context, fetchContext, transformParams ? transformParams(params) : params);
|
|
11
|
-
},
|
|
12
|
+
queryFn: params === idle ? skipToken : queryFn,
|
|
12
13
|
select: dataSource.transformResponse
|
|
13
|
-
}, options);
|
|
14
|
+
}, dataSource.options), options);
|
|
14
15
|
};
|
|
15
16
|
export var transformResult = function transformResult(result) {
|
|
16
17
|
return _objectSpread(_objectSpread({}, result), {}, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["composeFullKey","idle","normalizeStatus","composeOptions","context","dataSource","params","options","transformParams","
|
|
1
|
+
{"version":3,"names":["skipToken","composeFullKey","idle","normalizeStatus","composeOptions","context","dataSource","params","options","transformParams","queryFn","fetchContext","fetch","_objectSpread","queryKey","select","transformResponse","transformResult","result","status","fetchStatus","originalStatus"],"sources":["utils.ts"],"sourcesContent":["import {\n type QueryFunctionContext,\n type QueryObserverOptions,\n type QueryObserverResult,\n skipToken,\n} 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 DataSourceState,\n} from '../../../core';\nimport {normalizeStatus} from '../../utils/normalizeStatus';\n\nimport type {AnyPlainQueryDataSource} 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): QueryObserverOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n DataSourceData<TDataSource>,\n DataSourceResponse<TDataSource>,\n DataSourceKey\n> => {\n const {transformParams} = dataSource;\n\n const queryFn = (\n fetchContext: QueryFunctionContext<DataSourceKey>,\n ): DataSourceResponse<TDataSource> | Promise<DataSourceResponse<TDataSource>> => {\n return dataSource.fetch(\n context,\n fetchContext,\n transformParams ? transformParams(params) : params,\n );\n };\n\n return {\n queryKey: composeFullKey(dataSource, params),\n queryFn: params === idle ? skipToken : queryFn,\n select: dataSource.transformResponse,\n ...dataSource.options,\n ...options,\n };\n};\n\nexport const transformResult = <TDataSource extends AnyPlainQueryDataSource>(\n result: QueryObserverResult<DataSourceData<TDataSource>, DataSourceError<TDataSource>>,\n): DataSourceState<TDataSource> => {\n return {\n ...result,\n status: normalizeStatus(result.status, result.fetchStatus),\n originalStatus: result.status,\n } as DataSourceState<TDataSource>;\n};\n"],"mappings":";AAAA,SAIIA,SAAS,QACN,uBAAuB;AAE9B,SAAQC,cAAc,EAAEC,IAAI,QAAO,eAAe;AAWlD,SAAQC,eAAe,QAAO,6BAA6B;AAI3D,OAAO,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CACvBC,OAAuC,EACvCC,UAAuB,EACvBC,MAAqC,EACrCC,OAAiD,EAOhD;EACD,IAAOC,eAAe,GAAIH,UAAU,CAA7BG,eAAe;EAEtB,IAAMC,OAAO,GAAG,SAAVA,OAAOA,CACTC,YAAiD,EAC4B;IAC7E,OAAOL,UAAU,CAACM,KAAK,CACnBP,OAAO,EACPM,YAAY,EACZF,eAAe,GAAGA,eAAe,CAACF,MAAM,CAAC,GAAGA,MAChD,CAAC;EACL,CAAC;EAED,OAAAM,aAAA,CAAAA,aAAA;IACIC,QAAQ,EAAEb,cAAc,CAACK,UAAU,EAAEC,MAAM,CAAC;IAC5CG,OAAO,EAAEH,MAAM,KAAKL,IAAI,GAAGF,SAAS,GAAGU,OAAO;IAC9CK,MAAM,EAAET,UAAU,CAACU;EAAiB,GACjCV,UAAU,CAACE,OAAO,GAClBA,OAAO;AAElB,CAAC;AAED,OAAO,IAAMS,eAAe,GAAG,SAAlBA,eAAeA,CACxBC,MAAsF,EACvD;EAC/B,OAAAL,aAAA,CAAAA,aAAA,KACOK,MAAM;IACTC,MAAM,EAAEhB,eAAe,CAACe,MAAM,CAACC,MAAM,EAAED,MAAM,CAACE,WAAW,CAAC;IAC1DC,cAAc,EAAEH,MAAM,CAACC;EAAM;AAErC,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["normalizeStatus","status","fetchStatus"],"sources":["normalizeStatus.ts"],"sourcesContent":["import type {FetchStatus, QueryStatus} from '@tanstack/react-query';\n\nimport type {DataLoaderStatus} from '../../core';\n\nexport const normalizeStatus = (\n status: QueryStatus,\n fetchStatus: FetchStatus,\n): DataLoaderStatus => {\n if (status === '
|
|
1
|
+
{"version":3,"names":["normalizeStatus","status","fetchStatus"],"sources":["normalizeStatus.ts"],"sourcesContent":["import type {FetchStatus, QueryStatus} from '@tanstack/react-query';\n\nimport type {DataLoaderStatus} from '../../core';\n\nexport const normalizeStatus = (\n status: QueryStatus,\n fetchStatus: FetchStatus,\n): DataLoaderStatus => {\n if (status === 'pending') {\n if (fetchStatus === 'fetching') {\n return 'loading';\n }\n\n return 'success';\n }\n\n return status;\n};\n"],"mappings":"AAIA,OAAO,IAAMA,eAAe,GAAG,SAAlBA,eAAeA,CACxBC,MAAmB,EACnBC,WAAwB,EACL;EACnB,IAAID,MAAM,KAAK,SAAS,EAAE;IACtB,IAAIC,WAAW,KAAK,UAAU,EAAE;MAC5B,OAAO,SAAS;IACpB;IAEA,OAAO,SAAS;EACpB;EAEA,OAAOD,MAAM;AACjB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const notReachable: (value: never, message?: string) => never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["notReachable","value","message","Error","concat"],"sources":["notReachable.ts"],"sourcesContent":["export const notReachable = (value: never, message?: string): never => {\n throw new Error(message || `Not reachable state: ${value}`);\n};\n"],"mappings":"AAAA,OAAO,IAAMA,YAAY,GAAG,SAAfA,YAAYA,CAAIC,KAAY,EAAEC,OAAgB,EAAY;EACnE,MAAM,IAAIC,KAAK,CAACD,OAAO,4BAAAE,MAAA,CAA4BH,KAAK,CAAE,CAAC;AAC/D,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/data-source",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-alpha.0",
|
|
4
4
|
"description": "A wrapper around data fetching",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-fetching",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@gravity-ui/prettier-config": "^1.1.0",
|
|
54
54
|
"@gravity-ui/tsconfig": "^1.0.0",
|
|
55
55
|
"@swc/jest": "^0.2.36",
|
|
56
|
-
"@tanstack/react-query": "^
|
|
56
|
+
"@tanstack/react-query": "^5.51.23",
|
|
57
57
|
"@types/jest": "^29.5.12",
|
|
58
58
|
"@types/react": "^18.3.3",
|
|
59
59
|
"eslint": "^8.57.0",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"react": "^18.3.1"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"@tanstack/react-query": "^
|
|
67
|
-
"react": "^
|
|
66
|
+
"@tanstack/react-query": "^5.0.0",
|
|
67
|
+
"react": "^18.0.0"
|
|
68
68
|
}
|
|
69
69
|
}
|