@sanity/client 6.20.2 → 6.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -394,6 +394,12 @@ export declare class ClientError extends Error {
394
394
  /** @public */
395
395
  export declare type ClientPerspective = 'previewDrafts' | 'published' | 'raw'
396
396
 
397
+ /** @public */
398
+ export declare type ClientReturn<
399
+ GroqString extends string,
400
+ Fallback = Any,
401
+ > = GroqString extends keyof SanityQueries ? SanityQueries[GroqString] : Fallback
402
+
397
403
  /** @public */
398
404
  export declare interface ContentSourceMap {
399
405
  mappings: ContentSourceMapMappings
@@ -853,6 +859,12 @@ export declare interface ListenOptions {
853
859
  * @defaultValue `true`
854
860
  */
855
861
  includeResult?: boolean
862
+ /**
863
+ * Whether or not to include the mutations that was performed.
864
+ * If you do not need the mutations, set this to `false` to reduce bandwidth usage.
865
+ * @defaultValue `true`
866
+ */
867
+ includeMutations?: boolean
856
868
  /**
857
869
  * Whether or not to include the document as it looked before the mutation event.
858
870
  * The previous revision will be available on the `.previous` property of the events,
@@ -1300,10 +1312,11 @@ export declare class ObservableSanityClient {
1300
1312
  *
1301
1313
  * @param query - GROQ-query to perform
1302
1314
  */
1303
- fetch<R = Any, Q extends QueryWithoutParams = QueryWithoutParams>(
1304
- query: string,
1305
- params?: Q | QueryWithoutParams,
1306
- ): Observable<R>
1315
+ fetch<
1316
+ R = Any,
1317
+ Q extends QueryWithoutParams = QueryWithoutParams,
1318
+ const G extends string = string,
1319
+ >(query: G, params?: Q | QueryWithoutParams): Observable<ClientReturn<G, R>>
1307
1320
  /**
1308
1321
  * Perform a GROQ-query against the configured dataset.
1309
1322
  *
@@ -1311,11 +1324,15 @@ export declare class ObservableSanityClient {
1311
1324
  * @param params - Optional query parameters
1312
1325
  * @param options - Optional request options
1313
1326
  */
1314
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
1315
- query: string,
1327
+ fetch<
1328
+ R = Any,
1329
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1330
+ const G extends string = string,
1331
+ >(
1332
+ query: G,
1316
1333
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1317
1334
  options?: FilteredResponseQueryOptions,
1318
- ): Observable<R>
1335
+ ): Observable<ClientReturn<G, R>>
1319
1336
  /**
1320
1337
  * Perform a GROQ-query against the configured dataset.
1321
1338
  *
@@ -1323,11 +1340,15 @@ export declare class ObservableSanityClient {
1323
1340
  * @param params - Optional query parameters
1324
1341
  * @param options - Request options
1325
1342
  */
1326
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
1343
+ fetch<
1344
+ R = Any,
1345
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1346
+ const G extends string = string,
1347
+ >(
1327
1348
  query: string,
1328
1349
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1329
1350
  options: UnfilteredResponseQueryOptions,
1330
- ): Observable<RawQueryResponse<R>>
1351
+ ): Observable<RawQueryResponse<ClientReturn<G, R>>>
1331
1352
  /**
1332
1353
  * Perform a GROQ-query against the configured dataset.
1333
1354
  *
@@ -1335,11 +1356,15 @@ export declare class ObservableSanityClient {
1335
1356
  * @param params - Optional query parameters
1336
1357
  * @param options - Request options
1337
1358
  */
1338
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
1339
- query: string,
1359
+ fetch<
1360
+ R = Any,
1361
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1362
+ const G extends string = string,
1363
+ >(
1364
+ query: G,
1340
1365
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1341
1366
  options: UnfilteredResponseWithoutQuery,
1342
- ): Observable<RawQuerylessQueryResponse<R>>
1367
+ ): Observable<RawQuerylessQueryResponse<ClientReturn<G, R>>>
1343
1368
  /**
1344
1369
  * Fetch a single document with the given ID.
1345
1370
  *
@@ -2184,10 +2209,11 @@ export declare class SanityClient {
2184
2209
  *
2185
2210
  * @param query - GROQ-query to perform
2186
2211
  */
