@tramvai/module-common 1.30.1 → 1.32.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.
@@ -10,12 +10,13 @@ export declare class BundleManager implements Interface {
10
10
  componentRegistry: ComponentRegistry;
11
11
  dispatcher: typeof DISPATCHER_TOKEN;
12
12
  dispatcherContext: typeof DISPATCHER_CONTEXT_TOKEN;
13
- constructor({ bundleList, componentRegistry, actionRegistry, dispatcher, dispatcherContext }: {
13
+ constructor({ bundleList, componentRegistry, actionRegistry, dispatcher, dispatcherContext, logger, }: {
14
14
  bundleList: any;
15
15
  componentRegistry: any;
16
16
  actionRegistry: any;
17
17
  dispatcher: any;
18
18
  dispatcherContext: any;
19
+ logger: any;
19
20
  });
20
21
  get(name: string, pageComponent: string): Promise<Bundle>;
21
22
  has(name: string, pageComponent: string): boolean;
@@ -5,8 +5,8 @@ export declare class ComponentRegistry implements Interface {
5
5
  constructor({ componentList }?: {
6
6
  componentList?: Record<string, any>[];
7
7
  });
8
- add(name: string, component: any, bundle?: string): void;
9
- get(name: string, bundle?: string): any;
10
- getComponentParam<T>(param: string, defaultValue: T, component: string, bundle: string): T;
8
+ add(name: string, component: any, group?: string): void;
9
+ get(name: string, group?: string): any;
10
+ getComponentParam<T>(param: string, defaultValue: T, component: string, group: string): T;
11
11
  }
12
12
  export {};
@@ -8,7 +8,7 @@ import { LogModule } from '@tramvai/module-log';
8
8
  import { Hooks } from '@tinkoff/hook-runner';
9
9
  import { REQUEST_MANAGER_TOKEN, REQUEST, COMBINE_REDUCERS, STORE_TOKEN, RESPONSE_MANAGER_TOKEN, RESPONSE, ACTION_EXECUTION_TOKEN, LOGGER_TOKEN, PUBSUB_FACTORY_TOKEN, PUBSUB_TOKEN, ROOT_PUBSUB_TOKEN, ACTION_REGISTRY_TOKEN, ACTION_CONDITIONALS, CONTEXT_TOKEN, ACTION_PAGE_RUNNER_TOKEN, DISPATCHER_TOKEN, DISPATCHER_CONTEXT_TOKEN, STORE_MIDDLEWARE, CREATE_CACHE_TOKEN, CLEAR_CACHE_TOKEN, REGISTER_CLEAR_CACHE_TOKEN, HOOK_TOKEN, COMPONENT_REGISTRY_TOKEN, BUNDLE_MANAGER_TOKEN, ADDITIONAL_BUNDLE_TOKEN } from '@tramvai/tokens-common';
10
10
  export * from '@tramvai/tokens-common';
11
- import { getAllFileSystemPages, isFileSystemPageComponent } from '@tramvai/experiments';
11
+ import { fileSystemPagesEnabled, getAllFileSystemPages, isFileSystemPageComponent } from '@tramvai/experiments';
12
12
  import pathOr from '@tinkoff/utils/object/pathOr';
13
13
  import flatten from '@tinkoff/utils/array/flatten';
14
14
  import { createEvent, createReducer, convertAction, createDispatcher, devTools } from '@tramvai/state';
@@ -29,20 +29,26 @@ import LRU from 'lru-cache';
29
29
 
30
30
  const FS_PAGES_DEFAULT_BUNDLE = '__default';
31
31
  class BundleManager {
32
- constructor({ bundleList, componentRegistry, actionRegistry, dispatcher, dispatcherContext }) {
32
+ constructor({ bundleList, componentRegistry, actionRegistry, dispatcher, dispatcherContext, logger, }) {
33
33
  this.bundles = bundleList;
34
34
  this.componentRegistry = componentRegistry;
35
35
  this.actionRegistry = actionRegistry;
36
36
  this.dispatcher = dispatcher;
37
37
  this.dispatcherContext = dispatcherContext;
38
- if (process.env.__TRAMVAI_EXPERIMENTAL_ENABLE_FILE_SYSTEM_PAGES) {
38
+ if (fileSystemPagesEnabled()) {
39
+ const log = logger('file-system-pages:bundle-manager');
40
+ const components = getAllFileSystemPages();
39
41
  const componentsDefaultBundle = createBundle({
40
42
  name: FS_PAGES_DEFAULT_BUNDLE,
41
- components: getAllFileSystemPages(),
43
+ components,
42
44
  });
43
45
  this.bundles[FS_PAGES_DEFAULT_BUNDLE] = () => Promise.resolve({
44
46
  default: componentsDefaultBundle,
45
47
  });
48
+ log.info({
49
+ event: 'create default bundle with file-system pages',
50
+ components: Object.keys(components),
51
+ });
46
52
  }
47
53
  }
48
54
  get(name, pageComponent) {
@@ -68,6 +74,12 @@ class BundleManager {
68
74
  const component = typeof componentOrLoader.load === 'function'
69
75
  ? (await componentOrLoader.load()).default
70
76
  : componentOrLoader;
77
+ // allow page components to register any other components
78
+ if (component.components) {
79
+ eachObj((cmp, name) => {
80
+ this.componentRegistry.add(name, cmp, pageComponent);
81
+ }, component.components);
82
+ }
71
83
  if (component.actions) {
72
84
  this.actionRegistry.add(pageComponent, component.actions);
73
85
  }
@@ -100,24 +112,24 @@ class BundleManager {
100
112
  }
101
113
  }
102
114
 
103
- const DEFAULT_BUNDLE = '__default';
115
+ const DEFAULT_GROUP = '__default';
104
116
  class ComponentRegistry {
105
117
  constructor({ componentList } = {}) {
106
118
  this.components = {
107
- [DEFAULT_BUNDLE]: Object.assign({}, ...flatten(componentList !== null && componentList !== void 0 ? componentList : [])),
119
+ [DEFAULT_GROUP]: Object.assign({}, ...flatten(componentList !== null && componentList !== void 0 ? componentList : [])),
108
120
  };
109
121
  }
110
- add(name, component, bundle = DEFAULT_BUNDLE) {
111
- const bundleComponents = this.components[bundle] || {};
112
- bundleComponents[name] = component;
113
- this.components[bundle] = bundleComponents;
122
+ add(name, component, group = DEFAULT_GROUP) {
123
+ const groupComponents = this.components[group] || {};
124
+ groupComponents[name] = component;
125
+ this.components[group] = groupComponents;
114
126
  }
115
- get(name, bundle = DEFAULT_BUNDLE) {
116
- const bundleComponents = this.components[bundle] || {};
117
- return bundleComponents[name] || this.components[DEFAULT_BUNDLE][name];
127
+ get(name, group = DEFAULT_GROUP) {
128
+ const groupComponents = this.components[group] || {};
129
+ return groupComponents[name] || this.components[DEFAULT_GROUP][name];
118
130
  }
119
- getComponentParam(param, defaultValue, component, bundle) {
120
- return pathOr([param], defaultValue, this.get(component, bundle));
131
+ getComponentParam(param, defaultValue, component, group) {
132
+ return pathOr([param], defaultValue, this.get(component, group));
121
133
  }
122
134
  }
123
135
 
@@ -997,6 +1009,7 @@ CommonModule = __decorate([
997
1009
  actionRegistry: ACTION_REGISTRY_TOKEN,
998
1010
  dispatcher: DISPATCHER_TOKEN,
999
1011
  dispatcherContext: DISPATCHER_CONTEXT_TOKEN,
1012
+ logger: LOGGER_TOKEN,
1000
1013
  },
1001
1014
  }),
1002
1015
  provide({
package/lib/index.es.js CHANGED
@@ -8,7 +8,7 @@ import { LogModule } from '@tramvai/module-log';
8
8
  import { Hooks } from '@tinkoff/hook-runner';
9
9
  import { REQUEST_MANAGER_TOKEN, REQUEST, COMBINE_REDUCERS, CONTEXT_TOKEN, RESPONSE_MANAGER_TOKEN, RESPONSE, ACTION_EXECUTION_TOKEN, LOGGER_TOKEN, PUBSUB_FACTORY_TOKEN, PUBSUB_TOKEN, ROOT_PUBSUB_TOKEN, ACTION_REGISTRY_TOKEN, ACTION_CONDITIONALS, STORE_TOKEN, ACTION_PAGE_RUNNER_TOKEN, DISPATCHER_TOKEN, DISPATCHER_CONTEXT_TOKEN, STORE_MIDDLEWARE, CLEAR_CACHE_TOKEN, CREATE_CACHE_TOKEN, REGISTER_CLEAR_CACHE_TOKEN, HOOK_TOKEN, COMPONENT_REGISTRY_TOKEN, BUNDLE_MANAGER_TOKEN, ADDITIONAL_BUNDLE_TOKEN } from '@tramvai/tokens-common';
10
10
  export * from '@tramvai/tokens-common';
11
- import { getAllFileSystemPages, isFileSystemPageComponent } from '@tramvai/experiments';
11
+ import { fileSystemPagesEnabled, getAllFileSystemPages, isFileSystemPageComponent } from '@tramvai/experiments';
12
12
  import pathOr from '@tinkoff/utils/object/pathOr';
13
13
  import flatten from '@tinkoff/utils/array/flatten';
14
14
  import { createEvent, createReducer, convertAction, createDispatcher, devTools } from '@tramvai/state';
@@ -31,20 +31,26 @@ import { createPapiMethod } from '@tramvai/papi';
31
31
 
32
32
  const FS_PAGES_DEFAULT_BUNDLE = '__default';
33
33
  class BundleManager {
34
- constructor({ bundleList, componentRegistry, actionRegistry, dispatcher, dispatcherContext }) {
34
+ constructor({ bundleList, componentRegistry, actionRegistry, dispatcher, dispatcherContext, logger, }) {
35
35
  this.bundles = bundleList;
36
36
  this.componentRegistry = componentRegistry;
37
37
  this.actionRegistry = actionRegistry;
38
38
  this.dispatcher = dispatcher;
39
39
  this.dispatcherContext = dispatcherContext;
40
- if (process.env.__TRAMVAI_EXPERIMENTAL_ENABLE_FILE_SYSTEM_PAGES) {
40
+ if (fileSystemPagesEnabled()) {
41
+ const log = logger('file-system-pages:bundle-manager');
42
+ const components = getAllFileSystemPages();
41
43
  const componentsDefaultBundle = createBundle({
42
44
  name: FS_PAGES_DEFAULT_BUNDLE,
43
- components: getAllFileSystemPages(),
45
+ components,
44
46
  });
45
47
  this.bundles[FS_PAGES_DEFAULT_BUNDLE] = () => Promise.resolve({
46
48
  default: componentsDefaultBundle,
47
49
  });
50
+ log.info({
51
+ event: 'create default bundle with file-system pages',
52
+ components: Object.keys(components),
53
+ });
48
54
  }
49
55
  }
50
56
  get(name, pageComponent) {
@@ -70,6 +76,12 @@ class BundleManager {
70
76
  const component = typeof componentOrLoader.load === 'function'
71
77
  ? (await componentOrLoader.load()).default
72
78
  : componentOrLoader;
79
+ // allow page components to register any other components
80
+ if (component.components) {
81
+ eachObj((cmp, name) => {
82
+ this.componentRegistry.add(name, cmp, pageComponent);
83
+ }, component.components);
84
+ }
73
85
  if (component.actions) {
74
86
  this.actionRegistry.add(pageComponent, component.actions);
75
87
  }
@@ -102,24 +114,24 @@ class BundleManager {
102
114
  }
103
115
  }
104
116
 
105
- const DEFAULT_BUNDLE = '__default';
117
+ const DEFAULT_GROUP = '__default';
106
118
  class ComponentRegistry {
107
119
  constructor({ componentList } = {}) {
108
120
  this.components = {
109
- [DEFAULT_BUNDLE]: Object.assign({}, ...flatten(componentList !== null && componentList !== void 0 ? componentList : [])),
121
+ [DEFAULT_GROUP]: Object.assign({}, ...flatten(componentList !== null && componentList !== void 0 ? componentList : [])),
110
122
  };
111
123
  }
112
- add(name, component, bundle = DEFAULT_BUNDLE) {
113
- const bundleComponents = this.components[bundle] || {};
114
- bundleComponents[name] = component;
115
- this.components[bundle] = bundleComponents;
124
+ add(name, component, group = DEFAULT_GROUP) {
125
+ const groupComponents = this.components[group] || {};
126
+ groupComponents[name] = component;
127
+ this.components[group] = groupComponents;
116
128
  }
117
- get(name, bundle = DEFAULT_BUNDLE) {
118
- const bundleComponents = this.components[bundle] || {};
119
- return bundleComponents[name] || this.components[DEFAULT_BUNDLE][name];
129
+ get(name, group = DEFAULT_GROUP) {
130
+ const groupComponents = this.components[group] || {};
131
+ return groupComponents[name] || this.components[DEFAULT_GROUP][name];
120
132
  }
121
- getComponentParam(param, defaultValue, component, bundle) {
122
- return pathOr([param], defaultValue, this.get(component, bundle));
133
+ getComponentParam(param, defaultValue, component, group) {
134
+ return pathOr([param], defaultValue, this.get(component, group));
123
135
  }
124
136
  }
125
137
 
@@ -1030,6 +1042,7 @@ CommonModule = __decorate([
1030
1042
  actionRegistry: ACTION_REGISTRY_TOKEN,
1031
1043
  dispatcher: DISPATCHER_TOKEN,
1032
1044
  dispatcherContext: DISPATCHER_CONTEXT_TOKEN,
1045
+ logger: LOGGER_TOKEN,
1033
1046
  },
1034
1047
  }),
1035
1048
  provide({
package/lib/index.js CHANGED
@@ -48,20 +48,26 @@ var LRU__default = /*#__PURE__*/_interopDefaultLegacy(LRU);
48
48
 
49
49
  const FS_PAGES_DEFAULT_BUNDLE = '__default';
50
50
  class BundleManager {
51
- constructor({ bundleList, componentRegistry, actionRegistry, dispatcher, dispatcherContext }) {
51
+ constructor({ bundleList, componentRegistry, actionRegistry, dispatcher, dispatcherContext, logger, }) {
52
52
  this.bundles = bundleList;
53
53
  this.componentRegistry = componentRegistry;
54
54
  this.actionRegistry = actionRegistry;
55
55
  this.dispatcher = dispatcher;
56
56
  this.dispatcherContext = dispatcherContext;
57
- if (process.env.__TRAMVAI_EXPERIMENTAL_ENABLE_FILE_SYSTEM_PAGES) {
57
+ if (experiments.fileSystemPagesEnabled()) {
58
+ const log = logger('file-system-pages:bundle-manager');
59
+ const components = experiments.getAllFileSystemPages();
58
60
  const componentsDefaultBundle = core.createBundle({
59
61
  name: FS_PAGES_DEFAULT_BUNDLE,
60
- components: experiments.getAllFileSystemPages(),
62
+ components,
61
63
  });
62
64
  this.bundles[FS_PAGES_DEFAULT_BUNDLE] = () => Promise.resolve({
63
65
  default: componentsDefaultBundle,
64
66
  });
67
+ log.info({
68
+ event: 'create default bundle with file-system pages',
69
+ components: Object.keys(components),
70
+ });
65
71
  }
66
72
  }
67
73
  get(name, pageComponent) {
@@ -87,6 +93,12 @@ class BundleManager {
87
93
  const component = typeof componentOrLoader.load === 'function'
88
94
  ? (await componentOrLoader.load()).default
89
95
  : componentOrLoader;
96
+ // allow page components to register any other components
97
+ if (component.components) {
98
+ eachObj__default["default"]((cmp, name) => {
99
+ this.componentRegistry.add(name, cmp, pageComponent);
100
+ }, component.components);
101
+ }
90
102
  if (component.actions) {
91
103
  this.actionRegistry.add(pageComponent, component.actions);
92
104
  }
@@ -119,24 +131,24 @@ class BundleManager {
119
131
  }
120
132
  }
121
133
 
122
- const DEFAULT_BUNDLE = '__default';
134
+ const DEFAULT_GROUP = '__default';
123
135
  class ComponentRegistry {
124
136
  constructor({ componentList } = {}) {
125
137
  this.components = {
126
- [DEFAULT_BUNDLE]: Object.assign({}, ...flatten__default["default"](componentList !== null && componentList !== void 0 ? componentList : [])),
138
+ [DEFAULT_GROUP]: Object.assign({}, ...flatten__default["default"](componentList !== null && componentList !== void 0 ? componentList : [])),
127
139
  };
128
140
  }
129
- add(name, component, bundle = DEFAULT_BUNDLE) {
130
- const bundleComponents = this.components[bundle] || {};
131
- bundleComponents[name] = component;
132
- this.components[bundle] = bundleComponents;
141
+ add(name, component, group = DEFAULT_GROUP) {
142
+ const groupComponents = this.components[group] || {};
143
+ groupComponents[name] = component;
144
+ this.components[group] = groupComponents;
133
145
  }
134
- get(name, bundle = DEFAULT_BUNDLE) {
135
- const bundleComponents = this.components[bundle] || {};
136
- return bundleComponents[name] || this.components[DEFAULT_BUNDLE][name];
146
+ get(name, group = DEFAULT_GROUP) {
147
+ const groupComponents = this.components[group] || {};
148
+ return groupComponents[name] || this.components[DEFAULT_GROUP][name];
137
149
  }
138
- getComponentParam(param, defaultValue, component, bundle) {
139
- return pathOr__default["default"]([param], defaultValue, this.get(component, bundle));
150
+ getComponentParam(param, defaultValue, component, group) {
151
+ return pathOr__default["default"]([param], defaultValue, this.get(component, group));
140
152
  }
141
153
  }
142
154
 
@@ -1047,6 +1059,7 @@ exports.CommonModule = tslib.__decorate([
1047
1059
  actionRegistry: tokensCommon.ACTION_REGISTRY_TOKEN,
1048
1060
  dispatcher: tokensCommon.DISPATCHER_TOKEN,
1049
1061
  dispatcherContext: tokensCommon.DISPATCHER_CONTEXT_TOKEN,
1062
+ logger: tokensCommon.LOGGER_TOKEN,
1050
1063
  },
1051
1064
  }),
1052
1065
  core.provide({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-common",
3
- "version": "1.30.1",
3
+ "version": "1.32.1",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -30,22 +30,22 @@
30
30
  "@tinkoff/errors": "0.2.18",
31
31
  "@tinkoff/pubsub": "0.4.23",
32
32
  "@tinkoff/url": "0.7.37",
33
- "@tramvai/module-cookie": "1.30.1",
34
- "@tramvai/module-environment": "1.30.1",
35
- "@tramvai/module-log": "1.30.1",
36
- "@tramvai/tokens-common": "1.30.1",
37
- "@tramvai/experiments": "1.30.1",
33
+ "@tramvai/module-cookie": "1.32.1",
34
+ "@tramvai/module-environment": "1.32.1",
35
+ "@tramvai/module-log": "1.32.1",
36
+ "@tramvai/tokens-common": "1.32.1",
37
+ "@tramvai/experiments": "1.32.1",
38
38
  "@tinkoff/hook-runner": "0.3.21",
39
39
  "lru-cache": "^6.0.0"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@tinkoff/utils": "^2.1.2",
43
- "@tramvai/cli": "1.30.1",
44
- "@tramvai/core": "1.30.1",
45
- "@tramvai/papi": "1.30.1",
46
- "@tramvai/state": "1.30.1",
47
- "@tramvai/tokens-metrics": "1.30.1",
48
- "@tramvai/tokens-server": "1.30.1",
43
+ "@tramvai/cli": "1.32.1",
44
+ "@tramvai/core": "1.32.1",
45
+ "@tramvai/papi": "1.32.1",
46
+ "@tramvai/state": "1.32.1",
47
+ "@tramvai/tokens-metrics": "1.32.1",
48
+ "@tramvai/tokens-server": "1.32.1",
49
49
  "@tinkoff/dippy": "0.7.35",
50
50
  "tslib": "^2.0.3"
51
51
  },