@j2inn/resolvable-ui-elements 1.0.5 → 1.1.1-beta.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/README.md CHANGED
@@ -1,36 +1,36 @@
1
- # What is resolvable-ui-elements?
2
- The main goal of this library is to enhance the flexibility of the UI code written, by adding a layer that separates the queries and information used to interact with the backend from the UI code, moving it to a separated JSON file.
3
-
4
- The JSON file (typically called `elements.json`) can be generated from a spreadsheet used to simplify the data management for a project UI.
5
-
6
-
7
- ## How do I get set up? ###
8
- To install this package run `npm i @j2inn/resolvable-ui-elements`
9
-
10
- ## Where do I get more info? ###
11
- See: https://finproducts.atlassian.net/wiki/spaces/ECO/pages/32881311778/Element+Types
12
-
13
- ## Codebase Structure ##
14
-
15
- src
16
- ├── resolvableElements
17
- │ ├── elements # Element classes implementation
18
- │ ├── interfacesGeneration # Code for generating interfaces from an elements.json file
19
- │ ├── react # React hooks to use resolvable elements.
20
- │ └── ...
21
- └── ...
22
-
23
- ## BE libraries dependencies ##
24
- If you decide to use the Resolver's `evalFuncName` feature, this library should be used in combination with [finOemAuthzExt](https://bitbucket.org/finproducts/finoemauthzext). The pod allows the usage of the wrapper function.
25
- ```typescript
26
- /**
27
- * Function name to be used for expressions eval,
28
- * used to enable custom backend permission check using elements path
29
- * @example
30
- * customEval(\`page/section/elementName\`, parametersDict)
31
- */
32
- evalFuncName?: string
33
- ```
34
-
35
- ### v1.0.4 ###
36
- Version 1.0.4 of this library introduces the usage of optional parameters in function evaluation. To be able to use them, [finOemAuthzExt](https://bitbucket.org/finproducts/finoemauthzext) 1.0.2+ should be used for the BE.
1
+ # What is resolvable-ui-elements?
2
+ The main goal of this library is to enhance the flexibility of the UI code written, by adding a layer that separates the queries and information used to interact with the backend from the UI code, moving it to a separated JSON file.
3
+
4
+ The JSON file (typically called `elements.json`) can be generated from a spreadsheet used to simplify the data management for a project UI.
5
+
6
+
7
+ ## How do I get set up? ###
8
+ To install this package run `npm i @j2inn/resolvable-ui-elements`
9
+
10
+ ## Where do I get more info? ###
11
+ See: https://finproducts.atlassian.net/wiki/spaces/ECO/pages/32881311778/Element+Types
12
+
13
+ ## Codebase Structure ##
14
+
15
+ src
16
+ ├── resolvableElements
17
+ │ ├── elements # Element classes implementation
18
+ │ ├── interfacesGeneration # Code for generating interfaces from an elements.json file
19
+ │ ├── react # React hooks to use resolvable elements.
20
+ │ └── ...
21
+ └── ...
22
+
23
+ ## BE libraries dependencies ##
24
+ If you decide to use the Resolver's `evalFuncName` feature, this library should be used in combination with [finOemAuthzExt](https://bitbucket.org/finproducts/finoemauthzext). The pod allows the usage of the wrapper function.
25
+ ```typescript
26
+ /**
27
+ * Function name to be used for expressions eval,
28
+ * used to enable custom backend permission check using elements path
29
+ * @example
30
+ * customEval(\`page/section/elementName\`, parametersDict)
31
+ */
32
+ evalFuncName?: string
33
+ ```
34
+
35
+ ### v1.0.4 ###
36
+ Version 1.0.4 of this library introduces the usage of optional parameters in function evaluation. To be able to use them, [finOemAuthzExt](https://bitbucket.org/finproducts/finoemauthzext) 1.0.2+ should be used for the BE.
@@ -1,20 +1,26 @@
1
1
  import { HDict } from 'haystack-core';
2
2
  import { ResolvableValueElement } from '../ResolvableValueElement';
3
3
  import { UiElementConstructorData, UiElementData } from '../UiElement';
4
+ import { ResolvableExprElementMeta } from './ResolvableExprElementMeta';
4
5
  /**
5
6
  * Resolves to the result of an expression.
6
7
  */
7
8
  export declare class ResolvableExprElement<T extends UiElementData> extends ResolvableValueElement<T> {
8
9
  #private;
9
- static collectionTypes: Set<string>;
10
10
  constructor(data: UiElementConstructorData<T>);
11
11
  refreshes: number;
12
+ protected getMeta: () => ResolvableExprElementMeta;
12
13
  protected doInitialize: (parameters: HDict) => Promise<void>;
13
14
  /**
14
15
  * Checks whether the declared resolvedType of this element is a collection.
15
16
  * @returns true if the resolvedType is a collection.
16
17
  */
17
18
  isExpectedResultACollection: () => boolean;
19
+ /**
20
+ * Checks whether the declared resolvedType of this element is a single value.
21
+ * @returns true if the resolvedType is a value.
22
+ */
23
+ isExpectedResultVal: () => boolean;
18
24
  protected doClose: () => Promise<void>;
19
25
  getParameterList: () => string[];
20
26
  }
@@ -13,44 +13,77 @@ const GRID_VAL_COLUMN_NAME = 'val';
13
13
  * Resolves to the result of an expression.
14
14
  */
15
15
  class ResolvableExprElement extends ResolvableValueElement_1.ResolvableValueElement {
16
- static collectionTypes = new Set(['HGrid', 'HList']);
17
16
  constructor(data) {
18
17
  super(data);
19
18
  }
20
19
  refreshes = 0;
21
20
  #timeout;
21
+ getMeta = () => this._meta;
22
22
  doInitialize = async (parameters) => {
23
+ const { refreshAfter } = this.getMeta();
23
24
  await this.#updateValue(parameters);
25
+ if (refreshAfter) {
26
+ this.#setRefreshTimeout(refreshAfter, parameters);
27
+ }
28
+ };
29
+ #setRefreshTimeout = (refreshAfter, parameters) => {
30
+ this.#timeout = setTimeout(() => {
31
+ this.refreshes++;
32
+ this.#updateValue(parameters);
33
+ this.#setRefreshTimeout(refreshAfter, parameters);
34
+ }, haystack_core_1.HNum.make(refreshAfter, haystack_units_1.second).convertTo(haystack_units_1.millisecond).value);
24
35
  };
