@sanity/validation 6.23.0-next.7 → 6.23.0
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 -18
- package/lib/_internal.js +2 -1
- package/lib/_internal.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +1 -1
- package/lib/{validateDocument-CnUrz4db.d.ts → validateDocument-DESiHtPx.d.ts} +35 -5
- package/lib/{validateDocument-BRt0o35E.js → validateDocument-DZEYmQ4p.js} +109 -54
- package/lib/validateDocument-DZEYmQ4p.js.map +1 -0
- package/package.json +5 -5
- 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-DESiHtPx.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,5 @@ 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 };
|
|
100
|
+
export { type LocaleSource, type ValidateDocumentInternalOptions, type ValidateDocumentObservableOptions, type ValidateItemOptions, type ValidationContext, type ValidationScheduling, accepts, evaluateDocumentInternal, evaluateDocumentObservable, resolveTypeForArrayItem, validateDocumentInternal, validateDocumentObservable, validateItem };
|
|
115
101
|
//# sourceMappingURL=_internal.d.ts.map
|
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-DZEYmQ4p.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,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, 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-DESiHtPx.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 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 ValidationLocaleSource, 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,
|
|
1
|
+
export { i as validateDocument, s as validateDocumentWithWorkspace, c as validateDocuments, b as validationMarkerCodes, u as withReleaseReferences } from "./validateDocument-DZEYmQ4p.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
|
/**
|
|
@@ -56,6 +67,7 @@ declare module '@sanity/types' {
|
|
|
56
67
|
}
|
|
57
68
|
interface InternalValidationContext extends ValidationContext {
|
|
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;
|
|
@@ -327,6 +355,8 @@ declare function evaluateDocumentInternal(options: ValidateDocumentInternalOptio
|
|
|
327
355
|
* @internal
|
|
328
356
|
*/
|
|
329
357
|
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>;
|
|
330
360
|
getClient: (options: {
|
|
331
361
|
apiVersion: string;
|
|
332
362
|
}) => SanityClient;
|
|
@@ -370,5 +400,5 @@ type ValidateItemOptions = {
|
|
|
370
400
|
__internal?: InternalValidationContext['__internal'];
|
|
371
401
|
} & Pick<ValidationContext$1, 'currentUser'> & ExplicitUndefined<Omit<ValidationContext$1, '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$1 as w, DocumentValidationMarker as x, validateItem as y };
|
|
374
|
-
//# sourceMappingURL=validateDocument-
|
|
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
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isInternalValidator, markInternalValidator } from "@sanity/schema/_internal";
|
|
2
|
-
import { isArrayOfBlocksSchemaType, isArrayOfObjectsSchemaType, isKeyedObject, isReference, isSlug, isTypedObject } from "@sanity/types";
|
|
2
|
+
import { isArrayOfBlocksSchemaType, isArrayOfObjectsSchemaType, isKeyedObject, isReference, isReferenceSchemaType, 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,6 +13,7 @@ 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";
|
|
16
17
|
/** Machine-readable codes emitted by built-in document validation. @beta */
|
|
17
18
|
const validationMarkerCodes = {
|
|
18
19
|
arrayDuplicateItem: "array.duplicate-item",
|
|
@@ -38,6 +39,7 @@ const validationMarkerCodes = {
|
|
|
38
39
|
objectUnknownField: "object.unknown-field",
|
|
39
40
|
referenceInvalid: "reference.invalid",
|
|
40
41
|
referenceNotPublished: "reference.not-published",
|
|
42
|
+
referenceTargetTypeMismatch: "reference.target-type-mismatch",
|
|
41
43
|
ruleAllFailed: "rule.all-failed",
|
|
42
44
|
ruleEitherFailed: "rule.either-failed",
|
|
43
45
|
slugInvalidType: "slug.invalid-type",
|
|
@@ -99,6 +101,7 @@ const validationLocaleStrings = {
|
|
|
99
101
|
"object.not-media-library-asset": "Must be a reference to a Media Library asset",
|
|
100
102
|
"object.not-reference": "Must be a reference to a document",
|
|
101
103
|
"object.reference-not-published": "Referenced document must be published",
|
|
104
|
+
"object.reference-target-type-mismatch": "Referenced document has type \"{{actualType}}\"; expected one of: {{allowedTypes}}",
|
|
102
105
|
"slug.missing-current": "Slug must have a value",
|
|
103
106
|
"slug.not-object": "Slug must be an object",
|
|
104
107
|
"slug.not-unique": "Slug is already in use",
|
|
@@ -218,6 +221,39 @@ function createBatchedGetDocumentExists(client, defaultSignal) {
|
|
|
218
221
|
});
|
|
219
222
|
};
|
|
220
223
|
}
|
|
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
|
+
}
|
|
221
257
|
function pathToString(path = []) {
|
|
222
258
|
return path.reduce((target, segment, i) => {
|
|
223
259
|
let segmentType = typeof segment;
|
|
@@ -633,17 +669,36 @@ const dateValidators = {
|
|
|
633
669
|
message: message || i18n.t("validation:object.not-reference")
|
|
634
670
|
};
|
|
635
671
|
if (!type) throw Error("`type` was not provided in validation context");
|
|
636
|
-
|
|
672
|
+
let getDocumentType = context.__internal?.getDocumentType, weak = "weak" in type && type.weak;
|
|
673
|
+
if (weak && !getDocumentType) return !0;
|
|
637
674
|
if (!getDocumentExists) throw Error("`getDocumentExists` was not provided in validation context");
|
|
638
|
-
let
|
|
639
|
-
return documentId && value._ref == getPublishedId(documentId) || await getDocumentExists({
|
|
675
|
+
let selfReference = document?._id && value._ref === getPublishedId(document._id), exists = selfReference || await getDocumentExists({
|
|
640
676
|
id: value._ref,
|
|
641
677
|
signal: context.signal
|
|
642
|
-
})
|
|
678
|
+
});
|
|
679
|
+
if (!exists && !weak) return {
|
|
643
680
|
code: validationMarkerCodes.referenceNotPublished,
|
|
644
681
|
details: { referenceId: value._ref },
|
|
645
682
|
message: i18n.t("validation:object.reference-not-published", { documentId: value._ref })
|
|
646
683
|
};
|
|
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;
|
|
647
702
|
},
|
|
648
703
|
assetRequired: (flag, value, message, { i18n }) => !value || !value.asset || !value.asset._ref ? {
|
|
649
704
|
__internal_metadata: { name: "assetRequired" },
|
|
@@ -894,7 +949,7 @@ const slugUniquenessValidator = (value, context) => {
|
|
|
894
949
|
}
|
|
895
950
|
let message = isLocalizedMessages(this._message) ? localizeMessage(this._message, context.i18n) : this._message;
|
|
896
951
|
try {
|
|
897
|
-
let validatorContext = curr.flag === "all" || curr.flag === "either" ? {
|
|
952
|
+
let validatorContext = curr.flag === "reference" || curr.flag === "all" || curr.flag === "either" ? {
|
|
898
953
|
...context,
|
|
899
954
|
__internal
|
|
900
955
|
} : context;
|
|
@@ -909,28 +964,7 @@ const slugUniquenessValidator = (value, context) => {
|
|
|
909
964
|
}
|
|
910
965
|
}))).flat();
|
|
911
966
|
}
|
|
912
|
-
};
|
|
913
|
-
/**
|
|
914
|
-
* Check if the provided file type should be accepted by the input with accept attribute.
|
|
915
|
-
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#attr-accept
|
|
916
|
-
*
|
|
917
|
-
* Inspired by https://github.com/enyo/dropzone (MIT) (c) 2021 Matias Meno
|
|
918
|
-
* Based on https://github.com/react-dropzone/attr-accept (MIT) (c) 2015 Andrey Okonetchnikov
|
|
919
|
-
*
|
|
920
|
-
* @param file - https://developer.mozilla.org/en-US/docs/Web/API/File
|
|
921
|
-
* @param acceptedFiles - List of accepted mime types (comma-separated string or array)
|
|
922
|
-
* @returns True if file is accepted, false otherwise
|
|
923
|
-
* @internal
|
|
924
|
-
*/
|
|
925
|
-
function accepts(file, acceptedFiles) {
|
|
926
|
-
if (!file || !acceptedFiles) return !0;
|
|
927
|
-
let acceptedFilesArray = Array.isArray(acceptedFiles) ? acceptedFiles : acceptedFiles.split(","), fileName = file.name || "", mimeType = (file.type || "").toLowerCase(), baseMimeType = mimeType.replace(/\/.*$/, "");
|
|
928
|
-
return acceptedFilesArray.some((type) => {
|
|
929
|
-
let validType = type.trim().toLowerCase();
|
|
930
|
-
return validType.charAt(0) === "." ? !fileName || fileName.toLowerCase().endsWith(validType) : validType.endsWith("/*") ? baseMimeType === validType.replace(/\/.*$/, "") : mimeType === validType;
|
|
931
|
-
});
|
|
932
|
-
}
|
|
933
|
-
const resolvedFileTypes = /* @__PURE__ */ new Map();
|
|
967
|
+
}, resolvedFileTypes = /* @__PURE__ */ new Map();
|
|
934
968
|
function isUnknownFileType(fileType) {
|
|
935
969
|
return [fileType.mimeType, fileType.extension].every((value) => (value ?? "") === "");
|
|
936
970
|
}
|
|
@@ -1179,8 +1213,17 @@ function createPace(scheduling) {
|
|
|
1179
1213
|
* @beta
|
|
1180
1214
|
*/
|
|
1181
1215
|
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 }) {
|
|
1182
1225
|
let id = document._id, variant = document._system?.variants?.[0]?._ref ?? document._system?.variant?._ref;
|
|
1183
|
-
if (!isVersionId(id) || variant) return getDocumentExists;
|
|
1226
|
+
if (!isVersionId(id) || variant) return async (options) => await getDocumentExists(options) ? options.id : void 0;
|
|
1184
1227
|
let versionName = getVersionNameFromId(id);
|
|
1185
1228
|
return async ({ id: referenceId, signal }) => {
|
|
1186
1229
|
let versionId = getVersionId(referenceId, versionName), [versionExists, publishedExists] = await Promise.all([getDocumentExists({
|
|
@@ -1190,10 +1233,10 @@ function withReleaseReferences({ document, getDocumentExists, isUnpublished }) {
|
|
|
1190
1233
|
id: referenceId,
|
|
1191
1234
|
signal
|
|
1192
1235
|
})]);
|
|
1193
|
-
return versionExists ?
|
|
1236
|
+
return versionExists ? await isUnpublished({
|
|
1194
1237
|
id: versionId,
|
|
1195
1238
|
signal
|
|
1196
|
-
}) : publishedExists;
|
|
1239
|
+
}) ? void 0 : versionId : publishedExists ? referenceId : void 0;
|
|
1197
1240
|
};
|
|
1198
1241
|
}
|
|
1199
1242
|
/**
|
|
@@ -1256,7 +1299,7 @@ function resolveTypeForArrayItem(item, candidates) {
|
|
|
1256
1299
|
* @beta
|
|
1257
1300
|
* @deprecated Prefer {@link validateDocument} with `{document, schema, client}` for new code.
|
|
1258
1301
|
*/
|
|
1259
|
-
function validateDocumentWithWorkspace({ document, workspace, getClient = workspace.getClient, getDocumentExists, environment = "studio", maxCustomValidationConcurrency, maxFetchConcurrency, currentUser, customValidation, signal }) {
|
|
1302
|
+
function validateDocumentWithWorkspace({ document, workspace, getClient = workspace.getClient, getDocumentExists, environment = "studio", maxCustomValidationConcurrency, maxFetchConcurrency, currentUser, customValidation, signal, validateReferenceTypes = !0 }) {
|
|
1260
1303
|
return validateDocumentInternal({
|
|
1261
1304
|
currentUser,
|
|
1262
1305
|
customValidation,
|
|
@@ -1268,7 +1311,8 @@ function validateDocumentWithWorkspace({ document, workspace, getClient = worksp
|
|
|
1268
1311
|
maxCustomValidationConcurrency,
|
|
1269
1312
|
maxFetchConcurrency,
|
|
1270
1313
|
schema: workspace.schema,
|
|
1271
|
-
signal
|
|
1314
|
+
signal,
|
|
1315
|
+
validateReferenceTypes
|
|
1272
1316
|
});
|
|
1273
1317
|
}
|
|
1274
1318
|
/**
|
|
@@ -1300,14 +1344,14 @@ function validateDocuments(options) {
|
|
|
1300
1344
|
});
|
|
1301
1345
|
}
|
|
1302
1346
|
function normalizeValidationOptions(options) {
|
|
1303
|
-
let { client, customValidation = !!options.client, getDocumentExists, schema, ...internalOptions } = options;
|
|
1347
|
+
let { client, customValidation = !!options.client, getDocumentExists, i18n, schema, ...internalOptions } = options;
|
|
1304
1348
|
return {
|
|
1305
1349
|
...internalOptions,
|
|
1306
1350
|
customValidation,
|
|
1307
1351
|
environment: "cli",
|
|
1308
1352
|
getClient: client ? ({ apiVersion }) => client.withConfig({ apiVersion }) : throwClientUnavailable,
|
|
1309
1353
|
getDocumentExists: getDocumentExists || (client ? void 0 : throwClientUnavailable),
|
|
1310
|
-
i18n: getFallbackLocaleSource(),
|
|
1354
|
+
i18n: i18n ?? getFallbackLocaleSource(),
|
|
1311
1355
|
schema
|
|
1312
1356
|
};
|
|
1313
1357
|
}
|
|
@@ -1344,16 +1388,12 @@ function evaluateDocumentInternal(options) {
|
|
|
1344
1388
|
...sharedOptions
|
|
1345
1389
|
}).then(([result]) => result);
|
|
1346
1390
|
}
|
|
1347
|
-
function evaluateDocumentsInternal({ documents, schema, getClient, getDocumentExists, i18n = getFallbackLocaleSource(), environment, maxCustomValidationConcurrency, maxFetchConcurrency, currentUser, customValidation = !0, signal }) {
|
|
1391
|
+
function evaluateDocumentsInternal({ documents, schema, getClient, getDocumentExists, i18n = getFallbackLocaleSource(), environment, maxCustomValidationConcurrency, maxFetchConcurrency, currentUser, customValidation = !0, signal, validateReferenceTypes = !0 }) {
|
|
1348
1392
|
if (signal?.aborted) return Promise.reject(signal.reason);
|
|
1349
1393
|
if (documents.length === 0) return Promise.resolve([]);
|
|
1350
|
-
let limitConcurrency = createClientConcurrencyLimiter(maxFetchConcurrency ?? 25, signal), getConcurrencyLimitedClient = (clientOptions) => limitConcurrency(getClient(clientOptions)), batchedGetDocumentExists = getDocumentExists ? void 0 : createBatchedGetDocumentExists(getClient(DEFAULT_VALIDATION_CLIENT_OPTIONS), signal);
|
|
1351
|
-
return Promise.all(documents.map((document) =>
|
|
1352
|
-
|
|
1353
|
-
getClient: getConcurrencyLimitedClient,
|
|
1354
|
-
i18n,
|
|
1355
|
-
schema,
|
|
1356
|
-
getDocumentExists: batchedGetDocumentExists ? withReleaseReferences({
|
|
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({
|
|
1357
1397
|
document,
|
|
1358
1398
|
getDocumentExists: batchedGetDocumentExists,
|
|
1359
1399
|
isUnpublished: ({ id, signal: checkSignal }) => getConcurrencyLimitedClient(DEFAULT_VALIDATION_CLIENT_OPTIONS).fetch("*[_id == $id][0]._system.delete == true", { id }, {
|
|
@@ -1361,14 +1401,28 @@ function evaluateDocumentsInternal({ documents, schema, getClient, getDocumentEx
|
|
|
1361
1401
|
signal: checkSignal,
|
|
1362
1402
|
tag: "validation.release-reference"
|
|
1363
1403
|
})
|
|
1364
|
-
}) : getDocumentExists,
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
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
|
+
}));
|
|
1372
1426
|
}
|
|
1373
1427
|
const customValidationConcurrencyLimiters = /* @__PURE__ */ new WeakMap();
|
|
1374
1428
|
/**
|
|
@@ -1404,7 +1458,7 @@ async function evaluateDocument(options) {
|
|
|
1404
1458
|
pace.dispose();
|
|
1405
1459
|
}
|
|
1406
1460
|
}
|
|
1407
|
-
async function evaluateDocumentWithoutCancellation({ document, getClient, i18n = getFallbackLocaleSource(), schema, getDocumentExists, environment, maxCustomValidationConcurrency, currentUser, customValidation = !0, signal, pace }) {
|
|
1461
|
+
async function evaluateDocumentWithoutCancellation({ document, getClient, i18n = getFallbackLocaleSource(), schema, getDocumentExists, getDocumentType, environment, maxCustomValidationConcurrency, currentUser, customValidation = !0, signal, pace }) {
|
|
1408
1462
|
try {
|
|
1409
1463
|
if (typeof document?._type != "string") throw Error("Tried to validate a value without a '_type'");
|
|
1410
1464
|
let documentType = schema.get(document._type);
|
|
@@ -1433,6 +1487,7 @@ async function evaluateDocumentWithoutCancellation({ document, getClient, i18n =
|
|
|
1433
1487
|
customValidation,
|
|
1434
1488
|
signal,
|
|
1435
1489
|
__internal: {
|
|
1490
|
+
getDocumentType,
|
|
1436
1491
|
markIncomplete: () => {
|
|
1437
1492
|
complete = !1;
|
|
1438
1493
|
},
|
|
@@ -1599,6 +1654,6 @@ function toDocumentValidationMarker(marker) {
|
|
|
1599
1654
|
code: validationMarkerCodes.validationFailed
|
|
1600
1655
|
};
|
|
1601
1656
|
}
|
|
1602
|
-
export {
|
|
1657
|
+
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 };
|
|
1603
1658
|
|
|
1604
|
-
//# sourceMappingURL=validateDocument-
|
|
1659
|
+
//# sourceMappingURL=validateDocument-DZEYmQ4p.js.map
|