@sanity/client 6.17.2 → 6.17.3-canary.1

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.
@@ -618,8 +618,8 @@ const encodeQueryString = ({
618
618
  autoGenerateArrayKeys: options.autoGenerateArrayKeys,
619
619
  skipCrossDatasetReferenceValidation: options.skipCrossDatasetReferenceValidation
620
620
  }), isResponse = (event) => event.type === "response", getBody = (event) => event.body, indexBy = (docs, attr) => docs.reduce((indexed, doc) => (indexed[attr(doc)] = doc, indexed), /* @__PURE__ */ Object.create(null)), getQuerySizeLimit = 11264;
621
- function _fetch(client, httpRequest, _stega, query, _params = {}, options = {}) {
622
- const stega = "stega" in options ? {
621
+ function _fetch(client, httpRequest, _stega, query, __params = {}, options = {}) {
622
+ const _params = options.refresh ? { ...__params, _: options.refresh } : __params, stega = "stega" in options ? {
623
623
  ..._stega || {},
624
624
  ...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
625
625
  } : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, { cache, next, ...opts } = {
@@ -931,6 +931,57 @@ function cooerceError(err) {
931
931
  function extractErrorMessage(err) {
932
932
  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";
933
933
  }
934
+ function _live(opts = {}) {
935
+ const path = _getDataUrl(this, "sync-tags"), url = new URL(this.getUrl(path, !1));
936
+ return opts.start && url.searchParams.append("start", opts.start), new rxjs.Observable((observer) => {
937
+ const controller = new AbortController(), { signal } = controller;
938
+ return fetch(url, { signal }).then(async (res) => {
939
+ if (!res.body)
940
+ throw new TypeError("Response body is not readable");
941
+ const reader = res.body.pipeThrough(new TextDecoderStream()).pipeThrough(splitStream(`
942
+ `)).pipeThrough(parseJSON()).getReader(), results = {
943
+ [Symbol.asyncIterator]() {
944
+ return {
945
+ next: () => reader.read()
946
+ };
947
+ }
948
+ };
949
+ for await (const chunk of results) {
950
+ if (signal.aborted)
951
+ break;
952
+ if (chunk.type === "error") {
953
+ observer.error(chunk);
954
+ break;
955
+ }
956
+ observer.next(chunk);
957
+ }
958
+ }).catch((err) => {
959
+ (err == null ? void 0 : err.name) !== "TimeoutError" && (err == null ? void 0 : err.name) !== "AbortError" && observer.error(err);
960
+ }), () => {
961
+ controller.abort();
962
+ };
963
+ });
964
+ }
965
+ function splitStream(splitOn) {
966
+ let buffer = "";
967
+ return new TransformStream({
968
+ transform(chunk, controller) {
969
+ buffer += chunk;
970
+ const parts = buffer.split(splitOn);
971
+ parts.slice(0, -1).forEach((part) => controller.enqueue(part)), buffer = parts[parts.length - 1];
972
+ },
973
+ flush(controller) {
974
+ buffer && controller.enqueue(buffer);
975
+ }
976
+ });
977
+ }
978
+ function parseJSON() {
979
+ return new TransformStream({
980
+ transform(chunk, controller) {
981
+ chunk && controller.enqueue(JSON.parse(chunk));
982
+ }
983
+ });
984
+ }
934
985
  var __accessCheck$3 = (obj, member, msg) => {
935
986
  if (!member.has(obj))
936
987
  throw TypeError("Cannot " + msg);
@@ -1135,7 +1186,7 @@ var __defProp2 = Object.defineProperty, __defNormalProp = (obj, key, value) => k
1135
1186
  }, __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value), _clientConfig, _httpRequest;
1136
1187
  const _ObservableSanityClient = class _ObservableSanityClient2 {
1137
1188
  constructor(httpRequest, config = defaultConfig) {
1138
- __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));
1189
+ __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));
1139
1190
  }
1140
1191
  /**
1141
1192
  * Clone the client - returns a new instance
@@ -1264,7 +1315,7 @@ let ObservableSanityClient = _ObservableSanityClient;
1264
1315
  var _clientConfig2, _httpRequest2;
1265
1316
  const _SanityClient = class _SanityClient2 {
1266
1317
  constructor(httpRequest, config = defaultConfig) {
1267
- __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);
1318
+ __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);
1268
1319
  }
1269
1320
  /**
1270
1321
  * Clone the client - returns a new instance