@gravity-ui/data-source 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/core/index.d.ts +1 -1
- package/build/cjs/core/index.js.map +1 -1
- package/build/cjs/core/types/DataSource.d.ts +21 -17
- package/build/cjs/core/types/DataSource.js.map +1 -1
- package/build/cjs/core/utils/skipContext.d.ts +24 -0
- package/build/cjs/core/utils/skipContext.js +24 -0
- package/build/cjs/core/utils/skipContext.js.map +1 -1
- package/build/cjs/react-query/impl/infinite/factory.d.ts +1 -1
- package/build/cjs/react-query/impl/infinite/factory.js.map +1 -1
- package/build/cjs/react-query/impl/infinite/types.d.ts +7 -7
- package/build/cjs/react-query/impl/infinite/types.js.map +1 -1
- package/build/cjs/react-query/impl/infinite/utils.js +44 -7
- package/build/cjs/react-query/impl/infinite/utils.js.map +1 -1
- package/build/cjs/react-query/impl/plain/factory.d.ts +1 -1
- package/build/cjs/react-query/impl/plain/factory.js.map +1 -1
- package/build/cjs/react-query/impl/plain/types.d.ts +4 -4
- package/build/cjs/react-query/impl/plain/types.js.map +1 -1
- package/build/cjs/react-query/impl/plain/utils.js +42 -4
- package/build/cjs/react-query/impl/plain/utils.js.map +1 -1
- package/build/cjs/react-query/impl/utils.d.ts +4 -0
- package/build/cjs/react-query/impl/utils.js +27 -0
- package/build/cjs/react-query/impl/utils.js.map +1 -0
- package/build/esm/core/index.d.ts +1 -1
- package/build/esm/core/index.js.map +1 -1
- package/build/esm/core/types/DataSource.d.ts +21 -17
- package/build/esm/core/types/DataSource.js.map +1 -1
- package/build/esm/core/utils/skipContext.d.ts +24 -0
- package/build/esm/core/utils/skipContext.js +24 -0
- package/build/esm/core/utils/skipContext.js.map +1 -1
- package/build/esm/react-query/impl/infinite/factory.d.ts +1 -1
- package/build/esm/react-query/impl/infinite/factory.js.map +1 -1
- package/build/esm/react-query/impl/infinite/types.d.ts +7 -7
- package/build/esm/react-query/impl/infinite/types.js.map +1 -1
- package/build/esm/react-query/impl/infinite/utils.js +44 -7
- package/build/esm/react-query/impl/infinite/utils.js.map +1 -1
- package/build/esm/react-query/impl/plain/factory.d.ts +1 -1
- package/build/esm/react-query/impl/plain/factory.js.map +1 -1
- package/build/esm/react-query/impl/plain/types.d.ts +4 -4
- package/build/esm/react-query/impl/plain/types.js.map +1 -1
- package/build/esm/react-query/impl/plain/utils.js +42 -4
- package/build/esm/react-query/impl/plain/utils.js.map +1 -1
- package/build/esm/react-query/impl/utils.d.ts +4 -0
- package/build/esm/react-query/impl/utils.js +21 -0
- package/build/esm/react-query/impl/utils.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { DataSourceKey, DataSourceTag, DataSource, AnyDataSource, DataSourceContext, DataSourceParams, DataSourceRequest, DataSourceResponse, DataSourceData, DataSourceError, DataSourceOptions, DataSourceState, DataSourceFetchContext, ActualParams, ActualData, } from './types/DataSource';
|
|
1
|
+
export type { DataSourceKey, DataSourceTag, DataSource, AnyDataSource, DataSourceContext, DataSourceParams, DataSourceRequest, DataSourceResponse, DataSourceErrorResponse, DataSourceData, DataSourceError, DataSourceOptions, DataSourceState, DataSourceFetchContext, ActualParams, ActualData, ActualResponse, } from './types/DataSource';
|
|
2
2
|
export type { DataManager } from './types/DataManger';
|
|
3
3
|
export type { DataLoaderStatus } from './types/DataLoaderStatus';
|
|
4
4
|
export type { InvalidateRepeatOptions, InvalidateOptions } from './types/DataManagerOptions';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_constants","require","_composeKey","_composeFullKey","_getError","_getStatus","_hasTag","_mergeStatuses","_skipContext","_withCancellation"],"sources":["index.ts"],"sourcesContent":["export type {\n DataSourceKey,\n DataSourceTag,\n DataSource,\n AnyDataSource,\n DataSourceContext,\n DataSourceParams,\n DataSourceRequest,\n DataSourceResponse,\n DataSourceData,\n DataSourceError,\n DataSourceOptions,\n DataSourceState,\n DataSourceFetchContext,\n ActualParams,\n ActualData,\n} from './types/DataSource';\nexport type {DataManager} from './types/DataManger';\nexport type {DataLoaderStatus} from './types/DataLoaderStatus';\nexport type {InvalidateRepeatOptions, InvalidateOptions} from './types/DataManagerOptions';\n\nexport {idle} from './constants';\n\nexport {composeKey} from './utils/composeKey';\nexport {composeFullKey} from './utils/composeFullKey';\nexport {getError} from './utils/getError';\nexport {getStatus} from './utils/getStatus';\nexport {hasTag} from './utils/hasTag';\nexport {mergeStatuses} from './utils/mergeStatuses';\nexport {skipContext} from './utils/skipContext';\nexport type {Cancellable} from './utils/withCancellation';\nexport {isCancellable, isAbortable, withCancellation} from './utils/withCancellation';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"names":["_constants","require","_composeKey","_composeFullKey","_getError","_getStatus","_hasTag","_mergeStatuses","_skipContext","_withCancellation"],"sources":["index.ts"],"sourcesContent":["export type {\n DataSourceKey,\n DataSourceTag,\n DataSource,\n AnyDataSource,\n DataSourceContext,\n DataSourceParams,\n DataSourceRequest,\n DataSourceResponse,\n DataSourceErrorResponse,\n DataSourceData,\n DataSourceError,\n DataSourceOptions,\n DataSourceState,\n DataSourceFetchContext,\n ActualParams,\n ActualData,\n ActualResponse,\n} from './types/DataSource';\nexport type {DataManager} from './types/DataManger';\nexport type {DataLoaderStatus} from './types/DataLoaderStatus';\nexport type {InvalidateRepeatOptions, InvalidateOptions} from './types/DataManagerOptions';\n\nexport {idle} from './constants';\n\nexport {composeKey} from './utils/composeKey';\nexport {composeFullKey} from './utils/composeFullKey';\nexport {getError} from './utils/getError';\nexport {getStatus} from './utils/getStatus';\nexport {hasTag} from './utils/hasTag';\nexport {mergeStatuses} from './utils/mergeStatuses';\nexport {skipContext} from './utils/skipContext';\nexport type {Cancellable} from './utils/withCancellation';\nexport {isCancellable, isAbortable, withCancellation} from './utils/withCancellation';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,IAAAA,UAAA,GAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,cAAA,GAAAN,OAAA;AACA,IAAAO,YAAA,GAAAP,OAAA;AAEA,IAAAQ,iBAAA,GAAAR,OAAA","ignoreList":[]}
|
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
import type { idle } from '../constants';
|
|
2
2
|
export type DataSourceKey = ReadonlyArray<unknown>;
|
|
3
3
|
export type DataSourceTag = string;
|
|
4
|
-
declare const errorHintSymbol: unique symbol;
|
|
5
4
|
declare const stateHintSymbol: unique symbol;
|
|
6
|
-
export interface DataSource<TContext, TParams, TRequest, TResponse, TData, TError, TOptions, TState, TFetchContext> {
|
|
5
|
+
export interface DataSource<TContext, TParams, TRequest, TResponse, TData, TError, TErrorResponse, TOptions, TState, TFetchContext> {
|
|
7
6
|
readonly name: string;
|
|
8
7
|
fetch: (context: TContext, fetchContext: TFetchContext, request: TRequest) => Promise<TResponse> | TResponse;
|
|
9
|
-
tags?: (params: ActualParams<TParams
|
|
10
|
-
transformParams?: (params: TParams) => TRequest
|
|
11
|
-
transformResponse?: (response: TResponse) => TData;
|
|
12
|
-
|
|
8
|
+
tags?: (params: ActualParams<NoInfer<TParams>, NoInfer<TRequest>>) => DataSourceTag[];
|
|
9
|
+
transformParams?: (params: TParams) => NoInfer<TRequest>;
|
|
10
|
+
transformResponse?: (response: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>) => TData;
|
|
11
|
+
/**
|
|
12
|
+
* When set, the `fetch` errors will be transformed into data without changing the state to error.
|
|
13
|
+
*/
|
|
14
|
+
transformError?: (error: TError) => TErrorResponse;
|
|
13
15
|
options?: Partial<TOptions>;
|
|
14
16
|
[stateHintSymbol]?: TState;
|
|
15
17
|
}
|
|
16
|
-
export type AnyDataSource = DataSource<any, any, any, any, any, any, any, any, any>;
|
|
17
|
-
export type DataSourceContext<TDataSource> = TDataSource extends DataSource<infer TContext, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer _TOptions, infer _TState, infer _TFetchContext> ? TContext : never;
|
|
18
|
-
export type DataSourceParams<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer TParams, infer TRequest, infer _TResponse, infer _TData, infer _TError, infer _TOptions, infer _TState, infer _TFetchContext> ? ActualParams<TParams, TRequest> : never;
|
|
19
|
-
export type DataSourceRequest<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer TRequest, infer _TResponse, infer _TData, infer _TError, infer _TOptions, infer _TState, infer _TFetchContext> ? TRequest : never;
|
|
20
|
-
export type DataSourceResponse<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer TResponse, infer _TData, infer _TError, infer _TOptions, infer _TState, infer _TFetchContext> ? TResponse : never;
|
|
21
|
-
export type DataSourceData<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer TResponse, infer TData, infer _TError, infer _TOptions, infer _TState, infer _TFetchContext> ? ActualData<TData,
|
|
22
|
-
export type DataSourceError<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer TError, infer _TOptions, infer _TState, infer _TFetchContext> ? TError : never;
|
|
23
|
-
export type
|
|
24
|
-
export type
|
|
25
|
-
export type
|
|
18
|
+
export type AnyDataSource = DataSource<any, any, any, any, any, any, any, any, any, any>;
|
|
19
|
+
export type DataSourceContext<TDataSource> = TDataSource extends DataSource<infer TContext, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? TContext : never;
|
|
20
|
+
export type DataSourceParams<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer TParams, infer TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? ActualParams<TParams, TRequest> : never;
|
|
21
|
+
export type DataSourceRequest<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? TRequest : never;
|
|
22
|
+
export type DataSourceResponse<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer TResponse, infer _TData, infer _TError, infer TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? ActualResponse<TResponse, TErrorResponse> : never;
|
|
23
|
+
export type DataSourceData<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer TResponse, infer TData, infer _TError, infer TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? ActualData<TResponse, TData, TErrorResponse> : never;
|
|
24
|
+
export type DataSourceError<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer TError, infer _TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? TError : never;
|
|
25
|
+
export type DataSourceErrorResponse<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? TErrorResponse : never;
|
|
26
|
+
export type DataSourceOptions<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer TOptions, infer _TState, infer _TFetchContext> ? TOptions : never;
|
|
27
|
+
export type DataSourceState<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer _TOptions, infer TState, infer _TFetchContext> ? TState : never;
|
|
28
|
+
export type DataSourceFetchContext<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer _TOptions, infer _TState, infer TFetchContext> ? TFetchContext : never;
|
|
26
29
|
export type ActualParams<TParams, TRequest> = (unknown extends TParams ? TRequest : TParams) | typeof idle;
|
|
27
|
-
export type
|
|
30
|
+
export type ActualResponse<TResponse, TErrorResponse> = unknown extends TErrorResponse ? TResponse : TResponse | TErrorResponse;
|
|
31
|
+
export type ActualData<TResponse, TData, TErrorResponse> = unknown extends TData ? ActualResponse<TResponse, TErrorResponse> : TData;
|
|
28
32
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["DataSource.ts"],"sourcesContent":["import type {idle} from '../constants';\n\nexport type DataSourceKey = ReadonlyArray<unknown>;\nexport type DataSourceTag = string;\n\ndeclare const
|
|
1
|
+
{"version":3,"names":[],"sources":["DataSource.ts"],"sourcesContent":["import type {idle} from '../constants';\n\nexport type DataSourceKey = ReadonlyArray<unknown>;\nexport type DataSourceTag = string;\n\ndeclare const stateHintSymbol: unique symbol;\n\nexport interface DataSource<\n TContext,\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n TErrorResponse,\n TOptions,\n TState,\n TFetchContext,\n> {\n readonly name: string;\n\n fetch: (\n context: TContext,\n fetchContext: TFetchContext,\n request: TRequest,\n ) => Promise<TResponse> | TResponse;\n tags?: (params: ActualParams<NoInfer<TParams>, NoInfer<TRequest>>) => DataSourceTag[];\n\n transformParams?: (params: TParams) => NoInfer<TRequest>;\n transformResponse?: (\n response: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n ) => TData;\n\n /**\n * When set, the `fetch` errors will be transformed into data without changing the state to error.\n */\n transformError?: (error: TError) => TErrorResponse;\n\n options?: Partial<TOptions>;\n [stateHintSymbol]?: TState;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyDataSource = DataSource<any, any, any, any, any, any, any, any, any, any>;\n\nexport type DataSourceContext<TDataSource> =\n TDataSource extends DataSource<\n infer TContext,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TContext\n : never;\n\nexport type DataSourceParams<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer TParams,\n infer TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? ActualParams<TParams, TRequest>\n : never;\n\nexport type DataSourceRequest<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TRequest\n : never;\n\nexport type DataSourceResponse<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer TResponse,\n infer _TData,\n infer _TError,\n infer TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? ActualResponse<TResponse, TErrorResponse>\n : never;\n\nexport type DataSourceData<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer TResponse,\n infer TData,\n infer _TError,\n infer TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? ActualData<TResponse, TData, TErrorResponse>\n : never;\n\nexport type DataSourceError<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TError\n : never;\n\nexport type DataSourceErrorResponse<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TErrorResponse\n : never;\n\nexport type DataSourceOptions<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TOptions\n : never;\n\nexport type DataSourceState<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer TState,\n infer _TFetchContext\n >\n ? TState\n : never;\n\nexport type DataSourceFetchContext<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer TFetchContext\n >\n ? TFetchContext\n : never;\n\nexport type ActualParams<TParams, TRequest> =\n | (unknown extends TParams ? TRequest : TParams)\n | typeof idle;\n\nexport type ActualResponse<TResponse, TErrorResponse> = unknown extends TErrorResponse\n ? TResponse\n : TResponse | TErrorResponse;\n\nexport type ActualData<TResponse, TData, TErrorResponse> = unknown extends TData\n ? ActualResponse<TResponse, TErrorResponse>\n : TData;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,2 +1,26 @@
|
|
|
1
1
|
import type { AnyFunction } from '../types/utils';
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
*
|
|
5
|
+
* The function is intended to be used with the `fetch` parameter of the query data source config.
|
|
6
|
+
* It is used to ignore the query data context and the query function context parameters.
|
|
7
|
+
*
|
|
8
|
+
* NOTE: When passed directly to the `fetch` parameter, typescript fails to infer the types of the `DataSource` fields.
|
|
9
|
+
* It is better to define a constant first.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* function someFetchFunction(request: TRequest) {...}
|
|
14
|
+
*
|
|
15
|
+
* const fetchData = skipContext(someFetchFunction);
|
|
16
|
+
*
|
|
17
|
+
* const dataSource = makePlainQueryDataSource({
|
|
18
|
+
* ...
|
|
19
|
+
* fetch: fetchData,
|
|
20
|
+
* ...
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* @param fetch fetch function
|
|
24
|
+
* @returns fetch function with the ignored query data source context and the query function context.
|
|
25
|
+
*/
|
|
2
26
|
export declare const skipContext: <TFunc extends AnyFunction>(fetch: TFunc) => (_0: unknown, _1: unknown, ...args: Parameters<TFunc>) => ReturnType<TFunc>;
|
|
@@ -4,6 +4,30 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.skipContext = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* @description
|
|
9
|
+
*
|
|
10
|
+
* The function is intended to be used with the `fetch` parameter of the query data source config.
|
|
11
|
+
* It is used to ignore the query data context and the query function context parameters.
|
|
12
|
+
*
|
|
13
|
+
* NOTE: When passed directly to the `fetch` parameter, typescript fails to infer the types of the `DataSource` fields.
|
|
14
|
+
* It is better to define a constant first.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* function someFetchFunction(request: TRequest) {...}
|
|
19
|
+
*
|
|
20
|
+
* const fetchData = skipContext(someFetchFunction);
|
|
21
|
+
*
|
|
22
|
+
* const dataSource = makePlainQueryDataSource({
|
|
23
|
+
* ...
|
|
24
|
+
* fetch: fetchData,
|
|
25
|
+
* ...
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* @param fetch fetch function
|
|
29
|
+
* @returns fetch function with the ignored query data source context and the query function context.
|
|
30
|
+
*/
|
|
7
31
|
var skipContext = exports.skipContext = function skipContext(fetch) {
|
|
8
32
|
return function (_0, _1) {
|
|
9
33
|
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["skipContext","exports","fetch","_0","_1","_len","arguments","length","args","Array","_key","apply"],"sources":["skipContext.ts"],"sourcesContent":["import type {AnyFunction} from '../types/utils';\n\nexport const skipContext = <TFunc extends AnyFunction>(fetch: TFunc) => {\n return (_0: unknown, _1: unknown, ...args: Parameters<TFunc>): ReturnType<TFunc> => {\n return fetch(...args);\n };\n};\n"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"names":["skipContext","exports","fetch","_0","_1","_len","arguments","length","args","Array","_key","apply"],"sources":["skipContext.ts"],"sourcesContent":["import type {AnyFunction} from '../types/utils';\n\n/**\n * @description\n *\n * The function is intended to be used with the `fetch` parameter of the query data source config.\n * It is used to ignore the query data context and the query function context parameters.\n *\n * NOTE: When passed directly to the `fetch` parameter, typescript fails to infer the types of the `DataSource` fields.\n * It is better to define a constant first.\n *\n * @example\n *\n * function someFetchFunction(request: TRequest) {...}\n *\n * const fetchData = skipContext(someFetchFunction);\n *\n * const dataSource = makePlainQueryDataSource({\n * ...\n * fetch: fetchData,\n * ...\n * })\n *\n * @param fetch fetch function\n * @returns fetch function with the ignored query data source context and the query function context.\n */\nexport const skipContext = <TFunc extends AnyFunction>(fetch: TFunc) => {\n return (_0: unknown, _1: unknown, ...args: Parameters<TFunc>): ReturnType<TFunc> => {\n return fetch(...args);\n };\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,WAAW,GAAAC,OAAA,CAAAD,WAAA,GAAG,SAAdA,WAAWA,CAA+BE,KAAY,EAAK;EACpE,OAAO,UAACC,EAAW,EAAEC,EAAW,EAAoD;IAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAA/CC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAJF,IAAI,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;IAAA;IACrC,OAAOR,KAAK,CAAAS,KAAA,SAAIH,IAAI,CAAC;EACzB,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { InfiniteQueryDataSource } from './types';
|
|
2
|
-
export declare const makeInfiniteQueryDataSource: <TParams, TRequest, TResponse, TData, TError>(config: Omit<InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError>, "type">) => InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError>;
|
|
2
|
+
export declare const makeInfiniteQueryDataSource: <TParams, TRequest, TResponse, TData, TError, TErrorResponse>(config: Omit<InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>, "type">) => InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["makeInfiniteQueryDataSource","exports","config","_objectSpread","type"],"sources":["factory.ts"],"sourcesContent":["import type {InfiniteQueryDataSource} from './types';\n\nexport const makeInfiniteQueryDataSource =
|
|
1
|
+
{"version":3,"names":["makeInfiniteQueryDataSource","exports","config","_objectSpread","type"],"sources":["factory.ts"],"sourcesContent":["import type {InfiniteQueryDataSource} from './types';\n\nexport const makeInfiniteQueryDataSource = <\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n TErrorResponse,\n>(\n config: Omit<\n InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>,\n 'type'\n >,\n): InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> => ({\n ...config,\n type: 'infinite',\n});\n"],"mappings":";;;;;;;;AAEO,IAAMA,2BAA2B,GAAAC,OAAA,CAAAD,2BAAA,GAAG,SAA9BA,2BAA2BA,CAQpCE,MAGC;EAAA,WAAAC,sBAAA,MAAAA,sBAAA,MAEED,MAAM;IACTE,IAAI,EAAE;EAAU;AAAA,CAClB","ignoreList":[]}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { DefaultError, InfiniteData, InfiniteQueryObserverOptions, InfiniteQueryObserverResult, QueryFunctionContext, QueryKey } from '@tanstack/react-query';
|
|
2
2
|
import type { Overwrite } from 'utility-types';
|
|
3
|
-
import type { ActualData, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
3
|
+
import type { ActualData, ActualResponse, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
4
4
|
import type { QueryDataSourceContext } from '../../types/base';
|
|
5
5
|
import type { QueryDataAdditionalOptions } from '../../types/options';
|
|
6
6
|
export type InfiniteQueryObserverExtendedOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = Overwrite<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, QueryDataAdditionalOptions<TQueryFnData, TError, InfiniteData<TQueryData, TPageParam>, TQueryKey>>;
|
|
7
|
-
export type InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, InfiniteQueryObserverExtendedOptions<TResponse
|
|
7
|
+
export type InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, TErrorResponse, InfiniteQueryObserverExtendedOptions<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, NoInfer<TError>, InfiniteData<ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>, Partial<NoInfer<TRequest>>>, ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, DataSourceKey, Partial<NoInfer<TRequest>>>, ResultWrapper<InfiniteQueryObserverResult<InfiniteData<ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>, Partial<NoInfer<TRequest>>>, NoInfer<TError>>, NoInfer<TRequest>, NoInfer<TResponse>, NoInfer<TData>, NoInfer<TError>, NoInfer<TErrorResponse>>, QueryFunctionContext<DataSourceKey, Partial<NoInfer<TRequest>>>> & {
|
|
8
8
|
type: 'infinite';
|
|
9
|
-
next: (lastPage: TResponse
|
|
10
|
-
prev?: (firstPage: TResponse
|
|
9
|
+
next: (lastPage: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, allPages: Array<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>>) => Partial<NoInfer<TRequest>> | undefined | null;
|
|
10
|
+
prev?: (firstPage: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, allPages: Array<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>>) => Partial<NoInfer<TRequest>> | undefined | null;
|
|
11
11
|
};
|
|
12
|
-
export type AnyInfiniteQueryDataSource = InfiniteQueryDataSource<any, any, any, any, any>;
|
|
12
|
+
export type AnyInfiniteQueryDataSource = InfiniteQueryDataSource<any, any, any, any, any, any>;
|
|
13
13
|
export type AnyPageParam = Partial<any>;
|
|
14
|
-
type ResultWrapper<TResult, TRequest, TResponse, TData, TError> = TResult extends InfiniteQueryObserverResult<InfiniteData<ActualData<TData,
|
|
14
|
+
type ResultWrapper<TResult, TRequest, TResponse, TData, TError, TErrorResponse> = TResult extends InfiniteQueryObserverResult<InfiniteData<ActualData<TResponse, TData, TErrorResponse>, Partial<TRequest>>, TError> ? Overwrite<TResult, {
|
|
15
15
|
status: DataLoaderStatus;
|
|
16
|
-
data: Array<FlatArray<Array<ActualData<TData,
|
|
16
|
+
data: Array<FlatArray<Array<ActualData<TResponse, TData, TErrorResponse>>, 1>>;
|
|
17
17
|
}> & {
|
|
18
18
|
originalStatus: TResult['status'];
|
|
19
19
|
originalData: TResult['data'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryFunctionContext,\n QueryKey,\n} from '@tanstack/react-query';\nimport type {Overwrite} from 'utility-types';\n\nimport type {ActualData
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryFunctionContext,\n QueryKey,\n} from '@tanstack/react-query';\nimport type {Overwrite} from 'utility-types';\n\nimport type {\n ActualData,\n ActualResponse,\n DataLoaderStatus,\n DataSource,\n DataSourceKey,\n} from '../../../core';\nimport type {QueryDataSourceContext} from '../../types/base';\nimport type {QueryDataAdditionalOptions} from '../../types/options';\n\nexport type InfiniteQueryObserverExtendedOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = Overwrite<\n InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>,\n QueryDataAdditionalOptions<\n TQueryFnData,\n TError,\n InfiniteData<TQueryData, TPageParam>,\n TQueryKey\n >\n>;\n\nexport type InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> =\n DataSource<\n QueryDataSourceContext,\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n TErrorResponse,\n InfiniteQueryObserverExtendedOptions<\n ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n NoInfer<TError>,\n InfiniteData<\n ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>,\n Partial<NoInfer<TRequest>>\n >,\n ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n DataSourceKey,\n Partial<NoInfer<TRequest>>\n >,\n ResultWrapper<\n InfiniteQueryObserverResult<\n InfiniteData<\n ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>,\n Partial<NoInfer<TRequest>>\n >,\n NoInfer<TError>\n >,\n NoInfer<TRequest>,\n NoInfer<TResponse>,\n NoInfer<TData>,\n NoInfer<TError>,\n NoInfer<TErrorResponse>\n >,\n QueryFunctionContext<DataSourceKey, Partial<NoInfer<TRequest>>>\n > & {\n type: 'infinite';\n next: (\n lastPage: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n allPages: Array<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>>,\n ) => Partial<NoInfer<TRequest>> | undefined | null;\n prev?: (\n firstPage: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n allPages: Array<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>>,\n ) => Partial<NoInfer<TRequest>> | undefined | null;\n };\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyInfiniteQueryDataSource = InfiniteQueryDataSource<any, any, any, any, any, any>;\n\n// It is used instead of `Partial<DataSourceRequest<TDataSource>>` because TS can't calculate type\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyPageParam = Partial<any>;\n\ntype ResultWrapper<TResult, TRequest, TResponse, TData, TError, TErrorResponse> =\n TResult extends InfiniteQueryObserverResult<\n InfiniteData<ActualData<TResponse, TData, TErrorResponse>, Partial<TRequest>>,\n TError\n >\n ? Overwrite<\n TResult,\n {\n status: DataLoaderStatus;\n data: Array<FlatArray<Array<ActualData<TResponse, TData, TErrorResponse>>, 1>>;\n }\n > & {\n originalStatus: TResult['status'];\n originalData: TResult['data'];\n }\n : never;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -5,28 +5,65 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.composeOptions = void 0;
|
|
7
7
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
8
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
9
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
8
10
|
var _reactQuery = require("@tanstack/react-query");
|
|
9
11
|
var _core = require("../../../core");
|
|
12
|
+
var _utils = require("../utils");
|
|
10
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
14
|
var EMPTY_OBJECT = {};
|
|
12
15
|
var composeOptions = exports.composeOptions = function composeOptions(context, dataSource, params, options) {
|
|
13
16
|
var transformParams = dataSource.transformParams,
|
|
17
|
+
transformError = dataSource.transformError,
|
|
14
18
|
transformResponse = dataSource.transformResponse,
|
|
15
19
|
next = dataSource.next,
|
|
16
20
|
prev = dataSource.prev;
|
|
17
|
-
var queryFn = function
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
var queryFn = /*#__PURE__*/function () {
|
|
22
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(fetchContext) {
|
|
23
|
+
var request, paginatedRequest, response;
|
|
24
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
25
|
+
while (1) switch (_context.prev = _context.next) {
|
|
26
|
+
case 0:
|
|
27
|
+
request = transformParams ? transformParams(params) : params;
|
|
28
|
+
paginatedRequest = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, request), fetchContext.pageParam);
|
|
29
|
+
_context.prev = 2;
|
|
30
|
+
_context.next = 5;
|
|
31
|
+
return dataSource.fetch(context, fetchContext, paginatedRequest);
|
|
32
|
+
case 5:
|
|
33
|
+
response = _context.sent;
|
|
34
|
+
return _context.abrupt("return", (0, _utils.formatNullableValue)(response));
|
|
35
|
+
case 9:
|
|
36
|
+
_context.prev = 9;
|
|
37
|
+
_context.t0 = _context["catch"](2);
|
|
38
|
+
if (transformError) {
|
|
39
|
+
_context.next = 13;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
throw _context.t0;
|
|
43
|
+
case 13:
|
|
44
|
+
return _context.abrupt("return", (0, _utils.formatNullableValue)(transformError(_context.t0)));
|
|
45
|
+
case 14:
|
|
46
|
+
case "end":
|
|
47
|
+
return _context.stop();
|
|
48
|
+
}
|
|
49
|
+
}, _callee, null, [[2, 9]]);
|
|
50
|
+
}));
|
|
51
|
+
return function queryFn(_x) {
|
|
52
|
+
return _ref.apply(this, arguments);
|
|
53
|
+
};
|
|
54
|
+
}();
|
|
55
|
+
var selectPage = function selectPage(response) {
|
|
56
|
+
var actualResponse = (0, _utils.parseNullableValue)(response);
|
|
57
|
+
return transformResponse ? transformResponse(actualResponse) : actualResponse;
|
|
21
58
|
};
|
|
22
59
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
23
60
|
queryKey: (0, _core.composeFullKey)(dataSource, params),
|
|
24
61
|
queryFn: params === _core.idle ? _reactQuery.skipToken : queryFn,
|
|
25
|
-
select:
|
|
62
|
+
select: function select(data) {
|
|
26
63
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, data), {}, {
|
|
27
|
-
pages: data.pages.map(
|
|
64
|
+
pages: data.pages.map(selectPage)
|
|
28
65
|
});
|
|
29
|
-
}
|
|
66
|
+
},
|
|
30
67
|
initialPageParam: EMPTY_OBJECT,
|
|
31
68
|
getNextPageParam: next,
|
|
32
69
|
getPreviousPageParam: prev
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactQuery","require","_core","_interopRequireDefault","e","__esModule","default","EMPTY_OBJECT","composeOptions","exports","context","dataSource","params","options","transformParams","transformResponse","next","prev","queryFn","fetchContext","request","paginatedRequest","_objectSpread","pageParam","fetch","queryKey","composeFullKey","idle","skipToken","select","data","pages","map","
|
|
1
|
+
{"version":3,"names":["_reactQuery","require","_core","_utils","_interopRequireDefault","e","__esModule","default","EMPTY_OBJECT","composeOptions","exports","context","dataSource","params","options","transformParams","transformError","transformResponse","next","prev","queryFn","_ref","_asyncToGenerator","_regeneratorRuntime","mark","_callee","fetchContext","request","paginatedRequest","response","wrap","_callee$","_context","_objectSpread","pageParam","fetch","sent","abrupt","formatNullableValue","t0","stop","_x","apply","arguments","selectPage","actualResponse","parseNullableValue","queryKey","composeFullKey","idle","skipToken","select","data","pages","map","initialPageParam","getNextPageParam","getPreviousPageParam"],"sources":["utils.ts"],"sourcesContent":["import {skipToken} from '@tanstack/react-query';\nimport type {InfiniteData, QueryFunctionContext} from '@tanstack/react-query';\n\nimport {composeFullKey, idle} from '../../../core';\nimport type {\n DataSourceContext,\n DataSourceData,\n DataSourceError,\n DataSourceKey,\n DataSourceOptions,\n DataSourceParams,\n DataSourceResponse,\n} from '../../../core';\nimport type {nullSymbol, undefinedSymbol} from '../utils';\nimport {formatNullableValue, parseNullableValue} from '../utils';\n\nimport type {\n AnyInfiniteQueryDataSource,\n AnyPageParam,\n InfiniteQueryObserverExtendedOptions,\n} from './types';\n\nconst EMPTY_OBJECT = {};\n\nexport const composeOptions = <TDataSource extends AnyInfiniteQueryDataSource>(\n context: DataSourceContext<TDataSource>,\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n options?: Partial<DataSourceOptions<TDataSource>>,\n): InfiniteQueryObserverExtendedOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n InfiniteData<DataSourceData<TDataSource>, AnyPageParam>,\n DataSourceResponse<TDataSource>,\n DataSourceKey,\n AnyPageParam\n> => {\n const {transformParams, transformError, transformResponse, next, prev} = dataSource;\n\n const queryFn = async (\n fetchContext: QueryFunctionContext<DataSourceKey, AnyPageParam>,\n ): Promise<DataSourceResponse<TDataSource> | typeof undefinedSymbol | typeof nullSymbol> => {\n const request = transformParams ? transformParams(params) : params;\n const paginatedRequest = {...request, ...fetchContext.pageParam};\n\n try {\n const response = await dataSource.fetch(context, fetchContext, paginatedRequest);\n\n return formatNullableValue(response);\n } catch (error) {\n if (!transformError) {\n throw error;\n }\n\n return formatNullableValue(transformError(error));\n }\n };\n\n const selectPage = (\n response: DataSourceResponse<TDataSource> | typeof undefinedSymbol | typeof nullSymbol,\n ): DataSourceData<TDataSource> => {\n const actualResponse = parseNullableValue(response);\n\n return transformResponse ? transformResponse(actualResponse) : actualResponse;\n };\n\n return {\n queryKey: composeFullKey(dataSource, params),\n queryFn: params === idle ? skipToken : queryFn,\n select: (data) => ({...data, pages: data.pages.map(selectPage)}),\n initialPageParam: EMPTY_OBJECT,\n getNextPageParam: next,\n getPreviousPageParam: prev,\n ...dataSource.options,\n ...options,\n };\n};\n"],"mappings":";;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAGA,IAAAC,KAAA,GAAAD,OAAA;AAWA,IAAAE,MAAA,GAAAF,OAAA;AAAgE,SAAAG,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAQhE,IAAMG,YAAY,GAAG,CAAC,CAAC;AAEhB,IAAMC,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,SAAjBA,cAAcA,CACvBE,OAAuC,EACvCC,UAAuB,EACvBC,MAAqC,EACrCC,OAAiD,EAQhD;EACD,IAAOC,eAAe,GAAmDH,UAAU,CAA5EG,eAAe;IAAEC,cAAc,GAAmCJ,UAAU,CAA3DI,cAAc;IAAEC,iBAAiB,GAAgBL,UAAU,CAA3CK,iBAAiB;IAAEC,IAAI,GAAUN,UAAU,CAAxBM,IAAI;IAAEC,IAAI,GAAIP,UAAU,CAAlBO,IAAI;EAErE,IAAMC,OAAO;IAAA,IAAAC,IAAA,OAAAC,0BAAA,gBAAAC,oBAAA,CAAAC,IAAA,CAAG,SAAAC,QACZC,YAA+D;MAAA,IAAAC,OAAA,EAAAC,gBAAA,EAAAC,QAAA;MAAA,OAAAN,oBAAA,CAAAO,IAAA,UAAAC,SAAAC,QAAA;QAAA,kBAAAA,QAAA,CAAAb,IAAA,GAAAa,QAAA,CAAAd,IAAA;UAAA;YAEzDS,OAAO,GAAGZ,eAAe,GAAGA,eAAe,CAACF,MAAM,CAAC,GAAGA,MAAM;YAC5De,gBAAgB,OAAAK,sBAAA,MAAAA,sBAAA,MAAON,OAAO,GAAKD,YAAY,CAACQ,SAAS;YAAAF,QAAA,CAAAb,IAAA;YAAAa,QAAA,CAAAd,IAAA;YAAA,OAGpCN,UAAU,CAACuB,KAAK,CAACxB,OAAO,EAAEe,YAAY,EAAEE,gBAAgB,CAAC;UAAA;YAA1EC,QAAQ,GAAAG,QAAA,CAAAI,IAAA;YAAA,OAAAJ,QAAA,CAAAK,MAAA,WAEP,IAAAC,0BAAmB,EAACT,QAAQ,CAAC;UAAA;YAAAG,QAAA,CAAAb,IAAA;YAAAa,QAAA,CAAAO,EAAA,GAAAP,QAAA;YAAA,IAE/BhB,cAAc;cAAAgB,QAAA,CAAAd,IAAA;cAAA;YAAA;YAAA,MAAAc,QAAA,CAAAO,EAAA;UAAA;YAAA,OAAAP,QAAA,CAAAK,MAAA,WAIZ,IAAAC,0BAAmB,EAACtB,cAAc,CAAAgB,QAAA,CAAAO,EAAM,CAAC,CAAC;UAAA;UAAA;YAAA,OAAAP,QAAA,CAAAQ,IAAA;QAAA;MAAA,GAAAf,OAAA;IAAA,CAExD;IAAA,gBAjBKL,OAAOA,CAAAqB,EAAA;MAAA,OAAApB,IAAA,CAAAqB,KAAA,OAAAC,SAAA;IAAA;EAAA,GAiBZ;EAED,IAAMC,UAAU,GAAG,SAAbA,UAAUA,CACZf,QAAsF,EACxD;IAC9B,IAAMgB,cAAc,GAAG,IAAAC,yBAAkB,EAACjB,QAAQ,CAAC;IAEnD,OAAOZ,iBAAiB,GAAGA,iBAAiB,CAAC4B,cAAc,CAAC,GAAGA,cAAc;EACjF,CAAC;EAED,WAAAZ,sBAAA,MAAAA,sBAAA;IACIc,QAAQ,EAAE,IAAAC,oBAAc,EAACpC,UAAU,EAAEC,MAAM,CAAC;IAC5CO,OAAO,EAAEP,MAAM,KAAKoC,UAAI,GAAGC,qBAAS,GAAG9B,OAAO;IAC9C+B,MAAM,EAAE,SAARA,MAAMA,CAAGC,IAAI;MAAA,WAAAnB,sBAAA,MAAAA,sBAAA,MAAUmB,IAAI;QAAEC,KAAK,EAAED,IAAI,CAACC,KAAK,CAACC,GAAG,CAACV,UAAU;MAAC;IAAA,CAAE;IAChEW,gBAAgB,EAAE/C,YAAY;IAC9BgD,gBAAgB,EAAEtC,IAAI;IACtBuC,oBAAoB,EAAEtC;EAAI,GACvBP,UAAU,CAACE,OAAO,GAClBA,OAAO;AAElB,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { PlainQueryDataSource } from './types';
|
|
2
|
-
export declare const makePlainQueryDataSource: <TParams, TRequest, TResponse, TData, TError>(config: Omit<PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError>, "type">) => PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError>;
|
|
2
|
+
export declare const makePlainQueryDataSource: <TParams, TRequest, TResponse, TData, TError, TErrorResponse>(config: Omit<PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>, "type">) => PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["makePlainQueryDataSource","exports","config","_objectSpread","type"],"sources":["factory.ts"],"sourcesContent":["import type {PlainQueryDataSource} from './types';\n\nexport const makePlainQueryDataSource =
|
|
1
|
+
{"version":3,"names":["makePlainQueryDataSource","exports","config","_objectSpread","type"],"sources":["factory.ts"],"sourcesContent":["import type {PlainQueryDataSource} from './types';\n\nexport const makePlainQueryDataSource = <\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n TErrorResponse,\n>(\n config: Omit<\n PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>,\n 'type'\n >,\n): PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> => ({\n ...config,\n type: 'plain',\n});\n"],"mappings":";;;;;;;;AAEO,IAAMA,wBAAwB,GAAAC,OAAA,CAAAD,wBAAA,GAAG,SAA3BA,wBAAwBA,CAQjCE,MAGC;EAAA,WAAAC,sBAAA,MAAAA,sBAAA,MAEED,MAAM;IACTE,IAAI,EAAE;EAAO;AAAA,CACf","ignoreList":[]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { DefaultError, QueryFunctionContext, QueryKey, QueryObserverOptions, QueryObserverResult } from '@tanstack/react-query';
|
|
2
2
|
import type { Overwrite } from 'utility-types';
|
|
3
|
-
import type { ActualData, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
3
|
+
import type { ActualData, ActualResponse, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
4
4
|
import type { QueryDataSourceContext } from '../../types/base';
|
|
5
5
|
import type { QueryDataAdditionalOptions } from '../../types/options';
|
|
6
6
|
export type QueryObserverExtendedOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = never> = Overwrite<QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, QueryDataAdditionalOptions<TQueryFnData, TError, TQueryData, TQueryKey>>;
|
|
7
|
-
export type PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, QueryObserverExtendedOptions<TResponse
|
|
7
|
+
export type PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, TErrorResponse, QueryObserverExtendedOptions<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, NoInfer<TError>, ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>, ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, DataSourceKey>, ResultWrapper<QueryObserverResult<ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>, NoInfer<TError>>, NoInfer<TResponse>, NoInfer<TData>, NoInfer<TError>, NoInfer<TErrorResponse>>, QueryFunctionContext<DataSourceKey>> & {
|
|
8
8
|
type: 'plain';
|
|
9
9
|
};
|
|
10
|
-
export type AnyPlainQueryDataSource = PlainQueryDataSource<any, any, any, any, any>;
|
|
11
|
-
type ResultWrapper<TResult, TResponse, TData, TError> = TResult extends QueryObserverResult<ActualData<TData,
|
|
10
|
+
export type AnyPlainQueryDataSource = PlainQueryDataSource<any, any, any, any, any, any>;
|
|
11
|
+
type ResultWrapper<TResult, TResponse, TData, TError, TErrorResponse> = TResult extends QueryObserverResult<ActualData<TResponse, TData, TErrorResponse>, TError> ? Overwrite<TResult, {
|
|
12
12
|
status: DataLoaderStatus;
|
|
13
13
|
}> & {
|
|
14
14
|
originalStatus: TResult['status'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n DefaultError,\n QueryFunctionContext,\n QueryKey,\n QueryObserverOptions,\n QueryObserverResult,\n} from '@tanstack/react-query';\nimport type {Overwrite} from 'utility-types';\n\nimport type {ActualData
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n DefaultError,\n QueryFunctionContext,\n QueryKey,\n QueryObserverOptions,\n QueryObserverResult,\n} from '@tanstack/react-query';\nimport type {Overwrite} from 'utility-types';\n\nimport type {\n ActualData,\n ActualResponse,\n DataLoaderStatus,\n DataSource,\n DataSourceKey,\n} from '../../../core';\nimport type {QueryDataSourceContext} from '../../types/base';\nimport type {QueryDataAdditionalOptions} from '../../types/options';\n\nexport type QueryObserverExtendedOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n> = Overwrite<\n QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>,\n QueryDataAdditionalOptions<TQueryFnData, TError, TQueryData, TQueryKey>\n>;\n\nexport type PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> =\n DataSource<\n QueryDataSourceContext,\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n TErrorResponse,\n QueryObserverExtendedOptions<\n ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n NoInfer<TError>,\n ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>,\n ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n DataSourceKey\n >,\n ResultWrapper<\n QueryObserverResult<\n ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>,\n NoInfer<TError>\n >,\n NoInfer<TResponse>,\n NoInfer<TData>,\n NoInfer<TError>,\n NoInfer<TErrorResponse>\n >,\n QueryFunctionContext<DataSourceKey>\n > & {\n type: 'plain';\n };\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyPlainQueryDataSource = PlainQueryDataSource<any, any, any, any, any, any>;\n\ntype ResultWrapper<TResult, TResponse, TData, TError, TErrorResponse> =\n TResult extends QueryObserverResult<ActualData<TResponse, TData, TErrorResponse>, TError>\n ? Overwrite<TResult, {status: DataLoaderStatus}> & {originalStatus: TResult['status']}\n : never;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -5,18 +5,56 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.composeOptions = void 0;
|
|
7
7
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
8
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
9
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
8
10
|
var _reactQuery = require("@tanstack/react-query");
|
|
9
11
|
var _core = require("../../../core");
|
|
12
|
+
var _utils = require("../utils");
|
|
10
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
14
|
var composeOptions = exports.composeOptions = function composeOptions(context, dataSource, params, options) {
|
|
12
|
-
var transformParams = dataSource.transformParams
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
var transformParams = dataSource.transformParams,
|
|
16
|
+
transformResponse = dataSource.transformResponse,
|
|
17
|
+
transformError = dataSource.transformError;
|
|
18
|
+
var queryFn = /*#__PURE__*/function () {
|
|
19
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(fetchContext) {
|
|
20
|
+
var response;
|
|
21
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
22
|
+
while (1) switch (_context.prev = _context.next) {
|
|
23
|
+
case 0:
|
|
24
|
+
_context.prev = 0;
|
|
25
|
+
_context.next = 3;
|
|
26
|
+
return dataSource.fetch(context, fetchContext, transformParams ? transformParams(params) : params);
|
|
27
|
+
case 3:
|
|
28
|
+
response = _context.sent;
|
|
29
|
+
return _context.abrupt("return", (0, _utils.formatNullableValue)(response));
|
|
30
|
+
case 7:
|
|
31
|
+
_context.prev = 7;
|
|
32
|
+
_context.t0 = _context["catch"](0);
|
|
33
|
+
if (transformError) {
|
|
34
|
+
_context.next = 11;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
throw _context.t0;
|
|
38
|
+
case 11:
|
|
39
|
+
return _context.abrupt("return", (0, _utils.formatNullableValue)(transformError(_context.t0)));
|
|
40
|
+
case 12:
|
|
41
|
+
case "end":
|
|
42
|
+
return _context.stop();
|
|
43
|
+
}
|
|
44
|
+
}, _callee, null, [[0, 7]]);
|
|
45
|
+
}));
|
|
46
|
+
return function queryFn(_x) {
|
|
47
|
+
return _ref.apply(this, arguments);
|
|
48
|
+
};
|
|
49
|
+
}();
|
|
50
|
+
var select = function select(response) {
|
|
51
|
+
var actualResponse = (0, _utils.parseNullableValue)(response);
|
|
52
|
+
return transformResponse ? transformResponse(actualResponse) : actualResponse;
|
|
15
53
|
};
|
|
16
54
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
17
55
|
queryKey: (0, _core.composeFullKey)(dataSource, params),
|
|
18
56
|
queryFn: params === _core.idle ? _reactQuery.skipToken : queryFn,
|
|
19
|
-
select:
|
|
57
|
+
select: select
|
|
20
58
|
}, dataSource.options), options);
|
|
21
59
|
};
|
|
22
60
|
// #sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactQuery","require","_core","_interopRequireDefault","e","__esModule","default","composeOptions","exports","context","dataSource","params","options","transformParams","queryFn","fetchContext","fetch","
|
|
1
|
+
{"version":3,"names":["_reactQuery","require","_core","_utils","_interopRequireDefault","e","__esModule","default","composeOptions","exports","context","dataSource","params","options","transformParams","transformResponse","transformError","queryFn","_ref","_asyncToGenerator","_regeneratorRuntime","mark","_callee","fetchContext","response","wrap","_callee$","_context","prev","next","fetch","sent","abrupt","formatNullableValue","t0","stop","_x","apply","arguments","select","actualResponse","parseNullableValue","_objectSpread","queryKey","composeFullKey","idle","skipToken"],"sources":["utils.ts"],"sourcesContent":["import {type QueryFunctionContext, skipToken} from '@tanstack/react-query';\n\nimport {composeFullKey, idle} from '../../../core';\nimport type {\n DataSourceContext,\n DataSourceData,\n DataSourceError,\n DataSourceKey,\n DataSourceOptions,\n DataSourceParams,\n DataSourceResponse,\n} from '../../../core';\nimport type {nullSymbol, undefinedSymbol} from '../utils';\nimport {formatNullableValue, parseNullableValue} from '../utils';\n\nimport type {AnyPlainQueryDataSource, QueryObserverExtendedOptions} from './types';\n\nexport const composeOptions = <TDataSource extends AnyPlainQueryDataSource>(\n context: DataSourceContext<TDataSource>,\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n options?: Partial<DataSourceOptions<TDataSource>>,\n): QueryObserverExtendedOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n DataSourceData<TDataSource>,\n DataSourceResponse<TDataSource>,\n DataSourceKey\n> => {\n const {transformParams, transformResponse, transformError} = dataSource;\n\n const queryFn = async (\n fetchContext: QueryFunctionContext<DataSourceKey>,\n ): Promise<DataSourceResponse<TDataSource> | typeof undefinedSymbol | typeof nullSymbol> => {\n try {\n const response = await dataSource.fetch(\n context,\n fetchContext,\n transformParams ? transformParams(params) : params,\n );\n\n return formatNullableValue(response);\n } catch (error) {\n if (!transformError) {\n throw error;\n }\n\n return formatNullableValue(transformError(error));\n }\n };\n\n const select = (\n response: DataSourceResponse<TDataSource> | typeof undefinedSymbol | typeof nullSymbol,\n ): DataSourceData<TDataSource> => {\n const actualResponse = parseNullableValue(response);\n\n return transformResponse ? transformResponse(actualResponse) : actualResponse;\n };\n\n return {\n queryKey: composeFullKey(dataSource, params),\n queryFn: params === idle ? skipToken : queryFn,\n select,\n ...dataSource.options,\n ...options,\n };\n};\n"],"mappings":";;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AAWA,IAAAE,MAAA,GAAAF,OAAA;AAAgE,SAAAG,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAIzD,IAAMG,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,SAAjBA,cAAcA,CACvBE,OAAuC,EACvCC,UAAuB,EACvBC,MAAqC,EACrCC,OAAiD,EAOhD;EACD,IAAOC,eAAe,GAAuCH,UAAU,CAAhEG,eAAe;IAAEC,iBAAiB,GAAoBJ,UAAU,CAA/CI,iBAAiB;IAAEC,cAAc,GAAIL,UAAU,CAA5BK,cAAc;EAEzD,IAAMC,OAAO;IAAA,IAAAC,IAAA,OAAAC,0BAAA,gBAAAC,oBAAA,CAAAC,IAAA,CAAG,SAAAC,QACZC,YAAiD;MAAA,IAAAC,QAAA;MAAA,OAAAJ,oBAAA,CAAAK,IAAA,UAAAC,SAAAC,QAAA;QAAA,kBAAAA,QAAA,CAAAC,IAAA,GAAAD,QAAA,CAAAE,IAAA;UAAA;YAAAF,QAAA,CAAAC,IAAA;YAAAD,QAAA,CAAAE,IAAA;YAAA,OAGtBlB,UAAU,CAACmB,KAAK,CACnCpB,OAAO,EACPa,YAAY,EACZT,eAAe,GAAGA,eAAe,CAACF,MAAM,CAAC,GAAGA,MAChD,CAAC;UAAA;YAJKY,QAAQ,GAAAG,QAAA,CAAAI,IAAA;YAAA,OAAAJ,QAAA,CAAAK,MAAA,WAMP,IAAAC,0BAAmB,EAACT,QAAQ,CAAC;UAAA;YAAAG,QAAA,CAAAC,IAAA;YAAAD,QAAA,CAAAO,EAAA,GAAAP,QAAA;YAAA,IAE/BX,cAAc;cAAAW,QAAA,CAAAE,IAAA;cAAA;YAAA;YAAA,MAAAF,QAAA,CAAAO,EAAA;UAAA;YAAA,OAAAP,QAAA,CAAAK,MAAA,WAIZ,IAAAC,0BAAmB,EAACjB,cAAc,CAAAW,QAAA,CAAAO,EAAM,CAAC,CAAC;UAAA;UAAA;YAAA,OAAAP,QAAA,CAAAQ,IAAA;QAAA;MAAA,GAAAb,OAAA;IAAA,CAExD;IAAA,gBAlBKL,OAAOA,CAAAmB,EAAA;MAAA,OAAAlB,IAAA,CAAAmB,KAAA,OAAAC,SAAA;IAAA;EAAA,GAkBZ;EAED,IAAMC,MAAM,GAAG,SAATA,MAAMA,CACRf,QAAsF,EACxD;IAC9B,IAAMgB,cAAc,GAAG,IAAAC,yBAAkB,EAACjB,QAAQ,CAAC;IAEnD,OAAOT,iBAAiB,GAAGA,iBAAiB,CAACyB,cAAc,CAAC,GAAGA,cAAc;EACjF,CAAC;EAED,WAAAE,sBAAA,MAAAA,sBAAA;IACIC,QAAQ,EAAE,IAAAC,oBAAc,EAACjC,UAAU,EAAEC,MAAM,CAAC;IAC5CK,OAAO,EAAEL,MAAM,KAAKiC,UAAI,GAAGC,qBAAS,GAAG7B,OAAO;IAC9CsB,MAAM,EAANA;EAAM,GACH5B,UAAU,CAACE,OAAO,GAClBA,OAAO;AAElB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const undefinedSymbol: unique symbol;
|
|
2
|
+
export declare const nullSymbol: unique symbol;
|
|
3
|
+
export declare const formatNullableValue: <T>(value: T | undefined | null) => T | typeof undefinedSymbol | typeof nullSymbol;
|
|
4
|
+
export declare const parseNullableValue: <T>(value: T | typeof undefinedSymbol | typeof nullSymbol) => T | undefined | null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.undefinedSymbol = exports.parseNullableValue = exports.nullSymbol = exports.formatNullableValue = void 0;
|
|
7
|
+
var undefinedSymbol = exports.undefinedSymbol = Symbol('undefined');
|
|
8
|
+
var nullSymbol = exports.nullSymbol = Symbol('null');
|
|
9
|
+
var formatNullableValue = exports.formatNullableValue = function formatNullableValue(value) {
|
|
10
|
+
if (value === undefined) {
|
|
11
|
+
return undefinedSymbol;
|
|
12
|
+
}
|
|
13
|
+
if (value === null) {
|
|
14
|
+
return nullSymbol;
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
};
|
|
18
|
+
var parseNullableValue = exports.parseNullableValue = function parseNullableValue(value) {
|
|
19
|
+
if (value === undefinedSymbol) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
if (value === nullSymbol) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
};
|
|
27
|
+
// #sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["undefinedSymbol","exports","Symbol","nullSymbol","formatNullableValue","value","undefined","parseNullableValue"],"sources":["utils.ts"],"sourcesContent":["export const undefinedSymbol = Symbol('undefined');\nexport const nullSymbol = Symbol('null');\n\nexport const formatNullableValue = <T>(\n value: T | undefined | null,\n): T | typeof undefinedSymbol | typeof nullSymbol => {\n if (value === undefined) {\n return undefinedSymbol;\n }\n\n if (value === null) {\n return nullSymbol;\n }\n\n return value;\n};\n\nexport const parseNullableValue = <T>(\n value: T | typeof undefinedSymbol | typeof nullSymbol,\n): T | undefined | null => {\n if (value === undefinedSymbol) {\n return undefined;\n }\n\n if (value === nullSymbol) {\n return null;\n }\n\n return value;\n};\n"],"mappings":";;;;;;AAAO,IAAMA,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAAGE,MAAM,CAAC,WAAW,CAAC;AAC3C,IAAMC,UAAU,GAAAF,OAAA,CAAAE,UAAA,GAAGD,MAAM,CAAC,MAAM,CAAC;AAEjC,IAAME,mBAAmB,GAAAH,OAAA,CAAAG,mBAAA,GAAG,SAAtBA,mBAAmBA,CAC5BC,KAA2B,EACsB;EACjD,IAAIA,KAAK,KAAKC,SAAS,EAAE;IACrB,OAAON,eAAe;EAC1B;EAEA,IAAIK,KAAK,KAAK,IAAI,EAAE;IAChB,OAAOF,UAAU;EACrB;EAEA,OAAOE,KAAK;AAChB,CAAC;AAEM,IAAME,kBAAkB,GAAAN,OAAA,CAAAM,kBAAA,GAAG,SAArBA,kBAAkBA,CAC3BF,KAAqD,EAC9B;EACvB,IAAIA,KAAK,KAAKL,eAAe,EAAE;IAC3B,OAAOM,SAAS;EACpB;EAEA,IAAID,KAAK,KAAKF,UAAU,EAAE;IACtB,OAAO,IAAI;EACf;EAEA,OAAOE,KAAK;AAChB,CAAC","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { DataSourceKey, DataSourceTag, DataSource, AnyDataSource, DataSourceContext, DataSourceParams, DataSourceRequest, DataSourceResponse, DataSourceData, DataSourceError, DataSourceOptions, DataSourceState, DataSourceFetchContext, ActualParams, ActualData, } from './types/DataSource';
|
|
1
|
+
export type { DataSourceKey, DataSourceTag, DataSource, AnyDataSource, DataSourceContext, DataSourceParams, DataSourceRequest, DataSourceResponse, DataSourceErrorResponse, DataSourceData, DataSourceError, DataSourceOptions, DataSourceState, DataSourceFetchContext, ActualParams, ActualData, ActualResponse, } from './types/DataSource';
|
|
2
2
|
export type { DataManager } from './types/DataManger';
|
|
3
3
|
export type { DataLoaderStatus } from './types/DataLoaderStatus';
|
|
4
4
|
export type { InvalidateRepeatOptions, InvalidateOptions } from './types/DataManagerOptions';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["idle","composeKey","composeFullKey","getError","getStatus","hasTag","mergeStatuses","skipContext","isCancellable","isAbortable","withCancellation"],"sources":["index.ts"],"sourcesContent":["export type {\n DataSourceKey,\n DataSourceTag,\n DataSource,\n AnyDataSource,\n DataSourceContext,\n DataSourceParams,\n DataSourceRequest,\n DataSourceResponse,\n DataSourceData,\n DataSourceError,\n DataSourceOptions,\n DataSourceState,\n DataSourceFetchContext,\n ActualParams,\n ActualData,\n} from './types/DataSource';\nexport type {DataManager} from './types/DataManger';\nexport type {DataLoaderStatus} from './types/DataLoaderStatus';\nexport type {InvalidateRepeatOptions, InvalidateOptions} from './types/DataManagerOptions';\n\nexport {idle} from './constants';\n\nexport {composeKey} from './utils/composeKey';\nexport {composeFullKey} from './utils/composeFullKey';\nexport {getError} from './utils/getError';\nexport {getStatus} from './utils/getStatus';\nexport {hasTag} from './utils/hasTag';\nexport {mergeStatuses} from './utils/mergeStatuses';\nexport {skipContext} from './utils/skipContext';\nexport type {Cancellable} from './utils/withCancellation';\nexport {isCancellable, isAbortable, withCancellation} from './utils/withCancellation';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["idle","composeKey","composeFullKey","getError","getStatus","hasTag","mergeStatuses","skipContext","isCancellable","isAbortable","withCancellation"],"sources":["index.ts"],"sourcesContent":["export type {\n DataSourceKey,\n DataSourceTag,\n DataSource,\n AnyDataSource,\n DataSourceContext,\n DataSourceParams,\n DataSourceRequest,\n DataSourceResponse,\n DataSourceErrorResponse,\n DataSourceData,\n DataSourceError,\n DataSourceOptions,\n DataSourceState,\n DataSourceFetchContext,\n ActualParams,\n ActualData,\n ActualResponse,\n} from './types/DataSource';\nexport type {DataManager} from './types/DataManger';\nexport type {DataLoaderStatus} from './types/DataLoaderStatus';\nexport type {InvalidateRepeatOptions, InvalidateOptions} from './types/DataManagerOptions';\n\nexport {idle} from './constants';\n\nexport {composeKey} from './utils/composeKey';\nexport {composeFullKey} from './utils/composeFullKey';\nexport {getError} from './utils/getError';\nexport {getStatus} from './utils/getStatus';\nexport {hasTag} from './utils/hasTag';\nexport {mergeStatuses} from './utils/mergeStatuses';\nexport {skipContext} from './utils/skipContext';\nexport type {Cancellable} from './utils/withCancellation';\nexport {isCancellable, isAbortable, withCancellation} from './utils/withCancellation';\n"],"mappings":"AAuBA,SAAQA,IAAI,QAAO,aAAa;AAEhC,SAAQC,UAAU,QAAO,oBAAoB;AAC7C,SAAQC,cAAc,QAAO,wBAAwB;AACrD,SAAQC,QAAQ,QAAO,kBAAkB;AACzC,SAAQC,SAAS,QAAO,mBAAmB;AAC3C,SAAQC,MAAM,QAAO,gBAAgB;AACrC,SAAQC,aAAa,QAAO,uBAAuB;AACnD,SAAQC,WAAW,QAAO,qBAAqB;AAE/C,SAAQC,aAAa,EAAEC,WAAW,EAAEC,gBAAgB,QAAO,0BAA0B","ignoreList":[]}
|
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
import type { idle } from '../constants';
|
|
2
2
|
export type DataSourceKey = ReadonlyArray<unknown>;
|
|
3
3
|
export type DataSourceTag = string;
|
|
4
|
-
declare const errorHintSymbol: unique symbol;
|
|
5
4
|
declare const stateHintSymbol: unique symbol;
|
|
6
|
-
export interface DataSource<TContext, TParams, TRequest, TResponse, TData, TError, TOptions, TState, TFetchContext> {
|
|
5
|
+
export interface DataSource<TContext, TParams, TRequest, TResponse, TData, TError, TErrorResponse, TOptions, TState, TFetchContext> {
|
|
7
6
|
readonly name: string;
|
|
8
7
|
fetch: (context: TContext, fetchContext: TFetchContext, request: TRequest) => Promise<TResponse> | TResponse;
|
|
9
|
-
tags?: (params: ActualParams<TParams
|
|
10
|
-
transformParams?: (params: TParams) => TRequest
|
|
11
|
-
transformResponse?: (response: TResponse) => TData;
|
|
12
|
-
|
|
8
|
+
tags?: (params: ActualParams<NoInfer<TParams>, NoInfer<TRequest>>) => DataSourceTag[];
|
|
9
|
+
transformParams?: (params: TParams) => NoInfer<TRequest>;
|
|
10
|
+
transformResponse?: (response: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>) => TData;
|
|
11
|
+
/**
|
|
12
|
+
* When set, the `fetch` errors will be transformed into data without changing the state to error.
|
|
13
|
+
*/
|
|
14
|
+
transformError?: (error: TError) => TErrorResponse;
|
|
13
15
|
options?: Partial<TOptions>;
|
|
14
16
|
[stateHintSymbol]?: TState;
|
|
15
17
|
}
|
|
16
|
-
export type AnyDataSource = DataSource<any, any, any, any, any, any, any, any, any>;
|
|
17
|
-
export type DataSourceContext<TDataSource> = TDataSource extends DataSource<infer TContext, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer _TOptions, infer _TState, infer _TFetchContext> ? TContext : never;
|
|
18
|
-
export type DataSourceParams<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer TParams, infer TRequest, infer _TResponse, infer _TData, infer _TError, infer _TOptions, infer _TState, infer _TFetchContext> ? ActualParams<TParams, TRequest> : never;
|
|
19
|
-
export type DataSourceRequest<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer TRequest, infer _TResponse, infer _TData, infer _TError, infer _TOptions, infer _TState, infer _TFetchContext> ? TRequest : never;
|
|
20
|
-
export type DataSourceResponse<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer TResponse, infer _TData, infer _TError, infer _TOptions, infer _TState, infer _TFetchContext> ? TResponse : never;
|
|
21
|
-
export type DataSourceData<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer TResponse, infer TData, infer _TError, infer _TOptions, infer _TState, infer _TFetchContext> ? ActualData<TData,
|
|
22
|
-
export type DataSourceError<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer TError, infer _TOptions, infer _TState, infer _TFetchContext> ? TError : never;
|
|
23
|
-
export type
|
|
24
|
-
export type
|
|
25
|
-
export type
|
|
18
|
+
export type AnyDataSource = DataSource<any, any, any, any, any, any, any, any, any, any>;
|
|
19
|
+
export type DataSourceContext<TDataSource> = TDataSource extends DataSource<infer TContext, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? TContext : never;
|
|
20
|
+
export type DataSourceParams<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer TParams, infer TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? ActualParams<TParams, TRequest> : never;
|
|
21
|
+
export type DataSourceRequest<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? TRequest : never;
|
|
22
|
+
export type DataSourceResponse<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer TResponse, infer _TData, infer _TError, infer TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? ActualResponse<TResponse, TErrorResponse> : never;
|
|
23
|
+
export type DataSourceData<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer TResponse, infer TData, infer _TError, infer TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? ActualData<TResponse, TData, TErrorResponse> : never;
|
|
24
|
+
export type DataSourceError<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer TError, infer _TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? TError : never;
|
|
25
|
+
export type DataSourceErrorResponse<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer TErrorResponse, infer _TOptions, infer _TState, infer _TFetchContext> ? TErrorResponse : never;
|
|
26
|
+
export type DataSourceOptions<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer TOptions, infer _TState, infer _TFetchContext> ? TOptions : never;
|
|
27
|
+
export type DataSourceState<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer _TOptions, infer TState, infer _TFetchContext> ? TState : never;
|
|
28
|
+
export type DataSourceFetchContext<TDataSource> = TDataSource extends DataSource<infer _TContenxt, infer _TParams, infer _TRequest, infer _TResponse, infer _TData, infer _TError, infer _TErrorResponse, infer _TOptions, infer _TState, infer TFetchContext> ? TFetchContext : never;
|
|
26
29
|
export type ActualParams<TParams, TRequest> = (unknown extends TParams ? TRequest : TParams) | typeof idle;
|
|
27
|
-
export type
|
|
30
|
+
export type ActualResponse<TResponse, TErrorResponse> = unknown extends TErrorResponse ? TResponse : TResponse | TErrorResponse;
|
|
31
|
+
export type ActualData<TResponse, TData, TErrorResponse> = unknown extends TData ? ActualResponse<TResponse, TErrorResponse> : TData;
|
|
28
32
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["DataSource.ts"],"sourcesContent":["import type {idle} from '../constants';\n\nexport type DataSourceKey = ReadonlyArray<unknown>;\nexport type DataSourceTag = string;\n\ndeclare const
|
|
1
|
+
{"version":3,"names":[],"sources":["DataSource.ts"],"sourcesContent":["import type {idle} from '../constants';\n\nexport type DataSourceKey = ReadonlyArray<unknown>;\nexport type DataSourceTag = string;\n\ndeclare const stateHintSymbol: unique symbol;\n\nexport interface DataSource<\n TContext,\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n TErrorResponse,\n TOptions,\n TState,\n TFetchContext,\n> {\n readonly name: string;\n\n fetch: (\n context: TContext,\n fetchContext: TFetchContext,\n request: TRequest,\n ) => Promise<TResponse> | TResponse;\n tags?: (params: ActualParams<NoInfer<TParams>, NoInfer<TRequest>>) => DataSourceTag[];\n\n transformParams?: (params: TParams) => NoInfer<TRequest>;\n transformResponse?: (\n response: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n ) => TData;\n\n /**\n * When set, the `fetch` errors will be transformed into data without changing the state to error.\n */\n transformError?: (error: TError) => TErrorResponse;\n\n options?: Partial<TOptions>;\n [stateHintSymbol]?: TState;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyDataSource = DataSource<any, any, any, any, any, any, any, any, any, any>;\n\nexport type DataSourceContext<TDataSource> =\n TDataSource extends DataSource<\n infer TContext,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TContext\n : never;\n\nexport type DataSourceParams<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer TParams,\n infer TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? ActualParams<TParams, TRequest>\n : never;\n\nexport type DataSourceRequest<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TRequest\n : never;\n\nexport type DataSourceResponse<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer TResponse,\n infer _TData,\n infer _TError,\n infer TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? ActualResponse<TResponse, TErrorResponse>\n : never;\n\nexport type DataSourceData<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer TResponse,\n infer TData,\n infer _TError,\n infer TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? ActualData<TResponse, TData, TErrorResponse>\n : never;\n\nexport type DataSourceError<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TError\n : never;\n\nexport type DataSourceErrorResponse<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TErrorResponse\n : never;\n\nexport type DataSourceOptions<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TOptions\n : never;\n\nexport type DataSourceState<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer TState,\n infer _TFetchContext\n >\n ? TState\n : never;\n\nexport type DataSourceFetchContext<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TErrorResponse,\n infer _TOptions,\n infer _TState,\n infer TFetchContext\n >\n ? TFetchContext\n : never;\n\nexport type ActualParams<TParams, TRequest> =\n | (unknown extends TParams ? TRequest : TParams)\n | typeof idle;\n\nexport type ActualResponse<TResponse, TErrorResponse> = unknown extends TErrorResponse\n ? TResponse\n : TResponse | TErrorResponse;\n\nexport type ActualData<TResponse, TData, TErrorResponse> = unknown extends TData\n ? ActualResponse<TResponse, TErrorResponse>\n : TData;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,2 +1,26 @@
|
|
|
1
1
|
import type { AnyFunction } from '../types/utils';
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
*
|
|
5
|
+
* The function is intended to be used with the `fetch` parameter of the query data source config.
|
|
6
|
+
* It is used to ignore the query data context and the query function context parameters.
|
|
7
|
+
*
|
|
8
|
+
* NOTE: When passed directly to the `fetch` parameter, typescript fails to infer the types of the `DataSource` fields.
|
|
9
|
+
* It is better to define a constant first.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* function someFetchFunction(request: TRequest) {...}
|
|
14
|
+
*
|
|
15
|
+
* const fetchData = skipContext(someFetchFunction);
|
|
16
|
+
*
|
|
17
|
+
* const dataSource = makePlainQueryDataSource({
|
|
18
|
+
* ...
|
|
19
|
+
* fetch: fetchData,
|
|
20
|
+
* ...
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* @param fetch fetch function
|
|
24
|
+
* @returns fetch function with the ignored query data source context and the query function context.
|
|
25
|
+
*/
|
|
2
26
|
export declare const skipContext: <TFunc extends AnyFunction>(fetch: TFunc) => (_0: unknown, _1: unknown, ...args: Parameters<TFunc>) => ReturnType<TFunc>;
|
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
*
|
|
4
|
+
* The function is intended to be used with the `fetch` parameter of the query data source config.
|
|
5
|
+
* It is used to ignore the query data context and the query function context parameters.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: When passed directly to the `fetch` parameter, typescript fails to infer the types of the `DataSource` fields.
|
|
8
|
+
* It is better to define a constant first.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* function someFetchFunction(request: TRequest) {...}
|
|
13
|
+
*
|
|
14
|
+
* const fetchData = skipContext(someFetchFunction);
|
|
15
|
+
*
|
|
16
|
+
* const dataSource = makePlainQueryDataSource({
|
|
17
|
+
* ...
|
|
18
|
+
* fetch: fetchData,
|
|
19
|
+
* ...
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* @param fetch fetch function
|
|
23
|
+
* @returns fetch function with the ignored query data source context and the query function context.
|
|
24
|
+
*/
|
|
1
25
|
export var skipContext = function skipContext(fetch) {
|
|
2
26
|
return function (_0, _1) {
|
|
3
27
|
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["skipContext","fetch","_0","_1","_len","arguments","length","args","Array","_key","apply"],"sources":["skipContext.ts"],"sourcesContent":["import type {AnyFunction} from '../types/utils';\n\nexport const skipContext = <TFunc extends AnyFunction>(fetch: TFunc) => {\n return (_0: unknown, _1: unknown, ...args: Parameters<TFunc>): ReturnType<TFunc> => {\n return fetch(...args);\n };\n};\n"],"mappings":"AAEA,OAAO,IAAMA,WAAW,GAAG,SAAdA,WAAWA,CAA+BC,KAAY,EAAK;EACpE,OAAO,UAACC,EAAW,EAAEC,EAAW,EAAoD;IAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAA/CC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAJF,IAAI,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;IAAA;IACrC,OAAOR,KAAK,CAAAS,KAAA,SAAIH,IAAI,CAAC;EACzB,CAAC;AACL,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["skipContext","fetch","_0","_1","_len","arguments","length","args","Array","_key","apply"],"sources":["skipContext.ts"],"sourcesContent":["import type {AnyFunction} from '../types/utils';\n\n/**\n * @description\n *\n * The function is intended to be used with the `fetch` parameter of the query data source config.\n * It is used to ignore the query data context and the query function context parameters.\n *\n * NOTE: When passed directly to the `fetch` parameter, typescript fails to infer the types of the `DataSource` fields.\n * It is better to define a constant first.\n *\n * @example\n *\n * function someFetchFunction(request: TRequest) {...}\n *\n * const fetchData = skipContext(someFetchFunction);\n *\n * const dataSource = makePlainQueryDataSource({\n * ...\n * fetch: fetchData,\n * ...\n * })\n *\n * @param fetch fetch function\n * @returns fetch function with the ignored query data source context and the query function context.\n */\nexport const skipContext = <TFunc extends AnyFunction>(fetch: TFunc) => {\n return (_0: unknown, _1: unknown, ...args: Parameters<TFunc>): ReturnType<TFunc> => {\n return fetch(...args);\n };\n};\n"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAMA,WAAW,GAAG,SAAdA,WAAWA,CAA+BC,KAAY,EAAK;EACpE,OAAO,UAACC,EAAW,EAAEC,EAAW,EAAoD;IAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAA/CC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAJF,IAAI,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;IAAA;IACrC,OAAOR,KAAK,CAAAS,KAAA,SAAIH,IAAI,CAAC;EACzB,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { InfiniteQueryDataSource } from './types';
|
|
2
|
-
export declare const makeInfiniteQueryDataSource: <TParams, TRequest, TResponse, TData, TError>(config: Omit<InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError>, "type">) => InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError>;
|
|
2
|
+
export declare const makeInfiniteQueryDataSource: <TParams, TRequest, TResponse, TData, TError, TErrorResponse>(config: Omit<InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>, "type">) => InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["makeInfiniteQueryDataSource","config","_objectSpread","type"],"sources":["factory.ts"],"sourcesContent":["import type {InfiniteQueryDataSource} from './types';\n\nexport const makeInfiniteQueryDataSource =
|
|
1
|
+
{"version":3,"names":["makeInfiniteQueryDataSource","config","_objectSpread","type"],"sources":["factory.ts"],"sourcesContent":["import type {InfiniteQueryDataSource} from './types';\n\nexport const makeInfiniteQueryDataSource = <\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n TErrorResponse,\n>(\n config: Omit<\n InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>,\n 'type'\n >,\n): InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> => ({\n ...config,\n type: 'infinite',\n});\n"],"mappings":";AAEA,OAAO,IAAMA,2BAA2B,GAAG,SAA9BA,2BAA2BA,CAQpCC,MAGC;EAAA,OAAAC,aAAA,CAAAA,aAAA,KAEED,MAAM;IACTE,IAAI,EAAE;EAAU;AAAA,CAClB","ignoreList":[]}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { DefaultError, InfiniteData, InfiniteQueryObserverOptions, InfiniteQueryObserverResult, QueryFunctionContext, QueryKey } from '@tanstack/react-query';
|
|
2
2
|
import type { Overwrite } from 'utility-types';
|
|
3
|
-
import type { ActualData, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
3
|
+
import type { ActualData, ActualResponse, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
4
4
|
import type { QueryDataSourceContext } from '../../types/base';
|
|
5
5
|
import type { QueryDataAdditionalOptions } from '../../types/options';
|
|
6
6
|
export type InfiniteQueryObserverExtendedOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = Overwrite<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, QueryDataAdditionalOptions<TQueryFnData, TError, InfiniteData<TQueryData, TPageParam>, TQueryKey>>;
|
|
7
|
-
export type InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, InfiniteQueryObserverExtendedOptions<TResponse
|
|
7
|
+
export type InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, TErrorResponse, InfiniteQueryObserverExtendedOptions<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, NoInfer<TError>, InfiniteData<ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>, Partial<NoInfer<TRequest>>>, ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, DataSourceKey, Partial<NoInfer<TRequest>>>, ResultWrapper<InfiniteQueryObserverResult<InfiniteData<ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>, Partial<NoInfer<TRequest>>>, NoInfer<TError>>, NoInfer<TRequest>, NoInfer<TResponse>, NoInfer<TData>, NoInfer<TError>, NoInfer<TErrorResponse>>, QueryFunctionContext<DataSourceKey, Partial<NoInfer<TRequest>>>> & {
|
|
8
8
|
type: 'infinite';
|
|
9
|
-
next: (lastPage: TResponse
|
|
10
|
-
prev?: (firstPage: TResponse
|
|
9
|
+
next: (lastPage: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, allPages: Array<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>>) => Partial<NoInfer<TRequest>> | undefined | null;
|
|
10
|
+
prev?: (firstPage: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, allPages: Array<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>>) => Partial<NoInfer<TRequest>> | undefined | null;
|
|
11
11
|
};
|
|
12
|
-
export type AnyInfiniteQueryDataSource = InfiniteQueryDataSource<any, any, any, any, any>;
|
|
12
|
+
export type AnyInfiniteQueryDataSource = InfiniteQueryDataSource<any, any, any, any, any, any>;
|
|
13
13
|
export type AnyPageParam = Partial<any>;
|
|
14
|
-
type ResultWrapper<TResult, TRequest, TResponse, TData, TError> = TResult extends InfiniteQueryObserverResult<InfiniteData<ActualData<TData,
|
|
14
|
+
type ResultWrapper<TResult, TRequest, TResponse, TData, TError, TErrorResponse> = TResult extends InfiniteQueryObserverResult<InfiniteData<ActualData<TResponse, TData, TErrorResponse>, Partial<TRequest>>, TError> ? Overwrite<TResult, {
|
|
15
15
|
status: DataLoaderStatus;
|
|
16
|
-
data: Array<FlatArray<Array<ActualData<TData,
|
|
16
|
+
data: Array<FlatArray<Array<ActualData<TResponse, TData, TErrorResponse>>, 1>>;
|
|
17
17
|
}> & {
|
|
18
18
|
originalStatus: TResult['status'];
|
|
19
19
|
originalData: TResult['data'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryFunctionContext,\n QueryKey,\n} from '@tanstack/react-query';\nimport type {Overwrite} from 'utility-types';\n\nimport type {ActualData
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryFunctionContext,\n QueryKey,\n} from '@tanstack/react-query';\nimport type {Overwrite} from 'utility-types';\n\nimport type {\n ActualData,\n ActualResponse,\n DataLoaderStatus,\n DataSource,\n DataSourceKey,\n} from '../../../core';\nimport type {QueryDataSourceContext} from '../../types/base';\nimport type {QueryDataAdditionalOptions} from '../../types/options';\n\nexport type InfiniteQueryObserverExtendedOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = Overwrite<\n InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>,\n QueryDataAdditionalOptions<\n TQueryFnData,\n TError,\n InfiniteData<TQueryData, TPageParam>,\n TQueryKey\n >\n>;\n\nexport type InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> =\n DataSource<\n QueryDataSourceContext,\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n TErrorResponse,\n InfiniteQueryObserverExtendedOptions<\n ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n NoInfer<TError>,\n InfiniteData<\n ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>,\n Partial<NoInfer<TRequest>>\n >,\n ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n DataSourceKey,\n Partial<NoInfer<TRequest>>\n >,\n ResultWrapper<\n InfiniteQueryObserverResult<\n InfiniteData<\n ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>,\n Partial<NoInfer<TRequest>>\n >,\n NoInfer<TError>\n >,\n NoInfer<TRequest>,\n NoInfer<TResponse>,\n NoInfer<TData>,\n NoInfer<TError>,\n NoInfer<TErrorResponse>\n >,\n QueryFunctionContext<DataSourceKey, Partial<NoInfer<TRequest>>>\n > & {\n type: 'infinite';\n next: (\n lastPage: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n allPages: Array<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>>,\n ) => Partial<NoInfer<TRequest>> | undefined | null;\n prev?: (\n firstPage: ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n allPages: Array<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>>,\n ) => Partial<NoInfer<TRequest>> | undefined | null;\n };\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyInfiniteQueryDataSource = InfiniteQueryDataSource<any, any, any, any, any, any>;\n\n// It is used instead of `Partial<DataSourceRequest<TDataSource>>` because TS can't calculate type\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyPageParam = Partial<any>;\n\ntype ResultWrapper<TResult, TRequest, TResponse, TData, TError, TErrorResponse> =\n TResult extends InfiniteQueryObserverResult<\n InfiniteData<ActualData<TResponse, TData, TErrorResponse>, Partial<TRequest>>,\n TError\n >\n ? Overwrite<\n TResult,\n {\n status: DataLoaderStatus;\n data: Array<FlatArray<Array<ActualData<TResponse, TData, TErrorResponse>>, 1>>;\n }\n > & {\n originalStatus: TResult['status'];\n originalData: TResult['data'];\n }\n : never;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,25 +1,62 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
4
|
import { skipToken } from '@tanstack/react-query';
|
|
3
5
|
import { composeFullKey, idle } from '../../../core';
|
|
6
|
+
import { formatNullableValue, parseNullableValue } from '../utils';
|
|
4
7
|
var EMPTY_OBJECT = {};
|
|
5
8
|
export var composeOptions = function composeOptions(context, dataSource, params, options) {
|
|
6
9
|
var transformParams = dataSource.transformParams,
|
|
10
|
+
transformError = dataSource.transformError,
|
|
7
11
|
transformResponse = dataSource.transformResponse,
|
|
8
12
|
next = dataSource.next,
|
|
9
13
|
prev = dataSource.prev;
|
|
10
|
-
var queryFn = function
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
var queryFn = /*#__PURE__*/function () {
|
|
15
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(fetchContext) {
|
|
16
|
+
var request, paginatedRequest, response;
|
|
17
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
18
|
+
while (1) switch (_context.prev = _context.next) {
|
|
19
|
+
case 0:
|
|
20
|
+
request = transformParams ? transformParams(params) : params;
|
|
21
|
+
paginatedRequest = _objectSpread(_objectSpread({}, request), fetchContext.pageParam);
|
|
22
|
+
_context.prev = 2;
|
|
23
|
+
_context.next = 5;
|
|
24
|
+
return dataSource.fetch(context, fetchContext, paginatedRequest);
|
|
25
|
+
case 5:
|
|
26
|
+
response = _context.sent;
|
|
27
|
+
return _context.abrupt("return", formatNullableValue(response));
|
|
28
|
+
case 9:
|
|
29
|
+
_context.prev = 9;
|
|
30
|
+
_context.t0 = _context["catch"](2);
|
|
31
|
+
if (transformError) {
|
|
32
|
+
_context.next = 13;
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
throw _context.t0;
|
|
36
|
+
case 13:
|
|
37
|
+
return _context.abrupt("return", formatNullableValue(transformError(_context.t0)));
|
|
38
|
+
case 14:
|
|
39
|
+
case "end":
|
|
40
|
+
return _context.stop();
|
|
41
|
+
}
|
|
42
|
+
}, _callee, null, [[2, 9]]);
|
|
43
|
+
}));
|
|
44
|
+
return function queryFn(_x) {
|
|
45
|
+
return _ref.apply(this, arguments);
|
|
46
|
+
};
|
|
47
|
+
}();
|
|
48
|
+
var selectPage = function selectPage(response) {
|
|
49
|
+
var actualResponse = parseNullableValue(response);
|
|
50
|
+
return transformResponse ? transformResponse(actualResponse) : actualResponse;
|
|
14
51
|
};
|
|
15
52
|
return _objectSpread(_objectSpread({
|
|
16
53
|
queryKey: composeFullKey(dataSource, params),
|
|
17
54
|
queryFn: params === idle ? skipToken : queryFn,
|
|
18
|
-
select:
|
|
55
|
+
select: function select(data) {
|
|
19
56
|
return _objectSpread(_objectSpread({}, data), {}, {
|
|
20
|
-
pages: data.pages.map(
|
|
57
|
+
pages: data.pages.map(selectPage)
|
|
21
58
|
});
|
|
22
|
-
}
|
|
59
|
+
},
|
|
23
60
|
initialPageParam: EMPTY_OBJECT,
|
|
24
61
|
getNextPageParam: next,
|
|
25
62
|
getPreviousPageParam: prev
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["skipToken","composeFullKey","idle","EMPTY_OBJECT","composeOptions","context","dataSource","params","options","transformParams","transformResponse","next","prev","queryFn","fetchContext","request","paginatedRequest","_objectSpread","pageParam","fetch","queryKey","select","data","pages","map","
|
|
1
|
+
{"version":3,"names":["skipToken","composeFullKey","idle","formatNullableValue","parseNullableValue","EMPTY_OBJECT","composeOptions","context","dataSource","params","options","transformParams","transformError","transformResponse","next","prev","queryFn","_ref","_asyncToGenerator","_regeneratorRuntime","mark","_callee","fetchContext","request","paginatedRequest","response","wrap","_callee$","_context","_objectSpread","pageParam","fetch","sent","abrupt","t0","stop","_x","apply","arguments","selectPage","actualResponse","queryKey","select","data","pages","map","initialPageParam","getNextPageParam","getPreviousPageParam"],"sources":["utils.ts"],"sourcesContent":["import {skipToken} from '@tanstack/react-query';\nimport type {InfiniteData, QueryFunctionContext} from '@tanstack/react-query';\n\nimport {composeFullKey, idle} from '../../../core';\nimport type {\n DataSourceContext,\n DataSourceData,\n DataSourceError,\n DataSourceKey,\n DataSourceOptions,\n DataSourceParams,\n DataSourceResponse,\n} from '../../../core';\nimport type {nullSymbol, undefinedSymbol} from '../utils';\nimport {formatNullableValue, parseNullableValue} from '../utils';\n\nimport type {\n AnyInfiniteQueryDataSource,\n AnyPageParam,\n InfiniteQueryObserverExtendedOptions,\n} from './types';\n\nconst EMPTY_OBJECT = {};\n\nexport const composeOptions = <TDataSource extends AnyInfiniteQueryDataSource>(\n context: DataSourceContext<TDataSource>,\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n options?: Partial<DataSourceOptions<TDataSource>>,\n): InfiniteQueryObserverExtendedOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n InfiniteData<DataSourceData<TDataSource>, AnyPageParam>,\n DataSourceResponse<TDataSource>,\n DataSourceKey,\n AnyPageParam\n> => {\n const {transformParams, transformError, transformResponse, next, prev} = dataSource;\n\n const queryFn = async (\n fetchContext: QueryFunctionContext<DataSourceKey, AnyPageParam>,\n ): Promise<DataSourceResponse<TDataSource> | typeof undefinedSymbol | typeof nullSymbol> => {\n const request = transformParams ? transformParams(params) : params;\n const paginatedRequest = {...request, ...fetchContext.pageParam};\n\n try {\n const response = await dataSource.fetch(context, fetchContext, paginatedRequest);\n\n return formatNullableValue(response);\n } catch (error) {\n if (!transformError) {\n throw error;\n }\n\n return formatNullableValue(transformError(error));\n }\n };\n\n const selectPage = (\n response: DataSourceResponse<TDataSource> | typeof undefinedSymbol | typeof nullSymbol,\n ): DataSourceData<TDataSource> => {\n const actualResponse = parseNullableValue(response);\n\n return transformResponse ? transformResponse(actualResponse) : actualResponse;\n };\n\n return {\n queryKey: composeFullKey(dataSource, params),\n queryFn: params === idle ? skipToken : queryFn,\n select: (data) => ({...data, pages: data.pages.map(selectPage)}),\n initialPageParam: EMPTY_OBJECT,\n getNextPageParam: next,\n getPreviousPageParam: prev,\n ...dataSource.options,\n ...options,\n };\n};\n"],"mappings":";;;AAAA,SAAQA,SAAS,QAAO,uBAAuB;AAG/C,SAAQC,cAAc,EAAEC,IAAI,QAAO,eAAe;AAWlD,SAAQC,mBAAmB,EAAEC,kBAAkB,QAAO,UAAU;AAQhE,IAAMC,YAAY,GAAG,CAAC,CAAC;AAEvB,OAAO,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CACvBC,OAAuC,EACvCC,UAAuB,EACvBC,MAAqC,EACrCC,OAAiD,EAQhD;EACD,IAAOC,eAAe,GAAmDH,UAAU,CAA5EG,eAAe;IAAEC,cAAc,GAAmCJ,UAAU,CAA3DI,cAAc;IAAEC,iBAAiB,GAAgBL,UAAU,CAA3CK,iBAAiB;IAAEC,IAAI,GAAUN,UAAU,CAAxBM,IAAI;IAAEC,IAAI,GAAIP,UAAU,CAAlBO,IAAI;EAErE,IAAMC,OAAO;IAAA,IAAAC,IAAA,GAAAC,iBAAA,eAAAC,mBAAA,CAAAC,IAAA,CAAG,SAAAC,QACZC,YAA+D;MAAA,IAAAC,OAAA,EAAAC,gBAAA,EAAAC,QAAA;MAAA,OAAAN,mBAAA,CAAAO,IAAA,UAAAC,SAAAC,QAAA;QAAA,kBAAAA,QAAA,CAAAb,IAAA,GAAAa,QAAA,CAAAd,IAAA;UAAA;YAEzDS,OAAO,GAAGZ,eAAe,GAAGA,eAAe,CAACF,MAAM,CAAC,GAAGA,MAAM;YAC5De,gBAAgB,GAAAK,aAAA,CAAAA,aAAA,KAAON,OAAO,GAAKD,YAAY,CAACQ,SAAS;YAAAF,QAAA,CAAAb,IAAA;YAAAa,QAAA,CAAAd,IAAA;YAAA,OAGpCN,UAAU,CAACuB,KAAK,CAACxB,OAAO,EAAEe,YAAY,EAAEE,gBAAgB,CAAC;UAAA;YAA1EC,QAAQ,GAAAG,QAAA,CAAAI,IAAA;YAAA,OAAAJ,QAAA,CAAAK,MAAA,WAEP9B,mBAAmB,CAACsB,QAAQ,CAAC;UAAA;YAAAG,QAAA,CAAAb,IAAA;YAAAa,QAAA,CAAAM,EAAA,GAAAN,QAAA;YAAA,IAE/BhB,cAAc;cAAAgB,QAAA,CAAAd,IAAA;cAAA;YAAA;YAAA,MAAAc,QAAA,CAAAM,EAAA;UAAA;YAAA,OAAAN,QAAA,CAAAK,MAAA,WAIZ9B,mBAAmB,CAACS,cAAc,CAAAgB,QAAA,CAAAM,EAAM,CAAC,CAAC;UAAA;UAAA;YAAA,OAAAN,QAAA,CAAAO,IAAA;QAAA;MAAA,GAAAd,OAAA;IAAA,CAExD;IAAA,gBAjBKL,OAAOA,CAAAoB,EAAA;MAAA,OAAAnB,IAAA,CAAAoB,KAAA,OAAAC,SAAA;IAAA;EAAA,GAiBZ;EAED,IAAMC,UAAU,GAAG,SAAbA,UAAUA,CACZd,QAAsF,EACxD;IAC9B,IAAMe,cAAc,GAAGpC,kBAAkB,CAACqB,QAAQ,CAAC;IAEnD,OAAOZ,iBAAiB,GAAGA,iBAAiB,CAAC2B,cAAc,CAAC,GAAGA,cAAc;EACjF,CAAC;EAED,OAAAX,aAAA,CAAAA,aAAA;IACIY,QAAQ,EAAExC,cAAc,CAACO,UAAU,EAAEC,MAAM,CAAC;IAC5CO,OAAO,EAAEP,MAAM,KAAKP,IAAI,GAAGF,SAAS,GAAGgB,OAAO;IAC9C0B,MAAM,EAAE,SAARA,MAAMA,CAAGC,IAAI;MAAA,OAAAd,aAAA,CAAAA,aAAA,KAAUc,IAAI;QAAEC,KAAK,EAAED,IAAI,CAACC,KAAK,CAACC,GAAG,CAACN,UAAU;MAAC;IAAA,CAAE;IAChEO,gBAAgB,EAAEzC,YAAY;IAC9B0C,gBAAgB,EAAEjC,IAAI;IACtBkC,oBAAoB,EAAEjC;EAAI,GACvBP,UAAU,CAACE,OAAO,GAClBA,OAAO;AAElB,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { PlainQueryDataSource } from './types';
|
|
2
|
-
export declare const makePlainQueryDataSource: <TParams, TRequest, TResponse, TData, TError>(config: Omit<PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError>, "type">) => PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError>;
|
|
2
|
+
export declare const makePlainQueryDataSource: <TParams, TRequest, TResponse, TData, TError, TErrorResponse>(config: Omit<PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>, "type">) => PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["makePlainQueryDataSource","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,\n TResponse,\n TData,\n TError,\n TErrorResponse,\n>(\n config: Omit<\n PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse>,\n 'type'\n >,\n): PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> => ({\n ...config,\n type: 'plain',\n});\n"],"mappings":";AAEA,OAAO,IAAMA,wBAAwB,GAAG,SAA3BA,wBAAwBA,CAQjCC,MAGC;EAAA,OAAAC,aAAA,CAAAA,aAAA,KAEED,MAAM;IACTE,IAAI,EAAE;EAAO;AAAA,CACf","ignoreList":[]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { DefaultError, QueryFunctionContext, QueryKey, QueryObserverOptions, QueryObserverResult } from '@tanstack/react-query';
|
|
2
2
|
import type { Overwrite } from 'utility-types';
|
|
3
|
-
import type { ActualData, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
3
|
+
import type { ActualData, ActualResponse, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
4
4
|
import type { QueryDataSourceContext } from '../../types/base';
|
|
5
5
|
import type { QueryDataAdditionalOptions } from '../../types/options';
|
|
6
6
|
export type QueryObserverExtendedOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = never> = Overwrite<QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, QueryDataAdditionalOptions<TQueryFnData, TError, TQueryData, TQueryKey>>;
|
|
7
|
-
export type PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, QueryObserverExtendedOptions<TResponse
|
|
7
|
+
export type PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, TErrorResponse, QueryObserverExtendedOptions<ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, NoInfer<TError>, ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>, ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>, DataSourceKey>, ResultWrapper<QueryObserverResult<ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>, NoInfer<TError>>, NoInfer<TResponse>, NoInfer<TData>, NoInfer<TError>, NoInfer<TErrorResponse>>, QueryFunctionContext<DataSourceKey>> & {
|
|
8
8
|
type: 'plain';
|
|
9
9
|
};
|
|
10
|
-
export type AnyPlainQueryDataSource = PlainQueryDataSource<any, any, any, any, any>;
|
|
11
|
-
type ResultWrapper<TResult, TResponse, TData, TError> = TResult extends QueryObserverResult<ActualData<TData,
|
|
10
|
+
export type AnyPlainQueryDataSource = PlainQueryDataSource<any, any, any, any, any, any>;
|
|
11
|
+
type ResultWrapper<TResult, TResponse, TData, TError, TErrorResponse> = TResult extends QueryObserverResult<ActualData<TResponse, TData, TErrorResponse>, TError> ? Overwrite<TResult, {
|
|
12
12
|
status: DataLoaderStatus;
|
|
13
13
|
}> & {
|
|
14
14
|
originalStatus: TResult['status'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n DefaultError,\n QueryFunctionContext,\n QueryKey,\n QueryObserverOptions,\n QueryObserverResult,\n} from '@tanstack/react-query';\nimport type {Overwrite} from 'utility-types';\n\nimport type {ActualData
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n DefaultError,\n QueryFunctionContext,\n QueryKey,\n QueryObserverOptions,\n QueryObserverResult,\n} from '@tanstack/react-query';\nimport type {Overwrite} from 'utility-types';\n\nimport type {\n ActualData,\n ActualResponse,\n DataLoaderStatus,\n DataSource,\n DataSourceKey,\n} from '../../../core';\nimport type {QueryDataSourceContext} from '../../types/base';\nimport type {QueryDataAdditionalOptions} from '../../types/options';\n\nexport type QueryObserverExtendedOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n> = Overwrite<\n QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>,\n QueryDataAdditionalOptions<TQueryFnData, TError, TQueryData, TQueryKey>\n>;\n\nexport type PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError, TErrorResponse> =\n DataSource<\n QueryDataSourceContext,\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n TErrorResponse,\n QueryObserverExtendedOptions<\n ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n NoInfer<TError>,\n ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>,\n ActualResponse<NoInfer<TResponse>, NoInfer<TErrorResponse>>,\n DataSourceKey\n >,\n ResultWrapper<\n QueryObserverResult<\n ActualData<NoInfer<TResponse>, NoInfer<TData>, NoInfer<TErrorResponse>>,\n NoInfer<TError>\n >,\n NoInfer<TResponse>,\n NoInfer<TData>,\n NoInfer<TError>,\n NoInfer<TErrorResponse>\n >,\n QueryFunctionContext<DataSourceKey>\n > & {\n type: 'plain';\n };\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyPlainQueryDataSource = PlainQueryDataSource<any, any, any, any, any, any>;\n\ntype ResultWrapper<TResult, TResponse, TData, TError, TErrorResponse> =\n TResult extends QueryObserverResult<ActualData<TResponse, TData, TErrorResponse>, TError>\n ? Overwrite<TResult, {status: DataLoaderStatus}> & {originalStatus: TResult['status']}\n : never;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,15 +1,53 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
4
|
import { skipToken } from '@tanstack/react-query';
|
|
3
5
|
import { composeFullKey, idle } from '../../../core';
|
|
6
|
+
import { formatNullableValue, parseNullableValue } from '../utils';
|
|
4
7
|
export var composeOptions = function composeOptions(context, dataSource, params, options) {
|
|
5
|
-
var transformParams = dataSource.transformParams
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
var transformParams = dataSource.transformParams,
|
|
9
|
+
transformResponse = dataSource.transformResponse,
|
|
10
|
+
transformError = dataSource.transformError;
|
|
11
|
+
var queryFn = /*#__PURE__*/function () {
|
|
12
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(fetchContext) {
|
|
13
|
+
var response;
|
|
14
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
15
|
+
while (1) switch (_context.prev = _context.next) {
|
|
16
|
+
case 0:
|
|
17
|
+
_context.prev = 0;
|
|
18
|
+
_context.next = 3;
|
|
19
|
+
return dataSource.fetch(context, fetchContext, transformParams ? transformParams(params) : params);
|
|
20
|
+
case 3:
|
|
21
|
+
response = _context.sent;
|
|
22
|
+
return _context.abrupt("return", formatNullableValue(response));
|
|
23
|
+
case 7:
|
|
24
|
+
_context.prev = 7;
|
|
25
|
+
_context.t0 = _context["catch"](0);
|
|
26
|
+
if (transformError) {
|
|
27
|
+
_context.next = 11;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
throw _context.t0;
|
|
31
|
+
case 11:
|
|
32
|
+
return _context.abrupt("return", formatNullableValue(transformError(_context.t0)));
|
|
33
|
+
case 12:
|
|
34
|
+
case "end":
|
|
35
|
+
return _context.stop();
|
|
36
|
+
}
|
|
37
|
+
}, _callee, null, [[0, 7]]);
|
|
38
|
+
}));
|
|
39
|
+
return function queryFn(_x) {
|
|
40
|
+
return _ref.apply(this, arguments);
|
|
41
|
+
};
|
|
42
|
+
}();
|
|
43
|
+
var select = function select(response) {
|
|
44
|
+
var actualResponse = parseNullableValue(response);
|
|
45
|
+
return transformResponse ? transformResponse(actualResponse) : actualResponse;
|
|
8
46
|
};
|
|
9
47
|
return _objectSpread(_objectSpread({
|
|
10
48
|
queryKey: composeFullKey(dataSource, params),
|
|
11
49
|
queryFn: params === idle ? skipToken : queryFn,
|
|
12
|
-
select:
|
|
50
|
+
select: select
|
|
13
51
|
}, dataSource.options), options);
|
|
14
52
|
};
|
|
15
53
|
// #sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["skipToken","composeFullKey","idle","composeOptions","context","dataSource","params","options","transformParams","queryFn","fetchContext","fetch","
|
|
1
|
+
{"version":3,"names":["skipToken","composeFullKey","idle","formatNullableValue","parseNullableValue","composeOptions","context","dataSource","params","options","transformParams","transformResponse","transformError","queryFn","_ref","_asyncToGenerator","_regeneratorRuntime","mark","_callee","fetchContext","response","wrap","_callee$","_context","prev","next","fetch","sent","abrupt","t0","stop","_x","apply","arguments","select","actualResponse","_objectSpread","queryKey"],"sources":["utils.ts"],"sourcesContent":["import {type QueryFunctionContext, skipToken} from '@tanstack/react-query';\n\nimport {composeFullKey, idle} from '../../../core';\nimport type {\n DataSourceContext,\n DataSourceData,\n DataSourceError,\n DataSourceKey,\n DataSourceOptions,\n DataSourceParams,\n DataSourceResponse,\n} from '../../../core';\nimport type {nullSymbol, undefinedSymbol} from '../utils';\nimport {formatNullableValue, parseNullableValue} from '../utils';\n\nimport type {AnyPlainQueryDataSource, QueryObserverExtendedOptions} from './types';\n\nexport const composeOptions = <TDataSource extends AnyPlainQueryDataSource>(\n context: DataSourceContext<TDataSource>,\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n options?: Partial<DataSourceOptions<TDataSource>>,\n): QueryObserverExtendedOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n DataSourceData<TDataSource>,\n DataSourceResponse<TDataSource>,\n DataSourceKey\n> => {\n const {transformParams, transformResponse, transformError} = dataSource;\n\n const queryFn = async (\n fetchContext: QueryFunctionContext<DataSourceKey>,\n ): Promise<DataSourceResponse<TDataSource> | typeof undefinedSymbol | typeof nullSymbol> => {\n try {\n const response = await dataSource.fetch(\n context,\n fetchContext,\n transformParams ? transformParams(params) : params,\n );\n\n return formatNullableValue(response);\n } catch (error) {\n if (!transformError) {\n throw error;\n }\n\n return formatNullableValue(transformError(error));\n }\n };\n\n const select = (\n response: DataSourceResponse<TDataSource> | typeof undefinedSymbol | typeof nullSymbol,\n ): DataSourceData<TDataSource> => {\n const actualResponse = parseNullableValue(response);\n\n return transformResponse ? transformResponse(actualResponse) : actualResponse;\n };\n\n return {\n queryKey: composeFullKey(dataSource, params),\n queryFn: params === idle ? skipToken : queryFn,\n select,\n ...dataSource.options,\n ...options,\n };\n};\n"],"mappings":";;;AAAA,SAAmCA,SAAS,QAAO,uBAAuB;AAE1E,SAAQC,cAAc,EAAEC,IAAI,QAAO,eAAe;AAWlD,SAAQC,mBAAmB,EAAEC,kBAAkB,QAAO,UAAU;AAIhE,OAAO,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CACvBC,OAAuC,EACvCC,UAAuB,EACvBC,MAAqC,EACrCC,OAAiD,EAOhD;EACD,IAAOC,eAAe,GAAuCH,UAAU,CAAhEG,eAAe;IAAEC,iBAAiB,GAAoBJ,UAAU,CAA/CI,iBAAiB;IAAEC,cAAc,GAAIL,UAAU,CAA5BK,cAAc;EAEzD,IAAMC,OAAO;IAAA,IAAAC,IAAA,GAAAC,iBAAA,eAAAC,mBAAA,CAAAC,IAAA,CAAG,SAAAC,QACZC,YAAiD;MAAA,IAAAC,QAAA;MAAA,OAAAJ,mBAAA,CAAAK,IAAA,UAAAC,SAAAC,QAAA;QAAA,kBAAAA,QAAA,CAAAC,IAAA,GAAAD,QAAA,CAAAE,IAAA;UAAA;YAAAF,QAAA,CAAAC,IAAA;YAAAD,QAAA,CAAAE,IAAA;YAAA,OAGtBlB,UAAU,CAACmB,KAAK,CACnCpB,OAAO,EACPa,YAAY,EACZT,eAAe,GAAGA,eAAe,CAACF,MAAM,CAAC,GAAGA,MAChD,CAAC;UAAA;YAJKY,QAAQ,GAAAG,QAAA,CAAAI,IAAA;YAAA,OAAAJ,QAAA,CAAAK,MAAA,WAMPzB,mBAAmB,CAACiB,QAAQ,CAAC;UAAA;YAAAG,QAAA,CAAAC,IAAA;YAAAD,QAAA,CAAAM,EAAA,GAAAN,QAAA;YAAA,IAE/BX,cAAc;cAAAW,QAAA,CAAAE,IAAA;cAAA;YAAA;YAAA,MAAAF,QAAA,CAAAM,EAAA;UAAA;YAAA,OAAAN,QAAA,CAAAK,MAAA,WAIZzB,mBAAmB,CAACS,cAAc,CAAAW,QAAA,CAAAM,EAAM,CAAC,CAAC;UAAA;UAAA;YAAA,OAAAN,QAAA,CAAAO,IAAA;QAAA;MAAA,GAAAZ,OAAA;IAAA,CAExD;IAAA,gBAlBKL,OAAOA,CAAAkB,EAAA;MAAA,OAAAjB,IAAA,CAAAkB,KAAA,OAAAC,SAAA;IAAA;EAAA,GAkBZ;EAED,IAAMC,MAAM,GAAG,SAATA,MAAMA,CACRd,QAAsF,EACxD;IAC9B,IAAMe,cAAc,GAAG/B,kBAAkB,CAACgB,QAAQ,CAAC;IAEnD,OAAOT,iBAAiB,GAAGA,iBAAiB,CAACwB,cAAc,CAAC,GAAGA,cAAc;EACjF,CAAC;EAED,OAAAC,aAAA,CAAAA,aAAA;IACIC,QAAQ,EAAEpC,cAAc,CAACM,UAAU,EAAEC,MAAM,CAAC;IAC5CK,OAAO,EAAEL,MAAM,KAAKN,IAAI,GAAGF,SAAS,GAAGa,OAAO;IAC9CqB,MAAM,EAANA;EAAM,GACH3B,UAAU,CAACE,OAAO,GAClBA,OAAO;AAElB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const undefinedSymbol: unique symbol;
|
|
2
|
+
export declare const nullSymbol: unique symbol;
|
|
3
|
+
export declare const formatNullableValue: <T>(value: T | undefined | null) => T | typeof undefinedSymbol | typeof nullSymbol;
|
|
4
|
+
export declare const parseNullableValue: <T>(value: T | typeof undefinedSymbol | typeof nullSymbol) => T | undefined | null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export var undefinedSymbol = Symbol('undefined');
|
|
2
|
+
export var nullSymbol = Symbol('null');
|
|
3
|
+
export var formatNullableValue = function formatNullableValue(value) {
|
|
4
|
+
if (value === undefined) {
|
|
5
|
+
return undefinedSymbol;
|
|
6
|
+
}
|
|
7
|
+
if (value === null) {
|
|
8
|
+
return nullSymbol;
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
};
|
|
12
|
+
export var parseNullableValue = function parseNullableValue(value) {
|
|
13
|
+
if (value === undefinedSymbol) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
if (value === nullSymbol) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
};
|
|
21
|
+
// #sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["undefinedSymbol","Symbol","nullSymbol","formatNullableValue","value","undefined","parseNullableValue"],"sources":["utils.ts"],"sourcesContent":["export const undefinedSymbol = Symbol('undefined');\nexport const nullSymbol = Symbol('null');\n\nexport const formatNullableValue = <T>(\n value: T | undefined | null,\n): T | typeof undefinedSymbol | typeof nullSymbol => {\n if (value === undefined) {\n return undefinedSymbol;\n }\n\n if (value === null) {\n return nullSymbol;\n }\n\n return value;\n};\n\nexport const parseNullableValue = <T>(\n value: T | typeof undefinedSymbol | typeof nullSymbol,\n): T | undefined | null => {\n if (value === undefinedSymbol) {\n return undefined;\n }\n\n if (value === nullSymbol) {\n return null;\n }\n\n return value;\n};\n"],"mappings":"AAAA,OAAO,IAAMA,eAAe,GAAGC,MAAM,CAAC,WAAW,CAAC;AAClD,OAAO,IAAMC,UAAU,GAAGD,MAAM,CAAC,MAAM,CAAC;AAExC,OAAO,IAAME,mBAAmB,GAAG,SAAtBA,mBAAmBA,CAC5BC,KAA2B,EACsB;EACjD,IAAIA,KAAK,KAAKC,SAAS,EAAE;IACrB,OAAOL,eAAe;EAC1B;EAEA,IAAII,KAAK,KAAK,IAAI,EAAE;IAChB,OAAOF,UAAU;EACrB;EAEA,OAAOE,KAAK;AAChB,CAAC;AAED,OAAO,IAAME,kBAAkB,GAAG,SAArBA,kBAAkBA,CAC3BF,KAAqD,EAC9B;EACvB,IAAIA,KAAK,KAAKJ,eAAe,EAAE;IAC3B,OAAOK,SAAS;EACpB;EAEA,IAAID,KAAK,KAAKF,UAAU,EAAE;IACtB,OAAO,IAAI;EACf;EAEA,OAAOE,KAAK;AAChB,CAAC","ignoreList":[]}
|