@beseif-solutions/prow-core 0.3.13 → 0.3.14

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.
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const handlebars_1 = __importDefault(require("handlebars"));
7
6
  const lodash_1 = __importDefault(require("lodash"));
8
7
  class Context {
9
8
  constructor() {
10
9
  this.resolve = (field, source, data) => {
10
+ console.log(`Resolve for field ${field.key}`, source, data);
11
11
  if (lodash_1.default.isNull(source) || lodash_1.default.isUndefined(source)) {
12
12
  return source;
13
13
  }
@@ -27,36 +27,36 @@ class Context {
27
27
  return source;
28
28
  }
29
29
  const clonedData = lodash_1.default.cloneDeep(data);
30
+ const parts = Array.from(unresolved.match(/{{[^}]+}}|[^{}]+/g) || []);
30
31
  let resolved = unresolved;
31
- const process = handlebars_1.default.parseWithoutProcessing(unresolved);
32
- for (const x of process.body) {
33
- if (x.type === `MustacheStatement`) {
34
- const path = x[`path`].original;
35
- const expression = x[`escaped`] ? `{{${path}}}` : `{{{${path}}}}`;
36
- const get = lodash_1.default.get(clonedData, path);
37
- if (get) {
38
- const shouldInfer = field.as_array && lodash_1.default.isArray(get)
39
- || field.type === `dict` && lodash_1.default.isObject(get)
40
- || field.type === `file` && lodash_1.default.isObject(get)
41
- || field.type === `number` && typeof get === `number`
42
- || field.type === `string` && typeof get === `string`
43
- || field.type === `boolean` && typeof get === `boolean`
44
- || field.type === `any`;
45
- if (unresolved === expression && shouldInfer) {
46
- resolved = get;
47
- break;
48
- }
49
- else {
50
- if (serialized) {
51
- resolved = resolved.replace(`"${expression}"`, lodash_1.default.isObject(get) ? JSON.stringify(get) : `"${get}"`);
52
- }
53
- resolved = resolved.replace(expression, get);
54
- }
32
+ for (const expression of parts) {
33
+ if (!expression.startsWith(`{{`)) {
34
+ continue;
35
+ }
36
+ const path = expression.replace(/^{+/g, ``).replace(/}+$/g, ``);
37
+ const get = lodash_1.default.get(clonedData, path);
38
+ if (get) {
39
+ const shouldInfer = field.as_array && lodash_1.default.isArray(get)
40
+ || field.type === `dict` && lodash_1.default.isObject(get)
41
+ || field.type === `file` && lodash_1.default.isObject(get)
42
+ || field.type === `number` && typeof get === `number`
43
+ || field.type === `string` && typeof get === `string`
44
+ || field.type === `boolean` && typeof get === `boolean`
45
+ || field.type === `any`;
46
+ if (unresolved === expression && shouldInfer) {
47
+ resolved = get;
48
+ break;
55
49
  }
56
50
  else {
57
- resolved = resolved.replace(expression, ``);
51
+ if (serialized) {
52
+ resolved = resolved.replace(`"${expression}"`, lodash_1.default.isObject(get) ? JSON.stringify(get) : `"${get}"`);
53
+ }
54
+ resolved = resolved.replace(expression, get);
58
55
  }
59
56
  }
57
+ else {
58
+ resolved = resolved.replace(expression, ``);
59
+ }
60
60
  }
61
61
  const parsed = serialized ? JSON.parse(resolved) : resolved;
62
62
  return (typeof resolved === `string` ? resolved : JSON.stringify(resolved)).includes(`{{`) ?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beseif-solutions/prow-core",
3
- "version": "0.3.13",
3
+ "version": "0.3.14",
4
4
  "description": "Prow core functionalities and classes",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -17,13 +17,12 @@
17
17
  "author": "",
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
+ "@types/lodash": "^4.14.168",
20
21
  "axios": "^1.7.7",
21
22
  "dotenv": "^16.4.5",
22
- "handlebars": "^4.7.8",
23
23
  "i18n": "^0.15.1",
24
24
  "joi": "^17.13.3",
25
25
  "lodash": "^4.17.21",
26
- "@types/lodash": "^4.14.168",
27
26
  "moment-timezone": "^0.5.46",
28
27
  "ts-node": "^8.10.2"
29
28
  },
@@ -1,10 +1,12 @@
1
- import Handlebars from "handlebars";
2
1
  import _ from "lodash";
3
2
  import { Field } from "./fields";
4
3
 
5
4
  class Context {
6
5
 
7
6
  public readonly resolve = (field: Field, source: any, data: Record<string, any>) => {
7
+
8
+ console.log(`Resolve for field ${field.key}`, source, data);
9
+
8
10
  if (_.isNull(source) || _.isUndefined(source)) { return source; }
9
11
 
10
12
  let serialized = false;
@@ -20,34 +22,34 @@ class Context {
20
22
 
21
23
  const clonedData = _.cloneDeep(data);
22
24
 
25
+
26
+ const parts = Array.from(unresolved.match(/{{[^}]+}}|[^{}]+/g) || []);
27
+
23
28
  let resolved: any = unresolved;
24
- const process = Handlebars.parseWithoutProcessing(unresolved);
25
- for (const x of process.body) {
26
- if (x.type === `MustacheStatement`) {
27
- const path = x[`path`].original;
28
- const expression = x[`escaped`] ? `{{${path}}}` : `{{{${path}}}}`;
29
- const get = _.get(clonedData, path);
30
-
31
- if (get) {
32
- const shouldInfer =
33
- field.as_array && _.isArray(get)
34
- || field.type === `dict` && _.isObject(get)
35
- || field.type === `file` && _.isObject(get)
36
- || field.type === `number` && typeof get === `number`
37
- || field.type === `string` && typeof get === `string`
38
- || field.type === `boolean` && typeof get === `boolean`
39
- || field.type === `any`;
40
-
41
- if (unresolved === expression && shouldInfer) {
42
- resolved = get;
43
- break;
44
- } else {
45
- if (serialized) { resolved = resolved.replace(`"${expression}"`, _.isObject(get) ? JSON.stringify(get) : `"${get}"`); }
46
- resolved = resolved.replace(expression, get);
47
-
48
- }
49
- } else { resolved = resolved.replace(expression, ``); }
50
- }
29
+ for (const expression of parts) {
30
+ if (!expression.startsWith(`{{`)) { continue; }
31
+ const path = expression.replace(/^{+/g, ``).replace(/}+$/g, ``);
32
+ const get = _.get(clonedData, path);
33
+
34
+ if (get) {
35
+ const shouldInfer =
36
+ field.as_array && _.isArray(get)
37
+ || field.type === `dict` && _.isObject(get)
38
+ || field.type === `file` && _.isObject(get)
39
+ || field.type === `number` && typeof get === `number`
40
+ || field.type === `string` && typeof get === `string`
41
+ || field.type === `boolean` && typeof get === `boolean`
42
+ || field.type === `any`;
43
+
44
+ if (unresolved === expression && shouldInfer) {
45
+ resolved = get;
46
+ break;
47
+ } else {
48
+ if (serialized) { resolved = resolved.replace(`"${expression}"`, _.isObject(get) ? JSON.stringify(get) : `"${get}"`); }
49
+ resolved = resolved.replace(expression, get);
50
+
51
+ }
52
+ } else { resolved = resolved.replace(expression, ``); }
51
53
  }
52
54
 
53
55
  const parsed = serialized ? JSON.parse(resolved) : resolved;