2187
- fetch<R = Any, Q extends QueryWithoutParams = QueryWithoutParams>(
2188
- query: string,
2189
- params?: Q | QueryWithoutParams,
2190
- ): Promise<R>
2212
+ fetch<
2213
+ R = Any,
2214
+ Q extends QueryWithoutParams = QueryWithoutParams,
2215
+ const G extends string = string,
2216
+ >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
2191
2217
  /**
2192
2218
  * Perform a GROQ-query against the configured dataset.
2193
2219
  *
@@ -2195,11 +2221,15 @@ export declare class SanityClient {
2195
2221
  * @param params - Optional query parameters
2196
2222
  * @param options - Optional request options
2197
2223
  */
2198
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
2199
- query: string,
2224
+ fetch<
2225
+ R = Any,
2226
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2227
+ const G extends string = string,
2228
+ >(
2229
+ query: G,
2200
2230
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2201
2231
  options?: FilteredResponseQueryOptions,
2202
- ): Promise<R>
2232
+ ): Promise<ClientReturn<G, R>>
2203
2233
  /**
2204
2234
  * Perform a GROQ-query against the configured dataset.
2205
2235
  *
@@ -2207,11 +2237,15 @@ export declare class SanityClient {
2207
2237
  * @param params - Optional query parameters
2208
2238
  * @param options - Request options
2209
2239
  */
2210
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
2211
- query: string,
2240
+ fetch<
2241
+ R = Any,
2242
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2243
+ const G extends string = string,
2244
+ >(
2245
+ query: G,
2212
2246
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2213
2247
  options: UnfilteredResponseQueryOptions,
2214
- ): Promise<RawQueryResponse<R>>
2248
+ ): Promise<RawQueryResponse<ClientReturn<G, R>>>
2215
2249
  /**
2216
2250
  * Perform a GROQ-query against the configured dataset.
2217
2251
  *
@@ -2219,11 +2253,15 @@ export declare class SanityClient {
2219
2253
  * @param params - Optional query parameters
2220
2254
  * @param options - Request options
2221
2255
  */
2222
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
2223
- query: string,
2256
+ fetch<
2257
+ R = Any,
2258
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2259
+ const G extends string = string,
2260
+ >(
2261
+ query: G,
2224
2262
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2225
2263
  options: UnfilteredResponseWithoutQuery,
2226
- ): Promise<RawQuerylessQueryResponse<R>>
2264
+ ): Promise<RawQuerylessQueryResponse<ClientReturn<G, R>>>
2227
2265
  /**
2228
2266
  * Fetch a single document with the given ID.
2229
2267
  *
@@ -2746,6 +2784,9 @@ export declare interface SanityProjectMember {
2746
2784
  isCurrentUser: boolean
2747
2785
  }
2748
2786
 
2787
+ /** @public */
2788
+ export declare interface SanityQueries {}
2789
+
2749
2790
  /** @internal */
