@sanity/client 6.1.2 → 6.1.3-perspective.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/README.md +159 -0
- package/dist/index.browser.cjs +83 -17
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +83 -17
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +84 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +84 -18
- package/dist/index.js.map +1 -1
- package/package.json +18 -18
- package/src/data/dataMethods.ts +1 -1
- package/src/types.ts +9 -1
- package/umd/sanityClient.js +151 -85
- package/umd/sanityClient.min.js +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -283,7 +283,8 @@ export declare interface ClientConfig {
|
|
|
283
283
|
/** @defaultValue true */
|
|
284
284
|
useCdn?: boolean
|
|
285
285
|
token?: string
|
|
286
|
-
|
|
286
|
+
/** @defaultValue 'raw' */
|
|
287
|
+
perspective?: ClientPerspective
|
|
287
288
|
apiHost?: string
|
|
288
289
|
apiVersion?: string
|
|
289
290
|
proxy?: string
|
|
@@ -326,6 +327,9 @@ export declare class ClientError extends Error {
|
|
|
326
327
|
constructor(res: Any)
|
|
327
328
|
}
|
|
328
329
|
|
|
330
|
+
/** @public */
|
|
331
|
+
export declare type ClientPerspective = 'previewDrafts' | 'published' | 'raw'
|
|
332
|
+
|
|
329
333
|
/** @public */
|
|
330
334
|
export declare interface ContentSourceMap {
|
|
331
335
|
mappings: ContentSourceMapMappings
|
|
@@ -2059,6 +2063,10 @@ export declare type SanityDocument<T extends Record<string, Any> = Record<string
|
|
|
2059
2063
|
_type: string
|
|
2060
2064
|
_createdAt: string
|
|
2061
2065
|
_updatedAt: string
|
|
2066
|
+
/**
|
|
2067
|
+
* Present when `perspective` is set to `previewDrafts`
|
|
2068
|
+
*/
|
|
2069
|
+
_originalId?: string
|
|
2062
2070
|
}
|
|
2063
2071
|
|
|
2064
2072
|
/** @public */
|
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.1.
|
|
7
|
+
var version = "6.1.3-perspective.1";
|
|
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;
|
|
@@ -845,7 +888,7 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
845
888
|
...options.query
|
|
846
889
|
};
|
|
847
890
|
}
|
|
848
|
-
if (typeof config.perspective === "string" && config.perspective !== "
|
|
891
|
+
if (typeof config.perspective === "string" && config.perspective !== "raw") {
|
|
849
892
|
options.query = {
|
|
850
893
|
perspective: config.perspective,
|
|
851
894
|
...options.query
|
|
@@ -1496,6 +1539,17 @@ class UsersClient {
|
|
|
1496
1539
|
}
|
|
1497
1540
|
_client2 = new WeakMap();
|
|
1498
1541
|
_httpRequest2$1 = new WeakMap();
|
|
1542
|
+
var __defProp = Object.defineProperty;
|
|
1543
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
1544
|
+
enumerable: true,
|
|
1545
|
+
configurable: true,
|
|
1546
|
+
writable: true,
|
|
1547
|
+
value
|
|
1548
|
+
}) : obj[key] = value;
|
|
1549
|
+
var __publicField = (obj, key, value) => {
|
|
1550
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1551
|
+
return value;
|
|
1552
|
+
};
|
|
1499
1553
|
var __accessCheck = (obj, member, msg) => {
|
|
1500
1554
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
1501
1555
|
};
|
|
@@ -1513,9 +1567,13 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1513
1567
|
return value;
|
|
1514
1568
|
};
|
|
1515
1569
|
var _clientConfig, _httpRequest, _clientConfig2, _httpRequest2;
|
|
1516
|
-
const _ObservableSanityClient = class {
|
|
1570
|
+
const _ObservableSanityClient = class _ObservableSanityClient {
|
|
1517
1571
|
constructor(httpRequest) {
|
|
1518
1572
|
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
|
|
1573
|
+
__publicField(this, "assets");
|
|
1574
|
+
__publicField(this, "datasets");
|
|
1575
|
+
__publicField(this, "projects");
|
|
1576
|
+
__publicField(this, "users");
|
|
1519
1577
|
/**
|
|
1520
1578
|
* Private properties
|
|
1521
1579
|
*/
|
|
@@ -1524,7 +1582,7 @@ const _ObservableSanityClient = class {
|
|
|
1524
1582
|
/**
|
|
1525
1583
|
* Instance properties
|
|
1526
1584
|
*/
|
|
1527
|
-
this
|
|
1585
|
+
__publicField(this, "listen", _listen);
|
|
1528
1586
|
this.config(config);
|
|
1529
1587
|
__privateSet(this, _httpRequest, httpRequest);
|
|
1530
1588
|
this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest));
|
|
@@ -1646,12 +1704,20 @@ const _ObservableSanityClient = class {
|
|
|
1646
1704
|
return _getDataUrl(this, operation, path);
|
|
1647
1705
|
}
|
|
1648
1706
|
};
|
|
1649
|
-
let ObservableSanityClient = _ObservableSanityClient;
|
|
1650
1707
|
_clientConfig = new WeakMap();
|
|
1651
1708
|
_httpRequest = new WeakMap();
|
|
1652
|
-
|
|
1709
|
+
let ObservableSanityClient = _ObservableSanityClient;
|
|
1710
|
+
const _SanityClient = class _SanityClient {
|
|
1653
1711
|
constructor(httpRequest) {
|
|
1654
1712
|
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
|
|
1713
|
+
__publicField(this, "assets");
|
|
1714
|
+
__publicField(this, "datasets");
|
|
1715
|
+
__publicField(this, "projects");
|
|
1716
|
+
__publicField(this, "users");
|
|
1717
|
+
/**
|
|
1718
|
+
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1719
|
+
*/
|
|
1720
|
+
__publicField(this, "observable");
|
|
1655
1721
|
/**
|
|
1656
1722
|
* Private properties
|
|
1657
1723
|
*/
|
|
@@ -1660,7 +1726,7 @@ const _SanityClient = class {
|
|
|
1660
1726
|
/**
|
|
1661
1727
|
* Instance properties
|
|
1662
1728
|
*/
|
|
1663
|
-
this
|
|
1729
|
+
__publicField(this, "listen", _listen);
|
|
1664
1730
|
this.config(config);
|
|
1665
1731
|
__privateSet(this, _httpRequest2, httpRequest);
|
|
1666
1732
|
this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2));
|
|
@@ -1800,9 +1866,9 @@ const _SanityClient = class {
|
|
|
1800
1866
|
return _getDataUrl(this, operation, path);
|
|
1801
1867
|
}
|
|
1802
1868
|
};
|
|
1803
|
-
let SanityClient = _SanityClient;
|
|
1804
1869
|
_clientConfig2 = new WeakMap();
|
|
1805
1870
|
_httpRequest2 = new WeakMap();
|
|
1871
|
+
let SanityClient = _SanityClient;
|
|
1806
1872
|
const httpRequest = defineHttpRequest(middleware, {});
|
|
1807
1873
|
const requester = httpRequest.defaultRequester;
|
|
1808
1874
|
const createClient = config => new SanityClient(defineHttpRequest(middleware, {
|