@equinor/fusion-framework-module-context 5.0.19 → 5.1.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 +52 -0
- package/dist/esm/ContextConfigBuilder.js +17 -0
- package/dist/esm/ContextConfigBuilder.js.map +1 -1
- package/dist/esm/ContextProvider.js +8 -0
- package/dist/esm/ContextProvider.js.map +1 -1
- package/dist/esm/configurator.js +6 -1
- package/dist/esm/configurator.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ContextConfigBuilder.d.ts +13 -0
- package/dist/types/ContextProvider.d.ts +15 -0
- package/dist/types/configurator.d.ts +2 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/ContextConfigBuilder.ts +19 -0
- package/src/ContextProvider.ts +26 -0
- package/src/configurator.ts +9 -1
- package/src/version.ts +1 -1
|
@@ -16,6 +16,19 @@ export declare class ContextConfigBuilder<TModules extends Array<AnyModule> = []
|
|
|
16
16
|
setContextParameterFn(fn: ContextModuleConfig['contextParameterFn']): void;
|
|
17
17
|
setValidateContext(fn: ContextModuleConfig['validateContext']): void;
|
|
18
18
|
setResolveContext(fn: ContextModuleConfig['resolveContext']): void;
|
|
19
|
+
/**
|
|
20
|
+
* Sets the function responsible for extracting the context ID from a given path.
|
|
21
|
+
*
|
|
22
|
+
* @param fn - A function that defines how to extract the context ID from a path.
|
|
23
|
+
* This function should match the type defined in `ContextModuleConfig['extractContextIdFromPath']`.
|
|
24
|
+
*/
|
|
25
|
+
setContextPathExtractor(fn: ContextModuleConfig['extractContextIdFromPath']): void;
|
|
26
|
+
/**
|
|
27
|
+
* Sets the function responsible for generating a path from the context.
|
|
28
|
+
*
|
|
29
|
+
* @param fn - A function that takes a context and generates a corresponding path.
|
|
30
|
+
*/
|
|
31
|
+
setContextPathGenerator(fn: ContextModuleConfig['generatePathFromContext']): void;
|
|
19
32
|
setResolveInitialContext(fn: ContextModuleConfig['resolveInitialContext']): void;
|
|
20
33
|
setContextClient(client: {
|
|
21
34
|
get: QueryFn<ContextItem, GetContextParameters> | QueryCtorOptions<ContextItem, GetContextParameters>;
|
|
@@ -101,6 +101,21 @@ export interface IContextProvider {
|
|
|
101
101
|
validate?: boolean;
|
|
102
102
|
resolve?: boolean;
|
|
103
103
|
}): Promise<ContextItem<Record<string, unknown>> | null>;
|
|
104
|
+
/**
|
|
105
|
+
* Method for extracting context id from a path.
|
|
106
|
+
*
|
|
107
|
+
* @param path path to resolve context from
|
|
108
|
+
* @returns the resolved context item id
|
|
109
|
+
*/
|
|
110
|
+
extractContextIdFromPath?: (path: string) => string | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Method for generating path from a context item.
|
|
113
|
+
*
|
|
114
|
+
* @param context context item to generate path from
|
|
115
|
+
* @param path current path
|
|
116
|
+
* @returns path for the context item
|
|
117
|
+
*/
|
|
118
|
+
generatePathFromContext?: (context: ContextItem, path: string) => string | undefined;
|
|
104
119
|
}
|
|
105
120
|
export declare class ContextProvider implements IContextProvider {
|
|
106
121
|
#private;
|
|
@@ -23,6 +23,8 @@ export interface ContextModuleConfig {
|
|
|
23
23
|
connectParentContext?: boolean;
|
|
24
24
|
/** set initial context from parent, will await resolve */
|
|
25
25
|
skipInitialContext?: boolean;
|
|
26
|
+
extractContextIdFromPath?: (path: string) => string | undefined;
|
|
27
|
+
generatePathFromContext?: (context: ContextItem, path: string) => string | undefined;
|
|
26
28
|
/**
|
|
27
29
|
* Method for generating context query parameters.
|
|
28
30
|
*/
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.0
|
|
1
|
+
export declare const version = "5.1.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-module-context",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"rxjs": "^7.8.1",
|
|
52
52
|
"typescript": "^5.8.2",
|
|
53
|
-
"@equinor/fusion-framework-module": "^4.3.7",
|
|
54
53
|
"@equinor/fusion-framework-module-event": "^4.3.2",
|
|
55
54
|
"@equinor/fusion-framework-module-navigation": "^4.0.9",
|
|
55
|
+
"@equinor/fusion-framework-module": "^4.3.7",
|
|
56
56
|
"@equinor/fusion-framework-module-services": "^5.1.2"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
@@ -74,6 +74,25 @@ export class ContextConfigBuilder<
|
|
|
74
74
|
this.config.resolveContext = fn;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Sets the function responsible for extracting the context ID from a given path.
|
|
79
|
+
*
|
|
80
|
+
* @param fn - A function that defines how to extract the context ID from a path.
|
|
81
|
+
* This function should match the type defined in `ContextModuleConfig['extractContextIdFromPath']`.
|
|
82
|
+
*/
|
|
83
|
+
setContextPathExtractor(fn: ContextModuleConfig['extractContextIdFromPath']) {
|
|
84
|
+
this.config.extractContextIdFromPath = fn;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Sets the function responsible for generating a path from the context.
|
|
89
|
+
*
|
|
90
|
+
* @param fn - A function that takes a context and generates a corresponding path.
|
|
91
|
+
*/
|
|
92
|
+
setContextPathGenerator(fn: ContextModuleConfig['generatePathFromContext']) {
|
|
93
|
+
this.config.generatePathFromContext = fn;
|
|
94
|
+
}
|
|
95
|
+
|
|
77
96
|
setResolveInitialContext(fn: ContextModuleConfig['resolveInitialContext']) {
|
|
78
97
|
this.config.resolveInitialContext = fn;
|
|
79
98
|
}
|
package/src/ContextProvider.ts
CHANGED
|
@@ -138,6 +138,23 @@ export interface IContextProvider {
|
|
|
138
138
|
context: ContextItem<Record<string, unknown>> | null,
|
|
139
139
|
opt?: { validate?: boolean; resolve?: boolean },
|
|
140
140
|
): Promise<ContextItem<Record<string, unknown>> | null>;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Method for extracting context id from a path.
|
|
144
|
+
*
|
|
145
|
+
* @param path path to resolve context from
|
|
146
|
+
* @returns the resolved context item id
|
|
147
|
+
*/
|
|
148
|
+
extractContextIdFromPath?: (path: string) => string | undefined;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Method for generating path from a context item.
|
|
152
|
+
*
|
|
153
|
+
* @param context context item to generate path from
|
|
154
|
+
* @param path current path
|
|
155
|
+
* @returns path for the context item
|
|
156
|
+
*/
|
|
157
|
+
generatePathFromContext?: (context: ContextItem, path: string) => string | undefined;
|
|
141
158
|
}
|
|
142
159
|
|
|
143
160
|
export class ContextProvider implements IContextProvider {
|
|
@@ -205,6 +222,15 @@ export class ContextProvider implements IContextProvider {
|
|
|
205
222
|
config.resolveContext && (this.resolveContext = config.resolveContext?.bind(this));
|
|
206
223
|
config.validateContext && (this.validateContext = config.validateContext?.bind(this));
|
|
207
224
|
|
|
225
|
+
if (config.extractContextIdFromPath) {
|
|
226
|
+
// @ts-ignore
|
|
227
|
+
this.extractContextIdFromPath = config.extractContextIdFromPath;
|
|
228
|
+
}
|
|
229
|
+
if (config.generatePathFromContext) {
|
|
230
|
+
// @ts-ignore
|
|
231
|
+
this.generatePathFromContext = config.generatePathFromContext;
|
|
232
|
+
}
|
|
233
|
+
|
|
208
234
|
this.#contextType = config.contextType;
|
|
209
235
|
this.#contextFilter = config.contextFilter;
|
|
210
236
|
|
package/src/configurator.ts
CHANGED
|
@@ -40,6 +40,9 @@ export interface ContextModuleConfig {
|
|
|
40
40
|
/** set initial context from parent, will await resolve */
|
|
41
41
|
skipInitialContext?: boolean;
|
|
42
42
|
|
|
43
|
+
extractContextIdFromPath?: (path: string) => string | undefined;
|
|
44
|
+
generatePathFromContext?: (context: ContextItem, path: string) => string | undefined;
|
|
45
|
+
|
|
43
46
|
/**
|
|
44
47
|
* Method for generating context query parameters.
|
|
45
48
|
*/
|
|
@@ -105,7 +108,12 @@ export class ContextModuleConfigurator implements IContextModuleConfigurator {
|
|
|
105
108
|
Promise.resolve({} as Partial<ContextModuleConfig>),
|
|
106
109
|
);
|
|
107
110
|
|
|
108
|
-
config.resolveInitialContext ??= resolveInitialContext(
|
|
111
|
+
config.resolveInitialContext ??= resolveInitialContext({
|
|
112
|
+
path: {
|
|
113
|
+
extract: config.extractContextIdFromPath,
|
|
114
|
+
validate: config.extractContextIdFromPath ? () => true : undefined,
|
|
115
|
+
},
|
|
116
|
+
});
|
|
109
117
|
|
|
110
118
|
// TODO - make less lazy
|
|
111
119
|
config.client ??= await (async (): Promise<ContextModuleConfig['client']> => {
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '5.0
|
|
2
|
+
export const version = '5.1.0';
|