@sanity/schema 6.21.0-next.13 → 6.21.0-next.17

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,6 +1,6 @@
1
1
  import { a as SchemaValidationResult, i as ProblemPathTypeSegment, l as Schema$1, n as ProblemPathPropertySegment, o as TypeWithProblems, r as ProblemPathSegment, s as _FIXME_, t as ProblemPath } from "./typedefs-LNWlFyVi.js";
2
2
  import { SetSynchronization, SynchronizationRequest, SynchronizationResult } from "@sanity/descriptors";
3
- import { SanityDocumentLike, Schema, SchemaType, SchemaTypeDefinition, SchemaValidationProblem, SchemaValidationProblemGroup } from "@sanity/types";
3
+ import { CustomValidator, MediaValidator, SanityDocumentLike, Schema, SchemaType, SchemaTypeDefinition, SchemaValidationProblem, SchemaValidationProblemGroup } from "@sanity/types";
4
4
  import { RequestOptions } from "get-it";
5
5
  import { SchemaType as SchemaType$1 } from "groq-js";
6
6
  import { ComponentType, ReactNode } from "react";
@@ -192,6 +192,11 @@ export declare function prepareSchemaUpload(schema: Schema, options: PrepareSche
192
192
  */
193
193
  export declare function uploadSchema(schema: Schema, options: UploadSchemaOptions): Promise<string>;
194
194
  export declare const isActionEnabled: (schemaType: SchemaType, action: string) => boolean;
195
+ type ValidationCallback = CustomValidator | MediaValidator;
196
+ /** @internal */
197
+ export declare function markInternalValidator<T extends ValidationCallback>(validator: T): T;
198
+ /** @internal */
199
+ export declare function isInternalValidator(validator: unknown): boolean;
195
200
  export declare const DEFAULT_MAX_FIELD_DEPTH = 5;
196
201
  export declare function resolveSearchConfigForBaseFieldPaths(type: any, maxDepth?: number): any;
197
202
  /**
package/lib/_internal.js CHANGED
@@ -13,6 +13,15 @@ import get from "lodash-es/get.js";
13
13
  import humanizeList from "humanize-list";
14
14
  import leven from "leven";
15
15
  import { createReferenceTypeNode } from "groq-js";
16
+ const internalValidators = /* @__PURE__ */ new WeakSet();
17
+ /** @internal */
18
+ function markInternalValidator(validator) {
19
+ return internalValidators.add(validator), validator;
20
+ }
21
+ /** @internal */
22
+ function isInternalValidator(validator) {
23
+ return typeof validator == "function" && internalValidators.has(validator);
24
+ }
16
25
  const DEFAULT_IMAGE_FIELDS = [
17
26
  "asset",
18
27
  "hotspot",
@@ -380,9 +389,6 @@ function maybeValidations(obj) {
380
389
  scheme: ["http", "https"]
381
390
  });
382
391
  break;
383
- case "slug":
384
- impliedRules.push({ type: "custom" });
385
- break;
386
392
  case "reference":
387
393
  impliedRules.push({ type: "reference" });
388
394
  break;
@@ -525,7 +531,7 @@ function convertRuleSpec(spec, optional) {
525
531
  ...allowCredentials && { allowCredentials }
526
532
  };
527
533
  }
528
- case "custom": return {
534
+ case "custom": return isInternalValidator(constraint) ? void 0 : {
529
535
  type: "custom",
530
536
  ...optional && { optional }
531
537
  };
@@ -2443,7 +2449,7 @@ function transformValidation(validation) {
2443
2449
  rules: _rules.filter((rule) => {
2444
2450
  if (!("constraint" in rule)) return !1;
2445
2451
  let { flag, constraint } = rule;
2446
- return !disallowedFlags.includes(flag) && !(typeof constraint == "object" && "type" in constraint && disallowedConstraintTypes.includes(constraint.type));
2452
+ return flag === "custom" && isInternalValidator(constraint) || disallowedFlags.includes(flag) ? !1 : !(typeof constraint == "object" && "type" in constraint && disallowedConstraintTypes.includes(constraint.type));
2447
2453
  }).reduce((rules, rule) => {
2448
2454
  let transformedRule = (validationRuleTransformers[rule.flag] ?? ((spec) => retainSerializableProps(spec)))(rule);
2449
2455
  return transformedRule ? [...rules, transformedRule] : rules;
@@ -3098,6 +3104,6 @@ function validateMediaLibraryAssetAspect(maybeAspect) {
3098
3104
  }).getTypes()).map((group) => group.problems.filter(({ severity }) => severity === "error")).filter((problems) => problems.length);
3099
3105
  return [errors.length === 0, errors];
3100
3106
  }
3101
- export { ALL_FIELDS_GROUP_NAME, DEFAULT_MAX_FIELD_DEPTH, DescriptorConverter, ValidationError, builtinTypes, createSchemaFromManifestTypes, createStoredWorkspaceSchemaPayload, extractCreateWorkspaceManifest, extractManifestSchemaTypes, extractSchema, getWorkspaceSchemaId, groupProblems, isActionEnabled, parseWorkspaceSchemaId, prepareSchemaUpload, processSchemaSynchronization, resolveSearchConfig, resolveSearchConfigForBaseFieldPaths, uploadSchema, validForNamesChars, validForNamesPattern, validateMediaLibraryAssetAspect, validateSchema };
3107
+ export { ALL_FIELDS_GROUP_NAME, DEFAULT_MAX_FIELD_DEPTH, DescriptorConverter, ValidationError, builtinTypes, createSchemaFromManifestTypes, createStoredWorkspaceSchemaPayload, extractCreateWorkspaceManifest, extractManifestSchemaTypes, extractSchema, getWorkspaceSchemaId, groupProblems, isActionEnabled, isInternalValidator, markInternalValidator, parseWorkspaceSchemaId, prepareSchemaUpload, processSchemaSynchronization, resolveSearchConfig, resolveSearchConfigForBaseFieldPaths, uploadSchema, validForNamesChars, validForNamesPattern, validateMediaLibraryAssetAspect, validateSchema };
3102
3108
 
3103
3109
  //# sourceMappingURL=_internal.js.map