@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.
@@ -178,60 +178,50 @@ const requestTag = tag => {
178
178
  }
179
179
  return tag;
180
180
  };
181
- const enc = encodeURIComponent;
182
181
  var encodeQueryString = _ref => {
183
182
  let {
184
183
  query,
185
184
  params = {},
186
185
  options = {}
187
186
  } = _ref;
187
+ const searchParams = new URLSearchParams();
188
188
  const {
189
189
  tag,
190
190
  ...opts
191
191
  } = options;
192
- const q = "query=".concat(enc(query));
193
- const base = tag ? "?tag=".concat(enc(tag), "&").concat(q) : "?".concat(q);
194
- const qString = Object.keys(params).reduce((qs, param) => "".concat(qs, "&").concat(enc("$".concat(param)), "=").concat(enc(JSON.stringify(params[param]))), base);
195
- return Object.keys(opts).reduce((qs, option) => {
196
- return options[option] ? "".concat(qs, "&").concat(enc(option), "=").concat(enc(options[option])) : qs;
197
- }, qString);
192
+ if (tag) searchParams.set("tag", tag);
193
+ searchParams.set("query", query);
194
+ for (const [key, value] of Object.entries(params)) {
195
+ searchParams.set("$".concat(key), JSON.stringify(value));
196
+ }
197
+ for (const [key, value] of Object.entries(opts)) {
198
+ if (value) searchParams.set(key, "".concat(value));
199
+ }
200
+ return "?".concat(searchParams);
198
201
  };
