@tramvai/module-child-app 2.70.1 → 2.72.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/browser/child/singletonProviders.browser.js +91 -0
- package/lib/browser/loader.browser.js +64 -0
- package/lib/browser/preload.browser.js +115 -0
- package/lib/browser/providers.browser.js +113 -0
- package/lib/browser/render.browser.js +28 -0
- package/lib/browser/runCommand.browser.js +8 -0
- package/lib/browser.browser.js +17 -0
- package/lib/server/child/singletonProviders.es.js +24 -0
- package/lib/server/child/singletonProviders.js +32 -0
- package/lib/server/loader.es.js +48 -0
- package/lib/server/loader.js +52 -0
- package/lib/server/preload.es.js +77 -0
- package/lib/server/preload.js +81 -0
- package/lib/server/providers.es.js +131 -0
- package/lib/server/providers.js +135 -0
- package/lib/server/render-slots.es.js +50 -0
- package/lib/server/render-slots.js +54 -0
- package/lib/server/render.es.js +39 -0
- package/lib/server/render.js +43 -0
- package/lib/server/stateManager.es.js +49 -0
- package/lib/server/stateManager.js +54 -0
- package/lib/server.browser.js +2 -1082
- package/lib/server.es.js +5 -1067
- package/lib/server.js +5 -1072
- package/lib/shared/child/providers.browser.js +36 -0
- package/lib/shared/child/providers.es.js +36 -0
- package/lib/shared/child/providers.js +44 -0
- package/lib/shared/child/singletonProviders.browser.js +24 -0
- package/lib/shared/child/singletonProviders.es.js +24 -0
- package/lib/shared/child/singletonProviders.js +28 -0
- package/lib/shared/child/stubs.browser.js +18 -0
- package/lib/shared/child/stubs.es.js +18 -0
- package/lib/shared/child/stubs.js +22 -0
- package/lib/shared/child/validate.browser.js +11 -0
- package/lib/shared/child/validate.es.js +11 -0
- package/lib/shared/child/validate.js +15 -0
- package/lib/shared/command.browser.js +38 -0
- package/lib/shared/command.es.js +38 -0
- package/lib/shared/command.js +42 -0
- package/lib/shared/constants.browser.js +3 -0
- package/lib/shared/constants.es.js +3 -0
- package/lib/shared/constants.js +7 -0
- package/lib/shared/di.browser.js +44 -0
- package/lib/shared/di.es.js +44 -0
- package/lib/shared/di.js +48 -0
- package/lib/shared/loader.browser.js +7 -0
- package/lib/shared/loader.es.js +7 -0
- package/lib/shared/loader.js +11 -0
- package/lib/shared/providers.browser.js +231 -0
- package/lib/shared/providers.es.js +231 -0
- package/lib/shared/providers.js +235 -0
- package/lib/shared/react/component.browser.js +104 -0
- package/lib/shared/react/component.es.js +104 -0
- package/lib/shared/react/component.js +112 -0
- package/lib/shared/react/render-context.browser.js +5 -0
- package/lib/shared/react/render-context.es.js +5 -0
- package/lib/shared/react/render-context.js +9 -0
- package/lib/shared/render.browser.js +10 -0
- package/lib/shared/render.es.js +10 -0
- package/lib/shared/render.js +14 -0
- package/lib/shared/resolutionConfigManager.browser.js +58 -0
- package/lib/shared/resolutionConfigManager.es.js +58 -0
- package/lib/shared/resolutionConfigManager.js +67 -0
- package/lib/shared/singletonDi.browser.js +95 -0
- package/lib/shared/singletonDi.es.js +95 -0
- package/lib/shared/singletonDi.js +103 -0
- package/lib/shared/store.browser.js +13 -0
- package/lib/shared/store.es.js +13 -0
- package/lib/shared/store.js +18 -0
- package/lib/shared/webpack/moduleFederation.browser.js +49 -0
- package/lib/shared/webpack/moduleFederation.es.js +49 -0
- package/lib/shared/webpack/moduleFederation.js +54 -0
- package/package.json +17 -18
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import flatten from '@tinkoff/utils/array/flatten';
|
|
2
|
+
import { provide } from '@tramvai/core';
|
|
3
|
+
import { ChildDispatcherContext } from '@tramvai/state';
|
|
4
|
+
import { CHILD_APP_INTERNAL_ROOT_STATE_ALLOWED_STORE_TOKEN } from '@tramvai/tokens-child-app';
|
|
5
|
+
import { DISPATCHER_CONTEXT_TOKEN, DISPATCHER_TOKEN, STORE_MIDDLEWARE, INITIAL_APP_STATE_TOKEN } from '@tramvai/tokens-common';
|
|
6
|
+
|
|
7
|
+
const getChildProviders = (appDi) => {
|
|
8
|
+
const parentDispatcherContext = appDi.get(DISPATCHER_CONTEXT_TOKEN);
|
|
9
|
+
return [
|
|
10
|
+
provide({
|
|
11
|
+
provide: DISPATCHER_CONTEXT_TOKEN,
|
|
12
|
+
useFactory: ({ dispatcher, middlewares, initialState, parentAllowedStores }) => {
|
|
13
|
+
return new ChildDispatcherContext({
|
|
14
|
+
dispatcher,
|
|
15
|
+
// context will be set later by the CONTEXT_TOKEN
|
|
16
|
+
context: {},
|
|
17
|
+
initialState: initialState !== null && initialState !== void 0 ? initialState : { stores: [] },
|
|
18
|
+
middlewares: flatten(middlewares || []),
|
|
19
|
+
parentDispatcherContext,
|
|
20
|
+
parentAllowedStores: flatten(parentAllowedStores || []),
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
deps: {
|
|
24
|
+
dispatcher: DISPATCHER_TOKEN,
|
|
25
|
+
middlewares: { token: STORE_MIDDLEWARE, optional: true },
|
|
26
|
+
initialState: { token: INITIAL_APP_STATE_TOKEN, optional: true },
|
|
27
|
+
parentAllowedStores: {
|
|
28
|
+
token: CHILD_APP_INTERNAL_ROOT_STATE_ALLOWED_STORE_TOKEN,
|
|
29
|
+
optional: true,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { getChildProviders };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import flatten from '@tinkoff/utils/array/flatten';
|
|
2
|
+
import { provide } from '@tramvai/core';
|
|
3
|
+
import { ChildDispatcherContext } from '@tramvai/state';
|
|
4
|
+
import { CHILD_APP_INTERNAL_ROOT_STATE_ALLOWED_STORE_TOKEN } from '@tramvai/tokens-child-app';
|
|
5
|
+
import { DISPATCHER_CONTEXT_TOKEN, DISPATCHER_TOKEN, STORE_MIDDLEWARE, INITIAL_APP_STATE_TOKEN } from '@tramvai/tokens-common';
|
|
6
|
+
|
|
7
|
+
const getChildProviders = (appDi) => {
|
|
8
|
+
const parentDispatcherContext = appDi.get(DISPATCHER_CONTEXT_TOKEN);
|
|
9
|
+
return [
|
|
10
|
+
provide({
|
|
11
|
+
provide: DISPATCHER_CONTEXT_TOKEN,
|
|
12
|
+
useFactory: ({ dispatcher, middlewares, initialState, parentAllowedStores }) => {
|
|
13
|
+
return new ChildDispatcherContext({
|
|
14
|
+
dispatcher,
|
|
15
|
+
// context will be set later by the CONTEXT_TOKEN
|
|
16
|
+
context: {},
|
|
17
|
+
initialState: initialState !== null && initialState !== void 0 ? initialState : { stores: [] },
|
|
18
|
+
middlewares: flatten(middlewares || []),
|
|
19
|
+
parentDispatcherContext,
|
|
20
|
+
parentAllowedStores: flatten(parentAllowedStores || []),
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
deps: {
|
|
24
|
+
dispatcher: DISPATCHER_TOKEN,
|
|
25
|
+
middlewares: { token: STORE_MIDDLEWARE, optional: true },
|
|
26
|
+
initialState: { token: INITIAL_APP_STATE_TOKEN, optional: true },
|
|
27
|
+
parentAllowedStores: {
|
|
28
|
+
token: CHILD_APP_INTERNAL_ROOT_STATE_ALLOWED_STORE_TOKEN,
|
|
29
|
+
optional: true,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { getChildProviders };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var flatten = require('@tinkoff/utils/array/flatten');
|
|
6
|
+
var core = require('@tramvai/core');
|
|
7
|
+
var state = require('@tramvai/state');
|
|
8
|
+
var tokensChildApp = require('@tramvai/tokens-child-app');
|
|
9
|
+
var tokensCommon = require('@tramvai/tokens-common');
|
|
10
|
+
|
|
11
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
+
|
|
13
|
+
var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
|
|
14
|
+
|
|
15
|
+
const getChildProviders = (appDi) => {
|
|
16
|
+
const parentDispatcherContext = appDi.get(tokensCommon.DISPATCHER_CONTEXT_TOKEN);
|
|
17
|
+
return [
|
|
18
|
+
core.provide({
|
|
19
|
+
provide: tokensCommon.DISPATCHER_CONTEXT_TOKEN,
|
|
20
|
+
useFactory: ({ dispatcher, middlewares, initialState, parentAllowedStores }) => {
|
|
21
|
+
return new state.ChildDispatcherContext({
|
|
22
|
+
dispatcher,
|
|
23
|
+
// context will be set later by the CONTEXT_TOKEN
|
|
24
|
+
context: {},
|
|
25
|
+
initialState: initialState !== null && initialState !== void 0 ? initialState : { stores: [] },
|
|
26
|
+
middlewares: flatten__default["default"](middlewares || []),
|
|
27
|
+
parentDispatcherContext,
|
|
28
|
+
parentAllowedStores: flatten__default["default"](parentAllowedStores || []),
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
deps: {
|
|
32
|
+
dispatcher: tokensCommon.DISPATCHER_TOKEN,
|
|
33
|
+
middlewares: { token: tokensCommon.STORE_MIDDLEWARE, optional: true },
|
|
34
|
+
initialState: { token: tokensCommon.INITIAL_APP_STATE_TOKEN, optional: true },
|
|
35
|
+
parentAllowedStores: {
|
|
36
|
+
token: tokensChildApp.CHILD_APP_INTERNAL_ROOT_STATE_ALLOWED_STORE_TOKEN,
|
|
37
|
+
optional: true,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.getChildProviders = getChildProviders;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { provide } from '@tramvai/core';
|
|
2
|
+
import { LOGGER_TOKEN } from '@tramvai/tokens-common';
|
|
3
|
+
import { RENDER_SLOTS } from '@tramvai/tokens-render';
|
|
4
|
+
import { getChildProviders as getChildProviders$1 } from '../../browser/child/singletonProviders.browser.js';
|
|
5
|
+
|
|
6
|
+
const getChildProviders = (appDi) => {
|
|
7
|
+
const logger = appDi.get(LOGGER_TOKEN);
|
|
8
|
+
return [
|
|
9
|
+
provide({
|
|
10
|
+
provide: LOGGER_TOKEN,
|
|
11
|
+
useValue: Object.assign((opts) => {
|
|
12
|
+
return logger('child-app').child(opts);
|
|
13
|
+
}, logger),
|
|
14
|
+
}),
|
|
15
|
+
provide({
|
|
16
|
+
provide: RENDER_SLOTS,
|
|
17
|
+
multi: true,
|
|
18
|
+
useValue: [],
|
|
19
|
+
}),
|
|
20
|
+
...getChildProviders$1(appDi),
|
|
21
|
+
];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { getChildProviders };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { provide } from '@tramvai/core';
|
|
2
|
+
import { LOGGER_TOKEN } from '@tramvai/tokens-common';
|
|
3
|
+
import { RENDER_SLOTS } from '@tramvai/tokens-render';
|
|
4
|
+
import { getChildProviders as getChildProviders$1 } from '../../server/child/singletonProviders.es.js';
|
|
5
|
+
|
|
6
|
+
const getChildProviders = (appDi) => {
|
|
7
|
+
const logger = appDi.get(LOGGER_TOKEN);
|
|
8
|
+
return [
|
|
9
|
+
provide({
|
|
10
|
+
provide: LOGGER_TOKEN,
|
|
11
|
+
useValue: Object.assign((opts) => {
|
|
12
|
+
return logger('child-app').child(opts);
|
|
13
|
+
}, logger),
|
|
14
|
+
}),
|
|
15
|
+
provide({
|
|
16
|
+
provide: RENDER_SLOTS,
|
|
17
|
+
multi: true,
|
|
18
|
+
useValue: [],
|
|
19
|
+
}),
|
|
20
|
+
...getChildProviders$1(),
|
|
21
|
+
];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { getChildProviders };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@tramvai/core');
|
|
6
|
+
var tokensCommon = require('@tramvai/tokens-common');
|
|
7
|
+
var tokensRender = require('@tramvai/tokens-render');
|
|
8
|
+
var singletonProviders = require('../../server/child/singletonProviders.js');
|
|
9
|
+
|
|
10
|
+
const getChildProviders = (appDi) => {
|
|
11
|
+
const logger = appDi.get(tokensCommon.LOGGER_TOKEN);
|
|
12
|
+
return [
|
|
13
|
+
core.provide({
|
|
14
|
+
provide: tokensCommon.LOGGER_TOKEN,
|
|
15
|
+
useValue: Object.assign((opts) => {
|
|
16
|
+
return logger('child-app').child(opts);
|
|
17
|
+
}, logger),
|
|
18
|
+
}),
|
|
19
|
+
core.provide({
|
|
20
|
+
provide: tokensRender.RENDER_SLOTS,
|
|
21
|
+
multi: true,
|
|
22
|
+
useValue: [],
|
|
23
|
+
}),
|
|
24
|
+
...singletonProviders.getChildProviders(),
|
|
25
|
+
];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
exports.getChildProviders = getChildProviders;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { COMMAND_LINE_RUNNER_TOKEN } from '@tramvai/core';
|
|
2
|
+
import { DISPATCHER_TOKEN, STORE_TOKEN, CONTEXT_TOKEN } from '@tramvai/tokens-common';
|
|
3
|
+
|
|
4
|
+
const commonModuleStubs = [
|
|
5
|
+
DISPATCHER_TOKEN,
|
|
6
|
+
STORE_TOKEN,
|
|
7
|
+
CONTEXT_TOKEN,
|
|
8
|
+
COMMAND_LINE_RUNNER_TOKEN,
|
|
9
|
+
].map((provide) => {
|
|
10
|
+
return {
|
|
11
|
+
provide,
|
|
12
|
+
useFactory: () => {
|
|
13
|
+
throw Object.assign(new Error('Pure usage of the token is not allowed inside ChildApp, please add `CommonChildAppModule` from module `@tramvai/module-common` to your ChildApp'), { code: 'E_STUB' });
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export { commonModuleStubs };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { COMMAND_LINE_RUNNER_TOKEN } from '@tramvai/core';
|
|
2
|
+
import { DISPATCHER_TOKEN, STORE_TOKEN, CONTEXT_TOKEN } from '@tramvai/tokens-common';
|
|
3
|
+
|
|
4
|
+
const commonModuleStubs = [
|
|
5
|
+
DISPATCHER_TOKEN,
|
|
6
|
+
STORE_TOKEN,
|
|
7
|
+
CONTEXT_TOKEN,
|
|
8
|
+
COMMAND_LINE_RUNNER_TOKEN,
|
|
9
|
+
].map((provide) => {
|
|
10
|
+
return {
|
|
11
|
+
provide,
|
|
12
|
+
useFactory: () => {
|
|
13
|
+
throw Object.assign(new Error('Pure usage of the token is not allowed inside ChildApp, please add `CommonChildAppModule` from module `@tramvai/module-common` to your ChildApp'), { code: 'E_STUB' });
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export { commonModuleStubs };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@tramvai/core');
|
|
6
|
+
var tokensCommon = require('@tramvai/tokens-common');
|
|
7
|
+
|
|
8
|
+
const commonModuleStubs = [
|
|
9
|
+
tokensCommon.DISPATCHER_TOKEN,
|
|
10
|
+
tokensCommon.STORE_TOKEN,
|
|
11
|
+
tokensCommon.CONTEXT_TOKEN,
|
|
12
|
+
core.COMMAND_LINE_RUNNER_TOKEN,
|
|
13
|
+
].map((provide) => {
|
|
14
|
+
return {
|
|
15
|
+
provide,
|
|
16
|
+
useFactory: () => {
|
|
17
|
+
throw Object.assign(new Error('Pure usage of the token is not allowed inside ChildApp, please add `CommonChildAppModule` from module `@tramvai/module-common` to your ChildApp'), { code: 'E_STUB' });
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
exports.commonModuleStubs = commonModuleStubs;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ENV_USED_TOKEN } from '@tramvai/tokens-common';
|
|
2
|
+
|
|
3
|
+
const validateChildAppProvider = (provider) => {
|
|
4
|
+
if (provider.provide.name === ENV_USED_TOKEN.name) {
|
|
5
|
+
throw new Error(`child-app Cannot use 'ENV_USED_TOKEN' as envs should be controlled by the root-app.
|
|
6
|
+
Consider passing configs from the root-app to child-app explicitly and remove defining 'ENV_USED_TOKEN' in the child-app itself.
|
|
7
|
+
You can still use 'ENV_MANAGER_TOKEN' in child-app to get env values`);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { validateChildAppProvider };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ENV_USED_TOKEN } from '@tramvai/tokens-common';
|
|
2
|
+
|
|
3
|
+
const validateChildAppProvider = (provider) => {
|
|
4
|
+
if (provider.provide.name === ENV_USED_TOKEN.name) {
|
|
5
|
+
throw new Error(`child-app Cannot use 'ENV_USED_TOKEN' as envs should be controlled by the root-app.
|
|
6
|
+
Consider passing configs from the root-app to child-app explicitly and remove defining 'ENV_USED_TOKEN' in the child-app itself.
|
|
7
|
+
You can still use 'ENV_MANAGER_TOKEN' in child-app to get env values`);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { validateChildAppProvider };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tokensCommon = require('@tramvai/tokens-common');
|
|
6
|
+
|
|
7
|
+
const validateChildAppProvider = (provider) => {
|
|
8
|
+
if (provider.provide.name === tokensCommon.ENV_USED_TOKEN.name) {
|
|
9
|
+
throw new Error(`child-app Cannot use 'ENV_USED_TOKEN' as envs should be controlled by the root-app.
|
|
10
|
+
Consider passing configs from the root-app to child-app explicitly and remove defining 'ENV_USED_TOKEN' in the child-app itself.
|
|
11
|
+
You can still use 'ENV_MANAGER_TOKEN' in child-app to get env values`);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
exports.validateChildAppProvider = validateChildAppProvider;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { COMMAND_LINE_RUNNER_TOKEN } from '@tramvai/core';
|
|
2
|
+
|
|
3
|
+
class CommandLineRunner {
|
|
4
|
+
constructor({ logger, rootCommandLineRunner, diManager, }) {
|
|
5
|
+
this.log = logger('child-app:command-line-runner');
|
|
6
|
+
this.rootCommandLineRunner = rootCommandLineRunner;
|
|
7
|
+
this.diManager = diManager;
|
|
8
|
+
}
|
|
9
|
+
async run(type, status, config) {
|
|
10
|
+
const di = this.diManager.getChildDi(config);
|
|
11
|
+
if (!di) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const commandLineRunner = di.get({ token: COMMAND_LINE_RUNNER_TOKEN, optional: true });
|
|
16
|
+
if (commandLineRunner && commandLineRunner !== this.rootCommandLineRunner) {
|
|
17
|
+
// TODO:child-app create independent metrics instance for child apps
|
|
18
|
+
// for now just reuse metrics implementation from root as otherwise it fails after attempt to create metrics instance with the same name
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
commandLineRunner.metricsInstance = this.rootCommandLineRunner.metricsInstance;
|
|
21
|
+
await commandLineRunner.run(type, status, [], di);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (error.code !== 'E_STUB') {
|
|
26
|
+
this.log.error({
|
|
27
|
+
event: 'run-failed',
|
|
28
|
+
error,
|
|
29
|
+
type,
|
|
30
|
+
status,
|
|
31
|
+
config,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { CommandLineRunner };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { COMMAND_LINE_RUNNER_TOKEN } from '@tramvai/core';
|
|
2
|
+
|
|
3
|
+
class CommandLineRunner {
|
|
4
|
+
constructor({ logger, rootCommandLineRunner, diManager, }) {
|
|
5
|
+
this.log = logger('child-app:command-line-runner');
|
|
6
|
+
this.rootCommandLineRunner = rootCommandLineRunner;
|
|
7
|
+
this.diManager = diManager;
|
|
8
|
+
}
|
|
9
|
+
async run(type, status, config) {
|
|
10
|
+
const di = this.diManager.getChildDi(config);
|
|
11
|
+
if (!di) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const commandLineRunner = di.get({ token: COMMAND_LINE_RUNNER_TOKEN, optional: true });
|
|
16
|
+
if (commandLineRunner && commandLineRunner !== this.rootCommandLineRunner) {
|
|
17
|
+
// TODO:child-app create independent metrics instance for child apps
|
|
18
|
+
// for now just reuse metrics implementation from root as otherwise it fails after attempt to create metrics instance with the same name
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
commandLineRunner.metricsInstance = this.rootCommandLineRunner.metricsInstance;
|
|
21
|
+
await commandLineRunner.run(type, status, [], di);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (error.code !== 'E_STUB') {
|
|
26
|
+
this.log.error({
|
|
27
|
+
event: 'run-failed',
|
|
28
|
+
error,
|
|
29
|
+
type,
|
|
30
|
+
status,
|
|
31
|
+
config,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { CommandLineRunner };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@tramvai/core');
|
|
6
|
+
|
|
7
|
+
class CommandLineRunner {
|
|
8
|
+
constructor({ logger, rootCommandLineRunner, diManager, }) {
|
|
9
|
+
this.log = logger('child-app:command-line-runner');
|
|
10
|
+
this.rootCommandLineRunner = rootCommandLineRunner;
|
|
11
|
+
this.diManager = diManager;
|
|
12
|
+
}
|
|
13
|
+
async run(type, status, config) {
|
|
14
|
+
const di = this.diManager.getChildDi(config);
|
|
15
|
+
if (!di) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const commandLineRunner = di.get({ token: core.COMMAND_LINE_RUNNER_TOKEN, optional: true });
|
|
20
|
+
if (commandLineRunner && commandLineRunner !== this.rootCommandLineRunner) {
|
|
21
|
+
// TODO:child-app create independent metrics instance for child apps
|
|
22
|
+
// for now just reuse metrics implementation from root as otherwise it fails after attempt to create metrics instance with the same name
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
commandLineRunner.metricsInstance = this.rootCommandLineRunner.metricsInstance;
|
|
25
|
+
await commandLineRunner.run(type, status, [], di);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (error.code !== 'E_STUB') {
|
|
30
|
+
this.log.error({
|
|
31
|
+
event: 'run-failed',
|
|
32
|
+
error,
|
|
33
|
+
type,
|
|
34
|
+
status,
|
|
35
|
+
config,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.CommandLineRunner = CommandLineRunner;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ChildContainer } from '@tinkoff/dippy';
|
|
2
|
+
import { getChildProviders } from './child/providers.browser.js';
|
|
3
|
+
|
|
4
|
+
class DiManager {
|
|
5
|
+
constructor({ appDi, loader, singletonDiManager, }) {
|
|
6
|
+
this.cache = new Map();
|
|
7
|
+
this.appDi = appDi;
|
|
8
|
+
this.loader = loader;
|
|
9
|
+
this.singletonDiManager = singletonDiManager;
|
|
10
|
+
}
|
|
11
|
+
getChildDi(config) {
|
|
12
|
+
const { key } = config;
|
|
13
|
+
if (this.cache.has(key)) {
|
|
14
|
+
return this.cache.get(key);
|
|
15
|
+
}
|
|
16
|
+
const di = this.resolveDi(config);
|
|
17
|
+
di && this.cache.set(key, di);
|
|
18
|
+
return di;
|
|
19
|
+
}
|
|
20
|
+
forEachChildDi(cb) {
|
|
21
|
+
this.cache.forEach((di) => {
|
|
22
|
+
cb(di);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
resolveDi(config) {
|
|
26
|
+
const children = this.loader.get(config);
|
|
27
|
+
if (!children) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const singletonDi = this.singletonDiManager.getChildDi(config);
|
|
31
|
+
if (!singletonDi) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const di = new ChildContainer(singletonDi, this.appDi);
|
|
35
|
+
// add providers on the Request Level to make it possible to reuse providers from the root-app ChildContainer
|
|
36
|
+
const childProviders = getChildProviders(this.appDi);
|
|
37
|
+
childProviders.forEach((provider) => {
|
|
38
|
+
di.register(provider);
|
|
39
|
+
});
|
|
40
|
+
return di;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { DiManager };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ChildContainer } from '@tinkoff/dippy';
|
|
2
|
+
import { getChildProviders } from './child/providers.es.js';
|
|
3
|
+
|
|
4
|
+
class DiManager {
|
|
5
|
+
constructor({ appDi, loader, singletonDiManager, }) {
|
|
6
|
+
this.cache = new Map();
|
|
7
|
+
this.appDi = appDi;
|
|
8
|
+
this.loader = loader;
|
|
9
|
+
this.singletonDiManager = singletonDiManager;
|
|
10
|
+
}
|
|
11
|
+
getChildDi(config) {
|
|
12
|
+
const { key } = config;
|
|
13
|
+
if (this.cache.has(key)) {
|
|
14
|
+
return this.cache.get(key);
|
|
15
|
+
}
|
|
16
|
+
const di = this.resolveDi(config);
|
|
17
|
+
di && this.cache.set(key, di);
|
|
18
|
+
return di;
|
|
19
|
+
}
|
|
20
|
+
forEachChildDi(cb) {
|
|
21
|
+
this.cache.forEach((di) => {
|
|
22
|
+
cb(di);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
resolveDi(config) {
|
|
26
|
+
const children = this.loader.get(config);
|
|
27
|
+
if (!children) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const singletonDi = this.singletonDiManager.getChildDi(config);
|
|
31
|
+
if (!singletonDi) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const di = new ChildContainer(singletonDi, this.appDi);
|
|
35
|
+
// add providers on the Request Level to make it possible to reuse providers from the root-app ChildContainer
|
|
36
|
+
const childProviders = getChildProviders(this.appDi);
|
|
37
|
+
childProviders.forEach((provider) => {
|
|
38
|
+
di.register(provider);
|
|
39
|
+
});
|
|
40
|
+
return di;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { DiManager };
|
package/lib/shared/di.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var dippy = require('@tinkoff/dippy');
|
|
6
|
+
var providers = require('./child/providers.js');
|
|
7
|
+
|
|
8
|
+
class DiManager {
|
|
9
|
+
constructor({ appDi, loader, singletonDiManager, }) {
|
|
10
|
+
this.cache = new Map();
|
|
11
|
+
this.appDi = appDi;
|
|
12
|
+
this.loader = loader;
|
|
13
|
+
this.singletonDiManager = singletonDiManager;
|
|
14
|
+
}
|
|
15
|
+
getChildDi(config) {
|
|
16
|
+
const { key } = config;
|
|
17
|
+
if (this.cache.has(key)) {
|
|
18
|
+
return this.cache.get(key);
|
|
19
|
+
}
|
|
20
|
+
const di = this.resolveDi(config);
|
|
21
|
+
di && this.cache.set(key, di);
|
|
22
|
+
return di;
|
|
23
|
+
}
|
|
24
|
+
forEachChildDi(cb) {
|
|
25
|
+
this.cache.forEach((di) => {
|
|
26
|
+
cb(di);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
resolveDi(config) {
|
|
30
|
+
const children = this.loader.get(config);
|
|
31
|
+
if (!children) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const singletonDi = this.singletonDiManager.getChildDi(config);
|
|
35
|
+
if (!singletonDi) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const di = new dippy.ChildContainer(singletonDi, this.appDi);
|
|
39
|
+
// add providers on the Request Level to make it possible to reuse providers from the root-app ChildContainer
|
|
40
|
+
const childProviders = providers.getChildProviders(this.appDi);
|
|
41
|
+
childProviders.forEach((provider) => {
|
|
42
|
+
di.register(provider);
|
|
43
|
+
});
|
|
44
|
+
return di;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.DiManager = DiManager;
|