@sanity/client 5.4.0 → 5.4.1-lazy-event-source.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 +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.cjs
CHANGED
|
@@ -7,13 +7,6 @@ var getIt = require('get-it');
|
|
|
7
7
|
var middleware = require('get-it/middleware');
|
|
8
8
|
var rxjs = require('rxjs');
|
|
9
9
|
var operators = require('rxjs/operators');
|
|
10
|
-
var polyfilledEventSource = require('@sanity/eventsource');
|
|
11
|
-
function _interopDefaultCompat(e) {
|
|
12
|
-
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
13
|
-
default: e
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
var polyfilledEventSource__default = /*#__PURE__*/_interopDefaultCompat(polyfilledEventSource);
|
|
17
10
|
var envMiddleware = [];
|
|
18
11
|
const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
|
|
19
12
|
class ClientError extends Error {
|
|
@@ -1072,7 +1065,6 @@ const pick = (obj, props) => props.reduce((selection, prop) => {
|
|
|
1072
1065
|
return selection;
|
|
1073
1066
|
}, {});
|
|
1074
1067
|
const MAX_URL_LENGTH = 16e3 - 1200;
|
|
1075
|
-
const EventSource = polyfilledEventSource__default.default;
|
|
1076
1068
|
const possibleOptions = ["includePreviousRevision", "includeResult", "visibility", "effectFormat", "tag"];
|
|
1077
1069
|
const defaultOptions = {
|
|
1078
1070
|
includeResult: true
|
|
@@ -1115,7 +1107,13 @@ function _listen(query, params) {
|
|
|
1115
1107
|
};
|
|
1116
1108
|
}
|
|
1117
1109
|
return new rxjs.Observable(observer => {
|
|
1118
|
-
let es
|
|
1110
|
+
let es;
|
|
1111
|
+
getEventSource().then(eventSource => {
|
|
1112
|
+
es = eventSource;
|
|
1113
|
+
}).catch(reason => {
|
|
1114
|
+
observer.error(reason);
|
|
1115
|
+
stop();
|
|
1116
|
+
});
|
|
1119
1117
|
let reconnectTimer;
|
|
1120
1118
|
let stopped = false;
|
|
1121
1119
|
function onError() {
|
|
@@ -1126,7 +1124,7 @@ function _listen(query, params) {
|
|
|
1126
1124
|
if (stopped) {
|
|
1127
1125
|
return;
|
|
1128
1126
|
}
|
|
1129
|
-
if (es.readyState ===
|
|
1127
|
+
if (es.readyState === es.CLOSED) {
|
|
1130
1128
|
unsubscribe();
|
|
1131
1129
|
clearTimeout(reconnectTimer);
|
|
1132
1130
|
reconnectTimer = setTimeout(open, 100);
|
|
@@ -1145,6 +1143,7 @@ function _listen(query, params) {
|
|
|
1145
1143
|
observer.complete();
|
|
1146
1144
|
}
|
|
1147
1145
|
function unsubscribe() {
|
|
1146
|
+
if (!es) return;
|
|
1148
1147
|
es.removeEventListener("error", onError);
|
|
1149
1148
|
es.removeEventListener("channelError", onChannelError);
|
|
1150
1149
|
es.removeEventListener("disconnect", onDisconnect);
|
|
@@ -1158,7 +1157,10 @@ function _listen(query, params) {
|
|
|
1158
1157
|
});
|
|
1159
1158
|
}
|
|
1160
1159
|
}
|
|
1161
|
-
function getEventSource() {
|
|
1160
|
+
async function getEventSource() {
|
|
1161
|
+
const {
|
|
1162
|
+
default: EventSource
|
|
1163
|
+
} = await import('@sanity/eventsource');
|
|
1162
1164
|
const evs = new EventSource(uri, esOptions);
|
|
1163
1165
|
evs.addEventListener("error", onError);
|
|
1164
1166
|
evs.addEventListener("channelError", onChannelError);
|
|
@@ -1167,7 +1169,12 @@ function _listen(query, params) {
|
|
|
1167
1169
|
return evs;
|
|
1168
1170
|
}
|
|
1169
1171
|
function open() {
|
|
1170
|
-
|
|
1172
|
+
getEventSource().then(eventSource => {
|
|
1173
|
+
es = eventSource;
|
|
1174
|
+
}).catch(reason => {
|
|
1175
|
+
observer.error(reason);
|
|
1176
|
+
stop();
|
|
1177
|
+
});
|
|
1171
1178
|
}
|
|
1172
1179
|
function stop() {
|
|
1173
1180
|
stopped = true;
|