25
36
  #updateValue = async (parameters) => {
26
- const { expr, refreshAfter, path } = this
27
- ._meta;
37
+ const { expr, path } = this.getMeta();
28
38
  const grid = await this.resolver.evalExprElement(expr, parameters, path);
29
- // Identify when it's necessary to unpack the result `val` or not
30
- // since the eval wraps the result value in a grid's first dict `val` tag for non-collections.
31
- const shouldUnpackResult = !this.isExpectedResultACollection() &&
32
- grid.hasColumn(GRID_VAL_COLUMN_NAME);
33
- if (shouldUnpackResult) {
34
- this.value = grid[0]?.get(GRID_VAL_COLUMN_NAME);
39
+ this.value = this.#unpackResult(grid);
40
+ };
41
+ /**
42
+ * Unpacks grid if expected `resolvedType` result requires it.
43
+ * @param grid result grid
44
+ * @returns unpacked value
45
+ */
46
+ #unpackResult = (grid) => {
47
+ // Identify when it's necessary to unpack the result from `val` column or not
48
+ if (this.isExpectedResultACollection()) {
49
+ if (!grid.hasColumn(GRID_VAL_COLUMN_NAME)) {
50
+ this.#logValColumnNotFound(grid);
51
+ }
52
+ // Unpack val column into array
53
+ return grid.map((row) => row.get(GRID_VAL_COLUMN_NAME));
35
54
  }
36
- else {
37
- this.value = grid;
55
+ else if (this.isExpectedResultVal()) {
56
+ if (!grid.hasColumn(GRID_VAL_COLUMN_NAME)) {
57
+ this.#logValColumnNotFound(grid);
58
+ }
59
+ // Unpack first dict val column into value
60
+ return grid[0]?.get(GRID_VAL_COLUMN_NAME);
38
61
  }
39
- if (refreshAfter) {
40
- this.#timeout = setTimeout(() => {
41
- this.refreshes++;
42
- this.#updateValue(parameters);
43
- }, haystack_core_1.HNum.make(refreshAfter, haystack_units_1.second).convertTo(haystack_units_1.millisecond).value);
62
+ else {
63
+ // Default to using the grid response as it is
64
+ return grid;
44
65
  }
45
66
  };
