@sanity/client 5.0.0-esm.2 → 5.0.0-esm.4

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.
@@ -197,23 +197,23 @@ var encodeQueryString = _ref => {
197
197
  return options[option] ? "".concat(qs, "&").concat(enc(option), "=").concat(enc(options[option])) : qs;
198
198
  }, qString);
199
199
  };
200
- var __accessCheck$5 = (obj, member, msg) => {
200
+ var __accessCheck$7 = (obj, member, msg) => {
201
201
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
202
202
  };
203
- var __privateGet$4 = (obj, member, getter) => {
204
- __accessCheck$5(obj, member, "read from private field");
203
+ var __privateGet$7 = (obj, member, getter) => {
204
+ __accessCheck$7(obj, member, "read from private field");
205
205
  return getter ? getter.call(obj) : member.get(obj);
206
206
  };
207
- var __privateAdd$5 = (obj, member, value) => {
207
+ var __privateAdd$7 = (obj, member, value) => {
208
208
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
209
209
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
210
210
  };
211
- var __privateSet$4 = (obj, member, value, setter) => {
212
- __accessCheck$5(obj, member, "write to private field");
211
+ var __privateSet$7 = (obj, member, value, setter) => {
212
+ __accessCheck$7(obj, member, "write to private field");
213
213
  setter ? setter.call(obj, value) : member.set(obj, value);
214
214
  return value;
215
215
  };
216
- var _client$3, _client2$3;
216
+ var _client$6, _client2$6;
217
217
  class BasePatch {
218
218
  constructor(selection) {
219
219
  let operations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -304,16 +304,16 @@ class BasePatch {
304
304
  const _ObservablePatch = class extends BasePatch {
305
305
  constructor(selection, operations, client) {
306
306
  super(selection, operations);
307
- __privateAdd$5(this, _client$3, void 0);
308
- __privateSet$4(this, _client$3, client);
307
+ __privateAdd$7(this, _client$6, void 0);
308
+ __privateSet$7(this, _client$6, client);
309
309
  }
310
310
  clone() {
311
311
  return new _ObservablePatch(this.selection, {
312
312
  ...this.operations
313
- }, __privateGet$4(this, _client$3));
313
+ }, __privateGet$7(this, _client$6));
314
314
  }
315
315
  commit(options) {
316
- if (!__privateGet$4(this, _client$3)) {
316
+ if (!__privateGet$7(this, _client$6)) {
317
317
  throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
318
318
  }
319
319
  const returnFirst = typeof this.selection === "string";
@@ -321,26 +321,26 @@ const _ObservablePatch = class extends BasePatch {
321
321
  returnFirst,
322
322
  returnDocuments: true
323
323
  }, options);
324
- return __privateGet$4(this, _client$3).mutate({
324
+ return __privateGet$7(this, _client$6).mutate({
325
325
  patch: this.serialize()
326
326
  }, opts);
327
327
  }
328
328
  };
329
329
  let ObservablePatch = _ObservablePatch;
330
- _client$3 = new WeakMap();
330
+ _client$6 = new WeakMap();
331
331
  const _Patch = class extends BasePatch {
332
332
  constructor(selection, operations, client) {
333
333
  super(selection, operations);
334
- __privateAdd$5(this, _client2$3, void 0);
335
- __privateSet$4(this, _client2$3, client);
334
+ __privateAdd$7(this, _client2$6, void 0);
335
+ __privateSet$7(this, _client2$6, client);
336
336
  }
337
337
  clone() {
338
338
  return new _Patch(this.selection, {
339
339
  ...this.operations
340
- }, __privateGet$4(this, _client2$3));
340
+ }, __privateGet$7(this, _client2$6));
341
341
  }
342
342
  commit(options) {
343
- if (!__privateGet$4(this, _client2$3)) {
343
+ if (!__privateGet$7(this, _client2$6)) {
344
344
  throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
345
345
  }
346
346
  const returnFirst = typeof this.selection === "string";
@@ -348,30 +348,30 @@ const _Patch = class extends BasePatch {
348
348
  returnFirst,
349
349
  returnDocuments: true
350
350
  }, options);
351
- return __privateGet$4(this, _client2$3).mutate({
351
+ return __privateGet$7(this, _client2$6).mutate({
352
352
  patch: this.serialize()
353
353
  }, opts);
354
354
  }
355
355
  };
356
356
  let Patch = _Patch;
357
- _client2$3 = new WeakMap();
358
- var __accessCheck$4 = (obj, member, msg) => {
357
+ _client2$6 = new WeakMap();
358
+ var __accessCheck$6 = (obj, member, msg) => {
359
359
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
360
360
  };
361
- var __privateGet$3 = (obj, member, getter) => {
362
- __accessCheck$4(obj, member, "read from private field");
361
+ var __privateGet$6 = (obj, member, getter) => {
362
+ __accessCheck$6(obj, member, "read from private field");
363
363
  return getter ? getter.call(obj) : member.get(obj);
364
364
  };
365
- var __privateAdd$4 = (obj, member, value) => {
365
+ var __privateAdd$6 = (obj, member, value) => {
366
366
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
367
367
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
368
368
  };
369
- var __privateSet$3 = (obj, member, value, setter) => {
370
- __accessCheck$4(obj, member, "write to private field");
369
+ var __privateSet$6 = (obj, member, value, setter) => {
370
+ __accessCheck$6(obj, member, "write to private field");
371
371
  setter ? setter.call(obj, value) : member.set(obj, value);
372
372
  return value;
373
373
  };
374
- var _client$2, _client2$2;
374
+ var _client$5, _client2$5;
375
375
  const defaultMutateOptions = {
376
376
  returnDocuments: false
377
377
  };
@@ -437,17 +437,17 @@ class BaseTransaction {
437
437
  const _Transaction = class extends BaseTransaction {
438
438
  constructor(operations, client, transactionId) {
439
439
  super(operations, transactionId);
440
- __privateAdd$4(this, _client$2, void 0);
441
- __privateSet$3(this, _client$2, client);
440
+ __privateAdd$6(this, _client$5, void 0);
441
+ __privateSet$6(this, _client$5, client);
442
442
  }
443
443
  clone() {
444
- return new _Transaction([...this.operations], __privateGet$3(this, _client$2), this.trxId);
444
+ return new _Transaction([...this.operations], __privateGet$6(this, _client$5), this.trxId);
445
445
  }
446
446
  commit(options) {
447
- if (!__privateGet$3(this, _client$2)) {
447
+ if (!__privateGet$6(this, _client$5)) {
448
448
  throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
449
449
  }
450
- return __privateGet$3(this, _client$2).mutate(this.serialize(), Object.assign({
450
+ return __privateGet$6(this, _client$5).mutate(this.serialize(), Object.assign({
451
451
  transactionId: this.trxId
452
452
  }, defaultMutateOptions, options || {}));
453
453
  }
@@ -460,7 +460,7 @@ const _Transaction = class extends BaseTransaction {
460
460
  });
461
461
  }
462
462
  if (isBuilder) {
463
- const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$3(this, _client$2)));
463
+ const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$6(this, _client$5)));
464
464
  if (!(patch instanceof Patch)) {
465
465
  throw new Error("function passed to `patch()` must return the patch");
466
466
  }
@@ -477,21 +477,21 @@ const _Transaction = class extends BaseTransaction {
477
477
  }
478
478
  };
479
479
  let Transaction = _Transaction;
480
- _client$2 = new WeakMap();
480
+ _client$5 = new WeakMap();
481
481
  const _ObservableTransaction = class extends BaseTransaction {
482
482
  constructor(operations, client, transactionId) {
483
483
  super(operations, transactionId);
484
- __privateAdd$4(this, _client2$2, void 0);
485
- __privateSet$3(this, _client2$2, client);
484
+ __privateAdd$6(this, _client2$5, void 0);
485
+ __privateSet$6(this, _client2$5, client);
486
486
  }
487
487
  clone() {
488
- return new _ObservableTransaction([...this.operations], __privateGet$3(this, _client2$2), this.trxId);
488
+ return new _ObservableTransaction([...this.operations], __privateGet$6(this, _client2$5), this.trxId);
489
489
  }
490
490
  commit(options) {
491
- if (!__privateGet$3(this, _client2$2)) {
491
+ if (!__privateGet$6(this, _client2$5)) {
492
492
  throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
493
493
  }
494
- return __privateGet$3(this, _client2$2).mutate(this.serialize(), Object.assign({
494
+ return __privateGet$6(this, _client2$5).mutate(this.serialize(), Object.assign({
495
495
  transactionId: this.trxId
496
496
  }, defaultMutateOptions, options || {}));
497
497
  }
@@ -504,7 +504,7 @@ const _ObservableTransaction = class extends BaseTransaction {
504
504
  });
505
505
  }
506
506
  if (isBuilder) {
507
- const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$3(this, _client2$2)));
507
+ const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$6(this, _client2$5)));
508
508
  if (!(patch instanceof ObservablePatch)) {
509
509
  throw new Error("function passed to `patch()` must return the patch");
510
510
  }
@@ -521,7 +521,7 @@ const _ObservableTransaction = class extends BaseTransaction {
521
521
  }
522
522
  };
523
523
  let ObservableTransaction = _ObservableTransaction;
524
- _client2$2 = new WeakMap();
524
+ _client2$5 = new WeakMap();
525
525
  const excludeFalsey = (param, defValue) => {
526
526
  const value = typeof param === "undefined" ? defValue : param;
527
527
  return param === false ? void 0 : value;
@@ -555,7 +555,7 @@ function _fetch(client, httpRequest, query, params) {
555
555
  function _getDocument(client, httpRequest, id) {
556
556
  let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
557
557
  const options = {
558
- uri: client.getDataUrl("doc", id),
558
+ uri: _getDataUrl(client, "doc", id),
559
559
  json: true,
560
560
  tag: opts.tag
561
561
  };
@@ -564,7 +564,7 @@ function _getDocument(client, httpRequest, id) {
564
564
  function _getDocuments(client, httpRequest, ids) {
565
565
  let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
566
566
  const options = {
567
- uri: client.getDataUrl("doc", ids.join(",")),
567
+ uri: _getDataUrl(client, "doc", ids.join(",")),
568
568
  json: true,
569
569
  tag: opts.tag
570
570
  };
@@ -611,7 +611,7 @@ function _dataRequest(client, httpRequest, endpoint, body) {
611
611
  tag,
612
612
  headers
613
613
  } = options;
614
- const uri = client.getDataUrl(endpoint, stringQuery);
614
+ const uri = _getDataUrl(client, endpoint, stringQuery);
615
615
  const reqOptions = {
616
616
  method: useGet ? "GET" : "POST",
617
617
  uri,
@@ -667,7 +667,7 @@ function _requestObservable(client, httpRequest, options) {
667
667
  };
668
668
  }
669
669
  const reqOptions = getRequestOptions(config, Object.assign({}, options, {
670
- url: client.getUrl(uri, useCdn)
670
+ url: _getUrl(client, uri, useCdn)
671
671
  }));
672
672
  return new Observable(subscriber => httpRequest(reqOptions, config.requester).subscribe(subscriber));
673
673
  }
@@ -675,50 +675,66 @@ function _request(client, httpRequest, options) {
675
675
  const observable = _requestObservable(client, httpRequest, options).pipe(filter(event => event.type === "response"), map(event => event.body));
676
676
  return observable;
677
677
  }
678
- var __accessCheck$3 = (obj, member, msg) => {
678
+ function _getDataUrl(client, operation, path) {
679
+ const config = client.config();
680
+ const catalog = hasDataset(config);
681
+ const baseUri = "/".concat(operation, "/").concat(catalog);
682
+ const uri = path ? "".concat(baseUri, "/").concat(path) : baseUri;
683
+ return "/data".concat(uri).replace(/\/($|\?)/, "$1");
684
+ }
685
+ function _getUrl(client, uri) {
686
+ let canUseCdn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
687
+ const {
688
+ url,
689
+ cdnUrl
690
+ } = client.config();
691
+ const base = canUseCdn ? cdnUrl : url;
692
+ return "".concat(base, "/").concat(uri.replace(/^\//, ""));
693
+ }
694
+ var __accessCheck$5 = (obj, member, msg) => {
679
695
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
680
696
  };
681
- var __privateGet$2 = (obj, member, getter) => {
682
- __accessCheck$3(obj, member, "read from private field");
697
+ var __privateGet$5 = (obj, member, getter) => {
698
+ __accessCheck$5(obj, member, "read from private field");
683
699
  return getter ? getter.call(obj) : member.get(obj);
684
700
  };
685
- var __privateAdd$3 = (obj, member, value) => {
701
+ var __privateAdd$5 = (obj, member, value) => {
686
702
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
687
703
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
688
704
  };
689
- var __privateSet$2 = (obj, member, value, setter) => {
690
- __accessCheck$3(obj, member, "write to private field");
705
+ var __privateSet$5 = (obj, member, value, setter) => {
706
+ __accessCheck$5(obj, member, "write to private field");
691
707
  setter ? setter.call(obj, value) : member.set(obj, value);
692
708
  return value;
693
709
  };
694
- var _client$1, _httpRequest$2, _client2$1, _httpRequest2$2;
710
+ var _client$4, _httpRequest$5, _client2$4, _httpRequest2$5;
695
711
  class ObservableAssetsClient {
696
712
  constructor(client, httpRequest) {
697
- __privateAdd$3(this, _client$1, void 0);
698
- __privateAdd$3(this, _httpRequest$2, void 0);
699
- __privateSet$2(this, _client$1, client);
700
- __privateSet$2(this, _httpRequest$2, httpRequest);
713
+ __privateAdd$5(this, _client$4, void 0);
714
+ __privateAdd$5(this, _httpRequest$5, void 0);
715
+ __privateSet$5(this, _client$4, client);
716
+ __privateSet$5(this, _httpRequest$5, httpRequest);
701
717
  }
702
718
  upload(assetType, body, options) {
703
- return _upload(__privateGet$2(this, _client$1), __privateGet$2(this, _httpRequest$2), assetType, body, options);
719
+ return _upload(__privateGet$5(this, _client$4), __privateGet$5(this, _httpRequest$5), assetType, body, options);
704
720
  }
705
721
  }
706
- _client$1 = new WeakMap();
707
- _httpRequest$2 = new WeakMap();
722
+ _client$4 = new WeakMap();
723
+ _httpRequest$5 = new WeakMap();
708
724
  class AssetsClient {
709
725
  constructor(client, httpRequest) {
710
- __privateAdd$3(this, _client2$1, void 0);
711
- __privateAdd$3(this, _httpRequest2$2, void 0);
712
- __privateSet$2(this, _client2$1, client);
713
- __privateSet$2(this, _httpRequest2$2, httpRequest);
726
+ __privateAdd$5(this, _client2$4, void 0);
727
+ __privateAdd$5(this, _httpRequest2$5, void 0);
728
+ __privateSet$5(this, _client2$4, client);
729
+ __privateSet$5(this, _httpRequest2$5, httpRequest);
714
730
  }
715
731
  upload(assetType, body, options) {
716
- const observable = _upload(__privateGet$2(this, _client2$1), __privateGet$2(this, _httpRequest2$2), assetType, body, options);
732
+ const observable = _upload(__privateGet$5(this, _client2$4), __privateGet$5(this, _httpRequest2$5), assetType, body, options);
717
733
  return lastValueFrom(observable.pipe(filter(event => event.type === "response"), map(event => event.body.document)));
718
734
  }
719
735
  }
720
- _client2$1 = new WeakMap();
721
- _httpRequest2$2 = new WeakMap();
736
+ _client2$4 = new WeakMap();
737
+ _httpRequest2$5 = new WeakMap();
722
738
  function _upload(client, httpRequest, assetType, body) {
723
739
  let opts = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
724
740
  validateAssetType(assetType);
@@ -772,65 +788,65 @@ function optionsFromFile(opts, file) {
772
788
  contentType: file.type
773
789
  }, opts);
774
790
  }
775
- var __accessCheck$2 = (obj, member, msg) => {
791
+ var __accessCheck$4 = (obj, member, msg) => {
776
792
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
777
793
  };
778
- var __privateGet$1 = (obj, member, getter) => {
779
- __accessCheck$2(obj, member, "read from private field");
794
+ var __privateGet$4 = (obj, member, getter) => {
795
+ __accessCheck$4(obj, member, "read from private field");
780
796
  return getter ? getter.call(obj) : member.get(obj);
781
797
  };
782
- var __privateAdd$2 = (obj, member, value) => {
798
+ var __privateAdd$4 = (obj, member, value) => {
783
799
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
784
800
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
785
801
  };
786
- var __privateSet$1 = (obj, member, value, setter) => {
787
- __accessCheck$2(obj, member, "write to private field");
802
+ var __privateSet$4 = (obj, member, value, setter) => {
803
+ __accessCheck$4(obj, member, "write to private field");
788
804
  setter ? setter.call(obj, value) : member.set(obj, value);
789
805
  return value;
790
806
  };
791
- var _client, _httpRequest$1, _client2, _httpRequest2$1;
807
+ var _client$3, _httpRequest$4, _client2$3, _httpRequest2$4;
792
808
  class ObservableAuthClient {
793
809
  constructor(client, httpRequest) {
794
- __privateAdd$2(this, _client, void 0);
795
- __privateAdd$2(this, _httpRequest$1, void 0);
796
- __privateSet$1(this, _client, client);
797
- __privateSet$1(this, _httpRequest$1, httpRequest);
810
+ __privateAdd$4(this, _client$3, void 0);
811
+ __privateAdd$4(this, _httpRequest$4, void 0);
812
+ __privateSet$4(this, _client$3, client);
813
+ __privateSet$4(this, _httpRequest$4, httpRequest);
798
814
  }
799
815
  getLoginProviders() {
800
- return _request(__privateGet$1(this, _client), __privateGet$1(this, _httpRequest$1), {
816
+ return _request(__privateGet$4(this, _client$3), __privateGet$4(this, _httpRequest$4), {
801
817
  uri: "/auth/providers"
802
818
  });
803
819
  }
804
820
  logout() {
805
- return _request(__privateGet$1(this, _client), __privateGet$1(this, _httpRequest$1), {
821
+ return _request(__privateGet$4(this, _client$3), __privateGet$4(this, _httpRequest$4), {
806
822
  uri: "/auth/logout",
807
823
  method: "POST"
808
824
  });
809
825
  }
810
826
  }
811
- _client = new WeakMap();
812
- _httpRequest$1 = new WeakMap();
827
+ _client$3 = new WeakMap();
828
+ _httpRequest$4 = new WeakMap();
813
829
  class AuthClient {
814
830
  constructor(client, httpRequest) {
815
- __privateAdd$2(this, _client2, void 0);
816
- __privateAdd$2(this, _httpRequest2$1, void 0);
817
- __privateSet$1(this, _client2, client);
818
- __privateSet$1(this, _httpRequest2$1, httpRequest);
831
+ __privateAdd$4(this, _client2$3, void 0);
832
+ __privateAdd$4(this, _httpRequest2$4, void 0);
833
+ __privateSet$4(this, _client2$3, client);
834
+ __privateSet$4(this, _httpRequest2$4, httpRequest);
819
835
  }
820
836
  getLoginProviders() {
821
- return lastValueFrom(_request(__privateGet$1(this, _client2), __privateGet$1(this, _httpRequest2$1), {
837
+ return lastValueFrom(_request(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), {
822
838
  uri: "/auth/providers"
823
839
  }));
824
840
  }
825
841
  logout() {
826
- return lastValueFrom(_request(__privateGet$1(this, _client2), __privateGet$1(this, _httpRequest2$1), {
842
+ return lastValueFrom(_request(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), {
827
843
  uri: "/auth/logout",
828
844
  method: "POST"
829
845
  }));
830
846
  }
831
847
  }
832
- _client2 = new WeakMap();
833
- _httpRequest2$1 = new WeakMap();
848
+ _client2$3 = new WeakMap();
849
+ _httpRequest2$4 = new WeakMap();
834
850
  const BASE_URL = "https://docs.sanity.io/help/";
835
851
  function generateHelpUrl(slug) {
836
852
  return BASE_URL + slug;
@@ -960,7 +976,7 @@ function _listen(query, params) {
960
976
  ...listenOpts
961
977
  }
962
978
  });
963
- const uri = "".concat(url).concat(this.getDataUrl("listen", qs));
979
+ const uri = "".concat(url).concat(_getDataUrl(this, "listen", qs));
964
980
  if (uri.length > MAX_URL_LENGTH) {
965
981
  return new Observable(observer => observer.error(new Error("Query too large for listener")));
966
982
  }
@@ -1063,101 +1079,183 @@ function extractErrorMessage(err) {
1063
1079
  }
1064
1080
  return typeof err.error === "string" ? err.error : JSON.stringify(err.error, null, 2);
1065
1081
  }
1066
- var __accessCheck$1 = (obj, member, msg) => {
1082
+ var __accessCheck$3 = (obj, member, msg) => {
1067
1083
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
1068
1084
  };
1069
- var __privateAdd$1 = (obj, member, value) => {
1085
+ var __privateGet$3 = (obj, member, getter) => {
1086
+ __accessCheck$3(obj, member, "read from private field");
1087
+ return getter ? getter.call(obj) : member.get(obj);
1088
+ };
1089
+ var __privateAdd$3 = (obj, member, value) => {
1070
1090
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
1071
1091
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1072
1092
  };
1073
- var __privateMethod = (obj, member, method) => {
1074
- __accessCheck$1(obj, member, "access private method");
1075
- return method;
1093
+ var __privateSet$3 = (obj, member, value, setter) => {
1094
+ __accessCheck$3(obj, member, "write to private field");
1095
+ setter ? setter.call(obj, value) : member.set(obj, value);
1096
+ return value;
1076
1097
  };
1077
- var __modify, _modify_fn;
1078
- class BaseDatasetsClient {
1079
- constructor() {
1080
- __privateAdd$1(this, __modify);
1098
+ var _client$2, _httpRequest$3, _client2$2, _httpRequest2$3;
1099
+ class ObservableDatasetsClient {
1100
+ constructor(client, httpRequest) {
1101
+ __privateAdd$3(this, _client$2, void 0);
1102
+ __privateAdd$3(this, _httpRequest$3, void 0);
1103
+ __privateSet$3(this, _client$2, client);
1104
+ __privateSet$3(this, _httpRequest$3, httpRequest);
1081
1105
  }
1082
1106
  create(name, options) {
1083
- return __privateMethod(this, __modify, _modify_fn).call(this, "PUT", name, options);
1107
+ return _modify(__privateGet$3(this, _client$2), __privateGet$3(this, _httpRequest$3), "PUT", name, options);
1084
1108
  }
1085
1109
  edit(name, options) {
1086
- return __privateMethod(this, __modify, _modify_fn).call(this, "PATCH", name, options);
1110
+ return _modify(__privateGet$3(this, _client$2), __privateGet$3(this, _httpRequest$3), "PATCH", name, options);
1087
1111
  }
1088
1112
  delete(name) {
1089
- return __privateMethod(this, __modify, _modify_fn).call(this, "DELETE", name);
1113
+ return _modify(__privateGet$3(this, _client$2), __privateGet$3(this, _httpRequest$3), "DELETE", name);
1090
1114
  }
1091
1115
  list() {
1092
- return this.client.request({
1116
+ return _request(__privateGet$3(this, _client$2), __privateGet$3(this, _httpRequest$3), {
1093
1117
  uri: "/datasets"
1094
1118
  });
1095
1119
  }
1096
1120
  }
1097
- __modify = new WeakSet();
1098
- _modify_fn = function (method, name, options) {
1121
+ _client$2 = new WeakMap();
1122
+ _httpRequest$3 = new WeakMap();
1123
+ class DatasetsClient {
1124
+ constructor(client, httpRequest) {
1125
+ __privateAdd$3(this, _client2$2, void 0);
1126
+ __privateAdd$3(this, _httpRequest2$3, void 0);
1127
+ __privateSet$3(this, _client2$2, client);
1128
+ __privateSet$3(this, _httpRequest2$3, httpRequest);
1129
+ }
1130
+ create(name, options) {
1131
+ return lastValueFrom(_modify(__privateGet$3(this, _client2$2), __privateGet$3(this, _httpRequest2$3), "PUT", name, options));
1132
+ }
1133
+ edit(name, options) {
1134
+ return lastValueFrom(_modify(__privateGet$3(this, _client2$2), __privateGet$3(this, _httpRequest2$3), "PATCH", name, options));
1135
+ }
1136
+ delete(name) {
1137
+ return lastValueFrom(_modify(__privateGet$3(this, _client2$2), __privateGet$3(this, _httpRequest2$3), "DELETE", name));
1138
+ }
1139
+ list() {
1140
+ return lastValueFrom(_request(__privateGet$3(this, _client2$2), __privateGet$3(this, _httpRequest2$3), {
1141
+ uri: "/datasets"
1142
+ }));
1143
+ }
1144
+ }
1145
+ _client2$2 = new WeakMap();
1146
+ _httpRequest2$3 = new WeakMap();
1147
+ function _modify(client, httpRequest, method, name, options) {
1099
1148
  dataset(name);
1100
- return this.client.request({
1149
+ return _request(client, httpRequest, {
1101
1150
  method,
1102
1151
  uri: "/datasets/".concat(name),
1103
1152
  body: options
1104
1153
  });
1105
- };
1106
- class ObservableDatasetsClient extends BaseDatasetsClient {
1107
- constructor(client) {
1108
- super();
1109
- this.client = client;
1110
- }
1111
1154
  }
1112
- class DatasetsClient extends BaseDatasetsClient {
1113
- constructor(client) {
1114
- super();
1115
- this.client = client;
1155
+ var __accessCheck$2 = (obj, member, msg) => {
1156
+ if (!member.has(obj)) throw TypeError("Cannot " + msg);
1157
+ };
1158
+ var __privateGet$2 = (obj, member, getter) => {
1159
+ __accessCheck$2(obj, member, "read from private field");
1160
+ return getter ? getter.call(obj) : member.get(obj);
1161
+ };
1162
+ var __privateAdd$2 = (obj, member, value) => {
1163
+ if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
1164
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1165
+ };
1166
+ var __privateSet$2 = (obj, member, value, setter) => {
1167
+ __accessCheck$2(obj, member, "write to private field");
1168
+ setter ? setter.call(obj, value) : member.set(obj, value);
1169
+ return value;
1170
+ };
1171
+ var _client$1, _httpRequest$2, _client2$1, _httpRequest2$2;
1172
+ class ObservableProjectsClient {
1173
+ constructor(client, httpRequest) {
1174
+ __privateAdd$2(this, _client$1, void 0);
1175
+ __privateAdd$2(this, _httpRequest$2, void 0);
1176
+ __privateSet$2(this, _client$1, client);
1177
+ __privateSet$2(this, _httpRequest$2, httpRequest);
1116
1178
  }
1117
- }
1118
- class BaseProjectsClient {
1119
1179
  list() {
1120
- return this.client.request({
1180
+ return _request(__privateGet$2(this, _client$1), __privateGet$2(this, _httpRequest$2), {
1121
1181
  uri: "/projects"
1122
1182
  });
1123
1183
  }
1124
1184
  getById(projectId) {
1125
- return this.client.request({
1185
+ return _request(__privateGet$2(this, _client$1), __privateGet$2(this, _httpRequest$2), {
1126
1186
  uri: "/projects/".concat(projectId)
1127
1187
  });
1128
1188
  }
1129
1189
  }
1130
- class ObservableProjectsClient extends BaseProjectsClient {
1131
- constructor(client) {
1132
- super();
1133
- this.client = client;
1190
+ _client$1 = new WeakMap();
1191
+ _httpRequest$2 = new WeakMap();
1192
+ class ProjectsClient {
1193
+ constructor(client, httpRequest) {
1194
+ __privateAdd$2(this, _client2$1, void 0);
1195
+ __privateAdd$2(this, _httpRequest2$2, void 0);
1196
+ __privateSet$2(this, _client2$1, client);
1197
+ __privateSet$2(this, _httpRequest2$2, httpRequest);
1134
1198
  }
1135
- }
1136
- class ProjectsClient extends BaseProjectsClient {
1137
- constructor(client) {
1138
- super();
1139
- this.client = client;
1199
+ list() {
1200
+ return lastValueFrom(_request(__privateGet$2(this, _client2$1), __privateGet$2(this, _httpRequest2$2), {
1201
+ uri: "/projects"
1202
+ }));
1203
+ }
1204
+ getById(projectId) {
1205
+ return lastValueFrom(_request(__privateGet$2(this, _client2$1), __privateGet$2(this, _httpRequest2$2), {
1206
+ uri: "/projects/".concat(projectId)
1207
+ }));
1140
1208
  }
1141
1209
  }
1142
- class BaseUsersClient {
1210
+ _client2$1 = new WeakMap();
1211
+ _httpRequest2$2 = new WeakMap();
1212
+ var __accessCheck$1 = (obj, member, msg) => {
1213
+ if (!member.has(obj)) throw TypeError("Cannot " + msg);
1214
+ };
1215
+ var __privateGet$1 = (obj, member, getter) => {
1216
+ __accessCheck$1(obj, member, "read from private field");
1217
+ return getter ? getter.call(obj) : member.get(obj);
1218
+ };
1219
+ var __privateAdd$1 = (obj, member, value) => {
1220
+ if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
1221
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1222
+ };
1223
+ var __privateSet$1 = (obj, member, value, setter) => {
1224
+ __accessCheck$1(obj, member, "write to private field");
1225
+ setter ? setter.call(obj, value) : member.set(obj, value);
1226
+ return value;
1227
+ };
1228
+ var _client, _httpRequest$1, _client2, _httpRequest2$1;
1229
+ class ObservableUsersClient {
1230
+ constructor(client, httpRequest) {
1231
+ __privateAdd$1(this, _client, void 0);
1232
+ __privateAdd$1(this, _httpRequest$1, void 0);
1233
+ __privateSet$1(this, _client, client);
1234
+ __privateSet$1(this, _httpRequest$1, httpRequest);
1235
+ }
1143
1236
  getById(id) {
1144
- return this.client.request({
1237
+ return _request(__privateGet$1(this, _client), __privateGet$1(this, _httpRequest$1), {
1145
1238
  uri: "/users/".concat(id)
1146
1239
  });
1147
1240
  }
1148
1241
  }
1149
- class ObservableUsersClient extends BaseUsersClient {
1150
- constructor(client) {
1151
- super();
1152
- this.client = client;
1242
+ _client = new WeakMap();
1243
+ _httpRequest$1 = new WeakMap();
1244
+ class UsersClient {
1245
+ constructor(client, httpRequest) {
1246
+ __privateAdd$1(this, _client2, void 0);
1247
+ __privateAdd$1(this, _httpRequest2$1, void 0);
1248
+ __privateSet$1(this, _client2, client);
1249
+ __privateSet$1(this, _httpRequest2$1, httpRequest);
1153
1250
  }
1154
- }
1155
- class UsersClient extends BaseUsersClient {
1156
- constructor(client) {
1157
- super();
1158
- this.client = client;
1251
+ getById(id) {
1252
+ return lastValueFrom(_request(__privateGet$1(this, _client2), __privateGet$1(this, _httpRequest2$1), {
1253
+ uri: "/users/".concat(id)
1254
+ }));
1159
1255
  }
1160
1256
  }
1257
+ _client2 = new WeakMap();
1258
+ _httpRequest2$1 = new WeakMap();
1161
1259
  var __accessCheck = (obj, member, msg) => {
1162
1260
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
1163
1261
  };
@@ -1176,16 +1274,17 @@ var __privateSet = (obj, member, value, setter) => {
1176
1274
  };
1177
1275
  var _clientConfig, _httpRequest, _clientConfig2, _httpRequest2;
1178
1276
  const _ObservableSanityClient = class {
1179
- constructor(httpRequest, config) {
1277
+ constructor(httpRequest) {
1278
+ let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
1180
1279
  __privateAdd(this, _clientConfig, void 0);
1181
1280
  __privateAdd(this, _httpRequest, void 0);
1182
1281
  this.config(config);
1183
1282
  __privateSet(this, _httpRequest, httpRequest);
1184
1283
  this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest));
1185
1284
  this.auth = new ObservableAuthClient(this, __privateGet(this, _httpRequest));
1186
- this.datasets = new ObservableDatasetsClient(this);
1187
- this.projects = new ObservableProjectsClient(this);
1188
- this.users = new ObservableUsersClient(this);
1285
+ this.datasets = new ObservableDatasetsClient(this, __privateGet(this, _httpRequest));
1286
+ this.projects = new ObservableProjectsClient(this, __privateGet(this, _httpRequest));
1287
+ this.users = new ObservableUsersClient(this, __privateGet(this, _httpRequest));
1189
1288
  }
1190
1289
  clone() {
1191
1290
  return new _ObservableSanityClient(__privateGet(this, _httpRequest), this.config());
@@ -1242,35 +1341,24 @@ const _ObservableSanityClient = class {
1242
1341
  request(options) {
1243
1342
  return _request(this, __privateGet(this, _httpRequest), options);
1244
1343
  }
1245
- getUrl(uri) {
1246
- let canUseCdn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1247
- const base = canUseCdn ? __privateGet(this, _clientConfig).cdnUrl : __privateGet(this, _clientConfig).url;
1248
- return "".concat(base, "/").concat(uri.replace(/^\//, ""));
1249
- }
1250
- getDataUrl(operation, path) {
1251
- const config = this.config();
1252
- const catalog = hasDataset(config);
1253
- const baseUri = "/".concat(operation, "/").concat(catalog);
1254
- const uri = path ? "".concat(baseUri, "/").concat(path) : baseUri;
1255
- return "/data".concat(uri).replace(/\/($|\?)/, "$1");
1256
- }
1257
1344
  };
1258
1345
  let ObservableSanityClient = _ObservableSanityClient;
1259
1346
  _clientConfig = new WeakMap();
1260
1347
  _httpRequest = new WeakMap();
1261
1348
  const _SanityClient = class {
1262
- constructor(httpRequest, config) {
1349
+ constructor(httpRequest) {
1350
+ let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
1263
1351
  __privateAdd(this, _clientConfig2, void 0);
1264
1352
  __privateAdd(this, _httpRequest2, void 0);
1265
1353
  this.listen = _listen;
1266
- this.observable = new ObservableSanityClient(httpRequest, config);
1267
1354
  this.config(config);
1268
1355
  __privateSet(this, _httpRequest2, httpRequest);
1269
1356
  this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2));
1270
1357
  this.auth = new AuthClient(this, __privateGet(this, _httpRequest2));
1271
- this.datasets = new DatasetsClient(this);
1272
- this.projects = new ProjectsClient(this);
1273
- this.users = new UsersClient(this);
1358
+ this.datasets = new DatasetsClient(this, __privateGet(this, _httpRequest2));
1359
+ this.projects = new ProjectsClient(this, __privateGet(this, _httpRequest2));
1360
+ this.users = new UsersClient(this, __privateGet(this, _httpRequest2));
1361
+ this.observable = new ObservableSanityClient(httpRequest, config);
1274
1362
  }
1275
1363
  clone() {
1276
1364
  return new _SanityClient(__privateGet(this, _httpRequest2), this.config());
@@ -1284,7 +1372,9 @@ const _SanityClient = class {
1284
1372
  if (__privateGet(this, _clientConfig2) && __privateGet(this, _clientConfig2).allowReconfigure === false) {
1285
1373
  throw new Error("Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client");
1286
1374
  }
1287
- this.observable.config(newConfig);
1375
+ if (this.observable) {
1376
+ this.observable.config(newConfig);
1377
+ }
1288
1378
  __privateSet(this, _clientConfig2, initConfig(newConfig, __privateGet(this, _clientConfig2) || {}));
1289
1379
  return this;
1290
1380
  }
@@ -1331,26 +1421,12 @@ const _SanityClient = class {
1331
1421
  dataRequest(endpoint, body, options) {
1332
1422
  return lastValueFrom(_dataRequest(this, __privateGet(this, _httpRequest2), endpoint, body, options));
1333
1423
  }
1334
- getUrl(uri) {
1335
- let canUseCdn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1336
- const base = canUseCdn ? __privateGet(this, _clientConfig2).cdnUrl : __privateGet(this, _clientConfig2).url;
1337
- return "".concat(base, "/").concat(uri.replace(/^\//, ""));
1338
- }
1339
- getDataUrl(operation, path) {
1340
- const config = this.config();
1341
- const catalog = hasDataset(config);
1342
- const baseUri = "/".concat(operation, "/").concat(catalog);
1343
- const uri = path ? "".concat(baseUri, "/").concat(path) : baseUri;
1344
- return "/data".concat(uri).replace(/\/($|\?)/, "$1");
1345
- }
1346
1424
  };
1347
1425
  let SanityClient = _SanityClient;
1348
1426
  _clientConfig2 = new WeakMap();
1349
1427
  _httpRequest2 = new WeakMap();
1350
1428
  const httpRequest = defineHttpRequest(envMiddleware);
1351
1429
  const requester = httpRequest.defaultRequester;
1352
- function createClient(config) {
1353
- return new SanityClient(httpRequest, config);
1354
- }
1430
+ const createClient = config => new SanityClient(httpRequest, config);
1355
1431
  export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, createClient, requester };
1356
1432
  //# sourceMappingURL=index.browser.js.map