@sanity/client 6.12.2 → 6.12.3
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/dist/_chunks/browserMiddleware-IWUpjfF7.cjs.map +1 -1
- package/dist/_chunks/browserMiddleware-zDVeirri.js.map +1 -1
- package/dist/_chunks/{nodeMiddleware-WxY6WiGP.cjs → nodeMiddleware-Gh18jsRe.cjs} +3 -3
- package/dist/_chunks/nodeMiddleware-Gh18jsRe.cjs.map +1 -0
- package/dist/_chunks/{nodeMiddleware-itgO-mht.js → nodeMiddleware-OX5-R8Hk.js} +3 -3
- package/dist/_chunks/nodeMiddleware-OX5-R8Hk.js.map +1 -0
- package/dist/_chunks/{stegaEncodeSourceMap-6b6FFhTO.js → stegaEncodeSourceMap-OKnT3zAM.js} +2 -2
- package/dist/_chunks/{stegaEncodeSourceMap-6b6FFhTO.js.map → stegaEncodeSourceMap-OKnT3zAM.js.map} +1 -1
- package/dist/_chunks/{stegaEncodeSourceMap-d-bYFA5X.cjs → stegaEncodeSourceMap-ZDmZYDbM.cjs} +2 -2
- package/dist/_chunks/{stegaEncodeSourceMap-d-bYFA5X.cjs.map → stegaEncodeSourceMap-ZDmZYDbM.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +61 -118
- package/dist/index.js +2 -2
- package/dist/stega.cjs +2 -2
- package/dist/stega.d.ts +61 -118
- package/dist/stega.js +3 -3
- package/package.json +1 -1
- package/src/SanityClient.ts +25 -76
- package/src/data/encodeQueryString.ts +2 -2
- package/src/data/listen.ts +4 -4
- package/src/types.ts +36 -52
- package/dist/_chunks/nodeMiddleware-WxY6WiGP.cjs.map +0 -1
- package/dist/_chunks/nodeMiddleware-itgO-mht.js.map +0 -1
package/dist/stega.d.ts
CHANGED
|
@@ -324,7 +324,12 @@ export declare interface ClientConfig {
|
|
|
324
324
|
/**
|
|
325
325
|
*@deprecated set `cache` and `next` options on `client.fetch` instead
|
|
326
326
|
*/
|
|
327
|
-
fetch?:
|
|
327
|
+
fetch?:
|
|
328
|
+
| {
|
|
329
|
+
cache?: ResponseQueryOptions['cache']
|
|
330
|
+
next?: ResponseQueryOptions['next']
|
|
331
|
+
}
|
|
332
|
+
| boolean
|
|
328
333
|
/**
|
|
329
334
|
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
330
335
|
*/
|
|
@@ -704,7 +709,7 @@ export declare type InsertPatch =
|
|
|
704
709
|
export declare function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
705
710
|
this: SanityClient | ObservableSanityClient,
|
|
706
711
|
query: string,
|
|
707
|
-
params?:
|
|
712
|
+
params?: ListenParams,
|
|
708
713
|
): Observable<MutationEvent_2<R>>
|
|
709
714
|
|
|
710
715
|
/**
|
|
@@ -718,7 +723,7 @@ export declare function _listen<R extends Record<string, Any> = Record<string, A
|
|
|
718
723
|
export declare function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
719
724
|
this: SanityClient | ObservableSanityClient,
|
|
720
725
|
query: string,
|
|
721
|
-
params?:
|
|
726
|
+
params?: ListenParams,
|
|
722
727
|
options?: ListenOptions,
|
|
723
728
|
): Observable<ListenEvent<R>>
|
|
724
729
|
|
|
@@ -788,6 +793,11 @@ export declare interface ListenOptions {
|
|
|
788
793
|
tag?: string
|
|
789
794
|
}
|
|
790
795
|
|
|
796
|
+
/** @public */
|
|
797
|
+
export declare type ListenParams = {
|
|
798
|
+
[key: string]: Any
|
|
799
|
+
}
|
|
800
|
+
|
|
791
801
|
/** @public */
|
|
792
802
|
export declare type Logger =
|
|
793
803
|
| typeof console
|
|
@@ -945,12 +955,17 @@ export declare type MutationOperation = 'create' | 'delete' | 'update' | 'none'
|
|
|
945
955
|
export declare type MutationSelection =
|
|
946
956
|
| {
|
|
947
957
|
query: string
|
|
948
|
-
params?:
|
|
958
|
+
params?: MutationSelectionQueryParams
|
|
949
959
|
}
|
|
950
960
|
| {
|
|
951
961
|
id: string | string[]
|
|
952
962
|
}
|
|
953
963
|
|
|
964
|
+
/** @internal */
|
|
965
|
+
export declare type MutationSelectionQueryParams = {
|
|
966
|
+
[key: string]: Any
|
|
967
|
+
}
|
|
968
|
+
|
|
954
969
|
/** @internal */
|
|
955
970
|
export declare class ObservableAssetsClient {
|
|
956
971
|
#private
|
|
@@ -1155,54 +1170,34 @@ export declare class ObservableSanityClient {
|
|
|
1155
1170
|
*
|
|
1156
1171
|
* @param query - GROQ-query to perform
|
|
1157
1172
|
*/
|
|
1158
|
-
fetch<R = Any
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
* @param query - GROQ-query to perform
|
|
1163
|
-
* @param params - Query parameters
|
|
1164
|
-
*/
|
|
1165
|
-
fetch<R = Any, Q = QueryParamsWithoutQueryOptions>(query: string, params: Q): Observable<R>
|
|
1173
|
+
fetch<R = Any, Q extends QueryWithoutParams = QueryWithoutParams>(
|
|
1174
|
+
query: string,
|
|
1175
|
+
params?: Q | QueryWithoutParams,
|
|
1176
|
+
): Observable<R>
|
|
1166
1177
|
/**
|
|
1167
1178
|
* Perform a GROQ-query against the configured dataset.
|
|
1168
1179
|
*
|
|
1169
1180
|
* @param query - GROQ-query to perform
|
|
1170
|
-
* @param params -
|
|
1171
|
-
* @param options -
|
|
1181
|
+
* @param params - Optional query parameters
|
|
1182
|
+
* @param options - Optional request options
|
|
1172
1183
|
*/
|
|
1173
|
-
fetch<R = Any, Q =
|
|
1184
|
+
fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
|
|
1174
1185
|
query: string,
|
|
1175
|
-
params: Q
|
|
1176
|
-
options
|
|
1186
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
1187
|
+
options?: FilteredResponseQueryOptions,
|
|
1177
1188
|
): Observable<R>
|
|
1178
1189
|
/**
|
|
1179
1190
|
* Perform a GROQ-query against the configured dataset.
|
|
1180
1191
|
*
|
|
1181
1192
|
* @param query - GROQ-query to perform
|
|
1182
|
-
* @param params -
|
|
1193
|
+
* @param params - Optional query parameters
|
|
1183
1194
|
* @param options - Request options
|
|
1184
1195
|
*/
|
|
1185
|
-
fetch<R = Any, Q =
|
|
1196
|
+
fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
|
|
1186
1197
|
query: string,
|
|
1187
|
-
params: Q
|
|
1198
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
1188
1199
|
options: UnfilteredResponseQueryOptions,
|
|
1189
1200
|
): Observable<RawQueryResponse<R>>
|
|
1190
|
-
/**
|
|
1191
|
-
* You're passing in query parameters to a GROQ query that looks like query options.
|
|
1192
|
-
* This is likely a mistake, you can either:
|
|
1193
|
-
* a) replace the second argument with an empty object, and move the options to the third argument
|
|
1194
|
-
* ```diff
|
|
1195
|
-
* -client.fetch(query, {cache: 'no-store'})
|
|
1196
|
-
* +client.fetch(query, {}, {cache: 'no-store'})
|
|
1197
|
-
* ```
|
|
1198
|
-
* b) add a generic type parameter that allows the query parameters to be passed in to silence the error
|
|
1199
|
-
* @deprecated not actually deprecated, marking it as deprecated makes this error easier to spot
|
|
1200
|
-
*/
|
|
1201
|
-
fetch<R = Any>(
|
|
1202
|
-
query: string,
|
|
1203
|
-
params: QueryParamsLikelyByMistake & QueryParams,
|
|
1204
|
-
options?: QueryOptions,
|
|
1205
|
-
): unknown
|
|
1206
1201
|
/**
|
|
1207
1202
|
* Fetch a single document with the given ID.
|
|
1208
1203
|
*
|
|
@@ -1799,68 +1794,45 @@ export declare class ProjectsClient {
|
|
|
1799
1794
|
export declare type QueryOptions = FilteredResponseQueryOptions | UnfilteredResponseQueryOptions
|
|
1800
1795
|
|
|
1801
1796
|
/** @public */
|
|
1802
|
-
export declare
|
|
1803
|
-
[key: string]:
|
|
1804
|
-
}
|
|
1805
|
-
|
|
1806
|
-
/**
|
|
1807
|
-
* It's easy to accidentally set query options such as `filterResponse`, `cache` and `next` as the second parameter in `client.fetch`,
|
|
1808
|
-
* as that is a wide type used to set GROQ query paramaters and it accepts anything that can serialize to JSON.
|
|
1809
|
-
* This type is used to prevent that, and will cause a type error if you try to pass a query option as the second parameter.
|
|
1810
|
-
* If this type is `never`, it means `_QueryParamsLikelyByMistake` is missing keys from `QueryOptions`.
|
|
1811
|
-
* @internal
|
|
1812
|
-
*/
|
|
1813
|
-
export declare type QueryParamsLikelyByMistake =
|
|
1814
|
-
Required<_QueryParamsLikelyByMistake> extends Record<keyof QueryOptions, Any>
|
|
1815
|
-
? _QueryParamsLikelyByMistake
|
|
1816
|
-
: never
|
|
1817
|
-
|
|
1818
|
-
/**
|
|
1819
|
-
* Verify this type has all the same keys as QueryOptions before exporting
|
|
1820
|
-
* @internal
|
|
1821
|
-
*/
|
|
1822
|
-
export declare type _QueryParamsLikelyByMistake = {
|
|
1797
|
+
export declare interface QueryParams {
|
|
1798
|
+
[key: string]: any
|
|
1823
1799
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1824
|
-
body?:
|
|
1800
|
+
body?: never
|
|
1825
1801
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1826
|
-
cache?:
|
|
1802
|
+
cache?: 'next' extends keyof RequestInit ? never : any
|
|
1827
1803
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1828
|
-
filterResponse?:
|
|
1804
|
+
filterResponse?: never
|
|
1829
1805
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1830
|
-
headers?:
|
|
1806
|
+
headers?: never
|
|
1831
1807
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1832
|
-
method?:
|
|
1808
|
+
method?: never
|
|
1833
1809
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1834
|
-
next?:
|
|
1810
|
+
next?: 'next' extends keyof RequestInit ? never : any
|
|
1835
1811
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1836
|
-
perspective?:
|
|
1812
|
+
perspective?: never
|
|
1837
1813
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1838
|
-
query?:
|
|
1814
|
+
query?: never
|
|
1839
1815
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1840
|
-
resultSourceMap?:
|
|
1816
|
+
resultSourceMap?: never
|
|
1841
1817
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1842
|
-
signal?:
|
|
1818
|
+
signal?: never
|
|
1843
1819
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1844
|
-
stega?:
|
|
1820
|
+
stega?: never
|
|
1845
1821
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1846
|
-
tag?:
|
|
1822
|
+
tag?: never
|
|
1847
1823
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1848
|
-
timeout?:
|
|
1824
|
+
timeout?: never
|
|
1849
1825
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1850
|
-
token?:
|
|
1826
|
+
token?: never
|
|
1851
1827
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1852
|
-
useCdn?:
|
|
1828
|
+
useCdn?: never
|
|
1853
1829
|
}
|
|
1854
1830
|
|
|
1855
1831
|
/**
|
|
1856
|
-
*
|
|
1857
|
-
*
|
|
1858
|
-
* This type is used to prevent that, and will cause a type error if you try to pass a query option as the second parameter.
|
|
1859
|
-
* @internal
|
|
1832
|
+
* This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
|
|
1833
|
+
* @public
|
|
1860
1834
|
*/
|
|
1861
|
-
export declare type
|
|
1862
|
-
[K in keyof _QueryParamsLikelyByMistake]: never
|
|
1863
|
-
} & QueryParams
|
|
1835
|
+
export declare type QueryWithoutParams = Record<string, never> | undefined
|
|
1864
1836
|
|
|
1865
1837
|
/** @public */
|
|
1866
1838
|
export declare interface RawQueryResponse<R> {
|
|
@@ -1904,15 +1876,6 @@ export declare type ReconnectEvent = {
|
|
|
1904
1876
|
/** @public */
|
|
1905
1877
|
export declare const requester: Requester
|
|
1906
1878
|
|
|
1907
|
-
/**
|
|
1908
|
-
* Options for the native `fetch` feature, used by the Next.js app-router
|
|
1909
|
-
* @public
|
|
1910
|
-
*/
|
|
1911
|
-
export declare interface RequestFetchOptions<T = 'next'> {
|
|
1912
|
-
cache?: RequestInit['cache']
|
|
1913
|
-
next?: T extends keyof RequestInit ? RequestInit[T] : never
|
|
1914
|
-
}
|
|
1915
|
-
|
|
1916
1879
|
/** @internal */
|
|
1917
1880
|
export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
|
|
1918
1881
|
url?: string
|
|
@@ -2014,25 +1977,21 @@ export declare class SanityClient {
|
|
|
2014
1977
|
*
|
|
2015
1978
|
* @param query - GROQ-query to perform
|
|
2016
1979
|
*/
|
|
2017
|
-
fetch<R = Any
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
* @param query - GROQ-query to perform
|
|
2022
|
-
* @param params - Optional query parameters
|
|
2023
|
-
*/
|
|
2024
|
-
fetch<R = Any, Q = QueryParamsWithoutQueryOptions>(query: string, params: Q): Promise<R>
|
|
1980
|
+
fetch<R = Any, Q extends QueryWithoutParams = QueryWithoutParams>(
|
|
1981
|
+
query: string,
|
|
1982
|
+
params?: Q | QueryWithoutParams,
|
|
1983
|
+
): Promise<R>
|
|
2025
1984
|
/**
|
|
2026
1985
|
* Perform a GROQ-query against the configured dataset.
|
|
2027
1986
|
*
|
|
2028
1987
|
* @param query - GROQ-query to perform
|
|
2029
1988
|
* @param params - Optional query parameters
|
|
2030
|
-
* @param options -
|
|
1989
|
+
* @param options - Optional request options
|
|
2031
1990
|
*/
|
|
2032
|
-
fetch<R = Any, Q =
|
|
1991
|
+
fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
|
|
2033
1992
|
query: string,
|
|
2034
|
-
params: Q
|
|
2035
|
-
options
|
|
1993
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
1994
|
+
options?: FilteredResponseQueryOptions,
|
|
2036
1995
|
): Promise<R>
|
|
2037
1996
|
/**
|
|
2038
1997
|
* Perform a GROQ-query against the configured dataset.
|
|
@@ -2041,27 +2000,11 @@ export declare class SanityClient {
|
|
|
2041
2000
|
* @param params - Optional query parameters
|
|
2042
2001
|
* @param options - Request options
|
|
2043
2002
|
*/
|
|
2044
|
-
fetch<R = Any, Q =
|
|
2003
|
+
fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
|
|
2045
2004
|
query: string,
|
|
2046
|
-
params: Q
|
|
2005
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
2047
2006
|
options: UnfilteredResponseQueryOptions,
|
|
2048
2007
|
): Promise<RawQueryResponse<R>>
|
|
2049
|
-
/**
|
|
2050
|
-
* You're passing in query parameters to a GROQ query that looks like query options.
|
|
2051
|
-
* This is likely a mistake, you can either:
|
|
2052
|
-
* a) replace the second argument with an empty object, and move the options to the third argument
|
|
2053
|
-
* ```diff
|
|
2054
|
-
* -client.fetch(query, {cache: 'no-store'})
|
|
2055
|
-
* +client.fetch(query, {}, {cache: 'no-store'})
|
|
2056
|
-
* ```
|
|
2057
|
-
* b) add a generic type parameter that allows the query parameters to be passed in to silence the error
|
|
2058
|
-
* @deprecated not actually deprecated, marking it as deprecated makes this error easier to spot
|
|
2059
|
-
*/
|
|
2060
|
-
fetch<R = Any>(
|
|
2061
|
-
query: string,
|
|
2062
|
-
params: QueryParamsLikelyByMistake & QueryParams,
|
|
2063
|
-
options?: QueryOptions,
|
|
2064
|
-
): unknown
|
|
2065
2008
|
/**
|
|
2066
2009
|
* Fetch a single document with the given ID.
|
|
2067
2010
|
*
|
package/dist/stega.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { SanityClient, ObservableSanityClient, defineCreateClientExports, middleware } from './_chunks/nodeMiddleware-
|
|
2
|
-
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableTransaction, Patch, ServerError, Transaction, vercelStegaCleanAll } from './_chunks/nodeMiddleware-
|
|
1
|
+
import { SanityClient, ObservableSanityClient, defineCreateClientExports, middleware } from './_chunks/nodeMiddleware-OX5-R8Hk.js';
|
|
2
|
+
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableTransaction, Patch, ServerError, Transaction, vercelStegaCleanAll } from './_chunks/nodeMiddleware-OX5-R8Hk.js';
|
|
3
3
|
export { adapter as unstable__adapter, environment as unstable__environment } from 'get-it';
|
|
4
|
-
export { encodeIntoResult, stegaEncodeSourceMap } from './_chunks/stegaEncodeSourceMap-
|
|
4
|
+
export { encodeIntoResult, stegaEncodeSourceMap } from './_chunks/stegaEncodeSourceMap-OKnT3zAM.js';
|
|
5
5
|
|
|
6
6
|
class SanityStegaClient extends SanityClient {
|
|
7
7
|
}
|
package/package.json
CHANGED
package/src/SanityClient.ts
CHANGED
|
@@ -27,8 +27,7 @@ import type {
|
|
|
27
27
|
PatchSelection,
|
|
28
28
|
QueryOptions,
|
|
29
29
|
QueryParams,
|
|
30
|
-
|
|
31
|
-
QueryParamsWithoutQueryOptions,
|
|
30
|
+
QueryWithoutParams,
|
|
32
31
|
RawQueryResponse,
|
|
33
32
|
RawRequestOptions,
|
|
34
33
|
SanityDocument,
|
|
@@ -133,58 +132,35 @@ export class ObservableSanityClient {
|
|
|
133
132
|
*
|
|
134
133
|
* @param query - GROQ-query to perform
|
|
135
134
|
*/
|
|
136
|
-
fetch<R = Any
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
* @param query - GROQ-query to perform
|
|
141
|
-
* @param params - Query parameters
|
|
142
|
-
*/
|
|
143
|
-
fetch<R = Any, Q = QueryParamsWithoutQueryOptions>(query: string, params: Q): Observable<R>
|
|
135
|
+
fetch<R = Any, Q extends QueryWithoutParams = QueryWithoutParams>(
|
|
136
|
+
query: string,
|
|
137
|
+
params?: Q | QueryWithoutParams,
|
|
138
|
+
): Observable<R>
|
|
144
139
|
/**
|
|
145
140
|
* Perform a GROQ-query against the configured dataset.
|
|
146
141
|
*
|
|
147
142
|
* @param query - GROQ-query to perform
|
|
148
|
-
* @param params -
|
|
149
|
-
* @param options -
|
|
143
|
+
* @param params - Optional query parameters
|
|
144
|
+
* @param options - Optional request options
|
|
150
145
|
*/
|
|
151
|
-
fetch<R = Any, Q =
|
|
146
|
+
fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
|
|
152
147
|
query: string,
|
|
153
|
-
params: Q
|
|
154
|
-
options
|
|
148
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
149
|
+
options?: FilteredResponseQueryOptions,
|
|
155
150
|
): Observable<R>
|
|
156
151
|
/**
|
|
157
152
|
* Perform a GROQ-query against the configured dataset.
|
|
158
153
|
*
|
|
159
154
|
* @param query - GROQ-query to perform
|
|
160
|
-
* @param params -
|
|
155
|
+
* @param params - Optional query parameters
|
|
161
156
|
* @param options - Request options
|
|
162
157
|
*/
|
|
163
|
-
fetch<R = Any, Q =
|
|
158
|
+
fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
|
|
164
159
|
query: string,
|
|
165
|
-
params: Q
|
|
160
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
166
161
|
options: UnfilteredResponseQueryOptions,
|
|
167
162
|
): Observable<RawQueryResponse<R>>
|
|
168
|
-
|
|
169
|
-
* You're passing in query parameters to a GROQ query that looks like query options.
|
|
170
|
-
* This is likely a mistake, you can either:
|
|
171
|
-
* a) replace the second argument with an empty object, and move the options to the third argument
|
|
172
|
-
* ```diff
|
|
173
|
-
* -client.fetch(query, {cache: 'no-store'})
|
|
174
|
-
* +client.fetch(query, {}, {cache: 'no-store'})
|
|
175
|
-
* ```
|
|
176
|
-
* b) add a generic type parameter that allows the query parameters to be passed in to silence the error
|
|
177
|
-
* @deprecated not actually deprecated, marking it as deprecated makes this error easier to spot
|
|
178
|
-
*/
|
|
179
|
-
fetch<
|
|
180
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
181
|
-
R = Any,
|
|
182
|
-
>(
|
|
183
|
-
query: string,
|
|
184
|
-
params: QueryParamsLikelyByMistake & QueryParams,
|
|
185
|
-
options?: QueryOptions,
|
|
186
|
-
): unknown
|
|
187
|
-
fetch<R, Q extends QueryParams>(
|
|
163
|
+
fetch<R, Q>(
|
|
188
164
|
query: string,
|
|
189
165
|
params?: Q,
|
|
190
166
|
options?: QueryOptions,
|
|
@@ -795,25 +771,21 @@ export class SanityClient {
|
|
|
795
771
|
*
|
|
796
772
|
* @param query - GROQ-query to perform
|
|
797
773
|
*/
|
|
798
|
-
fetch<R = Any
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
* @param query - GROQ-query to perform
|
|
803
|
-
* @param params - Optional query parameters
|
|
804
|
-
*/
|
|
805
|
-
fetch<R = Any, Q = QueryParamsWithoutQueryOptions>(query: string, params: Q): Promise<R>
|
|
774
|
+
fetch<R = Any, Q extends QueryWithoutParams = QueryWithoutParams>(
|
|
775
|
+
query: string,
|
|
776
|
+
params?: Q | QueryWithoutParams,
|
|
777
|
+
): Promise<R>
|
|
806
778
|
/**
|
|
807
779
|
* Perform a GROQ-query against the configured dataset.
|
|
808
780
|
*
|
|
809
781
|
* @param query - GROQ-query to perform
|
|
810
782
|
* @param params - Optional query parameters
|
|
811
|
-
* @param options -
|
|
783
|
+
* @param options - Optional request options
|
|
812
784
|
*/
|
|
813
|
-
fetch<R = Any, Q =
|
|
785
|
+
fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
|
|
814
786
|
query: string,
|
|
815
|
-
params: Q
|
|
816
|
-
options
|
|
787
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
788
|
+
options?: FilteredResponseQueryOptions,
|
|
817
789
|
): Promise<R>
|
|
818
790
|
/**
|
|
819
791
|
* Perform a GROQ-query against the configured dataset.
|
|
@@ -822,35 +794,12 @@ export class SanityClient {
|
|
|
822
794
|
* @param params - Optional query parameters
|
|
823
795
|
* @param options - Request options
|
|
824
796
|
*/
|
|
825
|
-
fetch<R = Any, Q =
|
|
797
|
+
fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
|
|
826
798
|
query: string,
|
|
827
|
-
params: Q
|
|
799
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
828
800
|
options: UnfilteredResponseQueryOptions,
|
|
829
801
|
): Promise<RawQueryResponse<R>>
|
|
830
|
-
|
|
831
|
-
* You're passing in query parameters to a GROQ query that looks like query options.
|
|
832
|
-
* This is likely a mistake, you can either:
|
|
833
|
-
* a) replace the second argument with an empty object, and move the options to the third argument
|
|
834
|
-
* ```diff
|
|
835
|
-
* -client.fetch(query, {cache: 'no-store'})
|
|
836
|
-
* +client.fetch(query, {}, {cache: 'no-store'})
|
|
837
|
-
* ```
|
|
838
|
-
* b) add a generic type parameter that allows the query parameters to be passed in to silence the error
|
|
839
|
-
* @deprecated not actually deprecated, marking it as deprecated makes this error easier to spot
|
|
840
|
-
*/
|
|
841
|
-
fetch<
|
|
842
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
843
|
-
R = Any,
|
|
844
|
-
>(
|
|
845
|
-
query: string,
|
|
846
|
-
params: QueryParamsLikelyByMistake & QueryParams,
|
|
847
|
-
options?: QueryOptions,
|
|
848
|
-
): unknown
|
|
849
|
-
fetch<R, Q extends QueryParams>(
|
|
850
|
-
query: string,
|
|
851
|
-
params?: Q,
|
|
852
|
-
options?: QueryOptions,
|
|
853
|
-
): Promise<RawQueryResponse<R> | R> {
|
|
802
|
+
fetch<R, Q>(query: string, params?: Q, options?: QueryOptions): Promise<RawQueryResponse<R> | R> {
|
|
854
803
|
return lastValueFrom(
|
|
855
804
|
dataMethods._fetch<R, Q>(
|
|
856
805
|
this,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {Any, QueryParams} from '../types'
|
|
1
|
+
import type {Any, ListenParams, QueryParams} from '../types'
|
|
2
2
|
|
|
3
3
|
export const encodeQueryString = ({
|
|
4
4
|
query,
|
|
@@ -6,7 +6,7 @@ export const encodeQueryString = ({
|
|
|
6
6
|
options = {},
|
|
7
7
|
}: {
|
|
8
8
|
query: string
|
|
9
|
-
params?: QueryParams
|
|
9
|
+
params?: ListenParams | QueryParams
|
|
10
10
|
options?: Any
|
|
11
11
|
}) => {
|
|
12
12
|
const searchParams = new URLSearchParams()
|
package/src/data/listen.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Observable} from 'rxjs'
|
|
2
2
|
|
|
3
3
|
import type {ObservableSanityClient, SanityClient} from '../SanityClient'
|
|
4
|
-
import type {Any, ListenEvent, ListenOptions,
|
|
4
|
+
import type {Any, ListenEvent, ListenOptions, ListenParams, MutationEvent} from '../types'
|
|
5
5
|
import defaults from '../util/defaults'
|
|
6
6
|
import {pick} from '../util/pick'
|
|
7
7
|
import {_getDataUrl} from './dataMethods'
|
|
@@ -35,7 +35,7 @@ const defaultOptions = {
|
|
|
35
35
|
export function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
36
36
|
this: SanityClient | ObservableSanityClient,
|
|
37
37
|
query: string,
|
|
38
|
-
params?:
|
|
38
|
+
params?: ListenParams,
|
|
39
39
|
): Observable<MutationEvent<R>>
|
|
40
40
|
/**
|
|
41
41
|
* Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
|
|
@@ -48,14 +48,14 @@ export function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
|
48
48
|
export function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
49
49
|
this: SanityClient | ObservableSanityClient,
|
|
50
50
|
query: string,
|
|
51
|
-
params?:
|
|
51
|
+
params?: ListenParams,
|
|
52
52
|
options?: ListenOptions,
|
|
53
53
|
): Observable<ListenEvent<R>>
|
|
54
54
|
/** @public */
|
|
55
55
|
export function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
56
56
|
this: SanityClient | ObservableSanityClient,
|
|
57
57
|
query: string,
|
|
58
|
-
params?:
|
|
58
|
+
params?: ListenParams,
|
|
59
59
|
opts: ListenOptions = {},
|
|
60
60
|
): Observable<MutationEvent<R> | ListenEvent<R>> {
|
|
61
61
|
const {url, token, withCredentials, requestTagPrefix} = this.config()
|
package/src/types.ts
CHANGED
|
@@ -30,15 +30,6 @@ export interface RequestOptions {
|
|
|
30
30
|
signal?: AbortSignal
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
/**
|
|
34
|
-
* Options for the native `fetch` feature, used by the Next.js app-router
|
|
35
|
-
* @public
|
|
36
|
-
*/
|
|
37
|
-
export interface RequestFetchOptions<T = 'next'> {
|
|
38
|
-
cache?: RequestInit['cache']
|
|
39
|
-
next?: T extends keyof RequestInit ? RequestInit[T] : never
|
|
40
|
-
}
|
|
41
|
-
|
|
42
33
|
/** @public */
|
|
43
34
|
export type ClientPerspective = 'previewDrafts' | 'published' | 'raw'
|
|
44
35
|
|
|
@@ -90,7 +81,12 @@ export interface ClientConfig {
|
|
|
90
81
|
/**
|
|
91
82
|
*@deprecated set `cache` and `next` options on `client.fetch` instead
|
|
92
83
|
*/
|
|
93
|
-
fetch?:
|
|
84
|
+
fetch?:
|
|
85
|
+
| {
|
|
86
|
+
cache?: ResponseQueryOptions['cache']
|
|
87
|
+
next?: ResponseQueryOptions['next']
|
|
88
|
+
}
|
|
89
|
+
| boolean
|
|
94
90
|
/**
|
|
95
91
|
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
96
92
|
*/
|
|
@@ -434,69 +430,54 @@ export interface PatchOperations {
|
|
|
434
430
|
}
|
|
435
431
|
|
|
436
432
|
/** @public */
|
|
437
|
-
export
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
* Verify this type has all the same keys as QueryOptions before exporting
|
|
441
|
-
* @internal
|
|
442
|
-
*/
|
|
443
|
-
export type _QueryParamsLikelyByMistake = {
|
|
433
|
+
export interface QueryParams {
|
|
434
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
435
|
+
[key: string]: any
|
|
444
436
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
445
|
-
body?:
|
|
437
|
+
body?: never
|
|
446
438
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
447
|
-
cache?:
|
|
439
|
+
cache?: 'next' extends keyof RequestInit ? never : any
|
|
448
440
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
449
|
-
filterResponse?:
|
|
441
|
+
filterResponse?: never
|
|
450
442
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
451
|
-
headers?:
|
|
443
|
+
headers?: never
|
|
452
444
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
453
|
-
method?:
|
|
445
|
+
method?: never
|
|
454
446
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
455
|
-
next?:
|
|
447
|
+
next?: 'next' extends keyof RequestInit ? never : any
|
|
456
448
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
457
|
-
perspective?:
|
|
449
|
+
perspective?: never
|
|
458
450
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
459
|
-
query?:
|
|
451
|
+
query?: never
|
|
460
452
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
461
|
-
resultSourceMap?:
|
|
453
|
+
resultSourceMap?: never
|
|
462
454
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
463
|
-
signal?:
|
|
455
|
+
signal?: never
|
|
464
456
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
465
|
-
stega?:
|
|
457
|
+
stega?: never
|
|
466
458
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
467
|
-
tag?:
|
|
459
|
+
tag?: never
|
|
468
460
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
469
|
-
timeout?:
|
|
461
|
+
timeout?: never
|
|
470
462
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
471
|
-
token?:
|
|
463
|
+
token?: never
|
|
472
464
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
473
|
-
useCdn?:
|
|
465
|
+
useCdn?: never
|
|
466
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
474
467
|
}
|
|
475
468
|
|
|
476
469
|
/**
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
* This type is used to prevent that, and will cause a type error if you try to pass a query option as the second parameter.
|
|
480
|
-
* If this type is `never`, it means `_QueryParamsLikelyByMistake` is missing keys from `QueryOptions`.
|
|
481
|
-
* @internal
|
|
482
|
-
*/
|
|
483
|
-
export type QueryParamsLikelyByMistake =
|
|
484
|
-
Required<_QueryParamsLikelyByMistake> extends Record<keyof QueryOptions, Any>
|
|
485
|
-
? _QueryParamsLikelyByMistake
|
|
486
|
-
: never
|
|
487
|
-
|
|
488
|
-
/**
|
|
489
|
-
* It's easy to accidentally set query options such as `filterResponse`, `cache` and `next` as the second parameter in `client.fetch`,
|
|
490
|
-
* as that is a wide type used to set GROQ query paramaters and it accepts anything that can serialize to JSON.
|
|
491
|
-
* This type is used to prevent that, and will cause a type error if you try to pass a query option as the second parameter.
|
|
492
|
-
* @internal
|
|
470
|
+
* This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
|
|
471
|
+
* @public
|
|
493
472
|
*/
|
|
494
|
-
export type
|
|
495
|
-
[K in keyof _QueryParamsLikelyByMistake]: never
|
|
496
|
-
} & QueryParams
|
|
473
|
+
export type QueryWithoutParams = Record<string, never> | undefined
|
|
497
474
|
|
|
498
475
|
/** @internal */
|
|
499
|
-
export type
|
|
476
|
+
export type MutationSelectionQueryParams = {[key: string]: Any}
|
|
477
|
+
/** @internal */
|
|
478
|
+
export type MutationSelection =
|
|
479
|
+
| {query: string; params?: MutationSelectionQueryParams}
|
|
480
|
+
| {id: string | string[]}
|
|
500
481
|
/** @internal */
|
|
501
482
|
export type PatchSelection = string | string[] | MutationSelection
|
|
502
483
|
/** @internal */
|
|
@@ -679,6 +660,9 @@ export type ListenEventName =
|
|
|
679
660
|
/** The listener has been disconnected, and a reconnect attempt is scheduled */
|
|
680
661
|
| 'reconnect'
|
|
681
662
|
|
|
663
|
+
/** @public */
|
|
664
|
+
export type ListenParams = {[key: string]: Any}
|
|
665
|
+
|
|
682
666
|
/** @public */
|
|
683
667
|
export interface ListenOptions {
|
|
684
668
|
/**
|