@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Joi from "joi";
|
|
2
|
-
import { Field } from "../minified-utils/fields";
|
|
3
2
|
import { Common, CoreConfig, CoreFunction } from "./commons";
|
|
3
|
+
import { Field } from "../minified-utils/fields";
|
|
4
4
|
type CredentialsConfig = Pick<CoreConfig, `credentials`>;
|
|
5
5
|
type CommonCredentials<Config extends CredentialsConfig = {}> = Common<Config> & {
|
|
6
6
|
model: `credentials`;
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.credentialsSchema = exports.staticCredentialsSchema = exports.sessionCredentialsSchema = exports.oauthCredentialsSchema = void 0;
|
|
7
7
|
const joi_1 = __importDefault(require("joi"));
|
|
8
|
-
const
|
|
8
|
+
const validation_1 = require("../minified-utils/validation");
|
|
9
9
|
const commons_1 = require("./commons");
|
|
10
10
|
const commonCredentialsSchema = () => joi_1.default.object({
|
|
11
11
|
model: joi_1.default.valid(`credentials`).required(),
|
|
@@ -38,7 +38,7 @@ const sessionCredentialsSchema = () => joi_1.default.object({
|
|
|
38
38
|
exports.sessionCredentialsSchema = sessionCredentialsSchema;
|
|
39
39
|
const staticCredentialsSchema = () => joi_1.default.object({
|
|
40
40
|
type: joi_1.default.valid(`static`).required(),
|
|
41
|
-
fields: (0,
|
|
41
|
+
fields: (0, validation_1.fieldsSchema)()
|
|
42
42
|
.required()
|
|
43
43
|
.min(1),
|
|
44
44
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Joi from "joi";
|
|
2
|
-
import { Field } from "../minified-utils/fields";
|
|
3
2
|
import { Common, CoreConfig, CoreFunction } from "./commons";
|
|
4
3
|
import { ObjectOrArray } from "../minified-utils/types";
|
|
4
|
+
import { Field } from "../minified-utils/fields";
|
|
5
5
|
type CommonConnectableEvent<Keys extends string = string> = {
|
|
6
6
|
key: Keys;
|
|
7
7
|
};
|
package/dist/entities/events.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.actionOutputSchema = exports.triggerOutputSchema = exports.eventSchema = exports.actionSchema = exports.asyncActionSchema = exports.syncActionSchema = exports.triggerSchema = exports.immediateTriggerSchema = exports.scheduledTriggerSchema = void 0;
|
|
7
7
|
const joi_1 = __importDefault(require("joi"));
|
|
8
|
-
const
|
|
8
|
+
const validation_1 = require("../minified-utils/validation");
|
|
9
9
|
const commons_1 = require("./commons");
|
|
10
10
|
const commonConnectableEventSchema = () => joi_1.default.object({
|
|
11
11
|
key: joi_1.default.string().required(),
|
|
@@ -32,7 +32,7 @@ const commonEventsSchema = () => joi_1.default.object({
|
|
|
32
32
|
}).required(),
|
|
33
33
|
credentials: joi_1.default.array().items((0, commons_1.idSchema)().optional()).required().min(0),
|
|
34
34
|
sandbox: joi_1.default.bool().required(),
|
|
35
|
-
fields: (0,
|
|
35
|
+
fields: (0, validation_1.fieldsSchema)().required(),
|
|
36
36
|
examples: joi_1.default.array(),
|
|
37
37
|
sources: joi_1.default.array().items(joi_1.default.object({
|
|
38
38
|
role: joi_1.default.valid(`subscriber`, `consumer`).required(),
|
package/dist/entities/source.js
CHANGED
|
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.sourceSchema = void 0;
|
|
7
7
|
const joi_1 = __importDefault(require("joi"));
|
|
8
|
-
const
|
|
8
|
+
const validation_1 = require("../minified-utils/validation");
|
|
9
9
|
const commons_1 = require("./commons");
|
|
10
10
|
const sourceSchema = () => joi_1.default.object({
|
|
11
11
|
model: joi_1.default.valid(`source`).required(),
|
|
12
12
|
sandbox: joi_1.default.boolean().required(),
|
|
13
|
-
fields: (0,
|
|
13
|
+
fields: (0, validation_1.fieldsSchema)().required().min(1),
|
|
14
14
|
}).concat((0, commons_1.commonSchema)());
|
|
15
15
|
exports.sourceSchema = sourceSchema;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ export { Action, actionOutputSchema, actionSchema, AsyncAction, Event, eventSche
|
|
|
5
5
|
export { Provider, providerSchema } from './entities/provider';
|
|
6
6
|
export { Source } from './entities/source';
|
|
7
7
|
export { getPath, hasExpression, isDynamic, isExpression, split } from './minified-utils/context';
|
|
8
|
-
export { alter,
|
|
8
|
+
export { alter, extract, fieldSchema, fieldsSchema, validate, ValidationResult } from './minified-utils/validation';
|
|
9
|
+
export { Condition, Field, File, SelectFieldChoice } from './minified-utils/fields';
|
|
9
10
|
export { DEFAULT_LOCALE, i18n, LocalizedField, LocalizedProperties, localizeFields, localizeGroup, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
|
|
10
11
|
export { Properties } from './minified-utils/properties';
|
|
11
12
|
export { Protocol } from './minified-utils/protocol';
|
package/dist/index.js
CHANGED
|
@@ -27,12 +27,12 @@ Object.defineProperty(exports, "hasExpression", { enumerable: true, get: functio
|
|
|
27
27
|
Object.defineProperty(exports, "isDynamic", { enumerable: true, get: function () { return context_1.isDynamic; } });
|
|
28
28
|
Object.defineProperty(exports, "isExpression", { enumerable: true, get: function () { return context_1.isExpression; } });
|
|
29
29
|
Object.defineProperty(exports, "split", { enumerable: true, get: function () { return context_1.split; } });
|
|
30
|
-
var
|
|
31
|
-
Object.defineProperty(exports, "alter", { enumerable: true, get: function () { return
|
|
32
|
-
Object.defineProperty(exports, "extract", { enumerable: true, get: function () { return
|
|
33
|
-
Object.defineProperty(exports, "fieldSchema", { enumerable: true, get: function () { return
|
|
34
|
-
Object.defineProperty(exports, "fieldsSchema", { enumerable: true, get: function () { return
|
|
35
|
-
Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return
|
|
30
|
+
var validation_1 = require("./minified-utils/validation");
|
|
31
|
+
Object.defineProperty(exports, "alter", { enumerable: true, get: function () { return validation_1.alter; } });
|
|
32
|
+
Object.defineProperty(exports, "extract", { enumerable: true, get: function () { return validation_1.extract; } });
|
|
33
|
+
Object.defineProperty(exports, "fieldSchema", { enumerable: true, get: function () { return validation_1.fieldSchema; } });
|
|
34
|
+
Object.defineProperty(exports, "fieldsSchema", { enumerable: true, get: function () { return validation_1.fieldsSchema; } });
|
|
35
|
+
Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return validation_1.validate; } });
|
|
36
36
|
var locales_1 = require("./minified-utils/locales");
|
|
37
37
|
Object.defineProperty(exports, "DEFAULT_LOCALE", { enumerable: true, get: function () { return locales_1.DEFAULT_LOCALE; } });
|
|
38
38
|
Object.defineProperty(exports, "i18n", { enumerable: true, get: function () { return locales_1.i18n; } });
|
|
@@ -30,6 +30,13 @@ const isDynamic = (data, processed) => {
|
|
|
30
30
|
return !error;
|
|
31
31
|
};
|
|
32
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`;
|
|
33
40
|
const MAX_RESOLVE_DEPTH = 10;
|
|
34
41
|
class Context {
|
|
35
42
|
constructor() {
|
|
@@ -39,8 +46,8 @@ class Context {
|
|
|
39
46
|
}
|
|
40
47
|
let serialized = false;
|
|
41
48
|
let unresolved;
|
|
42
|
-
const dynamicSource = (0, exports.isDynamic)(source, false);
|
|
43
|
-
if ((lodash_1.default.isObject(source) || lodash_1.default.isArray(source)) && field.type === `dict` &&
|
|
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) {
|
|
44
51
|
serialized = true;
|
|
45
52
|
unresolved = JSON.stringify(source);
|
|
46
53
|
}
|
|
@@ -56,14 +63,7 @@ class Context {
|
|
|
56
63
|
const path = (0, exports.getPath)(unresolved);
|
|
57
64
|
if (lodash_1.default.has(clonedData, path)) {
|
|
58
65
|
const get = lodash_1.default.get(clonedData, path);
|
|
59
|
-
|
|
60
|
-
|| field.type === `dict` && lodash_1.default.isObject(get)
|
|
61
|
-
|| field.type === `file` && lodash_1.default.isObject(get)
|
|
62
|
-
|| field.type === `number` && typeof get === `number`
|
|
63
|
-
|| field.type === `string` && typeof get === `string`
|
|
64
|
-
|| field.type === `boolean` && typeof get === `boolean`
|
|
65
|
-
|| field.type === `any`;
|
|
66
|
-
if (shouldInfer) {
|
|
66
|
+
if (shouldInfer(field, get)) {
|
|
67
67
|
resolved = get;
|
|
68
68
|
}
|
|
69
69
|
else {
|
|
@@ -103,9 +103,18 @@ class Context {
|
|
|
103
103
|
const item = {};
|
|
104
104
|
for (const [key, map] of Object.entries(response.mapping)) {
|
|
105
105
|
if (map.type === `property`) {
|
|
106
|
+
const child = field.items.find((fi) => fi.key === key);
|
|
107
|
+
if (!child) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
106
110
|
const prop = lodash_1.default.get(i, map.value);
|
|
107
111
|
if (typeof prop !== `undefined`) {
|
|
108
|
-
|
|
112
|
+
if (shouldInfer(child, prop)) {
|
|
113
|
+
item[key] = prop;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
item[key] = lodash_1.default.toString(prop);
|
|
117
|
+
}
|
|
109
118
|
}
|
|
110
119
|
}
|
|
111
120
|
else if (map.type === `literal`) {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import Joi from "joi";
|
|
2
1
|
import { Where } from "./where";
|
|
3
2
|
export type Condition = {
|
|
4
3
|
condition: Where;
|
|
5
4
|
overrides: Partial<Field>;
|
|
6
5
|
};
|
|
7
|
-
type
|
|
6
|
+
export type CommonField = {
|
|
8
7
|
key: string;
|
|
9
8
|
altered_by?: Condition[];
|
|
10
9
|
disabled?: boolean;
|
|
@@ -20,17 +19,17 @@ type Common = {
|
|
|
20
19
|
array_max?: number;
|
|
21
20
|
array_length?: number;
|
|
22
21
|
}) & Record<`experimental_${string}`, any>;
|
|
23
|
-
export type Field<Extend = Record<never, never>> =
|
|
24
|
-
type InputField<Extend = Record<never, never>> = (AnyInputField<Extend> | StringInputField<Extend> | NumberInputField<Extend> | BooleanInputField<Extend> | DateTimeInputField<Extend> | DateInputField<Extend> | TimeInputField<Extend> | DictInputField<Extend> | FileInputField<Extend>) & Extend;
|
|
25
|
-
type Any = string | number | boolean | Any[] | {
|
|
22
|
+
export type Field<Extend = Record<never, never>> = CommonField & InputField<Extend>;
|
|
23
|
+
export type InputField<Extend = Record<never, never>> = (AnyInputField<Extend> | StringInputField<Extend> | NumberInputField<Extend> | BooleanInputField<Extend> | DateTimeInputField<Extend> | DateInputField<Extend> | TimeInputField<Extend> | DictInputField<Extend> | FileInputField<Extend>) & Extend;
|
|
24
|
+
export type Any = string | number | boolean | Any[] | {
|
|
26
25
|
[key: string]: Any;
|
|
27
26
|
};
|
|
28
|
-
type AnyInputField<Extend = Record<never, never>> = {
|
|
27
|
+
export type AnyInputField<Extend = Record<never, never>> = {
|
|
29
28
|
type: `any`;
|
|
30
29
|
default?: Any | Any[];
|
|
31
30
|
allow_nullish?: boolean;
|
|
32
31
|
} & (SelectField<Any, Extend> | {});
|
|
33
|
-
type StringInputField<Extend = Record<never, never>> = {
|
|
32
|
+
export type StringInputField<Extend = Record<never, never>> = {
|
|
34
33
|
type: `string`;
|
|
35
34
|
default?: string | string[];
|
|
36
35
|
length?: number;
|
|
@@ -40,7 +39,7 @@ type StringInputField<Extend = Record<never, never>> = {
|
|
|
40
39
|
pattern?: `email` | `uri`;
|
|
41
40
|
allow_empty?: boolean;
|
|
42
41
|
} & (SelectField<string, Extend> | CustomDisplayTextField | IDETextField | {});
|
|
43
|
-
type NumberInputField<Extend = Record<never, never>> = {
|
|
42
|
+
export type NumberInputField<Extend = Record<never, never>> = {
|
|
44
43
|
type: `number`;
|
|
45
44
|
default?: number | number[];
|
|
46
45
|
min?: number;
|
|
@@ -51,7 +50,7 @@ type NumberInputField<Extend = Record<never, never>> = {
|
|
|
51
50
|
} | {
|
|
52
51
|
float?: false;
|
|
53
52
|
}) & (SelectField<number, Extend> | {});
|
|
54
|
-
type BooleanInputField<Extend = Record<never, never>> = {
|
|
53
|
+
export type BooleanInputField<Extend = Record<never, never>> = {
|
|
55
54
|
type: `boolean`;
|
|
56
55
|
default?: boolean | boolean[];
|
|
57
56
|
} & (SelectField<boolean, Extend> | {
|
|
@@ -59,25 +58,25 @@ type BooleanInputField<Extend = Record<never, never>> = {
|
|
|
59
58
|
} | {
|
|
60
59
|
format: `switch`;
|
|
61
60
|
} | {});
|
|
62
|
-
type DateTimeInputField<Extend = Record<never, never>> = {
|
|
61
|
+
export type DateTimeInputField<Extend = Record<never, never>> = {
|
|
63
62
|
type: `datetime`;
|
|
64
63
|
timezone?: string;
|
|
65
64
|
default?: string | number | (string | number)[];
|
|
66
65
|
min?: number | string;
|
|
67
66
|
max?: number | string;
|
|
68
67
|
} & (SelectField<string | number, Extend> | {});
|
|
69
|
-
type DateInputField<Extend = Record<never, never>> = {
|
|
68
|
+
export type DateInputField<Extend = Record<never, never>> = {
|
|
70
69
|
type: `date`;
|
|
71
70
|
default?: string | string[];
|
|
72
71
|
min?: string;
|
|
73
72
|
max?: string;
|
|
74
73
|
} & (SelectField<string, Extend> | {});
|
|
75
|
-
type TimeInputField<Extend = Record<never, never>> = {
|
|
74
|
+
export type TimeInputField<Extend = Record<never, never>> = {
|
|
76
75
|
type: `time`;
|
|
77
76
|
timezone?: string;
|
|
78
77
|
default?: string | string[];
|
|
79
78
|
} & (SelectField<string, Extend> | {});
|
|
80
|
-
type DictInputField<Extend = Record<never, never>> = {
|
|
79
|
+
export type DictInputField<Extend = Record<never, never>> = {
|
|
81
80
|
type: `dict`;
|
|
82
81
|
default?: Record<string, any> | Record<string, any>[];
|
|
83
82
|
items?: Field<Extend>[];
|
|
@@ -88,12 +87,12 @@ export type File = {
|
|
|
88
87
|
type: string;
|
|
89
88
|
content: string;
|
|
90
89
|
};
|
|
91
|
-
type FileInputField<Extend = Record<never, never>> = {
|
|
90
|
+
export type FileInputField<Extend = Record<never, never>> = {
|
|
92
91
|
type: `file`;
|
|
93
92
|
default?: File | File[];
|
|
94
93
|
accept?: string | string[];
|
|
95
94
|
} & (SelectField<File, Extend> | {});
|
|
96
|
-
type SelectField<Values = string | number | boolean | File, Extend = Record<never, never>> = {
|
|
95
|
+
export type SelectField<Values = string | number | boolean | File, Extend = Record<never, never>> = {
|
|
97
96
|
format: `select`;
|
|
98
97
|
choices: SelectFieldChoice<Values, Extend>[] | string;
|
|
99
98
|
unknown?: boolean;
|
|
@@ -103,39 +102,10 @@ export type SelectFieldChoice<Values = string | number | boolean | File, Extend
|
|
|
103
102
|
value: Values;
|
|
104
103
|
group?: string;
|
|
105
104
|
} & Extend;
|
|
106
|
-
type CustomDisplayTextField = {
|
|
105
|
+
export type CustomDisplayTextField = {
|
|
107
106
|
format: `textarea` | `rich-text` | `markdown`;
|
|
108
107
|
};
|
|
109
|
-
type IDETextField = {
|
|
108
|
+
export type IDETextField = {
|
|
110
109
|
format: `code`;
|
|
111
110
|
language?: string;
|
|
112
111
|
};
|
|
113
|
-
type ValidationExtended = {
|
|
114
|
-
original: any;
|
|
115
|
-
value: any;
|
|
116
|
-
} & ({
|
|
117
|
-
valid: true;
|
|
118
|
-
} | {
|
|
119
|
-
valid: false;
|
|
120
|
-
errors: {
|
|
121
|
-
path: string;
|
|
122
|
-
message: string;
|
|
123
|
-
type: string;
|
|
124
|
-
}[];
|
|
125
|
-
});
|
|
126
|
-
export declare const fieldSchema: () => Joi.ObjectSchema<any>;
|
|
127
|
-
export declare const fieldsSchema: () => Joi.ArraySchema<any[]>;
|
|
128
|
-
export type ValidationResult<Extended = Record<string, never>> = {
|
|
129
|
-
valid: boolean;
|
|
130
|
-
fields: Field<Extended & ValidationExtended>[];
|
|
131
|
-
};
|
|
132
|
-
export declare const alter: (field: Field, relative: string, data: Record<string, any>) => Field<Record<never, never>>;
|
|
133
|
-
export declare const validate: <I>(fields: Field<I>[], data: Record<string, any>, options?: {
|
|
134
|
-
secure?: boolean;
|
|
135
|
-
break?: boolean;
|
|
136
|
-
context?: Record<string, any>;
|
|
137
|
-
}) => Promise<ValidationResult<I>>;
|
|
138
|
-
export declare const extract: (validation: Field<ValidationExtended>[], options?: {
|
|
139
|
-
original?: boolean;
|
|
140
|
-
}) => Promise<Record<string, any>>;
|
|
141
|
-
export {};
|