@prismicio/types-internal 2.2.0-alpha.0 → 2.2.0-alpha.1
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.
|
@@ -37,8 +37,22 @@ const ImportDocument = (mask) => new t.Type("ImportDocument", (u) => (0, Objects
|
|
|
37
37
|
const fieldCodec = getFieldCodec(maskFieldValue);
|
|
38
38
|
const result = fieldCodec.decode(fieldValue);
|
|
39
39
|
// returning validation errors
|
|
40
|
-
if (Either.isLeft(result))
|
|
41
|
-
|
|
40
|
+
if (Either.isLeft(result)) {
|
|
41
|
+
// error.context is pointing at root when it should point to a `fieldKey`.
|
|
42
|
+
// We need to override the context to make it right.
|
|
43
|
+
const errors = result.left.map(error => {
|
|
44
|
+
const contextHead = error.context[0];
|
|
45
|
+
const context = [
|
|
46
|
+
{ key: '', actual: raw, type: (0, exports.ImportDocument)(mask) },
|
|
47
|
+
contextHead
|
|
48
|
+
? { ...contextHead, key: fieldKey }
|
|
49
|
+
: { key: fieldKey, actual: fieldValue, type: fieldCodec },
|
|
50
|
+
...error.context.slice(1)
|
|
51
|
+
];
|
|
52
|
+
return { ...error, context };
|
|
53
|
+
});
|
|
54
|
+
return { ...acc, errors: [...acc.errors, ...errors] };
|
|
55
|
+
}
|
|
42
56
|
// registering the field as validated
|
|
43
57
|
return {
|
|
44
58
|
...acc,
|
package/package.json
CHANGED
|
@@ -54,8 +54,24 @@ export const ImportDocument = (mask: StaticCustomType) =>
|
|
|
54
54
|
const result = fieldCodec.decode(fieldValue)
|
|
55
55
|
|
|
56
56
|
// returning validation errors
|
|
57
|
-
if (Either.isLeft(result))
|
|
58
|
-
|
|
57
|
+
if (Either.isLeft(result)) {
|
|
58
|
+
// error.context is pointing at root when it should point to a `fieldKey`.
|
|
59
|
+
// We need to override the context to make it right.
|
|
60
|
+
const errors: t.Errors = result.left.map(error => {
|
|
61
|
+
const contextHead = error.context[0];
|
|
62
|
+
const context = [
|
|
63
|
+
{ key: '', actual: raw, type: ImportDocument(mask) },
|
|
64
|
+
contextHead
|
|
65
|
+
? { ...contextHead, key: fieldKey }
|
|
66
|
+
: {key: fieldKey, actual: fieldValue, type: fieldCodec},
|
|
67
|
+
...error.context.slice(1)
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
return { ...error, context };
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return { ...acc, errors: [...acc.errors, ...errors] };
|
|
74
|
+
}
|
|
59
75
|
|
|
60
76
|
// registering the field as validated
|
|
61
77
|
return {
|
|
@@ -77,3 +93,4 @@ function getFieldCodec(maskValue: StaticWidget) {
|
|
|
77
93
|
if (isNestableWidget(maskValue)) return getNestableFieldCodec(maskValue)
|
|
78
94
|
throw new Error(`Unsupported type of field ${maskValue.type}`)
|
|
79
95
|
}
|
|
96
|
+
|