@sanity/client 5.0.0 → 5.1.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.
package/dist/index.d.ts CHANGED
@@ -503,6 +503,13 @@ export declare interface ListenOptions {
503
503
  tag?: string
504
504
  }
505
505
 
506
+ /**
507
+ * @public
508
+ * @deprecated Use the named export `createClient` instead of the `default` export
509
+ */
510
+ declare function migrationNotice(): void
511
+ export default migrationNotice
512
+
506
513
  /** @internal */
507
514
  export declare interface MultipleMutationResult {
508
515
  transactionId: string
@@ -1409,6 +1416,7 @@ export declare interface RequestOptions {
1409
1416
  method?: string
1410
1417
  query?: FIXME
1411
1418
  body?: FIXME
1419
+ signal?: AbortSignal
1412
1420
  }
1413
1421
 
1414
1422
  /** @public */
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { Observable, lastValueFrom } from 'rxjs';
4
4
  import { map, filter } from 'rxjs/operators';
5
5
  import polyfilledEventSource from '@sanity/eventsource';
6
6
  var name = "@sanity/client";
7
- var version = "5.0.0";
7
+ var version = "5.1.0";
8
8
  const middleware = [debug({
9
9
  verbose: true,
10
10
  namespace: "sanity:client"
@@ -747,7 +747,8 @@ function _dataRequest(client, httpRequest, endpoint, body) {
747
747
  headers,
748
748
  token,
749
749
  tag,
750
- canUseCdn: isQuery
750
+ canUseCdn: isQuery,
751
+ signal: options.signal
751
752
  };
752
753
  return _requestObservable(client, httpRequest, reqOptions).pipe(filter(isResponse), map(getBody), map(res => {
753
754
  if (!isMutation) {
@@ -794,9 +795,10 @@ function _requestObservable(client, httpRequest, options) {
794
795
  const reqOptions = getRequestOptions(config, Object.assign({}, options, {
795
796
  url: _getUrl(client, uri, useCdn)
796
797
  }));
797
- return new Observable(subscriber =>
798
+ const request = new Observable(subscriber =>
798
799
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- the typings thinks it's optional because it's not required to specify it when calling createClient, but it's always defined in practice since SanityClient provides a default
799
800
  httpRequest(reqOptions, config.requester).subscribe(subscriber));
801
+ return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
800
802
  }
801
803
  function _request(client, httpRequest, options) {
802
804
  const observable = _requestObservable(client, httpRequest, options).pipe(filter(event => event.type === "response"), map(event => event.body));
@@ -818,6 +820,33 @@ function _getUrl(client, uri) {
818
820
  const base = canUseCdn ? cdnUrl : url;
819
821
  return "".concat(base, "/").concat(uri.replace(/^\//, ""));
820
822
  }
823
+ function _withAbortSignal(signal) {
824
+ return input => {
825
+ return new Observable(observer => {
826
+ const abort = () => observer.error(_createAbortError(signal));
827
+ if (signal && signal.aborted) {
828
+ abort();
829
+ return;
830
+ }
831
+ const subscription = input.subscribe(observer);
832
+ signal.addEventListener("abort", abort);
833
+ return () => {
834
+ signal.removeEventListener("abort", abort);
835
+ subscription.unsubscribe();
836
+ };
837
+ });
838
+ };
839
+ }
840
+ const isDomExceptionSupported = Boolean(globalThis.DOMException);
841
+ function _createAbortError(signal) {
842
+ var _a, _b;
843
+ if (isDomExceptionSupported) {
844
+ return new DOMException((_a = signal == null ? void 0 : signal.reason) != null ? _a : "The operation was aborted.", "AbortError");
845
+ }
846
+ const error = new Error((_b = signal == null ? void 0 : signal.reason) != null ? _b : "The operation was aborted.");
847
+ error.name = "AbortError";
848
+ return error;
849
+ }
821
850
  var __accessCheck$4 = (obj, member, msg) => {
822
851
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
823
852
  };
@@ -1660,8 +1689,11 @@ const _SanityClient = class {
1660
1689
  let SanityClient = _SanityClient;
1661
1690
  _clientConfig2 = new WeakMap();
1662
1691
  _httpRequest2 = new WeakMap();
1692
+ function migrationNotice() {
1693
+ throw new TypeError("The default export of @sanity/client has been deprecated. Use the named export `createClient` instead");
1694
+ }
1663
1695
  const httpRequest = defineHttpRequest(middleware);
1664
1696
  const requester = httpRequest.defaultRequester;
1665
1697
  const createClient = config => new SanityClient(httpRequest, config);
1666
- export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, createClient, requester };
1698
+ export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, createClient, migrationNotice as default, requester };
1667
1699
  //# sourceMappingURL=index.js.map