-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbookmark-module.ts
71 lines (61 loc) · 2.54 KB
/
bookmark-module.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { Module, ModulesInstance, SemanticVersion } from '@equinor/fusion-framework-module';
import { EventModule } from '@equinor/fusion-framework-module-event';
import { ServicesModule } from '@equinor/fusion-framework-module-services';
import { AppModule } from '@equinor/fusion-framework-module-app';
import { ContextModule } from '@equinor/fusion-framework-module-context';
import { BookmarkProvider } from './BookmarkProvider';
import { BookmarkModuleConfigurator } from './BookmarkConfigurator';
import { ConsoleLogger, ILogger } from '@equinor/fusion-log';
import { lastValueFrom } from 'rxjs';
import { version } from './version';
import { type IBookmarkProvider } from './BookmarkProvider.interface';
export type BookmarkModuleKey = 'bookmark';
export const moduleKey: BookmarkModuleKey = 'bookmark';
export type BookmarkModule = Module<
BookmarkModuleKey,
IBookmarkProvider,
BookmarkModuleConfigurator,
[EventModule, ServicesModule, AppModule, ContextModule]
>;
// TODO - remove when all framework uses log
const fallbackLogger: ILogger = new ConsoleLogger('BookmarkModule');
export const module: BookmarkModule = {
name: moduleKey,
version: new SemanticVersion(version),
configure: (args) => {
// use parent logger if available, else fallback to console logger
const log: ILogger =
(args?.log as ILogger)?.createSubLogger('BookmarkModule') || fallbackLogger;
// Set client from parent module if available
const ref = args?.ref as ModulesInstance<[BookmarkModule]>;
// create a configurator instance
const configurator = new BookmarkModuleConfigurator({ log, ref });
return configurator;
},
initialize: async (args) => {
const parent = args.ref?.bookmark as BookmarkProvider;
const config = await lastValueFrom(
args.config.createConfig(args, {
filters: parent?.filters,
sourceSystem: parent?.sourceSystem,
resolve: parent
? {
application: parent.resolvedApplication.bind(parent),
context: parent.resolvedContext.bind(parent),
}
: undefined,
}),
);
const provider = new BookmarkProvider(config);
return provider;
},
dispose: (args) => {
(args.instance as BookmarkProvider).dispose();
},
};
declare module '@equinor/fusion-framework-module' {
interface Modules {
bookmark: BookmarkModule;
}
}
export default module;