@beseif-solutions/prow-core 1.0.0 → 1.0.2
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/entities/credentials.d.ts +1 -1
- package/dist/entities/credentials.js +2 -2
- package/dist/entities/events.d.ts +1 -1
- package/dist/entities/events.js +2 -2
- package/dist/entities/source.d.ts +1 -1
- package/dist/entities/source.js +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +6 -6
- package/dist/minified-utils/context.js +20 -11
- package/dist/minified-utils/fields.d.ts +16 -46
- package/dist/minified-utils/fields.js +0 -615
- package/dist/minified-utils/validation.d.ts +31 -0
- package/dist/minified-utils/validation.js +617 -0
- package/package.json +1 -1
- package/src/entities/credentials.ts +2 -1
- package/src/entities/events.ts +2 -1
- package/src/entities/source.ts +2 -1
- package/src/index.ts +3 -2
- package/src/minified-utils/context.ts +22 -13
- package/src/minified-utils/fields.ts +17 -668
- package/src/minified-utils/validation.ts +653 -0
|
@@ -39,6 +39,15 @@ export const isDynamic = (data: any, processed: boolean): data is Dynamic => {
|
|
|
39
39
|
return !error;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
+
const shouldInfer = (field: Field, value: any): boolean =>
|
|
43
|
+
field.as_array && _.isArray(value)
|
|
44
|
+
|| field.type === `dict` && _.isObject(value)
|
|
45
|
+
|| field.type === `file` && _.isObject(value)
|
|
46
|
+
|| field.type === `number` && typeof value === `number`
|
|
47
|
+
|| field.type === `string` && typeof value === `string`
|
|
48
|
+
|| field.type === `boolean` && typeof value === `boolean`
|
|
49
|
+
|| field.type === `any`;
|
|
50
|
+
|
|
42
51
|
const MAX_RESOLVE_DEPTH = 10;
|
|
43
52
|
|
|
44
53
|
class Context {
|
|
@@ -49,9 +58,9 @@ class Context {
|
|
|
49
58
|
let serialized = false;
|
|
50
59
|
let unresolved: string;
|
|
51
60
|
|
|
52
|
-
const dynamicSource = isDynamic(source, false);
|
|
61
|
+
const dynamicSource = field.type === `dict` && field.items && isDynamic(source, false);
|
|
53
62
|
|
|
54
|
-
if ((_.isObject(source) || _.isArray(source)) && field.type === `dict` &&
|
|
63
|
+
if (((_.isObject(source) || _.isArray(source)) && field.type === `dict` && !field.items) || dynamicSource) {
|
|
55
64
|
serialized = true;
|
|
56
65
|
unresolved = JSON.stringify(source);
|
|
57
66
|
} else if (typeof source === `string`) {
|
|
@@ -68,16 +77,7 @@ class Context {
|
|
|
68
77
|
const path = getPath(unresolved);
|
|
69
78
|
if (_.has(clonedData, path)) {
|
|
70
79
|
const get = _.get(clonedData, path);
|
|
71
|
-
|
|
72
|
-
field.as_array && _.isArray(get)
|
|
73
|
-
|| field.type === `dict` && _.isObject(get)
|
|
74
|
-
|| field.type === `file` && _.isObject(get)
|
|
75
|
-
|| field.type === `number` && typeof get === `number`
|
|
76
|
-
|| field.type === `string` && typeof get === `string`
|
|
77
|
-
|| field.type === `boolean` && typeof get === `boolean`
|
|
78
|
-
|| field.type === `any`;
|
|
79
|
-
|
|
80
|
-
if (shouldInfer) {
|
|
80
|
+
if (shouldInfer(field, get)) {
|
|
81
81
|
resolved = get;
|
|
82
82
|
} else {
|
|
83
83
|
resolved = _.toString(get);
|
|
@@ -111,8 +111,17 @@ class Context {
|
|
|
111
111
|
const item: Record<string, any> = {};
|
|
112
112
|
for (const [key, map] of Object.entries(response.mapping)) {
|
|
113
113
|
if (map.type === `property`) {
|
|
114
|
+
const child = field.items.find((fi) => fi.key === key);
|
|
115
|
+
if (!child) { continue; }
|
|
116
|
+
|
|
114
117
|
const prop = _.get(i, map.value);
|
|
115
|
-
if (typeof prop !== `undefined`) {
|
|
118
|
+
if (typeof prop !== `undefined`) {
|
|
119
|
+
if (shouldInfer(child, prop)) {
|
|
120
|
+
item[key] = prop;
|
|
121
|
+
} else {
|
|
122
|
+
item[key] = _.toString(prop);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
116
125
|
} else if (map.type === `literal`) {
|
|
117
126
|
item[key] = map.value;
|
|
118
127
|
}
|