67
+ #logValColumnNotFound = (grid) => {
68
+ const { expr } = this.getMeta();
69
+ console.warn(`expected "${GRID_VAL_COLUMN_NAME}" column on expr result not found`, expr, grid);
70
+ grid.inspect();
71
+ };
46
72
  /**
47
73
  * Checks whether the declared resolvedType of this element is a collection.
48
74
  * @returns true if the resolvedType is a collection.
49
75
  */
50
76
  isExpectedResultACollection = () => {
51
- const { resolvedType } = this._meta;
52
- return (ResolvableExprElement.collectionTypes.has(resolvedType) ||
53
- resolvedType.endsWith('[]'));
77
+ const { resolvedType } = this.getMeta();
78
+ return resolvedType.endsWith('[]');
79
+ };
80
+ /**
81
+ * Checks whether the declared resolvedType of this element is a single value.
82
+ * @returns true if the resolvedType is a value.
83
+ */
84
+ isExpectedResultVal = () => {
85
+ const { resolvedType } = this.getMeta();
86
+ return resolvedType !== 'HGrid' && !this.isExpectedResultACollection();
54
87
  };
55
88
  doClose = async () => {
56
89
  if (this.#timeout) {
@@ -58,7 +91,7 @@ class ResolvableExprElement extends ResolvableValueElement_1.ResolvableValueElem
58
91
  }
59
92
  };
