@sanity/client 6.17.1-canary.0 → 6.17.2

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.
@@ -1123,7 +1123,6 @@ export declare class ObservableSanityClient {
1123
1123
  * Instance properties
1124
1124
  */
1125
1125
  listen: typeof _listen
1126
- syncTags: typeof _syncTags
1127
1126
  constructor(httpRequest: HttpRequest, config?: ClientConfig)
1128
1127
  /**
1129
1128
  * Clone the client - returns a new instance
@@ -1832,7 +1831,6 @@ export declare interface RawQueryResponse<R> {
1832
1831
  ms: number
1833
1832
  result: R
1834
1833
  resultSourceMap?: ContentSourceMap
1835
- syncTags?: `s1:${string}`[]
1836
1834
  }
1837
1835
 
1838
1836
  /** @internal */
@@ -1945,7 +1943,6 @@ export declare class SanityClient {
1945
1943
  * Instance properties
1946
1944
  */
1947
1945
  listen: typeof _listen
1948
- syncTags: typeof _syncTags
1949
1946
  constructor(httpRequest: HttpRequest, config?: ClientConfig)
1950
1947
  /**
1951
1948
  * Clone the client - returns a new instance
@@ -2598,35 +2595,6 @@ export {StudioBaseUrl}
2598
2595
 
2599
2596
  export {StudioUrl}
2600
2597
 
2601
- /** @public */
2602
- export declare function _syncTags(
2603
- this: SanityClient | ObservableSanityClient,
2604
- opts?: SyncTagsOptions,
2605
- ): Observable<SyncTagsChangeEvent | SyncTagsErrorEvent | SyncTagsRestartEvent>
2606
-
2607
- /** @public */
2608
- export declare interface SyncTagsChangeEvent {
2609
- tags: `s1:${string}`[]
2610
- pos: string
2611
- }
2612
-
2613
- /** @public */
2614
- export declare interface SyncTagsErrorEvent {
2615
- type: 'error'
2616
- status: number
2617
- message: string
2618
- }
2619
-
2620
- /** @public */
2621
- export declare interface SyncTagsOptions {
2622
- pos?: string
2623
- }
2624
-
2625
- /** @public */
2626
- export declare interface SyncTagsRestartEvent {
2627
- type: 'restart'
2628
- }
2629
-
2630
2598
  /** @public */
2631
2599
  export declare class Transaction extends BaseTransaction {
2632
2600
  #private
@@ -1123,7 +1123,6 @@ export declare class ObservableSanityClient {
1123
1123
  * Instance properties
1124
1124
  */
1125
1125
  listen: typeof _listen
1126
- syncTags: typeof _syncTags
1127
1126
  constructor(httpRequest: HttpRequest, config?: ClientConfig)
1128
1127
  /**
1129
1128
  * Clone the client - returns a new instance
@@ -1832,7 +1831,6 @@ export declare interface RawQueryResponse<R> {
1832
1831
  ms: number
1833
1832
  result: R
1834
1833
  resultSourceMap?: ContentSourceMap
1835
- syncTags?: `s1:${string}`[]
1836
1834
  }
1837
1835
 
1838
1836
  /** @internal */
@@ -1945,7 +1943,6 @@ export declare class SanityClient {
1945
1943
  * Instance properties
1946
1944
  */
1947
1945
  listen: typeof _listen
1948
- syncTags: typeof _syncTags
1949
1946
  constructor(httpRequest: HttpRequest, config?: ClientConfig)
1950
1947
  /**
1951
1948
  * Clone the client - returns a new instance
@@ -2598,35 +2595,6 @@ export {StudioBaseUrl}
2598
2595
 
2599
2596
  export {StudioUrl}
2600
2597
 
2601
- /** @public */
2602
- export declare function _syncTags(
2603
- this: SanityClient | ObservableSanityClient,
2604
- opts?: SyncTagsOptions,
2605
- ): Observable<SyncTagsChangeEvent | SyncTagsErrorEvent | SyncTagsRestartEvent>
2606
-
2607
- /** @public */
2608
- export declare interface SyncTagsChangeEvent {
2609
- tags: `s1:${string}`[]
2610
- pos: string
2611
- }
2612
-
2613
- /** @public */
2614
- export declare interface SyncTagsErrorEvent {
2615
- type: 'error'
2616
- status: number
2617
- message: string
2618
- }
2619
-
2620
- /** @public */
2621
- export declare interface SyncTagsOptions {
2622
- pos?: string
2623
- }
2624
-
2625
- /** @public */
2626
- export declare interface SyncTagsRestartEvent {
2627
- type: 'restart'
2628
- }
2629
-
2630
2598
  /** @public */
2631
2599
  export declare class Transaction extends BaseTransaction {
2632
2600
  #private
@@ -856,13 +856,8 @@ function _listen(query, params, opts = {}) {
856
856
  return (token || withCredentials) && (esOptions.withCredentials = !0), token && (esOptions.headers = {
857
857
  Authorization: `Bearer ${token}`
858
858
  }), new Observable((observer) => {
859
- let es;
860
- getEventSource().then((eventSource) => {
861
- es = eventSource;
862
- }).catch((reason) => {
863
- observer.error(reason), stop();
864
- });
865
- let reconnectTimer, stopped = !1;
859
+ let es, reconnectTimer, stopped = !1, unsubscribed = !1;
860
+ open();
866
861
  function onError() {
867
862
  stopped || (emitReconnect(), !stopped && es.readyState === es.CLOSED && (unsubscribe(), clearTimeout(reconnectTimer), reconnectTimer = setTimeout(open, 100)));
868
863
  }
@@ -883,18 +878,21 @@ function _listen(query, params, opts = {}) {
883
878
  shouldEmitReconnect && observer.next({ type: "reconnect" });
884
879
  }
885
880
  async function getEventSource() {
886
- const { default: EventSource } = await import("@sanity/eventsource"), evs = new EventSource(uri, esOptions);
881
+ const { default: EventSource } = await import("@sanity/eventsource");
882
+ if (unsubscribed)
883
+ return;
884
+ const evs = new EventSource(uri, esOptions);
887
885
  return evs.addEventListener("error", onError), evs.addEventListener("channelError", onChannelError), evs.addEventListener("disconnect", onDisconnect), listenFor.forEach((type) => evs.addEventListener(type, onMessage)), evs;
888
886
  }
889
887
  function open() {
890
888
  getEventSource().then((eventSource) => {
891
- es = eventSource;
889
+ eventSource && (es = eventSource);
892
890
  }).catch((reason) => {
893
891
  observer.error(reason), stop();
894
892
  });
895
893
  }
896
894
  function stop() {
897
- stopped = !0, unsubscribe();
895
+ stopped = !0, unsubscribe(), unsubscribed = !0;
898
896
  }
899
897
  return stop;
900
898
  });
@@ -916,57 +914,6 @@ function cooerceError(err) {
916
914
  function extractErrorMessage(err) {
917
915
  return err.error ? err.error.description ? err.error.description : typeof err.error == "string" ? err.error : JSON.stringify(err.error, null, 2) : err.message || "Unknown listener error";
918
916
  }
919
- function _syncTags(opts = {}) {
920
- const path = _getDataUrl(this, "sync-tags"), url = new URL(this.getUrl(path, !0));
921
- return opts.pos && url.searchParams.append("start", opts.pos), new Observable((observer) => {
922
- const controller = new AbortController(), { signal } = controller;
923
- return fetch(url, { signal }).then(async (res) => {
924
- if (!res.body)
925
- throw new TypeError("Response body is not readable");
926
- const reader = res.body.pipeThrough(new TextDecoderStream()).pipeThrough(splitStream(`
927
- `)).pipeThrough(parseJSON()).getReader(), results = {
928
- [Symbol.asyncIterator]() {
929
- return {
930
- next: () => reader.read()
931
- };
932
- }
933
- };
934
- for await (const chunk of results) {
935
- if (signal.aborted)
936
- break;
937
- if (chunk.type === "error") {
938
- observer.error(chunk);
939
- break;
940
- }
941
- observer.next(chunk);
942
- }
943
- }).catch((err) => {
944
- (err == null ? void 0 : err.name) !== "TimeoutError" && (err == null ? void 0 : err.name) !== "AbortError" && observer.error(err);
945
- }), () => {
946
- controller.abort();
947
- };
948
- });
949
- }
950
- function splitStream(splitOn) {
951
- let buffer = "";
952
- return new TransformStream({
953
- transform(chunk, controller) {
954
- buffer += chunk;
955
- const parts = buffer.split(splitOn);
956
- parts.slice(0, -1).forEach((part) => controller.enqueue(part)), buffer = parts[parts.length - 1];
957
- },
958
- flush(controller) {
959
- buffer && controller.enqueue(buffer);
960
- }
961
- });
962
- }
963
- function parseJSON() {
964
- return new TransformStream({
965
- transform(chunk, controller) {
966
- chunk && controller.enqueue(JSON.parse(chunk));
967
- }
968
- });
969
- }
970
917
  var __accessCheck$3 = (obj, member, msg) => {
971
918
  if (!member.has(obj))
972
919
  throw TypeError("Cannot " + msg);
@@ -1171,7 +1118,7 @@ var __defProp = Object.defineProperty, __defNormalProp = (obj, key, value) => ke
1171
1118
  }, __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value), _clientConfig, _httpRequest;
1172
1119
  const _ObservableSanityClient = class _ObservableSanityClient2 {
1173
1120
  constructor(httpRequest, config = defaultConfig) {
1174
- __publicField(this, "assets"), __publicField(this, "datasets"), __publicField(this, "projects"), __publicField(this, "users"), __privateAdd(this, _clientConfig, void 0), __privateAdd(this, _httpRequest, void 0), __publicField(this, "listen", _listen), __publicField(this, "syncTags", _syncTags), this.config(config), __privateSet(this, _httpRequest, httpRequest), this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest)), this.datasets = new ObservableDatasetsClient(this, __privateGet(this, _httpRequest)), this.projects = new ObservableProjectsClient(this, __privateGet(this, _httpRequest)), this.users = new ObservableUsersClient(this, __privateGet(this, _httpRequest));
1121
+ __publicField(this, "assets"), __publicField(this, "datasets"), __publicField(this, "projects"), __publicField(this, "users"), __privateAdd(this, _clientConfig, void 0), __privateAdd(this, _httpRequest, void 0), __publicField(this, "listen", _listen), this.config(config), __privateSet(this, _httpRequest, httpRequest), this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest)), this.datasets = new ObservableDatasetsClient(this, __privateGet(this, _httpRequest)), this.projects = new ObservableProjectsClient(this, __privateGet(this, _httpRequest)), this.users = new ObservableUsersClient(this, __privateGet(this, _httpRequest));
1175
1122
  }
1176
1123
  /**
1177
1124
  * Clone the client - returns a new instance
@@ -1300,7 +1247,7 @@ let ObservableSanityClient = _ObservableSanityClient;
1300
1247
  var _clientConfig2, _httpRequest2;
1301
1248
  const _SanityClient = class _SanityClient2 {
1302
1249
  constructor(httpRequest, config = defaultConfig) {
1303
- __publicField(this, "assets"), __publicField(this, "datasets"), __publicField(this, "projects"), __publicField(this, "users"), __publicField(this, "observable"), __privateAdd(this, _clientConfig2, void 0), __privateAdd(this, _httpRequest2, void 0), __publicField(this, "listen", _listen), __publicField(this, "syncTags", _syncTags), this.config(config), __privateSet(this, _httpRequest2, httpRequest), this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2)), this.datasets = new DatasetsClient(this, __privateGet(this, _httpRequest2)), this.projects = new ProjectsClient(this, __privateGet(this, _httpRequest2)), this.users = new UsersClient(this, __privateGet(this, _httpRequest2)), this.observable = new ObservableSanityClient(httpRequest, config);
1250
+ __publicField(this, "assets"), __publicField(this, "datasets"), __publicField(this, "projects"), __publicField(this, "users"), __publicField(this, "observable"), __privateAdd(this, _clientConfig2, void 0), __privateAdd(this, _httpRequest2, void 0), __publicField(this, "listen", _listen), this.config(config), __privateSet(this, _httpRequest2, httpRequest), this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2)), this.datasets = new DatasetsClient(this, __privateGet(this, _httpRequest2)), this.projects = new ProjectsClient(this, __privateGet(this, _httpRequest2)), this.users = new UsersClient(this, __privateGet(this, _httpRequest2)), this.observable = new ObservableSanityClient(httpRequest, config);
1304
1251
  }
1305
1252
  /**
1306
1253
  * Clone the client - returns a new instance