@tramvai/module-common 2.160.19 → 2.160.21

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.
@@ -2,9 +2,22 @@ import LRU from '@tinkoff/lru-cache-nano';
2
2
  import LFU from '@akashbabu/lfu-cache';
3
3
 
4
4
  class LFUToCacheAdapter extends LFU {
5
+ set(key, value, options) {
6
+ return this.set(key, value);
7
+ }
5
8
  has(key) {
6
9
  return typeof this.get(key) !== 'undefined';
7
10
  }
11
+ dump() {
12
+ const arr = [];
13
+ this.forEach(([key, value]) => arr.push([key, { value }]));
14
+ return arr;
15
+ }
16
+ load(arr) {
17
+ arr.forEach(([key, { value }]) => {
18
+ this.set(key, value);
19
+ });
20
+ }
8
21
  }
9
22
  const cacheFactory = (type, options = { max: 100 }) => {
10
23
  if (type === 'memory-lfu') {
@@ -11,9 +11,22 @@ var LRU__default = /*#__PURE__*/_interopDefaultLegacy(LRU);
11
11
  var LFU__default = /*#__PURE__*/_interopDefaultLegacy(LFU);
12
12
 
13
13
  class LFUToCacheAdapter extends LFU__default["default"] {
14
+ set(key, value, options) {
15
+ return this.set(key, value);
16
+ }
14
17
  has(key) {
15
18
  return typeof this.get(key) !== 'undefined';
16
19
  }
20
+ dump() {
21
+ const arr = [];
22
+ this.forEach(([key, value]) => arr.push([key, { value }]));
23
+ return arr;
24
+ }
25
+ load(arr) {
26
+ arr.forEach(([key, { value }]) => {
27
+ this.set(key, value);
28
+ });
29
+ }
17
30
  }
18
31
  const cacheFactory = (type, options = { max: 100 }) => {
19
32
  if (type === 'memory-lfu') {
@@ -4,8 +4,37 @@ import { INITIAL_APP_STATE_TOKEN } from '@tramvai/tokens-common';
4
4
  const providers = [
5
5
  provide({
6
6
  provide: INITIAL_APP_STATE_TOKEN,
7
- useFactory: () => { var _a, _b; return JSON.parse((_b = (_a = document.getElementById('__TRAMVAI_STATE__')) === null || _a === void 0 ? void 0 : _a.textContent) !== null && _b !== void 0 ? _b : '{}'); },
8
7
  scope: Scope.REQUEST,
8
+ useFactory: () => {
9
+ var _a;
10
+ let initialState;
11
+ try {
12
+ initialState = (_a = document.getElementById('__TRAMVAI_STATE__')) === null || _a === void 0 ? void 0 : _a.textContent;
13
+ if (!initialState) {
14
+ throw Error('__TRAMVAI_STATE__ element is empty or missing');
15
+ }
16
+ return JSON.parse(initialState);
17
+ }
18
+ catch (e) {
19
+ if (window.logger) {
20
+ const log = window.logger('tramvai-state');
21
+ log.error({
22
+ event: 'initial-state-parse-error',
23
+ error: e,
24
+ initialState,
25
+ });
26
+ }
27
+ else {
28
+ // if logger is not ready, we still can log this error in inline scripts with error interceptors.
29
+ // force unhandled promise reject, because we don't need to break application here with sync error.
30
+ // eslint-disable-next-line promise/catch-or-return
31
+ Promise.resolve().then(() => {
32
+ throw Object.assign(e, { initialState, event: 'initial-state-parse-error' });
33
+ });
34
+ }
35
+ return {};
36
+ }
37
+ },
9
38
  }),
10
39
  provide({
11
40
  provide: commandLineListTokens.listen,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-common",
3
- "version": "2.160.19",
3
+ "version": "2.160.21",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -31,33 +31,33 @@
31
31
  "dependencies": {
32
32
  "@tinkoff/errors": "0.3.8",
33
33
  "@tinkoff/hook-runner": "0.4.6",
34
- "@tinkoff/lru-cache-nano": "^7.8.1",
34
+ "@tinkoff/lru-cache-nano": "^7.9.0",
35
35
  "@akashbabu/lfu-cache": "1.0.2",
36
36
  "@tinkoff/pubsub": "0.5.7",
37
37
  "@tinkoff/url": "0.8.6",
38
38
  "@tramvai/safe-strings": "0.5.12",
39
- "@tramvai/experiments": "2.160.19",
40
- "@tramvai/module-cookie": "2.160.19",
41
- "@tramvai/module-environment": "2.160.19",
42
- "@tramvai/module-log": "2.160.19",
43
- "@tramvai/tokens-child-app": "2.160.19",
44
- "@tramvai/tokens-core-private": "2.160.19",
45
- "@tramvai/tokens-common": "2.160.19",
46
- "@tramvai/tokens-render": "2.160.19",
47
- "@tramvai/tokens-server-private": "2.160.19",
48
- "@tramvai/types-actions-state-context": "2.160.19",
39
+ "@tramvai/experiments": "2.160.21",
40
+ "@tramvai/module-cookie": "2.160.21",
41
+ "@tramvai/module-environment": "2.160.21",
42
+ "@tramvai/module-log": "2.160.21",
43
+ "@tramvai/tokens-child-app": "2.160.21",
44
+ "@tramvai/tokens-core-private": "2.160.21",
45
+ "@tramvai/tokens-common": "2.160.21",
46
+ "@tramvai/tokens-render": "2.160.21",
47
+ "@tramvai/tokens-server-private": "2.160.21",
48
+ "@tramvai/types-actions-state-context": "2.160.21",
49
49
  "hoist-non-react-statics": "^3.3.1",
50
50
  "node-abort-controller": "^3.0.1"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "@tinkoff/dippy": "0.8.16",
54
54
  "@tinkoff/utils": "^2.1.2",
55
- "@tramvai/cli": "2.160.19",
56
- "@tramvai/core": "2.160.19",
57
- "@tramvai/papi": "2.160.19",
58
- "@tramvai/react": "2.160.19",
59
- "@tramvai/state": "2.160.19",
60
- "@tramvai/tokens-server": "2.160.19",
55
+ "@tramvai/cli": "2.160.21",
56
+ "@tramvai/core": "2.160.21",
57
+ "@tramvai/papi": "2.160.21",
58
+ "@tramvai/react": "2.160.21",
59
+ "@tramvai/state": "2.160.21",
60
+ "@tramvai/tokens-server": "2.160.21",
61
61
  "react": ">=16.14.0",
62
62
  "tslib": "^2.4.0"
63
63
  },