@sanity/validation 3.2.4-next.5 → 3.2.5-client-v5.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,22 @@
1
1
  import {Observable} from 'rxjs'
2
2
  import {RuleClass} from '@sanity/types'
3
- import type {SanityClient} from '@sanity/client'
4
3
  import {SanityDocument} from '@sanity/types'
5
4
  import {Schema} from '@sanity/types'
6
5
  import {SchemaType} from '@sanity/types'
7
6
  import {ValidationContext} from '@sanity/types'
8
7
  import {ValidationMarker} from '@sanity/types'
9
8
 
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
+
10
20
  export declare function inferFromSchema(schema: Schema): Schema
11
21
 
12
22
  export declare function inferFromSchemaType(
@@ -20,17 +30,21 @@ export declare function inferFromSchemaType(typeDef: SchemaType): SchemaType
20
30
  export declare const Rule: RuleClass
21
31
 
22
32
  export declare function validateDocument(
23
- getClient: (options: {apiVersion: string}) => SanityClient,
33
+ getClient: ValidateItemOptions['getClient'],
24
34
  doc: SanityDocument,
25
35
  schema: Schema,
26
36
  context?: Pick<ValidationContext, 'getDocumentExists'>
27
37
  ): Promise<ValidationMarker[]>
28
38
 
29
39
  export declare function validateDocumentObservable(
30
- getClient: (options: {apiVersion: string}) => SanityClient,
40
+ getClient: ValidateItemOptions['getClient'],
31
41
  doc: SanityDocument,
32
42
  schema: Schema,
33
43
  context?: Pick<ValidationContext, 'getDocumentExists'>
34
44
  ): Observable<ValidationMarker[]>
35
45
 
46
+ declare type ValidateItemOptions = {
47
+ value: unknown
48
+ } & ExplicitUndefined<ValidationContext>
49
+
36
50
  export {}
package/lib/index.esm.js CHANGED
@@ -1117,11 +1117,7 @@ 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
- });
1123
1120
  const validationOptions = {
1124
- client,
1125
1121
  getClient,
1126
1122
  schema,
1127
1123
  parent: void 0,
@@ -1131,16 +1127,6 @@ function validateDocumentObservable(getClient, doc, schema, context) {
1131
1127
  type: documentType,
1132
1128
  getDocumentExists: context == null ? void 0 : context.getDocumentExists
1133
1129
  };
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
- }, {});
1144
1130
  return validateItemObservable(validationOptions).pipe(catchError(err => {
1145
1131
  console.error(err);
1146
1132
  return of([{