@sanity/client 6.1.3 → 6.2.0-fetch.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,12 +4,26 @@ import { retry, jsonRequest, jsonResponse, progress, observable } from 'get-it/m
4
4
  import { Observable, lastValueFrom } from 'rxjs';
5
5
  import { map, filter } from 'rxjs/operators';
6
6
  var envMiddleware = [];
7
+ var __defProp$3 = Object.defineProperty;
8
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value
13
+ }) : obj[key] = value;
14
+ var __publicField$3 = (obj, key, value) => {
15
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
16
+ return value;
17
+ };
7
18
  const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
8
19
  class ClientError extends Error {
9
20
  constructor(res) {
10
21
  const props = extractErrorProps(res);
11
22
  super(props.message);
12
- this.statusCode = 400;
23
+ __publicField$3(this, "response");
24
+ __publicField$3(this, "statusCode", 400);
25
+ __publicField$3(this, "responseBody");
26
+ __publicField$3(this, "details");
13
27
  Object.assign(this, props);
14
28
  }
15
29
  }
@@ -17,7 +31,10 @@ class ServerError extends Error {
17
31
  constructor(res) {
18
32
  const props = extractErrorProps(res);
19
33
  super(props.message);
20
- this.statusCode = 500;
34
+ __publicField$3(this, "response");
35
+ __publicField$3(this, "statusCode", 500);
36
+ __publicField$3(this, "responseBody");
37
+ __publicField$3(this, "details");
21
38
  Object.assign(this, props);
22
39
  }
23
40
  }
@@ -238,6 +255,17 @@ const encodeQueryString = _ref2 => {
238
255
  }
239
256
  return "?".concat(searchParams);
240
257
  };
258
+ var __defProp$2 = Object.defineProperty;
259
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, {
260
+ enumerable: true,
261
+ configurable: true,
262
+ writable: true,
263
+ value
264
+ }) : obj[key] = value;
265
+ var __publicField$2 = (obj, key, value) => {
266
+ __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
267
+ return value;
268
+ };
241
269
  var __accessCheck$6 = (obj, member, msg) => {
242
270
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
243
271
  };
@@ -258,6 +286,8 @@ var _client$5, _client2$5;
258
286
  class BasePatch {
259
287
  constructor(selection) {
260
288
  let operations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
289
+ __publicField$2(this, "selection");
290
+ __publicField$2(this, "operations");
261
291
  this.selection = selection;
262
292
  this.operations = operations;
263
293
  }
@@ -411,7 +441,7 @@ class BasePatch {
411
441
  return this._assign(op, props, false);
412
442
  }
413
443
  }
414
- const _ObservablePatch = class extends BasePatch {
444
+ const _ObservablePatch = class _ObservablePatch extends BasePatch {
415
445
  constructor(selection, operations, client) {
416
446
  super(selection, operations);
417
447
  __privateAdd$6(this, _client$5, void 0);
@@ -439,9 +469,9 @@ const _ObservablePatch = class extends BasePatch {
439
469
  }, opts);
440
470
  }
441
471
  };
442
- let ObservablePatch = _ObservablePatch;
443
472
  _client$5 = new WeakMap();
444
- const _Patch = class extends BasePatch {
473
+ let ObservablePatch = _ObservablePatch;
474
+ const _Patch = class _Patch extends BasePatch {
445
475
  constructor(selection, operations, client) {
446
476
  super(selection, operations);
447
477
  __privateAdd$6(this, _client2$5, void 0);
@@ -469,8 +499,19 @@ const _Patch = class extends BasePatch {
469
499
  }, opts);
470
500
  }
471
501
  };
472
- let Patch = _Patch;
473
502
  _client2$5 = new WeakMap();
503
+ let Patch = _Patch;
504
+ var __defProp$1 = Object.defineProperty;
505
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, {
506
+ enumerable: true,
507
+ configurable: true,
508
+ writable: true,
509
+ value
510
+ }) : obj[key] = value;
511
+ var __publicField$1 = (obj, key, value) => {
512
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
513
+ return value;
514
+ };
474
515
  var __accessCheck$5 = (obj, member, msg) => {
475
516
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
476
517
  };
@@ -495,6 +536,8 @@ class BaseTransaction {
495
536
  constructor() {
496
537
  let operations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
497
538
  let transactionId = arguments.length > 1 ? arguments[1] : undefined;
539
+ __publicField$1(this, "operations");
540
+ __publicField$1(this, "trxId");
498
541
  this.operations = operations;
499
542
  this.trxId = transactionId;
500
543
  }
@@ -583,7 +626,7 @@ class BaseTransaction {
583
626
  return this;
584
627
  }
585
628
  }
586
- const _Transaction = class extends BaseTransaction {
629
+ const _Transaction = class _Transaction extends BaseTransaction {
587
630
  constructor(operations, client, transactionId) {
588
631
  super(operations, transactionId);
589
632
  __privateAdd$5(this, _client$4, void 0);
@@ -628,9 +671,9 @@ const _Transaction = class extends BaseTransaction {
628
671
  });
629
672
  }
630
673
  };
631
- let Transaction = _Transaction;
632
674
  _client$4 = new WeakMap();
633
- const _ObservableTransaction = class extends BaseTransaction {
675
+ let Transaction = _Transaction;
676
+ const _ObservableTransaction = class _ObservableTransaction extends BaseTransaction {
634
677
  constructor(operations, client, transactionId) {
635
678
  super(operations, transactionId);
636
679
  __privateAdd$5(this, _client2$4, void 0);
@@ -675,8 +718,8 @@ const _ObservableTransaction = class extends BaseTransaction {
675
718
  });
676
719
  }
677
720
  };
