@sanity/validation 2.22.3-reference-updates.73 → 2.22.3
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/objectValidator.d.ts.map +1 -1
- package/lib/validateDocument.js +4 -5
- package/lib/validators/objectValidator.js +7 -44
- package/package.json +5 -5
- package/src/validateDocument.test.ts +0 -6
- package/src/validateDocument.ts +1 -3
- package/src/validators/objectValidator.ts +3 -22
|
@@ -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,EAMjB,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,EAMjB,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,CA4HnD"}
|
|
@@ -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,UAqCvB,CAAA;AAED,eAAe,gBAAgB,CAAA"}
|
package/lib/validateDocument.js
CHANGED
|
@@ -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
|
|
|
@@ -5,16 +5,10 @@ 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 }; }
|
|
13
11
|
|
|
14
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
15
|
-
|
|
16
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
17
|
-
|
|
18
12
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
19
13
|
|
|
20
14
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
@@ -37,48 +31,17 @@ var objectValidators = _objectSpread(_objectSpread({}, _genericValidator.default
|
|
|
37
31
|
|
|
38
32
|
return true;
|
|
39
33
|
},
|
|
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
|
-
});
|
|
68
|
-
|
|
69
|
-
if (!exists) {
|
|
70
|
-
return 'This reference must be published';
|
|
71
|
-
}
|
|
72
|
-
|
|
34
|
+
reference: (_unused, value, message) => {
|
|
35
|
+
if (!value) {
|
|
73
36
|
return true;
|
|
74
|
-
}
|
|
37
|
+
}
|
|
75
38
|
|
|
76
|
-
|
|
77
|
-
return
|
|
39
|
+
if (typeof value._ref !== 'string') {
|
|
40
|
+
return message || 'Must be a reference to a document';
|
|
78
41
|
}
|
|
79
42
|
|
|
80
|
-
return
|
|
81
|
-
}
|
|
43
|
+
return true;
|
|
44
|
+
},
|
|
82
45
|
assetRequired: (flag, value, message) => {
|
|
83
46
|
if (!value || !value.asset || !value.asset._ref) {
|
|
84
47
|
var assetType = flag.assetType || 'Asset';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/validation",
|
|
3
|
-
"version": "2.22.3
|
|
3
|
+
"version": "2.22.3",
|
|
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.22.3
|
|
36
|
-
"@sanity/schema": "2.22.3
|
|
35
|
+
"@sanity/client": "2.22.3",
|
|
36
|
+
"@sanity/schema": "2.22.3"
|
|
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.22.3
|
|
47
|
+
"@sanity/types": "2.22.3",
|
|
48
48
|
"date-fns": "^2.16.1",
|
|
49
49
|
"lodash": "^4.17.15"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "3e7d474f5ca24c97cfc33f6fc038996e33ccbac9"
|
|
52
52
|
}
|
|
@@ -168,7 +168,6 @@ describe('validateItem', () => {
|
|
|
168
168
|
path: [],
|
|
169
169
|
parent: undefined,
|
|
170
170
|
type: schema.get('testObj'),
|
|
171
|
-
getDocumentExists: undefined,
|
|
172
171
|
})
|
|
173
172
|
).resolves.toMatchObject([
|
|
174
173
|
{
|
|
@@ -242,7 +241,6 @@ describe('validateItem', () => {
|
|
|
242
241
|
path: undefined,
|
|
243
242
|
type: schema.get('testObj'),
|
|
244
243
|
value: {foo: 5},
|
|
245
|
-
getDocumentExists: undefined,
|
|
246
244
|
})
|
|
247
245
|
).resolves.toMatchObject([
|
|
248
246
|
{
|
|
@@ -408,7 +406,6 @@ describe('validateItem', () => {
|
|
|
408
406
|
path: [],
|
|
409
407
|
type: schema.get('blockTest'),
|
|
410
408
|
value: document,
|
|
411
|
-
getDocumentExists: undefined,
|
|
412
409
|
})
|
|
413
410
|
|
|
414
411
|
expect(result).toMatchObject([
|
|
@@ -511,7 +508,6 @@ describe('validateItem', () => {
|
|
|
511
508
|
path: [],
|
|
512
509
|
type: schema.get('values'),
|
|
513
510
|
value: values,
|
|
514
|
-
getDocumentExists: undefined,
|
|
515
511
|
})
|
|
516
512
|
).resolves.toEqual([
|
|
517
513
|
{
|
|
@@ -609,7 +605,6 @@ describe('validateItem', () => {
|
|
|
609
605
|
document,
|
|
610
606
|
parent: document,
|
|
611
607
|
path: undefined,
|
|
612
|
-
getDocumentExists: undefined,
|
|
613
608
|
})
|
|
614
609
|
).resolves.toMatchObject([
|
|
615
610
|
{
|
|
@@ -750,7 +745,6 @@ describe('validateItem', () => {
|
|
|
750
745
|
parent: undefined,
|
|
751
746
|
path: undefined,
|
|
752
747
|
type: schema.get('root'),
|
|
753
|
-
getDocumentExists: undefined,
|
|
754
748
|
})
|
|
755
749
|
|
|
756
750
|
// after `validateItem(...)` has been initiated, all of the custom
|
package/src/validateDocument.ts
CHANGED
|
@@ -48,8 +48,7 @@ export function resolveTypeForArrayItem(
|
|
|
48
48
|
|
|
49
49
|
export default async function validateDocument(
|
|
50
50
|
doc: SanityDocument,
|
|
51
|
-
schema: Schema
|
|
52
|
-
context?: Pick<ValidationContext, 'getDocumentExists'>
|
|
51
|
+
schema: Schema
|
|
53
52
|
): Promise<ValidationMarker[]> {
|
|
54
53
|
const documentType = schema.get(doc._type)
|
|
55
54
|
if (!documentType) {
|
|
@@ -64,7 +63,6 @@ export default async function validateDocument(
|
|
|
64
63
|
path: [],
|
|
65
64
|
document: doc,
|
|
66
65
|
type: documentType,
|
|
67
|
-
getDocumentExists: context?.getDocumentExists,
|
|
68
66
|
})
|
|
69
67
|
} catch (err) {
|
|
70
68
|
console.error(err)
|
|
@@ -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,34 +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
|
-
if (!exists) {
|
|
48
|
-
return 'This reference must be published'
|
|
49
|
-
}
|
|
50
|
-
|
|
51
32
|
return true
|
|
52
33
|
},
|
|
53
34
|
|