@sanity/client 6.20.2-beta.2 → 6.21.0

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.
@@ -336,13 +336,6 @@ export declare interface ClientConfig {
336
336
  apiHost?: string
337
337
  apiVersion?: string
338
338
  proxy?: string
339
- /**
340
- * Spread the requests over a number of hostnames to work around HTTP/1.1 limitations.
341
- * Only applicable in browsers, and for certain allowed projects.
342
- *
343
- * @alpha
344
- */
345
- useDomainSharding?: boolean
346
339
  /**
347
340
  * Optional request tag prefix for all request tags
348
341
  */
@@ -401,6 +394,12 @@ export declare class ClientError extends Error {
401
394
  /** @public */
402
395
  export declare type ClientPerspective = 'previewDrafts' | 'published' | 'raw'
403
396
 
397
+ /** @public */
398
+ export declare type ClientReturn<
399
+ GroqString extends string,
400
+ Fallback = Any,
401
+ > = GroqString extends keyof SanityQueries ? SanityQueries[GroqString] : Fallback
402
+
404
403
  /** @public */
405
404
  export declare interface ContentSourceMap {
406
405
  mappings: ContentSourceMapMappings
@@ -1307,10 +1306,11 @@ export declare class ObservableSanityClient {
1307
1306
  *
1308
1307
  * @param query - GROQ-query to perform
1309
1308
  */
1310
- fetch<R = Any, Q extends QueryWithoutParams = QueryWithoutParams>(
1311
- query: string,
1312
- params?: Q | QueryWithoutParams,
1313
- ): Observable<R>
1309
+ fetch<
1310
+ R = Any,
1311
+ Q extends QueryWithoutParams = QueryWithoutParams,
1312
+ const G extends string = string,
1313
+ >(query: G, params?: Q | QueryWithoutParams): Observable<ClientReturn<G, R>>
1314
1314
  /**
1315
1315
  * Perform a GROQ-query against the configured dataset.
1316
1316
  *
@@ -1318,11 +1318,15 @@ export declare class ObservableSanityClient {
1318
1318
  * @param params - Optional query parameters
1319
1319
  * @param options - Optional request options
1320
1320
  */
1321
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
1322
- query: string,
1321
+ fetch<
1322
+ R = Any,
1323
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1324
+ const G extends string = string,
1325
+ >(
1326
+ query: G,
1323
1327
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1324
1328
  options?: FilteredResponseQueryOptions,
1325
- ): Observable<R>
1329
+ ): Observable<ClientReturn<G, R>>
1326
1330
  /**
1327
1331
  * Perform a GROQ-query against the configured dataset.
1328
1332
  *
@@ -1330,11 +1334,15 @@ export declare class ObservableSanityClient {
1330
1334
  * @param params - Optional query parameters
1331
1335
  * @param options - Request options
1332
1336
  */
1333
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
1337
+ fetch<
1338
+ R = Any,
1339
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1340
+ const G extends string = string,
1341
+ >(
1334
1342
  query: string,
1335
1343
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1336
1344
  options: UnfilteredResponseQueryOptions,
1337
- ): Observable<RawQueryResponse<R>>
1345
+ ): Observable<RawQueryResponse<ClientReturn<G, R>>>
1338
1346
  /**
1339
1347
  * Perform a GROQ-query against the configured dataset.
1340
1348
  *
@@ -1342,11 +1350,15 @@ export declare class ObservableSanityClient {
1342
1350
  * @param params - Optional query parameters
1343
1351
  * @param options - Request options
1344
1352
  */
1345
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
1346
- query: string,
1353
+ fetch<
1354
+ R = Any,
1355
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1356
+ const G extends string = string,
1357
+ >(
1358
+ query: G,
1347
1359
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1348
1360
  options: UnfilteredResponseWithoutQuery,
1349
- ): Observable<RawQuerylessQueryResponse<R>>
1361
+ ): Observable<RawQuerylessQueryResponse<ClientReturn<G, R>>>
1350
1362
  /**
1351
1363
  * Fetch a single document with the given ID.
1352
1364
  *
@@ -2191,10 +2203,11 @@ export declare class SanityClient {
2191
2203
  *
2192
2204
  * @param query - GROQ-query to perform
2193
2205
  */
2194
- fetch<R = Any, Q extends QueryWithoutParams = QueryWithoutParams>(
2195
- query: string,
2196
- params?: Q | QueryWithoutParams,
2197
- ): Promise<R>
2206
+ fetch<
2207
+ R = Any,
2208
+ Q extends QueryWithoutParams = QueryWithoutParams,
2209
+ const G extends string = string,
2210
+ >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
2198
2211
  /**
2199
2212
  * Perform a GROQ-query against the configured dataset.
2200
2213
  *
@@ -2202,11 +2215,15 @@ export declare class SanityClient {
2202
2215
  * @param params - Optional query parameters
2203
2216
  * @param options - Optional request options
2204
2217
  */
2205
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
2206
- query: string,
2218
+ fetch<
2219
+ R = Any,
2220
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2221
+ const G extends string = string,
2222
+ >(
2223
+ query: G,
2207
2224
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2208
2225
  options?: FilteredResponseQueryOptions,
2209
- ): Promise<R>
2226
+ ): Promise<ClientReturn<G, R>>
2210
2227
  /**
2211
2228
  * Perform a GROQ-query against the configured dataset.
2212
2229
  *
@@ -2214,11 +2231,15 @@ export declare class SanityClient {
2214
2231
  * @param params - Optional query parameters
2215
2232
  * @param options - Request options
2216
2233
  */
