@hookform/resolvers 2.0.0-rc.1 → 2.0.0
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.
- package/LICENSE +21 -0
- package/README.md +115 -18
- package/dist/index.d.ts +1 -0
- package/dist/resolvers.js +2 -0
- package/dist/resolvers.js.map +1 -0
- package/dist/resolvers.mjs +2 -0
- package/dist/resolvers.modern.js +2 -0
- package/dist/resolvers.modern.js.map +1 -0
- package/dist/resolvers.module.js +2 -0
- package/dist/resolvers.module.js.map +1 -0
- package/dist/resolvers.umd.js +2 -0
- package/dist/resolvers.umd.js.map +1 -0
- package/dist/toNestError.d.ts +2 -0
- package/joi/dist/index.d.ts +2 -0
- package/joi/dist/joi.d.ts +2 -0
- package/joi/dist/joi.js +2 -0
- package/joi/dist/joi.js.map +1 -0
- package/joi/dist/joi.mjs +2 -0
- package/joi/dist/joi.modern.js +2 -0
- package/joi/dist/joi.modern.js.map +1 -0
- package/joi/dist/joi.module.js +2 -0
- package/joi/dist/joi.module.js.map +1 -0
- package/joi/dist/joi.umd.js +2 -0
- package/joi/dist/joi.umd.js.map +1 -0
- package/joi/dist/types.d.ts +5 -0
- package/joi/package.json +17 -0
- package/joi/src/__tests__/Form.tsx +61 -0
- package/joi/src/__tests__/__fixtures__/data.ts +76 -0
- package/joi/src/__tests__/__snapshots__/joi.ts.snap +283 -0
- package/joi/src/__tests__/joi.ts +89 -0
- package/joi/src/index.ts +2 -0
- package/joi/src/joi.ts +63 -0
- package/joi/src/types.ts +17 -0
- package/package.json +111 -55
- package/superstruct/dist/index.d.ts +2 -0
- package/superstruct/dist/superstruct.d.ts +2 -0
- package/superstruct/dist/superstruct.js +2 -0
- package/superstruct/dist/superstruct.js.map +1 -0
- package/superstruct/dist/superstruct.mjs +2 -0
- package/superstruct/dist/superstruct.modern.js +2 -0
- package/superstruct/dist/superstruct.modern.js.map +1 -0
- package/superstruct/dist/superstruct.module.js +2 -0
- package/superstruct/dist/superstruct.module.js.map +1 -0
- package/superstruct/dist/superstruct.umd.js +2 -0
- package/superstruct/dist/superstruct.umd.js.map +1 -0
- package/superstruct/dist/types.d.ts +5 -0
- package/superstruct/package.json +18 -0
- package/superstruct/src/__tests__/Form.tsx +62 -0
- package/superstruct/src/__tests__/__fixtures__/data.ts +73 -0
- package/superstruct/src/__tests__/__snapshots__/superstruct.ts.snap +64 -0
- package/superstruct/src/__tests__/superstruct.ts +20 -0
- package/superstruct/src/index.ts +2 -0
- package/superstruct/src/superstruct.ts +30 -0
- package/superstruct/src/types.ts +18 -0
- package/vest/dist/index.d.ts +1 -0
- package/vest/dist/vest.d.ts +2 -0
- package/vest/dist/vest.js +2 -0
- package/vest/dist/vest.js.map +1 -0
- package/vest/dist/vest.mjs +2 -0
- package/vest/dist/vest.modern.js +2 -0
- package/vest/dist/vest.modern.js.map +1 -0
- package/vest/dist/vest.module.js +2 -0
- package/vest/dist/vest.module.js.map +1 -0
- package/vest/dist/vest.umd.js +2 -0
- package/vest/dist/vest.umd.js.map +1 -0
- package/vest/package.json +18 -0
- package/vest/src/__tests__/Form.tsx +64 -0
- package/vest/src/__tests__/__fixtures__/data.ts +67 -0
- package/vest/src/__tests__/__snapshots__/vest.ts.snap +141 -0
- package/vest/src/__tests__/vest.ts +65 -0
- package/vest/src/index.ts +1 -0
- package/vest/src/types.ts +21 -0
- package/vest/src/vest.ts +45 -0
- package/yup/dist/index.d.ts +2 -0
- package/yup/dist/types.d.ts +8 -0
- package/yup/dist/yup.d.ts +2 -0
- package/yup/dist/yup.js +2 -0
- package/yup/dist/yup.js.map +1 -0
- package/yup/dist/yup.mjs +2 -0
- package/yup/dist/yup.modern.js +2 -0
- package/yup/dist/yup.modern.js.map +1 -0
- package/yup/dist/yup.module.js +2 -0
- package/yup/dist/yup.module.js.map +1 -0
- package/yup/dist/yup.umd.js +2 -0
- package/yup/dist/yup.umd.js.map +1 -0
- package/yup/package.json +17 -0
- package/yup/src/__tests__/Form.tsx +54 -0
- package/yup/src/__tests__/__fixtures__/data.ts +65 -0
- package/yup/src/__tests__/__snapshots__/yup.ts.snap +221 -0
- package/yup/src/__tests__/yup.ts +150 -0
- package/yup/src/index.ts +2 -0
- package/yup/src/types.ts +22 -0
- package/yup/src/yup.ts +65 -0
- package/zod/dist/index.d.ts +2 -0
- package/zod/dist/types.d.ts +6 -0
- package/zod/dist/zod.d.ts +2 -0
- package/zod/dist/zod.js +2 -0
- package/zod/dist/zod.js.map +1 -0
- package/zod/dist/zod.mjs +2 -0
- package/zod/dist/zod.modern.js +2 -0
- package/zod/dist/zod.modern.js.map +1 -0
- package/zod/dist/zod.module.js +2 -0
- package/zod/dist/zod.module.js.map +1 -0
- package/zod/dist/zod.umd.js +2 -0
- package/zod/dist/zod.umd.js.map +1 -0
- package/zod/package.json +17 -0
- package/zod/src/__tests__/Form.tsx +54 -0
- package/zod/src/__tests__/__fixtures__/data.ts +68 -0
- package/zod/src/__tests__/__snapshots__/zod.ts.snap +355 -0
- package/zod/src/__tests__/zod.ts +71 -0
- package/zod/src/index.ts +2 -0
- package/zod/src/types.ts +18 -0
- package/zod/src/zod.ts +65 -0
- package/dist/ie11/joi.d.ts +0 -3
- package/dist/ie11/joi.js +0 -104
- package/dist/ie11/joi.js.map +0 -1
- package/dist/ie11/superstruct.d.ts +0 -3
- package/dist/ie11/superstruct.js +0 -95
- package/dist/ie11/superstruct.js.map +0 -1
- package/dist/ie11/utils/convertArrayToPathName.d.ts +0 -2
- package/dist/ie11/utils/convertArrayToPathName.js +0 -12
- package/dist/ie11/utils/convertArrayToPathName.js.map +0 -1
- package/dist/ie11/yup.d.ts +0 -3
- package/dist/ie11/yup.js +0 -132
- package/dist/ie11/yup.js.map +0 -1
- package/dist/joi.d.ts +0 -3
- package/dist/joi.js +0 -41
- package/dist/joi.js.map +0 -1
- package/dist/superstruct.d.ts +0 -3
- package/dist/superstruct.js +0 -39
- package/dist/superstruct.js.map +0 -1
- package/dist/umd/index.js +0 -2
- package/dist/umd/index.js.map +0 -1
- package/dist/utils/convertArrayToPathName.d.ts +0 -2
- package/dist/utils/convertArrayToPathName.js +0 -8
- package/dist/utils/convertArrayToPathName.js.map +0 -1
- package/dist/yup.d.ts +0 -3
- package/dist/yup.js +0 -49
- package/dist/yup.js.map +0 -1
- package/joi.d.ts +0 -1
- package/joi.js +0 -1
- package/superstruct.js +0 -1
- package/yup.d.ts +0 -1
- package/yup.js +0 -1
package/dist/ie11/superstruct.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.superstructResolver = void 0;
|
|
51
|
-
var react_hook_form_1 = require("react-hook-form");
|
|
52
|
-
var convertArrayToPathName_1 = require("./utils/convertArrayToPathName");
|
|
53
|
-
var parseErrorSchema = function (error, validateAllFieldCriteria) {
|
|
54
|
-
return Array.isArray(error.failures)
|
|
55
|
-
? error.failures.reduce(function (previous, _a) {
|
|
56
|
-
var _b, _c, _d;
|
|
57
|
-
var path = _a.path, _e = _a.message, message = _e === void 0 ? '' : _e, type = _a.type;
|
|
58
|
-
var currentPath = convertArrayToPathName_1.default(path);
|
|
59
|
-
return __assign(__assign({}, previous), (path
|
|
60
|
-
? previous[currentPath] && validateAllFieldCriteria
|
|
61
|
-
? (_b = {},
|
|
62
|
-
_b[currentPath] = react_hook_form_1.appendErrors(currentPath, validateAllFieldCriteria, previous, type || '', message),
|
|
63
|
-
_b) : (_c = {},
|
|
64
|
-
_c[currentPath] = previous[currentPath] || __assign({ message: message,
|
|
65
|
-
type: type }, (validateAllFieldCriteria
|
|
66
|
-
? {
|
|
67
|
-
types: (_d = {}, _d[type || ''] = message || true, _d),
|
|
68
|
-
}
|
|
69
|
-
: {})),
|
|
70
|
-
_c)
|
|
71
|
-
: {}));
|
|
72
|
-
}, {})
|
|
73
|
-
: [];
|
|
74
|
-
};
|
|
75
|
-
exports.superstructResolver = function (schema) { return function (values, _, validateAllFieldCriteria) {
|
|
76
|
-
if (validateAllFieldCriteria === void 0) { validateAllFieldCriteria = false; }
|
|
77
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
78
|
-
return __generator(this, function (_a) {
|
|
79
|
-
try {
|
|
80
|
-
return [2 /*return*/, {
|
|
81
|
-
values: schema(values),
|
|
82
|
-
errors: {},
|
|
83
|
-
}];
|
|
84
|
-
}
|
|
85
|
-
catch (e) {
|
|
86
|
-
return [2 /*return*/, {
|
|
87
|
-
values: {},
|
|
88
|
-
errors: react_hook_form_1.transformToNestObject(parseErrorSchema(e, validateAllFieldCriteria)),
|
|
89
|
-
}];
|
|
90
|
-
}
|
|
91
|
-
return [2 /*return*/];
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
}; };
|
|
95
|
-
//# sourceMappingURL=superstruct.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"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AM,CAAC,MAAM,CAAC;wBACtB,MAAM,EAAE,EAAE;qBACX,EAAC;aACH;YAAC,OAAO,CAAC,EAAE;gBACV,sBAAO;wBACL,MAAM,EAAE,EAAE;wBACV,MAAM,EAAE,uCAAqB,CAC3B,gBAAgB,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAC9C;qBACF,EAAC;aACH;;;;CACF,EAlB4B,CAkB5B,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = (function (paths) {
|
|
4
|
-
return paths
|
|
5
|
-
.reduce(function (previous, path, index) {
|
|
6
|
-
return "" + previous + (typeof path === 'string'
|
|
7
|
-
? "" + (index > 0 ? '.' : '') + path
|
|
8
|
-
: "[" + path + "]");
|
|
9
|
-
}, '')
|
|
10
|
-
.toString();
|
|
11
|
-
});
|
|
12
|
-
//# sourceMappingURL=convertArrayToPathName.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convertArrayToPathName.js","sourceRoot":"","sources":["../../../src/utils/convertArrayToPathName.ts"],"names":[],"mappings":";;AAAA,mBAAe,UAAC,KAA0B;IACxC,OAAA,KAAK;SACF,MAAM,CACL,UAAC,QAAQ,EAAE,IAAqB,EAAE,KAAK;QACrC,OAAA,KAAG,QAAQ,IACT,OAAO,IAAI,KAAK,QAAQ;YACtB,CAAC,CAAC,MAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAG,IAAM;YAClC,CAAC,CAAC,MAAI,IAAI,MAAG,CACf;IAJF,CAIE,EACJ,EAAE,CACH;SACA,QAAQ,EAAE;AAVb,CAUa,EAAC"}
|
package/dist/ie11/yup.d.ts
DELETED
package/dist/ie11/yup.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
-
if (!m) return o;
|
|
52
|
-
var i = m.call(o), r, ar = [], e;
|
|
53
|
-
try {
|
|
54
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
-
}
|
|
56
|
-
catch (error) { e = { error: error }; }
|
|
57
|
-
finally {
|
|
58
|
-
try {
|
|
59
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
-
}
|
|
61
|
-
finally { if (e) throw e.error; }
|
|
62
|
-
}
|
|
63
|
-
return ar;
|
|
64
|
-
};
|
|
65
|
-
var __spread = (this && this.__spread) || function () {
|
|
66
|
-
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
67
|
-
return ar;
|
|
68
|
-
};
|
|
69
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
70
|
-
exports.yupResolver = void 0;
|
|
71
|
-
var react_hook_form_1 = require("react-hook-form");
|
|
72
|
-
var parseErrorSchema = function (error, validateAllFieldCriteria) {
|
|
73
|
-
var _a;
|
|
74
|
-
return Array.isArray(error.inner) && error.inner.length
|
|
75
|
-
? error.inner.reduce(function (previous, _a) {
|
|
76
|
-
var _b, _c;
|
|
77
|
-
var path = _a.path, message = _a.message, type = _a.type;
|
|
78
|
-
var previousTypes = (previous[path] && previous[path].types) || {};
|
|
79
|
-
var key = path || type;
|
|
80
|
-
return __assign(__assign({}, previous), (key
|
|
81
|
-
? (_b = {},
|
|
82
|
-
_b[key] = __assign(__assign({}, (previous[key] || {
|
|
83
|
-
message: message,
|
|
84
|
-
type: type,
|
|
85
|
-
})), (validateAllFieldCriteria
|
|
86
|
-
? {
|
|
87
|
-
types: __assign(__assign({}, previousTypes), (_c = {}, _c[type] = previousTypes[type]
|
|
88
|
-
? __spread([].concat(previousTypes[type]), [message]) : message, _c)),
|
|
89
|
-
}
|
|
90
|
-
: {})),
|
|
91
|
-
_b) : {}));
|
|
92
|
-
}, {})
|
|
93
|
-
: (_a = {},
|
|
94
|
-
_a[error.path] = { message: error.message, type: error.type },
|
|
95
|
-
_a);
|
|
96
|
-
};
|
|
97
|
-
exports.yupResolver = function (schema, options) {
|
|
98
|
-
if (options === void 0) { options = {
|
|
99
|
-
abortEarly: false,
|
|
100
|
-
}; }
|
|
101
|
-
return function (values, context, validateAllFieldCriteria) {
|
|
102
|
-
if (validateAllFieldCriteria === void 0) { validateAllFieldCriteria = false; }
|
|
103
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
104
|
-
var _a, e_1, parsedErrors;
|
|
105
|
-
return __generator(this, function (_b) {
|
|
106
|
-
switch (_b.label) {
|
|
107
|
-
case 0:
|
|
108
|
-
_b.trys.push([0, 2, , 3]);
|
|
109
|
-
if (options.context &&
|
|
110
|
-
process.env.NODE_ENV === 'development') {
|
|
111
|
-
// eslint-disable-next-line no-console
|
|
112
|
-
console.warn("You should not used the yup options context. Please, use the 'useForm' context object instead");
|
|
113
|
-
}
|
|
114
|
-
_a = {};
|
|
115
|
-
return [4 /*yield*/, schema.validate(values, __assign(__assign({}, options), { context: context }))];
|
|
116
|
-
case 1: return [2 /*return*/, (_a.values = (_b.sent()),
|
|
117
|
-
_a.errors = {},
|
|
118
|
-
_a)];
|
|
119
|
-
case 2:
|
|
120
|
-
e_1 = _b.sent();
|
|
121
|
-
parsedErrors = parseErrorSchema(e_1, validateAllFieldCriteria);
|
|
122
|
-
return [2 /*return*/, {
|
|
123
|
-
values: {},
|
|
124
|
-
errors: react_hook_form_1.transformToNestObject(parsedErrors),
|
|
125
|
-
}];
|
|
126
|
-
case 3: return [2 /*return*/];
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
//# sourceMappingURL=yup.js.map
|
package/dist/ie11/yup.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"yup.js","sourceRoot":"","sources":["../../src/yup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAA+E;AAG/E,IAAM,gBAAgB,GAAG,UACvB,KAA0B,EAC1B,wBAAiC;;IAEjC,OAAA,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM;QAC9C,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAChB,UAAC,QAA6B,EAAE,EAAuB;;gBAArB,IAAI,UAAA,EAAE,OAAO,aAAA,EAAE,IAAI,UAAA;YACnD,IAAM,aAAa,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YACrE,IAAM,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BAAwB,CAAC,CAAC;wBACnE,sBAAO;gCACL,MAAM,EAAE,EAAE;gCACV,MAAM,EAAE,uCAAqB,CAAC,YAAY,CAAC;6BAC5C,EAAC;;;;;KAEL;AA7B4B,CA6B5B,CAAC"}
|
package/dist/joi.d.ts
DELETED
package/dist/joi.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.joiResolver = void 0;
|
|
4
|
-
const react_hook_form_1 = require("react-hook-form");
|
|
5
|
-
const convertArrayToPathName_1 = require("./utils/convertArrayToPathName");
|
|
6
|
-
const parseErrorSchema = (error, validateAllFieldCriteria) => Array.isArray(error.details)
|
|
7
|
-
? error.details.reduce((previous, { path, message = '', type }) => {
|
|
8
|
-
const currentPath = convertArrayToPathName_1.default(path);
|
|
9
|
-
return Object.assign(Object.assign({}, previous), (path
|
|
10
|
-
? previous[currentPath] && validateAllFieldCriteria
|
|
11
|
-
? {
|
|
12
|
-
[currentPath]: react_hook_form_1.appendErrors(currentPath, validateAllFieldCriteria, previous, type, message),
|
|
13
|
-
}
|
|
14
|
-
: {
|
|
15
|
-
[currentPath]: previous[currentPath] || Object.assign({ message,
|
|
16
|
-
type }, (validateAllFieldCriteria
|
|
17
|
-
? {
|
|
18
|
-
types: { [type]: message || true },
|
|
19
|
-
}
|
|
20
|
-
: {})),
|
|
21
|
-
}
|
|
22
|
-
: {}));
|
|
23
|
-
}, {})
|
|
24
|
-
: [];
|
|
25
|
-
exports.joiResolver = (schema, options = {
|
|
26
|
-
abortEarly: false,
|
|
27
|
-
}) => async (values, _, validateAllFieldCriteria = false) => {
|
|
28
|
-
try {
|
|
29
|
-
return {
|
|
30
|
-
values: await schema.validateAsync(values, Object.assign({}, options)),
|
|
31
|
-
errors: {},
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
catch (e) {
|
|
35
|
-
return {
|
|
36
|
-
values: {},
|
|
37
|
-
errors: react_hook_form_1.transformToNestObject(parseErrorSchema(e, validateAllFieldCriteria)),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
//# sourceMappingURL=joi.js.map
|
package/dist/joi.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"joi.js","sourceRoot":"","sources":["../src/joi.ts"],"names":[],"mappings":";;;AAAA,qDAKyB;AAEzB,2EAAoE;AAEpE,MAAM,gBAAgB,GAAG,CACvB,KAA0B,EAC1B,wBAAiC,EACjC,EAAE,CACF,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;IAC1B,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAClB,CAAC,QAA6B,EAAE,EAAE,IAAI,EAAE,OAAO,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QAC9D,MAAM,WAAW,GAAG,gCAAsB,CAAC,IAAI,CAAC,CAAC;QAEjD,uCACK,QAAQ,GACR,CAAC,IAAI;YACN,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,wBAAwB;gBACjD,CAAC,CAAC;oBACE,CAAC,WAAW,CAAC,EAAE,8BAAY,CACzB,WAAW,EACX,wBAAwB,EACxB,QAAQ,EACR,IAAI,EACJ,OAAO,CACR;iBACF;gBACH,CAAC,CAAC;oBACE,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,oBAClC,OAAO;wBACP,IAAI,IACD,CAAC,wBAAwB;wBAC1B,CAAC,CAAC;4BACE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,IAAI,IAAI,EAAE;yBACnC;wBACH,CAAC,CAAC,EAAE,CAAC,CACR;iBACF;YACL,CAAC,CAAC,EAAE,CAAC,EACP;IACJ,CAAC,EACD,EAAE,CACH;IACH,CAAC,CAAC,EAAE,CAAC;AAEI,QAAA,WAAW,GAAG,CACzB,MAAkB,EAClB,UAAsC;IACpC,UAAU,EAAE,KAAK;CAClB,EACuB,EAAE,CAAC,KAAK,EAChC,MAAM,EACN,CAAC,EACD,wBAAwB,GAAG,KAAK,EAChC,EAAE;IACF,IAAI;QACF,OAAO;YACL,MAAM,EAAE,MAAM,MAAM,CAAC,aAAa,CAAC,MAAM,oBACpC,OAAO,EACV;YACF,MAAM,EAAE,EAAE;SACX,CAAC;KACH;IAAC,OAAO,CAAC,EAAE;QACV,OAAO;YACL,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,uCAAqB,CAC3B,gBAAgB,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAC9C;SACF,CAAC;KACH;AACH,CAAC,CAAC"}
|
package/dist/superstruct.d.ts
DELETED
package/dist/superstruct.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.superstructResolver = void 0;
|
|
4
|
-
const react_hook_form_1 = require("react-hook-form");
|
|
5
|
-
const convertArrayToPathName_1 = require("./utils/convertArrayToPathName");
|
|
6
|
-
const parseErrorSchema = (error, validateAllFieldCriteria) => Array.isArray(error.failures)
|
|
7
|
-
? error.failures.reduce((previous, { path, message = '', type }) => {
|
|
8
|
-
const currentPath = convertArrayToPathName_1.default(path);
|
|
9
|
-
return Object.assign(Object.assign({}, previous), (path
|
|
10
|
-
? previous[currentPath] && validateAllFieldCriteria
|
|
11
|
-
? {
|
|
12
|
-
[currentPath]: react_hook_form_1.appendErrors(currentPath, validateAllFieldCriteria, previous, type || '', message),
|
|
13
|
-
}
|
|
14
|
-
: {
|
|
15
|
-
[currentPath]: previous[currentPath] || Object.assign({ message,
|
|
16
|
-
type }, (validateAllFieldCriteria
|
|
17
|
-
? {
|
|
18
|
-
types: { [type || '']: message || true },
|
|
19
|
-
}
|
|
20
|
-
: {})),
|
|
21
|
-
}
|
|
22
|
-
: {}));
|
|
23
|
-
}, {})
|
|
24
|
-
: [];
|
|
25
|
-
exports.superstructResolver = (schema) => async (values, _, validateAllFieldCriteria = false) => {
|
|
26
|
-
try {
|
|
27
|
-
return {
|
|
28
|
-
values: schema(values),
|
|
29
|
-
errors: {},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
return {
|
|
34
|
-
values: {},
|
|
35
|
-
errors: react_hook_form_1.transformToNestObject(parseErrorSchema(e, validateAllFieldCriteria)),
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=superstruct.js.map
|
package/dist/superstruct.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.js","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;;AAAA,qDAKyB;AAEzB,2EAAoE;AAEpE,MAAM,gBAAgB,GAAG,CACvB,KAA8B,EAC9B,wBAAiC,EACjC,EAAE,CACF,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC3B,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CACnB,CAAC,QAA6B,EAAE,EAAE,IAAI,EAAE,OAAO,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QAC9D,MAAM,WAAW,GAAG,gCAAsB,CAAC,IAAI,CAAC,CAAC;QAEjD,uCACK,QAAQ,GACR,CAAC,IAAI;YACN,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,wBAAwB;gBACjD,CAAC,CAAC;oBACE,CAAC,WAAW,CAAC,EAAE,8BAAY,CACzB,WAAW,EACX,wBAAwB,EACxB,QAAQ,EACR,IAAI,IAAI,EAAE,EACV,OAAO,CACR;iBACF;gBACH,CAAC,CAAC;oBACE,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,oBAClC,OAAO;wBACP,IAAI,IACD,CAAC,wBAAwB;wBAC1B,CAAC,CAAC;4BACE,KAAK,EAAE,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,OAAO,IAAI,IAAI,EAAE;yBACzC;wBACH,CAAC,CAAC,EAAE,CAAC,CACR;iBACF;YACL,CAAC,CAAC,EAAE,CAAC,EACP;IACJ,CAAC,EACD,EAAE,CACH;IACH,CAAC,CAAC,EAAE,CAAC;AAEI,QAAA,mBAAmB,GAAG,CACjC,MAA0B,EACF,EAAE,CAAC,KAAK,EAChC,MAAM,EACN,CAAC,EACD,wBAAwB,GAAG,KAAK,EAChC,EAAE;IACF,IAAI;QACF,OAAO;YACL,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;YACtB,MAAM,EAAE,EAAE;SACX,CAAC;KACH;IAAC,OAAO,CAAC,EAAE;QACV,OAAO;YACL,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,uCAAqB,CAC3B,gBAAgB,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAC9C;SACF,CAAC;KACH;AACH,CAAC,CAAC"}
|
package/dist/umd/index.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
!function(e,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports,require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","react-hook-form"],s):s((e=e||self).ReactHookFormResolvers={},e.ReactHookForm)}(this,(function(e,s){"use strict";var r=e=>e.reduce((e,s,r)=>`${e}${"string"==typeof s?`${r>0?".":""}${s}`:`[${s}]`}`,"").toString();const t=(e,t)=>Array.isArray(e.failures)?e.failures.reduce((e,{path:a,message:n="",type:o})=>{const c=r(a);return Object.assign(Object.assign({},e),a?e[c]&&t?{[c]:s.appendErrors(c,t,e,o||"",n)}:{[c]:e[c]||Object.assign({message:n,type:o},t?{types:{[o||""]:n||!0}}:{})}:{})},{}):[],a=(e,t)=>Array.isArray(e.details)?e.details.reduce((e,{path:a,message:n="",type:o})=>{const c=r(a);return Object.assign(Object.assign({},e),a?e[c]&&t?{[c]:s.appendErrors(c,t,e,o,n)}:{[c]:e[c]||Object.assign({message:n,type:o},t?{types:{[o]:n||!0}}:{})}:{})},{}):[];e.joiResolver=(e,r={abortEarly:!1})=>async(t,n,o=!1)=>{try{return{values:await e.validateAsync(t,Object.assign({},r)),errors:{}}}catch(e){return{values:{},errors:s.transformToNestObject(a(e,o))}}},e.superstructResolver=e=>async(r,a,n=!1)=>{try{return{values:e(r),errors:{}}}catch(e){return{values:{},errors:s.transformToNestObject(t(e,n))}}},e.yupResolver=(e,r={abortEarly:!1})=>async(t,a,n=!1)=>{try{return r.context&&process.env.NODE_ENV,{values:await e.validate(t,Object.assign(Object.assign({},r),{context:a})),errors:{}}}catch(e){const r=((e,s)=>Array.isArray(e.inner)&&e.inner.length?e.inner.reduce((e,{path:r,message:t,type:a})=>{const n=e[r]&&e[r].types||{},o=r||a;return Object.assign(Object.assign({},e),o?{[o]:Object.assign(Object.assign({},e[o]||{message:t,type:a}),s?{types:Object.assign(Object.assign({},n),{[a]:n[a]?[...[].concat(n[a]),t]:t})}:{})}:{})},{}):{[e.path]:{message:e.message,type:e.type}})(e,n);return{values:{},errors:s.transformToNestObject(r)}}},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
package/dist/umd/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/utils/convertArrayToPathName.ts","../../src/superstruct.ts","../../src/joi.ts","../../src/yup.ts"],"sourcesContent":["export default (paths: (string | number)[]): string =>\n paths\n .reduce(\n (previous, path: string | number, index): string =>\n `${previous}${\n typeof path === 'string'\n ? `${index > 0 ? '.' : ''}${path}`\n : `[${path}]`\n }`,\n '',\n )\n .toString();\n","import {\n appendErrors,\n transformToNestObject,\n Resolver,\n FieldValues,\n} from 'react-hook-form';\nimport Superstruct from 'superstruct';\nimport convertArrayToPathName from './utils/convertArrayToPathName';\n\nconst parseErrorSchema = (\n error: Superstruct.StructError,\n validateAllFieldCriteria: boolean,\n) =>\n Array.isArray(error.failures)\n ? error.failures.reduce(\n (previous: Record<string, any>, { path, message = '', type }) => {\n const currentPath = convertArrayToPathName(path);\n\n return {\n ...previous,\n ...(path\n ? previous[currentPath] && validateAllFieldCriteria\n ? {\n [currentPath]: appendErrors(\n currentPath,\n validateAllFieldCriteria,\n previous,\n type || '',\n message,\n ),\n }\n : {\n [currentPath]: previous[currentPath] || {\n message,\n type,\n ...(validateAllFieldCriteria\n ? {\n types: { [type || '']: message || true },\n }\n : {}),\n },\n }\n : {}),\n };\n },\n {},\n )\n : [];\n\nexport const superstructResolver = <TFieldValues extends FieldValues>(\n schema: Superstruct.Struct,\n): Resolver<TFieldValues> => async (\n values,\n _,\n validateAllFieldCriteria = false,\n) => {\n try {\n return {\n values: schema(values),\n errors: {},\n };\n } catch (e) {\n return {\n values: {},\n errors: transformToNestObject(\n parseErrorSchema(e, validateAllFieldCriteria),\n ),\n };\n }\n};\n","import {\n appendErrors,\n transformToNestObject,\n Resolver,\n FieldValues,\n} from 'react-hook-form';\nimport Joi from '@hapi/joi';\nimport convertArrayToPathName from './utils/convertArrayToPathName';\n\nconst parseErrorSchema = (\n error: Joi.ValidationError,\n validateAllFieldCriteria: boolean,\n) =>\n Array.isArray(error.details)\n ? error.details.reduce(\n (previous: Record<string, any>, { path, message = '', type }) => {\n const currentPath = convertArrayToPathName(path);\n\n return {\n ...previous,\n ...(path\n ? previous[currentPath] && validateAllFieldCriteria\n ? {\n [currentPath]: appendErrors(\n currentPath,\n validateAllFieldCriteria,\n previous,\n type,\n message,\n ),\n }\n : {\n [currentPath]: previous[currentPath] || {\n message,\n type,\n ...(validateAllFieldCriteria\n ? {\n types: { [type]: message || true },\n }\n : {}),\n },\n }\n : {}),\n };\n },\n {},\n )\n : [];\n\nexport const joiResolver = <TFieldValues extends FieldValues>(\n schema: Joi.Schema,\n options: Joi.AsyncValidationOptions = {\n abortEarly: false,\n },\n): Resolver<TFieldValues> => async (\n values,\n _,\n validateAllFieldCriteria = false,\n) => {\n try {\n return {\n values: await schema.validateAsync(values, {\n ...options,\n }),\n errors: {},\n };\n } catch (e) {\n return {\n values: {},\n errors: transformToNestObject(\n parseErrorSchema(e, validateAllFieldCriteria),\n ),\n };\n }\n};\n","import { Resolver, transformToNestObject, FieldValues } from 'react-hook-form';\nimport Yup from 'yup';\n\nconst parseErrorSchema = (\n error: Yup.ValidationError,\n validateAllFieldCriteria: boolean,\n) =>\n Array.isArray(error.inner) && error.inner.length\n ? error.inner.reduce(\n (previous: Record<string, any>, { path, message, type }) => {\n const previousTypes = (previous[path] && previous[path].types) || {};\n const key = path || type;\n\n return {\n ...previous,\n ...(key\n ? {\n [key]: {\n ...(previous[key] || {\n message,\n type,\n }),\n ...(validateAllFieldCriteria\n ? {\n types: {\n ...previousTypes,\n [type]: previousTypes[type]\n ? [...[].concat(previousTypes[type]), message]\n : message,\n },\n }\n : {}),\n },\n }\n : {}),\n };\n },\n {},\n )\n : {\n [error.path]: { message: error.message, type: error.type },\n };\n\nexport const yupResolver = <TFieldValues extends FieldValues>(\n schema: Yup.ObjectSchema | Yup.Lazy,\n options: Omit<Yup.ValidateOptions, 'context'> = {\n abortEarly: false,\n },\n): Resolver<TFieldValues> => async (\n values,\n context,\n validateAllFieldCriteria = false,\n) => {\n try {\n if (\n (options as Yup.ValidateOptions).context &&\n process.env.NODE_ENV === 'development'\n ) {\n // eslint-disable-next-line no-console\n console.warn(\n \"You should not used the yup options context. Please, use the 'useForm' context object instead\",\n );\n }\n return {\n values: (await schema.validate(values, {\n ...options,\n context,\n })) as any,\n errors: {},\n };\n } catch (e) {\n const parsedErrors = parseErrorSchema(e, validateAllFieldCriteria);\n return {\n values: {},\n errors: transformToNestObject(parsedErrors),\n };\n }\n};\n"],"names":["paths","reduce","previous","path","index","toString","parseErrorSchema","error","validateAllFieldCriteria","Array","isArray","failures","message","type","currentPath","convertArrayToPathName","[object Object]","appendErrors","types","details","schema","options","abortEarly","async","values","_","validateAsync","errors","e","transformToNestObject","context","process","env","NODE_ENV","validate","parsedErrors","inner","length","previousTypes","key","concat"],"mappings":"yRAAg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ACAjB,GAA2B,KAE3B,IACE,MAAO,CACLgB,OAAQJ,EAAOI,GACfG,OAAQ,IAEV,MAAOC,GACP,MAAO,CACLJ,OAAQ,GACRG,OAAQE,wBACNvB,EAAiBsB,EAAGpB,qBEtBD,CACzBY,EACAC,EAAgD,CAC9CC,YAAY,KAEaC,MAC3BC,EACAM,EACAtB,GAA2B,KAE3B,IAUE,OARGa,EAAgCS,SACjCC,QAAQC,IAAIC,SAOP,CACLT,aAAeJ,EAAOc,SAASV,iCAC1BH,IACHS,QAAAA,KAEFH,OAAQ,IAEV,MAAOC,GACP,MAAMO,EApEe,EACvB5B,EACAC,IAEAC,MAAMC,QAAQH,EAAM6B,QAAU7B,EAAM6B,MAAMC,OACtC9B,EAAM6B,MAAMnC,OACV,CAACC,GAAiCC,KAAAA,EAAMS,QAAAA,EAASC,KAAAA,MAC/C,MAAMyB,EAAiBpC,EAASC,IAASD,EAASC,GAAMe,OAAU,GAC5DqB,EAAMpC,GAAQU,EAEpB,sCACKX,GACCqC,EACA,CACEvB,CAACuB,kCACKrC,EAASqC,IAAQ,CACnB3B,QAAAA,EACAC,KAAAA,IAEEL,EACA,CACEU,qCACKoB,IACHtB,CAACH,GAAOyB,EAAczB,GAClB,IAAI,GAAG2B,OAAOF,EAAczB,IAAQD,GACpCA,KAGR,KAGR,KAGR,IAEF,CACEI,CAACT,EAAMJ,MAAO,CAAES,QAASL,EAAMK,QAASC,KAAMN,EAAMM,OA+BnCP,CAAiBsB,EAAGpB,GACzC,MAAO,CACLgB,OAAQ,GACRG,OAAQE,wBAAsBM"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = (paths) => paths
|
|
4
|
-
.reduce((previous, path, index) => `${previous}${typeof path === 'string'
|
|
5
|
-
? `${index > 0 ? '.' : ''}${path}`
|
|
6
|
-
: `[${path}]`}`, '')
|
|
7
|
-
.toString();
|
|
8
|
-
//# sourceMappingURL=convertArrayToPathName.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convertArrayToPathName.js","sourceRoot":"","sources":["../../src/utils/convertArrayToPathName.ts"],"names":[],"mappings":";;AAAA,kBAAe,CAAC,KAA0B,EAAU,EAAE,CACpD,KAAK;KACF,MAAM,CACL,CAAC,QAAQ,EAAE,IAAqB,EAAE,KAAK,EAAU,EAAE,CACjD,GAAG,QAAQ,GACT,OAAO,IAAI,KAAK,QAAQ;IACtB,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE;IAClC,CAAC,CAAC,IAAI,IAAI,GACd,EAAE,EACJ,EAAE,CACH;KACA,QAAQ,EAAE,CAAC"}
|
package/dist/yup.d.ts
DELETED
package/dist/yup.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.yupResolver = void 0;
|
|
4
|
-
const react_hook_form_1 = require("react-hook-form");
|
|
5
|
-
const parseErrorSchema = (error, validateAllFieldCriteria) => Array.isArray(error.inner) && error.inner.length
|
|
6
|
-
? error.inner.reduce((previous, { path, message, type }) => {
|
|
7
|
-
const previousTypes = (previous[path] && previous[path].types) || {};
|
|
8
|
-
const key = path || type;
|
|
9
|
-
return Object.assign(Object.assign({}, previous), (key
|
|
10
|
-
? {
|
|
11
|
-
[key]: Object.assign(Object.assign({}, (previous[key] || {
|
|
12
|
-
message,
|
|
13
|
-
type,
|
|
14
|
-
})), (validateAllFieldCriteria
|
|
15
|
-
? {
|
|
16
|
-
types: Object.assign(Object.assign({}, previousTypes), { [type]: previousTypes[type]
|
|
17
|
-
? [...[].concat(previousTypes[type]), message]
|
|
18
|
-
: message }),
|
|
19
|
-
}
|
|
20
|
-
: {})),
|
|
21
|
-
}
|
|
22
|
-
: {}));
|
|
23
|
-
}, {})
|
|
24
|
-
: {
|
|
25
|
-
[error.path]: { message: error.message, type: error.type },
|
|
26
|
-
};
|
|
27
|
-
exports.yupResolver = (schema, options = {
|
|
28
|
-
abortEarly: false,
|
|
29
|
-
}) => async (values, context, validateAllFieldCriteria = false) => {
|
|
30
|
-
try {
|
|
31
|
-
if (options.context &&
|
|
32
|
-
process.env.NODE_ENV === 'development') {
|
|
33
|
-
// eslint-disable-next-line no-console
|
|
34
|
-
console.warn("You should not used the yup options context. Please, use the 'useForm' context object instead");
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
values: (await schema.validate(values, Object.assign(Object.assign({}, options), { context }))),
|
|
38
|
-
errors: {},
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
catch (e) {
|
|
42
|
-
const parsedErrors = parseErrorSchema(e, validateAllFieldCriteria);
|
|
43
|
-
return {
|
|
44
|
-
values: {},
|
|
45
|
-
errors: react_hook_form_1.transformToNestObject(parsedErrors),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
//# sourceMappingURL=yup.js.map
|
package/dist/yup.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"yup.js","sourceRoot":"","sources":["../src/yup.ts"],"names":[],"mappings":";;;AAAA,qDAA+E;AAG/E,MAAM,gBAAgB,GAAG,CACvB,KAA0B,EAC1B,wBAAiC,EACjC,EAAE,CACF,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM;IAC9C,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAChB,CAAC,QAA6B,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;QACzD,MAAM,aAAa,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QACrE,MAA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AgB,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAAC;QACnE,OAAO;YACL,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,uCAAqB,CAAC,YAAY,CAAC;SAC5C,CAAC;KACH;AACH,CAAC,CAAC"}
|
package/joi.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './dist/joi';
|
package/joi.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./dist/joi');
|
package/superstruct.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./dist/superstruct');
|
package/yup.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './dist/yup';
|
package/yup.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./dist/yup');
|