@j2inn/resolvable-ui-elements 1.0.3 → 1.0.4

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
@@ -20,3 +20,17 @@ See: https://finproducts.atlassian.net/wiki/spaces/ECO/pages/32881311778/Element
20
20
  │ └── ...
21
21
  └── ...
22
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,10 +1,13 @@
1
1
  import { HDict } from 'haystack-core';
2
2
  export declare const REG_EXPR_MATCHING_TEMPLATE: RegExp;
3
3
  /**
4
- * Replaces variables (defined as <$parameterName>) in an expression with the values given in the parameters dict.
5
- * The HVal.toAxon function is used for conversion to a string.
4
+ * Replaces variables (defined as {{parameterName}}) in an expression with the values given in the parameters dict.
5
+ * The HVal.toAxon function is used for conversion to a string. Optional parameters can be marked using a '?'
6
+ * after the parameter name. They can safely be omitted in the parameters Dict.
6
7
  * @example
7
- * resolveTemplatedExpression("func({{num}})", HDict.make({num: HNum.make("22")})) => "func(22)"
8
+ * resolveTemplatedExpression("func({{num}})", HDict.make({num: HNum.make(22)})) => "func(22)"
9
+ * @example
10
+ * resolveTemplatedExpression("func({{num}}, {{unit?}})", HDict.make({num: HNum.make(22)})) => "func(22, null)"
8
11
  * @param expr the axon expression
9
12
  * @param params the parameters expressed as dict
10
13
  * @returns the axon expression resolved with the specified params
@@ -16,4 +19,4 @@ export declare const resolveTemplateExpression: (expr: string, parameters?: HDic
16
19
  * @param replacer
17
20
  * @returns a new string containing the compiled template string
18
21
  */
19
- export declare const replaceTemplateVariables: (templateString: string, replacer: (substring: string, match: string) => string) => string;
22
+ export declare const replaceTemplateVariables: (templateString: string, replacer: (substring: string, match: string, optional: string) => string) => string;
@@ -4,23 +4,31 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.replaceTemplateVariables = exports.resolveTemplateExpression = exports.REG_EXPR_MATCHING_TEMPLATE = void 0;
7
- exports.REG_EXPR_MATCHING_TEMPLATE = new RegExp('{{([^{}]*)}}', 'g');
7
+ const haystack_core_1 = require("haystack-core");
8
+ exports.REG_EXPR_MATCHING_TEMPLATE = new RegExp(/{{([^{}?]*)(\??)}}/, 'g');
8
9
  /**
9
- * Replaces variables (defined as <$parameterName>) in an expression with the values given in the parameters dict.
10
- * The HVal.toAxon function is used for conversion to a string.
10
+ * Replaces variables (defined as {{parameterName}}) in an expression with the values given in the parameters dict.
11
+ * The HVal.toAxon function is used for conversion to a string. Optional parameters can be marked using a '?'
12
+ * after the parameter name. They can safely be omitted in the parameters Dict.
11
13
  * @example
12
- * resolveTemplatedExpression("func({{num}})", HDict.make({num: HNum.make("22")})) => "func(22)"
14
+ * resolveTemplatedExpression("func({{num}})", HDict.make({num: HNum.make(22)})) => "func(22)"
15
+ * @example
16
+ * resolveTemplatedExpression("func({{num}}, {{unit?}})", HDict.make({num: HNum.make(22)})) => "func(22, null)"
13
17
  * @param expr the axon expression
14
18
  * @param params the parameters expressed as dict
15
19
  * @returns the axon expression resolved with the specified params
16
20
  */
