@equinor/fusion-framework-module-context 8.0.0 → 8.0.2
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 +32 -0
- package/README.md +70 -0
- package/dist/esm/ContextConfigBuilder.js +17 -6
- package/dist/esm/ContextConfigBuilder.js.map +1 -1
- package/dist/esm/ContextProvider.js +71 -15
- package/dist/esm/ContextProvider.js.map +1 -1
- package/dist/esm/client/ContextClient.js +13 -3
- package/dist/esm/client/ContextClient.js.map +1 -1
- package/dist/esm/configurator.js +10 -11
- package/dist/esm/configurator.js.map +1 -1
- package/dist/esm/{errors.js → errors/FusionContextSearchError.js} +3 -1
- package/dist/esm/errors/FusionContextSearchError.js.map +1 -0
- package/dist/esm/errors/index.js +2 -0
- package/dist/esm/errors/index.js.map +1 -0
- package/dist/esm/get-context-selector.js +14 -0
- package/dist/esm/get-context-selector.js.map +1 -0
- package/dist/esm/parse-context-item.js +31 -0
- package/dist/esm/parse-context-item.js.map +1 -0
- package/dist/esm/query-context-selector.js +12 -0
- package/dist/esm/query-context-selector.js.map +1 -0
- package/dist/esm/related-context-selector.js +12 -0
- package/dist/esm/related-context-selector.js.map +1 -0
- package/dist/esm/utils/extract-context-id-from-path.js +35 -0
- package/dist/esm/utils/extract-context-id-from-path.js.map +1 -0
- package/dist/esm/utils/resolve-context-from-path.js +11 -22
- package/dist/esm/utils/resolve-context-from-path.js.map +1 -1
- package/dist/esm/utils/resolve-initial-context.js +11 -15
- 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/ContextConfigBuilder.d.ts +16 -1
- package/dist/types/ContextProvider.d.ts +45 -3
- package/dist/types/client/ContextClient.d.ts +8 -1
- package/dist/types/{errors.d.ts → errors/FusionContextSearchError.d.ts} +2 -0
- package/dist/types/errors/index.d.ts +1 -0
- package/dist/types/get-context-selector.d.ts +9 -0
- package/dist/types/parse-context-item.d.ts +8 -0
- package/dist/types/query-context-selector.d.ts +7 -0
- package/dist/types/related-context-selector.d.ts +7 -0
- package/dist/types/types.d.ts +1 -1
- package/dist/types/utils/extract-context-id-from-path.d.ts +22 -0
- package/dist/types/utils/resolve-context-from-path.d.ts +9 -16
- package/dist/types/utils/resolve-initial-context.d.ts +3 -6
- package/dist/types/version.d.ts +1 -1
- package/package.json +15 -11
- package/src/ContextConfigBuilder.ts +32 -7
- package/src/ContextProvider.ts +86 -21
- package/src/client/ContextClient.ts +13 -3
- package/src/configurator.ts +16 -12
- package/src/{errors.ts → errors/FusionContextSearchError.ts} +2 -0
- package/src/errors/index.ts +1 -0
- package/src/get-context-selector.ts +18 -0
- package/src/parse-context-item.ts +39 -0
- package/src/query-context-selector.ts +15 -0
- package/src/related-context-selector.ts +15 -0
- package/src/types.ts +1 -1
- package/src/utils/extract-context-id-from-path.ts +39 -0
- package/src/utils/resolve-context-from-path.ts +21 -28
- package/src/utils/resolve-initial-context.ts +11 -23
- package/src/version.ts +1 -1
- package/dist/esm/errors.js.map +0 -1
- package/dist/esm/selectors.js +0 -58
- package/dist/esm/selectors.js.map +0 -1
- package/dist/types/selectors.d.ts +0 -19
- package/src/selectors.ts +0 -70
|
@@ -35,7 +35,7 @@ export type ContextConfigBuilderCallback = <TDeps extends Array<AnyModule> = []>
|
|
|
35
35
|
* - The builder pattern allows chaining configuration methods for clarity and convenience.
|
|
36
36
|
* - The `requireInstance` method enables asynchronous retrieval of module instances by name.
|
|
37
37
|
*
|
|
38
|
-
* @todo - this should extend the BaseConfigBuilder
|
|
38
|
+
* @todo(#5120) - this should extend the BaseConfigBuilder
|
|
39
39
|
*
|
|
40
40
|
* @see ContextModuleConfig
|
|
41
41
|
* @see ModuleInitializerArgs
|
|
@@ -43,8 +43,23 @@ export type ContextConfigBuilderCallback = <TDeps extends Array<AnyModule> = []>
|
|
|
43
43
|
export declare class ContextConfigBuilder<TModules extends Array<AnyModule> = [], TInit extends ModuleInitializerArgs<any, any> = ModuleInitializerArgs<ContextModuleConfigurator, TModules>> {
|
|
44
44
|
#private;
|
|
45
45
|
config: Partial<ContextModuleConfig>;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new `ContextConfigBuilder`.
|
|
48
|
+
* @param init - Module initializer arguments used to resolve module instances.
|
|
49
|
+
* @param config - The partial context module config to build upon.
|
|
50
|
+
*/
|
|
46
51
|
constructor(init: TInit, config?: Partial<ContextModuleConfig>);
|
|
52
|
+
/**
|
|
53
|
+
* Requires a module instance by its registered key.
|
|
54
|
+
* @param module - The key of the module to resolve.
|
|
55
|
+
* @returns A promise that resolves to the requested module instance.
|
|
56
|
+
*/
|
|
47
57
|
requireInstance<TKey extends string = Extract<keyof Modules, string>>(module: TKey): Promise<ModuleType<Modules[TKey]>>;
|
|
58
|
+
/**
|
|
59
|
+
* Requires a module instance by name.
|
|
60
|
+
* @param module - The name of the module to resolve.
|
|
61
|
+
* @returns A promise that resolves to the requested module instance.
|
|
62
|
+
*/
|
|
48
63
|
requireInstance<T>(module: string): Promise<T>;
|
|
49
64
|
/**
|
|
50
65
|
* Sets the context type for the current configuration.
|
|
@@ -6,6 +6,7 @@ import type { ContextItem, QueryContextParameters, RelatedContextParameters } fr
|
|
|
6
6
|
import type { ModuleType } from '@equinor/fusion-framework-module';
|
|
7
7
|
import type { EventModule, FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
|
|
8
8
|
import Query from '@equinor/fusion-query';
|
|
9
|
+
import type { SemVer } from 'semver';
|
|
9
10
|
/**
|
|
10
11
|
* Interface representing a provider for managing and interacting with context items within an application.
|
|
11
12
|
*
|
|
@@ -257,6 +258,13 @@ export interface IContextProvider {
|
|
|
257
258
|
* @returns path for the context item
|
|
258
259
|
*/
|
|
259
260
|
generatePathFromContext?: (context: ContextItem, path: string) => string | undefined;
|
|
261
|
+
/**
|
|
262
|
+
* The version of the context provider.
|
|
263
|
+
*
|
|
264
|
+
* @remarks
|
|
265
|
+
* This property represents the version of the context provider, which can be a string or a SemVer object.
|
|
266
|
+
*/
|
|
267
|
+
readonly version: string | SemVer;
|
|
260
268
|
}
|
|
261
269
|
/**
|
|
262
270
|
* Provides context management functionality, including querying, setting, validating, and resolving context items.
|
|
@@ -290,12 +298,40 @@ export interface IContextProvider {
|
|
|
290
298
|
*/
|
|
291
299
|
export declare class ContextProvider extends BaseModuleProvider<ContextModuleConfig> implements IContextProvider {
|
|
292
300
|
#private;
|
|
301
|
+
/**
|
|
302
|
+
* The underlying context client used to resolve and hold the current context item.
|
|
303
|
+
* @returns The internal {@link ContextClient} instance.
|
|
304
|
+
*/
|
|
293
305
|
get contextClient(): ContextClient;
|
|
306
|
+
/**
|
|
307
|
+
* The query client used to search for context items.
|
|
308
|
+
* @returns The internal `Query` instance used by {@link queryContext}.
|
|
309
|
+
*/
|
|
294
310
|
get queryClient(): Query<ContextItem[], QueryContextParameters>;
|
|
311
|
+
/**
|
|
312
|
+
* Observable stream emitting the current context item.
|
|
313
|
+
* @returns Observable that emits the current `ContextItem`, `null`, or `undefined`.
|
|
314
|
+
*/
|
|
295
315
|
get currentContext$(): Observable<ContextItem | null | undefined>;
|
|
316
|
+
/**
|
|
317
|
+
* Snapshot of the current context item.
|
|
318
|
+
* @returns The current `ContextItem`, or `null`/`undefined` if not set.
|
|
319
|
+
*/
|
|
296
320
|
get currentContext(): ContextItem | undefined | null;
|
|
297
|
-
/**
|
|
321
|
+
/**
|
|
322
|
+
* Sets the current context item.
|
|
323
|
+
* @deprecated do not use, will be removed
|
|
324
|
+
* @param context - The context item to set as current. Must not be `undefined`.
|
|
325
|
+
* @throws Error if `context` is `undefined`.
|
|
326
|
+
*/
|
|
298
327
|
set currentContext(context: ContextItem | null | undefined);
|
|
328
|
+
/**
|
|
329
|
+
* Creates a new instance of `ContextProvider`.
|
|
330
|
+
* @param args - Constructor arguments.
|
|
331
|
+
* @param args.config - The context module configuration.
|
|
332
|
+
* @param args.event - Optional event module instance for dispatching context change events.
|
|
333
|
+
* @param args.parentContext - Optional parent context provider. Deprecated, use {@link connectParentContext}.
|
|
334
|
+
*/
|
|
299
335
|
constructor(args: {
|
|
300
336
|
config: ContextModuleConfig;
|
|
301
337
|
event?: ModuleType<EventModule>;
|
|
@@ -357,6 +393,11 @@ export declare class ContextProvider extends BaseModuleProvider<ContextModuleCon
|
|
|
357
393
|
* If the observable is subscribe, unsubscribing __WILL__ abort the task and remove it from queue
|
|
358
394
|
*
|
|
359
395
|
* @param context context item which would be queue to set as current
|
|
396
|
+
* @param opt Optional settings.
|
|
397
|
+
* @param opt.validate Whether to validate the context item before setting it.
|
|
398
|
+
* @param opt.resolve Whether to attempt to resolve the context item if validation fails.
|
|
399
|
+
* @template T The type of the context item, which extends `ContextItem<Record<string, unknown>>` or can be `null`.
|
|
400
|
+
* @returns An observable that emits the context item once the queued task completes.
|
|
360
401
|
*/
|
|
361
402
|
setCurrentContext<T extends ContextItem<Record<string, unknown>> | null>(context: T, opt?: {
|
|
362
403
|
validate?: boolean;
|
|
@@ -391,7 +432,7 @@ export declare class ContextProvider extends BaseModuleProvider<ContextModuleCon
|
|
|
391
432
|
* - Emit the context and complete the observable.
|
|
392
433
|
*
|
|
393
434
|
* @protected
|
|
394
|
-
* @
|
|
435
|
+
* @template T - The type of the context item, which extends `ContextItem<Record<string, unknown>>` or can be `null`.
|
|
395
436
|
* @param context - The new context to set.
|
|
396
437
|
* @param opt - Optional settings:
|
|
397
438
|
* - `validate`: Whether to validate the context before setting.
|
|
@@ -412,7 +453,7 @@ export declare class ContextProvider extends BaseModuleProvider<ContextModuleCon
|
|
|
412
453
|
*
|
|
413
454
|
* @see {@link setCurrentContext} for more details.
|
|
414
455
|
*
|
|
415
|
-
* @
|
|
456
|
+
* @template T - The type of the context item, which extends `ContextItem<Record<string, unknown>>` or can be `null`.
|
|
416
457
|
* @param context - The context item to set as the current context, or `null` to clear it.
|
|
417
458
|
* @param opt - Optional settings for context handling.
|
|
418
459
|
* @param opt.validate - If `true`, validates the context before setting it.
|
|
@@ -433,6 +474,7 @@ export declare class ContextProvider extends BaseModuleProvider<ContextModuleCon
|
|
|
433
474
|
*
|
|
434
475
|
* @param search - The search string to filter context items.
|
|
435
476
|
* @returns An Observable that emits an array of `ContextItem` objects matching the search criteria.
|
|
477
|
+
* @throws Re-throws the underlying cause of a `QueryClientError`, otherwise re-throws the original error.
|
|
436
478
|
*/
|
|
437
479
|
queryContext(search: string): Observable<Array<ContextItem>>;
|
|
438
480
|
/**
|
|
@@ -20,7 +20,7 @@ export type GetContextParameters = {
|
|
|
20
20
|
* @template ContextItem The type of the context item managed by the client.
|
|
21
21
|
* @extends Observable<ContextItem | null | undefined>
|
|
22
22
|
*
|
|
23
|
-
* @todo - should this have `undefined` as a valid value?
|
|
23
|
+
* @todo(#5116) - should this have `undefined` as a valid value?
|
|
24
24
|
*
|
|
25
25
|
* @example
|
|
26
26
|
* ```typescript
|
|
@@ -55,6 +55,10 @@ export declare class ContextClient extends Observable<ContextItem | null | undef
|
|
|
55
55
|
get client(): Query<ContextItem, {
|
|
56
56
|
id: string;
|
|
57
57
|
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new `ContextClient`.
|
|
60
|
+
* @param options - Query constructor options used to fetch a `ContextItem` by its ID.
|
|
61
|
+
*/
|
|
58
62
|
constructor(options: QueryCtorOptions<ContextItem, GetContextParameters>);
|
|
59
63
|
/**
|
|
60
64
|
* Sets the current context based on the provided identifier or context item.
|
|
@@ -85,6 +89,9 @@ export declare class ContextClient extends Observable<ContextItem | null | undef
|
|
|
85
89
|
resolveContextAsync(id: string, opt?: {
|
|
86
90
|
awaitResolve: boolean;
|
|
87
91
|
}): Promise<ContextItem>;
|
|
92
|
+
/**
|
|
93
|
+
* Disposes of the client, completing the internal current-context subject.
|
|
94
|
+
*/
|
|
88
95
|
dispose(): void;
|
|
89
96
|
}
|
|
90
97
|
export default ContextClient;
|
|
@@ -16,10 +16,12 @@ export declare class FusionContextSearchError extends Error {
|
|
|
16
16
|
#private;
|
|
17
17
|
/**
|
|
18
18
|
* The title of the error.
|
|
19
|
+
* @returns The error title.
|
|
19
20
|
*/
|
|
20
21
|
get title(): string;
|
|
21
22
|
/**
|
|
22
23
|
* The description of the error, if available.
|
|
24
|
+
* @returns The error description, or `undefined` if none was provided.
|
|
23
25
|
*/
|
|
24
26
|
get description(): string | undefined;
|
|
25
27
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FusionContextSearchError';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ContextItem } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Parse the response from the GetContext API into a context item.
|
|
4
|
+
* @param response The response object containing the context item.
|
|
5
|
+
* @returns A promise that resolves to the context item.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getContextSelector: (response: Response) => Promise<ContextItem>;
|
|
8
|
+
export { queryContextSelector } from './query-context-selector';
|
|
9
|
+
export { relatedContextSelector } from './related-context-selector';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ApiVersion, ApiContextEntity } from '@equinor/fusion-framework-module-services/context';
|
|
2
|
+
import type { ContextItem } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Parses an ApiContextEntity object into a ContextItem object.
|
|
5
|
+
* @param item The ApiContextEntity object to parse.
|
|
6
|
+
* @returns The parsed ContextItem object.
|
|
7
|
+
*/
|
|
8
|
+
export declare const parseContextItem: (item: ApiContextEntity<ApiVersion.v1>) => ContextItem;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ContextItem } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Parse the response from the QueryContext API into an array of context items.
|
|
4
|
+
* @param response The response object.
|
|
5
|
+
* @returns A promise that resolves to an array of context items.
|
|
6
|
+
*/
|
|
7
|
+
export declare const queryContextSelector: (response: Response) => Promise<ContextItem[]>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ContextItem } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Parse the response from the RelatedContext API into an array of context items.
|
|
4
|
+
* @param response The response object containing the related context items.
|
|
5
|
+
* @returns A promise that resolves to an array of ContextItem objects.
|
|
6
|
+
*/
|
|
7
|
+
export declare const relatedContextSelector: (response: Response) => Promise<ContextItem[]>;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* @property graphic - Optional graphical representation, either as a string or an object containing type and content.
|
|
17
17
|
* @property meta - Optional meta information, either as a string or an object containing type and content.
|
|
18
18
|
*
|
|
19
|
-
* @todo - convert to Zod schema for validation and type safety.
|
|
19
|
+
* @todo(#5122) - convert to Zod schema for validation and type safety.
|
|
20
20
|
*/
|
|
21
21
|
export type ContextItem<TType extends Record<string, unknown> = Record<string, unknown>> = {
|
|
22
22
|
id: string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Method will try to extract a context id from a path.
|
|
3
|
+
* The default matcher is a GUID pattern.
|
|
4
|
+
* Will iterate over the path and return the first match.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const path = '/apps/context/7fd97952-7fe6-409b-a6dc-292dbf0e50d7?dsadasdas#example';
|
|
9
|
+
* const contextId = extractContextIdFromPath(path); // '7fd97952-7fe6-409b-a6dc-292dbf0e50d7'
|
|
10
|
+
*
|
|
11
|
+
* // Custom matcher for numeric IDs
|
|
12
|
+
* extractContextIdFromPath('/projects/42/details', /^\d+$/); // '42'
|
|
13
|
+
*
|
|
14
|
+
* // No match
|
|
15
|
+
* extractContextIdFromPath('/apps/my-app/settings'); // undefined
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param path string - the path to extract the context id from
|
|
19
|
+
* @param matcher RegExp - the pattern to match against
|
|
20
|
+
* @returns string | undefined - the context id or undefined
|
|
21
|
+
*/
|
|
22
|
+
export declare const extractContextIdFromPath: (path: string, matcher?: RegExp) => string | undefined;
|
|
@@ -2,6 +2,7 @@ import { type Observable } from 'rxjs';
|
|
|
2
2
|
import type { ModuleType } from '@equinor/fusion-framework-module';
|
|
3
3
|
import type { ContextModule } from '../module';
|
|
4
4
|
import type { ContextItem } from '../types';
|
|
5
|
+
export { extractContextIdFromPath } from './extract-context-id-from-path';
|
|
5
6
|
/**
|
|
6
7
|
* Arguments for resolving a context from a path.
|
|
7
8
|
*/
|
|
@@ -19,22 +20,6 @@ export type ContextPathResolveArgs = {
|
|
|
19
20
|
*/
|
|
20
21
|
validate?: (contextId: string) => boolean;
|
|
21
22
|
};
|
|
22
|
-
/**
|
|
23
|
-
* Method will try to extract a context id from a path.
|
|
24
|
-
* The default matcher is a GUID pattern.
|
|
25
|
-
* Will iterate over the path and return the first match.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```ts
|
|
29
|
-
* const path = '/apps/context/7fd97952-7fe6-409b-a6dc-292dbf0e50d7?dsadasdas#example';
|
|
30
|
-
* const contextId = extractContextIdFromPath(path); // '7fd97952-7fe6-409b-a6dc-292dbf0e50d7'
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* @param path string - the path to extract the context id from
|
|
34
|
-
* @param matcher RegExp - the pattern to match against
|
|
35
|
-
* @returns string | undefined - the context id or undefined
|
|
36
|
-
*/
|
|
37
|
-
export declare const extractContextIdFromPath: (path: string, matcher?: RegExp) => string | undefined;
|
|
38
23
|
/**
|
|
39
24
|
* Method will try to resolve a context from a path.
|
|
40
25
|
* The method will return a function that takes a path and returns an observable of the resolved context.
|
|
@@ -54,6 +39,10 @@ export declare const extractContextIdFromPath: (path: string, matcher?: RegExp)
|
|
|
54
39
|
*
|
|
55
40
|
* @param context The context module.
|
|
56
41
|
* @returns A function that takes a path and returns an Observable of the resolved context item.
|
|
42
|
+
* @deprecated Replaced by the context-navigation plugin which resolves
|
|
43
|
+
* initial context from the URL via adapter `decode()` during module initialization.
|
|
44
|
+
* Portal-level code should use `enableContextNavigation` which handles
|
|
45
|
+
* URL-to-context resolution automatically. Will be removed in a future major version.
|
|
57
46
|
*/
|
|
58
47
|
export declare function resolveContextFromPath(context: ModuleType<ContextModule>): (path: string) => Observable<ContextItem>;
|
|
59
48
|
/**
|
|
@@ -74,6 +63,10 @@ export declare function resolveContextFromPath(context: ModuleType<ContextModule
|
|
|
74
63
|
* @param context The context module.
|
|
75
64
|
* @param args The arguments for resolving the path.
|
|
76
65
|
* @returns A function that takes a path and returns an Observable of the resolved context item.
|
|
66
|
+
* @deprecated Replaced by the context-navigation plugin which resolves
|
|
67
|
+
* initial context from the URL via adapter `decode()` during module initialization.
|
|
68
|
+
* Portal-level code should use `enableContextNavigation` which handles
|
|
69
|
+
* URL-to-context resolution automatically. Will be removed in a future major version.
|
|
77
70
|
*/
|
|
78
71
|
export declare function resolveContextFromPath(context: ModuleType<ContextModule>, args?: ContextPathResolveArgs): (path: string) => Observable<ContextItem>;
|
|
79
72
|
export default resolveContextFromPath;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ContextModuleConfig } from '../configurator';
|
|
2
|
-
import { type ContextPathResolveArgs } from './resolve-context-from-path';
|
|
3
2
|
/**
|
|
4
3
|
* Resolves the initial context from the parent module.
|
|
5
4
|
*
|
|
@@ -10,12 +9,10 @@ export declare const resolveContextFromParent: ContextModuleConfig['resolveIniti
|
|
|
10
9
|
/**
|
|
11
10
|
* Resolves the initial context for a Fusion Framework context module.
|
|
12
11
|
*
|
|
13
|
-
*
|
|
12
|
+
* Attempts to resolve the initial context from the parent context provider.
|
|
13
|
+
* URL-based resolution is handled by the context-navigation plugin.
|
|
14
14
|
*
|
|
15
|
-
* @param options - Optional configuration for resolving the context path.
|
|
16
15
|
* @returns A function that accepts the module's reference and modules, and returns an Observable of the resolved initial context.
|
|
17
16
|
*/
|
|
18
|
-
export declare const resolveInitialContext: (
|
|
19
|
-
path?: ContextPathResolveArgs;
|
|
20
|
-
}) => Required<ContextModuleConfig>["resolveInitialContext"];
|
|
17
|
+
export declare const resolveInitialContext: () => Required<ContextModuleConfig>['resolveInitialContext'];
|
|
21
18
|
export default resolveInitialContext;
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "8.0.
|
|
1
|
+
export declare const version = "8.0.2";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-module-context",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"types": "./dist/types/index.d.ts"
|
|
10
10
|
},
|
|
11
11
|
"./errors.js": {
|
|
12
|
-
"import": "./dist/esm/errors.js",
|
|
13
|
-
"types": "./dist/types/errors.d.ts"
|
|
12
|
+
"import": "./dist/esm/errors/index.js",
|
|
13
|
+
"types": "./dist/types/errors/index.d.ts"
|
|
14
14
|
},
|
|
15
15
|
"./utils": {
|
|
16
16
|
"import": "./dist/esm/utils/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dist/types/index.d.ts"
|
|
26
26
|
],
|
|
27
27
|
"errors.js": [
|
|
28
|
-
"dist/types/errors.d.ts"
|
|
28
|
+
"dist/types/errors/index.d.ts"
|
|
29
29
|
],
|
|
30
30
|
"utils": [
|
|
31
31
|
"dist/types/utils/index.d.ts"
|
|
@@ -45,19 +45,23 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"fast-deep-equal": "^3.1.3",
|
|
48
|
-
"@equinor/fusion-query": "^7.0.
|
|
48
|
+
"@equinor/fusion-query": "^7.0.3"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"rxjs": "^7.8.1",
|
|
52
|
-
"typescript": "^
|
|
53
|
-
"@
|
|
54
|
-
"
|
|
55
|
-
"@equinor/fusion-framework-module-
|
|
56
|
-
"@equinor/fusion-framework-module-navigation": "^7.0.
|
|
52
|
+
"typescript": "^7.0.2",
|
|
53
|
+
"@types/semver": "^7.0.0",
|
|
54
|
+
"semver": "^7.0.0",
|
|
55
|
+
"@equinor/fusion-framework-module-event": "^6.0.1",
|
|
56
|
+
"@equinor/fusion-framework-module-navigation": "^7.0.7",
|
|
57
|
+
"@equinor/fusion-framework-module": "^6.1.2",
|
|
58
|
+
"@equinor/fusion-framework-module-services": "^8.0.3"
|
|
57
59
|
},
|
|
58
60
|
"peerDependencies": {
|
|
61
|
+
"@types/semver": "^7.0.0",
|
|
62
|
+
"semver": "^7.0.0",
|
|
59
63
|
"rxjs": "^7.0.0",
|
|
60
|
-
"@equinor/fusion-framework-module": "^6.
|
|
64
|
+
"@equinor/fusion-framework-module": "^6.1.2"
|
|
61
65
|
},
|
|
62
66
|
"scripts": {
|
|
63
67
|
"build": "tsc -b"
|
|
@@ -52,19 +52,25 @@ export type ContextConfigBuilderCallback = <TDeps extends Array<AnyModule> = []>
|
|
|
52
52
|
* - The builder pattern allows chaining configuration methods for clarity and convenience.
|
|
53
53
|
* - The `requireInstance` method enables asynchronous retrieval of module instances by name.
|
|
54
54
|
*
|
|
55
|
-
* @todo - this should extend the BaseConfigBuilder
|
|
55
|
+
* @todo(#5120) - this should extend the BaseConfigBuilder
|
|
56
56
|
*
|
|
57
57
|
* @see ContextModuleConfig
|
|
58
58
|
* @see ModuleInitializerArgs
|
|
59
59
|
*/
|
|
60
60
|
export class ContextConfigBuilder<
|
|
61
61
|
TModules extends Array<AnyModule> = [],
|
|
62
|
+
// biome-ignore lint/suspicious/noExplicitAny: `ModuleInitializerArgs<any, any>` widens the constraint to accept initializer args for any configurator/module set \u2014 `unknown` breaks assignability of the concrete default type argument
|
|
62
63
|
TInit extends ModuleInitializerArgs<any, any> = ModuleInitializerArgs<
|
|
63
64
|
ContextModuleConfigurator,
|
|
64
65
|
TModules
|
|
65
66
|
>,
|
|
66
67
|
> {
|
|
67
68
|
#init: TInit;
|
|
69
|
+
/**
|
|
70
|
+
* Creates a new `ContextConfigBuilder`.
|
|
71
|
+
* @param init - Module initializer arguments used to resolve module instances.
|
|
72
|
+
* @param config - The partial context module config to build upon.
|
|
73
|
+
*/
|
|
68
74
|
constructor(
|
|
69
75
|
init: TInit,
|
|
70
76
|
public config: Partial<ContextModuleConfig> = {},
|
|
@@ -72,13 +78,31 @@ export class ContextConfigBuilder<
|
|
|
72
78
|
this.#init = init;
|
|
73
79
|
}
|
|
74
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Requires a module instance by its registered key.
|
|
83
|
+
* @param module - The key of the module to resolve.
|
|
84
|
+
* @returns A promise that resolves to the requested module instance.
|
|
85
|
+
*/
|
|
75
86
|
requireInstance<TKey extends string = Extract<keyof Modules, string>>(
|
|
76
87
|
module: TKey,
|
|
77
88
|
): Promise<ModuleType<Modules[TKey]>>;
|
|
78
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Requires a module instance by name.
|
|
92
|
+
* @param module - The name of the module to resolve.
|
|
93
|
+
* @returns A promise that resolves to the requested module instance.
|
|
94
|
+
*/
|
|
79
95
|
requireInstance<T>(module: string): Promise<T>;
|
|
80
96
|
|
|
81
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Requires a module instance by key or name.
|
|
99
|
+
* @param module - The key or name of the module to resolve.
|
|
100
|
+
* @returns A promise that resolves to the requested module instance.
|
|
101
|
+
*/
|
|
102
|
+
requireInstance(
|
|
103
|
+
module: string,
|
|
104
|
+
// biome-ignore lint/suspicious/noExplicitAny: implementation signature must satisfy both overloads above (`Promise<ModuleType<...>>` and `Promise<T>`); `unknown` is not assignable to the generic `Promise<T>` overload
|
|
105
|
+
): Promise<any> {
|
|
82
106
|
return this.#init.requireInstance(module);
|
|
83
107
|
}
|
|
84
108
|
|
|
@@ -192,7 +216,7 @@ export class ContextConfigBuilder<
|
|
|
192
216
|
},
|
|
193
217
|
expire = 1 * 60 * 1000,
|
|
194
218
|
): void {
|
|
195
|
-
|
|
219
|
+
const clientConfig: ContextModuleConfig['client'] = {
|
|
196
220
|
get:
|
|
197
221
|
typeof client.get === 'function'
|
|
198
222
|
? {
|
|
@@ -206,7 +230,7 @@ export class ContextConfigBuilder<
|
|
|
206
230
|
query:
|
|
207
231
|
typeof client.query === 'function'
|
|
208
232
|
? {
|
|
209
|
-
// TODO - might cast to checksum
|
|
233
|
+
// TODO(#5118) - might cast to checksum
|
|
210
234
|
key: (args) => JSON.stringify(args),
|
|
211
235
|
client: {
|
|
212
236
|
fn: client.query,
|
|
@@ -215,12 +239,13 @@ export class ContextConfigBuilder<
|
|
|
215
239
|
}
|
|
216
240
|
: client.query,
|
|
217
241
|
};
|
|
242
|
+
this.config.client = clientConfig;
|
|
243
|
+
// only override the related-context client config if one was provided
|
|
218
244
|
if (client.related) {
|
|
219
|
-
|
|
220
|
-
this.config.client!.related =
|
|
245
|
+
clientConfig.related =
|
|
221
246
|
typeof client.related === 'function'
|
|
222
247
|
? {
|
|
223
|
-
// TODO - might cast to checksum
|
|
248
|
+
// TODO(#5118) - might cast to checksum
|
|
224
249
|
key: (args) => JSON.stringify(args),
|
|
225
250
|
client: {
|
|
226
251
|
fn: client.related,
|