@beseif-solutions/prow-core 0.4.4 → 0.4.5

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.
@@ -58,13 +58,14 @@ const defaultSchema = (type) => joi_1.default.when(`as_array`, {
58
58
  then: joi_1.default.array().items(type),
59
59
  otherwise: type,
60
60
  });
61
- const anySchema = () => {
61
+ const anySchema = (nullish = true) => {
62
62
  const randId = Math.random().toString(36).substring(2, 15);
63
- 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}`)))
63
+ 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}`)), ...nullish ? [joi_1.default.valid(null, ``)] : [])
64
64
  .id(randId);
65
65
  };
66
66
  const anyInputFieldSchema = () => joi_1.default.object({
67
67
  default: defaultSchema(anySchema()),
68
+ allow_nullish: joi_1.default.bool().default(true),
68
69
  })
69
70
  .concat(joi_1.default.object({
70
71
  format: joi_1.default.string().valid(`select`),
@@ -248,10 +249,7 @@ const getSimpleFieldSchema = (field) => {
248
249
  let typeSchema;
249
250
  switch (field.type) {
250
251
  case `any`:
251
- typeSchema = anySchema();
252
- if (field.allow_nullish) {
253
- typeSchema = typeSchema.allow(null, ``, 0);
254
- }
252
+ typeSchema = anySchema(field.allow_nullish);
255
253
  break;
256
254
  case `boolean`:
257
255
  typeSchema = joi_1.default.bool();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beseif-solutions/prow-core",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "description": "Prow core functionalities and classes",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -249,7 +249,7 @@ const defaultSchema = (type: Joi.Schema) =>
249
249
  otherwise: type,
250
250
  });
251
251
 
252
- const anySchema = () => {
252
+ const anySchema = (nullish = true) => {
253
253
  // eslint-disable-next-line @typescript-eslint/no-magic-numbers
254
254
  const randId = Math.random().toString(36).substring(2, 15);
255
255
  return Joi.alternatives(
@@ -257,13 +257,16 @@ const anySchema = () => {
257
257
  Joi.bool(),
258
258
  Joi.number(),
259
259
  Joi.array().items(Joi.link(`#${randId}`)),
260
- Joi.object().pattern(Joi.string(), Joi.link(`#${randId}`)))
260
+ Joi.object().pattern(Joi.string(), Joi.link(`#${randId}`)),
261
+ ...nullish ? [Joi.valid(null, ``)] : [],
262
+ )
261
263
  .id(randId);
262
264
  };
263
265
 
264
266
  const anyInputFieldSchema = () =>
265
267
  Joi.object({
266
268
  default: defaultSchema(anySchema()),
269
+ allow_nullish: Joi.bool().default(true),
267
270
  })
268
271
  .concat(Joi.object({
269
272
  format: Joi.string().valid(`select`),
@@ -474,9 +477,7 @@ const getSimpleFieldSchema = (field: Field) => {
474
477
  let typeSchema: Joi.Schema;
475
478
  switch (field.type) {
476
479
  case `any`:
477
- typeSchema = anySchema();
478
- // allow null values for any type
479
- if (field.allow_nullish) { typeSchema = typeSchema.allow(null, ``, 0); }
480
+ typeSchema = anySchema(field.allow_nullish);
480
481
  break;
481
482
  case `boolean`:
482
483
  typeSchema = Joi.bool();