@sanity/validation 2.29.5-get-started-template.15 → 2.30.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dateValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/dateValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAA;AAIxC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAErE;
|
|
1
|
+
{"version":3,"file":"dateValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/dateValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAA;AAIxC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAErE;AAiDD,QAAA,MAAM,cAAc,EAAE,UAuDrB,CAAA;AAED,eAAe,cAAc,CAAA"}
|
package/lib/Rule.js
CHANGED
|
@@ -31,7 +31,7 @@ var _objectValidator = _interopRequireDefault(require("./validators/objectValida
|
|
|
31
31
|
|
|
32
32
|
var _dateValidator = _interopRequireDefault(require("./validators/dateValidator"));
|
|
33
33
|
|
|
34
|
-
var _class
|
|
34
|
+
var _class;
|
|
35
35
|
|
|
36
36
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
37
37
|
|
|
@@ -77,7 +77,7 @@ var ruleConstraintTypes = ['Array', 'Boolean', 'Date', 'Number', 'Object', 'Stri
|
|
|
77
77
|
// an instance definition. This should help reminder downstream users to import
|
|
78
78
|
// from the `@sanity/types` package.
|
|
79
79
|
|
|
80
|
-
var Rule = (
|
|
80
|
+
var Rule = (_class = class Rule {
|
|
81
81
|
constructor(typeDef) {
|
|
82
82
|
_defineProperty(this, "_type", undefined);
|
|
83
83
|
|
|
@@ -486,6 +486,6 @@ var Rule = (_temp = _class = class Rule {
|
|
|
486
486
|
}, _defineProperty(_class, "FIELD_REF", FIELD_REF), _defineProperty(_class, "array", def => new _class(def).type('Array')), _defineProperty(_class, "object", def => new _class(def).type('Object')), _defineProperty(_class, "string", def => new _class(def).type('String')), _defineProperty(_class, "number", def => new _class(def).type('Number')), _defineProperty(_class, "boolean", def => new _class(def).type('Boolean')), _defineProperty(_class, "dateTime", def => new _class(def).type('Date')), _defineProperty(_class, "valueOfField", path => ({
|
|
487
487
|
type: FIELD_REF,
|
|
488
488
|
path
|
|
489
|
-
})),
|
|
489
|
+
})), _class);
|
|
490
490
|
var _default = Rule;
|
|
491
491
|
exports.default = _default;
|
|
@@ -38,7 +38,7 @@ var getFormattedDate = function getFormattedDate() {
|
|
|
38
38
|
|
|
39
39
|
if (type === 'date') {
|
|
40
40
|
// If the type is date only
|
|
41
|
-
return (0, _format.default)(value, format);
|
|
41
|
+
return (0, _format.default)(new Date(value), format);
|
|
42
42
|
} // If the type is datetime
|
|
43
43
|
|
|
44
44
|
|
|
@@ -48,7 +48,7 @@ var getFormattedDate = function getFormattedDate() {
|
|
|
48
48
|
format += ' HH:mm';
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
return (0, _format.default)(value, format);
|
|
51
|
+
return (0, _format.default)(new Date(value), format);
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
function parseDate(date) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/validation",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.30.0",
|
|
4
4
|
"description": "Validation and warning infrastructure for Sanity projects",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./dist/dts",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@sanity/client": "^3.2.0",
|
|
36
|
-
"@sanity/schema": "2.29.
|
|
36
|
+
"@sanity/schema": "2.29.3"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@sanity/client": "^3.2.0"
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@sanity/types": "2.29.5
|
|
47
|
+
"@sanity/types": "2.29.5",
|
|
48
48
|
"date-fns": "^2.16.1",
|
|
49
49
|
"lodash": "^4.17.15"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "3dc314180466f1132fa236b0e3386a770a2b9469"
|
|
52
52
|
}
|
|
@@ -16,22 +16,25 @@ interface DateTimeOptions {
|
|
|
16
16
|
timeFormat?: string
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const getFormattedDate = (type = '', value: number | Date, options?: DateTimeOptions) => {
|
|
19
|
+
const getFormattedDate = (type = '', value: string | number | Date, options?: DateTimeOptions) => {
|
|
20
20
|
let format = 'yyyy-MM-dd'
|
|
21
21
|
if (options && options.dateFormat) {
|
|
22
22
|
format = options.dateFormat
|
|
23
23
|
}
|
|
24
|
+
|
|
24
25
|
if (type === 'date') {
|
|
25
26
|
// If the type is date only
|
|
26
|
-
return formatDate(value, format)
|
|
27
|
+
return formatDate(new Date(value), format)
|
|
27
28
|
}
|
|
29
|
+
|
|
28
30
|
// If the type is datetime
|
|
29
31
|
if (options && options.timeFormat) {
|
|
30
32
|
format += ` ${options.timeFormat}`
|
|
31
33
|
} else {
|
|
32
34
|
format += ' HH:mm'
|
|
33
35
|
}
|
|
34
|
-
|
|
36
|
+
|
|
37
|
+
return formatDate(new Date(value), format)
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
function parseDate(date: unknown): Date | null
|
|
@@ -80,6 +83,7 @@ const dateValidators: Validators = {
|
|
|
80
83
|
: {}
|
|
81
84
|
|
|
82
85
|
const date = getFormattedDate(context.type.name, minDate, dateTimeOptions)
|
|
86
|
+
|
|
83
87
|
return message || `Must be at or after ${date}`
|
|
84
88
|
},
|
|
85
89
|
|