@sanity/client 6.12.1 → 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-_KkwuHdG.cjs → nodeMiddleware-Gh18jsRe.cjs} +3 -3
- package/dist/_chunks/nodeMiddleware-Gh18jsRe.cjs.map +1 -0
- package/dist/_chunks/{nodeMiddleware-HdS59hO2.js → nodeMiddleware-OX5-R8Hk.js} +3 -3
- package/dist/_chunks/nodeMiddleware-OX5-R8Hk.js.map +1 -0
- package/dist/_chunks/{stegaEncodeSourceMap-PeZZ9GUr.js → stegaEncodeSourceMap-OKnT3zAM.js} +2 -2
- package/dist/_chunks/{stegaEncodeSourceMap-PeZZ9GUr.js.map → stegaEncodeSourceMap-OKnT3zAM.js.map} +1 -1
- package/dist/_chunks/{stegaEncodeSourceMap-xrSaflZH.cjs → stegaEncodeSourceMap-ZDmZYDbM.cjs} +2 -2
- package/dist/_chunks/{stegaEncodeSourceMap-xrSaflZH.cjs.map → stegaEncodeSourceMap-ZDmZYDbM.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +50 -110
- package/dist/index.js +2 -2
- package/dist/stega.cjs +2 -2
- package/dist/stega.d.ts +50 -110
- package/dist/stega.js +3 -3
- package/package.json +3 -3
- package/src/SanityClient.ts +19 -65
- package/src/data/encodeQueryString.ts +2 -2
- package/src/data/listen.ts +4 -4
- package/src/types.ts +35 -64
- package/dist/_chunks/nodeMiddleware-HdS59hO2.js.map +0 -1
- package/dist/_chunks/nodeMiddleware-_KkwuHdG.cjs.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,8 +1170,9 @@ export declare class ObservableSanityClient {
|
|
|
1155
1170
|
*
|
|
1156
1171
|
* @param query - GROQ-query to perform
|
|
1157
1172
|
*/
|
|
1158
|
-
fetch<R = Any, Q extends
|
|
1173
|
+
fetch<R = Any, Q extends QueryWithoutParams = QueryWithoutParams>(
|
|
1159
1174
|
query: string,
|
|
1175
|
+
params?: Q | QueryWithoutParams,
|
|
1160
1176
|
): Observable<R>
|
|
1161
1177
|
/**
|
|
1162
1178
|
* Perform a GROQ-query against the configured dataset.
|
|
@@ -1165,9 +1181,9 @@ export declare class ObservableSanityClient {
|
|
|
1165
1181
|
* @param params - Optional query parameters
|
|
1166
1182
|
* @param options - Optional request options
|
|
1167
1183
|
*/
|
|
1168
|
-
fetch<R = Any, Q =
|
|
1184
|
+
fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
|
|
1169
1185
|
query: string,
|
|
1170
|
-
params:
|
|
1186
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
1171
1187
|
options?: FilteredResponseQueryOptions,
|
|
1172
1188
|
): Observable<R>
|
|
1173
1189
|
/**
|
|
@@ -1177,27 +1193,11 @@ export declare class ObservableSanityClient {
|
|
|
1177
1193
|
* @param params - Optional query parameters
|
|
1178
1194
|
* @param options - Request options
|
|
1179
1195
|
*/
|
|
1180
|
-
fetch<R = Any, Q =
|
|
1196
|
+
fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
|
|
1181
1197
|
query: string,
|
|
1182
|
-
params:
|
|
1198
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
1183
1199
|
options: UnfilteredResponseQueryOptions,
|
|
1184
1200
|
): Observable<RawQueryResponse<R>>
|
|
1185
|
-
/**
|
|
1186
|
-
* You're passing in query parameters to a GROQ query that looks like query options.
|
|
1187
|
-
* This is likely a mistake, you can either:
|
|
1188
|
-
* a) replace the second argument with an empty object, and move the options to the third argument
|
|
1189
|
-
* ```diff
|
|
1190
|
-
* -client.fetch(query, {cache: 'no-store'})
|
|
1191
|
-
* +client.fetch(query, {}, {cache: 'no-store'})
|
|
1192
|
-
* ```
|
|
1193
|
-
* b) add a generic type parameter that allows the query parameters to be passed in to silence the error
|
|
1194
|
-
* @deprecated not actually deprecated, marking it as deprecated makes this error easier to spot
|
|
1195
|
-
*/
|
|
1196
|
-
fetch<R = Any>(
|
|
1197
|
-
query: string,
|
|
1198
|
-
params: QueryParamsLikelyByMistake & QueryParams,
|
|
1199
|
-
options?: QueryOptions,
|
|
1200
|
-
): unknown
|
|
1201
1201
|
/**
|
|
1202
1202
|
* Fetch a single document with the given ID.
|
|
1203
1203
|
*
|
|
@@ -1794,81 +1794,45 @@ export declare class ProjectsClient {
|
|
|
1794
1794
|
export declare type QueryOptions = FilteredResponseQueryOptions | UnfilteredResponseQueryOptions
|
|
1795
1795
|
|
|
1796
1796
|
/** @public */
|
|
1797
|
-
export declare
|
|
1798
|
-
[key: string]:
|
|
1799
|
-
}
|
|
1800
|
-
|
|
1801
|
-
/**
|
|
1802
|
-
* It's easy to accidentally set query options such as `filterResponse`, `cache` and `next` as the second parameter in `client.fetch`,
|
|
1803
|
-
* as that is a wide type used to set GROQ query paramaters and it accepts anything that can serialize to JSON.
|
|
1804
|
-
* 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.
|
|
1805
|
-
* If this type is `never`, it means `_QueryParamsLikelyByMistake` is missing keys from `QueryOptions`.
|
|
1806
|
-
* @internal
|
|
1807
|
-
*/
|
|
1808
|
-
export declare type QueryParamsLikelyByMistake =
|
|
1809
|
-
Required<_QueryParamsLikelyByMistake> extends Record<keyof QueryOptions, Any>
|
|
1810
|
-
? _QueryParamsLikelyByMistake
|
|
1811
|
-
: never
|
|
1812
|
-
|
|
1813
|
-
/**
|
|
1814
|
-
* Verify this type has all the same keys as QueryOptions before exporting
|
|
1815
|
-
* @internal
|
|
1816
|
-
*/
|
|
1817
|
-
export declare type _QueryParamsLikelyByMistake = {
|
|
1797
|
+
export declare interface QueryParams {
|
|
1798
|
+
[key: string]: any
|
|
1818
1799
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1819
|
-
body?:
|
|
1800
|
+
body?: never
|
|
1820
1801
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1821
|
-
cache?:
|
|
1802
|
+
cache?: 'next' extends keyof RequestInit ? never : any
|
|
1822
1803
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1823
|
-
filterResponse?:
|
|
1804
|
+
filterResponse?: never
|
|
1824
1805
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1825
|
-
headers?:
|
|
1806
|
+
headers?: never
|
|
1826
1807
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1827
|
-
method?:
|
|
1808
|
+
method?: never
|
|
1828
1809
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1829
|
-
next?:
|
|
1810
|
+
next?: 'next' extends keyof RequestInit ? never : any
|
|
1830
1811
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1831
|
-
perspective?:
|
|
1812
|
+
perspective?: never
|
|
1832
1813
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1833
|
-
query?:
|
|
1814
|
+
query?: never
|
|
1834
1815
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1835
|
-
resultSourceMap?:
|
|
1816
|
+
resultSourceMap?: never
|
|
1836
1817
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1837
|
-
signal?:
|
|
1818
|
+
signal?: never
|
|
1838
1819
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1839
|
-
stega?:
|
|
1820
|
+
stega?: never
|
|
1840
1821
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1841
|
-
tag?:
|
|
1822
|
+
tag?: never
|
|
1842
1823
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1843
|
-
timeout?:
|
|
1824
|
+
timeout?: never
|
|
1844
1825
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1845
|
-
token?:
|
|
1826
|
+
token?: never
|
|
1846
1827
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
1847
|
-
useCdn?:
|
|
1828
|
+
useCdn?: never
|
|
1848
1829
|
}
|
|
1849
1830
|
|
|
1850
1831
|
/**
|
|
1851
|
-
*
|
|
1832
|
+
* This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
|
|
1852
1833
|
* @public
|
|
1853
1834
|
*/
|
|
1854
|
-
export declare type
|
|
1855
|
-
QueryParamsParameterType extends QueryParams
|
|
1856
|
-
? QueryParamsParameterType
|
|
1857
|
-
: QueryParamsParameterType extends Record<string, never>
|
|
1858
|
-
? Record<string, never>
|
|
1859
|
-
: QueryParamsParameterType extends undefined
|
|
1860
|
-
? undefined | Record<string, never>
|
|
1861
|
-
: never
|
|
1862
|
-
|
|
1863
|
-
/**
|
|
1864
|
-
* It's easy to accidentally set query options such as `filterResponse`, `cache` and `next` as the second parameter in `client.fetch`,
|
|
1865
|
-
* as that is a wide type used to set GROQ query paramaters and it accepts anything that can serialize to JSON.
|
|
1866
|
-
* 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.
|
|
1867
|
-
* @internal
|
|
1868
|
-
*/
|
|
1869
|
-
export declare type QueryParamsWithoutQueryOptions = {
|
|
1870
|
-
[K in keyof _QueryParamsLikelyByMistake]: never
|
|
1871
|
-
} & QueryParams
|
|
1835
|
+
export declare type QueryWithoutParams = Record<string, never> | undefined
|
|
1872
1836
|
|
|
1873
1837
|
/** @public */
|
|
1874
1838
|
export declare interface RawQueryResponse<R> {
|
|
@@ -1912,15 +1876,6 @@ export declare type ReconnectEvent = {
|
|
|
1912
1876
|
/** @public */
|
|
1913
1877
|
export declare const requester: Requester
|
|
1914
1878
|
|
|
1915
|
-
/**
|
|
1916
|
-
* Options for the native `fetch` feature, used by the Next.js app-router
|
|
1917
|
-
* @public
|
|
1918
|
-
*/
|
|
1919
|
-
export declare interface RequestFetchOptions<T = 'next'> {
|
|
1920
|
-
cache?: RequestInit['cache']
|
|
1921
|
-
next?: T extends keyof RequestInit ? RequestInit[T] : never
|
|
1922
|
-
}
|
|
1923
|
-
|
|
1924
1879
|
/** @internal */
|
|
1925
1880
|
export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
|
|
1926
1881
|
url?: string
|
|
@@ -2022,8 +1977,9 @@ export declare class SanityClient {
|
|
|
2022
1977
|
*
|
|
2023
1978
|
* @param query - GROQ-query to perform
|
|
2024
1979
|
*/
|
|
2025
|
-
fetch<R = Any, Q extends
|
|
1980
|
+
fetch<R = Any, Q extends QueryWithoutParams = QueryWithoutParams>(
|
|
2026
1981
|
query: string,
|
|
1982
|
+
params?: Q | QueryWithoutParams,
|
|
2027
1983
|
): Promise<R>
|
|
2028
1984
|
/**
|
|
2029
1985
|
* Perform a GROQ-query against the configured dataset.
|
|
@@ -2032,9 +1988,9 @@ export declare class SanityClient {
|
|
|
2032
1988
|
* @param params - Optional query parameters
|
|
2033
1989
|
* @param options - Optional request options
|
|
2034
1990
|
*/
|
|
2035
|
-
fetch<R = Any, Q =
|
|
1991
|
+
fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
|
|
2036
1992
|
query: string,
|
|
2037
|
-
params:
|
|
1993
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
2038
1994
|
options?: FilteredResponseQueryOptions,
|
|
2039
1995
|
): Promise<R>
|
|
2040
1996
|
/**
|
|
@@ -2044,27 +2000,11 @@ export declare class SanityClient {
|
|
|
2044
2000
|
* @param params - Optional query parameters
|
|
2045
2001
|
* @param options - Request options
|
|
2046
2002
|
*/
|
|
2047
|
-
fetch<R = Any, Q =
|
|
2003
|
+
fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
|
|
2048
2004
|
query: string,
|
|
2049
|
-
params:
|
|
2005
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
2050
2006
|
options: UnfilteredResponseQueryOptions,
|
|
2051
2007
|
): Promise<RawQueryResponse<R>>
|
|
2052
|
-
/**
|
|
2053
|
-
* You're passing in query parameters to a GROQ query that looks like query options.
|
|
2054
|
-
* This is likely a mistake, you can either:
|
|
2055
|
-
* a) replace the second argument with an empty object, and move the options to the third argument
|
|
2056
|
-
* ```diff
|
|
2057
|
-
* -client.fetch(query, {cache: 'no-store'})
|
|
2058
|
-
* +client.fetch(query, {}, {cache: 'no-store'})
|
|
2059
|
-
* ```
|
|
2060
|
-
* b) add a generic type parameter that allows the query parameters to be passed in to silence the error
|
|
2061
|
-
* @deprecated not actually deprecated, marking it as deprecated makes this error easier to spot
|
|
2062
|
-
*/
|
|
2063
|
-
fetch<R = Any>(
|
|
2064
|
-
query: string,
|
|
2065
|
-
params: QueryParamsLikelyByMistake & QueryParams,
|
|
2066
|
-
options?: QueryOptions,
|
|
2067
|
-
): unknown
|
|
2068
2008
|
/**
|
|
2069
2009
|
* Fetch a single document with the given ID.
|
|
2070
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/client",
|
|
3
|
-
"version": "6.12.
|
|
3
|
+
"version": "6.12.3",
|
|
4
4
|
"description": "Client for retrieving, creating and patching data from Sanity.io",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
"@edge-runtime/vm": "^3.1.8",
|
|
139
139
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
140
140
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
141
|
-
"@sanity/pkg-utils": "^4.1.
|
|
141
|
+
"@sanity/pkg-utils": "^4.1.1",
|
|
142
142
|
"@types/json-diff": "^1.0.3",
|
|
143
143
|
"@types/node": "^20.8.8",
|
|
144
144
|
"@typescript-eslint/eslint-plugin": "^6.19.1",
|
|
@@ -153,7 +153,7 @@
|
|
|
153
153
|
"json-diff": "^1.0.6",
|
|
154
154
|
"ls-engines": "^0.9.1",
|
|
155
155
|
"next": "^14.1.0",
|
|
156
|
-
"nock": "^13.5.
|
|
156
|
+
"nock": "^13.5.1",
|
|
157
157
|
"prettier": "^3.2.4",
|
|
158
158
|
"prettier-plugin-packagejson": "^2.4.9",
|
|
159
159
|
"rimraf": "^5.0.1",
|
package/src/SanityClient.ts
CHANGED
|
@@ -27,9 +27,7 @@ import type {
|
|
|
27
27
|
PatchSelection,
|
|
28
28
|
QueryOptions,
|
|
29
29
|
QueryParams,
|
|
30
|
-
|
|
31
|
-
QueryParamsParameter,
|
|
32
|
-
QueryParamsWithoutQueryOptions,
|
|
30
|
+
QueryWithoutParams,
|
|
33
31
|
RawQueryResponse,
|
|
34
32
|
RawRequestOptions,
|
|
35
33
|
SanityDocument,
|
|
@@ -134,11 +132,10 @@ export class ObservableSanityClient {
|
|
|
134
132
|
*
|
|
135
133
|
* @param query - GROQ-query to perform
|
|
136
134
|
*/
|
|
137
|
-
fetch<
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
>(query: string): Observable<R>
|
|
135
|
+
fetch<R = Any, Q extends QueryWithoutParams = QueryWithoutParams>(
|
|
136
|
+
query: string,
|
|
137
|
+
params?: Q | QueryWithoutParams,
|
|
138
|
+
): Observable<R>
|
|
142
139
|
/**
|
|
143
140
|
* Perform a GROQ-query against the configured dataset.
|
|
144
141
|
*
|
|
@@ -146,9 +143,9 @@ export class ObservableSanityClient {
|
|
|
146
143
|
* @param params - Optional query parameters
|
|
147
144
|
* @param options - Optional request options
|
|
148
145
|
*/
|
|
149
|
-
fetch<R = Any, Q =
|
|
146
|
+
fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
|
|
150
147
|
query: string,
|
|
151
|
-
params:
|
|
148
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
152
149
|
options?: FilteredResponseQueryOptions,
|
|
153
150
|
): Observable<R>
|
|
154
151
|
/**
|
|
@@ -158,31 +155,12 @@ export class ObservableSanityClient {
|
|
|
158
155
|
* @param params - Optional query parameters
|
|
159
156
|
* @param options - Request options
|
|
160
157
|
*/
|
|
161
|
-
fetch<R = Any, Q =
|
|
158
|
+
fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
|
|
162
159
|
query: string,
|
|
163
|
-
params:
|
|
160
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
164
161
|
options: UnfilteredResponseQueryOptions,
|
|
165
162
|
): Observable<RawQueryResponse<R>>
|
|
166
|
-
|
|
167
|
-
* You're passing in query parameters to a GROQ query that looks like query options.
|
|
168
|
-
* This is likely a mistake, you can either:
|
|
169
|
-
* a) replace the second argument with an empty object, and move the options to the third argument
|
|
170
|
-
* ```diff
|
|
171
|
-
* -client.fetch(query, {cache: 'no-store'})
|
|
172
|
-
* +client.fetch(query, {}, {cache: 'no-store'})
|
|
173
|
-
* ```
|
|
174
|
-
* b) add a generic type parameter that allows the query parameters to be passed in to silence the error
|
|
175
|
-
* @deprecated not actually deprecated, marking it as deprecated makes this error easier to spot
|
|
176
|
-
*/
|
|
177
|
-
fetch<
|
|
178
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
179
|
-
R = Any,
|
|
180
|
-
>(
|
|
181
|
-
query: string,
|
|
182
|
-
params: QueryParamsLikelyByMistake & QueryParams,
|
|
183
|
-
options?: QueryOptions,
|
|
184
|
-
): unknown
|
|
185
|
-
fetch<R, Q extends QueryParams>(
|
|
163
|
+
fetch<R, Q>(
|
|
186
164
|
query: string,
|
|
187
165
|
params?: Q,
|
|
188
166
|
options?: QueryOptions,
|
|
@@ -793,11 +771,10 @@ export class SanityClient {
|
|
|
793
771
|
*
|
|
794
772
|
* @param query - GROQ-query to perform
|
|
795
773
|
*/
|
|
796
|
-
fetch<
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
>(query: string): Promise<R>
|
|
774
|
+
fetch<R = Any, Q extends QueryWithoutParams = QueryWithoutParams>(
|
|
775
|
+
query: string,
|
|
776
|
+
params?: Q | QueryWithoutParams,
|
|
777
|
+
): Promise<R>
|
|
801
778
|
/**
|
|
802
779
|
* Perform a GROQ-query against the configured dataset.
|
|
803
780
|
*
|
|
@@ -805,9 +782,9 @@ export class SanityClient {
|
|
|
805
782
|
* @param params - Optional query parameters
|
|
806
783
|
* @param options - Optional request options
|
|
807
784
|
*/
|
|
808
|
-
fetch<R = Any, Q =
|
|
785
|
+
fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
|
|
809
786
|
query: string,
|
|
810
|
-
params:
|
|
787
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
811
788
|
options?: FilteredResponseQueryOptions,
|
|
812
789
|
): Promise<R>
|
|
813
790
|
/**
|
|
@@ -817,35 +794,12 @@ export class SanityClient {
|
|
|
817
794
|
* @param params - Optional query parameters
|
|
818
795
|
* @param options - Request options
|
|
819
796
|
*/
|
|
820
|
-
fetch<R = Any, Q =
|
|
797
|
+
fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
|
|
821
798
|
query: string,
|
|
822
|
-
params:
|
|
799
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
823
800
|
options: UnfilteredResponseQueryOptions,
|
|
824
801
|
): Promise<RawQueryResponse<R>>
|
|
825
|
-
|
|
826
|
-
* You're passing in query parameters to a GROQ query that looks like query options.
|
|
827
|
-
* This is likely a mistake, you can either:
|
|
828
|
-
* a) replace the second argument with an empty object, and move the options to the third argument
|
|
829
|
-
* ```diff
|
|
830
|
-
* -client.fetch(query, {cache: 'no-store'})
|
|
831
|
-
* +client.fetch(query, {}, {cache: 'no-store'})
|
|
832
|
-
* ```
|
|
833
|
-
* b) add a generic type parameter that allows the query parameters to be passed in to silence the error
|
|
834
|
-
* @deprecated not actually deprecated, marking it as deprecated makes this error easier to spot
|
|
835
|
-
*/
|
|
836
|
-
fetch<
|
|
837
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
838
|
-
R = Any,
|
|
839
|
-
>(
|
|
840
|
-
query: string,
|
|
841
|
-
params: QueryParamsLikelyByMistake & QueryParams,
|
|
842
|
-
options?: QueryOptions,
|
|
843
|
-
): unknown
|
|
844
|
-
fetch<R, Q extends QueryParams>(
|
|
845
|
-
query: string,
|
|
846
|
-
params?: Q,
|
|
847
|
-
options?: QueryOptions,
|
|
848
|
-
): Promise<RawQueryResponse<R> | R> {
|
|
802
|
+
fetch<R, Q>(query: string, params?: Q, options?: QueryOptions): Promise<RawQueryResponse<R> | R> {
|
|
849
803
|
return lastValueFrom(
|
|
850
804
|
dataMethods._fetch<R, Q>(
|
|
851
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,82 +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
|
-
* as that is a wide type used to set GROQ query paramaters and it accepts anything that can serialize to JSON.
|
|
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
|
|
493
|
-
*/
|
|
494
|
-
export type QueryParamsWithoutQueryOptions = {
|
|
495
|
-
[K in keyof _QueryParamsLikelyByMistake]: never
|
|
496
|
-
} & QueryParams
|
|
497
|
-
|
|
498
|
-
/**
|
|
499
|
-
* Transform a QueryParams generic type to a valid parameter type for `client.fetch
|
|
470
|
+
* This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
|
|
500
471
|
* @public
|
|
501
472
|
*/
|
|
502
|
-
export type
|
|
503
|
-
QueryParamsParameterType extends QueryParams
|
|
504
|
-
? QueryParamsParameterType
|
|
505
|
-
: QueryParamsParameterType extends Record<string, never>
|
|
506
|
-
? Record<string, never>
|
|
507
|
-
: QueryParamsParameterType extends undefined
|
|
508
|
-
? undefined | Record<string, never>
|
|
509
|
-
: never
|
|
473
|
+
export type QueryWithoutParams = Record<string, never> | undefined
|
|
510
474
|
|
|
511
475
|
/** @internal */
|
|
512
|
-
export type
|
|
476
|
+
export type MutationSelectionQueryParams = {[key: string]: Any}
|
|
477
|
+
/** @internal */
|
|
478
|
+
export type MutationSelection =
|
|
479
|
+
| {query: string; params?: MutationSelectionQueryParams}
|
|
480
|
+
| {id: string | string[]}
|
|
513
481
|
/** @internal */
|
|
514
482
|
export type PatchSelection = string | string[] | MutationSelection
|
|
515
483
|
/** @internal */
|
|
@@ -692,6 +660,9 @@ export type ListenEventName =
|
|
|
692
660
|
/** The listener has been disconnected, and a reconnect attempt is scheduled */
|
|
693
661
|
| 'reconnect'
|
|
694
662
|
|
|
663
|
+
/** @public */
|
|
664
|
+
export type ListenParams = {[key: string]: Any}
|
|
665
|
+
|
|
695
666
|
/** @public */
|
|
696
667
|
export interface ListenOptions {
|
|
697
668
|
/**
|