@sanity/client 6.17.3 → 6.18.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.cts CHANGED
@@ -775,6 +775,27 @@ export declare type ListenParams = {
775
775
  [key: string]: Any
776
776
  }
777
777
 
778
+ /**
779
+ * @alpha this API is experimental and may change or even be removed
780
+ */
781
+ export declare class LiveClient {
782
+ #private
783
+ constructor(client: SanityClient | ObservableSanityClient)
784
+ events(): Observable<LiveEventMessage | LiveEventRestart>
785
+ }
786
+
787
+ /** @alpha this API is experimental and may change or even be removed */
788
+ export declare interface LiveEventMessage {
789
+ type: 'message'
790
+ id: string
791
+ tags: SyncTag[]
792
+ }
793
+
794
+ /** @alpha this API is experimental and may change or even be removed */
795
+ export declare interface LiveEventRestart {
796
+ type: 'restart'
797
+ }
798
+
778
799
  /** @public */
779
800
  export declare type Logger =
780
801
  | typeof console
@@ -1117,6 +1138,7 @@ export declare class ObservableSanityClient {
1117
1138
  #private
1118
1139
  assets: ObservableAssetsClient
1119
1140
  datasets: ObservableDatasetsClient
1141
+ live: LiveClient
1120
1142
  projects: ObservableProjectsClient
1121
1143
  users: ObservableUsersClient
1122
1144
  /**
@@ -1814,6 +1836,8 @@ export declare interface QueryParams {
1814
1836
  token?: never
1815
1837
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
1816
1838
  useCdn?: never
1839
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
1840
+ lastLiveEventId?: never
1817
1841
  }
1818
1842
 
1819
1843
  /**
@@ -1831,6 +1855,8 @@ export declare interface RawQueryResponse<R> {
1831
1855
  ms: number
1832
1856
  result: R
1833
1857
  resultSourceMap?: ContentSourceMap
1858
+ /** @alpha this API is experimental and may change or even be removed */
1859
+ syncTags?: SyncTag[]
1834
1860
  }
1835
1861
 
1836
1862
  /** @internal */
@@ -1877,6 +1903,8 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
1877
1903
  returnQuery?: boolean
1878
1904
  resultSourceMap?: boolean | 'withKeyArraySelector'
1879
1905
  perspective?: ClientPerspective
1906
+ /** @alpha this API is experimental and may change or even be removed */
1907
+ lastLiveEventId?: string
1880
1908
  }
1881
1909
 
1882
1910
  /** @public */
@@ -1913,6 +1941,8 @@ export declare interface ResponseQueryOptions extends RequestOptions {
1913
1941
  stega?: boolean | StegaConfig
1914
1942
  cache?: 'next' extends keyof RequestInit ? RequestInit['cache'] : never
1915
1943
  next?: ('next' extends keyof RequestInit ? RequestInit : never)['next']
1944
+ /** @alpha this API is experimental and may change or even be removed */
1945
+ lastLiveEventId?: string | string[] | null
1916
1946
  }
1917
1947
 
1918
1948
  /** @internal */
