@equinor/fusion-framework-module-context 0.4.1 → 0.5.1
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 +10 -0
- package/dist/esm/client/ContextClient.js +7 -7
- package/dist/esm/client/ContextClient.js.map +1 -1
- package/dist/esm/configurator.js +22 -8
- package/dist/esm/configurator.js.map +1 -1
- package/dist/esm/index.js +9 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/provider.js +56 -37
- package/dist/esm/provider.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/client/ContextClient.d.ts +1 -1
- package/dist/types/configurator.d.ts +6 -7
- package/dist/types/index.d.ts +2 -1
- package/dist/types/module.d.ts +2 -2
- package/dist/types/provider.d.ts +2 -0
- package/dist/types/types.d.ts +2 -2
- package/package.json +3 -3
- package/src/configurator.ts +34 -22
- package/src/index.ts +17 -3
- package/src/provider.ts +27 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { Query, QueryCtorOptions } from '@equinor/fusion-observable/query';
|
|
3
3
|
import { ContextItem } from '../types';
|
|
4
|
-
export
|
|
4
|
+
export type ContextClientOptions = {
|
|
5
5
|
query: QueryCtorOptions<ContextItem, {
|
|
6
6
|
id: string;
|
|
7
7
|
}>;
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import { AnyModule, ModuleInitializerArgs } from '@equinor/fusion-framework-module';
|
|
2
|
-
import { ServicesModule } from '@equinor/fusion-framework-module-services';
|
|
2
|
+
import { ServicesModule, IApiProvider } from '@equinor/fusion-framework-module-services';
|
|
3
3
|
import { QueryCtorOptions } from '@equinor/fusion-observable/query';
|
|
4
4
|
import { ContextClientOptions } from './client/ContextClient';
|
|
5
5
|
import { ContextItem, QueryContextParameters } from './types';
|
|
6
6
|
export interface IContextModuleConfig {
|
|
7
7
|
getContext: ContextClientOptions;
|
|
8
8
|
queryContext: QueryCtorOptions<ContextItem[], QueryContextParameters>;
|
|
9
|
+
contextType?: string[];
|
|
10
|
+
contextFilter?: (items: Array<ContextItem>) => Array<ContextItem>;
|
|
9
11
|
}
|
|
10
12
|
export interface IContextModuleConfigurator<TDeps extends Array<AnyModule> = [ServicesModule]> {
|
|
11
13
|
createConfig: (args: ModuleInitializerArgs<IContextModuleConfigurator, TDeps>) => Promise<IContextModuleConfig>;
|
|
12
14
|
processConfig: (config: IContextModuleConfig) => IContextModuleConfig;
|
|
13
|
-
createContextClientGet(init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>): Promise<QueryCtorOptions<ContextItem, {
|
|
14
|
-
id: string;
|
|
15
|
-
}>['client']>;
|
|
16
|
-
createContextClientQuery(init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>): Promise<QueryCtorOptions<ContextItem[], QueryContextParameters>['client']>;
|
|
17
15
|
}
|
|
18
16
|
export declare class ContextModuleConfigurator implements IContextModuleConfigurator<[ServicesModule]> {
|
|
19
17
|
getContext?: Promise<ContextClientOptions['query']['client']>;
|
|
20
18
|
defaultExpireTime: number;
|
|
21
|
-
|
|
19
|
+
protected _createContextClientGet(apiProvider: IApiProvider): Promise<QueryCtorOptions<ContextItem, {
|
|
22
20
|
id: string;
|
|
23
21
|
}>['client']>;
|
|
24
|
-
|
|
22
|
+
protected _createContextClientQuery(apiProvider: IApiProvider): Promise<QueryCtorOptions<ContextItem[], QueryContextParameters>['client']>;
|
|
23
|
+
protected _getServiceProvider(init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>): Promise<IApiProvider>;
|
|
25
24
|
createConfig(init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>): Promise<IContextModuleConfig>;
|
|
26
25
|
processConfig(config: IContextModuleConfig): IContextModuleConfig;
|
|
27
26
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IModulesConfigurator } from '@equinor/fusion-framework-module';
|
|
2
|
-
|
|
2
|
+
import { IContextModuleConfig } from './configurator';
|
|
3
|
+
export declare const enableContext: (configurator: IModulesConfigurator, options?: Pick<IContextModuleConfig, 'contextFilter' | 'contextType'>) => void;
|
|
3
4
|
export { ContextModuleConfigurator, IContextModuleConfigurator, IContextModuleConfig, } from './configurator';
|
|
4
5
|
export { IContextProvider, ContextProvider } from './provider';
|
|
5
6
|
export { default, ContextModule, module as contextModule, moduleKey as contextModuleKey, } from './module';
|
package/dist/types/module.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ import { EventModule } from '@equinor/fusion-framework-module-event';
|
|
|
3
3
|
import { ServicesModule } from '@equinor/fusion-framework-module-services';
|
|
4
4
|
import { IContextModuleConfigurator } from './configurator';
|
|
5
5
|
import { IContextProvider } from './provider';
|
|
6
|
-
export
|
|
6
|
+
export type ContextModuleKey = 'context';
|
|
7
7
|
export declare const moduleKey: ContextModuleKey;
|
|
8
|
-
export
|
|
8
|
+
export type ContextModule = Module<ContextModuleKey, IContextProvider, IContextModuleConfigurator, [
|
|
9
9
|
ServicesModule,
|
|
10
10
|
EventModule
|
|
11
11
|
]>;
|
package/dist/types/provider.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export declare class ContextProvider implements IContextProvider {
|
|
|
15
15
|
#private;
|
|
16
16
|
get contextClient(): ContextClient;
|
|
17
17
|
get queryClient(): Query<ContextItem<Record<string, unknown>>[], QueryContextParameters>;
|
|
18
|
+
queryContext(search: string): Observable<Array<ContextItem>>;
|
|
19
|
+
queryContextAsync(search: string): Promise<Array<ContextItem>>;
|
|
18
20
|
get currentContext$(): Observable<ContextItem | undefined>;
|
|
19
21
|
get currentContext(): ContextItem | undefined;
|
|
20
22
|
set currentContext(context: ContextItem | undefined);
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type ContextItem<TType extends Record<string, unknown> = Record<string, unknown>> = {
|
|
2
2
|
id: string;
|
|
3
3
|
externalId?: string;
|
|
4
4
|
source?: string;
|
|
@@ -15,7 +15,7 @@ export interface ContextItemType {
|
|
|
15
15
|
isChildType: boolean;
|
|
16
16
|
parentTypeIds: string[];
|
|
17
17
|
}
|
|
18
|
-
export
|
|
18
|
+
export type QueryContextParameters = {
|
|
19
19
|
search?: string;
|
|
20
20
|
filter?: {
|
|
21
21
|
type?: string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-module-context",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@equinor/fusion-framework-module": "^1.2.9",
|
|
35
35
|
"@equinor/fusion-framework-module-event": "^1.1.4",
|
|
36
|
-
"@equinor/fusion-framework-module-services": "^0.5.
|
|
36
|
+
"@equinor/fusion-framework-module-services": "^0.5.7",
|
|
37
37
|
"@equinor/fusion-observable": "^1.4.1",
|
|
38
38
|
"rxjs": "^7.5.7"
|
|
39
39
|
},
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"@equinor/fusion-observable": "^1.2.1",
|
|
43
43
|
"rxjs": "^7.5.7"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "08348a63143c1fc0d62fd75e81271ffc2cab9be4"
|
|
46
46
|
}
|
package/src/configurator.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
AnyModule,
|
|
3
|
+
ModuleInitializerArgs,
|
|
4
|
+
ModulesInstanceType,
|
|
5
|
+
} from '@equinor/fusion-framework-module';
|
|
6
|
+
import { ServicesModule, IApiProvider } from '@equinor/fusion-framework-module-services';
|
|
3
7
|
import { QueryCtorOptions } from '@equinor/fusion-observable/query';
|
|
4
8
|
import { ContextClientOptions } from './client/ContextClient';
|
|
5
9
|
import { ContextItem, QueryContextParameters } from './types';
|
|
@@ -8,6 +12,8 @@ import { getContextSelector, queryContextSelector } from './selectors';
|
|
|
8
12
|
export interface IContextModuleConfig {
|
|
9
13
|
getContext: ContextClientOptions;
|
|
10
14
|
queryContext: QueryCtorOptions<ContextItem[], QueryContextParameters>;
|
|
15
|
+
contextType?: string[];
|
|
16
|
+
contextFilter?: (items: Array<ContextItem>) => Array<ContextItem>;
|
|
11
17
|
}
|
|
12
18
|
|
|
13
19
|
export interface IContextModuleConfigurator<TDeps extends Array<AnyModule> = [ServicesModule]> {
|
|
@@ -15,17 +21,9 @@ export interface IContextModuleConfigurator<TDeps extends Array<AnyModule> = [Se
|
|
|
15
21
|
createConfig: (
|
|
16
22
|
args: ModuleInitializerArgs<IContextModuleConfigurator, TDeps>
|
|
17
23
|
) => Promise<IContextModuleConfig>;
|
|
18
|
-
processConfig: (config: IContextModuleConfig) => IContextModuleConfig;
|
|
19
|
-
|
|
20
|
-
/** fired on initialize of module */
|
|
21
|
-
createContextClientGet(
|
|
22
|
-
init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>
|
|
23
|
-
): Promise<QueryCtorOptions<ContextItem, { id: string }>['client']>;
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>
|
|
28
|
-
): Promise<QueryCtorOptions<ContextItem[], QueryContextParameters>['client']>;
|
|
25
|
+
/** post process function for altering created config */
|
|
26
|
+
processConfig: (config: IContextModuleConfig) => IContextModuleConfig;
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
export class ContextModuleConfigurator implements IContextModuleConfigurator<[ServicesModule]> {
|
|
@@ -33,11 +31,10 @@ export class ContextModuleConfigurator implements IContextModuleConfigurator<[Se
|
|
|
33
31
|
|
|
34
32
|
defaultExpireTime = 1 * 60 * 1000;
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
protected async _createContextClientGet(
|
|
35
|
+
apiProvider: IApiProvider
|
|
38
36
|
): Promise<QueryCtorOptions<ContextItem, { id: string }>['client']> {
|
|
39
|
-
const
|
|
40
|
-
const contextClient = await provider.createContextClient('json$');
|
|
37
|
+
const contextClient = await apiProvider.createContextClient('json$');
|
|
41
38
|
return {
|
|
42
39
|
fn: (args) => {
|
|
43
40
|
return contextClient.get('v1', args, { selector: getContextSelector });
|
|
@@ -45,11 +42,10 @@ export class ContextModuleConfigurator implements IContextModuleConfigurator<[Se
|
|
|
45
42
|
};
|
|
46
43
|
}
|
|
47
44
|
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
protected async _createContextClientQuery(
|
|
46
|
+
apiProvider: IApiProvider
|
|
50
47
|
): Promise<QueryCtorOptions<ContextItem[], QueryContextParameters>['client']> {
|
|
51
|
-
const
|
|
52
|
-
const contextClient = await provider.createContextClient('json$');
|
|
48
|
+
const contextClient = await apiProvider.createContextClient('json$');
|
|
53
49
|
return {
|
|
54
50
|
fn: (query) => {
|
|
55
51
|
return contextClient.query('v1', { query }, { selector: queryContextSelector });
|
|
@@ -57,19 +53,35 @@ export class ContextModuleConfigurator implements IContextModuleConfigurator<[Se
|
|
|
57
53
|
};
|
|
58
54
|
}
|
|
59
55
|
|
|
56
|
+
protected async _getServiceProvider(
|
|
57
|
+
init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>
|
|
58
|
+
): Promise<IApiProvider> {
|
|
59
|
+
if (init.hasModule('services')) {
|
|
60
|
+
return init.requireInstance('services');
|
|
61
|
+
} else {
|
|
62
|
+
const parentServiceModule = (init.ref as ModulesInstanceType<[ServicesModule]>)
|
|
63
|
+
?.services;
|
|
64
|
+
if (parentServiceModule) {
|
|
65
|
+
return parentServiceModule;
|
|
66
|
+
}
|
|
67
|
+
throw Error('no service services provider configures [ServicesModule]');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
60
71
|
public async createConfig(
|
|
61
72
|
init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>
|
|
62
73
|
) {
|
|
74
|
+
const apiProvider = await this._getServiceProvider(init);
|
|
63
75
|
const config: IContextModuleConfig = {
|
|
64
76
|
getContext: {
|
|
65
77
|
query: {
|
|
66
|
-
client: await this.
|
|
78
|
+
client: await this._createContextClientGet(apiProvider),
|
|
67
79
|
key: ({ id }) => id,
|
|
68
80
|
expire: this.defaultExpireTime,
|
|
69
81
|
},
|
|
70
82
|
},
|
|
71
83
|
queryContext: {
|
|
72
|
-
client: await this.
|
|
84
|
+
client: await this._createContextClientQuery(apiProvider),
|
|
73
85
|
key: (args) => JSON.stringify(args),
|
|
74
86
|
expire: this.defaultExpireTime,
|
|
75
87
|
},
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
import { IModulesConfigurator } from '@equinor/fusion-framework-module';
|
|
2
|
+
import { IContextModuleConfig } from './configurator';
|
|
2
3
|
|
|
3
4
|
import { module } from './module';
|
|
4
5
|
/**
|
|
5
6
|
* Method for enabling the Service module
|
|
6
|
-
* @param
|
|
7
|
+
* @param configurator - configuration object
|
|
7
8
|
*/
|
|
8
|
-
export const enableContext = (
|
|
9
|
-
|
|
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
|
+
});
|
|
10
24
|
};
|
|
11
25
|
|
|
12
26
|
export {
|
package/src/provider.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { lastValueFrom, Observable, Subscription } from 'rxjs';
|
|
2
|
+
import { map, pairwise } from 'rxjs/operators';
|
|
2
3
|
|
|
3
4
|
import { IContextModuleConfig } from './configurator';
|
|
4
5
|
|
|
@@ -28,12 +29,15 @@ export interface IContextProvider {
|
|
|
28
29
|
|
|
29
30
|
export class ContextProvider implements IContextProvider {
|
|
30
31
|
#contextClient: ContextClient;
|
|
31
|
-
#contextQuery: Query<ContextItem
|
|
32
|
+
#contextQuery: Query<Array<ContextItem>, QueryContextParameters>;
|
|
32
33
|
|
|
33
34
|
#event?: ModuleType<EventModule>;
|
|
34
35
|
|
|
35
36
|
#subscriptions = new Subscription();
|
|
36
37
|
|
|
38
|
+
#contextType?: IContextModuleConfig['contextType'];
|
|
39
|
+
#contextFilter: IContextModuleConfig['contextFilter'];
|
|
40
|
+
|
|
37
41
|
public get contextClient() {
|
|
38
42
|
return this.#contextClient;
|
|
39
43
|
}
|
|
@@ -42,6 +46,23 @@ export class ContextProvider implements IContextProvider {
|
|
|
42
46
|
return this.#contextQuery;
|
|
43
47
|
}
|
|
44
48
|
|
|
49
|
+
public queryContext(search: string): Observable<Array<ContextItem>> {
|
|
50
|
+
const query$ = this.queryClient
|
|
51
|
+
.query({
|
|
52
|
+
search,
|
|
53
|
+
filter: {
|
|
54
|
+
type: this.#contextType,
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
.pipe(map((x) => x.value));
|
|
58
|
+
|
|
59
|
+
return this.#contextFilter ? query$.pipe(map(this.#contextFilter)) : query$;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public queryContextAsync(search: string): Promise<Array<ContextItem>> {
|
|
63
|
+
return lastValueFrom(this.queryContext(search));
|
|
64
|
+
}
|
|
65
|
+
|
|
45
66
|
get currentContext$(): Observable<ContextItem | undefined> {
|
|
46
67
|
return this.#contextClient.currentContext$;
|
|
47
68
|
}
|
|
@@ -77,6 +98,10 @@ export class ContextProvider implements IContextProvider {
|
|
|
77
98
|
parentContext?: IContextProvider;
|
|
78
99
|
}) {
|
|
79
100
|
const { config, event, parentContext } = args;
|
|
101
|
+
|
|
102
|
+
this.#contextType = config.contextType;
|
|
103
|
+
this.#contextFilter = config.contextFilter;
|
|
104
|
+
|
|
80
105
|
this.#contextClient = new ContextClient(config.getContext);
|
|
81
106
|
|
|
82
107
|
this.#contextQuery = new Query(config.queryContext);
|