60
93
  getParameterList = () => {
61
- const { expr } = this._meta;
94
+ const { expr } = this.getMeta();
62
95
  const parameters = [];
63
96
  if (expr) {
64
97
  (0, resolveTemplatedExpression_1.replaceTemplateVariables)(expr, (_, match) => {
@@ -1 +1 @@
1
- {"version":3,"file":"ResolvableExprElement.js","sourceRoot":"","sources":["../../../../src/resolvableElements/elements/expr/ResolvableExprElement.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iDAA2C;AAC3C,mDAAoD;AACpD,iFAA2E;AAE3E,sEAAkE;AAIlE,MAAM,oBAAoB,GAAG,KAAK,CAAA;AAElC;;GAEG;AACH,MAAa,qBAEX,SAAQ,+CAAyB;IAClC,MAAM,CAAC,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;IAEpD,YAAY,IAAiC;QAC5C,KAAK,CAAC,IAAI,CAAC,CAAA;IACZ,CAAC;IAED,SAAS,GAAG,CAAC,CAAA;IACb,QAAQ,CAAS;IAEP,YAAY,GAAG,KAAK,EAAE,UAAiB,EAAiB,EAAE;QACnE,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;IACpC,CAAC,CAAA;IAED,YAAY,GAAG,KAAK,EAAE,UAAiB,EAAiB,EAAE;QACzD,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,IAAI;aACvC,KAAkC,CAAA;QAEpC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,CAAA;QAExE,iEAAiE;QACjE,8FAA8F;QAC9F,MAAM,kBAAkB,GACvB,CAAC,IAAI,CAAC,2BAA2B,EAAE;YACnC,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAA;QACrC,IAAI,kBAAkB,EAAE;YACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,oBAAoB,CAAC,CAAA;S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YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IACnC,CAAC,CAAA;IAED;;;OAGG;IACH,mBAAmB,GAAG,GAAY,EAAE;QACnC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;QAEvC,OAAO,YAAY,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,2BAA2B,EAAE,CAAA;IACvE,CAAC,CAAA;IAES,OAAO,GAAG,KAAK,IAAmB,EAAE;QAC7C,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClB,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;SAC3B;IACF,CAAC,CAAA;IAED,gBAAgB,GAAmB,GAAG,EAAE;QACvC,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;QAE/B,MAAM,UAAU,GAAa,EAAE,CAAA;QAE/B,IAAI,IAAI,EAAE;YACT,IAAA,qDAAwB,EAAC,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;gBAC3C,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;gBACtB,OAAO,EAAE,CAAA;YACV,CAAC,CAAC,CAAA;SACF;QAED,OAAO,UAAU,CAAA;IAClB,CAAC,CAAA;CACD;AAlHD,sDAkHC"}
@@ -1,20 +1,26 @@
1
1
  import { HDict } from 'haystack-core';
2
2
  import { ResolvableValueElement } from '../ResolvableValueElement';
3
3
  import { UiElementConstructorData, UiElementData } from '../UiElement';
4
+ import { ResolvableExprElementMeta } from './ResolvableExprElementMeta';
4
5
  /**
5
6
  * Resolves to the result of an expression.
6
7
  */
7
8
  export declare class ResolvableExprElement<T extends UiElementData> extends ResolvableValueElement<T> {
8
9
  #private;
9
- static collectionTypes: Set<string>;
10
10
  constructor(data: UiElementConstructorData<T>);
11
11
  refreshes: number;
12
+ protected getMeta: () => ResolvableExprElementMeta;
12
13
  protected doInitialize: (parameters: HDict) => Promise<void>;
13
14
  /**
14
15
  * Checks whether the declared resolvedType of this element is a collection.
15
16
  * @returns true if the resolvedType is a collection.
16
17
  */
17
18
  isExpectedResultACollection: () => boolean;
19
+ /**
20
+ * Checks whether the declared resolvedType of this element is a single value.
21
+ * @returns true if the resolvedType is a value.
22
+ */
23
+ isExpectedResultVal: () => boolean;
18
24
  protected doClose: () => Promise<void>;
19
25
  getParameterList: () => string[];
20
26
  }
@@ -10,44 +10,77 @@ const GRID_VAL_COLUMN_NAME = 'val';
10
10
  * Resolves to the result of an expression.
11
11
  */
12
12
  export class ResolvableExprElement extends ResolvableValueElement {
13
- static collectionTypes = new Set(['HGrid', 'HList']);
14
13
  constructor(data) {
15
14
  super(data);
16
15
  }
17
16
  refreshes = 0;
18
17
  #timeout;
18
+ getMeta = () => this._meta;
19
19
  doInitialize = async (parameters) => {
20
+ const { refreshAfter } = this.getMeta();
20
21
  await this.#updateValue(parameters);
22
+ if (refreshAfter) {
23
+ this.#setRefreshTimeout(refreshAfter, parameters);
24
+ }
25
+ };
26
+ #setRefreshTimeout = (refreshAfter, parameters) => {
27
+ this.#timeout = setTimeout(() => {
28
+ this.refreshes++;
29
+ this.#updateValue(parameters);
30
+ this.#setRefreshTimeout(refreshAfter, parameters);
31
+ }, HNum.make(refreshAfter, second).convertTo(millisecond).value);
21
32
  };
22
33
  #updateValue = async (parameters) => {
23
- const { expr, refreshAfter, path } = this
24
- ._meta;
34
+ const { expr, path } = this.getMeta();
25
35
  const grid = await this.resolver.evalExprElement(expr, parameters, path);
26
- // Identify when it's necessary to unpack the result `val` or not
27
- // since the eval wraps the result value in a grid's first dict `val` tag for non-collections.
28
- const shouldUnpackResult = !this.isExpectedResultACollection() &&
29
- grid.hasColumn(GRID_VAL_COLUMN_NAME);
30
- if (shouldUnpackResult) {
31
- this.value = grid[0]?.get(GRID_VAL_COLUMN_NAME);
36
+ this.value = this.#unpackResult(grid);
37
+ };
38
+ /**
39
+ * Unpacks grid if expected `resolvedType` result requires it.
40
+ * @param grid result grid
41
+ * @returns unpacked value
42
+ */
43
+ #unpackResult = (grid) => {
44
+ // Identify when it's necessary to unpack the result from `val` column or not
45
+ if (this.isExpectedResultACollection()) {
46
+ if (!grid.hasColumn(GRID_VAL_COLUMN_NAME)) {
47
+ this.#logValColumnNotFound(grid);
48
+ }
49
+ // Unpack val column into array
50
+ return grid.map((row) => row.get(GRID_VAL_COLUMN_NAME));
32
51
  }
33
- else {
34
- this.value = grid;
52
+ else if (this.isExpectedResultVal()) {
53
+ if (!grid.hasColumn(GRID_VAL_COLUMN_NAME)) {
54
+ this.#logValColumnNotFound(grid);
55
+ }
56
+ // Unpack first dict val column into value
57
+ return grid[0]?.get(GRID_VAL_COLUMN_NAME);
35
58
  }
36
- if (refreshAfter) {
37
- this.#timeout = setTimeout(() => {
38
- this.refreshes++;
39
- this.#updateValue(parameters);
40
- }, HNum.make(refreshAfter, second).convertTo(millisecond).value);
59
+ else {
60
+ // Default to using the grid response as it is
61
+ return grid;
41
62
  }
42
63
  };
64
+ #logValColumnNotFound = (grid) => {
65
+ const { expr } = this.getMeta();
66
+ console.warn(`expected "${GRID_VAL_COLUMN_NAME}" column on expr result not found`, expr, grid);
67
+ grid.inspect();
68
+ };
43
69
  /**
44
70
  * Checks whether the declared resolvedType of this element is a collection.
45
71
  * @returns true if the resolvedType is a collection.
46
72
  */
47
73
  isExpectedResultACollection = () => {
48
- const { resolvedType } = this._meta;
49
- return (ResolvableExprElement.collectionTypes.has(resolvedType) ||
50
- resolvedType.endsWith('[]'));
74
+ const { resolvedType } = this.getMeta();
75
+ return resolvedType.endsWith('[]');
76
+ };
77
+ /**
78
+ * Checks whether the declared resolvedType of this element is a single value.
79
+ * @returns true if the resolvedType is a value.
80
+ */
81
+ isExpectedResultVal = () => {
82
+ const { resolvedType } = this.getMeta();
83
+ return resolvedType !== 'HGrid' && !this.isExpectedResultACollection();
51
84
  };
52
85
  doClose = async () => {
53
86
  if (this.#timeout) {
@@ -55,7 +88,7 @@ export class ResolvableExprElement extends ResolvableValueElement {
55
88
  }
56
89
  };
57
90
  getParameterList = () => {
58
- const { expr } = this._meta;
91
+ const { expr } = this.getMeta();
59
92
  const parameters = [];
60
93
  if (expr) {
61
94
  replaceTemplateVariables(expr, (_, match) => {
@@ -1 +1 @@
1
- {"version":3,"file":"ResolvableExprElement.js","sourceRoot":"","sources":["../../../../src/resolvableElements/elements/expr/ResolvableExprElement.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAS,IAAI,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAA;AAE3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAIlE,MAAM,oBAAoB,GAAG,KAAK,CAAA;AAElC;;GAEG;AACH,MAAM,OAAO,qBAEX,SAAQ,sBAAyB;IAClC,MAAM,CAAC,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;IAEpD,YAAY,IAAiC;QAC5C,KAAK,CAAC,IAAI,CAAC,CAAA;IACZ,CAAC;IAED,SAAS,GAAG,CAAC,CAAA;IACb,QAAQ,CAAS;IAEP,YAAY,GAAG,KAAK,EAAE,UAAiB,EAAiB,EAAE;QACnE,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;IACpC,CAAC,CAAA;IAED,YAAY,GAAG,KAAK,EAAE,UAAiB,EAAiB,EAAE;QACzD,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,IAAI;aACvC,KAAkC,CAAA;QAEpC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,CAAA;QAExE,iEAAiE;QACjE,8FAA8F;QAC9F,MAAM,kBAAkB,GACvB,CAAC,IAAI,CAAC,2B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AAO,EAAE,CAAA;YACV,CAAC,CAAC,CAAA;SACF;QAED,OAAO,UAAU,CAAA;IAClB,CAAC,CAAA"}
1
+ {"version":3,"file":"ResolvableExprElement.js","sourceRoot":"","sources":["../../../../src/resolvableElements/elements/expr/ResolvableExprElement.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAgB,IAAI,EAAQ,MAAM,eAAe,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAA;AAE3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAIlE,MAAM,oBAAoB,GAAG,KAAK,CAAA;AAElC;;GAEG;AACH,MAAM,OAAO,qBAEX,SAAQ,sBAAyB;IAClC,YAAY,IAAiC;QAC5C,KAAK,CAAC,IAAI,CAAC,CAAA;IACZ,CAAC;IAED,SAAS,GAAG,CAAC,CAAA;IACb,QAAQ,CAAS;IAEP,OAAO,GAAG,GAA8B,EAAE,CACnD,IAAI,CAAC,KAAkC,CAAA;IAE9B,YAAY,GAAG,KAAK,EAAE,UAAiB,EAAiB,EAAE;QACnE,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;QAEvC,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;QAEnC,IAAI,YAAY,EAAE;YACjB,IAAI,CAAC,kBAAkB,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;SACjD;IACF,CAAC,CAAA;IAED,kBAAkB,GAAG,CAAC,YAAoB,EAAE,UAAiB,EAAE,EAAE;QAChE,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,GAAG,EAAE;YAC/B,IAAI,CAAC,SAAS,EAAE,CAAA;YAChB,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;YAC7B,IAAI,CAAC,kBAAkB,CAAC,YAAY,EAAE,UAAU,CAAC,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"description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -49,4 +49,4 @@
49
49
  "ts-jest": "^28.0.8",
50
50
  "typescript": "^4.8.2"
51
51
  }
52
- }
52
+ }