17
21
  const resolveTemplateExpression = (expr, parameters) => {
18
22
  const paramDict = parameters;
19
- return (0, exports.replaceTemplateVariables)(expr, (_substring, match) => {
23
+ return (0, exports.replaceTemplateVariables)(expr, (_substring, match, optional) => {
24
+ const isOptional = optional === '?';
20
25
  const parameter = paramDict?.get(match)?.toAxon();
21
26
  if (parameter != null) {
22
27
  return parameter;
23
28
  }
29
+ else if (isOptional) {
30
+ return haystack_core_1.AXON_NULL;
31
+ }
24
32
  throw new Error(`ERROR: Missing parameter: ${match} in ${paramDict?.toAxon()}`);
25
33
  });
26
34
  };
@@ -1 +1 @@
1
- {"version":3,"file":"resolveTemplatedExpression.js","sourceRoot":"","sources":["../../src/resolvableElements/resolveTemplatedExpression.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAIU,QAAA,0BAA0B,GAAG,IAAI,MAAM,CAAC,cAAc,EAAE,GAAG,CAAC,CAAA;AAEzE;;;;;;;;GAQG;AACI,MAAM,yBAAyB,GAAG,CACxC,IAAY,EACZ,UAAkB,EACT,EAAE;IACX,MAAM,SAAS,GAAG,UAAU,CAAA;IAE5B,OAAO,IAAA,gCAAwB,EAC9B,IAAI,EACJ,CAAC,UAAkB,EAAE,KAAa,EAAE,EAAE;QACrC,MAAM,SAAS,GAAG,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;QACjD,IAAI,SAAS,IAAI,IAAI,EAAE;YACtB,OAAO,SAAS,CAAA;SAChB;QACD,MAAM,IAAI,KAAK,CACd,6BAA6B,KAAK,OAAO,SAAS,EAAE,MAAM,EAAE,EAAE,CAC9D,CAAA;IACF,CAAC,CACD,CAAA;AACF,CAAC,CAAA;AAlBY,QAAA,yBAAyB,6BAkBrC;AAED;;;;;GAKG;AACI,MAAM,wBAAwB,GAAG,CACvC,cAAsB,EACtB,QAAsD,EAC7C,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,kCAA0B,EAAE,QAAQ,CAAC,CAAA;AAH5D,QAAA,wBAAwB,4BAGoC"}
1
+ {"version":3,"file":"resolveTemplatedExpression.js","sourceRoot":"","sources":["../../src/resolvableElements/resolveTemplatedExpression.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iDAAgD;AAEnC,QAAA,0BAA0B,GAAG,IAAI,MAAM,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAA;AAE/E;;;;;;;;;;;GAWG;AACI,MAAM,yBAAyB,GAAG,CACxC,IAAY,EACZ,UAAkB,EACT,EAAE;IACX,MAAM,SAAS,GAAG,UAAU,CAAA;IAE5B,OAAO,IAAA,gCAAwB,EAC9B,IAAI,EACJ,CAAC,UAAkB,EAAE,KAAa,EAAE,QAAgB,EAAE,EAAE;QACvD,MAAM,UAAU,GAAG,QAAQ,KAAK,GAAG,CAAA;QACnC,MAAM,SAAS,GAAG,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;QACjD,IAAI,SAAS,IAAI,IAAI,EAAE;YACtB,OAAO,SAAS,CAAA;SAChB;aAAM,IAAI,UAAU,EAAE;YACtB,OAAO,yBAAS,CAAA;SAChB;QACD,MAAM,IAAI,KAAK,CACd,6BAA6B,KAAK,OAAO,SAAS,EAAE,MAAM,EAAE,EAAE,CAC9D,CAAA;IACF,CAAC,CACD,CAAA;AACF,CAAC,CAAA;AArBY,QAAA,yBAAyB,6BAqBrC;AAED;;;;;GAKG;AACI,MAAM,wBAAwB,GAAG,CACvC,cAAsB,EACtB,QAAwE,EAC/D,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,kCAA0B,EAAE,QAAQ,CAAC,CAAA;AAH5D,QAAA,wBAAwB,4BAGoC"}
@@ -1,10 +1,13 @@
1
1
  import { HDict } from 'haystack-core';
2
2
  export declare const REG_EXPR_MATCHING_TEMPLATE: RegExp;
3
3
  /**
4
- * Replaces variables (defined as <$parameterName>) in an expression with the values given in the parameters dict.
5
- * The HVal.toAxon function is used for conversion to a string.
4
+ * Replaces variables (defined as {{parameterName}}) in an expression with the values given in the parameters dict.
5
+ * The HVal.toAxon function is used for conversion to a string. Optional parameters can be marked using a '?'
6
+ * after the parameter name. They can safely be omitted in the parameters Dict.
6
7
  * @example
7
- * resolveTemplatedExpression("func({{num}})", HDict.make({num: HNum.make("22")})) => "func(22)"
8
+ * resolveTemplatedExpression("func({{num}})", HDict.make({num: HNum.make(22)})) => "func(22)"
9
+ * @example
10
+ * resolveTemplatedExpression("func({{num}}, {{unit?}})", HDict.make({num: HNum.make(22)})) => "func(22, null)"
8
11
  * @param expr the axon expression
9
12
  * @param params the parameters expressed as dict
10
13
  * @returns the axon expression resolved with the specified params
@@ -16,4 +19,4 @@ export declare const resolveTemplateExpression: (expr: string, parameters?: HDic
16
19
  * @param replacer
17
20
  * @returns a new string containing the compiled template string
18
21
  */
19
- export declare const replaceTemplateVariables: (templateString: string, replacer: (substring: string, match: string) => string) => string;
22
+ export declare const replaceTemplateVariables: (templateString: string, replacer: (substring: string, match: string, optional: string) => string) => string;
@@ -1,23 +1,31 @@
1
1
  /*
2
2
  * Copyright (c) 2022, J2 Innovations. All Rights Reserved
3
3
  */
4
- export const REG_EXPR_MATCHING_TEMPLATE = new RegExp('{{([^{}]*)}}', 'g');
4
+ import { AXON_NULL } from 'haystack-core';
5
+ export const REG_EXPR_MATCHING_TEMPLATE = new RegExp(/{{([^{}?]*)(\??)}}/, 'g');
5
6
  /**
6
- * Replaces variables (defined as <$parameterName>) in an expression with the values given in the parameters dict.
7
- * The HVal.toAxon function is used for conversion to a string.
7
+ * Replaces variables (defined as {{parameterName}}) in an expression with the values given in the parameters dict.
8
+ * The HVal.toAxon function is used for conversion to a string. Optional parameters can be marked using a '?'
9
+ * after the parameter name. They can safely be omitted in the parameters Dict.
8
10
  * @example
9
- * resolveTemplatedExpression("func({{num}})", HDict.make({num: HNum.make("22")})) => "func(22)"
11
+ * resolveTemplatedExpression("func({{num}})", HDict.make({num: HNum.make(22)})) => "func(22)"
12
+ * @example
13
+ * resolveTemplatedExpression("func({{num}}, {{unit?}})", HDict.make({num: HNum.make(22)})) => "func(22, null)"
10
14
  * @param expr the axon expression
11
15
  * @param params the parameters expressed as dict
12
16
  * @returns the axon expression resolved with the specified params
13
17
  */
14
18
  export const resolveTemplateExpression = (expr, parameters) => {
15
19
  const paramDict = parameters;
16
- return replaceTemplateVariables(expr, (_substring, match) => {
20
+ return replaceTemplateVariables(expr, (_substring, match, optional) => {
21
+ const isOptional = optional === '?';
17
22
  const parameter = paramDict?.get(match)?.toAxon();
18
23
  if (parameter != null) {
19
24
  return parameter;
20
25
  }
26
+ else if (isOptional) {
27
+ return AXON_NULL;
28
+ }
21
29
  throw new Error(`ERROR: Missing parameter: ${match} in ${paramDict?.toAxon()}`);
22
30
  });
23
31
  };
@@ -1 +1 @@
1
- {"version":3,"file":"resolveTemplatedExpression.js","sourceRoot":"","sources":["../../src/resolvableElements/resolveTemplatedExpression.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,MAAM,CAAC,cAAc,EAAE,GAAG,CAAC,CAAA;AAEzE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACxC,IAAY,EACZ,UAAkB,EACT,EAAE;IACX,MAAM,SAAS,GAAG,UAAU,CAAA;IAE5B,OAAO,wBAAwB,CAC9B,IAAI,EACJ,CAAC,UAAkB,EAAE,KAAa,EAAE,EAAE;QACrC,MAAM,SAAS,GAAG,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;QACjD,IAAI,SAAS,IAAI,IAAI,EAAE;YACtB,OAAO,SAAS,CAAA;SAChB;QACD,MAAM,IAAI,KAAK,CACd,6BAA6B,KAAK,OAAO,SAAS,EAAE,MAAM,EAAE,EAAE,CAC9D,CAAA;IACF,CAAC,CACD,CAAA;AACF,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACvC,cAAsB,EACtB,QAAsD,EAC7C,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,0BAA0B,EAAE,QAAQ,CAAC,CAAA"}
1
+ {"version":3,"file":"resolveTemplatedExpression.js","sourceRoot":"","sources":["../../src/resolvableElements/resolveTemplatedExpression.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAS,MAAM,eAAe,CAAA;AAEhD,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,MAAM,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAA;AAE/E;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACxC,IAAY,EACZ,UAAkB,EACT,EAAE;IACX,MAAM,SAAS,GAAG,UAAU,CAAA;IAE5B,OAAO,wBAAwB,CAC9B,IAAI,EACJ,CAAC,UAAkB,EAAE,KAAa,EAAE,QAAgB,EAAE,EAAE;QACvD,MAAM,UAAU,GAAG,QAAQ,KAAK,GAAG,CAAA;QACnC,MAAM,SAAS,GAAG,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;QACjD,IAAI,SAAS,IAAI,IAAI,EAAE;YACtB,OAAO,SAAS,CAAA;SAChB;aAAM,IAAI,UAAU,EAAE;YACtB,OAAO,SAAS,CAAA;SAChB;QACD,MAAM,IAAI,KAAK,CACd,6BAA6B,KAAK,OAAO,SAAS,EAAE,MAAM,EAAE,EAAE,CAC9D,CAAA;IACF,CAAC,CACD,CAAA;AACF,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACvC,cAAsB,EACtB,QAAwE,EAC/D,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,0BAA0B,EAAE,QAAQ,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,52 +1,52 @@
1
- {
2
- "name": "@j2inn/resolvable-ui-elements",
3
- "version": "1.0.3",
4
- "description": "",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "module": "dist_es/index.js",
8
- "scripts": {
9
- "clean": "rimraf ./dist && rimraf ./dist_es",
10
- "prebuild": "npm run clean && npm run lint && npm run test",
11
- "build": "tsc && npm run-script build:es",
12
- "build:es": "tsc --module ESNext --outDir dist_es",
13
- "checktypes": "tsc --noEmit",
14
- "format": "prettier-eslint --list-different --write \"$(pwd)/src/**/*.{ts,tsx,js,jsx}\"",
15
- "lint": "eslint --fix --ext ts,tsx,js,jsx src/",
16
- "test": "jest --passWithNoTests",
17
- "prepack": "npm run lint && npm run test && npm run build"
18
- },
19
- "author": "",
20
- "license": "ISC",
21
- "files": [
22
- "dist/**/*",
23
- "dist_es/**/*"
24
- ],
25
- "peerDependencies": {
26
- "haystack-core": "^2.0.45",
27
- "haystack-nclient": "^3.0.32",
28
- "haystack-react": "^3.0.17",
29
- "haystack-units": "^1.0.22",
30
- "react": "^18.2.0",
31
- "react-dom": "^18.2.0"
32
- },
33
- "devDependencies": {
34
- "@types/jest": "^27.4.0",
35
- "@types/node": "^15.0.2",
36
- "@types/react": "^18.0.18",
37
- "@types/react-dom": "^18.0.6",
38
- "@typescript-eslint/eslint-plugin": "^5.28.0",
39
- "@typescript-eslint/parser": "^5.28.0",
40
- "eslint": "^7.32.0",
41
- "eslint-config-prettier": "^8.3.0",
42
- "eslint-plugin-jest": "^26.1.3",
43
- "eslint-plugin-prettier": "^4.0.0",
44
- "eslint-plugin-react": "^7.29.4",
45
- "prettier": "^2.6.1",
46
- "prettier-eslint": "^13.0.0",
47
- "prettier-eslint-cli": "^5.0.1",
48
- "rimraf": "^3.0.2",
49
- "ts-jest": "^28.0.8",
50
- "typescript": "^4.8.2"
51
- }
52
- }
1
+ {
2
+ "name": "@j2inn/resolvable-ui-elements",
3
+ "version": "1.0.4",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "module": "dist_es/index.js",
8
+ "scripts": {
9
+ "clean": "rimraf ./dist && rimraf ./dist_es",
10
+ "prebuild": "npm run clean && npm run lint && npm run test",
11
+ "build": "tsc && npm run-script build:es",
12
+ "build:es": "tsc --module ESNext --outDir dist_es",
13
+ "checktypes": "tsc --noEmit",
14
+ "format": "prettier-eslint --list-different --write \"$(pwd)/src/**/*.{ts,tsx,js,jsx}\"",
15
+ "lint": "eslint --fix --ext ts,tsx,js,jsx src/",
16
+ "test": "jest --passWithNoTests",
17
+ "prepack": "npm run lint && npm run test && npm run build"
18
+ },
19
+ "author": "",
20
+ "license": "ISC",
21
+ "files": [
22
+ "dist/**/*",
23
+ "dist_es/**/*"
24
+ ],
25
+ "peerDependencies": {
26
+ "haystack-core": "^2.0.45",
27
+ "haystack-nclient": "^3.0.32",
28
+ "haystack-react": "^3.0.17",
29
+ "haystack-units": "^1.0.22",
30
+ "react": "^18.2.0",
31
+ "react-dom": "^18.2.0"
32
+ },
33
+ "devDependencies": {
34
+ "@types/jest": "^27.4.0",
35
+ "@types/node": "^15.0.2",
36
+ "@types/react": "^18.0.18",
37
+ "@types/react-dom": "^18.0.6",
38
+ "@typescript-eslint/eslint-plugin": "^5.28.0",
39
+ "@typescript-eslint/parser": "^5.28.0",
40
+ "eslint": "^7.32.0",
41
+ "eslint-config-prettier": "^8.3.0",
42
+ "eslint-plugin-jest": "^26.1.3",
43
+ "eslint-plugin-prettier": "^4.0.0",
44
+ "eslint-plugin-react": "^7.29.4",
45
+ "prettier": "^2.6.1",
46
+ "prettier-eslint": "^13.0.0",
47
+ "prettier-eslint-cli": "^5.0.1",
48
+ "rimraf": "^3.0.2",
49
+ "ts-jest": "^28.0.8",
50
+ "typescript": "^4.8.2"
51
+ }
52
+ }