@foxford/den 1.0.2 → 2.1.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/adapter.cjs +3 -2
- package/adapter.d.cts +1 -1
- package/adapter.d.ts +1 -1
- package/adapter.js +2 -1
- package/{chunk-4FPCRHSM.cjs → chunk-5DJZZML5.cjs} +15 -35
- package/chunk-A6ZPAM6Z.cjs +26 -0
- package/chunk-C7BM4DGX.cjs +18 -0
- package/chunk-HJO26HIQ.js +41 -0
- package/chunk-LJE7K7VD.cjs +35 -0
- package/chunk-TCYGDT2A.js +35 -0
- package/chunk-TPBI6TOU.js +26 -0
- package/{chunk-E7HG2NXO.js → chunk-WBHHHICS.js} +0 -22
- package/{chunk-S5KTWI6P.js → chunk-WRQC6BVJ.js} +9 -29
- package/chunk-XHYR3SGG.cjs +41 -0
- package/define-repository-Ca62_YCy.d.ts +83 -0
- package/define-repository-MDEWHqM7.d.cts +83 -0
- package/define-slot-BKvArA02.d.cts +74 -0
- package/define-slot-Dil8Kr1A.d.ts +74 -0
- package/define.cjs +6 -3
- package/define.d.cts +3 -2
- package/define.d.ts +3 -2
- package/define.js +7 -4
- package/index.cjs +27 -43
- package/index.d.cts +6 -26
- package/index.d.ts +6 -26
- package/index.js +9 -25
- package/island/index.cjs +156 -0
- package/island/index.d.cts +196 -0
- package/island/index.d.ts +196 -0
- package/island/index.js +156 -0
- package/package.json +26 -10
- package/types-COwVwgzE.d.cts +777 -0
- package/types-COwVwgzE.d.ts +777 -0
- package/view-adapter-CSPKr2xy.d.ts +122 -0
- package/view-adapter-zbHBVVqR.d.cts +122 -0
- package/chunk-NRE6DV6O.cjs +0 -40
- package/define-slot--HM6B232.d.ts +0 -500
- package/define-slot-es1K6_-L.d.cts +0 -500
- package/types-B4Arep3V.d.cts +0 -415
- package/types-B4Arep3V.d.ts +0 -415
package/island/index.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ViewLayerToken,
|
|
3
|
+
resolveViewAdapter,
|
|
4
|
+
viewAdapterOf
|
|
5
|
+
} from "../chunk-TCYGDT2A.js";
|
|
6
|
+
import {
|
|
7
|
+
LoggerToken,
|
|
8
|
+
logger,
|
|
9
|
+
unitLogger
|
|
10
|
+
} from "../chunk-TPBI6TOU.js";
|
|
11
|
+
import {
|
|
12
|
+
__spreadValues
|
|
13
|
+
} from "../chunk-HJO26HIQ.js";
|
|
14
|
+
|
|
15
|
+
// src/island/lifecycle.ts
|
|
16
|
+
import { log } from "@foxford/logger";
|
|
17
|
+
|
|
18
|
+
// src/island/runtime.ts
|
|
19
|
+
import { Container } from "@foxford/ioc";
|
|
20
|
+
var appContainer = null;
|
|
21
|
+
function getAppContainer() {
|
|
22
|
+
var _a;
|
|
23
|
+
if (appContainer === null) {
|
|
24
|
+
appContainer = new Container();
|
|
25
|
+
((_a = logger.getLogger("island:runtime")) != null ? _a : logger).debug("app-\u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440 \u0441\u043E\u0437\u0434\u0430\u043D");
|
|
26
|
+
}
|
|
27
|
+
return appContainer;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/island/lifecycle.ts
|
|
31
|
+
function createIslandContainer(descriptor, options = {}) {
|
|
32
|
+
var _a, _b, _c, _d, _e;
|
|
33
|
+
const { parent = getAppContainer() } = options;
|
|
34
|
+
const appLog = (_b = log.getLogger((_a = descriptor.name) != null ? _a : "app")) != null ? _b : logger;
|
|
35
|
+
const islandLog = (_c = appLog.getLogger("client")) != null ? _c : appLog;
|
|
36
|
+
try {
|
|
37
|
+
const container = parent.createChild();
|
|
38
|
+
container.bind(LoggerToken).toValue(islandLog);
|
|
39
|
+
descriptor.viewLayer.register(container);
|
|
40
|
+
const viewModels = (_d = descriptor.viewModels) != null ? _d : [];
|
|
41
|
+
const slots = Object.entries((_e = descriptor.slots) != null ? _e : {});
|
|
42
|
+
islandLog.info(
|
|
43
|
+
`\u043E\u0441\u0442\u0440\u043E\u0432: \u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440 \u0441\u043E\u0437\u0434\u0430\u043D (units=${descriptor.units.length}, vms=${viewModels.length}, slots=${slots.length})`
|
|
44
|
+
);
|
|
45
|
+
for (const unit of descriptor.units) {
|
|
46
|
+
unit.register(container);
|
|
47
|
+
}
|
|
48
|
+
for (const vm of viewModels) {
|
|
49
|
+
vm.register(container);
|
|
50
|
+
}
|
|
51
|
+
for (const [name, slot] of slots) {
|
|
52
|
+
slot.register(container, name);
|
|
53
|
+
}
|
|
54
|
+
return container;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
islandLog.error("\u043E\u0441\u0442\u0440\u043E\u0432: \u0441\u0431\u043E\u0440\u043A\u0430 \u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440\u0430 \u0443\u043F\u0430\u043B\u0430", error);
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function hydrateIslandState(container, descriptor, denState) {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
for (const vm of (_a = descriptor.viewModels) != null ? _a : []) {
|
|
63
|
+
const instance = container.resolve(vm.token);
|
|
64
|
+
const saved = denState[vm.token.description];
|
|
65
|
+
if (saved !== void 0 && typeof ((_b = instance.state) == null ? void 0 : _b.set) === "function") {
|
|
66
|
+
unitLogger(container, vm.token.description).debug("\u0433\u0438\u0434\u0440\u0430\u0446\u0438\u044F VM \u0438\u0437 denState");
|
|
67
|
+
instance.state.set(saved);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function activateIslandViewModels(container, descriptor) {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
for (const vm of (_a = descriptor.viewModels) != null ? _a : []) {
|
|
74
|
+
const instance = container.resolve(vm.token);
|
|
75
|
+
unitLogger(container, vm.token.description).debug("\u0430\u043A\u0442\u0438\u0432\u0430\u0446\u0438\u044F VM (\u0431\u0435\u0437 \u0441\u0435\u0440\u0432\u0435\u0440\u043D\u043E\u0433\u043E denState)");
|
|
76
|
+
void ((_b = instance.activate) == null ? void 0 : _b.call(instance));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function resolveEagerUnits(container, descriptor) {
|
|
80
|
+
var _a;
|
|
81
|
+
for (const token of (_a = descriptor.eager) != null ? _a : []) {
|
|
82
|
+
const instance = container.resolve(token);
|
|
83
|
+
unitLogger(container, token.description).debug("eager: \u0435\u0434\u0438\u043D\u0438\u0446\u0430 \u043F\u043E\u0434\u043D\u044F\u0442\u0430 \u043F\u0440\u0438 \u043C\u043E\u043D\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0438");
|
|
84
|
+
if (instance instanceof Promise) {
|
|
85
|
+
instance.catch(
|
|
86
|
+
(error) => unitLogger(container, token.description).error("eager: \u0435\u0434\u0438\u043D\u0438\u0446\u0430 \u043D\u0435 \u043F\u043E\u0434\u043D\u044F\u043B\u0430\u0441\u044C", error)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/island/slot-address.ts
|
|
93
|
+
function slotAddress(app, slot) {
|
|
94
|
+
return `${app}:${slot}`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/island/registry.ts
|
|
98
|
+
var nextId = 1;
|
|
99
|
+
var islands = /* @__PURE__ */ new Map();
|
|
100
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
101
|
+
var snapshot = [];
|
|
102
|
+
function notify() {
|
|
103
|
+
snapshot = [...islands.values()];
|
|
104
|
+
for (const listener of listeners) {
|
|
105
|
+
listener();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function registerIsland(record) {
|
|
109
|
+
const id = nextId++;
|
|
110
|
+
islands.set(id, __spreadValues({ id }, record));
|
|
111
|
+
notify();
|
|
112
|
+
return () => {
|
|
113
|
+
islands.delete(id);
|
|
114
|
+
notify();
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function getIslandsSnapshot() {
|
|
118
|
+
return snapshot;
|
|
119
|
+
}
|
|
120
|
+
function subscribeIslands(listener) {
|
|
121
|
+
listeners.add(listener);
|
|
122
|
+
return () => listeners.delete(listener);
|
|
123
|
+
}
|
|
124
|
+
function describeIsland(descriptor, denState) {
|
|
125
|
+
var _a, _b;
|
|
126
|
+
return {
|
|
127
|
+
denStateKeys: Object.keys(denState != null ? denState : {}),
|
|
128
|
+
name: descriptor.name,
|
|
129
|
+
// Адресами, а не локальными ключами: панель показывает острова разных приложений разом,
|
|
130
|
+
// и `aside` без префикса в этом списке ничего не значит.
|
|
131
|
+
slots: Object.keys((_a = descriptor.slots) != null ? _a : {}).map((slot) => slotAddress(descriptor.name, slot)),
|
|
132
|
+
units: descriptor.units.map((unit) => unit.token.description),
|
|
133
|
+
viewModels: ((_b = descriptor.viewModels) != null ? _b : []).map((vm) => vm.token.description)
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/island/routes.ts
|
|
138
|
+
function normalizeRoutes(routes = []) {
|
|
139
|
+
return routes.map((route) => typeof route === "string" ? { source: route } : route);
|
|
140
|
+
}
|
|
141
|
+
export {
|
|
142
|
+
ViewLayerToken,
|
|
143
|
+
activateIslandViewModels,
|
|
144
|
+
createIslandContainer,
|
|
145
|
+
describeIsland,
|
|
146
|
+
getAppContainer,
|
|
147
|
+
getIslandsSnapshot,
|
|
148
|
+
hydrateIslandState,
|
|
149
|
+
normalizeRoutes,
|
|
150
|
+
registerIsland,
|
|
151
|
+
resolveEagerUnits,
|
|
152
|
+
resolveViewAdapter,
|
|
153
|
+
slotAddress,
|
|
154
|
+
subscribeIslands,
|
|
155
|
+
viewAdapterOf
|
|
156
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foxford/den",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Den — декларативный метафреймворк Foxford (core runtime)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"foxford",
|
|
@@ -40,6 +40,11 @@
|
|
|
40
40
|
"import": "./define.js",
|
|
41
41
|
"require": "./define.cjs",
|
|
42
42
|
"types": "./define.d.ts"
|
|
43
|
+
},
|
|
44
|
+
"./island": {
|
|
45
|
+
"import": "./island/index.js",
|
|
46
|
+
"require": "./island/index.cjs",
|
|
47
|
+
"types": "./island/index.d.ts"
|
|
43
48
|
}
|
|
44
49
|
},
|
|
45
50
|
"files": [
|
|
@@ -48,12 +53,20 @@
|
|
|
48
53
|
"adapter.d.cts",
|
|
49
54
|
"adapter.d.ts",
|
|
50
55
|
"adapter.js",
|
|
51
|
-
"chunk-
|
|
52
|
-
"chunk-
|
|
53
|
-
"chunk-
|
|
54
|
-
"chunk-
|
|
55
|
-
"
|
|
56
|
-
"
|
|
56
|
+
"chunk-5DJZZML5.cjs",
|
|
57
|
+
"chunk-A6ZPAM6Z.cjs",
|
|
58
|
+
"chunk-C7BM4DGX.cjs",
|
|
59
|
+
"chunk-HJO26HIQ.js",
|
|
60
|
+
"chunk-LJE7K7VD.cjs",
|
|
61
|
+
"chunk-TCYGDT2A.js",
|
|
62
|
+
"chunk-TPBI6TOU.js",
|
|
63
|
+
"chunk-WBHHHICS.js",
|
|
64
|
+
"chunk-WRQC6BVJ.js",
|
|
65
|
+
"chunk-XHYR3SGG.cjs",
|
|
66
|
+
"define-repository-Ca62_YCy.d.ts",
|
|
67
|
+
"define-repository-MDEWHqM7.d.cts",
|
|
68
|
+
"define-slot-BKvArA02.d.cts",
|
|
69
|
+
"define-slot-Dil8Kr1A.d.ts",
|
|
57
70
|
"define.cjs",
|
|
58
71
|
"define.d.cts",
|
|
59
72
|
"define.d.ts",
|
|
@@ -62,10 +75,13 @@
|
|
|
62
75
|
"index.d.cts",
|
|
63
76
|
"index.d.ts",
|
|
64
77
|
"index.js",
|
|
78
|
+
"island",
|
|
65
79
|
"package.json",
|
|
66
|
-
"types-
|
|
67
|
-
"types-
|
|
80
|
+
"types-COwVwgzE.d.cts",
|
|
81
|
+
"types-COwVwgzE.d.ts",
|
|
82
|
+
"view-adapter-CSPKr2xy.d.ts",
|
|
83
|
+
"view-adapter-zbHBVVqR.d.cts"
|
|
68
84
|
],
|
|
69
|
-
"sha": "
|
|
85
|
+
"sha": "d6b3073",
|
|
70
86
|
"scripts": {}
|
|
71
87
|
}
|