2217
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
2218
- query: string,
2234
+ fetch<
2235
+ R = Any,
2236
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2237
+ const G extends string = string,
2238
+ >(
2239
+ query: G,
2219
2240
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2220
2241
  options: UnfilteredResponseQueryOptions,
2221
- ): Promise<RawQueryResponse<R>>
2242
+ ): Promise<RawQueryResponse<ClientReturn<G, R>>>
2222
2243
  /**
2223
2244
  * Perform a GROQ-query against the configured dataset.
2224
2245
  *
@@ -2226,11 +2247,15 @@ export declare class SanityClient {
2226
2247
  * @param params - Optional query parameters
2227
2248
  * @param options - Request options
2228
2249
  */
2229
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
2230
- query: string,
2250
+ fetch<
2251
+ R = Any,
2252
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2253
+ const G extends string = string,
2254
+ >(
2255
+ query: G,
2231
2256
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2232
2257
  options: UnfilteredResponseWithoutQuery,
2233
- ): Promise<RawQuerylessQueryResponse<R>>
2258
+ ): Promise<RawQuerylessQueryResponse<ClientReturn<G, R>>>
2234
2259
  /**
2235
2260
  * Fetch a single document with the given ID.
2236
2261
  *
@@ -2753,6 +2778,9 @@ export declare interface SanityProjectMember {
2753
2778
  isCurrentUser: boolean
2754
2779
  }
2755
2780
 
2781
+ /** @public */
2782
+ export declare interface SanityQueries {}
2783
+
2756
2784
  /** @internal */
