@beseif-solutions/prow-core 1.2.1 → 1.2.3
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.
|
@@ -106,7 +106,7 @@ export type SelectFieldChoice<Values = string | number | boolean | File, Extend
|
|
|
106
106
|
key: string;
|
|
107
107
|
value: Values;
|
|
108
108
|
group?: string;
|
|
109
|
-
} & Extend;
|
|
109
|
+
} & Record<`experimental_${string}`, any> & Extend;
|
|
110
110
|
export type CustomDisplayTextField = {
|
|
111
111
|
format: `textarea` | `rich-text` | `markdown`;
|
|
112
112
|
};
|
|
@@ -50,7 +50,8 @@ const choiceSchema = (type) => joi_1.default.object({
|
|
|
50
50
|
key: joi_1.default.string().required(),
|
|
51
51
|
value: type.required(),
|
|
52
52
|
group: joi_1.default.string(),
|
|
53
|
-
}).
|
|
53
|
+
}).concat(joi_1.default.object()
|
|
54
|
+
.pattern(joi_1.default.string().regex(/^experimental_/), joi_1.default.any())).unknown();
|
|
54
55
|
const choicesSchema = (type) => joi_1.default.alternatives(joi_1.default.string(), joi_1.default.array().min(1)
|
|
55
56
|
.items(choiceSchema(type)));
|
|
56
57
|
const defaultSchema = (type) => joi_1.default.when(`as_array`, {
|
|
@@ -410,25 +411,25 @@ const alter = (field, relative, data) => {
|
|
|
410
411
|
exports.alter = alter;
|
|
411
412
|
const recursive_schema = async (field, data, options) => {
|
|
412
413
|
try {
|
|
413
|
-
let
|
|
414
|
-
if (
|
|
415
|
-
|
|
414
|
+
let alteredField = lodash_1.default.cloneDeep(field);
|
|
415
|
+
if (alteredField.altered_by?.length > 0) {
|
|
416
|
+
alteredField = (0, exports.alter)(alteredField, options.relative, data);
|
|
416
417
|
if (options.alter) {
|
|
417
|
-
delete
|
|
418
|
+
delete alteredField.altered_by;
|
|
418
419
|
}
|
|
419
|
-
if (typeof
|
|
420
|
+
if (typeof alteredField.show === `boolean` && !alteredField.show) {
|
|
420
421
|
return;
|
|
421
422
|
}
|
|
422
423
|
}
|
|
423
424
|
const relativeKey = options.relative ?
|
|
424
425
|
options.relative.endsWith(`]`) ?
|
|
425
|
-
options.array ? options.relative : `${options.relative}.${
|
|
426
|
-
: `${options.relative}.${
|
|
427
|
-
:
|
|
428
|
-
const value = lodash_1.default.get(data, relativeKey,
|
|
429
|
-
const resolved = context_1.default.resolve(
|
|
426
|
+
options.array ? options.relative : `${options.relative}.${alteredField.key}`
|
|
427
|
+
: `${options.relative}.${alteredField.key}`
|
|
428
|
+
: alteredField.key;
|
|
429
|
+
const value = lodash_1.default.get(data, relativeKey, alteredField.default);
|
|
430
|
+
const resolved = context_1.default.resolve(alteredField, value, options.context);
|
|
430
431
|
if (!options.no_undefined || typeof resolved !== `undefined`) {
|
|
431
|
-
if (
|
|
432
|
+
if (alteredField.type === `any` && typeof resolved === `undefined`) {
|
|
432
433
|
lodash_1.default.set(data, relativeKey, null);
|
|
433
434
|
}
|
|
434
435
|
else {
|
|
@@ -439,8 +440,8 @@ const recursive_schema = async (field, data, options) => {
|
|
|
439
440
|
return { schema: null, field: null };
|
|
440
441
|
}
|
|
441
442
|
let calculatedSchema;
|
|
442
|
-
if (
|
|
443
|
-
const noArrayField = lodash_1.default.omit(
|
|
443
|
+
if (alteredField.as_array) {
|
|
444
|
+
const noArrayField = lodash_1.default.omit(alteredField, [`as_array`, `array_min`, `array_max`, `array_length`]);
|
|
444
445
|
if (resolved) {
|
|
445
446
|
const itemSchemas = [];
|
|
446
447
|
if (lodash_1.default.isArray(resolved)) {
|
|
@@ -453,7 +454,7 @@ const recursive_schema = async (field, data, options) => {
|
|
|
453
454
|
const withoutUndefined = resolved.filter((r) => typeof r !== `undefined`);
|
|
454
455
|
lodash_1.default.set(data, relativeKey, withoutUndefined);
|
|
455
456
|
}
|
|
456
|
-
calculatedSchema = getOrderedArrayFieldSchema(
|
|
457
|
+
calculatedSchema = getOrderedArrayFieldSchema(alteredField, itemSchemas);
|
|
457
458
|
}
|
|
458
459
|
else {
|
|
459
460
|
let genericItemSchema;
|
|
@@ -471,36 +472,35 @@ const recursive_schema = async (field, data, options) => {
|
|
|
471
472
|
else {
|
|
472
473
|
genericItemSchema = getSimpleFieldSchema(noArrayField);
|
|
473
474
|
}
|
|
474
|
-
calculatedSchema = getItemsArrayFieldSchema(
|
|
475
|
+
calculatedSchema = getItemsArrayFieldSchema(alteredField, [genericItemSchema]);
|
|
475
476
|
}
|
|
476
477
|
}
|
|
477
|
-
else if (
|
|
478
|
-
if (resolved ||
|
|
478
|
+
else if (alteredField.type === `dict` && alteredField.items) {
|
|
479
|
+
if (resolved || alteredField.required) {
|
|
479
480
|
const items = [];
|
|
480
|
-
for (const item of
|
|
481
|
+
for (const item of alteredField.items) {
|
|
481
482
|
const recursive = await recursive_schema(item, data, { alter: options.alter && true, relative: relativeKey, context: options.context });
|
|
482
483
|
if (recursive) {
|
|
483
484
|
items.push({ key: item.key, schema: recursive.schema, field: recursive.field });
|
|
484
485
|
}
|
|
485
486
|
}
|
|
486
|
-
calculatedSchema = getObjectFieldSchema(
|
|
487
|
-
|
|
487
|
+
calculatedSchema = getObjectFieldSchema(alteredField, items);
|
|
488
|
+
alteredField.items = items.map((i) => i.field);
|
|
488
489
|
}
|
|
489
490
|
else {
|
|
490
|
-
|
|
491
|
-
calculatedSchema = getSimpleFieldSchema(newField);
|
|
491
|
+
calculatedSchema = getSimpleFieldSchema(lodash_1.default.omit(alteredField, [`items`]));
|
|
492
492
|
}
|
|
493
493
|
}
|
|
494
494
|
else {
|
|
495
|
-
calculatedSchema = getSimpleFieldSchema(
|
|
495
|
+
calculatedSchema = getSimpleFieldSchema(alteredField);
|
|
496
496
|
}
|
|
497
497
|
if (!calculatedSchema) {
|
|
498
|
-
throw new Error(`Could not resolve schema for field ${
|
|
498
|
+
throw new Error(`Could not resolve schema for field ${alteredField.key}`);
|
|
499
499
|
}
|
|
500
|
-
if (
|
|
500
|
+
if (alteredField.disabled) {
|
|
501
501
|
lodash_1.default.unset(data, relativeKey);
|
|
502
502
|
}
|
|
503
|
-
return { schema: calculatedSchema, field:
|
|
503
|
+
return { schema: calculatedSchema, field: alteredField };
|
|
504
504
|
}
|
|
505
505
|
catch (e) {
|
|
506
506
|
throw e;
|
package/package.json
CHANGED
|
@@ -160,7 +160,9 @@ export type SelectFieldChoice<Values = string | number | boolean | File, Extend
|
|
|
160
160
|
key: string,
|
|
161
161
|
value: Values,
|
|
162
162
|
group?: string,
|
|
163
|
-
}
|
|
163
|
+
}
|
|
164
|
+
& Record<`experimental_${string}`, any>
|
|
165
|
+
& Extend;
|
|
164
166
|
|
|
165
167
|
/* custom display configuration */
|
|
166
168
|
export type CustomDisplayTextField = {
|
|
@@ -50,8 +50,11 @@ const commonFieldSchema = () =>
|
|
|
50
50
|
then: Joi.number(),
|
|
51
51
|
otherwise: Joi.forbidden(),
|
|
52
52
|
}),
|
|
53
|
-
}).concat(
|
|
54
|
-
|
|
53
|
+
}).concat(
|
|
54
|
+
// experimental properties for custom front features
|
|
55
|
+
Joi.object()
|
|
56
|
+
.pattern(Joi.string().regex(/^experimental_/), Joi.any())
|
|
57
|
+
);
|
|
55
58
|
|
|
56
59
|
const types = [`any`, `string`, `number`, `boolean`, `date`, `datetime`, `time`, `dict`, `file`];
|
|
57
60
|
|
|
@@ -69,7 +72,11 @@ const choiceSchema = (type: Joi.Schema) =>
|
|
|
69
72
|
key: Joi.string().required(),
|
|
70
73
|
value: type.required(),
|
|
71
74
|
group: Joi.string(),
|
|
72
|
-
}).
|
|
75
|
+
}).concat(
|
|
76
|
+
// experimental properties for custom front features
|
|
77
|
+
Joi.object()
|
|
78
|
+
.pattern(Joi.string().regex(/^experimental_/), Joi.any())
|
|
79
|
+
).unknown();
|
|
73
80
|
|
|
74
81
|
const choicesSchema = (type: Joi.Schema) =>
|
|
75
82
|
Joi.alternatives(
|
|
@@ -459,30 +466,30 @@ export const alter = (field: Field, relative: string, data: Record<string, any>)
|
|
|
459
466
|
|
|
460
467
|
const recursive_schema = async (field: Field, data: Record<string, any>, options: { alter: boolean, context: Record<string, any>, relative?: string, array?: boolean, no_undefined?: boolean }): Promise<{ schema: Joi.Schema, field: Field }> => {
|
|
461
468
|
try {
|
|
462
|
-
let
|
|
469
|
+
let alteredField: Field = _.cloneDeep(field);
|
|
463
470
|
|
|
464
471
|
// alterations over already resolved data (previous fields)
|
|
465
|
-
if (
|
|
466
|
-
|
|
472
|
+
if (alteredField.altered_by?.length > 0) {
|
|
473
|
+
alteredField = alter(alteredField, options.relative, data);
|
|
467
474
|
|
|
468
475
|
// remove altered_by only if it's not an array -> array alterations must be kept for front-end rendering
|
|
469
|
-
if (options.alter) { delete
|
|
476
|
+
if (options.alter) { delete alteredField.altered_by; }
|
|
470
477
|
|
|
471
|
-
if (typeof
|
|
478
|
+
if (typeof alteredField.show === `boolean` && !alteredField.show) { return; }
|
|
472
479
|
}
|
|
473
480
|
|
|
474
481
|
const relativeKey = options.relative ?
|
|
475
482
|
options.relative.endsWith(`]`) ?
|
|
476
|
-
options.array ? options.relative : `${options.relative}.${
|
|
477
|
-
: `${options.relative}.${
|
|
478
|
-
:
|
|
483
|
+
options.array ? options.relative : `${options.relative}.${alteredField.key}`
|
|
484
|
+
: `${options.relative}.${alteredField.key}`
|
|
485
|
+
: alteredField.key;
|
|
479
486
|
|
|
480
|
-
const value = _.get(data, relativeKey,
|
|
487
|
+
const value = _.get(data, relativeKey, alteredField.default);
|
|
481
488
|
|
|
482
489
|
// resolve value with context (even if it's not valid)
|
|
483
|
-
const resolved = context.resolve(
|
|
490
|
+
const resolved = context.resolve(alteredField, value, options.context);
|
|
484
491
|
if (!options.no_undefined || typeof resolved !== `undefined`) {
|
|
485
|
-
if (
|
|
492
|
+
if (alteredField.type === `any` && typeof resolved === `undefined`) {
|
|
486
493
|
// any field - allow_nullish
|
|
487
494
|
_.set(data, relativeKey, null);
|
|
488
495
|
} else {
|
|
@@ -495,8 +502,8 @@ const recursive_schema = async (field: Field, data: Record<string, any>, options
|
|
|
495
502
|
|
|
496
503
|
// get schema for field with data
|
|
497
504
|
let calculatedSchema: Joi.Schema;
|
|
498
|
-
if (
|
|
499
|
-
const noArrayField = _.omit(
|
|
505
|
+
if (alteredField.as_array) {
|
|
506
|
+
const noArrayField = _.omit(alteredField, [`as_array`, `array_min`, `array_max`, `array_length`]) as Field;
|
|
500
507
|
|
|
501
508
|
if (resolved) {
|
|
502
509
|
const itemSchemas: Joi.Schema[] = [];
|
|
@@ -511,7 +518,7 @@ const recursive_schema = async (field: Field, data: Record<string, any>, options
|
|
|
511
518
|
_.set(data, relativeKey, withoutUndefined);
|
|
512
519
|
}
|
|
513
520
|
|
|
514
|
-
calculatedSchema = getOrderedArrayFieldSchema(
|
|
521
|
+
calculatedSchema = getOrderedArrayFieldSchema(alteredField, itemSchemas);
|
|
515
522
|
} else {
|
|
516
523
|
let genericItemSchema: Joi.Schema;
|
|
517
524
|
if (noArrayField.type === `dict` && noArrayField.items) {
|
|
@@ -528,33 +535,33 @@ const recursive_schema = async (field: Field, data: Record<string, any>, options
|
|
|
528
535
|
genericItemSchema = getSimpleFieldSchema(noArrayField);
|
|
529
536
|
}
|
|
530
537
|
|
|
531
|
-
calculatedSchema = getItemsArrayFieldSchema(
|
|
538
|
+
calculatedSchema = getItemsArrayFieldSchema(alteredField, [genericItemSchema]);
|
|
532
539
|
}
|
|
533
|
-
} else if (
|
|
534
|
-
if (resolved ||
|
|
540
|
+
} else if (alteredField.type === `dict` && alteredField.items) {
|
|
541
|
+
if (resolved || alteredField.required) {
|
|
535
542
|
const items: { key: string, schema: Joi.Schema, field: Field }[] = [];
|
|
536
543
|
|
|
537
|
-
for (const item of
|
|
544
|
+
for (const item of alteredField.items) {
|
|
538
545
|
const recursive = await recursive_schema(item, data, { alter: options.alter && true, relative: relativeKey, context: options.context });
|
|
539
546
|
if (recursive) { items.push({ key: item.key, schema: recursive.schema, field: recursive.field }); }
|
|
540
547
|
}
|
|
541
548
|
|
|
542
|
-
calculatedSchema = getObjectFieldSchema(
|
|
543
|
-
|
|
549
|
+
calculatedSchema = getObjectFieldSchema(alteredField, items);
|
|
550
|
+
alteredField.items = items.map((i) => i.field);
|
|
544
551
|
} else {
|
|
545
|
-
|
|
546
|
-
calculatedSchema = getSimpleFieldSchema(
|
|
552
|
+
// omit items to avoid simple field error
|
|
553
|
+
calculatedSchema = getSimpleFieldSchema(_.omit(alteredField, [`items`]) as Field);
|
|
547
554
|
}
|
|
548
555
|
} else {
|
|
549
|
-
calculatedSchema = getSimpleFieldSchema(
|
|
556
|
+
calculatedSchema = getSimpleFieldSchema(alteredField);
|
|
550
557
|
}
|
|
551
558
|
|
|
552
|
-
if (!calculatedSchema) { throw new Error(`Could not resolve schema for field ${
|
|
559
|
+
if (!calculatedSchema) { throw new Error(`Could not resolve schema for field ${alteredField.key}`); }
|
|
553
560
|
|
|
554
561
|
// if disabled schema validation is done but the value is not set
|
|
555
|
-
if (
|
|
562
|
+
if (alteredField.disabled) { _.unset(data, relativeKey); }
|
|
556
563
|
|
|
557
|
-
return { schema: calculatedSchema, field:
|
|
564
|
+
return { schema: calculatedSchema, field: alteredField };
|
|
558
565
|
} catch (e) { throw e; }
|
|
559
566
|
};
|
|
560
567
|
|