2750
2791
  export declare interface SanityReference {
2751
2792
  _ref: string
@@ -394,6 +394,12 @@ export declare class ClientError extends Error {
394
394
  /** @public */
395
395
  export declare type ClientPerspective = 'previewDrafts' | 'published' | 'raw'
396
396
 
397
+ /** @public */
398
+ export declare type ClientReturn<
399
+ GroqString extends string,
400
+ Fallback = Any,
401
+ > = GroqString extends keyof SanityQueries ? SanityQueries[GroqString] : Fallback
402
+
397
403
  /** @public */
398
404
  export declare interface ContentSourceMap {
399
405
  mappings: ContentSourceMapMappings
@@ -853,6 +859,12 @@ export declare interface ListenOptions {
853
859
  * @defaultValue `true`
854
860
  */
855
861
  includeResult?: boolean
862
+ /**
863
+ * Whether or not to include the mutations that was performed.
864
+ * If you do not need the mutations, set this to `false` to reduce bandwidth usage.
865
+ * @defaultValue `true`
866
+ */
867
+ includeMutations?: boolean
856
868
  /**
857
869
  * Whether or not to include the document as it looked before the mutation event.
858
870
  * The previous revision will be available on the `.previous` property of the events,
@@ -1300,10 +1312,11 @@ export declare class ObservableSanityClient {
1300
1312
  *
1301
1313
  * @param query - GROQ-query to perform
1302
1314
  */
1303
- fetch<R = Any, Q extends QueryWithoutParams = QueryWithoutParams>(
1304
- query: string,
1305
- params?: Q | QueryWithoutParams,
1306
- ): Observable<R>
1315
+ fetch<
1316
+ R = Any,
1317
+ Q extends QueryWithoutParams = QueryWithoutParams,
1318
+ const G extends string = string,
1319
+ >(query: G, params?: Q | QueryWithoutParams): Observable<ClientReturn<G, R>>
1307
1320
  /**
1308
1321
  * Perform a GROQ-query against the configured dataset.
1309
1322
  *
@@ -1311,11 +1324,15 @@ export declare class ObservableSanityClient {
1311
1324
  * @param params - Optional query parameters
1312
1325
  * @param options - Optional request options
1313
1326
  */
1314
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
1315
- query: string,
1327
+ fetch<
1328
+ R = Any,
1329
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1330
+ const G extends string = string,
1331
+ >(
1332
+ query: G,
1316
1333
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1317
1334
  options?: FilteredResponseQueryOptions,
1318
- ): Observable<R>
1335
+ ): Observable<ClientReturn<G, R>>
1319
1336
  /**
1320
1337
  * Perform a GROQ-query against the configured dataset.
1321
1338
  *
@@ -1323,11 +1340,15 @@ export declare class ObservableSanityClient {
1323
1340
  * @param params - Optional query parameters
1324
1341
  * @param options - Request options
1325
1342
  */
1326
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
1343
+ fetch<
1344
+ R = Any,
1345
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1346
+ const G extends string = string,
1347
+ >(
1327
1348
  query: string,
1328
1349
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1329
1350
  options: UnfilteredResponseQueryOptions,
1330
- ): Observable<RawQueryResponse<R>>
1351
+ ): Observable<RawQueryResponse<ClientReturn<G, R>>>
1331
1352
  /**
1332
1353
  * Perform a GROQ-query against the configured dataset.
1333
1354
  *
@@ -1335,11 +1356,15 @@ export declare class ObservableSanityClient {
1335
1356
  * @param params - Optional query parameters
1336
1357
  * @param options - Request options
1337
1358
  */
1338
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
1339
- query: string,
1359
+ fetch<
1360
+ R = Any,
1361
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1362
+ const G extends string = string,
1363
+ >(
1364
+ query: G,
1340
1365
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1341
1366
  options: UnfilteredResponseWithoutQuery,
1342
- ): Observable<RawQuerylessQueryResponse<R>>
1367
+ ): Observable<RawQuerylessQueryResponse<ClientReturn<G, R>>>
1343
1368
  /**
1344
1369
  * Fetch a single document with the given ID.
1345
1370
  *
@@ -2184,10 +2209,11 @@ export declare class SanityClient {
2184
2209
  *
2185
2210
  * @param query - GROQ-query to perform
2186
2211
  */
2187
- fetch<R = Any, Q extends QueryWithoutParams = QueryWithoutParams>(
2188
- query: string,
2189
- params?: Q | QueryWithoutParams,
2190
- ): Promise<R>
2212
+ fetch<
2213
+ R = Any,
2214
+ Q extends QueryWithoutParams = QueryWithoutParams,
2215
+ const G extends string = string,
2216
+ >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
2191
2217
  /**
2192
2218
  * Perform a GROQ-query against the configured dataset.
2193
2219
  *
@@ -2195,11 +2221,15 @@ export declare class SanityClient {
2195
2221
  * @param params - Optional query parameters
2196
2222
  * @param options - Optional request options
2197
2223
  */
2198
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
2199
- query: string,
2224
+ fetch<
2225
+ R = Any,
2226
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2227
+ const G extends string = string,
2228
+ >(
2229
+ query: G,
2200
2230
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2201
2231
  options?: FilteredResponseQueryOptions,
2202
- ): Promise<R>
2232
+ ): Promise<ClientReturn<G, R>>
2203
2233
  /**
2204
2234
  * Perform a GROQ-query against the configured dataset.
2205
2235
  *
@@ -2207,11 +2237,15 @@ export declare class SanityClient {
2207
2237
  * @param params - Optional query parameters
2208
2238
  * @param options - Request options
2209
2239
  */
