@sanity/validation 3.2.5-client-v5.11 → 3.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dts/src/index.d.ts +3 -17
- package/lib/index.esm.js +14 -0
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +14 -0
- package/lib/index.js.map +1 -1
- package/package.json +6 -6
- package/src/validateDocument.test.ts +10 -5
- package/src/validateDocument.ts +29 -3
package/lib/dts/src/index.d.ts
CHANGED
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
import {Observable} from 'rxjs'
|
|
2
2
|
import {RuleClass} from '@sanity/types'
|
|
3
|
+
import type {SanityClient} from '@sanity/client'
|
|
3
4
|
import {SanityDocument} from '@sanity/types'
|
|
4
5
|
import {Schema} from '@sanity/types'
|
|
5
6
|
import {SchemaType} from '@sanity/types'
|
|
6
7
|
import {ValidationContext} from '@sanity/types'
|
|
7
8
|
import {ValidationMarker} from '@sanity/types'
|
|
8
9
|
|
|
9
|
-
/**
|
|
10
|
-
* this is used make optional properties required by replacing optionals with
|
|
11
|
-
* `T[P] | undefined`. this is used to prevent errors in `validateItem` where
|
|
12
|
-
* an option from a previous invocation would be incorrectly passed down.
|
|
13
|
-
*
|
|
14
|
-
* https://medium.com/terria/typescript-transforming-optional-properties-to-required-properties-that-may-be-undefined-7482cb4e1585
|
|
15
|
-
*/
|
|
16
|
-
declare type ExplicitUndefined<T> = {
|
|
17
|
-
[P in keyof Required<T>]: Pick<T, P> extends Required<Pick<T, P>> ? T[P] : T[P] | undefined
|
|
18
|
-
}
|
|
19
|
-
|
|
20
10
|
export declare function inferFromSchema(schema: Schema): Schema
|
|
21
11
|
|
|
22
12
|
export declare function inferFromSchemaType(
|
|
@@ -30,21 +20,17 @@ export declare function inferFromSchemaType(typeDef: SchemaType): SchemaType
|
|
|
30
20
|
export declare const Rule: RuleClass
|
|
31
21
|
|
|
32
22
|
export declare function validateDocument(
|
|
33
|
-
getClient:
|
|
23
|
+
getClient: (options: {apiVersion: string}) => SanityClient,
|
|
34
24
|
doc: SanityDocument,
|
|
35
25
|
schema: Schema,
|
|
36
26
|
context?: Pick<ValidationContext, 'getDocumentExists'>
|
|
37
27
|
): Promise<ValidationMarker[]>
|
|
38
28
|
|
|
39
29
|
export declare function validateDocumentObservable(
|
|
40
|
-
getClient:
|
|
30
|
+
getClient: (options: {apiVersion: string}) => SanityClient,
|
|
41
31
|
doc: SanityDocument,
|
|
42
32
|
schema: Schema,
|
|
43
33
|
context?: Pick<ValidationContext, 'getDocumentExists'>
|
|
44
34
|
): Observable<ValidationMarker[]>
|
|
45
35
|
|
|
46
|
-
declare type ValidateItemOptions = {
|
|
47
|
-
value: unknown
|
|
48
|
-
} & ExplicitUndefined<ValidationContext>
|
|
49
|
-
|
|
50
36
|
export {}
|
package/lib/index.esm.js
CHANGED
|
@@ -1117,7 +1117,11 @@ function validateDocumentObservable(getClient, doc, schema, context) {
|
|
|
1117
1117
|
console.warn('Schema type for object type "%s" not found, skipping validation', doc._type);
|
|
1118
1118
|
return of(EMPTY_MARKERS);
|
|
1119
1119
|
}
|
|
1120
|
+
const client = getClient({
|
|
1121
|
+
apiVersion: "2021-06-07"
|
|
1122
|
+
});
|
|
1120
1123
|
const validationOptions = {
|
|
1124
|
+
client,
|
|
1121
1125
|
getClient,
|
|
1122
1126
|
schema,
|
|
1123
1127
|
parent: void 0,
|
|
@@ -1127,6 +1131,16 @@ function validateDocumentObservable(getClient, doc, schema, context) {
|
|
|
1127
1131
|
type: documentType,
|
|
1128
1132
|
getDocumentExists: context == null ? void 0 : context.getDocumentExists
|
|
1129
1133
|
};
|
|
1134
|
+
const wrappedClient = client;
|
|
1135
|
+
validationOptions.client = [...Object.keys(client), ...Object.keys(wrappedClient.__proto__)].reduce((acc, key) => {
|
|
1136
|
+
const original = Object.hasOwnProperty.call(client, key) ? wrappedClient[key] : wrappedClient.__proto__[key];
|
|
1137
|
+
return Object.defineProperty(acc, key, {
|
|
1138
|
+
get() {
|
|
1139
|
+
console.warn('`configContext.client` is deprecated and will be removed in the next release! Use `context.getClient({apiVersion: "2021-06-07"})` instead');
|
|
1140
|
+
return original;
|
|
1141
|
+
}
|
|
1142
|
+
});
|
|
1143
|
+
}, {});
|
|
1130
1144
|
return validateItemObservable(validationOptions).pipe(catchError(err => {
|
|
1131
1145
|
console.error(err);
|
|
1132
1146
|
return of([{
|