@equinor/fusion-framework-module-context 8.0.1 → 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 +17 -0
- package/README.md +70 -0
- package/dist/esm/ContextProvider.js +2 -2
- package/dist/esm/ContextProvider.js.map +1 -1
- package/dist/esm/configurator.js +1 -6
- package/dist/esm/configurator.js.map +1 -1
- package/dist/esm/utils/extract-context-id-from-path.js +11 -1
- package/dist/esm/utils/extract-context-id-from-path.js.map +1 -1
- package/dist/esm/utils/resolve-context-from-path.js.map +1 -1
- package/dist/esm/utils/resolve-initial-context.js +9 -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/ContextProvider.d.ts +8 -0
- package/dist/types/utils/extract-context-id-from-path.d.ts +6 -0
- package/dist/types/utils/resolve-context-from-path.d.ts +8 -0
- package/dist/types/utils/resolve-initial-context.d.ts +3 -6
- package/dist/types/version.d.ts +1 -1
- package/package.json +11 -7
- package/src/ContextProvider.ts +10 -2
- package/src/configurator.ts +1 -6
- package/src/utils/extract-context-id-from-path.ts +9 -0
- package/src/utils/resolve-context-from-path.ts +8 -0
- package/src/utils/resolve-initial-context.ts +9 -23
- package/src/version.ts +1 -1
|
@@ -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.
|
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
* ```ts
|
|
8
8
|
* const path = '/apps/context/7fd97952-7fe6-409b-a6dc-292dbf0e50d7?dsadasdas#example';
|
|
9
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
|
|
10
16
|
* ```
|
|
11
17
|
*
|
|
12
18
|
* @param path string - the path to extract the context id from
|
|
@@ -39,6 +39,10 @@ export type ContextPathResolveArgs = {
|
|
|
39
39
|
*
|
|
40
40
|
* @param context The context module.
|
|
41
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.
|
|
42
46
|
*/
|
|
43
47
|
export declare function resolveContextFromPath(context: ModuleType<ContextModule>): (path: string) => Observable<ContextItem>;
|
|
44
48
|
/**
|
|
@@ -59,6 +63,10 @@ export declare function resolveContextFromPath(context: ModuleType<ContextModule
|
|
|
59
63
|
* @param context The context module.
|
|
60
64
|
* @param args The arguments for resolving the path.
|
|
61
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.
|
|
62
70
|
*/
|
|
63
71
|
export declare function resolveContextFromPath(context: ModuleType<ContextModule>, args?: ContextPathResolveArgs): (path: string) => Observable<ContextItem>;
|
|
64
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": {
|
|
@@ -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
52
|
"typescript": "^7.0.2",
|
|
53
|
-
"@
|
|
54
|
-
"
|
|
55
|
-
"@equinor/fusion-framework-module-
|
|
56
|
-
"@equinor/fusion-framework-module-
|
|
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.1.
|
|
64
|
+
"@equinor/fusion-framework-module": "^6.1.2"
|
|
61
65
|
},
|
|
62
66
|
"scripts": {
|
|
63
67
|
"build": "tsc -b"
|
package/src/ContextProvider.ts
CHANGED
|
@@ -24,6 +24,7 @@ import type {
|
|
|
24
24
|
FrameworkEventInit,
|
|
25
25
|
} from '@equinor/fusion-framework-module-event';
|
|
26
26
|
import Query from '@equinor/fusion-query';
|
|
27
|
+
import type { SemVer } from 'semver';
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Interface representing a provider for managing and interacting with context items within an application.
|
|
@@ -296,6 +297,13 @@ export interface IContextProvider {
|
|
|
296
297
|
* @returns path for the context item
|
|
297
298
|
*/
|
|
298
299
|
generatePathFromContext?: (context: ContextItem, path: string) => string | undefined;
|
|
300
|
+
/**
|
|
301
|
+
* The version of the context provider.
|
|
302
|
+
*
|
|
303
|
+
* @remarks
|
|
304
|
+
* This property represents the version of the context provider, which can be a string or a SemVer object.
|
|
305
|
+
*/
|
|
306
|
+
readonly version: string | SemVer;
|
|
299
307
|
}
|
|
300
308
|
|
|
301
309
|
/**
|
|
@@ -435,12 +443,12 @@ export class ContextProvider
|
|
|
435
443
|
|
|
436
444
|
// override extractContextIdFromPath if configured
|
|
437
445
|
if (config.extractContextIdFromPath) {
|
|
438
|
-
// @ts-expect-error
|
|
446
|
+
// @ts-expect-error - this is to avoid breaking change, the signature will be updated in future major release
|
|
439
447
|
this.extractContextIdFromPath = config.extractContextIdFromPath;
|
|
440
448
|
}
|
|
441
449
|
// override generatePathFromContext if configured
|
|
442
450
|
if (config.generatePathFromContext) {
|
|
443
|
-
// @ts-expect-error
|
|
451
|
+
// @ts-expect-error - this is to avoid breaking change, the signature will be updated in future major release
|
|
444
452
|
this.generatePathFromContext = config.generatePathFromContext;
|
|
445
453
|
}
|
|
446
454
|
|
package/src/configurator.ts
CHANGED
|
@@ -249,12 +249,7 @@ export class ContextModuleConfigurator implements IContextModuleConfigurator {
|
|
|
249
249
|
Promise.resolve({} as Partial<ContextModuleConfig>),
|
|
250
250
|
);
|
|
251
251
|
|
|
252
|
-
config.resolveInitialContext ??= resolveInitialContext(
|
|
253
|
-
path: {
|
|
254
|
-
extract: config.extractContextIdFromPath,
|
|
255
|
-
validate: config.extractContextIdFromPath ? () => true : undefined,
|
|
256
|
-
},
|
|
257
|
-
});
|
|
252
|
+
config.resolveInitialContext ??= resolveInitialContext();
|
|
258
253
|
|
|
259
254
|
// TODO(#5119) - make less lazy
|
|
260
255
|
config.client ??= await (async (): Promise<ContextModuleConfig['client']> => {
|
|
@@ -11,6 +11,12 @@ const matchGUID =
|
|
|
11
11
|
* ```ts
|
|
12
12
|
* const path = '/apps/context/7fd97952-7fe6-409b-a6dc-292dbf0e50d7?dsadasdas#example';
|
|
13
13
|
* const contextId = extractContextIdFromPath(path); // '7fd97952-7fe6-409b-a6dc-292dbf0e50d7'
|
|
14
|
+
*
|
|
15
|
+
* // Custom matcher for numeric IDs
|
|
16
|
+
* extractContextIdFromPath('/projects/42/details', /^\d+$/); // '42'
|
|
17
|
+
*
|
|
18
|
+
* // No match
|
|
19
|
+
* extractContextIdFromPath('/apps/my-app/settings'); // undefined
|
|
14
20
|
* ```
|
|
15
21
|
*
|
|
16
22
|
* @param path string - the path to extract the context id from
|
|
@@ -21,7 +27,10 @@ export const extractContextIdFromPath = (
|
|
|
21
27
|
path: string,
|
|
22
28
|
matcher: RegExp = matchGUID,
|
|
23
29
|
): string | undefined =>
|
|
30
|
+
//
|
|
24
31
|
path
|
|
32
|
+
// remove query-string and hash fragments before segment matching
|
|
33
|
+
.split(/[?#]/)[0]
|
|
25
34
|
// remove leading slashes
|
|
26
35
|
.replace(/^\/+/, '')
|
|
27
36
|
// split path by slashes
|
|
@@ -51,6 +51,10 @@ const validateContextId = (contextId: string): boolean => !!contextId.match(matc
|
|
|
51
51
|
*
|
|
52
52
|
* @param context The context module.
|
|
53
53
|
* @returns A function that takes a path and returns an Observable of the resolved context item.
|
|
54
|
+
* @deprecated Replaced by the context-navigation plugin which resolves
|
|
55
|
+
* initial context from the URL via adapter `decode()` during module initialization.
|
|
56
|
+
* Portal-level code should use `enableContextNavigation` which handles
|
|
57
|
+
* URL-to-context resolution automatically. Will be removed in a future major version.
|
|
54
58
|
*/
|
|
55
59
|
export function resolveContextFromPath(
|
|
56
60
|
context: ModuleType<ContextModule>,
|
|
@@ -74,6 +78,10 @@ export function resolveContextFromPath(
|
|
|
74
78
|
* @param context The context module.
|
|
75
79
|
* @param args The arguments for resolving the path.
|
|
76
80
|
* @returns A function that takes a path and returns an Observable of the resolved context item.
|
|
81
|
+
* @deprecated Replaced by the context-navigation plugin which resolves
|
|
82
|
+
* initial context from the URL via adapter `decode()` during module initialization.
|
|
83
|
+
* Portal-level code should use `enableContextNavigation` which handles
|
|
84
|
+
* URL-to-context resolution automatically. Will be removed in a future major version.
|
|
77
85
|
*/
|
|
78
86
|
export function resolveContextFromPath(
|
|
79
87
|
context: ModuleType<ContextModule>,
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import type { ModulesInstance } from '@equinor/fusion-framework-module';
|
|
2
2
|
import type { ContextModule } from '../module';
|
|
3
3
|
import type { ContextModuleConfig } from '../configurator';
|
|
4
|
-
import { concat, EMPTY,
|
|
5
|
-
|
|
6
|
-
import { type ContextPathResolveArgs, resolveContextFromPath } from './resolve-context-from-path';
|
|
7
|
-
import type { NavigationModule } from '@equinor/fusion-framework-module-navigation';
|
|
4
|
+
import { concat, EMPTY, of, take } from 'rxjs';
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* Resolves the initial context from the parent module.
|
|
@@ -14,9 +11,9 @@ import type { NavigationModule } from '@equinor/fusion-framework-module-navigati
|
|
|
14
11
|
*/
|
|
15
12
|
export const resolveContextFromParent: ContextModuleConfig['resolveInitialContext'] = ({ ref }) => {
|
|
16
13
|
const parentContext = (ref as ModulesInstance<[ContextModule]>)?.context;
|
|
17
|
-
// check if the parent has context module
|
|
18
14
|
if (!parentContext) {
|
|
19
|
-
|
|
15
|
+
// No parent context available — either portal level or parent lacks context module.
|
|
16
|
+
return EMPTY;
|
|
20
17
|
}
|
|
21
18
|
// return the current context from the parent or empty if the parent does not have a context
|
|
22
19
|
return parentContext.currentContext ? of(parentContext.currentContext) : EMPTY;
|
|
@@ -25,30 +22,19 @@ export const resolveContextFromParent: ContextModuleConfig['resolveInitialContex
|
|
|
25
22
|
/**
|
|
26
23
|
* Resolves the initial context for a Fusion Framework context module.
|
|
27
24
|
*
|
|
28
|
-
*
|
|
25
|
+
* Attempts to resolve the initial context from the parent context provider.
|
|
26
|
+
* URL-based resolution is handled by the context-navigation plugin.
|
|
29
27
|
*
|
|
30
|
-
* @param options - Optional configuration for resolving the context path.
|
|
31
28
|
* @returns A function that accepts the module's reference and modules, and returns an Observable of the resolved initial context.
|
|
32
29
|
*/
|
|
33
30
|
// Deliberately co-located with resolveContextFromParent, which it composes with
|
|
34
31
|
// fusion-lint-disable-next-line single-export-per-file
|
|
35
32
|
export const resolveInitialContext =
|
|
36
|
-
(
|
|
37
|
-
path?: ContextPathResolveArgs;
|
|
38
|
-
}): Required<ContextModuleConfig>['resolveInitialContext'] =>
|
|
33
|
+
(): Required<ContextModuleConfig>['resolveInitialContext'] =>
|
|
39
34
|
({ ref, modules }) => {
|
|
40
|
-
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
// use the path from the navigation module, or the path from the parent navigation module
|
|
44
|
-
const pathname =
|
|
45
|
-
navigation?.path.pathname ??
|
|
46
|
-
(ref as Partial<ModulesInstance<[NavigationModule]>>).navigation?.path.pathname;
|
|
47
|
-
// try to resolve the context from the path, and if that fails, try to resolve the context from the parent
|
|
48
|
-
return concat(
|
|
49
|
-
pathname ? pathResolver(pathname) : EMPTY,
|
|
50
|
-
resolveContextFromParent({ ref, modules }),
|
|
51
|
-
).pipe(first());
|
|
35
|
+
// Resolve from parent context if available.
|
|
36
|
+
// URL-based resolution is handled by the context-navigation plugin.
|
|
37
|
+
return concat(resolveContextFromParent({ ref, modules })).pipe(take(1));
|
|
52
38
|
};
|
|
53
39
|
|
|
54
40
|
export default resolveInitialContext;
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '8.0.
|
|
2
|
+
export const version = '8.0.2';
|