2210
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
2211
- query: string,
2240
+ fetch<
2241
+ R = Any,
2242
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2243
+ const G extends string = string,
2244
+ >(
2245
+ query: G,
2212
2246
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2213
2247
  options: UnfilteredResponseQueryOptions,
2214
- ): Promise<RawQueryResponse<R>>
2248
+ ): Promise<RawQueryResponse<ClientReturn<G, R>>>
2215
2249
  /**
2216
2250
  * Perform a GROQ-query against the configured dataset.
2217
2251
  *
@@ -2219,11 +2253,15 @@ export declare class SanityClient {
2219
2253
  * @param params - Optional query parameters
2220
2254
  * @param options - Request options
2221
2255
  */
2222
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
2223
- query: string,
2256
+ fetch<
2257
+ R = Any,
2258
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2259
+ const G extends string = string,
2260
+ >(
2261
+ query: G,
2224
2262
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2225
2263
  options: UnfilteredResponseWithoutQuery,
2226
- ): Promise<RawQuerylessQueryResponse<R>>
2264
+ ): Promise<RawQuerylessQueryResponse<ClientReturn<G, R>>>
2227
2265
  /**
2228
2266
  * Fetch a single document with the given ID.
2229
2267
  *
@@ -2746,6 +2784,9 @@ export declare interface SanityProjectMember {
2746
2784
  isCurrentUser: boolean
2747
2785
  }
2748
2786
 
2787
+ /** @public */
2788
+ export declare interface SanityQueries {}
2789
+
2749
2790
  /** @internal */
2750
2791
  export declare interface SanityReference {
2751
2792
  _ref: string
@@ -594,13 +594,13 @@ const encodeQueryString = ({
594
594
  params = {},
595
595
  options = {}
596
596
  }) => {
597
- const searchParams = new URLSearchParams(), { tag, returnQuery, ...opts } = options;
597
+ const searchParams = new URLSearchParams(), { tag, includeMutations, returnQuery, ...opts } = options;
598
598
  tag && searchParams.append("tag", tag), searchParams.append("query", query);
599
599
  for (const [key, value] of Object.entries(params))
600
600
  searchParams.append(`$${key}`, JSON.stringify(value));
601
601
  for (const [key, value] of Object.entries(opts))
602
602
  value && searchParams.append(key, `${value}`);
603
- return returnQuery === !1 && searchParams.append("returnQuery", "false"), `?${searchParams}`;
603
+ return returnQuery === !1 && searchParams.append("returnQuery", "false"), includeMutations === !1 && searchParams.append("includeMutations", "false"), `?${searchParams}`;
604
604
  }, excludeFalsey = (param, defValue) => param === !1 ? void 0 : typeof param > "u" ? defValue : param, getMutationQuery = (options = {}) => ({
605
605
  dryRun: options.dryRun,
606
606
  returnIds: !0,
@@ -859,6 +859,7 @@ var defaults = (obj, defaults2) => Object.keys(defaults2).concat(Object.keys(obj
859
859
  const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop] > "u" || (selection[prop] = obj[prop]), selection), {}), MAX_URL_LENGTH = 14800, possibleOptions = [
860
860
  "includePreviousRevision",
861
861
  "includeResult",
862
+ "includeMutations",
862
863
  "visibility",
863
864
  "effectFormat",
864
865
  "tag"