@sanity/client 5.4.0 → 5.4.1
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 +19 -12
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +19 -6
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +20 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/data/listen.ts +21 -6
- package/umd/sanityClient.js +1170 -1138
- package/umd/sanityClient.min.js +3 -3
package/dist/index.browser.js
CHANGED
|
@@ -3,7 +3,6 @@ export { adapter as unstable__adapter, environment as unstable__environment } fr
|
|
|
3
3
|
import { jsonRequest, jsonResponse, progress, observable } from 'get-it/middleware';
|
|
4
4
|
import { Observable, lastValueFrom } from 'rxjs';
|
|
5
5
|
import { map, filter } from 'rxjs/operators';
|
|
6
|
-
import polyfilledEventSource from '@sanity/eventsource';
|
|
7
6
|
var envMiddleware = [];
|
|
8
7
|
const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
|
|
9
8
|
class ClientError extends Error {
|
|
@@ -1062,7 +1061,6 @@ const pick = (obj, props) => props.reduce((selection, prop) => {
|
|
|
1062
1061
|
return selection;
|
|
1063
1062
|
}, {});
|
|
1064
1063
|
const MAX_URL_LENGTH = 16e3 - 1200;
|
|
1065
|
-
const EventSource = polyfilledEventSource;
|
|
1066
1064
|
const possibleOptions = ["includePreviousRevision", "includeResult", "visibility", "effectFormat", "tag"];
|
|
1067
1065
|
const defaultOptions = {
|
|
1068
1066
|
includeResult: true
|
|
@@ -1105,7 +1103,13 @@ function _listen(query, params) {
|
|
|
1105
1103
|
};
|
|
1106
1104
|
}
|
|
1107
1105
|
return new Observable(observer => {
|
|
1108
|
-
let es
|
|
1106
|
+
let es;
|
|
1107
|
+
getEventSource().then(eventSource => {
|
|
1108
|
+
es = eventSource;
|
|
1109
|
+
}).catch(reason => {
|
|
1110
|
+
observer.error(reason);
|
|
1111
|
+
stop();
|
|
1112
|
+
});
|
|
1109
1113
|
let reconnectTimer;
|
|
1110
1114
|
let stopped = false;
|
|
1111
1115
|
function onError() {
|
|
@@ -1116,7 +1120,7 @@ function _listen(query, params) {
|
|
|
1116
1120
|
if (stopped) {
|
|
1117
1121
|
return;
|
|
1118
1122
|
}
|
|
1119
|
-
if (es.readyState ===
|
|
1123
|
+
if (es.readyState === es.CLOSED) {
|
|
1120
1124
|
unsubscribe();
|
|
1121
1125
|
clearTimeout(reconnectTimer);
|
|
1122
1126
|
reconnectTimer = setTimeout(open, 100);
|
|
@@ -1135,6 +1139,7 @@ function _listen(query, params) {
|
|
|
1135
1139
|
observer.complete();
|
|
1136
1140
|
}
|
|
1137
1141
|
function unsubscribe() {
|
|
1142
|
+
if (!es) return;
|
|
1138
1143
|
es.removeEventListener("error", onError);
|
|
1139
1144
|
es.removeEventListener("channelError", onChannelError);
|
|
1140
1145
|
es.removeEventListener("disconnect", onDisconnect);
|
|
@@ -1148,7 +1153,10 @@ function _listen(query, params) {
|
|
|
1148
1153
|
});
|
|
1149
1154
|
}
|
|
1150
1155
|
}
|
|
1151
|
-
function getEventSource() {
|
|
1156
|
+
async function getEventSource() {
|
|
1157
|
+
const {
|
|
1158
|
+
default: EventSource
|
|
1159
|
+
} = await import('@sanity/eventsource');
|
|
1152
1160
|
const evs = new EventSource(uri, esOptions);
|
|
1153
1161
|
evs.addEventListener("error", onError);
|
|
1154
1162
|
evs.addEventListener("channelError", onChannelError);
|
|
@@ -1157,7 +1165,12 @@ function _listen(query, params) {
|
|
|
1157
1165
|
return evs;
|
|
1158
1166
|
}
|
|
1159
1167
|
function open() {
|
|
1160
|
-
|
|
1168
|
+
getEventSource().then(eventSource => {
|
|
1169
|
+
es = eventSource;
|
|
1170
|
+
}).catch(reason => {
|
|
1171
|
+
observer.error(reason);
|
|
1172
|
+
stop();
|
|
1173
|
+
});
|
|
1161
1174
|
}
|
|
1162
1175
|
function stop() {
|
|
1163
1176
|
stopped = true;
|