react-redux-cache 0.19.2 → 0.19.4-rc.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 +25 -7
- package/dist/cjs/createActions.js +65 -0
- package/dist/cjs/createCache.js +208 -0
- package/dist/cjs/createCacheReducer.js +285 -0
- package/dist/cjs/createSelectors.js +68 -0
- package/dist/cjs/index.js +83 -0
- package/dist/cjs/mutate.js +161 -0
- package/dist/cjs/query.js +180 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/useMutation.js +82 -0
- package/dist/cjs/useQuery.js +121 -0
- package/dist/cjs/utilsAndConstants.js +189 -0
- package/dist/esm/createActions.js +61 -0
- package/dist/esm/createCache.js +203 -0
- package/dist/esm/createCacheReducer.js +271 -0
- package/dist/esm/createSelectors.js +64 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/mutate.js +157 -0
- package/dist/esm/query.js +169 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/useMutation.js +88 -0
- package/dist/esm/useQuery.js +125 -0
- package/dist/esm/utilsAndConstants.js +168 -0
- package/dist/types/createActions.d.ts +106 -0
- package/dist/types/createCache.d.ts +712 -0
- package/dist/types/createCacheReducer.d.ts +11 -0
- package/dist/types/createSelectors.d.ts +79 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/mutate.d.ts +94 -0
- package/dist/types/query.d.ts +122 -0
- package/dist/types/types.d.ts +322 -0
- package/dist/types/useMutation.d.ts +39 -0
- package/dist/types/useQuery.d.ts +40 -0
- package/dist/types/utilsAndConstants.d.ts +39 -0
- package/package.json +22 -10
- package/dist/createActions.d.ts +0 -83
- package/dist/createActions.js +0 -64
- package/dist/createCache.d.ts +0 -378
- package/dist/createCache.js +0 -185
- package/dist/createCacheReducer.d.ts +0 -3
- package/dist/createCacheReducer.js +0 -243
- package/dist/createSelectors.d.ts +0 -18
- package/dist/createSelectors.js +0 -61
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -53
- package/dist/mutate.d.ts +0 -4
- package/dist/mutate.js +0 -98
- package/dist/query.d.ts +0 -4
- package/dist/query.js +0 -107
- package/dist/types.d.ts +0 -187
- package/dist/types.js +0 -3
- package/dist/useMutation.d.ts +0 -4
- package/dist/useMutation.js +0 -61
- package/dist/useQuery.d.ts +0 -4
- package/dist/useQuery.js +0 -77
- package/dist/utilsAndConstants.d.ts +0 -20
- package/dist/utilsAndConstants.js +0 -161
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {Actions} from './createActions'
|
|
2
|
+
import {Selectors} from './createSelectors'
|
|
3
|
+
import {Cache, QueryOptions, QueryState, Typenames, UseQueryOptions} from './types'
|
|
4
|
+
|
|
5
|
+
export declare const useQuery: <
|
|
6
|
+
N extends string,
|
|
7
|
+
T extends Typenames,
|
|
8
|
+
QP,
|
|
9
|
+
QR,
|
|
10
|
+
MP,
|
|
11
|
+
MR,
|
|
12
|
+
QK extends keyof (QP & QR)
|
|
13
|
+
>(
|
|
14
|
+
cache: Cache<N, T, QP, QR, MP, MR>,
|
|
15
|
+
actions: Actions<N, T, QP, QR, MP, MR>,
|
|
16
|
+
selectors: Selectors<N, T, QP, QR, MP, MR>,
|
|
17
|
+
options: UseQueryOptions<N, T, QK, QP, QR, MP, MR>
|
|
18
|
+
) => readonly [
|
|
19
|
+
Omit<
|
|
20
|
+
QueryState<
|
|
21
|
+
T,
|
|
22
|
+
QK extends keyof QP & keyof QR ? QP[QK] : never,
|
|
23
|
+
QK extends keyof QP & keyof QR ? QR[QK] : never
|
|
24
|
+
>,
|
|
25
|
+
'expiresAt'
|
|
26
|
+
>,
|
|
27
|
+
(
|
|
28
|
+
options?: Partial<Pick<QueryOptions<N, T, QP, QR, QK, MP, MR>, 'params' | 'onlyIfExpired'>>
|
|
29
|
+
) => Promise<
|
|
30
|
+
import('./types').QueryResult<
|
|
31
|
+
QK extends infer T_1
|
|
32
|
+
? T_1 extends QK
|
|
33
|
+
? T_1 extends keyof QP & keyof QR
|
|
34
|
+
? QR[T_1]
|
|
35
|
+
: never
|
|
36
|
+
: never
|
|
37
|
+
: never
|
|
38
|
+
>
|
|
39
|
+
>
|
|
40
|
+
]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CacheOptions,
|
|
3
|
+
EntitiesMap,
|
|
4
|
+
EntityChanges,
|
|
5
|
+
Key,
|
|
6
|
+
QueryState,
|
|
7
|
+
QueryStateComparer,
|
|
8
|
+
Typenames,
|
|
9
|
+
} from './types'
|
|
10
|
+
|
|
11
|
+
export declare const PACKAGE_SHORT_NAME = 'rrc'
|
|
12
|
+
export declare const optionalUtils: {
|
|
13
|
+
deepEqual?: (a: any, b: any) => boolean
|
|
14
|
+
}
|
|
15
|
+
export declare const IS_DEV: boolean
|
|
16
|
+
export declare const EMPTY_OBJECT: Readonly<{}>
|
|
17
|
+
export declare const EMPTY_ARRAY: readonly never[]
|
|
18
|
+
export declare const NOOP: () => void
|
|
19
|
+
export declare const defaultGetCacheKey: <P = unknown>(params: P) => Key
|
|
20
|
+
export declare const log: (tag: string, data?: unknown) => void
|
|
21
|
+
export declare const FetchPolicy: {
|
|
22
|
+
/** Only if cache does not exist (result is undefined) or expired. */
|
|
23
|
+
NoCacheOrExpired: <T extends Typenames = Typenames, P = unknown, R = unknown>(
|
|
24
|
+
expired: boolean,
|
|
25
|
+
_params: P,
|
|
26
|
+
state: QueryState<T, P, R>
|
|
27
|
+
) => boolean
|
|
28
|
+
/** Every fetch trigger. */
|
|
29
|
+
Always: () => boolean
|
|
30
|
+
}
|
|
31
|
+
export declare const applyEntityChanges: <T extends Typenames>(
|
|
32
|
+
entities: EntitiesMap<T>,
|
|
33
|
+
changes: EntityChanges<T>,
|
|
34
|
+
options: CacheOptions
|
|
35
|
+
) => EntitiesMap<T> | undefined
|
|
36
|
+
export declare const isEmptyObject: (o: object) => boolean
|
|
37
|
+
export declare const createStateComparer: <T extends Typenames = Typenames, Q = unknown, P = unknown>(
|
|
38
|
+
fields: (keyof QueryState<T, Q, P>)[]
|
|
39
|
+
) => QueryStateComparer<T, Q, P>
|
package/package.json
CHANGED
|
@@ -2,16 +2,29 @@
|
|
|
2
2
|
"name": "react-redux-cache",
|
|
3
3
|
"author": "Alexander Danilov",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.19.
|
|
5
|
+
"version": "0.19.4-rc.0",
|
|
6
6
|
"description": "Powerful data fetching and caching library for Redux and Zustand that supports normalization.",
|
|
7
|
-
"main": "dist/index.js",
|
|
8
|
-
"
|
|
7
|
+
"main": "./dist/cjs/index.js",
|
|
8
|
+
"module": "./dist/esm/index.js",
|
|
9
|
+
"types": "./dist/types/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"require": "./dist/cjs/index.js",
|
|
13
|
+
"import": "./dist/esm/index.js",
|
|
14
|
+
"types": "./dist/types/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
9
17
|
"scripts": {
|
|
10
|
-
"example": "(cd example && yarn && yarn dev)",
|
|
18
|
+
"example": "(cd example && yarn --production && yarn dev)",
|
|
11
19
|
"clean": "rm -rf dist",
|
|
12
|
-
"lint": "yarn eslint
|
|
13
|
-
"lint-fix": "yarn eslint --fix
|
|
14
|
-
"
|
|
20
|
+
"lint": "yarn eslint",
|
|
21
|
+
"lint-fix": "yarn eslint --fix",
|
|
22
|
+
"lint-fix-dist": "yarn eslint --quiet --fix dist/ > /dev/null 2>&1 || true",
|
|
23
|
+
"build-cjs": "tsc -p tsconfig.cjs.json && rm -rf dist/cjs/testing && rm -rf dist/cjs/__tests__",
|
|
24
|
+
"build-esm": "tsc -p tsconfig.esm.json > /dev/null ; rm -rf dist/esm/testing && rm -rf dist/esm/__tests__",
|
|
25
|
+
"build-types": "tsc -p tsconfig.types.json > /dev/null ; rm -rf dist/types/testing && rm -rf dist/types/__tests__",
|
|
26
|
+
"build": "yarn clean && yarn lint && yarn build-cjs && yarn build-esm && yarn build-types && yarn size && yarn lint-fix-dist",
|
|
27
|
+
"size": "npx minified-size dist/esm/*.js | grep 'total:' | sed -E 's/.*total: [^,]*, ([^,]*), ([^,]*), ([^,]*).*/<br\\/>minified: \\1<br\\/>gzipped: \\2<br\\/>brotlied: \\3/'",
|
|
15
28
|
"test": "node node_modules/jest/bin/jest.js",
|
|
16
29
|
"preminor-rc": "yarn build && npm version preminor --preid rc",
|
|
17
30
|
"prepatch-rc": "yarn build && npm version prepatch --preid rc",
|
|
@@ -41,12 +54,14 @@
|
|
|
41
54
|
"@typescript-eslint/parser": "5.59.5",
|
|
42
55
|
"eslint": "8.40.0",
|
|
43
56
|
"eslint-config-prettier": "8.8.0",
|
|
57
|
+
"eslint-plugin-import": "2.32.0",
|
|
44
58
|
"eslint-plugin-prettier": "4.2.1",
|
|
45
59
|
"eslint-plugin-react": "7.33.2",
|
|
46
60
|
"eslint-plugin-react-hooks": "4.6.0",
|
|
47
61
|
"eslint-plugin-simple-import-sort": "10.0.0",
|
|
48
62
|
"jest": "29.5.0",
|
|
49
63
|
"jest-environment-jsdom": "29.7.0",
|
|
64
|
+
"minified-size": "4.0.0",
|
|
50
65
|
"prettier": "2.8.8",
|
|
51
66
|
"react": "18.2.0",
|
|
52
67
|
"react-dom": "18.2.0",
|
|
@@ -60,9 +75,6 @@
|
|
|
60
75
|
"files": [
|
|
61
76
|
"dist/*"
|
|
62
77
|
],
|
|
63
|
-
"exports": {
|
|
64
|
-
".": "./dist/index.js"
|
|
65
|
-
},
|
|
66
78
|
"keywords": [
|
|
67
79
|
"react",
|
|
68
80
|
"redux",
|
package/dist/createActions.d.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type { EntityChanges, Key, MutationState, QueryState, Typenames } from './types';
|
|
2
|
-
import { CacheState } from './types';
|
|
3
|
-
export type Actions<N extends string = string, T extends Typenames = Typenames, QP = unknown, QR = unknown, MP = unknown, MR = unknown> = ReturnType<typeof createActions<N, T, QP, QR, MP, MR>>;
|
|
4
|
-
export declare const createActions: <N extends string, T extends Typenames, QP, QR, MP, MR>(name: N) => {
|
|
5
|
-
updateQueryStateAndEntities: {
|
|
6
|
-
<K extends keyof (QP | QR)>(queryKey: K, queryCacheKey: Key, state?: Partial<QueryState<T, QP[K], QR[K]>>, entityChanges?: EntityChanges<T>): {
|
|
7
|
-
type: `@rrc/${N}/updateQueryStateAndEntities`;
|
|
8
|
-
queryKey: K;
|
|
9
|
-
queryCacheKey: Key;
|
|
10
|
-
state: Partial<QueryState<T, QP[K], QR[K]>> | undefined;
|
|
11
|
-
entityChanges: EntityChanges<T> | undefined;
|
|
12
|
-
};
|
|
13
|
-
type: `@rrc/${N}/updateQueryStateAndEntities`;
|
|
14
|
-
};
|
|
15
|
-
updateMutationStateAndEntities: {
|
|
16
|
-
<K extends keyof (MP | MR)>(mutationKey: K, state?: Partial<MutationState<T, MP[K], MR[K]>>, entityChanges?: EntityChanges<T>): {
|
|
17
|
-
type: `@rrc/${N}/updateMutationStateAndEntities`;
|
|
18
|
-
mutationKey: K;
|
|
19
|
-
state: Partial<MutationState<T, MP[K], MR[K]>> | undefined;
|
|
20
|
-
entityChanges: EntityChanges<T> | undefined;
|
|
21
|
-
};
|
|
22
|
-
type: `@rrc/${N}/updateMutationStateAndEntities`;
|
|
23
|
-
};
|
|
24
|
-
mergeEntityChanges: {
|
|
25
|
-
(changes: EntityChanges<T>): {
|
|
26
|
-
type: `@rrc/${N}/mergeEntityChanges`;
|
|
27
|
-
changes: EntityChanges<T>;
|
|
28
|
-
};
|
|
29
|
-
type: `@rrc/${N}/mergeEntityChanges`;
|
|
30
|
-
};
|
|
31
|
-
invalidateQuery: {
|
|
32
|
-
<K extends keyof (QP | QR)>(queries: {
|
|
33
|
-
/** Query key */
|
|
34
|
-
query: K;
|
|
35
|
-
/** Query cache key */
|
|
36
|
-
cacheKey?: Key;
|
|
37
|
-
/** Unix timestamp at which query expires. Is set to the query state. @Default Date.now() */
|
|
38
|
-
expiresAt?: number;
|
|
39
|
-
}[]): {
|
|
40
|
-
type: `@rrc/${N}/invalidateQuery`;
|
|
41
|
-
queries: {
|
|
42
|
-
/** Query key */
|
|
43
|
-
query: K;
|
|
44
|
-
/** Query cache key */
|
|
45
|
-
cacheKey?: Key;
|
|
46
|
-
/** Unix timestamp at which query expires. Is set to the query state. @Default Date.now() */
|
|
47
|
-
expiresAt?: number;
|
|
48
|
-
}[];
|
|
49
|
-
};
|
|
50
|
-
type: `@rrc/${N}/invalidateQuery`;
|
|
51
|
-
};
|
|
52
|
-
clearQueryState: {
|
|
53
|
-
<K extends keyof (QP | QR)>(queries: {
|
|
54
|
-
/** Query key */
|
|
55
|
-
query: K;
|
|
56
|
-
/** Query cache key */
|
|
57
|
-
cacheKey?: Key;
|
|
58
|
-
}[]): {
|
|
59
|
-
type: `@rrc/${N}/clearQueryState`;
|
|
60
|
-
queries: {
|
|
61
|
-
/** Query key */
|
|
62
|
-
query: K;
|
|
63
|
-
/** Query cache key */
|
|
64
|
-
cacheKey?: Key;
|
|
65
|
-
}[];
|
|
66
|
-
};
|
|
67
|
-
type: `@rrc/${N}/clearQueryState`;
|
|
68
|
-
};
|
|
69
|
-
clearMutationState: {
|
|
70
|
-
<K extends keyof (MP | MR)>(mutationKeys: K[]): {
|
|
71
|
-
type: `@rrc/${N}/clearMutationState`;
|
|
72
|
-
mutationKeys: K[];
|
|
73
|
-
};
|
|
74
|
-
type: `@rrc/${N}/clearMutationState`;
|
|
75
|
-
};
|
|
76
|
-
clearCache: {
|
|
77
|
-
(stateToKeep?: Partial<CacheState<T, QP, QR, MP, MR>>): {
|
|
78
|
-
type: `@rrc/${N}/clearCache`;
|
|
79
|
-
stateToKeep: Partial<CacheState<T, QP, QR, MP, MR>> | undefined;
|
|
80
|
-
};
|
|
81
|
-
type: `@rrc/${N}/clearCache`;
|
|
82
|
-
};
|
|
83
|
-
};
|
package/dist/createActions.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createActions = void 0;
|
|
4
|
-
const utilsAndConstants_1 = require("./utilsAndConstants");
|
|
5
|
-
const createActions = (name) => {
|
|
6
|
-
const actionPrefix = `@${utilsAndConstants_1.PACKAGE_SHORT_NAME}/${name}/`;
|
|
7
|
-
const updateQueryStateAndEntitiesType = `${actionPrefix}updateQueryStateAndEntities`;
|
|
8
|
-
const updateQueryStateAndEntities = (queryKey, queryCacheKey, state, entityChanges) => ({
|
|
9
|
-
type: updateQueryStateAndEntitiesType,
|
|
10
|
-
queryKey,
|
|
11
|
-
queryCacheKey,
|
|
12
|
-
state,
|
|
13
|
-
entityChanges,
|
|
14
|
-
});
|
|
15
|
-
updateQueryStateAndEntities.type = updateQueryStateAndEntitiesType;
|
|
16
|
-
const updateMutationStateAndEntitiesType = `${actionPrefix}updateMutationStateAndEntities`;
|
|
17
|
-
const updateMutationStateAndEntities = (mutationKey, state, entityChanges) => ({
|
|
18
|
-
type: updateMutationStateAndEntitiesType,
|
|
19
|
-
mutationKey,
|
|
20
|
-
state,
|
|
21
|
-
entityChanges,
|
|
22
|
-
});
|
|
23
|
-
updateMutationStateAndEntities.type = updateMutationStateAndEntitiesType;
|
|
24
|
-
const mergeEntityChangesType = `${actionPrefix}mergeEntityChanges`;
|
|
25
|
-
const mergeEntityChanges = (changes) => ({
|
|
26
|
-
type: mergeEntityChangesType,
|
|
27
|
-
changes,
|
|
28
|
-
});
|
|
29
|
-
mergeEntityChanges.type = mergeEntityChangesType;
|
|
30
|
-
const invalidateQueryType = `${actionPrefix}invalidateQuery`;
|
|
31
|
-
const invalidateQuery = (queries) => ({
|
|
32
|
-
type: invalidateQueryType,
|
|
33
|
-
queries,
|
|
34
|
-
});
|
|
35
|
-
invalidateQuery.type = invalidateQueryType;
|
|
36
|
-
const clearQueryStateType = `${actionPrefix}clearQueryState`;
|
|
37
|
-
const clearQueryState = (queries) => ({
|
|
38
|
-
type: clearQueryStateType,
|
|
39
|
-
queries,
|
|
40
|
-
});
|
|
41
|
-
clearQueryState.type = clearQueryStateType;
|
|
42
|
-
const clearMutationStateType = `${actionPrefix}clearMutationState`;
|
|
43
|
-
const clearMutationState = (mutationKeys) => ({
|
|
44
|
-
type: clearMutationStateType,
|
|
45
|
-
mutationKeys,
|
|
46
|
-
});
|
|
47
|
-
clearMutationState.type = clearMutationStateType;
|
|
48
|
-
const clearCacheType = `${actionPrefix}clearCache`;
|
|
49
|
-
const clearCache = (stateToKeep) => ({
|
|
50
|
-
type: clearCacheType,
|
|
51
|
-
stateToKeep,
|
|
52
|
-
});
|
|
53
|
-
clearCache.type = clearCacheType;
|
|
54
|
-
return {
|
|
55
|
-
updateQueryStateAndEntities,
|
|
56
|
-
updateMutationStateAndEntities,
|
|
57
|
-
mergeEntityChanges,
|
|
58
|
-
invalidateQuery,
|
|
59
|
-
clearQueryState,
|
|
60
|
-
clearMutationState,
|
|
61
|
-
clearCache,
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
exports.createActions = createActions;
|