@tramvai/module-common 7.21.0 → 7.26.8

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.
@@ -43,6 +43,17 @@ function cacheFactory(cacheType = MEMORY_LRU, options) {
43
43
  }
44
44
  return cache;
45
45
  }
46
+ function getUniqueName(name, cacheNames) {
47
+ if (!cacheNames.has(name)) {
48
+ return name;
49
+ }
50
+ const baseName = `${name}-unsafe-copy`;
51
+ let index = 1;
52
+ while (cacheNames.has(`${baseName}-${index}`)) {
53
+ index += 1;
54
+ }
55
+ return `${baseName}-${index}`;
56
+ }
46
57
  function getCacheFactory({ cacheNames, metrics, }) {
47
58
  return function (cacheType, options) {
48
59
  const cache = cacheFactory(cacheType, options);
@@ -50,7 +61,10 @@ function getCacheFactory({ cacheNames, metrics, }) {
50
61
  return cache;
51
62
  }
52
63
  if (cacheNames.has(options.name)) {
53
- throw new Error(`Cache with name ${options.name} is already created`);
64
+ if (process.env.NODE_ENV === 'development') {
65
+ throw new Error(`Cache with name ${options.name} is already created`);
66
+ }
67
+ options.name = getUniqueName(options.name, cacheNames);
54
68
  }
55
69
  cacheNames.add(options.name);
56
70
  return new CacheWithMetricsProxy(cache, options, metrics);
@@ -52,6 +52,17 @@ function cacheFactory(cacheType$1 = tokensCommon.MEMORY_LRU, options) {
52
52
  }
53
53
  return cache;
54
54
  }
55
+ function getUniqueName(name, cacheNames) {
56
+ if (!cacheNames.has(name)) {
57
+ return name;
58
+ }
59
+ const baseName = `${name}-unsafe-copy`;
60
+ let index = 1;
61
+ while (cacheNames.has(`${baseName}-${index}`)) {
62
+ index += 1;
63
+ }
64
+ return `${baseName}-${index}`;
65
+ }
55
66
  function getCacheFactory({ cacheNames, metrics, }) {
56
67
  return function (cacheType, options) {
57
68
  const cache = cacheFactory(cacheType, options);
@@ -59,7 +70,10 @@ function getCacheFactory({ cacheNames, metrics, }) {
59
70
  return cache;
60
71
  }
61
72
  if (cacheNames.has(options.name)) {
62
- throw new Error(`Cache with name ${options.name} is already created`);
73
+ if (process.env.NODE_ENV === 'development') {
74
+ throw new Error(`Cache with name ${options.name} is already created`);
75
+ }
76
+ options.name = getUniqueName(options.name, cacheNames);
63
77
  }
64
78
  cacheNames.add(options.name);
65
79
  return new cacheWithMetricsProxy.CacheWithMetricsProxy(cache, options, metrics);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-common",
3
- "version": "7.21.0",
3
+ "version": "7.26.8",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -36,30 +36,30 @@
36
36
  "@tinkoff/lru-cache-nano": "^7.9.0",
37
37
  "@tinkoff/pubsub": "0.10.1",
38
38
  "@tinkoff/url": "0.13.1",
39
- "@tramvai/experiments": "7.21.0",
40
- "@tramvai/module-cookie": "7.21.0",
41
- "@tramvai/module-environment": "7.21.0",
42
- "@tramvai/module-log": "7.21.0",
39
+ "@tramvai/experiments": "7.26.8",
40
+ "@tramvai/module-cookie": "7.26.8",
41
+ "@tramvai/module-environment": "7.26.8",
42
+ "@tramvai/module-log": "7.26.8",
43
43
  "@tramvai/safe-strings": "0.10.1",
44
- "@tramvai/tokens-child-app": "7.21.0",
45
- "@tramvai/tokens-common": "7.21.0",
46
- "@tramvai/tokens-core-private": "7.21.0",
47
- "@tramvai/tokens-metrics": "7.21.0",
48
- "@tramvai/tokens-render": "7.21.0",
49
- "@tramvai/tokens-router": "7.21.0",
50
- "@tramvai/tokens-server-private": "7.21.0",
51
- "@tramvai/types-actions-state-context": "7.21.0",
44
+ "@tramvai/tokens-child-app": "7.26.8",
45
+ "@tramvai/tokens-common": "7.26.8",
46
+ "@tramvai/tokens-core-private": "7.26.8",
47
+ "@tramvai/tokens-metrics": "7.26.8",
48
+ "@tramvai/tokens-render": "7.26.8",
49
+ "@tramvai/tokens-router": "7.26.8",
50
+ "@tramvai/tokens-server-private": "7.26.8",
51
+ "@tramvai/types-actions-state-context": "7.26.8",
52
52
  "hoist-non-react-statics": "^3.3.1"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "@tinkoff/dippy": "^1.0.0",
56
56
  "@tinkoff/utils": "^2.1.2",
57
- "@tramvai/cli": "7.21.0",
58
- "@tramvai/core": "7.21.0",
59
- "@tramvai/papi": "7.21.0",
60
- "@tramvai/react": "7.21.0",
61
- "@tramvai/state": "7.21.0",
62
- "@tramvai/tokens-server": "7.21.0",
57
+ "@tramvai/cli": "7.26.8",
58
+ "@tramvai/core": "7.26.8",
59
+ "@tramvai/papi": "7.26.8",
60
+ "@tramvai/react": "7.26.8",
61
+ "@tramvai/state": "7.26.8",
62
+ "@tramvai/tokens-server": "7.26.8",
63
63
  "react": ">=16.14.0",
64
64
  "tslib": "^2.4.0"
65
65
  },