react-redux-cache 0.8.0 → 0.8.1

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/dist/index.js CHANGED
@@ -27,7 +27,6 @@ Object.defineProperty(exports, "defaultQueryMutationState", { enumerable: true,
27
27
  // rca -> vite
28
28
  // defaults
29
29
  // remove cachePolicy? make skip/enabled a function? skip -> enabled/shouldFetch?
30
- // remove mergeResults? bcs store is passed to queries/mutations
31
30
  // remove undefined optional fields & emtpy states
32
31
  // generate full api docs
33
32
  // ! medium
@@ -8,6 +8,7 @@ export declare const DEFAULT_QUERY_MUTATION_STATE: Readonly<{
8
8
  loading: false;
9
9
  }>;
10
10
  export declare const EMPTY_OBJECT: Readonly<{}>;
11
+ export declare const EMPTY_ARRAY: readonly never[];
11
12
  export declare const defaultGetCacheKey: <P = unknown>(params: P) => Key;
12
13
  export declare const log: (tag: string, data?: unknown) => void;
13
14
  export declare const applyEntityChanges: <T extends Typenames>(entities: EntitiesMap<T>, changes: EntityChanges<T>, options: CacheOptions) => EntitiesMap<T> | undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyEntityChanges = exports.log = exports.defaultGetCacheKey = exports.EMPTY_OBJECT = exports.DEFAULT_QUERY_MUTATION_STATE = exports.IS_DEV = exports.optionalUtils = exports.PACKAGE_SHORT_NAME = void 0;
3
+ exports.applyEntityChanges = exports.log = exports.defaultGetCacheKey = exports.EMPTY_ARRAY = exports.EMPTY_OBJECT = exports.DEFAULT_QUERY_MUTATION_STATE = exports.IS_DEV = exports.optionalUtils = exports.PACKAGE_SHORT_NAME = void 0;
4
4
  exports.PACKAGE_SHORT_NAME = 'rrc';
5
5
  exports.optionalUtils = {
6
6
  deepEqual: undefined,
@@ -22,6 +22,7 @@ exports.IS_DEV = (() => {
22
22
  })();
23
23
  exports.DEFAULT_QUERY_MUTATION_STATE = Object.freeze({ loading: false });
24
24
  exports.EMPTY_OBJECT = Object.freeze({});
25
+ exports.EMPTY_ARRAY = Object.freeze([]);
25
26
  const defaultGetCacheKey = (params) => {
26
27
  switch (typeof params) {
27
28
  case 'string':
@@ -40,11 +41,8 @@ const log = (tag, data) => {
40
41
  exports.log = log;
41
42
  const applyEntityChanges = (entities, changes, options) => {
42
43
  var _a, _b, _c, _d;
43
- if (options.validateFunctionArguments) {
44
- // check for merge and entities both set
45
- if (changes.merge && changes.entities) {
46
- throw new Error('Merge and entities should not be both set');
47
- }
44
+ if (changes.merge && changes.entities) {
45
+ console.warn('react-redux-cache.applyEntityChanges: merge and entities should not be both set');
48
46
  }
49
47
  const { merge = changes.entities, replace, remove } = changes;
50
48
  if (!merge && !replace && !remove) {
@@ -52,11 +50,12 @@ const applyEntityChanges = (entities, changes, options) => {
52
50
  }
53
51
  const deepEqual = options.deepComparisonEnabled ? exports.optionalUtils.deepEqual : undefined;
54
52
  let result;
53
+ // TODO refactor to remove this Set
55
54
  const typenames = new Set([
56
- ...(changes.entities ? Object.keys(changes.entities) : []),
57
- ...(changes.merge ? Object.keys(changes.merge) : []),
58
- ...(changes.remove ? Object.keys(changes.remove) : []),
59
- ...(changes.replace ? Object.keys(changes.replace) : []),
55
+ ...(changes.entities ? Object.keys(changes.entities) : exports.EMPTY_ARRAY),
56
+ ...(changes.merge ? Object.keys(changes.merge) : exports.EMPTY_ARRAY),
57
+ ...(changes.remove ? Object.keys(changes.remove) : exports.EMPTY_ARRAY),
58
+ ...(changes.replace ? Object.keys(changes.replace) : exports.EMPTY_ARRAY),
60
59
  ]);
61
60
  for (const typename of typenames) {
62
61
  const entitiesToMerge = merge === null || merge === void 0 ? void 0 : merge[typename];
@@ -74,7 +73,8 @@ const applyEntityChanges = (entities, changes, options) => {
74
73
  entitiesToRemove === null || entitiesToRemove === void 0 ? void 0 : entitiesToRemove.forEach((id) => idsSet.add(String(id))); // String() because Object.keys always returns strings
75
74
  const totalKeysInResponse = ((_a = mergeIds === null || mergeIds === void 0 ? void 0 : mergeIds.length) !== null && _a !== void 0 ? _a : 0) + ((_b = replaceIds === null || replaceIds === void 0 ? void 0 : replaceIds.length) !== null && _b !== void 0 ? _b : 0) + ((_c = entitiesToRemove === null || entitiesToRemove === void 0 ? void 0 : entitiesToRemove.length) !== null && _c !== void 0 ? _c : 0);
76
75
  if (totalKeysInResponse !== 0 && idsSet.size !== totalKeysInResponse) {
77
- throw new Error('Merge, replace and remove changes have intersections for: ' + typename);
76
+ console.warn('react-redux-cache.applyEntityChanges: merge, replace and remove changes have intersections for: ' +
77
+ typename);
78
78
  }
79
79
  }
80
80
  const oldEntities = (_d = entities[typename]) !== null && _d !== void 0 ? _d : exports.EMPTY_OBJECT;
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.8.0",
5
+ "version": "0.8.1",
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",