@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.
- package/dist/index.browser.cjs +97 -18
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +97 -18
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +98 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +98 -19
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/src/data/dataMethods.ts +7 -1
- package/src/types.ts +8 -2
- package/umd/sanityClient.js +147 -69
- package/umd/sanityClient.min.js +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -496,7 +496,7 @@ export declare interface ErrorProps {
|
|
|
496
496
|
}
|
|
497
497
|
|
|
498
498
|
/** @public */
|
|
499
|
-
export declare type FilteredResponseQueryOptions =
|
|
499
|
+
export declare type FilteredResponseQueryOptions = ResponseQueryOptions & {
|
|
500
500
|
filterResponse?: true
|
|
501
501
|
}
|
|
502
502
|
|
|
@@ -1568,6 +1568,12 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
1568
1568
|
headers: Record<string, string>
|
|
1569
1569
|
}
|
|
1570
1570
|
|
|
1571
|
+
/** @public */
|
|
1572
|
+
export declare type ResponseQueryOptions<T = 'next'> = RequestOptions & {
|
|
1573
|
+
cache?: RequestInit['cache']
|
|
1574
|
+
next?: T extends keyof RequestInit ? RequestInit[T] : never
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1571
1577
|
/** @internal */
|
|
1572
1578
|
export declare interface SanityAssetDocument extends SanityDocument {
|
|
1573
1579
|
url: string
|
|
@@ -2274,7 +2280,7 @@ export declare type TransactionMutationOptions =
|
|
|
2274
2280
|
| TransactionAllDocumentIdsMutationOptions
|
|
2275
2281
|
|
|
2276
2282
|
/** @public */
|
|
2277
|
-
export declare type UnfilteredResponseQueryOptions =
|
|
2283
|
+
export declare type UnfilteredResponseQueryOptions = ResponseQueryOptions & {
|
|
2278
2284
|
filterResponse: false
|
|
2279
2285
|
}
|
|
2280
2286
|
|
package/dist/index.js
CHANGED
|
@@ -4,19 +4,33 @@ export { adapter as unstable__adapter, environment as unstable__environment } fr
|
|
|
4
4
|
import { Observable, lastValueFrom } from 'rxjs';
|
|
5
5
|
import { map, filter } from 'rxjs/operators';
|
|
6
6
|
var name = "@sanity/client";
|
|
7
|
-
var version = "6.
|
|
7
|
+
var version = "6.2.0-fetch.0";
|
|
8
8
|
const middleware = [debug({
|
|
9
9
|
verbose: true,
|
|
10
10
|
namespace: "sanity:client"
|
|
11
11
|
}), headers({
|
|
12
12
|
"User-Agent": "".concat(name, " ").concat(version)
|
|
13
13
|
})];
|
|
14
|
+
var __defProp$3 = Object.defineProperty;
|
|
15
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value
|
|
20
|
+
}) : obj[key] = value;
|
|
21
|
+
var __publicField$3 = (obj, key, value) => {
|
|
22
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
14
25
|
const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
|
|
15
26
|
class ClientError extends Error {
|
|
16
27
|
constructor(res) {
|
|
17
28
|
const props = extractErrorProps(res);
|
|
18
29
|
super(props.message);
|
|
19
|
-
this
|
|
30
|
+
__publicField$3(this, "response");
|
|
31
|
+
__publicField$3(this, "statusCode", 400);
|
|
32
|
+
__publicField$3(this, "responseBody");
|
|
33
|
+
__publicField$3(this, "details");
|
|
20
34
|
Object.assign(this, props);
|
|
21
35
|
}
|
|
22
36
|
}
|
|
@@ -24,7 +38,10 @@ class ServerError extends Error {
|
|
|
24
38
|
constructor(res) {
|
|
25
39
|
const props = extractErrorProps(res);
|
|
26
40
|
super(props.message);
|
|
27
|
-
this
|
|
41
|
+
__publicField$3(this, "response");
|
|
42
|
+
__publicField$3(this, "statusCode", 500);
|
|
43
|
+
__publicField$3(this, "responseBody");
|
|
44
|
+
__publicField$3(this, "details");
|
|
28
45
|
Object.assign(this, props);
|
|
29
46
|
}
|
|
30
47
|
}
|
|
@@ -245,6 +262,17 @@ const encodeQueryString = _ref2 => {
|
|
|
245
262
|
}
|
|
246
263
|
return "?".concat(searchParams);
|
|
247
264
|
};
|
|
265
|
+
var __defProp$2 = Object.defineProperty;
|
|
266
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, {
|
|
267
|
+
enumerable: true,
|
|
268
|
+
configurable: true,
|
|
269
|
+
writable: true,
|
|
270
|
+
value
|
|
271
|
+
}) : obj[key] = value;
|
|
272
|
+
var __publicField$2 = (obj, key, value) => {
|
|
273
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
274
|
+
return value;
|
|
275
|
+
};
|
|
248
276
|
var __accessCheck$6 = (obj, member, msg) => {
|
|
249
277
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
250
278
|
};
|
|
@@ -265,6 +293,8 @@ var _client$5, _client2$5;
|
|
|
265
293
|
class BasePatch {
|
|
266
294
|
constructor(selection) {
|
|
267
295
|
let operations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
296
|
+
__publicField$2(this, "selection");
|
|
297
|
+
__publicField$2(this, "operations");
|
|
268
298
|
this.selection = selection;
|
|
269
299
|
this.operations = operations;
|
|
270
300
|
}
|
|
@@ -418,7 +448,7 @@ class BasePatch {
|
|
|
418
448
|
return this._assign(op, props, false);
|
|
419
449
|
}
|
|
420
450
|
}
|
|
421
|
-
const _ObservablePatch = class extends BasePatch {
|
|
451
|
+
const _ObservablePatch = class _ObservablePatch extends BasePatch {
|
|
422
452
|
constructor(selection, operations, client) {
|
|
423
453
|
super(selection, operations);
|
|
424
454
|
__privateAdd$6(this, _client$5, void 0);
|
|
@@ -446,9 +476,9 @@ const _ObservablePatch = class extends BasePatch {
|
|
|
446
476
|
}, opts);
|
|
447
477
|
}
|
|
448
478
|
};
|
|
449
|
-
let ObservablePatch = _ObservablePatch;
|
|
450
479
|
_client$5 = new WeakMap();
|
|
451
|
-
|
|
480
|
+
let ObservablePatch = _ObservablePatch;
|
|
481
|
+
const _Patch = class _Patch extends BasePatch {
|
|
452
482
|
constructor(selection, operations, client) {
|
|
453
483
|
super(selection, operations);
|
|
454
484
|
__privateAdd$6(this, _client2$5, void 0);
|
|
@@ -476,8 +506,19 @@ const _Patch = class extends BasePatch {
|
|
|
476
506
|
}, opts);
|
|
477
507
|
}
|
|
478
508
|
};
|
|
479
|
-
let Patch = _Patch;
|
|
480
509
|
_client2$5 = new WeakMap();
|
|
510
|
+
let Patch = _Patch;
|
|
511
|
+
var __defProp$1 = Object.defineProperty;
|
|
512
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, {
|
|
513
|
+
enumerable: true,
|
|
514
|
+
configurable: true,
|
|
515
|
+
writable: true,
|
|
516
|
+
value
|
|
517
|
+
}) : obj[key] = value;
|
|
518
|
+
var __publicField$1 = (obj, key, value) => {
|
|
519
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
520
|
+
return value;
|
|
521
|
+
};
|
|
481
522
|
var __accessCheck$5 = (obj, member, msg) => {
|
|
482
523
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
483
524
|
};
|
|
@@ -502,6 +543,8 @@ class BaseTransaction {
|
|
|
502
543
|
constructor() {
|
|
503
544
|
let operations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
504
545
|
let transactionId = arguments.length > 1 ? arguments[1] : undefined;
|
|
546
|
+
__publicField$1(this, "operations");
|
|
547
|
+
__publicField$1(this, "trxId");
|
|
505
548
|
this.operations = operations;
|
|
506
549
|
this.trxId = transactionId;
|
|
507
550
|
}
|
|
@@ -590,7 +633,7 @@ class BaseTransaction {
|
|
|
590
633
|
return this;
|
|
591
634
|
}
|
|
592
635
|
}
|
|
593
|
-
const _Transaction = class extends BaseTransaction {
|
|
636
|
+
const _Transaction = class _Transaction extends BaseTransaction {
|
|
594
637
|
constructor(operations, client, transactionId) {
|
|
595
638
|
super(operations, transactionId);
|
|
596
639
|
__privateAdd$5(this, _client$4, void 0);
|
|
@@ -635,9 +678,9 @@ const _Transaction = class extends BaseTransaction {
|
|
|
635
678
|
});
|
|
636
679
|
}
|
|
637
680
|
};
|
|
638
|
-
let Transaction = _Transaction;
|
|
639
681
|
_client$4 = new WeakMap();
|
|
640
|
-
|
|
682
|
+
let Transaction = _Transaction;
|
|
683
|
+
const _ObservableTransaction = class _ObservableTransaction extends BaseTransaction {
|
|
641
684
|
constructor(operations, client, transactionId) {
|
|
642
685
|
super(operations, transactionId);
|
|
643
686
|
__privateAdd$5(this, _client2$4, void 0);
|
|
@@ -682,8 +725,8 @@ const _ObservableTransaction = class extends BaseTransaction {
|
|
|
682
725
|
});
|
|
683
726
|
}
|
|
684
727
|
};
|
|
685
|
-
let ObservableTransaction = _ObservableTransaction;
|
|
686
728
|
_client2$4 = new WeakMap();
|
|
729
|
+
let ObservableTransaction = _ObservableTransaction;
|
|
687
730
|
const excludeFalsey = (param, defValue) => {
|
|
688
731
|
const value = typeof param === "undefined" ? defValue : param;
|
|
689
732
|
return param === false ? void 0 : value;
|
|
@@ -709,10 +752,22 @@ const getQuerySizeLimit = 11264;
|
|
|
709
752
|
function _fetch(client, httpRequest, query, params) {
|
|
710
753
|
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
711
754
|
const mapResponse = options.filterResponse === false ? res => res : res => res.result;
|
|
755
|
+
const {
|
|
756
|
+
cache,
|
|
757
|
+
next,
|
|
758
|
+
...opts
|
|
759
|
+
} = options;
|
|
760
|
+
const reqOpts = typeof cache !== "undefined" || typeof next !== "undefined" ? {
|
|
761
|
+
...opts,
|
|
762
|
+
fetch: {
|
|
763
|
+
cache,
|
|
764
|
+
next
|
|
765
|
+
}
|
|
766
|
+
} : opts;
|
|
712
767
|
return _dataRequest(client, httpRequest, "query", {
|
|
713
768
|
query,
|
|
714
769
|
params
|
|
715
|
-
},
|
|
770
|
+
}, reqOpts).pipe(map(mapResponse));
|
|
716
771
|
}
|
|
717
772
|
function _getDocument(client, httpRequest, id) {
|
|
718
773
|
let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
@@ -794,7 +849,8 @@ function _dataRequest(client, httpRequest, endpoint, body) {
|
|
|
794
849
|
token,
|
|
795
850
|
tag,
|
|
796
851
|
canUseCdn: isQuery,
|
|
797
|
-
signal: options.signal
|
|
852
|
+
signal: options.signal,
|
|
853
|
+
fetch: options.fetch
|
|
798
854
|
};
|
|
799
855
|
return _requestObservable(client, httpRequest, reqOptions).pipe(filter(isResponse), map(getBody), map(res => {
|
|
800
856
|
if (!isMutation) {
|
|
@@ -1496,6 +1552,17 @@ class UsersClient {
|
|
|
1496
1552
|
}
|
|
1497
1553
|
_client2 = new WeakMap();
|
|
1498
1554
|
_httpRequest2$1 = new WeakMap();
|
|
1555
|
+
var __defProp = Object.defineProperty;
|
|
1556
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
1557
|
+
enumerable: true,
|
|
1558
|
+
configurable: true,
|
|
1559
|
+
writable: true,
|
|
1560
|
+
value
|
|
1561
|
+
}) : obj[key] = value;
|
|
1562
|
+
var __publicField = (obj, key, value) => {
|
|
1563
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1564
|
+
return value;
|
|
1565
|
+
};
|
|
1499
1566
|
var __accessCheck = (obj, member, msg) => {
|
|
1500
1567
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
1501
1568
|
};
|
|
@@ -1513,9 +1580,13 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1513
1580
|
return value;
|
|
1514
1581
|
};
|
|
1515
1582
|
var _clientConfig, _httpRequest, _clientConfig2, _httpRequest2;
|
|
1516
|
-
const _ObservableSanityClient = class {
|
|
1583
|
+
const _ObservableSanityClient = class _ObservableSanityClient {
|
|
1517
1584
|
constructor(httpRequest) {
|
|
1518
1585
|
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
|
|
1586
|
+
__publicField(this, "assets");
|
|
1587
|
+
__publicField(this, "datasets");
|
|
1588
|
+
__publicField(this, "projects");
|
|
1589
|
+
__publicField(this, "users");
|
|
1519
1590
|
/**
|
|
1520
1591
|
* Private properties
|
|
1521
1592
|
*/
|
|
@@ -1524,7 +1595,7 @@ const _ObservableSanityClient = class {
|
|
|
1524
1595
|
/**
|
|
1525
1596
|
* Instance properties
|
|
1526
1597
|
*/
|
|
1527
|
-
this
|
|
1598
|
+
__publicField(this, "listen", _listen);
|
|
1528
1599
|
this.config(config);
|
|
1529
1600
|
__privateSet(this, _httpRequest, httpRequest);
|
|
1530
1601
|
this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest));
|
|
@@ -1646,12 +1717,20 @@ const _ObservableSanityClient = class {
|
|
|
1646
1717
|
return _getDataUrl(this, operation, path);
|
|
1647
1718
|
}
|
|
1648
1719
|
};
|
|
1649
|
-
let ObservableSanityClient = _ObservableSanityClient;
|
|
1650
1720
|
_clientConfig = new WeakMap();
|
|
1651
1721
|
_httpRequest = new WeakMap();
|
|
1652
|
-
|
|
1722
|
+
let ObservableSanityClient = _ObservableSanityClient;
|
|
1723
|
+
const _SanityClient = class _SanityClient {
|
|
1653
1724
|
constructor(httpRequest) {
|
|
1654
1725
|
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
|
|
1726
|
+
__publicField(this, "assets");
|
|
1727
|
+
__publicField(this, "datasets");
|
|
1728
|
+
__publicField(this, "projects");
|
|
1729
|
+
__publicField(this, "users");
|
|
1730
|
+
/**
|
|
1731
|
+
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1732
|
+
*/
|
|
1733
|
+
__publicField(this, "observable");
|
|
1655
1734
|
/**
|
|
1656
1735
|
* Private properties
|
|
1657
1736
|
*/
|
|
@@ -1660,7 +1739,7 @@ const _SanityClient = class {
|
|
|
1660
1739
|
/**
|
|
1661
1740
|
* Instance properties
|
|
1662
1741
|
*/
|
|
1663
|
-
this
|
|
1742
|
+
__publicField(this, "listen", _listen);
|
|
1664
1743
|
this.config(config);
|
|
1665
1744
|
__privateSet(this, _httpRequest2, httpRequest);
|
|
1666
1745
|
this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2));
|
|
@@ -1800,9 +1879,9 @@ const _SanityClient = class {
|
|
|
1800
1879
|
return _getDataUrl(this, operation, path);
|
|
1801
1880
|
}
|
|
1802
1881
|
};
|
|
1803
|
-
let SanityClient = _SanityClient;
|
|
1804
1882
|
_clientConfig2 = new WeakMap();
|
|
1805
1883
|
_httpRequest2 = new WeakMap();
|
|
1884
|
+
let SanityClient = _SanityClient;
|
|
1806
1885
|
const httpRequest = defineHttpRequest(middleware, {});
|
|
1807
1886
|
const requester = httpRequest.defaultRequester;
|
|
1808
1887
|
const createClient = config => new SanityClient(defineHttpRequest(middleware, {
|