@equinor/fusion-framework-module-context 8.0.1 → 8.0.3
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 +23 -0
- package/README.md +70 -0
- package/dist/esm/ContextProvider.js +2 -2
- package/dist/esm/ContextProvider.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 +3 -2
- 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/version.d.ts +1 -1
- package/package.json +11 -7
- package/src/ContextProvider.ts +10 -2
- 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 +4 -3
- 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;
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "8.0.
|
|
1
|
+
export declare const version = "8.0.3";
|
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.3",
|
|
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.1.0"
|
|
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
|
|
|
@@ -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>,
|
|
@@ -2,8 +2,7 @@ import type { ModulesInstance } from '@equinor/fusion-framework-module';
|
|
|
2
2
|
import type { ContextModule } from '../module';
|
|
3
3
|
import type { ContextModuleConfig } from '../configurator';
|
|
4
4
|
import { concat, EMPTY, first, of } from 'rxjs';
|
|
5
|
-
|
|
6
|
-
import { type ContextPathResolveArgs, resolveContextFromPath } from './resolve-context-from-path';
|
|
5
|
+
import resolveContextFromPath, { type ContextPathResolveArgs } from './resolve-context-from-path';
|
|
7
6
|
import type { NavigationModule } from '@equinor/fusion-framework-module-navigation';
|
|
8
7
|
|
|
9
8
|
/**
|
|
@@ -16,7 +15,8 @@ export const resolveContextFromParent: ContextModuleConfig['resolveInitialContex
|
|
|
16
15
|
const parentContext = (ref as ModulesInstance<[ContextModule]>)?.context;
|
|
17
16
|
// check if the parent has context module
|
|
18
17
|
if (!parentContext) {
|
|
19
|
-
|
|
18
|
+
// No parent context available — either portal level or parent lacks context module.
|
|
19
|
+
return EMPTY;
|
|
20
20
|
}
|
|
21
21
|
// return the current context from the parent or empty if the parent does not have a context
|
|
22
22
|
return parentContext.currentContext ? of(parentContext.currentContext) : EMPTY;
|
|
@@ -30,6 +30,7 @@ export const resolveContextFromParent: ContextModuleConfig['resolveInitialContex
|
|
|
30
30
|
* @param options - Optional configuration for resolving the context path.
|
|
31
31
|
* @returns A function that accepts the module's reference and modules, and returns an Observable of the resolved initial context.
|
|
32
32
|
*/
|
|
33
|
+
|
|
33
34
|
// Deliberately co-located with resolveContextFromParent, which it composes with
|
|
34
35
|
// fusion-lint-disable-next-line single-export-per-file
|
|
35
36
|
export const 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.3';
|