@equinor/fusion-framework-module-context 6.0.7-next.0 → 7.0.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 +30 -5
- package/README.md +33 -0
- package/dist/esm/ContextConfigBuilder.js +70 -2
- package/dist/esm/ContextConfigBuilder.js.map +1 -1
- package/dist/esm/ContextProvider.js +207 -2
- package/dist/esm/ContextProvider.js.map +1 -1
- package/dist/esm/client/ContextClient.js +65 -1
- package/dist/esm/client/ContextClient.js.map +1 -1
- package/dist/esm/configurator.js +3 -5
- package/dist/esm/configurator.js.map +1 -1
- package/dist/esm/errors.js +12 -1
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/module.js +21 -0
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/utils/enable-context.js +19 -3
- package/dist/esm/utils/enable-context.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ContextConfigBuilder.d.ts +70 -0
- package/dist/types/ContextProvider.d.ts +347 -6
- package/dist/types/client/ContextClient.d.ts +65 -1
- package/dist/types/errors.d.ts +12 -1
- package/dist/types/module.d.ts +31 -0
- package/dist/types/types.d.ts +33 -0
- package/dist/types/utils/enable-context.d.ts +18 -2
- package/dist/types/version.d.ts +1 -1
- package/package.json +7 -7
- package/src/ContextConfigBuilder.ts +70 -4
- package/src/ContextProvider.ts +353 -10
- package/src/client/ContextClient.ts +66 -2
- package/src/configurator.ts +4 -5
- package/src/errors.ts +12 -1
- package/src/module.ts +31 -0
- package/src/types.ts +33 -0
- package/src/utils/enable-context.ts +19 -3
- package/src/version.ts +1 -1
package/src/configurator.ts
CHANGED
|
@@ -86,13 +86,12 @@ export class ContextModuleConfigurator implements IContextModuleConfigurator {
|
|
|
86
86
|
): Promise<IApiProvider> {
|
|
87
87
|
if (init.hasModule('services')) {
|
|
88
88
|
return init.requireInstance('services');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return parentServiceModule;
|
|
93
|
-
}
|
|
89
|
+
}
|
|
90
|
+
const parentServiceModule = (init.ref as ModulesInstanceType<[ServicesModule]>)?.services;
|
|
91
|
+
if (!parentServiceModule) {
|
|
94
92
|
throw Error('no service services provider configures [ServicesModule]');
|
|
95
93
|
}
|
|
94
|
+
return parentServiceModule;
|
|
96
95
|
}
|
|
97
96
|
|
|
98
97
|
public async createConfig(
|
package/src/errors.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Represents an error that occurs during a
|
|
2
|
+
* Represents an error that occurs during a Fusion context search operation.
|
|
3
|
+
*
|
|
4
|
+
* This error provides a title and an optional description to give more context
|
|
5
|
+
* about the failure. It extends the built-in `Error` class and sets the error
|
|
6
|
+
* name to `'FusionContextSearchError'`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* throw new FusionContextSearchError({ title: 'Search failed', description: 'No results found.' });
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
3
14
|
*/
|
|
4
15
|
export class FusionContextSearchError extends Error {
|
|
5
16
|
#details;
|
package/src/module.ts
CHANGED
|
@@ -14,6 +14,16 @@ export type ContextModuleKey = 'context';
|
|
|
14
14
|
|
|
15
15
|
export const moduleKey: ContextModuleKey = 'context';
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Represents a module for managing context within the framework.
|
|
19
|
+
*
|
|
20
|
+
* @typeParam ContextModuleKey - The unique key identifying the context module.
|
|
21
|
+
* @typeParam IContextProvider - The provider interface for context-related services.
|
|
22
|
+
* @typeParam IContextModuleConfigurator - The configurator interface for customizing the context module.
|
|
23
|
+
* @typeParam [ServicesModule, EventModule, NavigationModule] - The tuple of dependent modules required by the context module.
|
|
24
|
+
*
|
|
25
|
+
* @see Module
|
|
26
|
+
*/
|
|
17
27
|
export type ContextModule = Module<
|
|
18
28
|
ContextModuleKey,
|
|
19
29
|
IContextProvider,
|
|
@@ -21,6 +31,27 @@ export type ContextModule = Module<
|
|
|
21
31
|
[ServicesModule, EventModule, NavigationModule]
|
|
22
32
|
>;
|
|
23
33
|
|
|
34
|
+
/**
|
|
35
|
+
* The `module` object implements the `ContextModule` interface and provides the configuration,
|
|
36
|
+
* initialization, and lifecycle management for the context module within the Fusion Framework.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* - The `configure` method returns a new `ContextModuleConfigurator` for module configuration.
|
|
40
|
+
* - The `initialize` method asynchronously creates a `ContextProvider` using the provided configuration,
|
|
41
|
+
* optional event module, and optional parent context provider. It also sets up resource disposal and
|
|
42
|
+
* post-initialization logic.
|
|
43
|
+
* - The `postInitialize` function (attached during initialization) resolves the initial context if available,
|
|
44
|
+
* sets it as the current context, and connects to the parent context provider if configured to do so.
|
|
45
|
+
* - The `dispose` function ensures proper cleanup by unsubscribing from the provider's subscription.
|
|
46
|
+
*
|
|
47
|
+
* @property {string} name - The unique key identifying the module.
|
|
48
|
+
* @method configure - Returns a new instance of `ContextModuleConfigurator` for configuring the module.
|
|
49
|
+
* @method initialize - Asynchronously initializes the context provider, sets up context resolution,
|
|
50
|
+
* and manages lifecycle hooks.
|
|
51
|
+
* @see ContextModule
|
|
52
|
+
* @see ContextModuleConfigurator
|
|
53
|
+
* @see ContextProvider
|
|
54
|
+
*/
|
|
24
55
|
export const module: ContextModule = {
|
|
25
56
|
name: moduleKey,
|
|
26
57
|
configure: () => new ContextModuleConfigurator(),
|
package/src/types.ts
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a contextual item with associated metadata, value, and optional graphical or meta content.
|
|
3
|
+
*
|
|
4
|
+
* @typeParam TType - The type of the value property, defaults to a generic record.
|
|
5
|
+
* @property id - Unique identifier for the context item.
|
|
6
|
+
* @property externalId - Optional external identifier.
|
|
7
|
+
* @property source - Optional source of the context item.
|
|
8
|
+
* @property type - The type of the context item.
|
|
9
|
+
* @property value - The value associated with the context item.
|
|
10
|
+
* @property title - Optional title for display purposes.
|
|
11
|
+
* @property subTitle - Optional subtitle for display purposes.
|
|
12
|
+
* @property isActive - Optional flag indicating if the item is active.
|
|
13
|
+
* @property isDeleted - Optional flag indicating if the item is deleted.
|
|
14
|
+
* @property created - Optional creation date.
|
|
15
|
+
* @property updated - Optional last updated date.
|
|
16
|
+
* @property graphic - Optional graphical representation, either as a string or an object containing type and content.
|
|
17
|
+
* @property meta - Optional meta information, either as a string or an object containing type and content.
|
|
18
|
+
*
|
|
19
|
+
* @todo - convert to Zod schema for validation and type safety.
|
|
20
|
+
*/
|
|
1
21
|
export type ContextItem<TType extends Record<string, unknown> = Record<string, unknown>> = {
|
|
2
22
|
id: string;
|
|
3
23
|
externalId?: string;
|
|
@@ -38,6 +58,19 @@ export type QueryContextParameters = {
|
|
|
38
58
|
};
|
|
39
59
|
};
|
|
40
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Parameters for retrieving related context items.
|
|
63
|
+
*
|
|
64
|
+
* @property item - The context item to find relations for.
|
|
65
|
+
* @property filter - Optional filter criteria.
|
|
66
|
+
* @property filter.type - Optional array of types to filter related items by.
|
|
67
|
+
*/
|
|
41
68
|
export type RelatedContextParameters = { item: ContextItem; filter?: { type?: string[] } };
|
|
42
69
|
|
|
70
|
+
/**
|
|
71
|
+
* A function type that filters an array of `ContextItem` objects.
|
|
72
|
+
*
|
|
73
|
+
* @param items - The array of `ContextItem` objects to be filtered.
|
|
74
|
+
* @returns A new array of `ContextItem` objects after applying the filter.
|
|
75
|
+
*/
|
|
43
76
|
export type ContextFilterFn = (items: ContextItem[]) => ContextItem[];
|
|
@@ -9,11 +9,27 @@ import type { ContextConfigBuilder } from '../ContextConfigBuilder';
|
|
|
9
9
|
import { module } from '../module';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* Enables context configuration for a given modules configurator.
|
|
13
|
+
*
|
|
14
|
+
* @param configurator - The modules configurator instance to which the context module will be added.
|
|
15
|
+
* @param builder - An optional function that receives a context configuration builder. This function can be used to further configure the context module. It can be asynchronous.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* This utility function adds the context module to the provided configurator and optionally applies additional configuration using the provided builder function.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { enableContext } from '@equinor/fusion-framework-module-context';
|
|
23
|
+
*
|
|
24
|
+
* const configure = (configurator: IModulesConfigurator<any, any>) => {
|
|
25
|
+
* enableContext(configurator, (builder) => {
|
|
26
|
+
* // configure the context module here
|
|
27
|
+
* });
|
|
28
|
+
* };
|
|
29
|
+
* ```
|
|
14
30
|
*/
|
|
15
31
|
export const enableContext = (
|
|
16
|
-
//
|
|
32
|
+
// biome-ignore lint/suspicious/noExplicitAny: must be any to support all module types
|
|
17
33
|
configurator: IModulesConfigurator<any, any>,
|
|
18
34
|
builder?: <TDeps extends Array<AnyModule> = []>(
|
|
19
35
|
builder: ContextConfigBuilder<TDeps, ModuleInitializerArgs<IContextModuleConfigurator, TDeps>>,
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '
|
|
2
|
+
export const version = '7.0.1';
|