@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.cjs
CHANGED
|
@@ -1044,6 +1044,28 @@ function _listen(query, params, opts = {}) {
|
|
|
1044
1044
|
)
|
|
1045
1045
|
);
|
|
1046
1046
|
}
|
|
1047
|
+
function shareReplayLatest(configOrPredicate, config) {
|
|
1048
|
+
return _shareReplayLatest(
|
|
1049
|
+
typeof configOrPredicate == "function" ? { predicate: configOrPredicate, ...config } : configOrPredicate
|
|
1050
|
+
);
|
|
1051
|
+
}
|
|
1052
|
+
function _shareReplayLatest(config) {
|
|
1053
|
+
return (source) => {
|
|
1054
|
+
let latest, emitted = !1;
|
|
1055
|
+
const { predicate, ...shareConfig } = config, wrapped = source.pipe(
|
|
1056
|
+
rxjs.tap((value) => {
|
|
1057
|
+
config.predicate(value) && (emitted = !0, latest = value);
|
|
1058
|
+
}),
|
|
1059
|
+
rxjs.finalize(() => {
|
|
1060
|
+
emitted = !1, latest = void 0;
|
|
1061
|
+
}),
|
|
1062
|
+
rxjs.share(shareConfig)
|
|
1063
|
+
), emitLatest = new rxjs.Observable((subscriber) => {
|
|
1064
|
+
emitted && subscriber.next(latest), subscriber.complete();
|
|
1065
|
+
});
|
|
1066
|
+
return rxjs.merge(wrapped, emitLatest);
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1047
1069
|
const requiredApiVersion = "2021-03-25";
|
|
1048
1070
|
class LiveClient {
|
|
1049
1071
|
#client;
|
|
@@ -1078,6 +1100,9 @@ class LiveClient {
|
|
|
1078
1100
|
includeDrafts && token && (esOptions.headers = {
|
|
1079
1101
|
Authorization: `Bearer ${token}`
|
|
1080
1102
|
}), includeDrafts && withCredentials && (esOptions.withCredentials = !0);
|
|
1103
|
+
const key = `${url.href}::${JSON.stringify(esOptions)}`, existing = eventsCache.get(key);
|
|
1104
|
+
if (existing)
|
|
1105
|
+
return existing;
|
|
1081
1106
|
const events = connectEventSource(() => (
|
|
1082
1107
|
// use polyfill if there is no global EventSource or if we need to set headers
|
|
1083
1108
|
(typeof EventSource > "u" || esOptions.headers ? eventSourcePolyfill : rxjs.of(EventSource)).pipe(operators.map((EventSource2) => new EventSource2(url.href, esOptions)))
|
|
@@ -1105,8 +1130,13 @@ class LiveClient {
|
|
|
1105
1130
|
rxjs.catchError(() => {
|
|
1106
1131
|
throw new CorsOriginError({ projectId: projectId2 });
|
|
1107
1132
|
})
|
|
1133
|
+
), observable = rxjs.concat(checkCors, events).pipe(
|
|
1134
|
+
shareReplayLatest({
|
|
1135
|
+
predicate: (event) => event.type === "welcome"
|
|
1136
|
+
}),
|
|
1137
|
+
operators.finalize(() => eventsCache.delete(key))
|
|
1108
1138
|
);
|
|
1109
|
-
return
|
|
1139
|
+
return eventsCache.set(key, observable), observable;
|
|
1110
1140
|
}
|
|
1111
1141
|
}
|
|
1112
1142
|
function fetchObservable(url, init) {
|
|
@@ -1122,6 +1152,7 @@ function fetchObservable(url, init) {
|
|
|
1122
1152
|
), () => controller.abort();
|
|
1123
1153
|
});
|
|
1124
1154
|
}
|
|
1155
|
+
const eventsCache = /* @__PURE__ */ new Map();
|
|
1125
1156
|
class ObservableDatasetsClient {
|
|
1126
1157
|
#client;
|
|
1127
1158
|
#httpRequest;
|