@sanity/client 6.27.2 → 6.27.3-canary.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 +32 -1
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +36 -5
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +33 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +37 -6
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/data/live.ts +19 -2
- package/src/types.ts +0 -1
- package/src/util/shareReplayLatest.ts +71 -0
- package/umd/sanityClient.js +103 -3
- package/umd/sanityClient.min.js +2 -2
package/dist/index.browser.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getIt } from "get-it";
|
|
2
2
|
import { adapter, environment } from "get-it";
|
|
3
3
|
import { retry, jsonRequest, jsonResponse, progress, observable } from "get-it/middleware";
|
|
4
|
-
import { Observable, defer, isObservable, of, mergeMap, from, lastValueFrom, shareReplay, catchError, concat, timer, throwError, EMPTY } from "rxjs";
|
|
4
|
+
import { Observable, defer, isObservable, of, mergeMap, from, lastValueFrom, shareReplay, catchError, concat, timer, throwError, tap, finalize, share, merge, EMPTY } from "rxjs";
|
|
5
5
|
import { stegaClean } from "./_chunks-es/stegaClean.js";
|
|
6
|
-
import { combineLatestWith, map, filter } from "rxjs/operators";
|
|
6
|
+
import { combineLatestWith, map, filter, finalize as finalize$1 } from "rxjs/operators";
|
|
7
7
|
class ClientError extends Error {
|
|
8
8
|
response;
|
|
9
9
|
statusCode = 400;
|
|
@@ -507,9 +507,9 @@ class BasePatch {
|
|
|
507
507
|
reset() {
|
|
508
508
|
return this.operations = {}, this;
|
|
509
509
|
}
|
|
510
|
-
_assign(op, props,
|
|
510
|
+
_assign(op, props, merge2 = !0) {
|
|
511
511
|
return validateObject(op, props), this.operations = Object.assign({}, this.operations, {
|
|
512
|
-
[op]: Object.assign({},
|
|
512
|
+
[op]: Object.assign({}, merge2 && this.operations[op] || {}, props)
|
|
513
513
|
}), this;
|
|
514
514
|
}
|
|
515
515
|
_set(op, props) {
|
|
@@ -1026,6 +1026,28 @@ function _listen(query, params, opts = {}) {
|
|
|
1026
1026
|
)
|
|
1027
1027
|
);
|
|
1028
1028
|
}
|
|
1029
|
+
function shareReplayLatest(configOrPredicate, config) {
|
|
1030
|
+
return _shareReplayLatest(
|
|
1031
|
+
typeof configOrPredicate == "function" ? { predicate: configOrPredicate, ...config } : configOrPredicate
|
|
1032
|
+
);
|
|
1033
|
+
}
|
|
1034
|
+
function _shareReplayLatest(config) {
|
|
1035
|
+
return (source) => {
|
|
1036
|
+
let latest, emitted = !1;
|
|
1037
|
+
const { predicate, ...shareConfig } = config, wrapped = source.pipe(
|
|
1038
|
+
tap((value) => {
|
|
1039
|
+
config.predicate(value) && (emitted = !0, latest = value);
|
|
1040
|
+
}),
|
|
1041
|
+
finalize(() => {
|
|
1042
|
+
emitted = !1, latest = void 0;
|
|
1043
|
+
}),
|
|
1044
|
+
share(shareConfig)
|
|
1045
|
+
), emitLatest = new Observable((subscriber) => {
|
|
1046
|
+
emitted && subscriber.next(latest), subscriber.complete();
|
|
1047
|
+
});
|
|
1048
|
+
return merge(wrapped, emitLatest);
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1029
1051
|
const requiredApiVersion = "2021-03-25";
|
|
1030
1052
|
class LiveClient {
|
|
1031
1053
|
#client;
|
|
@@ -1060,6 +1082,9 @@ class LiveClient {
|
|
|
1060
1082
|
includeDrafts && token && (esOptions.headers = {
|
|
1061
1083
|
Authorization: `Bearer ${token}`
|
|
1062
1084
|
}), includeDrafts && withCredentials && (esOptions.withCredentials = !0);
|
|
1085
|
+
const key = `${url.href}::${JSON.stringify(esOptions)}`, existing = eventsCache.get(key);
|
|
1086
|
+
if (existing)
|
|
1087
|
+
return existing;
|
|
1063
1088
|
const events = connectEventSource(() => (
|
|
1064
1089
|
// use polyfill if there is no global EventSource or if we need to set headers
|
|
1065
1090
|
(typeof EventSource > "u" || esOptions.headers ? eventSourcePolyfill : of(EventSource)).pipe(map((EventSource2) => new EventSource2(url.href, esOptions)))
|
|
@@ -1087,8 +1112,13 @@ class LiveClient {
|
|
|
1087
1112
|
catchError(() => {
|
|
1088
1113
|
throw new CorsOriginError({ projectId: projectId2 });
|
|
1089
1114
|
})
|
|
1115
|
+
), observable2 = concat(checkCors, events).pipe(
|
|
1116
|
+
shareReplayLatest({
|
|
1117
|
+
predicate: (event) => event.type === "welcome"
|
|
1118
|
+
}),
|
|
1119
|
+
finalize$1(() => eventsCache.delete(key))
|
|
1090
1120
|
);
|
|
1091
|
-
return
|
|
1121
|
+
return eventsCache.set(key, observable2), observable2;
|
|
1092
1122
|
}
|
|
1093
1123
|
}
|
|
1094
1124
|
function fetchObservable(url, init) {
|
|
@@ -1104,6 +1134,7 @@ function fetchObservable(url, init) {
|
|
|
1104
1134
|
), () => controller.abort();
|
|
1105
1135
|
});
|
|
1106
1136
|
}
|
|
1137
|
+
const eventsCache = /* @__PURE__ */ new Map();
|
|
1107
1138
|
class ObservableDatasetsClient {
|
|
1108
1139
|
#client;
|
|
1109
1140
|
#httpRequest;
|