@beseif-solutions/prow-core 0.4.6 → 1.0.1
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/index.d.ts +5 -5
- package/dist/index.js +3 -1
- package/dist/minified-utils/context.d.ts +9 -1
- package/dist/minified-utils/context.js +59 -14
- package/package.json +1 -1
- package/src/index.ts +5 -5
- package/src/minified-utils/context.ts +75 -16
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { Core, core } from './core';
|
|
2
2
|
export { CoreFunction, idSchema } from './entities/commons';
|
|
3
|
-
export { Credentials,
|
|
4
|
-
export { Action,
|
|
3
|
+
export { Credentials, credentialsSchema, OAuthCredentials, oauthCredentialsSchema, SessionCredentials, sessionCredentialsSchema, StaticCredentials, staticCredentialsSchema } from './entities/credentials';
|
|
4
|
+
export { Action, actionOutputSchema, actionSchema, AsyncAction, Event, eventSchema, ImmediateTrigger, immediateTriggerSchema, Request, ScheduledTrigger, scheduledTriggerSchema, SyncAction, syncActionSchema, Trigger, triggerOutputSchema, triggerSchema } from './entities/events';
|
|
5
5
|
export { Provider, providerSchema } from './entities/provider';
|
|
6
6
|
export { Source } from './entities/source';
|
|
7
|
-
export { hasExpression, isExpression, split } from './minified-utils/context';
|
|
8
|
-
export {
|
|
9
|
-
export { DEFAULT_LOCALE, LocalizedField, LocalizedProperties,
|
|
7
|
+
export { getPath, hasExpression, isDynamic, isExpression, split } from './minified-utils/context';
|
|
8
|
+
export { alter, Condition, extract, Field, fieldSchema, fieldsSchema, File, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
|
|
9
|
+
export { DEFAULT_LOCALE, i18n, LocalizedField, LocalizedProperties, localizeFields, localizeGroup, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
|
|
10
10
|
export { Properties } from './minified-utils/properties';
|
|
11
11
|
export { Protocol } from './minified-utils/protocol';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Protocol = exports.Properties = exports.localizeProperties = exports.localizeOutputs = exports.localizeInputs = exports.localizeGroup = exports.localizeFields = exports.i18n = exports.DEFAULT_LOCALE = exports.validate = exports.fieldsSchema = exports.fieldSchema = exports.extract = exports.alter = exports.split = exports.isExpression = exports.hasExpression = exports.providerSchema = exports.triggerSchema = exports.triggerOutputSchema = exports.syncActionSchema = exports.scheduledTriggerSchema = exports.immediateTriggerSchema = exports.eventSchema = exports.actionSchema = exports.actionOutputSchema = exports.staticCredentialsSchema = exports.sessionCredentialsSchema = exports.oauthCredentialsSchema = exports.credentialsSchema = exports.idSchema = exports.core = void 0;
|
|
3
|
+
exports.Protocol = exports.Properties = exports.localizeProperties = exports.localizeOutputs = exports.localizeInputs = exports.localizeGroup = exports.localizeFields = exports.i18n = exports.DEFAULT_LOCALE = exports.validate = exports.fieldsSchema = exports.fieldSchema = exports.extract = exports.alter = exports.split = exports.isExpression = exports.isDynamic = exports.hasExpression = exports.getPath = exports.providerSchema = exports.triggerSchema = exports.triggerOutputSchema = exports.syncActionSchema = exports.scheduledTriggerSchema = exports.immediateTriggerSchema = exports.eventSchema = exports.actionSchema = exports.actionOutputSchema = exports.staticCredentialsSchema = exports.sessionCredentialsSchema = exports.oauthCredentialsSchema = exports.credentialsSchema = exports.idSchema = exports.core = void 0;
|
|
4
4
|
var core_1 = require("./core");
|
|
5
5
|
Object.defineProperty(exports, "core", { enumerable: true, get: function () { return core_1.core; } });
|
|
6
6
|
var commons_1 = require("./entities/commons");
|
|
@@ -22,7 +22,9 @@ Object.defineProperty(exports, "triggerSchema", { enumerable: true, get: functio
|
|
|
22
22
|
var provider_1 = require("./entities/provider");
|
|
23
23
|
Object.defineProperty(exports, "providerSchema", { enumerable: true, get: function () { return provider_1.providerSchema; } });
|
|
24
24
|
var context_1 = require("./minified-utils/context");
|
|
25
|
+
Object.defineProperty(exports, "getPath", { enumerable: true, get: function () { return context_1.getPath; } });
|
|
25
26
|
Object.defineProperty(exports, "hasExpression", { enumerable: true, get: function () { return context_1.hasExpression; } });
|
|
27
|
+
Object.defineProperty(exports, "isDynamic", { enumerable: true, get: function () { return context_1.isDynamic; } });
|
|
26
28
|
Object.defineProperty(exports, "isExpression", { enumerable: true, get: function () { return context_1.isExpression; } });
|
|
27
29
|
Object.defineProperty(exports, "split", { enumerable: true, get: function () { return context_1.split; } });
|
|
28
30
|
var fields_1 = require("./minified-utils/fields");
|
|
@@ -3,8 +3,16 @@ export declare const isExpression: (value: any) => boolean;
|
|
|
3
3
|
export declare const hasExpression: (value: any) => boolean;
|
|
4
4
|
export declare const split: (value: string) => string[];
|
|
5
5
|
export declare const getPath: (expression: string) => string;
|
|
6
|
+
type Dynamic = {
|
|
7
|
+
array: any[];
|
|
8
|
+
mapping: Record<string, {
|
|
9
|
+
type: `property` | `literal`;
|
|
10
|
+
value: any;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
export declare const isDynamic: (data: any, processed: boolean) => data is Dynamic;
|
|
6
14
|
declare class Context {
|
|
7
|
-
readonly resolve: (field: Field, source: any, data: Record<string, any
|
|
15
|
+
readonly resolve: (field: Field, source: any, data: Record<string, any>, depth?: number) => any;
|
|
8
16
|
}
|
|
9
17
|
declare const context: Context;
|
|
10
18
|
export default context;
|
|
@@ -3,8 +3,9 @@ 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
|
-
exports.getPath = exports.split = exports.hasExpression = exports.isExpression = void 0;
|
|
6
|
+
exports.isDynamic = exports.getPath = exports.split = exports.hasExpression = exports.isExpression = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const joi_1 = __importDefault(require("joi"));
|
|
8
9
|
const IS_EXPRESSION_REGEX = /^{{2,3}[^}]+}{2,3}$/;
|
|
9
10
|
const isExpression = (value) => typeof value === `string` ? IS_EXPRESSION_REGEX.test(value) : false;
|
|
10
11
|
exports.isExpression = isExpression;
|
|
@@ -16,15 +17,37 @@ const split = (value) => typeof value === `string` ? Array.from(value.match(SPLI
|
|
|
16
17
|
exports.split = split;
|
|
17
18
|
const getPath = (expression) => expression.replace(/^{+/g, ``).replace(/}+$/g, ``);
|
|
18
19
|
exports.getPath = getPath;
|
|
20
|
+
const isDynamic = (data, processed) => {
|
|
21
|
+
const schema = joi_1.default.object({
|
|
22
|
+
array: (processed ? joi_1.default.array() : joi_1.default.string()).required(),
|
|
23
|
+
mapping: joi_1.default.object()
|
|
24
|
+
.pattern(joi_1.default.string(), joi_1.default.object({
|
|
25
|
+
type: joi_1.default.string().valid(`property`, `literal`).required(),
|
|
26
|
+
value: joi_1.default.any().allow(null, ``).required(),
|
|
27
|
+
})).required(),
|
|
28
|
+
});
|
|
29
|
+
const { error } = schema.validate(data);
|
|
30
|
+
return !error;
|
|
31
|
+
};
|
|
32
|
+
exports.isDynamic = isDynamic;
|
|
33
|
+
const shouldInfer = (field, value) => field.as_array && lodash_1.default.isArray(value)
|
|
34
|
+
|| field.type === `dict` && lodash_1.default.isObject(value)
|
|
35
|
+
|| field.type === `file` && lodash_1.default.isObject(value)
|
|
36
|
+
|| field.type === `number` && typeof value === `number`
|
|
37
|
+
|| field.type === `string` && typeof value === `string`
|
|
38
|
+
|| field.type === `boolean` && typeof value === `boolean`
|
|
39
|
+
|| field.type === `any`;
|
|
40
|
+
const MAX_RESOLVE_DEPTH = 10;
|
|
19
41
|
class Context {
|
|
20
42
|
constructor() {
|
|
21
|
-
this.resolve = (field, source, data) => {
|
|
22
|
-
if (lodash_1.default.isNull(source) || lodash_1.default.isUndefined(source)) {
|
|
43
|
+
this.resolve = (field, source, data, depth = 0) => {
|
|
44
|
+
if (lodash_1.default.isNull(source) || lodash_1.default.isUndefined(source) || depth >= MAX_RESOLVE_DEPTH) {
|
|
23
45
|
return source;
|
|
24
46
|
}
|
|
25
47
|
let serialized = false;
|
|
26
48
|
let unresolved;
|
|
27
|
-
|
|
49
|
+
const dynamicSource = field.type === `dict` && field.items && (0, exports.isDynamic)(source, false);
|
|
50
|
+
if (((lodash_1.default.isObject(source) || lodash_1.default.isArray(source)) && field.type === `dict` && !field.items) || dynamicSource) {
|
|
28
51
|
serialized = true;
|
|
29
52
|
unresolved = JSON.stringify(source);
|
|
30
53
|
}
|
|
@@ -40,14 +63,7 @@ class Context {
|
|
|
40
63
|
const path = (0, exports.getPath)(unresolved);
|
|
41
64
|
if (lodash_1.default.has(clonedData, path)) {
|
|
42
65
|
const get = lodash_1.default.get(clonedData, path);
|
|
43
|
-
|
|
44
|
-
|| field.type === `dict` && lodash_1.default.isObject(get)
|
|
45
|
-
|| field.type === `file` && lodash_1.default.isObject(get)
|
|
46
|
-
|| field.type === `number` && typeof get === `number`
|
|
47
|
-
|| field.type === `string` && typeof get === `string`
|
|
48
|
-
|| field.type === `boolean` && typeof get === `boolean`
|
|
49
|
-
|| field.type === `any`;
|
|
50
|
-
if (shouldInfer) {
|
|
66
|
+
if (shouldInfer(field, get)) {
|
|
51
67
|
resolved = get;
|
|
52
68
|
}
|
|
53
69
|
else {
|
|
@@ -78,9 +94,38 @@ class Context {
|
|
|
78
94
|
}
|
|
79
95
|
}
|
|
80
96
|
const parsed = serialized ? JSON.parse(resolved) : resolved;
|
|
81
|
-
|
|
82
|
-
this.resolve(field, parsed, clonedData)
|
|
97
|
+
const response = (typeof resolved === `string` ? resolved : JSON.stringify(resolved)).includes(`{{`) ?
|
|
98
|
+
this.resolve(field, parsed, clonedData, depth + 1)
|
|
83
99
|
: parsed;
|
|
100
|
+
if (dynamicSource && (0, exports.isDynamic)(response, true)) {
|
|
101
|
+
const dynamic = [];
|
|
102
|
+
for (const i of response.array) {
|
|
103
|
+
const item = {};
|
|
104
|
+
for (const [key, map] of Object.entries(response.mapping)) {
|
|
105
|
+
if (map.type === `property`) {
|
|
106
|
+
const child = field.items.find((fi) => fi.key === key);
|
|
107
|
+
if (!child) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const prop = lodash_1.default.get(i, map.value);
|
|
111
|
+
if (typeof prop !== `undefined`) {
|
|
112
|
+
if (shouldInfer(child, prop)) {
|
|
113
|
+
item[key] = prop;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
item[key] = lodash_1.default.toString(prop);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else if (map.type === `literal`) {
|
|
121
|
+
item[key] = map.value;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
dynamic.push(item);
|
|
125
|
+
}
|
|
126
|
+
return dynamic;
|
|
127
|
+
}
|
|
128
|
+
return response;
|
|
84
129
|
};
|
|
85
130
|
}
|
|
86
131
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { Core, core } from './core';
|
|
2
2
|
export { CoreFunction, idSchema } from './entities/commons';
|
|
3
|
-
export { Credentials,
|
|
4
|
-
export { Action,
|
|
3
|
+
export { Credentials, credentialsSchema, OAuthCredentials, oauthCredentialsSchema, SessionCredentials, sessionCredentialsSchema, StaticCredentials, staticCredentialsSchema } from './entities/credentials';
|
|
4
|
+
export { Action, actionOutputSchema, actionSchema, AsyncAction, Event, eventSchema, ImmediateTrigger, immediateTriggerSchema, Request, ScheduledTrigger, scheduledTriggerSchema, SyncAction, syncActionSchema, Trigger, triggerOutputSchema, triggerSchema } from './entities/events';
|
|
5
5
|
export { Provider, providerSchema } from './entities/provider';
|
|
6
6
|
export { Source } from './entities/source';
|
|
7
|
-
export { hasExpression, isExpression, split } from './minified-utils/context';
|
|
8
|
-
export {
|
|
9
|
-
export { DEFAULT_LOCALE, LocalizedField, LocalizedProperties,
|
|
7
|
+
export { getPath, hasExpression, isDynamic, isExpression, split } from './minified-utils/context';
|
|
8
|
+
export { alter, Condition, extract, Field, fieldSchema, fieldsSchema, File, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
|
|
9
|
+
export { DEFAULT_LOCALE, i18n, LocalizedField, LocalizedProperties, localizeFields, localizeGroup, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
|
|
10
10
|
export { Properties } from './minified-utils/properties';
|
|
11
11
|
export { Protocol } from './minified-utils/protocol';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _ from "lodash";
|
|
2
2
|
import { Field } from "./fields";
|
|
3
|
+
import Joi from "joi";
|
|
3
4
|
|
|
4
5
|
const IS_EXPRESSION_REGEX = /^{{2,3}[^}]+}{2,3}$/;
|
|
5
6
|
export const isExpression = (value: any) =>
|
|
@@ -16,14 +17,50 @@ export const split = (value: string) =>
|
|
|
16
17
|
export const getPath = (expression: string) =>
|
|
17
18
|
expression.replace(/^{+/g, ``).replace(/}+$/g, ``);
|
|
18
19
|
|
|
20
|
+
type Dynamic = {
|
|
21
|
+
array: any[],
|
|
22
|
+
mapping: Record<string, {
|
|
23
|
+
type: `property` | `literal`,
|
|
24
|
+
value: any,
|
|
25
|
+
}>,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const isDynamic = (data: any, processed: boolean): data is Dynamic => {
|
|
29
|
+
const schema = Joi.object({
|
|
30
|
+
array: (processed ? Joi.array() : Joi.string()).required(),
|
|
31
|
+
mapping: Joi.object()
|
|
32
|
+
.pattern(Joi.string(), Joi.object({
|
|
33
|
+
type: Joi.string().valid(`property`, `literal`).required(),
|
|
34
|
+
value: Joi.any().allow(null, ``).required(),
|
|
35
|
+
})).required(),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const { error } = schema.validate(data);
|
|
39
|
+
return !error;
|
|
40
|
+
};
|
|
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
|
+
|
|
51
|
+
const MAX_RESOLVE_DEPTH = 10;
|
|
52
|
+
|
|
19
53
|
class Context {
|
|
20
54
|
|
|
21
|
-
public readonly resolve = (field: Field, source: any, data: Record<string, any
|
|
22
|
-
if (_.isNull(source) || _.isUndefined(source)) { return source; }
|
|
55
|
+
public readonly resolve = (field: Field, source: any, data: Record<string, any>, depth = 0) => {
|
|
56
|
+
if (_.isNull(source) || _.isUndefined(source) || depth >= MAX_RESOLVE_DEPTH) { return source; }
|
|
23
57
|
|
|
24
58
|
let serialized = false;
|
|
25
59
|
let unresolved: string;
|
|
26
|
-
|
|
60
|
+
|
|
61
|
+
const dynamicSource = field.type === `dict` && field.items && isDynamic(source, false);
|
|
62
|
+
|
|
63
|
+
if (((_.isObject(source) || _.isArray(source)) && field.type === `dict` && !field.items) || dynamicSource) {
|
|
27
64
|
serialized = true;
|
|
28
65
|
unresolved = JSON.stringify(source);
|
|
29
66
|
} else if (typeof source === `string`) {
|
|
@@ -40,16 +77,7 @@ class Context {
|
|
|
40
77
|
const path = getPath(unresolved);
|
|
41
78
|
if (_.has(clonedData, path)) {
|
|
42
79
|
const get = _.get(clonedData, path);
|
|
43
|
-
|
|
44
|
-
field.as_array && _.isArray(get)
|
|
45
|
-
|| field.type === `dict` && _.isObject(get)
|
|
46
|
-
|| field.type === `file` && _.isObject(get)
|
|
47
|
-
|| field.type === `number` && typeof get === `number`
|
|
48
|
-
|| field.type === `string` && typeof get === `string`
|
|
49
|
-
|| field.type === `boolean` && typeof get === `boolean`
|
|
50
|
-
|| field.type === `any`;
|
|
51
|
-
|
|
52
|
-
if (shouldInfer) {
|
|
80
|
+
if (shouldInfer(field, get)) {
|
|
53
81
|
resolved = get;
|
|
54
82
|
} else {
|
|
55
83
|
resolved = _.toString(get);
|
|
@@ -72,10 +100,41 @@ class Context {
|
|
|
72
100
|
|
|
73
101
|
const parsed = serialized ? JSON.parse(resolved) : resolved;
|
|
74
102
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
this.resolve(field, parsed, clonedData)
|
|
103
|
+
const response = (typeof resolved === `string` ? resolved : JSON.stringify(resolved)).includes(`{{`) ?
|
|
104
|
+
this.resolve(field, parsed, clonedData, depth + 1)
|
|
78
105
|
: parsed;
|
|
106
|
+
|
|
107
|
+
// check dynamic arrays
|
|
108
|
+
if (dynamicSource && isDynamic(response, true)) {
|
|
109
|
+
const dynamic = [];
|
|
110
|
+
for (const i of response.array) {
|
|
111
|
+
const item: Record<string, any> = {};
|
|
112
|
+
for (const [key, map] of Object.entries(response.mapping)) {
|
|
113
|
+
if (map.type === `property`) {
|
|
114
|
+
const child = field.items.find((fi) => fi.key === key);
|
|
115
|
+
if (!child) { continue; }
|
|
116
|
+
|
|
117
|
+
const prop = _.get(i, map.value);
|
|
118
|
+
if (typeof prop !== `undefined`) {
|
|
119
|
+
if (shouldInfer(child, prop)) {
|
|
120
|
+
item[key] = prop;
|
|
121
|
+
} else {
|
|
122
|
+
item[key] = _.toString(prop);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} else if (map.type === `literal`) {
|
|
126
|
+
item[key] = map.value;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
dynamic.push(item);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return dynamic;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
// recursive resolution
|
|
137
|
+
return response;
|
|
79
138
|
};
|
|
80
139
|
|
|
81
140
|
}
|