@equinor/fusion-framework-module-app 2.1.5 → 2.2.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/CHANGELOG.md +11 -0
- package/dist/esm/AppModuleProvider.js +91 -0
- package/dist/esm/AppModuleProvider.js.map +1 -0
- package/dist/esm/app/App.js +172 -0
- package/dist/esm/app/App.js.map +1 -0
- package/dist/esm/app/actions.js +17 -0
- package/dist/esm/app/actions.js.map +1 -0
- package/dist/esm/app/create-reducer.js +25 -0
- package/dist/esm/app/create-reducer.js.map +1 -0
- package/dist/esm/app/create-state.js +12 -0
- package/dist/esm/app/create-state.js.map +1 -0
- package/dist/esm/app/flows.js +17 -0
- package/dist/esm/app/flows.js.map +1 -0
- package/dist/esm/app/types.js +2 -0
- package/dist/esm/app/types.js.map +1 -0
- package/dist/esm/configurator.js +3 -3
- package/dist/esm/configurator.js.map +1 -1
- package/dist/esm/errors.js +37 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/events.js +7 -0
- package/dist/esm/events.js.map +1 -0
- package/dist/esm/index.js +4 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/module.js +5 -2
- package/dist/esm/module.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/AppModuleProvider.d.ts +26 -0
- package/dist/types/app/App.d.ts +34 -0
- package/dist/types/app/actions.d.ts +46 -0
- package/dist/types/app/create-reducer.d.ts +3 -0
- package/dist/types/app/create-state.d.ts +5 -0
- package/dist/types/app/flows.d.ts +7 -0
- package/dist/types/app/types.d.ts +9 -0
- package/dist/types/configurator.d.ts +8 -8
- package/dist/types/errors.d.ts +16 -0
- package/dist/types/events.d.ts +22 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/module.d.ts +4 -3
- package/dist/types/types.d.ts +29 -1
- package/package.json +14 -6
- package/src/AppModuleProvider.ts +159 -0
- package/src/app/App.ts +243 -0
- package/src/app/actions.ts +51 -0
- package/src/app/create-reducer.ts +41 -0
- package/src/app/create-state.ts +21 -0
- package/src/app/flows.ts +61 -0
- package/src/app/types.ts +11 -0
- package/src/configurator.ts +13 -13
- package/src/errors.ts +53 -0
- package/src/events.ts +34 -0
- package/src/index.ts +9 -2
- package/src/module.ts +9 -5
- package/src/types.ts +42 -1
- package/dist/esm/provider.js +0 -83
- package/dist/esm/provider.js.map +0 -1
- package/dist/types/provider.d.ts +0 -43
- package/src/provider.ts +0 -181
package/src/types.ts
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
|
+
import { AnyModule, CombinedModules, ModulesInstance } from '@equinor/fusion-framework-module';
|
|
1
2
|
import type { EventModule } from '@equinor/fusion-framework-module-event';
|
|
2
3
|
import type { HttpModule } from '@equinor/fusion-framework-module-http';
|
|
4
|
+
import { MsalModule } from '@equinor/fusion-framework-module-msal';
|
|
3
5
|
import type { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
|
|
4
6
|
|
|
7
|
+
// TODO
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
type Fusion = any;
|
|
10
|
+
|
|
11
|
+
export type AppEnv<TConfig = unknown, TProps = unknown> = {
|
|
12
|
+
basename?: string;
|
|
13
|
+
manifest?: AppManifest;
|
|
14
|
+
config?: AppConfig<TConfig>;
|
|
15
|
+
props?: TProps;
|
|
16
|
+
};
|
|
17
|
+
|
|
5
18
|
// TODO: change to module-services when new app service is created
|
|
6
19
|
export type ModuleDeps = [HttpModule, ServiceDiscoveryModule, EventModule];
|
|
7
20
|
|
|
@@ -20,7 +33,7 @@ type AppCategory = {
|
|
|
20
33
|
};
|
|
21
34
|
|
|
22
35
|
export type AppManifest = {
|
|
23
|
-
|
|
36
|
+
appKey: string;
|
|
24
37
|
name: string;
|
|
25
38
|
shortName: string;
|
|
26
39
|
version: string;
|
|
@@ -45,3 +58,31 @@ export type AppConfig<TEnvironment = unknown> = {
|
|
|
45
58
|
environment: TEnvironment;
|
|
46
59
|
endpoints: Record<string, string | Endpoint>;
|
|
47
60
|
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @template TEnvironment - name of hosted environment
|
|
64
|
+
* @template TModule - ES module type (import return type)
|
|
65
|
+
*/
|
|
66
|
+
export type AppBundle<TEnvironment = unknown, TModule = unknown> = {
|
|
67
|
+
manifest: AppManifest;
|
|
68
|
+
config: AppConfig<TEnvironment>;
|
|
69
|
+
module: TModule;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type AppModules<TModules extends Array<AnyModule> | unknown = unknown> = CombinedModules<
|
|
73
|
+
TModules,
|
|
74
|
+
[EventModule, HttpModule, MsalModule]
|
|
75
|
+
>;
|
|
76
|
+
|
|
77
|
+
export type ComponentRenderArgs<TFusion extends Fusion = Fusion, TEnv = AppEnv> = {
|
|
78
|
+
fusion: TFusion;
|
|
79
|
+
env: TEnv;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export type AppScriptModule = {
|
|
83
|
+
default: (el: HTMLElement, args: ComponentRenderArgs) => VoidFunction;
|
|
84
|
+
renderApp: (el: HTMLElement, args: ComponentRenderArgs) => VoidFunction;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export type AppModulesInstance<TModules extends Array<AnyModule> | unknown = unknown> =
|
|
88
|
+
ModulesInstance<AppModules<TModules>>;
|
package/dist/esm/provider.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
-
};
|
|
12
|
-
var _AppProvider_appClient, _AppProvider_appsClient, _AppProvider_configClient, _AppProvider_current$, _AppProvider_subscription;
|
|
13
|
-
import { BehaviorSubject, catchError, distinctUntilChanged, filter, firstValueFrom, from, map, merge, Observable, pairwise, scan, Subscription, switchMap, takeWhile, throwIfEmpty, } from 'rxjs';
|
|
14
|
-
import { Query } from '@equinor/fusion-query';
|
|
15
|
-
import { compareAppManifest } from './helpers';
|
|
16
|
-
export class AppProvider extends Observable {
|
|
17
|
-
get current() {
|
|
18
|
-
return __classPrivateFieldGet(this, _AppProvider_current$, "f").value;
|
|
19
|
-
}
|
|
20
|
-
get current$() {
|
|
21
|
-
return __classPrivateFieldGet(this, _AppProvider_current$, "f").pipe(distinctUntilChanged(compareAppManifest));
|
|
22
|
-
}
|
|
23
|
-
constructor(args) {
|
|
24
|
-
super((observer) => this.current$.subscribe(observer));
|
|
25
|
-
_AppProvider_appClient.set(this, void 0);
|
|
26
|
-
_AppProvider_appsClient.set(this, void 0);
|
|
27
|
-
_AppProvider_configClient.set(this, void 0);
|
|
28
|
-
_AppProvider_current$.set(this, void 0);
|
|
29
|
-
_AppProvider_subscription.set(this, new Subscription());
|
|
30
|
-
const { event, config } = args;
|
|
31
|
-
__classPrivateFieldSet(this, _AppProvider_current$, new BehaviorSubject(undefined), "f");
|
|
32
|
-
__classPrivateFieldSet(this, _AppProvider_appClient, new Query(config.getApp), "f");
|
|
33
|
-
__classPrivateFieldSet(this, _AppProvider_appsClient, new Query(config.getApps), "f");
|
|
34
|
-
__classPrivateFieldSet(this, _AppProvider_configClient, new Query(config.getConfig), "f");
|
|
35
|
-
__classPrivateFieldGet(this, _AppProvider_subscription, "f").add(__classPrivateFieldGet(this, _AppProvider_appClient, "f").complete);
|
|
36
|
-
__classPrivateFieldGet(this, _AppProvider_subscription, "f").add(__classPrivateFieldGet(this, _AppProvider_appsClient, "f").complete);
|
|
37
|
-
__classPrivateFieldGet(this, _AppProvider_subscription, "f").add(__classPrivateFieldGet(this, _AppProvider_configClient, "f").complete);
|
|
38
|
-
__classPrivateFieldGet(this, _AppProvider_subscription, "f").add(this.current$
|
|
39
|
-
.pipe(pairwise(), takeWhile(() => !!event))
|
|
40
|
-
.subscribe(([previous, next]) => {
|
|
41
|
-
event === null || event === void 0 ? void 0 : event.dispatchEvent('onCurrentAppChanged', {
|
|
42
|
-
source: this,
|
|
43
|
-
detail: { previous, next },
|
|
44
|
-
});
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
47
|
-
getApp(appKey) {
|
|
48
|
-
return Query.extractQueryValue(__classPrivateFieldGet(this, _AppProvider_appClient, "f").query({ appKey }).pipe(catchError((cause) => {
|
|
49
|
-
throw Error('failed to load manifest', { cause });
|
|
50
|
-
})));
|
|
51
|
-
}
|
|
52
|
-
getAllApps() {
|
|
53
|
-
return Query.extractQueryValue(__classPrivateFieldGet(this, _AppProvider_appsClient, "f").query());
|
|
54
|
-
}
|
|
55
|
-
getAppConfig(appKey, tag) {
|
|
56
|
-
return Query.extractQueryValue(__classPrivateFieldGet(this, _AppProvider_configClient, "f").query({ appKey, tag }).pipe(catchError((cause) => {
|
|
57
|
-
throw Error('failed to load config', { cause });
|
|
58
|
-
})));
|
|
59
|
-
}
|
|
60
|
-
setCurrentApp(appKey) {
|
|
61
|
-
return new Promise((complete, error) => {
|
|
62
|
-
const query$ = __classPrivateFieldGet(this, _AppProvider_appClient, "f").query({ appKey });
|
|
63
|
-
__classPrivateFieldGet(this, _AppProvider_subscription, "f").add(Query.extractQueryValue(query$).subscribe({
|
|
64
|
-
next: (x) => __classPrivateFieldGet(this, _AppProvider_current$, "f").next(x),
|
|
65
|
-
error,
|
|
66
|
-
complete,
|
|
67
|
-
}));
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
loadApp(appKey) {
|
|
71
|
-
const loadApp$ = this.getApp(appKey).pipe(switchMap((manifest) => {
|
|
72
|
-
return firstValueFrom(from(import(manifest.entry)).pipe(map((module) => ({ manifest, module }))));
|
|
73
|
-
}));
|
|
74
|
-
const loadConfig$ = this.getAppConfig(appKey).pipe(map((config) => ({ config })));
|
|
75
|
-
return merge(loadApp$, loadConfig$).pipe(scan((acc, next) => Object.assign({}, acc, next), {}), filter((x) => ['manifest', 'module', 'config'].every((key) => !!x[key])), throwIfEmpty(() => 'failed to load application'));
|
|
76
|
-
}
|
|
77
|
-
dispose() {
|
|
78
|
-
__classPrivateFieldGet(this, _AppProvider_subscription, "f").unsubscribe();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
_AppProvider_appClient = new WeakMap(), _AppProvider_appsClient = new WeakMap(), _AppProvider_configClient = new WeakMap(), _AppProvider_current$ = new WeakMap(), _AppProvider_subscription = new WeakMap();
|
|
82
|
-
export default AppProvider;
|
|
83
|
-
//# sourceMappingURL=provider.js.map
|
package/dist/esm/provider.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACH,eAAe,EACf,UAAU,EACV,oBAAoB,EACpB,MAAM,EACN,cAAc,EACd,IAAI,EACJ,GAAG,EACH,KAAK,EACL,UAAU,EACV,QAAQ,EACR,IAAI,EACJ,YAAY,EACZ,SAAS,EACT,SAAS,EACT,YAAY,GACf,MAAM,MAAM,CAAC;AAId,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAS9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AA0B/C,MAAM,OAAO,WAAY,SAAQ,U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,CAAC,CACnD,CAAC;IACN,CAAC;IAEM,OAAO;QACV,uBAAA,IAAI,iCAAc,CAAC,WAAW,EAAE,CAAC;IACrC,CAAC;CACJ;;AAUD,eAAe,WAAW,CAAC"}
|
package/dist/types/provider.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
|
-
import { ModuleType } from '@equinor/fusion-framework-module';
|
|
3
|
-
import { EventModule, FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
|
|
4
|
-
import { IAppModuleConfig } from './configurator';
|
|
5
|
-
import type { AppConfig, AppManifest } from './types';
|
|
6
|
-
export interface IAppProvider {
|
|
7
|
-
getApp(appKey: string): Observable<AppManifest>;
|
|
8
|
-
getAllApps(): Observable<AppManifest[]>;
|
|
9
|
-
getAppConfig<TType = unknown>(appKey: string): Observable<AppConfig<TType>>;
|
|
10
|
-
setCurrentApp(appKey: string): void;
|
|
11
|
-
readonly current$: Observable<AppManifest | undefined>;
|
|
12
|
-
current: AppManifest | undefined;
|
|
13
|
-
loadApp<TEnvironment = unknown, TModule = any>(appKey: string): Observable<AppBundle<TEnvironment, TModule>>;
|
|
14
|
-
}
|
|
15
|
-
export type AppBundle<TEnvironment = unknown, TModule = unknown> = {
|
|
16
|
-
manifest: AppManifest;
|
|
17
|
-
config: AppConfig<TEnvironment>;
|
|
18
|
-
module: TModule;
|
|
19
|
-
};
|
|
20
|
-
export declare class AppProvider extends Observable<AppManifest | undefined> implements IAppProvider {
|
|
21
|
-
#private;
|
|
22
|
-
get current(): AppManifest | undefined;
|
|
23
|
-
get current$(): Observable<AppManifest | undefined>;
|
|
24
|
-
constructor(args: {
|
|
25
|
-
config: IAppModuleConfig;
|
|
26
|
-
event?: ModuleType<EventModule>;
|
|
27
|
-
});
|
|
28
|
-
getApp(appKey: string): Observable<AppManifest>;
|
|
29
|
-
getAllApps(): Observable<AppManifest[]>;
|
|
30
|
-
getAppConfig<TType = unknown>(appKey: string, tag?: string): Observable<AppConfig<TType>>;
|
|
31
|
-
setCurrentApp(appKey: string): Promise<void>;
|
|
32
|
-
loadApp<TEnvironment = unknown, TModule = unknown>(appKey: string): Observable<AppBundle<TEnvironment, TModule>>;
|
|
33
|
-
dispose(): void;
|
|
34
|
-
}
|
|
35
|
-
declare module '@equinor/fusion-framework-module-event' {
|
|
36
|
-
interface FrameworkEventMap {
|
|
37
|
-
onCurrentAppChanged: FrameworkEvent<FrameworkEventInit<{
|
|
38
|
-
next?: AppManifest;
|
|
39
|
-
previous?: AppManifest;
|
|
40
|
-
}, IAppProvider>>;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
export default AppProvider;
|
package/src/provider.ts
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BehaviorSubject,
|
|
3
|
-
catchError,
|
|
4
|
-
distinctUntilChanged,
|
|
5
|
-
filter,
|
|
6
|
-
firstValueFrom,
|
|
7
|
-
from,
|
|
8
|
-
map,
|
|
9
|
-
merge,
|
|
10
|
-
Observable,
|
|
11
|
-
pairwise,
|
|
12
|
-
scan,
|
|
13
|
-
Subscription,
|
|
14
|
-
switchMap,
|
|
15
|
-
takeWhile,
|
|
16
|
-
throwIfEmpty,
|
|
17
|
-
} from 'rxjs';
|
|
18
|
-
|
|
19
|
-
import { ModuleType } from '@equinor/fusion-framework-module';
|
|
20
|
-
|
|
21
|
-
import { Query } from '@equinor/fusion-query';
|
|
22
|
-
|
|
23
|
-
import {
|
|
24
|
-
EventModule,
|
|
25
|
-
FrameworkEvent,
|
|
26
|
-
FrameworkEventInit,
|
|
27
|
-
} from '@equinor/fusion-framework-module-event';
|
|
28
|
-
|
|
29
|
-
import { IAppModuleConfig } from './configurator';
|
|
30
|
-
import { compareAppManifest } from './helpers';
|
|
31
|
-
|
|
32
|
-
import type { AppConfig, AppManifest } from './types';
|
|
33
|
-
|
|
34
|
-
export interface IAppProvider {
|
|
35
|
-
getApp(appKey: string): Observable<AppManifest>;
|
|
36
|
-
getAllApps(): Observable<AppManifest[]>;
|
|
37
|
-
getAppConfig<TType = unknown>(appKey: string): Observable<AppConfig<TType>>;
|
|
38
|
-
setCurrentApp(appKey: string): void;
|
|
39
|
-
readonly current$: Observable<AppManifest | undefined>;
|
|
40
|
-
current: AppManifest | undefined;
|
|
41
|
-
loadApp<TEnvironment = unknown, TModule = any>(
|
|
42
|
-
appKey: string
|
|
43
|
-
): Observable<AppBundle<TEnvironment, TModule>>;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @template TModule - ES module type
|
|
48
|
-
*/
|
|
49
|
-
export type AppBundle<TEnvironment = unknown, TModule = unknown> = {
|
|
50
|
-
manifest: AppManifest;
|
|
51
|
-
config: AppConfig<TEnvironment>;
|
|
52
|
-
/** ES module instance */
|
|
53
|
-
module: TModule;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export class AppProvider extends Observable<AppManifest | undefined> implements IAppProvider {
|
|
57
|
-
#appClient: Query<AppManifest, { appKey: string }>;
|
|
58
|
-
#appsClient: Query<AppManifest[], void>;
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
-
#configClient: Query<AppConfig<any>, { appKey: string; tag?: string }>;
|
|
61
|
-
|
|
62
|
-
#current$: BehaviorSubject<AppManifest | undefined>;
|
|
63
|
-
|
|
64
|
-
#subscription = new Subscription();
|
|
65
|
-
|
|
66
|
-
get current(): AppManifest | undefined {
|
|
67
|
-
return this.#current$.value;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
get current$(): Observable<AppManifest | undefined> {
|
|
71
|
-
return this.#current$.pipe(distinctUntilChanged(compareAppManifest));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
constructor(args: { config: IAppModuleConfig; event?: ModuleType<EventModule> }) {
|
|
75
|
-
super((observer) => this.current$.subscribe(observer));
|
|
76
|
-
|
|
77
|
-
const { event, config } = args;
|
|
78
|
-
|
|
79
|
-
this.#current$ = new BehaviorSubject<AppManifest | undefined>(undefined);
|
|
80
|
-
|
|
81
|
-
this.#appClient = new Query(config.getApp);
|
|
82
|
-
this.#appsClient = new Query(config.getApps);
|
|
83
|
-
this.#configClient = new Query(config.getConfig);
|
|
84
|
-
|
|
85
|
-
this.#subscription.add(this.#appClient.complete);
|
|
86
|
-
this.#subscription.add(this.#appsClient.complete);
|
|
87
|
-
this.#subscription.add(this.#configClient.complete);
|
|
88
|
-
this.#subscription.add(
|
|
89
|
-
this.current$
|
|
90
|
-
.pipe(
|
|
91
|
-
pairwise(),
|
|
92
|
-
takeWhile(() => !!event)
|
|
93
|
-
)
|
|
94
|
-
.subscribe(([previous, next]) => {
|
|
95
|
-
event?.dispatchEvent('onCurrentAppChanged', {
|
|
96
|
-
source: this,
|
|
97
|
-
detail: { previous, next },
|
|
98
|
-
});
|
|
99
|
-
})
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
public getApp(appKey: string): Observable<AppManifest> {
|
|
104
|
-
return Query.extractQueryValue(
|
|
105
|
-
this.#appClient.query({ appKey }).pipe(
|
|
106
|
-
catchError((cause) => {
|
|
107
|
-
throw Error('failed to load manifest', { cause });
|
|
108
|
-
})
|
|
109
|
-
)
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
public getAllApps(): Observable<AppManifest[]> {
|
|
114
|
-
return Query.extractQueryValue(this.#appsClient.query());
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
public getAppConfig<TType = unknown>(
|
|
118
|
-
appKey: string,
|
|
119
|
-
tag?: string
|
|
120
|
-
): Observable<AppConfig<TType>> {
|
|
121
|
-
return Query.extractQueryValue(
|
|
122
|
-
this.#configClient.query({ appKey, tag }).pipe(
|
|
123
|
-
catchError((cause) => {
|
|
124
|
-
throw Error('failed to load config', { cause });
|
|
125
|
-
})
|
|
126
|
-
)
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
public setCurrentApp(appKey: string): Promise<void> {
|
|
131
|
-
return new Promise((complete, error) => {
|
|
132
|
-
const query$ = this.#appClient.query({ appKey });
|
|
133
|
-
this.#subscription.add(
|
|
134
|
-
Query.extractQueryValue(query$).subscribe({
|
|
135
|
-
next: (x) => this.#current$.next(x),
|
|
136
|
-
error,
|
|
137
|
-
complete,
|
|
138
|
-
})
|
|
139
|
-
);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
public loadApp<TEnvironment = unknown, TModule = unknown>(
|
|
144
|
-
appKey: string
|
|
145
|
-
): Observable<AppBundle<TEnvironment, TModule>> {
|
|
146
|
-
const loadApp$ = this.getApp(appKey).pipe(
|
|
147
|
-
switchMap((manifest) => {
|
|
148
|
-
return firstValueFrom(
|
|
149
|
-
// TODO: use source from manifest when service is ready!
|
|
150
|
-
/* @vite-ignore */
|
|
151
|
-
from(import(manifest.entry)).pipe(map((module) => ({ manifest, module })))
|
|
152
|
-
);
|
|
153
|
-
})
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
const loadConfig$ = this.getAppConfig(appKey).pipe(map((config) => ({ config })));
|
|
157
|
-
|
|
158
|
-
return merge(loadApp$, loadConfig$).pipe(
|
|
159
|
-
scan((acc: Partial<AppBundle>, next) => Object.assign({}, acc, next), {}),
|
|
160
|
-
/** only output when all attributes are filled */
|
|
161
|
-
filter((x): x is AppBundle<TEnvironment, TModule> =>
|
|
162
|
-
['manifest', 'module', 'config'].every((key) => !!x[key as keyof AppBundle])
|
|
163
|
-
),
|
|
164
|
-
throwIfEmpty(() => 'failed to load application')
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
public dispose() {
|
|
169
|
-
this.#subscription.unsubscribe();
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
declare module '@equinor/fusion-framework-module-event' {
|
|
174
|
-
interface FrameworkEventMap {
|
|
175
|
-
onCurrentAppChanged: FrameworkEvent<
|
|
176
|
-
FrameworkEventInit<{ next?: AppManifest; previous?: AppManifest }, IAppProvider>
|
|
177
|
-
>;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export default AppProvider;
|