From a65a86c6bf7937c5699c730dec93ae3c66ad03f1 Mon Sep 17 00:00:00 2001
From: Prashant Rawat <pr7prashant@gmail.com>
Date: Tue, 30 May 2023 01:30:03 +0530
Subject: [PATCH] Add docstrings for validators service (#9197)

* add docstrings for validators service

* Update services/validators.js

---------

Co-authored-by: chris48s <chris48s@users.noreply.github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
---
 services/validators.js | 64 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 60 insertions(+), 4 deletions(-)

diff --git a/services/validators.js b/services/validators.js
index 4586f08a37..df8d72a4d4 100644
--- a/services/validators.js
+++ b/services/validators.js
@@ -1,3 +1,9 @@
+/**
+ * This module contains commonly used validators.
+ *
+ * @module
+ */
+
 import {
   semver as joiSemver,
   semverRange as joiSemverRange,
@@ -5,21 +11,71 @@ import {
 import joi from 'joi'
 const Joi = joi.extend(joiSemver).extend(joiSemverRange)
 
+/**
+ * Joi validator that checks if a value is a number, an integer, and greater than or equal to zero.
+ *
+ * @type {Joi}
+ */
 const optionalNonNegativeInteger = Joi.number().integer().min(0)
 
 export { optionalNonNegativeInteger }
+
+/**
+ * Joi validator that checks if a value is a number, an integer, greater than or equal to zero and the value must be present.
+ *
+ * @type {Joi}
+ */
 export const nonNegativeInteger = optionalNonNegativeInteger.required()
+
+/**
+ * Joi validator that checks if a value is a number, an integer and the value must be present.
+ *
+ * @type {Joi}
+ */
 export const anyInteger = Joi.number().integer().required()
+
+/**
+ * Joi validator that checks if a value is a valid semantic versioning string and the value must be present.
+ *
+ * @type {Joi}
+ */
 export const semver = Joi.semver().valid().required()
+
+/**
+ * Joi validator that checks if a value is a valid semantic versioning range and the value must be present.
+ *
+ * @type {Joi}
+ */
 export const semverRange = Joi.semverRange().valid().required()
+
+/**
+ * Joi validator that checks if a value is a string that matches a regular expression.
+ * The regular expression matches strings that start with one or more digits, followed by zero or more groups of a dot and one or more digits,
+ * followed by an optional suffix that starts with a dash or a plus sign and can contain any characters.
+ * This validator can be used to validate properties that can be version strings with an optional suffix or absent.
+ * For example, some valid values for this validator are: 1, 1.0, 1.0.0, 1.0.0-beta
+ * Some invalid values for this validator are: abc, 1.a, 1.0-, .1
+ *
+ * @type {Joi}
+ */
 export const optionalDottedVersionNClausesWithOptionalSuffix =
   Joi.string().regex(/^\d+(\.\d+)*([-+].*)?$/)
-// TODO This accepts URLs with query strings and fragments, which for some
-// purposes should be rejected.
+
+/**
+ * Joi validator that checks if a value is a URL
+ *
+ * TODO: This accepts URLs with query strings and fragments, which for some purposes should be rejected.
+ *
+ * @type {Joi}
+ */
 export const optionalUrl = Joi.string().uri({ scheme: ['http', 'https'] })
 
-// validator for a file size we are going to pass to bytes.parse
-// see https://github.com/visionmedia/bytes.js#bytesparsestringnumber-value-numbernull
+/**
+ * Joi validator for a file size we are going to pass to bytes.parse
+ * see https://github.com/visionmedia/bytes.js#bytesparsestringnumber-value-numbernull
+ *
+ * @type {Joi}
+ */
 export const fileSize = Joi.string()
   .regex(/^[0-9]+(b|kb|mb|gb|tb)$/i)
   .required()
-- 
GitLab