@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.
package/dist/index.cjs CHANGED
@@ -16,7 +16,7 @@ function _interopDefaultCompat(e) {
16
16
  }
17
17
  var polyfilledEventSource__default = /*#__PURE__*/_interopDefaultCompat(polyfilledEventSource);
18
18
  var name = "@sanity/client";
19
- var version = "5.0.0-esm.2";
19
+ var version = "5.0.0-esm.4";
20
20
  const middleware = [middleware$1.debug({
21
21
  verbose: true,
22
22
  namespace: "sanity:client"
@@ -217,23 +217,23 @@ var encodeQueryString = _ref => {
217
217
  return options[option] ? "".concat(qs, "&").concat(enc(option), "=").concat(enc(options[option])) : qs;
218
218
  }, qString);
219
219
  };
220
- var __accessCheck$5 = (obj, member, msg) => {
220
+ var __accessCheck$7 = (obj, member, msg) => {
221
221
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
222
222
  };
223
- var __privateGet$4 = (obj, member, getter) => {
224
- __accessCheck$5(obj, member, "read from private field");
223
+ var __privateGet$7 = (obj, member, getter) => {
224
+ __accessCheck$7(obj, member, "read from private field");
225
225
  return getter ? getter.call(obj) : member.get(obj);
226
226
  };
227
- var __privateAdd$5 = (obj, member, value) => {
227
+ var __privateAdd$7 = (obj, member, value) => {
228
228
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
229
229
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
230
230
  };
231
- var __privateSet$4 = (obj, member, value, setter) => {
232
- __accessCheck$5(obj, member, "write to private field");
231
+ var __privateSet$7 = (obj, member, value, setter) => {
232
+ __accessCheck$7(obj, member, "write to private field");
233
233
  setter ? setter.call(obj, value) : member.set(obj, value);
234
234
  return value;
235
235
  };
236
- var _client$3, _client2$3;
236
+ var _client$6, _client2$6;
237
237
  class BasePatch {
238
238
  constructor(selection) {
239
239
  let operations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -324,16 +324,16 @@ class BasePatch {
324
324
  const _ObservablePatch = class extends BasePatch {
325
325
  constructor(selection, operations, client) {
326
326
  super(selection, operations);
327
- __privateAdd$5(this, _client$3, void 0);
328
- __privateSet$4(this, _client$3, client);
327
+ __privateAdd$7(this, _client$6, void 0);
328
+ __privateSet$7(this, _client$6, client);
329
329
  }
330
330
  clone() {
331
331
  return new _ObservablePatch(this.selection, {
332
332
  ...this.operations
333
- }, __privateGet$4(this, _client$3));
333
+ }, __privateGet$7(this, _client$6));
334
334
  }
335
335
  commit(options) {
336
- if (!__privateGet$4(this, _client$3)) {
336
+ if (!__privateGet$7(this, _client$6)) {
337
337
  throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
338
338
  }
339
339
  const returnFirst = typeof this.selection === "string";
@@ -341,26 +341,26 @@ const _ObservablePatch = class extends BasePatch {
341
341
  returnFirst,
342
342
  returnDocuments: true
343
343
  }, options);
344
- return __privateGet$4(this, _client$3).mutate({
344
+ return __privateGet$7(this, _client$6).mutate({
345
345
  patch: this.serialize()
346
346
  }, opts);
347
347
  }
348
348
  };
349
349
  let ObservablePatch = _ObservablePatch;
350
- _client$3 = new WeakMap();
350
+ _client$6 = new WeakMap();
351
351
  const _Patch = class extends BasePatch {
352
352
  constructor(selection, operations, client) {
353
353
  super(selection, operations);
354
- __privateAdd$5(this, _client2$3, void 0);
355
- __privateSet$4(this, _client2$3, client);
354
+ __privateAdd$7(this, _client2$6, void 0);
355
+ __privateSet$7(this, _client2$6, client);
356
356
  }
357
357
  clone() {
358
358
  return new _Patch(this.selection, {
359
359
  ...this.operations
360
- }, __privateGet$4(this, _client2$3));
360
+ }, __privateGet$7(this, _client2$6));
361
361
  }
362
362
  commit(options) {
363
- if (!__privateGet$4(this, _client2$3)) {
363
+ if (!__privateGet$7(this, _client2$6)) {
364
364
  throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
365
365
  }
366
366
  const returnFirst = typeof this.selection === "string";
@@ -368,30 +368,30 @@ const _Patch = class extends BasePatch {
368
368
  returnFirst,
369
369
  returnDocuments: true
370
370
  }, options);
371
- return __privateGet$4(this, _client2$3).mutate({
371
+ return __privateGet$7(this, _client2$6).mutate({
372
372
  patch: this.serialize()
373
373
  }, opts);
374
374
  }
375
375
  };
376
376
  let Patch = _Patch;
377
- _client2$3 = new WeakMap();
378
- var __accessCheck$4 = (obj, member, msg) => {
377
+ _client2$6 = new WeakMap();
378
+ var __accessCheck$6 = (obj, member, msg) => {
379
379
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
380
380
  };
381
- var __privateGet$3 = (obj, member, getter) => {
382
- __accessCheck$4(obj, member, "read from private field");
381
+ var __privateGet$6 = (obj, member, getter) => {
382
+ __accessCheck$6(obj, member, "read from private field");
383
383
  return getter ? getter.call(obj) : member.get(obj);
384
384
  };
385
- var __privateAdd$4 = (obj, member, value) => {
385
+ var __privateAdd$6 = (obj, member, value) => {
386
386
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
387
387
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
388
388
  };
389
- var __privateSet$3 = (obj, member, value, setter) => {
390
- __accessCheck$4(obj, member, "write to private field");
389
+ var __privateSet$6 = (obj, member, value, setter) => {
390
+ __accessCheck$6(obj, member, "write to private field");
391
391
  setter ? setter.call(obj, value) : member.set(obj, value);
392
392
  return value;
393
393
  };
394
- var _client$2, _client2$2;
394
+ var _client$5, _client2$5;
395
395
  const defaultMutateOptions = {
396
396
  returnDocuments: false
397
397
  };
@@ -457,17 +457,17 @@ class BaseTransaction {
457
457
  const _Transaction = class extends BaseTransaction {
458
458
  constructor(operations, client, transactionId) {
459
459
  super(operations, transactionId);
460
- __privateAdd$4(this, _client$2, void 0);
461
- __privateSet$3(this, _client$2, client);
460
+ __privateAdd$6(this, _client$5, void 0);
461
+ __privateSet$6(this, _client$5, client);
462
462
  }
463
463
  clone() {
464
- return new _Transaction([...this.operations], __privateGet$3(this, _client$2), this.trxId);
464
+ return new _Transaction([...this.operations], __privateGet$6(this, _client$5), this.trxId);
465
465
  }
466
466
  commit(options) {
467
- if (!__privateGet$3(this, _client$2)) {
467
+ if (!__privateGet$6(this, _client$5)) {
468
468
  throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
469
469
  }
470
- return __privateGet$3(this, _client$2).mutate(this.serialize(), Object.assign({
470
+ return __privateGet$6(this, _client$5).mutate(this.serialize(), Object.assign({
471
471
  transactionId: this.trxId
472
472
  }, defaultMutateOptions, options || {}));
473
473
  }
@@ -480,7 +480,7 @@ const _Transaction = class extends BaseTransaction {
480
480
  });
481
481
  }
482
482
  if (isBuilder) {
483
- const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$3(this, _client$2)));
483
+ const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$6(this, _client$5)));
484
484
  if (!(patch instanceof Patch)) {
485
485
  throw new Error("function passed to `patch()` must return the patch");
486
486
  }
@@ -497,21 +497,21 @@ const _Transaction = class extends BaseTransaction {
497
497
  }
498
498
  };
499
499
  let Transaction = _Transaction;
500
- _client$2 = new WeakMap();
500
+ _client$5 = new WeakMap();
501
501
  const _ObservableTransaction = class extends BaseTransaction {
502
502
  constructor(operations, client, transactionId) {
503
503
  super(operations, transactionId);
504
- __privateAdd$4(this, _client2$2, void 0);
505
- __privateSet$3(this, _client2$2, client);
504
+ __privateAdd$6(this, _client2$5, void 0);
505
+ __privateSet$6(this, _client2$5, client);
506
506
  }
507
507
  clone() {
508
- return new _ObservableTransaction([...this.operations], __privateGet$3(this, _client2$2), this.trxId);
508
+ return new _ObservableTransaction([...this.operations], __privateGet$6(this, _client2$5), this.trxId);
509
509
  }
510
510
  commit(options) {
511
- if (!__privateGet$3(this, _client2$2)) {
511
+ if (!__privateGet$6(this, _client2$5)) {
512
512
  throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
513
513
  }
514
- return __privateGet$3(this, _client2$2).mutate(this.serialize(), Object.assign({
514
+ return __privateGet$6(this, _client2$5).mutate(this.serialize(), Object.assign({
515
515
  transactionId: this.trxId
516
516
  }, defaultMutateOptions, options || {}));
517
517
  }
@@ -524,7 +524,7 @@ const _ObservableTransaction = class extends BaseTransaction {
524
524
  });
525
525
  }
526
526
  if (isBuilder) {
527
- const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$3(this, _client2$2)));
527
+ const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$6(this, _client2$5)));
528
528
  if (!(patch instanceof ObservablePatch)) {
529
529
  throw new Error("function passed to `patch()` must return the patch");
530
530
  }
@@ -541,7 +541,7 @@ const _ObservableTransaction = class extends BaseTransaction {
541
541
  }
542
542
  };
543
543
  let ObservableTransaction = _ObservableTransaction;
544
- _client2$2 = new WeakMap();
544
+ _client2$5 = new WeakMap();
545
545
  const excludeFalsey = (param, defValue) => {
546
546
  const value = typeof param === "undefined" ? defValue : param;
547
547
  return param === false ? void 0 : value;
@@ -575,7 +575,7 @@ function _fetch(client, httpRequest, query, params) {
575
575
  function _getDocument(client, httpRequest, id) {
576
576
  let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
577
577
  const options = {
578
- uri: client.getDataUrl("doc", id),
578
+ uri: _getDataUrl(client, "doc", id),
579
579
  json: true,
580
580
  tag: opts.tag
581
581
  };
@@ -584,7 +584,7 @@ function _getDocument(client, httpRequest, id) {
584
584
  function _getDocuments(client, httpRequest, ids) {
585
585
  let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
586
586
  const options = {
587
- uri: client.getDataUrl("doc", ids.join(",")),
587
+ uri: _getDataUrl(client, "doc", ids.join(",")),
588
588
  json: true,
589
589
  tag: opts.tag
590
590
  };
@@ -631,7 +631,7 @@ function _dataRequest(client, httpRequest, endpoint, body) {
631
631
  tag,
632
632
  headers
633
633
  } = options;
634
- const uri = client.getDataUrl(endpoint, stringQuery);
634
+ const uri = _getDataUrl(client, endpoint, stringQuery);
635
635
  const reqOptions = {
636
636
  method: useGet ? "GET" : "POST",
637
637
  uri,
@@ -687,7 +687,7 @@ function _requestObservable(client, httpRequest, options) {
687
687
  };
688
688
  }
689
689
  const reqOptions = getRequestOptions(config, Object.assign({}, options, {
690
- url: client.getUrl(uri, useCdn)
690
+ url: _getUrl(client, uri, useCdn)
691
691
  }));
692
692
  return new rxjs.Observable(subscriber => httpRequest(reqOptions, config.requester).subscribe(subscriber));
693
693
  }
@@ -695,50 +695,66 @@ function _request(client, httpRequest, options) {
695
695
  const observable = _requestObservable(client, httpRequest, options).pipe(operators.filter(event => event.type === "response"), operators.map(event => event.body));
696
696
  return observable;
697
697
  }
698
- var __accessCheck$3 = (obj, member, msg) => {
698
+ function _getDataUrl(client, operation, path) {
699
+ const config = client.config();
700
+ const catalog = hasDataset(config);
701
+ const baseUri = "/".concat(operation, "/").concat(catalog);
702
+ const uri = path ? "".concat(baseUri, "/").concat(path) : baseUri;
703
+ return "/data".concat(uri).replace(/\/($|\?)/, "$1");
704
+ }
705
+ function _getUrl(client, uri) {
706
+ let canUseCdn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
707
+ const {
708
+ url,
709
+ cdnUrl
710
+ } = client.config();
711
+ const base = canUseCdn ? cdnUrl : url;
712
+ return "".concat(base, "/").concat(uri.replace(/^\//, ""));
713
+ }
714
+ var __accessCheck$5 = (obj, member, msg) => {
699
715
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
700
716
  };
701
- var __privateGet$2 = (obj, member, getter) => {
702
- __accessCheck$3(obj, member, "read from private field");
717
+ var __privateGet$5 = (obj, member, getter) => {
718
+ __accessCheck$5(obj, member, "read from private field");
703
719
  return getter ? getter.call(obj) : member.get(obj);
704
720
  };
705
- var __privateAdd$3 = (obj, member, value) => {
721
+ var __privateAdd$5 = (obj, member, value) => {
706
722
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
707
723
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
708
724
  };
709
- var __privateSet$2 = (obj, member, value, setter) => {
710
- __accessCheck$3(obj, member, "write to private field");
725
+ var __privateSet$5 = (obj, member, value, setter) => {
726
+ __accessCheck$5(obj, member, "write to private field");
711
727
  setter ? setter.call(obj, value) : member.set(obj, value);
712
728
  return value;
713
729
  };
714
- var _client$1, _httpRequest$2, _client2$1, _httpRequest2$2;
730
+ var _client$4, _httpRequest$5, _client2$4, _httpRequest2$5;
715
731
  class ObservableAssetsClient {
716
732
  constructor(client, httpRequest) {
717
- __privateAdd$3(this, _client$1, void 0);
718
- __privateAdd$3(this, _httpRequest$2, void 0);
719
- __privateSet$2(this, _client$1, client);
720
- __privateSet$2(this, _httpRequest$2, httpRequest);
733
+ __privateAdd$5(this, _client$4, void 0);
734
+ __privateAdd$5(this, _httpRequest$5, void 0);
735
+ __privateSet$5(this, _client$4, client);
736
+ __privateSet$5(this, _httpRequest$5, httpRequest);
721
737
  }
722
738
  upload(assetType, body, options) {
723
- return _upload(__privateGet$2(this, _client$1), __privateGet$2(this, _httpRequest$2), assetType, body, options);
739
+ return _upload(__privateGet$5(this, _client$4), __privateGet$5(this, _httpRequest$5), assetType, body, options);
724
740
  }
725
741
  }
726
- _client$1 = new WeakMap();
727
- _httpRequest$2 = new WeakMap();
742
+ _client$4 = new WeakMap();
743
+ _httpRequest$5 = new WeakMap();
728
744
  class AssetsClient {
729
745
  constructor(client, httpRequest) {
730
- __privateAdd$3(this, _client2$1, void 0);
731
- __privateAdd$3(this, _httpRequest2$2, void 0);
732
- __privateSet$2(this, _client2$1, client);
733
- __privateSet$2(this, _httpRequest2$2, httpRequest);
746
+ __privateAdd$5(this, _client2$4, void 0);
747
+ __privateAdd$5(this, _httpRequest2$5, void 0);
748
+ __privateSet$5(this, _client2$4, client);
749
+ __privateSet$5(this, _httpRequest2$5, httpRequest);
734
750
  }
735
751
  upload(assetType, body, options) {
736
- const observable = _upload(__privateGet$2(this, _client2$1), __privateGet$2(this, _httpRequest2$2), assetType, body, options);
752
+ const observable = _upload(__privateGet$5(this, _client2$4), __privateGet$5(this, _httpRequest2$5), assetType, body, options);
737
753
  return rxjs.lastValueFrom(observable.pipe(operators.filter(event => event.type === "response"), operators.map(event => event.body.document)));
738
754
  }
739
755
  }
740
- _client2$1 = new WeakMap();
741
- _httpRequest2$2 = new WeakMap();
756
+ _client2$4 = new WeakMap();
757
+ _httpRequest2$5 = new WeakMap();
742
758
  function _upload(client, httpRequest, assetType, body) {
743
759
  let opts = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
744
760
  validateAssetType(assetType);
@@ -792,65 +808,65 @@ function optionsFromFile(opts, file) {
792
808
  contentType: file.type
793
809
  }, opts);
794
810
  }
795
- var __accessCheck$2 = (obj, member, msg) => {
811
+ var __accessCheck$4 = (obj, member, msg) => {
796
812
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
797
813
  };
798
- var __privateGet$1 = (obj, member, getter) => {
799
- __accessCheck$2(obj, member, "read from private field");
814
+ var __privateGet$4 = (obj, member, getter) => {
815
+ __accessCheck$4(obj, member, "read from private field");
800
816
  return getter ? getter.call(obj) : member.get(obj);
801
817
  };
802
- var __privateAdd$2 = (obj, member, value) => {
818
+ var __privateAdd$4 = (obj, member, value) => {
803
819
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
804
820
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
805
821
  };
806
- var __privateSet$1 = (obj, member, value, setter) => {
807
- __accessCheck$2(obj, member, "write to private field");
822
+ var __privateSet$4 = (obj, member, value, setter) => {
823
+ __accessCheck$4(obj, member, "write to private field");
808
824
  setter ? setter.call(obj, value) : member.set(obj, value);
809
825
  return value;
810
826
  };
811
- var _client, _httpRequest$1, _client2, _httpRequest2$1;
827
+ var _client$3, _httpRequest$4, _client2$3, _httpRequest2$4;
812
828
  class ObservableAuthClient {
813
829
  constructor(client, httpRequest) {
814
- __privateAdd$2(this, _client, void 0);
815
- __privateAdd$2(this, _httpRequest$1, void 0);
816
- __privateSet$1(this, _client, client);
817
- __privateSet$1(this, _httpRequest$1, httpRequest);
830
+ __privateAdd$4(this, _client$3, void 0);
831
+ __privateAdd$4(this, _httpRequest$4, void 0);
832
+ __privateSet$4(this, _client$3, client);
833
+ __privateSet$4(this, _httpRequest$4, httpRequest);
818
834
  }
819
835
  getLoginProviders() {
820
- return _request(__privateGet$1(this, _client), __privateGet$1(this, _httpRequest$1), {
836
+ return _request(__privateGet$4(this, _client$3), __privateGet$4(this, _httpRequest$4), {
821
837
  uri: "/auth/providers"
822
838
  });
823
839
  }
824
840
  logout() {
825
- return _request(__privateGet$1(this, _client), __privateGet$1(this, _httpRequest$1), {
841
+ return _request(__privateGet$4(this, _client$3), __privateGet$4(this, _httpRequest$4), {
826
842
  uri: "/auth/logout",
827
843
  method: "POST"
828
844
  });
829
845
  }
830
846
  }
831
- _client = new WeakMap();
832
- _httpRequest$1 = new WeakMap();
847
+ _client$3 = new WeakMap();
848
+ _httpRequest$4 = new WeakMap();
833
849
  class AuthClient {
834
850
  constructor(client, httpRequest) {
835
- __privateAdd$2(this, _client2, void 0);
836
- __privateAdd$2(this, _httpRequest2$1, void 0);
837
- __privateSet$1(this, _client2, client);
838
- __privateSet$1(this, _httpRequest2$1, httpRequest);
851
+ __privateAdd$4(this, _client2$3, void 0);
852
+ __privateAdd$4(this, _httpRequest2$4, void 0);
853
+ __privateSet$4(this, _client2$3, client);
854
+ __privateSet$4(this, _httpRequest2$4, httpRequest);
839
855
  }
840
856
  getLoginProviders() {
841
- return rxjs.lastValueFrom(_request(__privateGet$1(this, _client2), __privateGet$1(this, _httpRequest2$1), {
857
+ return rxjs.lastValueFrom(_request(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), {
842
858
  uri: "/auth/providers"
843
859
  }));
844
860
  }
845
861
  logout() {
846
- return rxjs.lastValueFrom(_request(__privateGet$1(this, _client2), __privateGet$1(this, _httpRequest2$1), {
862
+ return rxjs.lastValueFrom(_request(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), {
847
863
  uri: "/auth/logout",
848
864
  method: "POST"
849
865
  }));
850
866
  }
851
867
  }
852
- _client2 = new WeakMap();
853
- _httpRequest2$1 = new WeakMap();
868
+ _client2$3 = new WeakMap();
869
+ _httpRequest2$4 = new WeakMap();
854
870
  const BASE_URL = "https://docs.sanity.io/help/";
855
871
  function generateHelpUrl(slug) {
856
872
  return BASE_URL + slug;
@@ -980,7 +996,7 @@ function _listen(query, params) {
980
996
  ...listenOpts
981
997
  }
982
998
  });
983
- const uri = "".concat(url).concat(this.getDataUrl("listen", qs));
999
+ const uri = "".concat(url).concat(_getDataUrl(this, "listen", qs));
984
1000
  if (uri.length > MAX_URL_LENGTH) {
985
1001
  return new rxjs.Observable(observer => observer.error(new Error("Query too large for listener")));
986
1002
  }
@@ -1083,101 +1099,183 @@ function extractErrorMessage(err) {
1083
1099
  }
1084
1100
  return typeof err.error === "string" ? err.error : JSON.stringify(err.error, null, 2);
1085
1101
  }
1086
- var __accessCheck$1 = (obj, member, msg) => {
1102
+ var __accessCheck$3 = (obj, member, msg) => {
1087
1103
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
1088
1104
  };
1089
- var __privateAdd$1 = (obj, member, value) => {
1105
+ var __privateGet$3 = (obj, member, getter) => {
1106
+ __accessCheck$3(obj, member, "read from private field");
1107
+ return getter ? getter.call(obj) : member.get(obj);
1108
+ };
1109
+ var __privateAdd$3 = (obj, member, value) => {
1090
1110
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
1091
1111
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1092
1112
  };
1093
- var __privateMethod = (obj, member, method) => {
1094
- __accessCheck$1(obj, member, "access private method");
1095
- return method;
1113
+ var __privateSet$3 = (obj, member, value, setter) => {
1114
+ __accessCheck$3(obj, member, "write to private field");
1115
+ setter ? setter.call(obj, value) : member.set(obj, value);
1116
+ return value;
1096
1117
  };
1097
- var __modify, _modify_fn;
1098
- class BaseDatasetsClient {
1099
- constructor() {
1100
- __privateAdd$1(this, __modify);
1118
+ var _client$2, _httpRequest$3, _client2$2, _httpRequest2$3;
1119
+ class ObservableDatasetsClient {
1120
+ constructor(client, httpRequest) {
1121
+ __privateAdd$3(this, _client$2, void 0);
1122
+ __privateAdd$3(this, _httpRequest$3, void 0);
1123
+ __privateSet$3(this, _client$2, client);
1124
+ __privateSet$3(this, _httpRequest$3, httpRequest);
1101
1125
  }
1102
1126
  create(name, options) {
1103
- return __privateMethod(this, __modify, _modify_fn).call(this, "PUT", name, options);
1127
+ return _modify(__privateGet$3(this, _client$2), __privateGet$3(this, _httpRequest$3), "PUT", name, options);
1104
1128
  }
1105
1129
  edit(name, options) {
1106
- return __privateMethod(this, __modify, _modify_fn).call(this, "PATCH", name, options);
1130
+ return _modify(__privateGet$3(this, _client$2), __privateGet$3(this, _httpRequest$3), "PATCH", name, options);
1107
1131
  }
1108
1132
  delete(name) {
1109
- return __privateMethod(this, __modify, _modify_fn).call(this, "DELETE", name);
1133
+ return _modify(__privateGet$3(this, _client$2), __privateGet$3(this, _httpRequest$3), "DELETE", name);
1110
1134
  }
1111
1135
  list() {
1112
- return this.client.request({
1136
+ return _request(__privateGet$3(this, _client$2), __privateGet$3(this, _httpRequest$3), {
1113
1137
  uri: "/datasets"
1114
1138
  });
1115
1139
  }
1116
1140
  }
1117
- __modify = new WeakSet();
1118
- _modify_fn = function (method, name, options) {
1141
+ _client$2 = new WeakMap();
1142
+ _httpRequest$3 = new WeakMap();
1143
+ class DatasetsClient {
1144
+ constructor(client, httpRequest) {
1145
+ __privateAdd$3(this, _client2$2, void 0);
1146
+ __privateAdd$3(this, _httpRequest2$3, void 0);
1147
+ __privateSet$3(this, _client2$2, client);
1148
+ __privateSet$3(this, _httpRequest2$3, httpRequest);
1149
+ }
1150
+ create(name, options) {
1151
+ return rxjs.lastValueFrom(_modify(__privateGet$3(this, _client2$2), __privateGet$3(this, _httpRequest2$3), "PUT", name, options));
1152
+ }
1153
+ edit(name, options) {
1154
+ return rxjs.lastValueFrom(_modify(__privateGet$3(this, _client2$2), __privateGet$3(this, _httpRequest2$3), "PATCH", name, options));
1155
+ }
1156
+ delete(name) {
1157
+ return rxjs.lastValueFrom(_modify(__privateGet$3(this, _client2$2), __privateGet$3(this, _httpRequest2$3), "DELETE", name));
1158
+ }
1159
+ list() {
1160
+ return rxjs.lastValueFrom(_request(__privateGet$3(this, _client2$2), __privateGet$3(this, _httpRequest2$3), {
1161
+ uri: "/datasets"
1162
+ }));
1163
+ }
1164
+ }
1165
+ _client2$2 = new WeakMap();
1166
+ _httpRequest2$3 = new WeakMap();
1167
+ function _modify(client, httpRequest, method, name, options) {
1119
1168
  dataset(name);
1120
- return this.client.request({
1169
+ return _request(client, httpRequest, {
1121
1170
  method,
1122
1171
  uri: "/datasets/".concat(name),
1123
1172
  body: options
1124
1173
  });
1125
- };
1126
- class ObservableDatasetsClient extends BaseDatasetsClient {
1127
- constructor(client) {
1128
- super();
1129
- this.client = client;
1130
- }
1131
1174
  }
1132
- class DatasetsClient extends BaseDatasetsClient {
1133
- constructor(client) {
1134
- super();
1135
- this.client = client;
1175
+ var __accessCheck$2 = (obj, member, msg) => {
1176
+ if (!member.has(obj)) throw TypeError("Cannot " + msg);
1177
+ };
1178
+ var __privateGet$2 = (obj, member, getter) => {
1179
+ __accessCheck$2(obj, member, "read from private field");
1180
+ return getter ? getter.call(obj) : member.get(obj);
1181
+ };
1182
+ var __privateAdd$2 = (obj, member, value) => {
1183
+ if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
1184
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1185
+ };
1186
+ var __privateSet$2 = (obj, member, value, setter) => {
1187
+ __accessCheck$2(obj, member, "write to private field");
1188
+ setter ? setter.call(obj, value) : member.set(obj, value);
1189
+ return value;
1190
+ };
1191
+ var _client$1, _httpRequest$2, _client2$1, _httpRequest2$2;
1192
+ class ObservableProjectsClient {
1193
+ constructor(client, httpRequest) {
1194
+ __privateAdd$2(this, _client$1, void 0);
1195
+ __privateAdd$2(this, _httpRequest$2, void 0);
1196
+ __privateSet$2(this, _client$1, client);
1197
+ __privateSet$2(this, _httpRequest$2, httpRequest);
1136
1198
  }
1137
- }
1138
- class BaseProjectsClient {
1139
1199
  list() {
1140
- return this.client.request({
1200
+ return _request(__privateGet$2(this, _client$1), __privateGet$2(this, _httpRequest$2), {
1141
1201
  uri: "/projects"
1142
1202
  });
1143
1203
  }
1144
1204
  getById(projectId) {
1145
- return this.client.request({
1205
+ return _request(__privateGet$2(this, _client$1), __privateGet$2(this, _httpRequest$2), {
1146
1206
  uri: "/projects/".concat(projectId)
1147
1207
  });
1148
1208
  }
1149
1209
  }
1150
- class ObservableProjectsClient extends BaseProjectsClient {
1151
- constructor(client) {
1152
- super();
1153
- this.client = client;
1210
+ _client$1 = new WeakMap();
1211
+ _httpRequest$2 = new WeakMap();
1212
+ class ProjectsClient {
1213
+ constructor(client, httpRequest) {
1214
+ __privateAdd$2(this, _client2$1, void 0);
1215
+ __privateAdd$2(this, _httpRequest2$2, void 0);
1216
+ __privateSet$2(this, _client2$1, client);
1217
+ __privateSet$2(this, _httpRequest2$2, httpRequest);
1154
1218
  }
1155
- }
1156
- class ProjectsClient extends BaseProjectsClient {
1157
- constructor(client) {
1158
- super();
1159
- this.client = client;
1219
+ list() {
1220
+ return rxjs.lastValueFrom(_request(__privateGet$2(this, _client2$1), __privateGet$2(this, _httpRequest2$2), {
1221
+ uri: "/projects"
1222
+ }));
1223
+ }
1224
+ getById(projectId) {
1225
+ return rxjs.lastValueFrom(_request(__privateGet$2(this, _client2$1), __privateGet$2(this, _httpRequest2$2), {
1226
+ uri: "/projects/".concat(projectId)
1227
+ }));
1160
1228
  }
1161
1229
  }
1162
- class BaseUsersClient {
1230
+ _client2$1 = new WeakMap();
1231
+ _httpRequest2$2 = new WeakMap();
1232
+ var __accessCheck$1 = (obj, member, msg) => {
1233
+ if (!member.has(obj)) throw TypeError("Cannot " + msg);
1234
+ };
1235
+ var __privateGet$1 = (obj, member, getter) => {
1236
+ __accessCheck$1(obj, member, "read from private field");
1237
+ return getter ? getter.call(obj) : member.get(obj);
1238
+ };
1239
+ var __privateAdd$1 = (obj, member, value) => {
1240
+ if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
1241
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1242
+ };
1243
+ var __privateSet$1 = (obj, member, value, setter) => {
1244
+ __accessCheck$1(obj, member, "write to private field");
1245
+ setter ? setter.call(obj, value) : member.set(obj, value);
1246
+ return value;
1247
+ };
1248
+ var _client, _httpRequest$1, _client2, _httpRequest2$1;
1249
+ class ObservableUsersClient {
1250
+ constructor(client, httpRequest) {
1251
+ __privateAdd$1(this, _client, void 0);
1252
+ __privateAdd$1(this, _httpRequest$1, void 0);
1253
+ __privateSet$1(this, _client, client);
1254
+ __privateSet$1(this, _httpRequest$1, httpRequest);
1255
+ }
1163
1256
  getById(id) {
1164
- return this.client.request({
1257
+ return _request(__privateGet$1(this, _client), __privateGet$1(this, _httpRequest$1), {
1165
1258
  uri: "/users/".concat(id)
1166
1259
  });
1167
1260
  }
1168
1261
  }
1169
- class ObservableUsersClient extends BaseUsersClient {
1170
- constructor(client) {
1171
- super();
1172
- this.client = client;
1262
+ _client = new WeakMap();
1263
+ _httpRequest$1 = new WeakMap();
1264
+ class UsersClient {
1265
+ constructor(client, httpRequest) {
1266
+ __privateAdd$1(this, _client2, void 0);
1267
+ __privateAdd$1(this, _httpRequest2$1, void 0);
1268
+ __privateSet$1(this, _client2, client);
1269
+ __privateSet$1(this, _httpRequest2$1, httpRequest);
1173
1270
  }
1174
- }
1175
- class UsersClient extends BaseUsersClient {
1176
- constructor(client) {
1177
- super();
1178
- this.client = client;
1271
+ getById(id) {
1272
+ return rxjs.lastValueFrom(_request(__privateGet$1(this, _client2), __privateGet$1(this, _httpRequest2$1), {
1273
+ uri: "/users/".concat(id)
1274
+ }));
1179
1275
  }
1180
1276
  }
1277
+ _client2 = new WeakMap();
1278
+ _httpRequest2$1 = new WeakMap();
1181
1279
  var __accessCheck = (obj, member, msg) => {
1182
1280
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
1183
1281
  };
@@ -1196,16 +1294,17 @@ var __privateSet = (obj, member, value, setter) => {
1196
1294
  };
1197
1295
  var _clientConfig, _httpRequest, _clientConfig2, _httpRequest2;
1198
1296
  const _ObservableSanityClient = class {
1199
- constructor(httpRequest, config) {
1297
+ constructor(httpRequest) {
1298
+ let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
1200
1299
  __privateAdd(this, _clientConfig, void 0);
1201
1300
  __privateAdd(this, _httpRequest, void 0);
1202
1301
  this.config(config);
1203
1302
  __privateSet(this, _httpRequest, httpRequest);
1204
1303
  this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest));
1205
1304
  this.auth = new ObservableAuthClient(this, __privateGet(this, _httpRequest));
1206
- this.datasets = new ObservableDatasetsClient(this);
1207
- this.projects = new ObservableProjectsClient(this);
1208
- this.users = new ObservableUsersClient(this);
1305
+ this.datasets = new ObservableDatasetsClient(this, __privateGet(this, _httpRequest));
1306
+ this.projects = new ObservableProjectsClient(this, __privateGet(this, _httpRequest));
1307
+ this.users = new ObservableUsersClient(this, __privateGet(this, _httpRequest));
1209
1308
  }
1210
1309
  clone() {
1211
1310
  return new _ObservableSanityClient(__privateGet(this, _httpRequest), this.config());
@@ -1262,35 +1361,24 @@ const _ObservableSanityClient = class {
1262
1361
  request(options) {
1263
1362
  return _request(this, __privateGet(this, _httpRequest), options);
1264
1363
  }
1265
- getUrl(uri) {
1266
- let canUseCdn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1267
- const base = canUseCdn ? __privateGet(this, _clientConfig).cdnUrl : __privateGet(this, _clientConfig).url;
1268
- return "".concat(base, "/").concat(uri.replace(/^\//, ""));
1269
- }
1270
- getDataUrl(operation, path) {
1271
- const config = this.config();
1272
- const catalog = hasDataset(config);
1273
- const baseUri = "/".concat(operation, "/").concat(catalog);
1274
- const uri = path ? "".concat(baseUri, "/").concat(path) : baseUri;
1275
- return "/data".concat(uri).replace(/\/($|\?)/, "$1");
1276
- }
1277
1364
  };
1278
1365
  let ObservableSanityClient = _ObservableSanityClient;
1279
1366
  _clientConfig = new WeakMap();
1280
1367
  _httpRequest = new WeakMap();
1281
1368
  const _SanityClient = class {
1282
- constructor(httpRequest, config) {
1369
+ constructor(httpRequest) {
1370
+ let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
1283
1371
  __privateAdd(this, _clientConfig2, void 0);
1284
1372
  __privateAdd(this, _httpRequest2, void 0);
1285
1373
  this.listen = _listen;
1286
- this.observable = new ObservableSanityClient(httpRequest, config);
1287
1374
  this.config(config);
1288
1375
  __privateSet(this, _httpRequest2, httpRequest);
1289
1376
  this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2));
1290
1377
  this.auth = new AuthClient(this, __privateGet(this, _httpRequest2));
1291
- this.datasets = new DatasetsClient(this);
1292
- this.projects = new ProjectsClient(this);
1293
- this.users = new UsersClient(this);
1378
+ this.datasets = new DatasetsClient(this, __privateGet(this, _httpRequest2));
1379
+ this.projects = new ProjectsClient(this, __privateGet(this, _httpRequest2));
1380
+ this.users = new UsersClient(this, __privateGet(this, _httpRequest2));
1381
+ this.observable = new ObservableSanityClient(httpRequest, config);
1294
1382
  }
1295
1383
  clone() {
1296
1384
  return new _SanityClient(__privateGet(this, _httpRequest2), this.config());
@@ -1304,7 +1392,9 @@ const _SanityClient = class {
1304
1392
  if (__privateGet(this, _clientConfig2) && __privateGet(this, _clientConfig2).allowReconfigure === false) {
1305
1393
  throw new Error("Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client");
1306
1394
  }
1307
- this.observable.config(newConfig);
1395
+ if (this.observable) {
1396
+ this.observable.config(newConfig);
1397
+ }
1308
1398
  __privateSet(this, _clientConfig2, initConfig(newConfig, __privateGet(this, _clientConfig2) || {}));
1309
1399
  return this;
1310
1400
  }
@@ -1351,27 +1441,13 @@ const _SanityClient = class {
1351
1441
  dataRequest(endpoint, body, options) {
1352
1442
  return rxjs.lastValueFrom(_dataRequest(this, __privateGet(this, _httpRequest2), endpoint, body, options));
1353
1443
  }
1354
- getUrl(uri) {
1355
- let canUseCdn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1356
- const base = canUseCdn ? __privateGet(this, _clientConfig2).cdnUrl : __privateGet(this, _clientConfig2).url;
1357
- return "".concat(base, "/").concat(uri.replace(/^\//, ""));
1358
- }
1359
- getDataUrl(operation, path) {
1360
- const config = this.config();
1361
- const catalog = hasDataset(config);
1362
- const baseUri = "/".concat(operation, "/").concat(catalog);
1363
- const uri = path ? "".concat(baseUri, "/").concat(path) : baseUri;
1364
- return "/data".concat(uri).replace(/\/($|\?)/, "$1");
1365
- }
1366
1444
  };
1367
1445
  let SanityClient = _SanityClient;
1368
1446
  _clientConfig2 = new WeakMap();
1369
1447
  _httpRequest2 = new WeakMap();
1370
1448
  const httpRequest = defineHttpRequest(middleware);
1371
1449
  const requester = httpRequest.defaultRequester;
1372
- function createClient(config) {
1373
- return new SanityClient(httpRequest, config);
1374
- }
1450
+ const createClient = config => new SanityClient(httpRequest, config);
1375
1451
  exports.BasePatch = BasePatch;
1376
1452
  exports.BaseTransaction = BaseTransaction;
1377
1453
  exports.ClientError = ClientError;