@beseif-solutions/prow-core 0.3.13 → 0.3.15
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/dist/minified-utils/context.js +25 -26
- package/package.json +2 -3
- package/src/minified-utils/context.ts +26 -27
|
@@ -3,7 +3,6 @@ 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() {
|
|
@@ -27,36 +26,36 @@ class Context {
|
|
|
27
26
|
return source;
|
|
28
27
|
}
|
|
29
28
|
const clonedData = lodash_1.default.cloneDeep(data);
|
|
29
|
+
const parts = Array.from(unresolved.match(/{{[^}]+}}|[^{}]+/g) || []);
|
|
30
30
|
let resolved = unresolved;
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
}
|
|
31
|
+
for (const expression of parts) {
|
|
32
|
+
if (!expression.startsWith(`{{`)) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const path = expression.replace(/^{+/g, ``).replace(/}+$/g, ``);
|
|
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;
|
|
55
48
|
}
|
|
56
49
|
else {
|
|
57
|
-
|
|
50
|
+
if (serialized) {
|
|
51
|
+
resolved = resolved.replace(`"${expression}"`, lodash_1.default.isObject(get) ? JSON.stringify(get) : `"${get}"`);
|
|
52
|
+
}
|
|
53
|
+
resolved = resolved.replace(expression, get);
|
|
58
54
|
}
|
|
59
55
|
}
|
|
56
|
+
else {
|
|
57
|
+
resolved = resolved.replace(expression, ``);
|
|
58
|
+
}
|
|
60
59
|
}
|
|
61
60
|
const parsed = serialized ? JSON.parse(resolved) : resolved;
|
|
62
61
|
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.
|
|
3
|
+
"version": "0.3.15",
|
|
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,4 +1,3 @@
|
|
|
1
|
-
import Handlebars from "handlebars";
|
|
2
1
|
import _ from "lodash";
|
|
3
2
|
import { Field } from "./fields";
|
|
4
3
|
|
|
@@ -20,34 +19,34 @@ class Context {
|
|
|
20
19
|
|
|
21
20
|
const clonedData = _.cloneDeep(data);
|
|
22
21
|
|
|
23
|
-
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
22
|
|
|
41
|
-
|
|
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);
|
|
23
|
+
const parts = Array.from(unresolved.match(/{{[^}]+}}|[^{}]+/g) || []);
|
|
47
24
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
25
|
+
let resolved: any = unresolved;
|
|
26
|
+
for (const expression of parts) {
|
|
27
|
+
if (!expression.startsWith(`{{`)) { continue; }
|
|
28
|
+
const path = expression.replace(/^{+/g, ``).replace(/}+$/g, ``);
|
|
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, ``); }
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
const parsed = serialized ? JSON.parse(resolved) : resolved;
|