@forge/cache
1.0.26-experimental-04cc2b91.0.27-next.0
out/utils/validator.js~
out/utils/validator.jsModified+7−7
Index: package/out/utils/validator.js
===================================================================
--- package/out/utils/validator.js
+++ package/out/utils/validator.js
@@ -1,13 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
-exports.InvalidValueTypeError = exports.WrongTypeOperationError = exports.ValueIsRequiredError = exports.MaxValueSizeExceededError = exports.InvalidKeyPatternError = exports.MaxValidKeyLengthExceededError = exports.MinValidKeyLengthRequiredError = exports.TunnelError = void 0;
-exports.assertIsValidValue = assertIsValidValue;
-exports.assertAndThrowIfArray = assertAndThrowIfArray;
-exports.assertAndThrowIfNotArray = assertAndThrowIfNotArray;
-exports.assertIsValidKey = assertIsValidKey;
-exports.assertIsSizedValue = assertIsSizedValue;
-exports.getErrorMessageObj = getErrorMessageObj;
+exports.getErrorMessageObj = exports.assertIsSizedValue = exports.assertIsValidKey = exports.assertAndThrowIfNotArray = exports.assertAndThrowIfArray = exports.assertIsValidValue = exports.InvalidValueTypeError = exports.WrongTypeOperationError = exports.ValueIsRequiredError = exports.MaxValueSizeExceededError = exports.InvalidKeyPatternError = exports.MaxValidKeyLengthExceededError = exports.MinValidKeyLengthRequiredError = exports.TunnelError = void 0;
const tslib_1 = require("tslib");
const object_sizeof_1 = tslib_1.__importDefault(require("object-sizeof"));
const errors_codes_1 = require("../errors-codes");
const MIN_VALID_KEY_LENGTH = 1;
@@ -87,18 +81,21 @@
if (typeof value !== 'string') {
throw new InvalidValueTypeError(typeof value);
}
}
+exports.assertIsValidValue = assertIsValidValue;
function assertAndThrowIfArray(value) {
if (value && Array.isArray(value)) {
throw new WrongTypeOperationError();
}
}
+exports.assertAndThrowIfArray = assertAndThrowIfArray;
function assertAndThrowIfNotArray(value) {
if (value && !Array.isArray(value)) {
throw new WrongTypeOperationError();
}
}
+exports.assertAndThrowIfNotArray = assertAndThrowIfNotArray;
function assertIsValidKey(key) {
if (typeof key !== 'string') {
throw new Error('Provided key must be a string');
}
@@ -111,13 +108,15 @@
if (!VALID_KEY_REGEX.test(key)) {
throw new InvalidKeyPatternError();
}
}
+exports.assertIsValidKey = assertIsValidKey;
function assertIsSizedValue(value) {
if ((0, object_sizeof_1.default)(value) > MAX_VALID_VALUE_LENGTH) {
throw new MaxValueSizeExceededError((0, object_sizeof_1.default)(value), MAX_VALID_VALUE_LENGTH);
}
}
+exports.assertIsSizedValue = assertIsSizedValue;
function getErrorMessageObj(title, code = 'BadRequest') {
const obj = {
error: {
code: code,
@@ -125,4 +124,5 @@
}
};
return JSON.stringify(obj);
}
+exports.getErrorMessageObj = getErrorMessageObj;