@beseif-solutions/prow-core 1.0.2 → 1.0.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.
|
@@ -457,8 +457,9 @@ const recursive_schema = async (field, data, options) => {
|
|
|
457
457
|
: newField.key;
|
|
458
458
|
const value = lodash_1.default.get(data, relativeKey, newField.default);
|
|
459
459
|
const resolved = context_1.default.resolve(newField, value, options.context);
|
|
460
|
-
|
|
461
|
-
|
|
460
|
+
lodash_1.default.set(data, relativeKey, resolved);
|
|
461
|
+
if (typeof resolved === `undefined` && options.array) {
|
|
462
|
+
return { schema: null, field: null };
|
|
462
463
|
}
|
|
463
464
|
let calculatedSchema;
|
|
464
465
|
if (newField.as_array) {
|
|
@@ -472,6 +473,8 @@ const recursive_schema = async (field, data, options) => {
|
|
|
472
473
|
itemSchemas.push(itemSchema);
|
|
473
474
|
}
|
|
474
475
|
}
|
|
476
|
+
const withoutUndefined = resolved.filter((r) => typeof r !== `undefined`);
|
|
477
|
+
lodash_1.default.set(data, relativeKey, withoutUndefined);
|
|
475
478
|
}
|
|
476
479
|
calculatedSchema = getOrderedArrayFieldSchema(newField, itemSchemas);
|
|
477
480
|
}
|
|
@@ -495,15 +498,21 @@ const recursive_schema = async (field, data, options) => {
|
|
|
495
498
|
}
|
|
496
499
|
}
|
|
497
500
|
else if (newField.type === `dict` && newField.items) {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
|
|
501
|
+
if (resolved || newField.required) {
|
|
502
|
+
const items = [];
|
|
503
|
+
for (const item of newField.items) {
|
|
504
|
+
const recursive = await recursive_schema(item, data, { alter: options.alter && true, relative: relativeKey, context: options.context });
|
|
505
|
+
if (recursive) {
|
|
506
|
+
items.push({ key: item.key, schema: recursive.schema, field: recursive.field });
|
|
507
|
+
}
|
|
503
508
|
}
|
|
509
|
+
calculatedSchema = getObjectFieldSchema(newField, items);
|
|
510
|
+
newField.items = items.map((i) => i.field);
|
|
511
|
+
}
|
|
512
|
+
else {
|
|
513
|
+
delete newField.items;
|
|
514
|
+
calculatedSchema = getSimpleFieldSchema(newField);
|
|
504
515
|
}
|
|
505
|
-
calculatedSchema = getObjectFieldSchema(newField, items);
|
|
506
|
-
newField.items = items.map((i) => i.field);
|
|
507
516
|
}
|
|
508
517
|
else {
|
|
509
518
|
calculatedSchema = getSimpleFieldSchema(newField);
|
|
@@ -600,7 +609,7 @@ const extract_recursive = async (validation, options, path = ``) => {
|
|
|
600
609
|
const key = lodash_1.default.compact([path, field.key]).join(`.`);
|
|
601
610
|
lodash_1.default.set(response, key, options.original ? field.original : field.value);
|
|
602
611
|
}
|
|
603
|
-
return response;
|
|
612
|
+
return JSON.parse(JSON.stringify(response));
|
|
604
613
|
}
|
|
605
614
|
catch (e) {
|
|
606
615
|
throw e;
|
package/package.json
CHANGED
|
@@ -505,9 +505,12 @@ const recursive_schema = async (field: Field, data: Record<string, any>, options
|
|
|
505
505
|
|
|
506
506
|
const value = _.get(data, relativeKey, newField.default);
|
|
507
507
|
|
|
508
|
-
// resolve value with context (even if it's not valid
|
|
508
|
+
// resolve value with context (even if it's not valid)
|
|
509
509
|
const resolved = context.resolve(newField, value, options.context);
|
|
510
|
-
|
|
510
|
+
_.set(data, relativeKey, resolved);
|
|
511
|
+
|
|
512
|
+
// omit undefined for array mappings
|
|
513
|
+
if (typeof resolved === `undefined` && options.array) { return { schema: null, field: null }; }
|
|
511
514
|
|
|
512
515
|
// get schema for field with data
|
|
513
516
|
let calculatedSchema: Joi.Schema;
|
|
@@ -521,6 +524,10 @@ const recursive_schema = async (field: Field, data: Record<string, any>, options
|
|
|
521
524
|
const { schema: itemSchema } = await recursive_schema(noArrayField, data, { alter: false, relative: `${relativeKey}[${i}]`, array: true, context: options.context });
|
|
522
525
|
if (itemSchema) { itemSchemas.push(itemSchema); }
|
|
523
526
|
}
|
|
527
|
+
|
|
528
|
+
// override array value - omit undefined items
|
|
529
|
+
const withoutUndefined = resolved.filter((r) => typeof r !== `undefined`);
|
|
530
|
+
_.set(data, relativeKey, withoutUndefined);
|
|
524
531
|
}
|
|
525
532
|
|
|
526
533
|
calculatedSchema = getOrderedArrayFieldSchema(newField, itemSchemas);
|
|
@@ -543,15 +550,20 @@ const recursive_schema = async (field: Field, data: Record<string, any>, options
|
|
|
543
550
|
calculatedSchema = getItemsArrayFieldSchema(newField, [genericItemSchema]);
|
|
544
551
|
}
|
|
545
552
|
} else if (newField.type === `dict` && newField.items) {
|
|
546
|
-
|
|
553
|
+
if (resolved || newField.required) {
|
|
554
|
+
const items: { key: string, schema: Joi.Schema, field: Field }[] = [];
|
|
547
555
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
556
|
+
for (const item of newField.items) {
|
|
557
|
+
const recursive = await recursive_schema(item, data, { alter: options.alter && true, relative: relativeKey, context: options.context });
|
|
558
|
+
if (recursive) { items.push({ key: item.key, schema: recursive.schema, field: recursive.field }); }
|
|
559
|
+
}
|
|
552
560
|
|
|
553
|
-
|
|
554
|
-
|
|
561
|
+
calculatedSchema = getObjectFieldSchema(newField, items);
|
|
562
|
+
newField.items = items.map((i) => i.field);
|
|
563
|
+
} else {
|
|
564
|
+
delete newField.items;
|
|
565
|
+
calculatedSchema = getSimpleFieldSchema(newField);
|
|
566
|
+
}
|
|
555
567
|
} else {
|
|
556
568
|
calculatedSchema = getSimpleFieldSchema(newField);
|
|
557
569
|
}
|
|
@@ -642,7 +654,8 @@ const extract_recursive = async (validation: Field<ValidationExtended>[], option
|
|
|
642
654
|
const key = _.compact([path, field.key]).join(`.`);
|
|
643
655
|
_.set(response, key, options.original ? field.original : field.value);
|
|
644
656
|
}
|
|
645
|
-
|
|
657
|
+
// remove undefined values
|
|
658
|
+
return JSON.parse(JSON.stringify(response));
|
|
646
659
|
} catch (e) { throw e; }
|
|
647
660
|
};
|
|
648
661
|
|