2757
2785
  export declare interface SanityReference {
2758
2786
  _ref: string
@@ -336,13 +336,6 @@ export declare interface ClientConfig {
336
336
  apiHost?: string
337
337
  apiVersion?: string
338
338
  proxy?: string
339
- /**
340
- * Spread the requests over a number of hostnames to work around HTTP/1.1 limitations.
341
- * Only applicable in browsers, and for certain allowed projects.
342
- *
343
- * @alpha
344
- */
345
- useDomainSharding?: boolean
346
339
  /**
347
340
  * Optional request tag prefix for all request tags
348
341
  */
@@ -401,6 +394,12 @@ export declare class ClientError extends Error {
401
394
  /** @public */
402
395
  export declare type ClientPerspective = 'previewDrafts' | 'published' | 'raw'
403
396
 
397
+ /** @public */
398
+ export declare type ClientReturn<
399
+ GroqString extends string,
400
+ Fallback = Any,
401
+ > = GroqString extends keyof SanityQueries ? SanityQueries[GroqString] : Fallback
402
+
404
403
  /** @public */
405
404
  export declare interface ContentSourceMap {
406
405
  mappings: ContentSourceMapMappings
@@ -1307,10 +1306,11 @@ export declare class ObservableSanityClient {
1307
1306
  *
1308
1307
  * @param query - GROQ-query to perform
1309
1308
  */
1310
- fetch<R = Any, Q extends QueryWithoutParams = QueryWithoutParams>(
1311
- query: string,
1312
- params?: Q | QueryWithoutParams,
1313
- ): Observable<R>
1309
+ fetch<
1310
+ R = Any,
1311
+ Q extends QueryWithoutParams = QueryWithoutParams,
1312
+ const G extends string = string,
1313
+ >(query: G, params?: Q | QueryWithoutParams): Observable<ClientReturn<G, R>>
1314
1314
  /**
1315
1315
  * Perform a GROQ-query against the configured dataset.
1316
1316
  *
@@ -1318,11 +1318,15 @@ export declare class ObservableSanityClient {
1318
1318
  * @param params - Optional query parameters
1319
1319
  * @param options - Optional request options
1320
1320
  */
1321
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
1322
- query: string,
1321
+ fetch<
1322
+ R = Any,
1323
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1324
+ const G extends string = string,
1325
+ >(
1326
+ query: G,
1323
1327
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1324
1328
  options?: FilteredResponseQueryOptions,
1325
- ): Observable<R>
1329
+ ): Observable<ClientReturn<G, R>>
1326
1330
  /**
1327
1331
  * Perform a GROQ-query against the configured dataset.
1328
1332
  *
@@ -1330,11 +1334,15 @@ export declare class ObservableSanityClient {
1330
1334
  * @param params - Optional query parameters
1331
1335
  * @param options - Request options
1332
1336
  */
1333
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
1337
+ fetch<
1338
+ R = Any,
1339
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1340
+ const G extends string = string,
1341
+ >(
1334
1342
  query: string,
1335
1343
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1336
1344
  options: UnfilteredResponseQueryOptions,
1337
- ): Observable<RawQueryResponse<R>>
1345
+ ): Observable<RawQueryResponse<ClientReturn<G, R>>>
1338
1346
  /**
1339
1347
  * Perform a GROQ-query against the configured dataset.
1340
1348
  *
@@ -1342,11 +1350,15 @@ export declare class ObservableSanityClient {
1342
1350
  * @param params - Optional query parameters
1343
1351
  * @param options - Request options
1344
1352
  */
1345
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
1346
- query: string,
1353
+ fetch<
1354
+ R = Any,
1355
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1356
+ const G extends string = string,
1357
+ >(
1358
+ query: G,
1347
1359
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1348
1360
  options: UnfilteredResponseWithoutQuery,
1349
- ): Observable<RawQuerylessQueryResponse<R>>
1361
+ ): Observable<RawQuerylessQueryResponse<ClientReturn<G, R>>>
1350
1362
  /**
1351
1363
  * Fetch a single document with the given ID.
1352
1364
  *
@@ -2191,10 +2203,11 @@ export declare class SanityClient {
2191
2203
  *
2192
2204
  * @param query - GROQ-query to perform
2193
2205
  */
2194
- fetch<R = Any, Q extends QueryWithoutParams = QueryWithoutParams>(
2195
- query: string,
2196
- params?: Q | QueryWithoutParams,
2197
- ): Promise<R>
2206
+ fetch<
2207
+ R = Any,
2208
+ Q extends QueryWithoutParams = QueryWithoutParams,
2209
+ const G extends string = string,
2210
+ >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
2198
2211
  /**
2199
2212
  * Perform a GROQ-query against the configured dataset.
2200
2213
  *
@@ -2202,11 +2215,15 @@ export declare class SanityClient {
2202
2215
  * @param params - Optional query parameters
2203
2216
  * @param options - Optional request options
2204
2217
  */
2205
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
2206
- query: string,
2218
+ fetch<
2219
+ R = Any,
2220
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2221
+ const G extends string = string,
2222
+ >(
2223
+ query: G,
2207
2224
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2208
2225
  options?: FilteredResponseQueryOptions,
2209
- ): Promise<R>
2226
+ ): Promise<ClientReturn<G, R>>
2210
2227
  /**
2211
2228
  * Perform a GROQ-query against the configured dataset.
2212
2229
  *
@@ -2214,11 +2231,15 @@ export declare class SanityClient {
2214
2231
  * @param params - Optional query parameters
2215
2232
  * @param options - Request options
2216
2233
  */
2217
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
2218
- query: string,
2234
+ fetch<
2235
+ R = Any,
2236
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2237
+ const G extends string = string,
2238
+ >(
2239
+ query: G,
2219
2240
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2220
2241
  options: UnfilteredResponseQueryOptions,
2221
- ): Promise<RawQueryResponse<R>>
2242
+ ): Promise<RawQueryResponse<ClientReturn<G, R>>>
2222
2243
  /**
2223
2244
  * Perform a GROQ-query against the configured dataset.
2224
2245
  *
@@ -2226,11 +2247,15 @@ export declare class SanityClient {
2226
2247
  * @param params - Optional query parameters
2227
2248
  * @param options - Request options
2228
2249
  */
