d3ae7e344d6533a0edbf46b11301eb66.json
33.9 KB
{"ast":null,"code":"import _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _regeneratorRuntime from \"@babel/runtime/regenerator\";\nimport _asyncToGenerator from \"@babel/runtime/helpers/esm/asyncToGenerator\";\nimport _typeof from \"@babel/runtime/helpers/esm/typeof\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport RawAsyncValidator from 'async-validator';\nimport * as React from 'react';\nimport warning from \"rc-util/es/warning\";\nimport { setValues } from './valueUtil';\nimport { defaultValidateMessages } from './messages'; // Remove incorrect original ts define\n\nvar AsyncValidator = RawAsyncValidator;\n/**\n * Replace with template.\n * `I'm ${name}` + { name: 'bamboo' } = I'm bamboo\n */\n\nfunction replaceMessage(template, kv) {\n return template.replace(/\\$\\{\\w+\\}/g, function (str) {\n var key = str.slice(2, -1);\n return kv[key];\n });\n}\n/**\n * We use `async-validator` to validate rules. So have to hot replace the message with validator.\n * { required: '${name} is required' } => { required: () => 'field is required' }\n */\n\n\nfunction convertMessages(messages, name, rule, messageVariables) {\n var kv = _objectSpread(_objectSpread({}, rule), {}, {\n name: name,\n enum: (rule.enum || []).join(', ')\n });\n\n var replaceFunc = function replaceFunc(template, additionalKV) {\n return function () {\n return replaceMessage(template, _objectSpread(_objectSpread({}, kv), additionalKV));\n };\n };\n /* eslint-disable no-param-reassign */\n\n\n function fillTemplate(source) {\n var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n Object.keys(source).forEach(function (ruleName) {\n var value = source[ruleName];\n\n if (typeof value === 'string') {\n target[ruleName] = replaceFunc(value, messageVariables);\n } else if (value && _typeof(value) === 'object') {\n target[ruleName] = {};\n fillTemplate(value, target[ruleName]);\n } else {\n target[ruleName] = value;\n }\n });\n return target;\n }\n /* eslint-enable */\n\n\n return fillTemplate(setValues({}, defaultValidateMessages, messages));\n}\n\nfunction validateRule(_x, _x2, _x3, _x4, _x5) {\n return _validateRule.apply(this, arguments);\n}\n/**\n * We use `async-validator` to validate the value.\n * But only check one value in a time to avoid namePath validate issue.\n */\n\n\nfunction _validateRule() {\n _validateRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(name, value, rule, options, messageVariables) {\n var cloneRule, subRuleField, validator, messages, result, subResults;\n return _regeneratorRuntime.wrap(function _callee2$(_context2) {\n while (1) {\n switch (_context2.prev = _context2.next) {\n case 0:\n cloneRule = _objectSpread({}, rule); // We should special handle array validate\n\n subRuleField = null;\n\n if (cloneRule && cloneRule.type === 'array' && cloneRule.defaultField) {\n subRuleField = cloneRule.defaultField;\n delete cloneRule.defaultField;\n }\n\n validator = new AsyncValidator(_defineProperty({}, name, [cloneRule]));\n messages = convertMessages(options.validateMessages, name, cloneRule, messageVariables);\n validator.messages(messages);\n result = [];\n _context2.prev = 7;\n _context2.next = 10;\n return Promise.resolve(validator.validate(_defineProperty({}, name, value), _objectSpread({}, options)));\n\n case 10:\n _context2.next = 15;\n break;\n\n case 12:\n _context2.prev = 12;\n _context2.t0 = _context2[\"catch\"](7);\n\n if (_context2.t0.errors) {\n result = _context2.t0.errors.map(function (_ref2, index) {\n var message = _ref2.message;\n return (// Wrap ReactNode with `key`\n\n /*#__PURE__*/\n React.isValidElement(message) ? /*#__PURE__*/React.cloneElement(message, {\n key: \"error_\".concat(index)\n }) : message\n );\n });\n } else {\n console.error(_context2.t0);\n result = [messages.default()];\n }\n\n case 15:\n if (!(!result.length && subRuleField)) {\n _context2.next = 20;\n break;\n }\n\n _context2.next = 18;\n return Promise.all(value.map(function (subValue, i) {\n return validateRule(\"\".concat(name, \".\").concat(i), subValue, subRuleField, options, messageVariables);\n }));\n\n case 18:\n subResults = _context2.sent;\n return _context2.abrupt(\"return\", subResults.reduce(function (prev, errors) {\n return [].concat(_toConsumableArray(prev), _toConsumableArray(errors));\n }, []));\n\n case 20:\n return _context2.abrupt(\"return\", result);\n\n case 21:\n case \"end\":\n return _context2.stop();\n }\n }\n }, _callee2, null, [[7, 12]]);\n }));\n return _validateRule.apply(this, arguments);\n}\n\nexport function validateRules(namePath, value, rules, options, validateFirst, messageVariables) {\n var name = namePath.join('.'); // Fill rule with context\n\n var filledRules = rules.map(function (currentRule) {\n var originValidatorFunc = currentRule.validator;\n\n if (!originValidatorFunc) {\n return currentRule;\n }\n\n return _objectSpread(_objectSpread({}, currentRule), {}, {\n validator: function validator(rule, val, callback) {\n var hasPromise = false; // Wrap callback only accept when promise not provided\n\n var wrappedCallback = function wrappedCallback() {\n for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n } // Wait a tick to make sure return type is a promise\n\n\n Promise.resolve().then(function () {\n warning(!hasPromise, 'Your validator function has already return a promise. `callback` will be ignored.');\n\n if (!hasPromise) {\n callback.apply(void 0, args);\n }\n });\n }; // Get promise\n\n\n var promise = originValidatorFunc(rule, val, wrappedCallback);\n hasPromise = promise && typeof promise.then === 'function' && typeof promise.catch === 'function';\n /**\n * 1. Use promise as the first priority.\n * 2. If promise not exist, use callback with warning instead\n */\n\n warning(hasPromise, '`callback` is deprecated. Please return a promise instead.');\n\n if (hasPromise) {\n promise.then(function () {\n callback();\n }).catch(function (err) {\n callback(err || ' ');\n });\n }\n }\n });\n });\n var summaryPromise;\n\n if (validateFirst === true) {\n // >>>>> Validate by serialization\n summaryPromise = new Promise( /*#__PURE__*/function () {\n var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(resolve, reject) {\n var i, errors;\n return _regeneratorRuntime.wrap(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n i = 0;\n\n case 1:\n if (!(i < filledRules.length)) {\n _context.next = 11;\n break;\n }\n\n _context.next = 4;\n return validateRule(name, value, filledRules[i], options, messageVariables);\n\n case 4:\n errors = _context.sent;\n\n if (!errors.length) {\n _context.next = 8;\n break;\n }\n\n reject(errors);\n return _context.abrupt(\"return\");\n\n case 8:\n i += 1;\n _context.next = 1;\n break;\n\n case 11:\n /* eslint-enable */\n resolve([]);\n\n case 12:\n case \"end\":\n return _context.stop();\n }\n }\n }, _callee);\n }));\n\n return function (_x6, _x7) {\n return _ref.apply(this, arguments);\n };\n }());\n } else {\n // >>>>> Validate by parallel\n var rulePromises = filledRules.map(function (rule) {\n return validateRule(name, value, rule, options, messageVariables);\n });\n summaryPromise = (validateFirst ? finishOnFirstFailed(rulePromises) : finishOnAllFailed(rulePromises)).then(function (errors) {\n if (!errors.length) {\n return [];\n }\n\n return Promise.reject(errors);\n });\n } // Internal catch error to avoid console error log.\n\n\n summaryPromise.catch(function (e) {\n return e;\n });\n return summaryPromise;\n}\n\nfunction finishOnAllFailed(_x8) {\n return _finishOnAllFailed.apply(this, arguments);\n}\n\nfunction _finishOnAllFailed() {\n _finishOnAllFailed = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(rulePromises) {\n return _regeneratorRuntime.wrap(function _callee3$(_context3) {\n while (1) {\n switch (_context3.prev = _context3.next) {\n case 0:\n return _context3.abrupt(\"return\", Promise.all(rulePromises).then(function (errorsList) {\n var _ref3;\n\n var errors = (_ref3 = []).concat.apply(_ref3, _toConsumableArray(errorsList));\n\n return errors;\n }));\n\n case 1:\n case \"end\":\n return _context3.stop();\n }\n }\n }, _callee3);\n }));\n return _finishOnAllFailed.apply(this, arguments);\n}\n\nfunction finishOnFirstFailed(_x9) {\n return _finishOnFirstFailed.apply(this, arguments);\n}\n\nfunction _finishOnFirstFailed() {\n _finishOnFirstFailed = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(rulePromises) {\n var count;\n return _regeneratorRuntime.wrap(function _callee4$(_context4) {\n while (1) {\n switch (_context4.prev = _context4.next) {\n case 0:\n count = 0;\n return _context4.abrupt(\"return\", new Promise(function (resolve) {\n rulePromises.forEach(function (promise) {\n promise.then(function (errors) {\n if (errors.length) {\n resolve(errors);\n }\n\n count += 1;\n\n if (count === rulePromises.length) {\n resolve([]);\n }\n });\n });\n }));\n\n case 2:\n case \"end\":\n return _context4.stop();\n }\n }\n }, _callee4);\n }));\n return _finishOnFirstFailed.apply(this, arguments);\n}","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/rc-field-form/es/utils/validateUtil.js"],"names":["_toConsumableArray","_defineProperty","_regeneratorRuntime","_asyncToGenerator","_typeof","_objectSpread","RawAsyncValidator","React","warning","setValues","defaultValidateMessages","AsyncValidator","replaceMessage","template","kv","replace","str","key","slice","convertMessages","messages","name","rule","messageVariables","enum","join","replaceFunc","additionalKV","fillTemplate","source","target","arguments","length","undefined","Object","keys","forEach","ruleName","value","validateRule","_x","_x2","_x3","_x4","_x5","_validateRule","apply","mark","_callee2","options","cloneRule","subRuleField","validator","result","subResults","wrap","_callee2$","_context2","prev","next","type","defaultField","validateMessages","Promise","resolve","validate","t0","errors","map","_ref2","index","message","isValidElement","cloneElement","concat","console","error","default","all","subValue","i","sent","abrupt","reduce","stop","validateRules","namePath","rules","validateFirst","filledRules","currentRule","originValidatorFunc","val","callback","hasPromise","wrappedCallback","_len","args","Array","_key","then","promise","catch","err","summaryPromise","_ref","_callee","reject","_callee$","_context","_x6","_x7","rulePromises","finishOnFirstFailed","finishOnAllFailed","e","_x8","_finishOnAllFailed","_callee3","_callee3$","_context3","errorsList","_ref3","_x9","_finishOnFirstFailed","_callee4","count","_callee4$","_context4"],"mappings":"AAAA,OAAOA,kBAAP,MAA+B,8CAA/B;AACA,OAAOC,eAAP,MAA4B,2CAA5B;AACA,OAAOC,mBAAP,MAAgC,4BAAhC;AACA,OAAOC,iBAAP,MAA8B,6CAA9B;AACA,OAAOC,OAAP,MAAoB,mCAApB;AACA,OAAOC,aAAP,MAA0B,0CAA1B;AACA,OAAOC,iBAAP,MAA8B,iBAA9B;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,OAAOC,OAAP,MAAoB,oBAApB;AAC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K,CAAL;AACEmE,YAAAA,KAAK,GAAG,CAAR;AACA,mBAAOE,SAAS,CAAC9C,MAAV,CAAiB,QAAjB,EAA2B,IAAInB,OAAJ,CAAY,UAAUC,OAAV,EAAmB;AAC/DgD,cAAAA,YAAY,CAAC5E,OAAb,CAAqB,UAAUiE,OAAV,EAAmB;AACtCA,gBAAAA,OAAO,CAACD,IAAR,CAAa,UAAUjC,MAAV,EAAkB;AAC7B,sBAAIA,MAAM,CAACnC,MAAX,EAAmB;AACjBgC,oBAAAA,OAAO,CAACG,MAAD,CAAP;AACD;;AAED2D,kBAAAA,KAAK,IAAI,CAAT;;AAEA,sBAAIA,KAAK,KAAKd,YAAY,CAAChF,MAA3B,EAAmC;AACjCgC,oBAAAA,OAAO,CAAC,EAAD,CAAP;AACD;AACF,iBAVD;AAWD,eAZD;AAaD,aAdiC,CAA3B,CAAP;;AAgBF,eAAK,CAAL;AACA,eAAK,KAAL;AACE,mBAAOgE,SAAS,CAAC5C,IAAV,EAAP;AArBJ;AAuBD;AACF,KA1BM,EA0BJyC,QA1BI,CAAP;AA2BD,GA7BsD,CAAf,CAAxC;AA8BA,SAAOD,oBAAoB,CAAC9E,KAArB,CAA2B,IAA3B,EAAiCf,SAAjC,CAAP;AACD","sourcesContent":["import _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _regeneratorRuntime from \"@babel/runtime/regenerator\";\nimport _asyncToGenerator from \"@babel/runtime/helpers/esm/asyncToGenerator\";\nimport _typeof from \"@babel/runtime/helpers/esm/typeof\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport RawAsyncValidator from 'async-validator';\nimport * as React from 'react';\nimport warning from \"rc-util/es/warning\";\nimport { setValues } from './valueUtil';\nimport { defaultValidateMessages } from './messages'; // Remove incorrect original ts define\n\nvar AsyncValidator = RawAsyncValidator;\n/**\n * Replace with template.\n * `I'm ${name}` + { name: 'bamboo' } = I'm bamboo\n */\n\nfunction replaceMessage(template, kv) {\n return template.replace(/\\$\\{\\w+\\}/g, function (str) {\n var key = str.slice(2, -1);\n return kv[key];\n });\n}\n/**\n * We use `async-validator` to validate rules. So have to hot replace the message with validator.\n * { required: '${name} is required' } => { required: () => 'field is required' }\n */\n\n\nfunction convertMessages(messages, name, rule, messageVariables) {\n var kv = _objectSpread(_objectSpread({}, rule), {}, {\n name: name,\n enum: (rule.enum || []).join(', ')\n });\n\n var replaceFunc = function replaceFunc(template, additionalKV) {\n return function () {\n return replaceMessage(template, _objectSpread(_objectSpread({}, kv), additionalKV));\n };\n };\n /* eslint-disable no-param-reassign */\n\n\n function fillTemplate(source) {\n var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n Object.keys(source).forEach(function (ruleName) {\n var value = source[ruleName];\n\n if (typeof value === 'string') {\n target[ruleName] = replaceFunc(value, messageVariables);\n } else if (value && _typeof(value) === 'object') {\n target[ruleName] = {};\n fillTemplate(value, target[ruleName]);\n } else {\n target[ruleName] = value;\n }\n });\n return target;\n }\n /* eslint-enable */\n\n\n return fillTemplate(setValues({}, defaultValidateMessages, messages));\n}\n\nfunction validateRule(_x, _x2, _x3, _x4, _x5) {\n return _validateRule.apply(this, arguments);\n}\n/**\n * We use `async-validator` to validate the value.\n * But only check one value in a time to avoid namePath validate issue.\n */\n\n\nfunction _validateRule() {\n _validateRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(name, value, rule, options, messageVariables) {\n var cloneRule, subRuleField, validator, messages, result, subResults;\n return _regeneratorRuntime.wrap(function _callee2$(_context2) {\n while (1) {\n switch (_context2.prev = _context2.next) {\n case 0:\n cloneRule = _objectSpread({}, rule); // We should special handle array validate\n\n subRuleField = null;\n\n if (cloneRule && cloneRule.type === 'array' && cloneRule.defaultField) {\n subRuleField = cloneRule.defaultField;\n delete cloneRule.defaultField;\n }\n\n validator = new AsyncValidator(_defineProperty({}, name, [cloneRule]));\n messages = convertMessages(options.validateMessages, name, cloneRule, messageVariables);\n validator.messages(messages);\n result = [];\n _context2.prev = 7;\n _context2.next = 10;\n return Promise.resolve(validator.validate(_defineProperty({}, name, value), _objectSpread({}, options)));\n\n case 10:\n _context2.next = 15;\n break;\n\n case 12:\n _context2.prev = 12;\n _context2.t0 = _context2[\"catch\"](7);\n\n if (_context2.t0.errors) {\n result = _context2.t0.errors.map(function (_ref2, index) {\n var message = _ref2.message;\n return (// Wrap ReactNode with `key`\n\n /*#__PURE__*/\n React.isValidElement(message) ? /*#__PURE__*/React.cloneElement(message, {\n key: \"error_\".concat(index)\n }) : message\n );\n });\n } else {\n console.error(_context2.t0);\n result = [messages.default()];\n }\n\n case 15:\n if (!(!result.length && subRuleField)) {\n _context2.next = 20;\n break;\n }\n\n _context2.next = 18;\n return Promise.all(value.map(function (subValue, i) {\n return validateRule(\"\".concat(name, \".\").concat(i), subValue, subRuleField, options, messageVariables);\n }));\n\n case 18:\n subResults = _context2.sent;\n return _context2.abrupt(\"return\", subResults.reduce(function (prev, errors) {\n return [].concat(_toConsumableArray(prev), _toConsumableArray(errors));\n }, []));\n\n case 20:\n return _context2.abrupt(\"return\", result);\n\n case 21:\n case \"end\":\n return _context2.stop();\n }\n }\n }, _callee2, null, [[7, 12]]);\n }));\n return _validateRule.apply(this, arguments);\n}\n\nexport function validateRules(namePath, value, rules, options, validateFirst, messageVariables) {\n var name = namePath.join('.'); // Fill rule with context\n\n var filledRules = rules.map(function (currentRule) {\n var originValidatorFunc = currentRule.validator;\n\n if (!originValidatorFunc) {\n return currentRule;\n }\n\n return _objectSpread(_objectSpread({}, currentRule), {}, {\n validator: function validator(rule, val, callback) {\n var hasPromise = false; // Wrap callback only accept when promise not provided\n\n var wrappedCallback = function wrappedCallback() {\n for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n }\n\n // Wait a tick to make sure return type is a promise\n Promise.resolve().then(function () {\n warning(!hasPromise, 'Your validator function has already return a promise. `callback` will be ignored.');\n\n if (!hasPromise) {\n callback.apply(void 0, args);\n }\n });\n }; // Get promise\n\n\n var promise = originValidatorFunc(rule, val, wrappedCallback);\n hasPromise = promise && typeof promise.then === 'function' && typeof promise.catch === 'function';\n /**\n * 1. Use promise as the first priority.\n * 2. If promise not exist, use callback with warning instead\n */\n\n warning(hasPromise, '`callback` is deprecated. Please return a promise instead.');\n\n if (hasPromise) {\n promise.then(function () {\n callback();\n }).catch(function (err) {\n callback(err || ' ');\n });\n }\n }\n });\n });\n var summaryPromise;\n\n if (validateFirst === true) {\n // >>>>> Validate by serialization\n summaryPromise = new Promise( /*#__PURE__*/function () {\n var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(resolve, reject) {\n var i, errors;\n return _regeneratorRuntime.wrap(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n i = 0;\n\n case 1:\n if (!(i < filledRules.length)) {\n _context.next = 11;\n break;\n }\n\n _context.next = 4;\n return validateRule(name, value, filledRules[i], options, messageVariables);\n\n case 4:\n errors = _context.sent;\n\n if (!errors.length) {\n _context.next = 8;\n break;\n }\n\n reject(errors);\n return _context.abrupt(\"return\");\n\n case 8:\n i += 1;\n _context.next = 1;\n break;\n\n case 11:\n /* eslint-enable */\n resolve([]);\n\n case 12:\n case \"end\":\n return _context.stop();\n }\n }\n }, _callee);\n }));\n\n return function (_x6, _x7) {\n return _ref.apply(this, arguments);\n };\n }());\n } else {\n // >>>>> Validate by parallel\n var rulePromises = filledRules.map(function (rule) {\n return validateRule(name, value, rule, options, messageVariables);\n });\n summaryPromise = (validateFirst ? finishOnFirstFailed(rulePromises) : finishOnAllFailed(rulePromises)).then(function (errors) {\n if (!errors.length) {\n return [];\n }\n\n return Promise.reject(errors);\n });\n } // Internal catch error to avoid console error log.\n\n\n summaryPromise.catch(function (e) {\n return e;\n });\n return summaryPromise;\n}\n\nfunction finishOnAllFailed(_x8) {\n return _finishOnAllFailed.apply(this, arguments);\n}\n\nfunction _finishOnAllFailed() {\n _finishOnAllFailed = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(rulePromises) {\n return _regeneratorRuntime.wrap(function _callee3$(_context3) {\n while (1) {\n switch (_context3.prev = _context3.next) {\n case 0:\n return _context3.abrupt(\"return\", Promise.all(rulePromises).then(function (errorsList) {\n var _ref3;\n\n var errors = (_ref3 = []).concat.apply(_ref3, _toConsumableArray(errorsList));\n\n return errors;\n }));\n\n case 1:\n case \"end\":\n return _context3.stop();\n }\n }\n }, _callee3);\n }));\n return _finishOnAllFailed.apply(this, arguments);\n}\n\nfunction finishOnFirstFailed(_x9) {\n return _finishOnFirstFailed.apply(this, arguments);\n}\n\nfunction _finishOnFirstFailed() {\n _finishOnFirstFailed = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(rulePromises) {\n var count;\n return _regeneratorRuntime.wrap(function _callee4$(_context4) {\n while (1) {\n switch (_context4.prev = _context4.next) {\n case 0:\n count = 0;\n return _context4.abrupt(\"return\", new Promise(function (resolve) {\n rulePromises.forEach(function (promise) {\n promise.then(function (errors) {\n if (errors.length) {\n resolve(errors);\n }\n\n count += 1;\n\n if (count === rulePromises.length) {\n resolve([]);\n }\n });\n });\n }));\n\n case 2:\n case \"end\":\n return _context4.stop();\n }\n }\n }, _callee4);\n }));\n return _finishOnFirstFailed.apply(this, arguments);\n}"]},"metadata":{},"sourceType":"module"}