@sanity/validation 6.23.0 → 7.0.0-next-major.20261111083413

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/README.md CHANGED
@@ -24,7 +24,6 @@ if (!complete) {
24
24
  - `status` is deprecated; use `complete` and inspect marker levels and codes. It treats any marker as `failed`.
25
25
  - Built-in codes: `validationMarkerCodes`. Custom validators can return namespaced codes such as `custom.seo-title`.
26
26
  - Omit `client` for local checks without custom callbacks or network checks. Skipped checks make `complete` false. Use `customValidation: false` to skip custom callbacks while keeping network checks.
27
- - Pass `i18n: workspace.i18n` to `validateDocument`/`validateDocuments` to preserve the workspace's locale and translation resources, including those used by custom validators through `context.i18n`.
28
27
  - Precompiled rules retain their original package version's behavior; recompile with the current version for current callback-skipping and concurrency semantics.
29
28
 
30
29
  ## Batch validation
@@ -38,12 +37,6 @@ const results = await validateDocuments({documents, schema, client, maxFetchConc
38
37
 
39
38
  `maxFetchConcurrency` defaults to 25. One `signal` cancels the entire batch.
40
39
 
41
- ## Reference target types
42
-
43
- Reference targets are checked against the field's `to` types by default.
44
- Set `validateReferenceTypes: false` to disable these checks and their network reads.
45
- If a target's type cannot be checked, validation is marked incomplete.
46
-
47
40
  ## Cancellation
48
41
 
49
42
  ```ts
@@ -1,6 +1,5 @@
1
- import { E as LocaleSource, S as ValidationMarkerCode, T as ValidationScheduling, d as evaluateDocumentInternal, f as evaluateDocumentObservable, g as validateDocumentObservable, h as validateDocumentInternal, n as ValidateDocumentInternalOptions, p as resolveTypeForArrayItem, r as ValidateDocumentObservableOptions, s as ValidateItemOptions, w as ValidationContext, y as validateItem } from "./validateDocument-DESiHtPx.js";
1
+ import { E as LocaleSource, S as ValidationMarkerCode, T as ValidationScheduling, d as evaluateDocumentInternal, f as evaluateDocumentObservable, g as validateDocumentObservable, h as validateDocumentInternal, n as ValidateDocumentInternalOptions, p as resolveTypeForArrayItem, r as ValidateDocumentObservableOptions, s as ValidateItemOptions, w as ValidationContext, y as validateItem } from "./validateDocument-Bqq2KtlY.js";
2
2
  import { Path, Rule as Rule$1, RuleClass, Schema, SchemaType, SchemaValidationValue, ValidationContext as ValidationContext$1, ValidationError, ValidationMarker } from "@sanity/types";
3
- import { accepts } from "@sanity/util/accepts";
4
3
  export declare function getFallbackLocaleSource(): LocaleSource;
5
4
  export declare const validationLocaleStrings: {
6
5
  readonly 'array.exact-length': 'Must have exactly {{wantedLength}} items';
@@ -23,9 +22,6 @@ export declare const validationLocaleStrings: {
23
22
  readonly 'number.maximum-precision': 'Max precision is {{limit}}';
24
23
  readonly 'number.minimum': 'Must be greater than or equal to {{minNumber}}';
25
24
  readonly 'number.non-integer': 'Must be an integer';
26
- readonly 'object.asset-not-accepted': 'File type "{{mimeType}}" is not accepted';
27
- readonly 'object.asset-not-accepted_file': 'File type "{{mimeType}}" is not accepted';
28
- readonly 'object.asset-not-accepted_image': 'Image type "{{mimeType}}" is not accepted';
29
25
  readonly 'object.asset-required': 'Asset is required';
30
26
  readonly 'object.asset-required_file': 'File is required';
31
27
  readonly 'object.asset-required_image': 'Image is required';
@@ -33,7 +29,6 @@ export declare const validationLocaleStrings: {
33
29
  readonly 'object.not-media-library-asset': 'Must be a reference to a Media Library asset';
34
30
  readonly 'object.not-reference': 'Must be a reference to a document';
35
31
  readonly 'object.reference-not-published': 'Referenced document must be published';
36
- readonly 'object.reference-target-type-mismatch': 'Referenced document has type "{{actualType}}"; expected one of: {{allowedTypes}}';
37
32
  readonly 'slug.missing-current': 'Slug must have a value';
38
33
  readonly 'slug.not-object': 'Slug must be an object';
39
34
  readonly 'slug.not-unique': 'Slug is already in use';
@@ -97,5 +92,5 @@ export declare function getTypeChain(type: SchemaType | undefined, visited?: Set
97
92
  export declare function normalizeValidationRules(typeDef: SchemaType | undefined, context?: ValidationContext$1): Rule$1[];
98
93
  export declare function pathToString(path?: Path | undefined): string;
99
94
  export declare function typeString(obj: unknown): string;
100
- export { type LocaleSource, type ValidateDocumentInternalOptions, type ValidateDocumentObservableOptions, type ValidateItemOptions, type ValidationContext, type ValidationScheduling, accepts, evaluateDocumentInternal, evaluateDocumentObservable, resolveTypeForArrayItem, validateDocumentInternal, validateDocumentObservable, validateItem };
95
+ export { type LocaleSource, type ValidateDocumentInternalOptions, type ValidateDocumentObservableOptions, type ValidateItemOptions, type ValidationContext, type ValidationScheduling, evaluateDocumentInternal, evaluateDocumentObservable, resolveTypeForArrayItem, validateDocumentInternal, validateDocumentObservable, validateItem };
101
96
  //# sourceMappingURL=_internal.d.ts.map
package/lib/_internal.js CHANGED
@@ -1,5 +1,4 @@
1
- import { _ as pathToString, a as validateDocumentInternal, d as compileValidationRules, f as normalizeValidationRules, g as convertToValidationMarker, h as typeString, l as validateItem, m as getTypeChain, n as evaluateDocumentObservable, o as validateDocumentObservable, p as Rule, r as resolveTypeForArrayItem, t as evaluateDocumentInternal, v as getFallbackLocaleSource, y as validationLocaleStrings } from "./validateDocument-DZEYmQ4p.js";
2
- import { accepts } from "@sanity/util/accepts";
1
+ import { _ as pathToString, a as validateDocumentInternal, d as compileValidationRules, f as normalizeValidationRules, g as convertToValidationMarker, h as typeString, l as validateItem, m as getTypeChain, n as evaluateDocumentObservable, o as validateDocumentObservable, p as Rule, r as resolveTypeForArrayItem, t as evaluateDocumentInternal, v as getFallbackLocaleSource, y as validationLocaleStrings } from "./validateDocument-Dws_67d7.js";
3
2
  function inferFromSchemaType(typeDef) {
4
3
  return traverse(typeDef, /* @__PURE__ */ new Set()), typeDef;
5
4
  }
@@ -35,6 +34,6 @@ function inferFromSchema(schema) {
35
34
  schemaType && inferFromSchemaType(schemaType);
36
35
  }), schema;
37
36
  }
38
- export { Rule, accepts, convertToValidationMarker, evaluateDocumentInternal, evaluateDocumentObservable, getFallbackLocaleSource, getTypeChain, hasValidationContext, inferFromSchema, inferFromSchemaType, normalizeValidationRules, pathToString, resolveTypeForArrayItem, typeString, validateDocumentInternal, validateDocumentObservable, validateItem, validationLocaleStrings };
37
+ export { Rule, convertToValidationMarker, evaluateDocumentInternal, evaluateDocumentObservable, getFallbackLocaleSource, getTypeChain, hasValidationContext, inferFromSchema, inferFromSchemaType, normalizeValidationRules, pathToString, resolveTypeForArrayItem, typeString, validateDocumentInternal, validateDocumentObservable, validateItem, validationLocaleStrings };
39
38
 
40
39
  //# sourceMappingURL=_internal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_internal.js","names":[],"sources":["../src/inferFromSchemaType.ts","../src/inferFromSchema.ts"],"sourcesContent":["import {type Schema, type SchemaType, type SchemaValidationValue} from '@sanity/types'\n\nimport {compileValidationRules} from './util/normalizeValidationRules'\n\n// NOTE: this overload is for TS API compatibility with a previous implementation\nexport function inferFromSchemaType(\n typeDef: SchemaType,\n // these are intentionally unused\n _schema: Schema,\n _visited?: Set<SchemaType>,\n): SchemaType\n// note: this seemingly redundant overload is required\nexport function inferFromSchemaType(typeDef: SchemaType): SchemaType\nexport function inferFromSchemaType(typeDef: SchemaType): SchemaType {\n traverse(typeDef, new Set())\n return typeDef\n}\n\nfunction traverse(typeDef: SchemaType, visited: Set<SchemaType>) {\n if (visited.has(typeDef)) {\n return\n }\n\n visited.add(typeDef)\n\n const usesValidationContext = hasValidationContext(typeDef.validation)\n\n // Only normalize validation at schema-compile time when it doesn't rely on runtime context.\n // Context-aware validation functions must be evaluated during validation, where context exists.\n if (!usesValidationContext) {\n typeDef.validation = compileValidationRules(typeDef)\n }\n\n if ('fields' in typeDef) {\n for (const field of typeDef.fields) {\n traverse(field.type, visited)\n }\n }\n\n if ('of' in typeDef) {\n for (const candidate of typeDef.of) {\n traverse(candidate, visited)\n }\n }\n\n // @ts-expect-error TODO (eventually): `annotations` does not exist on the SchemaType yet\n if (typeDef.annotations) {\n // @ts-expect-error TODO (eventually): `annotations` does not exist on the SchemaType yet\n for (const annotation of typeDef.annotations) {\n traverse(annotation, visited)\n }\n }\n}\n\n/**\n * Checks if a validation function may use the context parameter.\n *\n * Functions with 2+ parameters like `(rule, context) => ...` need runtime context\n * (e.g., `context.hidden`, `context.document`) and cannot be pre-evaluated at schema compile time.\n *\n * Simple functions with only a rule parameter can be normalized immediately.\n * Unrecognized signatures are deferred because their arity may hide context usage.\n *\n * @internal\n */\nexport function hasValidationContext(validation: SchemaValidationValue | undefined): boolean {\n if (!validation) return false\n if (Array.isArray(validation)) {\n return validation.some(hasValidationContext)\n }\n if (typeof validation !== 'function') return false\n\n // Check declared parameter count first (most common case)\n if (validation.length >= 2) return true\n\n // Default and rest parameters do not contribute to Function.length. Only compile\n // recognizable zero/one-parameter signatures; wrappers and unknown forms stay at runtime.\n const signature = Function.prototype.toString.call(validation)\n if (/\\barguments\\b|\\[native code\\]/.test(signature)) return true\n\n const simpleArrow = /^\\s*(?:[\\w$]+|\\(\\s*(?:[\\w$]+\\s*)?\\))\\s*=>/\n const simpleFunction = /^\\s*(?:function(?:\\s+[\\w$]+)?|[\\w$]+)\\s*\\(\\s*(?:[\\w$]+\\s*)?\\)\\s*\\{/\n return !simpleArrow.test(signature) && !simpleFunction.test(signature)\n}\n","import {type Schema} from '@sanity/types'\n\nimport {inferFromSchemaType} from './inferFromSchemaType'\n\n// Note: Mutates schema. Refactor when @sanity/schema supports middlewares\nexport function inferFromSchema(schema: Schema): Schema {\n const typeNames = schema.getLocalTypeNames()\n\n typeNames.forEach((typeName) => {\n const schemaType = schema.get(typeName)\n\n if (schemaType) {\n inferFromSchemaType(schemaType)\n }\n })\n\n return schema\n}\n"],"mappings":";;AAaA,SAAgB,oBAAoB,SAAiC;CAEnE,OADA,SAAS,yBAAS,IAAI,IAAI,CAAC,GACpB;AACT;AAEA,SAAS,SAAS,SAAqB,SAA0B;CAC/D,IAAI,SAAQ,IAAI,OAAO,GAIvB;EAUA,IAVA,QAAQ,IAAI,OAAO,GAEW,qBAAqB,QAAQ,UAIlC,MACvB,QAAQ,aAAa,uBAAuB,OAAO,IAGjD,YAAY,SACd,KAAK,IAAM,SAAS,QAAQ,QAC1B,SAAS,MAAM,MAAM,OAAO;EAIhC,IAAI,QAAQ,SACV,KAAK,IAAM,aAAa,QAAQ,IAC9B,SAAS,WAAW,OAAO;EAK/B,IAAI,QAAQ,aAEV,KAAK,IAAM,cAAc,QAAQ,aAC/B,SAAS,YAAY,OAAO;CA1Bb;AA6BrB;;;;;;;;;;;;AAaA,SAAgB,qBAAqB,YAAwD;CAC3F,IAAI,CAAC,YAAY,OAAO;CACxB,IAAI,MAAM,QAAQ,UAAU,GAC1B,OAAO,WAAW,KAAK,oBAAoB;CAE7C,IAAI,OAAO,cAAe,YAAY,OAAO;CAG7C,IAAI,WAAW,UAAU,GAAG,OAAO;CAInC,IAAM,YAAY,SAAS,UAAU,SAAS,KAAK,UAAU;CAK7D,OAJI,gCAAgC,KAAK,SAAS,IAAU,KAIrD,CAAC,4CAAY,KAAK,SAAS,KAAK,CAAC,qEAAe,KAAK,SAAS;AACvE;AC9EA,SAAgB,gBAAgB,QAAwB;CAWtD,OARA,OAFyB,kBAEjB,CAAC,CAAC,SAAS,aAAa;EAC9B,IAAM,aAAa,OAAO,IAAI,QAAQ;EAEtC,AAAI,cACF,oBAAoB,UAAU;CAElC,CAAC,GAEM;AACT"}
1
+ {"version":3,"file":"_internal.js","names":[],"sources":["../src/inferFromSchemaType.ts","../src/inferFromSchema.ts"],"sourcesContent":["import {type Schema, type SchemaType, type SchemaValidationValue} from '@sanity/types'\n\nimport {compileValidationRules} from './util/normalizeValidationRules'\n\n// NOTE: this overload is for TS API compatibility with a previous implementation\nexport function inferFromSchemaType(\n typeDef: SchemaType,\n // these are intentionally unused\n _schema: Schema,\n _visited?: Set<SchemaType>,\n): SchemaType\n// note: this seemingly redundant overload is required\nexport function inferFromSchemaType(typeDef: SchemaType): SchemaType\nexport function inferFromSchemaType(typeDef: SchemaType): SchemaType {\n traverse(typeDef, new Set())\n return typeDef\n}\n\nfunction traverse(typeDef: SchemaType, visited: Set<SchemaType>) {\n if (visited.has(typeDef)) {\n return\n }\n\n visited.add(typeDef)\n\n const usesValidationContext = hasValidationContext(typeDef.validation)\n\n // Only normalize validation at schema-compile time when it doesn't rely on runtime context.\n // Context-aware validation functions must be evaluated during validation, where context exists.\n if (!usesValidationContext) {\n typeDef.validation = compileValidationRules(typeDef)\n }\n\n if ('fields' in typeDef) {\n for (const field of typeDef.fields) {\n traverse(field.type, visited)\n }\n }\n\n if ('of' in typeDef) {\n for (const candidate of typeDef.of) {\n traverse(candidate, visited)\n }\n }\n\n // @ts-expect-error TODO (eventually): `annotations` does not exist on the SchemaType yet\n if (typeDef.annotations) {\n // @ts-expect-error TODO (eventually): `annotations` does not exist on the SchemaType yet\n for (const annotation of typeDef.annotations) {\n traverse(annotation, visited)\n }\n }\n}\n\n/**\n * Checks if a validation function may use the context parameter.\n *\n * Functions with 2+ parameters like `(rule, context) => ...` need runtime context\n * (e.g., `context.hidden`, `context.document`) and cannot be pre-evaluated at schema compile time.\n *\n * Simple functions with only a rule parameter can be normalized immediately.\n * Unrecognized signatures are deferred because their arity may hide context usage.\n *\n * @internal\n */\nexport function hasValidationContext(validation: SchemaValidationValue | undefined): boolean {\n if (!validation) return false\n if (Array.isArray(validation)) {\n return validation.some(hasValidationContext)\n }\n if (typeof validation !== 'function') return false\n\n // Check declared parameter count first (most common case)\n if (validation.length >= 2) return true\n\n // Default and rest parameters do not contribute to Function.length. Only compile\n // recognizable zero/one-parameter signatures; wrappers and unknown forms stay at runtime.\n const signature = Function.prototype.toString.call(validation)\n if (/\\barguments\\b|\\[native code\\]/.test(signature)) return true\n\n const simpleArrow = /^\\s*(?:[\\w$]+|\\(\\s*(?:[\\w$]+\\s*)?\\))\\s*=>/\n const simpleFunction = /^\\s*(?:function(?:\\s+[\\w$]+)?|[\\w$]+)\\s*\\(\\s*(?:[\\w$]+\\s*)?\\)\\s*\\{/\n return !simpleArrow.test(signature) && !simpleFunction.test(signature)\n}\n","import {type Schema} from '@sanity/types'\n\nimport {inferFromSchemaType} from './inferFromSchemaType'\n\n// Note: Mutates schema. Refactor when @sanity/schema supports middlewares\nexport function inferFromSchema(schema: Schema): Schema {\n const typeNames = schema.getLocalTypeNames()\n\n typeNames.forEach((typeName) => {\n const schemaType = schema.get(typeName)\n\n if (schemaType) {\n inferFromSchemaType(schemaType)\n }\n })\n\n return schema\n}\n"],"mappings":";AAaA,SAAgB,oBAAoB,SAAiC;CAEnE,OADA,SAAS,yBAAS,IAAI,IAAI,CAAC,GACpB;AACT;AAEA,SAAS,SAAS,SAAqB,SAA0B;CAC/D,IAAI,SAAQ,IAAI,OAAO,GAIvB;EAUA,IAVA,QAAQ,IAAI,OAAO,GAEW,qBAAqB,QAAQ,UAIlC,MACvB,QAAQ,aAAa,uBAAuB,OAAO,IAGjD,YAAY,SACd,KAAK,IAAM,SAAS,QAAQ,QAC1B,SAAS,MAAM,MAAM,OAAO;EAIhC,IAAI,QAAQ,SACV,KAAK,IAAM,aAAa,QAAQ,IAC9B,SAAS,WAAW,OAAO;EAK/B,IAAI,QAAQ,aAEV,KAAK,IAAM,cAAc,QAAQ,aAC/B,SAAS,YAAY,OAAO;CA1Bb;AA6BrB;;;;;;;;;;;;AAaA,SAAgB,qBAAqB,YAAwD;CAC3F,IAAI,CAAC,YAAY,OAAO;CACxB,IAAI,MAAM,QAAQ,UAAU,GAC1B,OAAO,WAAW,KAAK,oBAAoB;CAE7C,IAAI,OAAO,cAAe,YAAY,OAAO;CAG7C,IAAI,WAAW,UAAU,GAAG,OAAO;CAInC,IAAM,YAAY,SAAS,UAAU,SAAS,KAAK,UAAU;CAK7D,OAJI,gCAAgC,KAAK,SAAS,IAAU,KAIrD,CAAC,4CAAY,KAAK,SAAS,KAAK,CAAC,qEAAe,KAAK,SAAS;AACvE;AC9EA,SAAgB,gBAAgB,QAAwB;CAWtD,OARA,OAFyB,kBAEjB,CAAC,CAAC,SAAS,aAAa;EAC9B,IAAM,aAAa,OAAO,IAAI,QAAQ;EAEtC,AAAI,cACF,oBAAoB,UAAU;CAElC,CAAC,GAEM;AACT"}
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as validationMarkerCodes, D as ValidationLocaleSource, S as ValidationMarkerCode, _ as validateDocumentWithWorkspace, a as ValidateDocumentWorkspaceOptions, b as BuiltInValidationMarkerCode, c as ValidationClient, i as ValidateDocumentOptions, l as ValidationSchema, m as validateDocument, o as ValidateDocumentsOptions, t as DocumentValidationResult, u as ValidationSource, v as validateDocuments, x as DocumentValidationMarker } from "./validateDocument-DESiHtPx.js";
1
+ import { C as validationMarkerCodes, S as ValidationMarkerCode, _ as validateDocumentWithWorkspace, a as ValidateDocumentWorkspaceOptions, b as BuiltInValidationMarkerCode, c as ValidationClient, i as ValidateDocumentOptions, l as ValidationSchema, m as validateDocument, o as ValidateDocumentsOptions, t as DocumentValidationResult, u as ValidationSource, v as validateDocuments, x as DocumentValidationMarker } from "./validateDocument-Bqq2KtlY.js";
2
2
  import { SanityDocument } from "@sanity/types";
3
3
  type DocumentCheck = (options: {
4
4
  id: string;
@@ -21,5 +21,5 @@ interface ReleaseReferenceOptions {
21
21
  * @beta
22
22
  */
23
23
  export declare function withReleaseReferences({ document, getDocumentExists, isUnpublished }: ReleaseReferenceOptions): DocumentCheck;
24
- export { type BuiltInValidationMarkerCode, type DocumentValidationMarker, type DocumentValidationResult, type ReleaseReferenceOptions, type ValidateDocumentOptions, type ValidateDocumentWorkspaceOptions, type ValidateDocumentsOptions, type ValidationClient, type ValidationLocaleSource, type ValidationMarkerCode, type ValidationSchema, type ValidationSource, validateDocument, validateDocumentWithWorkspace, validateDocuments, validationMarkerCodes };
24
+ export { type BuiltInValidationMarkerCode, type DocumentValidationMarker, type DocumentValidationResult, type ReleaseReferenceOptions, type ValidateDocumentOptions, type ValidateDocumentWorkspaceOptions, type ValidateDocumentsOptions, type ValidationClient, type ValidationMarkerCode, type ValidationSchema, type ValidationSource, validateDocument, validateDocumentWithWorkspace, validateDocuments, validationMarkerCodes };
25
25
  //# sourceMappingURL=index.d.ts.map
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- export { i as validateDocument, s as validateDocumentWithWorkspace, c as validateDocuments, b as validationMarkerCodes, u as withReleaseReferences } from "./validateDocument-DZEYmQ4p.js";
1
+ export { i as validateDocument, s as validateDocumentWithWorkspace, c as validateDocuments, b as validationMarkerCodes, u as withReleaseReferences } from "./validateDocument-Dws_67d7.js";
@@ -3,22 +3,11 @@ import { ConcurrencyLimiter } from "@sanity/util/concurrency-limiter";
3
3
  import { BehaviorSubject, Observable } from "rxjs";
4
4
  import { TFunction } from "i18next";
5
5
  import { SanityClient } from "@sanity/client";
6
- /**
7
- * Translation utilities accepted across compatible Studio and i18next versions.
8
- *
9
- * @beta
10
- */
11
- interface ValidationLocaleSource {
12
- /** The locale used for localized validation messages. */
6
+ interface LocaleSource {
13
7
  currentLocale: {
14
8
  id: string;
15
9
  };
16
- /** Loads translation resources needed by built-in or custom validators. */
17
10
  loadNamespaces(namespaces: string[]): Promise<void>;
18
- /** Translates a key with optional interpolation and formatting options. */
19
- t: (key: string, options?: Record<string, unknown>) => string;
20
- }
21
- interface LocaleSource extends ValidationLocaleSource {
22
11
  t: TFunction;
23
12
  }
24
13
  /**
@@ -67,7 +56,6 @@ declare module '@sanity/types' {
67
56
  }
68
57
  interface InternalValidationContext extends ValidationContext {
69
58
  __internal?: {
70
- getDocumentType?: (id: string) => Promise<string | undefined>;
71
59
  customValidation?: boolean;
72
60
  customValidationConcurrencyLimiter?: {
73
61
  ready: (signal?: AbortSignal) => Promise<void>;
@@ -85,7 +73,6 @@ declare const validationMarkerCodes: {
85
73
  readonly arrayExactLength: 'array.exact-length';
86
74
  readonly arrayMaximumLength: 'array.maximum-length';
87
75
  readonly arrayMinimumLength: 'array.minimum-length';
88
- readonly assetNotAccepted: 'asset.not-accepted';
89
76
  readonly assetRequired: 'asset.required';
90
77
  readonly custom: 'custom';
91
78
  readonly dateInvalidFormat: 'date.invalid-format';
@@ -104,7 +91,6 @@ declare const validationMarkerCodes: {
104
91
  readonly objectUnknownField: 'object.unknown-field';
105
92
  readonly referenceInvalid: 'reference.invalid';
106
93
  readonly referenceNotPublished: 'reference.not-published';
107
- readonly referenceTargetTypeMismatch: 'reference.target-type-mismatch';
108
94
  readonly ruleAllFailed: 'rule.all-failed';
109
95
  readonly ruleEitherFailed: 'rule.either-failed';
110
96
  readonly slugInvalidType: 'slug.invalid-type';
@@ -152,12 +138,6 @@ interface ValidateDocumentBaseOptions {
152
138
  document: SanityDocument;
153
139
  /** The compiled schema to validate against. */
154
140
  schema: ValidationSchema;
155
- /**
156
- * Translation resources and locale used by built-in and custom validators.
157
- * Pass a resolved workspace's `i18n` to preserve its translations.
158
- * Defaults to the built-in English resources when omitted.
159
- */
160
- i18n?: ValidationLocaleSource;
161
141
  /** Signal used to cancel validation and any work it starts. */
162
142
  signal?: AbortSignal;
163
143
  /**
@@ -173,14 +153,6 @@ interface ValidateDocumentBaseOptions {
173
153
  id: string;
174
154
  signal?: AbortSignal;
175
155
  }) => Promise<boolean>;
176
- /**
177
- * Check referenced document types against the reference field's `to` types.
178
- * Defaults to `true` (`false` in Studio's `validateDocument`).
179
- * Uses batched network reads, including for weak references.
180
- * Without a client, checks that need a target lookup make validation incomplete.
181
- * Set to `false` to perform only the existing reference shape and existence checks.
182
- */
183
- validateReferenceTypes?: boolean;
184
156
  /**
185
157
  * The maximum amount of custom validation functions to be running
186
158
  * concurrently at once. This helps prevent custom validators from
@@ -290,7 +262,7 @@ interface ValidationSource {
290
262
  *
291
263
  * @beta
292
264
  */
293
- interface ValidateDocumentWorkspaceOptions extends Omit<ValidateDocumentBaseOptions, 'schema' | 'i18n'> {
265
+ interface ValidateDocumentWorkspaceOptions extends Omit<ValidateDocumentBaseOptions, 'schema'> {
294
266
  /** The resolved Studio workspace or source used for validation. */
295
267
  workspace: ValidationSource;
296
268
  /**
@@ -310,7 +282,7 @@ interface ValidateDocumentWorkspaceOptions extends Omit<ValidateDocumentBaseOpti
310
282
  * @beta
311
283
  * @deprecated Prefer {@link validateDocument} with `{document, schema, client}` for new code.
312
284
  */
313
- declare function validateDocumentWithWorkspace({ document, workspace, getClient, getDocumentExists, environment, maxCustomValidationConcurrency, maxFetchConcurrency, currentUser, customValidation, signal, validateReferenceTypes }: ValidateDocumentWorkspaceOptions): Promise<DocumentValidationMarker[]>;
285
+ declare function validateDocumentWithWorkspace({ document, workspace, getClient, getDocumentExists, environment, maxCustomValidationConcurrency, maxFetchConcurrency, currentUser, customValidation, signal }: ValidateDocumentWorkspaceOptions): Promise<DocumentValidationMarker[]>;
314
286
  /**
315
287
  * Validates a document against a compiled schema. Returns failures and whether
316
288
  * validation completed
@@ -338,7 +310,6 @@ interface ValidateDocumentInternalOptions {
338
310
  id: string;
339
311
  signal?: AbortSignal;
340
312
  }) => Promise<boolean>;
341
- validateReferenceTypes?: boolean;
342
313
  i18n?: LocaleSource;
343
314
  environment: 'cli' | 'studio';
344
315
  maxCustomValidationConcurrency?: number;
@@ -355,8 +326,6 @@ declare function evaluateDocumentInternal(options: ValidateDocumentInternalOptio
355
326
  * @internal
356
327
  */
357
328
  interface ValidateDocumentObservableOptions extends Pick<ValidationContext$1, 'getDocumentExists' | 'i18n' | 'signal' | 'currentUser'> {
358
- /** Lookup for resolved target types. Omit to disable type checks. */
359
- getDocumentType?: (id: string) => Promise<string | undefined>;
360
329
  getClient: (options: {
361
330
  apiVersion: string;
362
331
  }) => SanityClient;
@@ -400,5 +369,5 @@ type ValidateItemOptions = {
400
369
  __internal?: InternalValidationContext['__internal'];
401
370
  } & Pick<ValidationContext$1, 'currentUser'> & ExplicitUndefined<Omit<ValidationContext$1, 'hidden' | 'signal' | 'currentUser'>>;
402
371
  declare function validateItem(opts: ValidateItemOptions): Promise<ValidationMarker[]>;
403
- export { validationMarkerCodes as C, ValidationLocaleSource as D, LocaleSource as E, ValidationMarkerCode as S, ValidationScheduling as T, validateDocumentWithWorkspace as _, ValidateDocumentWorkspaceOptions as a, BuiltInValidationMarkerCode as b, ValidationClient as c, evaluateDocumentInternal as d, evaluateDocumentObservable as f, validateDocumentObservable as g, validateDocumentInternal as h, ValidateDocumentOptions as i, ValidationSchema as l, validateDocument as m, ValidateDocumentInternalOptions as n, ValidateDocumentsOptions as o, resolveTypeForArrayItem as p, ValidateDocumentObservableOptions as r, ValidateItemOptions as s, DocumentValidationResult as t, ValidationSource as u, validateDocuments as v, ValidationContext$1 as w, DocumentValidationMarker as x, validateItem as y };
404
- //# sourceMappingURL=validateDocument-DESiHtPx.d.ts.map
372
+ export { validationMarkerCodes as C, LocaleSource as E, ValidationMarkerCode as S, ValidationScheduling as T, validateDocumentWithWorkspace as _, ValidateDocumentWorkspaceOptions as a, BuiltInValidationMarkerCode as b, ValidationClient as c, evaluateDocumentInternal as d, evaluateDocumentObservable as f, validateDocumentObservable as g, validateDocumentInternal as h, ValidateDocumentOptions as i, ValidationSchema as l, validateDocument as m, ValidateDocumentInternalOptions as n, ValidateDocumentsOptions as o, resolveTypeForArrayItem as p, ValidateDocumentObservableOptions as r, ValidateItemOptions as s, DocumentValidationResult as t, ValidationSource as u, validateDocuments as v, ValidationContext$1 as w, DocumentValidationMarker as x, validateItem as y };
373
+ //# sourceMappingURL=validateDocument-Bqq2KtlY.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { isInternalValidator, markInternalValidator } from "@sanity/schema/_internal";
2
- import { isArrayOfBlocksSchemaType, isArrayOfObjectsSchemaType, isKeyedObject, isReference, isReferenceSchemaType, isSlug, isTypedObject } from "@sanity/types";
2
+ import { isArrayOfBlocksSchemaType, isArrayOfObjectsSchemaType, isKeyedObject, isReference, isSlug, isTypedObject } from "@sanity/types";
3
3
  import { createClientConcurrencyLimiter } from "@sanity/util/client";
4
4
  import { ConcurrencyLimiter } from "@sanity/util/concurrency-limiter";
5
5
  import { dequal } from "dequal/lite";
@@ -13,14 +13,12 @@ import isPlainObject from "lodash-es/isPlainObject.js";
13
13
  import * as legacyDateFormat from "@sanity/util/legacyDateFormat";
14
14
  import { getPublishedId, getVersionId, getVersionNameFromId, isVersionId } from "@sanity/id-utils";
15
15
  import memoize from "lodash-es/memoize.js";
16
- import { accepts } from "@sanity/util/accepts";
17
16
  /** Machine-readable codes emitted by built-in document validation. @beta */
18
17
  const validationMarkerCodes = {
19
18
  arrayDuplicateItem: "array.duplicate-item",
20
19
  arrayExactLength: "array.exact-length",
21
20
  arrayMaximumLength: "array.maximum-length",
22
21
  arrayMinimumLength: "array.minimum-length",
23
- assetNotAccepted: "asset.not-accepted",
24
22
  assetRequired: "asset.required",
25
23
  custom: "custom",
26
24
  dateInvalidFormat: "date.invalid-format",
@@ -39,7 +37,6 @@ const validationMarkerCodes = {
39
37
  objectUnknownField: "object.unknown-field",
40
38
  referenceInvalid: "reference.invalid",
41
39
  referenceNotPublished: "reference.not-published",
42
- referenceTargetTypeMismatch: "reference.target-type-mismatch",
43
40
  ruleAllFailed: "rule.all-failed",
44
41
  ruleEitherFailed: "rule.either-failed",
45
42
  slugInvalidType: "slug.invalid-type",
@@ -91,9 +88,6 @@ const validationLocaleStrings = {
91
88
  "number.maximum-precision": "Max precision is {{limit}}",
92
89
  "number.minimum": "Must be greater than or equal to {{minNumber}}",
93
90
  "number.non-integer": "Must be an integer",
94
- "object.asset-not-accepted": "File type \"{{mimeType}}\" is not accepted",
95
- "object.asset-not-accepted_file": "File type \"{{mimeType}}\" is not accepted",
96
- "object.asset-not-accepted_image": "Image type \"{{mimeType}}\" is not accepted",
97
91
  "object.asset-required": "Asset is required",
98
92
  "object.asset-required_file": "File is required",
99
93
  "object.asset-required_image": "Image is required",
@@ -101,7 +95,6 @@ const validationLocaleStrings = {
101
95
  "object.not-media-library-asset": "Must be a reference to a Media Library asset",
102
96
  "object.not-reference": "Must be a reference to a document",
103
97
  "object.reference-not-published": "Referenced document must be published",
104
- "object.reference-target-type-mismatch": "Referenced document has type \"{{actualType}}\"; expected one of: {{allowedTypes}}",
105
98
  "slug.missing-current": "Slug must have a value",
106
99
  "slug.not-object": "Slug must be an object",
107
100
  "slug.not-unique": "Slug is already in use",
@@ -221,39 +214,6 @@ function createBatchedGetDocumentExists(client, defaultSignal) {
221
214
  });
222
215
  };
223
216
  }
224
- /** Batches metadata reads and shares each target's result for one validation run. */
225
- function createBatchedGetDocumentType(getClient, signal) {
226
- let cache = /* @__PURE__ */ new Map(), pending = /* @__PURE__ */ new Map(), timer;
227
- async function flush() {
228
- clearTimeout(timer), timer = void 0;
229
- let batch = pending;
230
- pending = /* @__PURE__ */ new Map();
231
- try {
232
- signal?.throwIfAborted();
233
- let documents = await getClient().fetch("*[_id in $ids]{_id, _type}", { ids: [...batch.keys()] }, {
234
- perspective: "raw",
235
- useCdn: !1,
236
- signal,
237
- tag: "validation.reference-types"
238
- }), types = new Map(documents.map((document) => [document._id, document._type]));
239
- for (let [id, check] of batch) check.resolve(types.get(id));
240
- } catch (error) {
241
- for (let check of batch.values()) check.reject(error);
242
- }
243
- }
244
- return (id) => {
245
- if (signal?.aborted) return Promise.reject(signal.reason);
246
- let cached = cache.get(id);
247
- if (cached) return cached;
248
- let result = new Promise((resolve, reject) => {
249
- pending.set(id, {
250
- resolve,
251
- reject
252
- });
253
- });
254
- return cache.set(id, result), pending.size >= 100 ? flush() : timer ??= setTimeout(() => void flush(), 0), result;
255
- };
256
- }
257
217
  function pathToString(path = []) {
258
218
  return path.reduce((target, segment, i) => {
259
219
  let segmentType = typeof segment;
@@ -669,36 +629,17 @@ const dateValidators = {
669
629
  message: message || i18n.t("validation:object.not-reference")
670
630
  };
671
631
  if (!type) throw Error("`type` was not provided in validation context");
672
- let getDocumentType = context.__internal?.getDocumentType, weak = "weak" in type && type.weak;
673
- if (weak && !getDocumentType) return !0;
632
+ if ("weak" in type && type.weak) return !0;
674
633
  if (!getDocumentExists) throw Error("`getDocumentExists` was not provided in validation context");
675
- let selfReference = document?._id && value._ref === getPublishedId(document._id), exists = selfReference || await getDocumentExists({
634
+ let documentId = document?._id;
635
+ return documentId && value._ref == getPublishedId(documentId) || await getDocumentExists({
676
636
  id: value._ref,
677
637
  signal: context.signal
678
- });
679
- if (!exists && !weak) return {
638
+ }) ? !0 : {
680
639
  code: validationMarkerCodes.referenceNotPublished,
681
640
  details: { referenceId: value._ref },
682
641
  message: i18n.t("validation:object.reference-not-published", { documentId: value._ref })
683
642
  };
684
- if (exists && getDocumentType && isReferenceSchemaType(type)) {
685
- let actualType = selfReference ? document?._type : await getDocumentType(value._ref);
686
- if (!actualType) throw Error(`Could not read the type of referenced document "${value._ref}"`);
687
- let allowedTypes = type.to.map((target) => target.name);
688
- if (!allowedTypes.includes(actualType)) return {
689
- code: validationMarkerCodes.referenceTargetTypeMismatch,
690
- details: {
691
- referenceId: value._ref,
692
- actualType,
693
- allowedTypes
694
- },
695
- message: i18n.t("validation:object.reference-target-type-mismatch", {
696
- actualType,
697
- allowedTypes: allowedTypes.join(", ")
698
- })
699
- };
700
- }
701
- return !0;
702
643
  },
703
644
  assetRequired: (flag, value, message, { i18n }) => !value || !value.asset || !value.asset._ref ? {
704
645
  __internal_metadata: { name: "assetRequired" },
@@ -949,7 +890,7 @@ const slugUniquenessValidator = (value, context) => {
949
890
  }
950
891
  let message = isLocalizedMessages(this._message) ? localizeMessage(this._message, context.i18n) : this._message;
951
892
  try {
952
- let validatorContext = curr.flag === "reference" || curr.flag === "all" || curr.flag === "either" ? {
893
+ let validatorContext = curr.flag === "all" || curr.flag === "either" ? {
953
894
  ...context,
954
895
  __internal
955
896
  } : context;
@@ -964,61 +905,7 @@ const slugUniquenessValidator = (value, context) => {
964
905
  }
965
906
  }))).flat();
966
907
  }
967
- }, resolvedFileTypes = /* @__PURE__ */ new Map();
968
- function isUnknownFileType(fileType) {
969
- return [fileType.mimeType, fileType.extension].every((value) => (value ?? "") === "");
970
- }
971
- /**
972
- * Checks a stored asset against an HTML `accept` string with the same matcher uploads and
973
- * copy-paste use.
974
- *
975
- * @internal
976
- */
977
- function assetMatchesAccept(fileType, accept) {
978
- return accepts({
979
- type: fileType.mimeType ?? "",
980
- name: getAssetFilename(fileType)
981
- }, accept);
982
- }
983
- function getAssetFilename(fileType) {
984
- return fileType.originalFilename ? fileType.originalFilename : fileType.extension ? `asset.${fileType.extension}` : void 0;
985
- }
986
- function getAssetId(value) {
987
- if (typeof value == "object" && value && "asset" in value) {
988
- let { asset } = value;
989
- if (typeof asset == "object" && asset && "_ref" in asset) return typeof asset._ref == "string" ? asset._ref : void 0;
990
- }
991
- }
992
- async function fetchAssetFileType(assetId, context) {
993
- let cached = resolvedFileTypes.get(assetId);
994
- if (cached) return cached;
995
- let fileType = await context.getClient({ apiVersion: "2025-02-19" }).fetch("*[_id == $id][0]{mimeType, extension, originalFilename}", { id: assetId }, {
996
- signal: context.signal,
997
- tag: "validation.asset-accept"
998
- });
999
- return fileType && resolvedFileTypes.set(assetId, fileType), fileType;
1000
- }
1001
- /** @internal */
1002
- function createAssetAcceptValidator(accept, assetType) {
1003
- return async (value, context) => {
1004
- let assetId = getAssetId(value);
1005
- if (assetId === void 0) return !0;
1006
- let fileType = await fetchAssetFileType(assetId, context);
1007
- return fileType === null || isUnknownFileType(fileType) || assetMatchesAccept(fileType, accept) ? !0 : {
1008
- code: validationMarkerCodes.assetNotAccepted,
1009
- details: {
1010
- accept,
1011
- mimeType: fileType.mimeType,
1012
- extension: fileType.extension
1013
- },
1014
- message: context.i18n.t("validation:object.asset-not-accepted", {
1015
- context: assetType,
1016
- mimeType: fileType.mimeType ?? fileType.extension
1017
- })
1018
- };
1019
- };
1020
- }
1021
- const ruleConstraintTypes = {
908
+ }, ruleConstraintTypes = {
1022
909
  array: !0,
1023
910
  boolean: !0,
1024
911
  date: !0,
@@ -1056,35 +943,17 @@ function omitLeakedDefaultUri(rules, typeDef) {
1056
943
  function normalizeValidationRules(typeDef, context) {
1057
944
  if (!typeDef) return [];
1058
945
  let compiled = Array.isArray(typeDef.validation) ? compiledValidations.get(typeDef.validation) : void 0;
1059
- return compiled ? compiled.type === typeDef ? compiled.rules : normalizeValidationRules({
1060
- ...typeDef,
1061
- validation: compiled.definition
1062
- }, context) : [...normalizeAuthoredRules(typeDef, context), ...inferAssetAcceptRules(typeDef)];
1063
- }
1064
- function isAcceptedAssetType(name) {
1065
- return name === "image" || name === "file";
1066
- }
1067
- function getAcceptOption(typeDef) {
1068
- let options = typeDef.options;
1069
- return options && typeof options == "object" && "accept" in options && typeof options.accept == "string" ? options.accept.trim() : "";
1070
- }
1071
- function inferAssetAcceptRules(typeDef) {
1072
- let accept = getAcceptOption(typeDef), assetType = getTypeChain(typeDef).map((type) => type.name).find(isAcceptedAssetType);
1073
- return accept && assetType ? [new Rule$2(typeDef).custom(markInternalValidator(createAssetAcceptValidator(accept, assetType)), { bypassConcurrencyLimit: !0 }).warning()] : [];
1074
- }
1075
- function normalizeAuthoredRules(typeDef, context) {
1076
- let compiled = Array.isArray(typeDef.validation) ? compiledValidations.get(typeDef.validation) : void 0;
1077
- if (compiled) return normalizeAuthoredRules({
946
+ if (compiled) return compiled.type === typeDef ? compiled.rules : normalizeValidationRules({
1078
947
  ...typeDef,
1079
948
  validation: compiled.definition
1080
949
  }, context);
1081
950
  let validation = typeDef.validation;
1082
- if (Array.isArray(validation)) return omitLeakedDefaultUri(validation.flatMap((i) => normalizeAuthoredRules({
951
+ if (Array.isArray(validation)) return omitLeakedDefaultUri(validation.flatMap((i) => normalizeValidationRules({
1083
952
  ...typeDef,
1084
953
  validation: i
1085
954
  }, context)), typeDef);
1086
955
  let initialRule = new Rule$2(typeDef), baseRule = Object.values(getTypeChain(typeDef).reduce((acc, type) => (acc[type.name] = type, acc), {})).reduce(baseRuleReducer, isRuleConstraint(typeDef.jsonType) ? initialRule.type(typeDef.jsonType) : initialRule), options = typeDef.options, list = options && typeof options == "object" && "list" in options ? options.list : void 0;
1087
- return Array.isArray(list) && (baseRule = baseRule.valid(list.map((option) => extractValueFromListOption(option, typeDef)))), validation && typeof validation == "object" ? [validation] : validation && typeof validation == "function" ? normalizeAuthoredRules({
956
+ return Array.isArray(list) && (baseRule = baseRule.valid(list.map((option) => extractValueFromListOption(option, typeDef)))), validation && typeof validation == "object" ? [validation] : validation && typeof validation == "function" ? normalizeValidationRules({
1088
957
  ...typeDef,
1089
958
  validation: validation(baseRule, context)
1090
959
  }, context) : [baseRule];
@@ -1213,17 +1082,8 @@ function createPace(scheduling) {
1213
1082
  * @beta
1214
1083
  */
1215
1084
  function withReleaseReferences({ document, getDocumentExists, isUnpublished }) {
1216
- let resolveReference = createReferenceResolver({
1217
- document,
1218
- getDocumentExists,
1219
- isUnpublished
1220
- });
1221
- return async (options) => await resolveReference(options) !== void 0;
1222
- }
1223
- /** Resolve the exact published or release document ID used by reference validation. */
1224
- function createReferenceResolver({ document, getDocumentExists, isUnpublished }) {
1225
1085
  let id = document._id, variant = document._system?.variants?.[0]?._ref ?? document._system?.variant?._ref;
1226
- if (!isVersionId(id) || variant) return async (options) => await getDocumentExists(options) ? options.id : void 0;
1086
+ if (!isVersionId(id) || variant) return getDocumentExists;
1227
1087
  let versionName = getVersionNameFromId(id);
1228
1088
  return async ({ id: referenceId, signal }) => {
1229
1089
  let versionId = getVersionId(referenceId, versionName), [versionExists, publishedExists] = await Promise.all([getDocumentExists({
@@ -1233,10 +1093,10 @@ function createReferenceResolver({ document, getDocumentExists, isUnpublished })
1233
1093
  id: referenceId,
1234
1094
  signal
1235
1095
  })]);
1236
- return versionExists ? await isUnpublished({
1096
+ return versionExists ? !await isUnpublished({
1237
1097
  id: versionId,
1238
1098
  signal
1239
- }) ? void 0 : versionId : publishedExists ? referenceId : void 0;
1099
+ }) : publishedExists;
1240
1100
  };
1241
1101
  }
1242
1102
  /**
@@ -1299,7 +1159,7 @@ function resolveTypeForArrayItem(item, candidates) {
1299
1159
  * @beta
1300
1160
  * @deprecated Prefer {@link validateDocument} with `{document, schema, client}` for new code.
1301
1161
  */
1302
- function validateDocumentWithWorkspace({ document, workspace, getClient = workspace.getClient, getDocumentExists, environment = "studio", maxCustomValidationConcurrency, maxFetchConcurrency, currentUser, customValidation, signal, validateReferenceTypes = !0 }) {
1162
+ function validateDocumentWithWorkspace({ document, workspace, getClient = workspace.getClient, getDocumentExists, environment = "studio", maxCustomValidationConcurrency, maxFetchConcurrency, currentUser, customValidation, signal }) {
1303
1163
  return validateDocumentInternal({
1304
1164
  currentUser,
1305
1165
  customValidation,
@@ -1311,8 +1171,7 @@ function validateDocumentWithWorkspace({ document, workspace, getClient = worksp
1311
1171
  maxCustomValidationConcurrency,
1312
1172
  maxFetchConcurrency,
1313
1173
  schema: workspace.schema,
1314
- signal,
1315
- validateReferenceTypes
1174
+ signal
1316
1175
  });
1317
1176
  }
1318
1177
  /**
@@ -1344,14 +1203,14 @@ function validateDocuments(options) {
1344
1203
  });
1345
1204
  }
1346
1205
  function normalizeValidationOptions(options) {
1347
- let { client, customValidation = !!options.client, getDocumentExists, i18n, schema, ...internalOptions } = options;
1206
+ let { client, customValidation = !!options.client, getDocumentExists, schema, ...internalOptions } = options;
1348
1207
  return {
1349
1208
  ...internalOptions,
1350
1209
  customValidation,
1351
1210
  environment: "cli",
1352
1211
  getClient: client ? ({ apiVersion }) => client.withConfig({ apiVersion }) : throwClientUnavailable,
1353
1212
  getDocumentExists: getDocumentExists || (client ? void 0 : throwClientUnavailable),
1354
- i18n: i18n ?? getFallbackLocaleSource(),
1213
+ i18n: getFallbackLocaleSource(),
1355
1214
  schema
1356
1215
  };
1357
1216
  }
@@ -1388,12 +1247,16 @@ function evaluateDocumentInternal(options) {
1388
1247
  ...sharedOptions
1389
1248
  }).then(([result]) => result);
1390
1249
  }
1391
- function evaluateDocumentsInternal({ documents, schema, getClient, getDocumentExists, i18n = getFallbackLocaleSource(), environment, maxCustomValidationConcurrency, maxFetchConcurrency, currentUser, customValidation = !0, signal, validateReferenceTypes = !0 }) {
1250
+ function evaluateDocumentsInternal({ documents, schema, getClient, getDocumentExists, i18n = getFallbackLocaleSource(), environment, maxCustomValidationConcurrency, maxFetchConcurrency, currentUser, customValidation = !0, signal }) {
1392
1251
  if (signal?.aborted) return Promise.reject(signal.reason);
1393
1252
  if (documents.length === 0) return Promise.resolve([]);
1394
- let limitConcurrency = createClientConcurrencyLimiter(maxFetchConcurrency ?? 25, signal), getConcurrencyLimitedClient = (clientOptions) => limitConcurrency(getClient(clientOptions)), batchedGetDocumentExists = getDocumentExists ? void 0 : createBatchedGetDocumentExists(getClient(DEFAULT_VALIDATION_CLIENT_OPTIONS), signal), batchedGetDocumentType = validateReferenceTypes ? createBatchedGetDocumentType(() => getConcurrencyLimitedClient(DEFAULT_VALIDATION_CLIENT_OPTIONS), signal) : void 0;
1395
- return Promise.all(documents.map((document) => {
1396
- let resolveReference = batchedGetDocumentExists ? createReferenceResolver({
1253
+ let limitConcurrency = createClientConcurrencyLimiter(maxFetchConcurrency ?? 25, signal), getConcurrencyLimitedClient = (clientOptions) => limitConcurrency(getClient(clientOptions)), batchedGetDocumentExists = getDocumentExists ? void 0 : createBatchedGetDocumentExists(getClient(DEFAULT_VALIDATION_CLIENT_OPTIONS), signal);
1254
+ return Promise.all(documents.map((document) => evaluateDocument({
1255
+ document,
1256
+ getClient: getConcurrencyLimitedClient,
1257
+ i18n,
1258
+ schema,
1259
+ getDocumentExists: batchedGetDocumentExists ? withReleaseReferences({
1397
1260
  document,
1398
1261
  getDocumentExists: batchedGetDocumentExists,
1399
1262
  isUnpublished: ({ id, signal: checkSignal }) => getConcurrencyLimitedClient(DEFAULT_VALIDATION_CLIENT_OPTIONS).fetch("*[_id == $id][0]._system.delete == true", { id }, {
@@ -1401,28 +1264,14 @@ function evaluateDocumentsInternal({ documents, schema, getClient, getDocumentEx
1401
1264
  signal: checkSignal,
1402
1265
  tag: "validation.release-reference"
1403
1266
  })
1404
- }) : async (options) => await getDocumentExists(options) ? options.id : void 0, resolvedReferences = /* @__PURE__ */ new Map();
1405
- return evaluateDocument({
1406
- document,
1407
- getClient: getConcurrencyLimitedClient,
1408
- i18n,
1409
- schema,
1410
- getDocumentExists: async (options) => {
1411
- let resolvedId = await resolveReference(options);
1412
- return batchedGetDocumentType && resolvedId && resolvedReferences.set(options.id, resolvedId), resolvedId !== void 0;
1413
- },
1414
- getDocumentType: batchedGetDocumentType ? async (id) => {
1415
- let resolvedId = resolvedReferences.get(id);
1416
- return resolvedId ? batchedGetDocumentType(resolvedId) : void 0;
1417
- } : void 0,
1418
- environment,
1419
- maxCustomValidationConcurrency,
1420
- currentUser,
1421
- customValidation,
1422
- signal,
1423
- pace: createUnpacedPace()
1424
- });
1425
- }));
1267
+ }) : getDocumentExists,
1268
+ environment,
1269
+ maxCustomValidationConcurrency,
1270
+ currentUser,
1271
+ customValidation,
1272
+ signal,
1273
+ pace: createUnpacedPace()
1274
+ })));
1426
1275
  }
1427
1276
  const customValidationConcurrencyLimiters = /* @__PURE__ */ new WeakMap();
1428
1277
  /**
@@ -1458,7 +1307,7 @@ async function evaluateDocument(options) {
1458
1307
  pace.dispose();
1459
1308
  }
1460
1309
  }
1461
- async function evaluateDocumentWithoutCancellation({ document, getClient, i18n = getFallbackLocaleSource(), schema, getDocumentExists, getDocumentType, environment, maxCustomValidationConcurrency, currentUser, customValidation = !0, signal, pace }) {
1310
+ async function evaluateDocumentWithoutCancellation({ document, getClient, i18n = getFallbackLocaleSource(), schema, getDocumentExists, environment, maxCustomValidationConcurrency, currentUser, customValidation = !0, signal, pace }) {
1462
1311
  try {
1463
1312
  if (typeof document?._type != "string") throw Error("Tried to validate a value without a '_type'");
1464
1313
  let documentType = schema.get(document._type);
@@ -1487,7 +1336,6 @@ async function evaluateDocumentWithoutCancellation({ document, getClient, i18n =
1487
1336
  customValidation,
1488
1337
  signal,
1489
1338
  __internal: {
1490
- getDocumentType,
1491
1339
  markIncomplete: () => {
1492
1340
  complete = !1;
1493
1341
  },
@@ -1656,4 +1504,4 @@ function toDocumentValidationMarker(marker) {
1656
1504
  }
1657
1505
  export { pathToString as _, validateDocumentInternal as a, validationMarkerCodes as b, validateDocuments as c, compileValidationRules as d, normalizeValidationRules as f, convertToValidationMarker as g, typeString as h, validateDocument as i, validateItem as l, getTypeChain as m, evaluateDocumentObservable as n, validateDocumentObservable as o, Rule$2 as p, resolveTypeForArrayItem as r, validateDocumentWithWorkspace as s, evaluateDocumentInternal as t, withReleaseReferences as u, getFallbackLocaleSource as v, validationLocaleStrings as y };
1658
1506
 
1659
- //# sourceMappingURL=validateDocument-DZEYmQ4p.js.map
1507
+ //# sourceMappingURL=validateDocument-Dws_67d7.js.map