@beseif-solutions/prow-core 0.2.3 → 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 = () => 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(`/`)), joi_1.default.object().pattern(joi_1.default.string(), joi_1.default.link(`/`)));
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
  })
@@ -502,11 +506,17 @@ const validate_internal = async (fields, data, options) => {
502
506
  if (error) {
503
507
  extended = {
504
508
  valid: false,
505
- errors: error.details.map((d) => ({
509
+ errors: error.details ? error.details.map((d) => ({
506
510
  type: d.type,
507
511
  path: convertPath([field.key, ...d.path]),
508
512
  message: d.message,
509
- })),
513
+ })) : [
514
+ {
515
+ type: `unknown`,
516
+ path: field.key,
517
+ message: error.message,
518
+ },
519
+ ],
510
520
  original: value,
511
521
  value: null,
512
522
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beseif-solutions/prow-core",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Prow core functionalities and classes",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -242,13 +242,17 @@ const defaultSchema = (type: Joi.Schema) =>
242
242
  otherwise: type,
243
243
  });
244
244
 
245
- const anySchema = () =>
246
- Joi.alternatives(
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({
@@ -710,11 +714,17 @@ const validate_internal = async (fields: Field[], data: Record<string, any>, opt
710
714
  if (error) {
711
715
  extended = {
712
716
  valid: false,
713
- errors: error.details.map((d) => ({
717
+ errors: error.details ? error.details.map((d) => ({
714
718
  type: d.type,
715
719
  path: convertPath([field.key, ...d.path]),
716
720
  message: d.message,
717
- })),
721
+ })) : [
722
+ {
723
+ type: `unknown`,
724
+ path: field.key,
725
+ message: error.message,
726
+ },
727
+ ],
718
728
  original: value,
719
729
  value: null,
720
730
  };