@sanity/client 5.0.0-esm.13 → 5.0.0-esm.15

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.cjs CHANGED
@@ -15,7 +15,7 @@ function _interopDefaultCompat(e) {
15
15
  }
16
16
  var polyfilledEventSource__default = /*#__PURE__*/_interopDefaultCompat(polyfilledEventSource);
17
17
  var name = "@sanity/client";
18
- var version = "5.0.0-esm.13";
18
+ var version = "5.0.0-esm.15";
19
19
  const middleware = [middleware$1.debug({
20
20
  verbose: true,
21
21
  namespace: "sanity:client"
@@ -198,60 +198,50 @@ const requestTag = tag => {
198
198
  }
199
199
  return tag;
200
200
  };
201
- const enc = encodeURIComponent;
202
201
  var encodeQueryString = _ref => {
203
202
  let {
204
203
  query,
205
204
  params = {},
206
205
  options = {}
207
206
  } = _ref;
207
+ const searchParams = new URLSearchParams();
208
208
  const {
209
209
  tag,
210
210
  ...opts
211
211
  } = options;
212
- const q = "query=".concat(enc(query));
213
- const base = tag ? "?tag=".concat(enc(tag), "&").concat(q) : "?".concat(q);
214
- const qString = Object.keys(params).reduce((qs, param) => "".concat(qs, "&").concat(enc("$".concat(param)), "=").concat(enc(JSON.stringify(params[param]))), base);
215
- return Object.keys(opts).reduce((qs, option) => {
216
- return options[option] ? "".concat(qs, "&").concat(enc(option), "=").concat(enc(options[option])) : qs;
217
- }, qString);
212
+ if (tag) searchParams.set("tag", tag);
213
+ searchParams.set("query", query);
214
+ for (const [key, value] of Object.entries(params)) {
215
+ searchParams.set("$".concat(key), JSON.stringify(value));
216
+ }
217
+ for (const [key, value] of Object.entries(opts)) {
218
+ if (value) searchParams.set(key, "".concat(value));
219
+ }
220
+ return "?".concat(searchParams);
218
221
  };
219
- var __accessCheck$7 = (obj, member, msg) => {
222
+ var __accessCheck$6 = (obj, member, msg) => {
220
223
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
221
224
  };
222
- var __privateGet$7 = (obj, member, getter) => {
223
- __accessCheck$7(obj, member, "read from private field");
225
+ var __privateGet$6 = (obj, member, getter) => {
226
+ __accessCheck$6(obj, member, "read from private field");
224
227
  return getter ? getter.call(obj) : member.get(obj);
225
228
  };
226
- var __privateAdd$7 = (obj, member, value) => {
229
+ var __privateAdd$6 = (obj, member, value) => {
227
230
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
228
231
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
229
232
  };
230
- var __privateSet$7 = (obj, member, value, setter) => {
231
- __accessCheck$7(obj, member, "write to private field");
233
+ var __privateSet$6 = (obj, member, value, setter) => {
234
+ __accessCheck$6(obj, member, "write to private field");
232
235
  setter ? setter.call(obj, value) : member.set(obj, value);
233
236
  return value;
234
237
  };
235
- var _client$6, _client2$6;
238
+ var _client$5, _client2$5;
236
239
  class BasePatch {
237
240
  constructor(selection) {
238
241
  let operations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
239
242
  this.selection = selection;
240
243
  this.operations = operations;
241
244
  }
242
- /**
243
- * DEPRECATED: Don't use.
244
- * The operation is added to the current patch, ready to be commited by `commit()`
245
- *
246
- * @deprecated - Don't use.
247
- * @param attrs - Attributes to replace
248
- */
249
- replace(attrs) {
250
- validateObject("replace", attrs);
251
- return this._set("set", {
252
- $: attrs
253
- });
254
- }
255
245
  /**
256
246
  * Sets the given attributes to the document. Does NOT merge objects.
257
247
  * The operation is added to the current patch, ready to be commited by `commit()`
@@ -405,8 +395,8 @@ class BasePatch {
405
395
  const _ObservablePatch = class extends BasePatch {
406
396
  constructor(selection, operations, client) {
407
397
  super(selection, operations);
408
- __privateAdd$7(this, _client$6, void 0);
409
- __privateSet$7(this, _client$6, client);
398
+ __privateAdd$6(this, _client$5, void 0);
399
+ __privateSet$6(this, _client$5, client);
410
400
  }
411
401
  /**
412
402
  * Clones the patch
@@ -414,10 +404,10 @@ const _ObservablePatch = class extends BasePatch {
414
404
  clone() {
415
405
  return new _ObservablePatch(this.selection, {
416
406
  ...this.operations
417
- }, __privateGet$7(this, _client$6));
407
+ }, __privateGet$6(this, _client$5));
418
408
  }
419
409
  commit(options) {
420
- if (!__privateGet$7(this, _client$6)) {
410
+ if (!__privateGet$6(this, _client$5)) {
421
411
  throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
422
412
  }
423
413
  const returnFirst = typeof this.selection === "string";
@@ -425,18 +415,18 @@ const _ObservablePatch = class extends BasePatch {
425
415
  returnFirst,
426
416
  returnDocuments: true
427
417
  }, options);
428
- return __privateGet$7(this, _client$6).mutate({
418
+ return __privateGet$6(this, _client$5).mutate({
429
419
  patch: this.serialize()
430
420
  }, opts);
431
421
  }
432
422
  };
433
423
  let ObservablePatch = _ObservablePatch;
434
- _client$6 = new WeakMap();
424
+ _client$5 = new WeakMap();
435
425
  const _Patch = class extends BasePatch {
436
426
  constructor(selection, operations, client) {
437
427
  super(selection, operations);
438
- __privateAdd$7(this, _client2$6, void 0);
439
- __privateSet$7(this, _client2$6, client);
428
+ __privateAdd$6(this, _client2$5, void 0);
429
+ __privateSet$6(this, _client2$5, client);
440
430
  }
441
431
  /**
442
432
  * Clones the patch
@@ -444,10 +434,10 @@ const _Patch = class extends BasePatch {
444
434
  clone() {
445
435
  return new _Patch(this.selection, {
446
436
  ...this.operations
447
- }, __privateGet$7(this, _client2$6));
437
+ }, __privateGet$6(this, _client2$5));
448
438
  }
449
439
  commit(options) {
450
- if (!__privateGet$7(this, _client2$6)) {
440
+ if (!__privateGet$6(this, _client2$5)) {
451
441
  throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
452
442
  }
453
443
  const returnFirst = typeof this.selection === "string";
@@ -455,30 +445,30 @@ const _Patch = class extends BasePatch {
455
445
  returnFirst,
456
446
  returnDocuments: true
457
447
  }, options);
458
- return __privateGet$7(this, _client2$6).mutate({
448
+ return __privateGet$6(this, _client2$5).mutate({
459
449
  patch: this.serialize()
460
450
  }, opts);
461
451
  }
462
452
  };
463
453
  let Patch = _Patch;
464
- _client2$6 = new WeakMap();
465
- var __accessCheck$6 = (obj, member, msg) => {
454
+ _client2$5 = new WeakMap();
455
+ var __accessCheck$5 = (obj, member, msg) => {
466
456
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
467
457
  };
468
- var __privateGet$6 = (obj, member, getter) => {
469
- __accessCheck$6(obj, member, "read from private field");
458
+ var __privateGet$5 = (obj, member, getter) => {
459
+ __accessCheck$5(obj, member, "read from private field");
470
460
  return getter ? getter.call(obj) : member.get(obj);
471
461
  };
472
- var __privateAdd$6 = (obj, member, value) => {
462
+ var __privateAdd$5 = (obj, member, value) => {
473
463
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
474
464
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
475
465
  };
476
- var __privateSet$6 = (obj, member, value, setter) => {
477
- __accessCheck$6(obj, member, "write to private field");
466
+ var __privateSet$5 = (obj, member, value, setter) => {
467
+ __accessCheck$5(obj, member, "write to private field");
478
468
  setter ? setter.call(obj, value) : member.set(obj, value);
479
469
  return value;
480
470
  };
481
- var _client$5, _client2$5;
471
+ var _client$4, _client2$4;
482
472
  const defaultMutateOptions = {
483
473
  returnDocuments: false
484
474
  };
@@ -577,20 +567,20 @@ class BaseTransaction {
577
567
  const _Transaction = class extends BaseTransaction {
578
568
  constructor(operations, client, transactionId) {
579
569
  super(operations, transactionId);
580
- __privateAdd$6(this, _client$5, void 0);
581
- __privateSet$6(this, _client$5, client);
570
+ __privateAdd$5(this, _client$4, void 0);
571
+ __privateSet$5(this, _client$4, client);
582
572
  }
583
573
  /**
584
574
  * Clones the transaction
585
575
  */
586
576
  clone() {
587
- return new _Transaction([...this.operations], __privateGet$6(this, _client$5), this.trxId);
577
+ return new _Transaction([...this.operations], __privateGet$5(this, _client$4), this.trxId);
588
578
  }
589
579
  commit(options) {
590
- if (!__privateGet$6(this, _client$5)) {
580
+ if (!__privateGet$5(this, _client$4)) {
591
581
  throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
592
582
  }
593
- return __privateGet$6(this, _client$5).mutate(this.serialize(), Object.assign({
583
+ return __privateGet$5(this, _client$4).mutate(this.serialize(), Object.assign({
594
584
  transactionId: this.trxId
595
585
  }, defaultMutateOptions, options || {}));
596
586
  }
@@ -603,7 +593,7 @@ const _Transaction = class extends BaseTransaction {
603
593
  });
604
594
  }
605
595
  if (isBuilder) {
606
- const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$6(this, _client$5)));
596
+ const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$5(this, _client$4)));
607
597
  if (!(patch instanceof Patch)) {
608
598
  throw new Error("function passed to `patch()` must return the patch");
609
599
  }
@@ -620,24 +610,24 @@ const _Transaction = class extends BaseTransaction {
620
610
  }
621
611
  };
622
612
  let Transaction = _Transaction;
623
- _client$5 = new WeakMap();
613
+ _client$4 = new WeakMap();
624
614
  const _ObservableTransaction = class extends BaseTransaction {
625
615
  constructor(operations, client, transactionId) {
626
616
  super(operations, transactionId);
627
- __privateAdd$6(this, _client2$5, void 0);
628
- __privateSet$6(this, _client2$5, client);
617
+ __privateAdd$5(this, _client2$4, void 0);
618
+ __privateSet$5(this, _client2$4, client);
629
619
  }
630
620
  /**
631
621
  * Clones the transaction
632
622
  */
633
623
  clone() {
634
- return new _ObservableTransaction([...this.operations], __privateGet$6(this, _client2$5), this.trxId);
624
+ return new _ObservableTransaction([...this.operations], __privateGet$5(this, _client2$4), this.trxId);
635
625
  }
636
626
  commit(options) {
637
- if (!__privateGet$6(this, _client2$5)) {
627
+ if (!__privateGet$5(this, _client2$4)) {
638
628
  throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
639
629
  }
640
- return __privateGet$6(this, _client2$5).mutate(this.serialize(), Object.assign({
630
+ return __privateGet$5(this, _client2$4).mutate(this.serialize(), Object.assign({
641
631
  transactionId: this.trxId
642
632
  }, defaultMutateOptions, options || {}));
643
633
  }
@@ -650,7 +640,7 @@ const _ObservableTransaction = class extends BaseTransaction {
650
640
  });
651
641
  }
652
642
  if (isBuilder) {
653
- const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$6(this, _client2$5)));
643
+ const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$5(this, _client2$4)));
654
644
  if (!(patch instanceof ObservablePatch)) {
655
645
  throw new Error("function passed to `patch()` must return the patch");
656
646
  }
@@ -667,7 +657,7 @@ const _ObservableTransaction = class extends BaseTransaction {
667
657
  }
668
658
  };
669
659
  let ObservableTransaction = _ObservableTransaction;
670
- _client2$5 = new WeakMap();
660
+ _client2$4 = new WeakMap();
671
661
  const excludeFalsey = (param, defValue) => {
672
662
  const value = typeof param === "undefined" ? defValue : param;
673
663
  return param === false ? void 0 : value;
@@ -839,50 +829,50 @@ function _getUrl(client, uri) {
839
829
  const base = canUseCdn ? cdnUrl : url;
840
830
  return "".concat(base, "/").concat(uri.replace(/^\//, ""));
841
831
  }
842
- var __accessCheck$5 = (obj, member, msg) => {
832
+ var __accessCheck$4 = (obj, member, msg) => {
843
833
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
844
834
  };
845
- var __privateGet$5 = (obj, member, getter) => {
846
- __accessCheck$5(obj, member, "read from private field");
835
+ var __privateGet$4 = (obj, member, getter) => {
836
+ __accessCheck$4(obj, member, "read from private field");
847
837
  return getter ? getter.call(obj) : member.get(obj);
848
838
  };
849
- var __privateAdd$5 = (obj, member, value) => {
839
+ var __privateAdd$4 = (obj, member, value) => {
850
840
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
851
841
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
852
842
  };
853
- var __privateSet$5 = (obj, member, value, setter) => {
854
- __accessCheck$5(obj, member, "write to private field");
843
+ var __privateSet$4 = (obj, member, value, setter) => {
844
+ __accessCheck$4(obj, member, "write to private field");
855
845
  setter ? setter.call(obj, value) : member.set(obj, value);
856
846
  return value;
857
847
  };
858
- var _client$4, _httpRequest$5, _client2$4, _httpRequest2$5;
848
+ var _client$3, _httpRequest$4, _client2$3, _httpRequest2$4;
859
849
  class ObservableAssetsClient {
860
850
  constructor(client, httpRequest) {
861
- __privateAdd$5(this, _client$4, void 0);
862
- __privateAdd$5(this, _httpRequest$5, void 0);
863
- __privateSet$5(this, _client$4, client);
864
- __privateSet$5(this, _httpRequest$5, httpRequest);
851
+ __privateAdd$4(this, _client$3, void 0);
852
+ __privateAdd$4(this, _httpRequest$4, void 0);
853
+ __privateSet$4(this, _client$3, client);
854
+ __privateSet$4(this, _httpRequest$4, httpRequest);
865
855
  }
866
856
  upload(assetType, body, options) {
867
- return _upload(__privateGet$5(this, _client$4), __privateGet$5(this, _httpRequest$5), assetType, body, options);
857
+ return _upload(__privateGet$4(this, _client$3), __privateGet$4(this, _httpRequest$4), assetType, body, options);
868
858
  }
869
859
  }
870
- _client$4 = new WeakMap();
871
- _httpRequest$5 = new WeakMap();
860
+ _client$3 = new WeakMap();
861
+ _httpRequest$4 = new WeakMap();
872
862
  class AssetsClient {
873
863
  constructor(client, httpRequest) {
874
- __privateAdd$5(this, _client2$4, void 0);
875
- __privateAdd$5(this, _httpRequest2$5, void 0);
876
- __privateSet$5(this, _client2$4, client);
877
- __privateSet$5(this, _httpRequest2$5, httpRequest);
864
+ __privateAdd$4(this, _client2$3, void 0);
865
+ __privateAdd$4(this, _httpRequest2$4, void 0);
866
+ __privateSet$4(this, _client2$3, client);
867
+ __privateSet$4(this, _httpRequest2$4, httpRequest);
878
868
  }
879
869
  upload(assetType, body, options) {
880
- const observable = _upload(__privateGet$5(this, _client2$4), __privateGet$5(this, _httpRequest2$5), assetType, body, options);
870
+ const observable = _upload(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), assetType, body, options);
881
871
  return rxjs.lastValueFrom(observable.pipe(operators.filter(event => event.type === "response"), operators.map(event => event.body.document)));
882
872
  }
883
873
  }
884
- _client2$4 = new WeakMap();
885
- _httpRequest2$5 = new WeakMap();
874
+ _client2$3 = new WeakMap();
875
+ _httpRequest2$4 = new WeakMap();
886
876
  function _upload(client, httpRequest, assetType, body) {
887
877
  let opts = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
888
878
  validateAssetType(assetType);
@@ -936,77 +926,6 @@ function optionsFromFile(opts, file) {
936
926
  contentType: file.type
937
927
  }, opts);
938
928
  }
939
- var __accessCheck$4 = (obj, member, msg) => {
940
- if (!member.has(obj)) throw TypeError("Cannot " + msg);
941
- };
942
- var __privateGet$4 = (obj, member, getter) => {
943
- __accessCheck$4(obj, member, "read from private field");
944
- return getter ? getter.call(obj) : member.get(obj);
945
- };
946
- var __privateAdd$4 = (obj, member, value) => {
947
- if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
948
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
949
- };
950
- var __privateSet$4 = (obj, member, value, setter) => {
951
- __accessCheck$4(obj, member, "write to private field");
952
- setter ? setter.call(obj, value) : member.set(obj, value);
953
- return value;
954
- };
955
- var _client$3, _httpRequest$4, _client2$3, _httpRequest2$4;
956
- class ObservableAuthClient {
957
- constructor(client, httpRequest) {
958
- __privateAdd$4(this, _client$3, void 0);
959
- __privateAdd$4(this, _httpRequest$4, void 0);
960
- __privateSet$4(this, _client$3, client);
961
- __privateSet$4(this, _httpRequest$4, httpRequest);
962
- }
963
- /**
964
- * Fetch available login providers
965
- */
966
- getLoginProviders() {
967
- return _request(__privateGet$4(this, _client$3), __privateGet$4(this, _httpRequest$4), {
968
- uri: "/auth/providers"
969
- });
970
- }
971
- /**
972
- * Revoke the configured session/token
973
- */
974
- logout() {
975
- return _request(__privateGet$4(this, _client$3), __privateGet$4(this, _httpRequest$4), {
976
- uri: "/auth/logout",
977
- method: "POST"
978
- });
979
- }
980
- }
981
- _client$3 = new WeakMap();
982
- _httpRequest$4 = new WeakMap();
983
- class AuthClient {
984
- constructor(client, httpRequest) {
985
- __privateAdd$4(this, _client2$3, void 0);
986
- __privateAdd$4(this, _httpRequest2$4, void 0);
987
- __privateSet$4(this, _client2$3, client);
988
- __privateSet$4(this, _httpRequest2$4, httpRequest);
989
- }
990
- /**
991
- * Fetch available login providers
992
- */
993
- getLoginProviders() {
994
- return rxjs.lastValueFrom(_request(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), {
995
- uri: "/auth/providers"
996
- }));
997
- }
998
- /**
999
- * Revoke the configured session/token
1000
- */
1001
- logout() {
1002
- return rxjs.lastValueFrom(_request(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), {
1003
- uri: "/auth/logout",
1004
- method: "POST"
1005
- }));
1006
- }
1007
- }
1008
- _client2$3 = new WeakMap();
1009
- _httpRequest2$4 = new WeakMap();
1010
929
  const BASE_URL = "https://www.sanity.io/help/";
1011
930
  function generateHelpUrl(slug) {
1012
931
  return BASE_URL + slug;
@@ -1509,10 +1428,13 @@ const _ObservableSanityClient = class {
1509
1428
  */
1510
1429
  __privateAdd(this, _clientConfig, void 0);
1511
1430
  __privateAdd(this, _httpRequest, void 0);
1431
+ /**
1432
+ * Instance properties
1433
+ */
1434
+ this.listen = _listen;
1512
1435
  this.config(config);
1513
1436
  __privateSet(this, _httpRequest, httpRequest);
1514
1437
  this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest));
1515
- this.auth = new ObservableAuthClient(this, __privateGet(this, _httpRequest));
1516
1438
  this.datasets = new ObservableDatasetsClient(this, __privateGet(this, _httpRequest));
1517
1439
  this.projects = new ObservableProjectsClient(this, __privateGet(this, _httpRequest));
1518
1440
  this.users = new ObservableUsersClient(this, __privateGet(this, _httpRequest));
@@ -1631,7 +1553,6 @@ const _SanityClient = class {
1631
1553
  this.config(config);
1632
1554
  __privateSet(this, _httpRequest2, httpRequest);
1633
1555
  this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2));
1634
- this.auth = new AuthClient(this, __privateGet(this, _httpRequest2));
1635
1556
  this.datasets = new DatasetsClient(this, __privateGet(this, _httpRequest2));
1636
1557
  this.projects = new ProjectsClient(this, __privateGet(this, _httpRequest2));
1637
1558
  this.users = new UsersClient(this, __privateGet(this, _httpRequest2));