@sanity/client 6.12.2 → 6.12.4

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.
Files changed (40) hide show
  1. package/dist/_chunks/{browserMiddleware-zDVeirri.js → browserMiddleware-FL0Mlm8l.js} +2 -2
  2. package/dist/_chunks/browserMiddleware-FL0Mlm8l.js.map +1 -0
  3. package/dist/_chunks/{browserMiddleware-IWUpjfF7.cjs → browserMiddleware-dqqEd6vl.cjs} +2 -2
  4. package/dist/_chunks/browserMiddleware-dqqEd6vl.cjs.map +1 -0
  5. package/dist/_chunks/{nodeMiddleware-WxY6WiGP.cjs → nodeMiddleware-iUs-kdpz.cjs} +3 -3
  6. package/dist/_chunks/nodeMiddleware-iUs-kdpz.cjs.map +1 -0
  7. package/dist/_chunks/{nodeMiddleware-itgO-mht.js → nodeMiddleware-scsxYdRh.js} +3 -3
  8. package/dist/_chunks/nodeMiddleware-scsxYdRh.js.map +1 -0
  9. package/dist/_chunks/{stegaEncodeSourceMap-gZIRaYar.js → stegaEncodeSourceMap-LDHMEOVo.js} +9 -11
  10. package/dist/_chunks/{stegaEncodeSourceMap-gZIRaYar.js.map → stegaEncodeSourceMap-LDHMEOVo.js.map} +1 -1
  11. package/dist/_chunks/{stegaEncodeSourceMap-6b6FFhTO.js → stegaEncodeSourceMap-OHUCEAgw.js} +9 -11
  12. package/dist/_chunks/stegaEncodeSourceMap-OHUCEAgw.js.map +1 -0
  13. package/dist/_chunks/{stegaEncodeSourceMap-d-bYFA5X.cjs → stegaEncodeSourceMap-hWSK_ZZK.cjs} +9 -11
  14. package/dist/_chunks/stegaEncodeSourceMap-hWSK_ZZK.cjs.map +1 -0
  15. package/dist/_chunks/{stegaEncodeSourceMap-YNx-0kzT.cjs → stegaEncodeSourceMap-oPlkdofZ.cjs} +9 -11
  16. package/dist/_chunks/{stegaEncodeSourceMap-YNx-0kzT.cjs.map → stegaEncodeSourceMap-oPlkdofZ.cjs.map} +1 -1
  17. package/dist/index.browser.cjs +1 -1
  18. package/dist/index.browser.js +2 -2
  19. package/dist/index.cjs +1 -1
  20. package/dist/index.d.ts +61 -118
  21. package/dist/index.js +2 -2
  22. package/dist/stega.browser.cjs +2 -2
  23. package/dist/stega.browser.js +3 -3
  24. package/dist/stega.cjs +2 -2
  25. package/dist/stega.d.ts +61 -118
  26. package/dist/stega.js +3 -3
  27. package/package.json +6 -6
  28. package/src/SanityClient.ts +25 -76
  29. package/src/data/encodeQueryString.ts +2 -2
  30. package/src/data/listen.ts +4 -4
  31. package/src/stega/stegaEncodeSourceMap.ts +7 -9
  32. package/src/types.ts +36 -52
  33. package/umd/sanityClient.js +9 -11
  34. package/umd/sanityClient.min.js +1 -1
  35. package/dist/_chunks/browserMiddleware-IWUpjfF7.cjs.map +0 -1
  36. package/dist/_chunks/browserMiddleware-zDVeirri.js.map +0 -1
  37. package/dist/_chunks/nodeMiddleware-WxY6WiGP.cjs.map +0 -1
  38. package/dist/_chunks/nodeMiddleware-itgO-mht.js.map +0 -1
  39. package/dist/_chunks/stegaEncodeSourceMap-6b6FFhTO.js.map +0 -1
  40. package/dist/_chunks/stegaEncodeSourceMap-d-bYFA5X.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?: RequestFetchOptions | boolean
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?: QueryParams,
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?: QueryParams,
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?: QueryParams
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>(query: string): Observable<R>
1159
- /**
1160
- * Perform a GROQ-query against the configured dataset.
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 - Query parameters
1171
- * @param options - Request options
1181
+ * @param params - Optional query parameters
1182
+ * @param options - Optional request options
1172
1183
  */
