@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configurator.js","sourceRoot":"","sources":["../../src/configurator.ts"],"names":[],"mappings":"AAUA,OAAO,
|
|
1
|
+
{"version":3,"file":"configurator.js","sourceRoot":"","sources":["../../src/configurator.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAShC,OAAO,EAAE,oBAAoB,EAAqC,MAAM,wBAAwB,CAAC;AAEjG,OAAO,qBAAqB,MAAM,iCAAiC,CAAC;AA4JpE;;;;;;;;;GASG;AACH,MAAM,OAAO,yBAAyB;IACpC,2DAA2D;IAC3D,iBAAiB,GAAG,CAAC,GAAG,EAAE,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,iBAAiB;iBAC/B;aACF,CAAC;QACJ,CAAC,CAAC,EAAE,CAAC;QAEL,OAAO,MAA6B,CAAC;IACvC,CAAC;CACF;AAED,eAAe,yBAAyB,CAAC"}
|
|
@@ -16,12 +16,14 @@ export class FusionContextSearchError extends Error {
|
|
|
16
16
|
#details;
|
|
17
17
|
/**
|
|
18
18
|
* The title of the error.
|
|
19
|
+
* @returns The error title.
|
|
19
20
|
*/
|
|
20
21
|
get title() {
|
|
21
22
|
return this.#details.title;
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* The description of the error, if available.
|
|
26
|
+
* @returns The error description, or `undefined` if none was provided.
|
|
25
27
|
*/
|
|
26
28
|
get description() {
|
|
27
29
|
return this.#details.description;
|
|
@@ -37,4 +39,4 @@ export class FusionContextSearchError extends Error {
|
|
|
37
39
|
this.name = 'FusionContextSearchError';
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
|
-
//# sourceMappingURL=
|
|
42
|
+
//# sourceMappingURL=FusionContextSearchError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FusionContextSearchError.js","sourceRoot":"","sources":["../../../src/errors/FusionContextSearchError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,QAAQ,CAAC;IAET;;;OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACH,YACE,OASC,EACD,OAAsB;QAEtB,KAAK,CAAC,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACrD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { parseContextItem } from './parse-context-item';
|
|
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 const getContextSelector = async (response) => {
|
|
8
|
+
const result = (await response.json());
|
|
9
|
+
return parseContextItem(result);
|
|
10
|
+
};
|
|
11
|
+
// Deliberately re-exported from here to preserve the package's existing selectors entry point
|
|
12
|
+
export { queryContextSelector } from './query-context-selector';
|
|
13
|
+
export { relatedContextSelector } from './related-context-selector';
|
|
14
|
+
//# sourceMappingURL=get-context-selector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-context-selector.js","sourceRoot":"","sources":["../../src/get-context-selector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxD;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,QAAkB,EAAwB,EAAE;IACnF,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA6B,CAAC;IACnE,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC,CAAC;AAEF,8FAA8F;AAC9F,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses the context type from the response of the GetContext API.
|
|
3
|
+
*
|
|
4
|
+
* @param type The type property from the GetContext response.
|
|
5
|
+
* @returns The parsed context item type.
|
|
6
|
+
*/
|
|
7
|
+
const parseContextType = (type) => ({
|
|
8
|
+
id: type.id,
|
|
9
|
+
isChildType: type.isChildType,
|
|
10
|
+
parentTypeIds: type.parentTypeIds ?? [],
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Parses an ApiContextEntity object into a ContextItem object.
|
|
14
|
+
* @param item The ApiContextEntity object to parse.
|
|
15
|
+
* @returns The parsed ContextItem object.
|
|
16
|
+
*/
|
|
17
|
+
export const parseContextItem = (item) => {
|
|
18
|
+
return {
|
|
19
|
+
id: item.id,
|
|
20
|
+
externalId: item.externalId ?? undefined,
|
|
21
|
+
isActive: item.isActive,
|
|
22
|
+
isDeleted: item.isDeleted,
|
|
23
|
+
created: new Date(item.created),
|
|
24
|
+
source: item.source ?? undefined,
|
|
25
|
+
title: item.title ?? undefined,
|
|
26
|
+
type: parseContextType(item.type),
|
|
27
|
+
// TODO(#5115): parse and map the raw `value` payload into a typed context item value
|
|
28
|
+
value: item.value ?? {},
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=parse-context-item.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-context-item.js","sourceRoot":"","sources":["../../src/parse-context-item.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,MAAM,gBAAgB,GAAG,CAAC,IAAsC,EAAmB,EAAE,CAAC,CAAC;IACrF,EAAE,EAAE,IAAI,CAAC,EAAE;IACX,WAAW,EAAE,IAAI,CAAC,WAAW;IAC7B,aAAa,EAAE,IAAI,CAAC,aAAa,IAAI,EAAE;CACxC,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAqC,EAAe,EAAE;IACrF,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,SAAS;QACxC,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,OAAO,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,SAAS;QAChC,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,SAAS;QAC9B,IAAI,EAAE,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC;QACjC,qFAAqF;QACrF,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,EAAE;KACxB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { parseContextItem } from './parse-context-item';
|
|
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 const queryContextSelector = async (response) => {
|
|
8
|
+
const result = (await response.json());
|
|
9
|
+
// parse each raw API entry into a ContextItem
|
|
10
|
+
return result.map(parseContextItem);
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=query-context-selector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-context-selector.js","sourceRoot":"","sources":["../../src/query-context-selector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxD;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,QAAkB,EAA0B,EAAE;IACvF,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA+B,CAAC;IACrE,8CAA8C;IAC9C,OAAO,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AACtC,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { parseContextItem } from './parse-context-item';
|
|
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 const relatedContextSelector = async (response) => {
|
|
8
|
+
const result = (await response.json());
|
|
9
|
+
// parse each raw API entry into a ContextItem
|
|
10
|
+
return result.map(parseContextItem);
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=related-context-selector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"related-context-selector.js","sourceRoot":"","sources":["../../src/related-context-selector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxD;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EAAE,QAAkB,EAA0B,EAAE;IACzF,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAiC,CAAC;IACvE,8CAA8C;IAC9C,OAAO,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AACtC,CAAC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// GUID pattern
|
|
2
|
+
const matchGUID = /^(?:(?:[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})$/;
|
|
3
|
+
/**
|
|
4
|
+
* Method will try to extract a context id from a path.
|
|
5
|
+
* The default matcher is a GUID pattern.
|
|
6
|
+
* Will iterate over the path and return the first match.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const path = '/apps/context/7fd97952-7fe6-409b-a6dc-292dbf0e50d7?dsadasdas#example';
|
|
11
|
+
* const contextId = extractContextIdFromPath(path); // '7fd97952-7fe6-409b-a6dc-292dbf0e50d7'
|
|
12
|
+
*
|
|
13
|
+
* // Custom matcher for numeric IDs
|
|
14
|
+
* extractContextIdFromPath('/projects/42/details', /^\d+$/); // '42'
|
|
15
|
+
*
|
|
16
|
+
* // No match
|
|
17
|
+
* extractContextIdFromPath('/apps/my-app/settings'); // undefined
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @param path string - the path to extract the context id from
|
|
21
|
+
* @param matcher RegExp - the pattern to match against
|
|
22
|
+
* @returns string | undefined - the context id or undefined
|
|
23
|
+
*/
|
|
24
|
+
export const extractContextIdFromPath = (path, matcher = matchGUID) =>
|
|
25
|
+
//
|
|
26
|
+
path
|
|
27
|
+
// remove query-string and hash fragments before segment matching
|
|
28
|
+
.split(/[?#]/)[0]
|
|
29
|
+
// remove leading slashes
|
|
30
|
+
.replace(/^\/+/, '')
|
|
31
|
+
// split path by slashes
|
|
32
|
+
.split('/')
|
|
33
|
+
// find the first path fragment that matches the matcher
|
|
34
|
+
.find((x) => x.match(matcher));
|
|
35
|
+
//# sourceMappingURL=extract-context-id-from-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-context-id-from-path.js","sourceRoot":"","sources":["../../../src/utils/extract-context-id-from-path.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,MAAM,SAAS,GACb,uGAAuG,CAAC;AAE1G;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,IAAY,EACZ,OAAO,GAAW,SAAS,EACP,EAAE;AACtB,EAAE;AACF,IAAI;IACF,iEAAiE;KAChE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACjB,yBAAyB;KACxB,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IACpB,wBAAwB;KACvB,KAAK,CAAC,GAAG,CAAC;IACX,wDAAwD;KACvD,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC"}
|
|
@@ -1,36 +1,25 @@
|
|
|
1
1
|
import { EMPTY } from 'rxjs';
|
|
2
|
-
|
|
2
|
+
import { extractContextIdFromPath } from './extract-context-id-from-path';
|
|
3
|
+
export { extractContextIdFromPath } from './extract-context-id-from-path';
|
|
4
|
+
// GUID pattern, used as the default context id validator
|
|
3
5
|
const matchGUID = /^(?:(?:[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})$/;
|
|
6
|
+
const validateContextId = (contextId) => !!contextId.match(matchGUID);
|
|
4
7
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
10
|
-
* ```ts
|
|
11
|
-
* const path = '/apps/context/7fd97952-7fe6-409b-a6dc-292dbf0e50d7?dsadasdas#example';
|
|
12
|
-
* const contextId = extractContextIdFromPath(path); // '7fd97952-7fe6-409b-a6dc-292dbf0e50d7'
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @param path string - the path to extract the context id from
|
|
16
|
-
* @param matcher RegExp - the pattern to match against
|
|
17
|
-
* @returns string | undefined - the context id or undefined
|
|
8
|
+
* Resolves a context item from a path, using the provided extract/validate callbacks or the defaults.
|
|
9
|
+
* @param context The context module.
|
|
10
|
+
* @param args The arguments for resolving the path.
|
|
11
|
+
* @returns A function that takes a path and returns an Observable of the resolved context item.
|
|
12
|
+
* @throws Error if the extracted context id fails validation.
|
|
18
13
|
*/
|
|
19
|
-
export const extractContextIdFromPath = (path, matcher = matchGUID) => path
|
|
20
|
-
// remove leading slashes
|
|
21
|
-
.replace(/^\/+/, '')
|
|
22
|
-
// split path by slashes
|
|
23
|
-
.split('/')
|
|
24
|
-
// find the first path fragment that matches the matcher
|
|
25
|
-
.find((x) => x.match(matcher));
|
|
26
|
-
const validateContextId = (contextId) => !!contextId.match(matchGUID);
|
|
27
14
|
export function resolveContextFromPath(context, args) {
|
|
28
15
|
return (path) => {
|
|
29
16
|
const { extract = extractContextIdFromPath, validate = validateContextId } = args ?? {};
|
|
30
17
|
const contextId = extract(path);
|
|
18
|
+
// no context id found in the path, nothing to resolve
|
|
31
19
|
if (!contextId) {
|
|
32
20
|
return EMPTY;
|
|
33
21
|
}
|
|
22
|
+
// only resolve the context if the extracted id passes validation
|
|
34
23
|
if (validate(contextId)) {
|
|
35
24
|
return context.contextClient.resolveContext(contextId);
|
|
36
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-context-from-path.js","sourceRoot":"","sources":["../../../src/utils/resolve-context-from-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAmB,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"resolve-context-from-path.js","sourceRoot":"","sources":["../../../src/utils/resolve-context-from-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAmB,MAAM,MAAM,CAAC;AAM9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAE1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAoB1E,yDAAyD;AACzD,MAAM,SAAS,GACb,uGAAuG,CAAC;AAE1G,MAAM,iBAAiB,GAAG,CAAC,SAAiB,EAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AA0DvF;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CACpC,OAAkC,EAClC,IAA6B;IAE7B,OAAO,CAAC,IAAY,EAAE,EAAE;QACtB,MAAM,EAAE,OAAO,GAAG,wBAAwB,EAAE,QAAQ,GAAG,iBAAiB,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC;QACxF,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAChC,sDAAsD;QACtD,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,KAAK,CAAC;QACf,CAAC;QACD,iEAAiE;QACjE,IAAI,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;YACxB,OAAO,OAAO,CAAC,aAAa,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QACzD,CAAC;QAED,MAAM,KAAK,CAAC,+BAA+B,SAAS,gBAAgB,IAAI,GAAG,CAAC,CAAC;IAC/E,CAAC,CAAC;AACJ,CAAC;AAED,eAAe,sBAAsB,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { concat, EMPTY,
|
|
2
|
-
import { resolveContextFromPath } from './resolve-context-from-path';
|
|
1
|
+
import { concat, EMPTY, of, take } from 'rxjs';
|
|
3
2
|
/**
|
|
4
3
|
* Resolves the initial context from the parent module.
|
|
5
4
|
*
|
|
@@ -8,9 +7,9 @@ import { resolveContextFromPath } from './resolve-context-from-path';
|
|
|
8
7
|
*/
|
|
9
8
|
export const resolveContextFromParent = ({ ref }) => {
|
|
10
9
|
const parentContext = ref?.context;
|
|
11
|
-
// check if the parent has context module
|
|
12
10
|
if (!parentContext) {
|
|
13
|
-
|
|
11
|
+
// No parent context available — either portal level or parent lacks context module.
|
|
12
|
+
return EMPTY;
|
|
14
13
|
}
|
|
15
14
|
// return the current context from the parent or empty if the parent does not have a context
|
|
16
15
|
return parentContext.currentContext ? of(parentContext.currentContext) : EMPTY;
|
|
@@ -18,20 +17,17 @@ export const resolveContextFromParent = ({ ref }) => {
|
|
|
18
17
|
/**
|
|
19
18
|
* Resolves the initial context for a Fusion Framework context module.
|
|
20
19
|
*
|
|
21
|
-
*
|
|
20
|
+
* Attempts to resolve the initial context from the parent context provider.
|
|
21
|
+
* URL-based resolution is handled by the context-navigation plugin.
|
|
22
22
|
*
|
|
23
|
-
* @param options - Optional configuration for resolving the context path.
|
|
24
23
|
* @returns A function that accepts the module's reference and modules, and returns an Observable of the resolved initial context.
|
|
25
24
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
ref.navigation?.path.pathname;
|
|
33
|
-
// try to resolve the context from the path, and if that fails, try to resolve the context from the parent
|
|
34
|
-
return concat(pathname ? pathResolver(pathname) : EMPTY, resolveContextFromParent({ ref, modules })).pipe(first());
|
|
25
|
+
// Deliberately co-located with resolveContextFromParent, which it composes with
|
|
26
|
+
// fusion-lint-disable-next-line single-export-per-file
|
|
27
|
+
export const resolveInitialContext = () => ({ ref, modules }) => {
|
|
28
|
+
// Resolve from parent context if available.
|
|
29
|
+
// URL-based resolution is handled by the context-navigation plugin.
|
|
30
|
+
return concat(resolveContextFromParent({ ref, modules })).pipe(take(1));
|
|
35
31
|
};
|
|
36
32
|
export default resolveInitialContext;
|
|
37
33
|
//# sourceMappingURL=resolve-initial-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-initial-context.js","sourceRoot":"","sources":["../../../src/utils/resolve-initial-context.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"resolve-initial-context.js","sourceRoot":"","sources":["../../../src/utils/resolve-initial-context.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAiD,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;IAChG,MAAM,aAAa,GAAI,GAAwC,EAAE,OAAO,CAAC;IACzE,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,oFAAoF;QACpF,OAAO,KAAK,CAAC;IACf,CAAC;IACD,4FAA4F;IAC5F,OAAO,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACjF,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,gFAAgF;AAChF,uDAAuD;AACvD,MAAM,CAAC,MAAM,qBAAqB,GAChC,GAA2D,EAAE,CAC7D,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE;IACnB,4CAA4C;IAC5C,oEAAoE;IACpE,OAAO,MAAM,CAAC,wBAAwB,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1E,CAAC,CAAC;AAEJ,eAAe,qBAAqB,CAAC"}
|
package/dist/esm/version.js
CHANGED