@sanity/client 6.1.3 → 6.2.0-fetch.1
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.browser.cjs +99 -19
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +99 -19
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +100 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +21 -2
- package/dist/index.js +100 -20
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/src/data/dataMethods.ts +7 -1
- package/src/http/requestOptions.ts +1 -0
- package/src/types.ts +21 -2
- package/umd/sanityClient.js +149 -70
- package/umd/sanityClient.min.js +3 -3
package/dist/index.browser.cjs
CHANGED
|
@@ -8,12 +8,26 @@ var middleware = require('get-it/middleware');
|
|
|
8
8
|
var rxjs = require('rxjs');
|
|
9
9
|
var operators = require('rxjs/operators');
|
|
10
10
|
var envMiddleware = [];
|
|
11
|
+
var __defProp$3 = Object.defineProperty;
|
|
12
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value
|
|
17
|
+
}) : obj[key] = value;
|
|
18
|
+
var __publicField$3 = (obj, key, value) => {
|
|
19
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
20
|
+
return value;
|
|
21
|
+
};
|
|
11
22
|
const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
|
|
12
23
|
class ClientError extends Error {
|
|
13
24
|
constructor(res) {
|
|
14
25
|
const props = extractErrorProps(res);
|
|
15
26
|
super(props.message);
|
|
16
|
-
this
|
|
27
|
+
__publicField$3(this, "response");
|
|
28
|
+
__publicField$3(this, "statusCode", 400);
|
|
29
|
+
__publicField$3(this, "responseBody");
|
|
30
|
+
__publicField$3(this, "details");
|
|
17
31
|
Object.assign(this, props);
|
|
18
32
|
}
|
|
19
33
|
}
|
|
@@ -21,7 +35,10 @@ class ServerError extends Error {
|
|
|
21
35
|
constructor(res) {
|
|
22
36
|
const props = extractErrorProps(res);
|
|
23
37
|
super(props.message);
|
|
24
|
-
this
|
|
38
|
+
__publicField$3(this, "response");
|
|
39
|
+
__publicField$3(this, "statusCode", 500);
|
|
40
|
+
__publicField$3(this, "responseBody");
|
|
41
|
+
__publicField$3(this, "details");
|
|
25
42
|
Object.assign(this, props);
|
|
26
43
|
}
|
|
27
44
|
}
|
|
@@ -143,7 +160,8 @@ function requestOptions(config) {
|
|
|
143
160
|
timeout: typeof timeout === "undefined" ? 5 * 60 * 1e3 : timeout,
|
|
144
161
|
proxy: overrides.proxy || config.proxy,
|
|
145
162
|
json: true,
|
|
146
|
-
withCredentials
|
|
163
|
+
withCredentials,
|
|
164
|
+
fetch: overrides.fetch || config.fetch
|
|
147
165
|
});
|
|
148
166
|
}
|
|
149
167
|
function getSelection(sel) {
|
|
@@ -242,6 +260,17 @@ const encodeQueryString = _ref2 => {
|
|
|
242
260
|
}
|
|
243
261
|
return "?".concat(searchParams);
|
|
244
262
|
};
|
|
263
|
+
var __defProp$2 = Object.defineProperty;
|
|
264
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, {
|
|
265
|
+
enumerable: true,
|
|
266
|
+
configurable: true,
|
|
267
|
+
writable: true,
|
|
268
|
+
value
|
|
269
|
+
}) : obj[key] = value;
|
|
270
|
+
var __publicField$2 = (obj, key, value) => {
|
|
271
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
272
|
+
return value;
|
|
273
|
+
};
|
|
245
274
|
var __accessCheck$6 = (obj, member, msg) => {
|
|
246
275
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
247
276
|
};
|
|
@@ -262,6 +291,8 @@ var _client$5, _client2$5;
|
|
|
262
291
|
class BasePatch {
|
|
263
292
|
constructor(selection) {
|
|
264
293
|
let operations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
294
|
+
__publicField$2(this, "selection");
|
|
295
|
+
__publicField$2(this, "operations");
|
|
265
296
|
this.selection = selection;
|
|
266
297
|
this.operations = operations;
|
|
267
298
|
}
|
|
@@ -415,7 +446,7 @@ class BasePatch {
|
|
|
415
446
|
return this._assign(op, props, false);
|
|
416
447
|
}
|
|
417
448
|
}
|
|
418
|
-
const _ObservablePatch = class extends BasePatch {
|
|
449
|
+
const _ObservablePatch = class _ObservablePatch extends BasePatch {
|
|
419
450
|
constructor(selection, operations, client) {
|
|
420
451
|
super(selection, operations);
|
|
421
452
|
__privateAdd$6(this, _client$5, void 0);
|
|
@@ -443,9 +474,9 @@ const _ObservablePatch = class extends BasePatch {
|
|
|
443
474
|
}, opts);
|
|
444
475
|
}
|
|
445
476
|
};
|
|
446
|
-
let ObservablePatch = _ObservablePatch;
|
|
447
477
|
_client$5 = new WeakMap();
|
|
448
|
-
|
|
478
|
+
let ObservablePatch = _ObservablePatch;
|
|
479
|
+
const _Patch = class _Patch extends BasePatch {
|
|
449
480
|
constructor(selection, operations, client) {
|
|
450
481
|
super(selection, operations);
|
|
451
482
|
__privateAdd$6(this, _client2$5, void 0);
|
|
@@ -473,8 +504,19 @@ const _Patch = class extends BasePatch {
|
|
|
473
504
|
}, opts);
|
|
474
505
|
}
|
|
475
506
|
};
|
|
476
|
-
let Patch = _Patch;
|
|
477
507
|
_client2$5 = new WeakMap();
|
|
508
|
+
let Patch = _Patch;
|
|
509
|
+
var __defProp$1 = Object.defineProperty;
|
|
510
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, {
|
|
511
|
+
enumerable: true,
|
|
512
|
+
configurable: true,
|
|
513
|
+
writable: true,
|
|
514
|
+
value
|
|
515
|
+
}) : obj[key] = value;
|
|
516
|
+
var __publicField$1 = (obj, key, value) => {
|
|
517
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
518
|
+
return value;
|
|
519
|
+
};
|
|
478
520
|
var __accessCheck$5 = (obj, member, msg) => {
|
|
479
521
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
480
522
|
};
|
|
@@ -499,6 +541,8 @@ class BaseTransaction {
|
|
|
499
541
|
constructor() {
|
|
500
542
|
let operations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
501
543
|
let transactionId = arguments.length > 1 ? arguments[1] : undefined;
|
|
544
|
+
__publicField$1(this, "operations");
|
|
545
|
+
__publicField$1(this, "trxId");
|
|
502
546
|
this.operations = operations;
|
|
503
547
|
this.trxId = transactionId;
|
|
504
548
|
}
|
|
@@ -587,7 +631,7 @@ class BaseTransaction {
|
|
|
587
631
|
return this;
|
|
588
632
|
}
|
|
589
633
|
}
|
|
590
|
-
const _Transaction = class extends BaseTransaction {
|
|
634
|
+
const _Transaction = class _Transaction extends BaseTransaction {
|
|
591
635
|
constructor(operations, client, transactionId) {
|
|
592
636
|
super(operations, transactionId);
|
|
593
637
|
__privateAdd$5(this, _client$4, void 0);
|
|
@@ -632,9 +676,9 @@ const _Transaction = class extends BaseTransaction {
|
|
|
632
676
|
});
|
|
633
677
|
}
|
|
634
678
|
};
|
|
635
|
-
let Transaction = _Transaction;
|
|
636
679
|
_client$4 = new WeakMap();
|
|
637
|
-
|
|
680
|
+
let Transaction = _Transaction;
|
|
681
|
+
const _ObservableTransaction = class _ObservableTransaction extends BaseTransaction {
|
|
638
682
|
constructor(operations, client, transactionId) {
|
|
639
683
|
super(operations, transactionId);
|
|
640
684
|
__privateAdd$5(this, _client2$4, void 0);
|
|
@@ -679,8 +723,8 @@ const _ObservableTransaction = class extends BaseTransaction {
|
|
|
679
723
|
});
|
|
680
724
|
}
|
|
681
725
|
};
|
|
682
|
-
let ObservableTransaction = _ObservableTransaction;
|
|
683
726
|
_client2$4 = new WeakMap();
|
|
727
|
+
let ObservableTransaction = _ObservableTransaction;
|
|
684
728
|
const excludeFalsey = (param, defValue) => {
|
|
685
729
|
const value = typeof param === "undefined" ? defValue : param;
|
|
686
730
|
return param === false ? void 0 : value;
|
|
@@ -706,10 +750,22 @@ const getQuerySizeLimit = 11264;
|
|
|
706
750
|
function _fetch(client, httpRequest, query, params) {
|
|
707
751
|
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
708
752
|
const mapResponse = options.filterResponse === false ? res => res : res => res.result;
|
|
753
|
+
const {
|
|
754
|
+
cache,
|
|
755
|
+
next,
|
|
756
|
+
...opts
|
|
757
|
+
} = options;
|
|
758
|
+
const reqOpts = typeof cache !== "undefined" || typeof next !== "undefined" ? {
|
|
759
|
+
...opts,
|
|
760
|
+
fetch: {
|
|
761
|
+
cache,
|
|
762
|
+
next
|
|
763
|
+
}
|
|
764
|
+
} : opts;
|
|
709
765
|
return _dataRequest(client, httpRequest, "query", {
|
|
710
766
|
query,
|
|
711
767
|
params
|
|
712
|
-
},
|
|
768
|
+
}, reqOpts).pipe(operators.map(mapResponse));
|
|
713
769
|
}
|
|
714
770
|
function _getDocument(client, httpRequest, id) {
|
|
715
771
|
let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
@@ -791,7 +847,8 @@ function _dataRequest(client, httpRequest, endpoint, body) {
|
|
|
791
847
|
token,
|
|
792
848
|
tag,
|
|
793
849
|
canUseCdn: isQuery,
|
|
794
|
-
signal: options.signal
|
|
850
|
+
signal: options.signal,
|
|
851
|
+
fetch: options.fetch
|
|
795
852
|
};
|
|
796
853
|
return _requestObservable(client, httpRequest, reqOptions).pipe(operators.filter(isResponse), operators.map(getBody), operators.map(res => {
|
|
797
854
|
if (!isMutation) {
|
|
@@ -1493,6 +1550,17 @@ class UsersClient {
|
|
|
1493
1550
|
}
|
|
1494
1551
|
_client2 = new WeakMap();
|
|
1495
1552
|
_httpRequest2$1 = new WeakMap();
|
|
1553
|
+
var __defProp = Object.defineProperty;
|
|
1554
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
1555
|
+
enumerable: true,
|
|
1556
|
+
configurable: true,
|
|
1557
|
+
writable: true,
|
|
1558
|
+
value
|
|
1559
|
+
}) : obj[key] = value;
|
|
1560
|
+
var __publicField = (obj, key, value) => {
|
|
1561
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1562
|
+
return value;
|
|
1563
|
+
};
|
|
1496
1564
|
var __accessCheck = (obj, member, msg) => {
|
|
1497
1565
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
1498
1566
|
};
|
|
@@ -1510,9 +1578,13 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1510
1578
|
return value;
|
|
1511
1579
|
};
|
|
1512
1580
|
var _clientConfig, _httpRequest, _clientConfig2, _httpRequest2;
|
|
1513
|
-
const _ObservableSanityClient = class {
|
|
1581
|
+
const _ObservableSanityClient = class _ObservableSanityClient {
|
|
1514
1582
|
constructor(httpRequest) {
|
|
1515
1583
|
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
|
|
1584
|
+
__publicField(this, "assets");
|
|
1585
|
+
__publicField(this, "datasets");
|
|
1586
|
+
__publicField(this, "projects");
|
|
1587
|
+
__publicField(this, "users");
|
|
1516
1588
|
/**
|
|
1517
1589
|
* Private properties
|
|
1518
1590
|
*/
|
|
@@ -1521,7 +1593,7 @@ const _ObservableSanityClient = class {
|
|
|
1521
1593
|
/**
|
|
1522
1594
|
* Instance properties
|
|
1523
1595
|
*/
|
|
1524
|
-
this
|
|
1596
|
+
__publicField(this, "listen", _listen);
|
|
1525
1597
|
this.config(config);
|
|
1526
1598
|
__privateSet(this, _httpRequest, httpRequest);
|
|
1527
1599
|
this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest));
|
|
@@ -1643,12 +1715,20 @@ const _ObservableSanityClient = class {
|
|
|
1643
1715
|
return _getDataUrl(this, operation, path);
|
|
1644
1716
|
}
|
|
1645
1717
|
};
|
|
1646
|
-
let ObservableSanityClient = _ObservableSanityClient;
|
|
1647
1718
|
_clientConfig = new WeakMap();
|
|
1648
1719
|
_httpRequest = new WeakMap();
|
|
1649
|
-
|
|
1720
|
+
let ObservableSanityClient = _ObservableSanityClient;
|
|
1721
|
+
const _SanityClient = class _SanityClient {
|
|
1650
1722
|
constructor(httpRequest) {
|
|
1651
1723
|
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
|
|
1724
|
+
__publicField(this, "assets");
|
|
1725
|
+
__publicField(this, "datasets");
|
|
1726
|
+
__publicField(this, "projects");
|
|
1727
|
+
__publicField(this, "users");
|
|
1728
|
+
/**
|
|
1729
|
+
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1730
|
+
*/
|
|
1731
|
+
__publicField(this, "observable");
|
|
1652
1732
|
/**
|
|
1653
1733
|
* Private properties
|
|
1654
1734
|
*/
|
|
@@ -1657,7 +1737,7 @@ const _SanityClient = class {
|
|
|
1657
1737
|
/**
|
|
1658
1738
|
* Instance properties
|
|
1659
1739
|
*/
|
|
1660
|
-
this
|
|
1740
|
+
__publicField(this, "listen", _listen);
|
|
1661
1741
|
this.config(config);
|
|
1662
1742
|
__privateSet(this, _httpRequest2, httpRequest);
|
|
1663
1743
|
this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2));
|
|
@@ -1797,9 +1877,9 @@ const _SanityClient = class {
|
|
|
1797
1877
|
return _getDataUrl(this, operation, path);
|
|
1798
1878
|
}
|
|
1799
1879
|
};
|
|
1800
|
-
let SanityClient = _SanityClient;
|
|
1801
1880
|
_clientConfig2 = new WeakMap();
|
|
1802
1881
|
_httpRequest2 = new WeakMap();
|
|
1882
|
+
let SanityClient = _SanityClient;
|
|
1803
1883
|
const httpRequest = defineHttpRequest(envMiddleware, {});
|
|
1804
1884
|
const requester = httpRequest.defaultRequester;
|
|
1805
1885
|
const createClient = config => new SanityClient(defineHttpRequest(envMiddleware, {
|