@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,9 +1,10 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
var _excluded = ["queryFn", "refetchInterval"];
|
|
4
|
-
import { useQuery } from '@tanstack/react-query';
|
|
4
|
+
import { skipToken, useQuery } from '@tanstack/react-query';
|
|
5
5
|
import { useRefetchInterval } from '../../hooks/useRefetchInterval';
|
|
6
6
|
import { normalizeStatus } from '../../utils/normalizeStatus';
|
|
7
|
+
import { warnDisabledRefetch } from '../../utils/warnDisabledRefetch';
|
|
7
8
|
import { composeOptions } from './utils';
|
|
8
9
|
var usePlainQueryDataOptions = function usePlainQueryDataOptions(composedOptions) {
|
|
9
10
|
var queryFnOption = composedOptions.queryFn,
|
|
@@ -21,9 +22,11 @@ export var usePlainQueryData = function usePlainQueryData(context, dataSource, p
|
|
|
21
22
|
var extendedOptions = composeOptions(context, dataSource, params, options);
|
|
22
23
|
var composedOptions = usePlainQueryDataOptions(extendedOptions);
|
|
23
24
|
var state = useQuery(composedOptions);
|
|
25
|
+
var isDisabled = composedOptions.enabled === false || composedOptions.queryFn === skipToken;
|
|
24
26
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
25
27
|
status: normalizeStatus(state.status, state.fetchStatus),
|
|
26
|
-
originalStatus: state.status
|
|
28
|
+
originalStatus: state.status,
|
|
29
|
+
refetch: isDisabled ? warnDisabledRefetch : state.refetch
|
|
27
30
|
});
|
|
28
31
|
};
|
|
29
32
|
// #sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useQuery","useRefetchInterval","normalizeStatus","composeOptions","usePlainQueryDataOptions","composedOptions","queryFnOption","queryFn","refetchIntervalOption","refetchInterval","restOptions","_objectWithoutProperties","_excluded","_useRefetchInterval","_objectSpread","usePlainQueryData","context","dataSource","params","options","extendedOptions","state","status","fetchStatus","originalStatus"],"sources":["hooks.ts"],"sourcesContent":["import {type QueryObserverOptions, useQuery} from '@tanstack/react-query';\n\nimport type {\n DataSourceContext,\n DataSourceData,\n DataSourceError,\n DataSourceKey,\n DataSourceOptions,\n DataSourceParams,\n DataSourceResponse,\n DataSourceState,\n} from '../../../core';\nimport {useRefetchInterval} from '../../hooks/useRefetchInterval';\nimport {normalizeStatus} from '../../utils/normalizeStatus';\n\nimport type {AnyPlainQueryDataSource, QueryObserverExtendedOptions} from './types';\nimport {composeOptions} from './utils';\n\nconst usePlainQueryDataOptions = <TDataSource extends AnyPlainQueryDataSource>(\n composedOptions: QueryObserverExtendedOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n DataSourceData<TDataSource>,\n DataSourceResponse<TDataSource>,\n DataSourceKey\n >,\n): QueryObserverOptions<\n DataSourceResponse<TDataSource>,\n DataSourceError<TDataSource>,\n DataSourceData<TDataSource>,\n DataSourceResponse<TDataSource>,\n DataSourceKey\n> => {\n const {\n queryFn: queryFnOption,\n refetchInterval: refetchIntervalOption,\n ...restOptions\n } = composedOptions;\n\n const {queryFn, refetchInterval} = useRefetchInterval(refetchIntervalOption, queryFnOption);\n\n return {...restOptions, queryFn, refetchInterval};\n};\n\nexport const usePlainQueryData = <TDataSource extends AnyPlainQueryDataSource>(\n context: DataSourceContext<TDataSource>,\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n options?: Partial<DataSourceOptions<TDataSource>>,\n): DataSourceState<TDataSource> => {\n const extendedOptions = composeOptions(context, dataSource, params, options);\n const composedOptions = usePlainQueryDataOptions(extendedOptions);\n const state = useQuery(composedOptions);\n\n return {\n ...state,\n status: normalizeStatus(state.status, state.fetchStatus),\n originalStatus: state.status,\n } as DataSourceState<TDataSource>;\n};\n"],"mappings":";;;AAAA,SAAmCA,QAAQ,QAAO,uBAAuB;
|
|
1
|
+
{"version":3,"names":["skipToken","useQuery","useRefetchInterval","normalizeStatus","warnDisabledRefetch","composeOptions","usePlainQueryDataOptions","composedOptions","queryFnOption","queryFn","refetchIntervalOption","refetchInterval","restOptions","_objectWithoutProperties","_excluded","_useRefetchInterval","_objectSpread","usePlainQueryData","context","dataSource","params","options","extendedOptions","state","isDisabled","enabled","status","fetchStatus","originalStatus","refetch"],"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,SAAmCA,SAAS,EAAEC,QAAQ,QAAO,uBAAuB;AAYpF,SAAQC,kBAAkB,QAAO,gCAAgC;AACjE,SAAQC,eAAe,QAAO,6BAA6B;AAC3D,SAAQC,mBAAmB,QAAO,iCAAiC;AAGnE,SAAQC,cAAc,QAAO,SAAS;AAEtC,IAAMC,wBAAwB,GAAG,SAA3BA,wBAAwBA,CAC1BC,eAMC,EAOA;EACD,IACaC,aAAa,GAGtBD,eAAe,CAHfE,OAAO;IACUC,qBAAqB,GAEtCH,eAAe,CAFfI,eAAe;IACZC,WAAW,GAAAC,wBAAA,CACdN,eAAe,EAAAO,SAAA;EAEnB,IAAAC,mBAAA,GAAmCb,kBAAkB,CAACQ,qBAAqB,EAAEF,aAAa,CAAC;IAApFC,OAAO,GAAAM,mBAAA,CAAPN,OAAO;IAAEE,eAAe,GAAAI,mBAAA,CAAfJ,eAAe;EAE/B,OAAAK,aAAA,CAAAA,aAAA,KAAWJ,WAAW;IAAEH,OAAO,EAAPA,OAAO;IAAEE,eAAe,EAAfA;EAAe;AACpD,CAAC;AAED,OAAO,IAAMM,iBAAiB,GAAG,SAApBA,iBAAiBA,CAC1BC,OAAuC,EACvCC,UAAuB,EACvBC,MAAqC,EACrCC,OAAiD,EAClB;EAC/B,IAAMC,eAAe,GAAGjB,cAAc,CAACa,OAAO,EAAEC,UAAU,EAAEC,MAAM,EAAEC,OAAO,CAAC;EAC5E,IAAMd,eAAe,GAAGD,wBAAwB,CAACgB,eAAe,CAAC;EACjE,IAAMC,KAAK,GAAGtB,QAAQ,CAACM,eAAe,CAAC;EAEvC,IAAMiB,UAAU,GAAGjB,eAAe,CAACkB,OAAO,KAAK,KAAK,IAAIlB,eAAe,CAACE,OAAO,KAAKT,SAAS;EAE7F,OAAAgB,aAAA,CAAAA,aAAA,KACOO,KAAK;IACRG,MAAM,EAAEvB,eAAe,CAACoB,KAAK,CAACG,MAAM,EAAEH,KAAK,CAACI,WAAW,CAAC;IACxDC,cAAc,EAAEL,KAAK,CAACG,MAAM;IAC5BG,OAAO,EAAEL,UAAU,GAAGpB,mBAAmB,GAAGmB,KAAK,CAACM;EAAO;AAEjE,CAAC","ignoreList":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { DefaultError, QueryFunctionContext, QueryKey, QueryObserverOptions, QueryObserverResult } 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';
|
|
@@ -10,4 +10,5 @@ export { composeOptions as composePlainQueryOptions } from './impl/plain/utils';
|
|
|
10
10
|
export { normalizeStatus } from './utils/normalizeStatus';
|
|
11
11
|
export { getProgressiveRefetch } from './utils/getProgressiveRefetch';
|
|
12
12
|
export { ClientDataManager } from './ClientDataManager';
|
|
13
|
+
export { DataSourceProvider } from './DataSourceProvider';
|
|
13
14
|
// #sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useQueryContext","useQueryData","useQueryResponses","useRefetchAll","useRefetchErrored","makeInfiniteQueryDataSource","composeOptions","composeInfiniteQueryOptions","makePlainQueryDataSource","composePlainQueryOptions","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":"AAGA,SAAQA,eAAe,QAAO,yBAAyB;AACvD,SAAQC,YAAY,QAAO,sBAAsB;AACjD,SAAQC,iBAAiB,QAAO,2BAA2B;AAC3D,SAAQC,aAAa,QAAO,uBAAuB;AACnD,SAAQC,iBAAiB,QAAO,2BAA2B;AAG3D,SAAQC,2BAA2B,QAAO,yBAAyB;AACnE,SAAQC,cAAc,IAAIC,2BAA2B,QAAO,uBAAuB;AAGnF,SAAQC,wBAAwB,QAAO,sBAAsB;AAC7D,SAAQF,cAAc,IAAIG,wBAAwB,QAAO,oBAAoB;AAE7E,SAAQC,eAAe,QAAO,yBAAyB;AAEvD,SAAQC,qBAAqB,QAAO,+BAA+B;AAGnE,SAAQC,iBAAiB,QAAO,qBAAqB","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["useQueryContext","useQueryData","useQueryResponses","useRefetchAll","useRefetchErrored","makeInfiniteQueryDataSource","composeOptions","composeInfiniteQueryOptions","makePlainQueryDataSource","composePlainQueryOptions","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,SAAQA,eAAe,QAAO,yBAAyB;AACvD,SAAQC,YAAY,QAAO,sBAAsB;AACjD,SAAQC,iBAAiB,QAAO,2BAA2B;AAC3D,SAAQC,aAAa,QAAO,uBAAuB;AACnD,SAAQC,iBAAiB,QAAO,2BAA2B;AAG3D,SAAQC,2BAA2B,QAAO,yBAAyB;AACnE,SAAQC,cAAc,IAAIC,2BAA2B,QAAO,uBAAuB;AAGnF,SAAQC,wBAAwB,QAAO,sBAAsB;AAC7D,SAAQF,cAAc,IAAIG,wBAAwB,QAAO,oBAAoB;AAE7E,SAAQC,eAAe,QAAO,yBAAyB;AAEvD,SAAQC,qBAAqB,QAAO,+BAA+B;AAGnE,SAAQC,iBAAiB,QAAO,qBAAqB;AAErD,SAAQC,kBAAkB,QAAO,sBAAsB","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,143 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
|
+
var shouldInvalidateData = function shouldInvalidateData(globalConfig, mutationConfig) {
|
|
3
|
+
if (mutationConfig === false) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
if (!globalConfig) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
return true;
|
|
10
|
+
};
|
|
11
|
+
var shouldUpdateOptimistically = function shouldUpdateOptimistically(globalConfig, mutationConfig) {
|
|
12
|
+
if (mutationConfig === false) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
if (typeof mutationConfig === 'boolean' && mutationConfig || _typeof(mutationConfig) === 'object' && mutationConfig) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
if (!globalConfig) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
var getOptimisticProps = function getOptimisticProps(globalConfig, mutationConfig) {
|
|
24
|
+
var globalAutoRollback = _typeof(globalConfig) === 'object' ? globalConfig.autoCalculateRollback : undefined;
|
|
25
|
+
var mutationAutoRollback = _typeof(mutationConfig) === 'object' ? mutationConfig.autoCalculateRollback : undefined;
|
|
26
|
+
var globalDevLogging = _typeof(globalConfig) === 'object' ? globalConfig.devLogging : undefined;
|
|
27
|
+
var mutationDevLogging = _typeof(mutationConfig) === 'object' ? mutationConfig.devLogging : undefined;
|
|
28
|
+
return {
|
|
29
|
+
autoRollback: mutationAutoRollback !== null && mutationAutoRollback !== void 0 ? mutationAutoRollback : globalAutoRollback,
|
|
30
|
+
devLogging: mutationDevLogging !== null && mutationDevLogging !== void 0 ? mutationDevLogging : globalDevLogging
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export var createQueryNormalizer = function createQueryNormalizer(normalizer, queryClient, config, optimisticUpdate, invalidateData) {
|
|
34
|
+
if (!normalizer || !config) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
var globalOptimistic = _typeof(config) === 'object' && 'optimistic' in config ? config.optimistic : false;
|
|
38
|
+
var globalInvalidateData = _typeof(config) === 'object' && 'invalidate' in config ? config.invalidate : false;
|
|
39
|
+
var unsubscribeQueryCache = null;
|
|
40
|
+
var unsubscribeMutationCache = null;
|
|
41
|
+
return {
|
|
42
|
+
/** Get normalized data */
|
|
43
|
+
getNormalizedData: normalizer.getNormalizedData,
|
|
44
|
+
/** Set normalized data (for manual updates, WebSocket, etc.) */
|
|
45
|
+
setNormalizedData: function setNormalizedData(data) {
|
|
46
|
+
return optimisticUpdate(data);
|
|
47
|
+
},
|
|
48
|
+
/** Clear all normalized data */
|
|
49
|
+
clear: normalizer.clearNormalizedData,
|
|
50
|
+
/** Get object by ID */
|
|
51
|
+
getObjectById: normalizer.getObjectById,
|
|
52
|
+
/** Get query fragment */
|
|
53
|
+
getQueryFragment: normalizer.getQueryFragment,
|
|
54
|
+
/** Get dependent queries by data */
|
|
55
|
+
getDependentQueries: function getDependentQueries(mutationData) {
|
|
56
|
+
return normalizer.getDependentQueries(mutationData).map(function (key) {
|
|
57
|
+
return JSON.parse(key);
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
/** Get dependent queries by IDs */
|
|
61
|
+
getDependentQueriesByIds: function getDependentQueriesByIds(ids) {
|
|
62
|
+
return normalizer.getDependentQueriesByIds(ids).map(function (key) {
|
|
63
|
+
return JSON.parse(key);
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
/** Subscribe to QueryCache changes */
|
|
67
|
+
subscribe: function subscribe() {
|
|
68
|
+
// Subscribe to QueryCache (query additions/updates/removals)
|
|
69
|
+
unsubscribeQueryCache = queryClient.getQueryCache().subscribe(function (event) {
|
|
70
|
+
var _queryOptions$normali;
|
|
71
|
+
var queryKeyStr = JSON.stringify(event.query.queryKey);
|
|
72
|
+
if (event.type === 'removed') {
|
|
73
|
+
normalizer.removeQuery(queryKeyStr);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Check if the query should be normalized
|
|
78
|
+
// At this point options are already merged (DataSource + Hook)
|
|
79
|
+
var queryOptions = event.query.options;
|
|
80
|
+
var queryNormalize = (_queryOptions$normali = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.normalize) !== null && _queryOptions$normali !== void 0 ? _queryOptions$normali : true;
|
|
81
|
+
if (!queryNormalize) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (event.type === 'added' && event.query.state.data !== undefined) {
|
|
85
|
+
normalizer.setQuery(queryKeyStr, event.query.state.data);
|
|
86
|
+
} else if (event.type === 'updated' && event.action.type === 'success' && event.action.data !== undefined) {
|
|
87
|
+
normalizer.setQuery(queryKeyStr, event.action.data);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Subscribe to MutationCache for normalization + optimistic updates
|
|
92
|
+
unsubscribeMutationCache = queryClient.getMutationCache().subscribe(function (event) {
|
|
93
|
+
var _event$mutation;
|
|
94
|
+
// Cast to extended type with additional configs, if available
|
|
95
|
+
var mutationOptions = (_event$mutation = event.mutation) === null || _event$mutation === void 0 ? void 0 : _event$mutation.options;
|
|
96
|
+
var mutationQueryNormalize = mutationOptions === null || mutationOptions === void 0 ? void 0 : mutationOptions.normalize;
|
|
97
|
+
var mutationQueryOptimistic = mutationOptions === null || mutationOptions === void 0 ? void 0 : mutationOptions.optimistic;
|
|
98
|
+
var mutationQueryInvalidateData = mutationOptions === null || mutationOptions === void 0 ? void 0 : mutationOptions.invalidate;
|
|
99
|
+
if (shouldInvalidateData(globalInvalidateData, mutationQueryInvalidateData)) {
|
|
100
|
+
if (event.type === 'updated' && event.action.type === 'success' && event.action.data) {
|
|
101
|
+
invalidateData(event.action.data);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (!mutationQueryNormalize || !shouldUpdateOptimistically(globalOptimistic, mutationQueryOptimistic)) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
var _getOptimisticProps = getOptimisticProps(globalOptimistic, mutationQueryOptimistic),
|
|
108
|
+
autoRollback = _getOptimisticProps.autoRollback,
|
|
109
|
+
devLogging = _getOptimisticProps.devLogging;
|
|
110
|
+
if (event.type === 'updated' && event.action.type === 'success' && event.action.data) {
|
|
111
|
+
optimisticUpdate(event.action.data);
|
|
112
|
+
} else if (event.type === 'updated' && event.action.type === 'pending') {
|
|
113
|
+
var context = event.mutation.state.context;
|
|
114
|
+
if (context !== null && context !== void 0 && context.optimisticData) {
|
|
115
|
+
if (!context.rollbackData && mutationQueryOptimistic && autoRollback !== false) {
|
|
116
|
+
context.rollbackData = normalizer.getCurrentData(context.optimisticData);
|
|
117
|
+
if (devLogging) {
|
|
118
|
+
console.log('[OptimisticUpdate] Auto-calculated rollbackData:', context.rollbackData);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
optimisticUpdate(context.optimisticData);
|
|
122
|
+
}
|
|
123
|
+
} else if (event.type === 'updated' && event.action.type === 'error') {
|
|
124
|
+
var _context = event.mutation.state.context;
|
|
125
|
+
if (_context !== null && _context !== void 0 && _context.rollbackData) {
|
|
126
|
+
if (devLogging) {
|
|
127
|
+
console.log('[OptimisticUpdate] Rolling back changes');
|
|
128
|
+
}
|
|
129
|
+
optimisticUpdate(_context.rollbackData);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
unsubscribe: function unsubscribe() {
|
|
135
|
+
var _unsubscribeQueryCach, _unsubscribeMutationC;
|
|
136
|
+
(_unsubscribeQueryCach = unsubscribeQueryCache) === null || _unsubscribeQueryCach === void 0 || _unsubscribeQueryCach();
|
|
137
|
+
(_unsubscribeMutationC = unsubscribeMutationCache) === null || _unsubscribeMutationC === void 0 || _unsubscribeMutationC();
|
|
138
|
+
unsubscribeQueryCache = null;
|
|
139
|
+
unsubscribeMutationCache = null;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
// #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","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","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,IACrDE,OAAA,CAAOF,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,GACpBF,OAAA,CAAOH,YAAY,MAAK,QAAQ,GAAGA,YAAY,CAACM,qBAAqB,GAAGC,SAAS;EACrF,IAAMC,oBAAoB,GACtBL,OAAA,CAAOF,cAAc,MAAK,QAAQ,GAAGA,cAAc,CAACK,qBAAqB,GAAGC,SAAS;EACzF,IAAME,gBAAgB,GAAGN,OAAA,CAAOH,YAAY,MAAK,QAAQ,GAAGA,YAAY,CAACU,UAAU,GAAGH,SAAS;EAC/F,IAAM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MACf,CAAAD,qBAAA,GAAAjD,qBAAqB,cAAAiD,qBAAA,eAArBA,qBAAA,CAAwB,CAAC;MACzB,CAAAC,qBAAA,GAAAjD,wBAAwB,cAAAiD,qBAAA,eAAxBA,qBAAA,CAA2B,CAAC;MAC5BlD,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 @@
|
|
|
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":"AAAA,OAAO,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 @@
|
|
|
1
|
+
{"version":3,"names":["warn","warnDisabledRefetch"],"sources":["warnDisabledRefetch.ts"],"sourcesContent":["import {warn} from './warn';\n\nexport const warnDisabledRefetch = () => {\n warn('Disabled refetch is called');\n};\n"],"mappings":"AAAA,SAAQA,IAAI,QAAO,QAAQ;AAE3B,OAAO,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAmBA,CAAA,EAAS;EACrCD,IAAI,CAAC,4BAA4B,CAAC;AACtC,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/data-source",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "A wrapper around data fetching",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-fetching",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"typecheck": "tsc --noEmit"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
+
"@normy/core": "^0.14.0",
|
|
46
47
|
"utility-types": "^3.11.0"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|