199
- var __accessCheck$7 = (obj, member, msg) => {
202
+ var __accessCheck$6 = (obj, member, msg) => {
200
203
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
201
204
  };
202
- var __privateGet$7 = (obj, member, getter) => {
203
- __accessCheck$7(obj, member, "read from private field");
205
+ var __privateGet$6 = (obj, member, getter) => {
206
+ __accessCheck$6(obj, member, "read from private field");
204
207
  return getter ? getter.call(obj) : member.get(obj);
205
208
  };
206
- var __privateAdd$7 = (obj, member, value) => {
209
+ var __privateAdd$6 = (obj, member, value) => {
207
210
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
208
211
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
209
212
  };
210
- var __privateSet$7 = (obj, member, value, setter) => {
211
- __accessCheck$7(obj, member, "write to private field");
213
+ var __privateSet$6 = (obj, member, value, setter) => {
214
+ __accessCheck$6(obj, member, "write to private field");
212
215
  setter ? setter.call(obj, value) : member.set(obj, value);
213
216
  return value;
214
217
  };
215
- var _client$6, _client2$6;
218
+ var _client$5, _client2$5;
216
219
  class BasePatch {
217
220
  constructor(selection) {
218
221
  let operations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
219
222
  this.selection = selection;
220
223
  this.operations = operations;
221
224
  }
222
- /**
223
- * DEPRECATED: Don't use.
224
- * The operation is added to the current patch, ready to be commited by `commit()`
225
- *
226
- * @deprecated - Don't use.
227
- * @param attrs - Attributes to replace
228
- */
229
- replace(attrs) {
230
- validateObject("replace", attrs);
231
- return this._set("set", {
232
- $: attrs
233
- });
234
- }
235
225
  /**
236
226
  * Sets the given attributes to the document. Does NOT merge objects.
237
227
  * The operation is added to the current patch, ready to be commited by `commit()`
@@ -385,8 +375,8 @@ class BasePatch {
385
375
  const _ObservablePatch = class extends BasePatch {
386
376
  constructor(selection, operations, client) {
387
377
  super(selection, operations);
388
- __privateAdd$7(this, _client$6, void 0);
389
- __privateSet$7(this, _client$6, client);
378
+ __privateAdd$6(this, _client$5, void 0);
379
+ __privateSet$6(this, _client$5, client);
390
380
  }
391
381
  /**
392
382
  * Clones the patch
@@ -394,10 +384,10 @@ const _ObservablePatch = class extends BasePatch {
394
384
  clone() {
395
385
  return new _ObservablePatch(this.selection, {
396
386
  ...this.operations
397
- }, __privateGet$7(this, _client$6));
387
+ }, __privateGet$6(this, _client$5));
398
388
  }
399
389
  commit(options) {
400
- if (!__privateGet$7(this, _client$6)) {
390
+ if (!__privateGet$6(this, _client$5)) {
401
391
  throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
402
392
  }
403
393
  const returnFirst = typeof this.selection === "string";
@@ -405,18 +395,18 @@ const _ObservablePatch = class extends BasePatch {
405
395
  returnFirst,
406
396
  returnDocuments: true
407
397
  }, options);
408
- return __privateGet$7(this, _client$6).mutate({
398
+ return __privateGet$6(this, _client$5).mutate({
409
399
  patch: this.serialize()
410
400
  }, opts);
411
401
  }
412
402
  };
413
403
  let ObservablePatch = _ObservablePatch;
414
- _client$6 = new WeakMap();
404
+ _client$5 = new WeakMap();
415
405
  const _Patch = class extends BasePatch {
416
406
  constructor(selection, operations, client) {
417
407
  super(selection, operations);
418
- __privateAdd$7(this, _client2$6, void 0);
419
- __privateSet$7(this, _client2$6, client);
408
+ __privateAdd$6(this, _client2$5, void 0);
409
+ __privateSet$6(this, _client2$5, client);
420
410
  }
421
411
  /**
422
412
  * Clones the patch
@@ -424,10 +414,10 @@ const _Patch = class extends BasePatch {
424
414
  clone() {
425
415
  return new _Patch(this.selection, {
426
416
  ...this.operations
427
- }, __privateGet$7(this, _client2$6));
417
+ }, __privateGet$6(this, _client2$5));
428
418
  }
429
419
  commit(options) {
430
- if (!__privateGet$7(this, _client2$6)) {
420
+ if (!__privateGet$6(this, _client2$5)) {
431
421
  throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
432
422
  }
433
423
  const returnFirst = typeof this.selection === "string";
@@ -435,30 +425,30 @@ const _Patch = class extends BasePatch {
435
425
  returnFirst,
436
426
  returnDocuments: true
437
427
  }, options);
438
- return __privateGet$7(this, _client2$6).mutate({
428
+ return __privateGet$6(this, _client2$5).mutate({
439
429
  patch: this.serialize()
440
430
  }, opts);
441
431
  }
442
432
  };
443
433
  let Patch = _Patch;
444
- _client2$6 = new WeakMap();
445
- var __accessCheck$6 = (obj, member, msg) => {
434
+ _client2$5 = new WeakMap();
435
+ var __accessCheck$5 = (obj, member, msg) => {
446
436
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
447
437
  };
448
- var __privateGet$6 = (obj, member, getter) => {
449
- __accessCheck$6(obj, member, "read from private field");
438
+ var __privateGet$5 = (obj, member, getter) => {
439
+ __accessCheck$5(obj, member, "read from private field");
450
440
  return getter ? getter.call(obj) : member.get(obj);
451
441
  };
452
- var __privateAdd$6 = (obj, member, value) => {
442
+ var __privateAdd$5 = (obj, member, value) => {
453
443
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
454
444
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
455
445
  };
456
- var __privateSet$6 = (obj, member, value, setter) => {
457
- __accessCheck$6(obj, member, "write to private field");
446
+ var __privateSet$5 = (obj, member, value, setter) => {
447
+ __accessCheck$5(obj, member, "write to private field");
458
448
  setter ? setter.call(obj, value) : member.set(obj, value);
459
449
  return value;
460
450
  };
461
- var _client$5, _client2$5;
451
+ var _client$4, _client2$4;
462
452
  const defaultMutateOptions = {
463
453
  returnDocuments: false
464
454
  };
@@ -557,20 +547,20 @@ class BaseTransaction {
557
547
  const _Transaction = class extends BaseTransaction {
558
548
  constructor(operations, client, transactionId) {
559
549
  super(operations, transactionId);
560
- __privateAdd$6(this, _client$5, void 0);
561
- __privateSet$6(this, _client$5, client);
550
+ __privateAdd$5(this, _client$4, void 0);
551
+ __privateSet$5(this, _client$4, client);
562
552
  }
563
553
  /**
564
554
  * Clones the transaction
565
555
  */
566
556
  clone() {
567
- return new _Transaction([...this.operations], __privateGet$6(this, _client$5), this.trxId);
557
+ return new _Transaction([...this.operations], __privateGet$5(this, _client$4), this.trxId);
568
558
  }
569
559
  commit(options) {
570
- if (!__privateGet$6(this, _client$5)) {
560
+ if (!__privateGet$5(this, _client$4)) {
571
561
  throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
572
562
  }
573
- return __privateGet$6(this, _client$5).mutate(this.serialize(), Object.assign({
563
+ return __privateGet$5(this, _client$4).mutate(this.serialize(), Object.assign({
574
564
  transactionId: this.trxId
575
565
  }, defaultMutateOptions, options || {}));
576
566
  }
@@ -583,7 +573,7 @@ const _Transaction = class extends BaseTransaction {
583
573
  });
584
574
  }
585
575
  if (isBuilder) {
586
- const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$6(this, _client$5)));
576
+ const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$5(this, _client$4)));
587
577
  if (!(patch instanceof Patch)) {
588
578
  throw new Error("function passed to `patch()` must return the patch");
589
579
  }
@@ -600,24 +590,24 @@ const _Transaction = class extends BaseTransaction {
600
590
  }
601
591
  };
602
592
  let Transaction = _Transaction;
603
- _client$5 = new WeakMap();
593
+ _client$4 = new WeakMap();
604
594
  const _ObservableTransaction = class extends BaseTransaction {
605
595
  constructor(operations, client, transactionId) {
606
596
  super(operations, transactionId);
607
- __privateAdd$6(this, _client2$5, void 0);
608
- __privateSet$6(this, _client2$5, client);
597
+ __privateAdd$5(this, _client2$4, void 0);
598
+ __privateSet$5(this, _client2$4, client);
609
599
  }
610
600
  /**
611
601
  * Clones the transaction
612
602
  */
613
603
  clone() {
614
- return new _ObservableTransaction([...this.operations], __privateGet$6(this, _client2$5), this.trxId);
604
+ return new _ObservableTransaction([...this.operations], __privateGet$5(this, _client2$4), this.trxId);
615
605
  }
616
606
  commit(options) {
617
- if (!__privateGet$6(this, _client2$5)) {
607
+ if (!__privateGet$5(this, _client2$4)) {
618
608
  throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
619
609
  }
620
- return __privateGet$6(this, _client2$5).mutate(this.serialize(), Object.assign({
610
+ return __privateGet$5(this, _client2$4).mutate(this.serialize(), Object.assign({
621
611
  transactionId: this.trxId
622
612
  }, defaultMutateOptions, options || {}));
623
613
  }
@@ -630,7 +620,7 @@ const _ObservableTransaction = class extends BaseTransaction {
630
620
  });
631
621
  }
632
622
  if (isBuilder) {
633
- const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$6(this, _client2$5)));
623
+ const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$5(this, _client2$4)));
634
624
  if (!(patch instanceof ObservablePatch)) {
635
625
  throw new Error("function passed to `patch()` must return the patch");
636
626
  }
@@ -647,7 +637,7 @@ const _ObservableTransaction = class extends BaseTransaction {
647
637
  }
648
638
  };
649
639
  let ObservableTransaction = _ObservableTransaction;
650
- _client2$5 = new WeakMap();
640
+ _client2$4 = new WeakMap();
651
641
  const excludeFalsey = (param, defValue) => {
652
642
  const value = typeof param === "undefined" ? defValue : param;
653
643
  return param === false ? void 0 : value;
@@ -819,50 +809,50 @@ function _getUrl(client, uri) {
819
809
  const base = canUseCdn ? cdnUrl : url;
820
810
  return "".concat(base, "/").concat(uri.replace(/^\//, ""));
821
811
  }
822
- var __accessCheck$5 = (obj, member, msg) => {
812
+ var __accessCheck$4 = (obj, member, msg) => {
823
813
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
824
814
  };
825
- var __privateGet$5 = (obj, member, getter) => {
826
- __accessCheck$5(obj, member, "read from private field");
815
+ var __privateGet$4 = (obj, member, getter) => {
816
+ __accessCheck$4(obj, member, "read from private field");
827
817
  return getter ? getter.call(obj) : member.get(obj);
828
818
  };
829
- var __privateAdd$5 = (obj, member, value) => {
819
+ var __privateAdd$4 = (obj, member, value) => {
830
820
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
831
821
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
832
822
  };
833
- var __privateSet$5 = (obj, member, value, setter) => {
834
- __accessCheck$5(obj, member, "write to private field");
823
+ var __privateSet$4 = (obj, member, value, setter) => {
824
+ __accessCheck$4(obj, member, "write to private field");
835
825
  setter ? setter.call(obj, value) : member.set(obj, value);
836
826
  return value;
837
827
  };
838
- var _client$4, _httpRequest$5, _client2$4, _httpRequest2$5;
828
+ var _client$3, _httpRequest$4, _client2$3, _httpRequest2$4;
839
829
  class ObservableAssetsClient {
840
830
  constructor(client, httpRequest) {
841
- __privateAdd$5(this, _client$4, void 0);
842
- __privateAdd$5(this, _httpRequest$5, void 0);
843
- __privateSet$5(this, _client$4, client);
844
- __privateSet$5(this, _httpRequest$5, httpRequest);
831
+ __privateAdd$4(this, _client$3, void 0);
832
+ __privateAdd$4(this, _httpRequest$4, void 0);
833
+ __privateSet$4(this, _client$3, client);
834
+ __privateSet$4(this, _httpRequest$4, httpRequest);
845
835
  }
846
836
  upload(assetType, body, options) {
847
- return _upload(__privateGet$5(this, _client$4), __privateGet$5(this, _httpRequest$5), assetType, body, options);
837
+ return _upload(__privateGet$4(this, _client$3), __privateGet$4(this, _httpRequest$4), assetType, body, options);
848
838
  }
849
839
  }
850
- _client$4 = new WeakMap();
851
- _httpRequest$5 = new WeakMap();
840
+ _client$3 = new WeakMap();
841
+ _httpRequest$4 = new WeakMap();
852
842
  class AssetsClient {
853
843
  constructor(client, httpRequest) {
854
- __privateAdd$5(this, _client2$4, void 0);
855
- __privateAdd$5(this, _httpRequest2$5, void 0);
856
- __privateSet$5(this, _client2$4, client);
857
- __privateSet$5(this, _httpRequest2$5, httpRequest);
844
+ __privateAdd$4(this, _client2$3, void 0);
845
+ __privateAdd$4(this, _httpRequest2$4, void 0);
846
+ __privateSet$4(this, _client2$3, client);
847
+ __privateSet$4(this, _httpRequest2$4, httpRequest);
858
848
  }
859
849
  upload(assetType, body, options) {
860
- const observable = _upload(__privateGet$5(this, _client2$4), __privateGet$5(this, _httpRequest2$5), assetType, body, options);
850
+ const observable = _upload(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), assetType, body, options);
861
851
  return lastValueFrom(observable.pipe(filter(event => event.type === "response"), map(event => event.body.document)));
862
852
  }
863
853
  }
864
- _client2$4 = new WeakMap();
865
- _httpRequest2$5 = new WeakMap();
854
+ _client2$3 = new WeakMap();
855
+ _httpRequest2$4 = new WeakMap();
866
856
  function _upload(client, httpRequest, assetType, body) {
867
857
  let opts = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
868
858
  validateAssetType(assetType);
@@ -916,77 +906,6 @@ function optionsFromFile(opts, file) {
916
906
  contentType: file.type
917
907
  }, opts);
918
908
  }
919
- var __accessCheck$4 = (obj, member, msg) => {
920
- if (!member.has(obj)) throw TypeError("Cannot " + msg);
921
- };
922
- var __privateGet$4 = (obj, member, getter) => {
923
- __accessCheck$4(obj, member, "read from private field");
924
- return getter ? getter.call(obj) : member.get(obj);
925
- };
926
- var __privateAdd$4 = (obj, member, value) => {
927
- if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
928
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
929
- };
930
- var __privateSet$4 = (obj, member, value, setter) => {
931
- __accessCheck$4(obj, member, "write to private field");
932
- setter ? setter.call(obj, value) : member.set(obj, value);
933
- return value;
934
- };
935
- var _client$3, _httpRequest$4, _client2$3, _httpRequest2$4;
936
- class ObservableAuthClient {
937
- constructor(client, httpRequest) {
938
- __privateAdd$4(this, _client$3, void 0);
939
- __privateAdd$4(this, _httpRequest$4, void 0);
940
- __privateSet$4(this, _client$3, client);
941
- __privateSet$4(this, _httpRequest$4, httpRequest);
942
- }
943
- /**
944
- * Fetch available login providers
945
- */
946
- getLoginProviders() {
947
- return _request(__privateGet$4(this, _client$3), __privateGet$4(this, _httpRequest$4), {
948
- uri: "/auth/providers"
949
- });
950
- }
951
- /**
952
- * Revoke the configured session/token
953
- */
954
- logout() {
955
- return _request(__privateGet$4(this, _client$3), __privateGet$4(this, _httpRequest$4), {
956
- uri: "/auth/logout",
957
- method: "POST"
958
- });
959
- }
960
- }
961
- _client$3 = new WeakMap();
962
- _httpRequest$4 = new WeakMap();
963
- class AuthClient {
964
- constructor(client, httpRequest) {
965
- __privateAdd$4(this, _client2$3, void 0);
966
- __privateAdd$4(this, _httpRequest2$4, void 0);
967
- __privateSet$4(this, _client2$3, client);
968
- __privateSet$4(this, _httpRequest2$4, httpRequest);
969
- }
970
- /**
971
- * Fetch available login providers
972
- */
973
- getLoginProviders() {
974
- return lastValueFrom(_request(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), {
975
- uri: "/auth/providers"
976
- }));
977
- }
978
- /**
979
- * Revoke the configured session/token
980
- */
981
- logout() {
982
- return lastValueFrom(_request(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), {
983
- uri: "/auth/logout",
984
- method: "POST"
985
- }));
986
- }
987
- }
988
- _client2$3 = new WeakMap();
989
- _httpRequest2$4 = new WeakMap();
990
909
  const BASE_URL = "https://www.sanity.io/help/";
991
910
  function generateHelpUrl(slug) {
992
911
  return BASE_URL + slug;
@@ -1489,10 +1408,13 @@ const _ObservableSanityClient = class {
1489
1408
  */
1490
1409
  __privateAdd(this, _clientConfig, void 0);
1491
1410
  __privateAdd(this, _httpRequest, void 0);
1411
+ /**
1412
+ * Instance properties
1413
+ */
1414
+ this.listen = _listen;
1492
1415
  this.config(config);
1493
1416
  __privateSet(this, _httpRequest, httpRequest);
1494
1417
  this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest));
1495
- this.auth = new ObservableAuthClient(this, __privateGet(this, _httpRequest));
1496
1418
  this.datasets = new ObservableDatasetsClient(this, __privateGet(this, _httpRequest));
1497
1419
  this.projects = new ObservableProjectsClient(this, __privateGet(this, _httpRequest));
1498
1420
  this.users = new ObservableUsersClient(this, __privateGet(this, _httpRequest));
@@ -1611,7 +1533,6 @@ const _SanityClient = class {
1611
1533
  this.config(config);
1612
1534
  __privateSet(this, _httpRequest2, httpRequest);
1613
1535
  this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2));
1614
- this.auth = new AuthClient(this, __privateGet(this, _httpRequest2));
1615
1536
  this.datasets = new DatasetsClient(this, __privateGet(this, _httpRequest2));
1616
1537
  this.projects = new ProjectsClient(this, __privateGet(this, _httpRequest2));
1617
1538
  this.users = new UsersClient(this, __privateGet(this, _httpRequest2));