@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.
@@ -738,7 +738,8 @@ function _dataRequest(client, httpRequest, endpoint, body) {
738
738
  headers,
739
739
  token,
740
740
  tag,
741
- canUseCdn: isQuery
741
+ canUseCdn: isQuery,
742
+ signal: options.signal
742
743
  };
743
744
  return _requestObservable(client, httpRequest, reqOptions).pipe(filter(isResponse), map(getBody), map(res => {
744
745
  if (!isMutation) {
@@ -785,9 +786,10 @@ function _requestObservable(client, httpRequest, options) {
785
786
  const reqOptions = getRequestOptions(config, Object.assign({}, options, {
786
787
  url: _getUrl(client, uri, useCdn)
787
788
  }));
788
- return new Observable(subscriber =>
789
+ const request = new Observable(subscriber =>
789
790
  // 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
790
791
  httpRequest(reqOptions, config.requester).subscribe(subscriber));
792
+ return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
791
793
  }
792
794
  function _request(client, httpRequest, options) {
793
795
  const observable = _requestObservable(client, httpRequest, options).pipe(filter(event => event.type === "response"), map(event => event.body));
@@ -809,6 +811,33 @@ function _getUrl(client, uri) {
809
811
  const base = canUseCdn ? cdnUrl : url;
810
812
  return "".concat(base, "/").concat(uri.replace(/^\//, ""));
811
813
  }
814
+ function _withAbortSignal(signal) {
815
+ return input => {
816
+ return new Observable(observer => {
817
+ const abort = () => observer.error(_createAbortError(signal));
818
+ if (signal && signal.aborted) {
819
+ abort();
820
+ return;
821
+ }
822
+ const subscription = input.subscribe(observer);
823
+ signal.addEventListener("abort", abort);
824
+ return () => {
825
+ signal.removeEventListener("abort", abort);
826
+ subscription.unsubscribe();
827
+ };
828
+ });
829
+ };
830
+ }
831
+ const isDomExceptionSupported = Boolean(globalThis.DOMException);
832
+ function _createAbortError(signal) {
833
+ var _a, _b;
834
+ if (isDomExceptionSupported) {
835
+ return new DOMException((_a = signal == null ? void 0 : signal.reason) != null ? _a : "The operation was aborted.", "AbortError");
836
+ }
837
+ const error = new Error((_b = signal == null ? void 0 : signal.reason) != null ? _b : "The operation was aborted.");
838
+ error.name = "AbortError";
839
+ return error;
840
+ }
812
841
  var __accessCheck$4 = (obj, member, msg) => {
813
842
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
814
843
  };
@@ -1651,8 +1680,11 @@ const _SanityClient = class {
1651
1680
  let SanityClient = _SanityClient;
1652
1681
  _clientConfig2 = new WeakMap();
1653
1682
  _httpRequest2 = new WeakMap();
1683
+ function migrationNotice() {
1684
+ throw new TypeError("The default export of @sanity/client has been deprecated. Use the named export `createClient` instead");
1685
+ }
1654
1686
  const httpRequest = defineHttpRequest(envMiddleware);
1655
1687
  const requester = httpRequest.defaultRequester;
1656
1688
  const createClient = config => new SanityClient(httpRequest, config);
1657
- export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, createClient, requester };
1689
+ export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, createClient, migrationNotice as default, requester };
1658
1690
  //# sourceMappingURL=index.browser.js.map