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