@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.
Files changed (37) hide show
  1. package/CHANGELOG.md +30 -5
  2. package/README.md +33 -0
  3. package/dist/esm/ContextConfigBuilder.js +70 -2
  4. package/dist/esm/ContextConfigBuilder.js.map +1 -1
  5. package/dist/esm/ContextProvider.js +207 -2
  6. package/dist/esm/ContextProvider.js.map +1 -1
  7. package/dist/esm/client/ContextClient.js +65 -1
  8. package/dist/esm/client/ContextClient.js.map +1 -1
  9. package/dist/esm/configurator.js +3 -5
  10. package/dist/esm/configurator.js.map +1 -1
  11. package/dist/esm/errors.js +12 -1
  12. package/dist/esm/errors.js.map +1 -1
  13. package/dist/esm/module.js +21 -0
  14. package/dist/esm/module.js.map +1 -1
  15. package/dist/esm/utils/enable-context.js +19 -3
  16. package/dist/esm/utils/enable-context.js.map +1 -1
  17. package/dist/esm/version.js +1 -1
  18. package/dist/esm/version.js.map +1 -1
  19. package/dist/tsconfig.tsbuildinfo +1 -1
  20. package/dist/types/ContextConfigBuilder.d.ts +70 -0
  21. package/dist/types/ContextProvider.d.ts +347 -6
  22. package/dist/types/client/ContextClient.d.ts +65 -1
  23. package/dist/types/errors.d.ts +12 -1
  24. package/dist/types/module.d.ts +31 -0
  25. package/dist/types/types.d.ts +33 -0
  26. package/dist/types/utils/enable-context.d.ts +18 -2
  27. package/dist/types/version.d.ts +1 -1
  28. package/package.json +7 -7
  29. package/src/ContextConfigBuilder.ts +70 -4
  30. package/src/ContextProvider.ts +353 -10
  31. package/src/client/ContextClient.ts +66 -2
  32. package/src/configurator.ts +4 -5
  33. package/src/errors.ts +12 -1
  34. package/src/module.ts +31 -0
  35. package/src/types.ts +33 -0
  36. package/src/utils/enable-context.ts +19 -3
  37. package/src/version.ts +1 -1
@@ -1,5 +1,16 @@
1
1
  /**
2
- * Represents an error that occurs during a search in the Fusion Context.
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 declare class FusionContextSearchError extends Error {
5
16
  #private;
@@ -6,11 +6,42 @@ import { type IContextModuleConfigurator } from './configurator';
6
6
  import { type IContextProvider } from './ContextProvider';
7
7
  export type ContextModuleKey = 'context';
8
8
  export declare const moduleKey: ContextModuleKey;
9
+ /**
10
+ * Represents a module for managing context within the framework.
11
+ *
12
+ * @typeParam ContextModuleKey - The unique key identifying the context module.
13
+ * @typeParam IContextProvider - The provider interface for context-related services.
14
+ * @typeParam IContextModuleConfigurator - The configurator interface for customizing the context module.
15
+ * @typeParam [ServicesModule, EventModule, NavigationModule] - The tuple of dependent modules required by the context module.
16
+ *
17
+ * @see Module
18
+ */
9
19
  export type ContextModule = Module<ContextModuleKey, IContextProvider, IContextModuleConfigurator, [
10
20
  ServicesModule,
11
21
  EventModule,
12
22
  NavigationModule
13
23
  ]>;
24
+ /**
25
+ * The `module` object implements the `ContextModule` interface and provides the configuration,
26
+ * initialization, and lifecycle management for the context module within the Fusion Framework.
27
+ *
28
+ * @remarks
29
+ * - The `configure` method returns a new `ContextModuleConfigurator` for module configuration.
30
+ * - The `initialize` method asynchronously creates a `ContextProvider` using the provided configuration,
31
+ * optional event module, and optional parent context provider. It also sets up resource disposal and
32
+ * post-initialization logic.
33
+ * - The `postInitialize` function (attached during initialization) resolves the initial context if available,
34
+ * sets it as the current context, and connects to the parent context provider if configured to do so.
35
+ * - The `dispose` function ensures proper cleanup by unsubscribing from the provider's subscription.
36
+ *
37
+ * @property {string} name - The unique key identifying the module.
38
+ * @method configure - Returns a new instance of `ContextModuleConfigurator` for configuring the module.
39
+ * @method initialize - Asynchronously initializes the context provider, sets up context resolution,
40
+ * and manages lifecycle hooks.
41
+ * @see ContextModule
42
+ * @see ContextModuleConfigurator
43
+ * @see ContextProvider
44
+ */
14
45
  export declare const module: ContextModule;
