@sanity/client 0.0.0-dev.2 → 0.0.0-dev.4
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 +65 -31
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +54 -25
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +66 -32
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +41 -12
- package/dist/index.js +55 -26
- package/dist/index.js.map +1 -1
- package/package.json +21 -20
- package/src/assets/AssetsClient.ts +11 -10
- package/src/data/dataMethods.ts +2 -6
- package/src/data/listen.ts +29 -14
- package/src/http/errors.ts +32 -1
- package/src/index.browser.ts +3 -0
- package/src/index.ts +3 -0
- package/src/types.ts +35 -6
- package/src/validators.ts +1 -1
- package/umd/sanityClient.js +1195 -1143
- package/umd/sanityClient.min.js +3 -3
package/umd/sanityClient.js
CHANGED
|
@@ -4,6 +4,21 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.SanityClient = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
+
function _mergeNamespaces(n, m) {
|
|
8
|
+
m.forEach(function (e) {
|
|
9
|
+
e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
|
|
10
|
+
if (k !== 'default' && !(k in n)) {
|
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return e[k]; }
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
return Object.freeze(n);
|
|
20
|
+
}
|
|
21
|
+
|
|
7
22
|
const isReactNative = typeof navigator === "undefined" ? false : navigator.product === "ReactNative";
|
|
8
23
|
const defaultOptions$1 = {
|
|
9
24
|
timeout: isReactNative ? 6e4 : 12e4
|
|
@@ -232,6 +247,7 @@
|
|
|
232
247
|
* https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState
|
|
233
248
|
*/
|
|
234
249
|
this.readyState = 0;
|
|
250
|
+
this.responseType = "";
|
|
235
251
|
/**
|
|
236
252
|
* Private implementation details
|
|
237
253
|
*/
|
|
@@ -266,12 +282,13 @@
|
|
|
266
282
|
const options = {
|
|
267
283
|
method: __privateGet$7(this, _method),
|
|
268
284
|
headers: __privateGet$7(this, _headers),
|
|
269
|
-
signal: null,
|
|
270
285
|
body
|
|
271
286
|
};
|
|
272
287
|
if (typeof AbortController === "function") {
|
|
273
288
|
__privateSet$7(this, _controller, new AbortController());
|
|
274
|
-
|
|
289
|
+
if (typeof EventTarget !== "undefined" && __privateGet$7(this, _controller).signal instanceof EventTarget) {
|
|
290
|
+
options.signal = __privateGet$7(this, _controller).signal;
|
|
291
|
+
}
|
|
275
292
|
}
|
|
276
293
|
if (typeof document !== "undefined") {
|
|
277
294
|
options.credentials = this.withCredentials ? "include" : "omit";
|
|
@@ -416,7 +433,7 @@
|
|
|
416
433
|
}
|
|
417
434
|
function reduceResponse() {
|
|
418
435
|
return {
|
|
419
|
-
body: xhr.response || xhr.responseText,
|
|
436
|
+
body: xhr.response || (xhr.responseType === "" || xhr.responseType === "text" ? xhr.responseText : ""),
|
|
420
437
|
url: options.url,
|
|
421
438
|
method: options.method,
|
|
422
439
|
headers: parseHeaders(xhr.getAllResponseHeaders()),
|
|
@@ -442,9 +459,10 @@
|
|
|
442
459
|
let httpRequest = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : httpRequester;
|
|
443
460
|
return createRequester(initMiddleware, httpRequest);
|
|
444
461
|
};
|
|
462
|
+
const environment = "browser";
|
|
445
463
|
|
|
446
464
|
var browserExports = {};
|
|
447
|
-
var browser$
|
|
465
|
+
var browser$2 = {
|
|
448
466
|
get exports(){ return browserExports; },
|
|
449
467
|
set exports(v){ browserExports = v; },
|
|
450
468
|
};
|
|
@@ -1164,7 +1182,7 @@
|
|
|
1164
1182
|
return '[UnexpectedJSONParseError]: ' + error.message;
|
|
1165
1183
|
}
|
|
1166
1184
|
};
|
|
1167
|
-
} (browser$
|
|
1185
|
+
} (browser$2, browserExports));
|
|
1168
1186
|
|
|
1169
1187
|
/*!
|
|
1170
1188
|
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
|
@@ -1177,7 +1195,7 @@
|
|
|
1177
1195
|
return Object.prototype.toString.call(o) === '[object Object]';
|
|
1178
1196
|
}
|
|
1179
1197
|
|
|
1180
|
-
function isPlainObject(o) {
|
|
1198
|
+
function isPlainObject$1(o) {
|
|
1181
1199
|
var ctor,prot;
|
|
1182
1200
|
|
|
1183
1201
|
if (isObject(o) === false) return false;
|
|
@@ -1209,7 +1227,7 @@
|
|
|
1209
1227
|
return options;
|
|
1210
1228
|
}
|
|
1211
1229
|
const isStream = typeof body.pipe === "function";
|
|
1212
|
-
const shouldSerialize = !isStream && !isBuffer(body) && (serializeTypes.indexOf(typeof body) !== -1 || Array.isArray(body) || isPlainObject(body));
|
|
1230
|
+
const shouldSerialize = !isStream && !isBuffer(body) && (serializeTypes.indexOf(typeof body) !== -1 || Array.isArray(body) || isPlainObject$1(body));
|
|
1213
1231
|
if (!shouldSerialize) {
|
|
1214
1232
|
return options;
|
|
1215
1233
|
}
|
|
@@ -1287,6 +1305,7 @@
|
|
|
1287
1305
|
}
|
|
1288
1306
|
function progress() {
|
|
1289
1307
|
return {
|
|
1308
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1290
1309
|
onRequest: evt => {
|
|
1291
1310
|
if (evt.adapter !== "xhr") {
|
|
1292
1311
|
return;
|
|
@@ -1349,6 +1368,7 @@
|
|
|
1349
1368
|
});
|
|
1350
1369
|
return {
|
|
1351
1370
|
token,
|
|
1371
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- we know from the implementation that it's assigned during `constructor`
|
|
1352
1372
|
cancel
|
|
1353
1373
|
};
|
|
1354
1374
|
};
|
|
@@ -2034,1118 +2054,83 @@
|
|
|
2034
2054
|
});
|
|
2035
2055
|
}
|
|
2036
2056
|
|
|
2037
|
-
var
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
status: response.status,
|
|
2115
|
-
statusText: response.statusText,
|
|
2116
|
-
headers: response.headers,
|
|
2117
|
-
body: {
|
|
2118
|
-
getReader: function () {
|
|
2119
|
-
return reader;
|
|
2120
|
-
}
|
|
2121
|
-
}
|
|
2122
|
-
};
|
|
2123
|
-
});
|
|
2124
|
-
};
|
|
2125
|
-
AbortController = function () {
|
|
2126
|
-
this.signal = {
|
|
2127
|
-
_reader: null,
|
|
2128
|
-
_aborted: false
|
|
2129
|
-
};
|
|
2130
|
-
this.abort = function () {
|
|
2131
|
-
if (this.signal._reader != null) {
|
|
2132
|
-
this.signal._reader.cancel();
|
|
2133
|
-
}
|
|
2134
|
-
this.signal._aborted = true;
|
|
2135
|
-
};
|
|
2136
|
-
};
|
|
2137
|
-
}
|
|
2138
|
-
|
|
2139
|
-
function TextDecoderPolyfill() {
|
|
2140
|
-
this.bitsNeeded = 0;
|
|
2141
|
-
this.codePoint = 0;
|
|
2142
|
-
}
|
|
2143
|
-
|
|
2144
|
-
TextDecoderPolyfill.prototype.decode = function (octets) {
|
|
2145
|
-
function valid(codePoint, shift, octetsCount) {
|
|
2146
|
-
if (octetsCount === 1) {
|
|
2147
|
-
return codePoint >= 0x0080 >> shift && codePoint << shift <= 0x07FF;
|
|
2148
|
-
}
|
|
2149
|
-
if (octetsCount === 2) {
|
|
2150
|
-
return codePoint >= 0x0800 >> shift && codePoint << shift <= 0xD7FF || codePoint >= 0xE000 >> shift && codePoint << shift <= 0xFFFF;
|
|
2151
|
-
}
|
|
2152
|
-
if (octetsCount === 3) {
|
|
2153
|
-
return codePoint >= 0x010000 >> shift && codePoint << shift <= 0x10FFFF;
|
|
2154
|
-
}
|
|
2155
|
-
throw new Error();
|
|
2156
|
-
}
|
|
2157
|
-
function octetsCount(bitsNeeded, codePoint) {
|
|
2158
|
-
if (bitsNeeded === 6 * 1) {
|
|
2159
|
-
return codePoint >> 6 > 15 ? 3 : codePoint > 31 ? 2 : 1;
|
|
2160
|
-
}
|
|
2161
|
-
if (bitsNeeded === 6 * 2) {
|
|
2162
|
-
return codePoint > 15 ? 3 : 2;
|
|
2163
|
-
}
|
|
2164
|
-
if (bitsNeeded === 6 * 3) {
|
|
2165
|
-
return 3;
|
|
2166
|
-
}
|
|
2167
|
-
throw new Error();
|
|
2168
|
-
}
|
|
2169
|
-
var REPLACER = 0xFFFD;
|
|
2170
|
-
var string = "";
|
|
2171
|
-
var bitsNeeded = this.bitsNeeded;
|
|
2172
|
-
var codePoint = this.codePoint;
|
|
2173
|
-
for (var i = 0; i < octets.length; i += 1) {
|
|
2174
|
-
var octet = octets[i];
|
|
2175
|
-
if (bitsNeeded !== 0) {
|
|
2176
|
-
if (octet < 128 || octet > 191 || !valid(codePoint << 6 | octet & 63, bitsNeeded - 6, octetsCount(bitsNeeded, codePoint))) {
|
|
2177
|
-
bitsNeeded = 0;
|
|
2178
|
-
codePoint = REPLACER;
|
|
2179
|
-
string += String.fromCharCode(codePoint);
|
|
2180
|
-
}
|
|
2181
|
-
}
|
|
2182
|
-
if (bitsNeeded === 0) {
|
|
2183
|
-
if (octet >= 0 && octet <= 127) {
|
|
2184
|
-
bitsNeeded = 0;
|
|
2185
|
-
codePoint = octet;
|
|
2186
|
-
} else if (octet >= 192 && octet <= 223) {
|
|
2187
|
-
bitsNeeded = 6 * 1;
|
|
2188
|
-
codePoint = octet & 31;
|
|
2189
|
-
} else if (octet >= 224 && octet <= 239) {
|
|
2190
|
-
bitsNeeded = 6 * 2;
|
|
2191
|
-
codePoint = octet & 15;
|
|
2192
|
-
} else if (octet >= 240 && octet <= 247) {
|
|
2193
|
-
bitsNeeded = 6 * 3;
|
|
2194
|
-
codePoint = octet & 7;
|
|
2195
|
-
} else {
|
|
2196
|
-
bitsNeeded = 0;
|
|
2197
|
-
codePoint = REPLACER;
|
|
2198
|
-
}
|
|
2199
|
-
if (bitsNeeded !== 0 && !valid(codePoint, bitsNeeded, octetsCount(bitsNeeded, codePoint))) {
|
|
2200
|
-
bitsNeeded = 0;
|
|
2201
|
-
codePoint = REPLACER;
|
|
2202
|
-
}
|
|
2203
|
-
} else {
|
|
2204
|
-
bitsNeeded -= 6;
|
|
2205
|
-
codePoint = codePoint << 6 | octet & 63;
|
|
2206
|
-
}
|
|
2207
|
-
if (bitsNeeded === 0) {
|
|
2208
|
-
if (codePoint <= 0xFFFF) {
|
|
2209
|
-
string += String.fromCharCode(codePoint);
|
|
2210
|
-
} else {
|
|
2211
|
-
string += String.fromCharCode(0xD800 + (codePoint - 0xFFFF - 1 >> 10));
|
|
2212
|
-
string += String.fromCharCode(0xDC00 + (codePoint - 0xFFFF - 1 & 0x3FF));
|
|
2213
|
-
}
|
|
2214
|
-
}
|
|
2215
|
-
}
|
|
2216
|
-
this.bitsNeeded = bitsNeeded;
|
|
2217
|
-
this.codePoint = codePoint;
|
|
2218
|
-
return string;
|
|
2219
|
-
};
|
|
2220
|
-
|
|
2221
|
-
// Firefox < 38 throws an error with stream option
|
|
2222
|
-
var supportsStreamOption = function () {
|
|
2223
|
-
try {
|
|
2224
|
-
return new TextDecoder().decode(new TextEncoder().encode("test"), {stream: true}) === "test";
|
|
2225
|
-
} catch (error) {
|
|
2226
|
-
console.debug("TextDecoder does not support streaming option. Using polyfill instead: " + error);
|
|
2227
|
-
}
|
|
2228
|
-
return false;
|
|
2229
|
-
};
|
|
2230
|
-
|
|
2231
|
-
// IE, Edge
|
|
2232
|
-
if (TextDecoder == undefined || TextEncoder == undefined || !supportsStreamOption()) {
|
|
2233
|
-
TextDecoder = TextDecoderPolyfill;
|
|
2234
|
-
}
|
|
2235
|
-
|
|
2236
|
-
var k = function () {
|
|
2237
|
-
};
|
|
2238
|
-
|
|
2239
|
-
function XHRWrapper(xhr) {
|
|
2240
|
-
this.withCredentials = false;
|
|
2241
|
-
this.readyState = 0;
|
|
2242
|
-
this.status = 0;
|
|
2243
|
-
this.statusText = "";
|
|
2244
|
-
this.responseText = "";
|
|
2245
|
-
this.onprogress = k;
|
|
2246
|
-
this.onload = k;
|
|
2247
|
-
this.onerror = k;
|
|
2248
|
-
this.onreadystatechange = k;
|
|
2249
|
-
this._contentType = "";
|
|
2250
|
-
this._xhr = xhr;
|
|
2251
|
-
this._sendTimeout = 0;
|
|
2252
|
-
this._abort = k;
|
|
2253
|
-
}
|
|
2254
|
-
|
|
2255
|
-
XHRWrapper.prototype.open = function (method, url) {
|
|
2256
|
-
this._abort(true);
|
|
2257
|
-
|
|
2258
|
-
var that = this;
|
|
2259
|
-
var xhr = this._xhr;
|
|
2260
|
-
var state = 1;
|
|
2261
|
-
var timeout = 0;
|
|
2262
|
-
|
|
2263
|
-
this._abort = function (silent) {
|
|
2264
|
-
if (that._sendTimeout !== 0) {
|
|
2265
|
-
clearTimeout(that._sendTimeout);
|
|
2266
|
-
that._sendTimeout = 0;
|
|
2267
|
-
}
|
|
2268
|
-
if (state === 1 || state === 2 || state === 3) {
|
|
2269
|
-
state = 4;
|
|
2270
|
-
xhr.onload = k;
|
|
2271
|
-
xhr.onerror = k;
|
|
2272
|
-
xhr.onabort = k;
|
|
2273
|
-
xhr.onprogress = k;
|
|
2274
|
-
xhr.onreadystatechange = k;
|
|
2275
|
-
// IE 8 - 9: XDomainRequest#abort() does not fire any event
|
|
2276
|
-
// Opera < 10: XMLHttpRequest#abort() does not fire any event
|
|
2277
|
-
xhr.abort();
|
|
2278
|
-
if (timeout !== 0) {
|
|
2279
|
-
clearTimeout(timeout);
|
|
2280
|
-
timeout = 0;
|
|
2281
|
-
}
|
|
2282
|
-
if (!silent) {
|
|
2283
|
-
that.readyState = 4;
|
|
2284
|
-
that.onabort(null);
|
|
2285
|
-
that.onreadystatechange();
|
|
2286
|
-
}
|
|
2287
|
-
}
|
|
2288
|
-
state = 0;
|
|
2289
|
-
};
|
|
2290
|
-
|
|
2291
|
-
var onStart = function () {
|
|
2292
|
-
if (state === 1) {
|
|
2293
|
-
//state = 2;
|
|
2294
|
-
var status = 0;
|
|
2295
|
-
var statusText = "";
|
|
2296
|
-
var contentType = undefined;
|
|
2297
|
-
if (!("contentType" in xhr)) {
|
|
2298
|
-
try {
|
|
2299
|
-
status = xhr.status;
|
|
2300
|
-
statusText = xhr.statusText;
|
|
2301
|
-
contentType = xhr.getResponseHeader("Content-Type");
|
|
2302
|
-
} catch (error) {
|
|
2303
|
-
// IE < 10 throws exception for `xhr.status` when xhr.readyState === 2 || xhr.readyState === 3
|
|
2304
|
-
// Opera < 11 throws exception for `xhr.status` when xhr.readyState === 2
|
|
2305
|
-
// https://bugs.webkit.org/show_bug.cgi?id=29121
|
|
2306
|
-
status = 0;
|
|
2307
|
-
statusText = "";
|
|
2308
|
-
contentType = undefined;
|
|
2309
|
-
// Firefox < 14, Chrome ?, Safari ?
|
|
2310
|
-
// https://bugs.webkit.org/show_bug.cgi?id=29658
|
|
2311
|
-
// https://bugs.webkit.org/show_bug.cgi?id=77854
|
|
2312
|
-
}
|
|
2313
|
-
} else {
|
|
2314
|
-
status = 200;
|
|
2315
|
-
statusText = "OK";
|
|
2316
|
-
contentType = xhr.contentType;
|
|
2317
|
-
}
|
|
2318
|
-
if (status !== 0) {
|
|
2319
|
-
state = 2;
|
|
2320
|
-
that.readyState = 2;
|
|
2321
|
-
that.status = status;
|
|
2322
|
-
that.statusText = statusText;
|
|
2323
|
-
that._contentType = contentType;
|
|
2324
|
-
that.onreadystatechange();
|
|
2325
|
-
}
|
|
2326
|
-
}
|
|
2327
|
-
};
|
|
2328
|
-
var onProgress = function () {
|
|
2329
|
-
onStart();
|
|
2330
|
-
if (state === 2 || state === 3) {
|
|
2331
|
-
state = 3;
|
|
2332
|
-
var responseText = "";
|
|
2333
|
-
try {
|
|
2334
|
-
responseText = xhr.responseText;
|
|
2335
|
-
} catch (error) {
|
|
2336
|
-
// IE 8 - 9 with XMLHttpRequest
|
|
2337
|
-
}
|
|
2338
|
-
that.readyState = 3;
|
|
2339
|
-
that.responseText = responseText;
|
|
2340
|
-
that.onprogress();
|
|
2341
|
-
}
|
|
2342
|
-
};
|
|
2343
|
-
var onFinish = function (type, event) {
|
|
2344
|
-
if (event == null || event.preventDefault == null) {
|
|
2345
|
-
event = {
|
|
2346
|
-
preventDefault: k
|
|
2347
|
-
};
|
|
2348
|
-
}
|
|
2349
|
-
// Firefox 52 fires "readystatechange" (xhr.readyState === 4) without final "readystatechange" (xhr.readyState === 3)
|
|
2350
|
-
// IE 8 fires "onload" without "onprogress"
|
|
2351
|
-
onProgress();
|
|
2352
|
-
if (state === 1 || state === 2 || state === 3) {
|
|
2353
|
-
state = 4;
|
|
2354
|
-
if (timeout !== 0) {
|
|
2355
|
-
clearTimeout(timeout);
|
|
2356
|
-
timeout = 0;
|
|
2357
|
-
}
|
|
2358
|
-
that.readyState = 4;
|
|
2359
|
-
if (type === "load") {
|
|
2360
|
-
that.onload(event);
|
|
2361
|
-
} else if (type === "error") {
|
|
2362
|
-
that.onerror(event);
|
|
2363
|
-
} else if (type === "abort") {
|
|
2364
|
-
that.onabort(event);
|
|
2365
|
-
} else {
|
|
2366
|
-
throw new TypeError();
|
|
2367
|
-
}
|
|
2368
|
-
that.onreadystatechange();
|
|
2369
|
-
}
|
|
2370
|
-
};
|
|
2371
|
-
var onReadyStateChange = function (event) {
|
|
2372
|
-
if (xhr != undefined) { // Opera 12
|
|
2373
|
-
if (xhr.readyState === 4) {
|
|
2374
|
-
if (!("onload" in xhr) || !("onerror" in xhr) || !("onabort" in xhr)) {
|
|
2375
|
-
onFinish(xhr.responseText === "" ? "error" : "load", event);
|
|
2376
|
-
}
|
|
2377
|
-
} else if (xhr.readyState === 3) {
|
|
2378
|
-
if (!("onprogress" in xhr)) { // testing XMLHttpRequest#responseText too many times is too slow in IE 11
|
|
2379
|
-
// and in Firefox 3.6
|
|
2380
|
-
onProgress();
|
|
2381
|
-
}
|
|
2382
|
-
} else if (xhr.readyState === 2) {
|
|
2383
|
-
onStart();
|
|
2384
|
-
}
|
|
2385
|
-
}
|
|
2386
|
-
};
|
|
2387
|
-
var onTimeout = function () {
|
|
2388
|
-
timeout = setTimeout(function () {
|
|
2389
|
-
onTimeout();
|
|
2390
|
-
}, 500);
|
|
2391
|
-
if (xhr.readyState === 3) {
|
|
2392
|
-
onProgress();
|
|
2393
|
-
}
|
|
2394
|
-
};
|
|
2395
|
-
|
|
2396
|
-
// XDomainRequest#abort removes onprogress, onerror, onload
|
|
2397
|
-
if ("onload" in xhr) {
|
|
2398
|
-
xhr.onload = function (event) {
|
|
2399
|
-
onFinish("load", event);
|
|
2400
|
-
};
|
|
2401
|
-
}
|
|
2402
|
-
if ("onerror" in xhr) {
|
|
2403
|
-
xhr.onerror = function (event) {
|
|
2404
|
-
onFinish("error", event);
|
|
2405
|
-
};
|
|
2406
|
-
}
|
|
2407
|
-
// improper fix to match Firefox behaviour, but it is better than just ignore abort
|
|
2408
|
-
// see https://bugzilla.mozilla.org/show_bug.cgi?id=768596
|
|
2409
|
-
// https://bugzilla.mozilla.org/show_bug.cgi?id=880200
|
|
2410
|
-
// https://code.google.com/p/chromium/issues/detail?id=153570
|
|
2411
|
-
// IE 8 fires "onload" without "onprogress
|
|
2412
|
-
if ("onabort" in xhr) {
|
|
2413
|
-
xhr.onabort = function (event) {
|
|
2414
|
-
onFinish("abort", event);
|
|
2415
|
-
};
|
|
2416
|
-
}
|
|
2417
|
-
|
|
2418
|
-
if ("onprogress" in xhr) {
|
|
2419
|
-
xhr.onprogress = onProgress;
|
|
2420
|
-
}
|
|
2421
|
-
|
|
2422
|
-
// IE 8 - 9 (XMLHTTPRequest)
|
|
2423
|
-
// Opera < 12
|
|
2424
|
-
// Firefox < 3.5
|
|
2425
|
-
// Firefox 3.5 - 3.6 - ? < 9.0
|
|
2426
|
-
// onprogress is not fired sometimes or delayed
|
|
2427
|
-
// see also #64 (significant lag in IE 11)
|
|
2428
|
-
if ("onreadystatechange" in xhr) {
|
|
2429
|
-
xhr.onreadystatechange = function (event) {
|
|
2430
|
-
onReadyStateChange(event);
|
|
2431
|
-
};
|
|
2432
|
-
}
|
|
2433
|
-
|
|
2434
|
-
if ("contentType" in xhr || !("ontimeout" in XMLHttpRequest.prototype)) {
|
|
2435
|
-
url += (url.indexOf("?") === -1 ? "?" : "&") + "padding=true";
|
|
2436
|
-
}
|
|
2437
|
-
xhr.open(method, url, true);
|
|
2438
|
-
|
|
2439
|
-
if ("readyState" in xhr) {
|
|
2440
|
-
// workaround for Opera 12 issue with "progress" events
|
|
2441
|
-
// #91 (XMLHttpRequest onprogress not fired for streaming response in Edge 14-15-?)
|
|
2442
|
-
timeout = setTimeout(function () {
|
|
2443
|
-
onTimeout();
|
|
2444
|
-
}, 0);
|
|
2445
|
-
}
|
|
2446
|
-
};
|
|
2447
|
-
XHRWrapper.prototype.abort = function () {
|
|
2448
|
-
this._abort(false);
|
|
2449
|
-
};
|
|
2450
|
-
XHRWrapper.prototype.getResponseHeader = function (name) {
|
|
2451
|
-
return this._contentType;
|
|
2452
|
-
};
|
|
2453
|
-
XHRWrapper.prototype.setRequestHeader = function (name, value) {
|
|
2454
|
-
var xhr = this._xhr;
|
|
2455
|
-
if ("setRequestHeader" in xhr) {
|
|
2456
|
-
xhr.setRequestHeader(name, value);
|
|
2457
|
-
}
|
|
2458
|
-
};
|
|
2459
|
-
XHRWrapper.prototype.getAllResponseHeaders = function () {
|
|
2460
|
-
// XMLHttpRequest#getAllResponseHeaders returns null for CORS requests in Firefox 3.6.28
|
|
2461
|
-
return this._xhr.getAllResponseHeaders != undefined ? this._xhr.getAllResponseHeaders() || "" : "";
|
|
2462
|
-
};
|
|
2463
|
-
XHRWrapper.prototype.send = function () {
|
|
2464
|
-
// loading indicator in Safari < ? (6), Chrome < 14, Firefox
|
|
2465
|
-
// https://bugzilla.mozilla.org/show_bug.cgi?id=736723
|
|
2466
|
-
if ((!("ontimeout" in XMLHttpRequest.prototype) || (!("sendAsBinary" in XMLHttpRequest.prototype) && !("mozAnon" in XMLHttpRequest.prototype))) &&
|
|
2467
|
-
document != undefined &&
|
|
2468
|
-
document.readyState != undefined &&
|
|
2469
|
-
document.readyState !== "complete") {
|
|
2470
|
-
var that = this;
|
|
2471
|
-
that._sendTimeout = setTimeout(function () {
|
|
2472
|
-
that._sendTimeout = 0;
|
|
2473
|
-
that.send();
|
|
2474
|
-
}, 4);
|
|
2475
|
-
return;
|
|
2476
|
-
}
|
|
2477
|
-
|
|
2478
|
-
var xhr = this._xhr;
|
|
2479
|
-
// withCredentials should be set after "open" for Safari and Chrome (< 19 ?)
|
|
2480
|
-
if ("withCredentials" in xhr) {
|
|
2481
|
-
xhr.withCredentials = this.withCredentials;
|
|
2482
|
-
}
|
|
2483
|
-
try {
|
|
2484
|
-
// xhr.send(); throws "Not enough arguments" in Firefox 3.0
|
|
2485
|
-
xhr.send(undefined);
|
|
2486
|
-
} catch (error1) {
|
|
2487
|
-
// Safari 5.1.7, Opera 12
|
|
2488
|
-
throw error1;
|
|
2489
|
-
}
|
|
2490
|
-
};
|
|
2491
|
-
|
|
2492
|
-
function toLowerCase(name) {
|
|
2493
|
-
return name.replace(/[A-Z]/g, function (c) {
|
|
2494
|
-
return String.fromCharCode(c.charCodeAt(0) + 0x20);
|
|
2495
|
-
});
|
|
2496
|
-
}
|
|
2497
|
-
|
|
2498
|
-
function HeadersPolyfill(all) {
|
|
2499
|
-
// Get headers: implemented according to mozilla's example code: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#Example
|
|
2500
|
-
var map = Object.create(null);
|
|
2501
|
-
var array = all.split("\r\n");
|
|
2502
|
-
for (var i = 0; i < array.length; i += 1) {
|
|
2503
|
-
var line = array[i];
|
|
2504
|
-
var parts = line.split(": ");
|
|
2505
|
-
var name = parts.shift();
|
|
2506
|
-
var value = parts.join(": ");
|
|
2507
|
-
map[toLowerCase(name)] = value;
|
|
2508
|
-
}
|
|
2509
|
-
this._map = map;
|
|
2510
|
-
}
|
|
2511
|
-
HeadersPolyfill.prototype.get = function (name) {
|
|
2512
|
-
return this._map[toLowerCase(name)];
|
|
2513
|
-
};
|
|
2514
|
-
|
|
2515
|
-
if (XMLHttpRequest != null && XMLHttpRequest.HEADERS_RECEIVED == null) { // IE < 9, Firefox 3.6
|
|
2516
|
-
XMLHttpRequest.HEADERS_RECEIVED = 2;
|
|
2517
|
-
}
|
|
2518
|
-
|
|
2519
|
-
function XHRTransport() {
|
|
2520
|
-
}
|
|
2521
|
-
|
|
2522
|
-
XHRTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
|
|
2523
|
-
xhr.open("GET", url);
|
|
2524
|
-
var offset = 0;
|
|
2525
|
-
xhr.onprogress = function () {
|
|
2526
|
-
var responseText = xhr.responseText;
|
|
2527
|
-
var chunk = responseText.slice(offset);
|
|
2528
|
-
offset += chunk.length;
|
|
2529
|
-
onProgressCallback(chunk);
|
|
2530
|
-
};
|
|
2531
|
-
xhr.onerror = function (event) {
|
|
2532
|
-
event.preventDefault();
|
|
2533
|
-
onFinishCallback(new Error("NetworkError"));
|
|
2534
|
-
};
|
|
2535
|
-
xhr.onload = function () {
|
|
2536
|
-
onFinishCallback(null);
|
|
2537
|
-
};
|
|
2538
|
-
xhr.onabort = function () {
|
|
2539
|
-
onFinishCallback(null);
|
|
2540
|
-
};
|
|
2541
|
-
xhr.onreadystatechange = function () {
|
|
2542
|
-
if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
|
|
2543
|
-
var status = xhr.status;
|
|
2544
|
-
var statusText = xhr.statusText;
|
|
2545
|
-
var contentType = xhr.getResponseHeader("Content-Type");
|
|
2546
|
-
var headers = xhr.getAllResponseHeaders();
|
|
2547
|
-
onStartCallback(status, statusText, contentType, new HeadersPolyfill(headers));
|
|
2548
|
-
}
|
|
2549
|
-
};
|
|
2550
|
-
xhr.withCredentials = withCredentials;
|
|
2551
|
-
for (var name in headers) {
|
|
2552
|
-
if (Object.prototype.hasOwnProperty.call(headers, name)) {
|
|
2553
|
-
xhr.setRequestHeader(name, headers[name]);
|
|
2554
|
-
}
|
|
2555
|
-
}
|
|
2556
|
-
xhr.send();
|
|
2557
|
-
return xhr;
|
|
2558
|
-
};
|
|
2559
|
-
|
|
2560
|
-
function HeadersWrapper(headers) {
|
|
2561
|
-
this._headers = headers;
|
|
2562
|
-
}
|
|
2563
|
-
HeadersWrapper.prototype.get = function (name) {
|
|
2564
|
-
return this._headers.get(name);
|
|
2565
|
-
};
|
|
2566
|
-
|
|
2567
|
-
function FetchTransport() {
|
|
2568
|
-
}
|
|
2569
|
-
|
|
2570
|
-
FetchTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
|
|
2571
|
-
var reader = null;
|
|
2572
|
-
var controller = new AbortController();
|
|
2573
|
-
var signal = controller.signal;
|
|
2574
|
-
var textDecoder = new TextDecoder();
|
|
2575
|
-
fetch(url, {
|
|
2576
|
-
headers: headers,
|
|
2577
|
-
credentials: withCredentials ? "include" : "same-origin",
|
|
2578
|
-
signal: signal,
|
|
2579
|
-
cache: "no-store"
|
|
2580
|
-
}).then(function (response) {
|
|
2581
|
-
reader = response.body.getReader();
|
|
2582
|
-
onStartCallback(response.status, response.statusText, response.headers.get("Content-Type"), new HeadersWrapper(response.headers));
|
|
2583
|
-
// see https://github.com/promises-aplus/promises-spec/issues/179
|
|
2584
|
-
return new Promise(function (resolve, reject) {
|
|
2585
|
-
var readNextChunk = function () {
|
|
2586
|
-
reader.read().then(function (result) {
|
|
2587
|
-
if (result.done) {
|
|
2588
|
-
//Note: bytes in textDecoder are ignored
|
|
2589
|
-
resolve(undefined);
|
|
2590
|
-
} else {
|
|
2591
|
-
var chunk = textDecoder.decode(result.value, {stream: true});
|
|
2592
|
-
onProgressCallback(chunk);
|
|
2593
|
-
readNextChunk();
|
|
2594
|
-
}
|
|
2595
|
-
})["catch"](function (error) {
|
|
2596
|
-
reject(error);
|
|
2597
|
-
});
|
|
2598
|
-
};
|
|
2599
|
-
readNextChunk();
|
|
2600
|
-
});
|
|
2601
|
-
})["catch"](function (error) {
|
|
2602
|
-
if (error.name === "AbortError") {
|
|
2603
|
-
return undefined;
|
|
2604
|
-
} else {
|
|
2605
|
-
return error;
|
|
2606
|
-
}
|
|
2607
|
-
}).then(function (error) {
|
|
2608
|
-
onFinishCallback(error);
|
|
2609
|
-
});
|
|
2610
|
-
return {
|
|
2611
|
-
abort: function () {
|
|
2612
|
-
if (reader != null) {
|
|
2613
|
-
reader.cancel(); // https://bugzilla.mozilla.org/show_bug.cgi?id=1583815
|
|
2614
|
-
}
|
|
2615
|
-
controller.abort();
|
|
2616
|
-
}
|
|
2617
|
-
};
|
|
2618
|
-
};
|
|
2619
|
-
|
|
2620
|
-
function EventTarget() {
|
|
2621
|
-
this._listeners = Object.create(null);
|
|
2622
|
-
}
|
|
2623
|
-
|
|
2624
|
-
function throwError(e) {
|
|
2625
|
-
setTimeout(function () {
|
|
2626
|
-
throw e;
|
|
2627
|
-
}, 0);
|
|
2628
|
-
}
|
|
2629
|
-
|
|
2630
|
-
EventTarget.prototype.dispatchEvent = function (event) {
|
|
2631
|
-
event.target = this;
|
|
2632
|
-
var typeListeners = this._listeners[event.type];
|
|
2633
|
-
if (typeListeners != undefined) {
|
|
2634
|
-
var length = typeListeners.length;
|
|
2635
|
-
for (var i = 0; i < length; i += 1) {
|
|
2636
|
-
var listener = typeListeners[i];
|
|
2637
|
-
try {
|
|
2638
|
-
if (typeof listener.handleEvent === "function") {
|
|
2639
|
-
listener.handleEvent(event);
|
|
2640
|
-
} else {
|
|
2641
|
-
listener.call(this, event);
|
|
2642
|
-
}
|
|
2643
|
-
} catch (e) {
|
|
2644
|
-
throwError(e);
|
|
2645
|
-
}
|
|
2646
|
-
}
|
|
2647
|
-
}
|
|
2648
|
-
};
|
|
2649
|
-
EventTarget.prototype.addEventListener = function (type, listener) {
|
|
2650
|
-
type = String(type);
|
|
2651
|
-
var listeners = this._listeners;
|
|
2652
|
-
var typeListeners = listeners[type];
|
|
2653
|
-
if (typeListeners == undefined) {
|
|
2654
|
-
typeListeners = [];
|
|
2655
|
-
listeners[type] = typeListeners;
|
|
2656
|
-
}
|
|
2657
|
-
var found = false;
|
|
2658
|
-
for (var i = 0; i < typeListeners.length; i += 1) {
|
|
2659
|
-
if (typeListeners[i] === listener) {
|
|
2660
|
-
found = true;
|
|
2661
|
-
}
|
|
2662
|
-
}
|
|
2663
|
-
if (!found) {
|
|
2664
|
-
typeListeners.push(listener);
|
|
2665
|
-
}
|
|
2666
|
-
};
|
|
2667
|
-
EventTarget.prototype.removeEventListener = function (type, listener) {
|
|
2668
|
-
type = String(type);
|
|
2669
|
-
var listeners = this._listeners;
|
|
2670
|
-
var typeListeners = listeners[type];
|
|
2671
|
-
if (typeListeners != undefined) {
|
|
2672
|
-
var filtered = [];
|
|
2673
|
-
for (var i = 0; i < typeListeners.length; i += 1) {
|
|
2674
|
-
if (typeListeners[i] !== listener) {
|
|
2675
|
-
filtered.push(typeListeners[i]);
|
|
2676
|
-
}
|
|
2677
|
-
}
|
|
2678
|
-
if (filtered.length === 0) {
|
|
2679
|
-
delete listeners[type];
|
|
2680
|
-
} else {
|
|
2681
|
-
listeners[type] = filtered;
|
|
2682
|
-
}
|
|
2683
|
-
}
|
|
2684
|
-
};
|
|
2685
|
-
|
|
2686
|
-
function Event(type) {
|
|
2687
|
-
this.type = type;
|
|
2688
|
-
this.target = undefined;
|
|
2689
|
-
}
|
|
2690
|
-
|
|
2691
|
-
function MessageEvent(type, options) {
|
|
2692
|
-
Event.call(this, type);
|
|
2693
|
-
this.data = options.data;
|
|
2694
|
-
this.lastEventId = options.lastEventId;
|
|
2695
|
-
}
|
|
2696
|
-
|
|
2697
|
-
MessageEvent.prototype = Object.create(Event.prototype);
|
|
2698
|
-
|
|
2699
|
-
function ConnectionEvent(type, options) {
|
|
2700
|
-
Event.call(this, type);
|
|
2701
|
-
this.status = options.status;
|
|
2702
|
-
this.statusText = options.statusText;
|
|
2703
|
-
this.headers = options.headers;
|
|
2704
|
-
}
|
|
2705
|
-
|
|
2706
|
-
ConnectionEvent.prototype = Object.create(Event.prototype);
|
|
2707
|
-
|
|
2708
|
-
function ErrorEvent(type, options) {
|
|
2709
|
-
Event.call(this, type);
|
|
2710
|
-
this.error = options.error;
|
|
2711
|
-
}
|
|
2712
|
-
|
|
2713
|
-
ErrorEvent.prototype = Object.create(Event.prototype);
|
|
2714
|
-
|
|
2715
|
-
var WAITING = -1;
|
|
2716
|
-
var CONNECTING = 0;
|
|
2717
|
-
var OPEN = 1;
|
|
2718
|
-
var CLOSED = 2;
|
|
2719
|
-
|
|
2720
|
-
var AFTER_CR = -1;
|
|
2721
|
-
var FIELD_START = 0;
|
|
2722
|
-
var FIELD = 1;
|
|
2723
|
-
var VALUE_START = 2;
|
|
2724
|
-
var VALUE = 3;
|
|
2725
|
-
|
|
2726
|
-
var contentTypeRegExp = /^text\/event\-stream(;.*)?$/i;
|
|
2727
|
-
|
|
2728
|
-
var MINIMUM_DURATION = 1000;
|
|
2729
|
-
var MAXIMUM_DURATION = 18000000;
|
|
2730
|
-
|
|
2731
|
-
var parseDuration = function (value, def) {
|
|
2732
|
-
var n = value == null ? def : parseInt(value, 10);
|
|
2733
|
-
if (n !== n) {
|
|
2734
|
-
n = def;
|
|
2735
|
-
}
|
|
2736
|
-
return clampDuration(n);
|
|
2737
|
-
};
|
|
2738
|
-
var clampDuration = function (n) {
|
|
2739
|
-
return Math.min(Math.max(n, MINIMUM_DURATION), MAXIMUM_DURATION);
|
|
2740
|
-
};
|
|
2741
|
-
|
|
2742
|
-
var fire = function (that, f, event) {
|
|
2743
|
-
try {
|
|
2744
|
-
if (typeof f === "function") {
|
|
2745
|
-
f.call(that, event);
|
|
2746
|
-
}
|
|
2747
|
-
} catch (e) {
|
|
2748
|
-
throwError(e);
|
|
2749
|
-
}
|
|
2750
|
-
};
|
|
2751
|
-
|
|
2752
|
-
function EventSourcePolyfill(url, options) {
|
|
2753
|
-
EventTarget.call(this);
|
|
2754
|
-
options = options || {};
|
|
2755
|
-
|
|
2756
|
-
this.onopen = undefined;
|
|
2757
|
-
this.onmessage = undefined;
|
|
2758
|
-
this.onerror = undefined;
|
|
2759
|
-
|
|
2760
|
-
this.url = undefined;
|
|
2761
|
-
this.readyState = undefined;
|
|
2762
|
-
this.withCredentials = undefined;
|
|
2763
|
-
this.headers = undefined;
|
|
2764
|
-
|
|
2765
|
-
this._close = undefined;
|
|
2766
|
-
|
|
2767
|
-
start(this, url, options);
|
|
2768
|
-
}
|
|
2769
|
-
|
|
2770
|
-
function getBestXHRTransport() {
|
|
2771
|
-
return (XMLHttpRequest != undefined && ("withCredentials" in XMLHttpRequest.prototype)) || XDomainRequest == undefined
|
|
2772
|
-
? new XMLHttpRequest()
|
|
2773
|
-
: new XDomainRequest();
|
|
2774
|
-
}
|
|
2775
|
-
|
|
2776
|
-
var isFetchSupported = fetch != undefined && Response != undefined && "body" in Response.prototype;
|
|
2777
|
-
|
|
2778
|
-
function start(es, url, options) {
|
|
2779
|
-
url = String(url);
|
|
2780
|
-
var withCredentials = Boolean(options.withCredentials);
|
|
2781
|
-
var lastEventIdQueryParameterName = options.lastEventIdQueryParameterName || "lastEventId";
|
|
2782
|
-
|
|
2783
|
-
var initialRetry = clampDuration(1000);
|
|
2784
|
-
var heartbeatTimeout = parseDuration(options.heartbeatTimeout, 45000);
|
|
2785
|
-
|
|
2786
|
-
var lastEventId = "";
|
|
2787
|
-
var retry = initialRetry;
|
|
2788
|
-
var wasActivity = false;
|
|
2789
|
-
var textLength = 0;
|
|
2790
|
-
var headers = options.headers || {};
|
|
2791
|
-
var TransportOption = options.Transport;
|
|
2792
|
-
var xhr = isFetchSupported && TransportOption == undefined ? undefined : new XHRWrapper(TransportOption != undefined ? new TransportOption() : getBestXHRTransport());
|
|
2793
|
-
var transport = TransportOption != null && typeof TransportOption !== "string" ? new TransportOption() : (xhr == undefined ? new FetchTransport() : new XHRTransport());
|
|
2794
|
-
var abortController = undefined;
|
|
2795
|
-
var timeout = 0;
|
|
2796
|
-
var currentState = WAITING;
|
|
2797
|
-
var dataBuffer = "";
|
|
2798
|
-
var lastEventIdBuffer = "";
|
|
2799
|
-
var eventTypeBuffer = "";
|
|
2800
|
-
|
|
2801
|
-
var textBuffer = "";
|
|
2802
|
-
var state = FIELD_START;
|
|
2803
|
-
var fieldStart = 0;
|
|
2804
|
-
var valueStart = 0;
|
|
2805
|
-
|
|
2806
|
-
var onStart = function (status, statusText, contentType, headers) {
|
|
2807
|
-
if (currentState === CONNECTING) {
|
|
2808
|
-
if (status === 200 && contentType != undefined && contentTypeRegExp.test(contentType)) {
|
|
2809
|
-
currentState = OPEN;
|
|
2810
|
-
wasActivity = Date.now();
|
|
2811
|
-
retry = initialRetry;
|
|
2812
|
-
es.readyState = OPEN;
|
|
2813
|
-
var event = new ConnectionEvent("open", {
|
|
2814
|
-
status: status,
|
|
2815
|
-
statusText: statusText,
|
|
2816
|
-
headers: headers
|
|
2817
|
-
});
|
|
2818
|
-
es.dispatchEvent(event);
|
|
2819
|
-
fire(es, es.onopen, event);
|
|
2820
|
-
} else {
|
|
2821
|
-
var message = "";
|
|
2822
|
-
if (status !== 200) {
|
|
2823
|
-
if (statusText) {
|
|
2824
|
-
statusText = statusText.replace(/\s+/g, " ");
|
|
2825
|
-
}
|
|
2826
|
-
message = "EventSource's response has a status " + status + " " + statusText + " that is not 200. Aborting the connection.";
|
|
2827
|
-
} else {
|
|
2828
|
-
message = "EventSource's response has a Content-Type specifying an unsupported type: " + (contentType == undefined ? "-" : contentType.replace(/\s+/g, " ")) + ". Aborting the connection.";
|
|
2829
|
-
}
|
|
2830
|
-
close();
|
|
2831
|
-
var event = new ConnectionEvent("error", {
|
|
2832
|
-
status: status,
|
|
2833
|
-
statusText: statusText,
|
|
2834
|
-
headers: headers
|
|
2835
|
-
});
|
|
2836
|
-
es.dispatchEvent(event);
|
|
2837
|
-
fire(es, es.onerror, event);
|
|
2838
|
-
console.error(message);
|
|
2839
|
-
}
|
|
2840
|
-
}
|
|
2841
|
-
};
|
|
2842
|
-
|
|
2843
|
-
var onProgress = function (textChunk) {
|
|
2844
|
-
if (currentState === OPEN) {
|
|
2845
|
-
var n = -1;
|
|
2846
|
-
for (var i = 0; i < textChunk.length; i += 1) {
|
|
2847
|
-
var c = textChunk.charCodeAt(i);
|
|
2848
|
-
if (c === "\n".charCodeAt(0) || c === "\r".charCodeAt(0)) {
|
|
2849
|
-
n = i;
|
|
2850
|
-
}
|
|
2851
|
-
}
|
|
2852
|
-
var chunk = (n !== -1 ? textBuffer : "") + textChunk.slice(0, n + 1);
|
|
2853
|
-
textBuffer = (n === -1 ? textBuffer : "") + textChunk.slice(n + 1);
|
|
2854
|
-
if (textChunk !== "") {
|
|
2855
|
-
wasActivity = Date.now();
|
|
2856
|
-
textLength += textChunk.length;
|
|
2857
|
-
}
|
|
2858
|
-
for (var position = 0; position < chunk.length; position += 1) {
|
|
2859
|
-
var c = chunk.charCodeAt(position);
|
|
2860
|
-
if (state === AFTER_CR && c === "\n".charCodeAt(0)) {
|
|
2861
|
-
state = FIELD_START;
|
|
2862
|
-
} else {
|
|
2863
|
-
if (state === AFTER_CR) {
|
|
2864
|
-
state = FIELD_START;
|
|
2865
|
-
}
|
|
2866
|
-
if (c === "\r".charCodeAt(0) || c === "\n".charCodeAt(0)) {
|
|
2867
|
-
if (state !== FIELD_START) {
|
|
2868
|
-
if (state === FIELD) {
|
|
2869
|
-
valueStart = position + 1;
|
|
2870
|
-
}
|
|
2871
|
-
var field = chunk.slice(fieldStart, valueStart - 1);
|
|
2872
|
-
var value = chunk.slice(valueStart + (valueStart < position && chunk.charCodeAt(valueStart) === " ".charCodeAt(0) ? 1 : 0), position);
|
|
2873
|
-
if (field === "data") {
|
|
2874
|
-
dataBuffer += "\n";
|
|
2875
|
-
dataBuffer += value;
|
|
2876
|
-
} else if (field === "id") {
|
|
2877
|
-
lastEventIdBuffer = value;
|
|
2878
|
-
} else if (field === "event") {
|
|
2879
|
-
eventTypeBuffer = value;
|
|
2880
|
-
} else if (field === "retry") {
|
|
2881
|
-
initialRetry = parseDuration(value, initialRetry);
|
|
2882
|
-
retry = initialRetry;
|
|
2883
|
-
} else if (field === "heartbeatTimeout") {
|
|
2884
|
-
heartbeatTimeout = parseDuration(value, heartbeatTimeout);
|
|
2885
|
-
if (timeout !== 0) {
|
|
2886
|
-
clearTimeout(timeout);
|
|
2887
|
-
timeout = setTimeout(function () {
|
|
2888
|
-
onTimeout();
|
|
2889
|
-
}, heartbeatTimeout);
|
|
2890
|
-
}
|
|
2891
|
-
}
|
|
2892
|
-
}
|
|
2893
|
-
if (state === FIELD_START) {
|
|
2894
|
-
if (dataBuffer !== "") {
|
|
2895
|
-
lastEventId = lastEventIdBuffer;
|
|
2896
|
-
if (eventTypeBuffer === "") {
|
|
2897
|
-
eventTypeBuffer = "message";
|
|
2898
|
-
}
|
|
2899
|
-
var event = new MessageEvent(eventTypeBuffer, {
|
|
2900
|
-
data: dataBuffer.slice(1),
|
|
2901
|
-
lastEventId: lastEventIdBuffer
|
|
2902
|
-
});
|
|
2903
|
-
es.dispatchEvent(event);
|
|
2904
|
-
if (eventTypeBuffer === "open") {
|
|
2905
|
-
fire(es, es.onopen, event);
|
|
2906
|
-
} else if (eventTypeBuffer === "message") {
|
|
2907
|
-
fire(es, es.onmessage, event);
|
|
2908
|
-
} else if (eventTypeBuffer === "error") {
|
|
2909
|
-
fire(es, es.onerror, event);
|
|
2910
|
-
}
|
|
2911
|
-
if (currentState === CLOSED) {
|
|
2912
|
-
return;
|
|
2913
|
-
}
|
|
2914
|
-
}
|
|
2915
|
-
dataBuffer = "";
|
|
2916
|
-
eventTypeBuffer = "";
|
|
2917
|
-
}
|
|
2918
|
-
state = c === "\r".charCodeAt(0) ? AFTER_CR : FIELD_START;
|
|
2919
|
-
} else {
|
|
2920
|
-
if (state === FIELD_START) {
|
|
2921
|
-
fieldStart = position;
|
|
2922
|
-
state = FIELD;
|
|
2923
|
-
}
|
|
2924
|
-
if (state === FIELD) {
|
|
2925
|
-
if (c === ":".charCodeAt(0)) {
|
|
2926
|
-
valueStart = position + 1;
|
|
2927
|
-
state = VALUE_START;
|
|
2928
|
-
}
|
|
2929
|
-
} else if (state === VALUE_START) {
|
|
2930
|
-
state = VALUE;
|
|
2931
|
-
}
|
|
2932
|
-
}
|
|
2933
|
-
}
|
|
2934
|
-
}
|
|
2935
|
-
}
|
|
2936
|
-
};
|
|
2937
|
-
|
|
2938
|
-
var onFinish = function (error) {
|
|
2939
|
-
if (currentState === OPEN || currentState === CONNECTING) {
|
|
2940
|
-
currentState = WAITING;
|
|
2941
|
-
if (timeout !== 0) {
|
|
2942
|
-
clearTimeout(timeout);
|
|
2943
|
-
timeout = 0;
|
|
2944
|
-
}
|
|
2945
|
-
timeout = setTimeout(function () {
|
|
2946
|
-
onTimeout();
|
|
2947
|
-
}, retry);
|
|
2948
|
-
retry = clampDuration(Math.min(initialRetry * 16, retry * 2));
|
|
2949
|
-
|
|
2950
|
-
es.readyState = CONNECTING;
|
|
2951
|
-
var event = new ErrorEvent("error", {error: error});
|
|
2952
|
-
es.dispatchEvent(event);
|
|
2953
|
-
fire(es, es.onerror, event);
|
|
2954
|
-
if (error != undefined) {
|
|
2955
|
-
console.error(error);
|
|
2956
|
-
}
|
|
2957
|
-
}
|
|
2958
|
-
};
|
|
2959
|
-
|
|
2960
|
-
var close = function () {
|
|
2961
|
-
currentState = CLOSED;
|
|
2962
|
-
if (abortController != undefined) {
|
|
2963
|
-
abortController.abort();
|
|
2964
|
-
abortController = undefined;
|
|
2965
|
-
}
|
|
2966
|
-
if (timeout !== 0) {
|
|
2967
|
-
clearTimeout(timeout);
|
|
2968
|
-
timeout = 0;
|
|
2969
|
-
}
|
|
2970
|
-
es.readyState = CLOSED;
|
|
2971
|
-
};
|
|
2972
|
-
|
|
2973
|
-
var onTimeout = function () {
|
|
2974
|
-
timeout = 0;
|
|
2975
|
-
|
|
2976
|
-
if (currentState !== WAITING) {
|
|
2977
|
-
if (!wasActivity && abortController != undefined) {
|
|
2978
|
-
onFinish(new Error("No activity within " + heartbeatTimeout + " milliseconds." + " " + (currentState === CONNECTING ? "No response received." : textLength + " chars received.") + " " + "Reconnecting."));
|
|
2979
|
-
if (abortController != undefined) {
|
|
2980
|
-
abortController.abort();
|
|
2981
|
-
abortController = undefined;
|
|
2982
|
-
}
|
|
2983
|
-
} else {
|
|
2984
|
-
var nextHeartbeat = Math.max((wasActivity || Date.now()) + heartbeatTimeout - Date.now(), 1);
|
|
2985
|
-
wasActivity = false;
|
|
2986
|
-
timeout = setTimeout(function () {
|
|
2987
|
-
onTimeout();
|
|
2988
|
-
}, nextHeartbeat);
|
|
2989
|
-
}
|
|
2990
|
-
return;
|
|
2991
|
-
}
|
|
2992
|
-
|
|
2993
|
-
wasActivity = false;
|
|
2994
|
-
textLength = 0;
|
|
2995
|
-
timeout = setTimeout(function () {
|
|
2996
|
-
onTimeout();
|
|
2997
|
-
}, heartbeatTimeout);
|
|
2998
|
-
|
|
2999
|
-
currentState = CONNECTING;
|
|
3000
|
-
dataBuffer = "";
|
|
3001
|
-
eventTypeBuffer = "";
|
|
3002
|
-
lastEventIdBuffer = lastEventId;
|
|
3003
|
-
textBuffer = "";
|
|
3004
|
-
fieldStart = 0;
|
|
3005
|
-
valueStart = 0;
|
|
3006
|
-
state = FIELD_START;
|
|
3007
|
-
|
|
3008
|
-
// https://bugzilla.mozilla.org/show_bug.cgi?id=428916
|
|
3009
|
-
// Request header field Last-Event-ID is not allowed by Access-Control-Allow-Headers.
|
|
3010
|
-
var requestURL = url;
|
|
3011
|
-
if (url.slice(0, 5) !== "data:" && url.slice(0, 5) !== "blob:") {
|
|
3012
|
-
if (lastEventId !== "") {
|
|
3013
|
-
// Remove the lastEventId parameter if it's already part of the request URL.
|
|
3014
|
-
var i = url.indexOf("?");
|
|
3015
|
-
requestURL = i === -1 ? url : url.slice(0, i + 1) + url.slice(i + 1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g, function (p, paramName) {
|
|
3016
|
-
return paramName === lastEventIdQueryParameterName ? '' : p;
|
|
3017
|
-
});
|
|
3018
|
-
// Append the current lastEventId to the request URL.
|
|
3019
|
-
requestURL += (url.indexOf("?") === -1 ? "?" : "&") + lastEventIdQueryParameterName +"=" + encodeURIComponent(lastEventId);
|
|
3020
|
-
}
|
|
3021
|
-
}
|
|
3022
|
-
var withCredentials = es.withCredentials;
|
|
3023
|
-
var requestHeaders = {};
|
|
3024
|
-
requestHeaders["Accept"] = "text/event-stream";
|
|
3025
|
-
var headers = es.headers;
|
|
3026
|
-
if (headers != undefined) {
|
|
3027
|
-
for (var name in headers) {
|
|
3028
|
-
if (Object.prototype.hasOwnProperty.call(headers, name)) {
|
|
3029
|
-
requestHeaders[name] = headers[name];
|
|
3030
|
-
}
|
|
3031
|
-
}
|
|
3032
|
-
}
|
|
3033
|
-
try {
|
|
3034
|
-
abortController = transport.open(xhr, onStart, onProgress, onFinish, requestURL, withCredentials, requestHeaders);
|
|
3035
|
-
} catch (error) {
|
|
3036
|
-
close();
|
|
3037
|
-
throw error;
|
|
3038
|
-
}
|
|
3039
|
-
};
|
|
3040
|
-
|
|
3041
|
-
es.url = url;
|
|
3042
|
-
es.readyState = CONNECTING;
|
|
3043
|
-
es.withCredentials = withCredentials;
|
|
3044
|
-
es.headers = headers;
|
|
3045
|
-
es._close = close;
|
|
3046
|
-
|
|
3047
|
-
onTimeout();
|
|
3048
|
-
}
|
|
3049
|
-
|
|
3050
|
-
EventSourcePolyfill.prototype = Object.create(EventTarget.prototype);
|
|
3051
|
-
EventSourcePolyfill.prototype.CONNECTING = CONNECTING;
|
|
3052
|
-
EventSourcePolyfill.prototype.OPEN = OPEN;
|
|
3053
|
-
EventSourcePolyfill.prototype.CLOSED = CLOSED;
|
|
3054
|
-
EventSourcePolyfill.prototype.close = function () {
|
|
3055
|
-
this._close();
|
|
3056
|
-
};
|
|
3057
|
-
|
|
3058
|
-
EventSourcePolyfill.CONNECTING = CONNECTING;
|
|
3059
|
-
EventSourcePolyfill.OPEN = OPEN;
|
|
3060
|
-
EventSourcePolyfill.CLOSED = CLOSED;
|
|
3061
|
-
EventSourcePolyfill.prototype.withCredentials = undefined;
|
|
3062
|
-
|
|
3063
|
-
var R = NativeEventSource;
|
|
3064
|
-
if (XMLHttpRequest != undefined && (NativeEventSource == undefined || !("withCredentials" in NativeEventSource.prototype))) {
|
|
3065
|
-
// Why replace a native EventSource ?
|
|
3066
|
-
// https://bugzilla.mozilla.org/show_bug.cgi?id=444328
|
|
3067
|
-
// https://bugzilla.mozilla.org/show_bug.cgi?id=831392
|
|
3068
|
-
// https://code.google.com/p/chromium/issues/detail?id=260144
|
|
3069
|
-
// https://code.google.com/p/chromium/issues/detail?id=225654
|
|
3070
|
-
// ...
|
|
3071
|
-
R = EventSourcePolyfill;
|
|
3072
|
-
}
|
|
3073
|
-
|
|
3074
|
-
(function (factory) {
|
|
3075
|
-
{
|
|
3076
|
-
var v = factory(exports);
|
|
3077
|
-
if (v !== undefined) module.exports = v;
|
|
3078
|
-
}
|
|
3079
|
-
})(function (exports) {
|
|
3080
|
-
exports.EventSourcePolyfill = EventSourcePolyfill;
|
|
3081
|
-
exports.NativeEventSource = NativeEventSource;
|
|
3082
|
-
exports.EventSource = R;
|
|
3083
|
-
});
|
|
3084
|
-
}(typeof globalThis === 'undefined' ? (typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : commonjsGlobal) : globalThis));
|
|
3085
|
-
} (eventsource, eventsourceExports));
|
|
3086
|
-
|
|
3087
|
-
/* eslint-disable no-var */
|
|
3088
|
-
|
|
3089
|
-
var evs = eventsourceExports;
|
|
3090
|
-
|
|
3091
|
-
var browser = evs.EventSourcePolyfill;
|
|
3092
|
-
|
|
3093
|
-
var envMiddleware = [];
|
|
3094
|
-
class ClientError extends Error {
|
|
3095
|
-
constructor(res) {
|
|
3096
|
-
const props = extractErrorProps(res);
|
|
3097
|
-
super(props.message);
|
|
3098
|
-
this.statusCode = 400;
|
|
3099
|
-
Object.assign(this, props);
|
|
3100
|
-
}
|
|
3101
|
-
}
|
|
3102
|
-
class ServerError extends Error {
|
|
3103
|
-
constructor(res) {
|
|
3104
|
-
const props = extractErrorProps(res);
|
|
3105
|
-
super(props.message);
|
|
3106
|
-
this.statusCode = 500;
|
|
3107
|
-
Object.assign(this, props);
|
|
3108
|
-
}
|
|
3109
|
-
}
|
|
3110
|
-
function extractErrorProps(res) {
|
|
3111
|
-
const body = res.body;
|
|
3112
|
-
const props = {
|
|
3113
|
-
response: res,
|
|
3114
|
-
statusCode: res.statusCode,
|
|
3115
|
-
responseBody: stringifyBody(body, res),
|
|
3116
|
-
message: "",
|
|
3117
|
-
details: void 0
|
|
3118
|
-
};
|
|
3119
|
-
if (body.error && body.message) {
|
|
3120
|
-
props.message = "".concat(body.error, " - ").concat(body.message);
|
|
3121
|
-
return props;
|
|
3122
|
-
}
|
|
3123
|
-
if (body.error && body.error.description) {
|
|
3124
|
-
props.message = body.error.description;
|
|
3125
|
-
props.details = body.error;
|
|
3126
|
-
return props;
|
|
3127
|
-
}
|
|
3128
|
-
props.message = body.error || body.message || httpErrorMessage(res);
|
|
3129
|
-
return props;
|
|
3130
|
-
}
|
|
3131
|
-
function httpErrorMessage(res) {
|
|
3132
|
-
const statusMessage = res.statusMessage ? " ".concat(res.statusMessage) : "";
|
|
3133
|
-
return "".concat(res.method, "-request to ").concat(res.url, " resulted in HTTP ").concat(res.statusCode).concat(statusMessage);
|
|
3134
|
-
}
|
|
3135
|
-
function stringifyBody(body, res) {
|
|
3136
|
-
const contentType = (res.headers["content-type"] || "").toLowerCase();
|
|
3137
|
-
const isJson = contentType.indexOf("application/json") !== -1;
|
|
3138
|
-
return isJson ? JSON.stringify(body, null, 2) : body;
|
|
3139
|
-
}
|
|
3140
|
-
const httpError = {
|
|
3141
|
-
onResponse: res => {
|
|
3142
|
-
if (res.statusCode >= 500) {
|
|
3143
|
-
throw new ServerError(res);
|
|
3144
|
-
} else if (res.statusCode >= 400) {
|
|
3145
|
-
throw new ClientError(res);
|
|
3146
|
-
}
|
|
3147
|
-
return res;
|
|
3148
|
-
}
|
|
2057
|
+
var envMiddleware = [];
|
|
2058
|
+
const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
|
|
2059
|
+
class ClientError extends Error {
|
|
2060
|
+
constructor(res) {
|
|
2061
|
+
const props = extractErrorProps(res);
|
|
2062
|
+
super(props.message);
|
|
2063
|
+
this.statusCode = 400;
|
|
2064
|
+
Object.assign(this, props);
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
class ServerError extends Error {
|
|
2068
|
+
constructor(res) {
|
|
2069
|
+
const props = extractErrorProps(res);
|
|
2070
|
+
super(props.message);
|
|
2071
|
+
this.statusCode = 500;
|
|
2072
|
+
Object.assign(this, props);
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
function extractErrorProps(res) {
|
|
2076
|
+
const body = res.body;
|
|
2077
|
+
const props = {
|
|
2078
|
+
response: res,
|
|
2079
|
+
statusCode: res.statusCode,
|
|
2080
|
+
responseBody: stringifyBody(body, res),
|
|
2081
|
+
message: "",
|
|
2082
|
+
details: void 0
|
|
2083
|
+
};
|
|
2084
|
+
if (body.error && body.message) {
|
|
2085
|
+
props.message = "".concat(body.error, " - ").concat(body.message);
|
|
2086
|
+
return props;
|
|
2087
|
+
}
|
|
2088
|
+
if (isMutationError(body)) {
|
|
2089
|
+
const allItems = body.error.items || [];
|
|
2090
|
+
const items = allItems.slice(0, MAX_ITEMS_IN_ERROR_MESSAGE).map(item => {
|
|
2091
|
+
var _a;
|
|
2092
|
+
return (_a = item.error) == null ? void 0 : _a.description;
|
|
2093
|
+
}).filter(Boolean);
|
|
2094
|
+
let itemsStr = items.length ? ":\n- ".concat(items.join("\n- ")) : "";
|
|
2095
|
+
if (allItems.length > MAX_ITEMS_IN_ERROR_MESSAGE) {
|
|
2096
|
+
itemsStr += "\n...and ".concat(allItems.length - MAX_ITEMS_IN_ERROR_MESSAGE, " more");
|
|
2097
|
+
}
|
|
2098
|
+
props.message = "".concat(body.error.description).concat(itemsStr);
|
|
2099
|
+
props.details = body.error;
|
|
2100
|
+
return props;
|
|
2101
|
+
}
|
|
2102
|
+
if (body.error && body.error.description) {
|
|
2103
|
+
props.message = body.error.description;
|
|
2104
|
+
props.details = body.error;
|
|
2105
|
+
return props;
|
|
2106
|
+
}
|
|
2107
|
+
props.message = body.error || body.message || httpErrorMessage(res);
|
|
2108
|
+
return props;
|
|
2109
|
+
}
|
|
2110
|
+
function isMutationError(body) {
|
|
2111
|
+
return isPlainObject(body) && isPlainObject(body.error) && body.error.type === "mutationError" && typeof body.error.description === "string";
|
|
2112
|
+
}
|
|
2113
|
+
function isPlainObject(obj) {
|
|
2114
|
+
return typeof obj === "object" && obj !== null && !Array.isArray(obj);
|
|
2115
|
+
}
|
|
2116
|
+
function httpErrorMessage(res) {
|
|
2117
|
+
const statusMessage = res.statusMessage ? " ".concat(res.statusMessage) : "";
|
|
2118
|
+
return "".concat(res.method, "-request to ").concat(res.url, " resulted in HTTP ").concat(res.statusCode).concat(statusMessage);
|
|
2119
|
+
}
|
|
2120
|
+
function stringifyBody(body, res) {
|
|
2121
|
+
const contentType = (res.headers["content-type"] || "").toLowerCase();
|
|
2122
|
+
const isJson = contentType.indexOf("application/json") !== -1;
|
|
2123
|
+
return isJson ? JSON.stringify(body, null, 2) : body;
|
|
2124
|
+
}
|
|
2125
|
+
const httpError = {
|
|
2126
|
+
onResponse: res => {
|
|
2127
|
+
if (res.statusCode >= 500) {
|
|
2128
|
+
throw new ServerError(res);
|
|
2129
|
+
} else if (res.statusCode >= 400) {
|
|
2130
|
+
throw new ClientError(res);
|
|
2131
|
+
}
|
|
2132
|
+
return res;
|
|
2133
|
+
}
|
|
3149
2134
|
};
|
|
3150
2135
|
const printWarnings = {
|
|
3151
2136
|
onResponse: res => {
|
|
@@ -3230,7 +2215,7 @@
|
|
|
3230
2215
|
}
|
|
3231
2216
|
};
|
|
3232
2217
|
const validateDocumentId = (op, id) => {
|
|
3233
|
-
if (typeof id !== "string" || !/^[a-z0-9_.-]
|
|
2218
|
+
if (typeof id !== "string" || !/^[a-z0-9_][a-z0-9_.-]{0,127}$/i.test(id) || id.includes("..")) {
|
|
3234
2219
|
throw new Error("".concat(op, "(): \"").concat(id, "\" is not a valid document ID"));
|
|
3235
2220
|
}
|
|
3236
2221
|
};
|
|
@@ -3870,16 +2855,10 @@
|
|
|
3870
2855
|
...options.query
|
|
3871
2856
|
};
|
|
3872
2857
|
}
|
|
3873
|
-
if (config.
|
|
3874
|
-
if (config.apiVersion !== "X") {
|
|
3875
|
-
console.error("You need to set `apiVersion` to `X` to use `unstable_overlayDrafts");
|
|
3876
|
-
}
|
|
2858
|
+
if (config.encodeStegaSourceMap) {
|
|
3877
2859
|
options.query = {
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
...(options.query.params || {}),
|
|
3881
|
-
draftMode: true
|
|
3882
|
-
}
|
|
2860
|
+
encodeHackySourceMap: true,
|
|
2861
|
+
...options.query
|
|
3883
2862
|
};
|
|
3884
2863
|
}
|
|
3885
2864
|
const reqOptions = requestOptions(config, Object.assign({}, options, {
|
|
@@ -4026,7 +3005,7 @@
|
|
|
4026
3005
|
});
|
|
4027
3006
|
}
|
|
4028
3007
|
function optionsFromFile(opts, file) {
|
|
4029
|
-
if (typeof
|
|
3008
|
+
if (typeof File === "undefined" || !(file instanceof File)) {
|
|
4030
3009
|
return opts;
|
|
4031
3010
|
}
|
|
4032
3011
|
return Object.assign({
|
|
@@ -4139,7 +3118,6 @@
|
|
|
4139
3118
|
return selection;
|
|
4140
3119
|
}, {});
|
|
4141
3120
|
const MAX_URL_LENGTH = 16e3 - 1200;
|
|
4142
|
-
const EventSource = browser;
|
|
4143
3121
|
const possibleOptions = ["includePreviousRevision", "includeResult", "visibility", "effectFormat", "tag"];
|
|
4144
3122
|
const defaultOptions = {
|
|
4145
3123
|
includeResult: true
|
|
@@ -4182,7 +3160,13 @@
|
|
|
4182
3160
|
};
|
|
4183
3161
|
}
|
|
4184
3162
|
return new Observable(observer => {
|
|
4185
|
-
let es
|
|
3163
|
+
let es;
|
|
3164
|
+
getEventSource().then(eventSource => {
|
|
3165
|
+
es = eventSource;
|
|
3166
|
+
}).catch(reason => {
|
|
3167
|
+
observer.error(reason);
|
|
3168
|
+
stop();
|
|
3169
|
+
});
|
|
4186
3170
|
let reconnectTimer;
|
|
4187
3171
|
let stopped = false;
|
|
4188
3172
|
function onError() {
|
|
@@ -4193,7 +3177,7 @@
|
|
|
4193
3177
|
if (stopped) {
|
|
4194
3178
|
return;
|
|
4195
3179
|
}
|
|
4196
|
-
if (es.readyState ===
|
|
3180
|
+
if (es.readyState === es.CLOSED) {
|
|
4197
3181
|
unsubscribe();
|
|
4198
3182
|
clearTimeout(reconnectTimer);
|
|
4199
3183
|
reconnectTimer = setTimeout(open, 100);
|
|
@@ -4212,10 +3196,11 @@
|
|
|
4212
3196
|
observer.complete();
|
|
4213
3197
|
}
|
|
4214
3198
|
function unsubscribe() {
|
|
4215
|
-
es
|
|
4216
|
-
es.removeEventListener("
|
|
4217
|
-
es.removeEventListener("
|
|
4218
|
-
|
|
3199
|
+
if (!es) return;
|
|
3200
|
+
es.removeEventListener("error", onError);
|
|
3201
|
+
es.removeEventListener("channelError", onChannelError);
|
|
3202
|
+
es.removeEventListener("disconnect", onDisconnect);
|
|
3203
|
+
listenFor.forEach(type => es.removeEventListener(type, onMessage));
|
|
4219
3204
|
es.close();
|
|
4220
3205
|
}
|
|
4221
3206
|
function emitReconnect() {
|
|
@@ -4225,16 +3210,24 @@
|
|
|
4225
3210
|
});
|
|
4226
3211
|
}
|
|
4227
3212
|
}
|
|
4228
|
-
function getEventSource() {
|
|
3213
|
+
async function getEventSource() {
|
|
3214
|
+
const {
|
|
3215
|
+
default: EventSource
|
|
3216
|
+
} = await Promise.resolve().then(function () { return browser$1; });
|
|
4229
3217
|
const evs = new EventSource(uri, esOptions);
|
|
4230
|
-
evs.addEventListener("error", onError
|
|
4231
|
-
evs.addEventListener("channelError", onChannelError
|
|
4232
|
-
evs.addEventListener("disconnect", onDisconnect
|
|
4233
|
-
listenFor.forEach(type => evs.addEventListener(type, onMessage
|
|
3218
|
+
evs.addEventListener("error", onError);
|
|
3219
|
+
evs.addEventListener("channelError", onChannelError);
|
|
3220
|
+
evs.addEventListener("disconnect", onDisconnect);
|
|
3221
|
+
listenFor.forEach(type => evs.addEventListener(type, onMessage));
|
|
4234
3222
|
return evs;
|
|
4235
3223
|
}
|
|
4236
3224
|
function open() {
|
|
4237
|
-
|
|
3225
|
+
getEventSource().then(eventSource => {
|
|
3226
|
+
es = eventSource;
|
|
3227
|
+
}).catch(reason => {
|
|
3228
|
+
observer.error(reason);
|
|
3229
|
+
stop();
|
|
3230
|
+
});
|
|
4238
3231
|
}
|
|
4239
3232
|
function stop() {
|
|
4240
3233
|
stopped = true;
|
|
@@ -4824,6 +3817,1063 @@
|
|
|
4824
3817
|
return new SanityClient(httpRequest, config);
|
|
4825
3818
|
}
|
|
4826
3819
|
|
|
3820
|
+
var eventsourceExports = {};
|
|
3821
|
+
var eventsource = {
|
|
3822
|
+
get exports(){ return eventsourceExports; },
|
|
3823
|
+
set exports(v){ eventsourceExports = v; },
|
|
3824
|
+
};
|
|
3825
|
+
|
|
3826
|
+
/** @license
|
|
3827
|
+
* eventsource.js
|
|
3828
|
+
* Available under MIT License (MIT)
|
|
3829
|
+
* https://github.com/Yaffle/EventSource/
|
|
3830
|
+
*/
|
|
3831
|
+
|
|
3832
|
+
(function (module, exports) {
|
|
3833
|
+
/*jslint indent: 2, vars: true, plusplus: true */
|
|
3834
|
+
/*global setTimeout, clearTimeout */
|
|
3835
|
+
|
|
3836
|
+
(function (global) {
|
|
3837
|
+
|
|
3838
|
+
var setTimeout = global.setTimeout;
|
|
3839
|
+
var clearTimeout = global.clearTimeout;
|
|
3840
|
+
var XMLHttpRequest = global.XMLHttpRequest;
|
|
3841
|
+
var XDomainRequest = global.XDomainRequest;
|
|
3842
|
+
var ActiveXObject = global.ActiveXObject;
|
|
3843
|
+
var NativeEventSource = global.EventSource;
|
|
3844
|
+
|
|
3845
|
+
var document = global.document;
|
|
3846
|
+
var Promise = global.Promise;
|
|
3847
|
+
var fetch = global.fetch;
|
|
3848
|
+
var Response = global.Response;
|
|
3849
|
+
var TextDecoder = global.TextDecoder;
|
|
3850
|
+
var TextEncoder = global.TextEncoder;
|
|
3851
|
+
var AbortController = global.AbortController;
|
|
3852
|
+
|
|
3853
|
+
if (typeof window !== "undefined" && typeof document !== "undefined" && !("readyState" in document) && document.body == null) { // Firefox 2
|
|
3854
|
+
document.readyState = "loading";
|
|
3855
|
+
window.addEventListener("load", function (event) {
|
|
3856
|
+
document.readyState = "complete";
|
|
3857
|
+
}, false);
|
|
3858
|
+
}
|
|
3859
|
+
|
|
3860
|
+
if (XMLHttpRequest == null && ActiveXObject != null) { // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest_in_IE6
|
|
3861
|
+
XMLHttpRequest = function () {
|
|
3862
|
+
return new ActiveXObject("Microsoft.XMLHTTP");
|
|
3863
|
+
};
|
|
3864
|
+
}
|
|
3865
|
+
|
|
3866
|
+
if (Object.create == undefined) {
|
|
3867
|
+
Object.create = function (C) {
|
|
3868
|
+
function F(){}
|
|
3869
|
+
F.prototype = C;
|
|
3870
|
+
return new F();
|
|
3871
|
+
};
|
|
3872
|
+
}
|
|
3873
|
+
|
|
3874
|
+
if (!Date.now) {
|
|
3875
|
+
Date.now = function now() {
|
|
3876
|
+
return new Date().getTime();
|
|
3877
|
+
};
|
|
3878
|
+
}
|
|
3879
|
+
|
|
3880
|
+
// see #118 (Promise#finally with polyfilled Promise)
|
|
3881
|
+
// see #123 (data URLs crash Edge)
|
|
3882
|
+
// see #125 (CSP violations)
|
|
3883
|
+
// see pull/#138
|
|
3884
|
+
// => No way to polyfill Promise#finally
|
|
3885
|
+
|
|
3886
|
+
if (AbortController == undefined) {
|
|
3887
|
+
var originalFetch2 = fetch;
|
|
3888
|
+
fetch = function (url, options) {
|
|
3889
|
+
var signal = options.signal;
|
|
3890
|
+
return originalFetch2(url, {headers: options.headers, credentials: options.credentials, cache: options.cache}).then(function (response) {
|
|
3891
|
+
var reader = response.body.getReader();
|
|
3892
|
+
signal._reader = reader;
|
|
3893
|
+
if (signal._aborted) {
|
|
3894
|
+
signal._reader.cancel();
|
|
3895
|
+
}
|
|
3896
|
+
return {
|
|
3897
|
+
status: response.status,
|
|
3898
|
+
statusText: response.statusText,
|
|
3899
|
+
headers: response.headers,
|
|
3900
|
+
body: {
|
|
3901
|
+
getReader: function () {
|
|
3902
|
+
return reader;
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
};
|
|
3906
|
+
});
|
|
3907
|
+
};
|
|
3908
|
+
AbortController = function () {
|
|
3909
|
+
this.signal = {
|
|
3910
|
+
_reader: null,
|
|
3911
|
+
_aborted: false
|
|
3912
|
+
};
|
|
3913
|
+
this.abort = function () {
|
|
3914
|
+
if (this.signal._reader != null) {
|
|
3915
|
+
this.signal._reader.cancel();
|
|
3916
|
+
}
|
|
3917
|
+
this.signal._aborted = true;
|
|
3918
|
+
};
|
|
3919
|
+
};
|
|
3920
|
+
}
|
|
3921
|
+
|
|
3922
|
+
function TextDecoderPolyfill() {
|
|
3923
|
+
this.bitsNeeded = 0;
|
|
3924
|
+
this.codePoint = 0;
|
|
3925
|
+
}
|
|
3926
|
+
|
|
3927
|
+
TextDecoderPolyfill.prototype.decode = function (octets) {
|
|
3928
|
+
function valid(codePoint, shift, octetsCount) {
|
|
3929
|
+
if (octetsCount === 1) {
|
|
3930
|
+
return codePoint >= 0x0080 >> shift && codePoint << shift <= 0x07FF;
|
|
3931
|
+
}
|
|
3932
|
+
if (octetsCount === 2) {
|
|
3933
|
+
return codePoint >= 0x0800 >> shift && codePoint << shift <= 0xD7FF || codePoint >= 0xE000 >> shift && codePoint << shift <= 0xFFFF;
|
|
3934
|
+
}
|
|
3935
|
+
if (octetsCount === 3) {
|
|
3936
|
+
return codePoint >= 0x010000 >> shift && codePoint << shift <= 0x10FFFF;
|
|
3937
|
+
}
|
|
3938
|
+
throw new Error();
|
|
3939
|
+
}
|
|
3940
|
+
function octetsCount(bitsNeeded, codePoint) {
|
|
3941
|
+
if (bitsNeeded === 6 * 1) {
|
|
3942
|
+
return codePoint >> 6 > 15 ? 3 : codePoint > 31 ? 2 : 1;
|
|
3943
|
+
}
|
|
3944
|
+
if (bitsNeeded === 6 * 2) {
|
|
3945
|
+
return codePoint > 15 ? 3 : 2;
|
|
3946
|
+
}
|
|
3947
|
+
if (bitsNeeded === 6 * 3) {
|
|
3948
|
+
return 3;
|
|
3949
|
+
}
|
|
3950
|
+
throw new Error();
|
|
3951
|
+
}
|
|
3952
|
+
var REPLACER = 0xFFFD;
|
|
3953
|
+
var string = "";
|
|
3954
|
+
var bitsNeeded = this.bitsNeeded;
|
|
3955
|
+
var codePoint = this.codePoint;
|
|
3956
|
+
for (var i = 0; i < octets.length; i += 1) {
|
|
3957
|
+
var octet = octets[i];
|
|
3958
|
+
if (bitsNeeded !== 0) {
|
|
3959
|
+
if (octet < 128 || octet > 191 || !valid(codePoint << 6 | octet & 63, bitsNeeded - 6, octetsCount(bitsNeeded, codePoint))) {
|
|
3960
|
+
bitsNeeded = 0;
|
|
3961
|
+
codePoint = REPLACER;
|
|
3962
|
+
string += String.fromCharCode(codePoint);
|
|
3963
|
+
}
|
|
3964
|
+
}
|
|
3965
|
+
if (bitsNeeded === 0) {
|
|
3966
|
+
if (octet >= 0 && octet <= 127) {
|
|
3967
|
+
bitsNeeded = 0;
|
|
3968
|
+
codePoint = octet;
|
|
3969
|
+
} else if (octet >= 192 && octet <= 223) {
|
|
3970
|
+
bitsNeeded = 6 * 1;
|
|
3971
|
+
codePoint = octet & 31;
|
|
3972
|
+
} else if (octet >= 224 && octet <= 239) {
|
|
3973
|
+
bitsNeeded = 6 * 2;
|
|
3974
|
+
codePoint = octet & 15;
|
|
3975
|
+
} else if (octet >= 240 && octet <= 247) {
|
|
3976
|
+
bitsNeeded = 6 * 3;
|
|
3977
|
+
codePoint = octet & 7;
|
|
3978
|
+
} else {
|
|
3979
|
+
bitsNeeded = 0;
|
|
3980
|
+
codePoint = REPLACER;
|
|
3981
|
+
}
|
|
3982
|
+
if (bitsNeeded !== 0 && !valid(codePoint, bitsNeeded, octetsCount(bitsNeeded, codePoint))) {
|
|
3983
|
+
bitsNeeded = 0;
|
|
3984
|
+
codePoint = REPLACER;
|
|
3985
|
+
}
|
|
3986
|
+
} else {
|
|
3987
|
+
bitsNeeded -= 6;
|
|
3988
|
+
codePoint = codePoint << 6 | octet & 63;
|
|
3989
|
+
}
|
|
3990
|
+
if (bitsNeeded === 0) {
|
|
3991
|
+
if (codePoint <= 0xFFFF) {
|
|
3992
|
+
string += String.fromCharCode(codePoint);
|
|
3993
|
+
} else {
|
|
3994
|
+
string += String.fromCharCode(0xD800 + (codePoint - 0xFFFF - 1 >> 10));
|
|
3995
|
+
string += String.fromCharCode(0xDC00 + (codePoint - 0xFFFF - 1 & 0x3FF));
|
|
3996
|
+
}
|
|
3997
|
+
}
|
|
3998
|
+
}
|
|
3999
|
+
this.bitsNeeded = bitsNeeded;
|
|
4000
|
+
this.codePoint = codePoint;
|
|
4001
|
+
return string;
|
|
4002
|
+
};
|
|
4003
|
+
|
|
4004
|
+
// Firefox < 38 throws an error with stream option
|
|
4005
|
+
var supportsStreamOption = function () {
|
|
4006
|
+
try {
|
|
4007
|
+
return new TextDecoder().decode(new TextEncoder().encode("test"), {stream: true}) === "test";
|
|
4008
|
+
} catch (error) {
|
|
4009
|
+
console.debug("TextDecoder does not support streaming option. Using polyfill instead: " + error);
|
|
4010
|
+
}
|
|
4011
|
+
return false;
|
|
4012
|
+
};
|
|
4013
|
+
|
|
4014
|
+
// IE, Edge
|
|
4015
|
+
if (TextDecoder == undefined || TextEncoder == undefined || !supportsStreamOption()) {
|
|
4016
|
+
TextDecoder = TextDecoderPolyfill;
|
|
4017
|
+
}
|
|
4018
|
+
|
|
4019
|
+
var k = function () {
|
|
4020
|
+
};
|
|
4021
|
+
|
|
4022
|
+
function XHRWrapper(xhr) {
|
|
4023
|
+
this.withCredentials = false;
|
|
4024
|
+
this.readyState = 0;
|
|
4025
|
+
this.status = 0;
|
|
4026
|
+
this.statusText = "";
|
|
4027
|
+
this.responseText = "";
|
|
4028
|
+
this.onprogress = k;
|
|
4029
|
+
this.onload = k;
|
|
4030
|
+
this.onerror = k;
|
|
4031
|
+
this.onreadystatechange = k;
|
|
4032
|
+
this._contentType = "";
|
|
4033
|
+
this._xhr = xhr;
|
|
4034
|
+
this._sendTimeout = 0;
|
|
4035
|
+
this._abort = k;
|
|
4036
|
+
}
|
|
4037
|
+
|
|
4038
|
+
XHRWrapper.prototype.open = function (method, url) {
|
|
4039
|
+
this._abort(true);
|
|
4040
|
+
|
|
4041
|
+
var that = this;
|
|
4042
|
+
var xhr = this._xhr;
|
|
4043
|
+
var state = 1;
|
|
4044
|
+
var timeout = 0;
|
|
4045
|
+
|
|
4046
|
+
this._abort = function (silent) {
|
|
4047
|
+
if (that._sendTimeout !== 0) {
|
|
4048
|
+
clearTimeout(that._sendTimeout);
|
|
4049
|
+
that._sendTimeout = 0;
|
|
4050
|
+
}
|
|
4051
|
+
if (state === 1 || state === 2 || state === 3) {
|
|
4052
|
+
state = 4;
|
|
4053
|
+
xhr.onload = k;
|
|
4054
|
+
xhr.onerror = k;
|
|
4055
|
+
xhr.onabort = k;
|
|
4056
|
+
xhr.onprogress = k;
|
|
4057
|
+
xhr.onreadystatechange = k;
|
|
4058
|
+
// IE 8 - 9: XDomainRequest#abort() does not fire any event
|
|
4059
|
+
// Opera < 10: XMLHttpRequest#abort() does not fire any event
|
|
4060
|
+
xhr.abort();
|
|
4061
|
+
if (timeout !== 0) {
|
|
4062
|
+
clearTimeout(timeout);
|
|
4063
|
+
timeout = 0;
|
|
4064
|
+
}
|
|
4065
|
+
if (!silent) {
|
|
4066
|
+
that.readyState = 4;
|
|
4067
|
+
that.onabort(null);
|
|
4068
|
+
that.onreadystatechange();
|
|
4069
|
+
}
|
|
4070
|
+
}
|
|
4071
|
+
state = 0;
|
|
4072
|
+
};
|
|
4073
|
+
|
|
4074
|
+
var onStart = function () {
|
|
4075
|
+
if (state === 1) {
|
|
4076
|
+
//state = 2;
|
|
4077
|
+
var status = 0;
|
|
4078
|
+
var statusText = "";
|
|
4079
|
+
var contentType = undefined;
|
|
4080
|
+
if (!("contentType" in xhr)) {
|
|
4081
|
+
try {
|
|
4082
|
+
status = xhr.status;
|
|
4083
|
+
statusText = xhr.statusText;
|
|
4084
|
+
contentType = xhr.getResponseHeader("Content-Type");
|
|
4085
|
+
} catch (error) {
|
|
4086
|
+
// IE < 10 throws exception for `xhr.status` when xhr.readyState === 2 || xhr.readyState === 3
|
|
4087
|
+
// Opera < 11 throws exception for `xhr.status` when xhr.readyState === 2
|
|
4088
|
+
// https://bugs.webkit.org/show_bug.cgi?id=29121
|
|
4089
|
+
status = 0;
|
|
4090
|
+
statusText = "";
|
|
4091
|
+
contentType = undefined;
|
|
4092
|
+
// Firefox < 14, Chrome ?, Safari ?
|
|
4093
|
+
// https://bugs.webkit.org/show_bug.cgi?id=29658
|
|
4094
|
+
// https://bugs.webkit.org/show_bug.cgi?id=77854
|
|
4095
|
+
}
|
|
4096
|
+
} else {
|
|
4097
|
+
status = 200;
|
|
4098
|
+
statusText = "OK";
|
|
4099
|
+
contentType = xhr.contentType;
|
|
4100
|
+
}
|
|
4101
|
+
if (status !== 0) {
|
|
4102
|
+
state = 2;
|
|
4103
|
+
that.readyState = 2;
|
|
4104
|
+
that.status = status;
|
|
4105
|
+
that.statusText = statusText;
|
|
4106
|
+
that._contentType = contentType;
|
|
4107
|
+
that.onreadystatechange();
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
};
|
|
4111
|
+
var onProgress = function () {
|
|
4112
|
+
onStart();
|
|
4113
|
+
if (state === 2 || state === 3) {
|
|
4114
|
+
state = 3;
|
|
4115
|
+
var responseText = "";
|
|
4116
|
+
try {
|
|
4117
|
+
responseText = xhr.responseText;
|
|
4118
|
+
} catch (error) {
|
|
4119
|
+
// IE 8 - 9 with XMLHttpRequest
|
|
4120
|
+
}
|
|
4121
|
+
that.readyState = 3;
|
|
4122
|
+
that.responseText = responseText;
|
|
4123
|
+
that.onprogress();
|
|
4124
|
+
}
|
|
4125
|
+
};
|
|
4126
|
+
var onFinish = function (type, event) {
|
|
4127
|
+
if (event == null || event.preventDefault == null) {
|
|
4128
|
+
event = {
|
|
4129
|
+
preventDefault: k
|
|
4130
|
+
};
|
|
4131
|
+
}
|
|
4132
|
+
// Firefox 52 fires "readystatechange" (xhr.readyState === 4) without final "readystatechange" (xhr.readyState === 3)
|
|
4133
|
+
// IE 8 fires "onload" without "onprogress"
|
|
4134
|
+
onProgress();
|
|
4135
|
+
if (state === 1 || state === 2 || state === 3) {
|
|
4136
|
+
state = 4;
|
|
4137
|
+
if (timeout !== 0) {
|
|
4138
|
+
clearTimeout(timeout);
|
|
4139
|
+
timeout = 0;
|
|
4140
|
+
}
|
|
4141
|
+
that.readyState = 4;
|
|
4142
|
+
if (type === "load") {
|
|
4143
|
+
that.onload(event);
|
|
4144
|
+
} else if (type === "error") {
|
|
4145
|
+
that.onerror(event);
|
|
4146
|
+
} else if (type === "abort") {
|
|
4147
|
+
that.onabort(event);
|
|
4148
|
+
} else {
|
|
4149
|
+
throw new TypeError();
|
|
4150
|
+
}
|
|
4151
|
+
that.onreadystatechange();
|
|
4152
|
+
}
|
|
4153
|
+
};
|
|
4154
|
+
var onReadyStateChange = function (event) {
|
|
4155
|
+
if (xhr != undefined) { // Opera 12
|
|
4156
|
+
if (xhr.readyState === 4) {
|
|
4157
|
+
if (!("onload" in xhr) || !("onerror" in xhr) || !("onabort" in xhr)) {
|
|
4158
|
+
onFinish(xhr.responseText === "" ? "error" : "load", event);
|
|
4159
|
+
}
|
|
4160
|
+
} else if (xhr.readyState === 3) {
|
|
4161
|
+
if (!("onprogress" in xhr)) { // testing XMLHttpRequest#responseText too many times is too slow in IE 11
|
|
4162
|
+
// and in Firefox 3.6
|
|
4163
|
+
onProgress();
|
|
4164
|
+
}
|
|
4165
|
+
} else if (xhr.readyState === 2) {
|
|
4166
|
+
onStart();
|
|
4167
|
+
}
|
|
4168
|
+
}
|
|
4169
|
+
};
|
|
4170
|
+
var onTimeout = function () {
|
|
4171
|
+
timeout = setTimeout(function () {
|
|
4172
|
+
onTimeout();
|
|
4173
|
+
}, 500);
|
|
4174
|
+
if (xhr.readyState === 3) {
|
|
4175
|
+
onProgress();
|
|
4176
|
+
}
|
|
4177
|
+
};
|
|
4178
|
+
|
|
4179
|
+
// XDomainRequest#abort removes onprogress, onerror, onload
|
|
4180
|
+
if ("onload" in xhr) {
|
|
4181
|
+
xhr.onload = function (event) {
|
|
4182
|
+
onFinish("load", event);
|
|
4183
|
+
};
|
|
4184
|
+
}
|
|
4185
|
+
if ("onerror" in xhr) {
|
|
4186
|
+
xhr.onerror = function (event) {
|
|
4187
|
+
onFinish("error", event);
|
|
4188
|
+
};
|
|
4189
|
+
}
|
|
4190
|
+
// improper fix to match Firefox behaviour, but it is better than just ignore abort
|
|
4191
|
+
// see https://bugzilla.mozilla.org/show_bug.cgi?id=768596
|
|
4192
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=880200
|
|
4193
|
+
// https://code.google.com/p/chromium/issues/detail?id=153570
|
|
4194
|
+
// IE 8 fires "onload" without "onprogress
|
|
4195
|
+
if ("onabort" in xhr) {
|
|
4196
|
+
xhr.onabort = function (event) {
|
|
4197
|
+
onFinish("abort", event);
|
|
4198
|
+
};
|
|
4199
|
+
}
|
|
4200
|
+
|
|
4201
|
+
if ("onprogress" in xhr) {
|
|
4202
|
+
xhr.onprogress = onProgress;
|
|
4203
|
+
}
|
|
4204
|
+
|
|
4205
|
+
// IE 8 - 9 (XMLHTTPRequest)
|
|
4206
|
+
// Opera < 12
|
|
4207
|
+
// Firefox < 3.5
|
|
4208
|
+
// Firefox 3.5 - 3.6 - ? < 9.0
|
|
4209
|
+
// onprogress is not fired sometimes or delayed
|
|
4210
|
+
// see also #64 (significant lag in IE 11)
|
|
4211
|
+
if ("onreadystatechange" in xhr) {
|
|
4212
|
+
xhr.onreadystatechange = function (event) {
|
|
4213
|
+
onReadyStateChange(event);
|
|
4214
|
+
};
|
|
4215
|
+
}
|
|
4216
|
+
|
|
4217
|
+
if ("contentType" in xhr || !("ontimeout" in XMLHttpRequest.prototype)) {
|
|
4218
|
+
url += (url.indexOf("?") === -1 ? "?" : "&") + "padding=true";
|
|
4219
|
+
}
|
|
4220
|
+
xhr.open(method, url, true);
|
|
4221
|
+
|
|
4222
|
+
if ("readyState" in xhr) {
|
|
4223
|
+
// workaround for Opera 12 issue with "progress" events
|
|
4224
|
+
// #91 (XMLHttpRequest onprogress not fired for streaming response in Edge 14-15-?)
|
|
4225
|
+
timeout = setTimeout(function () {
|
|
4226
|
+
onTimeout();
|
|
4227
|
+
}, 0);
|
|
4228
|
+
}
|
|
4229
|
+
};
|
|
4230
|
+
XHRWrapper.prototype.abort = function () {
|
|
4231
|
+
this._abort(false);
|
|
4232
|
+
};
|
|
4233
|
+
XHRWrapper.prototype.getResponseHeader = function (name) {
|
|
4234
|
+
return this._contentType;
|
|
4235
|
+
};
|
|
4236
|
+
XHRWrapper.prototype.setRequestHeader = function (name, value) {
|
|
4237
|
+
var xhr = this._xhr;
|
|
4238
|
+
if ("setRequestHeader" in xhr) {
|
|
4239
|
+
xhr.setRequestHeader(name, value);
|
|
4240
|
+
}
|
|
4241
|
+
};
|
|
4242
|
+
XHRWrapper.prototype.getAllResponseHeaders = function () {
|
|
4243
|
+
// XMLHttpRequest#getAllResponseHeaders returns null for CORS requests in Firefox 3.6.28
|
|
4244
|
+
return this._xhr.getAllResponseHeaders != undefined ? this._xhr.getAllResponseHeaders() || "" : "";
|
|
4245
|
+
};
|
|
4246
|
+
XHRWrapper.prototype.send = function () {
|
|
4247
|
+
// loading indicator in Safari < ? (6), Chrome < 14, Firefox
|
|
4248
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=736723
|
|
4249
|
+
if ((!("ontimeout" in XMLHttpRequest.prototype) || (!("sendAsBinary" in XMLHttpRequest.prototype) && !("mozAnon" in XMLHttpRequest.prototype))) &&
|
|
4250
|
+
document != undefined &&
|
|
4251
|
+
document.readyState != undefined &&
|
|
4252
|
+
document.readyState !== "complete") {
|
|
4253
|
+
var that = this;
|
|
4254
|
+
that._sendTimeout = setTimeout(function () {
|
|
4255
|
+
that._sendTimeout = 0;
|
|
4256
|
+
that.send();
|
|
4257
|
+
}, 4);
|
|
4258
|
+
return;
|
|
4259
|
+
}
|
|
4260
|
+
|
|
4261
|
+
var xhr = this._xhr;
|
|
4262
|
+
// withCredentials should be set after "open" for Safari and Chrome (< 19 ?)
|
|
4263
|
+
if ("withCredentials" in xhr) {
|
|
4264
|
+
xhr.withCredentials = this.withCredentials;
|
|
4265
|
+
}
|
|
4266
|
+
try {
|
|
4267
|
+
// xhr.send(); throws "Not enough arguments" in Firefox 3.0
|
|
4268
|
+
xhr.send(undefined);
|
|
4269
|
+
} catch (error1) {
|
|
4270
|
+
// Safari 5.1.7, Opera 12
|
|
4271
|
+
throw error1;
|
|
4272
|
+
}
|
|
4273
|
+
};
|
|
4274
|
+
|
|
4275
|
+
function toLowerCase(name) {
|
|
4276
|
+
return name.replace(/[A-Z]/g, function (c) {
|
|
4277
|
+
return String.fromCharCode(c.charCodeAt(0) + 0x20);
|
|
4278
|
+
});
|
|
4279
|
+
}
|
|
4280
|
+
|
|
4281
|
+
function HeadersPolyfill(all) {
|
|
4282
|
+
// Get headers: implemented according to mozilla's example code: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#Example
|
|
4283
|
+
var map = Object.create(null);
|
|
4284
|
+
var array = all.split("\r\n");
|
|
4285
|
+
for (var i = 0; i < array.length; i += 1) {
|
|
4286
|
+
var line = array[i];
|
|
4287
|
+
var parts = line.split(": ");
|
|
4288
|
+
var name = parts.shift();
|
|
4289
|
+
var value = parts.join(": ");
|
|
4290
|
+
map[toLowerCase(name)] = value;
|
|
4291
|
+
}
|
|
4292
|
+
this._map = map;
|
|
4293
|
+
}
|
|
4294
|
+
HeadersPolyfill.prototype.get = function (name) {
|
|
4295
|
+
return this._map[toLowerCase(name)];
|
|
4296
|
+
};
|
|
4297
|
+
|
|
4298
|
+
if (XMLHttpRequest != null && XMLHttpRequest.HEADERS_RECEIVED == null) { // IE < 9, Firefox 3.6
|
|
4299
|
+
XMLHttpRequest.HEADERS_RECEIVED = 2;
|
|
4300
|
+
}
|
|
4301
|
+
|
|
4302
|
+
function XHRTransport() {
|
|
4303
|
+
}
|
|
4304
|
+
|
|
4305
|
+
XHRTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
|
|
4306
|
+
xhr.open("GET", url);
|
|
4307
|
+
var offset = 0;
|
|
4308
|
+
xhr.onprogress = function () {
|
|
4309
|
+
var responseText = xhr.responseText;
|
|
4310
|
+
var chunk = responseText.slice(offset);
|
|
4311
|
+
offset += chunk.length;
|
|
4312
|
+
onProgressCallback(chunk);
|
|
4313
|
+
};
|
|
4314
|
+
xhr.onerror = function (event) {
|
|
4315
|
+
event.preventDefault();
|
|
4316
|
+
onFinishCallback(new Error("NetworkError"));
|
|
4317
|
+
};
|
|
4318
|
+
xhr.onload = function () {
|
|
4319
|
+
onFinishCallback(null);
|
|
4320
|
+
};
|
|
4321
|
+
xhr.onabort = function () {
|
|
4322
|
+
onFinishCallback(null);
|
|
4323
|
+
};
|
|
4324
|
+
xhr.onreadystatechange = function () {
|
|
4325
|
+
if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
|
|
4326
|
+
var status = xhr.status;
|
|
4327
|
+
var statusText = xhr.statusText;
|
|
4328
|
+
var contentType = xhr.getResponseHeader("Content-Type");
|
|
4329
|
+
var headers = xhr.getAllResponseHeaders();
|
|
4330
|
+
onStartCallback(status, statusText, contentType, new HeadersPolyfill(headers));
|
|
4331
|
+
}
|
|
4332
|
+
};
|
|
4333
|
+
xhr.withCredentials = withCredentials;
|
|
4334
|
+
for (var name in headers) {
|
|
4335
|
+
if (Object.prototype.hasOwnProperty.call(headers, name)) {
|
|
4336
|
+
xhr.setRequestHeader(name, headers[name]);
|
|
4337
|
+
}
|
|
4338
|
+
}
|
|
4339
|
+
xhr.send();
|
|
4340
|
+
return xhr;
|
|
4341
|
+
};
|
|
4342
|
+
|
|
4343
|
+
function HeadersWrapper(headers) {
|
|
4344
|
+
this._headers = headers;
|
|
4345
|
+
}
|
|
4346
|
+
HeadersWrapper.prototype.get = function (name) {
|
|
4347
|
+
return this._headers.get(name);
|
|
4348
|
+
};
|
|
4349
|
+
|
|
4350
|
+
function FetchTransport() {
|
|
4351
|
+
}
|
|
4352
|
+
|
|
4353
|
+
FetchTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
|
|
4354
|
+
var reader = null;
|
|
4355
|
+
var controller = new AbortController();
|
|
4356
|
+
var signal = controller.signal;
|
|
4357
|
+
var textDecoder = new TextDecoder();
|
|
4358
|
+
fetch(url, {
|
|
4359
|
+
headers: headers,
|
|
4360
|
+
credentials: withCredentials ? "include" : "same-origin",
|
|
4361
|
+
signal: signal,
|
|
4362
|
+
cache: "no-store"
|
|
4363
|
+
}).then(function (response) {
|
|
4364
|
+
reader = response.body.getReader();
|
|
4365
|
+
onStartCallback(response.status, response.statusText, response.headers.get("Content-Type"), new HeadersWrapper(response.headers));
|
|
4366
|
+
// see https://github.com/promises-aplus/promises-spec/issues/179
|
|
4367
|
+
return new Promise(function (resolve, reject) {
|
|
4368
|
+
var readNextChunk = function () {
|
|
4369
|
+
reader.read().then(function (result) {
|
|
4370
|
+
if (result.done) {
|
|
4371
|
+
//Note: bytes in textDecoder are ignored
|
|
4372
|
+
resolve(undefined);
|
|
4373
|
+
} else {
|
|
4374
|
+
var chunk = textDecoder.decode(result.value, {stream: true});
|
|
4375
|
+
onProgressCallback(chunk);
|
|
4376
|
+
readNextChunk();
|
|
4377
|
+
}
|
|
4378
|
+
})["catch"](function (error) {
|
|
4379
|
+
reject(error);
|
|
4380
|
+
});
|
|
4381
|
+
};
|
|
4382
|
+
readNextChunk();
|
|
4383
|
+
});
|
|
4384
|
+
})["catch"](function (error) {
|
|
4385
|
+
if (error.name === "AbortError") {
|
|
4386
|
+
return undefined;
|
|
4387
|
+
} else {
|
|
4388
|
+
return error;
|
|
4389
|
+
}
|
|
4390
|
+
}).then(function (error) {
|
|
4391
|
+
onFinishCallback(error);
|
|
4392
|
+
});
|
|
4393
|
+
return {
|
|
4394
|
+
abort: function () {
|
|
4395
|
+
if (reader != null) {
|
|
4396
|
+
reader.cancel(); // https://bugzilla.mozilla.org/show_bug.cgi?id=1583815
|
|
4397
|
+
}
|
|
4398
|
+
controller.abort();
|
|
4399
|
+
}
|
|
4400
|
+
};
|
|
4401
|
+
};
|
|
4402
|
+
|
|
4403
|
+
function EventTarget() {
|
|
4404
|
+
this._listeners = Object.create(null);
|
|
4405
|
+
}
|
|
4406
|
+
|
|
4407
|
+
function throwError(e) {
|
|
4408
|
+
setTimeout(function () {
|
|
4409
|
+
throw e;
|
|
4410
|
+
}, 0);
|
|
4411
|
+
}
|
|
4412
|
+
|
|
4413
|
+
EventTarget.prototype.dispatchEvent = function (event) {
|
|
4414
|
+
event.target = this;
|
|
4415
|
+
var typeListeners = this._listeners[event.type];
|
|
4416
|
+
if (typeListeners != undefined) {
|
|
4417
|
+
var length = typeListeners.length;
|
|
4418
|
+
for (var i = 0; i < length; i += 1) {
|
|
4419
|
+
var listener = typeListeners[i];
|
|
4420
|
+
try {
|
|
4421
|
+
if (typeof listener.handleEvent === "function") {
|
|
4422
|
+
listener.handleEvent(event);
|
|
4423
|
+
} else {
|
|
4424
|
+
listener.call(this, event);
|
|
4425
|
+
}
|
|
4426
|
+
} catch (e) {
|
|
4427
|
+
throwError(e);
|
|
4428
|
+
}
|
|
4429
|
+
}
|
|
4430
|
+
}
|
|
4431
|
+
};
|
|
4432
|
+
EventTarget.prototype.addEventListener = function (type, listener) {
|
|
4433
|
+
type = String(type);
|
|
4434
|
+
var listeners = this._listeners;
|
|
4435
|
+
var typeListeners = listeners[type];
|
|
4436
|
+
if (typeListeners == undefined) {
|
|
4437
|
+
typeListeners = [];
|
|
4438
|
+
listeners[type] = typeListeners;
|
|
4439
|
+
}
|
|
4440
|
+
var found = false;
|
|
4441
|
+
for (var i = 0; i < typeListeners.length; i += 1) {
|
|
4442
|
+
if (typeListeners[i] === listener) {
|
|
4443
|
+
found = true;
|
|
4444
|
+
}
|
|
4445
|
+
}
|
|
4446
|
+
if (!found) {
|
|
4447
|
+
typeListeners.push(listener);
|
|
4448
|
+
}
|
|
4449
|
+
};
|
|
4450
|
+
EventTarget.prototype.removeEventListener = function (type, listener) {
|
|
4451
|
+
type = String(type);
|
|
4452
|
+
var listeners = this._listeners;
|
|
4453
|
+
var typeListeners = listeners[type];
|
|
4454
|
+
if (typeListeners != undefined) {
|
|
4455
|
+
var filtered = [];
|
|
4456
|
+
for (var i = 0; i < typeListeners.length; i += 1) {
|
|
4457
|
+
if (typeListeners[i] !== listener) {
|
|
4458
|
+
filtered.push(typeListeners[i]);
|
|
4459
|
+
}
|
|
4460
|
+
}
|
|
4461
|
+
if (filtered.length === 0) {
|
|
4462
|
+
delete listeners[type];
|
|
4463
|
+
} else {
|
|
4464
|
+
listeners[type] = filtered;
|
|
4465
|
+
}
|
|
4466
|
+
}
|
|
4467
|
+
};
|
|
4468
|
+
|
|
4469
|
+
function Event(type) {
|
|
4470
|
+
this.type = type;
|
|
4471
|
+
this.target = undefined;
|
|
4472
|
+
}
|
|
4473
|
+
|
|
4474
|
+
function MessageEvent(type, options) {
|
|
4475
|
+
Event.call(this, type);
|
|
4476
|
+
this.data = options.data;
|
|
4477
|
+
this.lastEventId = options.lastEventId;
|
|
4478
|
+
}
|
|
4479
|
+
|
|
4480
|
+
MessageEvent.prototype = Object.create(Event.prototype);
|
|
4481
|
+
|
|
4482
|
+
function ConnectionEvent(type, options) {
|
|
4483
|
+
Event.call(this, type);
|
|
4484
|
+
this.status = options.status;
|
|
4485
|
+
this.statusText = options.statusText;
|
|
4486
|
+
this.headers = options.headers;
|
|
4487
|
+
}
|
|
4488
|
+
|
|
4489
|
+
ConnectionEvent.prototype = Object.create(Event.prototype);
|
|
4490
|
+
|
|
4491
|
+
function ErrorEvent(type, options) {
|
|
4492
|
+
Event.call(this, type);
|
|
4493
|
+
this.error = options.error;
|
|
4494
|
+
}
|
|
4495
|
+
|
|
4496
|
+
ErrorEvent.prototype = Object.create(Event.prototype);
|
|
4497
|
+
|
|
4498
|
+
var WAITING = -1;
|
|
4499
|
+
var CONNECTING = 0;
|
|
4500
|
+
var OPEN = 1;
|
|
4501
|
+
var CLOSED = 2;
|
|
4502
|
+
|
|
4503
|
+
var AFTER_CR = -1;
|
|
4504
|
+
var FIELD_START = 0;
|
|
4505
|
+
var FIELD = 1;
|
|
4506
|
+
var VALUE_START = 2;
|
|
4507
|
+
var VALUE = 3;
|
|
4508
|
+
|
|
4509
|
+
var contentTypeRegExp = /^text\/event\-stream(;.*)?$/i;
|
|
4510
|
+
|
|
4511
|
+
var MINIMUM_DURATION = 1000;
|
|
4512
|
+
var MAXIMUM_DURATION = 18000000;
|
|
4513
|
+
|
|
4514
|
+
var parseDuration = function (value, def) {
|
|
4515
|
+
var n = value == null ? def : parseInt(value, 10);
|
|
4516
|
+
if (n !== n) {
|
|
4517
|
+
n = def;
|
|
4518
|
+
}
|
|
4519
|
+
return clampDuration(n);
|
|
4520
|
+
};
|
|
4521
|
+
var clampDuration = function (n) {
|
|
4522
|
+
return Math.min(Math.max(n, MINIMUM_DURATION), MAXIMUM_DURATION);
|
|
4523
|
+
};
|
|
4524
|
+
|
|
4525
|
+
var fire = function (that, f, event) {
|
|
4526
|
+
try {
|
|
4527
|
+
if (typeof f === "function") {
|
|
4528
|
+
f.call(that, event);
|
|
4529
|
+
}
|
|
4530
|
+
} catch (e) {
|
|
4531
|
+
throwError(e);
|
|
4532
|
+
}
|
|
4533
|
+
};
|
|
4534
|
+
|
|
4535
|
+
function EventSourcePolyfill(url, options) {
|
|
4536
|
+
EventTarget.call(this);
|
|
4537
|
+
options = options || {};
|
|
4538
|
+
|
|
4539
|
+
this.onopen = undefined;
|
|
4540
|
+
this.onmessage = undefined;
|
|
4541
|
+
this.onerror = undefined;
|
|
4542
|
+
|
|
4543
|
+
this.url = undefined;
|
|
4544
|
+
this.readyState = undefined;
|
|
4545
|
+
this.withCredentials = undefined;
|
|
4546
|
+
this.headers = undefined;
|
|
4547
|
+
|
|
4548
|
+
this._close = undefined;
|
|
4549
|
+
|
|
4550
|
+
start(this, url, options);
|
|
4551
|
+
}
|
|
4552
|
+
|
|
4553
|
+
function getBestXHRTransport() {
|
|
4554
|
+
return (XMLHttpRequest != undefined && ("withCredentials" in XMLHttpRequest.prototype)) || XDomainRequest == undefined
|
|
4555
|
+
? new XMLHttpRequest()
|
|
4556
|
+
: new XDomainRequest();
|
|
4557
|
+
}
|
|
4558
|
+
|
|
4559
|
+
var isFetchSupported = fetch != undefined && Response != undefined && "body" in Response.prototype;
|
|
4560
|
+
|
|
4561
|
+
function start(es, url, options) {
|
|
4562
|
+
url = String(url);
|
|
4563
|
+
var withCredentials = Boolean(options.withCredentials);
|
|
4564
|
+
var lastEventIdQueryParameterName = options.lastEventIdQueryParameterName || "lastEventId";
|
|
4565
|
+
|
|
4566
|
+
var initialRetry = clampDuration(1000);
|
|
4567
|
+
var heartbeatTimeout = parseDuration(options.heartbeatTimeout, 45000);
|
|
4568
|
+
|
|
4569
|
+
var lastEventId = "";
|
|
4570
|
+
var retry = initialRetry;
|
|
4571
|
+
var wasActivity = false;
|
|
4572
|
+
var textLength = 0;
|
|
4573
|
+
var headers = options.headers || {};
|
|
4574
|
+
var TransportOption = options.Transport;
|
|
4575
|
+
var xhr = isFetchSupported && TransportOption == undefined ? undefined : new XHRWrapper(TransportOption != undefined ? new TransportOption() : getBestXHRTransport());
|
|
4576
|
+
var transport = TransportOption != null && typeof TransportOption !== "string" ? new TransportOption() : (xhr == undefined ? new FetchTransport() : new XHRTransport());
|
|
4577
|
+
var abortController = undefined;
|
|
4578
|
+
var timeout = 0;
|
|
4579
|
+
var currentState = WAITING;
|
|
4580
|
+
var dataBuffer = "";
|
|
4581
|
+
var lastEventIdBuffer = "";
|
|
4582
|
+
var eventTypeBuffer = "";
|
|
4583
|
+
|
|
4584
|
+
var textBuffer = "";
|
|
4585
|
+
var state = FIELD_START;
|
|
4586
|
+
var fieldStart = 0;
|
|
4587
|
+
var valueStart = 0;
|
|
4588
|
+
|
|
4589
|
+
var onStart = function (status, statusText, contentType, headers) {
|
|
4590
|
+
if (currentState === CONNECTING) {
|
|
4591
|
+
if (status === 200 && contentType != undefined && contentTypeRegExp.test(contentType)) {
|
|
4592
|
+
currentState = OPEN;
|
|
4593
|
+
wasActivity = Date.now();
|
|
4594
|
+
retry = initialRetry;
|
|
4595
|
+
es.readyState = OPEN;
|
|
4596
|
+
var event = new ConnectionEvent("open", {
|
|
4597
|
+
status: status,
|
|
4598
|
+
statusText: statusText,
|
|
4599
|
+
headers: headers
|
|
4600
|
+
});
|
|
4601
|
+
es.dispatchEvent(event);
|
|
4602
|
+
fire(es, es.onopen, event);
|
|
4603
|
+
} else {
|
|
4604
|
+
var message = "";
|
|
4605
|
+
if (status !== 200) {
|
|
4606
|
+
if (statusText) {
|
|
4607
|
+
statusText = statusText.replace(/\s+/g, " ");
|
|
4608
|
+
}
|
|
4609
|
+
message = "EventSource's response has a status " + status + " " + statusText + " that is not 200. Aborting the connection.";
|
|
4610
|
+
} else {
|
|
4611
|
+
message = "EventSource's response has a Content-Type specifying an unsupported type: " + (contentType == undefined ? "-" : contentType.replace(/\s+/g, " ")) + ". Aborting the connection.";
|
|
4612
|
+
}
|
|
4613
|
+
close();
|
|
4614
|
+
var event = new ConnectionEvent("error", {
|
|
4615
|
+
status: status,
|
|
4616
|
+
statusText: statusText,
|
|
4617
|
+
headers: headers
|
|
4618
|
+
});
|
|
4619
|
+
es.dispatchEvent(event);
|
|
4620
|
+
fire(es, es.onerror, event);
|
|
4621
|
+
console.error(message);
|
|
4622
|
+
}
|
|
4623
|
+
}
|
|
4624
|
+
};
|
|
4625
|
+
|
|
4626
|
+
var onProgress = function (textChunk) {
|
|
4627
|
+
if (currentState === OPEN) {
|
|
4628
|
+
var n = -1;
|
|
4629
|
+
for (var i = 0; i < textChunk.length; i += 1) {
|
|
4630
|
+
var c = textChunk.charCodeAt(i);
|
|
4631
|
+
if (c === "\n".charCodeAt(0) || c === "\r".charCodeAt(0)) {
|
|
4632
|
+
n = i;
|
|
4633
|
+
}
|
|
4634
|
+
}
|
|
4635
|
+
var chunk = (n !== -1 ? textBuffer : "") + textChunk.slice(0, n + 1);
|
|
4636
|
+
textBuffer = (n === -1 ? textBuffer : "") + textChunk.slice(n + 1);
|
|
4637
|
+
if (textChunk !== "") {
|
|
4638
|
+
wasActivity = Date.now();
|
|
4639
|
+
textLength += textChunk.length;
|
|
4640
|
+
}
|
|
4641
|
+
for (var position = 0; position < chunk.length; position += 1) {
|
|
4642
|
+
var c = chunk.charCodeAt(position);
|
|
4643
|
+
if (state === AFTER_CR && c === "\n".charCodeAt(0)) {
|
|
4644
|
+
state = FIELD_START;
|
|
4645
|
+
} else {
|
|
4646
|
+
if (state === AFTER_CR) {
|
|
4647
|
+
state = FIELD_START;
|
|
4648
|
+
}
|
|
4649
|
+
if (c === "\r".charCodeAt(0) || c === "\n".charCodeAt(0)) {
|
|
4650
|
+
if (state !== FIELD_START) {
|
|
4651
|
+
if (state === FIELD) {
|
|
4652
|
+
valueStart = position + 1;
|
|
4653
|
+
}
|
|
4654
|
+
var field = chunk.slice(fieldStart, valueStart - 1);
|
|
4655
|
+
var value = chunk.slice(valueStart + (valueStart < position && chunk.charCodeAt(valueStart) === " ".charCodeAt(0) ? 1 : 0), position);
|
|
4656
|
+
if (field === "data") {
|
|
4657
|
+
dataBuffer += "\n";
|
|
4658
|
+
dataBuffer += value;
|
|
4659
|
+
} else if (field === "id") {
|
|
4660
|
+
lastEventIdBuffer = value;
|
|
4661
|
+
} else if (field === "event") {
|
|
4662
|
+
eventTypeBuffer = value;
|
|
4663
|
+
} else if (field === "retry") {
|
|
4664
|
+
initialRetry = parseDuration(value, initialRetry);
|
|
4665
|
+
retry = initialRetry;
|
|
4666
|
+
} else if (field === "heartbeatTimeout") {
|
|
4667
|
+
heartbeatTimeout = parseDuration(value, heartbeatTimeout);
|
|
4668
|
+
if (timeout !== 0) {
|
|
4669
|
+
clearTimeout(timeout);
|
|
4670
|
+
timeout = setTimeout(function () {
|
|
4671
|
+
onTimeout();
|
|
4672
|
+
}, heartbeatTimeout);
|
|
4673
|
+
}
|
|
4674
|
+
}
|
|
4675
|
+
}
|
|
4676
|
+
if (state === FIELD_START) {
|
|
4677
|
+
if (dataBuffer !== "") {
|
|
4678
|
+
lastEventId = lastEventIdBuffer;
|
|
4679
|
+
if (eventTypeBuffer === "") {
|
|
4680
|
+
eventTypeBuffer = "message";
|
|
4681
|
+
}
|
|
4682
|
+
var event = new MessageEvent(eventTypeBuffer, {
|
|
4683
|
+
data: dataBuffer.slice(1),
|
|
4684
|
+
lastEventId: lastEventIdBuffer
|
|
4685
|
+
});
|
|
4686
|
+
es.dispatchEvent(event);
|
|
4687
|
+
if (eventTypeBuffer === "open") {
|
|
4688
|
+
fire(es, es.onopen, event);
|
|
4689
|
+
} else if (eventTypeBuffer === "message") {
|
|
4690
|
+
fire(es, es.onmessage, event);
|
|
4691
|
+
} else if (eventTypeBuffer === "error") {
|
|
4692
|
+
fire(es, es.onerror, event);
|
|
4693
|
+
}
|
|
4694
|
+
if (currentState === CLOSED) {
|
|
4695
|
+
return;
|
|
4696
|
+
}
|
|
4697
|
+
}
|
|
4698
|
+
dataBuffer = "";
|
|
4699
|
+
eventTypeBuffer = "";
|
|
4700
|
+
}
|
|
4701
|
+
state = c === "\r".charCodeAt(0) ? AFTER_CR : FIELD_START;
|
|
4702
|
+
} else {
|
|
4703
|
+
if (state === FIELD_START) {
|
|
4704
|
+
fieldStart = position;
|
|
4705
|
+
state = FIELD;
|
|
4706
|
+
}
|
|
4707
|
+
if (state === FIELD) {
|
|
4708
|
+
if (c === ":".charCodeAt(0)) {
|
|
4709
|
+
valueStart = position + 1;
|
|
4710
|
+
state = VALUE_START;
|
|
4711
|
+
}
|
|
4712
|
+
} else if (state === VALUE_START) {
|
|
4713
|
+
state = VALUE;
|
|
4714
|
+
}
|
|
4715
|
+
}
|
|
4716
|
+
}
|
|
4717
|
+
}
|
|
4718
|
+
}
|
|
4719
|
+
};
|
|
4720
|
+
|
|
4721
|
+
var onFinish = function (error) {
|
|
4722
|
+
if (currentState === OPEN || currentState === CONNECTING) {
|
|
4723
|
+
currentState = WAITING;
|
|
4724
|
+
if (timeout !== 0) {
|
|
4725
|
+
clearTimeout(timeout);
|
|
4726
|
+
timeout = 0;
|
|
4727
|
+
}
|
|
4728
|
+
timeout = setTimeout(function () {
|
|
4729
|
+
onTimeout();
|
|
4730
|
+
}, retry);
|
|
4731
|
+
retry = clampDuration(Math.min(initialRetry * 16, retry * 2));
|
|
4732
|
+
|
|
4733
|
+
es.readyState = CONNECTING;
|
|
4734
|
+
var event = new ErrorEvent("error", {error: error});
|
|
4735
|
+
es.dispatchEvent(event);
|
|
4736
|
+
fire(es, es.onerror, event);
|
|
4737
|
+
if (error != undefined) {
|
|
4738
|
+
console.error(error);
|
|
4739
|
+
}
|
|
4740
|
+
}
|
|
4741
|
+
};
|
|
4742
|
+
|
|
4743
|
+
var close = function () {
|
|
4744
|
+
currentState = CLOSED;
|
|
4745
|
+
if (abortController != undefined) {
|
|
4746
|
+
abortController.abort();
|
|
4747
|
+
abortController = undefined;
|
|
4748
|
+
}
|
|
4749
|
+
if (timeout !== 0) {
|
|
4750
|
+
clearTimeout(timeout);
|
|
4751
|
+
timeout = 0;
|
|
4752
|
+
}
|
|
4753
|
+
es.readyState = CLOSED;
|
|
4754
|
+
};
|
|
4755
|
+
|
|
4756
|
+
var onTimeout = function () {
|
|
4757
|
+
timeout = 0;
|
|
4758
|
+
|
|
4759
|
+
if (currentState !== WAITING) {
|
|
4760
|
+
if (!wasActivity && abortController != undefined) {
|
|
4761
|
+
onFinish(new Error("No activity within " + heartbeatTimeout + " milliseconds." + " " + (currentState === CONNECTING ? "No response received." : textLength + " chars received.") + " " + "Reconnecting."));
|
|
4762
|
+
if (abortController != undefined) {
|
|
4763
|
+
abortController.abort();
|
|
4764
|
+
abortController = undefined;
|
|
4765
|
+
}
|
|
4766
|
+
} else {
|
|
4767
|
+
var nextHeartbeat = Math.max((wasActivity || Date.now()) + heartbeatTimeout - Date.now(), 1);
|
|
4768
|
+
wasActivity = false;
|
|
4769
|
+
timeout = setTimeout(function () {
|
|
4770
|
+
onTimeout();
|
|
4771
|
+
}, nextHeartbeat);
|
|
4772
|
+
}
|
|
4773
|
+
return;
|
|
4774
|
+
}
|
|
4775
|
+
|
|
4776
|
+
wasActivity = false;
|
|
4777
|
+
textLength = 0;
|
|
4778
|
+
timeout = setTimeout(function () {
|
|
4779
|
+
onTimeout();
|
|
4780
|
+
}, heartbeatTimeout);
|
|
4781
|
+
|
|
4782
|
+
currentState = CONNECTING;
|
|
4783
|
+
dataBuffer = "";
|
|
4784
|
+
eventTypeBuffer = "";
|
|
4785
|
+
lastEventIdBuffer = lastEventId;
|
|
4786
|
+
textBuffer = "";
|
|
4787
|
+
fieldStart = 0;
|
|
4788
|
+
valueStart = 0;
|
|
4789
|
+
state = FIELD_START;
|
|
4790
|
+
|
|
4791
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=428916
|
|
4792
|
+
// Request header field Last-Event-ID is not allowed by Access-Control-Allow-Headers.
|
|
4793
|
+
var requestURL = url;
|
|
4794
|
+
if (url.slice(0, 5) !== "data:" && url.slice(0, 5) !== "blob:") {
|
|
4795
|
+
if (lastEventId !== "") {
|
|
4796
|
+
// Remove the lastEventId parameter if it's already part of the request URL.
|
|
4797
|
+
var i = url.indexOf("?");
|
|
4798
|
+
requestURL = i === -1 ? url : url.slice(0, i + 1) + url.slice(i + 1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g, function (p, paramName) {
|
|
4799
|
+
return paramName === lastEventIdQueryParameterName ? '' : p;
|
|
4800
|
+
});
|
|
4801
|
+
// Append the current lastEventId to the request URL.
|
|
4802
|
+
requestURL += (url.indexOf("?") === -1 ? "?" : "&") + lastEventIdQueryParameterName +"=" + encodeURIComponent(lastEventId);
|
|
4803
|
+
}
|
|
4804
|
+
}
|
|
4805
|
+
var withCredentials = es.withCredentials;
|
|
4806
|
+
var requestHeaders = {};
|
|
4807
|
+
requestHeaders["Accept"] = "text/event-stream";
|
|
4808
|
+
var headers = es.headers;
|
|
4809
|
+
if (headers != undefined) {
|
|
4810
|
+
for (var name in headers) {
|
|
4811
|
+
if (Object.prototype.hasOwnProperty.call(headers, name)) {
|
|
4812
|
+
requestHeaders[name] = headers[name];
|
|
4813
|
+
}
|
|
4814
|
+
}
|
|
4815
|
+
}
|
|
4816
|
+
try {
|
|
4817
|
+
abortController = transport.open(xhr, onStart, onProgress, onFinish, requestURL, withCredentials, requestHeaders);
|
|
4818
|
+
} catch (error) {
|
|
4819
|
+
close();
|
|
4820
|
+
throw error;
|
|
4821
|
+
}
|
|
4822
|
+
};
|
|
4823
|
+
|
|
4824
|
+
es.url = url;
|
|
4825
|
+
es.readyState = CONNECTING;
|
|
4826
|
+
es.withCredentials = withCredentials;
|
|
4827
|
+
es.headers = headers;
|
|
4828
|
+
es._close = close;
|
|
4829
|
+
|
|
4830
|
+
onTimeout();
|
|
4831
|
+
}
|
|
4832
|
+
|
|
4833
|
+
EventSourcePolyfill.prototype = Object.create(EventTarget.prototype);
|
|
4834
|
+
EventSourcePolyfill.prototype.CONNECTING = CONNECTING;
|
|
4835
|
+
EventSourcePolyfill.prototype.OPEN = OPEN;
|
|
4836
|
+
EventSourcePolyfill.prototype.CLOSED = CLOSED;
|
|
4837
|
+
EventSourcePolyfill.prototype.close = function () {
|
|
4838
|
+
this._close();
|
|
4839
|
+
};
|
|
4840
|
+
|
|
4841
|
+
EventSourcePolyfill.CONNECTING = CONNECTING;
|
|
4842
|
+
EventSourcePolyfill.OPEN = OPEN;
|
|
4843
|
+
EventSourcePolyfill.CLOSED = CLOSED;
|
|
4844
|
+
EventSourcePolyfill.prototype.withCredentials = undefined;
|
|
4845
|
+
|
|
4846
|
+
var R = NativeEventSource;
|
|
4847
|
+
if (XMLHttpRequest != undefined && (NativeEventSource == undefined || !("withCredentials" in NativeEventSource.prototype))) {
|
|
4848
|
+
// Why replace a native EventSource ?
|
|
4849
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=444328
|
|
4850
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=831392
|
|
4851
|
+
// https://code.google.com/p/chromium/issues/detail?id=260144
|
|
4852
|
+
// https://code.google.com/p/chromium/issues/detail?id=225654
|
|
4853
|
+
// ...
|
|
4854
|
+
R = EventSourcePolyfill;
|
|
4855
|
+
}
|
|
4856
|
+
|
|
4857
|
+
(function (factory) {
|
|
4858
|
+
{
|
|
4859
|
+
var v = factory(exports);
|
|
4860
|
+
if (v !== undefined) module.exports = v;
|
|
4861
|
+
}
|
|
4862
|
+
})(function (exports) {
|
|
4863
|
+
exports.EventSourcePolyfill = EventSourcePolyfill;
|
|
4864
|
+
exports.NativeEventSource = NativeEventSource;
|
|
4865
|
+
exports.EventSource = R;
|
|
4866
|
+
});
|
|
4867
|
+
}(typeof globalThis === 'undefined' ? (typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : commonjsGlobal) : globalThis));
|
|
4868
|
+
} (eventsource, eventsourceExports));
|
|
4869
|
+
|
|
4870
|
+
var browser = eventsourceExports.EventSourcePolyfill;
|
|
4871
|
+
|
|
4872
|
+
var browser$1 = /*#__PURE__*/_mergeNamespaces({
|
|
4873
|
+
__proto__: null,
|
|
4874
|
+
default: browser
|
|
4875
|
+
}, [browser]);
|
|
4876
|
+
|
|
4827
4877
|
exports.BasePatch = BasePatch;
|
|
4828
4878
|
exports.BaseTransaction = BaseTransaction;
|
|
4829
4879
|
exports.ClientError = ClientError;
|
|
@@ -4837,6 +4887,8 @@
|
|
|
4837
4887
|
exports.createClient = createClient;
|
|
4838
4888
|
exports.default = deprecatedCreateClient;
|
|
4839
4889
|
exports.requester = requester;
|
|
4890
|
+
exports.unstable__adapter = adapter;
|
|
4891
|
+
exports.unstable__environment = environment;
|
|
4840
4892
|
|
|
4841
4893
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4842
4894
|
|