2229
- fetch<R = Any, Q extends QueryWithoutParams | QueryParams = QueryParams>(
2230
- query: string,
2250
+ fetch<
2251
+ R = Any,
2252
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2253
+ const G extends string = string,
2254
+ >(
2255
+ query: G,
2231
2256
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2232
2257
  options: UnfilteredResponseWithoutQuery,
2233
- ): Promise<RawQuerylessQueryResponse<R>>
2258
+ ): Promise<RawQuerylessQueryResponse<ClientReturn<G, R>>>
2234
2259
  /**
2235
2260
  * Fetch a single document with the given ID.
2236
2261
  *
@@ -2753,6 +2778,9 @@ export declare interface SanityProjectMember {
2753
2778
  isCurrentUser: boolean
2754
2779
  }
2755
2780
 
2781
+ /** @public */
2782
+ export declare interface SanityQueries {}
2783
+
2756
2784
  /** @internal */
2757
2785
  export declare interface SanityReference {
2758
2786
  _ref: string
@@ -586,7 +586,6 @@ function requestOptions(config, overrides = {}) {
586
586
  proxy: overrides.proxy || config.proxy,
587
587
  json: !0,
588
588
  withCredentials,
589
- useDomainSharding: config.useDomainSharding,
590
589
  fetch: typeof overrides.fetch == "object" && typeof config.fetch == "object" ? { ...config.fetch, ...overrides.fetch } : overrides.fetch || config.fetch
591
590
  });
592
591
  }
@@ -856,55 +855,6 @@ function optionsFromFile(opts, file) {
856
855
  opts
857
856
  );
858
857
  }
859
- const UNSHARDED_URL_RE = /^https:\/\/([a-z0-9]+)\.api\.(sanity\..*)/, SHARDED_URL_RE = /^https:\/\/[a-z0-9]+\.api\.r(\d+)\.sanity\.(.*)/, domainSharder = getDomainSharder();
860
- function getDomainSharder(initialBuckets) {
861
- const buckets = new Array(3).fill(0, 0);
862
- function incrementBucketForUrl(url) {
863
- const shard = getShardFromUrl(url);
864
- shard !== null && buckets[shard]++;
865
- }
866
- function decrementBucketForUrl(url) {
867
- const shard = getShardFromUrl(url);
868
- shard !== null && buckets[shard]--;
869
- }
870
- function getShardedUrl(url) {
871
- const [isMatch, projectId2, rest] = url.match(UNSHARDED_URL_RE) || [];
872
- if (!isMatch)
873
- return url;
874
- const bucket = buckets.reduce(
875
- (smallest, count, index) => count < buckets[smallest] ? index : smallest,
876
- 0
877
- );
878
- return `https://${projectId2}.api.r${bucket + 1}.${rest}`;
879
- }
880
- function getShardFromUrl(url) {
881
- const [isMatch, shard] = url.match(SHARDED_URL_RE) || [];
882
- return isMatch ? parseInt(shard, 10) - 1 : null;
883
- }
884
- return {
885
- middleware: {
886
- processOptions: (options) => {
887
- if (!useDomainSharding(options))
888
- return options;
889
- const url = getShardedUrl(options.url);
890
- return options.url = url, options;
891
- },
892
- onRequest(req) {
893
- return useDomainSharding(req.options) && incrementBucketForUrl(req.options.url), req;
894
- },
895
- onResponse(res, context) {
896
- return useDomainSharding(context.options) && decrementBucketForUrl(context.options.url), res;
897
- }
898
- },
899
- incrementBucketForUrl,
900
- decrementBucketForUrl,
901
- getShardedUrl,
902
- getBuckets: () => buckets
903
- };
904
- }
905
- function useDomainSharding(options) {
906
- return "useDomainSharding" in options && options.useDomainSharding === !0;
907
- }
908
858
  var defaults = (obj, defaults2) => Object.keys(defaults2).concat(Object.keys(obj)).reduce((target, prop) => (target[prop] = typeof obj[prop] > "u" ? defaults2[prop] : obj[prop], target), {});
