@sanity/client 6.17.2 → 6.17.3-canary.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.
@@ -775,6 +775,35 @@ export declare type ListenParams = {
775
775
  [key: string]: Any
776
776
  }
777
777
 
778
+ /** @public */
779
+ export declare function _live(
780
+ this: SanityClient | ObservableSanityClient,
781
+ opts?: LiveOptions,
782
+ ): Observable<LiveChangeEvent | LiveErrorEvent | LiveRestartEvent>
783
+
784
+ /** @public */
785
+ export declare interface LiveChangeEvent {
786
+ tags: `s1:${string}`[]
787
+ pos: string
788
+ }
789
+
790
+ /** @public */
791
+ export declare interface LiveErrorEvent {
792
+ type: 'error'
793
+ status: number
794
+ message: string
795
+ }
796
+
797
+ /** @public */
798
+ export declare interface LiveOptions {
799
+ start?: string
800
+ }
801
+
802
+ /** @public */
803
+ export declare interface LiveRestartEvent {
804
+ type: 'restart'
805
+ }
806
+
778
807
  /** @public */
779
808
  export declare type Logger =
780
809
  | typeof console
@@ -1123,6 +1152,7 @@ export declare class ObservableSanityClient {
1123
1152
  * Instance properties
1124
1153
  */
1125
1154
  listen: typeof _listen
1155
+ live: typeof _live
1126
1156
  constructor(httpRequest: HttpRequest, config?: ClientConfig)
1127
1157
  /**
1128
1158
  * Clone the client - returns a new instance
@@ -1831,6 +1861,7 @@ export declare interface RawQueryResponse<R> {
1831
1861
  ms: number
1832
1862
  result: R
1833
1863
  resultSourceMap?: ContentSourceMap
1864
+ syncTags?: `s1:${string}`[]
1834
1865
  }
1835
1866
 
1836
1867
  /** @internal */
@@ -1943,6 +1974,7 @@ export declare class SanityClient {
1943
1974
  * Instance properties
1944
1975
  */
1945
1976
  listen: typeof _listen
1977
+ live: typeof _live
1946
1978
  constructor(httpRequest: HttpRequest, config?: ClientConfig)
1947
1979
  /**
1948
1980
  * Clone the client - returns a new instance
@@ -775,6 +775,35 @@ export declare type ListenParams = {
775
775
  [key: string]: Any
776
776
  }
777
777
 
778
+ /** @public */
779
+ export declare function _live(
780
+ this: SanityClient | ObservableSanityClient,
781
+ opts?: LiveOptions,
782
+ ): Observable<LiveChangeEvent | LiveErrorEvent | LiveRestartEvent>
783
+
784
+ /** @public */
785
+ export declare interface LiveChangeEvent {
786
+ tags: `s1:${string}`[]
787
+ pos: string
788
+ }
789
+
790
+ /** @public */
791
+ export declare interface LiveErrorEvent {
792
+ type: 'error'
793
+ status: number
794
+ message: string
795
+ }
796
+
797
+ /** @public */
798
+ export declare interface LiveOptions {
799
+ start?: string
800
+ }
801
+
802
+ /** @public */
803
+ export declare interface LiveRestartEvent {
804
+ type: 'restart'
805
+ }
806
+
778
807
  /** @public */
779
808
  export declare type Logger =
780
809
  | typeof console
@@ -1123,6 +1152,7 @@ export declare class ObservableSanityClient {
1123
1152
  * Instance properties
1124
1153
  */
1125
1154
  listen: typeof _listen
1155
+ live: typeof _live
1126
1156
  constructor(httpRequest: HttpRequest, config?: ClientConfig)
1127
1157
  /**
1128
1158
  * Clone the client - returns a new instance
@@ -1831,6 +1861,7 @@ export declare interface RawQueryResponse<R> {
1831
1861
  ms: number
1832
1862
  result: R
1833
1863
  resultSourceMap?: ContentSourceMap
1864
+ syncTags?: `s1:${string}`[]
1834
1865
  }
1835
1866
 
1836
1867
  /** @internal */
@@ -1943,6 +1974,7 @@ export declare class SanityClient {
1943
1974
  * Instance properties
1944
1975
  */
1945
1976
  listen: typeof _listen
1977
+ live: typeof _live
1946
1978
  constructor(httpRequest: HttpRequest, config?: ClientConfig)
1947
1979
  /**
1948
1980
  * Clone the client - returns a new instance
@@ -914,6 +914,57 @@ function cooerceError(err) {
914
914
  function extractErrorMessage(err) {
915
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";
916
916
  }
917
+ function _live(opts = {}) {
918
+ const path = _getDataUrl(this, "sync-tags"), url = new URL(this.getUrl(path, !1));
919
+ return opts.start && url.searchParams.append("start", opts.start), new Observable((observer) => {
920
+ const controller = new AbortController(), { signal } = controller;
921
+ return fetch(url, { signal }).then(async (res) => {
922
+ if (!res.body)
923
+ throw new TypeError("Response body is not readable");
924
+ const reader = res.body.pipeThrough(new TextDecoderStream()).pipeThrough(splitStream(`
925
+ `)).pipeThrough(parseJSON()).getReader(), results = {
926
+ [Symbol.asyncIterator]() {
927
+ return {
928
+ next: () => reader.read()
929
+ };
930
+ }
931
+ };
932
+ for await (const chunk of results) {
933
+ if (signal.aborted)
934
+ break;
935
+ if (chunk.type === "error") {
936
+ observer.error(chunk);
937
+ break;
938
+ }
939
+ observer.next(chunk);
940
+ }
941
+ }).catch((err) => {
942
+ (err == null ? void 0 : err.name) !== "TimeoutError" && (err == null ? void 0 : err.name) !== "AbortError" && observer.error(err);
943
+ }), () => {
944
+ controller.abort();
945
+ };
946
+ });
947
+ }
948
+ function splitStream(splitOn) {
949
+ let buffer = "";
950
+ return new TransformStream({
951
+ transform(chunk, controller) {
952
+ buffer += chunk;
953
+ const parts = buffer.split(splitOn);
954
+ parts.slice(0, -1).forEach((part) => controller.enqueue(part)), buffer = parts[parts.length - 1];
955
+ },
956
+ flush(controller) {
957
+ buffer && controller.enqueue(buffer);
958
+ }
959
+ });
960
+ }
961
+ function parseJSON() {
962
+ return new TransformStream({
963
+ transform(chunk, controller) {
964
+ chunk && controller.enqueue(JSON.parse(chunk));
965
+ }
966
+ });
967
+ }
917
968
  var __accessCheck$3 = (obj, member, msg) => {
918
969
  if (!member.has(obj))
919
970
  throw TypeError("Cannot " + msg);
@@ -1118,7 +1169,7 @@ var __defProp = Object.defineProperty, __defNormalProp = (obj, key, value) => ke
1118
1169
  }, __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value), _clientConfig, _httpRequest;
1119
1170
  const _ObservableSanityClient = class _ObservableSanityClient2 {
1120
1171
  constructor(httpRequest, config = defaultConfig) {
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));
1172
+ __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, "live", _live), 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));
1122
1173
  }
1123
1174
  /**
1124
1175
  * Clone the client - returns a new instance
@@ -1247,7 +1298,7 @@ let ObservableSanityClient = _ObservableSanityClient;
1247
1298
  var _clientConfig2, _httpRequest2;
1248
1299
  const _SanityClient = class _SanityClient2 {
1249
1300
  constructor(httpRequest, config = defaultConfig) {
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);
1301
+ __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, "live", _live), 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);
1251
1302
  }
1252
1303
  /**
1253
1304
  * Clone the client - returns a new instance