@sanity/validation 6.23.0-next.7 → 6.24.0-next.111
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 +7 -0
- package/lib/_internal.d.ts +4 -19
- package/lib/_internal.js +2 -1
- package/lib/_internal.js.map +1 -1
- package/lib/index.d.ts +2 -3
- package/lib/index.js +1 -1
- package/lib/{validateDocument-CnUrz4db.d.ts → validateDocument-Clpbuo5v.d.ts} +37 -8
- package/lib/{validateDocument-BRt0o35E.js → validateDocument-NMKSm_Yr.js} +218 -141
- package/lib/validateDocument-NMKSm_Yr.js.map +1 -0
- package/package.json +9 -9
- package/lib/validateDocument-BRt0o35E.js.map +0 -1
package/README.md
CHANGED
|
@@ -24,6 +24,7 @@ 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`.
|
|
27
28
|
- Precompiled rules retain their original package version's behavior; recompile with the current version for current callback-skipping and concurrency semantics.
|
|
28
29
|
|
|
29
30
|
## Batch validation
|
|
@@ -37,6 +38,12 @@ const results = await validateDocuments({documents, schema, client, maxFetchConc
|
|
|
37
38
|
|
|
38
39
|
`maxFetchConcurrency` defaults to 25. One `signal` cancels the entire batch.
|
|
39
40
|
|
|
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
|
+
|
|
40
47
|
## Cancellation
|
|
41
48
|
|
|
42
49
|
```ts
|
package/lib/_internal.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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-
|
|
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-Clpbuo5v.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";
|
|
3
4
|
export declare function getFallbackLocaleSource(): LocaleSource;
|
|
4
5
|
export declare const validationLocaleStrings: {
|
|
5
6
|
readonly 'array.exact-length': 'Must have exactly {{wantedLength}} items';
|
|
@@ -32,6 +33,7 @@ export declare const validationLocaleStrings: {
|
|
|
32
33
|
readonly 'object.not-media-library-asset': 'Must be a reference to a Media Library asset';
|
|
33
34
|
readonly 'object.not-reference': 'Must be a reference to a document';
|
|
34
35
|
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}}';
|
|
35
37
|
readonly 'slug.missing-current': 'Slug must have a value';
|
|
36
38
|
readonly 'slug.not-object': 'Slug must be an object';
|
|
37
39
|
readonly 'slug.not-unique': 'Slug is already in use';
|
|
@@ -87,22 +89,6 @@ export declare function hasValidationContext(validation: SchemaValidationValue |
|
|
|
87
89
|
* @internal
|
|
88
90
|
*/
|
|
89
91
|
export declare const Rule: RuleClass;
|
|
90
|
-
/**
|
|
91
|
-
* Check if the provided file type should be accepted by the input with accept attribute.
|
|
92
|
-
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#attr-accept
|
|
93
|
-
*
|
|
94
|
-
* Inspired by https://github.com/enyo/dropzone (MIT) (c) 2021 Matias Meno
|
|
95
|
-
* Based on https://github.com/react-dropzone/attr-accept (MIT) (c) 2015 Andrey Okonetchnikov
|
|
96
|
-
*
|
|
97
|
-
* @param file - https://developer.mozilla.org/en-US/docs/Web/API/File
|
|
98
|
-
* @param acceptedFiles - List of accepted mime types (comma-separated string or array)
|
|
99
|
-
* @returns True if file is accepted, false otherwise
|
|
100
|
-
* @internal
|
|
101
|
-
*/
|
|
102
|
-
export declare function accepts(file: {
|
|
103
|
-
type: string;
|
|
104
|
-
name?: string;
|
|
105
|
-
}, acceptedFiles: string | string[]): boolean;
|
|
106
92
|
export declare function convertToValidationMarker(validatorResult: true | true[] | string | string[] | ValidationError | ValidationError[], level: 'error' | 'warning' | 'info' | undefined, context: ValidationContext, fallback?: {
|
|
107
93
|
code: ValidationMarkerCode;
|
|
108
94
|
details?: Record<string, unknown>;
|
|
@@ -111,5 +97,4 @@ export declare function getTypeChain(type: SchemaType | undefined, visited?: Set
|
|
|
111
97
|
export declare function normalizeValidationRules(typeDef: SchemaType | undefined, context?: ValidationContext$1): Rule$1[];
|
|
112
98
|
export declare function pathToString(path?: Path | undefined): string;
|
|
113
99
|
export declare function typeString(obj: unknown): string;
|
|
114
|
-
export { type LocaleSource, type ValidateDocumentInternalOptions, type ValidateDocumentObservableOptions, type ValidateItemOptions, type ValidationContext, type ValidationScheduling, evaluateDocumentInternal, evaluateDocumentObservable, resolveTypeForArrayItem, validateDocumentInternal, validateDocumentObservable, validateItem };
|
|
115
|
-
//# sourceMappingURL=_internal.d.ts.map
|
|
100
|
+
export { type LocaleSource, type ValidateDocumentInternalOptions, type ValidateDocumentObservableOptions, type ValidateItemOptions, type ValidationContext, type ValidationScheduling, accepts, evaluateDocumentInternal, evaluateDocumentObservable, resolveTypeForArrayItem, validateDocumentInternal, validateDocumentObservable, validateItem };
|
package/lib/_internal.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { _ as
|
|
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-NMKSm_Yr.js";
|
|
2
|
+
import { accepts } from "@sanity/util/accepts";
|
|
2
3
|
function inferFromSchemaType(typeDef) {
|
|
3
4
|
return traverse(typeDef, /* @__PURE__ */ new Set()), typeDef;
|
|
4
5
|
}
|
package/lib/_internal.js.map
CHANGED
|
@@ -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":"
|
|
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,OAVkB,OAAO,kBAEjB,CAAC,CAAC,SAAS,aAAa;EAC9B,IAAM,aAAa,OAAO,IAAI,QAAQ;EAElC,cACF,oBAAoB,UAAU;CAElC,CAAC,GAEM;AACT"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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-Clpbuo5v.js";
|
|
2
2
|
import { SanityDocument } from "@sanity/types";
|
|
3
3
|
type DocumentCheck = (options: {
|
|
4
4
|
id: string;
|
|
@@ -21,5 +21,4 @@ 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 ValidationMarkerCode, type ValidationSchema, type ValidationSource, validateDocument, validateDocumentWithWorkspace, validateDocuments, validationMarkerCodes };
|
|
25
|
-
//# sourceMappingURL=index.d.ts.map
|
|
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 };
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { i as validateDocument, s as validateDocumentWithWorkspace, c as validateDocuments,
|
|
1
|
+
export { i as validateDocument, s as validateDocumentWithWorkspace, c as validateDocuments, b as validationMarkerCodes, u as withReleaseReferences } from "./validateDocument-NMKSm_Yr.js";
|
|
@@ -3,11 +3,22 @@ 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
|
-
|
|
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. */
|
|
7
13
|
currentLocale: {
|
|
8
14
|
id: string;
|
|
9
15
|
};
|
|
16
|
+
/** Loads translation resources needed by built-in or custom validators. */
|
|
10
17
|
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 {
|
|
11
22
|
t: TFunction;
|
|
12
23
|
}
|
|
13
24
|
/**
|
|
@@ -54,8 +65,9 @@ declare module '@sanity/types' {
|
|
|
54
65
|
i18n: LocaleSource;
|
|
55
66
|
}
|
|
56
67
|
}
|
|
57
|
-
interface InternalValidationContext extends ValidationContext {
|
|
68
|
+
interface InternalValidationContext extends ValidationContext$1 {
|
|
58
69
|
__internal?: {
|
|
70
|
+
getDocumentType?: (id: string) => Promise<string | undefined>;
|
|
59
71
|
customValidation?: boolean;
|
|
60
72
|
customValidationConcurrencyLimiter?: {
|
|
61
73
|
ready: (signal?: AbortSignal) => Promise<void>;
|
|
@@ -92,6 +104,7 @@ declare const validationMarkerCodes: {
|
|
|
92
104
|
readonly objectUnknownField: 'object.unknown-field';
|
|
93
105
|
readonly referenceInvalid: 'reference.invalid';
|
|
94
106
|
readonly referenceNotPublished: 'reference.not-published';
|
|
107
|
+
readonly referenceTargetTypeMismatch: 'reference.target-type-mismatch';
|
|
95
108
|
readonly ruleAllFailed: 'rule.all-failed';
|
|
96
109
|
readonly ruleEitherFailed: 'rule.either-failed';
|
|
97
110
|
readonly slugInvalidType: 'slug.invalid-type';
|
|
@@ -139,6 +152,12 @@ interface ValidateDocumentBaseOptions {
|
|
|
139
152
|
document: SanityDocument;
|
|
140
153
|
/** The compiled schema to validate against. */
|
|
141
154
|
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;
|
|
142
161
|
/** Signal used to cancel validation and any work it starts. */
|
|
143
162
|
signal?: AbortSignal;
|
|
144
163
|
/**
|
|
@@ -154,6 +173,14 @@ interface ValidateDocumentBaseOptions {
|
|
|
154
173
|
id: string;
|
|
155
174
|
signal?: AbortSignal;
|
|
156
175
|
}) => 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;
|
|
157
184
|
/**
|
|
158
185
|
* The maximum amount of custom validation functions to be running
|
|
159
186
|
* concurrently at once. This helps prevent custom validators from
|
|
@@ -263,7 +290,7 @@ interface ValidationSource {
|
|
|
263
290
|
*
|
|
264
291
|
* @beta
|
|
265
292
|
*/
|
|
266
|
-
interface ValidateDocumentWorkspaceOptions extends Omit<ValidateDocumentBaseOptions, 'schema'> {
|
|
293
|
+
interface ValidateDocumentWorkspaceOptions extends Omit<ValidateDocumentBaseOptions, 'schema' | 'i18n'> {
|
|
267
294
|
/** The resolved Studio workspace or source used for validation. */
|
|
268
295
|
workspace: ValidationSource;
|
|
269
296
|
/**
|
|
@@ -283,7 +310,7 @@ interface ValidateDocumentWorkspaceOptions extends Omit<ValidateDocumentBaseOpti
|
|
|
283
310
|
* @beta
|
|
284
311
|
* @deprecated Prefer {@link validateDocument} with `{document, schema, client}` for new code.
|
|
285
312
|
*/
|
|
286
|
-
declare function validateDocumentWithWorkspace({ document, workspace, getClient, getDocumentExists, environment, maxCustomValidationConcurrency, maxFetchConcurrency, currentUser, customValidation, signal }: ValidateDocumentWorkspaceOptions): Promise<DocumentValidationMarker[]>;
|
|
313
|
+
declare function validateDocumentWithWorkspace({ document, workspace, getClient, getDocumentExists, environment, maxCustomValidationConcurrency, maxFetchConcurrency, currentUser, customValidation, signal, validateReferenceTypes }: ValidateDocumentWorkspaceOptions): Promise<DocumentValidationMarker[]>;
|
|
287
314
|
/**
|
|
288
315
|
* Validates a document against a compiled schema. Returns failures and whether
|
|
289
316
|
* validation completed
|
|
@@ -311,6 +338,7 @@ interface ValidateDocumentInternalOptions {
|
|
|
311
338
|
id: string;
|
|
312
339
|
signal?: AbortSignal;
|
|
313
340
|
}) => Promise<boolean>;
|
|
341
|
+
validateReferenceTypes?: boolean;
|
|
314
342
|
i18n?: LocaleSource;
|
|
315
343
|
environment: 'cli' | 'studio';
|
|
316
344
|
maxCustomValidationConcurrency?: number;
|
|
@@ -326,7 +354,9 @@ declare function evaluateDocumentInternal(options: ValidateDocumentInternalOptio
|
|
|
326
354
|
/**
|
|
327
355
|
* @internal
|
|
328
356
|
*/
|
|
329
|
-
interface ValidateDocumentObservableOptions extends Pick<ValidationContext
|
|
357
|
+
interface ValidateDocumentObservableOptions extends Pick<ValidationContext, 'getDocumentExists' | 'i18n' | 'signal' | 'currentUser'> {
|
|
358
|
+
/** Lookup for resolved target types. Omit to disable type checks. */
|
|
359
|
+
getDocumentType?: (id: string) => Promise<string | undefined>;
|
|
330
360
|
getClient: (options: {
|
|
331
361
|
apiVersion: string;
|
|
332
362
|
}) => SanityClient;
|
|
@@ -368,7 +398,6 @@ type ValidateItemOptions = {
|
|
|
368
398
|
/** See {@link ValidateDocumentObservableOptions.scheduling}. */
|
|
369
399
|
scheduling?: BehaviorSubject<ValidationScheduling>;
|
|
370
400
|
__internal?: InternalValidationContext['__internal'];
|
|
371
|
-
} & Pick<ValidationContext
|
|
401
|
+
} & Pick<ValidationContext, 'currentUser'> & ExplicitUndefined<Omit<ValidationContext, 'hidden' | 'signal' | 'currentUser'>>;
|
|
372
402
|
declare function validateItem(opts: ValidateItemOptions): Promise<ValidationMarker[]>;
|
|
373
|
-
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
|
|
374
|
-
//# sourceMappingURL=validateDocument-CnUrz4db.d.ts.map
|
|
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 as w, DocumentValidationMarker as x, validateItem as y };
|