15
46
  declare module '@equinor/fusion-framework-module' {
16
47
  interface Modules {
@@ -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;
@@ -31,10 +51,23 @@ export type QueryContextParameters = {
31
51
  externalId?: string;
32
52
  };
33
53
  };
54
+ /**
55
+ * Parameters for retrieving related context items.
56
+ *
57
+ * @property item - The context item to find relations for.
58
+ * @property filter - Optional filter criteria.
59
+ * @property filter.type - Optional array of types to filter related items by.
60
+ */
34
61
  export type RelatedContextParameters = {
35
62
  item: ContextItem;
36
63
  filter?: {
37
64
  type?: string[];
38
65
  };
39
66
  };
67
+ /**
68
+ * A function type that filters an array of `ContextItem` objects.
69
+ *
70
+ * @param items - The array of `ContextItem` objects to be filtered.
71
+ * @returns A new array of `ContextItem` objects after applying the filter.
72
+ */
40
73
  export type ContextFilterFn = (items: ContextItem[]) => ContextItem[];
@@ -2,7 +2,23 @@ import type { IModulesConfigurator, AnyModule, ModuleInitializerArgs } from '@eq
2
2
  import type { IContextModuleConfigurator } from '../configurator';
3
3
  import type { ContextConfigBuilder } from '../ContextConfigBuilder';
4
4
  /**
5
- * Method for enabling the Service module
6
- * @param configurator - configuration object
5
+ * Enables context configuration for a given modules configurator.
6
+ *
7
+ * @param configurator - The modules configurator instance to which the context module will be added.
8
+ * @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.
9
+ *
10
+ * @remarks
11
+ * This utility function adds the context module to the provided configurator and optionally applies additional configuration using the provided builder function.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { enableContext } from '@equinor/fusion-framework-module-context';
16
+ *
17
+ * const configure = (configurator: IModulesConfigurator<any, any>) => {
18
+ * enableContext(configurator, (builder) => {
19
+ * // configure the context module here
20
+ * });
21
+ * };
22
+ * ```
7
23
  */
8
24
  export declare const enableContext: (configurator: IModulesConfigurator<any, any>, builder?: <TDeps extends Array<AnyModule> = []>(builder: ContextConfigBuilder<TDeps, ModuleInitializerArgs<IContextModuleConfigurator, TDeps>>) => void | Promise<void>) => void;
@@ -1 +1 @@
1
- export declare const version = "6.0.7-next.0";
1
+ export declare const version = "7.0.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-module-context",
3
- "version": "6.0.7-next.0",
3
+ "version": "7.0.1",
4
4
  "description": "",
5
5
  "main": "./dist/esm/index.js",
6
6
  "exports": {
@@ -45,19 +45,19 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "fast-deep-equal": "^3.1.3",
48
- "@equinor/fusion-query": "^5.2.12-next.0"
48
+ "@equinor/fusion-query": "^6.0.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "rxjs": "^7.8.1",
52
52
  "typescript": "^5.8.2",
53
- "@equinor/fusion-framework-module-event": "^4.3.7-next.2",
54
- "@equinor/fusion-framework-module-services": "^6.0.4-next.0",
55
- "@equinor/fusion-framework-module-navigation": "^5.0.4-next.0",
56
- "@equinor/fusion-framework-module": "^4.4.3-next.2"
53
+ "@equinor/fusion-framework-module-event": "^4.3.7",
54
+ "@equinor/fusion-framework-module-navigation": "^6.0.0",
55
+ "@equinor/fusion-framework-module-services": "^7.1.2",
56
+ "@equinor/fusion-framework-module": "^5.0.3"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "rxjs": "^7.8.1",
60
- "@equinor/fusion-framework-module": "^4.4.3-next.2"
60
+ "@equinor/fusion-framework-module": "^5.0.3"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "tsc -b"
@@ -21,11 +21,36 @@ export type ContextConfigBuilderCallback = <TDeps extends Array<AnyModule> = []>
21
21
  builder: ContextConfigBuilder<TDeps, ModuleInitializerArgs<IContextModuleConfigurator, TDeps>>,
22
22
  ) => void | Promise<void>;
23
23
 
24
- // TODO - this should extend the BaseConfigBuilder
25
-
24
+ /**
25
+ * A builder class for configuring and customizing context module behavior within the Fusion Framework.
26
+ *
27
+ * `ContextConfigBuilder` provides a fluent API for setting up various aspects of context management,
28
+ * including context type, filtering, parent context connection, parameter resolution, validation,
29
+ * path extraction/generation, and client configuration for fetching context items.
30
+ *
31
+ * @typeParam TModules - An array of modules that extend `AnyModule`. Defaults to an empty array.
32
+ * @typeParam TInit - The initializer arguments for the module, extending `ModuleInitializerArgs`.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const builder = new ContextConfigBuilder(init);
37
+ * builder.setContextType(['ProjectMaster']);
38
+ * builder.setContextFilter(items => items.filter(ctx => ctx.isActive));
39
+ * builder.setContextClient({ get: fetchContextItem, query: fetchContextItems });
40
+ * ```
41
+ *
42
+ * @remarks
43
+ * - Use the provided setter methods to customize context behavior as needed.
44
+ * - The builder pattern allows chaining configuration methods for clarity and convenience.
45
+ * - The `requireInstance` method enables asynchronous retrieval of module instances by name.
46
+ *
47
+ * @todo - this should extend the BaseConfigBuilder
48
+ *
49
+ * @see ContextModuleConfig
50
+ * @see ModuleInitializerArgs
51
+ */
26
52
  export class ContextConfigBuilder<
27
53
  TModules extends Array<AnyModule> = [],
28
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
54
  TInit extends ModuleInitializerArgs<any, any> = ModuleInitializerArgs<
30
55
  ContextModuleConfigurator,
31
56
  TModules
@@ -45,31 +70,60 @@ export class ContextConfigBuilder<
45
70
 
46
71
  requireInstance<T>(module: string): Promise<T>;
47
72
 
48
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
73
  requireInstance(module: string): Promise<any> {
50
74
  return this.#init.requireInstance(module);
51
75
  }
52
76
 
77
+ /**
78
+ * Sets the context type for the current configuration.
79
+ *
80
+ * @param type - The context type to assign, as defined by `ContextModuleConfig['contextType']`.
81
+ */
53
82
  setContextType(type: ContextModuleConfig['contextType']) {
54
83
  this.config.contextType = type;
55
84
  }
56
85
 
86
+ /**
87
+ * Sets the context filter function for the configuration.
88
+ *
89
+ * @param filter - A function that determines whether a context should be included, as defined by `ContextModuleConfig['contextFilter']`.
90
+ */
57
91
  setContextFilter(filter: ContextModuleConfig['contextFilter']) {
58
92
  this.config.contextFilter = filter;
59
93
  }
60
94
 
95
+ /**
96
+ * Sets the function or configuration used to connect to a parent context.
97
+ *
98
+ * @param connect - The function or configuration that defines how to connect to the parent context.
99
+ */
61
100
  connectParentContext(connect: ContextModuleConfig['connectParentContext']) {
62
101
  this.config.connectParentContext = connect;
63
102
  }
64
103
 
104
+ /**
105
+ * Sets the function used to provide context parameters for the module configuration.
106
+ *
107
+ * @param fn - A function conforming to the `contextParameterFn` type defined in `ContextModuleConfig`.
108
+ */
65
109
  setContextParameterFn(fn: ContextModuleConfig['contextParameterFn']) {
66
110
  this.config.contextParameterFn = fn;
67
111
  }
68
112
 
113
+ /**
114
+ * Sets the function used to validate the context within the configuration.
115
+ *
116
+ * @param fn - A function that implements the `validateContext` signature from `ContextModuleConfig`.
117
+ */
69
118
  setValidateContext(fn: ContextModuleConfig['validateContext']) {
70
119
  this.config.validateContext = fn;
71
120
  }
72
121
 
122
+ /**
123
+ * Sets the function used to resolve the context for the module configuration.
124
+ *
125
+ * @param fn - A function that defines how the context should be resolved, conforming to the `resolveContext` type from `ContextModuleConfig`.
126
+ */
73
127
  setResolveContext(fn: ContextModuleConfig['resolveContext']) {
74
128
  this.config.resolveContext = fn;
75
129
  }
@@ -97,6 +151,18 @@ export class ContextConfigBuilder<
97
151
  this.config.resolveInitialContext = fn;
98
152
  }
99
153
 
154
+ /**
155
+ * Sets the context client configuration for fetching context items.
156
+ *
157
+ * This method allows you to provide custom query functions or query constructor options
158
+ * for retrieving single context items (`get`), querying multiple context items (`query`),
159
+ * and optionally fetching related context items (`related`). Each query can be provided
160
+ * as either a function or a configuration object. The expiration time for cached results
161
+ * can also be specified.
162
+ *
163
+ * @param client - An object containing the query functions or options for `get`, `query`, and optionally `related` context items.
164
+ * @param expire - Optional. The expiration time (in milliseconds) for cached query results. Defaults to 1 minute.
165
+ */
100
166
  setContextClient(
101
167
  client: {
102
168
  get: