remix-validated-form 3.0.0-beta.1 → 3.2.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/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-test.log +10 -35
- package/README.md +41 -13
- package/browser/ValidatedForm.d.ts +6 -1
- package/browser/ValidatedForm.js +52 -1
- package/browser/hooks.d.ts +25 -1
- package/browser/hooks.js +44 -13
- package/browser/internal/MultiValueMap.d.ts +0 -0
- package/browser/internal/MultiValueMap.js +1 -0
- package/browser/internal/SingleTypeMultiValueMap.d.ts +8 -0
- package/browser/internal/SingleTypeMultiValueMap.js +40 -0
- package/browser/internal/formContext.d.ts +25 -1
- package/browser/internal/formContext.js +5 -0
- package/browser/internal/getInputProps.d.ts +28 -0
- package/browser/internal/getInputProps.js +38 -0
- package/{build/validation/validation.test.d.ts → browser/internal/test.d.ts} +0 -0
- package/browser/internal/test.js +10 -0
- package/browser/server.d.ts +1 -1
- package/browser/server.js +11 -1
- package/browser/validation/types.d.ts +2 -0
- package/build/ValidatedForm.d.ts +6 -1
- package/build/ValidatedForm.js +52 -1
- package/build/hooks.d.ts +25 -1
- package/build/hooks.js +43 -12
- package/build/internal/SingleTypeMultiValueMap.d.ts +8 -0
- package/build/internal/SingleTypeMultiValueMap.js +45 -0
- package/build/internal/formContext.d.ts +25 -1
- package/build/internal/formContext.js +5 -0
- package/build/internal/getInputProps.d.ts +28 -0
- package/build/internal/getInputProps.js +42 -0
- package/build/internal/test.d.ts +1 -0
- package/build/internal/test.js +12 -0
- package/build/server.d.ts +1 -1
- package/build/server.js +11 -1
- package/build/validation/types.d.ts +2 -0
- package/package.json +1 -3
- package/src/ValidatedForm.tsx +73 -0
- package/src/hooks.ts +77 -9
- package/src/internal/SingleTypeMultiValueMap.ts +37 -0
- package/src/internal/formContext.ts +30 -1
- package/src/internal/getInputProps.ts +79 -0
- package/src/server.ts +18 -2
- package/src/validation/types.ts +8 -0
- package/build/test-data/testFormData.d.ts +0 -15
- package/build/test-data/testFormData.js +0 -50
- package/build/validation/validation.test.js +0 -295
- package/build/validation/withYup.d.ts +0 -6
- package/build/validation/withYup.js +0 -44
- package/build/validation/withZod.d.ts +0 -6
- package/build/validation/withZod.js +0 -57
@@ -1,44 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.withYup = void 0;
|
4
|
-
const createValidator_1 = require("./createValidator");
|
5
|
-
const validationErrorToFieldErrors = (error) => {
|
6
|
-
const fieldErrors = {};
|
7
|
-
error.inner.forEach((innerError) => {
|
8
|
-
if (!innerError.path)
|
9
|
-
return;
|
10
|
-
fieldErrors[innerError.path] = innerError.message;
|
11
|
-
});
|
12
|
-
return fieldErrors;
|
13
|
-
};
|
14
|
-
/**
|
15
|
-
* Create a `Validator` using a `yup` schema.
|
16
|
-
*/
|
17
|
-
const withYup = (validationSchema) => {
|
18
|
-
return (0, createValidator_1.createValidator)({
|
19
|
-
validate: (data) => {
|
20
|
-
try {
|
21
|
-
const validated = validationSchema.validateSync(data, {
|
22
|
-
abortEarly: false,
|
23
|
-
});
|
24
|
-
return { data: validated, error: undefined };
|
25
|
-
}
|
26
|
-
catch (err) {
|
27
|
-
return {
|
28
|
-
error: validationErrorToFieldErrors(err),
|
29
|
-
data: undefined,
|
30
|
-
};
|
31
|
-
}
|
32
|
-
},
|
33
|
-
validateField: (data, field) => {
|
34
|
-
try {
|
35
|
-
validationSchema.validateSyncAt(field, data);
|
36
|
-
return {};
|
37
|
-
}
|
38
|
-
catch (err) {
|
39
|
-
return { error: err.message };
|
40
|
-
}
|
41
|
-
},
|
42
|
-
});
|
43
|
-
};
|
44
|
-
exports.withYup = withYup;
|
@@ -1,57 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.withZod = void 0;
|
7
|
-
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
8
|
-
const toPath_1 = __importDefault(require("lodash/toPath"));
|
9
|
-
const createValidator_1 = require("./createValidator");
|
10
|
-
const getIssuesForError = (err) => {
|
11
|
-
return err.issues.flatMap((issue) => {
|
12
|
-
if ("unionErrors" in issue) {
|
13
|
-
return issue.unionErrors.flatMap((err) => getIssuesForError(err));
|
14
|
-
}
|
15
|
-
else {
|
16
|
-
return [issue];
|
17
|
-
}
|
18
|
-
});
|
19
|
-
};
|
20
|
-
function pathToString(array) {
|
21
|
-
return array.reduce(function (string, item) {
|
22
|
-
var prefix = string === "" ? "" : ".";
|
23
|
-
return string + (isNaN(Number(item)) ? prefix + item : "[" + item + "]");
|
24
|
-
}, "");
|
25
|
-
}
|
26
|
-
/**
|
27
|
-
* Create a validator using a `zod` schema.
|
28
|
-
*/
|
29
|
-
function withZod(zodSchema) {
|
30
|
-
return (0, createValidator_1.createValidator)({
|
31
|
-
validate: (value) => {
|
32
|
-
const result = zodSchema.safeParse(value);
|
33
|
-
if (result.success)
|
34
|
-
return { data: result.data, error: undefined };
|
35
|
-
const fieldErrors = {};
|
36
|
-
getIssuesForError(result.error).forEach((issue) => {
|
37
|
-
const path = pathToString(issue.path);
|
38
|
-
if (!fieldErrors[path])
|
39
|
-
fieldErrors[path] = issue.message;
|
40
|
-
});
|
41
|
-
return { error: fieldErrors, data: undefined };
|
42
|
-
},
|
43
|
-
validateField: (data, field) => {
|
44
|
-
var _a;
|
45
|
-
const result = zodSchema.safeParse(data);
|
46
|
-
if (result.success)
|
47
|
-
return { error: undefined };
|
48
|
-
return {
|
49
|
-
error: (_a = getIssuesForError(result.error).find((issue) => {
|
50
|
-
const allPathsAsString = issue.path.map((p) => `${p}`);
|
51
|
-
return (0, isEqual_1.default)(allPathsAsString, (0, toPath_1.default)(field));
|
52
|
-
})) === null || _a === void 0 ? void 0 : _a.message,
|
53
|
-
};
|
54
|
-
},
|
55
|
-
});
|
56
|
-
}
|
57
|
-
exports.withZod = withZod;
|