@tramvai/module-common 2.11.0 → 2.20.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/actions/actionExecution.d.ts +1 -0
- package/lib/command/commandLineRunner.d.ts +1 -0
- package/lib/index.browser.js +22 -21
- package/lib/index.es.js +22 -21
- package/lib/index.js +21 -21
- package/package.json +20 -20
|
@@ -6,6 +6,7 @@ export declare const getParameters: (action: Action) => ActionParameters<any, an
|
|
|
6
6
|
declare type ExecutionStatus = 'success' | 'failed' | 'pending' | 'forbidden';
|
|
7
7
|
export interface ExecutionState {
|
|
8
8
|
status: ExecutionStatus;
|
|
9
|
+
forbiddenBy?: string;
|
|
9
10
|
state: Record<string, any>;
|
|
10
11
|
}
|
|
11
12
|
declare type TransformAction = <T>(action: T) => T;
|
|
@@ -10,6 +10,7 @@ export declare class CommandLineRunner implements CommandLine {
|
|
|
10
10
|
executionContextManager: typeof EXECUTION_CONTEXT_MANAGER_TOKEN;
|
|
11
11
|
private metricsInstance;
|
|
12
12
|
private executionContextByDi;
|
|
13
|
+
private abortControllerByDi;
|
|
13
14
|
constructor({ lines, rootDi, logger, metrics, executionContextManager, }: {
|
|
14
15
|
lines: CommandLines;
|
|
15
16
|
rootDi: Container;
|
package/lib/index.browser.js
CHANGED
|
@@ -8,9 +8,8 @@ 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, ROOT_EXECUTION_CONTEXT_TOKEN, LOGGER_TOKEN, EXECUTION_CONTEXT_MANAGER_TOKEN, COMMAND_LINE_EXECUTION_CONTEXT_TOKEN, PUBSUB_FACTORY_TOKEN, PUBSUB_TOKEN, ROOT_PUBSUB_TOKEN, INITIAL_APP_STATE_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 { __lazyErrorHandler } from '@tramvai/react';
|
|
11
|
+
import { resolveLazyComponent, __lazyErrorHandler } from '@tramvai/react';
|
|
12
12
|
import { fileSystemPagesEnabled, getAllFileSystemPages, isFileSystemPageComponent } from '@tramvai/experiments';
|
|
13
|
-
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
14
13
|
import pathOr from '@tinkoff/utils/object/pathOr';
|
|
15
14
|
import flatten from '@tinkoff/utils/array/flatten';
|
|
16
15
|
import { createEvent, createReducer, convertAction, createDispatcher, devTools, Provider } from '@tramvai/state';
|
|
@@ -76,24 +75,17 @@ class BundleManager {
|
|
|
76
75
|
// preload `lazy` components then register actions and reducers
|
|
77
76
|
if (pageComponent && bundle.components[pageComponent]) {
|
|
78
77
|
const componentOrLoader = bundle.components[pageComponent];
|
|
79
|
-
const component =
|
|
80
|
-
? (await componentOrLoader.load()).default
|
|
81
|
-
: componentOrLoader;
|
|
82
|
-
// manually hoist static properties from preloaded component to loadable wrapper,
|
|
83
|
-
// this open access to current page component static properties outside before rendering
|
|
84
|
-
if (componentOrLoader !== component) {
|
|
85
|
-
hoistNonReactStatics(componentOrLoader, component);
|
|
86
|
-
}
|
|
78
|
+
const component = await resolveLazyComponent(componentOrLoader);
|
|
87
79
|
// allow page components to register any other components
|
|
88
|
-
if (component
|
|
80
|
+
if ('components' in component) {
|
|
89
81
|
eachObj((cmp, name) => {
|
|
90
82
|
this.componentRegistry.add(name, cmp, pageComponent);
|
|
91
83
|
}, component.components);
|
|
92
84
|
}
|
|
93
|
-
if (component
|
|
85
|
+
if ('actions' in component) {
|
|
94
86
|
this.actionRegistry.add(pageComponent, component.actions);
|
|
95
87
|
}
|
|
96
|
-
if (component
|
|
88
|
+
if ('reducers' in component) {
|
|
97
89
|
component.reducers.forEach((reducer) => {
|
|
98
90
|
this.dispatcher.registerStore(reducer);
|
|
99
91
|
});
|
|
@@ -381,6 +373,7 @@ const resolveDi = (type, status, diContainer, providers) => {
|
|
|
381
373
|
class CommandLineRunner {
|
|
382
374
|
constructor({ lines, rootDi, logger, metrics, executionContextManager, }) {
|
|
383
375
|
this.executionContextByDi = new WeakMap();
|
|
376
|
+
this.abortControllerByDi = new WeakMap();
|
|
384
377
|
this.lines = lines;
|
|
385
378
|
this.rootDi = rootDi;
|
|
386
379
|
this.log = logger('command:command-line-runner');
|
|
@@ -402,8 +395,9 @@ class CommandLineRunner {
|
|
|
402
395
|
// eslint-disable-next-line promise/no-nesting
|
|
403
396
|
return Promise.resolve()
|
|
404
397
|
.then(() => {
|
|
405
|
-
return this.executionContextManager.withContext(rootExecutionContext, `command-line:${line.toString()}`, async (executionContext) => {
|
|
398
|
+
return this.executionContextManager.withContext(rootExecutionContext, `command-line:${line.toString()}`, async (executionContext, abortController) => {
|
|
406
399
|
this.executionContextByDi.set(di, executionContext);
|
|
400
|
+
this.abortControllerByDi.set(di, abortController);
|
|
407
401
|
await this.createLineChain(di, line);
|
|
408
402
|
});
|
|
409
403
|
})
|
|
@@ -413,6 +407,7 @@ class CommandLineRunner {
|
|
|
413
407
|
// После завершения цепочки отдаем context выполнения
|
|
414
408
|
.finally(() => {
|
|
415
409
|
this.executionContextByDi.delete(di);
|
|
410
|
+
this.abortControllerByDi.delete(di);
|
|
416
411
|
})
|
|
417
412
|
.then(() => di));
|
|
418
413
|
}
|
|
@@ -471,12 +466,15 @@ class CommandLineRunner {
|
|
|
471
466
|
return Promise.resolve()
|
|
472
467
|
.then(() => instance())
|
|
473
468
|
.catch((err) => {
|
|
469
|
+
var _a;
|
|
474
470
|
this.log[isSilentError(err) ? 'debug' : 'error']({
|
|
475
471
|
event: 'line-error',
|
|
476
472
|
error: err,
|
|
477
473
|
line: line.toString(),
|
|
478
474
|
command: name,
|
|
479
475
|
});
|
|
476
|
+
// in case if any error happens during line execution results from other line handlers will not be used anyway
|
|
477
|
+
(_a = this.abortControllerByDi.get(di)) === null || _a === void 0 ? void 0 : _a.abort();
|
|
480
478
|
this.throwError(err, di);
|
|
481
479
|
});
|
|
482
480
|
}
|
|
@@ -674,6 +672,7 @@ class ActionChecker {
|
|
|
674
672
|
}
|
|
675
673
|
forbid() {
|
|
676
674
|
this.executionState.status = 'forbidden';
|
|
675
|
+
this.executionState.forbiddenBy = this.key;
|
|
677
676
|
this.forbiddenMarker = true;
|
|
678
677
|
}
|
|
679
678
|
allow() {
|
|
@@ -707,7 +706,7 @@ class ActionExecution {
|
|
|
707
706
|
}
|
|
708
707
|
}
|
|
709
708
|
async runInContext(executionContext, action, ...params) {
|
|
710
|
-
var _a;
|
|
709
|
+
var _a, _b;
|
|
711
710
|
let parameters;
|
|
712
711
|
const payload = (_a = params[0]) !== null && _a !== void 0 ? _a : DEFAULT_PAYLOAD;
|
|
713
712
|
// TODO: replace type with pure context usage
|
|
@@ -724,8 +723,10 @@ class ActionExecution {
|
|
|
724
723
|
if (!this.canExecuteAction(payload, parameters, executionState, type)) {
|
|
725
724
|
switch (parameters.conditionsFailResult) {
|
|
726
725
|
case 'reject':
|
|
727
|
-
|
|
728
|
-
|
|
726
|
+
return Promise.reject(new ConditionFailError({
|
|
727
|
+
conditionName: (_b = executionState.forbiddenBy) !== null && _b !== void 0 ? _b : 'unknown',
|
|
728
|
+
targetName: parameters.name,
|
|
729
|
+
}));
|
|
729
730
|
default:
|
|
730
731
|
return Promise.resolve();
|
|
731
732
|
}
|
|
@@ -734,11 +735,10 @@ class ActionExecution {
|
|
|
734
735
|
return this.executionContextManager.withContext(executionContext, {
|
|
735
736
|
name: parameters.name,
|
|
736
737
|
values: (executionContext === null || executionContext === void 0 ? void 0 : executionContext.values.pageActions) === true ? { pageActions: false } : undefined,
|
|
737
|
-
}, (executionActionContext) => {
|
|
738
|
-
const context = this.createActionContext(executionContext, executionActionContext, parameters);
|
|
738
|
+
}, (executionActionContext, abortController) => {
|
|
739
|
+
const context = this.createActionContext(executionContext, executionActionContext, abortController, parameters);
|
|
739
740
|
return Promise.resolve()
|
|
740
741
|
.then(() => {
|
|
741
|
-
// TODO: do not execute action if context.abortSignal is aborted
|
|
742
742
|
if (isTramvaiAction(action)) {
|
|
743
743
|
return action.fn.apply(context, params);
|
|
744
744
|
}
|
|
@@ -770,8 +770,9 @@ class ActionExecution {
|
|
|
770
770
|
const actionChecker = new ActionChecker(this.actionConditionals, payload, parameters, executionState, type);
|
|
771
771
|
return actionChecker.check();
|
|
772
772
|
}
|
|
773
|
-
createActionContext(parentExecutionContext, actionExecutionContext, parameters) {
|
|
773
|
+
createActionContext(parentExecutionContext, actionExecutionContext, abortController, parameters) {
|
|
774
774
|
return {
|
|
775
|
+
abortController,
|
|
775
776
|
abortSignal: actionExecutionContext === null || actionExecutionContext === void 0 ? void 0 : actionExecutionContext.abortSignal,
|
|
776
777
|
executeAction: this.runInContext.bind(this, actionExecutionContext),
|
|
777
778
|
deps: parameters.deps ? this.di.getOfDeps(parameters.deps) : EMPTY_DEPS,
|
package/lib/index.es.js
CHANGED
|
@@ -8,9 +8,8 @@ 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, ROOT_EXECUTION_CONTEXT_TOKEN, LOGGER_TOKEN, EXECUTION_CONTEXT_MANAGER_TOKEN, COMMAND_LINE_EXECUTION_CONTEXT_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, INITIAL_APP_STATE_TOKEN, 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 { __lazyErrorHandler } from '@tramvai/react';
|
|
11
|
+
import { resolveLazyComponent, __lazyErrorHandler } from '@tramvai/react';
|
|
12
12
|
import { fileSystemPagesEnabled, getAllFileSystemPages, isFileSystemPageComponent } from '@tramvai/experiments';
|
|
13
|
-
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
14
13
|
import pathOr from '@tinkoff/utils/object/pathOr';
|
|
15
14
|
import flatten from '@tinkoff/utils/array/flatten';
|
|
16
15
|
import { createEvent, createReducer, convertAction, createDispatcher, devTools, Provider } from '@tramvai/state';
|
|
@@ -78,24 +77,17 @@ class BundleManager {
|
|
|
78
77
|
// preload `lazy` components then register actions and reducers
|
|
79
78
|
if (pageComponent && bundle.components[pageComponent]) {
|
|
80
79
|
const componentOrLoader = bundle.components[pageComponent];
|
|
81
|
-
const component =
|
|
82
|
-
? (await componentOrLoader.load()).default
|
|
83
|
-
: componentOrLoader;
|
|
84
|
-
// manually hoist static properties from preloaded component to loadable wrapper,
|
|
85
|
-
// this open access to current page component static properties outside before rendering
|
|
86
|
-
if (componentOrLoader !== component) {
|
|
87
|
-
hoistNonReactStatics(componentOrLoader, component);
|
|
88
|
-
}
|
|
80
|
+
const component = await resolveLazyComponent(componentOrLoader);
|
|
89
81
|
// allow page components to register any other components
|
|
90
|
-
if (component
|
|
82
|
+
if ('components' in component) {
|
|
91
83
|
eachObj((cmp, name) => {
|
|
92
84
|
this.componentRegistry.add(name, cmp, pageComponent);
|
|
93
85
|
}, component.components);
|
|
94
86
|
}
|
|
95
|
-
if (component
|
|
87
|
+
if ('actions' in component) {
|
|
96
88
|
this.actionRegistry.add(pageComponent, component.actions);
|
|
97
89
|
}
|
|
98
|
-
if (component
|
|
90
|
+
if ('reducers' in component) {
|
|
99
91
|
component.reducers.forEach((reducer) => {
|
|
100
92
|
this.dispatcher.registerStore(reducer);
|
|
101
93
|
});
|
|
@@ -378,6 +370,7 @@ const resolveDi = (type, status, diContainer, providers) => {
|
|
|
378
370
|
class CommandLineRunner {
|
|
379
371
|
constructor({ lines, rootDi, logger, metrics, executionContextManager, }) {
|
|
380
372
|
this.executionContextByDi = new WeakMap();
|
|
373
|
+
this.abortControllerByDi = new WeakMap();
|
|
381
374
|
this.lines = lines;
|
|
382
375
|
this.rootDi = rootDi;
|
|
383
376
|
this.log = logger('command:command-line-runner');
|
|
@@ -399,8 +392,9 @@ class CommandLineRunner {
|
|
|
399
392
|
// eslint-disable-next-line promise/no-nesting
|
|
400
393
|
return Promise.resolve()
|
|
401
394
|
.then(() => {
|
|
402
|
-
return this.executionContextManager.withContext(rootExecutionContext, `command-line:${line.toString()}`, async (executionContext) => {
|
|
395
|
+
return this.executionContextManager.withContext(rootExecutionContext, `command-line:${line.toString()}`, async (executionContext, abortController) => {
|
|
403
396
|
this.executionContextByDi.set(di, executionContext);
|
|
397
|
+
this.abortControllerByDi.set(di, abortController);
|
|
404
398
|
await this.createLineChain(di, line);
|
|
405
399
|
});
|
|
406
400
|
})
|
|
@@ -410,6 +404,7 @@ class CommandLineRunner {
|
|
|
410
404
|
// После завершения цепочки отдаем context выполнения
|
|
411
405
|
.finally(() => {
|
|
412
406
|
this.executionContextByDi.delete(di);
|
|
407
|
+
this.abortControllerByDi.delete(di);
|
|
413
408
|
})
|
|
414
409
|
.then(() => di));
|
|
415
410
|
}
|
|
@@ -468,12 +463,15 @@ class CommandLineRunner {
|
|
|
468
463
|
return Promise.resolve()
|
|
469
464
|
.then(() => instance())
|
|
470
465
|
.catch((err) => {
|
|
466
|
+
var _a;
|
|
471
467
|
this.log[isSilentError(err) ? 'debug' : 'error']({
|
|
472
468
|
event: 'line-error',
|
|
473
469
|
error: err,
|
|
474
470
|
line: line.toString(),
|
|
475
471
|
command: name,
|
|
476
472
|
});
|
|
473
|
+
// in case if any error happens during line execution results from other line handlers will not be used anyway
|
|
474
|
+
(_a = this.abortControllerByDi.get(di)) === null || _a === void 0 ? void 0 : _a.abort();
|
|
477
475
|
this.throwError(err, di);
|
|
478
476
|
});
|
|
479
477
|
}
|
|
@@ -655,6 +653,7 @@ class ActionChecker {
|
|
|
655
653
|
}
|
|
656
654
|
forbid() {
|
|
657
655
|
this.executionState.status = 'forbidden';
|
|
656
|
+
this.executionState.forbiddenBy = this.key;
|
|
658
657
|
this.forbiddenMarker = true;
|
|
659
658
|
}
|
|
660
659
|
allow() {
|
|
@@ -688,7 +687,7 @@ class ActionExecution {
|
|
|
688
687
|
}
|
|
689
688
|
}
|
|
690
689
|
async runInContext(executionContext, action, ...params) {
|
|
691
|
-
var _a;
|
|
690
|
+
var _a, _b;
|
|
692
691
|
let parameters;
|
|
693
692
|
const payload = (_a = params[0]) !== null && _a !== void 0 ? _a : DEFAULT_PAYLOAD;
|
|
694
693
|
// TODO: replace type with pure context usage
|
|
@@ -705,8 +704,10 @@ class ActionExecution {
|
|
|
705
704
|
if (!this.canExecuteAction(payload, parameters, executionState, type)) {
|
|
706
705
|
switch (parameters.conditionsFailResult) {
|
|
707
706
|
case 'reject':
|
|
708
|
-
|
|
709
|
-
|
|
707
|
+
return Promise.reject(new ConditionFailError({
|
|
708
|
+
conditionName: (_b = executionState.forbiddenBy) !== null && _b !== void 0 ? _b : 'unknown',
|
|
709
|
+
targetName: parameters.name,
|
|
710
|
+
}));
|
|
710
711
|
default:
|
|
711
712
|
return Promise.resolve();
|
|
712
713
|
}
|
|
@@ -715,11 +716,10 @@ class ActionExecution {
|
|
|
715
716
|
return this.executionContextManager.withContext(executionContext, {
|
|
716
717
|
name: parameters.name,
|
|
717
718
|
values: (executionContext === null || executionContext === void 0 ? void 0 : executionContext.values.pageActions) === true ? { pageActions: false } : undefined,
|
|
718
|
-
}, (executionActionContext) => {
|
|
719
|
-
const context = this.createActionContext(executionContext, executionActionContext, parameters);
|
|
719
|
+
}, (executionActionContext, abortController) => {
|
|
720
|
+
const context = this.createActionContext(executionContext, executionActionContext, abortController, parameters);
|
|
720
721
|
return Promise.resolve()
|
|
721
722
|
.then(() => {
|
|
722
|
-
// TODO: do not execute action if context.abortSignal is aborted
|
|
723
723
|
if (isTramvaiAction(action)) {
|
|
724
724
|
return action.fn.apply(context, params);
|
|
725
725
|
}
|
|
@@ -751,8 +751,9 @@ class ActionExecution {
|
|
|
751
751
|
const actionChecker = new ActionChecker(this.actionConditionals, payload, parameters, executionState, type);
|
|
752
752
|
return actionChecker.check();
|
|
753
753
|
}
|
|
754
|
-
createActionContext(parentExecutionContext, actionExecutionContext, parameters) {
|
|
754
|
+
createActionContext(parentExecutionContext, actionExecutionContext, abortController, parameters) {
|
|
755
755
|
return {
|
|
756
|
+
abortController,
|
|
756
757
|
abortSignal: actionExecutionContext === null || actionExecutionContext === void 0 ? void 0 : actionExecutionContext.abortSignal,
|
|
757
758
|
executeAction: this.runInContext.bind(this, actionExecutionContext),
|
|
758
759
|
deps: parameters.deps ? this.di.getOfDeps(parameters.deps) : EMPTY_DEPS,
|
package/lib/index.js
CHANGED
|
@@ -12,7 +12,6 @@ var hookRunner = require('@tinkoff/hook-runner');
|
|
|
12
12
|
var tokensCommon = require('@tramvai/tokens-common');
|
|
13
13
|
var react = require('@tramvai/react');
|
|
14
14
|
var experiments = require('@tramvai/experiments');
|
|
15
|
-
var hoistNonReactStatics = require('hoist-non-react-statics');
|
|
16
15
|
var pathOr = require('@tinkoff/utils/object/pathOr');
|
|
17
16
|
var flatten = require('@tinkoff/utils/array/flatten');
|
|
18
17
|
var state = require('@tramvai/state');
|
|
@@ -40,7 +39,6 @@ var tokensChildApp = require('@tramvai/tokens-child-app');
|
|
|
40
39
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
41
40
|
|
|
42
41
|
var eachObj__default = /*#__PURE__*/_interopDefaultLegacy(eachObj);
|
|
43
|
-
var hoistNonReactStatics__default = /*#__PURE__*/_interopDefaultLegacy(hoistNonReactStatics);
|
|
44
42
|
var pathOr__default = /*#__PURE__*/_interopDefaultLegacy(pathOr);
|
|
45
43
|
var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
|
|
46
44
|
var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
|
|
@@ -96,24 +94,17 @@ class BundleManager {
|
|
|
96
94
|
// preload `lazy` components then register actions and reducers
|
|
97
95
|
if (pageComponent && bundle.components[pageComponent]) {
|
|
98
96
|
const componentOrLoader = bundle.components[pageComponent];
|
|
99
|
-
const component =
|
|
100
|
-
? (await componentOrLoader.load()).default
|
|
101
|
-
: componentOrLoader;
|
|
102
|
-
// manually hoist static properties from preloaded component to loadable wrapper,
|
|
103
|
-
// this open access to current page component static properties outside before rendering
|
|
104
|
-
if (componentOrLoader !== component) {
|
|
105
|
-
hoistNonReactStatics__default["default"](componentOrLoader, component);
|
|
106
|
-
}
|
|
97
|
+
const component = await react.resolveLazyComponent(componentOrLoader);
|
|
107
98
|
// allow page components to register any other components
|
|
108
|
-
if (component
|
|
99
|
+
if ('components' in component) {
|
|
109
100
|
eachObj__default["default"]((cmp, name) => {
|
|
110
101
|
this.componentRegistry.add(name, cmp, pageComponent);
|
|
111
102
|
}, component.components);
|
|
112
103
|
}
|
|
113
|
-
if (component
|
|
104
|
+
if ('actions' in component) {
|
|
114
105
|
this.actionRegistry.add(pageComponent, component.actions);
|
|
115
106
|
}
|
|
116
|
-
if (component
|
|
107
|
+
if ('reducers' in component) {
|
|
117
108
|
component.reducers.forEach((reducer) => {
|
|
118
109
|
this.dispatcher.registerStore(reducer);
|
|
119
110
|
});
|
|
@@ -396,6 +387,7 @@ const resolveDi = (type, status, diContainer, providers) => {
|
|
|
396
387
|
class CommandLineRunner {
|
|
397
388
|
constructor({ lines, rootDi, logger, metrics, executionContextManager, }) {
|
|
398
389
|
this.executionContextByDi = new WeakMap();
|
|
390
|
+
this.abortControllerByDi = new WeakMap();
|
|
399
391
|
this.lines = lines;
|
|
400
392
|
this.rootDi = rootDi;
|
|
401
393
|
this.log = logger('command:command-line-runner');
|
|
@@ -417,8 +409,9 @@ class CommandLineRunner {
|
|
|
417
409
|
// eslint-disable-next-line promise/no-nesting
|
|
418
410
|
return Promise.resolve()
|
|
419
411
|
.then(() => {
|
|
420
|
-
return this.executionContextManager.withContext(rootExecutionContext, `command-line:${line.toString()}`, async (executionContext) => {
|
|
412
|
+
return this.executionContextManager.withContext(rootExecutionContext, `command-line:${line.toString()}`, async (executionContext, abortController) => {
|
|
421
413
|
this.executionContextByDi.set(di, executionContext);
|
|
414
|
+
this.abortControllerByDi.set(di, abortController);
|
|
422
415
|
await this.createLineChain(di, line);
|
|
423
416
|
});
|
|
424
417
|
})
|
|
@@ -428,6 +421,7 @@ class CommandLineRunner {
|
|
|
428
421
|
// После завершения цепочки отдаем context выполнения
|
|
429
422
|
.finally(() => {
|
|
430
423
|
this.executionContextByDi.delete(di);
|
|
424
|
+
this.abortControllerByDi.delete(di);
|
|
431
425
|
})
|
|
432
426
|
.then(() => di));
|
|
433
427
|
}
|
|
@@ -486,12 +480,15 @@ class CommandLineRunner {
|
|
|
486
480
|
return Promise.resolve()
|
|
487
481
|
.then(() => instance())
|
|
488
482
|
.catch((err) => {
|
|
483
|
+
var _a;
|
|
489
484
|
this.log[errors.isSilentError(err) ? 'debug' : 'error']({
|
|
490
485
|
event: 'line-error',
|
|
491
486
|
error: err,
|
|
492
487
|
line: line.toString(),
|
|
493
488
|
command: name,
|
|
494
489
|
});
|
|
490
|
+
// in case if any error happens during line execution results from other line handlers will not be used anyway
|
|
491
|
+
(_a = this.abortControllerByDi.get(di)) === null || _a === void 0 ? void 0 : _a.abort();
|
|
495
492
|
this.throwError(err, di);
|
|
496
493
|
});
|
|
497
494
|
}
|
|
@@ -673,6 +670,7 @@ class ActionChecker {
|
|
|
673
670
|
}
|
|
674
671
|
forbid() {
|
|
675
672
|
this.executionState.status = 'forbidden';
|
|
673
|
+
this.executionState.forbiddenBy = this.key;
|
|
676
674
|
this.forbiddenMarker = true;
|
|
677
675
|
}
|
|
678
676
|
allow() {
|
|
@@ -706,7 +704,7 @@ class ActionExecution {
|
|
|
706
704
|
}
|
|
707
705
|
}
|
|
708
706
|
async runInContext(executionContext, action, ...params) {
|
|
709
|
-
var _a;
|
|
707
|
+
var _a, _b;
|
|
710
708
|
let parameters;
|
|
711
709
|
const payload = (_a = params[0]) !== null && _a !== void 0 ? _a : DEFAULT_PAYLOAD;
|
|
712
710
|
// TODO: replace type with pure context usage
|
|
@@ -723,8 +721,10 @@ class ActionExecution {
|
|
|
723
721
|
if (!this.canExecuteAction(payload, parameters, executionState, type)) {
|
|
724
722
|
switch (parameters.conditionsFailResult) {
|
|
725
723
|
case 'reject':
|
|
726
|
-
|
|
727
|
-
|
|
724
|
+
return Promise.reject(new errors.ConditionFailError({
|
|
725
|
+
conditionName: (_b = executionState.forbiddenBy) !== null && _b !== void 0 ? _b : 'unknown',
|
|
726
|
+
targetName: parameters.name,
|
|
727
|
+
}));
|
|
728
728
|
default:
|
|
729
729
|
return Promise.resolve();
|
|
730
730
|
}
|
|
@@ -733,11 +733,10 @@ class ActionExecution {
|
|
|
733
733
|
return this.executionContextManager.withContext(executionContext, {
|
|
734
734
|
name: parameters.name,
|
|
735
735
|
values: (executionContext === null || executionContext === void 0 ? void 0 : executionContext.values.pageActions) === true ? { pageActions: false } : undefined,
|
|
736
|
-
}, (executionActionContext) => {
|
|
737
|
-
const context = this.createActionContext(executionContext, executionActionContext, parameters);
|
|
736
|
+
}, (executionActionContext, abortController) => {
|
|
737
|
+
const context = this.createActionContext(executionContext, executionActionContext, abortController, parameters);
|
|
738
738
|
return Promise.resolve()
|
|
739
739
|
.then(() => {
|
|
740
|
-
// TODO: do not execute action if context.abortSignal is aborted
|
|
741
740
|
if (core.isTramvaiAction(action)) {
|
|
742
741
|
return action.fn.apply(context, params);
|
|
743
742
|
}
|
|
@@ -769,8 +768,9 @@ class ActionExecution {
|
|
|
769
768
|
const actionChecker = new ActionChecker(this.actionConditionals, payload, parameters, executionState, type);
|
|
770
769
|
return actionChecker.check();
|
|
771
770
|
}
|
|
772
|
-
createActionContext(parentExecutionContext, actionExecutionContext, parameters) {
|
|
771
|
+
createActionContext(parentExecutionContext, actionExecutionContext, abortController, parameters) {
|
|
773
772
|
return {
|
|
773
|
+
abortController,
|
|
774
774
|
abortSignal: actionExecutionContext === null || actionExecutionContext === void 0 ? void 0 : actionExecutionContext.abortSignal,
|
|
775
775
|
executeAction: this.runInContext.bind(this, actionExecutionContext),
|
|
776
776
|
deps: parameters.deps ? this.di.getOfDeps(parameters.deps) : EMPTY_DEPS,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-common",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -28,31 +28,31 @@
|
|
|
28
28
|
"build-for-publish": "true"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@tinkoff/errors": "0.2
|
|
32
|
-
"@tinkoff/hook-runner": "0.
|
|
31
|
+
"@tinkoff/errors": "0.3.2",
|
|
32
|
+
"@tinkoff/hook-runner": "0.4.2",
|
|
33
33
|
"@tinkoff/lru-cache-nano": "^7.8.1",
|
|
34
|
-
"@tinkoff/pubsub": "0.
|
|
35
|
-
"@tinkoff/url": "0.
|
|
36
|
-
"@tramvai/experiments": "2.
|
|
37
|
-
"@tramvai/module-cookie": "2.
|
|
38
|
-
"@tramvai/module-environment": "2.
|
|
39
|
-
"@tramvai/module-log": "2.
|
|
40
|
-
"@tramvai/tokens-child-app": "2.
|
|
41
|
-
"@tramvai/tokens-common": "2.
|
|
42
|
-
"@tramvai/tokens-render": "2.
|
|
34
|
+
"@tinkoff/pubsub": "0.5.2",
|
|
35
|
+
"@tinkoff/url": "0.8.2",
|
|
36
|
+
"@tramvai/experiments": "2.20.0",
|
|
37
|
+
"@tramvai/module-cookie": "2.20.0",
|
|
38
|
+
"@tramvai/module-environment": "2.20.0",
|
|
39
|
+
"@tramvai/module-log": "2.20.0",
|
|
40
|
+
"@tramvai/tokens-child-app": "2.20.0",
|
|
41
|
+
"@tramvai/tokens-common": "2.20.0",
|
|
42
|
+
"@tramvai/tokens-render": "2.20.0",
|
|
43
43
|
"hoist-non-react-statics": "^3.3.1",
|
|
44
44
|
"node-abort-controller": "^3.0.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@tinkoff/dippy": "0.
|
|
47
|
+
"@tinkoff/dippy": "0.8.2",
|
|
48
48
|
"@tinkoff/utils": "^2.1.2",
|
|
49
|
-
"@tramvai/cli": "2.
|
|
50
|
-
"@tramvai/core": "2.
|
|
51
|
-
"@tramvai/papi": "2.
|
|
52
|
-
"@tramvai/react": "2.
|
|
53
|
-
"@tramvai/state": "2.
|
|
54
|
-
"@tramvai/tokens-metrics": "2.
|
|
55
|
-
"@tramvai/tokens-server": "2.
|
|
49
|
+
"@tramvai/cli": "2.20.0",
|
|
50
|
+
"@tramvai/core": "2.20.0",
|
|
51
|
+
"@tramvai/papi": "2.20.0",
|
|
52
|
+
"@tramvai/react": "2.20.0",
|
|
53
|
+
"@tramvai/state": "2.20.0",
|
|
54
|
+
"@tramvai/tokens-metrics": "2.20.0",
|
|
55
|
+
"@tramvai/tokens-server": "2.20.0",
|
|
56
56
|
"react": ">=16.14.0",
|
|
57
57
|
"tslib": "^2.0.3"
|
|
58
58
|
},
|