@tramvai/module-common 2.70.1 → 2.72.3
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/CommonModule.browser.js +100 -0
- package/lib/CommonModule.es.js +100 -0
- package/lib/CommonModule.js +106 -0
- package/lib/actions/ActionModule.browser.js +79 -0
- package/lib/actions/ActionModule.es.js +79 -0
- package/lib/actions/ActionModule.js +82 -0
- package/lib/actions/actionChecker.browser.js +52 -0
- package/lib/actions/actionChecker.es.js +52 -0
- package/lib/actions/actionChecker.js +56 -0
- package/lib/actions/actionExecution.browser.js +107 -0
- package/lib/actions/actionExecution.es.js +107 -0
- package/lib/actions/actionExecution.js +118 -0
- package/lib/actions/actionPageRunner.browser.browser.js +33 -0
- package/lib/actions/actionPageRunner.es.js +61 -0
- package/lib/actions/actionPageRunner.js +65 -0
- package/lib/actions/actionRegistry.browser.js +33 -0
- package/lib/actions/actionRegistry.es.js +33 -0
- package/lib/actions/actionRegistry.js +45 -0
- package/lib/actions/actionTramvaiReducer.browser.js +10 -0
- package/lib/actions/actionTramvaiReducer.es.js +10 -0
- package/lib/actions/actionTramvaiReducer.js +15 -0
- package/lib/actions/conditions/always.browser.js +10 -0
- package/lib/actions/conditions/always.es.js +10 -0
- package/lib/actions/conditions/always.js +14 -0
- package/lib/actions/conditions/helpers.browser.js +4 -0
- package/lib/actions/conditions/helpers.es.js +4 -0
- package/lib/actions/conditions/helpers.js +9 -0
- package/lib/actions/conditions/onlyBrowser.browser.js +12 -0
- package/lib/actions/conditions/onlyBrowser.es.js +12 -0
- package/lib/actions/conditions/onlyBrowser.js +16 -0
- package/lib/actions/conditions/onlyServer.browser.js +12 -0
- package/lib/actions/conditions/onlyServer.es.js +12 -0
- package/lib/actions/conditions/onlyServer.js +16 -0
- package/lib/actions/conditions/pageBrowser.browser.js +13 -0
- package/lib/actions/conditions/pageBrowser.es.js +13 -0
- package/lib/actions/conditions/pageBrowser.js +17 -0
- package/lib/actions/conditions/pageServer.browser.js +13 -0
- package/lib/actions/conditions/pageServer.es.js +13 -0
- package/lib/actions/conditions/pageServer.js +17 -0
- package/lib/actions/constants.browser.js +9 -0
- package/lib/actions/constants.es.js +9 -0
- package/lib/actions/constants.js +13 -0
- package/lib/bundleManager/bundleManager.browser.js +105 -0
- package/lib/bundleManager/bundleManager.es.js +105 -0
- package/lib/bundleManager/bundleManager.js +115 -0
- package/lib/cache/CacheModule.browser.js +58 -0
- package/lib/cache/CacheModule.es.js +58 -0
- package/lib/cache/CacheModule.js +62 -0
- package/lib/cache/cacheFactory.browser.js +7 -0
- package/lib/cache/cacheFactory.es.js +7 -0
- package/lib/cache/cacheFactory.js +15 -0
- package/lib/cache/clientProviders.browser.js +3 -0
- package/lib/cache/papi.es.js +18 -0
- package/lib/cache/papi.js +22 -0
- package/lib/cache/serverProviders.es.js +18 -0
- package/lib/cache/serverProviders.js +22 -0
- package/lib/child-app/ChildAppModule.browser.js +38 -0
- package/lib/child-app/ChildAppModule.es.js +38 -0
- package/lib/child-app/ChildAppModule.js +40 -0
- package/lib/child-app/actions.browser.js +19 -0
- package/lib/child-app/actions.es.js +19 -0
- package/lib/child-app/actions.js +23 -0
- package/lib/child-app/clientProviders.browser.js +18 -0
- package/lib/child-app/command.browser.js +35 -0
- package/lib/child-app/command.es.js +35 -0
- package/lib/child-app/command.js +40 -0
- package/lib/child-app/serverProviders.es.js +3 -0
- package/lib/child-app/serverProviders.js +7 -0
- package/lib/child-app/state.browser.js +13 -0
- package/lib/child-app/state.es.js +13 -0
- package/lib/child-app/state.js +17 -0
- package/lib/command/CommandModule.browser.js +52 -0
- package/lib/command/CommandModule.es.js +52 -0
- package/lib/command/CommandModule.js +54 -0
- package/lib/command/commandLineRunner.browser.js +147 -0
- package/lib/command/commandLineRunner.es.js +147 -0
- package/lib/command/commandLineRunner.js +151 -0
- package/lib/command/defaultLines.browser.js +25 -0
- package/lib/command/defaultLines.es.js +25 -0
- package/lib/command/defaultLines.js +29 -0
- package/lib/componentRegistry/componentRegistry.browser.js +25 -0
- package/lib/componentRegistry/componentRegistry.es.js +25 -0
- package/lib/componentRegistry/componentRegistry.js +34 -0
- package/lib/createConsumerContext/createConsumerContext.browser.js +62 -0
- package/lib/createConsumerContext/createConsumerContext.es.js +62 -0
- package/lib/createConsumerContext/createConsumerContext.js +67 -0
- package/lib/executionContext/executionContextManager.browser.js +57 -0
- package/lib/executionContext/executionContextManager.es.js +57 -0
- package/lib/executionContext/executionContextManager.js +61 -0
- package/lib/index.browser.js +13 -1300
- package/lib/index.es.js +13 -1318
- package/lib/index.js +38 -1341
- package/lib/providers/clientProviders.browser.js +22 -0
- package/lib/providers/serverProviders.es.js +3 -0
- package/lib/providers/serverProviders.js +7 -0
- package/lib/pubsub/PubSubModule.browser.js +44 -0
- package/lib/pubsub/PubSubModule.es.js +44 -0
- package/lib/pubsub/PubSubModule.js +46 -0
- package/lib/requestManager/RequestManagerModule.browser.browser.js +38 -0
- package/lib/requestManager/RequestManagerModule.es.js +35 -0
- package/lib/requestManager/RequestManagerModule.js +37 -0
- package/lib/requestManager/RequestManagerStore.browser.js +8 -0
- package/lib/requestManager/RequestManagerStore.es.js +8 -0
- package/lib/requestManager/RequestManagerStore.js +13 -0
- package/lib/requestManager/requestManager.browser.js +57 -0
- package/lib/requestManager/requestManager.es.js +57 -0
- package/lib/requestManager/requestManager.js +61 -0
- package/lib/requestManager/sharedProviders.browser.js +23 -0
- package/lib/requestManager/sharedProviders.es.js +23 -0
- package/lib/requestManager/sharedProviders.js +27 -0
- package/lib/responseManager/ResponseManagerModule.browser.browser.js +21 -0
- package/lib/responseManager/ResponseManagerModule.es.js +13 -0
- package/lib/responseManager/ResponseManagerModule.js +15 -0
- package/lib/responseManager/responseManager.browser.js +52 -0
- package/lib/responseManager/responseManager.es.js +52 -0
- package/lib/responseManager/responseManager.js +61 -0
- package/lib/responseManager/sharedProviders.browser.js +13 -0
- package/lib/responseManager/sharedProviders.es.js +13 -0
- package/lib/responseManager/sharedProviders.js +17 -0
- package/lib/state/StateModule.browser.js +54 -0
- package/lib/state/StateModule.es.js +54 -0
- package/lib/state/StateModule.js +60 -0
- package/package.json +24 -25
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@tramvai/core');
|
|
6
|
+
|
|
7
|
+
const command = {
|
|
8
|
+
init: [core.commandLineListTokens.init, core.commandLineListTokens.listen],
|
|
9
|
+
close: [core.commandLineListTokens.close],
|
|
10
|
+
customer: [
|
|
11
|
+
core.commandLineListTokens.customerStart,
|
|
12
|
+
core.commandLineListTokens.resolveUserDeps,
|
|
13
|
+
core.commandLineListTokens.resolvePageDeps,
|
|
14
|
+
core.commandLineListTokens.generatePage,
|
|
15
|
+
core.commandLineListTokens.clear,
|
|
16
|
+
],
|
|
17
|
+
spa: [
|
|
18
|
+
core.commandLineListTokens.resolveUserDeps,
|
|
19
|
+
core.commandLineListTokens.resolvePageDeps,
|
|
20
|
+
core.commandLineListTokens.spaTransition,
|
|
21
|
+
],
|
|
22
|
+
afterSpa: [core.commandLineListTokens.afterSpaTransition],
|
|
23
|
+
};
|
|
24
|
+
const lines = {
|
|
25
|
+
server: command,
|
|
26
|
+
client: command,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.lines = lines;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import pathOr from '@tinkoff/utils/object/pathOr';
|
|
2
|
+
import flatten from '@tinkoff/utils/array/flatten';
|
|
3
|
+
|
|
4
|
+
const DEFAULT_GROUP = '__default';
|
|
5
|
+
class ComponentRegistry {
|
|
6
|
+
constructor({ componentList } = {}) {
|
|
7
|
+
this.components = {
|
|
8
|
+
[DEFAULT_GROUP]: Object.assign({}, ...flatten(componentList !== null && componentList !== void 0 ? componentList : [])),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
add(name, component, group = DEFAULT_GROUP) {
|
|
12
|
+
const groupComponents = this.components[group] || {};
|
|
13
|
+
groupComponents[name] = component;
|
|
14
|
+
this.components[group] = groupComponents;
|
|
15
|
+
}
|
|
16
|
+
get(name, group = DEFAULT_GROUP) {
|
|
17
|
+
const groupComponents = this.components[group] || {};
|
|
18
|
+
return groupComponents[name] || this.components[DEFAULT_GROUP][name];
|
|
19
|
+
}
|
|
20
|
+
getComponentParam(param, defaultValue, component, group) {
|
|
21
|
+
return pathOr([param], defaultValue, this.get(component, group));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { ComponentRegistry };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import pathOr from '@tinkoff/utils/object/pathOr';
|
|
2
|
+
import flatten from '@tinkoff/utils/array/flatten';
|
|
3
|
+
|
|
4
|
+
const DEFAULT_GROUP = '__default';
|
|
5
|
+
class ComponentRegistry {
|
|
6
|
+
constructor({ componentList } = {}) {
|
|
7
|
+
this.components = {
|
|
8
|
+
[DEFAULT_GROUP]: Object.assign({}, ...flatten(componentList !== null && componentList !== void 0 ? componentList : [])),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
add(name, component, group = DEFAULT_GROUP) {
|
|
12
|
+
const groupComponents = this.components[group] || {};
|
|
13
|
+
groupComponents[name] = component;
|
|
14
|
+
this.components[group] = groupComponents;
|
|
15
|
+
}
|
|
16
|
+
get(name, group = DEFAULT_GROUP) {
|
|
17
|
+
const groupComponents = this.components[group] || {};
|
|
18
|
+
return groupComponents[name] || this.components[DEFAULT_GROUP][name];
|
|
19
|
+
}
|
|
20
|
+
getComponentParam(param, defaultValue, component, group) {
|
|
21
|
+
return pathOr([param], defaultValue, this.get(component, group));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { ComponentRegistry };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var pathOr = require('@tinkoff/utils/object/pathOr');
|
|
6
|
+
var flatten = require('@tinkoff/utils/array/flatten');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var pathOr__default = /*#__PURE__*/_interopDefaultLegacy(pathOr);
|
|
11
|
+
var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
|
|
12
|
+
|
|
13
|
+
const DEFAULT_GROUP = '__default';
|
|
14
|
+
class ComponentRegistry {
|
|
15
|
+
constructor({ componentList } = {}) {
|
|
16
|
+
this.components = {
|
|
17
|
+
[DEFAULT_GROUP]: Object.assign({}, ...flatten__default["default"](componentList !== null && componentList !== void 0 ? componentList : [])),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
add(name, component, group = DEFAULT_GROUP) {
|
|
21
|
+
const groupComponents = this.components[group] || {};
|
|
22
|
+
groupComponents[name] = component;
|
|
23
|
+
this.components[group] = groupComponents;
|
|
24
|
+
}
|
|
25
|
+
get(name, group = DEFAULT_GROUP) {
|
|
26
|
+
const groupComponents = this.components[group] || {};
|
|
27
|
+
return groupComponents[name] || this.components[DEFAULT_GROUP][name];
|
|
28
|
+
}
|
|
29
|
+
getComponentParam(param, defaultValue, component, group) {
|
|
30
|
+
return pathOr__default["default"]([param], defaultValue, this.get(component, group));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.ComponentRegistry = ComponentRegistry;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { convertAction } from '@tramvai/state';
|
|
2
|
+
import { ACTION_EXECUTION_TOKEN } from '@tramvai/tokens-common';
|
|
3
|
+
|
|
4
|
+
class ConsumerContext {
|
|
5
|
+
constructor({ di, dispatcherContext, pubsub, store }) {
|
|
6
|
+
/* Side Effects */
|
|
7
|
+
this.executeAction = (action, payload) => {
|
|
8
|
+
return this.di.get(ACTION_EXECUTION_TOKEN).run(action, payload);
|
|
9
|
+
};
|
|
10
|
+
/* State manager */
|
|
11
|
+
this.dispatch = (actionOrNameEvent, payload) => {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
try {
|
|
14
|
+
resolve(this.store.dispatch(convertAction(actionOrNameEvent, payload)));
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
reject(err);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
this.dispatchWith = (createActionOrType, options) => {
|
|
22
|
+
return typeof createActionOrType === 'function'
|
|
23
|
+
? (...args) => this.dispatch(createActionOrType(...args), options)
|
|
24
|
+
: (payload) => this.dispatch(createActionOrType, payload);
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated
|
|
28
|
+
*/
|
|
29
|
+
this.getStore = (store) => {
|
|
30
|
+
return this.dispatcher.getStore(store);
|
|
31
|
+
};
|
|
32
|
+
this.dehydrate = () => ({
|
|
33
|
+
dispatcher: this.dispatcher.dehydrate(),
|
|
34
|
+
});
|
|
35
|
+
this.getState = (...args) => {
|
|
36
|
+
return this.store.getState(args[0]);
|
|
37
|
+
};
|
|
38
|
+
this.subscribe = (...args) => {
|
|
39
|
+
return this.store.subscribe(args[0], args[1]);
|
|
40
|
+
};
|
|
41
|
+
this.hasStore = (store) => this.dispatcher.hasStore(store);
|
|
42
|
+
this.registerStore = (store) => this.dispatcher.registerStore(store);
|
|
43
|
+
this.unregisterStore = (store) => this.dispatcher.unregisterStore(store);
|
|
44
|
+
this.store = store;
|
|
45
|
+
// @ts-expect-error
|
|
46
|
+
this.dispatcher = dispatcherContext;
|
|
47
|
+
// TODO убрать, нужно для некоторых старых сторов на платформе
|
|
48
|
+
this.dispatcher.setContext(this);
|
|
49
|
+
this.di = di; // кажется этого здесь не должно быть
|
|
50
|
+
this.pubsub = pubsub;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function createConsumerContext({ di, dispatcherContext, pubsub, store }) {
|
|
54
|
+
return new ConsumerContext({
|
|
55
|
+
di,
|
|
56
|
+
dispatcherContext,
|
|
57
|
+
pubsub,
|
|
58
|
+
store,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { ConsumerContext, createConsumerContext };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { convertAction } from '@tramvai/state';
|
|
2
|
+
import { ACTION_EXECUTION_TOKEN } from '@tramvai/tokens-common';
|
|
3
|
+
|
|
4
|
+
class ConsumerContext {
|
|
5
|
+
constructor({ di, dispatcherContext, pubsub, store }) {
|
|
6
|
+
/* Side Effects */
|
|
7
|
+
this.executeAction = (action, payload) => {
|
|
8
|
+
return this.di.get(ACTION_EXECUTION_TOKEN).run(action, payload);
|
|
9
|
+
};
|
|
10
|
+
/* State manager */
|
|
11
|
+
this.dispatch = (actionOrNameEvent, payload) => {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
try {
|
|
14
|
+
resolve(this.store.dispatch(convertAction(actionOrNameEvent, payload)));
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
reject(err);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
this.dispatchWith = (createActionOrType, options) => {
|
|
22
|
+
return typeof createActionOrType === 'function'
|
|
23
|
+
? (...args) => this.dispatch(createActionOrType(...args), options)
|
|
24
|
+
: (payload) => this.dispatch(createActionOrType, payload);
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated
|
|
28
|
+
*/
|
|
29
|
+
this.getStore = (store) => {
|
|
30
|
+
return this.dispatcher.getStore(store);
|
|
31
|
+
};
|
|
32
|
+
this.dehydrate = () => ({
|
|
33
|
+
dispatcher: this.dispatcher.dehydrate(),
|
|
34
|
+
});
|
|
35
|
+
this.getState = (...args) => {
|
|
36
|
+
return this.store.getState(args[0]);
|
|
37
|
+
};
|
|
38
|
+
this.subscribe = (...args) => {
|
|
39
|
+
return this.store.subscribe(args[0], args[1]);
|
|
40
|
+
};
|
|
41
|
+
this.hasStore = (store) => this.dispatcher.hasStore(store);
|
|
42
|
+
this.registerStore = (store) => this.dispatcher.registerStore(store);
|
|
43
|
+
this.unregisterStore = (store) => this.dispatcher.unregisterStore(store);
|
|
44
|
+
this.store = store;
|
|
45
|
+
// @ts-expect-error
|
|
46
|
+
this.dispatcher = dispatcherContext;
|
|
47
|
+
// TODO убрать, нужно для некоторых старых сторов на платформе
|
|
48
|
+
this.dispatcher.setContext(this);
|
|
49
|
+
this.di = di; // кажется этого здесь не должно быть
|
|
50
|
+
this.pubsub = pubsub;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function createConsumerContext({ di, dispatcherContext, pubsub, store }) {
|
|
54
|
+
return new ConsumerContext({
|
|
55
|
+
di,
|
|
56
|
+
dispatcherContext,
|
|
57
|
+
pubsub,
|
|
58
|
+
store,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { ConsumerContext, createConsumerContext };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var state = require('@tramvai/state');
|
|
6
|
+
var tokensCommon = require('@tramvai/tokens-common');
|
|
7
|
+
|
|
8
|
+
class ConsumerContext {
|
|
9
|
+
constructor({ di, dispatcherContext, pubsub, store }) {
|
|
10
|
+
/* Side Effects */
|
|
11
|
+
this.executeAction = (action, payload) => {
|
|
12
|
+
return this.di.get(tokensCommon.ACTION_EXECUTION_TOKEN).run(action, payload);
|
|
13
|
+
};
|
|
14
|
+
/* State manager */
|
|
15
|
+
this.dispatch = (actionOrNameEvent, payload) => {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
try {
|
|
18
|
+
resolve(this.store.dispatch(state.convertAction(actionOrNameEvent, payload)));
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
reject(err);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
this.dispatchWith = (createActionOrType, options) => {
|
|
26
|
+
return typeof createActionOrType === 'function'
|
|
27
|
+
? (...args) => this.dispatch(createActionOrType(...args), options)
|
|
28
|
+
: (payload) => this.dispatch(createActionOrType, payload);
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated
|
|
32
|
+
*/
|
|
33
|
+
this.getStore = (store) => {
|
|
34
|
+
return this.dispatcher.getStore(store);
|
|
35
|
+
};
|
|
36
|
+
this.dehydrate = () => ({
|
|
37
|
+
dispatcher: this.dispatcher.dehydrate(),
|
|
38
|
+
});
|
|
39
|
+
this.getState = (...args) => {
|
|
40
|
+
return this.store.getState(args[0]);
|
|
41
|
+
};
|
|
42
|
+
this.subscribe = (...args) => {
|
|
43
|
+
return this.store.subscribe(args[0], args[1]);
|
|
44
|
+
};
|
|
45
|
+
this.hasStore = (store) => this.dispatcher.hasStore(store);
|
|
46
|
+
this.registerStore = (store) => this.dispatcher.registerStore(store);
|
|
47
|
+
this.unregisterStore = (store) => this.dispatcher.unregisterStore(store);
|
|
48
|
+
this.store = store;
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
this.dispatcher = dispatcherContext;
|
|
51
|
+
// TODO убрать, нужно для некоторых старых сторов на платформе
|
|
52
|
+
this.dispatcher.setContext(this);
|
|
53
|
+
this.di = di; // кажется этого здесь не должно быть
|
|
54
|
+
this.pubsub = pubsub;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function createConsumerContext({ di, dispatcherContext, pubsub, store }) {
|
|
58
|
+
return new ConsumerContext({
|
|
59
|
+
di,
|
|
60
|
+
dispatcherContext,
|
|
61
|
+
pubsub,
|
|
62
|
+
store,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.ConsumerContext = ConsumerContext;
|
|
67
|
+
exports.createConsumerContext = createConsumerContext;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ExecutionAbortError } from '@tinkoff/errors';
|
|
2
|
+
import { AbortController } from 'node-abort-controller';
|
|
3
|
+
|
|
4
|
+
const EMPTY_VALUES = {};
|
|
5
|
+
const normalizeOptions = (nameOrOptions) => {
|
|
6
|
+
return typeof nameOrOptions === 'string' ? { name: nameOrOptions } : nameOrOptions;
|
|
7
|
+
};
|
|
8
|
+
class ExecutionContextManager {
|
|
9
|
+
async withContext(parentContext, nameOrOptions, cb) {
|
|
10
|
+
const options = normalizeOptions(nameOrOptions);
|
|
11
|
+
const { name, values: selfValues = EMPTY_VALUES } = options;
|
|
12
|
+
const contextName = parentContext ? `${parentContext.name}.${name}` : name;
|
|
13
|
+
if (parentContext === null || parentContext === void 0 ? void 0 : parentContext.abortSignal.aborted) {
|
|
14
|
+
throw new ExecutionAbortError({
|
|
15
|
+
message: `Execution aborted in context "${contextName}"`,
|
|
16
|
+
contextName,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const abortController = new AbortController();
|
|
20
|
+
let abortListener;
|
|
21
|
+
let values = selfValues;
|
|
22
|
+
if (parentContext) {
|
|
23
|
+
values = {
|
|
24
|
+
...parentContext.values,
|
|
25
|
+
...selfValues,
|
|
26
|
+
};
|
|
27
|
+
abortListener = () => {
|
|
28
|
+
abortController.abort();
|
|
29
|
+
};
|
|
30
|
+
// abort child context AbortController if parent AbortController was aborted
|
|
31
|
+
parentContext.abortSignal.addEventListener('abort', abortListener);
|
|
32
|
+
}
|
|
33
|
+
const context = {
|
|
34
|
+
name: contextName,
|
|
35
|
+
abortSignal: abortController.signal,
|
|
36
|
+
values,
|
|
37
|
+
};
|
|
38
|
+
try {
|
|
39
|
+
const result = await cb(context, abortController);
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (typeof error === 'object' && !error.executionContextName) {
|
|
44
|
+
error.executionContextName = context.name;
|
|
45
|
+
}
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
if (abortListener && parentContext) {
|
|
51
|
+
parentContext.abortSignal.removeEventListener('abort', abortListener);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { ExecutionContextManager };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ExecutionAbortError } from '@tinkoff/errors';
|
|
2
|
+
import { AbortController } from 'node-abort-controller';
|
|
3
|
+
|
|
4
|
+
const EMPTY_VALUES = {};
|
|
5
|
+
const normalizeOptions = (nameOrOptions) => {
|
|
6
|
+
return typeof nameOrOptions === 'string' ? { name: nameOrOptions } : nameOrOptions;
|
|
7
|
+
};
|
|
8
|
+
class ExecutionContextManager {
|
|
9
|
+
async withContext(parentContext, nameOrOptions, cb) {
|
|
10
|
+
const options = normalizeOptions(nameOrOptions);
|
|
11
|
+
const { name, values: selfValues = EMPTY_VALUES } = options;
|
|
12
|
+
const contextName = parentContext ? `${parentContext.name}.${name}` : name;
|
|
13
|
+
if (parentContext === null || parentContext === void 0 ? void 0 : parentContext.abortSignal.aborted) {
|
|
14
|
+
throw new ExecutionAbortError({
|
|
15
|
+
message: `Execution aborted in context "${contextName}"`,
|
|
16
|
+
contextName,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const abortController = new AbortController();
|
|
20
|
+
let abortListener;
|
|
21
|
+
let values = selfValues;
|
|
22
|
+
if (parentContext) {
|
|
23
|
+
values = {
|
|
24
|
+
...parentContext.values,
|
|
25
|
+
...selfValues,
|
|
26
|
+
};
|
|
27
|
+
abortListener = () => {
|
|
28
|
+
abortController.abort();
|
|
29
|
+
};
|
|
30
|
+
// abort child context AbortController if parent AbortController was aborted
|
|
31
|
+
parentContext.abortSignal.addEventListener('abort', abortListener);
|
|
32
|
+
}
|
|
33
|
+
const context = {
|
|
34
|
+
name: contextName,
|
|
35
|
+
abortSignal: abortController.signal,
|
|
36
|
+
values,
|
|
37
|
+
};
|
|
38
|
+
try {
|
|
39
|
+
const result = await cb(context, abortController);
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (typeof error === 'object' && !error.executionContextName) {
|
|
44
|
+
error.executionContextName = context.name;
|
|
45
|
+
}
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
if (abortListener && parentContext) {
|
|
51
|
+
parentContext.abortSignal.removeEventListener('abort', abortListener);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { ExecutionContextManager };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var errors = require('@tinkoff/errors');
|
|
6
|
+
var nodeAbortController = require('node-abort-controller');
|
|
7
|
+
|
|
8
|
+
const EMPTY_VALUES = {};
|
|
9
|
+
const normalizeOptions = (nameOrOptions) => {
|
|
10
|
+
return typeof nameOrOptions === 'string' ? { name: nameOrOptions } : nameOrOptions;
|
|
11
|
+
};
|
|
12
|
+
class ExecutionContextManager {
|
|
13
|
+
async withContext(parentContext, nameOrOptions, cb) {
|
|
14
|
+
const options = normalizeOptions(nameOrOptions);
|
|
15
|
+
const { name, values: selfValues = EMPTY_VALUES } = options;
|
|
16
|
+
const contextName = parentContext ? `${parentContext.name}.${name}` : name;
|
|
17
|
+
if (parentContext === null || parentContext === void 0 ? void 0 : parentContext.abortSignal.aborted) {
|
|
18
|
+
throw new errors.ExecutionAbortError({
|
|
19
|
+
message: `Execution aborted in context "${contextName}"`,
|
|
20
|
+
contextName,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const abortController = new nodeAbortController.AbortController();
|
|
24
|
+
let abortListener;
|
|
25
|
+
let values = selfValues;
|
|
26
|
+
if (parentContext) {
|
|
27
|
+
values = {
|
|
28
|
+
...parentContext.values,
|
|
29
|
+
...selfValues,
|
|
30
|
+
};
|
|
31
|
+
abortListener = () => {
|
|
32
|
+
abortController.abort();
|
|
33
|
+
};
|
|
34
|
+
// abort child context AbortController if parent AbortController was aborted
|
|
35
|
+
parentContext.abortSignal.addEventListener('abort', abortListener);
|
|
36
|
+
}
|
|
37
|
+
const context = {
|
|
38
|
+
name: contextName,
|
|
39
|
+
abortSignal: abortController.signal,
|
|
40
|
+
values,
|
|
41
|
+
};
|
|
42
|
+
try {
|
|
43
|
+
const result = await cb(context, abortController);
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (typeof error === 'object' && !error.executionContextName) {
|
|
48
|
+
error.executionContextName = context.name;
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
// @ts-expect-error
|
|
54
|
+
if (abortListener && parentContext) {
|
|
55
|
+
parentContext.abortSignal.removeEventListener('abort', abortListener);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
exports.ExecutionContextManager = ExecutionContextManager;
|