react-redux-cache 0.0.4 → 0.0.5

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.
@@ -5,7 +5,7 @@ import { useQuery } from './useQuery';
5
5
  /**
6
6
  * Creates reducer, actions and hooks for managing queries and mutations through redux cache.
7
7
  */
8
- export declare const createCache: <T extends Typenames, QP, QR, MP, MR>(cache: OptionalPartial<Cache<T, QP, QR, MP, MR>, "options">) => {
8
+ export declare const createCache: <T extends Typenames, QP, QR, MP, MR>(cache: OptionalPartial<Cache<T, QP, QR, MP, MR>, "queries" | "mutations" | "options">) => {
9
9
  cache: Cache<T, QP, QR, MP, MR>;
10
10
  /** Reducer of the cache, should be added to redux store. */
11
11
  reducer: (state: {
@@ -10,15 +10,17 @@ const utilsAndConstants_1 = require("./utilsAndConstants");
10
10
  * Creates reducer, actions and hooks for managing queries and mutations through redux cache.
11
11
  */
12
12
  const createCache = (cache) => {
13
- var _a, _b, _c, _d;
14
- var _e, _f, _g;
13
+ var _a, _b, _c, _d, _e, _f;
14
+ var _g, _h, _j;
15
15
  // @ts-expect-error hot
16
16
  const hotReloadEnabled = Boolean(module === null || module === void 0 ? void 0 : module.hot);
17
17
  // provide all optional fields
18
18
  (_a = cache.options) !== null && _a !== void 0 ? _a : (cache.options = {});
19
- (_b = (_e = cache.options).logsEnabled) !== null && _b !== void 0 ? _b : (_e.logsEnabled = false);
20
- (_c = (_f = cache.options).validateFunctionArguments) !== null && _c !== void 0 ? _c : (_f.validateFunctionArguments = utilsAndConstants_1.isDev);
21
- (_d = (_g = cache.options).validateHookArguments) !== null && _d !== void 0 ? _d : (_g.validateHookArguments = utilsAndConstants_1.isDev && !hotReloadEnabled);
19
+ (_b = (_g = cache.options).logsEnabled) !== null && _b !== void 0 ? _b : (_g.logsEnabled = false);
20
+ (_c = (_h = cache.options).validateFunctionArguments) !== null && _c !== void 0 ? _c : (_h.validateFunctionArguments = utilsAndConstants_1.isDev);
21
+ (_d = (_j = cache.options).validateHookArguments) !== null && _d !== void 0 ? _d : (_j.validateHookArguments = utilsAndConstants_1.isDev && !hotReloadEnabled);
22
+ (_e = cache.queries) !== null && _e !== void 0 ? _e : (cache.queries = {});
23
+ (_f = cache.mutations) !== null && _f !== void 0 ? _f : (cache.mutations = {});
22
24
  const nonPartialCache = cache;
23
25
  // make selectors
24
26
  const entitiesSelector = (state) => {
package/dist/index.d.ts CHANGED
@@ -3,4 +3,4 @@ export type { ReduxCacheState } from './reducer';
3
3
  export * from './types';
4
4
  export { defaultMutationCacheOptions } from './useMutation';
5
5
  export { defaultQueryCacheOptions, queryCacheOptionsByPolicy } from './useQuery';
6
- export { defaultGetParamsKey, defaultQueryMutationState, processEntityChanges, } from './utilsAndConstants';
6
+ export { defaultCacheOptions, defaultGetParamsKey, defaultQueryMutationState, processEntityChanges, } from './utilsAndConstants';
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.processEntityChanges = exports.defaultQueryMutationState = exports.defaultGetParamsKey = exports.queryCacheOptionsByPolicy = exports.defaultQueryCacheOptions = exports.defaultMutationCacheOptions = exports.createCache = void 0;
17
+ exports.processEntityChanges = exports.defaultQueryMutationState = exports.defaultGetParamsKey = exports.defaultCacheOptions = exports.queryCacheOptionsByPolicy = exports.defaultQueryCacheOptions = exports.defaultMutationCacheOptions = exports.createCache = void 0;
18
18
  var createCache_1 = require("./createCache");
19
19
  Object.defineProperty(exports, "createCache", { enumerable: true, get: function () { return createCache_1.createCache; } });
20
20
  __exportStar(require("./types"), exports);
@@ -24,14 +24,16 @@ var useQuery_1 = require("./useQuery");
24
24
  Object.defineProperty(exports, "defaultQueryCacheOptions", { enumerable: true, get: function () { return useQuery_1.defaultQueryCacheOptions; } });
25
25
  Object.defineProperty(exports, "queryCacheOptionsByPolicy", { enumerable: true, get: function () { return useQuery_1.queryCacheOptionsByPolicy; } });
26
26
  var utilsAndConstants_1 = require("./utilsAndConstants");
27
+ Object.defineProperty(exports, "defaultCacheOptions", { enumerable: true, get: function () { return utilsAndConstants_1.defaultCacheOptions; } });
27
28
  Object.defineProperty(exports, "defaultGetParamsKey", { enumerable: true, get: function () { return utilsAndConstants_1.defaultGetParamsKey; } });
28
29
  Object.defineProperty(exports, "defaultQueryMutationState", { enumerable: true, get: function () { return utilsAndConstants_1.defaultQueryMutationState; } });
29
30
  Object.defineProperty(exports, "processEntityChanges", { enumerable: true, get: function () { return utilsAndConstants_1.processEntityChanges; } });
30
31
  // Backlog
31
32
  // ! high
32
- // package.json exports
33
33
  // cover with tests
34
34
  // ! medium
35
+ // type extractors from cache
36
+ // custom useStore
35
37
  // return back deserialize selector?
36
38
  // resultSelector - return also boolean that result is full enough
37
39
  // selector for entities by typename
@@ -2,6 +2,11 @@
2
2
  import { CacheOptions, EntitiesMap, EntityChanges, Typenames } from './types';
3
3
  export declare const PACKAGE_SHORT_NAME = "RRC";
4
4
  export declare const isDev: boolean;
5
+ export declare const defaultCacheOptions: {
6
+ logsEnabled: boolean;
7
+ validateFunctionArguments: boolean;
8
+ validateHookArguments: boolean;
9
+ };
5
10
  export declare const defaultQueryMutationState: {
6
11
  readonly loading: false;
7
12
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.processEntityChanges = exports.log = exports.useAssertValueNotChanged = exports.useForceUpdate = exports.defaultGetParamsKey = exports.defaultQueryMutationState = exports.isDev = exports.PACKAGE_SHORT_NAME = void 0;
3
+ exports.processEntityChanges = exports.log = exports.useAssertValueNotChanged = exports.useForceUpdate = exports.defaultGetParamsKey = exports.defaultQueryMutationState = exports.defaultCacheOptions = exports.isDev = exports.PACKAGE_SHORT_NAME = void 0;
4
4
  const react_1 = require("react");
5
5
  const react_2 = require("react");
6
6
  exports.PACKAGE_SHORT_NAME = 'RRC';
@@ -13,6 +13,11 @@ exports.isDev = (() => {
13
13
  return process.env.NODE_ENV === 'development';
14
14
  }
15
15
  })();
16
+ exports.defaultCacheOptions = {
17
+ logsEnabled: false,
18
+ validateFunctionArguments: true,
19
+ validateHookArguments: true,
20
+ };
16
21
  exports.defaultQueryMutationState = { loading: false };
17
22
  const defaultGetParamsKey = (params) => {
18
23
  switch (typeof params) {
@@ -83,13 +88,6 @@ const processEntityChanges = (entities, changes, options) => {
83
88
  if (totalKeysInResponse !== 0 && idsSet.size !== totalKeysInResponse) {
84
89
  throw new Error('Merge, replace and remove changes have intersections for: ' + typename);
85
90
  }
86
- console.log('[VALIDATe]', {
87
- totalKeysInResponse,
88
- idsSet,
89
- mergeIds,
90
- replaceIds,
91
- entitiesToRemove,
92
- });
93
91
  }
94
92
  const newEntities = Object.assign({}, entities[typename]);
95
93
  // remove
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "react-redux-cache",
3
3
  "author": "Alexander Danilov",
4
4
  "license": "MIT",
5
- "version": "0.0.4",
5
+ "version": "0.0.5",
6
6
  "description": "Powerful data fetching and caching library that supports normalization, built on top of redux",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
@@ -14,6 +14,7 @@
14
14
  "prepublishOnly": "yarn build && yarn test"
15
15
  },
16
16
  "devDependencies": {
17
+ "@testing-library/jest-dom": "6.1.4",
17
18
  "@testing-library/react": "14.0.0",
18
19
  "@types/jest": "29.5.1",
19
20
  "@types/node": "20.1.2",
@@ -27,12 +28,15 @@
27
28
  "eslint-plugin-react-hooks": "4.6.0",
28
29
  "eslint-plugin-simple-import-sort": "10.0.0",
29
30
  "jest": "29.5.0",
31
+ "jest-environment-jsdom": "29.7.0",
30
32
  "prettier": "2.8.8",
31
33
  "react": "18.2.0",
32
34
  "react-dom": "18.2.0",
33
35
  "react-redux": "8.0.5",
36
+ "react-router-dom": "6.18.0",
34
37
  "redux": "4.2.1",
35
38
  "redux-logger": "3.0.6",
39
+ "redux-persist": "6.0.0",
36
40
  "ts-jest": "29.1.0",
37
41
  "typescript": "5.0.4"
38
42
  },