@tramvai/module-child-app 4.18.5 → 4.19.2
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 +7 -9
- package/lib/browser/providers.browser.js +17 -2
- package/lib/contracts/contractManager.base.browser.js +46 -0
- package/lib/contracts/contractManager.base.d.ts +16 -0
- package/lib/contracts/contractManager.base.es.js +46 -0
- package/lib/contracts/contractManager.base.js +54 -0
- package/lib/contracts/contractManager.browser.browser.js +22 -0
- package/lib/contracts/contractManager.browser.d.ts +15 -0
- package/lib/contracts/contractManager.server.d.ts +24 -0
- package/lib/contracts/contractManager.server.es.js +25 -0
- package/lib/contracts/contractManager.server.js +33 -0
- package/lib/server/providers.es.js +14 -3
- package/lib/server/providers.js +11 -0
- package/lib/server/stateManager.es.js +5 -6
- package/lib/server/stateManager.js +5 -6
- package/lib/shared/child/extractorProviders.es.js +2 -1
- package/lib/shared/child/extractorProviders.js +1 -0
- package/lib/shared/child/singletonProviders.browser.js +79 -4
- package/lib/shared/child/singletonProviders.d.ts +2 -1
- package/lib/shared/child/singletonProviders.es.js +79 -4
- package/lib/shared/child/singletonProviders.js +76 -1
- package/lib/shared/di.browser.js +4 -7
- package/lib/shared/di.d.ts +1 -1
- package/lib/shared/di.es.js +4 -7
- package/lib/shared/di.js +4 -7
- package/lib/shared/providers.browser.js +18 -2
- package/lib/shared/providers.es.js +18 -2
- package/lib/shared/providers.js +16 -0
- package/lib/shared/singletonDi.browser.js +6 -7
- package/lib/shared/singletonDi.d.ts +5 -2
- package/lib/shared/singletonDi.es.js +7 -8
- package/lib/shared/singletonDi.js +7 -8
- package/package.json +13 -13
- package/lib/shared/child/providers.browser.js +0 -54
- package/lib/shared/child/providers.d.ts +0 -5
- package/lib/shared/child/providers.es.js +0 -54
- package/lib/shared/child/providers.js +0 -62
- package/lib/shared/child/stubs.browser.js +0 -18
- package/lib/shared/child/stubs.d.ts +0 -5
- package/lib/shared/child/stubs.es.js +0 -18
- package/lib/shared/child/stubs.js +0 -22
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import noop from '@tinkoff/utils/function/noop';
|
|
2
2
|
import { provide } from '@tramvai/core';
|
|
3
|
-
import { commandLineListTokens, CHILD_APP_INTERNAL_ROOT_STATE_SUBSCRIPTION_TOKEN, CHILD_APP_PAGE_SERVICE_TOKEN } from '@tramvai/tokens-child-app';
|
|
3
|
+
import { commandLineListTokens, CHILD_APP_INTERNAL_ROOT_STATE_SUBSCRIPTION_TOKEN, CHILD_APP_PAGE_SERVICE_TOKEN, CHILD_REQUIRED_CONTRACTS, CHILD_APP_COMMON_INITIAL_STATE_TOKEN } from '@tramvai/tokens-child-app';
|
|
4
4
|
import { CONTEXT_TOKEN, ACTION_PAGE_RUNNER_TOKEN } from '@tramvai/tokens-common';
|
|
5
5
|
import { Subscription } from '@tramvai/state';
|
|
6
6
|
import { ROUTER_SPA_ACTIONS_RUN_MODE_TOKEN } from '@tramvai/tokens-router';
|
|
@@ -60,10 +60,7 @@ const getChildProviders = (appDi) => {
|
|
|
60
60
|
deps: {
|
|
61
61
|
actionRunner: ACTION_PAGE_RUNNER_TOKEN,
|
|
62
62
|
childAppPageService: CHILD_APP_PAGE_SERVICE_TOKEN,
|
|
63
|
-
spaMode:
|
|
64
|
-
token: ROUTER_SPA_ACTIONS_RUN_MODE_TOKEN,
|
|
65
|
-
optional: true,
|
|
66
|
-
},
|
|
63
|
+
spaMode: ROUTER_SPA_ACTIONS_RUN_MODE_TOKEN,
|
|
67
64
|
},
|
|
68
65
|
}),
|
|
69
66
|
provide({
|
|
@@ -81,12 +78,13 @@ const getChildProviders = (appDi) => {
|
|
|
81
78
|
deps: {
|
|
82
79
|
actionRunner: ACTION_PAGE_RUNNER_TOKEN,
|
|
83
80
|
childAppPageService: CHILD_APP_PAGE_SERVICE_TOKEN,
|
|
84
|
-
spaMode:
|
|
85
|
-
token: ROUTER_SPA_ACTIONS_RUN_MODE_TOKEN,
|
|
86
|
-
optional: true,
|
|
87
|
-
},
|
|
81
|
+
spaMode: ROUTER_SPA_ACTIONS_RUN_MODE_TOKEN,
|
|
88
82
|
},
|
|
89
83
|
}),
|
|
84
|
+
provide({
|
|
85
|
+
provide: CHILD_REQUIRED_CONTRACTS,
|
|
86
|
+
useValue: [CHILD_APP_COMMON_INITIAL_STATE_TOKEN],
|
|
87
|
+
}),
|
|
90
88
|
];
|
|
91
89
|
};
|
|
92
90
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Scope } from '@tinkoff/dippy';
|
|
1
|
+
import { Scope, DI_TOKEN } from '@tinkoff/dippy';
|
|
2
2
|
import { provide, commandLineListTokens } from '@tramvai/core';
|
|
3
|
-
import { CHILD_APP_LOADER_TOKEN, CHILD_APP_PRELOAD_MANAGER_TOKEN, CHILD_APP_COMMAND_LINE_RUNNER_TOKEN, CHILD_APP_RESOLUTION_CONFIG_MANAGER_TOKEN, CHILD_APP_RESOLVE_CONFIG_TOKEN, CHILD_APP_DI_MANAGER_TOKEN, CHILD_APP_COMMON_INITIAL_STATE_TOKEN, CHILD_APP_RENDER_MANAGER_TOKEN } from '@tramvai/tokens-child-app';
|
|
3
|
+
import { CHILD_APP_LOADER_TOKEN, CHILD_APP_PRELOAD_MANAGER_TOKEN, CHILD_APP_COMMAND_LINE_RUNNER_TOKEN, CHILD_APP_RESOLUTION_CONFIG_MANAGER_TOKEN, CHILD_APP_RESOLVE_CONFIG_TOKEN, CHILD_APP_DI_MANAGER_TOKEN, CHILD_APP_COMMON_INITIAL_STATE_TOKEN, CHILD_APP_RENDER_MANAGER_TOKEN, CHILD_APP_CONTRACT_MANAGER, HOST_PROVIDED_CONTRACTS } from '@tramvai/tokens-child-app';
|
|
4
4
|
import { LOGGER_TOKEN, STORE_TOKEN } from '@tramvai/tokens-common';
|
|
5
5
|
import { ROUTER_TOKEN, PAGE_SERVICE_TOKEN } from '@tramvai/tokens-router';
|
|
6
|
+
import { ChildAppContractManager } from '../contracts/contractManager.browser.browser.js';
|
|
6
7
|
import { BrowserLoader } from './loader.browser.js';
|
|
7
8
|
import { PreloadManager } from './preload.browser.js';
|
|
8
9
|
import { RenderManager } from './render.browser.js';
|
|
@@ -130,6 +131,20 @@ const browserProviders = [
|
|
|
130
131
|
logger: LOGGER_TOKEN,
|
|
131
132
|
},
|
|
132
133
|
}),
|
|
134
|
+
provide({
|
|
135
|
+
provide: CHILD_APP_CONTRACT_MANAGER,
|
|
136
|
+
useFactory: (deps) => new ChildAppContractManager(deps),
|
|
137
|
+
deps: {
|
|
138
|
+
appDi: DI_TOKEN,
|
|
139
|
+
hostProvidedContracts: HOST_PROVIDED_CONTRACTS,
|
|
140
|
+
},
|
|
141
|
+
}),
|
|
142
|
+
provide({
|
|
143
|
+
provide: HOST_PROVIDED_CONTRACTS,
|
|
144
|
+
useValue: {
|
|
145
|
+
providedContracts: [CHILD_APP_COMMON_INITIAL_STATE_TOKEN],
|
|
146
|
+
},
|
|
147
|
+
}),
|
|
133
148
|
];
|
|
134
149
|
|
|
135
150
|
export { browserProviders };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import flatten from '@tinkoff/utils/array/flatten';
|
|
2
|
+
import { optional } from '@tinkoff/dippy';
|
|
3
|
+
import { CHILD_APP_INTERNAL_CONFIG_TOKEN, IS_CHILD_APP_CONTRACTS_COMPATIBLE_TOKEN, CHILD_REQUIRED_CONTRACTS } from '@tramvai/tokens-child-app';
|
|
4
|
+
|
|
5
|
+
class BaseChildAppContractManager {
|
|
6
|
+
constructor({ hostProvidedContracts }) {
|
|
7
|
+
this.hostProvidedContracts = hostProvidedContracts;
|
|
8
|
+
}
|
|
9
|
+
registerChildContracts(childDi) {
|
|
10
|
+
var _a;
|
|
11
|
+
const childAppConfig = childDi.get(CHILD_APP_INTERNAL_CONFIG_TOKEN);
|
|
12
|
+
const childHasContractsSupport = childDi.get(optional(IS_CHILD_APP_CONTRACTS_COMPATIBLE_TOKEN));
|
|
13
|
+
const childRequiredContracts = flatten((_a = childDi.get(optional(CHILD_REQUIRED_CONTRACTS))) !== null && _a !== void 0 ? _a : []);
|
|
14
|
+
const childRequiredContractsKeys = childRequiredContracts.map((c) => c.toString());
|
|
15
|
+
const hostProvidedContracts = this.getHostProvidedContracts(childAppConfig.name);
|
|
16
|
+
// if contracts unsupported, it is a legacy child app, and we need to register all possible contracts
|
|
17
|
+
// otherwise register only required for child app contracts
|
|
18
|
+
const hasContractsToRegistration = !childHasContractsSupport || childRequiredContracts.length > 0;
|
|
19
|
+
if (hasContractsToRegistration) {
|
|
20
|
+
for (const contract of hostProvidedContracts) {
|
|
21
|
+
const contractKey = contract.toString();
|
|
22
|
+
// if contracts unsupported, it is a legacy child app, and we need to register all possible contracts
|
|
23
|
+
// otherwise match required and provided contracts by key
|
|
24
|
+
const isChildRequiredContract = !childHasContractsSupport || childRequiredContractsKeys.includes(contractKey);
|
|
25
|
+
if (isChildRequiredContract) {
|
|
26
|
+
this.registerContract(childDi, contract);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
getHostProvidedContracts(childAppName) {
|
|
32
|
+
const contracts = [];
|
|
33
|
+
// look over all provided by host contracts
|
|
34
|
+
for (const contract of this.hostProvidedContracts) {
|
|
35
|
+
// contracts without childAppName can be registered to any child app
|
|
36
|
+
// otherwise we need to match current and contract child app names
|
|
37
|
+
const contractAvailableForChild = !contract.childAppName || contract.childAppName === childAppName;
|
|
38
|
+
if (contractAvailableForChild) {
|
|
39
|
+
contracts.push(...contract.providedContracts);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return contracts;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { BaseChildAppContractManager };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ExtractDependencyType } from '@tinkoff/dippy';
|
|
2
|
+
import { type Container } from '@tinkoff/dippy';
|
|
3
|
+
import type { Contract, HOST_PROVIDED_CONTRACTS } from '@tramvai/tokens-child-app';
|
|
4
|
+
import { type ChildAppContractManager as IChildAppContractManager } from '@tramvai/tokens-child-app';
|
|
5
|
+
type HostProvidedContracts = ExtractDependencyType<typeof HOST_PROVIDED_CONTRACTS>;
|
|
6
|
+
export declare abstract class BaseChildAppContractManager implements IChildAppContractManager {
|
|
7
|
+
private hostProvidedContracts;
|
|
8
|
+
constructor({ hostProvidedContracts }: {
|
|
9
|
+
hostProvidedContracts: HostProvidedContracts;
|
|
10
|
+
});
|
|
11
|
+
registerChildContracts(childDi: Container): void;
|
|
12
|
+
abstract registerContract(childDi: Container, contract: Contract): void;
|
|
13
|
+
private getHostProvidedContracts;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=contractManager.base.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import flatten from '@tinkoff/utils/array/flatten';
|
|
2
|
+
import { optional } from '@tinkoff/dippy';
|
|
3
|
+
import { CHILD_APP_INTERNAL_CONFIG_TOKEN, IS_CHILD_APP_CONTRACTS_COMPATIBLE_TOKEN, CHILD_REQUIRED_CONTRACTS } from '@tramvai/tokens-child-app';
|
|
4
|
+
|
|
5
|
+
class BaseChildAppContractManager {
|
|
6
|
+
constructor({ hostProvidedContracts }) {
|
|
7
|
+
this.hostProvidedContracts = hostProvidedContracts;
|
|
8
|
+
}
|
|
9
|
+
registerChildContracts(childDi) {
|
|
10
|
+
var _a;
|
|
11
|
+
const childAppConfig = childDi.get(CHILD_APP_INTERNAL_CONFIG_TOKEN);
|
|
12
|
+
const childHasContractsSupport = childDi.get(optional(IS_CHILD_APP_CONTRACTS_COMPATIBLE_TOKEN));
|
|
13
|
+
const childRequiredContracts = flatten((_a = childDi.get(optional(CHILD_REQUIRED_CONTRACTS))) !== null && _a !== void 0 ? _a : []);
|
|
14
|
+
const childRequiredContractsKeys = childRequiredContracts.map((c) => c.toString());
|
|
15
|
+
const hostProvidedContracts = this.getHostProvidedContracts(childAppConfig.name);
|
|
16
|
+
// if contracts unsupported, it is a legacy child app, and we need to register all possible contracts
|
|
17
|
+
// otherwise register only required for child app contracts
|
|
18
|
+
const hasContractsToRegistration = !childHasContractsSupport || childRequiredContracts.length > 0;
|
|
19
|
+
if (hasContractsToRegistration) {
|
|
20
|
+
for (const contract of hostProvidedContracts) {
|
|
21
|
+
const contractKey = contract.toString();
|
|
22
|
+
// if contracts unsupported, it is a legacy child app, and we need to register all possible contracts
|
|
23
|
+
// otherwise match required and provided contracts by key
|
|
24
|
+
const isChildRequiredContract = !childHasContractsSupport || childRequiredContractsKeys.includes(contractKey);
|
|
25
|
+
if (isChildRequiredContract) {
|
|
26
|
+
this.registerContract(childDi, contract);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
getHostProvidedContracts(childAppName) {
|
|
32
|
+
const contracts = [];
|
|
33
|
+
// look over all provided by host contracts
|
|
34
|
+
for (const contract of this.hostProvidedContracts) {
|
|
35
|
+
// contracts without childAppName can be registered to any child app
|
|
36
|
+
// otherwise we need to match current and contract child app names
|
|
37
|
+
const contractAvailableForChild = !contract.childAppName || contract.childAppName === childAppName;
|
|
38
|
+
if (contractAvailableForChild) {
|
|
39
|
+
contracts.push(...contract.providedContracts);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return contracts;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { BaseChildAppContractManager };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var flatten = require('@tinkoff/utils/array/flatten');
|
|
6
|
+
var dippy = require('@tinkoff/dippy');
|
|
7
|
+
var tokensChildApp = require('@tramvai/tokens-child-app');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
|
|
12
|
+
|
|
13
|
+
class BaseChildAppContractManager {
|
|
14
|
+
constructor({ hostProvidedContracts }) {
|
|
15
|
+
this.hostProvidedContracts = hostProvidedContracts;
|
|
16
|
+
}
|
|
17
|
+
registerChildContracts(childDi) {
|
|
18
|
+
var _a;
|
|
19
|
+
const childAppConfig = childDi.get(tokensChildApp.CHILD_APP_INTERNAL_CONFIG_TOKEN);
|
|
20
|
+
const childHasContractsSupport = childDi.get(dippy.optional(tokensChildApp.IS_CHILD_APP_CONTRACTS_COMPATIBLE_TOKEN));
|
|
21
|
+
const childRequiredContracts = flatten__default["default"]((_a = childDi.get(dippy.optional(tokensChildApp.CHILD_REQUIRED_CONTRACTS))) !== null && _a !== void 0 ? _a : []);
|
|
22
|
+
const childRequiredContractsKeys = childRequiredContracts.map((c) => c.toString());
|
|
23
|
+
const hostProvidedContracts = this.getHostProvidedContracts(childAppConfig.name);
|
|
24
|
+
// if contracts unsupported, it is a legacy child app, and we need to register all possible contracts
|
|
25
|
+
// otherwise register only required for child app contracts
|
|
26
|
+
const hasContractsToRegistration = !childHasContractsSupport || childRequiredContracts.length > 0;
|
|
27
|
+
if (hasContractsToRegistration) {
|
|
28
|
+
for (const contract of hostProvidedContracts) {
|
|
29
|
+
const contractKey = contract.toString();
|
|
30
|
+
// if contracts unsupported, it is a legacy child app, and we need to register all possible contracts
|
|
31
|
+
// otherwise match required and provided contracts by key
|
|
32
|
+
const isChildRequiredContract = !childHasContractsSupport || childRequiredContractsKeys.includes(contractKey);
|
|
33
|
+
if (isChildRequiredContract) {
|
|
34
|
+
this.registerContract(childDi, contract);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
getHostProvidedContracts(childAppName) {
|
|
40
|
+
const contracts = [];
|
|
41
|
+
// look over all provided by host contracts
|
|
42
|
+
for (const contract of this.hostProvidedContracts) {
|
|
43
|
+
// contracts without childAppName can be registered to any child app
|
|
44
|
+
// otherwise we need to match current and contract child app names
|
|
45
|
+
const contractAvailableForChild = !contract.childAppName || contract.childAppName === childAppName;
|
|
46
|
+
if (contractAvailableForChild) {
|
|
47
|
+
contracts.push(...contract.providedContracts);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return contracts;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.BaseChildAppContractManager = BaseChildAppContractManager;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import isNil from '@tinkoff/utils/is/nil';
|
|
2
|
+
import { provide, optional } from '@tinkoff/dippy';
|
|
3
|
+
import { BaseChildAppContractManager } from './contractManager.base.browser.js';
|
|
4
|
+
|
|
5
|
+
class ChildAppContractManager extends BaseChildAppContractManager {
|
|
6
|
+
constructor({ appDi, hostProvidedContracts, }) {
|
|
7
|
+
super({ hostProvidedContracts });
|
|
8
|
+
this.appDi = appDi;
|
|
9
|
+
}
|
|
10
|
+
registerContract(childDi, contract) {
|
|
11
|
+
childDi.register(provide({
|
|
12
|
+
provide: contract,
|
|
13
|
+
useFactory: () => {
|
|
14
|
+
const value = this.appDi.get(optional(contract));
|
|
15
|
+
if (isNil(value)) ;
|
|
16
|
+
return value;
|
|
17
|
+
},
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { ChildAppContractManager };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ExtractDependencyType } from '@tinkoff/dippy';
|
|
2
|
+
import { type Container } from '@tinkoff/dippy';
|
|
3
|
+
import type { Contract, HOST_PROVIDED_CONTRACTS } from '@tramvai/tokens-child-app';
|
|
4
|
+
import { BaseChildAppContractManager } from './contractManager.base';
|
|
5
|
+
type HostProvidedContracts = ExtractDependencyType<typeof HOST_PROVIDED_CONTRACTS>;
|
|
6
|
+
export declare class ChildAppContractManager extends BaseChildAppContractManager {
|
|
7
|
+
private appDi;
|
|
8
|
+
constructor({ appDi, hostProvidedContracts, }: {
|
|
9
|
+
appDi: Container;
|
|
10
|
+
hostProvidedContracts: HostProvidedContracts;
|
|
11
|
+
});
|
|
12
|
+
registerContract(childDi: Container, contract: Contract): void;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=contractManager.browser.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DI_TOKEN, ExtractDependencyType } from '@tinkoff/dippy';
|
|
2
|
+
import { type Container } from '@tinkoff/dippy';
|
|
3
|
+
import type { Contract, HOST_PROVIDED_CONTRACTS } from '@tramvai/tokens-child-app';
|
|
4
|
+
import type { ASYNC_LOCAL_STORAGE_TOKEN } from '@tramvai/tokens-common';
|
|
5
|
+
import { BaseChildAppContractManager } from './contractManager.base';
|
|
6
|
+
declare module '@tramvai/tokens-common' {
|
|
7
|
+
interface AsyncLocalStorageState {
|
|
8
|
+
tramvaiRequestDi?: ExtractDependencyType<typeof DI_TOKEN>;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
type HostProvidedContracts = ExtractDependencyType<typeof HOST_PROVIDED_CONTRACTS>;
|
|
12
|
+
type AsyncLocalStorageType = ExtractDependencyType<typeof ASYNC_LOCAL_STORAGE_TOKEN>;
|
|
13
|
+
export declare class ChildAppContractManager extends BaseChildAppContractManager {
|
|
14
|
+
private appDi;
|
|
15
|
+
private asyncLocalStorage;
|
|
16
|
+
constructor({ appDi, asyncLocalStorage, hostProvidedContracts, }: {
|
|
17
|
+
appDi: Container;
|
|
18
|
+
asyncLocalStorage: AsyncLocalStorageType;
|
|
19
|
+
hostProvidedContracts: HostProvidedContracts;
|
|
20
|
+
});
|
|
21
|
+
registerContract(childDi: Container, contract: Contract): void;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=contractManager.server.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import isNil from '@tinkoff/utils/is/nil';
|
|
2
|
+
import { provide, optional } from '@tinkoff/dippy';
|
|
3
|
+
import { BaseChildAppContractManager } from './contractManager.base.es.js';
|
|
4
|
+
|
|
5
|
+
class ChildAppContractManager extends BaseChildAppContractManager {
|
|
6
|
+
constructor({ appDi, asyncLocalStorage, hostProvidedContracts, }) {
|
|
7
|
+
super({ hostProvidedContracts });
|
|
8
|
+
this.appDi = appDi;
|
|
9
|
+
this.asyncLocalStorage = asyncLocalStorage;
|
|
10
|
+
}
|
|
11
|
+
registerContract(childDi, contract) {
|
|
12
|
+
childDi.register(provide({
|
|
13
|
+
provide: contract,
|
|
14
|
+
useFactory: () => {
|
|
15
|
+
var _a, _b, _c;
|
|
16
|
+
const value = (_c = (_b = (_a = this.asyncLocalStorage.getStore()) === null || _a === void 0 ? void 0 : _a.tramvaiRequestDi) === null || _b === void 0 ? void 0 : _b.get(optional(contract))) !== null && _c !== void 0 ? _c : this.appDi.get(optional(contract));
|
|
17
|
+
if (isNil(value)) ;
|
|
18
|
+
// TODO: Request scoped contrace is resolved in Singleton scope - what should we do?
|
|
19
|
+
return value;
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { ChildAppContractManager };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var isNil = require('@tinkoff/utils/is/nil');
|
|
6
|
+
var dippy = require('@tinkoff/dippy');
|
|
7
|
+
var contractManager_base = require('./contractManager.base.js');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var isNil__default = /*#__PURE__*/_interopDefaultLegacy(isNil);
|
|
12
|
+
|
|
13
|
+
class ChildAppContractManager extends contractManager_base.BaseChildAppContractManager {
|
|
14
|
+
constructor({ appDi, asyncLocalStorage, hostProvidedContracts, }) {
|
|
15
|
+
super({ hostProvidedContracts });
|
|
16
|
+
this.appDi = appDi;
|
|
17
|
+
this.asyncLocalStorage = asyncLocalStorage;
|
|
18
|
+
}
|
|
19
|
+
registerContract(childDi, contract) {
|
|
20
|
+
childDi.register(dippy.provide({
|
|
21
|
+
provide: contract,
|
|
22
|
+
useFactory: () => {
|
|
23
|
+
var _a, _b, _c;
|
|
24
|
+
const value = (_c = (_b = (_a = this.asyncLocalStorage.getStore()) === null || _a === void 0 ? void 0 : _a.tramvaiRequestDi) === null || _b === void 0 ? void 0 : _b.get(dippy.optional(contract))) !== null && _c !== void 0 ? _c : this.appDi.get(dippy.optional(contract));
|
|
25
|
+
if (isNil__default["default"](value)) ;
|
|
26
|
+
// TODO: Request scoped contrace is resolved in Singleton scope - what should we do?
|
|
27
|
+
return value;
|
|
28
|
+
},
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
exports.ChildAppContractManager = ChildAppContractManager;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { combineValidators, isUrl, endsWith } from '@tinkoff/env-validators';
|
|
2
|
-
import { Scope, optional } from '@tinkoff/dippy';
|
|
2
|
+
import { Scope, optional, DI_TOKEN } from '@tinkoff/dippy';
|
|
3
3
|
import { provide, commandLineListTokens } from '@tramvai/core';
|
|
4
|
-
import { ENV_USED_TOKEN, LOGGER_TOKEN, CREATE_CACHE_TOKEN, ENV_MANAGER_TOKEN, STORE_TOKEN } from '@tramvai/tokens-common';
|
|
4
|
+
import { ENV_USED_TOKEN, LOGGER_TOKEN, CREATE_CACHE_TOKEN, ENV_MANAGER_TOKEN, STORE_TOKEN, ASYNC_LOCAL_STORAGE_TOKEN } from '@tramvai/tokens-common';
|
|
5
5
|
import { RESOURCES_REGISTRY, RENDER_SLOTS, ResourceType, ResourceSlot, RENDER_FLOW_AFTER_TOKEN, REACT_SERVER_RENDER_MODE, EXTEND_RENDER } from '@tramvai/tokens-render';
|
|
6
|
-
import { CHILD_APP_LOADER_TOKEN, CHILD_APP_STATE_MANAGER_TOKEN, CHILD_APP_DI_MANAGER_TOKEN, CHILD_APP_PRELOAD_MANAGER_TOKEN, CHILD_APP_COMMAND_LINE_RUNNER_TOKEN, CHILD_APP_RESOLUTION_CONFIG_MANAGER_TOKEN, CHILD_APP_RESOLVE_CONFIG_TOKEN, CHILD_APP_RENDER_MANAGER_TOKEN } from '@tramvai/tokens-child-app';
|
|
6
|
+
import { CHILD_APP_LOADER_TOKEN, CHILD_APP_STATE_MANAGER_TOKEN, CHILD_APP_DI_MANAGER_TOKEN, CHILD_APP_PRELOAD_MANAGER_TOKEN, CHILD_APP_COMMAND_LINE_RUNNER_TOKEN, CHILD_APP_RESOLUTION_CONFIG_MANAGER_TOKEN, CHILD_APP_RESOLVE_CONFIG_TOKEN, CHILD_APP_RENDER_MANAGER_TOKEN, CHILD_APP_CONTRACT_MANAGER, HOST_PROVIDED_CONTRACTS } from '@tramvai/tokens-child-app';
|
|
7
7
|
import { safeStringify } from '@tramvai/safe-strings';
|
|
8
8
|
import { ServerLoader } from './loader.es.js';
|
|
9
9
|
import { PreloadManager } from './preload.es.js';
|
|
@@ -12,6 +12,7 @@ import { setPreloaded } from '../shared/store.es.js';
|
|
|
12
12
|
import { RenderManager } from './render.es.js';
|
|
13
13
|
import { registerChildAppRenderSlots } from './render-slots.es.js';
|
|
14
14
|
import { GLOBAL_CHILD_STATE } from '../shared/constants.es.js';
|
|
15
|
+
import { ChildAppContractManager } from '../contracts/contractManager.server.es.js';
|
|
15
16
|
|
|
16
17
|
const serverProviders = [
|
|
17
18
|
provide({
|
|
@@ -138,6 +139,16 @@ const serverProviders = [
|
|
|
138
139
|
renderManager: CHILD_APP_RENDER_MANAGER_TOKEN,
|
|
139
140
|
},
|
|
140
141
|
}),
|
|
142
|
+
provide({
|
|
143
|
+
provide: CHILD_APP_CONTRACT_MANAGER,
|
|
144
|
+
scope: Scope.SINGLETON,
|
|
145
|
+
useFactory: (deps) => new ChildAppContractManager(deps),
|
|
146
|
+
deps: {
|
|
147
|
+
appDi: DI_TOKEN,
|
|
148
|
+
asyncLocalStorage: ASYNC_LOCAL_STORAGE_TOKEN,
|
|
149
|
+
hostProvidedContracts: HOST_PROVIDED_CONTRACTS,
|
|
150
|
+
},
|
|
151
|
+
}),
|
|
141
152
|
];
|
|
142
153
|
|
|
143
154
|
export { serverProviders };
|
package/lib/server/providers.js
CHANGED
|
@@ -16,6 +16,7 @@ var store = require('../shared/store.js');
|
|
|
16
16
|
var render = require('./render.js');
|
|
17
17
|
var renderSlots = require('./render-slots.js');
|
|
18
18
|
var constants = require('../shared/constants.js');
|
|
19
|
+
var contractManager_server = require('../contracts/contractManager.server.js');
|
|
19
20
|
|
|
20
21
|
const serverProviders = [
|
|
21
22
|
core.provide({
|
|
@@ -142,6 +143,16 @@ const serverProviders = [
|
|
|
142
143
|
renderManager: tokensChildApp.CHILD_APP_RENDER_MANAGER_TOKEN,
|
|
143
144
|
},
|
|
144
145
|
}),
|
|
146
|
+
core.provide({
|
|
147
|
+
provide: tokensChildApp.CHILD_APP_CONTRACT_MANAGER,
|
|
148
|
+
scope: dippy.Scope.SINGLETON,
|
|
149
|
+
useFactory: (deps) => new contractManager_server.ChildAppContractManager(deps),
|
|
150
|
+
deps: {
|
|
151
|
+
appDi: dippy.DI_TOKEN,
|
|
152
|
+
asyncLocalStorage: tokensCommon.ASYNC_LOCAL_STORAGE_TOKEN,
|
|
153
|
+
hostProvidedContracts: tokensChildApp.HOST_PROVIDED_CONTRACTS,
|
|
154
|
+
},
|
|
155
|
+
}),
|
|
145
156
|
];
|
|
146
157
|
|
|
147
158
|
exports.serverProviders = serverProviders;
|
|
@@ -33,12 +33,11 @@ class StateManager {
|
|
|
33
33
|
this.state[key] = context.dehydrate().dispatcher;
|
|
34
34
|
}
|
|
35
35
|
catch (error) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
36
|
+
this.log.error({
|
|
37
|
+
event: 'get-state-failed',
|
|
38
|
+
error,
|
|
39
|
+
config,
|
|
40
|
+
});
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
getState() {
|
|
@@ -37,12 +37,11 @@ class StateManager {
|
|
|
37
37
|
this.state[key] = context.dehydrate().dispatcher;
|
|
38
38
|
}
|
|
39
39
|
catch (error) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
40
|
+
this.log.error({
|
|
41
|
+
event: 'get-state-failed',
|
|
42
|
+
error,
|
|
43
|
+
config,
|
|
44
|
+
});
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
getState() {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { provide } from '@tramvai/core';
|
|
1
|
+
import { provide, Scope } from '@tramvai/core';
|
|
2
2
|
import { CHILD_APP_INTERNAL_CHUNK_EXTRACTOR } from '@tramvai/tokens-child-app';
|
|
3
3
|
import { ChunkExtractor } from '@loadable/server';
|
|
4
4
|
|
|
5
5
|
const extractorProviders = (loadableStats) => [
|
|
6
6
|
provide({
|
|
7
7
|
provide: CHILD_APP_INTERNAL_CHUNK_EXTRACTOR,
|
|
8
|
+
scope: Scope.REQUEST,
|
|
8
9
|
useFactory: () => {
|
|
9
10
|
return new ChunkExtractor({ stats: loadableStats !== null && loadableStats !== void 0 ? loadableStats : {}, entrypoints: [] });
|
|
10
11
|
},
|
|
@@ -9,6 +9,7 @@ var server = require('@loadable/server');
|
|
|
9
9
|
const extractorProviders = (loadableStats) => [
|
|
10
10
|
core.provide({
|
|
11
11
|
provide: tokensChildApp.CHILD_APP_INTERNAL_CHUNK_EXTRACTOR,
|
|
12
|
+
scope: core.Scope.REQUEST,
|
|
12
13
|
useFactory: () => {
|
|
13
14
|
return new server.ChunkExtractor({ stats: loadableStats !== null && loadableStats !== void 0 ? loadableStats : {}, entrypoints: [] });
|
|
14
15
|
},
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import flatten from '@tinkoff/utils/array/flatten';
|
|
2
|
-
import { provide, Scope } from '@tramvai/core';
|
|
2
|
+
import { provide, Scope, APP_INFO_TOKEN, optional } from '@tramvai/core';
|
|
3
3
|
import { ActionRegistry } from '@tramvai/module-common';
|
|
4
|
-
import { LOGGER_TOKEN } from '@tramvai/tokens-common';
|
|
4
|
+
import { LOGGER_TOKEN, COMPONENT_REGISTRY_TOKEN, LIMIT_ACTION_GLOBAL_TIME_RUN, ACTION_CONDITIONALS, DEFERRED_ACTIONS_MAP_TOKEN, EXECUTION_CONTEXT_MANAGER_TOKEN, COMMAND_LINE_EXECUTION_CONTEXT_TOKEN, PUBSUB_TOKEN, PUBSUB_FACTORY_TOKEN, DISPATCHER_CONTEXT_TOKEN, ASYNC_LOCAL_STORAGE_TOKEN, DISPATCHER_TOKEN, STORE_MIDDLEWARE, INITIAL_APP_STATE_TOKEN } from '@tramvai/tokens-common';
|
|
5
5
|
import { RENDER_SLOTS } from '@tramvai/tokens-render';
|
|
6
|
-
import { CHILD_APP_ACTIONS_REGISTRY_TOKEN, CHILD_APP_INTERNAL_ACTION_TOKEN } from '@tramvai/tokens-child-app';
|
|
6
|
+
import { CHILD_APP_ACTIONS_REGISTRY_TOKEN, CHILD_APP_INTERNAL_ACTION_TOKEN, CHILD_REQUIRED_CONTRACTS, CHILD_APP_INTERNAL_ROOT_DI_BORROW_TOKEN, CHILD_APP_INTERNAL_ROOT_STATE_ALLOWED_STORE_TOKEN, CHILD_APP_PAGE_SERVICE_TOKEN, CHILD_APP_INTERNAL_CONFIG_TOKEN, CHILD_APP_PAGE_COMPONENTS_TOKEN } from '@tramvai/tokens-child-app';
|
|
7
|
+
import { ROUTER_TOKEN, PAGE_SERVICE_TOKEN, LINK_PREFETCH_MANAGER_TOKEN, ROUTER_SPA_ACTIONS_RUN_MODE_TOKEN } from '@tramvai/tokens-router';
|
|
8
|
+
import { ChildDispatcherContext } from '@tramvai/state';
|
|
7
9
|
import { getChildProviders as getChildProviders$1 } from '../../browser/child/singletonProviders.browser.js';
|
|
10
|
+
import { extractorProviders } from './extractorProviders.browser.browser.js';
|
|
11
|
+
import { ChildAppPageService } from '../pageService.browser.js';
|
|
8
12
|
|
|
9
|
-
const getChildProviders = (appDi) => {
|
|
13
|
+
const getChildProviders = (appDi, loadableStats) => {
|
|
10
14
|
const logger = appDi.get(LOGGER_TOKEN);
|
|
11
15
|
return [
|
|
12
16
|
provide({
|
|
@@ -30,7 +34,78 @@ const getChildProviders = (appDi) => {
|
|
|
30
34
|
actionsList: CHILD_APP_INTERNAL_ACTION_TOKEN,
|
|
31
35
|
},
|
|
32
36
|
}),
|
|
37
|
+
provide({
|
|
38
|
+
provide: CHILD_REQUIRED_CONTRACTS,
|
|
39
|
+
useValue: [
|
|
40
|
+
ROUTER_TOKEN,
|
|
41
|
+
COMPONENT_REGISTRY_TOKEN,
|
|
42
|
+
PAGE_SERVICE_TOKEN,
|
|
43
|
+
LINK_PREFETCH_MANAGER_TOKEN,
|
|
44
|
+
ROUTER_SPA_ACTIONS_RUN_MODE_TOKEN,
|
|
45
|
+
LIMIT_ACTION_GLOBAL_TIME_RUN,
|
|
46
|
+
],
|
|
47
|
+
}),
|
|
48
|
+
// for backward compatibility, when:
|
|
49
|
+
// - host app is modern (with contracts)
|
|
50
|
+
// - child app is legacy (<= v3.x.x, without contracts)
|
|
51
|
+
// - DI is isolated
|
|
52
|
+
// in legacy tramvai versions, this tokens is not borrowed in CommonChildAppModule
|
|
53
|
+
provide({
|
|
54
|
+
provide: CHILD_APP_INTERNAL_ROOT_DI_BORROW_TOKEN,
|
|
55
|
+
multi: true,
|
|
56
|
+
useValue: [
|
|
57
|
+
APP_INFO_TOKEN,
|
|
58
|
+
ACTION_CONDITIONALS,
|
|
59
|
+
DEFERRED_ACTIONS_MAP_TOKEN,
|
|
60
|
+
EXECUTION_CONTEXT_MANAGER_TOKEN,
|
|
61
|
+
COMMAND_LINE_EXECUTION_CONTEXT_TOKEN,
|
|
62
|
+
PUBSUB_TOKEN,
|
|
63
|
+
PUBSUB_FACTORY_TOKEN,
|
|
64
|
+
],
|
|
65
|
+
}),
|
|
33
66
|
...getChildProviders$1(appDi),
|
|
67
|
+
...extractorProviders(),
|
|
68
|
+
provide({
|
|
69
|
+
provide: DISPATCHER_CONTEXT_TOKEN,
|
|
70
|
+
scope: Scope.REQUEST,
|
|
71
|
+
useFactory: ({ dispatcher, middlewares, initialState, parentAllowedStores }) => {
|
|
72
|
+
var _a, _b, _c, _d;
|
|
73
|
+
const parentDispatcherContext = (_d = (_c = (_b = (_a = appDi
|
|
74
|
+
.get(optional(ASYNC_LOCAL_STORAGE_TOKEN))) === null || _a === void 0 ? void 0 : _a.getStore()) === null || _b === void 0 ? void 0 : _b.tramvaiRequestDi) === null || _c === void 0 ? void 0 : _c.get(DISPATCHER_CONTEXT_TOKEN)) !== null && _d !== void 0 ? _d : appDi.get(DISPATCHER_CONTEXT_TOKEN);
|
|
75
|
+
return new ChildDispatcherContext({
|
|
76
|
+
dispatcher,
|
|
77
|
+
// context will be set later by the CONTEXT_TOKEN
|
|
78
|
+
context: {},
|
|
79
|
+
initialState: initialState !== null && initialState !== void 0 ? initialState : { stores: [] },
|
|
80
|
+
middlewares: flatten(middlewares || []),
|
|
81
|
+
parentDispatcherContext,
|
|
82
|
+
parentAllowedStores: flatten(parentAllowedStores || []),
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
deps: {
|
|
86
|
+
dispatcher: DISPATCHER_TOKEN,
|
|
87
|
+
middlewares: { token: STORE_MIDDLEWARE, optional: true },
|
|
88
|
+
initialState: { token: INITIAL_APP_STATE_TOKEN, optional: true },
|
|
89
|
+
parentAllowedStores: {
|
|
90
|
+
token: CHILD_APP_INTERNAL_ROOT_STATE_ALLOWED_STORE_TOKEN,
|
|
91
|
+
optional: true,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
}),
|
|
95
|
+
provide({
|
|
96
|
+
provide: CHILD_APP_PAGE_SERVICE_TOKEN,
|
|
97
|
+
scope: Scope.REQUEST,
|
|
98
|
+
useFactory: (deps) => {
|
|
99
|
+
return new ChildAppPageService(deps);
|
|
100
|
+
},
|
|
101
|
+
deps: {
|
|
102
|
+
actionsRegistry: CHILD_APP_ACTIONS_REGISTRY_TOKEN,
|
|
103
|
+
config: CHILD_APP_INTERNAL_CONFIG_TOKEN,
|
|
104
|
+
componentRegistry: COMPONENT_REGISTRY_TOKEN,
|
|
105
|
+
pageService: PAGE_SERVICE_TOKEN,
|
|
106
|
+
pageComponents: optional(CHILD_APP_PAGE_COMPONENTS_TOKEN),
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
34
109
|
];
|
|
35
110
|
};
|
|
36
111
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Container } from '@tinkoff/dippy';
|
|
2
2
|
import type { Provider } from '@tramvai/core';
|
|
3
|
-
|
|
3
|
+
import type { LoadableStats } from '../webpack/moduleFederation';
|
|
4
|
+
export declare const getChildProviders: (appDi: Container, loadableStats: LoadableStats) => Provider[];
|
|
4
5
|
//# sourceMappingURL=singletonProviders.d.ts.map
|