@@ -1933,6 +1963,7 @@ export declare class SanityClient {
1933
1963
  #private
1934
1964
  assets: AssetsClient
1935
1965
  datasets: DatasetsClient
1966
+ live: LiveClient
1936
1967
  projects: ProjectsClient
1937
1968
  users: UsersClient
1938
1969
  /**
@@ -2595,6 +2626,9 @@ export {StudioBaseUrl}
2595
2626
 
2596
2627
  export {StudioUrl}
2597
2628
 
2629
+ /** @alpha this API is experimental and may change or even be removed */
2630
+ export declare type SyncTag = `s1:${string}`
2631
+
2598
2632
  /** @public */
2599
2633
  export declare class Transaction extends BaseTransaction {
2600
2634
  #private
package/dist/index.d.ts CHANGED
@@ -775,6 +775,27 @@ export declare type ListenParams = {
775
775
  [key: string]: Any
776
776
  }
777
777
 
778
+ /**
779
+ * @alpha this API is experimental and may change or even be removed
780
+ */
781
+ export declare class LiveClient {
782
+ #private
783
+ constructor(client: SanityClient | ObservableSanityClient)
784
+ events(): Observable<LiveEventMessage | LiveEventRestart>
785
+ }
786
+
787
+ /** @alpha this API is experimental and may change or even be removed */
788
+ export declare interface LiveEventMessage {
789
+ type: 'message'
790
+ id: string
791
+ tags: SyncTag[]
792
+ }
793
+
794
+ /** @alpha this API is experimental and may change or even be removed */
795
+ export declare interface LiveEventRestart {
796
+ type: 'restart'
797
+ }
798
+
778
799
  /** @public */
779
800
  export declare type Logger =
780
801
  | typeof console
@@ -1117,6 +1138,7 @@ export declare class ObservableSanityClient {
1117
1138
  #private
1118
1139
  assets: ObservableAssetsClient
1119
1140
  datasets: ObservableDatasetsClient
1141
+ live: LiveClient
1120
1142
  projects: ObservableProjectsClient
1121
1143
  users: ObservableUsersClient
1122
1144
  /**
@@ -1814,6 +1836,8 @@ export declare interface QueryParams {
1814
1836
  token?: never
1815
1837
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
1816
1838
  useCdn?: never
1839
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
1840
+ lastLiveEventId?: never
1817
1841
  }
1818
1842
 
1819
1843
  /**
@@ -1831,6 +1855,8 @@ export declare interface RawQueryResponse<R> {
1831
1855
  ms: number
1832
1856
  result: R
1833
1857
  resultSourceMap?: ContentSourceMap
1858
+ /** @alpha this API is experimental and may change or even be removed */
1859
+ syncTags?: SyncTag[]
1834
1860
  }
1835
1861
 
1836
1862
  /** @internal */
@@ -1877,6 +1903,8 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
1877
1903
  returnQuery?: boolean
1878
1904
  resultSourceMap?: boolean | 'withKeyArraySelector'
1879
1905
  perspective?: ClientPerspective
1906
+ /** @alpha this API is experimental and may change or even be removed */
1907
+ lastLiveEventId?: string
1880
1908
  }
1881
1909
 
1882
1910
  /** @public */
@@ -1913,6 +1941,8 @@ export declare interface ResponseQueryOptions extends RequestOptions {
1913
1941
  stega?: boolean | StegaConfig
1914
1942
  cache?: 'next' extends keyof RequestInit ? RequestInit['cache'] : never
1915
1943
  next?: ('next' extends keyof RequestInit ? RequestInit : never)['next']
1944
+ /** @alpha this API is experimental and may change or even be removed */
1945
+ lastLiveEventId?: string | string[] | null
1916
1946
  }
1917
1947
 
1918
1948
  /** @internal */
@@ -1933,6 +1963,7 @@ export declare class SanityClient {
1933
1963
  #private
1934
1964
  assets: AssetsClient
1935
1965
  datasets: DatasetsClient
1966
+ live: LiveClient
1936
1967
  projects: ProjectsClient
1937
1968
  users: UsersClient
1938
1969
  /**
@@ -2595,6 +2626,9 @@ export {StudioBaseUrl}
2595
2626
 
2596
2627
  export {StudioUrl}
2597
2628
 
2629
+ /** @alpha this API is experimental and may change or even be removed */
2630
+ export declare type SyncTag = `s1:${string}`
2631
+
2598
2632
  /** @public */
2599
2633
  export declare class Transaction extends BaseTransaction {
2600
2634
  #private
package/dist/index.js CHANGED
@@ -144,14 +144,14 @@ const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = ["before",
144
144
  );
145
145
  return tag;
146
146
  };
147
- var __defProp$2 = Object.defineProperty, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$2 = (obj, key, value) => (__defNormalProp$2(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck$6 = (obj, member, msg) => {
147
+ var __defProp$2 = Object.defineProperty, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$2 = (obj, key, value) => (__defNormalProp$2(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck$7 = (obj, member, msg) => {
148
148
  if (!member.has(obj))
149
149
  throw TypeError("Cannot " + msg);
150
- }, __privateGet$6 = (obj, member, getter) => (__accessCheck$6(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$6 = (obj, member, value) => {
150
+ }, __privateGet$7 = (obj, member, getter) => (__accessCheck$7(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$7 = (obj, member, value) => {
151
151
  if (member.has(obj))
152
152
  throw TypeError("Cannot add the same private member more than once");
153
153
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
154
- }, __privateSet$6 = (obj, member, value, setter) => (__accessCheck$6(obj, member, "write to private field"), member.set(obj, value), value);
154
+ }, __privateSet$7 = (obj, member, value, setter) => (__accessCheck$7(obj, member, "write to private field"), member.set(obj, value), value);
155
155
  class BasePatch {
156
156
  constructor(selection, operations = {}) {
157
157
  __publicField$2(this, "selection"), __publicField$2(this, "operations"), this.selection = selection, this.operations = operations;
@@ -285,58 +285,58 @@ class BasePatch {
285
285
  return this._assign(op, props, !1);
286
286
  }
287
287
  }
288
- var _client$5;
288
+ var _client$6;
289
289
  const _ObservablePatch = class _ObservablePatch2 extends BasePatch {
290
290
  constructor(selection, operations, client) {
291
- super(selection, operations), __privateAdd$6(this, _client$5, void 0), __privateSet$6(this, _client$5, client);
291
+ super(selection, operations), __privateAdd$7(this, _client$6, void 0), __privateSet$7(this, _client$6, client);
292
292
  }
293
293
  /**
294
294
  * Clones the patch
295
295
  */
296
296
  clone() {
297
- return new _ObservablePatch2(this.selection, { ...this.operations }, __privateGet$6(this, _client$5));
297
+ return new _ObservablePatch2(this.selection, { ...this.operations }, __privateGet$7(this, _client$6));
298
298
  }
299
299
  commit(options) {
300
- if (!__privateGet$6(this, _client$5))
300
+ if (!__privateGet$7(this, _client$6))
301
301
  throw new Error(
302
302
  "No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method"
303
303
  );
304
304
  const returnFirst = typeof this.selection == "string", opts = Object.assign({ returnFirst, returnDocuments: !0 }, options);
305
- return __privateGet$6(this, _client$5).mutate({ patch: this.serialize() }, opts);
305
+ return __privateGet$7(this, _client$6).mutate({ patch: this.serialize() }, opts);
306
306
  }
307
307
  };
308
- _client$5 = /* @__PURE__ */ new WeakMap();
308
+ _client$6 = /* @__PURE__ */ new WeakMap();
309
309
  let ObservablePatch = _ObservablePatch;
310
310
  var _client2$5;
311
311
  const _Patch = class _Patch2 extends BasePatch {
312
312
  constructor(selection, operations, client) {
313
- super(selection, operations), __privateAdd$6(this, _client2$5, void 0), __privateSet$6(this, _client2$5, client);
313
+ super(selection, operations), __privateAdd$7(this, _client2$5, void 0), __privateSet$7(this, _client2$5, client);
314
314
  }
315
315
  /**
316
316
  * Clones the patch
317
317
  */
318
318
  clone() {
319
- return new _Patch2(this.selection, { ...this.operations }, __privateGet$6(this, _client2$5));
319
+ return new _Patch2(this.selection, { ...this.operations }, __privateGet$7(this, _client2$5));
320
320
  }
321
321
  commit(options) {
322
- if (!__privateGet$6(this, _client2$5))
322
+ if (!__privateGet$7(this, _client2$5))
323
323
  throw new Error(
324
324
  "No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method"
325
325
  );
326
326
  const returnFirst = typeof this.selection == "string", opts = Object.assign({ returnFirst, returnDocuments: !0 }, options);
327
- return __privateGet$6(this, _client2$5).mutate({ patch: this.serialize() }, opts);
327
+ return __privateGet$7(this, _client2$5).mutate({ patch: this.serialize() }, opts);
328
328
  }
329
329
  };
330
330
  _client2$5 = /* @__PURE__ */ new WeakMap();
331
331
  let Patch = _Patch;
332
- var __defProp$1 = Object.defineProperty, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$1 = (obj, key, value) => (__defNormalProp$1(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck$5 = (obj, member, msg) => {
332
+ var __defProp$1 = Object.defineProperty, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$1 = (obj, key, value) => (__defNormalProp$1(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck$6 = (obj, member, msg) => {
333
333
  if (!member.has(obj))
334
334
  throw TypeError("Cannot " + msg);
335
- }, __privateGet$5 = (obj, member, getter) => (__accessCheck$5(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$5 = (obj, member, value) => {
335
+ }, __privateGet$6 = (obj, member, getter) => (__accessCheck$6(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$6 = (obj, member, value) => {
336
336
  if (member.has(obj))
337
337
  throw TypeError("Cannot add the same private member more than once");
338
338
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
339
- }, __privateSet$5 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), member.set(obj, value), value);
339
+ }, __privateSet$6 = (obj, member, value, setter) => (__accessCheck$6(obj, member, "write to private field"), member.set(obj, value), value);
340
340
  const defaultMutateOptions = { returnDocuments: !1 };
341
341
  class BaseTransaction {
342
342
  constructor(operations = [], transactionId) {
@@ -405,23 +405,23 @@ class BaseTransaction {
405
405
  return this.operations.push(mut), this;
406
406
  }
407
407
  }
408
- var _client$4;
408
+ var _client$5;
409
409
  const _Transaction = class _Transaction2 extends BaseTransaction {
410
410
  constructor(operations, client, transactionId) {
411
- super(operations, transactionId), __privateAdd$5(this, _client$4, void 0), __privateSet$5(this, _client$4, client);
411
+ super(operations, transactionId), __privateAdd$6(this, _client$5, void 0), __privateSet$6(this, _client$5, client);
412
412
  }
413
413
  /**
414
414
  * Clones the transaction
415
415
  */
416
416
  clone() {
417
- return new _Transaction2([...this.operations], __privateGet$5(this, _client$4), this.trxId);
417
+ return new _Transaction2([...this.operations], __privateGet$6(this, _client$5), this.trxId);
418
418
  }
419
419
  commit(options) {
420
- if (!__privateGet$5(this, _client$4))
420
+ if (!__privateGet$6(this, _client$5))
421
421
  throw new Error(
422
422
  "No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method"
423
423
  );
424
- return __privateGet$5(this, _client$4).mutate(
424
+ return __privateGet$6(this, _client$5).mutate(
425
425
  this.serialize(),
426
426
  Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {})
427
427
  );
@@ -431,7 +431,7 @@ const _Transaction = class _Transaction2 extends BaseTransaction {
431
431
  if (typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof Patch)
432
432
  return this._add({ patch: patchOrDocumentId.serialize() });
433
433
  if (isBuilder) {
434
- const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$5(this, _client$4)));
434
+ const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$6(this, _client$5)));
435
435
  if (!(patch instanceof Patch))
436
436
  throw new Error("function passed to `patch()` must return the patch");
437
437
  return this._add({ patch: patch.serialize() });
@@ -439,25 +439,25 @@ const _Transaction = class _Transaction2 extends BaseTransaction {
439
439
  return this._add({ patch: { id: patchOrDocumentId, ...patchOps } });
440
440
  }
441
441
  };
442
- _client$4 = /* @__PURE__ */ new WeakMap();
442
+ _client$5 = /* @__PURE__ */ new WeakMap();
443
443
  let Transaction = _Transaction;
444
444
  var _client2$4;
445
445
  const _ObservableTransaction = class _ObservableTransaction2 extends BaseTransaction {
446
446
  constructor(operations, client, transactionId) {
447
- super(operations, transactionId), __privateAdd$5(this, _client2$4, void 0), __privateSet$5(this, _client2$4, client);
447
+ super(operations, transactionId), __privateAdd$6(this, _client2$4, void 0), __privateSet$6(this, _client2$4, client);
448
448
  }
449
449
  /**
450
450
  * Clones the transaction
451
451
  */
452
452
  clone() {
453
- return new _ObservableTransaction2([...this.operations], __privateGet$5(this, _client2$4), this.trxId);
453
+ return new _ObservableTransaction2([...this.operations], __privateGet$6(this, _client2$4), this.trxId);
454
454
  }
455
455
  commit(options) {
456
- if (!__privateGet$5(this, _client2$4))
456
+ if (!__privateGet$6(this, _client2$4))
457
457
  throw new Error(
458
458
  "No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method"
459
459
  );
460
- return __privateGet$5(this, _client2$4).mutate(
460
+ return __privateGet$6(this, _client2$4).mutate(
461
461
  this.serialize(),
462
462
  Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {})
463
463
  );
@@ -467,7 +467,7 @@ const _ObservableTransaction = class _ObservableTransaction2 extends BaseTransac
467
467
  if (typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof ObservablePatch)
468
468
  return this._add({ patch: patchOrDocumentId.serialize() });
469
469
  if (isBuilder) {
470
- const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$5(this, _client2$4)));
470
+ const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$6(this, _client2$4)));
471
471
  if (!(patch instanceof ObservablePatch))
472
472
  throw new Error("function passed to `patch()` must return the patch");
473
473
  return this._add({ patch: patch.serialize() });
@@ -675,7 +675,7 @@ function _mutate(client, httpRequest, mutations, options) {
675
675
  return _dataRequest(client, httpRequest, "mutate", { mutations: muts, transactionId }, options);
676
676
  }
677
677
  function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
678
- const isMutation = endpoint === "mutate", isQuery = endpoint === "query", strQuery = isMutation ? "" : encodeQueryString(body), useGet = !isMutation && strQuery.length < getQuerySizeLimit, stringQuery = useGet ? strQuery : "", returnFirst = options.returnFirst, { timeout, token, tag, headers: headers2, returnQuery } = options, uri = _getDataUrl(client, endpoint, stringQuery), reqOptions = {
678
+ const isMutation = endpoint === "mutate", isQuery = endpoint === "query", strQuery = isMutation ? "" : encodeQueryString(body), useGet = !isMutation && strQuery.length < getQuerySizeLimit, stringQuery = useGet ? strQuery : "", returnFirst = options.returnFirst, { timeout, token, tag, headers: headers2, returnQuery, lastLiveEventId } = options, uri = _getDataUrl(client, endpoint, stringQuery), reqOptions = {
679
679
  method: useGet ? "GET" : "POST",
680
680
  uri,
681
681
  json: !0,
@@ -688,6 +688,7 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
688
688
  returnQuery,
689
689
  perspective: options.perspective,
690
690
  resultSourceMap: options.resultSourceMap,
691
+ lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
691
692
  canUseCdn: isQuery,
692
693
  signal: options.signal,
693
694
  fetch: options.fetch,
@@ -725,7 +726,7 @@ function _requestObservable(client, httpRequest, options) {
725
726
  const resultSourceMap = (_b = options.resultSourceMap) != null ? _b : config.resultSourceMap;
726
727
  resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
727
728
  const perspective = options.perspective || config.perspective;
728
- typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query });
729
+ typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query });
729
730
  }
730
731
  const reqOptions = requestOptions(
731
732
  config,
@@ -772,30 +773,30 @@ function _createAbortError(signal) {
772
773
  const error = new Error((_b = signal == null ? void 0 : signal.reason) != null ? _b : "The operation was aborted.");
773
774
  return error.name = "AbortError", error;
774
775
  }
775
- var __accessCheck$4 = (obj, member, msg) => {
776
+ var __accessCheck$5 = (obj, member, msg) => {
776
777
  if (!member.has(obj))
777
778
  throw TypeError("Cannot " + msg);
778
- }, __privateGet$4 = (obj, member, getter) => (__accessCheck$4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$4 = (obj, member, value) => {
779
+ }, __privateGet$5 = (obj, member, getter) => (__accessCheck$5(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$5 = (obj, member, value) => {
779
780
  if (member.has(obj))
780
781
  throw TypeError("Cannot add the same private member more than once");
781
782
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
782
- }, __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value), _client$3, _httpRequest$4;
783
+ }, __privateSet$5 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), member.set(obj, value), value), _client$4, _httpRequest$4;
783
784
  class ObservableAssetsClient {
784
785
  constructor(client, httpRequest) {
785
- __privateAdd$4(this, _client$3, void 0), __privateAdd$4(this, _httpRequest$4, void 0), __privateSet$4(this, _client$3, client), __privateSet$4(this, _httpRequest$4, httpRequest);
786
+ __privateAdd$5(this, _client$4, void 0), __privateAdd$5(this, _httpRequest$4, void 0), __privateSet$5(this, _client$4, client), __privateSet$5(this, _httpRequest$4, httpRequest);
786
787
  }
787
788
  upload(assetType, body, options) {
788
- return _upload(__privateGet$4(this, _client$3), __privateGet$4(this, _httpRequest$4), assetType, body, options);
789
+ return _upload(__privateGet$5(this, _client$4), __privateGet$5(this, _httpRequest$4), assetType, body, options);
789
790
  }
790
791
  }
791
- _client$3 = /* @__PURE__ */ new WeakMap(), _httpRequest$4 = /* @__PURE__ */ new WeakMap();
792
+ _client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$4 = /* @__PURE__ */ new WeakMap();
792
793
  var _client2$3, _httpRequest2$4;
793
794
  class AssetsClient {
794
795
  constructor(client, httpRequest) {
795
- __privateAdd$4(this, _client2$3, void 0), __privateAdd$4(this, _httpRequest2$4, void 0), __privateSet$4(this, _client2$3, client), __privateSet$4(this, _httpRequest2$4, httpRequest);
796
+ __privateAdd$5(this, _client2$3, void 0), __privateAdd$5(this, _httpRequest2$4, void 0), __privateSet$5(this, _client2$3, client), __privateSet$5(this, _httpRequest2$4, httpRequest);
796
797
  }
797
798
  upload(assetType, body, options) {
798
- const observable2 = _upload(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), assetType, body, options);
799
+ const observable2 = _upload(__privateGet$5(this, _client2$3), __privateGet$5(this, _httpRequest2$4), assetType, body, options);
799
800
  return lastValueFrom(
800
801
  observable2.pipe(
801
802
  filter((event) => event.type === "response"),
@@ -865,7 +866,7 @@ function _listen(query, params, opts = {}) {
865
866
  observer.error(cooerceError(err));
866
867
  }
867
868
  function onMessage(evt) {
868
- const event = parseEvent(evt);
869
+ const event = parseEvent$1(evt);
869
870
  return event instanceof Error ? observer.error(event) : observer.next(event);
870
871
  }
871
872
  function onDisconnect() {
@@ -878,10 +879,10 @@ function _listen(query, params, opts = {}) {
878
879
  shouldEmitReconnect && observer.next({ type: "reconnect" });
879
880
  }
880
881
  async function getEventSource() {
881
- const { default: EventSource } = await import("@sanity/eventsource");
882
+ const { default: EventSource2 } = await import("@sanity/eventsource");
882
883
  if (unsubscribed)
883
884
  return;
884
- const evs = new EventSource(uri, esOptions);
885
+ const evs = new EventSource2(uri, esOptions);
885
886
  return evs.addEventListener("error", onError), evs.addEventListener("channelError", onChannelError), evs.addEventListener("disconnect", onDisconnect), listenFor.forEach((type) => evs.addEventListener(type, onMessage)), evs;
886
887
  }
887
888
  function open() {
@@ -897,7 +898,7 @@ function _listen(query, params, opts = {}) {
897
898
  return stop;
898
899
  });
899
900
  }
900
- function parseEvent(event) {
901
+ function parseEvent$1(event) {
901
902
  try {
902
903
  const data = event.data && JSON.parse(event.data) || {};
903
904
  return Object.assign({ type: event.type }, data);
@@ -908,12 +909,83 @@ function parseEvent(event) {
908
909
  function cooerceError(err) {
909
910
  if (err instanceof Error)
910
911
  return err;
911
- const evt = parseEvent(err);
912
+ const evt = parseEvent$1(err);
912
913
  return evt instanceof Error ? evt : new Error(extractErrorMessage(evt));
913
914
  }
914
915
  function extractErrorMessage(err) {
915
916
  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
917
  }
918
+ var __accessCheck$4 = (obj, member, msg) => {
919
+ if (!member.has(obj))
920
+ throw TypeError("Cannot " + msg);
921
+ }, __privateGet$4 = (obj, member, getter) => (__accessCheck$4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$4 = (obj, member, value) => {
922
+ if (member.has(obj))
923
+ throw TypeError("Cannot add the same private member more than once");
924
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
925
+ }, __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value), _client$3;
926
+ class LiveClient {
927
+ constructor(client) {
928
+ __privateAdd$4(this, _client$3, void 0), __privateSet$4(this, _client$3, client);
929
+ }
930
+ events() {
931
+ const path = _getDataUrl(__privateGet$4(this, _client$3), "live/events"), url = new URL(__privateGet$4(this, _client$3).getUrl(path, !1)), listenFor = ["restart", "message"];
932
+ return new Observable((observer) => {
933
+ let es, reconnectTimer, stopped = !1, unsubscribed = !1;
934
+ open();
935
+ function onError(evt) {
936
+ if (!stopped) {
937
+ if ("data" in evt) {
938
+ const event = parseEvent(evt);
939
+ observer.error(new Error(event.message, { cause: event }));
940
+ }
941
+ es.readyState === es.CLOSED && (unsubscribe(), clearTimeout(reconnectTimer), reconnectTimer = setTimeout(open, 100));
942
+ }
943
+ }
944
+ function onMessage(evt) {
945
+ const event = parseEvent(evt);
946
+ return event instanceof Error ? observer.error(event) : observer.next(event);
947
+ }
948
+ function unsubscribe() {
949
+ if (es) {
950
+ es.removeEventListener("error", onError);
951
+ for (const type of listenFor)
952
+ es.removeEventListener(type, onMessage);
953
+ es.close();
954
+ }
955
+ }
956
+ async function getEventSource() {
957
+ const EventSourceImplementation = typeof EventSource > "u" ? (await import("@sanity/eventsource")).default : EventSource;
958
+ if (unsubscribed)
959
+ return;
960
+ const evs = new EventSourceImplementation(url.toString());
961
+ evs.addEventListener("error", onError);
962
+ for (const type of listenFor)
963
+ evs.addEventListener(type, onMessage);
964
+ return evs;
965
+ }
966
+ function open() {
967
+ getEventSource().then((eventSource) => {
968
+ eventSource && (es = eventSource, unsubscribed && unsubscribe());
969
+ }).catch((reason) => {
970
+ observer.error(reason), stop();
971
+ });
972
+ }
973
+ function stop() {
974
+ stopped = !0, unsubscribe(), unsubscribed = !0;
975
+ }
976
+ return stop;
977
+ });
978
+ }
979
+ }
980
+ _client$3 = /* @__PURE__ */ new WeakMap();
981
+ function parseEvent(event) {
982
+ try {
983
+ const data = event.data && JSON.parse(event.data) || {};
984
+ return { type: event.type, id: event.lastEventId, ...data };
985
+ } catch (err) {
986
+ return err;
987
+ }
988
+ }
917
989
  var __accessCheck$3 = (obj, member, msg) => {
918
990
  if (!member.has(obj))
919
991
  throw TypeError("Cannot " + msg);
@@ -1118,7 +1190,7 @@ var __defProp = Object.defineProperty, __defNormalProp = (obj, key, value) => ke
1118
1190
  }, __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value), _clientConfig, _httpRequest;
1119
1191
  const _ObservableSanityClient = class _ObservableSanityClient2 {
1120
1192
  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));
1193
+ __publicField(this, "assets"), __publicField(this, "datasets"), __publicField(this, "live"), __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.live = new LiveClient(this), this.projects = new ObservableProjectsClient(this, __privateGet(this, _httpRequest)), this.users = new ObservableUsersClient(this, __privateGet(this, _httpRequest));
1122
1194
  }
1123
1195
  /**
1124
1196
  * Clone the client - returns a new instance
@@ -1247,7 +1319,7 @@ let ObservableSanityClient = _ObservableSanityClient;
1247
1319
  var _clientConfig2, _httpRequest2;
1248
1320
  const _SanityClient = class _SanityClient2 {
1249
1321
  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);
1322
+ __publicField(this, "assets"), __publicField(this, "datasets"), __publicField(this, "live"), __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.live = new LiveClient(this), this.projects = new ProjectsClient(this, __privateGet(this, _httpRequest2)), this.users = new UsersClient(this, __privateGet(this, _httpRequest2)), this.observable = new ObservableSanityClient(httpRequest, config);
1251
1323
  }
1252
1324
  /**
1253
1325
  * Clone the client - returns a new instance
@@ -1413,7 +1485,7 @@ function defineDeprecatedCreateClient(createClient2) {
1413
1485
  return printNoDefaultExport(), createClient2(config);
1414
1486
  };
1415
1487
  }
1416
- var name = "@sanity/client", version = "6.17.3";
1488
+ var name = "@sanity/client", version = "6.18.0";
1417
1489
  const middleware = [
1418
1490
  debug({ verbose: !0, namespace: "sanity:client" }),
1419
1491
  headers({ "User-Agent": `${name} ${version}` }),