@tramvai/core 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/actions/createActions.es.js +17 -0
- package/lib/actions/createActions.js +21 -0
- package/lib/actions/declareAction.es.js +11 -0
- package/lib/actions/declareAction.js +16 -0
- package/lib/bundles/createBundle.es.js +33 -0
- package/lib/bundles/createBundle.js +43 -0
- package/lib/createApp.es.js +104 -0
- package/lib/createApp.js +109 -0
- package/lib/index.es.js +5 -160
- package/lib/index.js +39 -194
- package/package.json +7 -8
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ACTION_PARAMETERS } from '@tramvai/tokens-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated: use `declareAction`
|
|
5
|
+
*/
|
|
6
|
+
function createAction(action) {
|
|
7
|
+
const result = Object.assign(action.fn, {
|
|
8
|
+
[ACTION_PARAMETERS]: action,
|
|
9
|
+
});
|
|
10
|
+
if (!action.conditions) {
|
|
11
|
+
// eslint-disable-next-line no-param-reassign
|
|
12
|
+
action.conditions = {};
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { createAction };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tokensCore = require('@tramvai/tokens-core');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated: use `declareAction`
|
|
9
|
+
*/
|
|
10
|
+
function createAction(action) {
|
|
11
|
+
const result = Object.assign(action.fn, {
|
|
12
|
+
[tokensCore.ACTION_PARAMETERS]: action,
|
|
13
|
+
});
|
|
14
|
+
if (!action.conditions) {
|
|
15
|
+
// eslint-disable-next-line no-param-reassign
|
|
16
|
+
action.conditions = {};
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.createAction = createAction;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function declareAction(action) {
|
|
2
|
+
return {
|
|
3
|
+
...action,
|
|
4
|
+
tramvaiActionVersion: 2,
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
function isTramvaiAction(action) {
|
|
8
|
+
return 'tramvaiActionVersion' in action && action.tramvaiActionVersion === 2;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { declareAction, isTramvaiAction };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function declareAction(action) {
|
|
6
|
+
return {
|
|
7
|
+
...action,
|
|
8
|
+
tramvaiActionVersion: 2,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function isTramvaiAction(action) {
|
|
12
|
+
return 'tramvaiActionVersion' in action && action.tramvaiActionVersion === 2;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.declareAction = declareAction;
|
|
16
|
+
exports.isTramvaiAction = isTramvaiAction;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import concat from '@tinkoff/utils/array/concat';
|
|
2
|
+
import mergeWith from '@tinkoff/utils/object/mergeWith';
|
|
3
|
+
import omit from '@tinkoff/utils/object/omit';
|
|
4
|
+
|
|
5
|
+
const mergePlan = (x, y) => {
|
|
6
|
+
if (Array.isArray(x) && Array.isArray(y)) {
|
|
7
|
+
return concat(x, y);
|
|
8
|
+
}
|
|
9
|
+
if (typeof x === 'object' && typeof y === 'object') {
|
|
10
|
+
return mergeWith(mergePlan, x, y);
|
|
11
|
+
}
|
|
12
|
+
return y;
|
|
13
|
+
};
|
|
14
|
+
const mergeOptions = /* #__PURE__*/ mergeWith(mergePlan);
|
|
15
|
+
const mergePresets = (presets) => {
|
|
16
|
+
if (!presets || !presets.length) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
const result = presets.map((preset) => mergeOptions(mergePresets(preset.presets), omit(['presets'], preset)));
|
|
20
|
+
if (result.length === 1) {
|
|
21
|
+
return result[0];
|
|
22
|
+
}
|
|
23
|
+
return mergeOptions(...result);
|
|
24
|
+
};
|
|
25
|
+
function createBundle(options) {
|
|
26
|
+
let presets = {};
|
|
27
|
+
if (options.presets) {
|
|
28
|
+
presets = mergePresets(options.presets);
|
|
29
|
+
}
|
|
30
|
+
return mergeOptions(presets, options);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { createBundle };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var concat = require('@tinkoff/utils/array/concat');
|
|
6
|
+
var mergeWith = require('@tinkoff/utils/object/mergeWith');
|
|
7
|
+
var omit = require('@tinkoff/utils/object/omit');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var concat__default = /*#__PURE__*/_interopDefaultLegacy(concat);
|
|
12
|
+
var mergeWith__default = /*#__PURE__*/_interopDefaultLegacy(mergeWith);
|
|
13
|
+
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
|
|
14
|
+
|
|
15
|
+
const mergePlan = (x, y) => {
|
|
16
|
+
if (Array.isArray(x) && Array.isArray(y)) {
|
|
17
|
+
return concat__default["default"](x, y);
|
|
18
|
+
}
|
|
19
|
+
if (typeof x === 'object' && typeof y === 'object') {
|
|
20
|
+
return mergeWith__default["default"](mergePlan, x, y);
|
|
21
|
+
}
|
|
22
|
+
return y;
|
|
23
|
+
};
|
|
24
|
+
const mergeOptions = /* #__PURE__*/ mergeWith__default["default"](mergePlan);
|
|
25
|
+
const mergePresets = (presets) => {
|
|
26
|
+
if (!presets || !presets.length) {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
const result = presets.map((preset) => mergeOptions(mergePresets(preset.presets), omit__default["default"](['presets'], preset)));
|
|
30
|
+
if (result.length === 1) {
|
|
31
|
+
return result[0];
|
|
32
|
+
}
|
|
33
|
+
return mergeOptions(...result);
|
|
34
|
+
};
|
|
35
|
+
function createBundle(options) {
|
|
36
|
+
let presets = {};
|
|
37
|
+
if (options.presets) {
|
|
38
|
+
presets = mergePresets(options.presets);
|
|
39
|
+
}
|
|
40
|
+
return mergeOptions(presets, options);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.createBundle = createBundle;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { createContainer, walkOfModules, getModuleParameters, isExtendedModule, MODULE_PARAMETERS, Scope } from '@tinkoff/dippy';
|
|
2
|
+
import { COMMAND_LINE_RUNNER_TOKEN, APP_INFO_TOKEN, BUNDLE_LIST_TOKEN, ACTIONS_LIST_TOKEN, MODULES_LIST_TOKEN } from '@tramvai/tokens-core';
|
|
3
|
+
import { LOGGER_TOKEN } from '@tramvai/tokens-common';
|
|
4
|
+
|
|
5
|
+
function appProviders(name, bundles, actions, modules) {
|
|
6
|
+
return [
|
|
7
|
+
{
|
|
8
|
+
// Информация о приложении
|
|
9
|
+
provide: APP_INFO_TOKEN,
|
|
10
|
+
scope: Scope.SINGLETON,
|
|
11
|
+
useValue: {
|
|
12
|
+
appName: name,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
// Список бандлов
|
|
17
|
+
provide: BUNDLE_LIST_TOKEN,
|
|
18
|
+
scope: Scope.SINGLETON,
|
|
19
|
+
useValue: bundles,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
// Список переданных экшенов
|
|
23
|
+
provide: ACTIONS_LIST_TOKEN,
|
|
24
|
+
scope: Scope.SINGLETON,
|
|
25
|
+
useValue: actions,
|
|
26
|
+
multi: true,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
// Спислок переданных модулей
|
|
30
|
+
provide: MODULES_LIST_TOKEN,
|
|
31
|
+
scope: Scope.SINGLETON,
|
|
32
|
+
useValue: modules,
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
class App {
|
|
37
|
+
constructor({ name, modules = [], bundles = {}, actions = [], providers }) {
|
|
38
|
+
this.di = createContainer();
|
|
39
|
+
this.modulesToResolve = new Set();
|
|
40
|
+
this.walkOfProviders(appProviders(name, bundles, actions, modules));
|
|
41
|
+
walkOfModules(modules).forEach((mod) => {
|
|
42
|
+
const moduleParameters = getModuleParameters(mod);
|
|
43
|
+
this.modulesToResolve.add(isExtendedModule(mod) ? mod.mainModule : mod);
|
|
44
|
+
this.walkOfProviders(moduleParameters.providers);
|
|
45
|
+
});
|
|
46
|
+
if (providers) {
|
|
47
|
+
this.walkOfProviders(providers);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async initialization(env, type = 'init') {
|
|
51
|
+
const logger = this.di.get({ token: LOGGER_TOKEN, optional: true });
|
|
52
|
+
const log = logger === null || logger === void 0 ? void 0 : logger('tramvai-core');
|
|
53
|
+
const commandLineRunner = this.di.get({ token: COMMAND_LINE_RUNNER_TOKEN, optional: true });
|
|
54
|
+
if (!commandLineRunner) {
|
|
55
|
+
throw new Error('`COMMAND_LINE_RUNNER_TOKEN` is not defined, have you added `@tramvai/module-common` to your dependency list?');
|
|
56
|
+
}
|
|
57
|
+
log === null || log === void 0 ? void 0 : log.warn({
|
|
58
|
+
event: 'tramvai-app-init',
|
|
59
|
+
message: 'Initializing. Run CommandLineRunner.',
|
|
60
|
+
});
|
|
61
|
+
const di = await commandLineRunner.run(env, type);
|
|
62
|
+
log === null || log === void 0 ? void 0 : log.warn({
|
|
63
|
+
event: 'tramvai-app-init',
|
|
64
|
+
message: 'CommandLineRunner executed successfully. Resolving modules.',
|
|
65
|
+
});
|
|
66
|
+
this.resolveModules();
|
|
67
|
+
log === null || log === void 0 ? void 0 : log.warn({
|
|
68
|
+
event: 'tramvai-app-init',
|
|
69
|
+
message: 'Modules resolved successfully. Tramvai App initialized',
|
|
70
|
+
});
|
|
71
|
+
return di;
|
|
72
|
+
}
|
|
73
|
+
walkOfProviders(providers) {
|
|
74
|
+
providers.forEach((provide) => {
|
|
75
|
+
this.di.register(provide);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
resolveModules() {
|
|
79
|
+
this.modulesToResolve.forEach((ModuleToResolve) => {
|
|
80
|
+
// eslint-disable-next-line no-new
|
|
81
|
+
new ModuleToResolve(this.resolveModuleDeps(ModuleToResolve));
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
resolveModuleDeps(module) {
|
|
85
|
+
const { deps } = module[MODULE_PARAMETERS];
|
|
86
|
+
if (deps) {
|
|
87
|
+
return this.di.getOfDeps(deps);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function createApp(options) {
|
|
92
|
+
let app;
|
|
93
|
+
try {
|
|
94
|
+
app = new App(options);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
// Флаг необходим чтобы среди логов найти те которые не дали трамваю стартануть
|
|
98
|
+
error.appCreationError = true;
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
return app.initialization(typeof window === 'undefined' ? 'server' : 'client').then(() => app);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { App, createApp };
|
package/lib/createApp.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var dippy = require('@tinkoff/dippy');
|
|
6
|
+
var tokensCore = require('@tramvai/tokens-core');
|
|
7
|
+
var tokensCommon = require('@tramvai/tokens-common');
|
|
8
|
+
|
|
9
|
+
function appProviders(name, bundles, actions, modules) {
|
|
10
|
+
return [
|
|
11
|
+
{
|
|
12
|
+
// Информация о приложении
|
|
13
|
+
provide: tokensCore.APP_INFO_TOKEN,
|
|
14
|
+
scope: dippy.Scope.SINGLETON,
|
|
15
|
+
useValue: {
|
|
16
|
+
appName: name,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
// Список бандлов
|
|
21
|
+
provide: tokensCore.BUNDLE_LIST_TOKEN,
|
|
22
|
+
scope: dippy.Scope.SINGLETON,
|
|
23
|
+
useValue: bundles,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
// Список переданных экшенов
|
|
27
|
+
provide: tokensCore.ACTIONS_LIST_TOKEN,
|
|
28
|
+
scope: dippy.Scope.SINGLETON,
|
|
29
|
+
useValue: actions,
|
|
30
|
+
multi: true,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
// Спислок переданных модулей
|
|
34
|
+
provide: tokensCore.MODULES_LIST_TOKEN,
|
|
35
|
+
scope: dippy.Scope.SINGLETON,
|
|
36
|
+
useValue: modules,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
class App {
|
|
41
|
+
constructor({ name, modules = [], bundles = {}, actions = [], providers }) {
|
|
42
|
+
this.di = dippy.createContainer();
|
|
43
|
+
this.modulesToResolve = new Set();
|
|
44
|
+
this.walkOfProviders(appProviders(name, bundles, actions, modules));
|
|
45
|
+
dippy.walkOfModules(modules).forEach((mod) => {
|
|
46
|
+
const moduleParameters = dippy.getModuleParameters(mod);
|
|
47
|
+
this.modulesToResolve.add(dippy.isExtendedModule(mod) ? mod.mainModule : mod);
|
|
48
|
+
this.walkOfProviders(moduleParameters.providers);
|
|
49
|
+
});
|
|
50
|
+
if (providers) {
|
|
51
|
+
this.walkOfProviders(providers);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async initialization(env, type = 'init') {
|
|
55
|
+
const logger = this.di.get({ token: tokensCommon.LOGGER_TOKEN, optional: true });
|
|
56
|
+
const log = logger === null || logger === void 0 ? void 0 : logger('tramvai-core');
|
|
57
|
+
const commandLineRunner = this.di.get({ token: tokensCore.COMMAND_LINE_RUNNER_TOKEN, optional: true });
|
|
58
|
+
if (!commandLineRunner) {
|
|
59
|
+
throw new Error('`COMMAND_LINE_RUNNER_TOKEN` is not defined, have you added `@tramvai/module-common` to your dependency list?');
|
|
60
|
+
}
|
|
61
|
+
log === null || log === void 0 ? void 0 : log.warn({
|
|
62
|
+
event: 'tramvai-app-init',
|
|
63
|
+
message: 'Initializing. Run CommandLineRunner.',
|
|
64
|
+
});
|
|
65
|
+
const di = await commandLineRunner.run(env, type);
|
|
66
|
+
log === null || log === void 0 ? void 0 : log.warn({
|
|
67
|
+
event: 'tramvai-app-init',
|
|
68
|
+
message: 'CommandLineRunner executed successfully. Resolving modules.',
|
|
69
|
+
});
|
|
70
|
+
this.resolveModules();
|
|
71
|
+
log === null || log === void 0 ? void 0 : log.warn({
|
|
72
|
+
event: 'tramvai-app-init',
|
|
73
|
+
message: 'Modules resolved successfully. Tramvai App initialized',
|
|
74
|
+
});
|
|
75
|
+
return di;
|
|
76
|
+
}
|
|
77
|
+
walkOfProviders(providers) {
|
|
78
|
+
providers.forEach((provide) => {
|
|
79
|
+
this.di.register(provide);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
resolveModules() {
|
|
83
|
+
this.modulesToResolve.forEach((ModuleToResolve) => {
|
|
84
|
+
// eslint-disable-next-line no-new
|
|
85
|
+
new ModuleToResolve(this.resolveModuleDeps(ModuleToResolve));
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
resolveModuleDeps(module) {
|
|
89
|
+
const { deps } = module[dippy.MODULE_PARAMETERS];
|
|
90
|
+
if (deps) {
|
|
91
|
+
return this.di.getOfDeps(deps);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function createApp(options) {
|
|
96
|
+
let app;
|
|
97
|
+
try {
|
|
98
|
+
app = new App(options);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
// Флаг необходим чтобы среди логов найти те которые не дали трамваю стартануть
|
|
102
|
+
error.appCreationError = true;
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
return app.initialization(typeof window === 'undefined' ? 'server' : 'client').then(() => app);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
exports.App = App;
|
|
109
|
+
exports.createApp = createApp;
|
package/lib/index.es.js
CHANGED
|
@@ -1,161 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
1
|
+
export { App, createApp } from './createApp.es.js';
|
|
2
|
+
export { createBundle } from './bundles/createBundle.es.js';
|
|
3
|
+
export { createAction } from './actions/createActions.es.js';
|
|
4
|
+
export { declareAction, isTramvaiAction } from './actions/declareAction.es.js';
|
|
4
5
|
export * from '@tramvai/tokens-core';
|
|
5
|
-
|
|
6
|
-
import concat from '@tinkoff/utils/array/concat';
|
|
7
|
-
import mergeWith from '@tinkoff/utils/object/mergeWith';
|
|
8
|
-
import omit from '@tinkoff/utils/object/omit';
|
|
9
|
-
|
|
10
|
-
function appProviders(name, bundles, actions, modules) {
|
|
11
|
-
return [
|
|
12
|
-
{
|
|
13
|
-
// Информация о приложении
|
|
14
|
-
provide: APP_INFO_TOKEN,
|
|
15
|
-
scope: Scope.SINGLETON,
|
|
16
|
-
useValue: {
|
|
17
|
-
appName: name,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
// Список бандлов
|
|
22
|
-
provide: BUNDLE_LIST_TOKEN,
|
|
23
|
-
scope: Scope.SINGLETON,
|
|
24
|
-
useValue: bundles,
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
// Список переданных экшенов
|
|
28
|
-
provide: ACTIONS_LIST_TOKEN,
|
|
29
|
-
scope: Scope.SINGLETON,
|
|
30
|
-
useValue: actions,
|
|
31
|
-
multi: true,
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
// Спислок переданных модулей
|
|
35
|
-
provide: MODULES_LIST_TOKEN,
|
|
36
|
-
scope: Scope.SINGLETON,
|
|
37
|
-
useValue: modules,
|
|
38
|
-
},
|
|
39
|
-
];
|
|
40
|
-
}
|
|
41
|
-
class App {
|
|
42
|
-
constructor({ name, modules = [], bundles = {}, actions = [], providers }) {
|
|
43
|
-
this.di = createContainer();
|
|
44
|
-
this.modulesToResolve = new Set();
|
|
45
|
-
this.walkOfProviders(appProviders(name, bundles, actions, modules));
|
|
46
|
-
walkOfModules(modules).forEach((mod) => {
|
|
47
|
-
const moduleParameters = getModuleParameters(mod);
|
|
48
|
-
this.modulesToResolve.add(isExtendedModule(mod) ? mod.mainModule : mod);
|
|
49
|
-
this.walkOfProviders(moduleParameters.providers);
|
|
50
|
-
});
|
|
51
|
-
if (providers) {
|
|
52
|
-
this.walkOfProviders(providers);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async initialization(env, type = 'init') {
|
|
56
|
-
const logger = this.di.get({ token: LOGGER_TOKEN, optional: true });
|
|
57
|
-
const log = logger === null || logger === void 0 ? void 0 : logger('tramvai-core');
|
|
58
|
-
const commandLineRunner = this.di.get({ token: COMMAND_LINE_RUNNER_TOKEN, optional: true });
|
|
59
|
-
if (!commandLineRunner) {
|
|
60
|
-
throw new Error('`COMMAND_LINE_RUNNER_TOKEN` is not defined, have you added `@tramvai/module-common` to your dependency list?');
|
|
61
|
-
}
|
|
62
|
-
log === null || log === void 0 ? void 0 : log.warn({
|
|
63
|
-
event: 'tramvai-app-init',
|
|
64
|
-
message: 'Initializing. Run CommandLineRunner.',
|
|
65
|
-
});
|
|
66
|
-
const di = await commandLineRunner.run(env, type);
|
|
67
|
-
log === null || log === void 0 ? void 0 : log.warn({
|
|
68
|
-
event: 'tramvai-app-init',
|
|
69
|
-
message: 'CommandLineRunner executed successfully. Resolving modules.',
|
|
70
|
-
});
|
|
71
|
-
this.resolveModules();
|
|
72
|
-
log === null || log === void 0 ? void 0 : log.warn({
|
|
73
|
-
event: 'tramvai-app-init',
|
|
74
|
-
message: 'Modules resolved successfully. Tramvai App initialized',
|
|
75
|
-
});
|
|
76
|
-
return di;
|
|
77
|
-
}
|
|
78
|
-
walkOfProviders(providers) {
|
|
79
|
-
providers.forEach((provide) => {
|
|
80
|
-
this.di.register(provide);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
resolveModules() {
|
|
84
|
-
this.modulesToResolve.forEach((ModuleToResolve) => {
|
|
85
|
-
// eslint-disable-next-line no-new
|
|
86
|
-
new ModuleToResolve(this.resolveModuleDeps(ModuleToResolve));
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
resolveModuleDeps(module) {
|
|
90
|
-
const { deps } = module[MODULE_PARAMETERS];
|
|
91
|
-
if (deps) {
|
|
92
|
-
return this.di.getOfDeps(deps);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
function createApp(options) {
|
|
97
|
-
let app;
|
|
98
|
-
try {
|
|
99
|
-
app = new App(options);
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
// Флаг необходим чтобы среди логов найти те которые не дали трамваю стартануть
|
|
103
|
-
error.appCreationError = true;
|
|
104
|
-
throw error;
|
|
105
|
-
}
|
|
106
|
-
return app.initialization(typeof window === 'undefined' ? 'server' : 'client').then(() => app);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const mergePlan = (x, y) => {
|
|
110
|
-
if (Array.isArray(x) && Array.isArray(y)) {
|
|
111
|
-
return concat(x, y);
|
|
112
|
-
}
|
|
113
|
-
if (typeof x === 'object' && typeof y === 'object') {
|
|
114
|
-
return mergeWith(mergePlan, x, y);
|
|
115
|
-
}
|
|
116
|
-
return y;
|
|
117
|
-
};
|
|
118
|
-
const mergeOptions = /* #__PURE__*/ mergeWith(mergePlan);
|
|
119
|
-
const mergePresets = (presets) => {
|
|
120
|
-
if (!presets || !presets.length) {
|
|
121
|
-
return {};
|
|
122
|
-
}
|
|
123
|
-
const result = presets.map((preset) => mergeOptions(mergePresets(preset.presets), omit(['presets'], preset)));
|
|
124
|
-
if (result.length === 1) {
|
|
125
|
-
return result[0];
|
|
126
|
-
}
|
|
127
|
-
return mergeOptions(...result);
|
|
128
|
-
};
|
|
129
|
-
function createBundle(options) {
|
|
130
|
-
let presets = {};
|
|
131
|
-
if (options.presets) {
|
|
132
|
-
presets = mergePresets(options.presets);
|
|
133
|
-
}
|
|
134
|
-
return mergeOptions(presets, options);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* @deprecated: use `declareAction`
|
|
139
|
-
*/
|
|
140
|
-
function createAction(action) {
|
|
141
|
-
const result = Object.assign(action.fn, {
|
|
142
|
-
[ACTION_PARAMETERS]: action,
|
|
143
|
-
});
|
|
144
|
-
if (!action.conditions) {
|
|
145
|
-
// eslint-disable-next-line no-param-reassign
|
|
146
|
-
action.conditions = {};
|
|
147
|
-
}
|
|
148
|
-
return result;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function declareAction(action) {
|
|
152
|
-
return {
|
|
153
|
-
...action,
|
|
154
|
-
tramvaiActionVersion: 2,
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
function isTramvaiAction(action) {
|
|
158
|
-
return 'tramvaiActionVersion' in action && action.tramvaiActionVersion === 2;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export { App, createAction, createApp, createBundle, declareAction, isTramvaiAction };
|
|
6
|
+
export { DI_TOKEN, IS_DI_CHILD_CONTAINER_TOKEN, MODULE_PARAMETERS, Module, Scope, createToken, declareModule, getModuleParameters, isExtendedModule, optional, provide, walkOfModules } from '@tinkoff/dippy';
|
package/lib/index.js
CHANGED
|
@@ -2,227 +2,72 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var createApp = require('./createApp.js');
|
|
6
|
+
var createBundle = require('./bundles/createBundle.js');
|
|
7
|
+
var createActions = require('./actions/createActions.js');
|
|
8
|
+
var declareAction = require('./actions/declareAction.js');
|
|
6
9
|
var tokensCore = require('@tramvai/tokens-core');
|
|
7
|
-
var
|
|
8
|
-
var concat = require('@tinkoff/utils/array/concat');
|
|
9
|
-
var mergeWith = require('@tinkoff/utils/object/mergeWith');
|
|
10
|
-
var omit = require('@tinkoff/utils/object/omit');
|
|
11
|
-
|
|
12
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
|
-
|
|
14
|
-
var concat__default = /*#__PURE__*/_interopDefaultLegacy(concat);
|
|
15
|
-
var mergeWith__default = /*#__PURE__*/_interopDefaultLegacy(mergeWith);
|
|
16
|
-
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
|
|
17
|
-
|
|
18
|
-
function appProviders(name, bundles, actions, modules) {
|
|
19
|
-
return [
|
|
20
|
-
{
|
|
21
|
-
// Информация о приложении
|
|
22
|
-
provide: tokensCore.APP_INFO_TOKEN,
|
|
23
|
-
scope: dippy.Scope.SINGLETON,
|
|
24
|
-
useValue: {
|
|
25
|
-
appName: name,
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
// Список бандлов
|
|
30
|
-
provide: tokensCore.BUNDLE_LIST_TOKEN,
|
|
31
|
-
scope: dippy.Scope.SINGLETON,
|
|
32
|
-
useValue: bundles,
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
// Список переданных экшенов
|
|
36
|
-
provide: tokensCore.ACTIONS_LIST_TOKEN,
|
|
37
|
-
scope: dippy.Scope.SINGLETON,
|
|
38
|
-
useValue: actions,
|
|
39
|
-
multi: true,
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
// Спислок переданных модулей
|
|
43
|
-
provide: tokensCore.MODULES_LIST_TOKEN,
|
|
44
|
-
scope: dippy.Scope.SINGLETON,
|
|
45
|
-
useValue: modules,
|
|
46
|
-
},
|
|
47
|
-
];
|
|
48
|
-
}
|
|
49
|
-
class App {
|
|
50
|
-
constructor({ name, modules = [], bundles = {}, actions = [], providers }) {
|
|
51
|
-
this.di = dippy.createContainer();
|
|
52
|
-
this.modulesToResolve = new Set();
|
|
53
|
-
this.walkOfProviders(appProviders(name, bundles, actions, modules));
|
|
54
|
-
dippy.walkOfModules(modules).forEach((mod) => {
|
|
55
|
-
const moduleParameters = dippy.getModuleParameters(mod);
|
|
56
|
-
this.modulesToResolve.add(dippy.isExtendedModule(mod) ? mod.mainModule : mod);
|
|
57
|
-
this.walkOfProviders(moduleParameters.providers);
|
|
58
|
-
});
|
|
59
|
-
if (providers) {
|
|
60
|
-
this.walkOfProviders(providers);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
async initialization(env, type = 'init') {
|
|
64
|
-
const logger = this.di.get({ token: tokensCommon.LOGGER_TOKEN, optional: true });
|
|
65
|
-
const log = logger === null || logger === void 0 ? void 0 : logger('tramvai-core');
|
|
66
|
-
const commandLineRunner = this.di.get({ token: tokensCore.COMMAND_LINE_RUNNER_TOKEN, optional: true });
|
|
67
|
-
if (!commandLineRunner) {
|
|
68
|
-
throw new Error('`COMMAND_LINE_RUNNER_TOKEN` is not defined, have you added `@tramvai/module-common` to your dependency list?');
|
|
69
|
-
}
|
|
70
|
-
log === null || log === void 0 ? void 0 : log.warn({
|
|
71
|
-
event: 'tramvai-app-init',
|
|
72
|
-
message: 'Initializing. Run CommandLineRunner.',
|
|
73
|
-
});
|
|
74
|
-
const di = await commandLineRunner.run(env, type);
|
|
75
|
-
log === null || log === void 0 ? void 0 : log.warn({
|
|
76
|
-
event: 'tramvai-app-init',
|
|
77
|
-
message: 'CommandLineRunner executed successfully. Resolving modules.',
|
|
78
|
-
});
|
|
79
|
-
this.resolveModules();
|
|
80
|
-
log === null || log === void 0 ? void 0 : log.warn({
|
|
81
|
-
event: 'tramvai-app-init',
|
|
82
|
-
message: 'Modules resolved successfully. Tramvai App initialized',
|
|
83
|
-
});
|
|
84
|
-
return di;
|
|
85
|
-
}
|
|
86
|
-
walkOfProviders(providers) {
|
|
87
|
-
providers.forEach((provide) => {
|
|
88
|
-
this.di.register(provide);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
resolveModules() {
|
|
92
|
-
this.modulesToResolve.forEach((ModuleToResolve) => {
|
|
93
|
-
// eslint-disable-next-line no-new
|
|
94
|
-
new ModuleToResolve(this.resolveModuleDeps(ModuleToResolve));
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
resolveModuleDeps(module) {
|
|
98
|
-
const { deps } = module[dippy.MODULE_PARAMETERS];
|
|
99
|
-
if (deps) {
|
|
100
|
-
return this.di.getOfDeps(deps);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
function createApp(options) {
|
|
105
|
-
let app;
|
|
106
|
-
try {
|
|
107
|
-
app = new App(options);
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
// Флаг необходим чтобы среди логов найти те которые не дали трамваю стартануть
|
|
111
|
-
error.appCreationError = true;
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
return app.initialization(typeof window === 'undefined' ? 'server' : 'client').then(() => app);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const mergePlan = (x, y) => {
|
|
118
|
-
if (Array.isArray(x) && Array.isArray(y)) {
|
|
119
|
-
return concat__default["default"](x, y);
|
|
120
|
-
}
|
|
121
|
-
if (typeof x === 'object' && typeof y === 'object') {
|
|
122
|
-
return mergeWith__default["default"](mergePlan, x, y);
|
|
123
|
-
}
|
|
124
|
-
return y;
|
|
125
|
-
};
|
|
126
|
-
const mergeOptions = /* #__PURE__*/ mergeWith__default["default"](mergePlan);
|
|
127
|
-
const mergePresets = (presets) => {
|
|
128
|
-
if (!presets || !presets.length) {
|
|
129
|
-
return {};
|
|
130
|
-
}
|
|
131
|
-
const result = presets.map((preset) => mergeOptions(mergePresets(preset.presets), omit__default["default"](['presets'], preset)));
|
|
132
|
-
if (result.length === 1) {
|
|
133
|
-
return result[0];
|
|
134
|
-
}
|
|
135
|
-
return mergeOptions(...result);
|
|
136
|
-
};
|
|
137
|
-
function createBundle(options) {
|
|
138
|
-
let presets = {};
|
|
139
|
-
if (options.presets) {
|
|
140
|
-
presets = mergePresets(options.presets);
|
|
141
|
-
}
|
|
142
|
-
return mergeOptions(presets, options);
|
|
143
|
-
}
|
|
10
|
+
var dippy = require('@tinkoff/dippy');
|
|
144
11
|
|
|
145
|
-
/**
|
|
146
|
-
* @deprecated: use `declareAction`
|
|
147
|
-
*/
|
|
148
|
-
function createAction(action) {
|
|
149
|
-
const result = Object.assign(action.fn, {
|
|
150
|
-
[tokensCore.ACTION_PARAMETERS]: action,
|
|
151
|
-
});
|
|
152
|
-
if (!action.conditions) {
|
|
153
|
-
// eslint-disable-next-line no-param-reassign
|
|
154
|
-
action.conditions = {};
|
|
155
|
-
}
|
|
156
|
-
return result;
|
|
157
|
-
}
|
|
158
12
|
|
|
159
|
-
function declareAction(action) {
|
|
160
|
-
return {
|
|
161
|
-
...action,
|
|
162
|
-
tramvaiActionVersion: 2,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
function isTramvaiAction(action) {
|
|
166
|
-
return 'tramvaiActionVersion' in action && action.tramvaiActionVersion === 2;
|
|
167
|
-
}
|
|
168
13
|
|
|
14
|
+
exports.App = createApp.App;
|
|
15
|
+
exports.createApp = createApp.createApp;
|
|
16
|
+
exports.createBundle = createBundle.createBundle;
|
|
17
|
+
exports.createAction = createActions.createAction;
|
|
18
|
+
exports.declareAction = declareAction.declareAction;
|
|
19
|
+
exports.isTramvaiAction = declareAction.isTramvaiAction;
|
|
169
20
|
Object.defineProperty(exports, 'DI_TOKEN', {
|
|
170
|
-
|
|
171
|
-
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return dippy.DI_TOKEN; }
|
|
172
23
|
});
|
|
173
24
|
Object.defineProperty(exports, 'IS_DI_CHILD_CONTAINER_TOKEN', {
|
|
174
|
-
|
|
175
|
-
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return dippy.IS_DI_CHILD_CONTAINER_TOKEN; }
|
|
176
27
|
});
|
|
177
28
|
Object.defineProperty(exports, 'MODULE_PARAMETERS', {
|
|
178
|
-
|
|
179
|
-
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () { return dippy.MODULE_PARAMETERS; }
|
|
180
31
|
});
|
|
181
32
|
Object.defineProperty(exports, 'Module', {
|
|
182
|
-
|
|
183
|
-
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () { return dippy.Module; }
|
|
184
35
|
});
|
|
185
36
|
Object.defineProperty(exports, 'Scope', {
|
|
186
|
-
|
|
187
|
-
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return dippy.Scope; }
|
|
188
39
|
});
|
|
189
40
|
Object.defineProperty(exports, 'createToken', {
|
|
190
|
-
|
|
191
|
-
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () { return dippy.createToken; }
|
|
192
43
|
});
|
|
193
44
|
Object.defineProperty(exports, 'declareModule', {
|
|
194
|
-
|
|
195
|
-
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function () { return dippy.declareModule; }
|
|
196
47
|
});
|
|
197
48
|
Object.defineProperty(exports, 'getModuleParameters', {
|
|
198
|
-
|
|
199
|
-
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () { return dippy.getModuleParameters; }
|
|
200
51
|
});
|
|
201
52
|
Object.defineProperty(exports, 'isExtendedModule', {
|
|
202
|
-
|
|
203
|
-
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: function () { return dippy.isExtendedModule; }
|
|
204
55
|
});
|
|
205
56
|
Object.defineProperty(exports, 'optional', {
|
|
206
|
-
|
|
207
|
-
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function () { return dippy.optional; }
|
|
208
59
|
});
|
|
209
60
|
Object.defineProperty(exports, 'provide', {
|
|
210
|
-
|
|
211
|
-
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () { return dippy.provide; }
|
|
212
63
|
});
|
|
213
64
|
Object.defineProperty(exports, 'walkOfModules', {
|
|
214
|
-
|
|
215
|
-
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () { return dippy.walkOfModules; }
|
|
216
67
|
});
|
|
217
|
-
exports.App = App;
|
|
218
|
-
exports.createAction = createAction;
|
|
219
|
-
exports.createApp = createApp;
|
|
220
|
-
exports.createBundle = createBundle;
|
|
221
|
-
exports.declareAction = declareAction;
|
|
222
|
-
exports.isTramvaiAction = isTramvaiAction;
|
|
223
68
|
Object.keys(tokensCore).forEach(function (k) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
69
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
get: function () { return tokensCore[k]; }
|
|
72
|
+
});
|
|
228
73
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.72.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -14,16 +14,15 @@
|
|
|
14
14
|
"url": "git@github.com:Tinkoff/tramvai.git"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
|
-
"build": "tramvai-build --
|
|
18
|
-
"watch": "tsc -w"
|
|
19
|
-
"build-for-publish": "true"
|
|
17
|
+
"build": "tramvai-build --forPublish --preserveModules",
|
|
18
|
+
"watch": "tsc -w"
|
|
20
19
|
},
|
|
21
20
|
"dependencies": {
|
|
22
21
|
"@tinkoff/utils": "^2.1.2",
|
|
23
|
-
"@tramvai/tokens-common": "2.
|
|
24
|
-
"@tramvai/tokens-core": "2.
|
|
25
|
-
"@tramvai/types-actions-state-context": "2.
|
|
26
|
-
"@tinkoff/dippy": "0.8.
|
|
22
|
+
"@tramvai/tokens-common": "2.72.0",
|
|
23
|
+
"@tramvai/tokens-core": "2.72.0",
|
|
24
|
+
"@tramvai/types-actions-state-context": "2.72.0",
|
|
25
|
+
"@tinkoff/dippy": "0.8.13",
|
|
27
26
|
"tslib": "^2.4.0"
|
|
28
27
|
},
|
|
29
28
|
"peerDependencies": {
|