@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.js
CHANGED
|
@@ -3,9 +3,8 @@ import { getIt } from 'get-it';
|
|
|
3
3
|
export { adapter as unstable__adapter, environment as unstable__environment } from 'get-it';
|
|
4
4
|
import { Observable, lastValueFrom } from 'rxjs';
|
|
5
5
|
import { map, filter } from 'rxjs/operators';
|
|
6
|
-
import polyfilledEventSource from '@sanity/eventsource';
|
|
7
6
|
var name = "@sanity/client";
|
|
8
|
-
var version = "5.4.
|
|
7
|
+
var version = "5.4.1";
|
|
9
8
|
const middleware = [debug({
|
|
10
9
|
verbose: true,
|
|
11
10
|
namespace: "sanity:client"
|
|
@@ -1071,7 +1070,6 @@ const pick = (obj, props) => props.reduce((selection, prop) => {
|
|
|
1071
1070
|
return selection;
|
|
1072
1071
|
}, {});
|
|
1073
1072
|
const MAX_URL_LENGTH = 16e3 - 1200;
|
|
1074
|
-
const EventSource = polyfilledEventSource;
|
|
1075
1073
|
const possibleOptions = ["includePreviousRevision", "includeResult", "visibility", "effectFormat", "tag"];
|
|
1076
1074
|
const defaultOptions = {
|
|
1077
1075
|
includeResult: true
|
|
@@ -1114,7 +1112,13 @@ function _listen(query, params) {
|
|
|
1114
1112
|
};
|
|
1115
1113
|
}
|
|
1116
1114
|
return new Observable(observer => {
|
|
1117
|
-
let es
|
|
1115
|
+
let es;
|
|
1116
|
+
getEventSource().then(eventSource => {
|
|
1117
|
+
es = eventSource;
|
|
1118
|
+
}).catch(reason => {
|
|
1119
|
+
observer.error(reason);
|
|
1120
|
+
stop();
|
|
1121
|
+
});
|
|
1118
1122
|
let reconnectTimer;
|
|
1119
1123
|
let stopped = false;
|
|
1120
1124
|
function onError() {
|
|
@@ -1125,7 +1129,7 @@ function _listen(query, params) {
|
|
|
1125
1129
|
if (stopped) {
|
|
1126
1130
|
return;
|
|
1127
1131
|
}
|
|
1128
|
-
if (es.readyState ===
|
|
1132
|
+
if (es.readyState === es.CLOSED) {
|
|
1129
1133
|
unsubscribe();
|
|
1130
1134
|
clearTimeout(reconnectTimer);
|
|
1131
1135
|
reconnectTimer = setTimeout(open, 100);
|
|
@@ -1144,6 +1148,7 @@ function _listen(query, params) {
|
|
|
1144
1148
|
observer.complete();
|
|
1145
1149
|
}
|
|
1146
1150
|
function unsubscribe() {
|
|
1151
|
+
if (!es) return;
|
|
1147
1152
|
es.removeEventListener("error", onError);
|
|
1148
1153
|
es.removeEventListener("channelError", onChannelError);
|
|
1149
1154
|
es.removeEventListener("disconnect", onDisconnect);
|
|
@@ -1157,7 +1162,10 @@ function _listen(query, params) {
|
|
|
1157
1162
|
});
|
|
1158
1163
|
}
|
|
1159
1164
|
}
|
|
1160
|
-
function getEventSource() {
|
|
1165
|
+
async function getEventSource() {
|
|
1166
|
+
const {
|
|
1167
|
+
default: EventSource
|
|
1168
|
+
} = await import('@sanity/eventsource');
|
|
1161
1169
|
const evs = new EventSource(uri, esOptions);
|
|
1162
1170
|
evs.addEventListener("error", onError);
|
|
1163
1171
|
evs.addEventListener("channelError", onChannelError);
|
|
@@ -1166,7 +1174,12 @@ function _listen(query, params) {
|
|
|
1166
1174
|
return evs;
|
|
1167
1175
|
}
|
|
1168
1176
|
function open() {
|
|
1169
|
-
|
|
1177
|
+
getEventSource().then(eventSource => {
|
|
1178
|
+
es = eventSource;
|
|
1179
|
+
}).catch(reason => {
|
|
1180
|
+
observer.error(reason);
|
|
1181
|
+
stop();
|
|
1182
|
+
});
|
|
1170
1183
|
}
|
|
1171
1184
|
function stop() {
|
|
1172
1185
|
stopped = true;
|