@sanity/client 5.0.0 → 5.1.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 +45 -0
- package/dist/index.browser.cjs +35 -2
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +35 -3
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +36 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +36 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- 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 +37 -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.1.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
|
};
|
|
@@ -1671,6 +1700,9 @@ const _SanityClient = class {
|
|
|
1671
1700
|
let SanityClient = _SanityClient;
|
|
1672
1701
|
_clientConfig2 = new WeakMap();
|
|
1673
1702
|
_httpRequest2 = new WeakMap();
|
|
1703
|
+
function migrationNotice() {
|
|
1704
|
+
throw new TypeError("The default export of @sanity/client has been deprecated. Use the named export `createClient` instead");
|
|
1705
|
+
}
|
|
1674
1706
|
const httpRequest = defineHttpRequest(middleware);
|
|
1675
1707
|
const requester = httpRequest.defaultRequester;
|
|
1676
1708
|
const createClient = config => new SanityClient(httpRequest, config);
|
|
@@ -1685,5 +1717,6 @@ exports.SanityClient = SanityClient;
|
|
|
1685
1717
|
exports.ServerError = ServerError;
|
|
1686
1718
|
exports.Transaction = Transaction;
|
|
1687
1719
|
exports.createClient = createClient;
|
|
1720
|
+
exports.default = migrationNotice;
|
|
1688
1721
|
exports.requester = requester;
|
|
1689
1722
|
//# sourceMappingURL=index.cjs.map
|