@sanity/client 5.0.0 → 5.2.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/README.md +61 -72
- package/dist/index.browser.cjs +71 -2
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +71 -3
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +72 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +36 -0
- package/dist/index.js +72 -4
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/SanityClient.ts +40 -0
- package/src/data/dataMethods.ts +52 -2
- package/src/index.browser.ts +2 -0
- package/src/index.ts +2 -0
- package/src/migrationNotice.ts +9 -0
- package/src/types.ts +1 -0
- package/umd/sanityClient.js +73 -2
- package/umd/sanityClient.min.js +3 -3
package/dist/index.cjs
CHANGED
|
@@ -15,7 +15,7 @@ function _interopDefaultCompat(e) {
|
|
|
15
15
|
}
|
|
16
16
|
var polyfilledEventSource__default = /*#__PURE__*/_interopDefaultCompat(polyfilledEventSource);
|
|
17
17
|
var name = "@sanity/client";
|
|
18
|
-
var version = "5.
|
|
18
|
+
var version = "5.2.0";
|
|
19
19
|
const middleware = [middleware$1.debug({
|
|
20
20
|
verbose: true,
|
|
21
21
|
namespace: "sanity:client"
|
|
@@ -758,7 +758,8 @@ function _dataRequest(client, httpRequest, endpoint, body) {
|
|
|
758
758
|
headers,
|
|
759
759
|
token,
|
|
760
760
|
tag,
|
|
761
|
-
canUseCdn: isQuery
|
|
761
|
+
canUseCdn: isQuery,
|
|
762
|
+
signal: options.signal
|
|
762
763
|
};
|
|
763
764
|
return _requestObservable(client, httpRequest, reqOptions).pipe(operators.filter(isResponse), operators.map(getBody), operators.map(res => {
|
|
764
765
|
if (!isMutation) {
|
|
@@ -805,9 +806,10 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
805
806
|
const reqOptions = getRequestOptions(config, Object.assign({}, options, {
|
|
806
807
|
url: _getUrl(client, uri, useCdn)
|
|
807
808
|
}));
|
|
808
|
-
|
|
809
|
+
const request = new rxjs.Observable(subscriber =>
|
|
809
810
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- the typings thinks it's optional because it's not required to specify it when calling createClient, but it's always defined in practice since SanityClient provides a default
|
|
810
811
|
httpRequest(reqOptions, config.requester).subscribe(subscriber));
|
|
812
|
+
return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
|
|
811
813
|
}
|
|
812
814
|
function _request(client, httpRequest, options) {
|
|
813
815
|
const observable = _requestObservable(client, httpRequest, options).pipe(operators.filter(event => event.type === "response"), operators.map(event => event.body));
|
|
@@ -829,6 +831,33 @@ function _getUrl(client, uri) {
|
|
|
829
831
|
const base = canUseCdn ? cdnUrl : url;
|
|
830
832
|
return "".concat(base, "/").concat(uri.replace(/^\//, ""));
|
|
831
833
|
}
|
|
834
|
+
function _withAbortSignal(signal) {
|
|
835
|
+
return input => {
|
|
836
|
+
return new rxjs.Observable(observer => {
|
|
837
|
+
const abort = () => observer.error(_createAbortError(signal));
|
|
838
|
+
if (signal && signal.aborted) {
|
|
839
|
+
abort();
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
const subscription = input.subscribe(observer);
|
|
843
|
+
signal.addEventListener("abort", abort);
|
|
844
|
+
return () => {
|
|
845
|
+
signal.removeEventListener("abort", abort);
|
|
846
|
+
subscription.unsubscribe();
|
|
847
|
+
};
|
|
848
|
+
});
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
const isDomExceptionSupported = Boolean(globalThis.DOMException);
|
|
852
|
+
function _createAbortError(signal) {
|
|
853
|
+
var _a, _b;
|
|
854
|
+
if (isDomExceptionSupported) {
|
|
855
|
+
return new DOMException((_a = signal == null ? void 0 : signal.reason) != null ? _a : "The operation was aborted.", "AbortError");
|
|
856
|
+
}
|
|
857
|
+
const error = new Error((_b = signal == null ? void 0 : signal.reason) != null ? _b : "The operation was aborted.");
|
|
858
|
+
error.name = "AbortError";
|
|
859
|
+
return error;
|
|
860
|
+
}
|
|
832
861
|
var __accessCheck$4 = (obj, member, msg) => {
|
|
833
862
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
834
863
|
};
|
|
@@ -1534,6 +1563,24 @@ const _ObservableSanityClient = class {
|
|
|
1534
1563
|
request(options) {
|
|
1535
1564
|
return _request(this, __privateGet(this, _httpRequest), options);
|
|
1536
1565
|
}
|
|
1566
|
+
/**
|
|
1567
|
+
* Get a Sanity API URL for the URI provided
|
|
1568
|
+
*
|
|
1569
|
+
* @param uri - URI/path to build URL for
|
|
1570
|
+
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
1571
|
+
*/
|
|
1572
|
+
getUrl(uri, canUseCdn) {
|
|
1573
|
+
return _getUrl(this, uri, canUseCdn);
|
|
1574
|
+
}
|
|
1575
|
+
/**
|
|
1576
|
+
* Get a Sanity API URL for the data operation and path provided
|
|
1577
|
+
*
|
|
1578
|
+
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
1579
|
+
* @param path - Path to append after the operation
|
|
1580
|
+
*/
|
|
1581
|
+
getDataUrl(operation, path) {
|
|
1582
|
+
return _getDataUrl(this, operation, path);
|
|
1583
|
+
}
|
|
1537
1584
|
};
|
|
1538
1585
|
let ObservableSanityClient = _ObservableSanityClient;
|
|
1539
1586
|
_clientConfig = new WeakMap();
|
|
@@ -1667,10 +1714,31 @@ const _SanityClient = class {
|
|
|
1667
1714
|
dataRequest(endpoint, body, options) {
|
|
1668
1715
|
return rxjs.lastValueFrom(_dataRequest(this, __privateGet(this, _httpRequest2), endpoint, body, options));
|
|
1669
1716
|
}
|
|
1717
|
+
/**
|
|
1718
|
+
* Get a Sanity API URL for the URI provided
|
|
1719
|
+
*
|
|
1720
|
+
* @param uri - URI/path to build URL for
|
|
1721
|
+
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
1722
|
+
*/
|
|
1723
|
+
getUrl(uri, canUseCdn) {
|
|
1724
|
+
return _getUrl(this, uri, canUseCdn);
|
|
1725
|
+
}
|
|
1726
|
+
/**
|
|
1727
|
+
* Get a Sanity API URL for the data operation and path provided
|
|
1728
|
+
*
|
|
1729
|
+
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
1730
|
+
* @param path - Path to append after the operation
|
|
1731
|
+
*/
|
|
1732
|
+
getDataUrl(operation, path) {
|
|
1733
|
+
return _getDataUrl(this, operation, path);
|
|
1734
|
+
}
|
|
1670
1735
|
};
|
|
1671
1736
|
let SanityClient = _SanityClient;
|
|
1672
1737
|
_clientConfig2 = new WeakMap();
|
|
1673
1738
|
_httpRequest2 = new WeakMap();
|
|
1739
|
+
function migrationNotice() {
|
|
1740
|
+
throw new TypeError("The default export of @sanity/client has been deprecated. Use the named export `createClient` instead");
|
|
1741
|
+
}
|
|
1674
1742
|
const httpRequest = defineHttpRequest(middleware);
|
|
1675
1743
|
const requester = httpRequest.defaultRequester;
|
|
1676
1744
|
const createClient = config => new SanityClient(httpRequest, config);
|
|
@@ -1685,5 +1753,6 @@ exports.SanityClient = SanityClient;
|
|
|
1685
1753
|
exports.ServerError = ServerError;
|
|
1686
1754
|
exports.Transaction = Transaction;
|
|
1687
1755
|
exports.createClient = createClient;
|
|
1756
|
+
exports.default = migrationNotice;
|
|
1688
1757
|
exports.requester = requester;
|
|
1689
1758
|
//# sourceMappingURL=index.cjs.map
|