PromoCursed/node_modules/.cache/babel-loader/42f94b448727780917cf2ae3f95195311ced93faaba133cc018fc0beeb61265f.json

1 line
34 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"import _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport _typeof from \"@babel/runtime/helpers/esm/typeof\";\nimport _classCallCheck from \"@babel/runtime/helpers/esm/classCallCheck\";\nimport _createClass from \"@babel/runtime/helpers/esm/createClass\";\nimport _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport { messages as defaultMessages, newMessages } from \"./messages\";\nimport { asyncMap, complementError, convertFieldsError, deepMerge, format, warning } from \"./util\";\nimport validators from \"./validator/index\";\nexport * from \"./interface\";\n\n/**\n * Encapsulates a validation schema.\n *\n * @param descriptor An object declaring validation rules\n * for this schema.\n */\nvar Schema = /*#__PURE__*/function () {\n function Schema(descriptor) {\n _classCallCheck(this, Schema);\n // ======================== Instance ========================\n _defineProperty(this, \"rules\", null);\n _defineProperty(this, \"_messages\", defaultMessages);\n this.define(descriptor);\n }\n _createClass(Schema, [{\n key: \"define\",\n value: function define(rules) {\n var _this = this;\n if (!rules) {\n throw new Error('Cannot configure a schema with no rules');\n }\n if (_typeof(rules) !== 'object' || Array.isArray(rules)) {\n throw new Error('Rules must be an object');\n }\n this.rules = {};\n Object.keys(rules).forEach(function (name) {\n var item = rules[name];\n _this.rules[name] = Array.isArray(item) ? item : [item];\n });\n }\n }, {\n key: \"messages\",\n value: function messages(_messages) {\n if (_messages) {\n this._messages = deepMerge(newMessages(), _messages);\n }\n return this._messages;\n }\n }, {\n key: \"validate\",\n value: function validate(source_) {\n var _this2 = this;\n var o = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var oc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {};\n var source = source_;\n var options = o;\n var callback = oc;\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n if (!this.rules || Object.keys(this.rules).length === 0) {\n if (callback) {\n callback(null, source);\n }\n return Promise.resolve(source);\n }\n function complete(results) {\n var errors = [];\n var fields = {};\n function add(e) {\n if (Array.isArray(e)) {\n var _errors;\n errors = (_errors = errors).concat.apply(_errors, _toConsumableArray(e));\n } else {\n errors.push(e);\n }\n }\n for (var i = 0; i < results.length; i++) {\n add(results[i]);\n }\n if (!errors.length) {\n callback(null, source);\n } else {\n fields = convertFieldsError(errors);\n callback(errors, fields);\n }\n }\n if (options.messages) {\n var messages = this.messages();\n if (messages === defaultMessages) {\n messages = newMessages();\n }\n deepMerge(messages, options.messages);\n options.messages = messages;\n } else {\n options.messages = this.messages();\n }\n var series = {};\n var keys = options.keys || Object.keys(this.rules);\n keys.forEach(function (z) {\n var arr = _this2.rules[z];\n var value = source[z];\n arr.forEach(function (r) {\n var rule = r;\n if (typeof rule.transform === 'function') {\n if (source === source_) {\n source = _objectSpread({}, source);\n }\n value = source[z] = rule.transform(value);\n if (value !== undefined && value !== null) {\n rule.type = rule.type || (Array.isArray(value) ? 'array' : _