@equinor/fusion-framework-module-context 0.6.11 → 1.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/CHANGELOG.md +12 -0
- package/dist/esm/ContextConfigBuilder.js +52 -0
- package/dist/esm/ContextConfigBuilder.js.map +1 -0
- package/dist/esm/client/ContextClient.js +2 -2
- package/dist/esm/client/ContextClient.js.map +1 -1
- package/dist/esm/configurator.js +35 -35
- package/dist/esm/configurator.js.map +1 -1
- package/dist/esm/enable-context.js +10 -0
- package/dist/esm/enable-context.js.map +1 -0
- package/dist/esm/index.js +1 -11
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/provider.js +2 -2
- package/dist/esm/provider.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ContextConfigBuilder.d.ts +19 -0
- package/dist/types/client/ContextClient.d.ts +3 -6
- package/dist/types/configurator.d.ts +17 -19
- package/dist/types/enable-context.d.ts +4 -0
- package/dist/types/index.d.ts +2 -4
- package/dist/types/module.d.ts +5 -0
- package/dist/types/provider.d.ts +3 -2
- package/dist/types/types.d.ts +1 -0
- package/package.json +4 -4
- package/src/ContextConfigBuilder.ts +89 -0
- package/src/client/ContextClient.ts +4 -7
- package/src/configurator.ts +50 -60
- package/src/enable-context.ts +30 -0
- package/src/index.ts +3 -26
- package/src/module.ts +7 -1
- package/src/provider.ts +8 -7
- package/src/types.ts +2 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AnyModule, ModuleInitializerArgs, Modules, ModuleType } from '@equinor/fusion-framework-module';
|
|
2
|
+
import type { QueryCtorOptions, QueryFn } from '@equinor/fusion-query';
|
|
3
|
+
import type { GetContextParameters } from './client/ContextClient';
|
|
4
|
+
import type { ContextModuleConfig, ContextModuleConfigurator, IContextModuleConfigurator } from './configurator';
|
|
5
|
+
import type { ContextItem, QueryContextParameters } from './types';
|
|
6
|
+
export type ContextConfigBuilderCallback = <TDeps extends Array<AnyModule> = []>(builder: ContextConfigBuilder<TDeps, ModuleInitializerArgs<IContextModuleConfigurator, TDeps>>) => void | Promise<void>;
|
|
7
|
+
export declare class ContextConfigBuilder<TModules extends Array<AnyModule> = [], TInit extends ModuleInitializerArgs<any, any> = ModuleInitializerArgs<ContextModuleConfigurator, TModules>> {
|
|
8
|
+
#private;
|
|
9
|
+
config: Partial<ContextModuleConfig>;
|
|
10
|
+
constructor(init: TInit, config?: Partial<ContextModuleConfig>);
|
|
11
|
+
requireInstance<TKey extends string = Extract<keyof Modules, string>>(module: TKey): Promise<ModuleType<Modules[TKey]>>;
|
|
12
|
+
requireInstance<T>(module: string): Promise<T>;
|
|
13
|
+
setContextType(type: ContextModuleConfig['contextType']): void;
|
|
14
|
+
setContextFilter(filter: ContextModuleConfig['contextFilter']): void;
|
|
15
|
+
setContextClient(client: {
|
|
16
|
+
get: QueryFn<ContextItem, GetContextParameters> | QueryCtorOptions<ContextItem, GetContextParameters>;
|
|
17
|
+
query: QueryFn<ContextItem[], QueryContextParameters> | QueryCtorOptions<ContextItem[], QueryContextParameters>;
|
|
18
|
+
}, expire?: number): void;
|
|
19
|
+
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { Query, QueryCtorOptions } from '@equinor/fusion-query';
|
|
3
3
|
import { ContextItem } from '../types';
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
id: string;
|
|
7
|
-
}>;
|
|
8
|
-
initial?: ContextItem;
|
|
4
|
+
export type GetContextParameters = {
|
|
5
|
+
id: string;
|
|
9
6
|
};
|
|
10
7
|
export declare class ContextClient extends Observable<ContextItem> {
|
|
11
8
|
#private;
|
|
@@ -14,7 +11,7 @@ export declare class ContextClient extends Observable<ContextItem> {
|
|
|
14
11
|
get client(): Query<ContextItem, {
|
|
15
12
|
id: string;
|
|
16
13
|
}>;
|
|
17
|
-
constructor(options:
|
|
14
|
+
constructor(options: QueryCtorOptions<ContextItem, GetContextParameters>);
|
|
18
15
|
setCurrentContext(idOrItem?: string | ContextItem): void;
|
|
19
16
|
resolveContext(id: string): Observable<ContextItem>;
|
|
20
17
|
}
|
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ModuleInitializerArgs } from '@equinor/fusion-framework-module';
|
|
2
2
|
import { ServicesModule, IApiProvider } from '@equinor/fusion-framework-module-services';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import { QueryCtorOptions } from '@equinor/fusion-query';
|
|
4
|
+
import { ContextFilterFn, ContextItem, QueryContextParameters } from './types';
|
|
5
|
+
import { GetContextParameters } from './client/ContextClient';
|
|
6
|
+
import { ContextConfigBuilderCallback } from './ContextConfigBuilder';
|
|
7
|
+
export interface ContextModuleConfig {
|
|
8
|
+
client: {
|
|
9
|
+
get: QueryCtorOptions<ContextItem, GetContextParameters>;
|
|
10
|
+
query: QueryCtorOptions<ContextItem[], QueryContextParameters>;
|
|
11
|
+
};
|
|
9
12
|
contextType?: string[];
|
|
10
|
-
contextFilter?:
|
|
13
|
+
contextFilter?: ContextFilterFn;
|
|
11
14
|
}
|
|
12
|
-
export interface IContextModuleConfigurator
|
|
13
|
-
|
|
14
|
-
processConfig: (config: IContextModuleConfig) => IContextModuleConfig;
|
|
15
|
+
export interface IContextModuleConfigurator {
|
|
16
|
+
addConfigBuilder: (init: ContextConfigBuilderCallback) => void;
|
|
15
17
|
}
|
|
16
|
-
export declare class ContextModuleConfigurator implements IContextModuleConfigurator
|
|
17
|
-
|
|
18
|
+
export declare class ContextModuleConfigurator implements IContextModuleConfigurator {
|
|
19
|
+
#private;
|
|
18
20
|
defaultExpireTime: number;
|
|
19
|
-
|
|
20
|
-
id: string;
|
|
21
|
-
}>['client']>;
|
|
22
|
-
protected _createContextClientQuery(apiProvider: IApiProvider): Promise<QueryCtorOptions<ContextItem[], QueryContextParameters>['client']>;
|
|
21
|
+
addConfigBuilder(init: ContextConfigBuilderCallback): void;
|
|
23
22
|
protected _getServiceProvider(init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>): Promise<IApiProvider>;
|
|
24
|
-
createConfig(init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>): Promise<
|
|
25
|
-
processConfig(config: IContextModuleConfig): IContextModuleConfig;
|
|
23
|
+
createConfig(init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>): Promise<ContextModuleConfig>;
|
|
26
24
|
}
|
|
27
25
|
export default ContextModuleConfigurator;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IModulesConfigurator, AnyModule, ModuleInitializerArgs } from '@equinor/fusion-framework-module';
|
|
2
|
+
import type { IContextModuleConfigurator } from 'configurator';
|
|
3
|
+
import type { ContextConfigBuilder } from 'ContextConfigBuilder';
|
|
4
|
+
export declare const enableContext: (configurator: IModulesConfigurator, builder?: (<TDeps extends AnyModule[] = []>(builder: ContextConfigBuilder<TDeps, ModuleInitializerArgs<IContextModuleConfigurator, TDeps>>) => void | Promise<void>) | undefined) => void;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { IContextModuleConfig } from './configurator';
|
|
3
|
-
export declare const enableContext: (configurator: IModulesConfigurator, options?: Pick<IContextModuleConfig, 'contextFilter' | 'contextType'>) => void;
|
|
4
|
-
export { ContextModuleConfigurator, IContextModuleConfigurator, IContextModuleConfig, } from './configurator';
|
|
1
|
+
export { ContextModuleConfigurator, IContextModuleConfigurator, ContextModuleConfig, } from './configurator';
|
|
5
2
|
export { IContextProvider, ContextProvider } from './provider';
|
|
6
3
|
export { default, ContextModule, module as contextModule, moduleKey as contextModuleKey, } from './module';
|
|
4
|
+
export { enableContext } from './enable-context';
|
|
7
5
|
export * from './types';
|
package/dist/types/module.d.ts
CHANGED
|
@@ -10,4 +10,9 @@ export type ContextModule = Module<ContextModuleKey, IContextProvider, IContextM
|
|
|
10
10
|
EventModule
|
|
11
11
|
]>;
|
|
12
12
|
export declare const module: ContextModule;
|
|
13
|
+
declare module '@equinor/fusion-framework-module' {
|
|
14
|
+
interface Modules {
|
|
15
|
+
context: ContextModule;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
13
18
|
export default module;
|
package/dist/types/provider.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
import {
|
|
2
|
+
import { ContextModuleConfig } from './configurator';
|
|
3
3
|
import { ContextClient } from './client/ContextClient';
|
|
4
4
|
import { ContextItem, QueryContextParameters } from './types';
|
|
5
5
|
import { ModuleType } from '@equinor/fusion-framework-module';
|
|
@@ -10,6 +10,7 @@ export interface IContextProvider {
|
|
|
10
10
|
readonly queryClient: Query<ContextItem[], QueryContextParameters>;
|
|
11
11
|
readonly currentContext$: Observable<ContextItem | undefined>;
|
|
12
12
|
currentContext: ContextItem | undefined;
|
|
13
|
+
queryContext(search: string): Observable<Array<ContextItem>>;
|
|
13
14
|
}
|
|
14
15
|
export declare class ContextProvider implements IContextProvider {
|
|
15
16
|
#private;
|
|
@@ -21,7 +22,7 @@ export declare class ContextProvider implements IContextProvider {
|
|
|
21
22
|
get currentContext(): ContextItem | undefined;
|
|
22
23
|
set currentContext(context: ContextItem | undefined);
|
|
23
24
|
constructor(args: {
|
|
24
|
-
config:
|
|
25
|
+
config: ContextModuleConfig;
|
|
25
26
|
event?: ModuleType<EventModule>;
|
|
26
27
|
parentContext?: IContextProvider;
|
|
27
28
|
});
|
package/dist/types/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-module-context",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -31,17 +31,17 @@
|
|
|
31
31
|
"directory": "packages/modules-context"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@equinor/fusion-query": "^0.
|
|
34
|
+
"@equinor/fusion-query": "^1.0.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@equinor/fusion-framework-module": "^1.2.10",
|
|
38
38
|
"@equinor/fusion-framework-module-event": "^1.1.6",
|
|
39
|
-
"@equinor/fusion-framework-module-services": "^0.
|
|
39
|
+
"@equinor/fusion-framework-module-services": "^1.0.0",
|
|
40
40
|
"rxjs": "^7.5.7"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@equinor/fusion-framework-module": "^1.2.5",
|
|
44
44
|
"rxjs": "^7.5.7"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "b93e25b79c3b34ee46bd3a16b059e850acdffe95"
|
|
47
47
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyModule,
|
|
3
|
+
ModuleInitializerArgs,
|
|
4
|
+
Modules,
|
|
5
|
+
ModuleType,
|
|
6
|
+
} from '@equinor/fusion-framework-module';
|
|
7
|
+
|
|
8
|
+
import type { QueryCtorOptions, QueryFn } from '@equinor/fusion-query';
|
|
9
|
+
|
|
10
|
+
import type { GetContextParameters } from './client/ContextClient';
|
|
11
|
+
|
|
12
|
+
import type {
|
|
13
|
+
ContextModuleConfig,
|
|
14
|
+
ContextModuleConfigurator,
|
|
15
|
+
IContextModuleConfigurator,
|
|
16
|
+
} from './configurator';
|
|
17
|
+
|
|
18
|
+
import type { ContextItem, QueryContextParameters } from './types';
|
|
19
|
+
|
|
20
|
+
export type ContextConfigBuilderCallback = <TDeps extends Array<AnyModule> = []>(
|
|
21
|
+
builder: ContextConfigBuilder<TDeps, ModuleInitializerArgs<IContextModuleConfigurator, TDeps>>
|
|
22
|
+
) => void | Promise<void>;
|
|
23
|
+
|
|
24
|
+
export class ContextConfigBuilder<
|
|
25
|
+
TModules extends Array<AnyModule> = [],
|
|
26
|
+
TInit extends ModuleInitializerArgs<any, any> = ModuleInitializerArgs<
|
|
27
|
+
ContextModuleConfigurator,
|
|
28
|
+
TModules
|
|
29
|
+
>
|
|
30
|
+
> {
|
|
31
|
+
#init: TInit;
|
|
32
|
+
constructor(init: TInit, public config: Partial<ContextModuleConfig> = {}) {
|
|
33
|
+
this.#init = init;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
requireInstance<TKey extends string = Extract<keyof Modules, string>>(
|
|
37
|
+
module: TKey
|
|
38
|
+
): Promise<ModuleType<Modules[TKey]>>;
|
|
39
|
+
|
|
40
|
+
requireInstance<T>(module: string): Promise<T>;
|
|
41
|
+
|
|
42
|
+
requireInstance(module: string): Promise<any> {
|
|
43
|
+
return this.#init.requireInstance(module);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
setContextType(type: ContextModuleConfig['contextType']) {
|
|
47
|
+
this.config.contextType = type;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
setContextFilter(filter: ContextModuleConfig['contextFilter']) {
|
|
51
|
+
this.config.contextFilter = filter;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
setContextClient(
|
|
55
|
+
client: {
|
|
56
|
+
get:
|
|
57
|
+
| QueryFn<ContextItem, GetContextParameters>
|
|
58
|
+
| QueryCtorOptions<ContextItem, GetContextParameters>;
|
|
59
|
+
query:
|
|
60
|
+
| QueryFn<ContextItem[], QueryContextParameters>
|
|
61
|
+
| QueryCtorOptions<ContextItem[], QueryContextParameters>;
|
|
62
|
+
},
|
|
63
|
+
expire = 1 * 60 * 1000
|
|
64
|
+
): void {
|
|
65
|
+
this.config.client = {
|
|
66
|
+
get:
|
|
67
|
+
typeof client.get === 'function'
|
|
68
|
+
? {
|
|
69
|
+
key: ({ id }) => id,
|
|
70
|
+
client: {
|
|
71
|
+
fn: client.get,
|
|
72
|
+
},
|
|
73
|
+
expire,
|
|
74
|
+
}
|
|
75
|
+
: client.get,
|
|
76
|
+
query:
|
|
77
|
+
typeof client.query === 'function'
|
|
78
|
+
? {
|
|
79
|
+
// TODO - might cast to checksum
|
|
80
|
+
key: (args) => JSON.stringify(args),
|
|
81
|
+
client: {
|
|
82
|
+
fn: client.query,
|
|
83
|
+
},
|
|
84
|
+
expire,
|
|
85
|
+
}
|
|
86
|
+
: client.query,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -5,10 +5,7 @@ import { Query, QueryCtorOptions } from '@equinor/fusion-query';
|
|
|
5
5
|
|
|
6
6
|
import { ContextItem } from '../types';
|
|
7
7
|
|
|
8
|
-
export type
|
|
9
|
-
query: QueryCtorOptions<ContextItem, { id: string }>;
|
|
10
|
-
initial?: ContextItem;
|
|
11
|
-
};
|
|
8
|
+
export type GetContextParameters = { id: string };
|
|
12
9
|
|
|
13
10
|
export class ContextClient extends Observable<ContextItem> {
|
|
14
11
|
#client: Query<ContextItem, { id: string }>;
|
|
@@ -27,10 +24,10 @@ export class ContextClient extends Observable<ContextItem> {
|
|
|
27
24
|
return this.#client;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
|
-
constructor(options:
|
|
27
|
+
constructor(options: QueryCtorOptions<ContextItem, GetContextParameters>) {
|
|
31
28
|
super((observer) => this.#currentContext$.subscribe(observer));
|
|
32
|
-
this.#client = new Query(options
|
|
33
|
-
this.#currentContext$ = new BehaviorSubject<ContextItem | undefined>(
|
|
29
|
+
this.#client = new Query(options);
|
|
30
|
+
this.#currentContext$ = new BehaviorSubject<ContextItem | undefined>(undefined);
|
|
34
31
|
}
|
|
35
32
|
|
|
36
33
|
public setCurrentContext(idOrItem?: string | ContextItem) {
|
package/src/configurator.ts
CHANGED
|
@@ -1,56 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AnyModule,
|
|
3
|
-
ModuleInitializerArgs,
|
|
4
|
-
ModulesInstanceType,
|
|
5
|
-
} from '@equinor/fusion-framework-module';
|
|
1
|
+
import { ModuleInitializerArgs, ModulesInstanceType } from '@equinor/fusion-framework-module';
|
|
6
2
|
import { ServicesModule, IApiProvider } from '@equinor/fusion-framework-module-services';
|
|
7
|
-
import type { QueryCtorOptions } from '@equinor/fusion-query';
|
|
8
|
-
import { ContextClientOptions } from './client/ContextClient';
|
|
9
|
-
import { ContextItem, QueryContextParameters } from './types';
|
|
10
3
|
import { getContextSelector, queryContextSelector } from './selectors';
|
|
4
|
+
import { QueryCtorOptions } from '@equinor/fusion-query';
|
|
5
|
+
import { ContextFilterFn, ContextItem, QueryContextParameters } from './types';
|
|
6
|
+
import { GetContextParameters } from './client/ContextClient';
|
|
7
|
+
import { ContextConfigBuilder, ContextConfigBuilderCallback } from './ContextConfigBuilder';
|
|
11
8
|
|
|
12
|
-
export interface
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
export interface ContextModuleConfig {
|
|
10
|
+
client: {
|
|
11
|
+
get: QueryCtorOptions<ContextItem, GetContextParameters>;
|
|
12
|
+
query: QueryCtorOptions<ContextItem[], QueryContextParameters>;
|
|
13
|
+
};
|
|
15
14
|
contextType?: string[];
|
|
16
|
-
contextFilter?:
|
|
15
|
+
contextFilter?: ContextFilterFn;
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
export interface IContextModuleConfigurator
|
|
20
|
-
|
|
21
|
-
createConfig: (
|
|
22
|
-
args: ModuleInitializerArgs<IContextModuleConfigurator, TDeps>
|
|
23
|
-
) => Promise<IContextModuleConfig>;
|
|
24
|
-
|
|
25
|
-
/** post process function for altering created config */
|
|
26
|
-
processConfig: (config: IContextModuleConfig) => IContextModuleConfig;
|
|
18
|
+
export interface IContextModuleConfigurator {
|
|
19
|
+
addConfigBuilder: (init: ContextConfigBuilderCallback) => void;
|
|
27
20
|
}
|
|
28
21
|
|
|
29
|
-
export class ContextModuleConfigurator implements IContextModuleConfigurator
|
|
30
|
-
getContext?: Promise<ContextClientOptions['query']['client']>;
|
|
31
|
-
|
|
22
|
+
export class ContextModuleConfigurator implements IContextModuleConfigurator {
|
|
32
23
|
defaultExpireTime = 1 * 60 * 1000;
|
|
33
24
|
|
|
34
|
-
|
|
35
|
-
apiProvider: IApiProvider
|
|
36
|
-
): Promise<QueryCtorOptions<ContextItem, { id: string }>['client']> {
|
|
37
|
-
const contextClient = await apiProvider.createContextClient('json$');
|
|
38
|
-
return {
|
|
39
|
-
fn: (args) => {
|
|
40
|
-
return contextClient.get('v1', args, { selector: getContextSelector });
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
}
|
|
25
|
+
#configBuilders: Array<ContextConfigBuilderCallback> = [];
|
|
44
26
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
): Promise<QueryCtorOptions<ContextItem[], QueryContextParameters>['client']> {
|
|
48
|
-
const contextClient = await apiProvider.createContextClient('json$');
|
|
49
|
-
return {
|
|
50
|
-
fn: (query) => {
|
|
51
|
-
return contextClient.query('v1', { query }, { selector: queryContextSelector });
|
|
52
|
-
},
|
|
53
|
-
};
|
|
27
|
+
addConfigBuilder(init: ContextConfigBuilderCallback): void {
|
|
28
|
+
this.#configBuilders.push(init);
|
|
54
29
|
}
|
|
55
30
|
|
|
56
31
|
protected async _getServiceProvider(
|
|
@@ -70,28 +45,43 @@ export class ContextModuleConfigurator implements IContextModuleConfigurator<[Se
|
|
|
70
45
|
|
|
71
46
|
public async createConfig(
|
|
72
47
|
init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>
|
|
73
|
-
) {
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
48
|
+
): Promise<ContextModuleConfig> {
|
|
49
|
+
const config = await this.#configBuilders.reduce(async (cur, cb) => {
|
|
50
|
+
const builder = new ContextConfigBuilder<any, any>(init, await cur);
|
|
51
|
+
await Promise.resolve(cb(builder));
|
|
52
|
+
return Object.assign(cur, builder.config);
|
|
53
|
+
}, Promise.resolve({} as Partial<ContextModuleConfig>));
|
|
54
|
+
|
|
55
|
+
// TODO - make less lazy
|
|
56
|
+
config.client ??= await (async (): Promise<ContextModuleConfig['client']> => {
|
|
57
|
+
const apiProvider = await this._getServiceProvider(init);
|
|
58
|
+
const contextClient = await apiProvider.createContextClient('json$');
|
|
59
|
+
return {
|
|
60
|
+
get: {
|
|
61
|
+
client: {
|
|
62
|
+
fn: (args) =>
|
|
63
|
+
contextClient.get('v1', args, { selector: getContextSelector }),
|
|
64
|
+
},
|
|
79
65
|
key: ({ id }) => id,
|
|
80
66
|
expire: this.defaultExpireTime,
|
|
81
67
|
},
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
68
|
+
query: {
|
|
69
|
+
client: {
|
|
70
|
+
fn: (query) =>
|
|
71
|
+
contextClient.query(
|
|
72
|
+
'v1',
|
|
73
|
+
{ query },
|
|
74
|
+
{ selector: queryContextSelector }
|
|
75
|
+
),
|
|
76
|
+
},
|
|
77
|
+
// TODO - might cast to checksum
|
|
78
|
+
key: (args) => JSON.stringify(args),
|
|
79
|
+
expire: this.defaultExpireTime,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
})();
|
|
92
83
|
|
|
93
|
-
|
|
94
|
-
return config;
|
|
84
|
+
return config as ContextModuleConfig;
|
|
95
85
|
}
|
|
96
86
|
}
|
|
97
87
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
IModulesConfigurator,
|
|
3
|
+
AnyModule,
|
|
4
|
+
ModuleInitializerArgs,
|
|
5
|
+
} from '@equinor/fusion-framework-module';
|
|
6
|
+
import type { IContextModuleConfigurator } from 'configurator';
|
|
7
|
+
import type { ContextConfigBuilder } from 'ContextConfigBuilder';
|
|
8
|
+
|
|
9
|
+
import { module } from './module';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Method for enabling the Service module
|
|
13
|
+
* @param configurator - configuration object
|
|
14
|
+
*/
|
|
15
|
+
export const enableContext = (
|
|
16
|
+
configurator: IModulesConfigurator,
|
|
17
|
+
builder?: <TDeps extends Array<AnyModule> = []>(
|
|
18
|
+
builder: ContextConfigBuilder<
|
|
19
|
+
TDeps,
|
|
20
|
+
ModuleInitializerArgs<IContextModuleConfigurator, TDeps>
|
|
21
|
+
>
|
|
22
|
+
) => void | Promise<void>
|
|
23
|
+
): void => {
|
|
24
|
+
configurator.addConfig({
|
|
25
|
+
module,
|
|
26
|
+
configure: (contextConfigurator) => {
|
|
27
|
+
builder && contextConfigurator.addConfigBuilder(builder);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,32 +1,7 @@
|
|
|
1
|
-
import { IModulesConfigurator } from '@equinor/fusion-framework-module';
|
|
2
|
-
import { IContextModuleConfig } from './configurator';
|
|
3
|
-
|
|
4
|
-
import { module } from './module';
|
|
5
|
-
/**
|
|
6
|
-
* Method for enabling the Service module
|
|
7
|
-
* @param configurator - configuration object
|
|
8
|
-
*/
|
|
9
|
-
export const enableContext = (
|
|
10
|
-
configurator: IModulesConfigurator,
|
|
11
|
-
options?: Pick<IContextModuleConfig, 'contextFilter' | 'contextType'>
|
|
12
|
-
): void => {
|
|
13
|
-
configurator.addConfig({
|
|
14
|
-
module,
|
|
15
|
-
configure: (contextConfigurator) => {
|
|
16
|
-
contextConfigurator.processConfig = (config) => {
|
|
17
|
-
return {
|
|
18
|
-
...config,
|
|
19
|
-
...options,
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
|
|
26
1
|
export {
|
|
27
2
|
ContextModuleConfigurator,
|
|
28
3
|
IContextModuleConfigurator,
|
|
29
|
-
|
|
4
|
+
ContextModuleConfig,
|
|
30
5
|
} from './configurator';
|
|
31
6
|
|
|
32
7
|
export { IContextProvider, ContextProvider } from './provider';
|
|
@@ -38,4 +13,6 @@ export {
|
|
|
38
13
|
moduleKey as contextModuleKey,
|
|
39
14
|
} from './module';
|
|
40
15
|
|
|
16
|
+
export { enableContext } from './enable-context';
|
|
17
|
+
|
|
41
18
|
export * from './types';
|
package/src/module.ts
CHANGED
|
@@ -21,7 +21,7 @@ export const module: ContextModule = {
|
|
|
21
21
|
name: moduleKey,
|
|
22
22
|
configure: () => new ContextModuleConfigurator(),
|
|
23
23
|
initialize: async (args) => {
|
|
24
|
-
const config = await args.config.createConfig(args);
|
|
24
|
+
const config = await (args.config as ContextModuleConfigurator).createConfig(args);
|
|
25
25
|
const event = args.hasModule('event') ? await args.requireInstance('event') : undefined;
|
|
26
26
|
const parentContext = (args.ref as ModulesInstance<[ContextModule]>)?.context;
|
|
27
27
|
return new ContextProvider({ config, event, parentContext });
|
|
@@ -32,4 +32,10 @@ export const module: ContextModule = {
|
|
|
32
32
|
},
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
declare module '@equinor/fusion-framework-module' {
|
|
36
|
+
interface Modules {
|
|
37
|
+
context: ContextModule;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
35
41
|
export default module;
|
package/src/provider.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { lastValueFrom, Observable, Subscription } from 'rxjs';
|
|
2
2
|
import { map, pairwise } from 'rxjs/operators';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { ContextModuleConfig } from './configurator';
|
|
5
5
|
|
|
6
6
|
import { ContextClient } from './client/ContextClient';
|
|
7
7
|
import { ContextItem, QueryContextParameters } from './types';
|
|
@@ -25,6 +25,8 @@ export interface IContextProvider {
|
|
|
25
25
|
|
|
26
26
|
readonly currentContext$: Observable<ContextItem | undefined>;
|
|
27
27
|
currentContext: ContextItem | undefined;
|
|
28
|
+
|
|
29
|
+
queryContext(search: string): Observable<Array<ContextItem>>;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
export class ContextProvider implements IContextProvider {
|
|
@@ -35,8 +37,8 @@ export class ContextProvider implements IContextProvider {
|
|
|
35
37
|
|
|
36
38
|
#subscriptions = new Subscription();
|
|
37
39
|
|
|
38
|
-
#contextType?:
|
|
39
|
-
#contextFilter:
|
|
40
|
+
#contextType?: ContextModuleConfig['contextType'];
|
|
41
|
+
#contextFilter: ContextModuleConfig['contextFilter'];
|
|
40
42
|
|
|
41
43
|
public get contextClient() {
|
|
42
44
|
return this.#contextClient;
|
|
@@ -93,7 +95,7 @@ export class ContextProvider implements IContextProvider {
|
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
constructor(args: {
|
|
96
|
-
config:
|
|
98
|
+
config: ContextModuleConfig;
|
|
97
99
|
event?: ModuleType<EventModule>;
|
|
98
100
|
parentContext?: IContextProvider;
|
|
99
101
|
}) {
|
|
@@ -102,9 +104,8 @@ export class ContextProvider implements IContextProvider {
|
|
|
102
104
|
this.#contextType = config.contextType;
|
|
103
105
|
this.#contextFilter = config.contextFilter;
|
|
104
106
|
|
|
105
|
-
this.#contextClient = new ContextClient(config.
|
|
106
|
-
|
|
107
|
-
this.#contextQuery = new Query(config.queryContext);
|
|
107
|
+
this.#contextClient = new ContextClient(config.client.get);
|
|
108
|
+
this.#contextQuery = new Query(config.client.query);
|
|
108
109
|
|
|
109
110
|
if (event) {
|
|
110
111
|
this.#event = event;
|