@foxford/den 1.0.1 → 2.0.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 +8 -42
- package/adapter.d.cts +1 -1
- package/adapter.d.ts +1 -1
- package/adapter.js +5 -13
- package/chunk-5DJZZML5.cjs +224 -0
- 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-WBHHHICS.js +18 -0
- package/chunk-WRQC6BVJ.js +224 -0
- package/chunk-XHYR3SGG.cjs +41 -0
- package/define-repository-DZg34Tb3.d.ts +83 -0
- package/define-repository-OpMj-Q9O.d.cts +83 -0
- package/define-slot-ESU7FR9O.d.ts +74 -0
- package/define-slot-RfgqKa6n.d.cts +74 -0
- package/define.cjs +15 -271
- package/define.d.cts +3 -2
- package/define.d.ts +3 -2
- package/define.js +15 -236
- package/index.cjs +88 -372
- package/index.d.cts +11 -10
- package/index.d.ts +11 -10
- package/index.js +39 -271
- package/island/index.cjs +137 -0
- package/island/index.d.cts +158 -0
- package/island/index.d.ts +158 -0
- package/island/index.js +137 -0
- package/package.json +27 -7
- package/types-Deyolj1-.d.cts +802 -0
- package/types-Deyolj1-.d.ts +802 -0
- package/view-adapter-CL0vZ-rv.d.ts +110 -0
- package/view-adapter-vwO-7b1t.d.cts +110 -0
- 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/index.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { C as Core, a as ContainerManager, R as RequestContext, G as GuardRunner, b as Guard, c as GuardResult, N as NavigationManager, d as NavigationEntry, e as NavigationInterceptor, D as Disposable, L as LeaveGuardResult, S as StateSerializer } from './types-
|
|
2
|
-
export {
|
|
1
|
+
import { C as Core, a as ContainerManager, R as RequestContext, G as GuardRunner, b as Guard, c as GuardResult, N as NavigationManager, d as NavigationEntry, e as NavigationInterceptor, D as Disposable, L as LeaveGuardResult, S as StateSerializer, f as DefineGuardOptions, g as GuardDefinition, H as HostConfig, h as DefineHostOptions, i as HostDefinition, E as ExtensionConfig, j as DefineExtensionOptions, k as ExtensionDefinition, A as ActionGuard, l as DefineActionGuardOptions, m as ActionGuardDefinition, n as LayoutConfig, o as DefineLayoutOptions, p as LayoutDefinition, q as LayerConfig, r as DefineLayerOptions, s as LayerDefinition } from './types-Deyolj1-.cjs';
|
|
2
|
+
export { t as Activatable, u as ActivatableToken, v as ContainerManagerToken, w as DefineRepositoryOptions, x as DefineServiceOptions, y as DefineViewModelOptions, z as Definition, B as GuardRunnerToken, F as NavigationManagerToken, I as RepositoryDefinition, J as RequestContextToken, K as ServiceDefinition, M as SlotEntry, O as SlotRegistry, P as SlotRegistryToken, Q as StateCache, T as StateParticipant, U as StateRegistry, V as StateRegistryToken, W as StateSerializerToken, X as ViewModelDefinition } from './types-Deyolj1-.cjs';
|
|
3
3
|
import { Container, Token } from '@foxford/ioc';
|
|
4
4
|
import { DefinitionResolver } from './adapter.cjs';
|
|
5
|
-
|
|
6
|
-
export {
|
|
5
|
+
export { d as defineRepository, a as defineService, b as defineViewModel } from './define-repository-OpMj-Q9O.cjs';
|
|
6
|
+
export { D as DefineSlotOptions, S as SlotDefinition, d as defineSlot } from './define-slot-RfgqKa6n.cjs';
|
|
7
|
+
export { V as ViewAdapter, a as ViewLayerDefinition, b as ViewLayerToken } from './view-adapter-vwO-7b1t.cjs';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Опции для создания Core Runtime.
|
|
@@ -273,22 +274,22 @@ declare function defineGuard<Deps extends readonly Token<unknown>[] = readonly [
|
|
|
273
274
|
* Определяет конфигурацию приложения с декларативным списком сервисов и guards.
|
|
274
275
|
* Заменяет ручной вызов setupContainer() — декларирует, какие сервисы запускаются
|
|
275
276
|
* при старте (eager), какие — лениво (lazy), и какие guards применяются глобально.
|
|
276
|
-
* Регистрирует
|
|
277
|
+
* Регистрирует HostConfig-значение в IoC-контейнере.
|
|
277
278
|
*
|
|
278
|
-
* @param token - Токен для регистрации
|
|
279
|
+
* @param token - Токен для регистрации HostConfig в IoC
|
|
279
280
|
* @param options - Опции: eager, lazy, guards
|
|
280
|
-
* @returns
|
|
281
|
+
* @returns HostDefinition с методом register(container)
|
|
281
282
|
*
|
|
282
283
|
* @example
|
|
283
284
|
* // app/app.ts
|
|
284
|
-
* export const app =
|
|
285
|
+
* export const app = defineHost(AppToken, {
|
|
285
286
|
* eager: [AuthServiceToken, NotificationServiceToken],
|
|
286
287
|
* lazy: [CartServiceToken],
|
|
287
288
|
* guards: [GlobalAuthGuardToken],
|
|
288
289
|
* })
|
|
289
290
|
* app.register(appContainer)
|
|
290
291
|
*/
|
|
291
|
-
declare function
|
|
292
|
+
declare function defineHost(token: Token<HostConfig>, options?: DefineHostOptions): HostDefinition;
|
|
292
293
|
|
|
293
294
|
/**
|
|
294
295
|
* Определяет app-scope расширение с lifecycle-хуками activate/deactivate.
|
|
@@ -383,4 +384,4 @@ declare function defineLayout(token: Token<LayoutConfig>, options?: DefineLayout
|
|
|
383
384
|
*/
|
|
384
385
|
declare function defineLayer(token: Token<LayerConfig>, options: DefineLayerOptions): LayerDefinition;
|
|
385
386
|
|
|
386
|
-
export { ActionGuard, ActionGuardDefinition,
|
|
387
|
+
export { ActionGuard, ActionGuardDefinition, ContainerManager, ContainerManagerImpl, Core, type CreateCoreOptions, DefineActionGuardOptions, DefineExtensionOptions, DefineGuardOptions, DefineHostOptions, DefineLayerOptions, DefineLayoutOptions, Disposable, ExtensionConfig, ExtensionDefinition, Guard, GuardDefinition, GuardResult, GuardRunner, GuardRunnerImpl, HostConfig, HostDefinition, LayerConfig, LayerDefinition, LayoutConfig, LayoutDefinition, LeaveGuardResult, NavigationEntry, NavigationInterceptor, NavigationManager, NavigationManagerImpl, RequestContext, StateSerializer, StateSerializerImpl, createCore, defaultGlobalResolver, defineActionGuard, defineExtension, defineGuard, defineHost, defineLayer, defineLayout };
|
package/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { C as Core, a as ContainerManager, R as RequestContext, G as GuardRunner, b as Guard, c as GuardResult, N as NavigationManager, d as NavigationEntry, e as NavigationInterceptor, D as Disposable, L as LeaveGuardResult, S as StateSerializer } from './types-
|
|
2
|
-
export {
|
|
1
|
+
import { C as Core, a as ContainerManager, R as RequestContext, G as GuardRunner, b as Guard, c as GuardResult, N as NavigationManager, d as NavigationEntry, e as NavigationInterceptor, D as Disposable, L as LeaveGuardResult, S as StateSerializer, f as DefineGuardOptions, g as GuardDefinition, H as HostConfig, h as DefineHostOptions, i as HostDefinition, E as ExtensionConfig, j as DefineExtensionOptions, k as ExtensionDefinition, A as ActionGuard, l as DefineActionGuardOptions, m as ActionGuardDefinition, n as LayoutConfig, o as DefineLayoutOptions, p as LayoutDefinition, q as LayerConfig, r as DefineLayerOptions, s as LayerDefinition } from './types-Deyolj1-.js';
|
|
2
|
+
export { t as Activatable, u as ActivatableToken, v as ContainerManagerToken, w as DefineRepositoryOptions, x as DefineServiceOptions, y as DefineViewModelOptions, z as Definition, B as GuardRunnerToken, F as NavigationManagerToken, I as RepositoryDefinition, J as RequestContextToken, K as ServiceDefinition, M as SlotEntry, O as SlotRegistry, P as SlotRegistryToken, Q as StateCache, T as StateParticipant, U as StateRegistry, V as StateRegistryToken, W as StateSerializerToken, X as ViewModelDefinition } from './types-Deyolj1-.js';
|
|
3
3
|
import { Container, Token } from '@foxford/ioc';
|
|
4
4
|
import { DefinitionResolver } from './adapter.js';
|
|
5
|
-
|
|
6
|
-
export {
|
|
5
|
+
export { d as defineRepository, a as defineService, b as defineViewModel } from './define-repository-DZg34Tb3.js';
|
|
6
|
+
export { D as DefineSlotOptions, S as SlotDefinition, d as defineSlot } from './define-slot-ESU7FR9O.js';
|
|
7
|
+
export { V as ViewAdapter, a as ViewLayerDefinition, b as ViewLayerToken } from './view-adapter-CL0vZ-rv.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Опции для создания Core Runtime.
|
|
@@ -273,22 +274,22 @@ declare function defineGuard<Deps extends readonly Token<unknown>[] = readonly [
|
|
|
273
274
|
* Определяет конфигурацию приложения с декларативным списком сервисов и guards.
|
|
274
275
|
* Заменяет ручной вызов setupContainer() — декларирует, какие сервисы запускаются
|
|
275
276
|
* при старте (eager), какие — лениво (lazy), и какие guards применяются глобально.
|
|
276
|
-
* Регистрирует
|
|
277
|
+
* Регистрирует HostConfig-значение в IoC-контейнере.
|
|
277
278
|
*
|
|
278
|
-
* @param token - Токен для регистрации
|
|
279
|
+
* @param token - Токен для регистрации HostConfig в IoC
|
|
279
280
|
* @param options - Опции: eager, lazy, guards
|
|
280
|
-
* @returns
|
|
281
|
+
* @returns HostDefinition с методом register(container)
|
|
281
282
|
*
|
|
282
283
|
* @example
|
|
283
284
|
* // app/app.ts
|
|
284
|
-
* export const app =
|
|
285
|
+
* export const app = defineHost(AppToken, {
|
|
285
286
|
* eager: [AuthServiceToken, NotificationServiceToken],
|
|
286
287
|
* lazy: [CartServiceToken],
|
|
287
288
|
* guards: [GlobalAuthGuardToken],
|
|
288
289
|
* })
|
|
289
290
|
* app.register(appContainer)
|
|
290
291
|
*/
|
|
291
|
-
declare function
|
|
292
|
+
declare function defineHost(token: Token<HostConfig>, options?: DefineHostOptions): HostDefinition;
|
|
292
293
|
|
|
293
294
|
/**
|
|
294
295
|
* Определяет app-scope расширение с lifecycle-хуками activate/deactivate.
|
|
@@ -383,4 +384,4 @@ declare function defineLayout(token: Token<LayoutConfig>, options?: DefineLayout
|
|
|
383
384
|
*/
|
|
384
385
|
declare function defineLayer(token: Token<LayerConfig>, options: DefineLayerOptions): LayerDefinition;
|
|
385
386
|
|
|
386
|
-
export { ActionGuard, ActionGuardDefinition,
|
|
387
|
+
export { ActionGuard, ActionGuardDefinition, ContainerManager, ContainerManagerImpl, Core, type CreateCoreOptions, DefineActionGuardOptions, DefineExtensionOptions, DefineGuardOptions, DefineHostOptions, DefineLayerOptions, DefineLayoutOptions, Disposable, ExtensionConfig, ExtensionDefinition, Guard, GuardDefinition, GuardResult, GuardRunner, GuardRunnerImpl, HostConfig, HostDefinition, LayerConfig, LayerDefinition, LayoutConfig, LayoutDefinition, LeaveGuardResult, NavigationEntry, NavigationInterceptor, NavigationManager, NavigationManagerImpl, RequestContext, StateSerializer, StateSerializerImpl, createCore, defaultGlobalResolver, defineActionGuard, defineExtension, defineGuard, defineHost, defineLayer, defineLayout };
|
package/index.js
CHANGED
|
@@ -1,34 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var ContainerManagerToken = createToken("core:ContainerManager");
|
|
25
|
-
var GuardRunnerToken = createToken("core:GuardRunner");
|
|
26
|
-
var NavigationManagerToken = createToken("core:NavigationManager");
|
|
27
|
-
var StateSerializerToken = createToken("core:StateSerializer");
|
|
28
|
-
var StateRegistryToken = createToken("core:StateRegistry");
|
|
29
|
-
var SlotRegistryToken = createToken("core:SlotRegistry");
|
|
30
|
-
var ActivatableToken = createToken("core:Activatable");
|
|
31
|
-
var RequestContextToken = createToken("core:RequestContext");
|
|
1
|
+
import {
|
|
2
|
+
ActivatableToken,
|
|
3
|
+
ContainerManagerToken,
|
|
4
|
+
GuardRunnerToken,
|
|
5
|
+
NavigationManagerToken,
|
|
6
|
+
RequestContextToken,
|
|
7
|
+
SlotRegistry,
|
|
8
|
+
SlotRegistryToken,
|
|
9
|
+
StateRegistryToken,
|
|
10
|
+
StateSerializerToken,
|
|
11
|
+
defineRepository,
|
|
12
|
+
defineService,
|
|
13
|
+
defineSlot,
|
|
14
|
+
defineViewModel
|
|
15
|
+
} from "./chunk-WRQC6BVJ.js";
|
|
16
|
+
import "./chunk-WBHHHICS.js";
|
|
17
|
+
import {
|
|
18
|
+
ViewLayerToken
|
|
19
|
+
} from "./chunk-TCYGDT2A.js";
|
|
20
|
+
import "./chunk-TPBI6TOU.js";
|
|
21
|
+
import {
|
|
22
|
+
__async
|
|
23
|
+
} from "./chunk-HJO26HIQ.js";
|
|
32
24
|
|
|
33
25
|
// src/core/state-registry.ts
|
|
34
26
|
var StateRegistry = class {
|
|
@@ -482,34 +474,6 @@ var StateSerializerImpl = class {
|
|
|
482
474
|
}
|
|
483
475
|
};
|
|
484
476
|
|
|
485
|
-
// src/core/slot-registry.ts
|
|
486
|
-
var SlotRegistry = class {
|
|
487
|
-
constructor() {
|
|
488
|
-
/** Слоты по имени. Повторная регистрация с тем же именем перезаписывает. */
|
|
489
|
-
this.slots = /* @__PURE__ */ new Map();
|
|
490
|
-
}
|
|
491
|
-
/**
|
|
492
|
-
* Регистрирует слот.
|
|
493
|
-
* @param entry - Запись слота (имя + непрозрачный view)
|
|
494
|
-
*/
|
|
495
|
-
add(entry) {
|
|
496
|
-
this.slots.set(entry.name, entry);
|
|
497
|
-
}
|
|
498
|
-
/**
|
|
499
|
-
* Возвращает слот по имени.
|
|
500
|
-
* @param name - Имя слота
|
|
501
|
-
*/
|
|
502
|
-
get(name) {
|
|
503
|
-
return this.slots.get(name);
|
|
504
|
-
}
|
|
505
|
-
/**
|
|
506
|
-
* Возвращает все зарегистрированные слоты.
|
|
507
|
-
*/
|
|
508
|
-
all() {
|
|
509
|
-
return [...this.slots.values()];
|
|
510
|
-
}
|
|
511
|
-
};
|
|
512
|
-
|
|
513
477
|
// src/core/state-cache.ts
|
|
514
478
|
var StateCache = class {
|
|
515
479
|
/**
|
|
@@ -598,156 +562,8 @@ var defaultGlobalResolver = (token) => {
|
|
|
598
562
|
});
|
|
599
563
|
};
|
|
600
564
|
|
|
601
|
-
// src/define-service.ts
|
|
602
|
-
import { inject, Lifecycle } from "@foxford/ioc";
|
|
603
|
-
|
|
604
|
-
// src/logger.ts
|
|
605
|
-
import { createToken as createToken2 } from "@foxford/ioc";
|
|
606
|
-
import { log } from "@foxford/logger";
|
|
607
|
-
var logger = log.getLogger("@foxford/den");
|
|
608
|
-
var LoggerToken = createToken2("den:Logger");
|
|
609
|
-
function scopeLogger(container) {
|
|
610
|
-
if (container.has(LoggerToken)) {
|
|
611
|
-
const resolved = container.resolve(LoggerToken);
|
|
612
|
-
if (!(resolved instanceof Promise)) {
|
|
613
|
-
return resolved;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
return logger;
|
|
617
|
-
}
|
|
618
|
-
function unitLogger(container, name) {
|
|
619
|
-
var _a;
|
|
620
|
-
const base = scopeLogger(container);
|
|
621
|
-
return (_a = base.getLogger(name)) != null ? _a : base;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
// src/define-service.ts
|
|
625
|
-
function defineService(token, options) {
|
|
626
|
-
const { requires, create, activate, deactivate, serialize, deserialize, scope } = options;
|
|
627
|
-
const requireTokens = requires != null ? requires : [];
|
|
628
|
-
const participatesInState = serialize !== void 0 || deserialize !== void 0;
|
|
629
|
-
return {
|
|
630
|
-
__meta: { requires: requireTokens, scope: scope != null ? scope : "app" },
|
|
631
|
-
__type: "service",
|
|
632
|
-
/**
|
|
633
|
-
* Регистрирует сервис в IoC-контейнере как Singleton.
|
|
634
|
-
* Если передана create — биндит экземпляр класса напрямую.
|
|
635
|
-
* Иначе — биндит Activatable-обёртку с хуками lifecycle.
|
|
636
|
-
* Если объявлены serialize/deserialize — при создании экземпляра сервис
|
|
637
|
-
* регистрируется участником в StateRegistry этого контейнера.
|
|
638
|
-
* @param container - Контейнер для регистрации
|
|
639
|
-
*/
|
|
640
|
-
register(container) {
|
|
641
|
-
const unitLog = unitLogger(container, token.description);
|
|
642
|
-
const factory = inject(requireTokens, (...args) => {
|
|
643
|
-
unitLog.debug(`\u0441\u043E\u0437\u0434\u0430\u043D\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 (${create ? "\u0444\u0430\u0431\u0440\u0438\u043A\u0430" : "lifecycle-\u043E\u0431\u0451\u0440\u0442\u043A\u0430"})`);
|
|
644
|
-
let instance;
|
|
645
|
-
if (create) {
|
|
646
|
-
instance = create(args);
|
|
647
|
-
} else {
|
|
648
|
-
const service = {
|
|
649
|
-
activate(params) {
|
|
650
|
-
return activate == null ? void 0 : activate(args, params);
|
|
651
|
-
},
|
|
652
|
-
deactivate() {
|
|
653
|
-
return deactivate == null ? void 0 : deactivate(args);
|
|
654
|
-
}
|
|
655
|
-
};
|
|
656
|
-
instance = service;
|
|
657
|
-
}
|
|
658
|
-
if (participatesInState) {
|
|
659
|
-
unitLog.debug("\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044F \u0443\u0447\u0430\u0441\u0442\u043D\u0438\u043A\u043E\u043C StateRegistry (serialize/deserialize)");
|
|
660
|
-
registerStateParticipant(container, token, instance, args, serialize, deserialize);
|
|
661
|
-
}
|
|
662
|
-
return instance;
|
|
663
|
-
});
|
|
664
|
-
container.bind(token).toFactory(factory, { lifecycle: Lifecycle.Singleton });
|
|
665
|
-
unitLog.debug(`\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044F \u0441\u0435\u0440\u0432\u0438\u0441\u0430 (scope=${scope != null ? scope : "app"}, requires=${requireTokens.length})`);
|
|
666
|
-
},
|
|
667
|
-
token
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
function registerStateParticipant(container, token, instance, deps, serialize, deserialize) {
|
|
671
|
-
if (!container.has(StateRegistryToken)) {
|
|
672
|
-
return;
|
|
673
|
-
}
|
|
674
|
-
const resolved = container.resolve(StateRegistryToken);
|
|
675
|
-
if (resolved instanceof Promise) {
|
|
676
|
-
return;
|
|
677
|
-
}
|
|
678
|
-
;
|
|
679
|
-
resolved.add(token.description, {
|
|
680
|
-
activate: (params) => {
|
|
681
|
-
var _a;
|
|
682
|
-
return (_a = instance.activate) == null ? void 0 : _a.call(instance, params);
|
|
683
|
-
},
|
|
684
|
-
fromJSON: deserialize ? (data) => deserialize(deps, data) : void 0,
|
|
685
|
-
toJSON: serialize ? () => serialize(deps) : void 0
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
// src/define-view-model.ts
|
|
690
|
-
import { inject as inject2, Lifecycle as Lifecycle2 } from "@foxford/ioc";
|
|
691
|
-
|
|
692
|
-
// src/adapter.ts
|
|
693
|
-
var activeResolver = null;
|
|
694
|
-
function resolveDefinition(token) {
|
|
695
|
-
if (activeResolver === null) {
|
|
696
|
-
throw new Error(
|
|
697
|
-
`den/adapter: \u0440\u0435\u0437\u043E\u043B\u0432\u0435\u0440 \u043D\u0435 \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D \u0434\u043B\u044F \xAB${token.description}\xBB \u2014 \u043D\u0438 \u043E\u0434\u0438\u043D host-\u0430\u0434\u0430\u043F\u0442\u0435\u0440 \u043D\u0435 \u0432\u044B\u0437\u0432\u0430\u043B installResolver()`
|
|
698
|
-
);
|
|
699
|
-
}
|
|
700
|
-
return activeResolver(token);
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
// src/define-view-model.ts
|
|
704
|
-
function defineViewModel(token, options) {
|
|
705
|
-
const { requires, create } = options;
|
|
706
|
-
const requireTokens = requires != null ? requires : [];
|
|
707
|
-
return {
|
|
708
|
-
__meta: { requires: requireTokens },
|
|
709
|
-
__type: "view-model",
|
|
710
|
-
/**
|
|
711
|
-
* Регистрирует VM в IoC-контейнере как Singleton.
|
|
712
|
-
* Зависимости из requires резолвятся автоматически через inject.
|
|
713
|
-
* @param container - Контейнер для регистрации
|
|
714
|
-
*/
|
|
715
|
-
register(container) {
|
|
716
|
-
const unitLog = unitLogger(container, token.description);
|
|
717
|
-
const factory = inject2(requireTokens, (...args) => {
|
|
718
|
-
unitLog.debug("\u0441\u043E\u0437\u0434\u0430\u043D\u0438\u0435 view-model");
|
|
719
|
-
return create(args);
|
|
720
|
-
});
|
|
721
|
-
container.bind(token).toFactory(factory, { lifecycle: Lifecycle2.Singleton });
|
|
722
|
-
unitLog.debug(`\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044F view-model (requires=${requireTokens.length})`);
|
|
723
|
-
},
|
|
724
|
-
/**
|
|
725
|
-
* Резолвит VM через стратегию активного host-адаптера.
|
|
726
|
-
* Вызывайте когда контейнер уже инициализирован (в render-контексте).
|
|
727
|
-
*
|
|
728
|
-
* Дескриптор не знает, откуда берётся инстанс — стратегию ставит адаптер
|
|
729
|
-
* через `installResolver()` (см. `@foxford/den/adapter`):
|
|
730
|
-
* - Vike (дефолт) — async/global: подъём по parent-chain, pending Promise при промахе;
|
|
731
|
-
* - Next — sync/island: контейнер острова из React-контекста.
|
|
732
|
-
*
|
|
733
|
-
* @returns Экземпляр VM или Promise с экземпляром
|
|
734
|
-
*/
|
|
735
|
-
resolve() {
|
|
736
|
-
return resolveDefinition(token);
|
|
737
|
-
},
|
|
738
|
-
token,
|
|
739
|
-
/**
|
|
740
|
-
* Псевдоним для resolve(). Резолвит VM через стратегию активного адаптера.
|
|
741
|
-
* @returns Экземпляр VM или Promise с экземпляром
|
|
742
|
-
*/
|
|
743
|
-
use() {
|
|
744
|
-
return this.resolve();
|
|
745
|
-
}
|
|
746
|
-
};
|
|
747
|
-
}
|
|
748
|
-
|
|
749
565
|
// src/define-guard.ts
|
|
750
|
-
import { inject
|
|
566
|
+
import { inject, Lifecycle } from "@foxford/ioc";
|
|
751
567
|
function defineGuard(token, options) {
|
|
752
568
|
const { requires, create, check } = options;
|
|
753
569
|
const requireTokens = requires != null ? requires : [];
|
|
@@ -762,8 +578,8 @@ function defineGuard(token, options) {
|
|
|
762
578
|
*/
|
|
763
579
|
register(container) {
|
|
764
580
|
if (create) {
|
|
765
|
-
const factory =
|
|
766
|
-
container.bind(token).toFactory(factory, { lifecycle:
|
|
581
|
+
const factory = inject(requireTokens, (...args) => create(args));
|
|
582
|
+
container.bind(token).toFactory(factory, { lifecycle: Lifecycle.Singleton });
|
|
767
583
|
} else if (check) {
|
|
768
584
|
const guard = { check };
|
|
769
585
|
container.bind(token).toValue(guard);
|
|
@@ -773,34 +589,8 @@ function defineGuard(token, options) {
|
|
|
773
589
|
};
|
|
774
590
|
}
|
|
775
591
|
|
|
776
|
-
// src/define-
|
|
777
|
-
|
|
778
|
-
function defineRepository(token, options) {
|
|
779
|
-
const { requires, create, scope } = options;
|
|
780
|
-
const requireTokens = requires != null ? requires : [];
|
|
781
|
-
return {
|
|
782
|
-
__meta: { requires: requireTokens, scope: scope != null ? scope : "app" },
|
|
783
|
-
__type: "repository",
|
|
784
|
-
/**
|
|
785
|
-
* Регистрирует репозиторий в IoC-контейнере как Singleton.
|
|
786
|
-
* Зависимости из requires резолвятся автоматически через inject.
|
|
787
|
-
* @param container - Контейнер для регистрации
|
|
788
|
-
*/
|
|
789
|
-
register(container) {
|
|
790
|
-
const unitLog = unitLogger(container, token.description);
|
|
791
|
-
const factory = inject4(requireTokens, (...args) => {
|
|
792
|
-
unitLog.debug("\u0441\u043E\u0437\u0434\u0430\u043D\u0438\u0435 \u0440\u0435\u043F\u043E\u0437\u0438\u0442\u043E\u0440\u0438\u044F");
|
|
793
|
-
return create(args);
|
|
794
|
-
});
|
|
795
|
-
container.bind(token).toFactory(factory, { lifecycle: Lifecycle4.Singleton });
|
|
796
|
-
unitLog.debug(`\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044F \u0440\u0435\u043F\u043E\u0437\u0438\u0442\u043E\u0440\u0438\u044F (scope=${scope != null ? scope : "app"}, requires=${requireTokens.length})`);
|
|
797
|
-
},
|
|
798
|
-
token
|
|
799
|
-
};
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
// src/define-app.ts
|
|
803
|
-
function defineApp(token, options = {}) {
|
|
592
|
+
// src/define-host.ts
|
|
593
|
+
function defineHost(token, options = {}) {
|
|
804
594
|
var _a, _b, _c;
|
|
805
595
|
const eager = (_a = options.eager) != null ? _a : [];
|
|
806
596
|
const lazy = (_b = options.lazy) != null ? _b : [];
|
|
@@ -808,9 +598,9 @@ function defineApp(token, options = {}) {
|
|
|
808
598
|
const config = { eager, guards, lazy };
|
|
809
599
|
return {
|
|
810
600
|
__meta: { eager, guards, lazy, requires: [] },
|
|
811
|
-
__type: "
|
|
601
|
+
__type: "host",
|
|
812
602
|
/**
|
|
813
|
-
* Регистрирует
|
|
603
|
+
* Регистрирует HostConfig как value в IoC-контейнере.
|
|
814
604
|
* Позволяет runtime получать конфигурацию приложения через контейнер.
|
|
815
605
|
* @param container - Контейнер для регистрации
|
|
816
606
|
*/
|
|
@@ -822,7 +612,7 @@ function defineApp(token, options = {}) {
|
|
|
822
612
|
}
|
|
823
613
|
|
|
824
614
|
// src/define-extension.ts
|
|
825
|
-
import { inject as
|
|
615
|
+
import { inject as inject2, Lifecycle as Lifecycle2 } from "@foxford/ioc";
|
|
826
616
|
function defineExtension(token, options = {}) {
|
|
827
617
|
const { requires, activate, deactivate } = options;
|
|
828
618
|
const requireTokens = requires != null ? requires : [];
|
|
@@ -835,7 +625,7 @@ function defineExtension(token, options = {}) {
|
|
|
835
625
|
* @param container - Контейнер для регистрации
|
|
836
626
|
*/
|
|
837
627
|
register(container) {
|
|
838
|
-
const factory =
|
|
628
|
+
const factory = inject2(requireTokens, (...args) => {
|
|
839
629
|
const config = {
|
|
840
630
|
__extensionConfig: true,
|
|
841
631
|
activate() {
|
|
@@ -847,14 +637,14 @@ function defineExtension(token, options = {}) {
|
|
|
847
637
|
};
|
|
848
638
|
return config;
|
|
849
639
|
});
|
|
850
|
-
container.bind(token).toFactory(factory, { lifecycle:
|
|
640
|
+
container.bind(token).toFactory(factory, { lifecycle: Lifecycle2.Singleton });
|
|
851
641
|
},
|
|
852
642
|
token
|
|
853
643
|
};
|
|
854
644
|
}
|
|
855
645
|
|
|
856
646
|
// src/define-action-guard.ts
|
|
857
|
-
import { inject as
|
|
647
|
+
import { inject as inject3, Lifecycle as Lifecycle3 } from "@foxford/ioc";
|
|
858
648
|
function defineActionGuard(token, options) {
|
|
859
649
|
const { requires, intercept } = options;
|
|
860
650
|
const requireTokens = requires != null ? requires : [];
|
|
@@ -867,7 +657,7 @@ function defineActionGuard(token, options) {
|
|
|
867
657
|
* @param container - Контейнер для регистрации
|
|
868
658
|
*/
|
|
869
659
|
register(container) {
|
|
870
|
-
const factory =
|
|
660
|
+
const factory = inject3(requireTokens, (...args) => {
|
|
871
661
|
const guard = {
|
|
872
662
|
intercept(next) {
|
|
873
663
|
return intercept(args, next);
|
|
@@ -875,7 +665,7 @@ function defineActionGuard(token, options) {
|
|
|
875
665
|
};
|
|
876
666
|
return guard;
|
|
877
667
|
});
|
|
878
|
-
container.bind(token).toFactory(factory, { lifecycle:
|
|
668
|
+
container.bind(token).toFactory(factory, { lifecycle: Lifecycle3.Singleton });
|
|
879
669
|
},
|
|
880
670
|
token
|
|
881
671
|
};
|
|
@@ -902,30 +692,6 @@ function defineLayout(token, options = {}) {
|
|
|
902
692
|
};
|
|
903
693
|
}
|
|
904
694
|
|
|
905
|
-
// src/define-slot.ts
|
|
906
|
-
function defineSlot({ name, view, units = [] }) {
|
|
907
|
-
return {
|
|
908
|
-
__type: "slot",
|
|
909
|
-
name,
|
|
910
|
-
register(container) {
|
|
911
|
-
const slotLog = unitLogger(container, `slot:${name}`);
|
|
912
|
-
for (const unit of units) {
|
|
913
|
-
unit.register(container);
|
|
914
|
-
}
|
|
915
|
-
const registry = container.has(SlotRegistryToken) ? container.resolve(SlotRegistryToken) : (() => {
|
|
916
|
-
const created = new SlotRegistry();
|
|
917
|
-
container.bind(SlotRegistryToken).toValue(created);
|
|
918
|
-
slotLog.debug("\u0441\u043E\u0437\u0434\u0430\u043D SlotRegistry \u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440\u0430");
|
|
919
|
-
return created;
|
|
920
|
-
})();
|
|
921
|
-
registry.add({ name, view });
|
|
922
|
-
slotLog.debug(`\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044F \u0441\u043B\u043E\u0442\u0430 (units=${units.length})`);
|
|
923
|
-
},
|
|
924
|
-
units,
|
|
925
|
-
view
|
|
926
|
-
};
|
|
927
|
-
}
|
|
928
|
-
|
|
929
695
|
// src/define-layer.ts
|
|
930
696
|
function defineLayer(token, options) {
|
|
931
697
|
const { name, adapter } = options;
|
|
@@ -933,6 +699,7 @@ function defineLayer(token, options) {
|
|
|
933
699
|
return {
|
|
934
700
|
__meta: { name, requires: [] },
|
|
935
701
|
__type: "layer",
|
|
702
|
+
config,
|
|
936
703
|
/**
|
|
937
704
|
* Регистрирует LayerConfig как value в IoC-контейнере.
|
|
938
705
|
* Runtime использует конфиг для инициализации view-адаптера.
|
|
@@ -960,12 +727,13 @@ export {
|
|
|
960
727
|
StateRegistryToken,
|
|
961
728
|
StateSerializerImpl,
|
|
962
729
|
StateSerializerToken,
|
|
730
|
+
ViewLayerToken,
|
|
963
731
|
createCore,
|
|
964
732
|
defaultGlobalResolver,
|
|
965
733
|
defineActionGuard,
|
|
966
|
-
defineApp,
|
|
967
734
|
defineExtension,
|
|
968
735
|
defineGuard,
|
|
736
|
+
defineHost,
|
|
969
737
|
defineLayer,
|
|
970
738
|
defineLayout,
|
|
971
739
|
defineRepository,
|
package/island/index.cjs
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkLJE7K7VDcjs = require('../chunk-LJE7K7VD.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkA6ZPAM6Zcjs = require('../chunk-A6ZPAM6Z.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkXHYR3SGGcjs = require('../chunk-XHYR3SGG.cjs');
|
|
14
|
+
|
|
15
|
+
// src/island/lifecycle.ts
|
|
16
|
+
var _logger = require('@foxford/logger');
|
|
17
|
+
|
|
18
|
+
// src/island/runtime.ts
|
|
19
|
+
var _ioc = require('@foxford/ioc');
|
|
20
|
+
var appContainer = null;
|
|
21
|
+
function getAppContainer() {
|
|
22
|
+
var _a;
|
|
23
|
+
if (appContainer === null) {
|
|
24
|
+
appContainer = new (0, _ioc.Container)();
|
|
25
|
+
((_a = _chunkA6ZPAM6Zcjs.logger.getLogger("island:runtime")) != null ? _a : _chunkA6ZPAM6Zcjs.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 = _logger.log.getLogger((_a = descriptor.name) != null ? _a : "app")) != null ? _b : _chunkA6ZPAM6Zcjs.logger;
|
|
35
|
+
const islandLog = (_c = appLog.getLogger("client")) != null ? _c : appLog;
|
|
36
|
+
try {
|
|
37
|
+
const container = parent.createChild();
|
|
38
|
+
container.bind(_chunkA6ZPAM6Zcjs.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
|
+
_chunkA6ZPAM6Zcjs.unitLogger.call(void 0, 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
|
+
_chunkA6ZPAM6Zcjs.unitLogger.call(void 0, 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
|
+
|
|
80
|
+
// src/island/slot-address.ts
|
|
81
|
+
function slotAddress(app, slot) {
|
|
82
|
+
return `${app}:${slot}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/island/registry.ts
|
|
86
|
+
var nextId = 1;
|
|
87
|
+
var islands = /* @__PURE__ */ new Map();
|
|
88
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
89
|
+
var snapshot = [];
|
|
90
|
+
function notify() {
|
|
91
|
+
snapshot = [...islands.values()];
|
|
92
|
+
for (const listener of listeners) {
|
|
93
|
+
listener();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function registerIsland(record) {
|
|
97
|
+
const id = nextId++;
|
|
98
|
+
islands.set(id, _chunkXHYR3SGGcjs.__spreadValues.call(void 0, { id }, record));
|
|
99
|
+
notify();
|
|
100
|
+
return () => {
|
|
101
|
+
islands.delete(id);
|
|
102
|
+
notify();
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function getIslandsSnapshot() {
|
|
106
|
+
return snapshot;
|
|
107
|
+
}
|
|
108
|
+
function subscribeIslands(listener) {
|
|
109
|
+
listeners.add(listener);
|
|
110
|
+
return () => listeners.delete(listener);
|
|
111
|
+
}
|
|
112
|
+
function describeIsland(descriptor, denState) {
|
|
113
|
+
var _a, _b;
|
|
114
|
+
return {
|
|
115
|
+
denStateKeys: Object.keys(denState != null ? denState : {}),
|
|
116
|
+
name: descriptor.name,
|
|
117
|
+
// Адресами, а не локальными ключами: панель показывает острова разных приложений разом,
|
|
118
|
+
// и `aside` без префикса в этом списке ничего не значит.
|
|
119
|
+
slots: Object.keys((_a = descriptor.slots) != null ? _a : {}).map((slot) => slotAddress(descriptor.name, slot)),
|
|
120
|
+
units: descriptor.units.map((unit) => unit.token.description),
|
|
121
|
+
viewModels: ((_b = descriptor.viewModels) != null ? _b : []).map((vm) => vm.token.description)
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
exports.ViewLayerToken = _chunkLJE7K7VDcjs.ViewLayerToken; exports.activateIslandViewModels = activateIslandViewModels; exports.createIslandContainer = createIslandContainer; exports.describeIsland = describeIsland; exports.getAppContainer = getAppContainer; exports.getIslandsSnapshot = getIslandsSnapshot; exports.hydrateIslandState = hydrateIslandState; exports.registerIsland = registerIsland; exports.resolveViewAdapter = _chunkLJE7K7VDcjs.resolveViewAdapter; exports.slotAddress = slotAddress; exports.subscribeIslands = subscribeIslands; exports.viewAdapterOf = _chunkLJE7K7VDcjs.viewAdapterOf;
|