@equinor/fusion-framework-module-context 9.0.0-next.0 → 9.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.
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +13 -10
- package/CHANGELOG.md +0 -1095
- package/docs/data-model.md +0 -134
- package/docs/lifecycle.md +0 -163
- package/docs/recipes.md +0 -89
- package/src/ContextModuleConfig.ts +0 -147
- package/src/ContextModuleConfigurator.interface.ts +0 -145
- package/src/ContextModuleConfigurator.ts +0 -295
- package/src/ContextProvider.ts +0 -1158
- package/src/__tests__/ContextModuleConfigurator.test.ts +0 -412
- package/src/__tests__/mock/context-mock.test.ts +0 -137
- package/src/__tests__/mock/create-context-item-factory.test.ts +0 -60
- package/src/__tests__/mock/create-context-items.test.ts +0 -58
- package/src/client/ContextClient.ts +0 -149
- package/src/errors/FusionContextSearchError.ts +0 -56
- package/src/errors/index.ts +0 -1
- package/src/index.ts +0 -29
- package/src/mock/ContextMockConfigurator.ts +0 -244
- package/src/mock/fixtures/create-context-item-factory.ts +0 -62
- package/src/mock/fixtures/create-context-items.ts +0 -80
- package/src/mock/fixtures/index.ts +0 -28
- package/src/mock/fixtures/string-to-seed.ts +0 -18
- package/src/mock/index.ts +0 -33
- package/src/mock/module.ts +0 -54
- package/src/module.ts +0 -178
- package/src/selectors/get-context-selector.ts +0 -14
- package/src/selectors/index.ts +0 -12
- package/src/selectors/query-context-selector.ts +0 -15
- package/src/selectors/related-context-selector.ts +0 -15
- package/src/types.ts +0 -98
- package/src/utils/enable-context.ts +0 -40
- package/src/utils/extract-context-id-from-path.ts +0 -39
- package/src/utils/index.ts +0 -15
- package/src/utils/parse-context-item.ts +0 -39
- package/src/utils/resolve-context-from-path.ts +0 -118
- package/src/utils/resolve-initial-context.ts +0 -58
- package/src/version.ts +0 -2
- package/tsconfig.json +0 -33
- package/vitest.config.ts +0 -11
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { EMPTY, type Observable } from 'rxjs';
|
|
2
|
-
|
|
3
|
-
import type { ModuleType } from '@equinor/fusion-framework-module';
|
|
4
|
-
|
|
5
|
-
import type { ContextModule } from '../module';
|
|
6
|
-
import type { ContextItem } from '../types';
|
|
7
|
-
import { extractContextIdFromPath } from './extract-context-id-from-path';
|
|
8
|
-
|
|
9
|
-
export { extractContextIdFromPath } from './extract-context-id-from-path';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Arguments for resolving a context from a path.
|
|
13
|
-
*/
|
|
14
|
-
export type ContextPathResolveArgs = {
|
|
15
|
-
/**
|
|
16
|
-
* Callback to extract a context id from a path.
|
|
17
|
-
* @param path string - the path to extract the context id from
|
|
18
|
-
* @returns string | undefined - the context id or undefined
|
|
19
|
-
*/
|
|
20
|
-
extract?: (path: string) => string | undefined;
|
|
21
|
-
/**
|
|
22
|
-
* Callback to validate a context id.
|
|
23
|
-
* @param contextId string - the context id to validate
|
|
24
|
-
* @returns boolean - true if the context id is valid
|
|
25
|
-
*/
|
|
26
|
-
validate?: (contextId: string) => boolean;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// GUID pattern, used as the default context id validator
|
|
30
|
-
const matchGUID =
|
|
31
|
-
/^(?:(?:[0-9a-fA-F]){8}-(?:[0-9a-fA-F]){4}-(?:[0-9a-fA-F]){4}-(?:[0-9a-fA-F]){4}-(?:[0-9a-fA-F]){12})$/;
|
|
32
|
-
|
|
33
|
-
const validateContextId = (contextId: string): boolean => !!contextId.match(matchGUID);
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Method will try to resolve a context from a path.
|
|
37
|
-
* The method will return a function that takes a path and returns an observable of the resolved context.
|
|
38
|
-
* The method will use the context module to resolve the context.
|
|
39
|
-
* The method will use the extract and validate methods from the args to extract and validate the context id.
|
|
40
|
-
* If the context id is not valid, the method will throw an error.
|
|
41
|
-
* If the context id is valid, the method will return an observable of the resolved context.
|
|
42
|
-
* If the context id is not found, the method will return an empty observable.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```ts
|
|
46
|
-
* const resolve = resolveContextFromPath(modules.context);
|
|
47
|
-
* resolve(
|
|
48
|
-
* '/apps/context/7fd97952-7fe6-409b-a6dc-292dbf0e50d7?foobar#example'
|
|
49
|
-
* ).subscribe(console.log);
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @param context The context module.
|
|
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.
|
|
58
|
-
*/
|
|
59
|
-
export function resolveContextFromPath(
|
|
60
|
-
context: ModuleType<ContextModule>,
|
|
61
|
-
): (path: string) => Observable<ContextItem>;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```ts
|
|
67
|
-
* const resolve = resolveContextFromPath(
|
|
68
|
-
* modules.context,
|
|
69
|
-
* {
|
|
70
|
-
* extract: (path) => path.find(extractingContextFromPath),
|
|
71
|
-
* validate: (id) => isValidContextId(id)
|
|
72
|
-
* });
|
|
73
|
-
* resolve(
|
|
74
|
-
* '/apps/context/7fd97952-7fe6-409b-a6dc-292dbf0e50d7?foobar#example'
|
|
75
|
-
* ).subscribe(console.log);
|
|
76
|
-
* ```
|
|
77
|
-
*
|
|
78
|
-
* @param context The context module.
|
|
79
|
-
* @param args The arguments for resolving the path.
|
|
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.
|
|
85
|
-
*/
|
|
86
|
-
export function resolveContextFromPath(
|
|
87
|
-
context: ModuleType<ContextModule>,
|
|
88
|
-
args?: ContextPathResolveArgs,
|
|
89
|
-
): (path: string) => Observable<ContextItem>;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Resolves a context item from a path, using the provided extract/validate callbacks or the defaults.
|
|
93
|
-
* @param context The context module.
|
|
94
|
-
* @param args The arguments for resolving the path.
|
|
95
|
-
* @returns A function that takes a path and returns an Observable of the resolved context item.
|
|
96
|
-
* @throws Error if the extracted context id fails validation.
|
|
97
|
-
*/
|
|
98
|
-
export function resolveContextFromPath(
|
|
99
|
-
context: ModuleType<ContextModule>,
|
|
100
|
-
args?: ContextPathResolveArgs,
|
|
101
|
-
) {
|
|
102
|
-
return (path: string) => {
|
|
103
|
-
const { extract = extractContextIdFromPath, validate = validateContextId } = args ?? {};
|
|
104
|
-
const contextId = extract(path);
|
|
105
|
-
// no context id found in the path, nothing to resolve
|
|
106
|
-
if (!contextId) {
|
|
107
|
-
return EMPTY;
|
|
108
|
-
}
|
|
109
|
-
// only resolve the context if the extracted id passes validation
|
|
110
|
-
if (validate(contextId)) {
|
|
111
|
-
return context.contextClient.resolveContext(contextId);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
throw Error(`Failed to validate context [${contextId}] from path [${path}]`);
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export default resolveContextFromPath;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { ModulesInstance } from '@equinor/fusion-framework-module';
|
|
2
|
-
import type { ContextModule } from '../module';
|
|
3
|
-
import type { ContextModuleConfig } from '../ContextModuleConfig';
|
|
4
|
-
import { concat, EMPTY, first, of } from 'rxjs';
|
|
5
|
-
import resolveContextFromPath, { type ContextPathResolveArgs } from './resolve-context-from-path';
|
|
6
|
-
import type { NavigationModule } from '@equinor/fusion-framework-module-navigation';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Resolves the initial context from the parent module.
|
|
10
|
-
*
|
|
11
|
-
* @param ref - parent modules.
|
|
12
|
-
* @returns An Observable of the resolved initial context.
|
|
13
|
-
*/
|
|
14
|
-
export const resolveContextFromParent: ContextModuleConfig['resolveInitialContext'] = ({ ref }) => {
|
|
15
|
-
const parentContext = (ref as ModulesInstance<[ContextModule]>)?.context;
|
|
16
|
-
// check if the parent has context module
|
|
17
|
-
if (!parentContext) {
|
|
18
|
-
// No parent context available — either portal level or parent lacks context module.
|
|
19
|
-
return EMPTY;
|
|
20
|
-
}
|
|
21
|
-
// return the current context from the parent or empty if the parent does not have a context
|
|
22
|
-
return parentContext.currentContext ? of(parentContext.currentContext) : EMPTY;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Resolves the initial context for a Fusion Framework context module.
|
|
27
|
-
*
|
|
28
|
-
* will try to resolve the initial context from the path, and if that fails, it will try to resolve the context from the parent.
|
|
29
|
-
*
|
|
30
|
-
* @param options - Optional configuration for resolving the context path.
|
|
31
|
-
* @returns A function that accepts the module's reference and modules, and returns an Observable of the resolved initial context.
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
// Deliberately co-located with resolveContextFromParent, which it composes with
|
|
35
|
-
// fusion-lint-disable-next-line single-export-per-file
|
|
36
|
-
export const resolveInitialContext =
|
|
37
|
-
(options?: {
|
|
38
|
-
path?: ContextPathResolveArgs;
|
|
39
|
-
}): Required<ContextModuleConfig>['resolveInitialContext'] =>
|
|
40
|
-
({ ref, modules }) => {
|
|
41
|
-
const { context, navigation } = modules;
|
|
42
|
-
// create a path resolver from the context module
|
|
43
|
-
const pathResolver = resolveContextFromPath(context, options?.path);
|
|
44
|
-
// use the path from the navigation module, or the path from the parent navigation module
|
|
45
|
-
const pathname =
|
|
46
|
-
navigation?.path.pathname ??
|
|
47
|
-
(ref as Partial<ModulesInstance<[NavigationModule]>>).navigation?.path.pathname;
|
|
48
|
-
// try to resolve the context from the path, and if that fails, try to resolve the context from the parent
|
|
49
|
-
return concat(
|
|
50
|
-
pathname ? pathResolver(pathname) : EMPTY,
|
|
51
|
-
resolveContextFromParent({ ref, modules }),
|
|
52
|
-
).pipe(
|
|
53
|
-
// having no initial context is valid; a default avoids first() throwing EmptyError for it
|
|
54
|
-
first(undefined, undefined),
|
|
55
|
-
);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export default resolveInitialContext;
|
package/src/version.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "dist/esm",
|
|
5
|
-
"rootDir": "src",
|
|
6
|
-
"declarationDir": "./dist/types"
|
|
7
|
-
},
|
|
8
|
-
"references": [
|
|
9
|
-
{
|
|
10
|
-
"path": "../../utils/query"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"path": "../module"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"path": "../navigation"
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"path": "../event"
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
"path": "../http"
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"path": "../services"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"path": "../telemetry"
|
|
29
|
-
}
|
|
30
|
-
],
|
|
31
|
-
"include": ["src/**/*"],
|
|
32
|
-
"exclude": ["node_modules", "dist"]
|
|
33
|
-
}
|
package/vitest.config.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { defineProject } from 'vitest/config';
|
|
2
|
-
|
|
3
|
-
import { name, version } from './package.json' with { type: 'json' };
|
|
4
|
-
|
|
5
|
-
export default defineProject({
|
|
6
|
-
test: {
|
|
7
|
-
environment: 'node',
|
|
8
|
-
include: ['src/__tests__/**/*.test.ts'],
|
|
9
|
-
name: `${name}@${version}`,
|
|
10
|
-
},
|
|
11
|
-
});
|