@sanity/client 6.11.3 → 6.11.4-canary.1
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 +4 -4
- package/dist/_chunks/{browserMiddleware-1MULg59S.cjs → browserMiddleware-EnEpy_gt.cjs} +247 -299
- package/dist/_chunks/browserMiddleware-EnEpy_gt.cjs.map +1 -0
- package/dist/_chunks/{browserMiddleware-heyg-fDk.js → browserMiddleware-nSeu_Rmf.js} +246 -299
- package/dist/_chunks/browserMiddleware-nSeu_Rmf.js.map +1 -0
- package/dist/_chunks/{nodeMiddleware-CHxg1-zH.cjs → nodeMiddleware-_hIIS1d7.cjs} +248 -300
- package/dist/_chunks/nodeMiddleware-_hIIS1d7.cjs.map +1 -0
- package/dist/_chunks/{nodeMiddleware-u_fUUnxa.js → nodeMiddleware-hZIb_1T_.js} +247 -300
- package/dist/_chunks/nodeMiddleware-hZIb_1T_.js.map +1 -0
- package/dist/_chunks/stegaEncodeSourceMap-4w5UCEGT.cjs +479 -0
- package/dist/_chunks/stegaEncodeSourceMap-4w5UCEGT.cjs.map +1 -0
- package/dist/_chunks/stegaEncodeSourceMap-SOgem38i.js +475 -0
- package/dist/_chunks/stegaEncodeSourceMap-SOgem38i.js.map +1 -0
- package/dist/_chunks/stegaEncodeSourceMap-Tuf6zjiN.cjs +230 -0
- package/dist/_chunks/stegaEncodeSourceMap-Tuf6zjiN.cjs.map +1 -0
- package/dist/_chunks/stegaEncodeSourceMap-zvyGxB_C.js +226 -0
- package/dist/_chunks/stegaEncodeSourceMap-zvyGxB_C.js.map +1 -0
- package/dist/index.browser.cjs +1 -1
- package/dist/index.browser.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +319 -49
- package/dist/index.js +2 -2
- package/dist/stega.browser.cjs +12 -695
- package/dist/stega.browser.cjs.map +1 -1
- package/dist/stega.browser.js +7 -690
- package/dist/stega.browser.js.map +1 -1
- package/dist/stega.cjs +12 -446
- package/dist/stega.cjs.js +3 -3
- package/dist/stega.cjs.map +1 -1
- package/dist/stega.d.ts +1418 -1422
- package/dist/stega.js +7 -441
- package/dist/stega.js.map +1 -1
- package/package.json +11 -9
- package/src/SanityClient.ts +152 -75
- package/src/assets/AssetsClient.ts +19 -10
- package/src/config.ts +34 -12
- package/src/data/dataMethods.ts +40 -14
- package/src/data/patch.ts +12 -10
- package/src/data/transaction.ts +13 -12
- package/src/datasets/DatasetsClient.ts +36 -16
- package/src/projects/ProjectsClient.ts +21 -12
- package/src/stega/index.browser.ts +3 -7
- package/src/stega/index.ts +3 -7
- package/src/stega/shared.ts +7 -5
- package/src/stega/types.ts +11 -18
- package/src/types.ts +107 -5
- package/src/users/UsersClient.ts +20 -13
- package/umd/sanityClient.js +3148 -2235
- package/umd/sanityClient.min.js +4 -3
- package/dist/_chunks/browserMiddleware-1MULg59S.cjs.map +0 -1
- package/dist/_chunks/browserMiddleware-heyg-fDk.js.map +0 -1
- package/dist/_chunks/nodeMiddleware-CHxg1-zH.cjs.map +0 -1
- package/dist/_chunks/nodeMiddleware-u_fUUnxa.js.map +0 -1
- package/src/stega/SanityStegaClient.ts +0 -298
- package/src/stega/config.ts +0 -76
package/src/SanityClient.ts
CHANGED
|
@@ -25,7 +25,11 @@ import type {
|
|
|
25
25
|
MutationSelection,
|
|
26
26
|
PatchOperations,
|
|
27
27
|
PatchSelection,
|
|
28
|
+
QueryOptions,
|
|
28
29
|
QueryParams,
|
|
30
|
+
QueryParamsLikelyByMistake,
|
|
31
|
+
QueryParamsParameter,
|
|
32
|
+
QueryParamsWithoutQueryOptions,
|
|
29
33
|
RawQueryResponse,
|
|
30
34
|
RawRequestOptions,
|
|
31
35
|
SanityDocument,
|
|
@@ -47,6 +51,9 @@ export type {
|
|
|
47
51
|
UsersClient,
|
|
48
52
|
}
|
|
49
53
|
|
|
54
|
+
const clientConfigSymbol = Symbol('#clientConfig')
|
|
55
|
+
const httpRequestSymbol = Symbol('#httpRequest')
|
|
56
|
+
|
|
50
57
|
/** @public */
|
|
51
58
|
export class ObservableSanityClient {
|
|
52
59
|
assets: ObservableAssetsClient
|
|
@@ -57,8 +64,8 @@ export class ObservableSanityClient {
|
|
|
57
64
|
/**
|
|
58
65
|
* Private properties
|
|
59
66
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
private [clientConfigSymbol]: InitializedClientConfig
|
|
68
|
+
private [httpRequestSymbol]: HttpRequest
|
|
62
69
|
|
|
63
70
|
/**
|
|
64
71
|
* Instance properties
|
|
@@ -68,19 +75,19 @@ export class ObservableSanityClient {
|
|
|
68
75
|
constructor(httpRequest: HttpRequest, config: ClientConfig = defaultConfig) {
|
|
69
76
|
this.config(config)
|
|
70
77
|
|
|
71
|
-
this
|
|
78
|
+
this[httpRequestSymbol] = httpRequest
|
|
72
79
|
|
|
73
|
-
this.assets = new ObservableAssetsClient(this, this
|
|
74
|
-
this.datasets = new ObservableDatasetsClient(this, this
|
|
75
|
-
this.projects = new ObservableProjectsClient(this, this
|
|
76
|
-
this.users = new ObservableUsersClient(this, this
|
|
80
|
+
this.assets = new ObservableAssetsClient(this, this[httpRequestSymbol])
|
|
81
|
+
this.datasets = new ObservableDatasetsClient(this, this[httpRequestSymbol])
|
|
82
|
+
this.projects = new ObservableProjectsClient(this, this[httpRequestSymbol])
|
|
83
|
+
this.users = new ObservableUsersClient(this, this[httpRequestSymbol])
|
|
77
84
|
}
|
|
78
85
|
|
|
79
86
|
/**
|
|
80
87
|
* Clone the client - returns a new instance
|
|
81
88
|
*/
|
|
82
89
|
clone(): ObservableSanityClient {
|
|
83
|
-
return new ObservableSanityClient(this
|
|
90
|
+
return new ObservableSanityClient(this[httpRequestSymbol], this.config())
|
|
84
91
|
}
|
|
85
92
|
|
|
86
93
|
/**
|
|
@@ -93,16 +100,16 @@ export class ObservableSanityClient {
|
|
|
93
100
|
config(newConfig?: Partial<ClientConfig>): this
|
|
94
101
|
config(newConfig?: Partial<ClientConfig>): ClientConfig | this {
|
|
95
102
|
if (newConfig === undefined) {
|
|
96
|
-
return {...this
|
|
103
|
+
return {...this[clientConfigSymbol]}
|
|
97
104
|
}
|
|
98
105
|
|
|
99
|
-
if (this
|
|
106
|
+
if (this[clientConfigSymbol] && this[clientConfigSymbol].allowReconfigure === false) {
|
|
100
107
|
throw new Error(
|
|
101
108
|
'Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client',
|
|
102
109
|
)
|
|
103
110
|
}
|
|
104
111
|
|
|
105
|
-
this
|
|
112
|
+
this[clientConfigSymbol] = initConfig(newConfig, this[clientConfigSymbol] || {})
|
|
106
113
|
return this
|
|
107
114
|
}
|
|
108
115
|
|
|
@@ -112,7 +119,17 @@ export class ObservableSanityClient {
|
|
|
112
119
|
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
113
120
|
*/
|
|
114
121
|
withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClient {
|
|
115
|
-
|
|
122
|
+
const thisConfig = this.config()
|
|
123
|
+
return new ObservableSanityClient(this[httpRequestSymbol], {
|
|
124
|
+
...thisConfig,
|
|
125
|
+
...newConfig,
|
|
126
|
+
stega: {
|
|
127
|
+
...(thisConfig.stega || {}),
|
|
128
|
+
...(typeof newConfig?.stega === 'boolean'
|
|
129
|
+
? {enabled: newConfig.stega}
|
|
130
|
+
: newConfig?.stega || {}),
|
|
131
|
+
},
|
|
132
|
+
})
|
|
116
133
|
}
|
|
117
134
|
|
|
118
135
|
/**
|
|
@@ -120,44 +137,67 @@ export class ObservableSanityClient {
|
|
|
120
137
|
*
|
|
121
138
|
* @param query - GROQ-query to perform
|
|
122
139
|
*/
|
|
123
|
-
fetch<
|
|
140
|
+
fetch<
|
|
141
|
+
R = Any,
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
143
|
+
Q extends never | undefined | Record<string, never> = never,
|
|
144
|
+
>(query: string): Observable<R>
|
|
124
145
|
/**
|
|
125
146
|
* Perform a GROQ-query against the configured dataset.
|
|
126
147
|
*
|
|
127
148
|
* @param query - GROQ-query to perform
|
|
128
|
-
* @param params -
|
|
129
|
-
|
|
130
|
-
fetch<R = Any, Q = QueryParams>(query: string, params: Q): Observable<R>
|
|
131
|
-
/**
|
|
132
|
-
* Perform a GROQ-query against the configured dataset.
|
|
133
|
-
*
|
|
134
|
-
* @param query - GROQ-query to perform
|
|
135
|
-
* @param params - Query parameters
|
|
136
|
-
* @param options - Request options
|
|
149
|
+
* @param params - Optional query parameters
|
|
150
|
+
* @param options - Optional request options
|
|
137
151
|
*/
|
|
138
|
-
fetch<R = Any, Q =
|
|
152
|
+
fetch<R = Any, Q = QueryParamsWithoutQueryOptions>(
|
|
139
153
|
query: string,
|
|
140
|
-
params: Q
|
|
141
|
-
options
|
|
154
|
+
params: QueryParamsParameter<Q>,
|
|
155
|
+
options?: FilteredResponseQueryOptions,
|
|
142
156
|
): Observable<R>
|
|
143
157
|
/**
|
|
144
158
|
* Perform a GROQ-query against the configured dataset.
|
|
145
159
|
*
|
|
146
160
|
* @param query - GROQ-query to perform
|
|
147
|
-
* @param params -
|
|
161
|
+
* @param params - Optional query parameters
|
|
148
162
|
* @param options - Request options
|
|
149
163
|
*/
|
|
150
|
-
fetch<R = Any, Q =
|
|
164
|
+
fetch<R = Any, Q = QueryParamsWithoutQueryOptions>(
|
|
151
165
|
query: string,
|
|
152
|
-
params: Q
|
|
166
|
+
params: QueryParamsParameter<Q>,
|
|
153
167
|
options: UnfilteredResponseQueryOptions,
|
|
154
168
|
): Observable<RawQueryResponse<R>>
|
|
169
|
+
/**
|
|
170
|
+
* You're passing in query parameters to a GROQ query that looks like query options.
|
|
171
|
+
* This is likely a mistake, you can either:
|
|
172
|
+
* a) replace the second argument with an empty object, and move the options to the third argument
|
|
173
|
+
* ```diff
|
|
174
|
+
* -client.fetch(query, {cache: 'no-store'})
|
|
175
|
+
* +client.fetch(query, {}, {cache: 'no-store'})
|
|
176
|
+
* ```
|
|
177
|
+
* b) add a generic type parameter that allows the query parameters to be passed in to silence the error
|
|
178
|
+
* @deprecated not actually deprecated, marking it as deprecated makes this error easier to spot
|
|
179
|
+
*/
|
|
180
|
+
fetch<
|
|
181
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
182
|
+
R = Any,
|
|
183
|
+
>(
|
|
184
|
+
query: string,
|
|
185
|
+
params: QueryParamsLikelyByMistake & QueryParams,
|
|
186
|
+
options?: QueryOptions,
|
|
187
|
+
): unknown
|
|
155
188
|
fetch<R, Q extends QueryParams>(
|
|
156
189
|
query: string,
|
|
157
190
|
params?: Q,
|
|
158
|
-
options
|
|
191
|
+
options?: QueryOptions,
|
|
159
192
|
): Observable<RawQueryResponse<R> | R> {
|
|
160
|
-
return dataMethods._fetch<R, Q>(
|
|
193
|
+
return dataMethods._fetch<R, Q>(
|
|
194
|
+
this,
|
|
195
|
+
this[httpRequestSymbol],
|
|
196
|
+
this[clientConfigSymbol].stega,
|
|
197
|
+
query,
|
|
198
|
+
params,
|
|
199
|
+
options,
|
|
200
|
+
)
|
|
161
201
|
}
|
|
162
202
|
|
|
163
203
|
/**
|
|
@@ -170,7 +210,7 @@ export class ObservableSanityClient {
|
|
|
170
210
|
id: string,
|
|
171
211
|
options?: {tag?: string},
|
|
172
212
|
): Observable<SanityDocument<R> | undefined> {
|
|
173
|
-
return dataMethods._getDocument<R>(this, this
|
|
213
|
+
return dataMethods._getDocument<R>(this, this[httpRequestSymbol], id, options)
|
|
174
214
|
}
|
|
175
215
|
|
|
176
216
|
/**
|
|
@@ -186,7 +226,7 @@ export class ObservableSanityClient {
|
|
|
186
226
|
ids: string[],
|
|
187
227
|
options?: {tag?: string},
|
|
188
228
|
): Observable<(SanityDocument<R> | null)[]> {
|
|
189
|
-
return dataMethods._getDocuments<R>(this, this
|
|
229
|
+
return dataMethods._getDocuments<R>(this, this[httpRequestSymbol], ids, options)
|
|
190
230
|
}
|
|
191
231
|
|
|
192
232
|
/**
|
|
@@ -255,7 +295,7 @@ export class ObservableSanityClient {
|
|
|
255
295
|
): Observable<
|
|
256
296
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
257
297
|
> {
|
|
258
|
-
return dataMethods._create<R>(this, this
|
|
298
|
+
return dataMethods._create<R>(this, this[httpRequestSymbol], document, 'create', options)
|
|
259
299
|
}
|
|
260
300
|
|
|
261
301
|
/**
|
|
@@ -324,7 +364,7 @@ export class ObservableSanityClient {
|
|
|
324
364
|
): Observable<
|
|
325
365
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
326
366
|
> {
|
|
327
|
-
return dataMethods._createIfNotExists<R>(this, this
|
|
367
|
+
return dataMethods._createIfNotExists<R>(this, this[httpRequestSymbol], document, options)
|
|
328
368
|
}
|
|
329
369
|
|
|
330
370
|
/**
|
|
@@ -393,7 +433,7 @@ export class ObservableSanityClient {
|
|
|
393
433
|
): Observable<
|
|
394
434
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
395
435
|
> {
|
|
396
|
-
return dataMethods._createOrReplace<R>(this, this
|
|
436
|
+
return dataMethods._createOrReplace<R>(this, this[httpRequestSymbol], document, options)
|
|
397
437
|
}
|
|
398
438
|
|
|
399
439
|
/**
|
|
@@ -511,7 +551,7 @@ export class ObservableSanityClient {
|
|
|
511
551
|
): Observable<
|
|
512
552
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
513
553
|
> {
|
|
514
|
-
return dataMethods._delete<R>(this, this
|
|
554
|
+
return dataMethods._delete<R>(this, this[httpRequestSymbol], selection, options)
|
|
515
555
|
}
|
|
516
556
|
|
|
517
557
|
/**
|
|
@@ -580,7 +620,7 @@ export class ObservableSanityClient {
|
|
|
580
620
|
): Observable<
|
|
581
621
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
582
622
|
> {
|
|
583
|
-
return dataMethods._mutate<R>(this, this
|
|
623
|
+
return dataMethods._mutate<R>(this, this[httpRequestSymbol], operations, options)
|
|
584
624
|
}
|
|
585
625
|
|
|
586
626
|
/**
|
|
@@ -638,7 +678,7 @@ export class ObservableSanityClient {
|
|
|
638
678
|
* @param options - Request options
|
|
639
679
|
*/
|
|
640
680
|
request<R = Any>(options: RawRequestOptions): Observable<R> {
|
|
641
|
-
return dataMethods._request(this, this
|
|
681
|
+
return dataMethods._request(this, this[httpRequestSymbol], options)
|
|
642
682
|
}
|
|
643
683
|
|
|
644
684
|
/**
|
|
@@ -677,8 +717,8 @@ export class SanityClient {
|
|
|
677
717
|
/**
|
|
678
718
|
* Private properties
|
|
679
719
|
*/
|
|
680
|
-
|
|
681
|
-
|
|
720
|
+
private [clientConfigSymbol]: InitializedClientConfig
|
|
721
|
+
private [httpRequestSymbol]: HttpRequest
|
|
682
722
|
|
|
683
723
|
/**
|
|
684
724
|
* Instance properties
|
|
@@ -688,12 +728,12 @@ export class SanityClient {
|
|
|
688
728
|
constructor(httpRequest: HttpRequest, config: ClientConfig = defaultConfig) {
|
|
689
729
|
this.config(config)
|
|
690
730
|
|
|
691
|
-
this
|
|
731
|
+
this[httpRequestSymbol] = httpRequest
|
|
692
732
|
|
|
693
|
-
this.assets = new AssetsClient(this, this
|
|
694
|
-
this.datasets = new DatasetsClient(this, this
|
|
695
|
-
this.projects = new ProjectsClient(this, this
|
|
696
|
-
this.users = new UsersClient(this, this
|
|
733
|
+
this.assets = new AssetsClient(this, this[httpRequestSymbol])
|
|
734
|
+
this.datasets = new DatasetsClient(this, this[httpRequestSymbol])
|
|
735
|
+
this.projects = new ProjectsClient(this, this[httpRequestSymbol])
|
|
736
|
+
this.users = new UsersClient(this, this[httpRequestSymbol])
|
|
697
737
|
|
|
698
738
|
this.observable = new ObservableSanityClient(httpRequest, config)
|
|
699
739
|
}
|
|
@@ -702,7 +742,7 @@ export class SanityClient {
|
|
|
702
742
|
* Clone the client - returns a new instance
|
|
703
743
|
*/
|
|
704
744
|
clone(): SanityClient {
|
|
705
|
-
return new SanityClient(this
|
|
745
|
+
return new SanityClient(this[httpRequestSymbol], this.config())
|
|
706
746
|
}
|
|
707
747
|
|
|
708
748
|
/**
|
|
@@ -715,10 +755,10 @@ export class SanityClient {
|
|
|
715
755
|
config(newConfig?: Partial<ClientConfig>): this
|
|
716
756
|
config(newConfig?: Partial<ClientConfig>): ClientConfig | this {
|
|
717
757
|
if (newConfig === undefined) {
|
|
718
|
-
return {...this
|
|
758
|
+
return {...this[clientConfigSymbol]}
|
|
719
759
|
}
|
|
720
760
|
|
|
721
|
-
if (this
|
|
761
|
+
if (this[clientConfigSymbol] && this[clientConfigSymbol].allowReconfigure === false) {
|
|
722
762
|
throw new Error(
|
|
723
763
|
'Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client',
|
|
724
764
|
)
|
|
@@ -728,7 +768,7 @@ export class SanityClient {
|
|
|
728
768
|
this.observable.config(newConfig)
|
|
729
769
|
}
|
|
730
770
|
|
|
731
|
-
this
|
|
771
|
+
this[clientConfigSymbol] = initConfig(newConfig, this[clientConfigSymbol] || {})
|
|
732
772
|
return this
|
|
733
773
|
}
|
|
734
774
|
|
|
@@ -738,7 +778,17 @@ export class SanityClient {
|
|
|
738
778
|
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
739
779
|
*/
|
|
740
780
|
withConfig(newConfig?: Partial<ClientConfig>): SanityClient {
|
|
741
|
-
|
|
781
|
+
const thisConfig = this.config()
|
|
782
|
+
return new SanityClient(this[httpRequestSymbol], {
|
|
783
|
+
...thisConfig,
|
|
784
|
+
...newConfig,
|
|
785
|
+
stega: {
|
|
786
|
+
...(thisConfig.stega || {}),
|
|
787
|
+
...(typeof newConfig?.stega === 'boolean'
|
|
788
|
+
? {enabled: newConfig.stega}
|
|
789
|
+
: newConfig?.stega || {}),
|
|
790
|
+
},
|
|
791
|
+
})
|
|
742
792
|
}
|
|
743
793
|
|
|
744
794
|
/**
|
|
@@ -746,25 +796,22 @@ export class SanityClient {
|
|
|
746
796
|
*
|
|
747
797
|
* @param query - GROQ-query to perform
|
|
748
798
|
*/
|
|
749
|
-
fetch<
|
|
799
|
+
fetch<
|
|
800
|
+
R = Any,
|
|
801
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
802
|
+
Q extends never | undefined | Record<string, never> = never,
|
|
803
|
+
>(query: string): Promise<R>
|
|
750
804
|
/**
|
|
751
805
|
* Perform a GROQ-query against the configured dataset.
|
|
752
806
|
*
|
|
753
807
|
* @param query - GROQ-query to perform
|
|
754
808
|
* @param params - Optional query parameters
|
|
809
|
+
* @param options - Optional request options
|
|
755
810
|
*/
|
|
756
|
-
fetch<R = Any, Q =
|
|
757
|
-
/**
|
|
758
|
-
* Perform a GROQ-query against the configured dataset.
|
|
759
|
-
*
|
|
760
|
-
* @param query - GROQ-query to perform
|
|
761
|
-
* @param params - Optional query parameters
|
|
762
|
-
* @param options - Request options
|
|
763
|
-
*/
|
|
764
|
-
fetch<R = Any, Q = QueryParams>(
|
|
811
|
+
fetch<R = Any, Q = QueryParamsWithoutQueryOptions>(
|
|
765
812
|
query: string,
|
|
766
|
-
params: Q
|
|
767
|
-
options
|
|
813
|
+
params: QueryParamsParameter<Q>,
|
|
814
|
+
options?: FilteredResponseQueryOptions,
|
|
768
815
|
): Promise<R>
|
|
769
816
|
/**
|
|
770
817
|
* Perform a GROQ-query against the configured dataset.
|
|
@@ -773,17 +820,45 @@ export class SanityClient {
|
|
|
773
820
|
* @param params - Optional query parameters
|
|
774
821
|
* @param options - Request options
|
|
775
822
|
*/
|
|
776
|
-
fetch<R = Any, Q =
|
|
823
|
+
fetch<R = Any, Q = QueryParamsWithoutQueryOptions>(
|
|
777
824
|
query: string,
|
|
778
|
-
params: Q
|
|
825
|
+
params: QueryParamsParameter<Q>,
|
|
779
826
|
options: UnfilteredResponseQueryOptions,
|
|
780
827
|
): Promise<RawQueryResponse<R>>
|
|
828
|
+
/**
|
|
829
|
+
* You're passing in query parameters to a GROQ query that looks like query options.
|
|
830
|
+
* This is likely a mistake, you can either:
|
|
831
|
+
* a) replace the second argument with an empty object, and move the options to the third argument
|
|
832
|
+
* ```diff
|
|
833
|
+
* -client.fetch(query, {cache: 'no-store'})
|
|
834
|
+
* +client.fetch(query, {}, {cache: 'no-store'})
|
|
835
|
+
* ```
|
|
836
|
+
* b) add a generic type parameter that allows the query parameters to be passed in to silence the error
|
|
837
|
+
* @deprecated not actually deprecated, marking it as deprecated makes this error easier to spot
|
|
838
|
+
*/
|
|
839
|
+
fetch<
|
|
840
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
841
|
+
R = Any,
|
|
842
|
+
>(
|
|
843
|
+
query: string,
|
|
844
|
+
params: QueryParamsLikelyByMistake & QueryParams,
|
|
845
|
+
options?: QueryOptions,
|
|
846
|
+
): unknown
|
|
781
847
|
fetch<R, Q extends QueryParams>(
|
|
782
848
|
query: string,
|
|
783
849
|
params?: Q,
|
|
784
|
-
options
|
|
850
|
+
options?: QueryOptions,
|
|
785
851
|
): Promise<RawQueryResponse<R> | R> {
|
|
786
|
-
return lastValueFrom(
|
|
852
|
+
return lastValueFrom(
|
|
853
|
+
dataMethods._fetch<R, Q>(
|
|
854
|
+
this,
|
|
855
|
+
this[httpRequestSymbol],
|
|
856
|
+
this[clientConfigSymbol].stega,
|
|
857
|
+
query,
|
|
858
|
+
params,
|
|
859
|
+
options,
|
|
860
|
+
),
|
|
861
|
+
)
|
|
787
862
|
}
|
|
788
863
|
|
|
789
864
|
/**
|
|
@@ -796,7 +871,7 @@ export class SanityClient {
|
|
|
796
871
|
id: string,
|
|
797
872
|
options?: {tag?: string},
|
|
798
873
|
): Promise<SanityDocument<R> | undefined> {
|
|
799
|
-
return lastValueFrom(dataMethods._getDocument<R>(this, this
|
|
874
|
+
return lastValueFrom(dataMethods._getDocument<R>(this, this[httpRequestSymbol], id, options))
|
|
800
875
|
}
|
|
801
876
|
|
|
802
877
|
/**
|
|
@@ -812,7 +887,7 @@ export class SanityClient {
|
|
|
812
887
|
ids: string[],
|
|
813
888
|
options?: {tag?: string},
|
|
814
889
|
): Promise<(SanityDocument<R> | null)[]> {
|
|
815
|
-
return lastValueFrom(dataMethods._getDocuments<R>(this, this
|
|
890
|
+
return lastValueFrom(dataMethods._getDocuments<R>(this, this[httpRequestSymbol], ids, options))
|
|
816
891
|
}
|
|
817
892
|
|
|
818
893
|
/**
|
|
@@ -882,7 +957,7 @@ export class SanityClient {
|
|
|
882
957
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
883
958
|
> {
|
|
884
959
|
return lastValueFrom(
|
|
885
|
-
dataMethods._create<R>(this, this
|
|
960
|
+
dataMethods._create<R>(this, this[httpRequestSymbol], document, 'create', options),
|
|
886
961
|
)
|
|
887
962
|
}
|
|
888
963
|
|
|
@@ -953,7 +1028,7 @@ export class SanityClient {
|
|
|
953
1028
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
954
1029
|
> {
|
|
955
1030
|
return lastValueFrom(
|
|
956
|
-
dataMethods._createIfNotExists<R>(this, this
|
|
1031
|
+
dataMethods._createIfNotExists<R>(this, this[httpRequestSymbol], document, options),
|
|
957
1032
|
)
|
|
958
1033
|
}
|
|
959
1034
|
|
|
@@ -1024,7 +1099,7 @@ export class SanityClient {
|
|
|
1024
1099
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
1025
1100
|
> {
|
|
1026
1101
|
return lastValueFrom(
|
|
1027
|
-
dataMethods._createOrReplace<R>(this, this
|
|
1102
|
+
dataMethods._createOrReplace<R>(this, this[httpRequestSymbol], document, options),
|
|
1028
1103
|
)
|
|
1029
1104
|
}
|
|
1030
1105
|
|
|
@@ -1143,7 +1218,7 @@ export class SanityClient {
|
|
|
1143
1218
|
): Promise<
|
|
1144
1219
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
1145
1220
|
> {
|
|
1146
|
-
return lastValueFrom(dataMethods._delete<R>(this, this
|
|
1221
|
+
return lastValueFrom(dataMethods._delete<R>(this, this[httpRequestSymbol], selection, options))
|
|
1147
1222
|
}
|
|
1148
1223
|
|
|
1149
1224
|
/**
|
|
@@ -1212,7 +1287,7 @@ export class SanityClient {
|
|
|
1212
1287
|
): Promise<
|
|
1213
1288
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
1214
1289
|
> {
|
|
1215
|
-
return lastValueFrom(dataMethods._mutate<R>(this, this
|
|
1290
|
+
return lastValueFrom(dataMethods._mutate<R>(this, this[httpRequestSymbol], operations, options))
|
|
1216
1291
|
}
|
|
1217
1292
|
|
|
1218
1293
|
/**
|
|
@@ -1272,7 +1347,7 @@ export class SanityClient {
|
|
|
1272
1347
|
* @returns Promise resolving to the response body
|
|
1273
1348
|
*/
|
|
1274
1349
|
request<R = Any>(options: RawRequestOptions): Promise<R> {
|
|
1275
|
-
return lastValueFrom(dataMethods._request<R>(this, this
|
|
1350
|
+
return lastValueFrom(dataMethods._request<R>(this, this[httpRequestSymbol], options))
|
|
1276
1351
|
}
|
|
1277
1352
|
|
|
1278
1353
|
/**
|
|
@@ -1286,7 +1361,9 @@ export class SanityClient {
|
|
|
1286
1361
|
* @internal
|
|
1287
1362
|
*/
|
|
1288
1363
|
dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any> {
|
|
1289
|
-
return lastValueFrom(
|
|
1364
|
+
return lastValueFrom(
|
|
1365
|
+
dataMethods._dataRequest(this, this[httpRequestSymbol], endpoint, body, options),
|
|
1366
|
+
)
|
|
1290
1367
|
}
|
|
1291
1368
|
|
|
1292
1369
|
/**
|
|
@@ -15,13 +15,16 @@ import type {
|
|
|
15
15
|
} from '../types'
|
|
16
16
|
import * as validators from '../validators'
|
|
17
17
|
|
|
18
|
+
const clientSymbol = Symbol('#client')
|
|
19
|
+
const httpRequestSymbol = Symbol('#httpRequest')
|
|
20
|
+
|
|
18
21
|
/** @internal */
|
|
19
22
|
export class ObservableAssetsClient {
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
private [clientSymbol]: ObservableSanityClient
|
|
24
|
+
private [httpRequestSymbol]: HttpRequest
|
|
22
25
|
constructor(client: ObservableSanityClient, httpRequest: HttpRequest) {
|
|
23
|
-
this
|
|
24
|
-
this
|
|
26
|
+
this[clientSymbol] = client
|
|
27
|
+
this[httpRequestSymbol] = httpRequest
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
/**
|
|
@@ -66,17 +69,17 @@ export class ObservableAssetsClient {
|
|
|
66
69
|
body: UploadBody,
|
|
67
70
|
options?: UploadClientConfig,
|
|
68
71
|
): Observable<HttpRequestEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>> {
|
|
69
|
-
return _upload(this
|
|
72
|
+
return _upload(this[clientSymbol], this[httpRequestSymbol], assetType, body, options)
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
/** @internal */
|
|
74
77
|
export class AssetsClient {
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
private [clientSymbol]: SanityClient
|
|
79
|
+
private [httpRequestSymbol]: HttpRequest
|
|
77
80
|
constructor(client: SanityClient, httpRequest: HttpRequest) {
|
|
78
|
-
this
|
|
79
|
-
this
|
|
81
|
+
this[clientSymbol] = client
|
|
82
|
+
this[httpRequestSymbol] = httpRequest
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
/**
|
|
@@ -120,7 +123,13 @@ export class AssetsClient {
|
|
|
120
123
|
body: UploadBody,
|
|
121
124
|
options?: UploadClientConfig,
|
|
122
125
|
): Promise<SanityAssetDocument | SanityImageAssetDocument> {
|
|
123
|
-
const observable = _upload(
|
|
126
|
+
const observable = _upload(
|
|
127
|
+
this[clientSymbol],
|
|
128
|
+
this[httpRequestSymbol],
|
|
129
|
+
assetType,
|
|
130
|
+
body,
|
|
131
|
+
options,
|
|
132
|
+
)
|
|
124
133
|
return lastValueFrom(
|
|
125
134
|
observable.pipe(
|
|
126
135
|
filter((event: Any) => event.type === 'response'),
|
package/src/config.ts
CHANGED
|
@@ -8,6 +8,7 @@ export const defaultConfig = {
|
|
|
8
8
|
apiHost: 'https://api.sanity.io',
|
|
9
9
|
apiVersion: '1',
|
|
10
10
|
useProjectHostname: true,
|
|
11
|
+
stega: {enabled: false},
|
|
11
12
|
} satisfies ClientConfig
|
|
12
13
|
|
|
13
14
|
const LOCALHOSTS = ['localhost', '127.0.0.1', '0.0.0.0']
|
|
@@ -44,12 +45,24 @@ export const initConfig = (
|
|
|
44
45
|
config: Partial<ClientConfig>,
|
|
45
46
|
prevConfig: Partial<ClientConfig>,
|
|
46
47
|
): InitializedClientConfig => {
|
|
47
|
-
const specifiedConfig =
|
|
48
|
+
const specifiedConfig = {
|
|
49
|
+
...prevConfig,
|
|
50
|
+
...config,
|
|
51
|
+
stega: {
|
|
52
|
+
...(typeof prevConfig.stega === 'boolean'
|
|
53
|
+
? {enabled: prevConfig.stega}
|
|
54
|
+
: prevConfig.stega || defaultConfig.stega),
|
|
55
|
+
...(typeof config.stega === 'boolean' ? {enabled: config.stega} : config.stega || {}),
|
|
56
|
+
},
|
|
57
|
+
}
|
|
48
58
|
if (!specifiedConfig.apiVersion) {
|
|
49
59
|
warnings.printNoApiVersionSpecifiedWarning()
|
|
50
60
|
}
|
|
51
61
|
|
|
52
|
-
const newConfig =
|
|
62
|
+
const newConfig = {
|
|
63
|
+
...defaultConfig,
|
|
64
|
+
...specifiedConfig,
|
|
65
|
+
} as InitializedClientConfig
|
|
53
66
|
const projectBased = newConfig.useProjectHostname
|
|
54
67
|
|
|
55
68
|
if (typeof Promise === 'undefined') {
|
|
@@ -65,20 +78,29 @@ export const initConfig = (
|
|
|
65
78
|
validateApiPerspective(newConfig.perspective)
|
|
66
79
|
}
|
|
67
80
|
|
|
68
|
-
if (
|
|
69
|
-
'encodeSourceMapAtPath' in newConfig ||
|
|
70
|
-
'encodeSourceMap' in newConfig ||
|
|
71
|
-
'studioUrl' in newConfig ||
|
|
72
|
-
'logger' in newConfig
|
|
73
|
-
) {
|
|
81
|
+
if ('encodeSourceMap' in newConfig) {
|
|
74
82
|
throw new Error(
|
|
75
|
-
`It looks like you're using options meant for '@sanity/preview-kit/client'
|
|
83
|
+
`It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMap' is not supported in '@sanity/client'. Did you mean 'stega.enabled'?`,
|
|
76
84
|
)
|
|
77
85
|
}
|
|
78
|
-
|
|
79
|
-
|
|
86
|
+
if ('encodeSourceMapAtPath' in newConfig) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMapAtPath' is not supported in '@sanity/client'. Did you mean 'stega.filter'?`,
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
if (typeof newConfig.stega.enabled !== 'boolean') {
|
|
92
|
+
throw new Error(`stega.enabled must be a boolean, received ${newConfig.stega.enabled}`)
|
|
93
|
+
}
|
|
94
|
+
if (newConfig.stega.enabled && newConfig.stega.studioUrl === undefined) {
|
|
95
|
+
throw new Error(`stega.studioUrl must be defined when stega.enabled is true`)
|
|
96
|
+
}
|
|
97
|
+
if (
|
|
98
|
+
newConfig.stega.enabled &&
|
|
99
|
+
typeof newConfig.stega.studioUrl !== 'string' &&
|
|
100
|
+
typeof newConfig.stega.studioUrl !== 'function'
|
|
101
|
+
) {
|
|
80
102
|
throw new Error(
|
|
81
|
-
`
|
|
103
|
+
`stega.studioUrl must be a string or a function, received ${newConfig.stega.studioUrl}`,
|
|
82
104
|
)
|
|
83
105
|
}
|
|
84
106
|
|