@equinor/fusion-framework-module-context 5.0.6 → 5.0.8
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 +60 -0
- package/dist/esm/ContextConfigBuilder.js +5 -0
- package/dist/esm/ContextConfigBuilder.js.map +1 -1
- package/dist/esm/ContextProvider.js +124 -23
- package/dist/esm/ContextProvider.js.map +1 -1
- package/dist/esm/client/ContextClient.js +7 -1
- package/dist/esm/client/ContextClient.js.map +1 -1
- package/dist/esm/configurator.js +4 -0
- package/dist/esm/configurator.js.map +1 -1
- package/dist/esm/errors.js +14 -0
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/module.js +20 -3
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/selectors.js +27 -0
- package/dist/esm/selectors.js.map +1 -1
- package/dist/esm/utils/enable-context.js +7 -1
- package/dist/esm/utils/enable-context.js.map +1 -1
- package/dist/esm/utils/resolve-context-from-path.js +19 -0
- package/dist/esm/utils/resolve-context-from-path.js.map +1 -1
- package/dist/esm/utils/resolve-initial-context.js +19 -0
- package/dist/esm/utils/resolve-initial-context.js.map +1 -1
- package/dist/esm/version.js +2 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ContextProvider.d.ts +86 -0
- package/dist/types/configurator.d.ts +9 -0
- package/dist/types/errors.d.ts +20 -0
- package/dist/types/selectors.d.ts +15 -0
- package/dist/types/utils/enable-context.d.ts +5 -1
- package/dist/types/utils/resolve-context-from-path.d.ts +67 -0
- package/dist/types/utils/resolve-initial-context.d.ts +15 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +8 -8
- package/src/version.ts +1 -1
package/dist/esm/module.js
CHANGED
|
@@ -17,21 +17,36 @@ export const module = {
|
|
|
17
17
|
initialize: function (args) {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
19
|
var _a;
|
|
20
|
+
// create config from configurator
|
|
20
21
|
const config = yield args.config.createConfig(args);
|
|
22
|
+
// get event module if available
|
|
21
23
|
const event = args.hasModule('event') ? yield args.requireInstance('event') : undefined;
|
|
24
|
+
// get parent context provider if available
|
|
22
25
|
const parentProvider = (_a = args.ref) === null || _a === void 0 ? void 0 : _a.context;
|
|
26
|
+
// create context provider
|
|
23
27
|
const provider = new ContextProvider({ config, event, parentContext: parentProvider });
|
|
28
|
+
// create subscription for disposing the provider
|
|
24
29
|
const subscription = new Subscription(() => provider.dispose());
|
|
25
|
-
|
|
30
|
+
// setup post initialize to module
|
|
31
|
+
this.postInitialize = (args) =>
|
|
32
|
+
// create observable for resolving initial context
|
|
33
|
+
new Observable((subscriber) => {
|
|
34
|
+
// resolve initial context if available from config if available
|
|
26
35
|
const resolveInitialContext$ = config.resolveInitialContext
|
|
27
|
-
? from(config.resolveInitialContext(args)).pipe(
|
|
36
|
+
? from(config.resolveInitialContext(args)).pipe(
|
|
37
|
+
// filter out invalid context items
|
|
38
|
+
filter((item) => !!item), switchMap((item) =>
|
|
39
|
+
// set current context with validation and resolution
|
|
40
|
+
args.modules.context.setCurrentContext(item, {
|
|
28
41
|
validate: true,
|
|
29
42
|
resolve: true,
|
|
30
43
|
})))
|
|
31
|
-
: EMPTY;
|
|
44
|
+
: EMPTY; // if no initial context is available, complete immediately
|
|
45
|
+
// add teardown to resolve initial context
|
|
32
46
|
subscriber.add(resolveInitialContext$
|
|
33
47
|
.pipe(catchError((err) => {
|
|
34
48
|
console.warn('ContextModule.postInitialize', 'failed to resolve initial context', err);
|
|
49
|
+
// failed to resolve initial context, complete immediately
|
|
35
50
|
return EMPTY;
|
|
36
51
|
}))
|
|
37
52
|
.subscribe({
|
|
@@ -39,6 +54,7 @@ export const module = {
|
|
|
39
54
|
console.debug('ContextModule.postInitialize', `initial context was resolved to [${item ? item.id : 'none'}]`, item);
|
|
40
55
|
},
|
|
41
56
|
complete: () => {
|
|
57
|
+
// connect parent context if available when stream completes
|
|
42
58
|
if (config.connectParentContext !== false && parentProvider) {
|
|
43
59
|
provider.connectParentContext(parentProvider);
|
|
44
60
|
}
|
|
@@ -46,6 +62,7 @@ export const module = {
|
|
|
46
62
|
},
|
|
47
63
|
}));
|
|
48
64
|
});
|
|
65
|
+
// add teardown to module
|
|
49
66
|
this.dispose = () => subscription.unsubscribe();
|
|
50
67
|
return provider;
|
|
51
68
|
});
|
package/dist/esm/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAQ5F,OAAO,EAA8B,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AACvF,OAAO,EAAoB,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAKtE,MAAM,CAAC,MAAM,SAAS,GAAqB,SAAS,CAAC;AASrD,MAAM,CAAC,MAAM,MAAM,GAAkB;IACjC,IAAI,EAAE,SAAS;IACf,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,yBAAyB,EAAE;IAChD,UAAU,EAAE,UAAgB,IAAI;;;
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/module.ts"],"names":[],"mappings":"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"}
|
package/dist/esm/selectors.js
CHANGED
|
@@ -7,6 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Parses the context type from the response of the GetContext API.
|
|
12
|
+
*
|
|
13
|
+
* @param type The type property from the GetContext response.
|
|
14
|
+
* @returns The parsed context item type.
|
|
15
|
+
*/
|
|
10
16
|
const parseContextType = (type) => {
|
|
11
17
|
var _a;
|
|
12
18
|
return ({
|
|
@@ -15,6 +21,11 @@ const parseContextType = (type) => {
|
|
|
15
21
|
parentTypeIds: (_a = type.parentTypeIds) !== null && _a !== void 0 ? _a : [],
|
|
16
22
|
});
|
|
17
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Parses an ApiContextEntity object into a ContextItem object.
|
|
26
|
+
* @param item The ApiContextEntity object to parse.
|
|
27
|
+
* @returns The parsed ContextItem object.
|
|
28
|
+
*/
|
|
18
29
|
const parseContextItem = (item) => {
|
|
19
30
|
var _a, _b, _c, _d;
|
|
20
31
|
return {
|
|
@@ -26,17 +37,33 @@ const parseContextItem = (item) => {
|
|
|
26
37
|
source: (_b = item.source) !== null && _b !== void 0 ? _b : undefined,
|
|
27
38
|
title: (_c = item.title) !== null && _c !== void 0 ? _c : undefined,
|
|
28
39
|
type: parseContextType(item.type),
|
|
40
|
+
// TODO
|
|
29
41
|
value: (_d = item.value) !== null && _d !== void 0 ? _d : {},
|
|
30
42
|
};
|
|
31
43
|
};
|
|
44
|
+
/**
|
|
45
|
+
* Parse the response from the GetContext API into a context item.
|
|
46
|
+
* @param response The response object containing the context item.
|
|
47
|
+
* @returns A promise that resolves to the context item.
|
|
48
|
+
*/
|
|
32
49
|
export const getContextSelector = (response) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
50
|
const result = (yield response.json());
|
|
34
51
|
return parseContextItem(result);
|
|
35
52
|
});
|
|
53
|
+
/**
|
|
54
|
+
* Parse the response from the QueryContext API into an array of context items.
|
|
55
|
+
* @param response The response object.
|
|
56
|
+
* @returns A promise that resolves to an array of context items.
|
|
57
|
+
*/
|
|
36
58
|
export const queryContextSelector = (response) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
59
|
const result = (yield response.json());
|
|
38
60
|
return result.map(parseContextItem);
|
|
39
61
|
});
|
|
62
|
+
/**
|
|
63
|
+
* Parse the response from the RelatedContext API into an array of context items.
|
|
64
|
+
* @param response The response object containing the related context items.
|
|
65
|
+
* @returns A promise that resolves to an array of ContextItem objects.
|
|
66
|
+
*/
|
|
40
67
|
export const relatedContextSelector = (response) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
68
|
const result = (yield response.json());
|
|
42
69
|
return result.map(parseContextItem);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.js","sourceRoot":"","sources":["../../src/selectors.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"selectors.js","sourceRoot":"","sources":["../../src/selectors.ts"],"names":[],"mappings":";;;;;;;;;AAMA;;;;;GAKG;AACH,MAAM,gBAAgB,GAAG,CAAC,IAAsC,EAAmB,EAAE;;IAAC,OAAA,CAAC;QACnF,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,aAAa,EAAE,MAAA,IAAI,CAAC,aAAa,mCAAI,EAAE;KAC1C,CAAC,CAAA;CAAA,CAAC;AAEH;;;;GAIG;AACH,MAAM,gBAAgB,GAAG,CAAC,IAAqC,EAAe,EAAE;;IAC5E,OAAO;QACH,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,UAAU,EAAE,MAAA,IAAI,CAAC,UAAU,mCAAI,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,MAAA,IAAI,CAAC,MAAM,mCAAI,SAAS;QAChC,KAAK,EAAE,MAAA,IAAI,CAAC,KAAK,mCAAI,SAAS;QAC9B,IAAI,EAAE,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC;QACjC,OAAO;QACP,KAAK,EAAE,MAAA,IAAI,CAAC,KAAK,mCAAI,EAAE;KAC1B,CAAC;AACN,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAO,QAAkB,EAAwB,EAAE;IACjF,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA6B,CAAC;IACnE,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC,CAAA,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAO,QAAkB,EAA0B,EAAE;IACrF,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA+B,CAAC;IACrE,OAAO,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AACxC,CAAC,CAAA,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAO,QAAkB,EAA0B,EAAE;IACvF,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAiC,CAAC;IACvE,OAAO,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AACxC,CAAC,CAAA,CAAC"}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { module } from '../module';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Method for enabling the Service module
|
|
4
|
+
* @param configurator - configuration object
|
|
5
|
+
*/
|
|
6
|
+
export const enableContext = (
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
+
configurator, builder) => {
|
|
3
9
|
configurator.addConfig({
|
|
4
10
|
module,
|
|
5
11
|
configure: (contextConfigurator) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enable-context.js","sourceRoot":"","sources":["../../../src/utils/enable-context.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"enable-context.js","sourceRoot":"","sources":["../../../src/utils/enable-context.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;AACzB,8DAA8D;AAC9D,YAA4C,EAC5C,OAKyB,EACrB,EAAE;IACN,YAAY,CAAC,SAAS,CAAC;QACnB,MAAM;QACN,SAAS,EAAE,CAAC,mBAAmB,EAAE,EAAE;YAC/B,OAAO,IAAI,mBAAmB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAC7D,CAAC;KACJ,CAAC,CAAC;AACP,CAAC,CAAC"}
|
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
import { EMPTY } from 'rxjs';
|
|
2
|
+
// GUID pattern
|
|
2
3
|
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})$/;
|
|
4
|
+
/**
|
|
5
|
+
* Method will try to extract a context id from a path.
|
|
6
|
+
* The default matcher is a GUID pattern.
|
|
7
|
+
* Will iterate over the path and return the first match.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
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
|
|
18
|
+
*/
|
|
3
19
|
export const extractContextIdFromPath = (path, matcher = matchGUID) => path
|
|
20
|
+
// remove leading slashes
|
|
4
21
|
.replace(/^\/+/, '')
|
|
22
|
+
// split path by slashes
|
|
5
23
|
.split('/')
|
|
24
|
+
// find the first path fragment that matches the matcher
|
|
6
25
|
.find((x) => x.match(matcher));
|
|
7
26
|
const validateContextId = (contextId) => !!contextId.match(matchGUID);
|
|
8
27
|
export function resolveContextFromPath(context, args) {
|
|
@@ -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,EAAc,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,EAAc,MAAM,MAAM,CAAC;AAyBzC,eAAe;AACf,MAAM,SAAS,GACX,uGAAuG,CAAC;AAE5G;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACpC,IAAY,EACZ,UAAkB,SAAS,EACT,EAAE,CACpB,IAAI;IACA,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;AAEvC,MAAM,iBAAiB,GAAG,CAAC,SAAiB,EAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AAoDvF,MAAM,UAAU,sBAAsB,CAClC,OAAkC,EAClC,IAA6B;IAE7B,OAAO,CAAC,IAAY,EAAE,EAAE;QACpB,MAAM,EAAE,OAAO,GAAG,wBAAwB,EAAE,QAAQ,GAAG,iBAAiB,EAAE,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC;QACxF,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,SAAS,EAAE,CAAC;YACb,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,IAAI,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;YACtB,OAAO,OAAO,CAAC,aAAa,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QAC3D,CAAC;QAED,MAAM,KAAK,CAAC,+BAA+B,SAAS,gBAAgB,IAAI,GAAG,CAAC,CAAC;IACjF,CAAC,CAAC;AACN,CAAC;AAED,eAAe,sBAAsB,CAAC"}
|
|
@@ -1,17 +1,36 @@
|
|
|
1
1
|
import { concat, EMPTY, first, of } from 'rxjs';
|
|
2
2
|
import { resolveContextFromPath } from './resolve-context-from-path';
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the initial context from the parent module.
|
|
5
|
+
*
|
|
6
|
+
* @param ref - parent modules.
|
|
7
|
+
* @returns An Observable of the resolved initial context.
|
|
8
|
+
*/
|
|
3
9
|
export const resolveContextFromParent = ({ ref }) => {
|
|
4
10
|
const parentContext = ref === null || ref === void 0 ? void 0 : ref.context;
|
|
11
|
+
// check if the parent has context module
|
|
5
12
|
if (!parentContext) {
|
|
6
13
|
throw Error(['resolveContextFromNavigation', 'ref does not support context!'].join('\n'));
|
|
7
14
|
}
|
|
15
|
+
// return the current context from the parent or empty if the parent does not have a context
|
|
8
16
|
return parentContext.currentContext ? of(parentContext.currentContext) : EMPTY;
|
|
9
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Resolves the initial context for a Fusion Framework context module.
|
|
20
|
+
*
|
|
21
|
+
* will try to resolve the initial context from the path, and if that fails, it will try to resolve the context from the parent.
|
|
22
|
+
*
|
|
23
|
+
* @param options - Optional configuration for resolving the context path.
|
|
24
|
+
* @returns A function that accepts the module's reference and modules, and returns an Observable of the resolved initial context.
|
|
25
|
+
*/
|
|
10
26
|
export const resolveInitialContext = (options) => ({ ref, modules }) => {
|
|
11
27
|
var _a, _b;
|
|
12
28
|
const { context, navigation } = modules;
|
|
29
|
+
// create a path resolver from the context module
|
|
13
30
|
const pathResolver = resolveContextFromPath(context, options === null || options === void 0 ? void 0 : options.path);
|
|
31
|
+
// use the path from the navigation module, or the path from the parent navigation module
|
|
14
32
|
const pathname = (_a = navigation === null || navigation === void 0 ? void 0 : navigation.path.pathname) !== null && _a !== void 0 ? _a : (_b = ref.navigation) === null || _b === void 0 ? void 0 : _b.path.pathname;
|
|
33
|
+
// try to resolve the context from the path, and if that fails, try to resolve the context from the parent
|
|
15
34
|
return concat(pathname ? pathResolver(pathname) : EMPTY, resolveContextFromParent({ ref, modules })).pipe(first());
|
|
16
35
|
};
|
|
17
36
|
export default resolveInitialContext;
|
|
@@ -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,KAAK,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAEhD,OAAO,EAA+B,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;
|
|
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,KAAK,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAEhD,OAAO,EAA+B,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAGlG;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAiD,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;IAC9F,MAAM,aAAa,GAAI,GAAwC,aAAxC,GAAG,uBAAH,GAAG,CAAuC,OAAO,CAAC;IACzE,yCAAyC;IACzC,IAAI,CAAC,aAAa,EAAE,CAAC;QACjB,MAAM,KAAK,CAAC,CAAC,8BAA8B,EAAE,+BAA+B,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9F,CAAC;IACD,4FAA4F;IAC5F,OAAO,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACnF,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAC9B,CAAC,OAEA,EAA0D,EAAE,CAC7D,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE;;IACjB,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IACxC,iDAAiD;IACjD,MAAM,YAAY,GAAG,sBAAsB,CAAC,OAAO,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC,CAAC;IACpE,yFAAyF;IACzF,MAAM,QAAQ,GACV,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,CAAC,QAAQ,mCACzB,MAAC,GAAoD,CAAC,UAAU,0CAAE,IAAI,CAAC,QAAQ,CAAC;IACpF,0GAA0G;IAC1G,OAAO,MAAM,CACT,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,EACzC,wBAAwB,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAC7C,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;AACpB,CAAC,CAAC;AAEN,eAAe,qBAAqB,CAAC"}
|
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC"}
|