@equinor/fusion-framework-module-context 4.1.0 → 4.1.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 +116 -110
- package/dist/esm/ContextConfigBuilder.js.map +1 -1
- package/dist/esm/ContextProvider.js +18 -11
- package/dist/esm/ContextProvider.js.map +1 -1
- package/dist/esm/client/ContextClient.js.map +1 -1
- package/dist/esm/configurator.js.map +1 -1
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/selectors.js.map +1 -1
- package/dist/esm/utils/resolve-context-from-path.js.map +1 -1
- package/dist/esm/utils/resolve-initial-context.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/ContextConfigBuilder.ts +2 -0
- package/src/ContextProvider.ts +192 -43
- package/src/errors.ts +20 -0
- package/src/module.ts +18 -1
- package/src/selectors.ts +26 -0
- package/src/version.ts +1 -1
package/src/module.ts
CHANGED
|
@@ -25,27 +25,41 @@ export const module: ContextModule = {
|
|
|
25
25
|
name: moduleKey,
|
|
26
26
|
configure: () => new ContextModuleConfigurator(),
|
|
27
27
|
initialize: async function (args) {
|
|
28
|
+
// create config from configurator
|
|
28
29
|
const config = await (args.config as ContextModuleConfigurator).createConfig(args);
|
|
30
|
+
|
|
31
|
+
// get event module if available
|
|
29
32
|
const event = args.hasModule('event') ? await args.requireInstance('event') : undefined;
|
|
33
|
+
|
|
34
|
+
// get parent context provider if available
|
|
30
35
|
const parentProvider = (args.ref as ModulesInstance<[ContextModule]>)?.context;
|
|
36
|
+
|
|
37
|
+
// create context provider
|
|
31
38
|
const provider = new ContextProvider({ config, event, parentContext: parentProvider });
|
|
32
39
|
|
|
40
|
+
// create subscription for disposing the provider
|
|
33
41
|
const subscription = new Subscription(() => provider.dispose());
|
|
34
42
|
|
|
43
|
+
// setup post initialize to module
|
|
35
44
|
this.postInitialize = (args) =>
|
|
45
|
+
// create observable for resolving initial context
|
|
36
46
|
new Observable((subscriber) => {
|
|
47
|
+
// resolve initial context if available from config if available
|
|
37
48
|
const resolveInitialContext$ = config.resolveInitialContext
|
|
38
49
|
? from(config.resolveInitialContext(args)).pipe(
|
|
50
|
+
// filter out invalid context items
|
|
39
51
|
filter((item): item is ContextItem => !!item),
|
|
40
52
|
switchMap((item) =>
|
|
53
|
+
// set current context with validation and resolution
|
|
41
54
|
args.modules.context.setCurrentContext(item, {
|
|
42
55
|
validate: true,
|
|
43
56
|
resolve: true,
|
|
44
57
|
}),
|
|
45
58
|
),
|
|
46
59
|
)
|
|
47
|
-
: EMPTY;
|
|
60
|
+
: EMPTY; // if no initial context is available, complete immediately
|
|
48
61
|
|
|
62
|
+
// add teardown to resolve initial context
|
|
49
63
|
subscriber.add(
|
|
50
64
|
resolveInitialContext$
|
|
51
65
|
.pipe(
|
|
@@ -55,6 +69,7 @@ export const module: ContextModule = {
|
|
|
55
69
|
'failed to resolve initial context',
|
|
56
70
|
err,
|
|
57
71
|
);
|
|
72
|
+
// failed to resolve initial context, complete immediately
|
|
58
73
|
return EMPTY;
|
|
59
74
|
}),
|
|
60
75
|
)
|
|
@@ -67,6 +82,7 @@ export const module: ContextModule = {
|
|
|
67
82
|
);
|
|
68
83
|
},
|
|
69
84
|
complete: () => {
|
|
85
|
+
// connect parent context if available when stream completes
|
|
70
86
|
if (config.connectParentContext !== false && parentProvider) {
|
|
71
87
|
provider.connectParentContext(parentProvider);
|
|
72
88
|
}
|
|
@@ -76,6 +92,7 @@ export const module: ContextModule = {
|
|
|
76
92
|
);
|
|
77
93
|
});
|
|
78
94
|
|
|
95
|
+
// add teardown to module
|
|
79
96
|
this.dispose = () => subscription.unsubscribe();
|
|
80
97
|
|
|
81
98
|
return provider;
|
package/src/selectors.ts
CHANGED
|
@@ -4,12 +4,23 @@ import type { QueryContextResponse } from '@equinor/fusion-framework-module-serv
|
|
|
4
4
|
import type { RelatedContextResponse } from '@equinor/fusion-framework-module-services/context/related';
|
|
5
5
|
import type { ContextItem, ContextItemType } from './types';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Parses the context type from the response of the GetContext API.
|
|
9
|
+
*
|
|
10
|
+
* @param type The type property from the GetContext response.
|
|
11
|
+
* @returns The parsed context item type.
|
|
12
|
+
*/
|
|
7
13
|
const parseContextType = (type: GetContextResponse<'v1'>['type']): ContextItemType => ({
|
|
8
14
|
id: type.id,
|
|
9
15
|
isChildType: type.isChildType,
|
|
10
16
|
parentTypeIds: type.parentTypeIds ?? [],
|
|
11
17
|
});
|
|
12
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Parses an ApiContextEntity object into a ContextItem object.
|
|
21
|
+
* @param item The ApiContextEntity object to parse.
|
|
22
|
+
* @returns The parsed ContextItem object.
|
|
23
|
+
*/
|
|
13
24
|
const parseContextItem = (item: ApiContextEntity<ApiVersion.v1>): ContextItem => {
|
|
14
25
|
return {
|
|
15
26
|
id: item.id,
|
|
@@ -25,16 +36,31 @@ const parseContextItem = (item: ApiContextEntity<ApiVersion.v1>): ContextItem =>
|
|
|
25
36
|
};
|
|
26
37
|
};
|
|
27
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Parse the response from the GetContext API into a context item.
|
|
41
|
+
* @param response The response object containing the context item.
|
|
42
|
+
* @returns A promise that resolves to the context item.
|
|
43
|
+
*/
|
|
28
44
|
export const getContextSelector = async (response: Response): Promise<ContextItem> => {
|
|
29
45
|
const result = (await response.json()) as GetContextResponse<'v1'>;
|
|
30
46
|
return parseContextItem(result);
|
|
31
47
|
};
|
|
32
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Parse the response from the QueryContext API into an array of context items.
|
|
51
|
+
* @param response The response object.
|
|
52
|
+
* @returns A promise that resolves to an array of context items.
|
|
53
|
+
*/
|
|
33
54
|
export const queryContextSelector = async (response: Response): Promise<ContextItem[]> => {
|
|
34
55
|
const result = (await response.json()) as QueryContextResponse<'v1'>;
|
|
35
56
|
return result.map(parseContextItem);
|
|
36
57
|
};
|
|
37
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Parse the response from the RelatedContext API into an array of context items.
|
|
61
|
+
* @param response The response object containing the related context items.
|
|
62
|
+
* @returns A promise that resolves to an array of ContextItem objects.
|
|
63
|
+
*/
|
|
38
64
|
export const relatedContextSelector = async (response: Response): Promise<ContextItem[]> => {
|
|
39
65
|
const result = (await response.json()) as RelatedContextResponse<'v1'>;
|
|
40
66
|
return result.map(parseContextItem);
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '4.1.
|
|
2
|
+
export const version = '4.1.1';
|