@sanity/validation 3.0.7-canary.7 → 3.1.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.
package/lib/index.js CHANGED
@@ -9,17 +9,26 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
9
9
  Object.defineProperty(exports, '__esModule', {
10
10
  value: true
11
11
  });
12
- var lodash = require('lodash');
12
+ var cloneDeep = require('lodash/cloneDeep.js');
13
+ var get = require('lodash/get.js');
13
14
  var types = require('@sanity/types');
14
15
  var formatDate = require('date-fns/format');
15
16
  var rxjs = require('rxjs');
16
17
  var operators = require('rxjs/operators');
18
+ var flatten = require('lodash/flatten.js');
19
+ var uniqBy = require('lodash/uniqBy.js');
20
+ var memoize = require('lodash/memoize.js');
17
21
  function _interopDefaultLegacy(e) {
18
22
  return e && typeof e === 'object' && 'default' in e ? e : {
19
23
  'default': e
20
24
  };
21
25
  }
26
+ var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
27
+ var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
22
28
  var formatDate__default = /*#__PURE__*/_interopDefaultLegacy(formatDate);
29
+ var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
30
+ var uniqBy__default = /*#__PURE__*/_interopDefaultLegacy(uniqBy);
31
+ var memoize__default = /*#__PURE__*/_interopDefaultLegacy(memoize);
23
32
  const ValidationError = class ValidationError2 {
24
33
  constructor(message) {
25
34
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -647,7 +656,7 @@ const Rule = (_a = class {
647
656
  rule._type = this._type;
648
657
  rule._message = this._message;
649
658
  rule._required = this._required;
650
- rule._rules = lodash.cloneDeep(this._rules);
659
+ rule._rules = cloneDeep__default["default"](this._rules);
651
660
  rule._level = this._level;
652
661
  rule._fieldRules = this._fieldRules;
653
662
  rule._typeDef = this._typeDef;
@@ -726,12 +735,6 @@ const Rule = (_a = class {
726
735
  constraint: fn
727
736
  }]);
728
737
  }
729
- block(fn) {
730
- return this.cloneWithRules([{
731
- flag: "custom",
732
- constraint: fn
733
- }]);
734
- }
735
738
  min(len) {
736
739
  return this.cloneWithRules([{
737
740
  flag: "min",
@@ -901,7 +904,7 @@ const Rule = (_a = class {
901
904
  }
902
905
  let specConstraint = "constraint" in curr ? curr.constraint : null;
903
906
  if (isFieldRef(specConstraint)) {
904
- specConstraint = lodash.get(context.parent, specConstraint.path);
907
+ specConstraint = get__default["default"](context.parent, specConstraint.path);
905
908
  }
906
909
  let result;
907
910
  try {
@@ -935,7 +938,7 @@ const cancelIdleCallbackShim = function cancelIdleCallbackShim2(handle) {
935
938
  const win = typeof window === "undefined" ? void 0 : window;
936
939
  const requestIdleCallback = (win == null ? void 0 : win.requestIdleCallback) || requestIdleCallbackShim;
937
940
  const cancelIdleCallback = (win == null ? void 0 : win.cancelIdleCallback) || cancelIdleCallbackShim;
938
- const memoizedWarnOnArraySlug = lodash.memoize(warnOnArraySlug);
941
+ const memoizedWarnOnArraySlug = memoize__default["default"](warnOnArraySlug);
939
942
  function getDocumentIds(id) {
940
943
  const isDraft = id.indexOf("drafts.") === 0;
941
944
  return {
@@ -1150,6 +1153,7 @@ function validateItemObservable(_ref) {
1150
1153
  parent
1151
1154
  } = _ref,
1152
1155
  restOfContext = _objectWithoutProperties(_ref, _excluded);
1156
+ var _a;
1153
1157
  const rules = normalizeValidationRules(type);
1154
1158
  const selfChecks = rules.map(rule => rxjs.defer(() => rule.validate(value, _objectSpread(_objectSpread({}, restOfContext), {}, {
1155
1159
  parent,
@@ -1196,7 +1200,7 @@ function validateItemObservable(_ref) {
1196
1200
  type: resolveTypeForArrayItem(item, type.of)
1197
1201
  }))));
1198
1202
  }
1199
- const shouldRunNestedValidationForMarkDefs = types.isBlock(value) && value.markDefs.length && types.isBlockSchemaType(type);
1203
+ const shouldRunNestedValidationForMarkDefs = types.isPortableTextTextBlock(value) && ((_a = value.markDefs) == null ? void 0 : _a.length) && types.isBlockSchemaType(type);
1200
1204
  if (shouldRunNestedValidationForMarkDefs) {
1201
1205
  const [spanChildrenField] = type.fields;
1202
1206
  const spanType = spanChildrenField.type.of.find(types.isSpanSchemaType);
@@ -1204,7 +1208,7 @@ function validateItemObservable(_ref) {
1204
1208
  acc.set(annotationType.name, annotationType);
1205
1209
  return acc;
1206
1210
  }, /* @__PURE__ */new Map());
1207
- nestedChecks = nestedChecks.concat(value.markDefs.map(markDef => validateItemObservable(_objectSpread(_objectSpread({}, restOfContext), {}, {
1211
+ nestedChecks = nestedChecks.concat((value.markDefs || []).map(markDef => validateItemObservable(_objectSpread(_objectSpread({}, restOfContext), {}, {
1208
1212
  parent: value,
1209
1213
  value: markDef,
1210
1214
  path: path.concat(["markDefs", {
@@ -1213,9 +1217,9 @@ function validateItemObservable(_ref) {
1213
1217
  type: annotations.get(markDef._type)
1214
1218
  }))));
1215
1219
  }
1216
- return rxjs.defer(() => rxjs.merge([...selfChecks, ...nestedChecks])).pipe(operators.mergeMap(validateNode => rxjs.concat(idle(), validateNode), 40), operators.mergeAll(), operators.toArray(), operators.map(lodash.flatten), operators.map(results => {
1220
+ return rxjs.defer(() => rxjs.merge([...selfChecks, ...nestedChecks])).pipe(operators.mergeMap(validateNode => rxjs.concat(idle(), validateNode), 40), operators.mergeAll(), operators.toArray(), operators.map(flatten__default["default"]), operators.map(results => {
1217
1221
  if (rules.some(rule => rule._fieldRules)) {
1218
- return lodash.uniqBy(results, rule => JSON.stringify(rule));
1222
+ return uniqBy__default["default"](results, rule => JSON.stringify(rule));
1219
1223
  }
1220
1224
  return results;
1221
1225
  }));