@beseif-solutions/prow-core 0.2.2 → 0.2.4
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.
|
@@ -56,7 +56,11 @@ const defaultSchema = (type) => joi_1.default.when(`as_array`, {
|
|
|
56
56
|
then: joi_1.default.array().items(type),
|
|
57
57
|
otherwise: type,
|
|
58
58
|
});
|
|
59
|
-
const anySchema = () =>
|
|
59
|
+
const anySchema = () => {
|
|
60
|
+
const randId = Math.random().toString(36).substring(2, 15);
|
|
61
|
+
return joi_1.default.alternatives(joi_1.default.string(), joi_1.default.bool(), joi_1.default.number(), joi_1.default.array().items(joi_1.default.link(`#${randId}`)), joi_1.default.object().pattern(joi_1.default.string(), joi_1.default.link(`#${randId}`)))
|
|
62
|
+
.id(randId);
|
|
63
|
+
};
|
|
60
64
|
const anyInputFieldSchema = () => joi_1.default.object({
|
|
61
65
|
default: defaultSchema(anySchema()),
|
|
62
66
|
})
|
|
@@ -422,6 +426,9 @@ const recursive_schema = async (field, data, options) => {
|
|
|
422
426
|
if (options.alter) {
|
|
423
427
|
delete newField.altered_by;
|
|
424
428
|
}
|
|
429
|
+
if (typeof newField.show === `boolean` && !newField.show) {
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
425
432
|
}
|
|
426
433
|
const alteredField = lodash_1.default.cloneDeep(newField);
|
|
427
434
|
if (newField.type === `file`) {
|
|
@@ -467,11 +474,7 @@ const recursive_schema = async (field, data, options) => {
|
|
|
467
474
|
if (!calculatedSchema) {
|
|
468
475
|
throw new Error(`Could not resolve schema for field ${newField.key}`);
|
|
469
476
|
}
|
|
470
|
-
if (
|
|
471
|
-
lodash_1.default.unset(data, relativeKey);
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
else if (newField.disabled) {
|
|
477
|
+
if (newField.disabled) {
|
|
475
478
|
lodash_1.default.unset(data, relativeKey);
|
|
476
479
|
}
|
|
477
480
|
return { schema: calculatedSchema, field: field.type === `file` ? alteredField : newField };
|
|
@@ -503,11 +506,17 @@ const validate_internal = async (fields, data, options) => {
|
|
|
503
506
|
if (error) {
|
|
504
507
|
extended = {
|
|
505
508
|
valid: false,
|
|
506
|
-
errors: error.details.map((d) => ({
|
|
509
|
+
errors: error.details ? error.details.map((d) => ({
|
|
507
510
|
type: d.type,
|
|
508
511
|
path: convertPath([field.key, ...d.path]),
|
|
509
512
|
message: d.message,
|
|
510
|
-
}))
|
|
513
|
+
})) : [
|
|
514
|
+
{
|
|
515
|
+
type: `unknown`,
|
|
516
|
+
path: field.key,
|
|
517
|
+
message: error.message,
|
|
518
|
+
},
|
|
519
|
+
],
|
|
511
520
|
original: value,
|
|
512
521
|
value: null,
|
|
513
522
|
};
|
package/package.json
CHANGED
|
@@ -242,13 +242,17 @@ const defaultSchema = (type: Joi.Schema) =>
|
|
|
242
242
|
otherwise: type,
|
|
243
243
|
});
|
|
244
244
|
|
|
245
|
-
const anySchema = () =>
|
|
246
|
-
|
|
245
|
+
const anySchema = () => {
|
|
246
|
+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
247
|
+
const randId = Math.random().toString(36).substring(2, 15);
|
|
248
|
+
return Joi.alternatives(
|
|
247
249
|
Joi.string(),
|
|
248
250
|
Joi.bool(),
|
|
249
251
|
Joi.number(),
|
|
250
|
-
Joi.array().items(Joi.link(
|
|
251
|
-
Joi.object().pattern(Joi.string(), Joi.link(
|
|
252
|
+
Joi.array().items(Joi.link(`#${randId}`)),
|
|
253
|
+
Joi.object().pattern(Joi.string(), Joi.link(`#${randId}`)))
|
|
254
|
+
.id(randId);
|
|
255
|
+
};
|
|
252
256
|
|
|
253
257
|
const anyInputFieldSchema = () =>
|
|
254
258
|
Joi.object({
|
|
@@ -625,6 +629,8 @@ const recursive_schema = async (field: Field, data: Record<string, any>, options
|
|
|
625
629
|
|
|
626
630
|
// remove altered_by only if it's not an array -> array alterations must be kept for front-end rendering
|
|
627
631
|
if (options.alter) { delete newField.altered_by; }
|
|
632
|
+
|
|
633
|
+
if (typeof newField.show === `boolean` && !newField.show) { return; }
|
|
628
634
|
}
|
|
629
635
|
|
|
630
636
|
const alteredField: Field = _.cloneDeep(newField);
|
|
@@ -676,14 +682,8 @@ const recursive_schema = async (field: Field, data: Record<string, any>, options
|
|
|
676
682
|
|
|
677
683
|
if (!calculatedSchema) { throw new Error(`Could not resolve schema for field ${newField.key}`); }
|
|
678
684
|
|
|
679
|
-
if
|
|
680
|
-
|
|
681
|
-
_.unset(data, relativeKey);
|
|
682
|
-
return;
|
|
683
|
-
} else if (newField.disabled) {
|
|
684
|
-
// TODO: check this
|
|
685
|
-
_.unset(data, relativeKey);
|
|
686
|
-
}
|
|
685
|
+
// if disabled schema validation is done but the value is not set
|
|
686
|
+
if (newField.disabled) { _.unset(data, relativeKey); }
|
|
687
687
|
|
|
688
688
|
return { schema: calculatedSchema, field: field.type === `file` ? alteredField : newField };
|
|
689
689
|
} catch (e) { throw e; }
|
|
@@ -714,11 +714,17 @@ const validate_internal = async (fields: Field[], data: Record<string, any>, opt
|
|
|
714
714
|
if (error) {
|
|
715
715
|
extended = {
|
|
716
716
|
valid: false,
|
|
717
|
-
errors: error.details.map((d) => ({
|
|
717
|
+
errors: error.details ? error.details.map((d) => ({
|
|
718
718
|
type: d.type,
|
|
719
719
|
path: convertPath([field.key, ...d.path]),
|
|
720
720
|
message: d.message,
|
|
721
|
-
}))
|
|
721
|
+
})) : [
|
|
722
|
+
{
|
|
723
|
+
type: `unknown`,
|
|
724
|
+
path: field.key,
|
|
725
|
+
message: error.message,
|
|
726
|
+
},
|
|
727
|
+
],
|
|
722
728
|
original: value,
|
|
723
729
|
value: null,
|
|
724
730
|
};
|