@sanity/validation 2.34.2-empty-template-cli.0 → 2.34.3-cdr-preview.7

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.
@@ -4,54 +4,41 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _genericValidator = _interopRequireDefault(require("./genericValidator"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
9
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
-
14
10
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
-
16
11
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
-
18
12
  var DUMMY_ORIGIN = 'http://sanity';
19
13
  var emailRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
20
-
21
14
  var isRelativeUrl = url => /^\.*\//.test(url);
22
-
23
15
  var stringValidators = _objectSpread(_objectSpread({}, _genericValidator.default), {}, {
24
16
  min: (minLength, value, message) => {
25
17
  if (!value || value.length >= minLength) {
26
18
  return true;
27
19
  }
28
-
29
20
  return message || "Must be at least ".concat(minLength, " characters long");
30
21
  },
31
22
  max: (maxLength, value, message) => {
32
23
  if (!value || value.length <= maxLength) {
33
24
  return true;
34
25
  }
35
-
36
26
  return message || "Must be at most ".concat(maxLength, " characters long");
37
27
  },
38
28
  length: (wantedLength, value, message) => {
39
29
  var strValue = value || '';
40
-
41
30
  if (strValue.length === wantedLength) {
42
31
  return true;
43
32
  }
44
-
45
33
  return message || "Must be exactly ".concat(wantedLength, " characters long");
46
34
  },
47
35
  uri: (constraints, value, message) => {
48
36
  var strValue = value || '';
49
37
  var options = constraints.options;
50
38
  var allowCredentials = options.allowCredentials,
51
- relativeOnly = options.relativeOnly;
39
+ relativeOnly = options.relativeOnly;
52
40
  var allowRelative = options.allowRelative || relativeOnly;
53
41
  var url;
54
-
55
42
  try {
56
43
  // WARNING: Safari checks for a given `base` param by looking at the length of arguments passed
57
44
  // to new URL(str, base), and will fail if invoked with new URL(strValue, undefined)
@@ -59,73 +46,58 @@ var stringValidators = _objectSpread(_objectSpread({}, _genericValidator.default
59
46
  } catch (err) {
60
47
  return message || 'Not a valid URL';
61
48
  }
62
-
63
49
  if (relativeOnly && url.origin !== DUMMY_ORIGIN) {
64
50
  return message || 'Only relative URLs are allowed';
65
51
  }
66
-
67
52
  if (!allowRelative && url.origin === DUMMY_ORIGIN && isRelativeUrl(strValue)) {
68
53
  return message || 'Relative URLs are not allowed';
69
54
  }
70
-
71
55
  if (!allowCredentials && (url.username || url.password)) {
72
56
  return message || "Username/password not allowed";
73
57
  }
74
-
75
58
  var urlScheme = url.protocol.replace(/:$/, '');
76
59
  var matchesAllowedScheme = options.scheme.some(scheme => scheme.test(urlScheme));
77
-
78
60
  if (!matchesAllowedScheme) {
79
61
  return message || 'Does not match allowed protocols/schemes';
80
62
  }
81
-
82
63
  return true;
83
64
  },
84
65
  stringCasing: (casing, value, message) => {
85
66
  var strValue = value || '';
86
-
87
67
  if (casing === 'uppercase' && strValue !== strValue.toLocaleUpperCase()) {
88
68
  return message || "Must be all uppercase letters";
89
69
  }
90
-
91
70
  if (casing === 'lowercase' && strValue !== strValue.toLocaleLowerCase()) {
92
71
  return message || "Must be all lowercase letters";
93
72
  }
94
-
95
73
  return true;
96
74
  },
97
75
  presence: (flag, value, message) => {
98
76
  if (flag === 'required' && !value) {
99
77
  return message || 'Required';
100
78
  }
101
-
102
79
  return true;
103
80
  },
104
81
  regex: (options, value, message) => {
105
82
  var pattern = options.pattern,
106
- name = options.name,
107
- invert = options.invert;
83
+ name = options.name,
84
+ invert = options.invert;
108
85
  var regName = name || "\"".concat(pattern.toString(), "\"");
109
86
  var strValue = value || '';
110
87
  var matches = pattern.test(strValue);
111
-
112
88
  if (!invert && !matches || invert && matches) {
113
89
  var defaultMessage = invert ? "Should not match ".concat(regName, "-pattern") : "Does not match ".concat(regName, "-pattern");
114
90
  return message || defaultMessage;
115
91
  }
116
-
117
92
  return true;
118
93
  },
119
94
  email: (_unused, value, message) => {
120
95
  var strValue = "".concat(value || '').trim();
121
-
122
96
  if (!strValue || emailRegex.test(strValue)) {
123
97
  return true;
124
98
  }
125
-
126
99
  return message || 'Must be a valid email address';
127
100
  }
128
101
  });
129
-
130
102
  var _default = stringValidators;
131
103
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/validation",
3
- "version": "2.34.2-empty-template-cli.0+184a9350e5",
3
+ "version": "2.34.3-cdr-preview.7+0d661c122",
4
4
  "description": "Validation and warning infrastructure for Sanity projects",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./dist/dts",
@@ -33,13 +33,13 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@sanity/client": "^3.3.3",
36
- "@sanity/schema": "2.34.2-empty-template-cli.0+184a9350e5"
36
+ "@sanity/schema": "2.34.3-cdr-preview.7+0d661c122"
37
37
  },
38
38
  "dependencies": {
39
- "@sanity/types": "2.34.2-empty-template-cli.0+184a9350e5",
39
+ "@sanity/types": "2.34.3-cdr-preview.7+0d661c122",
40
40
  "date-fns": "^2.16.1",
41
41
  "lodash": "^4.17.15",
42
42
  "rxjs": "^6.5.3"
43
43
  },
44
- "gitHead": "184a9350e50aa05877a3b10e052ce4e2ca743ef0"
44
+ "gitHead": "0d661c122864b683c7bfbcb03fddc2407c617ae0"
45
45
  }