@sanity/validation 2.21.8-reference-updates.21 → 2.21.10-shopify.4
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/dist/dts/validateDocument.d.ts +1 -1
- package/dist/dts/validateDocument.d.ts.map +1 -1
- package/dist/dts/validators/blockValidator.d.ts.map +1 -1
- package/dist/dts/validators/objectValidator.d.ts.map +1 -1
- package/lib/index.js +7 -7
- package/lib/util/convertToValidationMarker.js +1 -1
- package/lib/validateDocument.js +9 -7
- package/lib/validators/blockValidator.js +1 -2
- package/lib/validators/dateValidator.js +1 -1
- package/lib/validators/objectValidator.js +8 -41
- package/package.json +5 -5
- package/src/validateDocument.test.ts +0 -5
- package/src/validateDocument.ts +1 -3
- package/src/validators/blockValidator.ts +0 -1
- package/src/validators/objectValidator.ts +3 -23
|
@@ -3,7 +3,7 @@ import { SanityDocument, Schema, SchemaType, ValidationContext, ValidationMarker
|
|
|
3
3
|
* @internal
|
|
4
4
|
*/
|
|
5
5
|
export declare function resolveTypeForArrayItem(item: unknown, candidates: SchemaType[]): SchemaType | undefined;
|
|
6
|
-
export default function validateDocument(doc: SanityDocument, schema: Schema
|
|
6
|
+
export default function validateDocument(doc: SanityDocument, schema: Schema): Promise<ValidationMarker[]>;
|
|
7
7
|
/**
|
|
8
8
|
* this is used make optional properties required by replacing optionals with
|
|
9
9
|
* `T[P] | undefined`. this is used to prevent errors in `validateItem` where
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateDocument.d.ts","sourceRoot":"","sources":["../../src/validateDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EAGjB,MAAM,eAAe,CAAA;AAYtB;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,OAAO,EACb,UAAU,EAAE,UAAU,EAAE,GACvB,UAAU,GAAG,SAAS,CAiBxB;AAED,wBAA8B,gBAAgB,CAC5C,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"validateDocument.d.ts","sourceRoot":"","sources":["../../src/validateDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EAGjB,MAAM,eAAe,CAAA;AAYtB;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,OAAO,EACb,UAAU,EAAE,UAAU,EAAE,GACvB,UAAU,GAAG,SAAS,CAiBxB;AAED,wBAA8B,gBAAgB,CAC5C,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,gBAAgB,EAAE,CAAC,CA0B7B;AAED;;;;;;GAMG;AACH,aAAK,iBAAiB,CAAC,CAAC,IAAI;KACzB,CAAC,IAAI,MAAM,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS;CAC5F,CAAA;AAED,aAAK,mBAAmB,GAAG;IACzB,KAAK,EAAE,OAAO,CAAA;CACf,GAAG,iBAAiB,CAAC,iBAAiB,CAAC,CAAA;AAExC,wBAAsB,YAAY,CAAC,EACjC,KAAK,EACL,IAAI,EACJ,IAAS,EACT,MAAM,EACN,GAAG,aAAa,EACjB,EAAE,mBAAmB,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CA8FnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blockValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/blockValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,cAAc,EAAC,MAAM,eAAe,CAAA;AAG9D,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"blockValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/blockValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,cAAc,EAAC,MAAM,eAAe,CAAA;AAG9D,eAAO,MAAM,cAAc,EAAE,cAkD5B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objectValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/objectValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"objectValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/objectValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAA;AAKxC,QAAA,MAAM,gBAAgB,EAAE,UA8CvB,CAAA;AAED,eAAe,gBAAgB,CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -9,12 +9,7 @@ Object.defineProperty(exports, "Rule", {
|
|
|
9
9
|
return _Rule.default;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function get() {
|
|
15
|
-
return _validateDocument.default;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
12
|
+
exports.default = void 0;
|
|
18
13
|
Object.defineProperty(exports, "inferFromSchema", {
|
|
19
14
|
enumerable: true,
|
|
20
15
|
get: function get() {
|
|
@@ -27,7 +22,12 @@ Object.defineProperty(exports, "inferFromSchemaType", {
|
|
|
27
22
|
return _inferFromSchemaType.default;
|
|
28
23
|
}
|
|
29
24
|
});
|
|
30
|
-
exports
|
|
25
|
+
Object.defineProperty(exports, "validateDocument", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function get() {
|
|
28
|
+
return _validateDocument.default;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
31
|
|
|
32
32
|
var _Rule = _interopRequireDefault(require("./Rule"));
|
|
33
33
|
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isNonNullable = isNonNullable;
|
|
7
6
|
exports.default = convertToValidationMarker;
|
|
7
|
+
exports.isNonNullable = isNonNullable;
|
|
8
8
|
|
|
9
9
|
var _ValidationError = _interopRequireDefault(require("../ValidationError"));
|
|
10
10
|
|
package/lib/validateDocument.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.resolveTypeForArrayItem = resolveTypeForArrayItem;
|
|
7
6
|
exports.default = validateDocument;
|
|
7
|
+
exports.resolveTypeForArrayItem = resolveTypeForArrayItem;
|
|
8
8
|
exports.validateItem = validateItem;
|
|
9
9
|
|
|
10
10
|
var _uniqBy2 = _interopRequireDefault(require("lodash/uniqBy"));
|
|
@@ -74,7 +74,7 @@ function resolveTypeForArrayItem(item, candidates) {
|
|
|
74
74
|
}) || candidates.find(candidate => candidate.name === itemType) || candidates.find(candidate => candidate.name === 'object' && primitive === 'object');
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
function validateDocument(_x, _x2
|
|
77
|
+
function validateDocument(_x, _x2) {
|
|
78
78
|
return _validateDocument.apply(this, arguments);
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
@@ -87,7 +87,7 @@ function validateDocument(_x, _x2, _x3) {
|
|
|
87
87
|
|
|
88
88
|
|
|
89
89
|
function _validateDocument() {
|
|
90
|
-
_validateDocument = _asyncToGenerator(function* (doc, schema
|
|
90
|
+
_validateDocument = _asyncToGenerator(function* (doc, schema) {
|
|
91
91
|
var documentType = schema.get(doc._type);
|
|
92
92
|
|
|
93
93
|
if (!documentType) {
|
|
@@ -101,8 +101,7 @@ function _validateDocument() {
|
|
|
101
101
|
value: doc,
|
|
102
102
|
path: [],
|
|
103
103
|
document: doc,
|
|
104
|
-
type: documentType
|
|
105
|
-
getDocumentExists: context === null || context === void 0 ? void 0 : context.getDocumentExists
|
|
104
|
+
type: documentType
|
|
106
105
|
});
|
|
107
106
|
} catch (err) {
|
|
108
107
|
console.error(err);
|
|
@@ -117,7 +116,7 @@ function _validateDocument() {
|
|
|
117
116
|
return _validateDocument.apply(this, arguments);
|
|
118
117
|
}
|
|
119
118
|
|
|
120
|
-
function validateItem(
|
|
119
|
+
function validateItem(_x3) {
|
|
121
120
|
return _validateItem.apply(this, arguments);
|
|
122
121
|
}
|
|
123
122
|
|
|
@@ -141,7 +140,10 @@ function _validateItem() {
|
|
|
141
140
|
var nestedChecks = [];
|
|
142
141
|
var selfIsRequired = rules.some(rule => rule.isRequired());
|
|
143
142
|
var shouldRunNestedObjectValidation = // run nested validation for objects
|
|
144
|
-
(type === null || type === void 0 ? void 0 : type.jsonType) === 'object' && (
|
|
143
|
+
(type === null || type === void 0 ? void 0 : type.jsonType) === 'object' && ( // if the value is truthy
|
|
144
|
+
!!value || // or
|
|
145
|
+
// (the value is null or undefined) and the top-level value is required
|
|
146
|
+
(value === null || value === undefined) && selfIsRequired);
|
|
145
147
|
|
|
146
148
|
if (shouldRunNestedObjectValidation) {
|
|
147
149
|
var fieldTypes = type.fields.reduce((acc, field) => {
|
|
@@ -44,8 +44,7 @@ var blockValidator = /*#__PURE__*/function () {
|
|
|
44
44
|
path: (context.path || []).concat(['markDefs', {
|
|
45
45
|
_key: markDef._key
|
|
46
46
|
}]),
|
|
47
|
-
parent: value
|
|
48
|
-
getDocumentExists: context.getDocumentExists
|
|
47
|
+
parent: value
|
|
49
48
|
});
|
|
50
49
|
annotationValidations.push(validations);
|
|
51
50
|
});
|
|
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _types = require("@sanity/types");
|
|
9
|
-
|
|
10
8
|
var _genericValidator = _interopRequireDefault(require("./genericValidator"));
|
|
11
9
|
|
|
12
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -37,48 +35,17 @@ var objectValidators = _objectSpread(_objectSpread({}, _genericValidator.default
|
|
|
37
35
|
|
|
38
36
|
return true;
|
|
39
37
|
},
|
|
40
|
-
reference:
|
|
41
|
-
|
|
42
|
-
if (!value) {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!(0, _types.isReference)(value)) {
|
|
47
|
-
return message || 'Must be a reference to a document';
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
var type = context.type,
|
|
51
|
-
getDocumentExists = context.getDocumentExists;
|
|
52
|
-
|
|
53
|
-
if (!type) {
|
|
54
|
-
throw new Error("`type` was not provided in validation context");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if ('weak' in type && type.weak) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (!getDocumentExists) {
|
|
62
|
-
throw new Error("`getDocumentExists` was not provided in validation context");
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
var exists = yield getDocumentExists({
|
|
66
|
-
id: value._ref
|
|
67
|
-
}); // TODO: this error message copy may need improvement
|
|
68
|
-
|
|
69
|
-
if (!exists) {
|
|
70
|
-
return 'The referenced document is not yet published. Fix this error by opening the referenced document and publishing it';
|
|
71
|
-
}
|
|
72
|
-
|
|
38
|
+
reference: (_unused, value, message) => {
|
|
39
|
+
if (!value) {
|
|
73
40
|
return true;
|
|
74
|
-
}
|
|
41
|
+
}
|
|
75
42
|
|
|
76
|
-
|
|
77
|
-
return
|
|
43
|
+
if (typeof value._ref !== 'string') {
|
|
44
|
+
return message || 'Must be a reference to a document';
|
|
78
45
|
}
|
|
79
46
|
|
|
80
|
-
return
|
|
81
|
-
}
|
|
47
|
+
return true;
|
|
48
|
+
},
|
|
82
49
|
block: function () {
|
|
83
50
|
var _block = _asyncToGenerator(function* (validateBlock, value, message, context) {
|
|
84
51
|
var result = yield validateBlock(value, context);
|
|
@@ -90,7 +57,7 @@ var objectValidators = _objectSpread(_objectSpread({}, _genericValidator.default
|
|
|
90
57
|
return result;
|
|
91
58
|
});
|
|
92
59
|
|
|
93
|
-
function block(
|
|
60
|
+
function block(_x, _x2, _x3, _x4) {
|
|
94
61
|
return _block.apply(this, arguments);
|
|
95
62
|
}
|
|
96
63
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/validation",
|
|
3
|
-
"version": "2.21.
|
|
3
|
+
"version": "2.21.10-shopify.4+dffdee67c",
|
|
4
4
|
"description": "Validation and warning infrastructure for Sanity projects",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./dist/dts",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"directory": "packages/@sanity/validation"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@sanity/client": "2.21.
|
|
36
|
-
"@sanity/schema": "2.21.
|
|
35
|
+
"@sanity/client": "2.21.10-shopify.4+dffdee67c",
|
|
36
|
+
"@sanity/schema": "2.21.10-shopify.4+dffdee67c"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@sanity/client": "^2.0.0"
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@sanity/types": "2.21.
|
|
47
|
+
"@sanity/types": "2.21.10-shopify.4+dffdee67c",
|
|
48
48
|
"date-fns": "^2.16.1",
|
|
49
49
|
"lodash": "^4.17.15"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "dffdee67c802813521a57f917f2ec1df732f3d61"
|
|
52
52
|
}
|
|
@@ -165,7 +165,6 @@ describe('validateItem', () => {
|
|
|
165
165
|
path: [],
|
|
166
166
|
parent: undefined,
|
|
167
167
|
type: schema.get('testObj'),
|
|
168
|
-
getDocumentExists: undefined,
|
|
169
168
|
})
|
|
170
169
|
).resolves.toMatchObject([
|
|
171
170
|
{
|
|
@@ -236,7 +235,6 @@ describe('validateItem', () => {
|
|
|
236
235
|
path: undefined,
|
|
237
236
|
type: schema.get('testObj'),
|
|
238
237
|
value: {foo: 5},
|
|
239
|
-
getDocumentExists: undefined,
|
|
240
238
|
})
|
|
241
239
|
).resolves.toMatchObject([
|
|
242
240
|
{
|
|
@@ -287,7 +285,6 @@ describe('validateItem', () => {
|
|
|
287
285
|
path: [],
|
|
288
286
|
type: schema.get('values'),
|
|
289
287
|
value: values,
|
|
290
|
-
getDocumentExists: undefined,
|
|
291
288
|
})
|
|
292
289
|
).resolves.toEqual([
|
|
293
290
|
{
|
|
@@ -380,7 +377,6 @@ describe('validateItem', () => {
|
|
|
380
377
|
document,
|
|
381
378
|
parent: document,
|
|
382
379
|
path: undefined,
|
|
383
|
-
getDocumentExists: undefined,
|
|
384
380
|
})
|
|
385
381
|
).resolves.toMatchObject([
|
|
386
382
|
{
|
|
@@ -521,7 +517,6 @@ describe('validateItem', () => {
|
|
|
521
517
|
parent: undefined,
|
|
522
518
|
path: undefined,
|
|
523
519
|
type: schema.get('root'),
|
|
524
|
-
getDocumentExists: undefined,
|
|
525
520
|
})
|
|
526
521
|
|
|
527
522
|
// after `validateItem(...)` has been initiated, all of the custom
|
package/src/validateDocument.ts
CHANGED
|
@@ -45,8 +45,7 @@ export function resolveTypeForArrayItem(
|
|
|
45
45
|
|
|
46
46
|
export default async function validateDocument(
|
|
47
47
|
doc: SanityDocument,
|
|
48
|
-
schema: Schema
|
|
49
|
-
context?: Pick<ValidationContext, 'getDocumentExists'>
|
|
48
|
+
schema: Schema
|
|
50
49
|
): Promise<ValidationMarker[]> {
|
|
51
50
|
const documentType = schema.get(doc._type)
|
|
52
51
|
if (!documentType) {
|
|
@@ -61,7 +60,6 @@ export default async function validateDocument(
|
|
|
61
60
|
path: [],
|
|
62
61
|
document: doc,
|
|
63
62
|
type: documentType,
|
|
64
|
-
getDocumentExists: context?.getDocumentExists,
|
|
65
63
|
})
|
|
66
64
|
} catch (err) {
|
|
67
65
|
console.error(err)
|
|
@@ -38,7 +38,6 @@ export const blockValidator: BlockValidator = async (value, context) => {
|
|
|
38
38
|
type: annotationType,
|
|
39
39
|
path: (context.path || []).concat(['markDefs', {_key: markDef._key}]),
|
|
40
40
|
parent: value,
|
|
41
|
-
getDocumentExists: context.getDocumentExists,
|
|
42
41
|
})
|
|
43
42
|
annotationValidations.push(validations)
|
|
44
43
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {Validators
|
|
1
|
+
import {Validators} from '@sanity/types'
|
|
2
2
|
import genericValidator from './genericValidator'
|
|
3
3
|
|
|
4
4
|
const metaKeys = ['_key', '_type', '_weak']
|
|
@@ -20,35 +20,15 @@ const objectValidators: Validators = {
|
|
|
20
20
|
return true
|
|
21
21
|
},
|
|
22
22
|
|
|
23
|
-
reference:
|
|
23
|
+
reference: (_unused, value, message) => {
|
|
24
24
|
if (!value) {
|
|
25
25
|
return true
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
if (
|
|
28
|
+
if (typeof value._ref !== 'string') {
|
|
29
29
|
return message || 'Must be a reference to a document'
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const {type, getDocumentExists} = context
|
|
33
|
-
|
|
34
|
-
if (!type) {
|
|
35
|
-
throw new Error(`\`type\` was not provided in validation context`)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if ('weak' in type && type.weak) {
|
|
39
|
-
return true
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!getDocumentExists) {
|
|
43
|
-
throw new Error(`\`getDocumentExists\` was not provided in validation context`)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const exists = await getDocumentExists({id: value._ref})
|
|
47
|
-
// TODO: this error message copy may need improvement
|
|
48
|
-
if (!exists) {
|
|
49
|
-
return 'The referenced document is not yet published. Fix this error by opening the referenced document and publishing it'
|
|
50
|
-
}
|
|
51
|
-
|
|
52
32
|
return true
|
|
53
33
|
},
|
|
54
34
|
|