@gravity-ui/data-source 0.7.0 → 0.8.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/README.md +752 -15
- package/build/cjs/core/index.d.ts +1 -0
- package/build/cjs/core/index.js.map +1 -1
- package/build/cjs/core/types/DataManager.d.ts +5 -0
- package/build/cjs/core/types/DataManager.js.map +1 -1
- package/build/cjs/core/types/Normalizer.d.ts +29 -0
- package/build/cjs/core/types/Normalizer.js +6 -0
- package/build/cjs/core/types/Normalizer.js.map +1 -0
- package/build/cjs/react/DataManagerProvider.d.ts +7 -0
- package/build/cjs/react/DataManagerProvider.js +19 -0
- package/build/cjs/react/DataManagerProvider.js.map +1 -0
- package/build/cjs/react/__tests__/DataManagerContext.test.js +7 -6
- package/build/cjs/react/__tests__/DataManagerContext.test.js.map +1 -1
- package/build/cjs/react/__tests__/withDataManager.test.js +3 -0
- package/build/cjs/react/__tests__/withDataManager.test.js.map +1 -1
- package/build/cjs/react/index.d.ts +2 -0
- package/build/cjs/react/index.js +8 -0
- package/build/cjs/react/index.js.map +1 -1
- package/build/cjs/react-query/ClientDataManager.d.ts +11 -2
- package/build/cjs/react-query/ClientDataManager.js +76 -9
- package/build/cjs/react-query/ClientDataManager.js.map +1 -1
- package/build/cjs/react-query/DataSourceProvider.d.ts +7 -0
- package/build/cjs/react-query/DataSourceProvider.js +35 -0
- package/build/cjs/react-query/DataSourceProvider.js.map +1 -0
- package/build/cjs/react-query/__tests__/createQueryNormalizer.test.js +177 -0
- package/build/cjs/react-query/__tests__/createQueryNormalizer.test.js.map +1 -0
- package/build/cjs/react-query/__tests__/normalizationEdgeCases.test.js +100 -0
- package/build/cjs/react-query/__tests__/normalizationEdgeCases.test.js.map +1 -0
- package/build/cjs/react-query/__tests__/subscriptions.test.js +1180 -0
- package/build/cjs/react-query/__tests__/subscriptions.test.js.map +1 -0
- package/build/cjs/react-query/__tests__/threeLevelIntegration.test.js +514 -0
- package/build/cjs/react-query/__tests__/threeLevelIntegration.test.js.map +1 -0
- package/build/cjs/react-query/__tests__/updateQueriesFromMutationData.test.js +229 -0
- package/build/cjs/react-query/__tests__/updateQueriesFromMutationData.test.js.map +1 -0
- package/build/cjs/react-query/hooks/__tests__/useQueryData.refetch.test.js +195 -0
- package/build/cjs/react-query/hooks/__tests__/useQueryData.refetch.test.js.map +1 -0
- package/build/cjs/react-query/impl/infinite/hooks.js +4 -1
- package/build/cjs/react-query/impl/infinite/hooks.js.map +1 -1
- package/build/cjs/react-query/impl/infinite/types.d.ts +2 -2
- package/build/cjs/react-query/impl/infinite/types.js.map +1 -1
- package/build/cjs/react-query/impl/plain/hooks.js +4 -1
- package/build/cjs/react-query/impl/plain/hooks.js.map +1 -1
- package/build/cjs/react-query/impl/plain/types.d.ts +2 -2
- package/build/cjs/react-query/impl/plain/types.js.map +1 -1
- package/build/cjs/react-query/index.d.ts +2 -0
- package/build/cjs/react-query/index.js +7 -0
- package/build/cjs/react-query/index.js.map +1 -1
- package/build/cjs/react-query/types/normalizer.d.ts +21 -0
- package/build/cjs/react-query/types/normalizer.js +6 -0
- package/build/cjs/react-query/types/normalizer.js.map +1 -0
- package/build/cjs/react-query/types/options.d.ts +12 -0
- package/build/cjs/react-query/types/options.js.map +1 -1
- package/build/cjs/react-query/utils/normalize.d.ts +22 -0
- package/build/cjs/react-query/utils/normalize.js +150 -0
- package/build/cjs/react-query/utils/normalize.js.map +1 -0
- package/build/cjs/react-query/utils/warn.d.ts +1 -0
- package/build/cjs/react-query/utils/warn.js +15 -0
- package/build/cjs/react-query/utils/warn.js.map +1 -0
- package/build/cjs/react-query/utils/warnDisabledRefetch.d.ts +1 -0
- package/build/cjs/react-query/utils/warnDisabledRefetch.js +11 -0
- package/build/cjs/react-query/utils/warnDisabledRefetch.js.map +1 -0
- package/build/esm/core/index.d.ts +1 -0
- package/build/esm/core/index.js.map +1 -1
- package/build/esm/core/types/DataManager.d.ts +5 -0
- package/build/esm/core/types/DataManager.js.map +1 -1
- package/build/esm/core/types/Normalizer.d.ts +29 -0
- package/build/esm/core/types/Normalizer.js +2 -0
- package/build/esm/core/types/Normalizer.js.map +1 -0
- package/build/esm/react/DataManagerProvider.d.ts +7 -0
- package/build/esm/react/DataManagerProvider.js +12 -0
- package/build/esm/react/DataManagerProvider.js.map +1 -0
- package/build/esm/react/__tests__/DataManagerContext.test.js +7 -6
- package/build/esm/react/__tests__/DataManagerContext.test.js.map +1 -1
- package/build/esm/react/__tests__/withDataManager.test.js +3 -0
- package/build/esm/react/__tests__/withDataManager.test.js.map +1 -1
- package/build/esm/react/index.d.ts +2 -0
- package/build/esm/react/index.js +1 -0
- package/build/esm/react/index.js.map +1 -1
- package/build/esm/react-query/ClientDataManager.d.ts +11 -2
- package/build/esm/react-query/ClientDataManager.js +70 -3
- package/build/esm/react-query/ClientDataManager.js.map +1 -1
- package/build/esm/react-query/DataSourceProvider.d.ts +7 -0
- package/build/esm/react-query/DataSourceProvider.js +28 -0
- package/build/esm/react-query/DataSourceProvider.js.map +1 -0
- package/build/esm/react-query/__tests__/createQueryNormalizer.test.js +174 -0
- package/build/esm/react-query/__tests__/createQueryNormalizer.test.js.map +1 -0
- package/build/esm/react-query/__tests__/normalizationEdgeCases.test.js +98 -0
- package/build/esm/react-query/__tests__/normalizationEdgeCases.test.js.map +1 -0
- package/build/esm/react-query/__tests__/subscriptions.test.js +1176 -0
- package/build/esm/react-query/__tests__/subscriptions.test.js.map +1 -0
- package/build/esm/react-query/__tests__/threeLevelIntegration.test.js +511 -0
- package/build/esm/react-query/__tests__/threeLevelIntegration.test.js.map +1 -0
- package/build/esm/react-query/__tests__/updateQueriesFromMutationData.test.js +227 -0
- package/build/esm/react-query/__tests__/updateQueriesFromMutationData.test.js.map +1 -0
- package/build/esm/react-query/hooks/__tests__/useQueryData.refetch.test.js +192 -0
- package/build/esm/react-query/hooks/__tests__/useQueryData.refetch.test.js.map +1 -0
- package/build/esm/react-query/impl/infinite/hooks.js +5 -2
- package/build/esm/react-query/impl/infinite/hooks.js.map +1 -1
- package/build/esm/react-query/impl/infinite/types.d.ts +2 -2
- package/build/esm/react-query/impl/infinite/types.js.map +1 -1
- package/build/esm/react-query/impl/plain/hooks.js +5 -2
- package/build/esm/react-query/impl/plain/hooks.js.map +1 -1
- package/build/esm/react-query/impl/plain/types.d.ts +2 -2
- package/build/esm/react-query/impl/plain/types.js.map +1 -1
- package/build/esm/react-query/index.d.ts +2 -0
- package/build/esm/react-query/index.js +1 -0
- package/build/esm/react-query/index.js.map +1 -1
- package/build/esm/react-query/types/normalizer.d.ts +21 -0
- package/build/esm/react-query/types/normalizer.js +2 -0
- package/build/esm/react-query/types/normalizer.js.map +1 -0
- package/build/esm/react-query/types/options.d.ts +12 -0
- package/build/esm/react-query/types/options.js.map +1 -1
- package/build/esm/react-query/utils/normalize.d.ts +22 -0
- package/build/esm/react-query/utils/normalize.js +143 -0
- package/build/esm/react-query/utils/normalize.js.map +1 -0
- package/build/esm/react-query/utils/warn.d.ts +1 -0
- package/build/esm/react-query/utils/warn.js +9 -0
- package/build/esm/react-query/utils/warn.js.map +1 -0
- package/build/esm/react-query/utils/warnDisabledRefetch.d.ts +1 -0
- package/build/esm/react-query/utils/warnDisabledRefetch.js +5 -0
- package/build/esm/react-query/utils/warnDisabledRefetch.js.map +1 -0
- package/package.json +2 -1
|
@@ -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, DataLoaderStatus, DataSource, DataSourceKey} from '../../../core';\nimport type {QueryDataSourceContext} from '../../types/base';\nimport type {QueryDataAdditionalOptions} from '../../types/options';\n\nexport type InfiniteQueryObserverExtendedOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =
|
|
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 {Assign, Overwrite} from 'utility-types';\n\nimport type {ActualData, DataLoaderStatus, DataSource, DataSourceKey} from '../../../core';\nimport type {QueryDataSourceContext} from '../../types/base';\nimport type {QueryDataAdditionalOptions} from '../../types/options';\n\nexport type InfiniteQueryObserverExtendedOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = Assign<\n InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>,\n QueryDataAdditionalOptions<\n TQueryFnData,\n TError,\n InfiniteData<TQueryData, TPageParam>,\n TQueryKey\n >\n>;\n\nexport type InfiniteQueryDataSource<TParams, TRequest, TResponse, TData, TError> = DataSource<\n QueryDataSourceContext,\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n InfiniteQueryObserverExtendedOptions<\n NoInfer<TResponse>,\n NoInfer<TError>,\n InfiniteData<ActualData<NoInfer<TData>, NoInfer<TResponse>>, Partial<TRequest>>,\n NoInfer<TResponse>,\n DataSourceKey,\n Partial<NoInfer<TRequest>>\n >,\n ResultWrapper<\n InfiniteQueryObserverResult<\n InfiniteData<ActualData<NoInfer<TData>, NoInfer<TResponse>>, Partial<TRequest>>,\n NoInfer<TError>\n >,\n NoInfer<TRequest>,\n NoInfer<TResponse>,\n NoInfer<TData>,\n NoInfer<TError>\n >,\n QueryFunctionContext<DataSourceKey, Partial<NoInfer<TRequest>>>\n> & {\n type: 'infinite';\n next: (\n lastPage: NoInfer<TResponse>,\n allPages: NoInfer<TResponse>[],\n ) => Partial<NoInfer<TRequest>> | null | undefined;\n prev?: (\n firstPage: NoInfer<TResponse>,\n allPages: NoInfer<TResponse>[],\n ) => Partial<NoInfer<TRequest>> | null | undefined;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyInfiniteQueryDataSource = InfiniteQueryDataSource<any, any, any, any, any>;\n\n// It is used instead of `Partial<DataSourceRequest<TDataSource>>` because TS can't calculate type\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyPageParam = Partial<any>;\n\ntype ResultWrapper<TResult, TRequest, TResponse, TData, TError> =\n TResult extends InfiniteQueryObserverResult<\n InfiniteData<ActualData<TData, TResponse>, Partial<TRequest>>,\n TError\n >\n ? Overwrite<\n TResult,\n {\n status: DataLoaderStatus;\n data: Array<FlatArray<Array<ActualData<TData, TResponse>>, 1>>;\n }\n > & {\n originalStatus: TResult['status'];\n originalData: TResult['data'];\n }\n : never;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -9,6 +9,7 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
|
|
|
9
9
|
var _reactQuery = require("@tanstack/react-query");
|
|
10
10
|
var _useRefetchInterval2 = require("../../hooks/useRefetchInterval");
|
|
11
11
|
var _normalizeStatus = require("../../utils/normalizeStatus");
|
|
12
|
+
var _warnDisabledRefetch = require("../../utils/warnDisabledRefetch");
|
|
12
13
|
var _utils = require("./utils");
|
|
13
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
15
|
var _excluded = ["queryFn", "refetchInterval"];
|
|
@@ -28,9 +29,11 @@ var usePlainQueryData = exports.usePlainQueryData = function usePlainQueryData(c
|
|
|
28
29
|
var extendedOptions = (0, _utils.composeOptions)(context, dataSource, params, options);
|
|
29
30
|
var composedOptions = usePlainQueryDataOptions(extendedOptions);
|
|
30
31
|
var state = (0, _reactQuery.useQuery)(composedOptions);
|
|
32
|
+
var isDisabled = composedOptions.enabled === false || composedOptions.queryFn === _reactQuery.skipToken;
|
|
31
33
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, state), {}, {
|
|
32
34
|
status: (0, _normalizeStatus.normalizeStatus)(state.status, state.fetchStatus),
|
|
33
|
-
originalStatus: state.status
|
|
35
|
+
originalStatus: state.status,
|
|
36
|
+
refetch: isDisabled ? _warnDisabledRefetch.warnDisabledRefetch : state.refetch
|
|
34
37
|
});
|
|
35
38
|
};
|
|
36
39
|
// #sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactQuery","require","_useRefetchInterval2","_normalizeStatus","_utils","_interopRequireDefault","e","__esModule","default","usePlainQueryDataOptions","composedOptions","queryFnOption","queryFn","refetchIntervalOption","refetchInterval","restOptions","_objectWithoutProperties","_excluded","_useRefetchInterval","useRefetchInterval","_objectSpread","usePlainQueryData","exports","context","dataSource","params","options","extendedOptions","composeOptions","state","useQuery","status","normalizeStatus","fetchStatus","originalStatus"],"sources":["hooks.ts"],"sourcesContent":["import {type QueryObserverOptions, useQuery} from '@tanstack/react-query';\n\nimport type {\n DataSourceContext,\n DataSourceData,\n DataSourceError,\n DataSourceKey,\n DataSourceOptions,\n DataSourceParams,\n DataSourceResponse,\n DataSourceState,\n} from '../../../core';\nimport {useRefetchInterval} from '../../hooks/useRefetchInterval';\nimport {normalizeStatus} from '../../utils/normalizeStatus';\n\nimport type {AnyPlainQueryDataSource, QueryObserverExtendedOptions} from './types';\nimport {composeOptions} from './utils';\n\nconst usePlainQueryDataOptions = <TDataSource extends AnyPlainQueryDataSource>(\n composedOptions: QueryObserverExtendedOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n DataSourceData<TDataSource>,\n DataSourceResponse<TDataSource>,\n DataSourceKey\n >,\n): QueryObserverOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n DataSourceData<TDataSource>,\n DataSourceResponse<TDataSource>,\n DataSourceKey\n> => {\n const {\n queryFn: queryFnOption,\n refetchInterval: refetchIntervalOption,\n ...restOptions\n } = composedOptions;\n\n const {queryFn, refetchInterval} = useRefetchInterval(refetchIntervalOption, queryFnOption);\n\n return {...restOptions, queryFn, refetchInterval};\n};\n\nexport const usePlainQueryData = <TDataSource extends AnyPlainQueryDataSource>(\n context: DataSourceContext<TDataSource>,\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n options?: Partial<DataSourceOptions<TDataSource>>,\n): DataSourceState<TDataSource> => {\n const extendedOptions = composeOptions(context, dataSource, params, options);\n const composedOptions = usePlainQueryDataOptions(extendedOptions);\n const state = useQuery(composedOptions);\n\n return {\n ...state,\n status: normalizeStatus(state.status, state.fetchStatus),\n originalStatus: state.status,\n } as DataSourceState<TDataSource>;\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAYA,IAAAC,oBAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;
|
|
1
|
+
{"version":3,"names":["_reactQuery","require","_useRefetchInterval2","_normalizeStatus","_warnDisabledRefetch","_utils","_interopRequireDefault","e","__esModule","default","usePlainQueryDataOptions","composedOptions","queryFnOption","queryFn","refetchIntervalOption","refetchInterval","restOptions","_objectWithoutProperties","_excluded","_useRefetchInterval","useRefetchInterval","_objectSpread","usePlainQueryData","exports","context","dataSource","params","options","extendedOptions","composeOptions","state","useQuery","isDisabled","enabled","skipToken","status","normalizeStatus","fetchStatus","originalStatus","refetch","warnDisabledRefetch"],"sources":["hooks.ts"],"sourcesContent":["import {type QueryObserverOptions, skipToken, useQuery} from '@tanstack/react-query';\n\nimport type {\n DataSourceContext,\n DataSourceData,\n DataSourceError,\n DataSourceKey,\n DataSourceOptions,\n DataSourceParams,\n DataSourceResponse,\n DataSourceState,\n} from '../../../core';\nimport {useRefetchInterval} from '../../hooks/useRefetchInterval';\nimport {normalizeStatus} from '../../utils/normalizeStatus';\nimport {warnDisabledRefetch} from '../../utils/warnDisabledRefetch';\n\nimport type {AnyPlainQueryDataSource, QueryObserverExtendedOptions} from './types';\nimport {composeOptions} from './utils';\n\nconst usePlainQueryDataOptions = <TDataSource extends AnyPlainQueryDataSource>(\n composedOptions: QueryObserverExtendedOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n DataSourceData<TDataSource>,\n DataSourceResponse<TDataSource>,\n DataSourceKey\n >,\n): QueryObserverOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n DataSourceData<TDataSource>,\n DataSourceResponse<TDataSource>,\n DataSourceKey\n> => {\n const {\n queryFn: queryFnOption,\n refetchInterval: refetchIntervalOption,\n ...restOptions\n } = composedOptions;\n\n const {queryFn, refetchInterval} = useRefetchInterval(refetchIntervalOption, queryFnOption);\n\n return {...restOptions, queryFn, refetchInterval};\n};\n\nexport const usePlainQueryData = <TDataSource extends AnyPlainQueryDataSource>(\n context: DataSourceContext<TDataSource>,\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n options?: Partial<DataSourceOptions<TDataSource>>,\n): DataSourceState<TDataSource> => {\n const extendedOptions = composeOptions(context, dataSource, params, options);\n const composedOptions = usePlainQueryDataOptions(extendedOptions);\n const state = useQuery(composedOptions);\n\n const isDisabled = composedOptions.enabled === false || composedOptions.queryFn === skipToken;\n\n return {\n ...state,\n status: normalizeStatus(state.status, state.fetchStatus),\n originalStatus: state.status,\n refetch: isDisabled ? warnDisabledRefetch : state.refetch,\n } as DataSourceState<TDataSource>;\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAYA,IAAAC,oBAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,oBAAA,GAAAH,OAAA;AAGA,IAAAI,MAAA,GAAAJ,OAAA;AAAsC,SAAAK,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;;AAEtC,IAAMG,wBAAwB,GAAG,SAA3BA,wBAAwBA,CAC1BC,eAMC,E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from '@tanstack/react-query';
|
|
2
|
-
import type { Overwrite } from 'utility-types';
|
|
2
|
+
import type { Assign, Overwrite } from 'utility-types';
|
|
3
3
|
import type { ActualData, DataLoaderStatus, DataSource, DataSourceKey } from '../../../core';
|
|
4
4
|
import type { QueryDataSourceContext } from '../../types/base';
|
|
5
5
|
import type { QueryDataAdditionalOptions } from '../../types/options';
|
|
6
|
-
export type QueryObserverExtendedOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = never> =
|
|
6
|
+
export type QueryObserverExtendedOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = never> = Assign<QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, QueryDataAdditionalOptions<TQueryFnData, TError, TQueryData, TQueryKey>>;
|
|
7
7
|
export type PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError> = DataSource<QueryDataSourceContext, TParams, TRequest, TResponse, TData, TError, QueryObserverExtendedOptions<NoInfer<TResponse>, NoInfer<TError>, ActualData<NoInfer<TData>, NoInfer<TResponse>>, NoInfer<TResponse>, DataSourceKey>, ResultWrapper<QueryObserverResult<ActualData<NoInfer<TData>, NoInfer<TResponse>>, NoInfer<TError>>, NoInfer<TResponse>, NoInfer<TData>, NoInfer<TError>>, QueryFunctionContext<DataSourceKey>> & {
|
|
8
8
|
type: 'plain';
|
|
9
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n DefaultError,\n QueryFunctionContext,\n QueryKey,\n QueryObserverOptions,\n QueryObserverResult,\n} from '@tanstack/react-query';\nimport type {Overwrite} from 'utility-types';\n\nimport type {ActualData, DataLoaderStatus, DataSource, DataSourceKey} from '../../../core';\nimport type {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> =
|
|
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 {Assign, Overwrite} from 'utility-types';\n\nimport type {ActualData, DataLoaderStatus, DataSource, DataSourceKey} from '../../../core';\nimport type {QueryDataSourceContext} from '../../types/base';\nimport type {QueryDataAdditionalOptions} from '../../types/options';\n\nexport type QueryObserverExtendedOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n> = Assign<\n QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>,\n QueryDataAdditionalOptions<TQueryFnData, TError, TQueryData, TQueryKey>\n>;\n\nexport type PlainQueryDataSource<TParams, TRequest, TResponse, TData, TError> = DataSource<\n QueryDataSourceContext,\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n QueryObserverExtendedOptions<\n NoInfer<TResponse>,\n NoInfer<TError>,\n ActualData<NoInfer<TData>, NoInfer<TResponse>>,\n NoInfer<TResponse>,\n DataSourceKey\n >,\n ResultWrapper<\n QueryObserverResult<ActualData<NoInfer<TData>, NoInfer<TResponse>>, NoInfer<TError>>,\n NoInfer<TResponse>,\n NoInfer<TData>,\n NoInfer<TError>\n >,\n QueryFunctionContext<DataSourceKey>\n> & {\n type: 'plain';\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyPlainQueryDataSource = PlainQueryDataSource<any, any, any, any, any>;\n\ntype ResultWrapper<TResult, TResponse, TData, TError> =\n TResult extends QueryObserverResult<ActualData<TData, TResponse>, TError>\n ? Overwrite<TResult, {status: DataLoaderStatus}> & {originalStatus: TResult['status']}\n : never;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -16,3 +16,5 @@ export type { ProgressiveRefetchOptions } from './utils/getProgressiveRefetch';
|
|
|
16
16
|
export { getProgressiveRefetch } from './utils/getProgressiveRefetch';
|
|
17
17
|
export type { ClientDataManagerConfig } from './ClientDataManager';
|
|
18
18
|
export { ClientDataManager } from './ClientDataManager';
|
|
19
|
+
export { DataSourceProvider } from './DataSourceProvider';
|
|
20
|
+
export type { QueryNormalizer } from './types/normalizer';
|
|
@@ -9,6 +9,12 @@ Object.defineProperty(exports, "ClientDataManager", {
|
|
|
9
9
|
return _ClientDataManager.ClientDataManager;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "DataSourceProvider", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _DataSourceProvider.DataSourceProvider;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
12
18
|
Object.defineProperty(exports, "composeInfiniteQueryOptions", {
|
|
13
19
|
enumerable: true,
|
|
14
20
|
get: function () {
|
|
@@ -87,4 +93,5 @@ var _utils2 = require("./impl/plain/utils");
|
|
|
87
93
|
var _normalizeStatus = require("./utils/normalizeStatus");
|
|
88
94
|
var _getProgressiveRefetch = require("./utils/getProgressiveRefetch");
|
|
89
95
|
var _ClientDataManager = require("./ClientDataManager");
|
|
96
|
+
var _DataSourceProvider = require("./DataSourceProvider");
|
|
90
97
|
// #sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_useQueryContext","require","_useQueryData","_useQueryResponses","_useRefetchAll","_useRefetchErrored","_factory","_utils","_factory2","_utils2","_normalizeStatus","_getProgressiveRefetch","_ClientDataManager"],"sources":["index.ts"],"sourcesContent":["export type {QueryDataSourceContext, AnyQueryDataSource} from './types/base';\nexport type {RefetchIntervalFunction, RefetchInterval} from './types/refetch-interval';\n\nexport {useQueryContext} from './hooks/useQueryContext';\nexport {useQueryData} from './hooks/useQueryData';\nexport {useQueryResponses} from './hooks/useQueryResponses';\nexport {useRefetchAll} from './hooks/useRefetchAll';\nexport {useRefetchErrored} from './hooks/useRefetchErrored';\n\nexport type {InfiniteQueryDataSource, AnyInfiniteQueryDataSource} from './impl/infinite/types';\nexport {makeInfiniteQueryDataSource} from './impl/infinite/factory';\nexport {composeOptions as composeInfiniteQueryOptions} from './impl/infinite/utils';\n\nexport type {PlainQueryDataSource, AnyPlainQueryDataSource} from './impl/plain/types';\nexport {makePlainQueryDataSource} from './impl/plain/factory';\nexport {composeOptions as composePlainQueryOptions} from './impl/plain/utils';\n\nexport {normalizeStatus} from './utils/normalizeStatus';\nexport type {ProgressiveRefetchOptions} from './utils/getProgressiveRefetch';\nexport {getProgressiveRefetch} from './utils/getProgressiveRefetch';\n\nexport type {ClientDataManagerConfig} from './ClientDataManager';\nexport {ClientDataManager} from './ClientDataManager';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_useQueryContext","require","_useQueryData","_useQueryResponses","_useRefetchAll","_useRefetchErrored","_factory","_utils","_factory2","_utils2","_normalizeStatus","_getProgressiveRefetch","_ClientDataManager","_DataSourceProvider"],"sources":["index.ts"],"sourcesContent":["export type {QueryDataSourceContext, AnyQueryDataSource} from './types/base';\nexport type {RefetchIntervalFunction, RefetchInterval} from './types/refetch-interval';\n\nexport {useQueryContext} from './hooks/useQueryContext';\nexport {useQueryData} from './hooks/useQueryData';\nexport {useQueryResponses} from './hooks/useQueryResponses';\nexport {useRefetchAll} from './hooks/useRefetchAll';\nexport {useRefetchErrored} from './hooks/useRefetchErrored';\n\nexport type {InfiniteQueryDataSource, AnyInfiniteQueryDataSource} from './impl/infinite/types';\nexport {makeInfiniteQueryDataSource} from './impl/infinite/factory';\nexport {composeOptions as composeInfiniteQueryOptions} from './impl/infinite/utils';\n\nexport type {PlainQueryDataSource, AnyPlainQueryDataSource} from './impl/plain/types';\nexport {makePlainQueryDataSource} from './impl/plain/factory';\nexport {composeOptions as composePlainQueryOptions} from './impl/plain/utils';\n\nexport {normalizeStatus} from './utils/normalizeStatus';\nexport type {ProgressiveRefetchOptions} from './utils/getProgressiveRefetch';\nexport {getProgressiveRefetch} from './utils/getProgressiveRefetch';\n\nexport type {ClientDataManagerConfig} from './ClientDataManager';\nexport {ClientDataManager} from './ClientDataManager';\n\nexport {DataSourceProvider} from './DataSourceProvider';\n\nexport type {QueryNormalizer} from './types/normalizer';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAAA,gBAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,kBAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AAGA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAGA,IAAAO,SAAA,GAAAP,OAAA;AACA,IAAAQ,OAAA,GAAAR,OAAA;AAEA,IAAAS,gBAAA,GAAAT,OAAA;AAEA,IAAAU,sBAAA,GAAAV,OAAA;AAGA,IAAAW,kBAAA,GAAAX,OAAA;AAEA,IAAAY,mBAAA,GAAAZ,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Data, NormalizedData } from '@normy/core/types/types';
|
|
2
|
+
export interface QueryNormalizer {
|
|
3
|
+
/** Get normalized data */
|
|
4
|
+
getNormalizedData: () => NormalizedData;
|
|
5
|
+
/** Set normalized data (for manual updates, WebSocket, etc.) */
|
|
6
|
+
setNormalizedData: (data: Data) => void;
|
|
7
|
+
/** Clear all normalized data */
|
|
8
|
+
clear: () => void;
|
|
9
|
+
/** Get object by ID */
|
|
10
|
+
getObjectById: <T extends Data>(id: string, exampleObject?: T) => T | undefined;
|
|
11
|
+
/** Get query fragment */
|
|
12
|
+
getQueryFragment: <T extends Data>(fragment: Data, exampleObject?: T) => T | undefined;
|
|
13
|
+
/** Get dependent queries by data */
|
|
14
|
+
getDependentQueries: (mutationData: Data) => ReadonlyArray<readonly unknown[]>;
|
|
15
|
+
/** Get dependent queries by IDs */
|
|
16
|
+
getDependentQueriesByIds: (ids: ReadonlyArray<string>) => ReadonlyArray<readonly unknown[]>;
|
|
17
|
+
/** Subscribe to QueryCache changes */
|
|
18
|
+
subscribe: () => void;
|
|
19
|
+
/** Unsubscribe from QueryCache changes */
|
|
20
|
+
unsubscribe: () => void;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["normalizer.ts"],"sourcesContent":["import type {Data, NormalizedData} from '@normy/core/types/types';\n\nexport interface QueryNormalizer {\n /** Get normalized data */\n getNormalizedData: () => NormalizedData;\n /** Set normalized data (for manual updates, WebSocket, etc.) */\n setNormalizedData: (data: Data) => void;\n /** Clear all normalized data */\n clear: () => void;\n /** Get object by ID */\n getObjectById: <T extends Data>(id: string, exampleObject?: T) => T | undefined;\n /** Get query fragment */\n getQueryFragment: <T extends Data>(fragment: Data, exampleObject?: T) => T | undefined;\n /** Get dependent queries by data */\n getDependentQueries: (mutationData: Data) => ReadonlyArray<readonly unknown[]>;\n /** Get dependent queries by IDs */\n getDependentQueriesByIds: (ids: ReadonlyArray<string>) => ReadonlyArray<readonly unknown[]>;\n /** Subscribe to QueryCache changes */\n subscribe: () => void;\n /** Unsubscribe from QueryCache changes */\n unsubscribe: () => void;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import type { DefaultError, QueryKey } from '@tanstack/react-query';
|
|
2
|
+
import type { OptimisticConfig } from '../../core/types/Normalizer';
|
|
2
3
|
import type { RefetchInterval } from './refetch-interval';
|
|
3
4
|
export interface QueryDataAdditionalOptions<TQueryFnData = unknown, TError = DefaultError, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> {
|
|
4
5
|
refetchInterval?: RefetchInterval<TQueryFnData, TError, TQueryData, TQueryKey>;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated The use of the enabled option is deprecated.
|
|
8
|
+
* It is recommended to use idle as query parameters to control query state.
|
|
9
|
+
*/
|
|
10
|
+
enabled?: boolean;
|
|
11
|
+
/** Normalization configuration (enable/disable) */
|
|
12
|
+
normalize?: boolean;
|
|
13
|
+
/** Optimistic data update configuration */
|
|
14
|
+
optimistic?: boolean | OptimisticConfig;
|
|
15
|
+
/** Invalidate data configuration */
|
|
16
|
+
invalidate?: boolean;
|
|
5
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["options.ts"],"sourcesContent":["import type {DefaultError, QueryKey} from '@tanstack/react-query';\n\nimport type {RefetchInterval} from './refetch-interval';\n\nexport interface QueryDataAdditionalOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> {\n refetchInterval?: RefetchInterval<TQueryFnData, TError, TQueryData, TQueryKey>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["options.ts"],"sourcesContent":["import type {DefaultError, QueryKey} from '@tanstack/react-query';\n\nimport type {OptimisticConfig} from '../../core/types/Normalizer';\n\nimport type {RefetchInterval} from './refetch-interval';\n\nexport interface QueryDataAdditionalOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> {\n refetchInterval?: RefetchInterval<TQueryFnData, TError, TQueryData, TQueryKey>;\n /**\n * @deprecated The use of the enabled option is deprecated.\n * It is recommended to use idle as query parameters to control query state.\n */\n enabled?: boolean;\n /** Normalization configuration (enable/disable) */\n normalize?: boolean;\n /** Optimistic data update configuration */\n optimistic?: boolean | OptimisticConfig;\n /** Invalidate data configuration */\n invalidate?: boolean;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Data } from '@normy/core';
|
|
2
|
+
import type { QueryClient } from '@tanstack/react-query';
|
|
3
|
+
import type { Normalizer, NormalizerConfig } from '../../core/types/Normalizer';
|
|
4
|
+
export declare const createQueryNormalizer: (normalizer: Normalizer | undefined, queryClient: QueryClient, config: boolean | NormalizerConfig | undefined, optimisticUpdate: (mutationData: Data) => void, invalidateData: (data: Data) => void) => {
|
|
5
|
+
/** Get normalized data */
|
|
6
|
+
getNormalizedData: () => import("@normy/core/types/types").NormalizedData;
|
|
7
|
+
/** Set normalized data (for manual updates, WebSocket, etc.) */
|
|
8
|
+
setNormalizedData: (data: Data) => void;
|
|
9
|
+
/** Clear all normalized data */
|
|
10
|
+
clear: () => void;
|
|
11
|
+
/** Get object by ID */
|
|
12
|
+
getObjectById: <T extends Data>(id: string, exampleObject?: T) => T | undefined;
|
|
13
|
+
/** Get query fragment */
|
|
14
|
+
getQueryFragment: <T extends Data>(fragment: Data, exampleObject?: T) => T | undefined;
|
|
15
|
+
/** Get dependent queries by data */
|
|
16
|
+
getDependentQueries: (mutationData: Data) => (readonly unknown[])[];
|
|
17
|
+
/** Get dependent queries by IDs */
|
|
18
|
+
getDependentQueriesByIds: (ids: ReadonlyArray<string>) => (readonly unknown[])[];
|
|
19
|
+
/** Subscribe to QueryCache changes */
|
|
20
|
+
subscribe: () => void;
|
|
21
|
+
unsubscribe: () => void;
|
|
22
|
+
} | undefined;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createQueryNormalizer = void 0;
|
|
7
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
var shouldInvalidateData = function shouldInvalidateData(globalConfig, mutationConfig) {
|
|
10
|
+
if (mutationConfig === false) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
if (!globalConfig) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
};
|
|
18
|
+
var shouldUpdateOptimistically = function shouldUpdateOptimistically(globalConfig, mutationConfig) {
|
|
19
|
+
if (mutationConfig === false) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (typeof mutationConfig === 'boolean' && mutationConfig || (0, _typeof2.default)(mutationConfig) === 'object' && mutationConfig) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (!globalConfig) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
};
|
|
30
|
+
var getOptimisticProps = function getOptimisticProps(globalConfig, mutationConfig) {
|
|
31
|
+
var globalAutoRollback = (0, _typeof2.default)(globalConfig) === 'object' ? globalConfig.autoCalculateRollback : undefined;
|
|
32
|
+
var mutationAutoRollback = (0, _typeof2.default)(mutationConfig) === 'object' ? mutationConfig.autoCalculateRollback : undefined;
|
|
33
|
+
var globalDevLogging = (0, _typeof2.default)(globalConfig) === 'object' ? globalConfig.devLogging : undefined;
|
|
34
|
+
var mutationDevLogging = (0, _typeof2.default)(mutationConfig) === 'object' ? mutationConfig.devLogging : undefined;
|
|
35
|
+
return {
|
|
36
|
+
autoRollback: mutationAutoRollback !== null && mutationAutoRollback !== void 0 ? mutationAutoRollback : globalAutoRollback,
|
|
37
|
+
devLogging: mutationDevLogging !== null && mutationDevLogging !== void 0 ? mutationDevLogging : globalDevLogging
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
var createQueryNormalizer = exports.createQueryNormalizer = function createQueryNormalizer(normalizer, queryClient, config, optimisticUpdate, invalidateData) {
|
|
41
|
+
if (!normalizer || !config) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
var globalOptimistic = (0, _typeof2.default)(config) === 'object' && 'optimistic' in config ? config.optimistic : false;
|
|
45
|
+
var globalInvalidateData = (0, _typeof2.default)(config) === 'object' && 'invalidate' in config ? config.invalidate : false;
|
|
46
|
+
var unsubscribeQueryCache = null;
|
|
47
|
+
var unsubscribeMutationCache = null;
|
|
48
|
+
return {
|
|
49
|
+
/** Get normalized data */
|
|
50
|
+
getNormalizedData: normalizer.getNormalizedData,
|
|
51
|
+
/** Set normalized data (for manual updates, WebSocket, etc.) */
|
|
52
|
+
setNormalizedData: function setNormalizedData(data) {
|
|
53
|
+
return optimisticUpdate(data);
|
|
54
|
+
},
|
|
55
|
+
/** Clear all normalized data */
|
|
56
|
+
clear: normalizer.clearNormalizedData,
|
|
57
|
+
/** Get object by ID */
|
|
58
|
+
getObjectById: normalizer.getObjectById,
|
|
59
|
+
/** Get query fragment */
|
|
60
|
+
getQueryFragment: normalizer.getQueryFragment,
|
|
61
|
+
/** Get dependent queries by data */
|
|
62
|
+
getDependentQueries: function getDependentQueries(mutationData) {
|
|
63
|
+
return normalizer.getDependentQueries(mutationData).map(function (key) {
|
|
64
|
+
return JSON.parse(key);
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
/** Get dependent queries by IDs */
|
|
68
|
+
getDependentQueriesByIds: function getDependentQueriesByIds(ids) {
|
|
69
|
+
return normalizer.getDependentQueriesByIds(ids).map(function (key) {
|
|
70
|
+
return JSON.parse(key);
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
/** Subscribe to QueryCache changes */
|
|
74
|
+
subscribe: function subscribe() {
|
|
75
|
+
// Subscribe to QueryCache (query additions/updates/removals)
|
|
76
|
+
unsubscribeQueryCache = queryClient.getQueryCache().subscribe(function (event) {
|
|
77
|
+
var _queryOptions$normali;
|
|
78
|
+
var queryKeyStr = JSON.stringify(event.query.queryKey);
|
|
79
|
+
if (event.type === 'removed') {
|
|
80
|
+
normalizer.removeQuery(queryKeyStr);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Check if the query should be normalized
|
|
85
|
+
// At this point options are already merged (DataSource + Hook)
|
|
86
|
+
var queryOptions = event.query.options;
|
|
87
|
+
var queryNormalize = (_queryOptions$normali = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.normalize) !== null && _queryOptions$normali !== void 0 ? _queryOptions$normali : true;
|
|
88
|
+
if (!queryNormalize) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (event.type === 'added' && event.query.state.data !== undefined) {
|
|
92
|
+
normalizer.setQuery(queryKeyStr, event.query.state.data);
|
|
93
|
+
} else if (event.type === 'updated' && event.action.type === 'success' && event.action.data !== undefined) {
|
|
94
|
+
normalizer.setQuery(queryKeyStr, event.action.data);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Subscribe to MutationCache for normalization + optimistic updates
|
|
99
|
+
unsubscribeMutationCache = queryClient.getMutationCache().subscribe(function (event) {
|
|
100
|
+
var _event$mutation;
|
|
101
|
+
// Cast to extended type with additional configs, if available
|
|
102
|
+
var mutationOptions = (_event$mutation = event.mutation) === null || _event$mutation === void 0 ? void 0 : _event$mutation.options;
|
|
103
|
+
var mutationQueryNormalize = mutationOptions === null || mutationOptions === void 0 ? void 0 : mutationOptions.normalize;
|
|
104
|
+
var mutationQueryOptimistic = mutationOptions === null || mutationOptions === void 0 ? void 0 : mutationOptions.optimistic;
|
|
105
|
+
var mutationQueryInvalidateData = mutationOptions === null || mutationOptions === void 0 ? void 0 : mutationOptions.invalidate;
|
|
106
|
+
if (shouldInvalidateData(globalInvalidateData, mutationQueryInvalidateData)) {
|
|
107
|
+
if (event.type === 'updated' && event.action.type === 'success' && event.action.data) {
|
|
108
|
+
invalidateData(event.action.data);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (!mutationQueryNormalize || !shouldUpdateOptimistically(globalOptimistic, mutationQueryOptimistic)) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
var _getOptimisticProps = getOptimisticProps(globalOptimistic, mutationQueryOptimistic),
|
|
115
|
+
autoRollback = _getOptimisticProps.autoRollback,
|
|
116
|
+
devLogging = _getOptimisticProps.devLogging;
|
|
117
|
+
if (event.type === 'updated' && event.action.type === 'success' && event.action.data) {
|
|
118
|
+
optimisticUpdate(event.action.data);
|
|
119
|
+
} else if (event.type === 'updated' && event.action.type === 'pending') {
|
|
120
|
+
var context = event.mutation.state.context;
|
|
121
|
+
if (context !== null && context !== void 0 && context.optimisticData) {
|
|
122
|
+
if (!context.rollbackData && mutationQueryOptimistic && autoRollback !== false) {
|
|
123
|
+
context.rollbackData = normalizer.getCurrentData(context.optimisticData);
|
|
124
|
+
if (devLogging) {
|
|
125
|
+
console.log('[OptimisticUpdate] Auto-calculated rollbackData:', context.rollbackData);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
optimisticUpdate(context.optimisticData);
|
|
129
|
+
}
|
|
130
|
+
} else if (event.type === 'updated' && event.action.type === 'error') {
|
|
131
|
+
var _context = event.mutation.state.context;
|
|
132
|
+
if (_context !== null && _context !== void 0 && _context.rollbackData) {
|
|
133
|
+
if (devLogging) {
|
|
134
|
+
console.log('[OptimisticUpdate] Rolling back changes');
|
|
135
|
+
}
|
|
136
|
+
optimisticUpdate(_context.rollbackData);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
unsubscribe: function unsubscribe() {
|
|
142
|
+
var _unsubscribeQueryCach, _unsubscribeMutationC;
|
|
143
|
+
(_unsubscribeQueryCach = unsubscribeQueryCache) === null || _unsubscribeQueryCach === void 0 || _unsubscribeQueryCach();
|
|
144
|
+
(_unsubscribeMutationC = unsubscribeMutationCache) === null || _unsubscribeMutationC === void 0 || _unsubscribeMutationC();
|
|
145
|
+
unsubscribeQueryCache = null;
|
|
146
|
+
unsubscribeMutationCache = null;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
// #sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["shouldInvalidateData","globalConfig","mutationConfig","shouldUpdateOptimistically","_typeof","getOptimisticProps","globalAutoRollback","autoCalculateRollback","undefined","mutationAutoRollback","globalDevLogging","devLogging","mutationDevLogging","autoRollback","createQueryNormalizer","exports","normalizer","queryClient","config","optimisticUpdate","invalidateData","globalOptimistic","optimistic","globalInvalidateData","invalidate","unsubscribeQueryCache","unsubscribeMutationCache","getNormalizedData","setNormalizedData","data","clear","clearNormalizedData","getObjectById","getQueryFragment","getDependentQueries","mutationData","map","key","JSON","parse","getDependentQueriesByIds","ids","subscribe","getQueryCache","event","_queryOptions$normali","queryKeyStr","stringify","query","queryKey","type","removeQuery","queryOptions","options","queryNormalize","normalize","state","setQuery","action","getMutationCache","_event$mutation","mutationOptions","mutation","mutationQueryNormalize","mutationQueryOptimistic","mutationQueryInvalidateData","_getOptimisticProps","context","optimisticData","rollbackData","getCurrentData","console","log","_context","unsubscribe","_unsubscribeQueryCach","_unsubscribeMutationC"],"sources":["normalize.ts"],"sourcesContent":["import type {Data} from '@normy/core';\nimport type {QueryClient, QueryKey} from '@tanstack/react-query';\n\nimport type {Normalizer, NormalizerConfig, OptimisticConfig} from '../../core/types/Normalizer';\nimport type {QueryDataAdditionalOptions} from '../types/options';\n\ninterface QueryNormalizeOptions {\n normalize?: boolean;\n optimistic?: boolean | OptimisticConfig;\n invalidate?: boolean;\n}\n\nconst shouldInvalidateData = (globalConfig?: boolean, mutationConfig?: boolean): boolean => {\n if (mutationConfig === false) {\n return false;\n }\n\n if (!globalConfig) {\n return false;\n }\n\n return true;\n};\n\nconst shouldUpdateOptimistically = (\n globalConfig?: boolean | OptimisticConfig,\n mutationConfig?: boolean | OptimisticConfig,\n): boolean => {\n if (mutationConfig === false) {\n return false;\n }\n\n if (\n (typeof mutationConfig === 'boolean' && mutationConfig) ||\n (typeof mutationConfig === 'object' && mutationConfig)\n ) {\n return true;\n }\n\n if (!globalConfig) {\n return false;\n }\n\n return true;\n};\n\nconst getOptimisticProps = (\n globalConfig?: boolean | OptimisticConfig,\n mutationConfig?: boolean | OptimisticConfig,\n) => {\n const globalAutoRollback =\n typeof globalConfig === 'object' ? globalConfig.autoCalculateRollback : undefined;\n const mutationAutoRollback =\n typeof mutationConfig === 'object' ? mutationConfig.autoCalculateRollback : undefined;\n const globalDevLogging = typeof globalConfig === 'object' ? globalConfig.devLogging : undefined;\n const mutationDevLogging =\n typeof mutationConfig === 'object' ? mutationConfig.devLogging : undefined;\n\n return {\n autoRollback: mutationAutoRollback ?? globalAutoRollback,\n devLogging: mutationDevLogging ?? globalDevLogging,\n };\n};\n\nexport const createQueryNormalizer = (\n normalizer: Normalizer | undefined,\n queryClient: QueryClient,\n config: boolean | NormalizerConfig | undefined,\n optimisticUpdate: (mutationData: Data) => void,\n invalidateData: (data: Data) => void,\n) => {\n if (!normalizer || !config) {\n return undefined;\n }\n\n const globalOptimistic =\n typeof config === 'object' && 'optimistic' in config ? config.optimistic : false;\n\n const globalInvalidateData =\n typeof config === 'object' && 'invalidate' in config ? config.invalidate : false;\n\n let unsubscribeQueryCache: (() => void) | null = null;\n let unsubscribeMutationCache: (() => void) | null = null;\n\n return {\n /** Get normalized data */\n getNormalizedData: normalizer.getNormalizedData,\n /** Set normalized data (for manual updates, WebSocket, etc.) */\n setNormalizedData: (data: Data) => optimisticUpdate(data),\n /** Clear all normalized data */\n clear: normalizer.clearNormalizedData,\n /** Get object by ID */\n getObjectById: normalizer.getObjectById,\n /** Get query fragment */\n getQueryFragment: normalizer.getQueryFragment,\n /** Get dependent queries by data */\n getDependentQueries: (mutationData: Data) =>\n normalizer.getDependentQueries(mutationData).map((key) => JSON.parse(key) as QueryKey),\n /** Get dependent queries by IDs */\n getDependentQueriesByIds: (ids: ReadonlyArray<string>) =>\n normalizer.getDependentQueriesByIds(ids).map((key) => JSON.parse(key) as QueryKey),\n /** Subscribe to QueryCache changes */\n subscribe: () => {\n // Subscribe to QueryCache (query additions/updates/removals)\n unsubscribeQueryCache = queryClient.getQueryCache().subscribe((event) => {\n const queryKeyStr = JSON.stringify(event.query.queryKey);\n\n if (event.type === 'removed') {\n normalizer.removeQuery(queryKeyStr);\n\n return;\n }\n\n // Check if the query should be normalized\n // At this point options are already merged (DataSource + Hook)\n const queryOptions = event.query.options as QueryDataAdditionalOptions;\n\n const queryNormalize = queryOptions?.normalize ?? true;\n\n if (!queryNormalize) {\n return;\n }\n\n if (event.type === 'added' && event.query.state.data !== undefined) {\n normalizer.setQuery(queryKeyStr, event.query.state.data as Data);\n } else if (\n event.type === 'updated' &&\n event.action.type === 'success' &&\n event.action.data !== undefined\n ) {\n normalizer.setQuery(queryKeyStr, event.action.data as Data);\n }\n });\n\n // Subscribe to MutationCache for normalization + optimistic updates\n unsubscribeMutationCache = queryClient.getMutationCache().subscribe((event) => {\n // Cast to extended type with additional configs, if available\n const mutationOptions = event.mutation?.options as\n | QueryNormalizeOptions\n | undefined;\n\n const mutationQueryNormalize = mutationOptions?.normalize;\n const mutationQueryOptimistic = mutationOptions?.optimistic;\n const mutationQueryInvalidateData = mutationOptions?.invalidate;\n\n if (shouldInvalidateData(globalInvalidateData, mutationQueryInvalidateData)) {\n if (\n event.type === 'updated' &&\n event.action.type === 'success' &&\n event.action.data\n ) {\n invalidateData(event.action.data as Data);\n }\n }\n\n if (\n !mutationQueryNormalize ||\n !shouldUpdateOptimistically(globalOptimistic, mutationQueryOptimistic)\n ) {\n return;\n }\n\n const {autoRollback, devLogging} = getOptimisticProps(\n globalOptimistic,\n mutationQueryOptimistic,\n );\n\n if (\n event.type === 'updated' &&\n event.action.type === 'success' &&\n event.action.data\n ) {\n optimisticUpdate(event.action.data as Data);\n } else if (event.type === 'updated' && event.action.type === 'pending') {\n const context = event.mutation.state.context as {\n optimisticData?: Data;\n rollbackData?: Data;\n };\n\n if (context?.optimisticData) {\n if (\n !context.rollbackData &&\n mutationQueryOptimistic &&\n autoRollback !== false\n ) {\n context.rollbackData = normalizer.getCurrentData(\n context.optimisticData,\n );\n\n if (devLogging) {\n console.log(\n '[OptimisticUpdate] Auto-calculated rollbackData:',\n context.rollbackData,\n );\n }\n }\n\n optimisticUpdate(context.optimisticData);\n }\n } else if (event.type === 'updated' && event.action.type === 'error') {\n const context = event.mutation.state.context as {\n rollbackData?: Data;\n };\n\n if (context?.rollbackData) {\n if (devLogging) {\n console.log('[OptimisticUpdate] Rolling back changes');\n }\n\n optimisticUpdate(context.rollbackData);\n }\n }\n });\n },\n unsubscribe: () => {\n unsubscribeQueryCache?.();\n unsubscribeMutationCache?.();\n unsubscribeQueryCache = null;\n unsubscribeMutationCache = null;\n },\n };\n};\n"],"mappings":";;;;;;;;AAYA,IAAMA,oBAAoB,GAAG,SAAvBA,oBAAoBA,CAAIC,YAAsB,EAAEC,cAAwB,EAAc;EACxF,IAAIA,cAAc,KAAK,KAAK,EAAE;IAC1B,OAAO,KAAK;EAChB;EAEA,IAAI,CAACD,YAAY,EAAE;IACf,OAAO,KAAK;EAChB;EAEA,OAAO,IAAI;AACf,CAAC;AAED,IAAME,0BAA0B,GAAG,SAA7BA,0BAA0BA,CAC5BF,YAAyC,EACzCC,cAA2C,EACjC;EACV,IAAIA,cAAc,KAAK,KAAK,EAAE;IAC1B,OAAO,KAAK;EAChB;EAEA,IACK,OAAOA,cAAc,KAAK,SAAS,IAAIA,cAAc,IACrD,IAAAE,gBAAA,EAAOF,cAAc,MAAK,QAAQ,IAAIA,cAAe,EACxD;IACE,OAAO,IAAI;EACf;EAEA,IAAI,CAACD,YAAY,EAAE;IACf,OAAO,KAAK;EAChB;EAEA,OAAO,IAAI;AACf,CAAC;AAED,IAAMI,kBAAkB,GAAG,SAArBA,kBAAkBA,CACpBJ,YAAyC,EACzCC,cAA2C,EAC1C;EACD,IAAMI,kBAAkB,GACpB,IAAAF,gBAAA,EAAOH,YAAY,MAAK,QAAQ,GAAGA,YAAY,CAACM,qBAAqB,GAAGC,SAAS;EACrF,IAAMC,oBAAo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,EAAE;YACvB,IAAI1D,UAAU,EAAE;cACZ4D,OAAO,CAACC,GAAG,CAAC,yCAAyC,CAAC;YAC1D;YAEArD,gBAAgB,CAACsD,QAAO,CAACJ,YAAY,CAAC;UAC1C;QACJ;MACJ,CAAC,CAAC;IACN,CAAC;IACDK,WAAW,EAAE,SAAbA,WAAWA,CAAA,EAAQ;MAAA,IAAAC,qBAAA,EAAAC,qBAAA;MACf,CAAAD,qBAAA,GAAAlD,qBAAqB,cAAAkD,qBAAA,eAArBA,qBAAA,CAAwB,CAAC;MACzB,CAAAC,qBAAA,GAAAlD,wBAAwB,cAAAkD,qBAAA,eAAxBA,qBAAA,CAA2B,CAAC;MAC5BnD,qBAAqB,GAAG,IAAI;MAC5BC,wBAAwB,GAAG,IAAI;IACnC;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function warn(msg: string): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.warn = warn;
|
|
7
|
+
function warn(msg) {
|
|
8
|
+
if (!msg || process.env.NODE_ENV === 'production') {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// eslint-disable-next-line no-console
|
|
13
|
+
console.warn(msg);
|
|
14
|
+
}
|
|
15
|
+
// #sourceMappingURL=warn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["warn","msg","process","env","NODE_ENV","console"],"sources":["warn.ts"],"sourcesContent":["export function warn(msg: string) {\n if (!msg || process.env.NODE_ENV === 'production') {\n return;\n }\n\n // eslint-disable-next-line no-console\n console.warn(msg);\n}\n"],"mappings":";;;;;;AAAO,SAASA,IAAIA,CAACC,GAAW,EAAE;EAC9B,IAAI,CAACA,GAAG,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;IAC/C;EACJ;;EAEA;EACAC,OAAO,CAACL,IAAI,CAACC,GAAG,CAAC;AACrB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const warnDisabledRefetch: () => void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.warnDisabledRefetch = void 0;
|
|
7
|
+
var _warn = require("./warn");
|
|
8
|
+
var warnDisabledRefetch = exports.warnDisabledRefetch = function warnDisabledRefetch() {
|
|
9
|
+
(0, _warn.warn)('Disabled refetch is called');
|
|
10
|
+
};
|
|
11
|
+
// #sourceMappingURL=warnDisabledRefetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_warn","require","warnDisabledRefetch","exports","warn"],"sources":["warnDisabledRefetch.ts"],"sourcesContent":["import {warn} from './warn';\n\nexport const warnDisabledRefetch = () => {\n warn('Disabled refetch is called');\n};\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAEO,IAAMC,mBAAmB,GAAAC,OAAA,CAAAD,mBAAA,GAAG,SAAtBA,mBAAmBA,CAAA,EAAS;EACrC,IAAAE,UAAI,EAAC,4BAA4B,CAAC;AACtC,CAAC","ignoreList":[]}
|
|
@@ -2,6 +2,7 @@ export type { DataSourceKey, DataSourceTag, DataSource, AnyDataSource, DataSourc
|
|
|
2
2
|
export type { DataManager } from './types/DataManager';
|
|
3
3
|
export type { DataLoaderStatus } from './types/DataLoaderStatus';
|
|
4
4
|
export type { InvalidateRepeatOptions, InvalidateOptions } from './types/DataManagerOptions';
|
|
5
|
+
export type { Normalizer, NormalizerConfig, OptimisticConfig } from './types/Normalizer';
|
|
5
6
|
export { idle } from './constants';
|
|
6
7
|
export { composeKey } from './utils/composeKey';
|
|
7
8
|
export { composeFullKey } from './utils/composeFullKey';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["idle","composeKey","composeFullKey","getError","getStatus","hasTag","mergeStatuses","skipContext","withCatch","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/DataManager';\nexport type {DataLoaderStatus} from './types/DataLoaderStatus';\nexport type {InvalidateRepeatOptions, InvalidateOptions} from './types/DataManagerOptions';\n\nexport {idle} from './constants';\n\nexport {composeKey} from './utils/composeKey';\nexport {composeFullKey} from './utils/composeFullKey';\nexport {getError} from './utils/getError';\nexport {getStatus} from './utils/getStatus';\nexport {hasTag} from './utils/hasTag';\nexport {mergeStatuses} from './utils/mergeStatuses';\nexport {skipContext} from './utils/skipContext';\nexport {withCatch} from './utils/withCatch';\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","withCatch","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/DataManager';\nexport type {DataLoaderStatus} from './types/DataLoaderStatus';\nexport type {InvalidateRepeatOptions, InvalidateOptions} from './types/DataManagerOptions';\nexport type {Normalizer, NormalizerConfig, OptimisticConfig} from './types/Normalizer';\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 {withCatch} from './utils/withCatch';\nexport type {Cancellable} from './utils/withCancellation';\nexport {isCancellable, isAbortable, withCancellation} from './utils/withCancellation';\n"],"mappings":"AAsBA,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;AAC/C,SAAQC,SAAS,QAAO,mBAAmB;AAE3C,SAAQC,aAAa,EAAEC,WAAW,EAAEC,gBAAgB,QAAO,0BAA0B","ignoreList":[]}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import type { Data } from '@normy/core';
|
|
1
2
|
import type { InvalidateOptions } from './DataManagerOptions';
|
|
2
3
|
import type { AnyDataSource, DataSourceParams, DataSourceTag } from './DataSource';
|
|
4
|
+
import type { Normalizer } from './Normalizer';
|
|
3
5
|
export interface DataManager {
|
|
6
|
+
normalizer?: Normalizer;
|
|
7
|
+
optimisticUpdate(mutationData: Data): void;
|
|
8
|
+
invalidateData(data: Data): void;
|
|
4
9
|
invalidateTag(tag: DataSourceTag, invalidateOptions?: InvalidateOptions): Promise<void>;
|
|
5
10
|
invalidateTags(tags: DataSourceTag[], invalidateOptions?: InvalidateOptions): Promise<void>;
|
|
6
11
|
invalidateSource<TDataSource extends AnyDataSource>(dataSource: TDataSource, invalidateOptions?: InvalidateOptions): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["DataManager.ts"],"sourcesContent":["import type {InvalidateOptions} from './DataManagerOptions';\nimport type {AnyDataSource, DataSourceParams, DataSourceTag} from './DataSource';\n\nexport interface DataManager {\n invalidateTag(tag: DataSourceTag, invalidateOptions?: InvalidateOptions): Promise<void>;\n\n invalidateTags(tags: DataSourceTag[], invalidateOptions?: InvalidateOptions): Promise<void>;\n\n invalidateSource<TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n invalidateOptions?: InvalidateOptions,\n ): Promise<void>;\n\n resetSource<TDataSource extends AnyDataSource>(dataSource: TDataSource): Promise<void>;\n\n invalidateParams<TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n invalidateOptions?: InvalidateOptions,\n ): Promise<void>;\n\n resetParams<TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n ): Promise<void>;\n\n invalidateSourceTags<TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n invalidateOptions?: InvalidateOptions,\n ): Promise<void>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["DataManager.ts"],"sourcesContent":["import type {Data} from '@normy/core';\n\nimport type {InvalidateOptions} from './DataManagerOptions';\nimport type {AnyDataSource, DataSourceParams, DataSourceTag} from './DataSource';\nimport type {Normalizer} from './Normalizer';\n\nexport interface DataManager {\n normalizer?: Normalizer;\n\n optimisticUpdate(mutationData: Data): void;\n\n invalidateData(data: Data): void;\n\n invalidateTag(tag: DataSourceTag, invalidateOptions?: InvalidateOptions): Promise<void>;\n\n invalidateTags(tags: DataSourceTag[], invalidateOptions?: InvalidateOptions): Promise<void>;\n\n invalidateSource<TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n invalidateOptions?: InvalidateOptions,\n ): Promise<void>;\n\n resetSource<TDataSource extends AnyDataSource>(dataSource: TDataSource): Promise<void>;\n\n invalidateParams<TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n invalidateOptions?: InvalidateOptions,\n ): Promise<void>;\n\n resetParams<TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n ): Promise<void>;\n\n invalidateSourceTags<TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n invalidateOptions?: InvalidateOptions,\n ): Promise<void>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { NormalizerConfig as NormalizeConfigBase } from '@normy/core';
|
|
2
|
+
import type { Data, NormalizedData } from '@normy/core/types/types';
|
|
3
|
+
export interface OptimisticConfig {
|
|
4
|
+
/** Automatically calculate rollback data, defaults to true */
|
|
5
|
+
autoCalculateRollback?: boolean;
|
|
6
|
+
/** Whether debug logging is enabled */
|
|
7
|
+
devLogging?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface NormalizerConfig extends NormalizeConfigBase {
|
|
10
|
+
initialData?: NormalizedData;
|
|
11
|
+
optimistic?: boolean | OptimisticConfig;
|
|
12
|
+
invalidate?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface Normalizer {
|
|
15
|
+
getNormalizedData: () => NormalizedData;
|
|
16
|
+
clearNormalizedData: () => void;
|
|
17
|
+
setQuery: (queryKey: string, queryData: Data) => void;
|
|
18
|
+
removeQuery: (queryKey: string) => void;
|
|
19
|
+
getQueriesToUpdate: (mutationData: Data) => {
|
|
20
|
+
queryKey: string;
|
|
21
|
+
data: Data;
|
|
22
|
+
}[];
|
|
23
|
+
getObjectById: <T extends Data>(id: string, exampleObject?: T) => T | undefined;
|
|
24
|
+
getQueryFragment: <T extends Data>(fragment: Data, exampleObject?: T) => T | undefined;
|
|
25
|
+
getDependentQueries: (mutationData: Data) => readonly string[];
|
|
26
|
+
getDependentQueriesByIds: (ids: ReadonlyArray<string>) => readonly string[];
|
|
27
|
+
getCurrentData: <T extends Data>(newData: T) => T | undefined;
|
|
28
|
+
log: (...messages: unknown[]) => void;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["Normalizer.ts"],"sourcesContent":["import type {NormalizerConfig as NormalizeConfigBase} from '@normy/core';\nimport type {Data, NormalizedData} from '@normy/core/types/types';\n\nexport interface OptimisticConfig {\n /** Automatically calculate rollback data, defaults to true */\n autoCalculateRollback?: boolean;\n /** Whether debug logging is enabled */\n devLogging?: boolean;\n}\n\nexport interface NormalizerConfig extends NormalizeConfigBase {\n initialData?: NormalizedData;\n optimistic?: boolean | OptimisticConfig;\n invalidate?: boolean;\n}\n\nexport interface Normalizer {\n getNormalizedData: () => NormalizedData;\n clearNormalizedData: () => void;\n setQuery: (queryKey: string, queryData: Data) => void;\n removeQuery: (queryKey: string) => void;\n getQueriesToUpdate: (mutationData: Data) => {\n queryKey: string;\n data: Data;\n }[];\n getObjectById: <T extends Data>(id: string, exampleObject?: T) => T | undefined;\n getQueryFragment: <T extends Data>(fragment: Data, exampleObject?: T) => T | undefined;\n getDependentQueries: (mutationData: Data) => readonly string[];\n getDependentQueriesByIds: (ids: ReadonlyArray<string>) => readonly string[];\n getCurrentData: <T extends Data>(newData: T) => T | undefined;\n log: (...messages: unknown[]) => void;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DataManagerContext } from './DataManagerContext';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
export var DataManagerProvider = function DataManagerProvider(_ref) {
|
|
5
|
+
var children = _ref.children,
|
|
6
|
+
dataManager = _ref.dataManager;
|
|
7
|
+
return /*#__PURE__*/_jsx(DataManagerContext.Provider, {
|
|
8
|
+
value: dataManager,
|
|
9
|
+
children: children
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
// #sourceMappingURL=DataManagerProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","DataManagerContext","jsx","_jsx","DataManagerProvider","_ref","children","dataManager","Provider","value"],"sources":["DataManagerProvider.tsx"],"sourcesContent":["import React from 'react';\n\nimport type {DataManager} from '../core';\n\nimport {DataManagerContext} from './DataManagerContext';\n\nexport interface DataManagerProviderProps {\n children: React.ReactNode;\n dataManager: DataManager;\n}\n\nexport const DataManagerProvider: React.FC<DataManagerProviderProps> = ({\n children,\n dataManager,\n}) => {\n return (\n <DataManagerContext.Provider value={dataManager}>{children}</DataManagerContext.Provider>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAIzB,SAAQC,kBAAkB,QAAO,sBAAsB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAOxD,OAAO,IAAMC,mBAAuD,GAAG,SAA1DA,mBAAuDA,CAAAC,IAAA,EAG9D;EAAA,IAFFC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;IACRC,WAAW,GAAAF,IAAA,CAAXE,WAAW;EAEX,oBACIJ,IAAA,CAACF,kBAAkB,CAACO,QAAQ;IAACC,KAAK,EAAEF,WAAY;IAAAD,QAAA,EAAEA;EAAQ,CAA8B,CAAC;AAEjG,CAAC","ignoreList":[]}
|
|
@@ -5,6 +5,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
5
5
|
describe('useDataManager', function () {
|
|
6
6
|
it('should return dataManager from context', function () {
|
|
7
7
|
var mockDataManager = {
|
|
8
|
+
normalizer: undefined,
|
|
9
|
+
optimisticUpdate: jest.fn(),
|
|
10
|
+
invalidateData: jest.fn(),
|
|
8
11
|
invalidateTag: jest.fn(),
|
|
9
12
|
invalidateTags: jest.fn(),
|
|
10
13
|
invalidateSource: jest.fn(),
|
|
@@ -29,15 +32,13 @@ describe('useDataManager', function () {
|
|
|
29
32
|
expect(result.current).toBe(mockDataManager);
|
|
30
33
|
});
|
|
31
34
|
it('should throw an error when dataManager is not provided', function () {
|
|
32
|
-
|
|
35
|
+
var consoleSpy = jest.spyOn(console, 'error').mockImplementation();
|
|
36
|
+
expect(function () {
|
|
33
37
|
renderHook(function () {
|
|
34
38
|
return useDataManager();
|
|
35
39
|
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Just to be sure that the error is from the right place
|
|
39
|
-
expect(error.message).toBe('DataManager is not provided by context. Use DataManagerContext.Provider to do it');
|
|
40
|
-
}
|
|
40
|
+
}).toThrow('DataManager is not provided by context. Use DataManagerContext.Provider to do it');
|
|
41
|
+
consoleSpy.mockRestore();
|
|
41
42
|
});
|
|
42
43
|
});
|
|
43
44
|
// #sourceMappingURL=DataManagerContext.test.js.map
|