@equinor/fusion-framework-module-context 7.0.3 → 8.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 +28 -11
- package/README.md +168 -16
- package/dist/esm/ContextConfigBuilder.js +7 -0
- package/dist/esm/ContextConfigBuilder.js.map +1 -1
- package/dist/esm/configurator.js +31 -0
- package/dist/esm/configurator.js.map +1 -1
- package/dist/esm/index.js +12 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/module.js +6 -0
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/utils/index.js +10 -0
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ContextConfigBuilder.d.ts +15 -0
- package/dist/types/ContextProvider.d.ts +37 -0
- package/dist/types/configurator.d.ts +134 -4
- package/dist/types/index.d.ts +12 -0
- package/dist/types/module.d.ts +11 -0
- package/dist/types/types.d.ts +22 -0
- package/dist/types/utils/index.d.ts +10 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +9 -9
- package/src/ContextConfigBuilder.ts +15 -0
- package/src/ContextProvider.ts +37 -7
- package/src/configurator.ts +137 -4
- package/src/index.ts +13 -0
- package/src/module.ts +11 -0
- package/src/types.ts +22 -0
- package/src/utils/index.ts +10 -0
- package/src/version.ts +1 -1
package/src/configurator.ts
CHANGED
|
@@ -21,46 +21,133 @@ import { ContextConfigBuilder, type ContextConfigBuilderCallback } from './Conte
|
|
|
21
21
|
import type { IContextProvider } from './ContextProvider';
|
|
22
22
|
import resolveInitialContext from './utils/resolve-initial-context';
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Resolved configuration for the context module.
|
|
26
|
+
*
|
|
27
|
+
* Holds query clients, type filters, parent-connection settings, and
|
|
28
|
+
* optional callbacks for validation, resolution, and path integration.
|
|
29
|
+
* Produced by {@link ContextModuleConfigurator.createConfig} after all
|
|
30
|
+
* {@link ContextConfigBuilder} callbacks have run.
|
|
31
|
+
*
|
|
32
|
+
* @see ContextConfigBuilder — fluent API for populating this config.
|
|
33
|
+
* @see ContextProvider — runtime consumer of this config.
|
|
34
|
+
*/
|
|
24
35
|
export interface ContextModuleConfig {
|
|
36
|
+
/**
|
|
37
|
+
* Query client options used to fetch, search, and resolve related context items.
|
|
38
|
+
*
|
|
39
|
+
* - `get` — retrieves a single context item by ID.
|
|
40
|
+
* - `query` — searches context items by text and optional type filter.
|
|
41
|
+
* - `related` — fetches context items related to a given item (used during resolution).
|
|
42
|
+
*/
|
|
25
43
|
client: {
|
|
26
44
|
get: QueryCtorOptions<ContextItem, GetContextParameters>;
|
|
27
45
|
query: QueryCtorOptions<ContextItem[], QueryContextParameters>;
|
|
28
46
|
related?: QueryCtorOptions<ContextItem[], RelatedContextParameters>;
|
|
29
47
|
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Allowed context type IDs (e.g. `['ProjectMaster', 'Facility']`).
|
|
51
|
+
*
|
|
52
|
+
* When set, {@link ContextProvider.validateContext} only accepts items
|
|
53
|
+
* whose `type.id` matches one of these values (case-insensitive).
|
|
54
|
+
*/
|
|
30
55
|
contextType?: string[];
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Optional post-query filter applied to the result set returned by
|
|
59
|
+
* {@link ContextProvider.queryContext}.
|
|
60
|
+
*/
|
|
31
61
|
contextFilter?: ContextFilterFn;
|
|
32
62
|
|
|
33
63
|
/**
|
|
34
|
-
* connect context module to
|
|
64
|
+
* Whether to connect the context module to a parent context module.
|
|
65
|
+
*
|
|
66
|
+
* When `true` (the default), the provider subscribes to the parent's
|
|
67
|
+
* `currentContext$` and mirrors changes into its own state.
|
|
35
68
|
*
|
|
36
|
-
*
|
|
69
|
+
* @defaultValue `true`
|
|
37
70
|
*/
|
|
38
71
|
connectParentContext?: boolean;
|
|
39
72
|
|
|
40
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* When `true`, skips resolving an initial context from the path or parent
|
|
75
|
+
* during module post-initialization.
|
|
76
|
+
*/
|
|
41
77
|
skipInitialContext?: boolean;
|
|
42
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Extracts a context ID from a URL path segment.
|
|
81
|
+
*
|
|
82
|
+
* Used during initial context resolution and deep-link support.
|
|
83
|
+
* If not provided, the default GUID-based extractor is used.
|
|
84
|
+
*
|
|
85
|
+
* @param path - The URL path to inspect.
|
|
86
|
+
* @returns The extracted context ID, or `undefined` if none is found.
|
|
87
|
+
*/
|
|
43
88
|
extractContextIdFromPath?: (path: string) => string | undefined;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Generates a URL path that embeds the given context item's ID.
|
|
92
|
+
*
|
|
93
|
+
* Used by navigation integrations to update the browser URL when
|
|
94
|
+
* the context changes.
|
|
95
|
+
*
|
|
96
|
+
* @param context - The active context item.
|
|
97
|
+
* @param path - The current URL path.
|
|
98
|
+
* @returns The updated path, or `undefined` to leave it unchanged.
|
|
99
|
+
*/
|
|
44
100
|
generatePathFromContext?: (context: ContextItem, path: string) => string | undefined;
|
|
45
101
|
|
|
46
102
|
/**
|
|
47
|
-
*
|
|
103
|
+
* Transforms a user search string and the configured context type into
|
|
104
|
+
* the query parameters sent to the context API.
|
|
105
|
+
*
|
|
106
|
+
* Override this to customise how free-text searches are mapped to the
|
|
107
|
+
* backend query contract.
|
|
48
108
|
*/
|
|
49
109
|
contextParameterFn?: (args: {
|
|
50
110
|
search: string;
|
|
51
111
|
type: ContextModuleConfig['contextType'];
|
|
52
112
|
}) => string | QueryContextParameters;
|
|
53
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Custom context resolution strategy.
|
|
116
|
+
*
|
|
117
|
+
* Called with `this` bound to the {@link IContextProvider} when a context
|
|
118
|
+
* item fails validation and the caller requests resolution.
|
|
119
|
+
*
|
|
120
|
+
* @param item - The context item to resolve, or `null`.
|
|
121
|
+
* @returns An observable emitting the resolved context item.
|
|
122
|
+
*/
|
|
54
123
|
resolveContext?: (
|
|
55
124
|
this: IContextProvider,
|
|
56
125
|
item: ContextItem | null,
|
|
57
126
|
) => ReturnType<IContextProvider['resolveContext']>;
|
|
58
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Custom context validation strategy.
|
|
130
|
+
*
|
|
131
|
+
* Called with `this` bound to the {@link IContextProvider} to decide
|
|
132
|
+
* whether a candidate context item is acceptable.
|
|
133
|
+
*
|
|
134
|
+
* @param item - The context item to validate, or `null`.
|
|
135
|
+
* @returns `true` if the item is valid.
|
|
136
|
+
*/
|
|
59
137
|
validateContext?: (
|
|
60
138
|
this: IContextProvider,
|
|
61
139
|
item: ContextItem | null,
|
|
62
140
|
) => ReturnType<IContextProvider['validateContext']>;
|
|
63
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Resolves the initial context during module post-initialization.
|
|
144
|
+
*
|
|
145
|
+
* The default implementation tries to extract a context ID from the
|
|
146
|
+
* current navigation path, falling back to the parent provider's context.
|
|
147
|
+
*
|
|
148
|
+
* @param args - Module reference and instance map.
|
|
149
|
+
* @returns An observable input emitting the initial context item, or void.
|
|
150
|
+
*/
|
|
64
151
|
resolveInitialContext?: (args: {
|
|
65
152
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
153
|
ref?: AnyModuleInstance | any;
|
|
@@ -68,19 +155,54 @@ export interface ContextModuleConfig {
|
|
|
68
155
|
}) => ObservableInput<ContextItem | void>;
|
|
69
156
|
}
|
|
70
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Public configurator contract for the context module.
|
|
160
|
+
*
|
|
161
|
+
* Consumers call {@link addConfigBuilder} to register one or more
|
|
162
|
+
* {@link ContextConfigBuilderCallback} functions that will run during
|
|
163
|
+
* module initialization to populate the {@link ContextModuleConfig}.
|
|
164
|
+
*/
|
|
71
165
|
export interface IContextModuleConfigurator {
|
|
166
|
+
/**
|
|
167
|
+
* Registers a configuration callback that receives a {@link ContextConfigBuilder}.
|
|
168
|
+
*
|
|
169
|
+
* Multiple builders can be added; they execute sequentially and merge
|
|
170
|
+
* their results into a single {@link ContextModuleConfig}.
|
|
171
|
+
*
|
|
172
|
+
* @param init - Builder callback invoked during module initialization.
|
|
173
|
+
*/
|
|
72
174
|
addConfigBuilder: (init: ContextConfigBuilderCallback) => void;
|
|
73
175
|
}
|
|
74
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Default implementation of {@link IContextModuleConfigurator}.
|
|
179
|
+
*
|
|
180
|
+
* Collects {@link ContextConfigBuilderCallback} registrations and, when
|
|
181
|
+
* {@link createConfig} is called, runs them in order against a
|
|
182
|
+
* {@link ContextConfigBuilder} to produce the final {@link ContextModuleConfig}.
|
|
183
|
+
*
|
|
184
|
+
* If no custom client is configured, the configurator falls back to
|
|
185
|
+
* creating one from the {@link ServicesModule} API provider.
|
|
186
|
+
*/
|
|
75
187
|
export class ContextModuleConfigurator implements IContextModuleConfigurator {
|
|
188
|
+
/** Default cache TTL (in ms) for context query results. */
|
|
76
189
|
defaultExpireTime = 1 * 60 * 1000;
|
|
77
190
|
|
|
78
191
|
#configBuilders: Array<ContextConfigBuilderCallback> = [];
|
|
79
192
|
|
|
193
|
+
/** @inheritdoc */
|
|
80
194
|
addConfigBuilder(init: ContextConfigBuilderCallback): void {
|
|
81
195
|
this.#configBuilders.push(init);
|
|
82
196
|
}
|
|
83
197
|
|
|
198
|
+
/**
|
|
199
|
+
* Resolves the services API provider, preferring the local module
|
|
200
|
+
* instance and falling back to the parent module.
|
|
201
|
+
*
|
|
202
|
+
* @param init - Module initializer arguments.
|
|
203
|
+
* @returns The resolved API provider.
|
|
204
|
+
* @throws Error if no services module is available.
|
|
205
|
+
*/
|
|
84
206
|
protected async _getServiceProvider(
|
|
85
207
|
init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>,
|
|
86
208
|
): Promise<IApiProvider> {
|
|
@@ -94,6 +216,17 @@ export class ContextModuleConfigurator implements IContextModuleConfigurator {
|
|
|
94
216
|
return parentServiceModule;
|
|
95
217
|
}
|
|
96
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Runs all registered config builders and produces the final
|
|
221
|
+
* {@link ContextModuleConfig}.
|
|
222
|
+
*
|
|
223
|
+
* If no `resolveInitialContext` was set, the default path + parent
|
|
224
|
+
* resolver is used. If no `client` was set, one is created from the
|
|
225
|
+
* {@link ServicesModule} API provider.
|
|
226
|
+
*
|
|
227
|
+
* @param init - Module initializer arguments including dependency instances.
|
|
228
|
+
* @returns The fully resolved context module configuration.
|
|
229
|
+
*/
|
|
97
230
|
public async createConfig(
|
|
98
231
|
init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule, NavigationModule]>,
|
|
99
232
|
): Promise<ContextModuleConfig> {
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context module for the Fusion Framework.
|
|
3
|
+
*
|
|
4
|
+
* Provides context management for Fusion-based applications and portals,
|
|
5
|
+
* including setting, querying, validating, and resolving context items.
|
|
6
|
+
*
|
|
7
|
+
* Use {@link enableContext} to register the module in a configurator,
|
|
8
|
+
* then access the {@link IContextProvider} from the module instance
|
|
9
|
+
* to interact with context state.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
|
|
1
14
|
export {
|
|
2
15
|
ContextModuleConfigurator,
|
|
3
16
|
IContextModuleConfigurator,
|
package/src/module.ts
CHANGED
|
@@ -10,8 +10,19 @@ import { type IContextModuleConfigurator, ContextModuleConfigurator } from './co
|
|
|
10
10
|
import { type IContextProvider, ContextProvider } from './ContextProvider';
|
|
11
11
|
import type { ContextItem } from './types';
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Literal type identifying the context module within the Fusion Framework module system.
|
|
15
|
+
*
|
|
16
|
+
* Used as the key when registering or looking up the module in a `Modules` map.
|
|
17
|
+
*/
|
|
13
18
|
export type ContextModuleKey = 'context';
|
|
14
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Module registration key for the context module.
|
|
22
|
+
*
|
|
23
|
+
* Pass this value—or reference it as `contextModuleKey`—when you need to
|
|
24
|
+
* identify the context module by name at runtime (e.g., `hasModule(contextModuleKey)`).
|
|
25
|
+
*/
|
|
15
26
|
export const moduleKey: ContextModuleKey = 'context';
|
|
16
27
|
|
|
17
28
|
/**
|
package/src/types.ts
CHANGED
|
@@ -44,12 +44,34 @@ export type ContextItem<TType extends Record<string, unknown> = Record<string, u
|
|
|
44
44
|
};
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Describes the type classification of a {@link ContextItem}.
|
|
49
|
+
*
|
|
50
|
+
* Every context item carries a `type` that identifies what kind of
|
|
51
|
+
* entity it represents (e.g. `ProjectMaster`, `Facility`, `Contract`).
|
|
52
|
+
* The optional hierarchy fields indicate parent–child relationships
|
|
53
|
+
* between context types.
|
|
54
|
+
*/
|
|
47
55
|
export interface ContextItemType {
|
|
56
|
+
/** Unique identifier for the context type (e.g. `'ProjectMaster'`). */
|
|
48
57
|
id: string;
|
|
58
|
+
/** Whether this type is a child of another context type. */
|
|
49
59
|
isChildType?: boolean;
|
|
60
|
+
/** IDs of parent context types, when `isChildType` is `true`. */
|
|
50
61
|
parentTypeIds?: string[];
|
|
51
62
|
}
|
|
52
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Parameters for querying context items from the context API.
|
|
66
|
+
*
|
|
67
|
+
* Used by {@link ContextProvider.queryContext} and the underlying
|
|
68
|
+
* query client to search and filter context results.
|
|
69
|
+
*
|
|
70
|
+
* @property search - Free-text search term.
|
|
71
|
+
* @property filter - Optional structured filters.
|
|
72
|
+
* @property filter.type - Restrict results to specific context type IDs.
|
|
73
|
+
* @property filter.externalId - Filter by an external system identifier.
|
|
74
|
+
*/
|
|
53
75
|
export type QueryContextParameters = {
|
|
54
76
|
search?: string;
|
|
55
77
|
filter?: {
|
package/src/utils/index.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for context module configuration and initialization.
|
|
3
|
+
*
|
|
4
|
+
* - {@link enableContext} — register the context module on a configurator.
|
|
5
|
+
* - {@link resolveInitialContext} — default initial-context resolver (path → parent fallback).
|
|
6
|
+
* - {@link extractContextIdFromPath} — extract a GUID context ID from a URL path.
|
|
7
|
+
* - {@link resolveContextFromPath} — resolve a context item from a URL path.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
1
11
|
export { enableContext } from './enable-context';
|
|
2
12
|
export { resolveInitialContext } from './resolve-initial-context';
|
|
3
13
|
export { extractContextIdFromPath, resolveContextFromPath } from './resolve-context-from-path';
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '
|
|
2
|
+
export const version = '8.0.0';
|