678
- let ObservableTransaction = _ObservableTransaction;
679
721
  _client2$4 = new WeakMap();
722
+ let ObservableTransaction = _ObservableTransaction;
680
723
  const excludeFalsey = (param, defValue) => {
681
724
  const value = typeof param === "undefined" ? defValue : param;
682
725
  return param === false ? void 0 : value;
@@ -702,10 +745,22 @@ const getQuerySizeLimit = 11264;
702
745
  function _fetch(client, httpRequest, query, params) {
703
746
  let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
704
747
  const mapResponse = options.filterResponse === false ? res => res : res => res.result;
748
+ const {
749
+ cache,
750
+ next,
751
+ ...opts
752
+ } = options;
753
+ const reqOpts = typeof cache !== "undefined" || typeof next !== "undefined" ? {
754
+ ...opts,
755
+ fetch: {
756
+ cache,
757
+ next
758
+ }
759
+ } : opts;
705
760
  return _dataRequest(client, httpRequest, "query", {
706
761
  query,
707
762
  params
708
- }, options).pipe(map(mapResponse));
763
+ }, reqOpts).pipe(map(mapResponse));
709
764
  }
710
765
  function _getDocument(client, httpRequest, id) {
711
766
  let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
@@ -787,7 +842,8 @@ function _dataRequest(client, httpRequest, endpoint, body) {
787
842
  token,
788
843
  tag,
789
844
  canUseCdn: isQuery,
790
- signal: options.signal
845
+ signal: options.signal,
846
+ fetch: options.fetch
791
847
  };
792
848
  return _requestObservable(client, httpRequest, reqOptions).pipe(filter(isResponse), map(getBody), map(res => {
793
849
  if (!isMutation) {
@@ -1489,6 +1545,17 @@ class UsersClient {
1489
1545
  }
1490
1546
  _client2 = new WeakMap();
1491
1547
  _httpRequest2$1 = new WeakMap();
1548
+ var __defProp = Object.defineProperty;
1549
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
1550
+ enumerable: true,
1551
+ configurable: true,
1552
+ writable: true,
1553
+ value
1554
+ }) : obj[key] = value;
1555
+ var __publicField = (obj, key, value) => {
1556
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1557
+ return value;
1558
+ };
1492
1559
  var __accessCheck = (obj, member, msg) => {
1493
1560
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
1494
1561
  };
@@ -1506,9 +1573,13 @@ var __privateSet = (obj, member, value, setter) => {
1506
1573
  return value;
1507
1574
  };
1508
1575
  var _clientConfig, _httpRequest, _clientConfig2, _httpRequest2;
1509
- const _ObservableSanityClient = class {
1576
+ const _ObservableSanityClient = class _ObservableSanityClient {
1510
1577
  constructor(httpRequest) {
1511
1578
  let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
1579
+ __publicField(this, "assets");
1580
+ __publicField(this, "datasets");
1581
+ __publicField(this, "projects");
1582
+ __publicField(this, "users");
1512
1583
  /**
1513
1584
  * Private properties
1514
1585
  */
@@ -1517,7 +1588,7 @@ const _ObservableSanityClient = class {
1517
1588
  /**
1518
1589
  * Instance properties
1519
1590
  */
1520
- this.listen = _listen;
1591
+ __publicField(this, "listen", _listen);
1521
1592
  this.config(config);
1522
1593
  __privateSet(this, _httpRequest, httpRequest);
1523
1594
  this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest));
@@ -1639,12 +1710,20 @@ const _ObservableSanityClient = class {
1639
1710
  return _getDataUrl(this, operation, path);
1640
1711
  }
1641
1712
  };
1642
- let ObservableSanityClient = _ObservableSanityClient;
1643
1713
  _clientConfig = new WeakMap();
1644
1714
  _httpRequest = new WeakMap();
1645
- const _SanityClient = class {
1715
+ let ObservableSanityClient = _ObservableSanityClient;
1716
+ const _SanityClient = class _SanityClient {
1646
1717
  constructor(httpRequest) {
1647
1718
  let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
1719
+ __publicField(this, "assets");
1720
+ __publicField(this, "datasets");
1721
+ __publicField(this, "projects");
1722
+ __publicField(this, "users");
1723
+ /**
1724
+ * Observable version of the Sanity client, with the same configuration as the promise-based one
1725
+ */
1726
+ __publicField(this, "observable");
1648
1727
  /**
1649
1728
  * Private properties
1650
1729
  */
@@ -1653,7 +1732,7 @@ const _SanityClient = class {
1653
1732
  /**
1654
1733
  * Instance properties
1655
1734
  */
1656
- this.listen = _listen;
1735
+ __publicField(this, "listen", _listen);
1657
1736
  this.config(config);
1658
1737
  __privateSet(this, _httpRequest2, httpRequest);
1659
1738
  this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2));
@@ -1793,9 +1872,9 @@ const _SanityClient = class {
1793
1872
  return _getDataUrl(this, operation, path);
1794
1873
  }
1795
1874
  };
1796
- let SanityClient = _SanityClient;
1797
1875
  _clientConfig2 = new WeakMap();
1798
1876
  _httpRequest2 = new WeakMap();
1877
+ let SanityClient = _SanityClient;
1799
1878
  const httpRequest = defineHttpRequest(envMiddleware, {});
1800
1879
  const requester = httpRequest.defaultRequester;
1801
1880
  const createClient = config => new SanityClient(defineHttpRequest(envMiddleware, {