1173
- fetch<R = Any, Q = QueryParamsWithoutQueryOptions>(
1184
+ fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
1174
1185
  query: string,
1175
- params: Q | undefined,
1176
- options: FilteredResponseQueryOptions,
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 - Query parameters
1193
+ * @param params - Optional query parameters
1183
1194
  * @param options - Request options
1184
1195
  */
1185
- fetch<R = Any, Q = QueryParamsWithoutQueryOptions>(
1196
+ fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
1186
1197
  query: string,
1187
- params: Q | undefined,
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 type QueryParams = {
1803
- [key: string]: Any
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?: Any
1800
+ body?: never
1825
1801
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
1826
- cache?: Any
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?: Any
1804
+ filterResponse?: never
1829
1805
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
1830
- headers?: Any
1806
+ headers?: never
1831
1807
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
1832
- method?: Any
1808
+ method?: never
1833
1809
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
1834
- next?: Any
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?: Any
1812
+ perspective?: never
1837
1813
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
1838
- query?: Any
1814
+ query?: never
1839
1815
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
1840
- resultSourceMap?: Any
1816
+ resultSourceMap?: never
1841
1817
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
1842
- signal?: Any
1818
+ signal?: never
1843
1819
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
1844
- stega?: Any
1820
+ stega?: never
1845
1821
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
1846
- tag?: Any
1822
+ tag?: never
1847
1823
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
1848
- timeout?: Any
1824
+ timeout?: never
1849
1825
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
1850
- token?: Any
1826
+ token?: never
1851
1827
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
1852
- useCdn?: Any
1828
+ useCdn?: never
1853
1829
  }
1854
1830
 
1855
1831
  /**
1856
- * It's easy to accidentally set query options such as `filterResponse`, `cache` and `next` as the second parameter in `client.fetch`,
1857
- * as that is a wide type used to set GROQ query paramaters and it accepts anything that can serialize to JSON.
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 QueryParamsWithoutQueryOptions = {
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>(query: string): Promise<R>
2018
- /**
2019
- * Perform a GROQ-query against the configured dataset.
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 - Request options
1989
+ * @param options - Optional request options
2031
1990
  */
2032
- fetch<R = Any, Q = QueryParamsWithoutQueryOptions>(
1991
+ fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
2033
1992
  query: string,
2034
- params: Q | undefined,
2035
- options: FilteredResponseQueryOptions,
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 = QueryParamsWithoutQueryOptions>(
2003
+ fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
2045
2004
  query: string,
2046
- params: Q | undefined,
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-itgO-mht.js';
2
- export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableTransaction, Patch, ServerError, Transaction, vercelStegaCleanAll } from './_chunks/nodeMiddleware-itgO-mht.js';
1
+ import { SanityClient, ObservableSanityClient, defineCreateClientExports, middleware } from './_chunks/nodeMiddleware-scsxYdRh.js';
2
+ export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableTransaction, Patch, ServerError, Transaction, vercelStegaCleanAll } from './_chunks/nodeMiddleware-scsxYdRh.js';
3
3
  export { adapter as unstable__adapter, environment as unstable__environment } from 'get-it';
4
- export { encodeIntoResult, stegaEncodeSourceMap } from './_chunks/stegaEncodeSourceMap-6b6FFhTO.js';
4
+ export { encodeIntoResult, stegaEncodeSourceMap } from './_chunks/stegaEncodeSourceMap-OHUCEAgw.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.2",
3
+ "version": "6.12.4",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
@@ -138,11 +138,11 @@
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.1",
141
+ "@sanity/pkg-utils": "^4.1.4",
142
142
  "@types/json-diff": "^1.0.3",
143
143
  "@types/node": "^20.8.8",
144
- "@typescript-eslint/eslint-plugin": "^6.19.1",
145
- "@typescript-eslint/parser": "^6.19.1",
144
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
145
+ "@typescript-eslint/parser": "^6.21.0",
146
146
  "@vitest/coverage-v8": "1.2.2",
147
147
  "eslint": "^8.56.0",
148
148
  "eslint-config-prettier": "^9.1.0",
@@ -154,8 +154,8 @@
154
154
  "ls-engines": "^0.9.1",
155
155
  "next": "^14.1.0",
156
156
  "nock": "^13.5.1",
157
- "prettier": "^3.2.4",
158
- "prettier-plugin-packagejson": "^2.4.9",
157
+ "prettier": "^3.2.5",
158
+ "prettier-plugin-packagejson": "^2.4.10",
159
159
  "rimraf": "^5.0.1",
160
160
  "rollup": "^4.9.6",
161
161
  "sse-channel": "^4.0.0",
@@ -27,8 +27,7 @@ import type {
27
27
  PatchSelection,
28
28
  QueryOptions,
29
29
  QueryParams,
30
- QueryParamsLikelyByMistake,
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>(query: string): Observable<R>
137
- /**
138
- * Perform a GROQ-query against the configured dataset.
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 - Query parameters
149
- * @param options - Request options
143
+ * @param params - Optional query parameters
144
+ * @param options - Optional request options
150
145
  */
151
- fetch<R = Any, Q = QueryParamsWithoutQueryOptions>(
146
+ fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
152
147
  query: string,
153
- params: Q | undefined,
154
- options: FilteredResponseQueryOptions,
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 - Query parameters
155
+ * @param params - Optional query parameters
161
156
  * @param options - Request options
162
157
  */
163
- fetch<R = Any, Q = QueryParamsWithoutQueryOptions>(
158
+ fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
164
159
  query: string,
165
- params: Q | undefined,
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>(query: string): Promise<R>
799
- /**
800
- * Perform a GROQ-query against the configured dataset.
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 - Request options
783
+ * @param options - Optional request options
812
784
  */
813
- fetch<R = Any, Q = QueryParamsWithoutQueryOptions>(
785
+ fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
814
786
  query: string,
815
- params: Q | undefined,
816
- options: FilteredResponseQueryOptions,
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 = QueryParamsWithoutQueryOptions>(
797
+ fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
826
798
  query: string,
827
- params: Q | undefined,
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()
@@ -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, MutationEvent, QueryParams} from '../types'
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?: QueryParams,
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?: QueryParams,
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?: QueryParams,
58
+ params?: ListenParams,
59
59
  opts: ListenOptions = {},
60
60
  ): Observable<MutationEvent<R> | ListenEvent<R>> {
61
61
  const {url, token, withCredentials, requestTagPrefix} = this.config()
@@ -24,12 +24,12 @@ export function stegaEncodeSourceMap<Result = unknown>(
24
24
  const {filter, logger, enabled} = config
25
25
  if (!enabled) {
26
26
  const msg = "config.enabled must be true, don't call this function otherwise"
27
- logger?.error?.(`[@sanity/client/stega]: ${msg}`, {result, resultSourceMap, config})
27
+ logger?.error?.(`[@sanity/client]: ${msg}`, {result, resultSourceMap, config})
28
28
  throw new TypeError(msg)
29
29
  }
30
30
 
31
31
  if (!resultSourceMap) {
32
- logger?.error?.('[@sanity/client/stega]: Missing Content Source Map from response body', {
32
+ logger?.error?.('[@sanity/client]: Missing Content Source Map from response body', {
33
33
  result,
34
34
  resultSourceMap,
35
35
  config,
@@ -39,7 +39,7 @@ export function stegaEncodeSourceMap<Result = unknown>(
39
39
 
40
40
  if (!config.studioUrl) {
41
41
  const msg = 'config.studioUrl must be defined'
42
- logger?.error?.(`[@sanity/client/stega]: ${msg}`, {result, resultSourceMap, config})
42
+ logger?.error?.(`[@sanity/client]: ${msg}`, {result, resultSourceMap, config})
43
43
  throw new TypeError(msg)
44
44
  }
45
45
 
@@ -109,15 +109,13 @@ export function stegaEncodeSourceMap<Result = unknown>(
109
109
  const isSkipping = report.skipped.length
110
110
  const isEncoding = report.encoded.length
111
111
  if (isSkipping || isEncoding) {
112
- ;(logger?.groupCollapsed || logger.log)?.(
113
- '[@sanity/client/stega]: Encoding source map into result',
114
- )
112
+ ;(logger?.groupCollapsed || logger.log)?.('[@sanity/client]: Encoding source map into result')
115
113
  logger.log?.(
116
- `[@sanity/client/stega]: Paths encoded: ${report.encoded.length}, skipped: ${report.skipped.length}`,
114
+ `[@sanity/client]: Paths encoded: ${report.encoded.length}, skipped: ${report.skipped.length}`,
117
115
  )
118
116
  }
119
117
  if (report.encoded.length > 0) {
120
- logger?.log?.(`[@sanity/client/stega]: Table of encoded paths`)
118
+ logger?.log?.(`[@sanity/client]: Table of encoded paths`)
121
119
  ;(logger?.table || logger.log)?.(report.encoded)
122
120
  }
123
121
  if (report.skipped.length > 0) {
@@ -125,7 +123,7 @@ export function stegaEncodeSourceMap<Result = unknown>(
125
123
  for (const {path} of report.skipped) {
126
124
  skipped.add(path.replace(reKeySegment, '0').replace(/\[\d+\]/g, '[]'))
127
125
  }
128
- logger?.log?.(`[@sanity/client/stega]: List of skipped paths`, [...skipped.values()])
126
+ logger?.log?.(`[@sanity/client]: List of skipped paths`, [...skipped.values()])
129
127
  }
130
128
 
131
129
  if (isSkipping || isEncoding) {