909
859
  const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop] > "u" || (selection[prop] = obj[prop]), selection), {}), MAX_URL_LENGTH = 14800, possibleOptions = [
910
860
  "includePreviousRevision",
@@ -916,16 +866,15 @@ const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop]
916
866
  includeResult: !0
917
867
  };
918
868
  function _listen(query, params, opts = {}) {
919
- const { url, token, withCredentials, requestTagPrefix } = this.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, options = { ...defaults(opts, defaultOptions), tag }, listenOpts = pick(options, possibleOptions), qs = encodeQueryString({ query, params, options: { tag, ...listenOpts } });
920
- let uri = `${url}${_getDataUrl(this, "listen", qs)}`;
921
- if (this.config().useDomainSharding && (uri = domainSharder.getShardedUrl(uri)), uri.length > MAX_URL_LENGTH)
869
+ const { url, token, withCredentials, requestTagPrefix } = this.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, options = { ...defaults(opts, defaultOptions), tag }, listenOpts = pick(options, possibleOptions), qs = encodeQueryString({ query, params, options: { tag, ...listenOpts } }), uri = `${url}${_getDataUrl(this, "listen", qs)}`;
870
+ if (uri.length > MAX_URL_LENGTH)
922
871
  return new Observable((observer) => observer.error(new Error("Query too large for listener")));
923
872
  const listenFor = options.events ? options.events : ["mutation"], shouldEmitReconnect = listenFor.indexOf("reconnect") !== -1, esOptions = {};
924
873
  return (token || withCredentials) && (esOptions.withCredentials = !0), token && (esOptions.headers = {
925
874
  Authorization: `Bearer ${token}`
926
875
  }), new Observable((observer) => {
927
876
  let es, reconnectTimer, stopped = !1, unsubscribed = !1;
928
- domainSharder.incrementBucketForUrl(uri), open();
877
+ open();
929
878
  function onError() {
930
879
  stopped || (emitReconnect(), !stopped && es.readyState === es.CLOSED && (unsubscribe(), clearTimeout(reconnectTimer), reconnectTimer = setTimeout(open, 100)));
931
880
  }
@@ -960,7 +909,7 @@ function _listen(query, params, opts = {}) {
960
909
  });
961
910
  }
962
911
  function stop() {
963
- stopped = !0, unsubscribe(), unsubscribed = !0, domainSharder.decrementBucketForUrl(uri);
912
+ stopped = !0, unsubscribe(), unsubscribed = !0;
964
913
  }
965
914
  return stop;
966
915
  });
@@ -1581,7 +1530,7 @@ function defineDeprecatedCreateClient(createClient2) {
1581
1530
  return printNoDefaultExport(), createClient2(config);
1582
1531
  };
1583
1532
  }
1584
- var envMiddleware = [domainSharder.middleware];
1533
+ var envMiddleware = [];
1585
1534
  const exp = defineCreateClientExports(envMiddleware, SanityClient), requester = exp.requester, createClient = exp.createClient, deprecatedCreateClient = defineDeprecatedCreateClient(createClient);
1586
1535
  export {
1587
1536
  BasePatch,