@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.d.ts
CHANGED
|
@@ -503,6 +503,13 @@ export declare interface ListenOptions {
|
|
|
503
503
|
tag?: string
|
|
504
504
|
}
|
|
505
505
|
|
|
506
|
+
/**
|
|
507
|
+
* @public
|
|
508
|
+
* @deprecated Use the named export `createClient` instead of the `default` export
|
|
509
|
+
*/
|
|
510
|
+
declare function migrationNotice(): void
|
|
511
|
+
export default migrationNotice
|
|
512
|
+
|
|
506
513
|
/** @internal */
|
|
507
514
|
export declare interface MultipleMutationResult {
|
|
508
515
|
transactionId: string
|
|
@@ -1171,6 +1178,20 @@ export declare class ObservableSanityClient {
|
|
|
1171
1178
|
* @param options - Request options
|
|
1172
1179
|
*/
|
|
1173
1180
|
request<R = FIXME>(options: RawRequestOptions): Observable<R>
|
|
1181
|
+
/**
|
|
1182
|
+
* Get a Sanity API URL for the URI provided
|
|
1183
|
+
*
|
|
1184
|
+
* @param uri - URI/path to build URL for
|
|
1185
|
+
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
1186
|
+
*/
|
|
1187
|
+
getUrl(uri: string, canUseCdn?: boolean): string
|
|
1188
|
+
/**
|
|
1189
|
+
* Get a Sanity API URL for the data operation and path provided
|
|
1190
|
+
*
|
|
1191
|
+
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
1192
|
+
* @param path - Path to append after the operation
|
|
1193
|
+
*/
|
|
1194
|
+
getDataUrl(operation: string, path?: string): string
|
|
1174
1195
|
}
|
|
1175
1196
|
|
|
1176
1197
|
/** @public */
|
|
@@ -1409,6 +1430,7 @@ export declare interface RequestOptions {
|
|
|
1409
1430
|
method?: string
|
|
1410
1431
|
query?: FIXME
|
|
1411
1432
|
body?: FIXME
|
|
1433
|
+
signal?: AbortSignal
|
|
1412
1434
|
}
|
|
1413
1435
|
|
|
1414
1436
|
/** @public */
|
|
@@ -1888,6 +1910,20 @@ export declare class SanityClient {
|
|
|
1888
1910
|
* @param options - Request options
|
|
1889
1911
|
*/
|
|
1890
1912
|
dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<FIXME>
|
|
1913
|
+
/**
|
|
1914
|
+
* Get a Sanity API URL for the URI provided
|
|
1915
|
+
*
|
|
1916
|
+
* @param uri - URI/path to build URL for
|
|
1917
|
+
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
1918
|
+
*/
|
|
1919
|
+
getUrl(uri: string, canUseCdn?: boolean): string
|
|
1920
|
+
/**
|
|
1921
|
+
* Get a Sanity API URL for the data operation and path provided
|
|
1922
|
+
*
|
|
1923
|
+
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
1924
|
+
* @param path - Path to append after the operation
|
|
1925
|
+
*/
|
|
1926
|
+
getDataUrl(operation: string, path?: string): string
|
|
1891
1927
|
}
|
|
1892
1928
|
|
|
1893
1929
|
/** @internal */
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Observable, lastValueFrom } from 'rxjs';
|
|
|
4
4
|
import { map, filter } from 'rxjs/operators';
|
|
5
5
|
import polyfilledEventSource from '@sanity/eventsource';
|
|
6
6
|
var name = "@sanity/client";
|
|
7
|
-
var version = "5.
|
|
7
|
+
var version = "5.2.0";
|
|
8
8
|
const middleware = [debug({
|
|
9
9
|
verbose: true,
|
|
10
10
|
namespace: "sanity:client"
|
|
@@ -747,7 +747,8 @@ function _dataRequest(client, httpRequest, endpoint, body) {
|
|
|
747
747
|
headers,
|
|
748
748
|
token,
|
|
749
749
|
tag,
|
|
750
|
-
canUseCdn: isQuery
|
|
750
|
+
canUseCdn: isQuery,
|
|
751
|
+
signal: options.signal
|
|
751
752
|
};
|
|
752
753
|
return _requestObservable(client, httpRequest, reqOptions).pipe(filter(isResponse), map(getBody), map(res => {
|
|
753
754
|
if (!isMutation) {
|
|
@@ -794,9 +795,10 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
794
795
|
const reqOptions = getRequestOptions(config, Object.assign({}, options, {
|
|
795
796
|
url: _getUrl(client, uri, useCdn)
|
|
796
797
|
}));
|
|
797
|
-
|
|
798
|
+
const request = new Observable(subscriber =>
|
|
798
799
|
// 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
|
|
799
800
|
httpRequest(reqOptions, config.requester).subscribe(subscriber));
|
|
801
|
+
return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
|
|
800
802
|
}
|
|
801
803
|
function _request(client, httpRequest, options) {
|
|
802
804
|
const observable = _requestObservable(client, httpRequest, options).pipe(filter(event => event.type === "response"), map(event => event.body));
|
|
@@ -818,6 +820,33 @@ function _getUrl(client, uri) {
|
|
|
818
820
|
const base = canUseCdn ? cdnUrl : url;
|
|
819
821
|
return "".concat(base, "/").concat(uri.replace(/^\//, ""));
|
|
820
822
|
}
|
|
823
|
+
function _withAbortSignal(signal) {
|
|
824
|
+
return input => {
|
|
825
|
+
return new Observable(observer => {
|
|
826
|
+
const abort = () => observer.error(_createAbortError(signal));
|
|
827
|
+
if (signal && signal.aborted) {
|
|
828
|
+
abort();
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
const subscription = input.subscribe(observer);
|
|
832
|
+
signal.addEventListener("abort", abort);
|
|
833
|
+
return () => {
|
|
834
|
+
signal.removeEventListener("abort", abort);
|
|
835
|
+
subscription.unsubscribe();
|
|
836
|
+
};
|
|
837
|
+
});
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
const isDomExceptionSupported = Boolean(globalThis.DOMException);
|
|
841
|
+
function _createAbortError(signal) {
|
|
842
|
+
var _a, _b;
|
|
843
|
+
if (isDomExceptionSupported) {
|
|
844
|
+
return new DOMException((_a = signal == null ? void 0 : signal.reason) != null ? _a : "The operation was aborted.", "AbortError");
|
|
845
|
+
}
|
|
846
|
+
const error = new Error((_b = signal == null ? void 0 : signal.reason) != null ? _b : "The operation was aborted.");
|
|
847
|
+
error.name = "AbortError";
|
|
848
|
+
return error;
|
|
849
|
+
}
|
|
821
850
|
var __accessCheck$4 = (obj, member, msg) => {
|
|
822
851
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
823
852
|
};
|
|
@@ -1523,6 +1552,24 @@ const _ObservableSanityClient = class {
|
|
|
1523
1552
|
request(options) {
|
|
1524
1553
|
return _request(this, __privateGet(this, _httpRequest), options);
|
|
1525
1554
|
}
|
|
1555
|
+
/**
|
|
1556
|
+
* Get a Sanity API URL for the URI provided
|
|
1557
|
+
*
|
|
1558
|
+
* @param uri - URI/path to build URL for
|
|
1559
|
+
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
1560
|
+
*/
|
|
1561
|
+
getUrl(uri, canUseCdn) {
|
|
1562
|
+
return _getUrl(this, uri, canUseCdn);
|
|
1563
|
+
}
|
|
1564
|
+
/**
|
|
1565
|
+
* Get a Sanity API URL for the data operation and path provided
|
|
1566
|
+
*
|
|
1567
|
+
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
1568
|
+
* @param path - Path to append after the operation
|
|
1569
|
+
*/
|
|
1570
|
+
getDataUrl(operation, path) {
|
|
1571
|
+
return _getDataUrl(this, operation, path);
|
|
1572
|
+
}
|
|
1526
1573
|
};
|
|
1527
1574
|
let ObservableSanityClient = _ObservableSanityClient;
|
|
1528
1575
|
_clientConfig = new WeakMap();
|
|
@@ -1656,12 +1703,33 @@ const _SanityClient = class {
|
|
|
1656
1703
|
dataRequest(endpoint, body, options) {
|
|
1657
1704
|
return lastValueFrom(_dataRequest(this, __privateGet(this, _httpRequest2), endpoint, body, options));
|
|
1658
1705
|
}
|
|
1706
|
+
/**
|
|
1707
|
+
* Get a Sanity API URL for the URI provided
|
|
1708
|
+
*
|
|
1709
|
+
* @param uri - URI/path to build URL for
|
|
1710
|
+
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
1711
|
+
*/
|
|
1712
|
+
getUrl(uri, canUseCdn) {
|
|
1713
|
+
return _getUrl(this, uri, canUseCdn);
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1716
|
+
* Get a Sanity API URL for the data operation and path provided
|
|
1717
|
+
*
|
|
1718
|
+
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
1719
|
+
* @param path - Path to append after the operation
|
|
1720
|
+
*/
|
|
1721
|
+
getDataUrl(operation, path) {
|
|
1722
|
+
return _getDataUrl(this, operation, path);
|
|
1723
|
+
}
|
|
1659
1724
|
};
|
|
1660
1725
|
let SanityClient = _SanityClient;
|
|
1661
1726
|
_clientConfig2 = new WeakMap();
|
|
1662
1727
|
_httpRequest2 = new WeakMap();
|
|
1728
|
+
function migrationNotice() {
|
|
1729
|
+
throw new TypeError("The default export of @sanity/client has been deprecated. Use the named export `createClient` instead");
|
|
1730
|
+
}
|
|
1663
1731
|
const httpRequest = defineHttpRequest(middleware);
|
|
1664
1732
|
const requester = httpRequest.defaultRequester;
|
|
1665
1733
|
const createClient = config => new SanityClient(httpRequest, config);
|
|
1666
|
-
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, createClient, requester };
|
|
1734
|
+
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, createClient, migrationNotice as default, requester };
|
|
1667
1735
|
//# sourceMappingURL=index.js.map
|