@tramvai/module-common 2.36.0 → 2.37.0

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/lib/index.js CHANGED
@@ -10,6 +10,8 @@ var moduleCookie = require('@tramvai/module-cookie');
10
10
  var moduleLog = require('@tramvai/module-log');
11
11
  var hookRunner = require('@tinkoff/hook-runner');
12
12
  var tokensCommon = require('@tramvai/tokens-common');
13
+ var isObject = require('@tinkoff/utils/is/object');
14
+ var isArray = require('@tinkoff/utils/is/array');
13
15
  var react = require('@tramvai/react');
14
16
  var experiments = require('@tramvai/experiments');
15
17
  var pathOr = require('@tinkoff/utils/object/pathOr');
@@ -40,6 +42,8 @@ var tokensChildApp = require('@tramvai/tokens-child-app');
40
42
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
41
43
 
42
44
  var eachObj__default = /*#__PURE__*/_interopDefaultLegacy(eachObj);
45
+ var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
46
+ var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);
43
47
  var pathOr__default = /*#__PURE__*/_interopDefaultLegacy(pathOr);
44
48
  var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
45
49
  var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
@@ -96,16 +100,19 @@ class BundleManager {
96
100
  if (pageComponent && bundle.components[pageComponent]) {
97
101
  const componentOrLoader = bundle.components[pageComponent];
98
102
  const component = await react.resolveLazyComponent(componentOrLoader);
103
+ if (!component) {
104
+ return;
105
+ }
99
106
  // allow page components to register any other components
100
- if ('components' in component) {
107
+ if ('components' in component && isObject__default["default"](component.components)) {
101
108
  eachObj__default["default"]((cmp, name) => {
102
109
  this.componentRegistry.add(name, cmp, pageComponent);
103
110
  }, component.components);
104
111
  }
105
- if ('actions' in component) {
112
+ if ('actions' in component && isArray__default["default"](component.actions)) {
106
113
  this.actionRegistry.add(pageComponent, component.actions);
107
114
  }
108
- if ('reducers' in component) {
115
+ if ('reducers' in component && isArray__default["default"](component.reducers)) {
109
116
  component.reducers.forEach((reducer) => {
110
117
  this.dispatcher.registerStore(reducer);
111
118
  });
@@ -213,19 +220,19 @@ class RequestManager {
213
220
  }
214
221
 
215
222
  const sharedProviders$1 = [
216
- {
223
+ core.provide({
217
224
  provide: tokensCommon.REQUEST_MANAGER_TOKEN,
218
225
  scope: core.Scope.REQUEST,
219
226
  useClass: RequestManager,
220
227
  deps: {
221
228
  request: tokensServerPrivate.FASTIFY_REQUEST,
222
229
  },
223
- },
224
- {
230
+ }),
231
+ core.provide({
225
232
  provide: tokensCommon.COMBINE_REDUCERS,
226
233
  multi: true,
227
234
  useValue: RequestManagerStore,
228
- },
235
+ }),
229
236
  ];
230
237
 
231
238
  let RequestManagerModule = class RequestManagerModule {
@@ -234,7 +241,7 @@ RequestManagerModule = tslib.__decorate([
234
241
  core.Module({
235
242
  providers: [
236
243
  ...sharedProviders$1,
237
- {
244
+ core.provide({
238
245
  provide: core.commandLineListTokens.customerStart,
239
246
  multi: true,
240
247
  useFactory: ({ context, requestManager }) => {
@@ -251,7 +258,7 @@ RequestManagerModule = tslib.__decorate([
251
258
  context: tokensCommon.CONTEXT_TOKEN,
252
259
  requestManager: tokensCommon.REQUEST_MANAGER_TOKEN,
253
260
  },
254
- },
261
+ }),
255
262
  ],
256
263
  })
257
264
  ], RequestManagerModule);
@@ -305,11 +312,11 @@ class ResponseManager {
305
312
  }
306
313
 
307
314
  const sharedProviders = [
308
- {
315
+ core.provide({
309
316
  provide: tokensCommon.RESPONSE_MANAGER_TOKEN,
310
317
  scope: core.Scope.REQUEST,
311
318
  useClass: ResponseManager,
312
- },
319
+ }),
313
320
  ];
314
321
 
315
322
  let ResponseManagerModule = class ResponseManagerModule {
@@ -351,8 +358,8 @@ class ConsumerContext {
351
358
  this.dehydrate = () => ({
352
359
  dispatcher: this.dispatcher.dehydrate(),
353
360
  });
354
- this.getState = (reducer) => {
355
- return this.store.getState(reducer);
361
+ this.getState = (...args) => {
362
+ return this.store.getState(args[0]);
356
363
  };
357
364
  this.subscribe = (...args) => {
358
365
  return this.store.subscribe(args[0], args[1]);
@@ -361,6 +368,7 @@ class ConsumerContext {
361
368
  this.registerStore = (store) => this.dispatcher.registerStore(store);
362
369
  this.unregisterStore = (store) => this.dispatcher.unregisterStore(store);
363
370
  this.store = store;
371
+ // @ts-expect-error
364
372
  this.dispatcher = dispatcherContext;
365
373
  // TODO убрать, нужно для некоторых старых сторов на платформе
366
374
  this.dispatcher.setContext(this);
@@ -391,7 +399,7 @@ const resolveDi = (type, status, diContainer, providers) => {
391
399
  return di;
392
400
  };
393
401
  class CommandLineRunner {
394
- constructor({ lines, rootDi, logger, metrics, executionContextManager, }) {
402
+ constructor({ lines, rootDi, logger, metrics, executionContextManager }) {
395
403
  this.executionContextByDi = new WeakMap();
396
404
  this.abortControllerByDi = new WeakMap();
397
405
  this.lines = lines;
@@ -466,6 +474,7 @@ class CommandLineRunner {
466
474
  // пробегаемся по всем инстансам и для текущего получаем его запись, из которой можно получить стек
467
475
  for (let i = 0; i < instances.length; i++) {
468
476
  if (instances[i] === instance) {
477
+ // @ts-expect-error
469
478
  error.stack = `${error.stack}\n---- caused by: ----\n${record.multi[i].stack || ''}`;
470
479
  }
471
480
  }
@@ -566,7 +575,7 @@ exports.CommandModule = tslib.__decorate([
566
575
  }),
567
576
  dippy.provide({
568
577
  provide: tokensCommon.COMMAND_LINE_EXECUTION_CONTEXT_TOKEN,
569
- useFactory: ({ di, commandLineRunner, }) => {
578
+ useFactory: ({ di, commandLineRunner }) => {
570
579
  return () => {
571
580
  return commandLineRunner.resolveExecutionContextFromDi(di);
572
581
  };
@@ -591,7 +600,7 @@ let PubSubModule = class PubSubModule {
591
600
  PubSubModule = tslib.__decorate([
592
601
  core.Module({
593
602
  providers: [
594
- {
603
+ core.provide({
595
604
  // Фабрика для создания pubsub
596
605
  provide: tokensCommon.PUBSUB_FACTORY_TOKEN,
597
606
  scope: core.Scope.SINGLETON,
@@ -603,23 +612,23 @@ PubSubModule = tslib.__decorate([
603
612
  deps: {
604
613
  logger: tokensCommon.LOGGER_TOKEN,
605
614
  },
606
- },
607
- {
615
+ }),
616
+ core.provide({
608
617
  provide: tokensCommon.PUBSUB_TOKEN,
609
618
  scope: core.Scope.REQUEST,
610
619
  useFactory: ({ createPubsub }) => createPubsub(),
611
620
  deps: {
612
621
  createPubsub: tokensCommon.PUBSUB_FACTORY_TOKEN,
613
622
  },
614
- },
615
- {
623
+ }),
624
+ core.provide({
616
625
  provide: tokensCommon.ROOT_PUBSUB_TOKEN,
617
626
  scope: core.Scope.SINGLETON,
618
627
  useFactory: ({ createPubsub }) => createPubsub(),
619
628
  deps: {
620
629
  createPubsub: tokensCommon.PUBSUB_FACTORY_TOKEN,
621
630
  },
622
- },
631
+ }),
623
632
  ],
624
633
  })
625
634
  ], PubSubModule);
@@ -918,23 +927,24 @@ const pageBrowser = {
918
927
  },
919
928
  };
920
929
 
930
+ const LIMIT_ACTION_GLOBAL_TIME_RUN = core.createToken('limitActionGlobalTimeRun');
921
931
  let ActionModule = class ActionModule {
922
932
  };
923
933
  ActionModule = tslib.__decorate([
924
934
  core.Module({
925
935
  providers: [
926
- {
936
+ core.provide({
927
937
  provide: tokensCommon.COMBINE_REDUCERS,
928
938
  multi: true,
929
939
  useValue: actionTramvaiReducer,
930
- },
931
- {
940
+ }),
941
+ core.provide({
932
942
  // Регистер глобальных экшенов
933
943
  provide: tokensCommon.ACTION_REGISTRY_TOKEN,
934
944
  scope: core.Scope.SINGLETON,
935
945
  useClass: ActionRegistry,
936
946
  deps: { actionsList: core.ACTIONS_LIST_TOKEN },
937
- },
947
+ }),
938
948
  core.provide({
939
949
  provide: tokensCommon.ACTION_EXECUTION_TOKEN,
940
950
  scope: core.Scope.REQUEST,
@@ -960,19 +970,19 @@ ActionModule = tslib.__decorate([
960
970
  executionContextManager: tokensCommon.EXECUTION_CONTEXT_MANAGER_TOKEN,
961
971
  commandLineExecutionContext: tokensCommon.COMMAND_LINE_EXECUTION_CONTEXT_TOKEN,
962
972
  store: tokensCommon.STORE_TOKEN,
963
- limitTime: 'limitActionGlobalTimeRun',
973
+ limitTime: LIMIT_ACTION_GLOBAL_TIME_RUN,
964
974
  logger: tokensCommon.LOGGER_TOKEN,
965
975
  },
966
976
  }),
967
- {
968
- provide: 'limitActionGlobalTimeRun',
977
+ core.provide({
978
+ provide: LIMIT_ACTION_GLOBAL_TIME_RUN,
969
979
  useValue: 500,
970
- },
971
- {
980
+ }),
981
+ core.provide({
972
982
  provide: tokensCommon.ACTION_CONDITIONALS,
973
983
  multi: true,
974
984
  useValue: [alwaysCondition, onlyServer, onlyBrowser, pageServer, pageBrowser],
975
- },
985
+ }),
976
986
  ],
977
987
  })
978
988
  ], ActionModule);
@@ -982,7 +992,7 @@ let StateModule = class StateModule {
982
992
  StateModule = tslib.__decorate([
983
993
  core.Module({
984
994
  providers: [
985
- {
995
+ core.provide({
986
996
  provide: tokensCommon.DISPATCHER_TOKEN,
987
997
  scope: core.Scope.SINGLETON,
988
998
  useFactory: ({ stores }) => state.createDispatcher({ stores: stores && flatten__default["default"](stores) }),
@@ -992,8 +1002,8 @@ StateModule = tslib.__decorate([
992
1002
  optional: true,
993
1003
  },
994
1004
  },
995
- },
996
- {
1005
+ }),
1006
+ core.provide({
997
1007
  provide: tokensCommon.DISPATCHER_CONTEXT_TOKEN,
998
1008
  scope: core.Scope.REQUEST,
999
1009
  useFactory: ({ dispatcher, initialState, middlewares }) => {
@@ -1007,19 +1017,19 @@ StateModule = tslib.__decorate([
1007
1017
  middlewares: { token: tokensCommon.STORE_MIDDLEWARE, optional: true },
1008
1018
  initialState: { token: tokensCommon.INITIAL_APP_STATE_TOKEN, optional: true },
1009
1019
  },
1010
- },
1011
- {
1020
+ }),
1021
+ core.provide({
1012
1022
  provide: tokensCommon.STORE_TOKEN,
1013
1023
  scope: core.Scope.REQUEST,
1014
1024
  useFactory: ({ dispatcherContext }) => ({
1015
- getState: (reducer) => dispatcherContext.getState(reducer),
1016
- dispatch: (action) => dispatcherContext.dispatch(action),
1017
- subscribe: (reducer, callback) => dispatcherContext.subscribe(reducer, callback),
1025
+ getState: dispatcherContext.getState.bind(dispatcherContext),
1026
+ dispatch: dispatcherContext.dispatch.bind(dispatcherContext),
1027
+ subscribe: dispatcherContext.subscribe.bind(dispatcherContext),
1018
1028
  }),
1019
1029
  deps: {
1020
1030
  dispatcherContext: tokensCommon.DISPATCHER_CONTEXT_TOKEN,
1021
1031
  },
1022
- },
1032
+ }),
1023
1033
  ],
1024
1034
  })
1025
1035
  ], StateModule);
@@ -1044,7 +1054,7 @@ const papiClearCache = ({ clearCache, logger, }) => {
1044
1054
  };
1045
1055
 
1046
1056
  const providers$1 = [
1047
- {
1057
+ core.provide({
1048
1058
  provide: tokensServer.SERVER_MODULE_PAPI_PRIVATE_ROUTE,
1049
1059
  multi: true,
1050
1060
  useFactory: papiClearCache,
@@ -1052,7 +1062,7 @@ const providers$1 = [
1052
1062
  clearCache: tokensCommon.CLEAR_CACHE_TOKEN,
1053
1063
  logger: tokensCommon.LOGGER_TOKEN,
1054
1064
  },
1055
- },
1065
+ }),
1056
1066
  ];
1057
1067
 
1058
1068
  const cachesToken = dippy.createToken('_cachesList');
@@ -1150,7 +1160,8 @@ class ExecutionContextManager {
1150
1160
  throw error;
1151
1161
  }
1152
1162
  finally {
1153
- if (abortListener) {
1163
+ // @ts-expect-error
1164
+ if (abortListener && parentContext) {
1154
1165
  parentContext.abortSignal.removeEventListener('abort', abortListener);
1155
1166
  }
1156
1167
  }
@@ -1282,11 +1293,11 @@ const actionsProviders = [
1282
1293
  multi: true,
1283
1294
  useValue: [tokensCommon.ACTION_EXECUTION_TOKEN, tokensCommon.ACTION_PAGE_RUNNER_TOKEN],
1284
1295
  }),
1285
- {
1296
+ core.provide({
1286
1297
  provide: tokensCommon.COMBINE_REDUCERS,
1287
1298
  multi: true,
1288
1299
  useValue: actionTramvaiReducer,
1289
- },
1300
+ }),
1290
1301
  ];
1291
1302
 
1292
1303
  exports.CommonChildAppModule = class CommonChildAppModule {
@@ -1,20 +1,5 @@
1
- import { COMMAND_LINE_RUNNER_TOKEN } from '@tramvai/core';
2
- export declare const providers: ({
3
- provide: import("@tinkoff/dippy").BaseTokenInterface<{
4
- stores: Record<string, any>;
5
- }>;
6
- useFactory: () => any;
7
- scope: import("@tinkoff/dippy/lib/Provider").ScopeVariants;
8
- deps?: undefined;
9
- multi?: undefined;
10
- } | {
11
- provide: import("@tinkoff/dippy").MultiTokenInterface<import("@tramvai/core").Command>;
12
- useFactory: ({ commandLineRunner, }: {
13
- commandLineRunner: typeof COMMAND_LINE_RUNNER_TOKEN;
14
- }) => () => Promise<import("@tinkoff/dippy").Container>;
15
- deps: {
16
- commandLineRunner: import("@tinkoff/dippy").BaseTokenInterface<import("@tramvai/tokens-core").CommandLine>;
17
- };
18
- multi: boolean;
19
- scope?: undefined;
20
- })[];
1
+ export declare const providers: (import("@tramvai/core").Provider<unknown, import("@tinkoff/dippy").BaseTokenInterface<{
2
+ stores: Record<string, any>;
3
+ }>> | import("@tramvai/core").Provider<{
4
+ commandLineRunner: import("@tinkoff/dippy").BaseTokenInterface<import("@tramvai/tokens-core").CommandLine>;
5
+ }, import("@tinkoff/dippy").MultiTokenInterface<import("@tramvai/core").Command>>)[];
@@ -1 +1 @@
1
- export declare const providers: any[];
1
+ export declare const providers: never[];
@@ -13,8 +13,8 @@ export declare class RequestManager implements Interface {
13
13
  getUrl(): string;
14
14
  getParsedUrl(): Url;
15
15
  getMethod(): string;
16
- getHeader(key: string): string | string[];
17
- getHeaders(): Record<string, string | string[]>;
16
+ getHeader(key: string): string | string[] | undefined;
17
+ getHeaders(): Record<string, string | string[] | undefined>;
18
18
  getCookie(key: string): string;
19
19
  getCookies(): Record<string, string>;
20
20
  getClientIp(): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-common",
3
- "version": "2.36.0",
3
+ "version": "2.37.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -33,27 +33,27 @@
33
33
  "@tinkoff/lru-cache-nano": "^7.8.1",
34
34
  "@tinkoff/pubsub": "0.5.5",
35
35
  "@tinkoff/url": "0.8.4",
36
- "@tramvai/experiments": "2.36.0",
37
- "@tramvai/module-cookie": "2.36.0",
38
- "@tramvai/module-environment": "2.36.0",
39
- "@tramvai/module-log": "2.36.0",
40
- "@tramvai/tokens-child-app": "2.36.0",
41
- "@tramvai/tokens-common": "2.36.0",
42
- "@tramvai/tokens-render": "2.36.0",
43
- "@tramvai/tokens-server-private": "2.36.0",
36
+ "@tramvai/experiments": "2.37.0",
37
+ "@tramvai/module-cookie": "2.37.0",
38
+ "@tramvai/module-environment": "2.37.0",
39
+ "@tramvai/module-log": "2.37.0",
40
+ "@tramvai/tokens-child-app": "2.37.0",
41
+ "@tramvai/tokens-common": "2.37.0",
42
+ "@tramvai/tokens-render": "2.37.0",
43
+ "@tramvai/tokens-server-private": "2.37.0",
44
44
  "hoist-non-react-statics": "^3.3.1",
45
45
  "node-abort-controller": "^3.0.1"
46
46
  },
47
47
  "peerDependencies": {
48
- "@tinkoff/dippy": "0.8.8",
48
+ "@tinkoff/dippy": "0.8.9",
49
49
  "@tinkoff/utils": "^2.1.2",
50
- "@tramvai/cli": "2.36.0",
51
- "@tramvai/core": "2.36.0",
52
- "@tramvai/papi": "2.36.0",
53
- "@tramvai/react": "2.36.0",
54
- "@tramvai/state": "2.36.0",
55
- "@tramvai/tokens-metrics": "2.36.0",
56
- "@tramvai/tokens-server": "2.36.0",
50
+ "@tramvai/cli": "2.37.0",
51
+ "@tramvai/core": "2.37.0",
52
+ "@tramvai/papi": "2.37.0",
53
+ "@tramvai/react": "2.37.0",
54
+ "@tramvai/state": "2.37.0",
55
+ "@tramvai/tokens-metrics": "2.37.0",
56
+ "@tramvai/tokens-server": "2.37.0",
57
57
  "react": ">=16.14.0",
58
58
  "tslib": "^2.4.0"
59
59
  },